feat: add persistent cross-version investigation workspaces

This commit is contained in:
N0zoM1z0
2026-07-13 19:37:54 +08:00
parent d0e21f9231
commit 41366edd56
113 changed files with 3828 additions and 371 deletions
+45
View File
@@ -0,0 +1,45 @@
import { execFile } from "node:child_process";
import { readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { promisify } from "node:util";
import { TextReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
const exec = promisify(execFile);
/** Verify the packed CLI's persistent investigation and idempotent reuse. */
export async function verifyPackagedInvestigation(input) {
const artifactArchiveV2 = join(input.workspace, "artifact-v2.zip");
const writer = new ZipWriter(new Uint8ArrayWriter());
await writer.add("app/main.js", new TextReader("main(2);"));
await writer.add("app/new.js", new TextReader("feature();"));
await writeFile(artifactArchiveV2, await writer.close());
const workspacePath = join(input.evidenceRoot, "versions.json");
const args = [
"investigate-versions",
input.artifactArchive,
artifactArchiveV2,
workspacePath,
"--workspace-name",
"package-versions",
"--yes",
"--json",
];
const investigated = await runJson(input.cli, args, input.environment);
const reused = await runJson(input.cli, args, input.environment);
const persisted = JSON.parse(await readFile(workspacePath, "utf8"));
if (
investigated.operation !== "find_changed_behavior" ||
investigated.normalized_result?.behavior_status !== "unknown" ||
investigated.normalized_result?.investigation_run?.run_id === undefined ||
reused.evidence_id !== investigated.evidence_id ||
persisted.revision !== 3 ||
persisted.runs?.[0]?.status !== "complete"
)
throw new Error("packaged persistent investigation CLI failed");
}
async function runJson(command, args, environment) {
const output = await exec(command, args, { env: environment });
return JSON.parse(output.stdout);
}
+4
View File
@@ -15,6 +15,7 @@ import { Client } from "@modelcontextprotocol/client";
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
import { TextReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
import { TOOL_CONTRACTS } from "../dist/contracts/toolContracts.js";
import { verifyPackagedInvestigation } from "./verify-package-investigation.mjs";
const expectedToolCount = TOOL_CONTRACTS.length;
@@ -122,6 +123,7 @@ try {
!help.includes("upgrade") ||
!help.includes("inventory-artifact") ||
!help.includes("extract-artifact") ||
!help.includes("investigate-versions") ||
!help.includes("import-reference-source") ||
!help.includes("compare") ||
!llms.includes("decompile") ||
@@ -156,6 +158,8 @@ try {
artifactInventory.normalized_result?.manifest?.root_format !== "zip"
)
throw new Error("packaged artifact inventory CLI failed");
// prettier-ignore
await verifyPackagedInvestigation({ cli, workspace, evidenceRoot, artifactArchive, environment });
const overview = json(
await run(cli, ["analyze", process.execPath, "--json"], environment),
);