cursor-delegate-mcp 2.9.0 → 2.10.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/src/doctor.js CHANGED
@@ -1,14 +1,17 @@
1
1
  import process from "node:process";
2
2
  import { spawn } from "node:child_process";
3
+ import { existsSync } from "node:fs";
3
4
  import { AcpClient } from "./acp-client.js";
4
- import { commandExists, resolveAcpSpawn } from "./spawn.js";
5
- import { DETACHED, treeKill } from "./proc.js";
5
+ import { commandExists, resolveAcpSpawn, spawnArgv } from "./spawn.js";
6
+ import { DETACHED, isChildAlive, treeKill } from "./proc.js";
6
7
  import { readPackageVersion } from "./version.js";
7
8
  import { describeOptions } from "./model-options.js";
8
9
 
9
10
  const HANDSHAKE_TIMEOUT_MS = 15_000;
10
11
  const VERSION_PROBE_TIMEOUT_MS = 10_000;
11
12
  const PROBE_STDOUT_CAP = 64 * 1024;
13
+ // How long an aborted probe waits for its kill and close, as stop() bounds an agent's.
14
+ const PROBE_KILL_WAIT_MS = 2000;
12
15
  const DEFAULT_LOG_SIZE = "2000";
13
16
 
14
17
  function formatArg(value) {
@@ -31,40 +34,68 @@ function envReport(name, fallback = null) {
31
34
  return process.env[name] !== undefined ? process.env[name] : fallback;
32
35
  }
33
36
 
34
- // Time-boxed because a launcher that accepts --version and then never answers would hang doctor
35
- // forever — and doctor is what you run when delegation is already broken, so a wedged agent is
36
- // exactly the case it must survive. Same guard the deep handshake has.
37
- export function probeAgentVersion(spawnSpec, timeoutMs = VERSION_PROBE_TIMEOUT_MS) {
38
- const { command, options } = spawnSpec;
37
+ // Time-boxed, like the deep handshake: doctor runs when delegation is already broken, and a
38
+ // launcher that never answers must not hang it.
39
+ /**
40
+ * @param {{ command: string, args: string[], options?: any }} spawnSpec
41
+ * @param {number} [timeoutMs]
42
+ * @param {{ signal?: AbortSignal, onSpawn?: (probe: { pid: number | undefined, stop: () => Promise<void> }) => void }} [opts]
43
+ */
44
+ export function probeAgentVersion(spawnSpec, timeoutMs = VERSION_PROBE_TIMEOUT_MS, { signal, onSpawn } = {}) {
45
+ const { command, args, options } = spawnSpec;
39
46
  const launcher = String(command || "").replace(/^["']|["']$/g, "");
40
47
  const isJsScript = isJsLauncher(launcher);
41
48
  const execCommand = isJsScript ? process.execPath : command;
42
- const execArgs = isJsScript ? [launcher, "--version"] : ["--version"];
49
+ // --version replaces the acp subcommand, so a launcher prefix ("node index.js acp") still
50
+ // reaches the agent. With no acp token, --version goes alone.
51
+ const acpAt = Array.isArray(args) ? args.indexOf("acp") : -1;
52
+ const versionArgs = [...(acpAt > 0 ? args.slice(0, acpAt) : []), "--version"];
53
+ const execArgs = isJsScript ? [launcher, ...versionArgs] : versionArgs;
43
54
  // Through a shell, a missing launcher still spawns (the shell does) and would read as found.
44
55
  if (options?.shell && !isJsScript && !commandExists(launcher, options.env)) return Promise.resolve({ found: false, version: null });
56
+ const aborted = { version: null, error: "version probe aborted by MCP host" };
57
+ // Interrupted already: nothing is spawned, and found comes from the lookup alone.
58
+ if (signal?.aborted) {
59
+ return Promise.resolve({ found: isJsScript ? existsSync(launcher) : commandExists(launcher, options?.env), ...aborted });
60
+ }
45
61
  return new Promise((resolve) => {
46
62
  let settled = false;
63
+ let aborting = false;
47
64
  let stdout = "";
48
65
  let timer;
49
66
  const finish = (result) => {
50
67
  if (settled) return;
51
68
  settled = true;
52
69
  clearTimeout(timer);
70
+ signal?.removeEventListener("abort", onAbort);
53
71
  resolve(result);
54
72
  };
55
- const child = spawn(execCommand, execArgs, { ...options, detached: DETACHED, stdio: ["ignore", "pipe", "pipe"] });
56
- // Capped: a version string is a line, and a launcher that streams instead should not be
57
- // accumulated whole while the probe waits out its timeout.
73
+ const argv = spawnArgv(execCommand, execArgs, options);
74
+ const child = spawn(argv.command, argv.args, { ...argv.options, detached: DETACHED, stdio: ["ignore", "pipe", "pipe"] });
75
+ // treeKill: on win32 a plain kill reaches only the wrapper, not the launcher.
76
+ const stop = () => (child.pid ? treeKill(child.pid, { childAlive: isChildAlive(child) }).catch(() => {}) : Promise.resolve());
77
+ onSpawn?.({ pid: child.pid, stop });
78
+ const closed = new Promise((r) => child.once("close", r));
79
+ // Settles once the probe has closed, so doctor does not return with it running.
80
+ const onAbort = () => {
81
+ // Else it fires during the kill and reports a timeout.
82
+ clearTimeout(timer);
83
+ aborting = true;
84
+ const bound = new Promise((r) => { setTimeout(r, PROBE_KILL_WAIT_MS).unref?.(); });
85
+ Promise.race([Promise.all([stop(), closed]), bound]).then(() => finish({ found: true, ...aborted }));
86
+ };
87
+ signal?.addEventListener("abort", onAbort, { once: true });
88
+ // Capped: a version is one line, and a launcher that streams is not kept whole.
58
89
  child.stdout?.on("data", (chunk) => {
59
90
  if (stdout.length < PROBE_STDOUT_CAP) stdout += chunk.toString();
60
91
  });
61
- // Drained, not merely piped. An unread pipe fills, the launcher blocks writing to it and so
62
- // never exits, and the probe can only report that as a timeout — a healthy but noisy
63
- // launcher reads out identically to a wedged one. Nothing consumes the bytes.
92
+ // Drained: a full stderr pipe blocks the launcher, and a noisy one would read as wedged.
64
93
  child.stderr?.on("data", () => {});
65
94
  child.stderr?.on("error", () => {});
66
95
  child.on("error", () => finish({ found: false, version: null }));
67
96
  child.on("close", (code) => {
97
+ // An aborted probe reports the abort, not the exit its kill caused.
98
+ if (aborting) return;
68
99
  const version = code === 0 ? stdout.trim() || null : null;
69
100
  finish({
70
101
  found: true,
@@ -73,21 +104,22 @@ export function probeAgentVersion(spawnSpec, timeoutMs = VERSION_PROBE_TIMEOUT_M
73
104
  });
74
105
  });
75
106
  timer = setTimeout(() => {
76
- // treeKill, not child.kill: the spawn spec carries shell:true on win32, where a plain
77
- // kill only reaches the wrapper and leaves the launcher running.
78
- if (child.pid) treeKill(child.pid).catch(() => {});
79
- // The launcher exists — it spawned — it just never answered, which is a different
80
- // diagnosis from "not installed" and has to read that way.
107
+ stop();
108
+ // It spawned, so it is found; it just never answered.
81
109
  finish({ found: true, version: null, error: `version probe timed out after ${timeoutMs}ms` });
82
110
  }, timeoutMs);
83
111
  timer.unref?.();
84
112
  });
85
113
  }
86
114
 
87
- async function runDeepHandshake({ spawnSpec, clientFactory, workspace, timeoutMs }) {
115
+ async function runDeepHandshake({ spawnSpec, clientFactory, workspace, timeoutMs, signal, onClientReady }) {
116
+ if (signal?.aborted) return { ok: false, error: "Handshake aborted by MCP host" };
88
117
  const client = clientFactory({ spawnSpec });
118
+ // Handed out before the spawn, so a server shutdown can stop it.
119
+ onClientReady?.(client);
89
120
  const workspaceDir = workspace || process.cwd();
90
121
  let timer;
122
+ let onAbort;
91
123
  try {
92
124
  const details = {};
93
125
  const work = (async () => {
@@ -99,32 +131,39 @@ async function runDeepHandshake({ spawnSpec, clientFactory, workspace, timeoutMs
99
131
  details.models = (client.sessionModels?.availableModels ?? []).map((m) => m?.modelId).filter(Boolean);
100
132
  details.currentModel = client.sessionModels?.currentModelId ?? null;
101
133
  details.modes = (client.sessionModes?.availableModes ?? []).map((m) => m?.id).filter(Boolean);
102
- // session/new already returned these. currentModel only — any other model needs a set_model
103
- // first, which this handshake does not send. name and category are what tell an effort
104
- // option apart when its id is unfamiliar; currentValue is the level saved for the model.
134
+ // From session/new, for the current model only (another needs a set_model). name and
135
+ // category identify an unfamiliar effort option; currentValue is the model's saved level.
105
136
  details.currentModelOptions = describeOptions(client.configOptions);
106
137
  })();
107
138
  const timeout = new Promise((_, reject) => {
108
139
  timer = setTimeout(() => {
109
- // Not awaited, so the timeout still rejects at its stated deadline rather than at the
110
- // deadline plus teardown. The finally below awaits the same idempotent promise.
140
+ // Not awaited, so the timeout rejects on its deadline; the finally awaits the same stop.
111
141
  try { Promise.resolve(client.stop()).catch(() => {}); } catch {}
112
142
  reject(new Error(`Handshake timed out after ${timeoutMs}ms`));
113
143
  }, timeoutMs);
114
144
  });
115
- await Promise.race([work, timeout]);
145
+ const aborted = new Promise((_, reject) => {
146
+ onAbort = () => {
147
+ try { Promise.resolve(client.stop()).catch(() => {}); } catch {}
148
+ reject(new Error("Handshake aborted by MCP host"));
149
+ };
150
+ if (signal?.aborted) onAbort();
151
+ else signal?.addEventListener("abort", onAbort, { once: true });
152
+ });
153
+ await Promise.race([work, timeout, aborted]);
116
154
  return { ok: true, ...details };
117
155
  } catch (err) {
118
156
  return { ok: false, error: err?.message || String(err) };
119
157
  } finally {
120
158
  clearTimeout(timer);
121
- // Awaited so doctor does not return while the agent it spawned is still being torn down.
122
- // A killed child exits in milliseconds; only one that ignores the kill costs the full bound.
159
+ if (onAbort) signal?.removeEventListener("abort", onAbort);
160
+ // Awaited so doctor does not return with its agent still alive; a killed child exits in ms.
123
161
  try { await Promise.resolve(client.stop()); } catch {}
124
162
  }
125
163
  }
126
164
 
127
165
  /**
166
+ * onClientReady gets each process doctor starts, probe then agent, so a shutdown can stop it.
128
167
  * @param {{
129
168
  * getClientInfo?: () => { capabilities?: any, version?: any },
130
169
  * deep?: boolean,
@@ -134,6 +173,8 @@ async function runDeepHandshake({ spawnSpec, clientFactory, workspace, timeoutMs
134
173
  * handshakeTimeoutMs?: number,
135
174
  * versionTimeoutMs?: number,
136
175
  * readVersion?: () => string,
176
+ * signal?: AbortSignal,
177
+ * onClientReady?: (client: { stop: () => any }) => void,
137
178
  * }} [opts]
138
179
  */
139
180
  export async function runDoctor({
@@ -145,9 +186,11 @@ export async function runDoctor({
145
186
  handshakeTimeoutMs = HANDSHAKE_TIMEOUT_MS,
146
187
  versionTimeoutMs = VERSION_PROBE_TIMEOUT_MS,
147
188
  readVersion = readPackageVersion,
189
+ signal,
190
+ onClientReady,
148
191
  } = {}) {
149
192
  const { capabilities, version } = getClientInfo();
150
- const agentProbe = await probeAgentVersion(spawnSpec, versionTimeoutMs);
193
+ const agentProbe = await probeAgentVersion(spawnSpec, versionTimeoutMs, { signal, onSpawn: onClientReady });
151
194
 
152
195
  /** @type {{ plugin: any, client: any, agent: any & { handshake?: any }, runtime: any, env: any }} */
153
196
  const out = {
@@ -187,6 +230,8 @@ export async function runDoctor({
187
230
  clientFactory,
188
231
  workspace,
189
232
  timeoutMs: handshakeTimeoutMs,
233
+ signal,
234
+ onClientReady,
190
235
  });
191
236
  }
192
237
 
package/src/errors.js CHANGED
@@ -1,8 +1,6 @@
1
1
  /**
2
- * Every failure this bridge raises carries a `reason`, which is what lets a caller tell
3
- * "fix your arguments" from "retry" without parsing prose. Errors that came off the wire also
4
- * carry the agent's JSON-RPC `code`. One shape, one constructor, so the tag is never forgotten
5
- * and the type checker has something to check against.
2
+ * Every failure carries a `reason`, so a caller can tell "fix your arguments" from "retry"
3
+ * without parsing prose. Errors off the wire also carry the agent's JSON-RPC `code`.
6
4
  *
7
5
  * @typedef {Error & { reason?: string, code?: number }} DelegateError
8
6
  */
package/src/jsonrpc.js CHANGED
@@ -10,16 +10,12 @@ function readLogSize(raw) {
10
10
  return Math.floor(n);
11
11
  }
12
12
 
13
- // Depth an unparseable CURSOR_DELEGATE_TRANSCRIPT reads as. Deliberately not DEFAULT_LOG_SIZE:
14
- // that one bounds what the log retains in memory, this one is how much lands in the caller's
15
- // context. 1.10.0 removed a 40-frame always-on dump from failure text; opt-in is what buys this
16
- // budget, so keep it in that neighbourhood.
13
+ // Depth for an unparseable CURSOR_DELEGATE_TRANSCRIPT. Not DEFAULT_LOG_SIZE: that bounds memory,
14
+ // this bounds what lands in the caller's context, so keep it near the old 40-frame dump.
17
15
  const TRANSCRIPT_DEFAULT_FRAMES = 50;
18
16
 
19
- // Frames of transcript CURSOR_DELEGATE_TRANSCRIPT asks for. Unset or blank means none and a
20
- // number is the count (0 = none); anything unparseable reads as on at the default depth —
21
- // "true" and "yes" are natural things to set, and silently disabling the transcript on them is
22
- // the opposite of what the setter wanted.
17
+ // Frames CURSOR_DELEGATE_TRANSCRIPT asks for: unset or blank is none, a number is the count
18
+ // (0 = none), anything else ("true", "yes") is on at the default depth.
23
19
  export function transcriptFrames(raw = process.env.CURSOR_DELEGATE_TRANSCRIPT) {
24
20
  if (raw === undefined || raw.trim() === "") return 0;
25
21
  const n = Number(raw);
@@ -44,25 +40,20 @@ export class JsonRpcPeer {
44
40
  this.onActivity = onActivity || (() => {});
45
41
  this.nextId = 1;
46
42
  this.pending = new Map();
47
- // 0 disables recording and is documented; anything unparseable is a typo, and silently
48
- // disabling the transcript on a typo is the opposite of what the setter wanted.
43
+ // 0 disables recording; an unparseable value is a typo and keeps the default.
49
44
  this._logSize = readLogSize(process.env.ACP_LOG_SIZE);
50
- // The failure transcript is the only thing that reads these frames, and it is opt-in, so
51
- // recording by default retained up to _logSize × FRAME_CAP bytes per delegation that nothing
52
- // would ever ask for. ACP_LOG_SIZE still bounds retention and still disables at 0.
45
+ // Only the opt-in failure transcript reads these frames, so record only when it is on.
53
46
  this._recording = this._logSize > 0 && transcriptFrames() > 0;
54
47
  this._log = [];
55
48
  this.rl = readline.createInterface({ input });
56
- // The interface re-emits the input stream's error as its own, so the handler acp-client.js
57
- // puts on the child's stdout does not cover this one: an unhandled 'error' here is an
58
- // uncaught exception, which takes down the server and every concurrent delegation with it.
49
+ // readline re-emits the stream's error as its own, which acp-client's stdout handler does not
50
+ // cover; unhandled, it would take down the server.
59
51
  this.rl.on("error", () => {});
60
52
  this.rl.on("line", (line) => this._onLine(line));
61
53
  }
62
54
 
63
- // Trimming to the cap on every frame meant shifting a 2000-entry array per frame, which on a
64
- // chatty turn cost more than parsing the frames. Let the array overshoot by a quarter and trim
65
- // in one batch; readers below take the last _logSize, so what the log reports is unchanged.
55
+ // Overshoots by a quarter and trims in one batch, rather than shifting the array per frame;
56
+ // readers take the last _logSize.
66
57
  _record(dir, line) {
67
58
  if (!this._recording) return;
68
59
  const truncated = line.length > FRAME_CAP ? line.slice(0, FRAME_CAP) : line;
@@ -89,20 +80,17 @@ export class JsonRpcPeer {
89
80
  let msg;
90
81
  try { msg = JSON.parse(line); } catch { return; }
91
82
  if (msg === null || typeof msg !== "object" || Array.isArray(msg)) return;
92
- // Only a parsed frame counts. A blank line, a launcher banner or anything else the agent
93
- // prints is not the protocol advancing, and treating it as such is what let a chatty
94
- // launcher hold the idle guard open and made "Last ACP frame Ns ago" report a stderr byte.
83
+ // Only a parsed frame is activity; a blank line or launcher banner must not hold the idle
84
+ // guard open.
95
85
  this.onActivity();
96
86
  const hasId = msg.id !== undefined && msg.id !== null;
97
87
  if (hasId && (msg.result !== undefined || msg.error !== undefined)) {
98
- // Keyed by string: a peer that echoes "1" for the id 1 is still answering that request,
99
- // and matching by identity left it pending until a timeout fired an hour later.
88
+ // Keyed by string: a peer that echoes "1" for the id 1 is answering that request.
100
89
  const key = String(msg.id);
101
90
  const p = this.pending.get(key);
102
91
  if (p) {
103
92
  this.pending.delete(key);
104
- // cursor-agent puts the actual reason in error.data.message; error.message alone
105
- // is a bare "Invalid params".
93
+ // cursor-agent puts the reason in error.data.message; error.message is a bare "Invalid params".
106
94
  if (msg.error) {
107
95
  /** @type {import("./errors.js").DelegateError} */
108
96
  const err = new Error([msg.error.message || "rpc error", msg.error.data?.message].filter(Boolean).join(": "));
@@ -1,13 +1,11 @@
1
1
  // Config option ids differ per model, and a model rejects any id it does not declare. The set is
2
2
  // knowable only once a model is selected, from the configOptions the agent echoes back.
3
3
 
4
- // ACP marks a thought/reasoning level selector with category "thought_level" — grok-4.7 declares
5
- // reasoning_effort ("Effort") that way. Categories are optional in ACP, so the ids and names
6
- // below still classify options from an agent that sends none. A match only nominates an option:
7
- // the requested value must still appear exactly among the values it advertises.
4
+ // ACP marks a reasoning-level selector with category "thought_level" (grok-4.7's reasoning_effort).
5
+ // Categories are optional, so ids and names classify too. A match only nominates an option; the
6
+ // requested value must still be one it advertises.
8
7
  const THOUGHT_LEVEL_IDS = new Set(["thinking", "reasoning", "effort", "reasoning_effort", "thought_level"]);
9
- // Never an effort setting, and doctor reports them as currentModel and modes, so a list of what a
10
- // model offers leaves them out.
8
+ // Never effort, and doctor reports them as currentModel and modes, so option lists leave them out.
11
9
  const SELECTOR_IDS = new Set(["model", "mode"]);
12
10
 
13
11
  export function isThoughtLevel(opt) {
@@ -42,9 +40,8 @@ export function describeOptions(options) {
42
40
  }));
43
41
  }
44
42
 
45
- // The current value of every recognized effort option, keyed by id. All of them rather than one
46
- // picked: a model can declare a thinking toggle beside a level, and either alone can mislead.
47
- // Undefined when no recognized option reports a string value.
43
+ // Every recognized effort option's current value, by id: a model can pair a thinking toggle with a
44
+ // level, and either alone misleads. Undefined when none reports a string value.
48
45
  export function effortSettings(options) {
49
46
  const settings = {};
50
47
  for (const o of Array.isArray(options) ? options : []) {
@@ -55,11 +52,9 @@ export function effortSettings(options) {
55
52
  return Object.keys(settings).length > 0 ? settings : undefined;
56
53
  }
57
54
 
58
- // Resolve only values the selected model advertised. This keeps future vocabularies working
59
- // without aliases or a ranking table: xhigh, extra-high, max and ultra are just exact tokens.
60
- // No list, an empty list, or a thought-level option with no usable id/values is unavailable. A
61
- // list with nothing classified as thought-level is unrecognized — not proof the model has no
62
- // effort setting: categories are optional and ids get renamed, so the caller is shown the list.
55
+ // Only values the model advertised, as exact tokens, with no aliases or ranking table. No list, or
56
+ // no usable id or values, is unavailable. Nothing classified as effort is unrecognized, not proof
57
+ // there is none (categories are optional, ids get renamed), so the caller is shown the list.
63
58
  export function resolveEffort(options, value) {
64
59
  if (!Array.isArray(options) || options.length === 0) return { status: "unavailable" };
65
60
 
package/src/proc.js CHANGED
@@ -5,30 +5,25 @@ export function isChildAlive(child) {
5
5
  return child && child.exitCode === null && child.signalCode === null;
6
6
  }
7
7
 
8
- // POSIX only: detached makes the child a process group leader (setsid), which is what lets
9
- // treeKill reach the agent's own children. On win32 it would mean a separate console instead,
10
- // and taskkill /T already walks the tree. Every spawn site applies it, not resolveAcpSpawn —
11
- // an injected spawnSpec has to become a group leader too or the group kill finds nothing.
8
+ // POSIX only: a process group leader (setsid) lets treeKill reach the agent's children. On win32
9
+ // it would mean a new console, and taskkill /T walks the tree anyway. Applied at each spawn site,
10
+ // not in resolveAcpSpawn, so an injected spec gets it too.
12
11
  export const DETACHED = process.platform !== "win32";
13
12
 
14
- // On win32 a plain child.kill() only reaches the shell wrapper (spawn uses shell: true);
15
- // taskkill /T takes the whole tree so the agent itself dies too.
13
+ // On win32 child.kill() reaches only the wrapper; taskkill /T takes the whole tree.
16
14
  export async function treeKill(pid, { childAlive = true } = {}) {
17
15
  if (!pid) return;
18
16
  if (process.platform === "win32") {
19
- // taskkill /T walks parent links, which an exited leader no longer has: what it started is
20
- // either gone with it or detached and out of reach. So a post-exit kill has nothing left to
21
- // reach, and a reaped pid can already belong to somebody else — which makes the gate the
22
- // whole of it here, where POSIX still has the group to aim at.
17
+ // taskkill /T follows parent links, which an exited leader no longer has, and a reaped pid can
18
+ // already belong to another process: after the exit there is nothing safe to kill.
23
19
  if (!childAlive) return;
24
20
  await /** @type {Promise<void>} */ (new Promise((resolve) => {
25
21
  execFile("taskkill", ["/PID", String(pid), "/T", "/F"], { windowsHide: true }, () => resolve());
26
22
  }));
27
23
  return;
28
24
  }
29
- // Negative pid signals the whole group, so the agent's descendants go with it. A group outlives
30
- // its leader while any member is left, which is why this runs even for an exited child: that is
31
- // the case where descendants are the only thing still running.
25
+ // The negative pid signals the whole group, which outlives its leader, so this runs even after
26
+ // the child exited: its descendants may still be running.
32
27
  try { process.kill(-pid, "SIGKILL"); } catch {}
33
28
  // Reaches a child that is not a group leader, where the group kill raised ESRCH. Skipped once
34
29
  // the child is gone, since a reaped pid can already belong to something else.
@@ -15,16 +15,11 @@ export function createRequestRouter({ respond, respondError, onCreatePlan, onTod
15
15
  try {
16
16
  if (method === "session/request_permission") {
17
17
  const opts = params?.options || [];
18
- // The two allow kinds only. Taking opts[0] when neither is offered returned a reject
19
- // id under a `selected` outcome, which the agent reads as an approval of the denial —
20
- // a silent skip from a bridge that advertises auto-approval.
18
+ // Allow kinds only: opts[0] can be a reject option, and selecting it silently denies.
21
19
  const pick =
22
20
  opts.find((o) => o.kind === "allow_always") ||
23
21
  opts.find((o) => o.kind === "allow_once");
24
- // Selecting nothing is not a selection: an options-less request answered with
25
- // optionId undefined is a malformed ACP response, and a request offering no allow
26
- // option is one this bridge can approve nothing in. Say cancelled to both and let the
27
- // agent decide what to do about it.
22
+ // With no allow option there is nothing to select; cancelled is the valid ACP answer.
28
23
  if (!pick?.optionId) return respond(id, { outcome: { outcome: "cancelled" } });
29
24
  return respond(id, { outcome: { outcome: "selected", optionId: pick.optionId } });
30
25
  }
@@ -42,8 +37,7 @@ export function createRequestRouter({ respond, respondError, onCreatePlan, onTod
42
37
  onTodos?.({ todos: params?.todos, merge: params?.merge, toolCallId: params?.toolCallId });
43
38
  log({ method, params });
44
39
  if (id == null) return;
45
- // The documented response is {outcome:{outcome:"accepted", todos}}; the bare {} we
46
- // have always sent is accepted by cursor-agent, so it stays until that changes.
40
+ // The documented reply is {outcome:{outcome:"accepted", todos}}; cursor-agent accepts {}.
47
41
  return respond(id, {});
48
42
  }
49
43
  if (ACK_METHODS.has(method)) {
@@ -52,8 +46,7 @@ export function createRequestRouter({ respond, respondError, onCreatePlan, onTod
52
46
  }
53
47
  return respondError(id, -32601, `Unhandled method: ${method}`);
54
48
  } catch (err) {
55
- // -32603, not -32000: ACP assigns -32000 to auth_required, and a bug on this side
56
- // reported as "authenticate" sends the agent down a recovery path that cannot work.
49
+ // -32603, not -32000: ACP reserves -32000 for auth_required, which sends the agent to log in.
57
50
  if (id != null) return respondError(id, -32603, `Router error: ${err?.message || err}`);
58
51
  }
59
52
  };