UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

63 lines • 2.69 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 { encodeText } from "../../../../shell/bytes.js"; import { compareCodePoints } from "../../../../utils/sort.js"; /** Where a repository entry sits in the session's tree. */ export function entryPath(location, name) { return location.worktree.join(name); } /** * The paths each comparison changed, one row per path and side. * * A path both sides hold alike is no row: no format prints it, and a rename * is only ever found among changed paths. `first` is the number the first * comparison takes, for a command that makes its comparisons in batches. */ export function deltas(location, sides, first = 0) { const rows = []; sides.forEach(([before, after], index) => { for (const name of [...new Set([...before.keys(), ...after.keys()])].sort(compareCodePoints)) { const old = before.get(name) ?? null; const fresh = after.get(name) ?? null; if (old?.oid === fresh?.oid && old?.mode === fresh?.mode) continue; rows.push({ path: entryPath(location, name), name, old, new: fresh, side: first + index }); } }); return rows; } /** * The comparisons again, holding only the rows the session sees. A * comparison whose every row was dropped comes back empty, which the formats * read as "does not differ". */ export function shownSides(shown, count) { const sides = Array.from({ length: count }, () => [new Map(), new Map()]); for (const row of shown) { const side = sides[row.side]; if (side === undefined) continue; if (row.old !== null) side[0].set(row.name, row.old); if (row.new !== null) side[1].set(row.name, row.new); } return sides; } /** A listing's lines, those the session sees, in order. */ export function printed(shown) { const text = shown.map((row) => row.text).join(''); return Promise.resolve(text === '' ? null : encodeText(text)); } //# sourceMappingURL=rows.js.map