cursor-delegate-mcp 1.21.0 → 1.22.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cursor-delegate-mcp",
3
- "version": "1.21.0",
3
+ "version": "1.22.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/delegate.js CHANGED
@@ -15,6 +15,9 @@ import { PLAN_PRIORITIES, PLAN_STATUSES, TODO_STATUSES } from "./acp-enums.js";
15
15
  import { optionsFrom, resolveEffort, unsupportedWarning } from "./model-options.js";
16
16
 
17
17
  export const DEFAULT_MODEL = "composer-2.5";
18
+ // The one advertised id the agent resolves to a different model ("Auto"), so it is the one id
19
+ // whose served model has to be read back off a config reply for effectiveModel.
20
+ const ROUTED_MODEL = "default";
18
21
  export const DEFAULT_HANDSHAKE_MS = 60000;
19
22
  export const DEFAULT_HEARTBEAT_MS = 30000;
20
23
 
@@ -33,37 +36,12 @@ function fmtDuration(ms) {
33
36
  return s < 60 ? `${s}s` : `${Math.floor(s / 60)}m${String(s % 60).padStart(2, "0")}s`;
34
37
  }
35
38
 
36
- // Two separate questions. "Could this be a path?" is loose — worth a stat. "Was a path clearly
37
- // intended?" must be strict, since ordinary prose names files ("fix the bug in src/api.js") and
38
- // must never be rejected for it. Whitespace discriminates: a path argument has none.
39
- function looksLikeSpecPath(spec) {
40
- return !spec.includes("\n")
41
- && (spec.includes("/") || spec.includes("\\") || spec.endsWith(".md") || spec.endsWith(".txt"));
42
- }
43
- const isBareSpecPath = (spec) => !/\s/.test(spec.trim());
44
-
45
- async function resolveSpec(spec) {
46
- if (typeof spec !== "string") return spec;
47
- // A blank spec spins up a live session that only replies "No prompt content provided" —
48
- // a billed turn for nothing. Reject it here, before the spawn, like the other bad specs.
49
- if (spec.trim() === "") {
50
- throw makeError("invalid-spec", "spec is empty. Provide a task brief inline, or a path to one.");
51
- }
52
- if (!looksLikeSpecPath(spec)) return spec;
53
- let stat;
54
- try {
55
- stat = statSync(spec);
56
- } catch {
57
- // Only a bare path was unambiguously meant as one. Anything else is prose that happens
58
- // to name a file, and prose is the common case.
59
- if (!isBareSpecPath(spec)) return spec;
60
- throw makeError("invalid-spec", `spec looks like a file path but nothing exists at ${spec}. Pass the brief inline, or fix the path.`);
61
- }
62
- if (stat.isFile()) return readFile(spec, "utf8");
63
- if (isBareSpecPath(spec)) {
64
- throw makeError("invalid-spec", `spec looks like a file path but ${spec} is not a file. Pass the brief inline, or point at a file.`);
39
+ // A blank spec spins up a live session that only replies "No prompt content provided" —
40
+ // a billed turn for nothing. Reject it before the spawn, like a bad workspace.
41
+ function assertSpec(spec) {
42
+ if (typeof spec === "string" && spec.trim() === "") {
43
+ throw makeError("invalid-spec", "spec is empty. Provide a task brief.");
65
44
  }
66
- return spec;
67
45
  }
68
46
 
69
47
  // Without this, the agent's first write creates the directory: a typo'd workspace spawns a
@@ -204,6 +182,13 @@ async function applyConfig(client, sessionId, configId, value) {
204
182
 
205
183
  // The resolved model appears only in a set_config_option reply's configOptions (set_model
206
184
  // returns nothing). Absent for models that reject every option sent — the field then stays off.
185
+ // session/new and session/load both report the values the session opens with, which is what makes
186
+ // a config round-trip skippable: the bridge can see it would set what is already set.
187
+ function configOptionValue(configOptions, id) {
188
+ const opt = (Array.isArray(configOptions) ? configOptions : []).find((o) => o?.id === id);
189
+ return typeof opt?.currentValue === "string" ? opt.currentValue : undefined;
190
+ }
191
+
207
192
  function servedModelFrom(res) {
208
193
  const opts = optionsFrom(res);
209
194
  if (opts === undefined) return undefined;
@@ -268,18 +253,17 @@ export async function runDelegate({
268
253
  heartbeatMs = DEFAULT_HEARTBEAT_MS,
269
254
  signal,
270
255
  } = {}) {
256
+ // Nothing between here and the abort listener below may await: addEventListener does not
257
+ // replay an abort that already fired, so an abort landing in that window would be lost. A
258
+ // spec read used to await here, and did lose one. Throwing, not supervisor.abort(): tripping
259
+ // before supervise() installs its reject settles the supervisor with nothing listening.
271
260
  if (signal?.aborted) {
272
261
  throw makeError("aborted", "delegation aborted by MCP host");
273
262
  }
274
263
  // Before the spawn: validating later costs a process, a handshake and a billed turn.
275
264
  assertWorkspace(workspace);
276
- const promptText = await resolveSpec(spec);
277
- // addEventListener does not replay an abort that already fired, and the listener is registered
278
- // below, so an abort during the await above is otherwise lost. Throwing, not supervisor.abort():
279
- // tripping before supervise() installs its reject settles the supervisor with nothing listening.
280
- if (signal?.aborted) {
281
- throw makeError("aborted", "delegation aborted by MCP host");
282
- }
265
+ assertSpec(spec);
266
+ const promptText = spec;
283
267
  const capMs = hardCapMs ?? timeoutMs ?? envMs("CURSOR_DELEGATE_HARD_CAP_MS", 3600000);
284
268
  const shakeMs = handshakeMs ?? envMs("CURSOR_DELEGATE_HANDSHAKE_MS", DEFAULT_HANDSHAKE_MS);
285
269
  const turnIdleMs = idleMs ?? envMs("CURSOR_DELEGATE_IDLE_MS", 0);
@@ -428,15 +412,28 @@ export async function runDelegate({
428
412
  supervisor.setSessionId(sessionId);
429
413
  onSessionReady?.(sessionId, client);
430
414
  assertKnownModel(client, model);
431
- await client.setModel(sessionId, model);
432
- // fast is always sent — a resumed session may already have it on, so false is a real
433
- // instruction. Its reply carries this model's configOptions, which is where the effort id
434
- // comes from. effort and context go only when the caller named one. Each reply reports the
435
- // now-current model; the last one seen wins.
436
- const fastResult = await applyConfig(client, sessionId, "fast", fast);
437
- if (fastResult.unsupported && fast) unsupportedOptions.push({ arg: "fast" });
438
- else servedModel = servedModelFrom(fastResult.res) ?? servedModel;
439
- let modelOptions = optionsFrom(fastResult.res);
415
+ // session/new and session/load both report the model the session opened on, and an id that
416
+ // already matches is served without an explicit set — measured, so this round-trip has
417
+ // nothing to change. Cursor carries the selection across sessions, so the common shape
418
+ // (same model twice running) hits this.
419
+ const openedOnModel = client.sessionModels?.currentModelId === model;
420
+ if (!openedOnModel) await client.setModel(sessionId, model);
421
+ // fast is an instruction, not a probe. Cursor persists the tier, and persists it per model —
422
+ // both measured: one fast:true turn leaves the next fresh session reporting fast=true, and a
423
+ // set_model to another model reports that model's own tier. So the opening snapshot only
424
+ // describes the tier in force when the session also opened on this model; after a switch it
425
+ // describes the model we left. Skip only when both hold, which is the steady-state path this
426
+ // is for, and send whenever the reply itself is read: effort needs its option list, and a
427
+ // routable id needs the served model. An absent value reads as a mismatch and sends. effort
428
+ // and context go only when the caller named one; the last reply seen wins.
429
+ const openedFast = configOptionValue(client.configOptions, "fast");
430
+ let modelOptions;
431
+ if (!openedOnModel || openedFast !== String(fast) || effort !== undefined || model === ROUTED_MODEL) {
432
+ const fastResult = await applyConfig(client, sessionId, "fast", fast);
433
+ if (fastResult.unsupported && fast) unsupportedOptions.push({ arg: "fast" });
434
+ else servedModel = servedModelFrom(fastResult.res) ?? servedModel;
435
+ modelOptions = optionsFrom(fastResult.res);
436
+ }
440
437
  // A model that refuses fast leaves no list. Re-asserting the model just set is inert, and
441
438
  // its reply carries the full list — measured on claude-haiku-4-5, which refuses fast.
442
439
  if (modelOptions === undefined && effort !== undefined) {
package/src/jsonrpc.js CHANGED
@@ -30,6 +30,10 @@ export class JsonRpcPeer {
30
30
  // 0 disables recording and is documented; anything unparseable is a typo, and silently
31
31
  // disabling the transcript on a typo is the opposite of what the setter wanted.
32
32
  this._logSize = readLogSize(process.env.ACP_LOG_SIZE);
33
+ // The failure transcript is the only thing that reads these frames, and it is opt-in, so
34
+ // recording by default retained up to _logSize × FRAME_CAP bytes per delegation that nothing
35
+ // would ever ask for. ACP_LOG_SIZE still bounds retention and still disables at 0.
36
+ this._recording = this._logSize > 0 && Number(process.env.CURSOR_DELEGATE_TRANSCRIPT) > 0;
33
37
  this._log = [];
34
38
  this.rl = readline.createInterface({ input });
35
39
  this.rl.on("line", (line) => this._onLine(line));
@@ -39,7 +43,7 @@ export class JsonRpcPeer {
39
43
  // chatty turn cost more than parsing the frames. Let the array overshoot by a quarter and trim
40
44
  // in one batch; readers below take the last _logSize, so what the log reports is unchanged.
41
45
  _record(dir, line) {
42
- if (this._logSize <= 0) return;
46
+ if (!this._recording) return;
43
47
  const truncated = line.length > FRAME_CAP ? line.slice(0, FRAME_CAP) : line;
44
48
  this._log.push({ t: Date.now(), dir, line: truncated });
45
49
  if (this._log.length > this._logSize + (this._logSize >> 2)) {
package/src/server.js CHANGED
@@ -7,7 +7,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
7
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
- import { VERSION } from "./version.js";
10
+ import { VERSION, readPackageVersion } from "./version.js";
11
11
  import { DETACHED } from "./proc.js";
12
12
  import { PLAN_PRIORITIES, PLAN_STATUSES, TODO_STATUSES } from "./acp-enums.js";
13
13
 
@@ -148,7 +148,7 @@ export const doctorOutputShape = {
148
148
  };
149
149
 
150
150
  export const delegateInputSchema = z.object({
151
- spec: z.string().trim().min(1, "spec must not be blank").describe("Task brief: goal, scope, fixed decisions quoted exactly, acceptance criteria. Point at files to read rather than pasting code. A lone file path is read as the brief."),
151
+ spec: z.string().trim().min(1, "spec must not be blank").describe("Task brief: goal, scope, fixed decisions quoted exactly, acceptance criteria. Sent as written. Point at files to read rather than pasting code, or attach them with contextFiles."),
152
152
  mode: z.enum(["agent", "plan", "ask"]).default("agent").describe("agent implements; plan and ask are instructions to the agent, not limits."),
153
153
  resumeSessionId: z.string().optional().describe("Continue an existing ACP session."),
154
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."),
@@ -378,7 +378,15 @@ export function installSignalCleanup(map, { exit = (code) => process.exit(code)
378
378
  }
379
379
 
380
380
  if (isMain) {
381
- const server = buildServer();
382
- installSignalCleanup(inFlight);
383
- await server.connect(new StdioServerTransport());
381
+ // Without this the flag falls through to the transport, which owns stdout and waits on stdin —
382
+ // so confirming an install meant wiring the server into a host first. Reads the package.json
383
+ // beside this file, so it reports the code that is actually running rather than what a
384
+ // manifest pinned. stdout is free here because the transport never starts.
385
+ if (process.argv.slice(2).includes("--version")) {
386
+ console.log(readPackageVersion());
387
+ } else {
388
+ const server = buildServer();
389
+ installSignalCleanup(inFlight);
390
+ await server.connect(new StdioServerTransport());
391
+ }
384
392
  }