UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

51 lines • 2.24 kB
// ========= 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 { specOf } from "../../spec/builtins.js"; import { FlagView } from "../../spec/flag_view.js"; import { IOResult } from "../../../io/types.js"; import { stdinStream, streamOutput } from "../utils/stream.js"; import { reportedStream } from "../utils/operands.js"; import { asyncChain } from "../../../io/stream.js"; import { openStream } from "../../../rs/stream.js"; import { byteView } from "../../../shell/bytes.js"; import { StreamRefusal } from "../../../rs/errors.js"; export function parseFlags(bag) { const fl = new FlagView(bag, specOf('expand')); const tabs = fl.asList('tabs'); return { tabs, initialOnly: fl.asBool('initial') }; } export async function expandGeneric(paths, ctx, stream) { stream = stdinStream(stream, ctx.stdin); const parsed = parseFlags(ctx.flags); let engine; try { engine = await openStream('expand', { tabs: parsed.tabs.map((tab) => byteView(tab)), initial_only: parsed.initialOnly, }); } catch (error) { if (!(error instanceof StreamRefusal)) throw error; return [ null, new IOResult({ exitCode: 1, stderr: new TextEncoder().encode(`${error.message}\n`) }), ]; } const io = new IOResult(); const sources = paths.map((p) => reportedStream(stream(p), io, p, 'expand')); const source = paths.length > 0 ? asyncChain(sources) : (ctx.stdin ?? new Uint8Array()); return [streamOutput(engine, source, ctx.signal), io]; } //# sourceMappingURL=expand.js.map