ad2a851b94
Add exact recursive source checkout, independent Git/jj developer workbenches and source-only backup/recovery commands, with Workspace instance binding outside source. Qualify two empty Reader Graphs, packaged source commands, Agent VM compilation, exact Gitea read grants and reconciled Reader settings/annotation stability. Publish checked Reader Package/root revisions to canonical review branches and retention tags, retain all 57 repositories independently in private versioned storage, verify downloaded-backup recovery and advance the example pin. Add bounded Central pin acquisition and selection-specific read-only identities, qualified against all 57 canonical repositories without write authority. Replace regex fork dependency discovery with compiler-parsed lock imports and rewrite proposals; preserve source identities and unrelated files, passing instance binding through packed and ordinary host checks. Hosted run-pin versus authoring preparation and maintained duplicate removal remain pending. Live source selections, Template defaults and default source branches are unchanged.
49 lines
2.5 KiB
TypeScript
49 lines
2.5 KiB
TypeScript
import { readFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { loadQuixosLock, parseQuixosLockDocument, resolveQuixosLock } from "../resource-lock/index.js";
|
|
import { editStructure } from "./structural-edits.js";
|
|
import { workspaceSourcePin, type WorkspaceSourcePin } from "./source-closure.js";
|
|
|
|
/** Inspect/rewrite the root and its declared imports only, using the same lock
|
|
* grammar as compilation. Return proposed file contents; publishing them and
|
|
* selecting a Graph remain the caller's separate responsibilities. */
|
|
export async function workspaceSourceLocks(directory: string, input: unknown = []) {
|
|
if (!Array.isArray(input) || input.length > 256) throw Error("Invalid source lock replacements");
|
|
const replacements = new Map<string, WorkspaceSourcePin>();
|
|
const key = (source: WorkspaceSourcePin) => `${source.repository}\0${source.commit}`;
|
|
for (const entry of input) {
|
|
if (!entry || typeof entry !== "object") throw Error("Invalid source lock replacement");
|
|
const from = workspaceSourcePin(entry.from),
|
|
to = workspaceSourcePin(entry.to);
|
|
if (replacements.has(key(from))) throw Error("Duplicate source lock replacement");
|
|
replacements.set(key(from), to);
|
|
}
|
|
const lock = await loadQuixosLock(path.join(directory, "quixos.lock"));
|
|
if (!lock.ok) throw Error(`Invalid source lock: ${lock.diagnostics.map((d) => d.message).join("; ")}`);
|
|
const files = new Map<string, string>();
|
|
for (const filename of lock.lock.sourceFiles!) {
|
|
let source = await readFile(path.join(directory, filename), "utf8");
|
|
const parsed = parseQuixosLockDocument(source, filename);
|
|
if (!parsed.ok) throw Error("Source lock changed during inspection");
|
|
for (const dependency of parsed.document.resources) {
|
|
const replacement = replacements.get(key(dependency.source));
|
|
if (replacement)
|
|
source = editStructure(source, {
|
|
operation: "dependency",
|
|
kind: dependency.kind,
|
|
name: dependency.binding,
|
|
source: replacement,
|
|
});
|
|
}
|
|
files.set(filename, source);
|
|
}
|
|
const checked = await resolveQuixosLock(files.get("quixos.lock")!, async (filename) => {
|
|
const source = files.get(filename);
|
|
if (source === undefined) throw Error("Source lock import changed during inspection");
|
|
return source;
|
|
});
|
|
if (!checked.ok)
|
|
throw Error(`Invalid rewritten source locks: ${checked.diagnostics.map((d) => d.message).join("; ")}`);
|
|
return { lock: checked.lock, files: [...files].map(([path, source]) => ({ path, source })) };
|
|
}
|