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
+42
View File
@@ -0,0 +1,42 @@
import type { McpServer } from "@modelcontextprotocol/server";
import { SESSION_TOOL_CONTRACTS } from "../contracts/toolContracts.js";
import {
replayMachineRunInputSchema,
runReplayMachine,
} from "../domain/replayMachineRun.js";
import { ok } from "../domain/result.js";
import type { Logger } from "../logger.js";
import { safeParseToolInput } from "./toolInputValidation.js";
import { logToolExecution } from "./toolLogging.js";
import { toCallToolResult } from "./toolResult.js";
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
const contract = SESSION_TOOL_CONTRACTS.find(
({ name }) => name === "run_replay_machine",
);
if (contract === undefined)
throw new TypeError("Missing run_replay_machine tool contract");
/** Register direct execution-free finite replay-machine evaluation. */
export const registerReplayMachineTool = (
server: McpServer,
logger: Logger,
): void => {
server.registerTool(
contract.name,
toolRegistrationOptions(contract),
async (input) => {
const parsed = safeParseToolInput(
replayMachineRunInputSchema,
input,
contract.name,
);
if (!parsed.ok) return toCallToolResult(parsed, contract);
const result = await logToolExecution(logger, contract.name, () =>
Promise.resolve(ok(runReplayMachine(parsed.value))),
);
return toCallToolResult(result, contract);
},
);
};