@causyne/agent 1.20.5 → 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 CHANGED
@@ -12,11 +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
+ ## Installation
16
+
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:
20
+
21
+ ```sh
22
+ curl -fsSL https://causyne.com/install.sh | bash
23
+ ```
24
+
25
+ For Windows PowerShell:
26
+
27
+ ```powershell
28
+ irm https://causyne.com/install.ps1 | iex
29
+ ```
30
+
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.
38
+
15
39
  ## Contact
16
40
 
17
- - General inquiries and business communication: [contact@causyne.com](mailto:contact@causyne.com)
18
- - Product support and troubleshooting: [help@causyne.com](mailto:help@causyne.com)
19
- - 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.
20
42
 
21
43
  ## Development
22
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. Use the repository's
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causyne/agent",
3
- "version": "1.20.5",
3
+ "version": "1.20.7",
4
4
  "description": "Agentic AI for software, tools, and computer workflows",
5
5
  "main": "bin/causyne.js",
6
6
  "type": "module",
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
- async start() {
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, signal) => {
54
- const detail = this.stderrTail.trim() || `exit code ${code ?? 'null'}${signal ? ` signal ${signal}` : ''}`;
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
- await this.request(ACP_METHODS.SET_MODEL, {
90
- sessionId,
91
- modelId
92
- }, 30_000);
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,15 +185,21 @@ export class AcpClient {
98
185
  }, 30_000);
99
186
  }
100
187
  async loadSession(sessionId, cwd) {
101
- return await this.request(ACP_METHODS.LOAD, {
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) => {
201
+ if (signal?.aborted)
202
+ return;
110
203
  // handleLine already notifies options.onUpdate for this session. Calling
111
204
  // it again here duplicated every live chunk and file-action frame.
112
205
  if (update.sessionUpdate === 'agent_message_chunk' && update.content.type === 'text') {
@@ -115,21 +208,33 @@ export class AcpClient {
115
208
  };
116
209
  const previous = this.updateListener;
117
210
  this.updateListener = (sessionIdFromEvent, update) => {
211
+ if (signal?.aborted)
212
+ return;
118
213
  previous?.(sessionIdFromEvent, update);
119
214
  if (sessionIdFromEvent === sessionId)
120
215
  collector(update);
121
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 });
122
226
  try {
123
227
  const response = await this.request(ACP_METHODS.PROMPT, {
124
228
  sessionId,
125
229
  prompt: blocks
126
- }, this.options.promptTimeoutMs ?? 15 * 60 * 1000);
230
+ }, this.options.promptTimeoutMs ?? 15 * 60 * 1000, signal);
127
231
  return {
128
232
  stopReason: response?.stopReason ?? 'end_turn',
129
233
  text: collected
130
234
  };
131
235
  }
132
236
  finally {
237
+ signal?.removeEventListener('abort', onAbort);
133
238
  this.updateListener = previous;
134
239
  }
135
240
  }
@@ -145,21 +250,46 @@ export class AcpClient {
145
250
  return;
146
251
  this.closed = true;
147
252
  const child = this.child;
253
+ this.child = null;
148
254
  this.failAll(new Error('client closed'));
149
255
  if (!child)
150
256
  return;
257
+ if (child.exitCode !== null || child.signalCode !== null)
258
+ return;
151
259
  await new Promise((resolve) => {
152
- const timer = setTimeout(() => {
153
- child.kill('SIGKILL');
154
- resolve();
155
- }, 1500);
156
- child.once('exit', () => {
260
+ let settled = false;
261
+ const done = () => {
262
+ if (settled)
263
+ return;
264
+ settled = true;
157
265
  clearTimeout(timer);
158
266
  resolve();
159
- });
160
- child.kill('SIGTERM');
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
+ }
161
292
  });
162
- this.child = null;
163
293
  }
164
294
  updateListener = null;
165
295
  write(message) {
@@ -202,6 +332,7 @@ export class AcpClient {
202
332
  if (method === ACP_METHODS.UPDATE) {
203
333
  const params = parsed.params;
204
334
  if (params && typeof params.sessionId === 'string' && params.update) {
335
+ this.recordSessionModels(params.sessionId, params.update);
205
336
  this.updateListener?.(params.sessionId, params.update);
206
337
  this.options.onUpdate?.(params.sessionId, params.update);
207
338
  }
@@ -318,6 +449,7 @@ export class AcpClient {
318
449
  if (!pending)
319
450
  return;
320
451
  clearTimeout(pending.timer);
452
+ pending.cleanup?.();
321
453
  this.pending.delete(response.id);
322
454
  if (response.error) {
323
455
  const err = new Error(`${pending.method} failed: ${response.error.message}`);
@@ -328,22 +460,38 @@ export class AcpClient {
328
460
  }
329
461
  pending.resolve(response.result);
330
462
  }
331
- request(method, params, timeoutMs) {
463
+ request(method, params, timeoutMs, signal) {
464
+ if (signal?.aborted)
465
+ return Promise.reject(createAbortError());
332
466
  if (!this.child || this.closed)
333
467
  return Promise.reject(new Error('agent process is not running'));
334
468
  if (this.exitError)
335
469
  return Promise.reject(this.exitError);
336
470
  const id = this.nextId++;
337
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
+ };
338
481
  const timer = setTimeout(() => {
482
+ cleanup();
339
483
  this.pending.delete(id);
340
484
  reject(new Error(`${method} timed out after ${timeoutMs}ms`));
341
485
  }, timeoutMs);
486
+ if (typeof timer.unref === 'function')
487
+ timer.unref();
488
+ signal?.addEventListener('abort', onAbort, { once: true });
342
489
  this.pending.set(id, {
343
490
  resolve: (value) => resolve(value),
344
491
  reject,
345
492
  timer,
346
- method
493
+ method,
494
+ cleanup
347
495
  });
348
496
  this.write({ jsonrpc: '2.0', id, method, params });
349
497
  });
@@ -352,6 +500,7 @@ export class AcpClient {
352
500
  this.exitError = error;
353
501
  for (const [id, pending] of this.pending) {
354
502
  clearTimeout(pending.timer);
503
+ pending.cleanup?.();
355
504
  pending.reject(error);
356
505
  this.pending.delete(id);
357
506
  }