@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
52 lines • 2.44 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 { callerSignal } from "../../../context/session_context.js";
import { YieldBudget } from "../../../io/yield_budget.js";
import {} from "../../../commands/spec/types.js";
import { classifyWord } from "./heuristic.js";
import { classifyBarePath } from "./path.js";
// Classify a list of expanded words. The first element (command name)
// is never classified as a path. wordKinds (from CommandSpec, aligned
// with parts[1:]) decides per position: TEXT skips classification,
// PATH classifies even bare filenames, null falls back to the shape
// heuristics. wordBases, also aligned with parts[1:], names the
// directory a word resolves against when a chdir option (tar's -C)
// moved it; null there means the cwd. A long list yields between its
// words, so a cancel or the line's deadline lands mid-list.
export async function classifyParts(parts, registry, cwd, wordKinds = null, wordBases = null, access) {
if (parts.length === 0)
return [];
const result = [parts[0] ?? ''];
const budget = new YieldBudget(callerSignal());
for (let i = 1; i < parts.length; i++) {
await budget.run();
const w = parts[i];
if (w === undefined)
continue;
const kind = wordKinds !== null ? (wordKinds[i - 1] ?? null) : null;
const base = wordBases !== null ? (wordBases[i - 1] ?? null) : null;
const here = base ?? cwd;
if (kind !== null && kind !== 'path') {
result.push(w);
}
else if (kind === 'path') {
result.push(classifyBarePath(w, registry, here, access));
}
else {
result.push(classifyWord(w, registry, here, access));
}
}
return result;
}
//# sourceMappingURL=parts.js.map