File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,9 +11,10 @@ import * as Effect from "effect/Effect";
1111import { endCuaSession , ensureCuaMcpProxy } from "./CuaMcpProxy.ts" ;
1212
1313// Stands in for `cua-driver mcp`: answers `initialize`, reports its pid and
14- // whether the handshake finished, and never answers "hang".
14+ // whether the handshake finished, and answers "hang" only as it is stopped .
1515const FAKE_DRIVER = `
1616let initialized = false;
17+ let hanging = null;
1718let input = "";
1819const reply = (message) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\\n");
1920process.stdin.on("data", (chunk) => {
@@ -24,11 +25,16 @@ process.stdin.on("data", (chunk) => {
2425 const message = JSON.parse(line);
2526 if (message.method === "initialize") reply({ id: message.id, result: { protocolVersion: "2025-06-18" } });
2627 if (message.method === "notifications/initialized") initialized = true;
28+ if (message.method === "tools/call" && message.params.name === "hang") hanging = message.id;
2729 if (message.method === "tools/call" && message.params.name === "whoami") {
2830 reply({ id: message.id, result: { pid: process.pid, initialized } });
2931 }
3032 }
3133});
34+ process.on("SIGTERM", () => {
35+ if (hanging !== null) reply({ id: hanging, result: { late: true } });
36+ process.exit(0);
37+ });
3238` ;
3339
3440const temporaryDirs : Array < string > = [ ] ;
Original file line number Diff line number Diff line change @@ -66,6 +66,8 @@ function start() {
6666 let buffer = "";
6767 current.stdin.on("error", () => {});
6868 current.stdout.on("data", (chunk) => {
69+ // A replaced driver can still flush output; its calls were already failed.
70+ if (child !== current) return;
6971 buffer += chunk;
7072 const lines = buffer.split("\\n");
7173 buffer = lines.pop();
You can’t perform that action at this time.
0 commit comments