UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

48 lines • 2.21 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 { IOResult } from "../../../../io/types.js"; import { facts, sedGeneric, positionalAsPaths } from "../../generic/sed.js"; import { specOf } from "../../../spec/builtins.js"; import { FlagView } from "../../../spec/flag_view.js"; import {} from "../adapter.js"; import { commandFiles } from "../files.js"; const ENC = new TextEncoder(); export const BUILDER = { name: 'sed', facts: facts, write: true, read: true, fn: async (_accessor, paths, texts, ctx) => { const files = commandFiles(ctx, paths); // The default stream-to-stdout path is read-only and works on every // backend; only in-place editing needs a write op (#382). const fl = new FlagView(ctx.flags, specOf('sed')); if (fl.asBool('i') && !files.answers('write')) { return [ null, new IOResult({ exitCode: 1, stderr: ENC.encode('sed: -i not supported on this backend: Permission denied\n'), }), ]; } // With -e/-f the positional operand is a file, not the script. const usingE = fl.asList('e').length > 0; const usingF = fl.asPaths('f').length > 0; const operands = usingE || usingF ? [...positionalAsPaths(texts, ctx), ...paths] : paths; const resolved = operands.length > 0 ? await files.resolveGlob(operands) : operands; return sedGeneric(resolved, texts, ctx, files.read); }, }; //# sourceMappingURL=sed.js.map