Files
rea/src/cli/cutterCommands.ts
T
Ysopwnable a6c6a76d37 fix(cutter): cancel discovery probes and queued work
Propagate CLI/MCP cancellation through shared Cutter discovery, stop queued probes, and drain admitted workers. Deliver terminal bridge results only after socket closure. Preserve confirmed command Evidence and caller reasons when cancellation arrives during finalization.

Validated 66 focused tests, full CI static/docs gates, actual CLI SIGINT, compiled stdio cancellation/recovery, and official Linux Cutter 2.5.0 Qt5 CLI/MCP ELF workflows. Native UI cancellation and descriptor filesystem cancellation remain unverified.

Fixes #3946.
2026-10-16 22:49:06 +08:00

80 lines
2.8 KiB
TypeScript

import { z } from "incur";
import type { Logger } from "pino";
import { CutterBridgeClient } from "../cutter/CutterBridgeClient.js";
import { CutterBridgeService } from "../cutter/CutterBridgeService.js";
import { CLI_COMMANDS } from "../cliCommandNames.js";
import { logCliCommand } from "../cliLogging.js";
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
import { withCommandCancellation } from "./commandCancellation.js";
import type { CliInstance } from "./types.js";
import { cliIntegerArgument } from "./options.js";
/** Register commands that control an already-running Cutter instance. */
export const registerCutterCommands = (
cli: CliInstance,
logger: Logger,
environment: Readonly<NodeJS.ProcessEnv>,
): void => {
const cutter = new CutterBridgeService(new CutterBridgeClient(environment));
cli.command(CLI_COMMANDS.listCutterSessions, {
description:
"List live Cutter instances connected through the REA Python plugin bridge",
args: z.object({}),
run: () =>
withCommandCancellation((signal) =>
logCliCommand(logger, CLI_COMMANDS.listCutterSessions, async () => {
const result = await cutter.listSessions({ signal });
return result.ok ? result.value : projectAnalysisError(result.error);
}),
),
});
cli.command(CLI_COMMANDS.cutterCommand, {
description: "Execute one Rizin command in a selected live Cutter instance",
args: z.object({
sessionId: z
.string()
.uuid()
.describe("Session ID copied from list-cutter-sessions."),
expectedGeneration: cliIntegerArgument(0).describe(
"Session generation returned by list-cutter-sessions.",
),
command: z
.string()
.min(1)
.describe("One unrestricted Rizin command to run in Cutter.")
.refine((value) => !/[\r\n]/u.test(value)),
}),
options: z.object({
jsonOutput: z
.boolean()
.optional()
.describe(
"Return command-specific JSON output when available (independent of CLI output formatting).",
),
json: z
.boolean()
.optional()
.describe(
"Deprecated compatibility input: use --json-output; pass --json=true or --json=false (bare --json formats CLI output).",
),
}),
run: ({ args, options }) =>
withCommandCancellation((signal) =>
logCliCommand(logger, CLI_COMMANDS.cutterCommand, async () => {
const result = await cutter.execute(
{
session_id: args.sessionId,
expected_generation: args.expectedGeneration,
command: args.command,
json: options.jsonOutput ?? options.json ?? false,
},
{ signal },
);
return result.ok ? result.value : projectAnalysisError(result.error);
}),
),
});
};