cursor-delegate-mcp 2.9.0 → 2.11.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/CHANGELOG.md +66 -0
- package/package.json +3 -2
- package/src/acp-client.js +24 -30
- package/src/acp-enums.js +3 -8
- package/src/delegate.js +117 -129
- package/src/doctor.js +78 -31
- package/src/errors.js +2 -4
- package/src/jsonrpc.js +14 -26
- package/src/model-options.js +9 -14
- package/src/proc.js +8 -13
- package/src/request-router.js +4 -11
- package/src/server.js +107 -119
- package/src/session-supervisor.js +4 -6
- package/src/spawn.js +124 -26
- package/src/turn-state.js +14 -22
- package/src/version.js +2 -4
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
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
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
|
|
56
|
-
|
|
57
|
-
//
|
|
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
|
|
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
|
-
|
|
77
|
-
//
|
|
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,34 +131,41 @@ 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
|
|
103
|
-
//
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
122
|
-
//
|
|
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
|
-
* getClientInfo?: () => { capabilities?: any, version?: any },
|
|
168
|
+
* getClientInfo?: () => { capabilities?: any, version?: any, protocolVersion?: string },
|
|
130
169
|
* deep?: boolean,
|
|
131
170
|
* spawnSpec?: { command: string, args: string[], options?: object },
|
|
132
171
|
* clientFactory?: (opts: any) => any,
|
|
@@ -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
|
-
const { capabilities, version } = getClientInfo();
|
|
150
|
-
const agentProbe = await probeAgentVersion(spawnSpec, versionTimeoutMs);
|
|
192
|
+
const { capabilities, version, protocolVersion } = getClientInfo();
|
|
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 = {
|
|
@@ -156,6 +199,8 @@ export async function runDoctor({
|
|
|
156
199
|
name: version?.name ?? null,
|
|
157
200
|
version: version?.version ?? null,
|
|
158
201
|
capabilities: capabilities ?? {},
|
|
202
|
+
// The MCP revision the host speaks: 2026-07-28 or a 2025-era one.
|
|
203
|
+
...(typeof protocolVersion === "string" ? { protocolVersion } : {}),
|
|
159
204
|
},
|
|
160
205
|
agent: {
|
|
161
206
|
found: agentProbe.found,
|
|
@@ -187,6 +232,8 @@ export async function runDoctor({
|
|
|
187
232
|
clientFactory,
|
|
188
233
|
workspace,
|
|
189
234
|
timeoutMs: handshakeTimeoutMs,
|
|
235
|
+
signal,
|
|
236
|
+
onClientReady,
|
|
190
237
|
});
|
|
191
238
|
}
|
|
192
239
|
|
package/src/errors.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Every failure
|
|
3
|
-
*
|
|
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
|
|
14
|
-
//
|
|
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
|
|
20
|
-
//
|
|
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
|
|
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
|
-
//
|
|
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
|
-
//
|
|
57
|
-
//
|
|
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
|
-
//
|
|
64
|
-
//
|
|
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
|
|
93
|
-
//
|
|
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
|
|
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
|
|
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(": "));
|
package/src/model-options.js
CHANGED
|
@@ -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
|
|
5
|
-
//
|
|
6
|
-
//
|
|
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
|
|
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
|
-
//
|
|
46
|
-
//
|
|
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
|
-
//
|
|
59
|
-
//
|
|
60
|
-
//
|
|
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:
|
|
9
|
-
//
|
|
10
|
-
//
|
|
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
|
|
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
|
|
20
|
-
//
|
|
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
|
-
//
|
|
30
|
-
//
|
|
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.
|
package/src/request-router.js
CHANGED
|
@@ -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
|
-
//
|
|
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
|
-
//
|
|
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
|
|
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
|
|
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
|
};
|