Files
reverse-engineering-anything/src/cli/cutterCommands.ts
T
gensokyo-dev e18594b247 refactor(composition): unify capability bindings and cleanup ownership (#8441)
Bind typed service creation, observed availability and retryable cleanup in one composition owner. Reuse selected CLI/MCP factories and canonical contract groups without copying provider operation inventories.

Closes #8429. Refs #740.

Validated paired real application workflows, actual local Codex CLI Terra/high use, complete Evidence and Unknown checkpoint parity, compiler-backed import boundaries, SDK schemas and final real mixed routing. Automated review findings were fixed at their producing owners. Existing exact-base CodeQL alerts are documented on the PR under the owner-authorized unrelated-check exception; no global alerts or security rules were changed.

Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)
2026-11-01 13:30:21 +08:00

87 lines
2.9 KiB
TypeScript

import { projectCliAnalysisResult } from "./projectCliAnalysisResult.js";
import { z } from "incur";
import type { Logger } from "pino";
import { createCutterBridgeService } from "../composition/cutter.js";
import { CLI_COMMANDS } from "../cliCommandNames.js";
import { logCliCommand } from "../cliLogging.js";
import { finishAnalysisCommand } from "./finishAnalysisCommand.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 createCutter = () => createCutterBridgeService(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 cutter = createCutter();
return finishAnalysisCommand(
() => cutter.listSessions({ signal }),
cutter,
"cutter",
"list_cutter_sessions",
signal,
).then(projectCliAnalysisResult);
}),
),
});
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).",
),
}),
run: ({ args, options }) =>
withCommandCancellation((signal) =>
logCliCommand(logger, CLI_COMMANDS.cutterCommand, async () => {
const cutter = createCutter();
return finishAnalysisCommand(
() =>
cutter.execute(
{
session_id: args.sessionId,
expected_generation: args.expectedGeneration,
command: args.command,
json: options.jsonOutput ?? false,
},
{ signal },
),
cutter,
"cutter",
"cutter_command",
signal,
).then(projectCliAnalysisResult);
}),
),
});
};