cursor-delegate-mcp 1.21.0 → 2.0.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/CHANGELOG.md +746 -0
- package/package.json +3 -2
- package/src/acp-client.js +6 -2
- package/src/delegate.js +84 -54
- package/src/doctor.js +11 -1
- package/src/jsonrpc.js +30 -2
- package/src/proc.js +7 -1
- package/src/request-router.js +10 -5
- package/src/server.js +90 -27
- package/src/session-supervisor.js +2 -1
- package/src/turn-state.js +21 -35
|
@@ -29,7 +29,8 @@ export class SessionSupervisor {
|
|
|
29
29
|
this._onExit = (info) => {
|
|
30
30
|
this._trip(
|
|
31
31
|
"agent-exit",
|
|
32
|
-
|
|
32
|
+
// Kept whole, for the reason acp-client.js states where it builds the same message.
|
|
33
|
+
`agent exited (code=${info.code}${info.signal ? ", signal=" + info.signal : ""})${info.stderr ? ": " + String(info.stderr) : ""}`
|
|
33
34
|
);
|
|
34
35
|
};
|
|
35
36
|
}
|
package/src/turn-state.js
CHANGED
|
@@ -4,18 +4,6 @@
|
|
|
4
4
|
// also what reset() applies — a field added there is reset for free, and one that is missed is a
|
|
5
5
|
// silent stale-data bug on resume.
|
|
6
6
|
|
|
7
|
-
const MAX_OUTPUT = 10 * 1024 * 1024;
|
|
8
|
-
const TRUNCATION_MARKER = "\n\n[output truncated at 10MB]";
|
|
9
|
-
|
|
10
|
-
// Cutting a UTF-16 string at an arbitrary index can split a surrogate pair and leave a lone
|
|
11
|
-
// half-character — ill-formed Unicode that strict JSON consumers reject or mangle. Step back
|
|
12
|
-
// one unit when the boundary would land inside a pair.
|
|
13
|
-
function cutAtCodePoint(s, n) {
|
|
14
|
-
if (n >= s.length) return s;
|
|
15
|
-
const cu = s.charCodeAt(n - 1);
|
|
16
|
-
return s.slice(0, cu >= 0xd800 && cu <= 0xdbff ? n - 1 : n);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
7
|
const isTerminalToolStatus = (status) =>
|
|
20
8
|
status === "completed" || status === "failed" || status === "cancelled";
|
|
21
9
|
|
|
@@ -58,8 +46,6 @@ function progressStream(prefix, onProgress, throttleMs) {
|
|
|
58
46
|
function freshFields() {
|
|
59
47
|
return {
|
|
60
48
|
resultChunks: [],
|
|
61
|
-
resultLength: 0,
|
|
62
|
-
truncated: false,
|
|
63
49
|
// Text superseded by a later tool call is normally a preamble ("Inspecting the
|
|
64
50
|
// implementation."), but the rule cannot tell a preamble from the whole answer: an agent
|
|
65
51
|
// that replies and then runs one more command has its entire reply discarded, leaving the
|
|
@@ -69,6 +55,10 @@ function freshFields() {
|
|
|
69
55
|
sawToolCall: false,
|
|
70
56
|
collectingPostToolResult: false,
|
|
71
57
|
activeToolCalls: new Set(),
|
|
58
|
+
// Ids observed terminal, so a stale non-terminal re-send for one is recognized and dropped
|
|
59
|
+
// instead of restarting collection — which would demote an already-collected final message
|
|
60
|
+
// to discardedResult and mislabel it pre-tool-fallback.
|
|
61
|
+
finishedToolCalls: new Set(),
|
|
72
62
|
planEntries: [],
|
|
73
63
|
planOverview: undefined,
|
|
74
64
|
planDetail: undefined,
|
|
@@ -97,51 +87,47 @@ export function makeTurnState({ onProgress, progressThrottleMs = 2000 } = {}) {
|
|
|
97
87
|
state.messages.reset();
|
|
98
88
|
},
|
|
99
89
|
|
|
100
|
-
// The result text as it stands
|
|
90
|
+
// The result text as it stands.
|
|
101
91
|
text() {
|
|
102
|
-
|
|
103
|
-
return state.truncated ? joined + TRUNCATION_MARKER : joined;
|
|
92
|
+
return state.resultChunks.join("");
|
|
104
93
|
},
|
|
105
94
|
|
|
106
95
|
resetResult() {
|
|
107
|
-
if (state.
|
|
96
|
+
if (state.resultChunks.length > 0) state.discardedResult = state.resultChunks.join("");
|
|
108
97
|
state.resultChunks.length = 0;
|
|
109
|
-
state.resultLength = 0;
|
|
110
|
-
state.truncated = false;
|
|
111
98
|
},
|
|
112
99
|
|
|
100
|
+
// The stream is the model's own message, bounded by its output limit; a byte cap
|
|
101
|
+
// here would hand back a partial answer as if it were the whole one.
|
|
113
102
|
appendResult(text) {
|
|
114
|
-
|
|
115
|
-
const remaining = MAX_OUTPUT - state.resultLength;
|
|
116
|
-
if (text.length <= remaining) {
|
|
117
|
-
state.resultChunks.push(text);
|
|
118
|
-
state.resultLength += text.length;
|
|
119
|
-
} else if (remaining > 0) {
|
|
120
|
-
const cut = cutAtCodePoint(text, remaining);
|
|
121
|
-
state.resultChunks.push(cut);
|
|
122
|
-
state.resultLength += cut.length;
|
|
123
|
-
state.truncated = true;
|
|
124
|
-
} else {
|
|
125
|
-
state.truncated = true;
|
|
126
|
-
}
|
|
103
|
+
state.resultChunks.push(text);
|
|
127
104
|
},
|
|
128
105
|
|
|
129
106
|
startTool(toolCallId, status) {
|
|
130
107
|
state.sawToolCall = true;
|
|
131
108
|
state.collectingPostToolResult = false;
|
|
132
109
|
state.resetResult();
|
|
133
|
-
if (toolCallId != null && !isTerminalToolStatus(status))
|
|
110
|
+
if (toolCallId != null && !isTerminalToolStatus(status)) {
|
|
111
|
+
state.activeToolCalls.add(toolCallId);
|
|
112
|
+
// A fresh tool_call frame for a finished id is the agent reusing it, not history.
|
|
113
|
+
state.finishedToolCalls.delete(toolCallId);
|
|
114
|
+
}
|
|
115
|
+
if (toolCallId != null && isTerminalToolStatus(status)) state.finishedToolCalls.add(toolCallId);
|
|
134
116
|
if (isTerminalToolStatus(status) && state.activeToolCalls.size === 0) state.collectingPostToolResult = true;
|
|
135
117
|
},
|
|
136
118
|
|
|
137
119
|
updateToolStatus(toolCallId, status) {
|
|
138
120
|
if (!status) return;
|
|
121
|
+
if (toolCallId != null && !isTerminalToolStatus(status) && state.finishedToolCalls.has(toolCallId)) return;
|
|
139
122
|
if (!state.sawToolCall) {
|
|
140
123
|
state.sawToolCall = true;
|
|
141
124
|
state.resetResult();
|
|
142
125
|
}
|
|
143
126
|
if (isTerminalToolStatus(status)) {
|
|
144
|
-
if (toolCallId != null)
|
|
127
|
+
if (toolCallId != null) {
|
|
128
|
+
state.activeToolCalls.delete(toolCallId);
|
|
129
|
+
state.finishedToolCalls.add(toolCallId);
|
|
130
|
+
}
|
|
145
131
|
if (state.activeToolCalls.size === 0 && !state.collectingPostToolResult) {
|
|
146
132
|
// Discard any message text emitted while tools were still running.
|
|
147
133
|
// A duplicate or late terminal update must not wipe an already-collected final message.
|