UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

72 lines • 3.6 kB
import { runAwk } from "./awk.js"; import { runCp } from "./cp.js"; import { runLs } from "./ls.js"; import { runMv } from "./mv.js"; import { runSed } from "./sed.js"; import { runTar } from "./tar.js"; import { runTee } from "./tee.js"; import { runUnzip } from "./unzip.js"; import { runWc } from "./wc.js"; import { runZip } from "./zip_cmd.js"; import { DISPATCH_BUILDERS, RELAY_COMMANDS } from "../constants.js"; import { runDispatch } from "../../../generic_bind/dispatch.js"; // Run a command whose work must see every operand at once. Pure wiring: // every operand is read or written through dispatch primitives on its owning // mount, and the shared generic does the work in its primitive mode, so // output matches the single-mount commands. export async function runRelay(cmdName, scopes, textArgs, flagKwargs, dispatch, // Single-mount runner: wc counts each operand with its own mount's wc, // since a mount can count without reading; only its layout spans the line. // awk runs once on its first file's mount, reading the rest through the // dispatcher, so every operand keeps its own name. runSingle, // Maps an operand to its storage identity, for the transfer commands // that must tell a real move from one whose two prefixes address a // single store. storageKey, // Name-plane facts for the generics that render them (ls: links, attr // overlay, child mounts) and for the archivers' scan (tar, zip: links, // mount boundaries). vfs, // The session view, for the generic that renders the session's // profile (ls -l). sessionView, stdin = null, // The session's working directory, which cp resolves a typed link source // against. cwd = '/', argv = [], checkUnlink, diff, ids, signal) { if (!RELAY_COMMANDS.has(cmdName)) throw new Error(`Unsupported cross-mount relay command: ${cmdName}`); if (cmdName === 'awk') return runAwk(scopes, textArgs, flagKwargs, runSingle, stdin); // bc runs its files, then standard input, as one program: once, on its // first file's mount, reading the rest through the dispatcher. Only that // file names the mount, so none of the others is checked against a backend // that does not hold it. if (cmdName === 'bc') return runSingle('bc', scopes, textArgs, flagKwargs, { stdin, resolveHint: scopes[0] ?? null }); if (cmdName === 'sed') return runSed(scopes, textArgs, flagKwargs, dispatch, stdin, cwd, argv, sessionView?.snapshot()); if (cmdName === 'wc') return runWc(scopes, flagKwargs, dispatch, runSingle, cwd, vfs, stdin); if (cmdName === 'ls') return runLs(scopes, flagKwargs, dispatch, vfs, sessionView); if (cmdName === 'cp') return runCp(scopes, flagKwargs, dispatch, storageKey, vfs, cwd, stdin); if (cmdName === 'mv') { return runMv(scopes, flagKwargs, dispatch, storageKey, vfs, stdin, checkUnlink); } if (cmdName === 'tar') return runTar(scopes, textArgs, flagKwargs, dispatch, cwd, vfs, stdin); if (cmdName === 'tee') return runTee(scopes, flagKwargs, dispatch, stdin, storageKey); if (cmdName === 'unzip') return runUnzip(scopes, textArgs, flagKwargs, dispatch, cwd); if (cmdName === 'zip') return runZip(scopes, flagKwargs, dispatch, vfs); const builder = DISPATCH_BUILDERS.get(cmdName); if (builder !== undefined) { return runDispatch(builder, scopes, textArgs, flagKwargs, dispatch, cwd, vfs, stdin, signal, argv, undefined, diff, ids); } throw new Error(`No cross-mount composition for ${cmdName}`); } //# sourceMappingURL=relay.js.map