cursor-delegate-mcp 1.3.0 → 1.4.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 CHANGED
@@ -39,7 +39,7 @@ Delegation defaults to Cursor's **Composer 2.5**, which draws from the separate
39
39
 
40
40
  - 🤝 **Perfect Claude Code integration** — ships as a plugin with a skill, slash command, and hooks. Just say *"delegate this to Cursor"* and it happens.
41
41
  - 💬 **Answers Cursor's questions** — when Cursor needs a clarification mid-run, the question surfaces in your client's normal prompt. No stalled sessions.
42
- - 📦 **Structured results** — session id, files changed, stop reason, and plan payload. Claude knows exactly what happened and what to review.
42
+ - 📦 **Structured results** — final agent response, result source, session id, files changed, stop reason, and plan payload. Claude knows exactly what happened and what to review.
43
43
  - 📋 **Plan mode** — have Cursor draft a plan first, review it, then resume the same session to implement.
44
44
  - 🔍 **Ask mode** — read-only Q&A over the codebase, zero file changes.
45
45
  - 🩺 **Built-in diagnostics** — a `doctor` tool that tells you exactly what's missing if setup isn't right.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cursor-delegate-mcp",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "description": "MCP server bridging Claude Code to cursor-agent over the Agent Client Protocol (ACP).",
6
6
  "license": "MIT",
