feat(process): add direct replay machine runner

This commit is contained in:
morluto
2026-07-23 03:47:46 +08:00
parent d6f2007723
commit 3df9a07413
26 changed files with 1157 additions and 25 deletions
+44
View File
@@ -7,12 +7,20 @@ import {
import { logCliCommand } from "./cliLogging.js";
import type { Logger } from "./logger.js";
import { CLI_COMMANDS } from "./cliCommandNames.js";
import { parseCliJsonInput } from "./cliJsonInput.js";
import {
replayMachineRunInputSchema,
runReplayMachine,
} from "./domain/replayMachineRun.js";
import { AnalysisInputError, projectAnalysisError } from "./domain/errors.js";
import { projectInputIssues } from "./domain/inputIssueProjection.js";
/** Register Process Capture v4 one-shot commands through shared application services. */
export const registerProcessCommands = (
cli: ReturnType<typeof Cli.create>,
logger: Logger,
): void => {
registerReplayMachineCommand(cli, logger);
cli.command(CLI_COMMANDS.captureProcess, {
description: "Capture one approved Process Capture v4 JSON scenario",
args: z.object({ scenario: z.string().describe("Scenario JSON path") }),
@@ -33,3 +41,39 @@ export const registerProcessCommands = (
),
});
};
const registerReplayMachineCommand = (
cli: ReturnType<typeof Cli.create>,
logger: Logger,
): void => {
cli.command(CLI_COMMANDS.runReplayMachine, {
description:
"Run ordered protocol events directly through a finite replay machine",
args: z.object({
inputJson: z.string().describe("Inline replay JSON or JSON file path"),
}),
run: ({ args }) =>
logCliCommand(logger, CLI_COMMANDS.runReplayMachine, async () => {
const input = await parseCliJsonInput(
args.inputJson,
CLI_COMMANDS.runReplayMachine,
);
if (!input.ok) return input.error;
const parsed = replayMachineRunInputSchema.safeParse(input.value);
return parsed.success
? runReplayMachine(parsed.data)
: {
error: "Process command failed",
...projectAnalysisError(
new AnalysisInputError(
CLI_COMMANDS.runReplayMachine,
{
cause: parsed.error,
},
projectInputIssues(parsed.error.issues, input.value),
),
),
};
}),
});
};