refactor(cli): project Go, V8 and delivery inspectors from their contracts (#10576)

Migrate inspect-go-binary, inspect-v8-code-cache, inspect-devicetree and
inspect-native-exports onto the contract command description and delete
their hand-written options and input spreads.

The description gains evidenceDelivery. It adds the shared --detail and
--evidence_output options, and the run context carries the selected
delivery. A contract detail field selects that delivery and is not passed
to the analysis, as the hand-written commands did. Go's cross-field
budget rules stay with the service's contract parse, so standalone
--max-string-literals still returns invalid_request.

The parity guard accepts the declared CLI-only delivery options as the
only options without a contract field.
This commit is contained in:
morluto authored and GitHub committed 2026-11-15 09:14:56 +08:00
1 parent a11a54e797
commit da53dce1f7
7 files changed
+203 -292

No files matched your search

+26 -56
View File
@@ -1,66 +1,36 @@
import { z } from "incur";
import type { Logger } from "pino";
import { localPathStringSchema } from "../domain/localPath.js";
import { absoluteCallerPath } from "../filesystem/callerPath.js";
import { createV8CodeCacheService } from "../composition/v8CodeCache.js";
import { CLI_COMMANDS } from "../cliCommandNames.js";
import { logCliCommand } from "../cliLogging.js";
import { createV8CodeCacheService } from "../composition/v8CodeCache.js";
import { V8_CODE_CACHE_TOOL_CONTRACTS } from "../contracts/v8/v8CodeCacheToolContracts.js";
import { contractNamed } from "./contractCliDescription.js";
import {
inspectWithService,
registerContractCommand,
} from "./contractCommand.js";
import type { CliInstance } from "./types.js";
import { withCommandCancellation } from "./commandCancellation.js";
import { cliDecimalField } from "./options.js";
import { inspectV8CodeCacheInputSchema } from "../domain/v8/v8CodeCache.js";
import { projectCliAnalysisResult } from "./projectCliAnalysisResult.js";
import { finishCliEvidenceCommand } from "./cliEvidenceCallerPath.js";
/** Inspect operator-selected V8 code caches through the same shared workflow as MCP. */
export const registerV8CodeCacheCommands = (
cli: CliInstance,
logger: Logger,
): void => {
cli.command(CLI_COMMANDS.inspectV8CodeCache, {
description:
"Inspect a V8 code cache header and its embedded printable byte patterns without executing it",
args: z.object({
path: localPathStringSchema.describe("Local V8 code cache (.jsc) file"),
}),
options: z.object({
// Decimal tokens only: numeric coercion would read "0x10" as 16 and "1e3" as
// 1000. The shared fields keep their bounds, defaults and help.
maxFileBytes: cliDecimalField(
inspectV8CodeCacheInputSchema.shape.max_file_bytes,
),
maxStrings: cliDecimalField(
inspectV8CodeCacheInputSchema.shape.max_strings,
),
minStringBytes: cliDecimalField(
inspectV8CodeCacheInputSchema.shape.min_string_bytes,
),
}),
run: ({ args, options }) =>
withCommandCancellation(async (signal) => {
const v8CodeCache = createV8CodeCacheService();
return await logCliCommand(
logger,
CLI_COMMANDS.inspectV8CodeCache,
async () =>
finishCliEvidenceCommand(
args.path,
() =>
v8CodeCache.inspect(
{
path: absoluteCallerPath(args.path),
max_file_bytes: options.maxFileBytes,
max_strings: options.maxStrings,
min_string_bytes: options.minStringBytes,
},
{ signal },
),
v8CodeCache,
"rea-v8-code-cache",
"inspect_v8_code_cache",
signal,
).then(projectCliAnalysisResult),
);
}),
});
const contract = contractNamed(
V8_CODE_CACHE_TOOL_CONTRACTS,
"inspect_v8_code_cache",
);
registerContractCommand(
cli,
logger,
contract,
{
command: CLI_COMMANDS.inspectV8CodeCache,
description:
"Inspect a V8 code cache header and its embedded printable byte patterns without executing it",
positionals: ["path"],
callerPaths: ["path"],
fields: { path: { description: "Local V8 code cache (.jsc) file" } },
},
inspectWithService(createV8CodeCacheService, "rea-v8-code-cache"),
);
};