package/src/delegate.js CHANGED
@@ -63,11 +63,63 @@ export async function runDelegate({
63
63
  const client = make({ onElicit: wrappedElicit, mode, onCreatePlan: recordCreatePlan });
64
64
  const supervisor = new SessionSupervisor(client, { idleMs, hardCapMs: capMs, cancelGraceMs, killGraceMs });
65
65
 
66
- const textChunks = [];
67
- let textLength = 0;
66
+ const resultChunks = [];
67
+ let resultLength = 0;
68
68
  let truncated = false;
69
+ let sawToolCall = false;
70
+ let collectingPostToolResult = false;
71
+ const activeToolCalls = new Set();
69
72
  const touched = new Set();
70
73
 
74
+ const resetResult = () => {
75
+ resultChunks.length = 0;
76
+ resultLength = 0;
77
+ truncated = false;
78
+ };
79
+ const appendResult = (text) => {
80
+ if (truncated) return;
81
+ const remaining = MAX_OUTPUT - resultLength;
82
+ if (text.length <= remaining) {
83
+ resultChunks.push(text);
84
+ resultLength += text.length;
85
+ } else if (remaining > 0) {
86
+ resultChunks.push(text.slice(0, remaining));
87
+ resultLength += remaining;
88
+ truncated = true;
89
+ } else {
90
+ truncated = true;
91
+ }
92
+ };
93
+ const isTerminalToolStatus = (status) =>
94
+ status === "completed" || status === "failed" || status === "cancelled";
95
+ const startTool = (toolCallId, status) => {
96
+ sawToolCall = true;
97
+ collectingPostToolResult = false;
98
+ resetResult();
99
+ if (toolCallId != null && !isTerminalToolStatus(status)) activeToolCalls.add(toolCallId);
100
+ if (isTerminalToolStatus(status) && activeToolCalls.size === 0) collectingPostToolResult = true;
101
+ };
102
+ const updateToolStatus = (toolCallId, status) => {
103
+ if (!status) return;
104
+ if (!sawToolCall) {
105
+ sawToolCall = true;
106
+ resetResult();
107
+ }
108
+ if (isTerminalToolStatus(status)) {
109
+ if (toolCallId != null) activeToolCalls.delete(toolCallId);
110
+ if (activeToolCalls.size === 0 && !collectingPostToolResult) {
111
+ // Discard any message text emitted while tools were still running.
112
+ // A duplicate or late terminal update must not wipe an already-collected final message.
113
+ resetResult();
114
+ collectingPostToolResult = true;
115
+ }
116
+ } else {
117
+ collectingPostToolResult = false;
118
+ resetResult();
119
+ if (toolCallId != null) activeToolCalls.add(toolCallId);
120
+ }
121
+ };
122
+
71
123
  // Each stream reports its newest complete sentence, at most one per throttle window.
72
124
  // Capital-letter boundary: cursor-agent thoughts arrive as sentences with no separator.
73
125
  const SENTENCE_END = /[.!?](?=\s|[A-Z])|\n/;
@@ -109,6 +161,7 @@ export async function runDelegate({
109
161
  thoughtProgress.push(up.content.text);
110
162
  }
111
163
  if (up.sessionUpdate === "tool_call") {
164
+ startTool(up.toolCallId, up.status);
112
165
  const label = up.title || up.kind || "tool";
113
166
  const path = up.locations?.[0]?.path;
114
167
  const line = "running: " + String(label) + (path ? " — " + path : "");
@@ -116,22 +169,11 @@ export async function runDelegate({
116
169
  }
117
170
  if (up.sessionUpdate === "agent_message_chunk" && up.content?.text) {
118
171
  const text = up.content.text;
119
- if (!truncated) {
120
- const remaining = MAX_OUTPUT - textLength;
121
- if (text.length <= remaining) {
122
- textChunks.push(text);
123
- textLength += text.length;
124
- } else if (remaining > 0) {
125
- textChunks.push(text.slice(0, remaining));
126
- textLength += remaining;
127
- truncated = true;
128
- } else {
129
- truncated = true;
130
- }
131
- }
172
+ if (!sawToolCall || (collectingPostToolResult && activeToolCalls.size === 0)) appendResult(text);
132
173
  messageProgress.push(text);
133
174
  }
134
175
  if (up.sessionUpdate === "tool_call_update") {
176
+ updateToolStatus(up.toolCallId, up.status);
135
177
  for (const c of up.content || []) {
136
178
  if (c.type === "diff" && c.path) {
137
179
  touched.add(c.path);
@@ -154,9 +196,10 @@ export async function runDelegate({
154
196
  await client.setModel(sessionId, model);
155
197
  if (composerFastToggleApplies(model)) await client.setFast(sessionId, fast);
156
198
  await client.setMode(sessionId, mode);
157
- textChunks.length = 0;
158
- textLength = 0;
159
- truncated = false;
199
+ resetResult();
200
+ sawToolCall = false;
201
+ collectingPostToolResult = false;
202
+ activeToolCalls.clear();
160
203
  thoughtProgress.reset();
161
204
  messageProgress.reset();
162
205
  planEntries = [];
@@ -167,12 +210,18 @@ export async function runDelegate({
167
210
  });
168
211
  thoughtProgress.end();
169
212
  messageProgress.end();
170
- let result = textChunks.join("");
213
+ let result = resultChunks.join("");
171
214
  if (truncated) result += TRUNCATION_MARKER;
215
+ const finalMessageAvailable = result.length > 0;
216
+ const resultSource = finalMessageAvailable
217
+ ? (sawToolCall ? "post-tool" : "tool-free-stream")
218
+ : "none";
172
219
  const gitAfter = gitChangedSet(workspace);
173
220
  const touchedResult = computeTouched({ before: gitBefore, after: gitAfter, diffTouched: [...touched], workspace });
174
221
  const out = {
175
222
  result,
223
+ resultSource,
224
+ finalMessageAvailable,
176
225
  stopReason: res?.stopReason,
177
226
  sessionId,
178
227
  touchedFiles: touchedResult.files,
package/src/jsonrpc.js CHANGED
@@ -1,81 +1,81 @@
1
- import readline from "node:readline";
2
-
3
- const FRAME_CAP = 2048;
4
-
5
- export class JsonRpcPeer {
6
- constructor(input, output, { onNotification, onRequest, onActivity } = {}) {
7
- this.output = output;
8
- this.onNotification = onNotification || (() => {});
9
- this.onRequest = onRequest || (() => {});
10
- this.onActivity = onActivity || (() => {});
11
- this.nextId = 1;
12
- this.pending = new Map();
13
- const rawSize = process.env.ACP_LOG_SIZE !== undefined ? Number(process.env.ACP_LOG_SIZE) : 2000;
14
- this._logSize = rawSize > 0 && !Number.isNaN(rawSize) ? rawSize : 0;
15
- this._log = [];
16
- this.rl = readline.createInterface({ input });
17
- this.rl.on("line", (line) => this._onLine(line));
18
- }
19
-
20
- _record(dir, line) {
21
- if (this._logSize <= 0) return;
22
- const truncated = line.length > FRAME_CAP ? line.slice(0, FRAME_CAP) : line;
23
- this._log.push({ t: Date.now(), dir, line: truncated });
24
- if (this._log.length > this._logSize) {
25
- this._log.splice(0, this._log.length - this._logSize);
26
- }
27
- }
28
-
29
- getLog() { return [...this._log]; }
30
-
31
- formatLog(n) {
32
- const entries = n !== undefined ? this._log.slice(-n) : this._log;
33
- return entries.map((e) => `${new Date(e.t).toISOString()} ${e.dir} ${e.line}`).join("\n");
34
- }
35
-
36
- _onLine(line) {
37
- this.onActivity();
38
- this._record("in", line);
39
- if (!line.trim()) return;
40
- let msg;
41
- try { msg = JSON.parse(line); } catch { return; }
42
- const hasId = msg.id !== undefined && msg.id !== null;
43
- if (hasId && (msg.result !== undefined || msg.error !== undefined)) {
44
- const p = this.pending.get(msg.id);
45
- if (p) {
46
- this.pending.delete(msg.id);
47
- if (msg.error) p.reject(new Error(msg.error.message || "rpc error"));
48
- else p.resolve(msg.result);
49
- }
50
- } else if (msg.method && hasId) {
51
- this.onRequest(msg.id, msg.method, msg.params);
52
- } else if (msg.method) {
53
- this.onNotification(msg.method, msg.params);
54
- }
55
- }
56
-
57
- _write(obj) {
58
- const serialized = JSON.stringify(obj) + "\n";
59
- this._record("out", serialized);
60
- this.output.write(serialized);
61
- }
62
-
63
- request(method, params) {
64
- const id = this.nextId++;
65
- return new Promise((resolve, reject) => {
66
- this.pending.set(id, { resolve, reject });
67
- this._write({ jsonrpc: "2.0", id, method, params });
68
- });
69
- }
70
-
71
- notify(method, params) { this._write({ jsonrpc: "2.0", method, params }); }
72
- respond(id, result) { this._write({ jsonrpc: "2.0", id, result }); }
73
- respondError(id, code, message) { this._write({ jsonrpc: "2.0", id, error: { code, message } }); }
74
-
75
- rejectAllPending(err) {
76
- for (const p of this.pending.values()) p.reject(err);
77
- this.pending.clear();
78
- }
79
-
80
- close() { this.rl.close(); }
81
- }
1
+ import readline from "node:readline";
2
+
3
+ const FRAME_CAP = 2048;
4
+
5
+ export class JsonRpcPeer {
6
+ constructor(input, output, { onNotification, onRequest, onActivity } = {}) {
7
+ this.output = output;
8
+ this.onNotification = onNotification || (() => {});
9
+ this.onRequest = onRequest || (() => {});
10
+ this.onActivity = onActivity || (() => {});
11
+ this.nextId = 1;
12
+ this.pending = new Map();
13
+ const rawSize = process.env.ACP_LOG_SIZE !== undefined ? Number(process.env.ACP_LOG_SIZE) : 2000;
14
+ this._logSize = rawSize > 0 && !Number.isNaN(rawSize) ? rawSize : 0;
15
+ this._log = [];
16
+ this.rl = readline.createInterface({ input });
17
+ this.rl.on("line", (line) => this._onLine(line));
18
+ }
19
+
20
+ _record(dir, line) {
21
+ if (this._logSize <= 0) return;
22
+ const truncated = line.length > FRAME_CAP ? line.slice(0, FRAME_CAP) : line;
23
+ this._log.push({ t: Date.now(), dir, line: truncated });
24
+ if (this._log.length > this._logSize) {
25
+ this._log.splice(0, this._log.length - this._logSize);
26
+ }
27
+ }
28
+
29
+ getLog() { return [...this._log]; }
30
+
31
+ formatLog(n) {
32
+ const entries = n !== undefined ? this._log.slice(-n) : this._log;
33
+ return entries.map((e) => `${new Date(e.t).toISOString()} ${e.dir} ${e.line}`).join("\n");
34
+ }
35
+
36
+ _onLine(line) {
37
+ this.onActivity();
38
+ this._record("in", line);
39
+ if (!line.trim()) return;
40
+ let msg;
41
+ try { msg = JSON.parse(line); } catch { return; }
42
+ const hasId = msg.id !== undefined && msg.id !== null;
43
+ if (hasId && (msg.result !== undefined || msg.error !== undefined)) {
44
+ const p = this.pending.get(msg.id);
45
+ if (p) {
46
+ this.pending.delete(msg.id);
47
+ if (msg.error) p.reject(new Error(msg.error.message || "rpc error"));
48
+ else p.resolve(msg.result);
49
+ }
50
+ } else if (msg.method && hasId) {
51
+ this.onRequest(msg.id, msg.method, msg.params);
52
+ } else if (msg.method) {
53
+ this.onNotification(msg.method, msg.params);
54
+ }
55
+ }
56
+
57
+ _write(obj) {
58
+ const serialized = JSON.stringify(obj) + "\n";
59
+ this._record("out", serialized);
60
+ this.output.write(serialized);
61
+ }
62
+
63
+ request(method, params) {
64
+ const id = this.nextId++;
65
+ return new Promise((resolve, reject) => {
66
+ this.pending.set(id, { resolve, reject });
67
+ this._write({ jsonrpc: "2.0", id, method, params });
68
+ });
69
+ }
70
+
71
+ notify(method, params) { this._write({ jsonrpc: "2.0", method, params }); }
72
+ respond(id, result) { this._write({ jsonrpc: "2.0", id, result }); }
73
+ respondError(id, code, message) { this._write({ jsonrpc: "2.0", id, error: { code, message } }); }
74
+
75
+ rejectAllPending(err) {
76
+ for (const p of this.pending.values()) p.reject(err);
77
+ this.pending.clear();
78
+ }
79
+
80
+ close() { this.rl.close(); }
81
+ }
package/src/server.js CHANGED
@@ -126,7 +126,7 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
126
126
  "delegate",
127
127
  {
128
128
  description:
129
- "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=composer-2.5, fast=false. Plan workflow: mode=plan, then resume with mode=agent and resumeSessionId. Auto-approves writes in workspace; surfaces clarifying questions via elicitation. Returns result, stopReason, sessionId, touchedFiles, and plan (in plan mode). See plugin delegate skill for orchestration.",
129
+ "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=composer-2.5, fast=false. Plan workflow: mode=plan, then resume with mode=agent and resumeSessionId. Auto-approves writes in workspace; surfaces clarifying questions via elicitation. Returns the final agent result selected after the last tool call, resultSource, finalMessageAvailable, stopReason, sessionId, touchedFiles, and plan (in plan mode). See plugin delegate skill for orchestration.",
130
130
  inputSchema: {
131
131
  spec: z.string().describe("Inline task brief (default): goal, scope, acceptance criteria. Optional file path if the user wants a persisted spec."),
132
132
  mode: z.enum(["agent", "plan", "ask"]).default("agent"),