cursor-delegate-mcp 1.13.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cursor-delegate-mcp",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
4
4
  "type": "module",
5
5
  "description": "MCP server bridging AI coding hosts to cursor-agent over the Agent Client Protocol (ACP).",
6
6
  "license": "MIT",
@@ -44,10 +44,15 @@
44
44
  "scripts": {
45
45
  "test": "node --test test/*.test.js",
46
46
  "test:pack": "node test/npm-package-smoke.mjs",
47
- "start": "node src/server.js"
47
+ "start": "node src/server.js",
48
+ "typecheck": "tsc -p tsconfig.json"
48
49
  },
49
50
  "dependencies": {
50
51
  "@modelcontextprotocol/sdk": "^1.22.0",
51
52
  "zod": "^3.23.8"
53
+ },
54
+ "devDependencies": {
55
+ "@types/node": "^26.1.1",
56
+ "typescript": "^7.0.2"
52
57
  }
53
58
  }
package/src/acp-client.js CHANGED
@@ -1,40 +1,76 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { EventEmitter } from "node:events";
3
+ import { StringDecoder } from "node:string_decoder";
3
4
  import { JsonRpcPeer } from "./jsonrpc.js";
4
5
  import { createRequestRouter } from "./request-router.js";
5
6
  import { resolveAcpSpawn } from "./spawn.js";
6
7
  import { isChildAlive, treeKill } from "./proc.js";
7
8
  import { VERSION } from "./version.js";
9
+ import { makeError } from "./errors.js";
8
10
 
9
11
  const STDERR_CAP = 64 * 1024;
10
12
 
