refactor(cli): project reconstruction and source-to-bundle documents from their contracts (#10697)

* refactor(cli): project reconstruction ledger and coverage commands from their contracts

* refactor(cli): project compare-source-to-bundle from its contract and refuse omitted document fields

* fix(cli): advertise caller paths in JSON documents as the CLI admits them

* fix(cli): advertise that JSON document caller paths exclude URLs

* refactor(cli): narrow omitted document field refusal to object documents

* test(cli): give the coverage document fixture the current evidence_format
This commit is contained in:
morluto authored and GitHub committed 2026-11-15 19:40:22 +08:00
1 parent fd2eabb12a
commit 9be6a96fd6
12 files changed
+456 -182

No files matched your search

+56 -49
View File
@@ -1,63 +1,70 @@
import { z } from "incur";
import type { Logger } from "pino";
import type { CliInstance } from "./types.js";
import { CLI_COMMANDS } from "../cliCommandNames.js";
import { parseCliJsonInput } from "../cliJsonInput.js";
import { logCliCommand } from "../cliLogging.js";
import { compareSourceToBundleCliInputSchema } from "../contracts/javascript/applicationWorkflowInputContracts.js";
import { getEvidenceInputContract } from "../domain/evidenceInputContract.js";
import { withCommandCancellation } from "./commandCancellation.js";
import { jsonInputArgument } from "./jsonInputArgument.js";
import { APPLICATION_TOOL_CONTRACTS } from "../contracts/applicationToolContracts.js";
import { contractNamed } from "./contractCliDescription.js";
import { registerContractDocumentCommand } from "./contractCommand.js";
import {
evidenceBundleOption,
runEvidenceInputCommand,
} from "./evidenceInputCommand.js";
/** The reference file path exactly as the caller spelled it, if any. */
const spelledReferencePath = (document: unknown): string | undefined => {
if (typeof document !== "object" || document === null) return undefined;
const reference = (document as { readonly reference?: unknown }).reference;
if (typeof reference !== "object" || reference === null) return undefined;
const path = (reference as { readonly path?: unknown }).path;
return typeof path === "string" ? path : undefined;
};
/** CLI file transport delegates graph authentication and comparison to the same owners as MCP. */
export const registerSourceToBundleCommand = (
cli: CliInstance,
logger: Logger,
): void => {
const name = CLI_COMMANDS.compareSourceToBundle;
cli.command(name, {
description:
"Compare historical source (inline graph or reference {kind:file,path}) with authenticated application Evidence. Save the complete JSON to query with inspect-analysis-view.",
args: z.object({
inputJson: jsonInputArgument(
"Inline workflow JSON or JSON file path",
getEvidenceInputContract(compareSourceToBundleCliInputSchema)
.frameSchema,
),
}),
options: z.object({ evidenceBundle: evidenceBundleOption }),
run: ({ args, options }) =>
withCommandCancellation((signal) =>
logCliCommand(logger, name, async () => {
const input = await parseCliJsonInput(args.inputJson, name, signal);
if (!input.ok) return input.error;
const result = await runEvidenceInputCommand(
"compare_source_to_bundle",
options.evidenceBundle,
signal,
async (lookup, resources) => {
const { executeSourceToBundleComparison } =
await import("../application/javascript/JavaScriptApplicationWorkflowService.js");
const compared = await executeSourceToBundleComparison(
input.value,
compareSourceToBundleCliInputSchema,
lookup,
resources,
{ signal },
);
return compared.ok
? { ok: true, value: compared.value.evidence }
: compared;
): void =>
registerContractDocumentCommand(
cli,
logger,
contractNamed(APPLICATION_TOOL_CONTRACTS, "compare_source_to_bundle"),
{
command: CLI_COMMANDS.compareSourceToBundle,
description:
"Compare historical source (inline graph or reference {kind:file,path}) with authenticated application Evidence. Save the complete JSON to query with inspect-analysis-view.",
document: "Inline workflow JSON or JSON file path",
callerPaths: [["reference", "path"]],
omit: {
view: "A one-shot command retains no session Evidence for a selected view; save the complete comparison and query it with inspect-analysis-view",
},
cliOptions: { evidenceBundle: evidenceBundleOption },
},
async (document, { signal, operation, spelled, cliOptions }) => {
const requestedReferencePath = spelledReferencePath(spelled);
const result = await runEvidenceInputCommand(
operation,
cliOptions.evidenceBundle,
signal,
async (lookup, resources) => {
const { executeSourceToBundleComparison } =
await import("../application/javascript/JavaScriptApplicationWorkflowService.js");
const compared = await executeSourceToBundleComparison(
document,
lookup,
resources,
{
signal,
...(requestedReferencePath === undefined
? {}
: { requestedReferencePath }),
},
);
return result.ok
? result.value
: { error: "Application workflow failed", ...result.error };
}),
),
});
};
return compared.ok
? { ok: true, value: compared.value.evidence }
: compared;
},
);
return result.ok
? result.value
: { error: "Application workflow failed", ...result.error };
},
);