@causyne/agent 1.20.0 → 1.20.7
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 +13 -9
- package/SECURITY.md +1 -4
- package/package.json +1 -1
- package/src/acp/client.js +176 -26
- package/src/acp/client.ts +167 -25
- package/src/acp/protocol.js +116 -0
- package/src/acp/protocol.ts +163 -0
- package/src/acp/server.js +5 -6
- package/src/acp/server.ts +4 -6
- package/src/agentLoop.d.ts +1 -0
- package/src/agentLoop.js +681 -245
- package/src/agentLoop.ts +708 -262
- package/src/agentPolicy.js +9 -0
- package/src/agentPolicy.ts +9 -0
- package/src/approvalPolicy.js +55 -0
- package/src/approvalPolicy.ts +66 -0
- package/src/browser/browserRuntime.js +217 -14
- package/src/browser/browserRuntime.ts +255 -14
- package/src/browser/causyneBrowser.js +1215 -68
- package/src/browser/causyneBrowser.ts +1340 -72
- package/src/cliMode.js +52 -29
- package/src/commands.js +141 -17
- package/src/config.js +22 -12
- package/src/continuum/ui/continuumPicker.js +18 -1
- package/src/continuum/ui/continuumPicker.ts +19 -1
- package/src/dynamicCatalogue.js +87 -20
- package/src/dynamicCatalogue.ts +85 -15
- package/src/launchIntent.js +40 -0
- package/src/launchIntent.ts +49 -0
- package/src/memoryManager.js +26 -2
- package/src/modelCatalogue.js +2 -0
- package/src/planCache.js +320 -11
- package/src/planCache.ts +402 -13
- package/src/providers/acp.js +173 -18
- package/src/providers/acp.ts +169 -19
- package/src/providers/antigravity.d.ts +5 -1
- package/src/providers/antigravity.js +674 -34
- package/src/providers/antigravity.ts +707 -35
- package/src/providers/base.d.ts +10 -0
- package/src/providers/factory.js +2 -0
- package/src/providers/pi.js +161 -0
- package/src/providers/pi.ts +148 -0
- package/src/provisioning/capabilityProvisioner.js +17 -0
- package/src/provisioning/capabilityTools.js +1 -1
- package/src/sandbox.js +30 -39
- package/src/sessionJournal.js +53 -10
- package/src/sessionJournal.ts +64 -10
- package/src/taskShape.js +9 -9
- package/src/taskShape.ts +9 -9
- package/src/timeMachine.js +124 -0
- package/src/timeMachine.ts +141 -0
- package/src/toolPacks.js +4 -10
- package/src/tools/archive.js +196 -59
- package/src/tools/archive.ts +220 -0
- package/src/tools/browserAutomator.js +78 -9
- package/src/tools/browserAutomator.ts +90 -9
- package/src/tools/desktopOpen.js +114 -31
- package/src/tools/desktopOpen.ts +144 -0
- package/src/tools/gitExec.js +5 -3
- package/src/tools/nativeEngine.js +4 -3
- package/src/tools/nativeEngine.ts +5 -3
- package/src/tools/openSourceToolProvisioner.js +5 -4
- package/src/tools/openSourceToolProvisioner.ts +5 -4
- package/src/tools/registry.js +3 -0
- package/src/tools/screenshot.js +55 -71
- package/src/tools/screenshot.ts +70 -0
- package/src/tools/sysRun.js +284 -117
- package/src/tools/sysRun.ts +347 -0
- package/src/tools/toolSelfRepair.js +109 -2
- package/src/tools/toolSelfRepair.ts +100 -2
- package/src/tools/updatePlan.js +49 -1
- package/src/tools/updatePlan.ts +43 -1
- package/src/tools/viewImage.js +93 -78
- package/src/tools/viewImage.ts +116 -0
- package/src/tools/webFetch.js +20 -6
- package/src/tools/webFetch.ts +26 -6
- package/src/tui/activityLayout.js +9 -0
- package/src/tui/activityLayout.ts +10 -0
- package/src/tui/block.d.ts +1 -0
- package/src/tui/chatRenderer.d.ts +23 -0
- package/src/tui/chatRenderer.js +49 -49
- package/src/tui/clipboardSync.js +28 -1
- package/src/tui/clipboardSync.ts +26 -1
- package/src/tui/codeProgress.js +299 -0
- package/src/tui/codeProgress.ts +304 -0
- package/src/tui/codeStreamRenderer.js +132 -0
- package/src/tui/codeStreamRenderer.ts +141 -0
- package/src/tui/commandPresentation.js +11 -0
- package/src/tui/commandPresentation.ts +18 -0
- package/src/tui/completion.js +45 -13
- package/src/tui/composerControls.js +131 -0
- package/src/tui/composerControls.ts +184 -0
- package/src/tui/diff.d.ts +2 -0
- package/src/tui/home.js +4 -2
- package/src/tui/homeTransition.js +21 -0
- package/src/tui/homeTransition.ts +27 -0
- package/src/tui/homeView.js +62 -0
- package/src/tui/homeView.ts +91 -0
- package/src/tui/layout.js +46 -0
- package/src/tui/layout.ts +52 -0
- package/src/tui/messageActionPlacement.js +16 -0
- package/src/tui/messageActionPlacement.ts +25 -0
- package/src/tui/messageInteraction.js +221 -0
- package/src/tui/messageInteraction.ts +275 -0
- package/src/tui/modelPicker.js +4 -24
- package/src/tui/modelPicker.ts +4 -20
- package/src/tui/mouseHover.js +6 -0
- package/src/tui/mouseHover.ts +5 -0
- package/src/tui/prompt.js +175 -101
- package/src/tui/resizeRecovery.js +15 -0
- package/src/tui/resizeRecovery.ts +27 -0
- package/src/tui/scrollInteraction.js +97 -0
- package/src/tui/scrollInteraction.ts +189 -0
- package/src/tui/sessionLayout.js +12 -0
- package/src/tui/sessionLayout.ts +12 -0
- package/src/tui/sessionPicker.js +111 -16
- package/src/tui/sessionPicker.ts +121 -16
- package/src/tui/sessionSidebar.js +78 -0
- package/src/tui/sessionSidebar.ts +95 -0
- package/src/tui/setup.js +1 -1
- package/src/tui/setup.ts +1 -1
- package/src/tui/stageSurface.js +120 -58
- package/src/tui/text.d.ts +6 -0
- package/src/tui/textLayout.js +23 -0
- package/src/tui/textLayout.ts +28 -0
- package/src/tui/viewport.js +204 -279
- package/src/tui/viewport.ts +326 -0
- package/src/types/contracts.ts +54 -0
- package/src/utils/paths.js +5 -4
- package/src/utils/paths.ts +5 -5
package/README.md
CHANGED
|
@@ -12,29 +12,33 @@ documentation is intentionally concise while the project is evolving.
|
|
|
12
12
|
|
|
13
13
|
Learn more at [causyne.com](https://causyne.com/).
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Installation
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
This build is provided specifically for debugging, testing, and architectural evaluation. If you are exploring or debugging the harness, you can install it using the automated script or directly through npm.
|
|
18
|
+
|
|
19
|
+
For macOS, Linux, or WSL:
|
|
18
20
|
|
|
19
21
|
```sh
|
|
20
22
|
curl -fsSL https://causyne.com/install.sh | bash
|
|
21
23
|
```
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
For Windows PowerShell:
|
|
24
26
|
|
|
25
27
|
```powershell
|
|
26
28
|
irm https://causyne.com/install.ps1 | iex
|
|
27
29
|
```
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
Alternatively, you can install the global package via npm:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
npm install -g @causyne/agent
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Please treat this release as an experimental preview built for debugging and hands-on testing rather than day-to-day production workloads. As the developer behind Causyne, I would be genuinely grateful for your feedback, edge-case findings, and diagnostic reports. If you run into unexpected behavior or have thoughts on how the runtime behaves, please open an issue on GitHub or reach out directly to help@causyne.com.
|
|
32
38
|
|
|
33
39
|
## Contact
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
- Product support and troubleshooting: [help@causyne.com](mailto:help@causyne.com)
|
|
37
|
-
- Partnerships and direct communication: [ikbal@causyne.com](mailto:ikbal@causyne.com)
|
|
41
|
+
For general inquiries and business communication, reach out to contact@causyne.com. For technical questions, bug reports, and diagnostic feedback, email help@causyne.com. For security disclosures and vulnerability reports, email security@causyne.com. For partnerships and direct collaboration, write to ikbal@causyne.com.
|
|
38
42
|
|
|
39
43
|
## Development
|
|
40
44
|
|
package/SECURITY.md
CHANGED
|
@@ -18,7 +18,4 @@ cannot prove that a repository contains no secrets.
|
|
|
18
18
|
|
|
19
19
|
## Reporting a vulnerability
|
|
20
20
|
|
|
21
|
-
Please avoid publishing exploit details in a public issue.
|
|
22
|
-
private security-reporting channel when it becomes available. Until that channel
|
|
23
|
-
is published, retain the report privately rather than exposing user data or a
|
|
24
|
-
working exploit.
|
|
21
|
+
Please avoid publishing exploit details in a public issue. Report any security concern or vulnerability directly to security@causyne.com so it can be investigated and resolved promptly.
|
package/package.json
CHANGED
package/src/acp/client.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { ACP_ERROR_CODES, ACP_METHODS, ACP_PROTOCOL_VERSION, isJsonRpcRequest, isJsonRpcResponse } from './protocol.js';
|
|
4
|
+
import { ACP_ERROR_CODES, ACP_METHODS, ACP_PROTOCOL_VERSION, extractAcpSessionModels, isJsonRpcRequest, isJsonRpcResponse } from './protocol.js';
|
|
5
|
+
function createAbortError(message = 'ACP operation aborted by user') {
|
|
6
|
+
const err = new Error(message);
|
|
7
|
+
err.name = 'AbortError';
|
|
8
|
+
return err;
|
|
9
|
+
}
|
|
5
10
|
const MAX_STDERR_CHARS = 4000;
|
|
6
11
|
const MAX_UPDATE_CHARS = 200_000;
|
|
7
12
|
export class AcpClient {
|
|
@@ -14,6 +19,12 @@ export class AcpClient {
|
|
|
14
19
|
closed = false;
|
|
15
20
|
exitError = null;
|
|
16
21
|
initResult = null;
|
|
22
|
+
sessionModels = new Map();
|
|
23
|
+
latestSessionModels = {
|
|
24
|
+
availableModels: [],
|
|
25
|
+
modelLabels: {},
|
|
26
|
+
usesConfigOption: false
|
|
27
|
+
};
|
|
17
28
|
constructor(options) {
|
|
18
29
|
this.options = options;
|
|
19
30
|
}
|
|
@@ -29,7 +40,55 @@ export class AcpClient {
|
|
|
29
40
|
get authMethods() {
|
|
30
41
|
return this.initResult?.authMethods;
|
|
31
42
|
}
|
|
32
|
-
|
|
43
|
+
get discoveredModels() {
|
|
44
|
+
return [...this.latestSessionModels.availableModels];
|
|
45
|
+
}
|
|
46
|
+
get currentModelId() {
|
|
47
|
+
return this.latestSessionModels.currentModelId;
|
|
48
|
+
}
|
|
49
|
+
get modelLabels() {
|
|
50
|
+
return { ...this.latestSessionModels.modelLabels };
|
|
51
|
+
}
|
|
52
|
+
getSessionModels(sessionId) {
|
|
53
|
+
if (sessionId && this.sessionModels.has(sessionId)) {
|
|
54
|
+
const state = this.sessionModels.get(sessionId);
|
|
55
|
+
return {
|
|
56
|
+
currentModelId: state.currentModelId,
|
|
57
|
+
availableModels: [...state.availableModels],
|
|
58
|
+
modelLabels: { ...state.modelLabels },
|
|
59
|
+
usesConfigOption: state.usesConfigOption,
|
|
60
|
+
configOptionId: state.configOptionId
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
currentModelId: this.latestSessionModels.currentModelId,
|
|
65
|
+
availableModels: [...this.latestSessionModels.availableModels],
|
|
66
|
+
modelLabels: { ...this.latestSessionModels.modelLabels },
|
|
67
|
+
usesConfigOption: this.latestSessionModels.usesConfigOption,
|
|
68
|
+
configOptionId: this.latestSessionModels.configOptionId
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
recordSessionModels(sessionId, payload) {
|
|
72
|
+
const extracted = extractAcpSessionModels(payload);
|
|
73
|
+
if (extracted.availableModels.length === 0 && !extracted.currentModelId) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const existing = this.sessionModels.get(sessionId);
|
|
77
|
+
const merged = {
|
|
78
|
+
currentModelId: extracted.currentModelId ?? existing?.currentModelId,
|
|
79
|
+
availableModels: extracted.availableModels.length > 0
|
|
80
|
+
? extracted.availableModels
|
|
81
|
+
: (existing?.availableModels ?? []),
|
|
82
|
+
modelLabels: { ...(existing?.modelLabels ?? {}), ...extracted.modelLabels },
|
|
83
|
+
usesConfigOption: extracted.usesConfigOption || Boolean(existing?.usesConfigOption),
|
|
84
|
+
configOptionId: extracted.configOptionId ?? existing?.configOptionId
|
|
85
|
+
};
|
|
86
|
+
this.sessionModels.set(sessionId, merged);
|
|
87
|
+
this.latestSessionModels = merged;
|
|
88
|
+
}
|
|
89
|
+
async start(signal) {
|
|
90
|
+
if (signal?.aborted)
|
|
91
|
+
throw createAbortError();
|
|
33
92
|
if (this.child)
|
|
34
93
|
throw new Error('client already started');
|
|
35
94
|
const args = this.options.args ?? [];
|
|
@@ -42,6 +101,8 @@ export class AcpClient {
|
|
|
42
101
|
this.child = child;
|
|
43
102
|
child.stdout.setEncoding('utf8');
|
|
44
103
|
child.stdout.on('data', (chunk) => {
|
|
104
|
+
if (this.closed)
|
|
105
|
+
return;
|
|
45
106
|
this.buffer += chunk;
|
|
46
107
|
void this.drain();
|
|
47
108
|
});
|
|
@@ -50,8 +111,8 @@ export class AcpClient {
|
|
|
50
111
|
this.stderrTail = `${this.stderrTail}${chunk}`.slice(-MAX_STDERR_CHARS);
|
|
51
112
|
});
|
|
52
113
|
child.on('error', (error) => this.failAll(new Error(`agent process failed: ${error.message}`)));
|
|
53
|
-
child.on('exit', (code,
|
|
54
|
-
const detail = this.stderrTail.trim() || `exit code ${code ?? 'null'}${
|
|
114
|
+
child.on('exit', (code, exitSignal) => {
|
|
115
|
+
const detail = this.stderrTail.trim() || `exit code ${code ?? 'null'}${exitSignal ? ` signal ${exitSignal}` : ''}`;
|
|
55
116
|
this.failAll(new Error(`agent process exited: ${detail}`));
|
|
56
117
|
});
|
|
57
118
|
const hasFsRead = Boolean(this.options.fsReadHandler || this.options.cwd);
|
|
@@ -65,18 +126,19 @@ export class AcpClient {
|
|
|
65
126
|
},
|
|
66
127
|
clientInfo: { name: 'Causyne Agent', version: this.options.clientVersion ?? '0.0.0' }
|
|
67
128
|
};
|
|
68
|
-
const result = await this.request(ACP_METHODS.INITIALIZE, params, 30_000);
|
|
129
|
+
const result = await this.request(ACP_METHODS.INITIALIZE, params, 30_000, signal);
|
|
69
130
|
this.initResult = result;
|
|
70
131
|
return result;
|
|
71
132
|
}
|
|
72
|
-
async newSession(cwd, mcpServers = []) {
|
|
133
|
+
async newSession(cwd, mcpServers = [], signal) {
|
|
73
134
|
const result = await this.request(ACP_METHODS.NEW_SESSION, {
|
|
74
135
|
cwd,
|
|
75
136
|
mcpServers
|
|
76
|
-
}, 30_000);
|
|
137
|
+
}, 30_000, signal);
|
|
77
138
|
if (!result || typeof result.sessionId !== 'string' || !result.sessionId) {
|
|
78
139
|
throw new Error('agent did not return a session id');
|
|
79
140
|
}
|
|
141
|
+
this.recordSessionModels(result.sessionId, result);
|
|
80
142
|
return result.sessionId;
|
|
81
143
|
}
|
|
82
144
|
async authenticate(methodId, params = {}) {
|
|
@@ -85,11 +147,36 @@ export class AcpClient {
|
|
|
85
147
|
params
|
|
86
148
|
}, 30_000);
|
|
87
149
|
}
|
|
88
|
-
async setSessionModel(sessionId, modelId) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
150
|
+
async setSessionModel(sessionId, modelId, signal) {
|
|
151
|
+
const state = this.sessionModels.get(sessionId) ?? this.latestSessionModels;
|
|
152
|
+
try {
|
|
153
|
+
const res = await this.request(ACP_METHODS.SET_MODEL, {
|
|
154
|
+
sessionId,
|
|
155
|
+
modelId
|
|
156
|
+
}, 5_000, signal);
|
|
157
|
+
this.recordSessionModels(sessionId, res);
|
|
158
|
+
const updated = this.sessionModels.get(sessionId);
|
|
159
|
+
if (updated) {
|
|
160
|
+
updated.currentModelId = modelId;
|
|
161
|
+
this.latestSessionModels = updated;
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
if (signal?.aborted || (err instanceof Error && err.name === 'AbortError')) {
|
|
167
|
+
throw err;
|
|
168
|
+
}
|
|
169
|
+
if (state.usesConfigOption) {
|
|
170
|
+
const res = await this.request(ACP_METHODS.SET_CONFIG_OPTION, {
|
|
171
|
+
sessionId,
|
|
172
|
+
configId: state.configOptionId || 'model',
|
|
173
|
+
value: modelId
|
|
174
|
+
}, 5_000, signal);
|
|
175
|
+
this.recordSessionModels(sessionId, res);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
throw err;
|
|
179
|
+
}
|
|
93
180
|
}
|
|
94
181
|
async setSessionMode(sessionId, modeId) {
|
|
95
182
|
await this.request(ACP_METHODS.SET_MODE, {
|
|
@@ -98,37 +185,56 @@ export class AcpClient {
|
|
|
98
185
|
}, 30_000);
|
|
99
186
|
}
|
|
100
187
|
async loadSession(sessionId, cwd) {
|
|
101
|
-
|
|
188
|
+
const res = await this.request(ACP_METHODS.LOAD, {
|
|
102
189
|
sessionId,
|
|
103
190
|
cwd: cwd || this.options.cwd
|
|
104
191
|
}, 30_000);
|
|
192
|
+
this.recordSessionModels(sessionId, res);
|
|
193
|
+
return res;
|
|
105
194
|
}
|
|
106
|
-
async prompt(sessionId, input) {
|
|
195
|
+
async prompt(sessionId, input, signal) {
|
|
196
|
+
if (signal?.aborted)
|
|
197
|
+
throw createAbortError();
|
|
107
198
|
const blocks = typeof input === 'string' ? [{ type: 'text', text: input }] : input;
|
|
108
199
|
let collected = '';
|
|
109
200
|
const collector = (update) => {
|
|
110
|
-
|
|
201
|
+
if (signal?.aborted)
|
|
202
|
+
return;
|
|
203
|
+
// handleLine already notifies options.onUpdate for this session. Calling
|
|
204
|
+
// it again here duplicated every live chunk and file-action frame.
|
|
111
205
|
if (update.sessionUpdate === 'agent_message_chunk' && update.content.type === 'text') {
|
|
112
206
|
collected = `${collected}${update.content.text}`.slice(0, MAX_UPDATE_CHARS);
|
|
113
207
|
}
|
|
114
208
|
};
|
|
115
209
|
const previous = this.updateListener;
|
|
116
210
|
this.updateListener = (sessionIdFromEvent, update) => {
|
|
211
|
+
if (signal?.aborted)
|
|
212
|
+
return;
|
|
117
213
|
previous?.(sessionIdFromEvent, update);
|
|
118
214
|
if (sessionIdFromEvent === sessionId)
|
|
119
215
|
collector(update);
|
|
120
216
|
};
|
|
217
|
+
const onAbort = () => {
|
|
218
|
+
try {
|
|
219
|
+
this.notifyCancel(sessionId);
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
// ignore cancel write failure
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
121
226
|
try {
|
|
122
227
|
const response = await this.request(ACP_METHODS.PROMPT, {
|
|
123
228
|
sessionId,
|
|
124
229
|
prompt: blocks
|
|
125
|
-
}, this.options.promptTimeoutMs ?? 15 * 60 * 1000);
|
|
230
|
+
}, this.options.promptTimeoutMs ?? 15 * 60 * 1000, signal);
|
|
126
231
|
return {
|
|
127
232
|
stopReason: response?.stopReason ?? 'end_turn',
|
|
128
233
|
text: collected
|
|
129
234
|
};
|
|
130
235
|
}
|
|
131
236
|
finally {
|
|
237
|
+
signal?.removeEventListener('abort', onAbort);
|
|
132
238
|
this.updateListener = previous;
|
|
133
239
|
}
|
|
134
240
|
}
|
|
@@ -144,21 +250,46 @@ export class AcpClient {
|
|
|
144
250
|
return;
|
|
145
251
|
this.closed = true;
|
|
146
252
|
const child = this.child;
|
|
253
|
+
this.child = null;
|
|
147
254
|
this.failAll(new Error('client closed'));
|
|
148
255
|
if (!child)
|
|
149
256
|
return;
|
|
257
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
258
|
+
return;
|
|
150
259
|
await new Promise((resolve) => {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
260
|
+
let settled = false;
|
|
261
|
+
const done = () => {
|
|
262
|
+
if (settled)
|
|
263
|
+
return;
|
|
264
|
+
settled = true;
|
|
156
265
|
clearTimeout(timer);
|
|
157
266
|
resolve();
|
|
158
|
-
}
|
|
159
|
-
|
|
267
|
+
};
|
|
268
|
+
const timer = setTimeout(() => {
|
|
269
|
+
try {
|
|
270
|
+
child.kill('SIGKILL');
|
|
271
|
+
}
|
|
272
|
+
catch { /* ignore */ }
|
|
273
|
+
done();
|
|
274
|
+
}, 250);
|
|
275
|
+
if (typeof timer.unref === 'function')
|
|
276
|
+
timer.unref();
|
|
277
|
+
child.once('exit', done);
|
|
278
|
+
try {
|
|
279
|
+
child.stdin.destroy();
|
|
280
|
+
child.stdout.destroy();
|
|
281
|
+
child.stderr.destroy();
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
// ignore stream destroy errors
|
|
285
|
+
}
|
|
286
|
+
try {
|
|
287
|
+
child.kill('SIGTERM');
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
done();
|
|
291
|
+
}
|
|
160
292
|
});
|
|
161
|
-
this.child = null;
|
|
162
293
|
}
|
|
163
294
|
updateListener = null;
|
|
164
295
|
write(message) {
|
|
@@ -201,6 +332,7 @@ export class AcpClient {
|
|
|
201
332
|
if (method === ACP_METHODS.UPDATE) {
|
|
202
333
|
const params = parsed.params;
|
|
203
334
|
if (params && typeof params.sessionId === 'string' && params.update) {
|
|
335
|
+
this.recordSessionModels(params.sessionId, params.update);
|
|
204
336
|
this.updateListener?.(params.sessionId, params.update);
|
|
205
337
|
this.options.onUpdate?.(params.sessionId, params.update);
|
|
206
338
|
}
|
|
@@ -317,6 +449,7 @@ export class AcpClient {
|
|
|
317
449
|
if (!pending)
|
|
318
450
|
return;
|
|
319
451
|
clearTimeout(pending.timer);
|
|
452
|
+
pending.cleanup?.();
|
|
320
453
|
this.pending.delete(response.id);
|
|
321
454
|
if (response.error) {
|
|
322
455
|
const err = new Error(`${pending.method} failed: ${response.error.message}`);
|
|
@@ -327,22 +460,38 @@ export class AcpClient {
|
|
|
327
460
|
}
|
|
328
461
|
pending.resolve(response.result);
|
|
329
462
|
}
|
|
330
|
-
request(method, params, timeoutMs) {
|
|
463
|
+
request(method, params, timeoutMs, signal) {
|
|
464
|
+
if (signal?.aborted)
|
|
465
|
+
return Promise.reject(createAbortError());
|
|
331
466
|
if (!this.child || this.closed)
|
|
332
467
|
return Promise.reject(new Error('agent process is not running'));
|
|
333
468
|
if (this.exitError)
|
|
334
469
|
return Promise.reject(this.exitError);
|
|
335
470
|
const id = this.nextId++;
|
|
336
471
|
return new Promise((resolve, reject) => {
|
|
472
|
+
const cleanup = () => {
|
|
473
|
+
signal?.removeEventListener('abort', onAbort);
|
|
474
|
+
};
|
|
475
|
+
const onAbort = () => {
|
|
476
|
+
clearTimeout(timer);
|
|
477
|
+
cleanup();
|
|
478
|
+
this.pending.delete(id);
|
|
479
|
+
reject(createAbortError());
|
|
480
|
+
};
|
|
337
481
|
const timer = setTimeout(() => {
|
|
482
|
+
cleanup();
|
|
338
483
|
this.pending.delete(id);
|
|
339
484
|
reject(new Error(`${method} timed out after ${timeoutMs}ms`));
|
|
340
485
|
}, timeoutMs);
|
|
486
|
+
if (typeof timer.unref === 'function')
|
|
487
|
+
timer.unref();
|
|
488
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
341
489
|
this.pending.set(id, {
|
|
342
490
|
resolve: (value) => resolve(value),
|
|
343
491
|
reject,
|
|
344
492
|
timer,
|
|
345
|
-
method
|
|
493
|
+
method,
|
|
494
|
+
cleanup
|
|
346
495
|
});
|
|
347
496
|
this.write({ jsonrpc: '2.0', id, method, params });
|
|
348
497
|
});
|
|
@@ -351,6 +500,7 @@ export class AcpClient {
|
|
|
351
500
|
this.exitError = error;
|
|
352
501
|
for (const [id, pending] of this.pending) {
|
|
353
502
|
clearTimeout(pending.timer);
|
|
503
|
+
pending.cleanup?.();
|
|
354
504
|
pending.reject(error);
|
|
355
505
|
this.pending.delete(id);
|
|
356
506
|
}
|