11
13
  export class AcpClient extends EventEmitter {
14
+ /**
15
+ * @param {{
16
+ * spawnSpec?: { command: string, args: string[], options?: object },
17
+ * mode?: string,
18
+ * onCreatePlan?: (body: any) => void,
19
+ * onTodos?: (body: any) => void,
20
+ * }} [opts]
21
+ */
12
22
  constructor({ spawnSpec, mode, onCreatePlan, onTodos } = {}) {
13
23
  super();
14
24
  this.spawnSpec = spawnSpec || resolveAcpSpawn();
15
25
  this.mode = mode;
16
26
  this.onCreatePlan = onCreatePlan;
17
27
  this.onTodos = onTodos;
28
+ this._stderrChunks = [];
29
+ this._stderrLength = 0;
30
+ }
31
+
32
+ // The tail of stderr, which is what an exit error quotes. Kept as chunks and joined on read:
33
+ // rebuilding a 64KB string per chunk was the whole cost of a noisy agent. A StringDecoder
34
+ // holds partial UTF-8 across chunk boundaries, so a multi-byte character split by the pipe
35
+ // does not land in the error message as a replacement char.
36
+ get stderrBuffer() {
37
+ const joined = this._stderrChunks.join("");
38
+ return joined.length > STDERR_CAP ? joined.slice(-STDERR_CAP) : joined;
18
39
  }
19
40
 
20
41
  start() {
21
42
  const { command, args, options } = this.spawnSpec;
22
- this.stderrBuffer = "";
43
+ this._stderrChunks = [];
44
+ this._stderrLength = 0;
45
+ const stderrDecoder = new StringDecoder("utf8");
23
46
  this._exitEmitted = false;
24
47
  this.child = spawn(command, args, { ...options, stdio: ["pipe", "pipe", "pipe"] });
25
48
  this.child.stderr.on("data", (chunk) => {
26
- this.stderrBuffer = (this.stderrBuffer + chunk.toString()).slice(-STDERR_CAP);
49
+ const text = stderrDecoder.write(chunk);
50
+ if (text) {
51
+ this._stderrChunks.push(text);
52
+ this._stderrLength += text.length;
53
+ // Drop whole chunks from the front only once well past the cap, so the common case
54
+ // costs one push. The joined tail is trimmed exactly on read.
55
+ while (this._stderrChunks.length > 1 && this._stderrLength - this._stderrChunks[0].length >= STDERR_CAP) {
56
+ this._stderrLength -= this._stderrChunks.shift().length;
57
+ }
58
+ }
27
59
  this.emit("activity");
28
60
  });
29
61
  this.child.stderr.on("error", () => {});
62
+ // A supervisor trip writes session/cancel, which can land after the agent is already gone.
63
+ // Without a handler that surfaces as an unhandled 'error' event on some platforms, taking
64
+ // the whole MCP server down with it.
65
+ this.child.stdin.on("error", () => {});
30
66
  const emitExit = (code, signal) => {
31
67
  if (this._exitEmitted) return;
32
68
  this._exitEmitted = true;
33
69
  const stderr = this.stderrBuffer;
34
- const err = new Error(
70
+ const err = makeError(
71
+ "agent-exit",
35
72
  `agent exited (code=${code}${signal ? ", signal=" + signal : ""})${stderr ? ": " + String(stderr).slice(-2000) : ""}`
36
73
  );
37
- err.reason = "agent-exit";
38
74
  // exit + rejectAllPending both settle the same Promise.race; second rejection is intentional.
39
75
  this.peer?.rejectAllPending(err);
40
76
  this.emit("exit", { code, signal, stderr });
@@ -44,7 +80,7 @@ export class AcpClient extends EventEmitter {
44
80
  this.router = null; // set before first stdout line
45
81
  this.peer = new JsonRpcPeer(this.child.stdout, this.child.stdin, {
46
82
  onNotification: (method, params) => { if (method === "session/update") this.emit("update", params); },
47
- onRequest: (id, method, params) => this.router && this.router(id, method, params),
83
+ onRequest: (id, method, params) => { if (this.router) this.router(id, method, params); },
48
84
  onActivity: () => this.emit("activity"),
49
85
  });
50
86
  this.router = createRequestRouter({
@@ -55,16 +91,15 @@ export class AcpClient extends EventEmitter {
55
91
  mode: this.mode,
56
92
  log: (e) => this.emit("ack", e),
57
93
  });
58
- return new Promise((resolve, reject) => {
94
+ return /** @type {Promise<void>} */ (new Promise((resolve, reject) => {
59
95
  this.child.once("error", (e) => {
60
96
  // Tagged like every other failure class so the caller gets
61
97
  // "delegate failed [spawn-failed]: ..." instead of the one untagged prose error.
62
- const err = new Error(`Failed to spawn agent (${command}): ${e.message}. Install Cursor CLI and run 'cursor-agent login'.`);
63
- err.reason = "spawn-failed";
98
+ const err = makeError("spawn-failed", `Failed to spawn agent (${command}): ${e.message}. Install Cursor CLI and run 'cursor-agent login'.`);
64
99
  reject(err);
65
100
  });
66
101
  this.child.once("spawn", () => resolve());
67
- });
102
+ }));
68
103
  }
69
104
 
70
105
  // Stashed so the unknown-model pre-flight and doctor --deep can read the agent's real
@@ -0,0 +1,15 @@
1
+ // The value sets ACP allows for plan and todo fields. They live here because two layers read
2
+ // them: the sanitizers in delegate.js, which strip anything else off an agent frame, and the
3
+ // zod schemas in server.js, which advertise them to hosts. Kept in four hand-synced copies
4
+ // before, where a drift would have meant stripping a value the tool documents, or documenting
5
+ // one it strips.
6
+ //
7
+ // Plan status and todo status happen to carry the same three values today. They stay separate
8
+ // constants because ACP treats them as separate enums, and collapsing them would silently
9
+ // couple two things that are free to diverge.
10
+
11
+ export const PLAN_PRIORITIES = /** @type {const} */ (["high", "medium", "low"]);
12
+
13
+ export const PLAN_STATUSES = /** @type {const} */ (["pending", "in_progress", "completed"]);
14
+
15
+ export const TODO_STATUSES = /** @type {const} */ (["pending", "in_progress", "completed"]);