@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
54 lines • 2.08 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 { awkGeneric, isAssignment, servedHere } from "../../generic/awk.js";
import { commandFiles } from "../files.js";
/**
* Expand awk's file operands, keeping `var=value` ones in place: an
* assignment operand names no file, so it is never globbed, and awk
* assigns it when its input reaches it, between the files around it. An
* operand another mount serves arrives expanded and is read through the
* dispatcher, so it is left as it is too.
*/
async function resolveOperands(resolve, paths, ctx) {
const out = [];
let run = [];
for (const path of paths) {
if (!isAssignment(path.rawPath) && servedHere(ctx, path)) {
run.push(path);
continue;
}
if (run.length > 0)
for (const item of await resolve(run))
out.push(item);
run = [];
out.push(path);
}
if (run.length > 0)
for (const item of await resolve(run))
out.push(item);
return out;
}
const awk = async (_accessor, paths, texts, ctx) => {
const files = commandFiles(ctx, paths);
const resolve = (run) => files.resolveGlob(run);
const resolved = await resolveOperands(resolve, paths, ctx);
return awkGeneric(resolved, texts, ctx, files.read);
};
export const BUILDER = {
name: 'awk',
write: true,
read: true,
fn: awk,
};
//# sourceMappingURL=awk.js.map