@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
60 lines • 2.73 kB
JavaScript
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
import { fileStreamOp } from "../utils.js";
import { transferLinksOf } from "../utils.js";
import { refuseReveal } from "../../../generic_bind/files.js";
import { mvGeneric, parseFlags } from "../../mv.js";
import { flatScopes, readdirOp, relayCopy, relayWrite, statOp } from "../utils.js";
import { FlagView } from "../../../../spec/flag_view.js";
import { specOf } from "../../../../spec/builtins.js";
import { linkView, mountView } from "../../../utils/links.js";
// Move operands that span mounts via the shared generic mv. Pure wiring:
// copy through the transfer primitives, then unlink the source on its own
// mount.
export async function runMv(scopes, flagKwargs, dispatch,
// Maps an operand to its storage identity. Without it a move between
// two prefixes over one store would copy the object onto itself and
// then unlink the source, destroying it.
storageKey, vfs,
// Where -i reads its answers.
stdin = null,
// Refuses a source whose mount cannot condition the delete.
checkUnlink) {
const flat = flatScopes(scopes);
const stat = statOp(dispatch);
const readdir = readdirOp(dispatch);
const write = (p, data) => relayWrite(dispatch, p, data);
const mkdir = async (p) => {
await dispatch('mkdir', p);
};
const unlink = async (p) => {
await dispatch('unlink', p);
};
const rmdir = async (p) => {
await dispatch('rmdir', p);
};
const mounts = mountView(vfs);
const links = linkView(vfs);
return mvGeneric(flat, stat, {
read: fileStreamOp(dispatch),
write,
mkdir,
readdir,
unlink,
rmdir,
copy: (src, dst) => relayCopy(dispatch, src, dst),
...(checkUnlink !== undefined ? { checkUnlink } : {}),
}, parseFlags(new FlagView(flagKwargs, specOf('mv'))), storageKey, undefined, refuseReveal, links === undefined ? undefined : transferLinksOf(links, dispatch, '/'), stdin, mounts === undefined ? undefined : (p) => mounts.isRoot(p), dispatch);
}
//# sourceMappingURL=mv.js.map