@adecore/agents 0.39.0 → 0.40.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.
Files changed (168) hide show
  1. package/dist/async.d.ts +5 -0
  2. package/dist/async.js +13 -5
  3. package/dist/chat/acp-protocol.js +3 -5
  4. package/dist/chat/chat-core.js +0 -2
  5. package/dist/chat/chat-process.d.ts +1 -0
  6. package/dist/chat/chat-process.js +1 -1
  7. package/dist/chat/chat-session.js +6 -8
  8. package/dist/chat/claude-protocol.js +1 -6
  9. package/dist/chat/claude-transcript.js +1 -3
  10. package/dist/chat/codex-protocol.js +1 -6
  11. package/dist/chat/projector.js +1 -3
  12. package/dist/chat/request-summary.js +1 -3
  13. package/dist/coded-error.js +1 -5
  14. package/dist/context/argv.js +1 -2
  15. package/dist/context/verb.js +1 -3
  16. package/dist/error-text.d.ts +1 -0
  17. package/dist/error-text.js +4 -0
  18. package/dist/fields.d.ts +3 -0
  19. package/dist/fields.js +12 -0
  20. package/dist/fs.d.ts +1 -0
  21. package/dist/fs.js +8 -4
  22. package/dist/lineage.js +11 -5
  23. package/dist/messages/notice-store.js +3 -4
  24. package/dist/providers/accounts/acp-account.js +3 -20
  25. package/dist/providers/accounts/service.d.ts +1 -2
  26. package/dist/providers/accounts/service.js +5 -9
  27. package/dist/providers/accounts/status.js +1 -3
  28. package/dist/providers/acp-agent-state.js +1 -3
  29. package/dist/providers/claude.js +0 -1
  30. package/dist/providers/codex.js +0 -1
  31. package/dist/providers/detect.js +1 -1
  32. package/dist/providers/shell-commands.js +1 -2
  33. package/dist/run-process.js +1 -3
  34. package/dist/skills.d.ts +1 -1
  35. package/dist/skills.js +5 -8
  36. package/dist/tasks/background-limit.js +3 -2
  37. package/dist/tasks/task-coordinator.js +11 -17
  38. package/dist/testing/watch.js +0 -1
  39. package/dist/usage/limits/monitor.js +1 -2
  40. package/dist/usage/readers/claude.js +3 -10
  41. package/dist/usage/readers/codex.js +2 -9
  42. package/dist/usage/readers/grok.js +3 -10
  43. package/dist/usage/readers/host-log.js +3 -10
  44. package/dist/usage/record.d.ts +2 -0
  45. package/dist/usage/record.js +13 -0
  46. package/package.json +6 -6
  47. package/src/async.ts +23 -5
  48. package/src/chat/acp-backend.ts +121 -0
  49. package/src/chat/acp-protocol.ts +172 -6
  50. package/src/chat/attachment-store.ts +21 -0
  51. package/src/chat/backend.ts +0 -2
  52. package/src/chat/bookmark-store.ts +23 -0
  53. package/src/chat/chat-core.ts +208 -7
  54. package/src/chat/chat-log.ts +19 -0
  55. package/src/chat/chat-process.ts +52 -1
  56. package/src/chat/chat-session.ts +401 -10
  57. package/src/chat/chat-store.ts +50 -0
  58. package/src/chat/chat-title.ts +9 -0
  59. package/src/chat/claude-backend.ts +50 -0
  60. package/src/chat/claude-protocol.ts +155 -8
  61. package/src/chat/claude-title.ts +10 -0
  62. package/src/chat/claude-transcript.ts +47 -4
  63. package/src/chat/codex-backend.ts +131 -0
  64. package/src/chat/codex-protocol.ts +180 -8
  65. package/src/chat/codex-thread.ts +23 -0
  66. package/src/chat/composer-preferences.ts +6 -0
  67. package/src/chat/context-breakdown.ts +11 -0
  68. package/src/chat/delta-coalescer.ts +8 -0
  69. package/src/chat/external-sessions.ts +28 -0
  70. package/src/chat/generated-image.ts +25 -0
  71. package/src/chat/index.ts +5 -0
  72. package/src/chat/input.ts +13 -0
  73. package/src/chat/json-rpc-transport.ts +28 -0
  74. package/src/chat/limit-resume.ts +13 -0
  75. package/src/chat/projector.ts +160 -4
  76. package/src/chat/readable-text.ts +3 -0
  77. package/src/chat/request-summary.ts +18 -4
  78. package/src/chat/subagent-projection.ts +3 -0
  79. package/src/chat/subagent-reader.ts +76 -0
  80. package/src/chat/subagent-settlement.ts +24 -0
  81. package/src/chat/thread-search.ts +13 -0
  82. package/src/chat/thread.ts +31 -0
  83. package/src/chat/ui-queries.ts +122 -0
  84. package/src/chat/ui-replies.ts +34 -0
  85. package/src/chat/visual-store.ts +49 -0
  86. package/src/chat/wake-chat.ts +3 -0
  87. package/src/client-sinks.ts +2 -0
  88. package/src/coded-error.ts +1 -5
  89. package/src/context/argv.ts +18 -2
  90. package/src/context/index.ts +1 -0
  91. package/src/context/refusal.ts +3 -0
  92. package/src/context/verb.ts +32 -4
  93. package/src/coordination/index.ts +10 -0
  94. package/src/error-text.ts +7 -0
  95. package/src/fields.ts +14 -0
  96. package/src/fs.ts +20 -4
  97. package/src/host/agent-host.ts +20 -0
  98. package/src/host/environment.ts +6 -0
  99. package/src/host/handlers.ts +18 -0
  100. package/src/host/memory-port.ts +4 -0
  101. package/src/host/wiring.ts +10 -0
  102. package/src/index.ts +1 -0
  103. package/src/lineage.ts +24 -5
  104. package/src/messages/deliver-message.ts +6 -0
  105. package/src/messages/deliver-notice.ts +13 -0
  106. package/src/messages/notice-store.ts +16 -4
  107. package/src/modes.ts +1 -0
  108. package/src/outbox/outbox-worker.ts +31 -0
  109. package/src/outbox/outbox.ts +5 -0
  110. package/src/providers/accounts/accounts.ts +36 -0
  111. package/src/providers/accounts/acp-account.ts +22 -27
  112. package/src/providers/accounts/launch.ts +4 -0
  113. package/src/providers/accounts/service.ts +110 -12
  114. package/src/providers/accounts/shadow-home.ts +10 -0
  115. package/src/providers/accounts/status.ts +13 -4
  116. package/src/providers/accounts/store.ts +25 -0
  117. package/src/providers/accounts/variables.ts +11 -1
  118. package/src/providers/acp-agent-state.ts +24 -3
  119. package/src/providers/acp-provider.ts +5 -0
  120. package/src/providers/acp-usage-log.ts +2 -0
  121. package/src/providers/catalog.ts +17 -0
  122. package/src/providers/claude.ts +10 -1
  123. package/src/providers/codex-rules.ts +3 -0
  124. package/src/providers/codex.ts +2 -1
  125. package/src/providers/detect.ts +6 -1
  126. package/src/providers/provider.ts +1 -1
  127. package/src/providers/registry.ts +18 -2
  128. package/src/providers/shell-commands.ts +37 -2
  129. package/src/record-directory.ts +19 -0
  130. package/src/run-process.ts +24 -3
  131. package/src/serializer.ts +3 -0
  132. package/src/skills.ts +73 -10
  133. package/src/tasks/background-limit.ts +9 -2
  134. package/src/tasks/end-children.ts +9 -0
  135. package/src/tasks/give-task.ts +8 -0
  136. package/src/tasks/task-coordinator.ts +81 -17
  137. package/src/tasks/task-store.ts +28 -0
  138. package/src/tasks/waiting-child.ts +21 -0
  139. package/src/tasks/wake-parent.ts +26 -0
  140. package/src/tasks/wiring.ts +22 -0
  141. package/src/testing/accounts.ts +2 -0
  142. package/src/testing/fake-acp-capture.ts +16 -0
  143. package/src/testing/fake-acp.ts +66 -0
  144. package/src/testing/fake-claude.ts +177 -0
  145. package/src/testing/fake-cli.ts +29 -0
  146. package/src/testing/fake-codex.ts +122 -0
  147. package/src/testing/manual-clock.ts +2 -0
  148. package/src/testing/watch.ts +7 -1
  149. package/src/title-file.ts +12 -0
  150. package/src/usage/accounts.ts +6 -0
  151. package/src/usage/aggregate.ts +19 -0
  152. package/src/usage/exchange.ts +12 -0
  153. package/src/usage/index-file.ts +27 -0
  154. package/src/usage/limits/monitor.ts +31 -3
  155. package/src/usage/limits/normalize.ts +30 -0
  156. package/src/usage/limits/probe.ts +17 -0
  157. package/src/usage/pricing.ts +35 -0
  158. package/src/usage/projects.ts +8 -0
  159. package/src/usage/readers/claude.ts +12 -9
  160. package/src/usage/readers/codex.ts +40 -8
  161. package/src/usage/readers/grok.ts +17 -9
  162. package/src/usage/readers/host-log.ts +9 -9
  163. package/src/usage/record.ts +22 -0
  164. package/src/usage/roots.ts +6 -0
  165. package/src/usage/scanner.ts +61 -0
  166. package/src/usage/usage-service.ts +14 -0
  167. package/src/watch-seam.ts +8 -0
  168. package/src/windows-command.ts +12 -0
