cursor-delegate-mcp 3.1.0 → 3.2.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 +69 -0
- package/package.json +1 -1
- package/src/acp-client.js +20 -58
- package/src/delegate.js +40 -69
- package/src/doctor.js +16 -45
- package/src/errors.js +4 -3
- package/src/jsonrpc.js +11 -32
- package/src/proc.js +92 -77
- package/src/server.js +22 -153
- package/src/session-supervisor.js +6 -26
- package/src/shutdown.js +27 -0
- package/src/tasks.js +33 -23
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,75 @@ All notable changes to this project are documented here. The format follows
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [3.2.0] - 2026-11-24
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- A stop kills cursor-agent's process tree once and waits up to 5 s for cursor-agent to exit; on
|
|
14
|
+
Windows `taskkill` first gets up to 5 s of its own. A stop that cannot confirm the exit is final,
|
|
15
|
+
and the result warns `the bridge stopped cursor-agent (pid <pid>) but could not confirm that
|
|
16
|
+
cursor-agent and its processes exited; they may still be running.`, where it said the bridge did
|
|
17
|
+
not see cursor-agent exit and a later stop tried again.
|
|
18
|
+
- A force cancel whose kill cannot confirm the exit reports `cancelled`, and the session is no
|
|
19
|
+
longer kept for another force.
|
|
20
|
+
- Shutdown stops every agent, waits for the stops, and exits with the code of whatever triggered it
|
|
21
|
+
first. SIGINT, SIGTERM and SIGHUP trigger it on Windows too. A later signal waits for the same
|
|
22
|
+
stop, where a second signal killed each agent's process group and exited at once.
|
|
23
|
+
- A stopped task's status message carries a note only when the run started a fresh session after a
|
|
24
|
+
failed resume. A stop that cannot confirm cursor-agent exited is reported in the delegate result's
|
|
25
|
+
`protocolWarnings`.
|
|
26
|
+
- An `agent-error` message ends with the request and JSON-RPC code cursor-agent answered with, as in
|
|
27
|
+
`(session/new JSON-RPC -32603)`, and so does the note of a resume that failed for a session that
|
|
28
|
+
still exists. The skill reference describes `agent-error` as an error answer named with its code,
|
|
29
|
+
where it called every such code a rejected argument.
|
|
30
|
+
- The `model` field and the skill reference name only the default model and point to
|
|
31
|
+
`doctor deep:true` for the ids an account offers.
|
|
32
|
+
|
|
33
|
+
### Removed
|
|
34
|
+
|
|
35
|
+
- `CURSOR_DELEGATE_IDLE_MS`, the opt-in mid-turn idle guard (off by default), and its `idle-timeout`
|
|
36
|
+
reason. doctor no longer reports it.
|
|
37
|
+
- `ACP_LOG_SIZE`. The flight recorder keeps exactly the frames `CURSOR_DELEGATE_TRANSCRIPT` shows,
|
|
38
|
+
and records only while it is set. doctor no longer reports it.
|
|
39
|
+
- The protocol warning for each malformed plan or todo value. A plan entry or todo without string
|
|
40
|
+
content is still dropped, and a priority or status outside the ACP values still removed.
|
|
41
|
+
|
|
42
|
+
### Fixed
|
|
43
|
+
|
|
44
|
+
- On Windows a `taskkill` that fails or runs past 5 s is followed by a kill of the launcher by its
|
|
45
|
+
handle, and the result warns that cursor-agent and its processes may still be running. A failed
|
|
46
|
+
`taskkill` went unreported.
|
|
47
|
+
- `resumeSessionId` is trimmed, and a blank one starts a new session, as in agy-delegate-mcp. Both
|
|
48
|
+
were sent to cursor-agent as given.
|
|
49
|
+
|
|
50
|
+
### Internal
|
|
51
|
+
|
|
52
|
+
- `src/proc.js` and `src/shutdown.js` are the same in agy-delegate-mcp, cursor-delegate-mcp and
|
|
53
|
+
codex-delegate-mcp.
|
|
54
|
+
- `npm test` runs the test files named on the command line, without a deadline.
|
|
55
|
+
- The result and doctor shapes the tests check are in `test/output-shapes.js`.
|
|
56
|
+
- Tests of limits, options and source layout the code no longer has are removed.
|
|
57
|
+
|
|
58
|
+
## [3.1.1] - 2026-11-24
|
|
59
|
+
|
|
60
|
+
### Changed
|
|
61
|
+
|
|
62
|
+
- A finished task is kept for its hour however many finish, where only the last 100 were kept.
|
|
63
|
+
- `cancel` tells every session the server has seen from an unknown id, where only the last 500
|
|
64
|
+
sessions were kept.
|
|
65
|
+
|
|
66
|
+
### Fixed
|
|
67
|
+
|
|
68
|
+
- The server shuts down, stopping its agents, when its stdio transport closes. When the server's
|
|
69
|
+
stdout broke, as it does when the host dies, the transport paused stdin, no stdin EOF arrived,
|
|
70
|
+
and the server and the agent kept running.
|
|
71
|
+
- A completed task's result carries `resultType: "complete"`, as the `tools/call` result it stands
|
|
72
|
+
for, which the tasks extension's client schema requires.
|
|
73
|
+
- A task id resumes its session for as long as the server runs, not only for the hour its task is
|
|
74
|
+
kept.
|
|
75
|
+
- A finished task's status message is its error, or none, instead of its last progress line.
|
|
76
|
+
- `tasks/update` refuses a request with no `inputResponses`.
|
|
77
|
+
|
|
9
78
|
## [3.1.0] - 2026-11-24
|
|
10
79
|
|
|
11
80
|
### Changed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursor-delegate-mcp",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"mcpName": "io.github.andreilungeanu/cursor-delegate-mcp",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Delegate multi-file coding work from Claude Code, Codex, Copilot, or any MCP client to Cursor's CLI agent — structured results, plan mode, and changed files.",
|
package/src/acp-client.js
CHANGED
|
@@ -3,7 +3,7 @@ import { StringDecoder } from "node:string_decoder";
|
|
|
3
3
|
import { JsonRpcPeer } from "./jsonrpc.js";
|
|
4
4
|
import { createRequestRouter } from "./request-router.js";
|
|
5
5
|
import { commandExists, resolveAcpSpawn } from "./spawn.js";
|
|
6
|
-
import { children, isChildAlive, spawnChild } from "./proc.js";
|
|
6
|
+
import { children, isChildAlive, spawnChild, stopChild } from "./proc.js";
|
|
7
7
|
import { VERSION } from "./version.js";
|
|
8
8
|
import { makeError } from "./errors.js";
|
|
9
9
|
|
|
@@ -44,28 +44,20 @@ export class AcpClient extends EventEmitter {
|
|
|
44
44
|
super();
|
|
45
45
|
this.spawnSpec = spawnSpec || resolveAcpSpawn();
|
|
46
46
|
this.registry = registry;
|
|
47
|
-
/** @type {
|
|
48
|
-
this.
|
|
47
|
+
/** @type {any} */
|
|
48
|
+
this._child = null;
|
|
49
49
|
this.mode = mode;
|
|
50
50
|
this.onCreatePlan = onCreatePlan;
|
|
51
51
|
this.onTodos = onTodos;
|
|
52
|
-
|
|
53
|
-
this.
|
|
52
|
+
// The stderr tail an exit error quotes; not counted as activity.
|
|
53
|
+
this.stderrBuffer = "";
|
|
54
54
|
/** @type {Promise<boolean> | null} */
|
|
55
55
|
this._stopping = null;
|
|
56
56
|
/** @type {WirePhase} */
|
|
57
57
|
this._phase = "setup";
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
get child() { return this.
|
|
61
|
-
|
|
62
|
-
// The stderr tail an exit error quotes. Kept as chunks and joined on read, so a noisy agent costs
|
|
63
|
-
// a push per chunk; a StringDecoder keeps a multi-byte character split across reads intact.
|
|
64
|
-
// stderr is not ACP activity, so it does not feed the supervisor.
|
|
65
|
-
get stderrBuffer() {
|
|
66
|
-
const joined = this._stderrChunks.join("");
|
|
67
|
-
return joined.length > STDERR_CAP ? joined.slice(-STDERR_CAP) : joined;
|
|
68
|
-
}
|
|
60
|
+
get child() { return this._child; }
|
|
69
61
|
|
|
70
62
|
async start() {
|
|
71
63
|
const { command, args, options } = this.spawnSpec;
|
|
@@ -73,28 +65,12 @@ export class AcpClient extends EventEmitter {
|
|
|
73
65
|
if (opts?.shell && !commandExists(command, opts.env)) {
|
|
74
66
|
throw makeError("spawn-failed", `Failed to spawn agent (${command}): not found on PATH. Install Cursor CLI and run 'cursor-agent login'.`);
|
|
75
67
|
}
|
|
76
|
-
this.
|
|
77
|
-
this.
|
|
78
|
-
|
|
68
|
+
this._child = spawnChild(command, args, opts, { stdio: ["pipe", "pipe", "pipe"] }, this.registry);
|
|
69
|
+
this.stderrBuffer = "";
|
|
70
|
+
// Keeps a UTF-8 character split across reads whole.
|
|
79
71
|
const stderrDecoder = new StringDecoder("utf8");
|
|
80
72
|
this.child.stderr.on("data", (chunk) => {
|
|
81
|
-
|
|
82
|
-
if (text) {
|
|
83
|
-
this._stderrChunks.push(text);
|
|
84
|
-
this._stderrLength += text.length;
|
|
85
|
-
// Drop whole chunks from the front only once well past the cap, so the common case
|
|
86
|
-
// costs one push. The joined tail is trimmed exactly on read.
|
|
87
|
-
while (this._stderrChunks.length > 1 && this._stderrLength - this._stderrChunks[0].length >= STDERR_CAP) {
|
|
88
|
-
this._stderrLength -= this._stderrChunks.shift().length;
|
|
89
|
-
}
|
|
90
|
-
// A single read larger than the cap (seen on GitHub Windows runners) is sliced too, so
|
|
91
|
-
// retained memory stays bounded.
|
|
92
|
-
const overflow = this._stderrLength - STDERR_CAP;
|
|
93
|
-
if (overflow > 0) {
|
|
94
|
-
this._stderrChunks[0] = this._stderrChunks[0].slice(overflow);
|
|
95
|
-
this._stderrLength -= overflow;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
73
|
+
this.stderrBuffer = (this.stderrBuffer + stderrDecoder.write(chunk)).slice(-STDERR_CAP);
|
|
98
74
|
});
|
|
99
75
|
this.child.stderr.on("error", () => {});
|
|
100
76
|
// session/cancel can be written after the agent is gone, and an unhandled pipe 'error' would
|
|
@@ -200,36 +176,22 @@ export class AcpClient extends EventEmitter {
|
|
|
200
176
|
|
|
201
177
|
getTranscript(n) { return this.peer ? this.peer.formatLog(n) : ""; }
|
|
202
178
|
|
|
203
|
-
//
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
stop({ timeoutMs } = {}) {
|
|
207
|
-
if (!this._stopping) {
|
|
208
|
-
this._stopping = this._teardown(timeoutMs).then((observed) => {
|
|
209
|
-
if (!observed) this._stopping = null;
|
|
210
|
-
return observed;
|
|
211
|
-
}, (err) => {
|
|
212
|
-
this._stopping = null;
|
|
213
|
-
throw err;
|
|
214
|
-
});
|
|
215
|
-
}
|
|
179
|
+
// One stop per client, which every caller joins.
|
|
180
|
+
stop() {
|
|
181
|
+
this._stopping ??= this._teardown();
|
|
216
182
|
return this._stopping;
|
|
217
183
|
}
|
|
218
184
|
|
|
219
|
-
async _teardown(
|
|
220
|
-
const
|
|
221
|
-
if (!
|
|
185
|
+
async _teardown() {
|
|
186
|
+
const child = this._child;
|
|
187
|
+
if (!child) {
|
|
222
188
|
try { this.peer?.close(); } catch {}
|
|
223
189
|
return true;
|
|
224
190
|
}
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if (!observed && this._phase !== "exited" && isChildAlive(child)) {
|
|
230
|
-
try {
|
|
231
|
-
this.peer?.rejectAllPending(makeError("agent-exit", "agent process did not exit after stop"));
|
|
232
|
-
} catch {}
|
|
191
|
+
const observed = await stopChild(child);
|
|
192
|
+
// On an exit, emitExit rejects in-flight RPCs with stderr; rejecting here first would lose it.
|
|
193
|
+
if (isChildAlive(child)) {
|
|
194
|
+
try { this.peer?.rejectAllPending(makeError("agent-exit", "agent process did not exit after stop")); } catch {}
|
|
233
195
|
}
|
|
234
196
|
try { this.peer?.close(); } catch {}
|
|
235
197
|
return observed;
|
package/src/delegate.js
CHANGED
|
@@ -19,10 +19,10 @@ export const DEFAULT_MODEL = "composer-2.5";
|
|
|
19
19
|
// whose served model has to be read back off a config reply for effectiveModel.
|
|
20
20
|
const ROUTED_MODEL = "default";
|
|
21
21
|
export const DEFAULT_HANDSHAKE_MS = 60000;
|
|
22
|
-
|
|
22
|
+
const DEFAULT_HEARTBEAT_MS = 30000;
|
|
23
23
|
|
|
24
24
|
// A malformed or non-positive value falls back to the default, so a blank var (Number("") is 0)
|
|
25
|
-
// cannot arm a zero-length deadline.
|
|
25
|
+
// cannot arm a zero-length deadline.
|
|
26
26
|
function envMs(name, fallback) {
|
|
27
27
|
const raw = process.env[name];
|
|
28
28
|
if (raw === undefined) return fallback;
|
|
@@ -145,6 +145,12 @@ function isMissingSession(err) {
|
|
|
145
145
|
&& /\bnot found\b|\bdoes not exist\b|\bunknown session\b|\bno such session\b/i.test(message);
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
// The request and code of an error the agent answered with, as " (session/new JSON-RPC -32603)"; else "".
|
|
149
|
+
function rpcNote(err) {
|
|
150
|
+
if (err?.reason || typeof err?.code !== "number") return "";
|
|
151
|
+
return ` (${err.method ? `${err.method} ` : ""}JSON-RPC ${err.code})`;
|
|
152
|
+
}
|
|
153
|
+
|
|
148
154
|
async function openSession(client, resumeSessionId, workspace) {
|
|
149
155
|
if (!resumeSessionId) return client.newSession(workspace);
|
|
150
156
|
try {
|
|
@@ -154,7 +160,7 @@ async function openSession(client, resumeSessionId, workspace) {
|
|
|
154
160
|
if (!isMissingSession(err)) {
|
|
155
161
|
throw makeError(
|
|
156
162
|
"resume-failed",
|
|
157
|
-
`session ${resumeSessionId} could not be loaded: ${err?.message || String(err)}.`
|
|
163
|
+
`session ${resumeSessionId} could not be loaded: ${err?.message || String(err)}${rpcNote(err)}.`
|
|
158
164
|
+ ` The session was not resumed and no fresh session was started — retry, or omit`
|
|
159
165
|
+ ` resumeSessionId to start fresh deliberately.`
|
|
160
166
|
);
|
|
@@ -248,10 +254,9 @@ async function applyEffort(client, sessionId, model, value, modelOptions) {
|
|
|
248
254
|
* spec?: string, mode?: string, resumeSessionId?: string, workspace?: string,
|
|
249
255
|
* model?: string, fast?: boolean, effort?: string, context?: string,
|
|
250
256
|
* contextFiles?: string[], clientFactory?: (opts: any) => any,
|
|
251
|
-
*
|
|
257
|
+
* handshakeMs?: number, hardCapMs?: number, timeoutMs?: number,
|
|
252
258
|
* onSessionReady?: (sessionId: string, client: any) => void,
|
|
253
259
|
* onPromptSent?: (sessionId: string, resumeNote?: string) => void,
|
|
254
|
-
* onUnseenExit?: (note: string) => void,
|
|
255
260
|
* onTurnEnd?: () => void,
|
|
256
261
|
* onProgress?: (message: string) => void,
|
|
257
262
|
* progressThrottleMs?: number, heartbeatMs?: number, signal?: AbortSignal,
|
|
@@ -260,8 +265,8 @@ async function applyEffort(client, sessionId, model, value, modelOptions) {
|
|
|
260
265
|
export async function runDelegate({
|
|
261
266
|
spec, mode = "agent", resumeSessionId, workspace,
|
|
262
267
|
model = DEFAULT_MODEL, fast = false, effort, context, contextFiles, clientFactory,
|
|
263
|
-
|
|
264
|
-
onSessionReady, onPromptSent,
|
|
268
|
+
handshakeMs, hardCapMs, timeoutMs,
|
|
269
|
+
onSessionReady, onPromptSent, onTurnEnd, onProgress, progressThrottleMs = 2000,
|
|
265
270
|
heartbeatMs = DEFAULT_HEARTBEAT_MS,
|
|
266
271
|
signal,
|
|
267
272
|
} = {}) {
|
|
@@ -277,56 +282,27 @@ export async function runDelegate({
|
|
|
277
282
|
const promptText = spec;
|
|
278
283
|
const capMs = hardCapMs ?? timeoutMs ?? envMs("CURSOR_DELEGATE_HARD_CAP_MS", DEFAULT_HARD_CAP_MS);
|
|
279
284
|
const shakeMs = handshakeMs ?? envMs("CURSOR_DELEGATE_HANDSHAKE_MS", DEFAULT_HANDSHAKE_MS);
|
|
280
|
-
const turnIdleMs = idleMs ?? envMs("CURSOR_DELEGATE_IDLE_MS", 0);
|
|
281
285
|
const state = makeTurnState({ onProgress, progressThrottleMs });
|
|
282
286
|
|
|
283
|
-
// ACP requires string plan content and bounds priority
|
|
284
|
-
//
|
|
285
|
-
const sanitizePlan = (
|
|
286
|
-
const entries =
|
|
287
|
-
state.planEntries.forEach((raw, i) => {
|
|
288
|
-
if (typeof raw?.content !== "string") {
|
|
289
|
-
warnings.push(`plan entry ${i} dropped: ACP requires string content, got ${raw === null ? "null" : typeof raw?.content}`);
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
287
|
+
// ACP requires string plan content and bounds priority and status. An entry without text is
|
|
288
|
+
// dropped and a value outside the bounds removed, so the result keeps its shape.
|
|
289
|
+
const sanitizePlan = () => {
|
|
290
|
+
const entries = state.planEntries.filter((raw) => typeof raw?.content === "string").map((raw) => {
|
|
292
291
|
const entry = { ...raw };
|
|
293
|
-
if (
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
if (entry.status !== undefined && !PLAN_STATUSES.includes(entry.status)) {
|
|
298
|
-
warnings.push(`plan entry ${i}: non-ACP status ${JSON.stringify(entry.status)} removed`);
|
|
299
|
-
delete entry.status;
|
|
300
|
-
}
|
|
301
|
-
entries.push(entry);
|
|
292
|
+
if (!PLAN_PRIORITIES.includes(entry.priority)) delete entry.priority;
|
|
293
|
+
if (!PLAN_STATUSES.includes(entry.status)) delete entry.status;
|
|
294
|
+
return entry;
|
|
302
295
|
});
|
|
303
296
|
const plan = { entries };
|
|
304
|
-
if (state.planOverview
|
|
305
|
-
|
|
306
|
-
else warnings.push("plan overview dropped: expected string");
|
|
307
|
-
}
|
|
308
|
-
if (state.planDetail !== undefined) {
|
|
309
|
-
if (typeof state.planDetail === "string") plan.detail = state.planDetail;
|
|
310
|
-
else warnings.push("plan detail dropped: expected string");
|
|
311
|
-
}
|
|
297
|
+
if (typeof state.planOverview === "string") plan.overview = state.planOverview;
|
|
298
|
+
if (typeof state.planDetail === "string") plan.detail = state.planDetail;
|
|
312
299
|
return plan;
|
|
313
300
|
};
|
|
314
301
|
|
|
315
|
-
const sanitizeTodos = (
|
|
316
|
-
const entries = []
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
i++;
|
|
320
|
-
if (typeof raw?.content !== "string") {
|
|
321
|
-
warnings.push(`todo ${i} dropped: expected string content, got ${raw === null ? "null" : typeof raw?.content}`);
|
|
322
|
-
continue;
|
|
323
|
-
}
|
|
324
|
-
const status = TODO_STATUSES.includes(raw.status) ? raw.status : undefined;
|
|
325
|
-
if (raw.status !== undefined && status === undefined) {
|
|
326
|
-
warnings.push(`todo ${i}: unknown status ${JSON.stringify(raw.status)} removed`);
|
|
327
|
-
}
|
|
328
|
-
entries.push({ id: String(raw.id), content: raw.content, ...(status ? { status } : {}) });
|
|
329
|
-
}
|
|
302
|
+
const sanitizeTodos = () => {
|
|
303
|
+
const entries = [...state.todos.values()]
|
|
304
|
+
.filter((raw) => typeof raw?.content === "string")
|
|
305
|
+
.map((raw) => ({ id: String(raw.id), content: raw.content, ...(TODO_STATUSES.includes(raw.status) ? { status: raw.status } : {}) }));
|
|
330
306
|
const count = (s) => entries.filter((e) => e.status === s).length;
|
|
331
307
|
return {
|
|
332
308
|
todos: entries,
|
|
@@ -342,7 +318,7 @@ export async function runDelegate({
|
|
|
342
318
|
|
|
343
319
|
const make = clientFactory || ((opts) => new AcpClient(opts));
|
|
344
320
|
const client = make({ mode, onCreatePlan: state.recordCreatePlan, onTodos: state.recordTodos });
|
|
345
|
-
const supervisor = new SessionSupervisor(client, {
|
|
321
|
+
const supervisor = new SessionSupervisor(client, { handshakeMs: shakeMs, hardCapMs: capMs });
|
|
346
322
|
const onAbort = () => supervisor.abort();
|
|
347
323
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
348
324
|
|
|
@@ -453,7 +429,7 @@ export async function runDelegate({
|
|
|
453
429
|
let servedModel;
|
|
454
430
|
let effectiveEffort;
|
|
455
431
|
const contextWarnings = [];
|
|
456
|
-
// Set before the teardown in finally, which notes an
|
|
432
|
+
// Set before the teardown in finally, which notes an unconfirmed stop on whichever is going out.
|
|
457
433
|
/** @type {any} */
|
|
458
434
|
let out;
|
|
459
435
|
/** @type {{ cause: any, reason?: string, notes: string[] } | undefined} */
|
|
@@ -581,17 +557,15 @@ export async function runDelegate({
|
|
|
581
557
|
protocolWarnings.push(...contextWarnings);
|
|
582
558
|
protocolWarnings.push(...frameWarnings);
|
|
583
559
|
if (state.planEntries.length > 0 || state.planOverview !== undefined || state.planDetail !== undefined) {
|
|
584
|
-
// Sanitized even when dropped: its warnings report malformed frames in any mode.
|
|
585
|
-
const plan = sanitizePlan(protocolWarnings);
|
|
586
560
|
// In plan/ask the result is the plan in prose; entries would put the same steps in context
|
|
587
561
|
// twice, and the implementing resume reads the session, not this field. In agent mode the
|
|
588
562
|
// result is the implementation report, so the plan stays.
|
|
589
|
-
if (!dropPlan) out.plan =
|
|
563
|
+
if (!dropPlan) out.plan = sanitizePlan();
|
|
590
564
|
}
|
|
591
565
|
// Only when the agent tracked todos: an empty list would read as "nothing done". The list
|
|
592
566
|
// itself only while items remain; once all are done it restates the counts.
|
|
593
567
|
if (state.sawTodoFrame) {
|
|
594
|
-
const { todos: todoList, todoProgress } = sanitizeTodos(
|
|
568
|
+
const { todos: todoList, todoProgress } = sanitizeTodos();
|
|
595
569
|
out.todoProgress = todoProgress;
|
|
596
570
|
if (todoProgress.completed < todoProgress.total) out.todos = todoList;
|
|
597
571
|
}
|
|
@@ -605,14 +579,16 @@ export async function runDelegate({
|
|
|
605
579
|
if (resumeError) out.protocolWarnings = [`resuming ${resumeSessionId} failed, started a fresh session: ${resumeError}`];
|
|
606
580
|
return out;
|
|
607
581
|
}
|
|
608
|
-
// A JSON-RPC code means the agent
|
|
609
|
-
//
|
|
610
|
-
const
|
|
582
|
+
// A JSON-RPC code means the agent answered with an error, not that the bridge broke: a rejected
|
|
583
|
+
// argument (-32602) or a failure of its own (-32603).
|
|
584
|
+
const fromAgent = !err?.reason && typeof err?.code === "number";
|
|
585
|
+
const reason = err?.reason || (fromAgent ? "agent-error" : undefined);
|
|
611
586
|
failure = { cause: err, reason, notes: [] };
|
|
612
587
|
const { notes } = failure;
|
|
588
|
+
if (fromAgent) notes.push(rpcNote(err));
|
|
613
589
|
// A bare duration cannot distinguish a wedged agent from a slow command, so name what was
|
|
614
590
|
// outstanding — it also lets a retry resume the work already done.
|
|
615
|
-
const isTimeout = reason === "hard-cap"
|
|
591
|
+
const isTimeout = reason === "hard-cap";
|
|
616
592
|
// A handshake timeout gets the forensics but not the long-command advice: no prompt was sent,
|
|
617
593
|
// so no shell command explains the silence.
|
|
618
594
|
const isStall = isTimeout || reason === "handshake-timeout";
|
|
@@ -623,7 +599,7 @@ export async function runDelegate({
|
|
|
623
599
|
notes.push(`\n\nLast ACP frame ${age} ago${state.lastToolLabel ? `; last tool call: ${state.lastToolLabel}` : ""}.`);
|
|
624
600
|
if (state.sessionTitle) notes.push(` The agent titled this turn ${JSON.stringify(state.sessionTitle)}.`);
|
|
625
601
|
if (state.sawTodoFrame) {
|
|
626
|
-
const { todoProgress } = sanitizeTodos(
|
|
602
|
+
const { todoProgress } = sanitizeTodos();
|
|
627
603
|
const current = state.todoLabel();
|
|
628
604
|
notes.push(` ${todoProgress.completed} of ${todoProgress.total} todos completed${current ? `; ${current}` : ""}.`);
|
|
629
605
|
}
|
|
@@ -635,10 +611,8 @@ export async function runDelegate({
|
|
|
635
611
|
// config value included, not just the stalls.
|
|
636
612
|
if (sessionId) notes.push(` Resume with resumeSessionId ${sessionId}.`);
|
|
637
613
|
if (isTimeout) {
|
|
638
|
-
// Name the knob that fired: the hard cap does nothing for an idle-timeout.
|
|
639
|
-
const knob = reason === "idle-timeout" ? "CURSOR_DELEGATE_IDLE_MS" : "CURSOR_DELEGATE_HARD_CAP_MS";
|
|
640
614
|
notes.push(" cursor-agent does not stream shell output over ACP, so a long-running command emits"
|
|
641
|
-
+
|
|
615
|
+
+ " nothing until it exits. Split the command, run it in the background and poll, or raise CURSOR_DELEGATE_HARD_CAP_MS.");
|
|
642
616
|
}
|
|
643
617
|
// Opt-in: raw frames add nothing actionable to the caller's context beyond the forensics
|
|
644
618
|
// above; they help only someone debugging the bridge.
|
|
@@ -656,16 +630,13 @@ export async function runDelegate({
|
|
|
656
630
|
signal?.removeEventListener("abort", onAbort);
|
|
657
631
|
try { supervisor.finish(); } catch {}
|
|
658
632
|
// Awaited: a host may close stdin on the result, and on Windows the server's exit does not take
|
|
659
|
-
// a running agent with it (server.smoke.test.js).
|
|
660
|
-
|
|
661
|
-
let exited = false;
|
|
662
|
-
try { exited = await client.stop(); } catch {}
|
|
633
|
+
// a running agent with it (server.smoke.test.js). A stop that cannot confirm the exit is noted.
|
|
634
|
+
const exited = await client.stop();
|
|
663
635
|
if (exited === false) {
|
|
664
636
|
const pid = client.child?.pid;
|
|
665
|
-
const note = `the bridge stopped cursor-agent${pid ? ` (pid ${pid})` : ""} but
|
|
637
|
+
const note = `the bridge stopped cursor-agent${pid ? ` (pid ${pid})` : ""} but could not confirm that cursor-agent and its processes exited; they may still be running.`;
|
|
666
638
|
if (failure) failure.notes.push(` Note: ${note}`);
|
|
667
639
|
else if (out) (out.protocolWarnings ??= []).push(note);
|
|
668
|
-
try { onUnseenExit?.(note); } catch {}
|
|
669
640
|
}
|
|
670
641
|
}
|
|
671
642
|
// After teardown, so the exit note it adds is in the message.
|
package/src/doctor.js
CHANGED
|
@@ -2,14 +2,12 @@ import process from "node:process";
|
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { AcpClient } from "./acp-client.js";
|
|
4
4
|
import { commandExists, resolveAcpSpawn } from "./spawn.js";
|
|
5
|
-
import { children, spawnChild } from "./proc.js";
|
|
5
|
+
import { children, spawnChild, stopChild } from "./proc.js";
|
|
6
6
|
import { readPackageVersion } from "./version.js";
|
|
7
7
|
import { describeOptions } from "./model-options.js";
|
|
8
8
|
|
|
9
9
|
const HANDSHAKE_TIMEOUT_MS = 15_000;
|
|
10
10
|
const VERSION_PROBE_TIMEOUT_MS = 10_000;
|
|
11
|
-
const PROBE_STDOUT_CAP = 64 * 1024;
|
|
12
|
-
const DEFAULT_LOG_SIZE = "2000";
|
|
13
11
|
|
|
14
12
|
function formatArg(value) {
|
|
15
13
|
const s = String(value);
|
|
@@ -54,60 +52,35 @@ export function probeAgentVersion(spawnSpec, timeoutMs = VERSION_PROBE_TIMEOUT_M
|
|
|
54
52
|
// Interrupted already, or shutting down: nothing is spawned, and found comes from the lookup alone.
|
|
55
53
|
const notRun = (error) => Promise.resolve({ found: isJsScript ? existsSync(launcher) : commandExists(launcher, options?.env), version: null, error });
|
|
56
54
|
if (signal?.aborted) return notRun(aborted.error);
|
|
57
|
-
let
|
|
55
|
+
let child;
|
|
58
56
|
try {
|
|
59
|
-
|
|
57
|
+
child = spawnChild(execCommand, execArgs, options, { stdio: ["ignore", "pipe", "pipe"] }, registry);
|
|
60
58
|
} catch (err) {
|
|
61
59
|
return notRun(err.message);
|
|
62
60
|
}
|
|
63
|
-
const { child } = probe;
|
|
64
61
|
return new Promise((resolve) => {
|
|
65
|
-
let settled = false;
|
|
66
|
-
let aborting = false;
|
|
67
62
|
let stdout = "";
|
|
68
|
-
let timer;
|
|
69
63
|
const finish = (result) => {
|
|
70
|
-
if (settled) return;
|
|
71
|
-
settled = true;
|
|
72
64
|
clearTimeout(timer);
|
|
73
65
|
signal?.removeEventListener("abort", onAbort);
|
|
74
66
|
resolve(result);
|
|
75
67
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
aborting = true;
|
|
81
|
-
probe.stop().then(() => finish({ found: true, ...aborted }));
|
|
82
|
-
};
|
|
83
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
84
|
-
// Capped: a version is one line, and a launcher that streams is not kept whole.
|
|
85
|
-
child.stdout?.on("data", (chunk) => {
|
|
86
|
-
if (stdout.length < PROBE_STDOUT_CAP) stdout += chunk.toString();
|
|
87
|
-
});
|
|
88
|
-
// Drained: a full stderr pipe blocks the launcher, and a noisy one would read as wedged.
|
|
89
|
-
child.stderr?.on("data", () => {});
|
|
90
|
-
child.stderr?.on("error", () => {});
|
|
68
|
+
child.stdout.on("data", (chunk) => { stdout += chunk; });
|
|
69
|
+
// Drained: a full pipe blocks a noisy launcher, which would then read as a timeout.
|
|
70
|
+
child.stderr.on("data", () => {});
|
|
71
|
+
child.stderr.on("error", () => {});
|
|
91
72
|
child.on("error", () => finish({ found: false, version: null }));
|
|
92
|
-
child.on("close", (code) => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (aborting) return;
|
|
97
|
-
const version = code === 0 ? stdout.trim() || null : null;
|
|
98
|
-
finish({
|
|
99
|
-
found: true,
|
|
100
|
-
version,
|
|
101
|
-
...(code !== 0 ? { error: `version probe exited ${code}` } : {}),
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
timer = setTimeout(() => {
|
|
105
|
-
// Not awaited, so the timeout returns on time; the probe stays tracked until its stop settles.
|
|
106
|
-
probe.stop();
|
|
107
|
-
// It spawned, so it is found; it just never answered.
|
|
73
|
+
child.on("close", (code) => finish(code === 0 ? { found: true, version: stdout.trim() || null } : { found: true, version: null, error: `version probe exited ${code}` }));
|
|
74
|
+
// It spawned, so it is installed; it did not answer.
|
|
75
|
+
const timer = setTimeout(() => {
|
|
76
|
+
stopChild(child);
|
|
108
77
|
finish({ found: true, version: null, error: `version probe timed out after ${timeoutMs}ms` });
|
|
109
78
|
}, timeoutMs);
|
|
110
|
-
|
|
79
|
+
const onAbort = () => {
|
|
80
|
+
stopChild(child);
|
|
81
|
+
finish({ found: true, ...aborted });
|
|
82
|
+
};
|
|
83
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
111
84
|
});
|
|
112
85
|
}
|
|
113
86
|
|
|
@@ -210,13 +183,11 @@ export async function runDoctor({
|
|
|
210
183
|
transport: "stdio",
|
|
211
184
|
},
|
|
212
185
|
env: {
|
|
213
|
-
ACP_LOG_SIZE: envReport("ACP_LOG_SIZE", DEFAULT_LOG_SIZE),
|
|
214
186
|
ACP_AGENT_COMMAND: envReport("ACP_AGENT_COMMAND"),
|
|
215
187
|
ACP_AGENT_ARGS: envReport("ACP_AGENT_ARGS"),
|
|
216
188
|
CURSOR_DELEGATE_TRANSCRIPT: envReport("CURSOR_DELEGATE_TRANSCRIPT"),
|
|
217
189
|
CURSOR_DELEGATE_HANDSHAKE_MS: envReport("CURSOR_DELEGATE_HANDSHAKE_MS"),
|
|
218
190
|
CURSOR_DELEGATE_HARD_CAP_MS: envReport("CURSOR_DELEGATE_HARD_CAP_MS"),
|
|
219
|
-
CURSOR_DELEGATE_IDLE_MS: envReport("CURSOR_DELEGATE_IDLE_MS"),
|
|
220
191
|
},
|
|
221
192
|
};
|
|
222
193
|
|
package/src/errors.js
CHANGED
|
@@ -3,19 +3,20 @@
|
|
|
3
3
|
* without parsing prose. Errors off the wire also carry the agent's JSON-RPC `code`. A note goes on
|
|
4
4
|
* a new error with the old one as its `cause`: a caught error may be frozen or a primitive.
|
|
5
5
|
*
|
|
6
|
-
* @typedef {Error & { reason?: string, code?: number }} DelegateError
|
|
6
|
+
* @typedef {Error & { reason?: string, code?: number, method?: string }} DelegateError
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @param {string | undefined} reason
|
|
11
11
|
* @param {string} message
|
|
12
|
-
* @param {{ code?: number, cause?: unknown }} [extra]
|
|
12
|
+
* @param {{ code?: number, method?: string, cause?: unknown }} [extra]
|
|
13
13
|
* @returns {Readonly<DelegateError>}
|
|
14
14
|
*/
|
|
15
|
-
export function makeError(reason, message, { code, cause } = {}) {
|
|
15
|
+
export function makeError(reason, message, { code, method, cause } = {}) {
|
|
16
16
|
/** @type {DelegateError} */
|
|
17
17
|
const err = new Error(message, cause === undefined ? undefined : { cause });
|
|
18
18
|
if (reason !== undefined) err.reason = reason;
|
|
19
19
|
if (code !== undefined) err.code = code;
|
|
20
|
+
if (method !== undefined) err.method = method;
|
|
20
21
|
return err;
|
|
21
22
|
}
|