cursor-delegate-mcp 1.2.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 +66 -86
- package/package.json +3 -3
- package/src/delegate.js +112 -27
- package/src/doctor.js +2 -1
- package/src/jsonrpc.js +81 -81
- package/src/server.js +1 -5
- package/src/spawn.js +0 -1
package/README.md
CHANGED
|
@@ -1,74 +1,69 @@
|
|
|
1
1
|
# Cursor Delegate MCP
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Let Claude think. Let Cursor build.**
|
|
4
4
|
|
|
5
|
-
](https://www.npmjs.com/package/cursor-delegate-mcp)
|
|
6
|
+
[](https://www.npmjs.com/package/cursor-delegate-mcp)
|
|
7
|
+
[](https://nodejs.org)
|
|
8
|
+
[](LICENSE)
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
An MCP server that lets Claude Code (or any MCP client) delegate coding tasks to **Cursor's CLI agent** — and get structured results back, not a wall of terminal text.
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
- **Plan before you build** — Run in plan mode, review the plan, then resume the same session to implement.
|
|
15
|
-
- **Get structured output** — Session id, which files changed, stop reason, and optional plan payload — not just raw terminal text.
|
|
16
|
-
- **Ask questions mid-run** — If Cursor needs a clarification, it comes back through the client's normal prompt.
|
|
17
|
-
- **Check setup** — The `doctor` tool tells you if cursor-agent is missing or misconfigured.
|
|
18
|
-
|
|
19
|
-
> Delegation **auto-approves file writes** in the target workspace.
|
|
20
|
-
|
|
21
|
-
## Requirements
|
|
12
|
+

|
|
22
13
|
|
|
23
|
-
|
|
24
|
-
- [cursor-agent](https://cursor.com/docs/cli/overview) installed and logged in (`cursor-agent login`)
|
|
14
|
+
## Why
|
|
25
15
|
|
|
26
|
-
|
|
16
|
+
Frontier models like **Opus** and **Fable** are brilliant orchestrators — great at understanding intent, planning, and reviewing. Cursor's **Composer** is a fast, cheap workhorse for the actual edits, with its own generous usage pool.
|
|
27
17
|
|
|
28
|
-
|
|
18
|
+
This bridge pairs them: the big brain writes the brief and reviews the diff; Cursor does the typing. Your Claude quota goes to thinking, not boilerplate.
|
|
29
19
|
|
|
30
|
-
|
|
20
|
+
## How it works
|
|
31
21
|
|
|
32
|
-
```
|
|
33
|
-
/
|
|
34
|
-
|
|
22
|
+
```
|
|
23
|
+
You → Claude (Opus / Fable — plans & reviews)
|
|
24
|
+
│ MCP delegate tool
|
|
25
|
+
▼
|
|
26
|
+
cursor-agent (Composer 2.5 — implements)
|
|
27
|
+
│ edits your workspace
|
|
28
|
+
▼
|
|
29
|
+
Structured result: files changed, session id, plan
|
|
35
30
|
```
|
|
36
31
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
### Use it
|
|
40
|
-
|
|
41
|
-
Say what you want in plain language — for example:
|
|
32
|
+
Delegation defaults to Cursor's **Composer 2.5**, which draws from the separate **Auto + Composer** usage pool — so implementation work doesn't eat into your API-model quota. Want a different model? Just say so: *"delegate with Opus"*.
|
|
42
33
|
|
|
43
|
-
|
|
34
|
+
**Three modes:** `agent` (implement, default) · `plan` (draft a plan, review, resume to implement) · `ask` (read-only Q&A).
|
|
44
35
|
|
|
45
|
-
|
|
36
|
+
> **Note:** delegation auto-approves file writes in the target workspace — review the diff afterward, like any teammate's work.
|
|
46
37
|
|
|
47
|
-
|
|
38
|
+
## Features
|
|
48
39
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
+
- 💬 **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** — final agent response, result source, session id, files changed, stop reason, and plan payload. Claude knows exactly what happened and what to review.
|
|
43
|
+
- 📋 **Plan mode** — have Cursor draft a plan first, review it, then resume the same session to implement.
|
|
44
|
+
- 🔍 **Ask mode** — read-only Q&A over the codebase, zero file changes.
|
|
45
|
+
- 🩺 **Built-in diagnostics** — a `doctor` tool that tells you exactly what's missing if setup isn't right.
|
|
46
|
+
- 🔌 **Works everywhere MCP does** — Claude Code, VS Code, Codex CLI, Kiro, Kilo Code, and more.
|
|
52
47
|
|
|
53
|
-
|
|
48
|
+
## Quick start
|
|
54
49
|
|
|
55
|
-
|
|
50
|
+
**Requirements:** [Node.js 22+](https://nodejs.org/) and [cursor-agent](https://cursor.com/docs/cli/overview) logged in (`cursor-agent login`).
|
|
56
51
|
|
|
57
|
-
|
|
52
|
+
### Claude Code (recommended)
|
|
58
53
|
|
|
59
54
|
```shell
|
|
60
|
-
|
|
55
|
+
/plugin marketplace add andreilungeanu/cursor-delegate-mcp
|
|
56
|
+
/plugin install cursor-delegate-mcp@cursor-delegate-mcp
|
|
61
57
|
```
|
|
62
58
|
|
|
63
|
-
|
|
59
|
+
Then just ask:
|
|
64
60
|
|
|
65
|
-
|
|
61
|
+
> Delegate to Cursor: migrate src/api from callbacks to async/await and update the tests, then walk me through what changed.
|
|
66
62
|
|
|
67
|
-
|
|
63
|
+
Claude writes the brief, Cursor grinds through the files, and Claude reviews the diff with you — that's the whole loop.
|
|
68
64
|
|
|
69
|
-
#### Antigravity 2.0
|
|
70
65
|
|
|
71
|
-
|
|
66
|
+
### Any other MCP client
|
|
72
67
|
|
|
73
68
|
```json
|
|
74
69
|
{
|
|
@@ -81,24 +76,8 @@ Clarifying-question prompts are interactive only on elicitation-capable clients
|
|
|
81
76
|
}
|
|
82
77
|
```
|
|
83
78
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
`~/.cursor/mcp.json`:
|
|
87
|
-
|
|
88
|
-
```json
|
|
89
|
-
{
|
|
90
|
-
"mcpServers": {
|
|
91
|
-
"cursor-delegate-mcp": {
|
|
92
|
-
"command": "npx",
|
|
93
|
-
"args": ["-y", "cursor-delegate-mcp"]
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
#### VS Code
|
|
100
|
-
|
|
101
|
-
`.vscode/mcp.json`:
|
|
79
|
+
<details>
|
|
80
|
+
<summary><strong>VS Code</strong> — <code>.vscode/mcp.json</code></summary>
|
|
102
81
|
|
|
103
82
|
```json
|
|
104
83
|
{
|
|
@@ -112,9 +91,10 @@ Clarifying-question prompts are interactive only on elicitation-capable clients
|
|
|
112
91
|
}
|
|
113
92
|
```
|
|
114
93
|
|
|
115
|
-
|
|
94
|
+
</details>
|
|
116
95
|
|
|
117
|
-
|
|
96
|
+
<details>
|
|
97
|
+
<summary><strong>Codex CLI</strong> — <code>~/.codex/config.toml</code></summary>
|
|
118
98
|
|
|
119
99
|
```toml
|
|
120
100
|
[mcp_servers.cursor-delegate-mcp]
|
|
@@ -122,9 +102,10 @@ command = "npx"
|
|
|
122
102
|
args = ["-y", "cursor-delegate-mcp"]
|
|
123
103
|
```
|
|
124
104
|
|
|
125
|
-
|
|
105
|
+
</details>
|
|
126
106
|
|
|
127
|
-
|
|
107
|
+
<details>
|
|
108
|
+
<summary><strong>Kiro</strong> — <code>~/.kiro/settings/mcp.json</code></summary>
|
|
128
109
|
|
|
129
110
|
```json
|
|
130
111
|
{
|
|
@@ -137,9 +118,10 @@ args = ["-y", "cursor-delegate-mcp"]
|
|
|
137
118
|
}
|
|
138
119
|
```
|
|
139
120
|
|
|
140
|
-
|
|
121
|
+
</details>
|
|
141
122
|
|
|
142
|
-
|
|
123
|
+
<details>
|
|
124
|
+
<summary><strong>Kilo Code</strong> — <code>~/.config/kilo/kilo.jsonc</code></summary>
|
|
143
125
|
|
|
144
126
|
```jsonc
|
|
145
127
|
{
|
|
@@ -153,28 +135,26 @@ args = ["-y", "cursor-delegate-mcp"]
|
|
|
153
135
|
}
|
|
154
136
|
```
|
|
155
137
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
## Delegation modes
|
|
159
|
-
|
|
160
|
-
Applies to both the plugin and the MCP server:
|
|
161
|
-
|
|
162
|
-
- **Agent (default)** — Cursor implements in your workspace; you review the diff afterward.
|
|
163
|
-
- **Plan** — Cursor drafts a plan first; review it, then resume and implement.
|
|
164
|
-
- **Ask** — Read-only Q&A over the codebase; no file changes.
|
|
138
|
+
</details>
|
|
165
139
|
|
|
166
|
-
|
|
140
|
+
<details>
|
|
141
|
+
<summary><strong>Antigravity 2.0</strong> — <code>~/.gemini/config/mcp_config.json</code></summary>
|
|
167
142
|
|
|
168
|
-
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"mcpServers": {
|
|
146
|
+
"cursor-delegate-mcp": {
|
|
147
|
+
"command": "npx",
|
|
148
|
+
"args": ["-y", "cursor-delegate-mcp"]
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
169
153
|
|
|
170
|
-
|
|
154
|
+
</details>
|
|
171
155
|
|
|
172
|
-
|
|
173
|
-
| -------- | ------- | ----------- |
|
|
174
|
-
| `ACP_AGENT_COMMAND` | `agent` | Launcher for the ACP agent process. |
|
|
175
|
-
| `ACP_AGENT_ARGS` | `acp` | Arguments passed to the launcher. Quote arguments that contain spaces: `--config "C:\path with spaces\acp.json"`. |
|
|
176
|
-
| `ACP_LOG_SIZE` | `2000` | ACP frames kept for the error transcript; `0` disables. |
|
|
156
|
+
Call the **`delegate`** tool with your task; run **`doctor`** if anything seems off.
|
|
177
157
|
|
|
178
158
|
## License
|
|
179
159
|
|
|
180
|
-
MIT © Andrei Lungeanu
|
|
160
|
+
MIT © [Andrei Lungeanu](https://github.com/andreilungeanu)
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursor-delegate-mcp",
|
|
3
|
-
"version": "1.
|
|
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",
|
|
7
|
-
"author": "Andrei Lungeanu <
|
|
7
|
+
"author": "Andrei Lungeanu <andrei@lungeanu.ro>",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/andreilungeanu/cursor-delegate-mcp.git"
|
|
10
|
+
"url": "git+https://github.com/andreilungeanu/cursor-delegate-mcp.git"
|
|
11
11
|
},
|
|
12
12
|
"bugs": {
|
|
13
13
|
"url": "https://github.com/andreilungeanu/cursor-delegate-mcp/issues"
|
package/src/delegate.js
CHANGED
|
@@ -35,7 +35,7 @@ export async function runDelegate({
|
|
|
35
35
|
spec, mode = "agent", resumeSessionId, workspace,
|
|
36
36
|
model = "composer-2.5", fast = false, clientFactory, onElicit,
|
|
37
37
|
idleMs = 90000, hardCapMs, timeoutMs, cancelGraceMs = 10000, killGraceMs = 5000,
|
|
38
|
-
onSessionReady, onProgress, gitChangedSet = gitChangedSetReal,
|
|
38
|
+
onSessionReady, onProgress, progressThrottleMs = 2000, gitChangedSet = gitChangedSetReal,
|
|
39
39
|
} = {}) {
|
|
40
40
|
const capMs = hardCapMs ?? timeoutMs ?? 3600000;
|
|
41
41
|
const MAX_OUTPUT = 10 * 1024 * 1024;
|
|
@@ -63,43 +63,117 @@ 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
|
|
67
|
-
let
|
|
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();
|
|
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
|
+
|
|
123
|
+
// Each stream reports its newest complete sentence, at most one per throttle window.
|
|
124
|
+
// Capital-letter boundary: cursor-agent thoughts arrive as sentences with no separator.
|
|
125
|
+
const SENTENCE_END = /[.!?](?=\s|[A-Z])|\n/;
|
|
126
|
+
const MARKDOWN_LINE = /^(?:[|#>`~*_=+-]|\d+[.)]\s)/;
|
|
127
|
+
const progressStream = (prefix) => {
|
|
128
|
+
let buf = "", pending = null, lastEmit = 0;
|
|
129
|
+
const flush = (force) => {
|
|
130
|
+
if (pending === null || (!force && Date.now() - lastEmit < progressThrottleMs)) return;
|
|
131
|
+
lastEmit = Date.now();
|
|
132
|
+
try { onProgress?.(prefix + pending); } catch {}
|
|
133
|
+
pending = null;
|
|
134
|
+
};
|
|
135
|
+
const take = (s) => {
|
|
136
|
+
const line = s.replace(/\s+/g, " ").trim().slice(0, 200);
|
|
137
|
+
if (line.length > 3 && !MARKDOWN_LINE.test(line)) pending = line;
|
|
138
|
+
flush(false);
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
push(text) {
|
|
142
|
+
buf += text;
|
|
143
|
+
for (let m; (m = SENTENCE_END.exec(buf)); buf = buf.slice(m.index + 1)) {
|
|
144
|
+
take(buf.slice(0, m.index + 1));
|
|
145
|
+
}
|
|
146
|
+
if (buf.length > 300) { take(buf); buf = ""; }
|
|
147
|
+
},
|
|
148
|
+
end() { take(buf); buf = ""; flush(true); },
|
|
149
|
+
reset() { buf = ""; pending = null; },
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
const thoughtProgress = progressStream("thinking: ");
|
|
153
|
+
const messageProgress = progressStream("Cursor: ");
|
|
154
|
+
|
|
70
155
|
client.on("update", (u) => {
|
|
71
156
|
const up = u?.update || {};
|
|
72
157
|
if (up.sessionUpdate === "plan") {
|
|
73
158
|
planEntries = up.entries || [];
|
|
74
159
|
}
|
|
75
160
|
if (up.sessionUpdate === "agent_thought_chunk" && up.content?.text) {
|
|
76
|
-
|
|
77
|
-
const tail = text.length > 200 ? text.slice(-200) : text;
|
|
78
|
-
try { onProgress?.("thinking: " + (tail.trim() || text.slice(0, 200))); } catch {}
|
|
161
|
+
thoughtProgress.push(up.content.text);
|
|
79
162
|
}
|
|
80
163
|
if (up.sessionUpdate === "tool_call") {
|
|
164
|
+
startTool(up.toolCallId, up.status);
|
|
81
165
|
const label = up.title || up.kind || "tool";
|
|
82
|
-
|
|
166
|
+
const path = up.locations?.[0]?.path;
|
|
167
|
+
const line = "running: " + String(label) + (path ? " — " + path : "");
|
|
168
|
+
try { onProgress?.(line.slice(0, 200)); } catch {}
|
|
83
169
|
}
|
|
84
170
|
if (up.sessionUpdate === "agent_message_chunk" && up.content?.text) {
|
|
85
171
|
const text = up.content.text;
|
|
86
|
-
if (!
|
|
87
|
-
|
|
88
|
-
if (text.length <= remaining) {
|
|
89
|
-
textChunks.push(text);
|
|
90
|
-
textLength += text.length;
|
|
91
|
-
} else if (remaining > 0) {
|
|
92
|
-
textChunks.push(text.slice(0, remaining));
|
|
93
|
-
textLength += remaining;
|
|
94
|
-
truncated = true;
|
|
95
|
-
} else {
|
|
96
|
-
truncated = true;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
const tail = text.length > 200 ? text.slice(-200) : text;
|
|
100
|
-
try { onProgress?.(tail.trim() || text.slice(0, 200)); } catch {}
|
|
172
|
+
if (!sawToolCall || (collectingPostToolResult && activeToolCalls.size === 0)) appendResult(text);
|
|
173
|
+
messageProgress.push(text);
|
|
101
174
|
}
|
|
102
175
|
if (up.sessionUpdate === "tool_call_update") {
|
|
176
|
+
updateToolStatus(up.toolCallId, up.status);
|
|
103
177
|
for (const c of up.content || []) {
|
|
104
178
|
if (c.type === "diff" && c.path) {
|
|
105
179
|
touched.add(c.path);
|
|
@@ -111,7 +185,7 @@ export async function runDelegate({
|
|
|
111
185
|
|
|
112
186
|
try {
|
|
113
187
|
let sessionId;
|
|
114
|
-
const gitBefore = gitChangedSet(workspace);
|
|
188
|
+
const gitBefore = gitChangedSet(workspace);
|
|
115
189
|
const res = await supervisor.supervise(async () => {
|
|
116
190
|
await client.start();
|
|
117
191
|
await client.initialize();
|
|
@@ -122,21 +196,32 @@ export async function runDelegate({
|
|
|
122
196
|
await client.setModel(sessionId, model);
|
|
123
197
|
if (composerFastToggleApplies(model)) await client.setFast(sessionId, fast);
|
|
124
198
|
await client.setMode(sessionId, mode);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
199
|
+
resetResult();
|
|
200
|
+
sawToolCall = false;
|
|
201
|
+
collectingPostToolResult = false;
|
|
202
|
+
activeToolCalls.clear();
|
|
203
|
+
thoughtProgress.reset();
|
|
204
|
+
messageProgress.reset();
|
|
128
205
|
planEntries = [];
|
|
129
206
|
planOverview = undefined;
|
|
130
207
|
planDetail = undefined;
|
|
131
208
|
touched.clear();
|
|
132
209
|
return client.prompt(sessionId, resolveSpec(spec));
|
|
133
210
|
});
|
|
134
|
-
|
|
211
|
+
thoughtProgress.end();
|
|
212
|
+
messageProgress.end();
|
|
213
|
+
let result = resultChunks.join("");
|
|
135
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";
|
|
136
219
|
const gitAfter = gitChangedSet(workspace);
|
|
137
220
|
const touchedResult = computeTouched({ before: gitBefore, after: gitAfter, diffTouched: [...touched], workspace });
|
|
138
221
|
const out = {
|
|
139
222
|
result,
|
|
223
|
+
resultSource,
|
|
224
|
+
finalMessageAvailable,
|
|
140
225
|
stopReason: res?.stopReason,
|
|
141
226
|
sessionId,
|
|
142
227
|
touchedFiles: touchedResult.files,
|
package/src/doctor.js
CHANGED
|
@@ -68,6 +68,7 @@ export async function runDoctor({
|
|
|
68
68
|
spawnSpec = resolveAcpSpawn(),
|
|
69
69
|
clientFactory = (opts) => new AcpClient(opts),
|
|
70
70
|
workspace,
|
|
71
|
+
handshakeTimeoutMs = HANDSHAKE_TIMEOUT_MS,
|
|
71
72
|
} = {}) {
|
|
72
73
|
const { capabilities, version } = getClientInfo();
|
|
73
74
|
const agentProbe = await probeAgentVersion(spawnSpec);
|
|
@@ -95,7 +96,7 @@ export async function runDoctor({
|
|
|
95
96
|
spawnSpec,
|
|
96
97
|
clientFactory,
|
|
97
98
|
workspace,
|
|
98
|
-
timeoutMs:
|
|
99
|
+
timeoutMs: handshakeTimeoutMs,
|
|
99
100
|
});
|
|
100
101
|
}
|
|
101
102
|
|
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
|
@@ -24,11 +24,7 @@ export async function runDelegateTool({ args, extra, server, runDelegate, inFlig
|
|
|
24
24
|
let onProgress = () => {};
|
|
25
25
|
if (progressToken != null) {
|
|
26
26
|
let progress = 0;
|
|
27
|
-
let lastSent = 0;
|
|
28
27
|
onProgress = (message) => {
|
|
29
|
-
const now = Date.now();
|
|
30
|
-
if (progress > 0 && now - lastSent < 100) return;
|
|
31
|
-
lastSent = now;
|
|
32
28
|
try {
|
|
33
29
|
extra.sendNotification({
|
|
34
30
|
method: "notifications/progress",
|
|
@@ -130,7 +126,7 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
130
126
|
"delegate",
|
|
131
127
|
{
|
|
132
128
|
description:
|
|
133
|
-
"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.",
|
|
134
130
|
inputSchema: {
|
|
135
131
|
spec: z.string().describe("Inline task brief (default): goal, scope, acceptance criteria. Optional file path if the user wants a persisted spec."),
|
|
136
132
|
mode: z.enum(["agent", "plan", "ask"]).default("agent"),
|