mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 13:45:30 +00:00
refactor(cli): project view-delivery inspectors from their contracts (#10600)
* refactor(cli): project view-delivery inspectors from their contracts * refactor(cli): project APK signature, desktop application and EVM inspectors from contracts (#10603)
This commit is contained in:
1 parent
254bb21857
commit
fa53f7070a
15 files changed
+622
-605
No files matched your search
@@ -1,88 +1,40 @@
|
||||
import { z } from "incur";
|
||||
import { localPathStringSchema } from "../domain/localPath.js";
|
||||
import { absoluteCallerPath } from "../filesystem/callerPath.js";
|
||||
import { createPythonPycService } from "../composition/pythonPyc.js";
|
||||
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
||||
import { logCliCommand } from "../cliLogging.js";
|
||||
import type { Logger } from "pino";
|
||||
import type { CliInstance } from "./types.js";
|
||||
import { withCommandCancellation } from "./commandCancellation.js";
|
||||
import { inspectPythonPycInputSchema } from "../domain/python/pythonPyc.js";
|
||||
|
||||
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
||||
import { createPythonPycService } from "../composition/pythonPyc.js";
|
||||
import { PYTHON_PYC_TOOL_CONTRACTS } from "../contracts/python/pythonPycToolContracts.js";
|
||||
import { contractNamed } from "./contractCliDescription.js";
|
||||
import {
|
||||
analysisEvidenceDeliveryOptions,
|
||||
deliverCliAnalysisEvidence,
|
||||
parseCliAnalysisEvidenceDelivery,
|
||||
} from "./analysisEvidenceDelivery.js";
|
||||
import { pythonPycDeliverySchema } from "../domain/analysisView/pythonPycView.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import { cliDecimalField } from "./options.js";
|
||||
deliverWithService,
|
||||
registerContractCommand,
|
||||
} from "./contractCommand.js";
|
||||
import type { CliInstance } from "./types.js";
|
||||
|
||||
/** Inspect operator-selected pyc files through the same shared workflow as MCP. */
|
||||
export const registerPythonPycCommands = (
|
||||
cli: CliInstance,
|
||||
logger: Logger,
|
||||
): void => {
|
||||
cli.command(CLI_COMMANDS.inspectPythonPyc, {
|
||||
description:
|
||||
"Inspect a supported CPython 3.7–3.15 pyc header and marshal code objects without executing bytecode",
|
||||
args: z.object({
|
||||
path: localPathStringSchema.describe("Local CPython .pyc file"),
|
||||
}),
|
||||
options: z.object({
|
||||
// Decimal tokens only: numeric coercion would read "0x10" as 16 and
|
||||
// "1e2" as 100. The shared fields keep their bounds and defaults.
|
||||
maxFileBytes: cliDecimalField(
|
||||
inspectPythonPycInputSchema.shape.max_file_bytes,
|
||||
),
|
||||
maxObjects: cliDecimalField(
|
||||
inspectPythonPycInputSchema.shape.max_objects,
|
||||
),
|
||||
maxDepth: cliDecimalField(inspectPythonPycInputSchema.shape.max_depth),
|
||||
maxStringBytes: cliDecimalField(
|
||||
inspectPythonPycInputSchema.shape.max_string_bytes,
|
||||
),
|
||||
...analysisEvidenceDeliveryOptions,
|
||||
view: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
"JSON python-pyc view; requires --detail summary and --evidence_output",
|
||||
),
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
withCommandCancellation((signal) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.inspectPythonPyc, async () => {
|
||||
const delivery = parseCliAnalysisEvidenceDelivery(
|
||||
"inspect_python_pyc",
|
||||
options,
|
||||
pythonPycDeliverySchema,
|
||||
);
|
||||
if (!delivery.ok) return projectAnalysisError(delivery.error);
|
||||
const service = createPythonPycService();
|
||||
return deliverCliAnalysisEvidence({
|
||||
callerInputPath: args.path,
|
||||
run: () =>
|
||||
service.inspect(
|
||||
{
|
||||
path: absoluteCallerPath(args.path),
|
||||
max_file_bytes: options.maxFileBytes,
|
||||
max_objects: options.maxObjects,
|
||||
max_depth: options.maxDepth,
|
||||
max_string_bytes: options.maxStringBytes,
|
||||
},
|
||||
{ signal },
|
||||
),
|
||||
service,
|
||||
providerId: "rea-python-pyc",
|
||||
operation: "inspect_python_pyc",
|
||||
signal,
|
||||
detail: delivery.value.detail,
|
||||
evidenceOutput: delivery.value.evidenceOutput,
|
||||
...(delivery.value.view === undefined
|
||||
? {}
|
||||
: { view: delivery.value.view }),
|
||||
});
|
||||
}),
|
||||
),
|
||||
});
|
||||
registerContractCommand(
|
||||
cli,
|
||||
logger,
|
||||
contractNamed(PYTHON_PYC_TOOL_CONTRACTS, "inspect_python_pyc"),
|
||||
{
|
||||
command: CLI_COMMANDS.inspectPythonPyc,
|
||||
description:
|
||||
"Inspect a supported CPython 3.7–3.15 pyc header and marshal code objects without executing bytecode",
|
||||
positionals: ["path"],
|
||||
callerPaths: ["path"],
|
||||
evidenceDelivery: true,
|
||||
viewDelivery: { invalidJson: "view must be valid JSON" },
|
||||
fields: {
|
||||
path: { description: "Local CPython .pyc file" },
|
||||
view: {
|
||||
description:
|
||||
"JSON python-pyc view; requires --detail summary and --evidence_output",
|
||||
},
|
||||
},
|
||||
},
|
||||
deliverWithService(createPythonPycService, "rea-python-pyc"),
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user