cursor-delegate-mcp 1.14.0 โ 1.16.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/README.md +4 -4
- package/package.json +1 -1
- package/src/acp-enums.js +6 -8
- package/src/delegate.js +65 -91
- package/src/doctor.js +3 -4
- package/src/server.js +39 -62
- package/src/turn-state.js +10 -12
- package/src/version.js +4 -5
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ You โ your agent (plans & reviews)
|
|
|
44
44
|
|
|
45
45
|
- ๐ค **Native plugins** โ install into Claude Code, ChatGPT/Codex, or GitHub Copilot CLI and just say *"delegate this to Cursor"*. The shared skill teaches your agent how to delegate well.
|
|
46
46
|
- ๐ฌ **No stalled runs** โ if Cursor needs to clarify, it ends the turn and returns the question as a normal result. Your agent reads it and answers by resuming the same session โ nothing blocks on a modal waiting for input.
|
|
47
|
-
- ๐ฆ **Clean,
|
|
47
|
+
- ๐ฆ **Clean, named results** โ final answer, changed files, session id, and the plan, returned as one compact JSON payload. Nothing to scrape, nothing to guess.
|
|
48
48
|
- ๐ **Plan first** โ `plan` mode: Cursor drafts a plan, you review it, then the same session implements it.
|
|
49
49
|
- ๐ **Ask anything** โ `ask` mode: read-only Q&A over your codebase, zero file changes.
|
|
50
50
|
- ๐ฉบ **Self-diagnosing** โ a `doctor` tool that tells you exactly what's missing if setup isn't right.
|
|
@@ -58,7 +58,7 @@ You need [Node.js 22+](https://nodejs.org/) and the [Cursor CLI](https://cursor.
|
|
|
58
58
|
|
|
59
59
|
```shell
|
|
60
60
|
/plugin marketplace add andreilungeanu/cursor-delegate-mcp
|
|
61
|
-
/plugin install cursor-delegate
|
|
61
|
+
/plugin install cursor-delegate@cursor-delegate-mcp
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
Then just ask:
|
|
@@ -71,7 +71,7 @@ That's the whole loop โ Claude writes the brief, Cursor grinds through the fil
|
|
|
71
71
|
|
|
72
72
|
```shell
|
|
73
73
|
codex plugin marketplace add andreilungeanu/cursor-delegate-mcp
|
|
74
|
-
codex plugin add cursor-delegate
|
|
74
|
+
codex plugin add cursor-delegate@cursor-delegate-mcp
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
### GitHub Copilot CLI
|
|
@@ -164,4 +164,4 @@ Add the following server to the client's MCP config:
|
|
|
164
164
|
|
|
165
165
|
MIT ยฉ [Andrei Lungeanu](https://github.com/andreilungeanu)
|
|
166
166
|
|
|
167
|
-
<sub>[Security](SECURITY.md) ยท [Privacy](PRIVACY.md) ยท [Terms](TERMS.md) ยท [Changelog](CHANGELOG.md)</sub>
|
|
167
|
+
<sub>[Technical reference](TECHNICAL.md) ยท [Security](SECURITY.md) ยท [Privacy](PRIVACY.md) ยท [Terms](TERMS.md) ยท [Changelog](CHANGELOG.md)</sub>
|
package/package.json
CHANGED
package/src/acp-enums.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
// The value sets ACP allows for plan and todo fields
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// one it strips.
|
|
1
|
+
// The value sets ACP allows for plan and todo fields, shared by the two layers that read them:
|
|
2
|
+
// the sanitizers in delegate.js, which strip anything else off an agent frame, and the zod
|
|
3
|
+
// schemas in server.js, which advertise them to hosts. A drift between the two would strip a
|
|
4
|
+
// value the tool documents, or document one it strips.
|
|
6
5
|
//
|
|
7
|
-
// Plan status and todo status
|
|
8
|
-
//
|
|
9
|
-
// couple two things that are free to diverge.
|
|
6
|
+
// Plan status and todo status carry the same three values today but stay separate constants:
|
|
7
|
+
// ACP treats them as separate enums and they are free to diverge.
|
|
10
8
|
|
|
11
9
|
export const PLAN_PRIORITIES = /** @type {const} */ (["high", "medium", "low"]);
|
|
12
10
|
|
package/src/delegate.js
CHANGED
|
@@ -2,9 +2,9 @@ import process from "node:process";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
import { statSync } from "node:fs";
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
5
|
+
// Async: a sync read on the server's only thread stalls every other in-flight delegation and
|
|
6
|
+
// its progress stream. The statSync calls below stay sync โ they are argument validation and
|
|
7
|
+
// run before the spawn.
|
|
8
8
|
import { readFile } from "node:fs/promises";
|
|
9
9
|
import { AcpClient } from "./acp-client.js";
|
|
10
10
|
import { SessionSupervisor } from "./session-supervisor.js";
|
|
@@ -17,11 +17,9 @@ export const DEFAULT_MODEL = "composer-2.5";
|
|
|
17
17
|
export const DEFAULT_HANDSHAKE_MS = 60000;
|
|
18
18
|
export const DEFAULT_HEARTBEAT_MS = 30000;
|
|
19
19
|
|
|
20
|
-
// Malformed values fall back to the default rather than failing the call. Only a positive
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
// every call instantly. Falling back keeps the one documented meaning of 0, the idle guard's,
|
|
24
|
-
// which gets it from its own fallback being 0.
|
|
20
|
+
// Malformed values fall back to the default rather than failing the call. Only a positive value
|
|
21
|
+
// counts, so a blank var (Number("") is 0) cannot arm a zero-length deadline. The idle guard's
|
|
22
|
+
// documented 0 comes from its own fallback being 0, not from an env value.
|
|
25
23
|
function envMs(name, fallback) {
|
|
26
24
|
const raw = process.env[name];
|
|
27
25
|
if (raw === undefined) return fallback;
|
|
@@ -34,11 +32,9 @@ function fmtDuration(ms) {
|
|
|
34
32
|
return s < 60 ? `${s}s` : `${Math.floor(s / 60)}m${String(s % 60).padStart(2, "0")}s`;
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
// Two
|
|
38
|
-
// "
|
|
39
|
-
//
|
|
40
|
-
// mentions files ("fix the bug in src/api.js") and must never be rejected for it. Whitespace
|
|
41
|
-
// is the discriminator: a path argument has none, a sentence about a path does.
|
|
35
|
+
// Two separate questions. "Could this be a path?" is loose โ worth a stat. "Was a path clearly
|
|
36
|
+
// intended?" must be strict, since ordinary prose names files ("fix the bug in src/api.js") and
|
|
37
|
+
// must never be rejected for it. Whitespace discriminates: a path argument has none.
|
|
42
38
|
function looksLikeSpecPath(spec) {
|
|
43
39
|
return !spec.includes("\n")
|
|
44
40
|
&& (spec.includes("/") || spec.includes("\\") || spec.endsWith(".md") || spec.endsWith(".txt"));
|
|
@@ -69,9 +65,8 @@ async function resolveSpec(spec) {
|
|
|
69
65
|
return spec;
|
|
70
66
|
}
|
|
71
67
|
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
// always rejected the same mistakes; this is that check, applied to its sibling.
|
|
68
|
+
// Without this, the agent's first write creates the directory: a typo'd workspace spawns a
|
|
69
|
+
// parallel empty tree and every layer reports success. Same check contextFiles applies.
|
|
75
70
|
function assertWorkspace(workspace) {
|
|
76
71
|
if (workspace === undefined || workspace === null) return;
|
|
77
72
|
let stat;
|
|
@@ -92,18 +87,15 @@ const IMAGE_MIME = {
|
|
|
92
87
|
// Base64 inflates by a third and every byte lands in the prompt, unlike a link.
|
|
93
88
|
const MAX_IMAGE_BYTES = 5 * 1024 * 1024;
|
|
94
89
|
|
|
95
|
-
// A resource_link hands the agent a path
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
//
|
|
99
|
-
//
|
|
100
|
-
//
|
|
101
|
-
// image would silently vanish;
|
|
102
|
-
// - report anything skipped, since a dropped attachment is otherwise invisible.
|
|
90
|
+
// A resource_link hands the agent a path, not the file's bytes, so a large brief costs prompt
|
|
91
|
+
// space only for what the agent opens. Images have no such form โ they go inline. Both are
|
|
92
|
+
// measured working, including links outside the workspace. Two rules from that probe:
|
|
93
|
+
// - gate images on the advertised capability: cursor-agent accepts unsupported blocks without
|
|
94
|
+
// error (embeddedContext:false raises nothing), so an ungated image vanishes silently;
|
|
95
|
+
// - report anything skipped โ a dropped attachment is otherwise invisible.
|
|
103
96
|
async function buildContextBlocks(contextFiles, workspace, client, warnings) {
|
|
104
97
|
const blocks = [];
|
|
105
|
-
// A glob plus an explicit path
|
|
106
|
-
// sending it several times just wastes prompt space. Collapse by resolved absolute path.
|
|
98
|
+
// A glob plus an explicit path can resolve to one file; sending it twice wastes prompt space.
|
|
107
99
|
const seen = new Set();
|
|
108
100
|
for (const entry of contextFiles || []) {
|
|
109
101
|
if (typeof entry !== "string" || !entry.trim()) continue;
|
|
@@ -163,14 +155,11 @@ function assertKnownModel(client, model) {
|
|
|
163
155
|
throw makeError("unknown-model", `Unknown model ${JSON.stringify(model)}. This agent offers: ${ids.join(", ")}.`);
|
|
164
156
|
}
|
|
165
157
|
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
//
|
|
171
|
-
// Returns { unsupported, res }: unsupported is true when the model has no such knob; res is the
|
|
172
|
-
// set_config_option reply, which echoes the now-current model's configOptions (incl. the served
|
|
173
|
-
// model id) โ the only place the agent reports what model actually took after set_model.
|
|
158
|
+
// A model's config options are not discoverable up front (session/new reports only the default
|
|
159
|
+
// model's; set_model returns nothing), so probe by asking and read the rejection. Both -32602s
|
|
160
|
+
// are measured: "Unknown model config option: X" means no such knob โ report and carry on;
|
|
161
|
+
// "Invalid value for X: Y" is a caller error and must propagate.
|
|
162
|
+
// res echoes the now-current model's configOptions โ the only place the served model id appears.
|
|
174
163
|
async function applyConfig(client, sessionId, configId, value) {
|
|
175
164
|
try {
|
|
176
165
|
const res = await client.setConfigOption(sessionId, configId, value);
|
|
@@ -181,9 +170,8 @@ async function applyConfig(client, sessionId, configId, value) {
|
|
|
181
170
|
}
|
|
182
171
|
}
|
|
183
172
|
|
|
184
|
-
// The
|
|
185
|
-
//
|
|
186
|
-
// every option we send, which is fine โ the field then stays off.
|
|
173
|
+
// The resolved model appears only in a set_config_option reply's configOptions (set_model
|
|
174
|
+
// returns nothing). Absent for models that reject every option sent โ the field then stays off.
|
|
187
175
|
function servedModelFrom(res) {
|
|
188
176
|
const opts = res?.configOptions;
|
|
189
177
|
if (!Array.isArray(opts)) return undefined;
|
|
@@ -213,8 +201,7 @@ export async function runDelegate({
|
|
|
213
201
|
if (signal?.aborted) {
|
|
214
202
|
throw makeError("aborted", "delegation aborted by MCP host");
|
|
215
203
|
}
|
|
216
|
-
// Before the spawn:
|
|
217
|
-
// a handshake and a billed turn if it waits until the prompt is assembled.
|
|
204
|
+
// Before the spawn: validating later costs a process, a handshake and a billed turn.
|
|
218
205
|
assertWorkspace(workspace);
|
|
219
206
|
const promptText = await resolveSpec(spec);
|
|
220
207
|
const capMs = hardCapMs ?? timeoutMs ?? envMs("CURSOR_DELEGATE_HARD_CAP_MS", 3600000);
|
|
@@ -222,9 +209,8 @@ export async function runDelegate({
|
|
|
222
209
|
const turnIdleMs = idleMs ?? envMs("CURSOR_DELEGATE_IDLE_MS", 0);
|
|
223
210
|
const state = makeTurnState({ onProgress, progressThrottleMs });
|
|
224
211
|
|
|
225
|
-
// ACP requires plan
|
|
226
|
-
//
|
|
227
|
-
// work is done โ drop the bad data and report it as a protocol diagnostic.
|
|
212
|
+
// ACP requires string plan content and bounds priority/status. A frame that violates that must
|
|
213
|
+
// not fail the MCP call after the work is done โ drop the bad data, report it as a diagnostic.
|
|
228
214
|
const sanitizePlan = (warnings) => {
|
|
229
215
|
const entries = [];
|
|
230
216
|
state.planEntries.forEach((raw, i) => {
|
|
@@ -308,20 +294,19 @@ export async function runDelegate({
|
|
|
308
294
|
heartbeat.unref?.();
|
|
309
295
|
};
|
|
310
296
|
|
|
311
|
-
// session/load replays the previous turn as ordinary
|
|
312
|
-
//
|
|
313
|
-
//
|
|
314
|
-
// otherwise reports the previous turn's tool calls and edits as if they were happening.
|
|
297
|
+
// session/load replays the previous turn as ordinary update frames, tool_call and diff blocks
|
|
298
|
+
// included. state.reset() clears what they touch but cannot unsend a progress notification, so
|
|
299
|
+
// the guard below is what stops a resume reporting last turn's edits as if they were happening.
|
|
315
300
|
client.on("update", (u) => {
|
|
316
301
|
if (!promptInFlight) return;
|
|
317
302
|
const up = u?.update || {};
|
|
318
303
|
if (up.sessionUpdate === "plan") {
|
|
319
304
|
state.planEntries = up.entries || [];
|
|
320
305
|
}
|
|
321
|
-
// The agent
|
|
322
|
-
//
|
|
323
|
-
//
|
|
324
|
-
//
|
|
306
|
+
// The agent titles the turn a beat after the prompt lands ("File Creator") โ useful live,
|
|
307
|
+
// when several delegations run, and in timeout forensics. Kept out of the result: there it
|
|
308
|
+
// arrives too late to tell anything apart, and was measured contradicting the answer
|
|
309
|
+
// ("No Image Detected" on a turn describing an image).
|
|
325
310
|
if (up.sessionUpdate === "session_info_update" && typeof up.title === "string" && up.title) {
|
|
326
311
|
if (up.title !== state.sessionTitle) { try { onProgress?.(`turn titled: ${up.title}`.slice(0, 200)); } catch {} }
|
|
327
312
|
state.sessionTitle = up.title;
|
|
@@ -368,9 +353,9 @@ export async function runDelegate({
|
|
|
368
353
|
onSessionReady?.(sessionId, client);
|
|
369
354
|
assertKnownModel(client, model);
|
|
370
355
|
await client.setModel(sessionId, model);
|
|
371
|
-
// fast is always sent
|
|
372
|
-
// instruction. reasoning and context
|
|
373
|
-
//
|
|
356
|
+
// fast is always sent โ a resumed session may already have it on, so false is a real
|
|
357
|
+
// instruction. reasoning and context go only when the caller named one. Each reply reports
|
|
358
|
+
// the now-current model; the last one seen wins.
|
|
374
359
|
const fastResult = await applyConfig(client, sessionId, "fast", fast);
|
|
375
360
|
if (fastResult.unsupported && fast) unsupportedOptions.push("fast");
|
|
376
361
|
else servedModel = servedModelFrom(fastResult.res) ?? servedModel;
|
|
@@ -390,9 +375,8 @@ export async function runDelegate({
|
|
|
390
375
|
const blocks = await buildContextBlocks(contextFiles, workspace, client, contextWarnings);
|
|
391
376
|
return await client.prompt(sessionId, [{ type: "text", text: promptText }, ...blocks]);
|
|
392
377
|
} finally {
|
|
393
|
-
// The result is assembled across awaits below, so
|
|
394
|
-
//
|
|
395
|
-
// frames session/load replays before it.
|
|
378
|
+
// The result is assembled across awaits below, so without this a frame trailing the
|
|
379
|
+
// settled turn is still folded into it.
|
|
396
380
|
promptInFlight = false;
|
|
397
381
|
}
|
|
398
382
|
});
|
|
@@ -404,12 +388,11 @@ export async function runDelegate({
|
|
|
404
388
|
? (state.sawToolCall ? "post-tool" : "tool-free-stream")
|
|
405
389
|
: "none";
|
|
406
390
|
const protocolWarnings = [];
|
|
407
|
-
// plan.detail
|
|
408
|
-
//
|
|
409
|
-
//
|
|
410
|
-
//
|
|
411
|
-
//
|
|
412
|
-
// agent mode the plan was accepted and result is the implementation report โ both stay.
|
|
391
|
+
// plan.detail restates, in chat's sibling channel, a plan also filed via create_plan. It is
|
|
392
|
+
// never load-bearing: a resume-to-implement reads the agent's own session, and the
|
|
393
|
+
// orchestrator approves from result + plan.entries. So plan/ask drops it and leaves result as
|
|
394
|
+
// the agent's message verbatim. In agent mode result is the implementation report, a separate
|
|
395
|
+
// artifact from the plan โ both stay.
|
|
413
396
|
const dropPlanDetail = typeof state.planDetail === "string" && (mode === "plan" || mode === "ask");
|
|
414
397
|
if (!finalMessageAvailable && state.discardedResult) {
|
|
415
398
|
result = state.discardedResult;
|
|
@@ -426,9 +409,8 @@ export async function runDelegate({
|
|
|
426
409
|
if (typeof res.stopReason !== "string") {
|
|
427
410
|
protocolWarnings.push("stopReason dropped: ACP requires a string stop reason");
|
|
428
411
|
} else if (res.stopReason !== "end_turn") {
|
|
429
|
-
// end_turn
|
|
430
|
-
//
|
|
431
|
-
// happened: a refusal, a cancel, an output cap. Absence means the ordinary end_turn.
|
|
412
|
+
// end_turn carries no signal (it was end_turn on every stress-test call). Surface a stop
|
|
413
|
+
// reason only when something happened: a refusal, a cancel, an output cap.
|
|
432
414
|
stopReason = res.stopReason;
|
|
433
415
|
}
|
|
434
416
|
}
|
|
@@ -436,16 +418,13 @@ export async function runDelegate({
|
|
|
436
418
|
result,
|
|
437
419
|
sessionId,
|
|
438
420
|
};
|
|
439
|
-
//
|
|
440
|
-
//
|
|
441
|
-
// (shell-driven edits leave no diff event).
|
|
421
|
+
// Absence means "nothing reported", not "nothing changed" โ a claim this field cannot make,
|
|
422
|
+
// since shell-driven edits leave no diff event.
|
|
442
423
|
const filesReported = normalizeAgentReportedFiles([...state.touched], workspace);
|
|
443
424
|
if (filesReported.length) out.filesReportedByEditTools = filesReported;
|
|
444
|
-
// resultSource is a caveat, not a fact
|
|
445
|
-
//
|
|
446
|
-
//
|
|
447
|
-
// stated the same thing in a second boolean. resumed is emitted only when a resume actually
|
|
448
|
-
// took; a fresh session or a failed resume (which carries its own warning) leaves it absent.
|
|
425
|
+
// resultSource is a caveat, not a fact: on the happy path (post-tool / tool-free-stream)
|
|
426
|
+
// result is just the answer. Emit it only when it warns. resumed likewise appears only when a
|
|
427
|
+
// resume took โ a fresh session or a failed one (which carries its own warning) leaves it off.
|
|
449
428
|
if (resultSource !== "post-tool" && resultSource !== "tool-free-stream") out.resultSource = resultSource;
|
|
450
429
|
if (!!resumeSessionId && sessionId === resumeSessionId) out.resumed = true;
|
|
451
430
|
// Only when the agent served a different model than asked โ e.g. "default" routing to a
|
|
@@ -463,10 +442,9 @@ export async function runDelegate({
|
|
|
463
442
|
// duplicate โ drop it. entries and overview are structured and unique, and always stay.
|
|
464
443
|
if (dropPlanDetail) delete out.plan.detail;
|
|
465
444
|
}
|
|
466
|
-
// Most
|
|
467
|
-
//
|
|
468
|
-
//
|
|
469
|
-
// remain. On a fully-completed turn the list restates the counts entry by entry.
|
|
445
|
+
// Most turns emit no todos, so an empty list would read as "nothing done" rather than "not
|
|
446
|
+
// tracked". The full list is carried only when it says what todoProgress cannot โ which items
|
|
447
|
+
// remain; on a fully-completed turn it just restates the counts.
|
|
470
448
|
if (state.sawTodoFrame) {
|
|
471
449
|
const { todos: todoList, todoProgress } = sanitizeTodos(protocolWarnings);
|
|
472
450
|
out.todoProgress = todoProgress;
|
|
@@ -475,17 +453,15 @@ export async function runDelegate({
|
|
|
475
453
|
if (protocolWarnings.length) out.protocolWarnings = protocolWarnings;
|
|
476
454
|
return out;
|
|
477
455
|
} catch (err) {
|
|
478
|
-
// A JSON-RPC code means the agent rejected something rather than the bridge breaking
|
|
479
|
-
//
|
|
456
|
+
// A JSON-RPC code means the agent rejected something rather than the bridge breaking โ the
|
|
457
|
+
// distinction a caller needs to tell "fix your arguments" from "retry".
|
|
480
458
|
if (!err?.reason && typeof err?.code === "number") err.reason = "agent-error";
|
|
481
|
-
// A bare duration
|
|
482
|
-
//
|
|
483
|
-
// retry can resume from the work already done instead of restarting blind.
|
|
459
|
+
// A bare duration cannot distinguish a wedged agent from a slow command, so name what was
|
|
460
|
+
// outstanding โ it also lets a retry resume the work already done.
|
|
484
461
|
const isTimeout = err?.reason === "hard-cap" || err?.reason === "idle-timeout";
|
|
485
|
-
// A handshake timeout gets the forensics but not the long-command advice
|
|
486
|
-
// session
|
|
487
|
-
// any of which can hang
|
|
488
|
-
// ever sent, so no shell command can be the reason for the silence.
|
|
462
|
+
// A handshake timeout gets the forensics but not the long-command advice: no prompt was sent,
|
|
463
|
+
// so no shell command explains the silence. The session may still exist (it is set before
|
|
464
|
+
// set_model/set_config_option/set_mode, any of which can hang), so the resume hint applies.
|
|
489
465
|
const isStall = isTimeout || err?.reason === "handshake-timeout";
|
|
490
466
|
if (isStall || err?.reason === "aborted" || err?.reason === "agent-exit") {
|
|
491
467
|
const age = fmtDuration(supervisor.msSinceActivity());
|
|
@@ -500,7 +476,7 @@ export async function runDelegate({
|
|
|
500
476
|
const files = normalizeAgentReportedFiles([...state.touched], workspace);
|
|
501
477
|
if (files.length) err.message += ` Files reported edited: ${files.join(", ")}.`;
|
|
502
478
|
// Without this the resume hint below reads as "carry on from where you were", when the
|
|
503
|
-
// requested session was never loaded
|
|
479
|
+
// requested session was never loaded.
|
|
504
480
|
if (resumeError) {
|
|
505
481
|
err.message += ` Note: resuming ${resumeSessionId} had already failed (${resumeError}),`
|
|
506
482
|
+ ` so this ran as a fresh session and none of that earlier work was in context.`;
|
|
@@ -514,10 +490,8 @@ export async function runDelegate({
|
|
|
514
490
|
+ ` nothing until it exits. Split the command, run it in the background and poll, or raise ${knob}.`;
|
|
515
491
|
}
|
|
516
492
|
}
|
|
517
|
-
// Opt-in
|
|
518
|
-
//
|
|
519
|
-
// frames only help someone debugging the bridge, and that has always been done with a
|
|
520
|
-
// protocol probe, never with an error dump.
|
|
493
|
+
// Opt-in: the frames land in the caller's context and nothing there is actionable โ the
|
|
494
|
+
// forensics above already carry that. Raw frames only help someone debugging the bridge.
|
|
521
495
|
const frames = Number(process.env.CURSOR_DELEGATE_TRANSCRIPT);
|
|
522
496
|
if (frames > 0) {
|
|
523
497
|
try {
|
package/src/doctor.js
CHANGED
|
@@ -13,10 +13,9 @@ function formatCommand({ command, args }) {
|
|
|
13
13
|
return args?.length ? `${command} ${args.join(" ")}` : command;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
//
|
|
17
|
-
// doctor is
|
|
18
|
-
// the case it
|
|
19
|
-
// applied to the shallow probe that runs on every call.
|
|
16
|
+
// Time-boxed because a launcher that accepts --version and then never answers would hang doctor
|
|
17
|
+
// forever โ and doctor is what you run when delegation is already broken, so a wedged agent is
|
|
18
|
+
// exactly the case it must survive. Same guard the deep handshake has.
|
|
20
19
|
export function probeAgentVersion(spawnSpec, timeoutMs = VERSION_PROBE_TIMEOUT_MS) {
|
|
21
20
|
const { command, options } = spawnSpec;
|
|
22
21
|
const isJsScript = /\.js$/i.test(command);
|
package/src/server.js
CHANGED
|
@@ -54,46 +54,34 @@ const planEntrySchema = z.object({
|
|
|
54
54
|
status: z.enum(PLAN_STATUSES).optional(),
|
|
55
55
|
}).passthrough();
|
|
56
56
|
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
//
|
|
57
|
+
// Deliberately not declared to hosts as an outputSchema: declaring one obliges the server to
|
|
58
|
+
// also return structuredContent, and a host that reads both it and the text block โ Codex does โ
|
|
59
|
+
// puts the whole payload in the model's context twice. So this is an in-repo contract instead,
|
|
60
|
+
// enforced by the .strict() copy in delegate.test.js, which fails when a field added in
|
|
61
|
+
// delegate.js is forgotten here.
|
|
62
|
+
//
|
|
63
|
+
// Types only. What each field means, and what its absence means, is documented once in
|
|
64
|
+
// skills/delegate/reference.md.
|
|
61
65
|
export const delegateOutputShape = {
|
|
62
66
|
result: z.string(),
|
|
63
|
-
resultSource: z.enum(["pre-tool-fallback", "none"]).optional()
|
|
64
|
-
|
|
65
|
-
),
|
|
66
|
-
effectiveModel: z.string().optional().describe(
|
|
67
|
-
"The model id the agent reported serving, present only when it differs from the model you requested โ e.g. \"default\" resolving to a concrete id, or a cross-model resume. Read from the agent's post-set_model config report; absent when the agent confirmed the requested id or reported no model (some models report none)."
|
|
68
|
-
),
|
|
69
|
-
stopReason: z.string().optional().describe(
|
|
70
|
-
"Present only when it is not the ordinary end_turn โ a refusal, a cancel, or an output cap. Absence means the turn ended normally."
|
|
71
|
-
),
|
|
67
|
+
resultSource: z.enum(["pre-tool-fallback", "none"]).optional(),
|
|
68
|
+
effectiveModel: z.string().optional(),
|
|
69
|
+
stopReason: z.string().optional(),
|
|
72
70
|
sessionId: z.string(),
|
|
73
|
-
filesReportedByEditTools: z.array(z.string()).optional()
|
|
74
|
-
|
|
75
|
-
),
|
|
76
|
-
resumed: z.boolean().optional().describe(
|
|
77
|
-
"Present and true only when a requested resume took (the returned session id matched resumeSessionId). Absent for a fresh session, or when a resume failed โ a failed resume is reported in protocolWarnings."
|
|
78
|
-
),
|
|
71
|
+
filesReportedByEditTools: z.array(z.string()).optional(),
|
|
72
|
+
resumed: z.boolean().optional(),
|
|
79
73
|
cancelRequested: z.boolean().optional(),
|
|
80
|
-
protocolWarnings: z.array(z.string()).optional()
|
|
81
|
-
"Non-fatal diagnostics that did not justify failing the call โ dropped or sanitized ACP fields, a failed resume, ignored model options, skipped contextFiles. Read whenever present."
|
|
82
|
-
),
|
|
74
|
+
protocolWarnings: z.array(z.string()).optional(),
|
|
83
75
|
plan: z.object({
|
|
84
76
|
entries: z.array(planEntrySchema),
|
|
85
77
|
overview: z.string().optional(),
|
|
86
78
|
detail: z.string().optional(),
|
|
87
|
-
}).optional()
|
|
88
|
-
"The agent's plan. entries and overview are the structured plan and always present when a plan exists. detail (a prose rendition the agent also filed) is kept only in agent mode; in plan/ask it is dropped because result already carries the agent's own plan message. To act on a plan, resume the sessionId rather than forwarding detail: the plan lives in the agent's session."
|
|
89
|
-
),
|
|
79
|
+
}).optional(),
|
|
90
80
|
todos: z.array(z.object({
|
|
91
81
|
id: z.string(),
|
|
92
82
|
content: z.string(),
|
|
93
83
|
status: z.enum(TODO_STATUSES).optional(),
|
|
94
|
-
})).optional()
|
|
95
|
-
"Todo items the agent left unfinished, present only when todoProgress shows completed < total โ read it to see what remains before resuming. Absent both when the agent tracked no todos (common on short tasks) and when everything tracked was completed; todoProgress tells those apart."
|
|
96
|
-
),
|
|
84
|
+
})).optional(),
|
|
97
85
|
todoProgress: z.object({
|
|
98
86
|
total: z.number(),
|
|
99
87
|
completed: z.number(),
|
|
@@ -102,32 +90,28 @@ export const delegateOutputShape = {
|
|
|
102
90
|
}).optional(),
|
|
103
91
|
};
|
|
104
92
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
// What doctor reports about the launcher. Only `found` was advertised before, so `command`,
|
|
108
|
-
// `version`, `error` and the whole deep handshake reached hosts undeclared โ the same drift
|
|
109
|
-
// delegateOutputShape exists to prevent, one level further down.
|
|
93
|
+
// What doctor reports about the launcher โ the same in-repo contract as delegateOutputShape.
|
|
110
94
|
//
|
|
111
|
-
// Fields this bridge computes are typed; fields relayed verbatim from the agent are left
|
|
112
|
-
//
|
|
113
|
-
//
|
|
114
|
-
//
|
|
95
|
+
// Fields this bridge computes are typed; fields relayed verbatim from the agent are left unknown
|
|
96
|
+
// on purpose. doctor runs when the agent is already misbehaving, so a schema tight enough to
|
|
97
|
+
// reject a weird protocolVersion would fail on the agent's output rather than on ours.
|
|
98
|
+
// doctor.test.js parses every result against a strict copy of this shape.
|
|
99
|
+
//
|
|
100
|
+
// Types only; what the fields mean is documented once, in TECHNICAL.md.
|
|
115
101
|
export const doctorAgentShape = {
|
|
116
|
-
found: z.boolean()
|
|
117
|
-
command: z.string()
|
|
118
|
-
version: z.string().nullable()
|
|
119
|
-
|
|
120
|
-
),
|
|
121
|
-
error: z.string().optional().describe("Why version is null on a launcher that does exist, e.g. the probe timed out."),
|
|
102
|
+
found: z.boolean(),
|
|
103
|
+
command: z.string(),
|
|
104
|
+
version: z.string().nullable(),
|
|
105
|
+
error: z.string().optional(),
|
|
122
106
|
handshake: z.object({
|
|
123
107
|
ok: z.boolean(),
|
|
124
|
-
error: z.string().optional()
|
|
125
|
-
protocolVersion: z.unknown().optional()
|
|
108
|
+
error: z.string().optional(),
|
|
109
|
+
protocolVersion: z.unknown().optional(),
|
|
126
110
|
agentCapabilities: z.unknown().optional(),
|
|
127
|
-
models: z.array(z.unknown()).optional()
|
|
111
|
+
models: z.array(z.unknown()).optional(),
|
|
128
112
|
currentModel: z.unknown().optional(),
|
|
129
|
-
modes: z.array(z.unknown()).optional()
|
|
130
|
-
}).passthrough().optional()
|
|
113
|
+
modes: z.array(z.unknown()).optional(),
|
|
114
|
+
}).passthrough().optional(),
|
|
131
115
|
};
|
|
132
116
|
|
|
133
117
|
// Exported as a shape for the same reason as delegateOutputShape, and with agent split out
|
|
@@ -151,8 +135,6 @@ export const doctorOutputShape = {
|
|
|
151
135
|
env: z.record(z.unknown()),
|
|
152
136
|
};
|
|
153
137
|
|
|
154
|
-
const doctorOutputSchema = z.object(doctorOutputShape).passthrough();
|
|
155
|
-
|
|
156
138
|
export const delegateInputSchema = z.object({
|
|
157
139
|
spec: z.string().trim().min(1, "spec must not be blank").describe("Inline task brief (default): goal, scope, decisions already made (constraints and fixed choices โ quote the user's exact values verbatim), acceptance criteria. Point at files to read or mimic rather than pasting code. Optional file path if the user wants a persisted spec."),
|
|
158
140
|
mode: z.enum(["agent", "plan", "ask"]).default("agent").describe("Requested agent mode. plan and ask are passed to the agent as instructions, not enforced by the bridge โ the agent may write in any of them, so review the git diff after every run. ask held on every model tested while plan compliance varies by model, so prefer ask when you need the stricter read-only instruction."),
|
|
@@ -222,10 +204,9 @@ export async function runDelegateTool({ args, extra, runDelegate, inFlight, seen
|
|
|
222
204
|
},
|
|
223
205
|
});
|
|
224
206
|
if (handle?.cancelRequested) out.cancelRequested = true;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
};
|
|
207
|
+
// One copy, compact. The result also went out as structuredContent while an outputSchema
|
|
208
|
+
// was declared, which cost every host that reads both fields the whole payload twice.
|
|
209
|
+
return { content: [{ type: "text", text: JSON.stringify(out) }] };
|
|
229
210
|
} catch (err) {
|
|
230
211
|
return {
|
|
231
212
|
// The reason is already decided upstream; naming it here saves the caller parsing
|
|
@@ -261,7 +242,6 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
261
242
|
description:
|
|
262
243
|
`Delegate a coding task to cursor-agent over ACP. Never shell out to cursor-agent โ use this tool only. Pass structured task text inline in spec (default); a file path is optional when the user wants a persisted brief. Defaults: mode=agent, model=${DEFAULT_MODEL}, fast=false. Plan workflow: mode=plan, then resume with mode=agent and resumeSessionId. Auto-approves every permission the agent requests, in any mode and anywhere on disk. Clarifying questions arrive as prose in result โ resume with resumeSessionId to answer. Returns the final result, selection source, stop reason, session ID, agent-reported files, and optional plan. See the delegate skill for orchestration.`,
|
|
263
244
|
inputSchema: delegateInputSchema,
|
|
264
|
-
outputSchema: delegateOutputSchema,
|
|
265
245
|
annotations: {
|
|
266
246
|
title: "Delegate coding task to Cursor",
|
|
267
247
|
readOnlyHint: false,
|
|
@@ -294,8 +274,8 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
294
274
|
async ({ sessionId, force }) => {
|
|
295
275
|
const handles = inFlight.get(sessionId);
|
|
296
276
|
if (!handles || handles.size === 0) {
|
|
297
|
-
// A finished session and a garbage id
|
|
298
|
-
// read as "bad id" for a session that
|
|
277
|
+
// A finished session and a garbage id are both "not in flight". Reporting them alike
|
|
278
|
+
// would read as "bad id" for a session that ran and is still resumable.
|
|
299
279
|
const known = seenSessions.has(sessionId);
|
|
300
280
|
return {
|
|
301
281
|
content: [{ type: "text", text: known
|
|
@@ -346,7 +326,6 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
346
326
|
.default(false)
|
|
347
327
|
.describe("When true, run a lightweight ACP handshake (start โ initialize โ newSession) to verify the agent is usable"),
|
|
348
328
|
},
|
|
349
|
-
outputSchema: doctorOutputSchema,
|
|
350
329
|
annotations: {
|
|
351
330
|
title: "Diagnose Cursor delegation setup",
|
|
352
331
|
readOnlyHint: true,
|
|
@@ -363,10 +342,8 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
363
342
|
version: server.server.getClientVersion(),
|
|
364
343
|
}),
|
|
365
344
|
});
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
structuredContent: out,
|
|
369
|
-
};
|
|
345
|
+
// Single compact copy, for the reason runDelegateTool returns one.
|
|
346
|
+
return { content: [{ type: "text", text: JSON.stringify(out) }] };
|
|
370
347
|
}
|
|
371
348
|
);
|
|
372
349
|
|
package/src/turn-state.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
// Everything
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// one place now, freshFields(), which is also what reset() applies.
|
|
1
|
+
// Everything describing the turn in progress, in one object because it has to be wiped as one:
|
|
2
|
+
// session/load replays the previous turn as ordinary update frames, so anything left behind
|
|
3
|
+
// leaks into the next result. Fields are declared in exactly one place, freshFields(), which is
|
|
4
|
+
// also what reset() applies โ a field added there is reset for free, and one that is missed is a
|
|
5
|
+
// silent stale-data bug on resume.
|
|
7
6
|
|
|
8
7
|
const MAX_OUTPUT = 10 * 1024 * 1024;
|
|
9
8
|
const TRUNCATION_MARKER = "\n\n[output truncated at 10MB]";
|
|
@@ -55,18 +54,17 @@ function progressStream(prefix, onProgress, throttleMs) {
|
|
|
55
54
|
};
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
// The single declaration of what a turn accumulates.
|
|
57
|
+
// The single declaration of what a turn accumulates.
|
|
59
58
|
function freshFields() {
|
|
60
59
|
return {
|
|
61
60
|
resultChunks: [],
|
|
62
61
|
resultLength: 0,
|
|
63
62
|
truncated: false,
|
|
64
63
|
// Text superseded by a later tool call is normally a preamble ("Inspecting the
|
|
65
|
-
// implementation.")
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
// survived โ labelled, never blended with a real final message.
|
|
64
|
+
// implementation."), but the rule cannot tell a preamble from the whole answer: an agent
|
|
65
|
+
// that replies and then runs one more command has its entire reply discarded, leaving the
|
|
66
|
+
// caller "" with stopReason end_turn and no error. Kept so it can be handed back when
|
|
67
|
+
// nothing survived โ labelled, never blended with a real final message.
|
|
70
68
|
discardedResult: "",
|
|
71
69
|
sawToolCall: false,
|
|
72
70
|
collectingPostToolResult: false,
|
package/src/version.js
CHANGED
|
@@ -11,11 +11,10 @@ function readVersion() {
|
|
|
11
11
|
// Captured once, for the ACP/MCP identity handshake that is sent at connect and never re-read.
|
|
12
12
|
export const VERSION = readVersion();
|
|
13
13
|
|
|
14
|
-
// doctor
|
|
15
|
-
// does not restart it, so a version captured at process start goes stale after
|
|
16
|
-
// upgrade โ exactly when
|
|
17
|
-
//
|
|
18
|
-
// un-restarted child running old code, where no in-process value can be authoritative anyway.
|
|
14
|
+
// doctor reads fresh rather than using the constant: the MCP child is long-lived and
|
|
15
|
+
// /reload-plugins does not restart it, so a version captured at process start goes stale after
|
|
16
|
+
// an in-place upgrade โ exactly when doctor is run to confirm the new version shipped. An
|
|
17
|
+
// un-restarted child running old code stays a gap, but no in-process value can close that.
|
|
19
18
|
export function readPackageVersion() {
|
|
20
19
|
try {
|
|
21
20
|
return readVersion();
|