cursor-delegate-mcp 1.20.0 → 1.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/acp-client.js +41 -8
- package/src/delegate.js +42 -12
- package/src/doctor.js +8 -4
- package/src/model-options.js +20 -25
- package/src/proc.js +14 -2
- package/src/server.js +46 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursor-delegate-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.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, or Copilot to Cursor's CLI agent — structured results, plan mode, and changed files.",
|
package/src/acp-client.js
CHANGED
|
@@ -4,11 +4,14 @@ import { StringDecoder } from "node:string_decoder";
|
|
|
4
4
|
import { JsonRpcPeer } from "./jsonrpc.js";
|
|
5
5
|
import { createRequestRouter } from "./request-router.js";
|
|
6
6
|
import { resolveAcpSpawn } from "./spawn.js";
|
|
7
|
-
import { isChildAlive, treeKill } from "./proc.js";
|
|
7
|
+
import { DETACHED, isChildAlive, treeKill } from "./proc.js";
|
|
8
8
|
import { VERSION } from "./version.js";
|
|
9
9
|
import { makeError } from "./errors.js";
|
|
10
10
|
|
|
11
11
|
const STDERR_CAP = 64 * 1024;
|
|
12
|
+
// How long stop() waits for the child to actually exit after the kill is dispatched. SIGKILL and
|
|
13
|
+
// taskkill /F land in milliseconds, so this only ever elapses when the kill did not work.
|
|
14
|
+
const STOP_EXIT_TIMEOUT_MS = 2000;
|
|
12
15
|
|
|
13
16
|
export class AcpClient extends EventEmitter {
|
|
14
17
|
/**
|
|
@@ -27,6 +30,8 @@ export class AcpClient extends EventEmitter {
|
|
|
27
30
|
this.onTodos = onTodos;
|
|
28
31
|
this._stderrChunks = [];
|
|
29
32
|
this._stderrLength = 0;
|
|
33
|
+
/** @type {Promise<boolean> | null} */
|
|
34
|
+
this._stopping = null;
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
// The tail of stderr, which is what an exit error quotes. Kept as chunks and joined on read:
|
|
@@ -44,7 +49,7 @@ export class AcpClient extends EventEmitter {
|
|
|
44
49
|
this._stderrLength = 0;
|
|
45
50
|
const stderrDecoder = new StringDecoder("utf8");
|
|
46
51
|
this._exitEmitted = false;
|
|
47
|
-
this.child = spawn(command, args, { ...options, stdio: ["pipe", "pipe", "pipe"] });
|
|
52
|
+
this.child = spawn(command, args, { ...options, detached: DETACHED, stdio: ["pipe", "pipe", "pipe"] });
|
|
48
53
|
this.child.stderr.on("data", (chunk) => {
|
|
49
54
|
const text = stderrDecoder.write(chunk);
|
|
50
55
|
if (text) {
|
|
@@ -131,12 +136,40 @@ export class AcpClient extends EventEmitter {
|
|
|
131
136
|
|
|
132
137
|
getTranscript(n) { return this.peer ? this.peer.formatLog(n) : ""; }
|
|
133
138
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
139
|
+
// Idempotent, so a force-cancel racing the delegation's own finally tears down once and both
|
|
140
|
+
// see the same answer. Resolves true when the child was observed to exit, false when the bound
|
|
141
|
+
// elapsed first: dispatching a signal is not the same fact as the process being gone, and
|
|
142
|
+
// cancel reports the difference rather than calling both "killed".
|
|
143
|
+
stop({ timeoutMs = STOP_EXIT_TIMEOUT_MS } = {}) {
|
|
144
|
+
if (!this._stopping) this._stopping = this._teardown(timeoutMs);
|
|
145
|
+
return this._stopping;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async _teardown(timeoutMs) {
|
|
149
|
+
const child = this.child;
|
|
150
|
+
if (!child?.pid) {
|
|
151
|
+
try { this.peer?.close(); } catch {}
|
|
152
|
+
return true;
|
|
140
153
|
}
|
|
154
|
+
const alive = isChildAlive(child);
|
|
155
|
+
// Subscribed before the kill is dispatched. A child that dies immediately would otherwise
|
|
156
|
+
// exit in the gap and leave this waiting on an event that has already fired.
|
|
157
|
+
const exited = alive
|
|
158
|
+
? /** @type {Promise<boolean>} */ (new Promise((resolve) => child.once("exit", () => resolve(true))))
|
|
159
|
+
: Promise.resolve(true);
|
|
160
|
+
// Runs for an exited child too: the agent can be gone while the commands it spawned are still
|
|
161
|
+
// running, and on POSIX they stay in its process group, which is the only handle left on them.
|
|
162
|
+
treeKill(child.pid, { childAlive: alive }).catch(() => {});
|
|
163
|
+
/** @type {NodeJS.Timeout | undefined} */
|
|
164
|
+
let timer;
|
|
165
|
+
const bounded = /** @type {Promise<boolean>} */ (new Promise((resolve) => {
|
|
166
|
+
timer = setTimeout(() => resolve(false), timeoutMs);
|
|
167
|
+
}));
|
|
168
|
+
const observed = await Promise.race([exited, bounded]);
|
|
169
|
+
clearTimeout(timer);
|
|
170
|
+
// Pending RPCs are left to the exit handler, which rejects them with agent-exit. Rejecting
|
|
171
|
+
// them here too would settle the same promises twice for no new information.
|
|
172
|
+
try { this.peer?.close(); } catch {}
|
|
173
|
+
return observed;
|
|
141
174
|
}
|
|
142
175
|
}
|
package/src/delegate.js
CHANGED
|
@@ -12,7 +12,7 @@ import { normalizeAgentReportedFiles } from "./agent-reported-files.js";
|
|
|
12
12
|
import { makeTurnState } from "./turn-state.js";
|
|
13
13
|
import { makeError } from "./errors.js";
|
|
14
14
|
import { PLAN_PRIORITIES, PLAN_STATUSES, TODO_STATUSES } from "./acp-enums.js";
|
|
15
|
-
import { optionsFrom,
|
|
15
|
+
import { optionsFrom, resolveEffort, unsupportedWarning } from "./model-options.js";
|
|
16
16
|
|
|
17
17
|
export const DEFAULT_MODEL = "composer-2.5";
|
|
18
18
|
export const DEFAULT_HANDSHAKE_MS = 60000;
|
|
@@ -211,13 +211,42 @@ function servedModelFrom(res) {
|
|
|
211
211
|
return typeof m?.currentValue === "string" ? m.currentValue : undefined;
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
// Sent
|
|
215
|
-
//
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
214
|
+
// Sent only when the exact value appears under a thought-level option the selected model
|
|
215
|
+
// advertised. Local validation keeps a bad token out of ACP and, more importantly, out of a
|
|
216
|
+
// billed prompt. Missing capability data is not mislabeled as a caller mistake.
|
|
217
|
+
async function applyEffort(client, sessionId, model, value, modelOptions) {
|
|
218
|
+
const resolved = resolveEffort(modelOptions, value);
|
|
219
|
+
if (resolved.status === "unavailable") {
|
|
220
|
+
throw makeError(
|
|
221
|
+
"effort-options-unavailable",
|
|
222
|
+
`Cannot validate effort ${JSON.stringify(value)} for ${JSON.stringify(model)}:`
|
|
223
|
+
+ " the selected model did not report a usable effort option list."
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
if (resolved.status === "unsupported") {
|
|
227
|
+
throw makeError(
|
|
228
|
+
"invalid-effort",
|
|
229
|
+
`Model ${JSON.stringify(model)} does not advertise configurable effort.`
|
|
230
|
+
+ ` Accepted: none. Omit effort; do not send ${JSON.stringify("none")}.`
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
if (resolved.status === "invalid") {
|
|
234
|
+
throw makeError(
|
|
235
|
+
"invalid-effort",
|
|
236
|
+
`Invalid effort ${JSON.stringify(value)} for ${JSON.stringify(model)}.`
|
|
237
|
+
+ ` Accepted: ${JSON.stringify(resolved.accepted)}.`
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const r = await applyConfig(client, sessionId, resolved.id, resolved.value);
|
|
242
|
+
if (r.unsupported) {
|
|
243
|
+
throw makeError(
|
|
244
|
+
"effort-options-unavailable",
|
|
245
|
+
`Cannot apply effort ${JSON.stringify(value)} for ${JSON.stringify(model)}:`
|
|
246
|
+
+ ` the selected model advertised option ${JSON.stringify(resolved.id)} but rejected it.`
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
return r.res;
|
|
221
250
|
}
|
|
222
251
|
|
|
223
252
|
/**
|
|
@@ -416,9 +445,8 @@ export async function runDelegate({
|
|
|
416
445
|
servedModel = servedModelFrom(reasserted.res) ?? servedModel;
|
|
417
446
|
}
|
|
418
447
|
if (effort !== undefined) {
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
else servedModel = servedModelFrom(applied.res) ?? servedModel;
|
|
448
|
+
const r = await applyEffort(client, sessionId, model, effort, modelOptions);
|
|
449
|
+
servedModel = servedModelFrom(r) ?? servedModel;
|
|
422
450
|
}
|
|
423
451
|
if (context !== undefined) {
|
|
424
452
|
const r = await applyConfig(client, sessionId, "context", context);
|
|
@@ -567,6 +595,8 @@ export async function runDelegate({
|
|
|
567
595
|
clearInterval(heartbeat);
|
|
568
596
|
signal?.removeEventListener("abort", onAbort);
|
|
569
597
|
try { supervisor.finish(); } catch {}
|
|
570
|
-
|
|
598
|
+
// Deliberately not awaited: stop() waits for the child to exit, and every turn — success as
|
|
599
|
+
// much as failure — would pay that before returning. Nothing here reads whether it landed.
|
|
600
|
+
Promise.resolve(client.stop()).catch(() => {});
|
|
571
601
|
}
|
|
572
602
|
}
|
package/src/doctor.js
CHANGED
|
@@ -2,7 +2,7 @@ import process from "node:process";
|
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
3
|
import { AcpClient } from "./acp-client.js";
|
|
4
4
|
import { resolveAcpSpawn } from "./spawn.js";
|
|
5
|
-
import { treeKill } from "./proc.js";
|
|
5
|
+
import { DETACHED, treeKill } from "./proc.js";
|
|
6
6
|
import { readPackageVersion } from "./version.js";
|
|
7
7
|
import { allowedValues } from "./model-options.js";
|
|
8
8
|
|
|
@@ -32,7 +32,7 @@ export function probeAgentVersion(spawnSpec, timeoutMs = VERSION_PROBE_TIMEOUT_M
|
|
|
32
32
|
clearTimeout(timer);
|
|
33
33
|
resolve(result);
|
|
34
34
|
};
|
|
35
|
-
const child = spawn(execCommand, execArgs, { ...options, stdio: ["ignore", "pipe", "pipe"] });
|
|
35
|
+
const child = spawn(execCommand, execArgs, { ...options, detached: DETACHED, stdio: ["ignore", "pipe", "pipe"] });
|
|
36
36
|
child.stdout?.on("data", (chunk) => { stdout += chunk.toString(); });
|
|
37
37
|
child.on("error", () => finish({ found: false, version: null }));
|
|
38
38
|
child.on("close", (code) => {
|
|
@@ -77,7 +77,9 @@ async function runDeepHandshake({ spawnSpec, clientFactory, workspace, timeoutMs
|
|
|
77
77
|
})();
|
|
78
78
|
const timeout = new Promise((_, reject) => {
|
|
79
79
|
timer = setTimeout(() => {
|
|
80
|
-
|
|
80
|
+
// Not awaited, so the timeout still rejects at its stated deadline rather than at the
|
|
81
|
+
// deadline plus teardown. The finally below awaits the same idempotent promise.
|
|
82
|
+
try { Promise.resolve(client.stop()).catch(() => {}); } catch {}
|
|
81
83
|
reject(new Error(`Handshake timed out after ${timeoutMs}ms`));
|
|
82
84
|
}, timeoutMs);
|
|
83
85
|
});
|
|
@@ -87,7 +89,9 @@ async function runDeepHandshake({ spawnSpec, clientFactory, workspace, timeoutMs
|
|
|
87
89
|
return { ok: false, error: err?.message || String(err) };
|
|
88
90
|
} finally {
|
|
89
91
|
clearTimeout(timer);
|
|
90
|
-
|
|
92
|
+
// Awaited so doctor does not return while the agent it spawned is still being torn down.
|
|
93
|
+
// A killed child exits in milliseconds; only one that ignores the kill costs the full bound.
|
|
94
|
+
try { await Promise.resolve(client.stop()); } catch {}
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
97
|
|
package/src/model-options.js
CHANGED
|
@@ -21,32 +21,27 @@ export function allowedValues(opt) {
|
|
|
21
21
|
.filter((v) => typeof v === "string");
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
// Resolve only values the selected model advertised. This keeps future vocabularies working
|
|
25
|
+
// without aliases or a ranking table: xhigh, extra-high, max and ultra are just exact tokens.
|
|
26
|
+
// A reported config list with no thought-level option is authoritative (unsupported); no list,
|
|
27
|
+
// an empty list, or a thought-level option with no usable id/values is not.
|
|
28
|
+
export function resolveEffort(options, value) {
|
|
29
|
+
if (!Array.isArray(options) || options.length === 0) return { status: "unavailable" };
|
|
30
|
+
|
|
31
|
+
const candidates = options.filter(isThoughtLevel);
|
|
32
|
+
if (candidates.length === 0) return { status: "unsupported", accepted: [] };
|
|
33
|
+
|
|
34
|
+
const usable = candidates.filter((o) => typeof o?.id === "string");
|
|
35
|
+
const accepted = [...new Set(usable.flatMap(allowedValues))];
|
|
36
|
+
if (usable.length === 0 || accepted.length === 0) return { status: "unavailable" };
|
|
28
37
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// nothing — sending a level there is a guaranteed invalid value, which would fail the run.
|
|
33
|
-
export function resolveEffortId(options, value) {
|
|
34
|
-
const candidates = (Array.isArray(options) ? options : []).filter(isThoughtLevel);
|
|
35
|
-
if (candidates.length === 0) return undefined;
|
|
36
|
-
const pick = candidates.find((o) => allowedValues(o).includes(value))
|
|
37
|
-
?? candidates.find((o) => !isBoolean(o));
|
|
38
|
-
return typeof pick?.id === "string" ? pick.id : undefined;
|
|
38
|
+
const pick = usable.find((o) => allowedValues(o).includes(value));
|
|
39
|
+
if (pick === undefined) return { status: "invalid", accepted };
|
|
40
|
+
return { status: "matched", id: pick.id, value };
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
//
|
|
42
|
-
// under their own names.
|
|
43
|
-
export function unsupportedWarning(model, { arg
|
|
44
|
-
|
|
45
|
-
// No reply carried a list, so claiming the model declares nothing would assert a capability
|
|
46
|
-
// never observed.
|
|
47
|
-
if (modelOptions === undefined) return `effort ignored: ${model} did not report its option list`;
|
|
48
|
-
const ids = modelOptions.filter(isThoughtLevel).map((o) => o?.id).filter(Boolean);
|
|
49
|
-
return ids.length
|
|
50
|
-
? `effort ignored: ${model} declares ${ids.join(", ")}, which did not take the requested value`
|
|
51
|
-
: `effort ignored: ${model} declares no thinking or reasoning option`;
|
|
43
|
+
// Effort failures are fatal before the prompt. Only fast and context reach this soft-diagnostic
|
|
44
|
+
// path, and both are sent under their own names.
|
|
45
|
+
export function unsupportedWarning(model, { arg }) {
|
|
46
|
+
return `model ${model} has no ${arg} option; the requested value was ignored`;
|
|
52
47
|
}
|
package/src/proc.js
CHANGED
|
@@ -5,14 +5,26 @@ export function isChildAlive(child) {
|
|
|
5
5
|
return child && child.exitCode === null && child.signalCode === null;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
// POSIX only: detached makes the child a process group leader (setsid), which is what lets
|
|
9
|
+
// treeKill reach the agent's own children. On win32 it would mean a separate console instead,
|
|
10
|
+
// and taskkill /T already walks the tree. Every spawn site applies it, not resolveAcpSpawn —
|
|
11
|
+
// an injected spawnSpec has to become a group leader too or the group kill finds nothing.
|
|
12
|
+
export const DETACHED = process.platform !== "win32";
|
|
13
|
+
|
|
8
14
|
// On win32 a plain child.kill() only reaches the shell wrapper (spawn uses shell: true);
|
|
9
15
|
// taskkill /T takes the whole tree so the agent itself dies too.
|
|
10
|
-
export async function treeKill(pid) {
|
|
16
|
+
export async function treeKill(pid, { childAlive = true } = {}) {
|
|
11
17
|
if (process.platform === "win32") {
|
|
12
18
|
await /** @type {Promise<void>} */ (new Promise((resolve) => {
|
|
13
19
|
execFile("taskkill", ["/PID", String(pid), "/T", "/F"], () => resolve());
|
|
14
20
|
}));
|
|
15
21
|
return;
|
|
16
22
|
}
|
|
17
|
-
|
|
23
|
+
// Negative pid signals the whole group, so the agent's descendants go with it. A group outlives
|
|
24
|
+
// its leader while any member is left, which is why this runs even for an exited child: that is
|
|
25
|
+
// the case where descendants are the only thing still running.
|
|
26
|
+
try { process.kill(-pid, "SIGKILL"); } catch {}
|
|
27
|
+
// Reaches a child that is not a group leader, where the group kill raised ESRCH. Skipped once
|
|
28
|
+
// the child is gone, since a reaped pid can already belong to something else.
|
|
29
|
+
if (childAlive) { try { process.kill(pid, "SIGKILL"); } catch {} }
|
|
18
30
|
}
|
package/src/server.js
CHANGED
|
@@ -8,6 +8,7 @@ import { z } from "zod";
|
|
|
8
8
|
import { DEFAULT_MODEL, runDelegate as runDelegateDefault } from "./delegate.js";
|
|
9
9
|
import { runDoctor as runDoctorDefault } from "./doctor.js";
|
|
10
10
|
import { VERSION } from "./version.js";
|
|
11
|
+
import { DETACHED } from "./proc.js";
|
|
11
12
|
import { PLAN_PRIORITIES, PLAN_STATUSES, TODO_STATUSES } from "./acp-enums.js";
|
|
12
13
|
|
|
13
14
|
const nodeMajor = Number(process.versions.node.split(".")[0]);
|
|
@@ -103,20 +104,26 @@ export const delegateOutputShape = {
|
|
|
103
104
|
// doctor.test.js parses every result against a strict copy of this shape.
|
|
104
105
|
//
|
|
105
106
|
// Types only; what the fields mean is documented once, in TECHNICAL.md.
|
|
107
|
+
// Split out so the drift guard can make it strict on its own: a .strict() on agent does not look
|
|
108
|
+
// inside handshake, which is the level this schema has drifted at twice.
|
|
109
|
+
export const doctorHandshakeShape = {
|
|
110
|
+
ok: z.boolean(),
|
|
111
|
+
error: z.string().optional(),
|
|
112
|
+
protocolVersion: z.unknown().optional(),
|
|
113
|
+
agentCapabilities: z.unknown().optional(),
|
|
114
|
+
models: z.array(z.unknown()).optional(),
|
|
115
|
+
currentModel: z.unknown().optional(),
|
|
116
|
+
modes: z.array(z.unknown()).optional(),
|
|
117
|
+
// Built here rather than relayed, so it gets a real type where its neighbours get z.unknown().
|
|
118
|
+
currentModelOptions: z.array(z.object({ id: z.string(), values: z.array(z.string()) })).optional(),
|
|
119
|
+
};
|
|
120
|
+
|
|
106
121
|
export const doctorAgentShape = {
|
|
107
122
|
found: z.boolean(),
|
|
108
123
|
command: z.string(),
|
|
109
124
|
version: z.string().nullable(),
|
|
110
125
|
error: z.string().optional(),
|
|
111
|
-
handshake: z.object(
|
|
112
|
-
ok: z.boolean(),
|
|
113
|
-
error: z.string().optional(),
|
|
114
|
-
protocolVersion: z.unknown().optional(),
|
|
115
|
-
agentCapabilities: z.unknown().optional(),
|
|
116
|
-
models: z.array(z.unknown()).optional(),
|
|
117
|
-
currentModel: z.unknown().optional(),
|
|
118
|
-
modes: z.array(z.unknown()).optional(),
|
|
119
|
-
}).passthrough().optional(),
|
|
126
|
+
handshake: z.object(doctorHandshakeShape).passthrough().optional(),
|
|
120
127
|
};
|
|
121
128
|
|
|
122
129
|
// Exported as a shape for the same reason as delegateOutputShape, and with agent split out
|
|
@@ -147,9 +154,9 @@ export const delegateInputSchema = z.object({
|
|
|
147
154
|
workspace: z.string().optional().describe("The agent's working directory, not a limit. Defaults to the server process cwd, which under npx is often not your project root — pass it explicitly. Must already exist; never create one for the call."),
|
|
148
155
|
model: z.string().trim().min(1, "model must be a non-empty string").default(DEFAULT_MODEL).describe("Bare ACP family id, version included: composer-2.5, grok-4.5, claude-opus-5, gpt-5.6-sol. doctor deep:true lists every id."),
|
|
149
156
|
fast: z.boolean().default(false).describe("Fast tier; higher cost — only when the user asks."),
|
|
150
|
-
// Which
|
|
151
|
-
//
|
|
152
|
-
effort: z.string().trim().min(1).optional().describe("
|
|
157
|
+
// Which values a model offers is only knowable after selecting it, so this stays an open
|
|
158
|
+
// string and the bridge validates the exact token against the live option list.
|
|
159
|
+
effort: z.string().trim().min(1).optional().describe("Exact Cursor thinking-effort value for the selected model. Values differ per model and some expose no effort option; invalid values fail before the prompt and name the accepted set. Pass only when the user asks for Cursor effort — the host's own reasoning setting is unrelated."),
|
|
153
160
|
context: z.string().trim().min(1).optional().describe("Context window size; gpt-5.x accepts 272k and 1m. Do not pass speculatively."),
|
|
154
161
|
contextFiles: z.array(z.string()).optional().describe("Paths to attach instead of pasting contents into spec. Text becomes references the agent may open; images (png/jpg/gif/webp, <5MB) are sent inline. Relative paths resolve against workspace but are not limited to it. Skips are reported in protocolWarnings, never fatal."),
|
|
155
162
|
});
|
|
@@ -245,7 +252,7 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
245
252
|
"delegate",
|
|
246
253
|
{
|
|
247
254
|
description:
|
|
248
|
-
`Delegate a coding task to cursor-agent over ACP. Never shell out to cursor-agent — use this tool only. 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. Keep model (${DEFAULT_MODEL}), fast and effort at their defaults unless the user asks. See the delegate skill.`,
|
|
255
|
+
`Delegate a coding task to cursor-agent over ACP. Never shell out to cursor-agent — use this tool only. 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. Keep model (${DEFAULT_MODEL}), fast and effort at their defaults unless the user explicitly asks. See the delegate skill.`,
|
|
249
256
|
inputSchema: delegateInputSchema,
|
|
250
257
|
annotations: {
|
|
251
258
|
title: "Delegate coding task to Cursor",
|
|
@@ -262,7 +269,7 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
262
269
|
"cancel",
|
|
263
270
|
{
|
|
264
271
|
description:
|
|
265
|
-
"Best-effort cancel of an in-flight delegation by sessionId. session/cancel is advisory — the agent may finish the turn anyway, and the delegate result then carries cancelRequested. Status: cancelled, killed, not-running (turn already ended, still resumable), not-found (id
|
|
272
|
+
"Best-effort cancel of an in-flight delegation by sessionId. session/cancel is advisory — the agent may finish the turn anyway, and the delegate result then carries cancelRequested. Status: cancelled, killed (agent process observed to exit), not-running (turn already ended, still resumable), not-found (id not in this process's recent session history).",
|
|
266
273
|
inputSchema: {
|
|
267
274
|
sessionId: z.string(),
|
|
268
275
|
force: z.boolean().default(false).describe("Kill the agent process if the turn is still running after a short grace period."),
|
|
@@ -297,7 +304,12 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
297
304
|
await new Promise((r) => setTimeout(r, forceGraceMs));
|
|
298
305
|
const stillRunning = inFlight.get(sessionId);
|
|
299
306
|
if (!stillRunning || stillRunning.size === 0) return cancelResult("cancelled", sessionId);
|
|
300
|
-
|
|
307
|
+
const observed = await Promise.all(
|
|
308
|
+
[...stillRunning].map((handle) => Promise.resolve(handle.client.stop()).catch(() => false))
|
|
309
|
+
);
|
|
310
|
+
// "killed" claims the process is gone, so it needs the exit, not just a dispatched signal.
|
|
311
|
+
// When one does not follow, the handles stay registered and force can be tried again.
|
|
312
|
+
if (!observed.every(Boolean)) return cancelResult("cancelled", sessionId);
|
|
301
313
|
inFlight.delete(sessionId);
|
|
302
314
|
return cancelResult("killed", sessionId);
|
|
303
315
|
}
|
|
@@ -347,7 +359,26 @@ if (process.argv[1]) {
|
|
|
347
359
|
}
|
|
348
360
|
}
|
|
349
361
|
|
|
362
|
+
// Each agent runs in its own process group on POSIX, so a SIGINT or SIGTERM aimed at this process
|
|
363
|
+
// no longer reaches it the way it did when the two shared a group. Kill what is registered, then
|
|
364
|
+
// exit explicitly: installing a handler replaces Node's default, and a server that swallows Ctrl-C
|
|
365
|
+
// would be a worse bug than the agent it leaks. Delegations still in their handshake are not in
|
|
366
|
+
// the map yet, so this covers the turn, not the first few seconds of it.
|
|
367
|
+
export function installSignalCleanup(map, { exit = (code) => process.exit(code) } = {}) {
|
|
368
|
+
if (!DETACHED) return;
|
|
369
|
+
const signals = /** @type {[NodeJS.Signals, number][]} */ ([["SIGINT", 130], ["SIGTERM", 143]]);
|
|
370
|
+
for (const [signal, code] of signals) {
|
|
371
|
+
process.on(signal, () => {
|
|
372
|
+
for (const handles of map.values()) {
|
|
373
|
+
for (const handle of handles) { try { handle.client.stop(); } catch {} }
|
|
374
|
+
}
|
|
375
|
+
exit(code);
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
350
380
|
if (isMain) {
|
|
351
381
|
const server = buildServer();
|
|
382
|
+
installSignalCleanup(inFlight);
|
|
352
383
|
await server.connect(new StdioServerTransport());
|
|
353
384
|
}
|