perf(web): add idempotent batch verification fast paths
This commit is contained in:
@@ -22,6 +22,19 @@ const json = (file) => JSON.parse(read(file));
|
||||
const relative = (file) => path.relative(root, file).replaceAll(path.sep, "/");
|
||||
const tokenEstimate = (value) => Math.ceil(Buffer.byteLength(value, "utf8") / 4);
|
||||
|
||||
function inputMetadata(file, includeHash = true) {
|
||||
const relativePath = relative(file);
|
||||
let stat;
|
||||
try {
|
||||
stat = fs.statSync(file, { bigint: true });
|
||||
} catch (error) {
|
||||
return { path: relativePath, exists: false, bytes: null, mtime_ns: null, sha256: null, error: error?.code ?? "STAT_FAILED" };
|
||||
}
|
||||
const metadata = { path: relativePath, exists: true, bytes: Number(stat.size), mtime_ns: stat.mtimeNs.toString() };
|
||||
if (includeHash) metadata.sha256 = sha256File(file);
|
||||
return metadata;
|
||||
}
|
||||
|
||||
const queuePath = path.join(root, "docs/EXECUTION_QUEUE.md");
|
||||
const planPath = path.join(root, "tests/golden/M15-03A/next-task-plan.json");
|
||||
const legacyTaskIndexPath = path.join(root, "tests/golden/M15-03A/task-index.json");
|
||||
@@ -367,6 +380,13 @@ export function buildTaskContext(requestedTask) {
|
||||
const ownOutputDir = path.join(root, "tests/golden", task);
|
||||
const generatedPaths = [relative(ownOutputDir), relative(ownManifestPath), relative(ownStatusPath)];
|
||||
const selectedInputs = selectInputPaths(candidatePaths, { sourceBytes, sourceTokens, reservedPaths, generatedPaths });
|
||||
const metadataPaths = [...new Set([
|
||||
relative(queuePath),
|
||||
relative(taskPath),
|
||||
relative(parentManifestPath),
|
||||
...(fs.existsSync(parentStatusPath) ? [relative(parentStatusPath)] : []),
|
||||
...selectedInputs.inputPaths,
|
||||
])].map((candidate) => path.join(root, candidate));
|
||||
const nextTask = ownManifest?.nextTask ?? nextFromPlan(task) ?? null;
|
||||
const context = {
|
||||
schemaVersion: 1,
|
||||
@@ -381,6 +401,7 @@ export function buildTaskContext(requestedTask) {
|
||||
},
|
||||
commands,
|
||||
inputPaths: selectedInputs.inputPaths,
|
||||
inputMetadata: Object.fromEntries(metadataPaths.map((file) => [relative(file), inputMetadata(file)])),
|
||||
inputSelection: selectedInputs.inputSelection,
|
||||
exitCriteria: entry?.exitCriteria ?? ["focused command exits 0", "report and manifest are hash-bound", "failure path does not publish a late result"],
|
||||
nextTask,
|
||||
|
||||
Reference in New Issue
Block a user