@@ -60,6 +60,7 @@ export class JsonRpcTransport {
60
60
 
61
61
  constructor(options: JsonRpcTransportOptions) {
62
62
  this.options = options;
63
+
63
64
  this.child = new ChatChild({
64
65
  command: options.command,
65
66
  cwd: options.cwd,
@@ -68,6 +69,7 @@ export class JsonRpcTransport {
68
69
  onError: (error) => this.broken(error),
69
70
  onExit: (exitCode, stderr) => this.handleExit(exitCode, stderr)
70
71
  });
72
+
71
73
  void this.readLines();
72
74
  }
73
75
 
@@ -82,27 +84,35 @@ export class JsonRpcTransport {
82
84
  request(method: string, params: unknown, options: JsonRpcRequestOptions = {}): Promise<unknown> {
83
85
  const label = this.options.label;
84
86
  const timeoutMs = options.timeoutMs === undefined ? this.options.requestTimeoutMs : options.timeoutMs;
87
+
85
88
  return new Promise((resolve, reject) => {
86
89
  if (this.closed) {
87
90
  reject(new Error(`${label} is not running`));
91
+
88
92
  return;
89
93
  }
94
+
90
95
  const id = this.nextId++;
91
96
  let timer: ReturnType<typeof setTimeout> | null = null;
97
+
92
98
  if (timeoutMs !== null) {
93
99
  timer = setTimeout(() => {
94
100
  this.pending.delete(id);
95
101
  reject(new Error(`${method} failed: ${label} did not answer in ${timeoutMs / 1000} seconds`));
96
102
  }, timeoutMs);
103
+
97
104
  timer.unref?.();
98
105
  }
106
+
99
107
  this.pending.set(id, { resolve, reject, method, timer });
108
+
100
109
  try {
101
110
  this.write({ id, method, params });
102
111
  } catch (error) {
103
112
  if (timer !== null) {
104
113
  clearTimeout(timer);
105
114
  }
115
+
106
116
  this.pending.delete(id);
107
117
  reject(error);
108
118
  }
@@ -124,6 +134,7 @@ export class JsonRpcTransport {
124
134
  /* Closes stdin; the child ends on its own once it has nothing more to say. */
125
135
  end(): void {
126
136
  this.inputClosed = true;
137
+
127
138
  try {
128
139
  this.child.process.stdin.end();
129
140
  } catch {
@@ -148,12 +159,14 @@ export class JsonRpcTransport {
148
159
  if (this.closed || this.inputClosed) {
149
160
  throw new Error(`${this.options.label} stdin is closed`);
150
161
  }
162
+
151
163
  try {
152
164
  const framed = this.options.versionField ? { jsonrpc: '2.0', ...frame } : frame;
153
165
  this.child.process.stdin.write(`${JSON.stringify(framed)}\n`);
154
166
  this.child.process.stdin.flush();
155
167
  } catch (error) {
156
168
  this.inputClosed = true;
169
+
157
170
  throw error;
158
171
  }
159
172
  }
@@ -167,6 +180,7 @@ export class JsonRpcTransport {
167
180
  private failed(error: unknown): void {
168
181
  const failure = new Error(`Lost the connection to ${this.options.label}: ${errorText(error)}`);
169
182
  this.rejectPending(() => failure);
183
+
170
184
  try {
171
185
  this.options.onError?.(failure);
172
186
  } catch (reportError) {
@@ -203,28 +217,39 @@ export class JsonRpcTransport {
203
217
  if (this.closed || line.trim() === '') {
204
218
  return;
205
219
  }
220
+
206
221
  let frame: unknown;
222
+
207
223
  try {
208
224
  frame = JSON.parse(line);
209
225
  } catch {
210
226
  return;
211
227
  }
228
+
212
229
  if (typeof frame !== 'object' || frame === null || Array.isArray(frame)) {
213
230
  return;
214
231
  }
232
+
215
233
  const message = frame as JsonRpcFrame;
234
+
216
235
  if (typeof message.method === 'string') {
217
236
  this.options.onFrame(message);
237
+
218
238
  return;
219
239
  }
240
+
220
241
  const settle = typeof message.id === 'number' ? this.pending.get(message.id) : undefined;
242
+
221
243
  if (!settle) {
222
244
  return;
223
245
  }
246
+
224
247
  this.pending.delete(message.id as number);
248
+
225
249
  if (settle.timer !== null) {
226
250
  clearTimeout(settle.timer);
227
251
  }
252
+
228
253
  if (message.error !== undefined) {
229
254
  settle.reject(new JsonRpcError(this.options.errorName ?? 'JsonRpcError', settle.method, message.error));
230
255
  } else {
@@ -236,6 +261,7 @@ export class JsonRpcTransport {
236
261
  if (this.closed) {
237
262
  return;
238
263
  }
264
+
239
265
  this.closed = true;
240
266
  this.rejectPending((method) => new Error(`${method} failed: ${this.options.label} exited`));
241
267
  this.options.onExit(exitCode, stderr);
@@ -246,8 +272,10 @@ export class JsonRpcTransport {
246
272
  if (settle.timer !== null) {
247
273
  clearTimeout(settle.timer);
248
274
  }
275
+
249
276
  settle.reject(reason(settle.method));
250
277
  }
278
+
251
279
  this.pending.clear();
252
280
  }
253
281
  }
@@ -6,6 +6,7 @@ export const LIMIT_RETRY_DELAYS_MS: readonly number[] = [60_000, 5 * 60_000, 15
6
6
  /* The last turn of a thread, when it stopped on a limit. */
7
7
  export function limitedTurn(items: readonly ChatItem[]): (ChatTurnItem & { limit: ChatTurnLimit }) | null {
8
8
  const last = items.findLast((item) => item.kind === 'turn');
9
+
9
10
  return last?.kind === 'turn' && last.state === 'error' && last.limit !== undefined ? (last as ChatTurnItem & { limit: ChatTurnLimit }) : null;
10
11
  }
11
12
 
@@ -13,20 +14,27 @@ export function limitedTurn(items: readonly ChatItem[]): (ChatTurnItem & { limit
13
14
  function limitedInARow(items: readonly ChatItem[], turn: ChatTurnItem): number {
14
15
  let count = 0;
15
16
  let seen = false;
17
+
16
18
  for (let i = items.length - 1; i >= 0; i--) {
17
19
  const item = items[i]!;
20
+
18
21
  if (item.kind !== 'turn') {
19
22
  continue;
20
23
  }
24
+
21
25
  seen ||= item.id === turn.id;
26
+
22
27
  if (!seen) {
23
28
  continue;
24
29
  }
30
+
25
31
  if (item.state !== 'error' || item.limit === undefined) {
26
32
  break;
27
33
  }
34
+
28
35
  count += 1;
29
36
  }
37
+
30
38
  return count;
31
39
  }
32
40
 
@@ -39,17 +47,22 @@ export function limitResumeAt(items: readonly ChatItem[], turn: ChatTurnItem, no
39
47
  if (turn.state !== 'error' || turn.limit === undefined) {
40
48
  return null;
41
49
  }
50
+
42
51
  const tries = limitedInARow(items, turn);
43
52
  const delay = LIMIT_RETRY_DELAYS_MS[tries - 1];
53
+
44
54
  if (delay === undefined) {
45
55
  return null;
46
56
  }
57
+
47
58
  if (turn.limit.kind === 'overload') {
48
59
  return now + delay;
49
60
  }
61
+
50
62
  if (turn.limit.resetsAt === undefined) {
51
63
  return null;
52
64
  }
65
+
53
66
  return tries === 1 ? turn.limit.resetsAt : Math.max(turn.limit.resetsAt, now + delay);
54
67
  }
55
68