@agentshouse/kit 0.2.1-cf268dff1869b → 0.2.1-cf2c570b41f24

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 (54) hide show
  1. package/README.md +18 -25
  2. package/dist/acp.js +12 -9
  3. package/dist/afk.js +17 -0
  4. package/dist/agents.js +72 -26
  5. package/dist/api.js +18 -4
  6. package/dist/binaries.js +60 -0
  7. package/dist/bridge.js +99 -44
  8. package/dist/calls.js +18 -1
  9. package/dist/chunks.js +54 -0
  10. package/dist/clis.js +33 -15
  11. package/dist/connect.js +121 -0
  12. package/dist/connection.js +25 -10
  13. package/dist/content.js +106 -0
  14. package/dist/conversations.js +251 -158
  15. package/dist/copies.js +1260 -599
  16. package/dist/earlier.js +273 -0
  17. package/dist/end.js +6 -9
  18. package/dist/events.js +544 -297
  19. package/dist/files.js +77 -11
  20. package/dist/git.js +0 -70
  21. package/dist/grok.js +39 -0
  22. package/dist/home.js +86 -22
  23. package/dist/house-cli.js +145 -162
  24. package/dist/instructions.js +2 -4
  25. package/dist/keys.js +238 -0
  26. package/dist/kit-cli.js +14 -4
  27. package/dist/login.js +34 -20
  28. package/dist/logout.js +2 -2
  29. package/dist/manifest.js +75 -0
  30. package/dist/mcp.js +43 -7
  31. package/dist/owner.js +46 -0
  32. package/dist/placement.js +0 -6
  33. package/dist/refusals.js +50 -23
  34. package/dist/resident.js +117 -76
  35. package/dist/scripts.js +79 -15
  36. package/dist/secret-input.js +1 -1
  37. package/dist/settings.js +247 -0
  38. package/dist/sign-in.js +49 -4
  39. package/dist/supervisor.js +163 -0
  40. package/dist/transcription.js +5 -2
  41. package/dist/update.js +31 -22
  42. package/dist/wire.js +2 -10
  43. package/dist/work.js +27 -2
  44. package/dist/workspace.js +113 -0
  45. package/package.json +12 -8
  46. package/dist/authority-main.js +0 -22
  47. package/dist/chatgpt.js +0 -32
  48. package/dist/configure-main.js +0 -6
  49. package/dist/enrol-main.js +0 -10
  50. package/dist/git-main.js +0 -153
  51. package/dist/parts.js +0 -82
  52. package/dist/service-main.js +0 -9
  53. package/dist/service.js +0 -55
  54. package/dist/translate.js +0 -45
package/dist/events.js CHANGED
@@ -1,81 +1,93 @@
1
1
  const AUTONOMOUS_ORIGINS = new Set(['task-notification', 'peer', 'coordinator', 'observer', 'observer-activity']);
2
- const COMMAND = { shown: 'command' };
3
- const HIDDEN = { shown: 'hidden' };
4
- const FINISHED = new Set(['completed', 'failed']);
2
+ const FINISHED = new Set(['completed', 'failed', 'stopped']);
5
3
  export const RUNNING_JOB = new Set(['running', 'paused']);
6
- const MESSAGE_TARGETS = new Map([
7
- ['send_routine_request', ['routine', 'agent']],
8
- ['cancel_routine_request', ['request']],
9
- ['send_mail', ['conversation', 'request']],
10
- ]);
11
- function words(line) {
12
- const found = [];
13
- let word = null;
14
- let quote = null;
15
- for (let index = 0; index < line.length; index++) {
16
- const character = line[index];
17
- if (quote !== null) {
18
- if (character === quote)
19
- quote = null;
20
- else if (character === '\\' && quote === '"')
21
- word += line[++index] ?? '';
22
- else
23
- word += character;
24
- }
25
- else if (character === "'" || character === '"') {
26
- quote = character;
27
- word ??= '';
28
- }
29
- else if (character === '\\') {
30
- word = (word ?? '') + (line[++index] ?? '');
31
- }
32
- else if (/\s/.test(character)) {
33
- if (word !== null)
34
- found.push(word);
35
- word = null;
36
- }
37
- else {
38
- word = (word ?? '') + character;
39
- }
40
- }
41
- if (word !== null)
42
- found.push(word);
43
- return found;
44
- }
45
- export function houseMessage(line) {
46
- const [program, verb, json] = words(line.trim());
47
- if (program !== 'house' || verb !== 'run_command' || json === undefined)
48
- return null;
49
- let call;
50
- try {
51
- call = JSON.parse(json);
52
- }
53
- catch {
54
- return null;
55
- }
56
- if (call === null)
57
- return null;
58
- const targets = MESSAGE_TARGETS.get(call.command);
59
- if (targets === undefined)
60
- return null;
61
- const target = targets.map((argument) => call.arguments?.[argument]).find((value) => typeof value === 'string');
62
- return { shown: 'message', command: call.command, target: target ?? null };
63
- }
64
- function decidedByLine(command, final) {
65
- const line = typeof command === 'string' ? command : Array.isArray(command) ? command.at(-1) : undefined;
66
- if (typeof line !== 'string')
67
- return final ? COMMAND : null;
68
- return houseMessage(line) ?? COMMAND;
4
+ const ENDED = { completed: 'done', failed: 'failed', stopped: 'stopped', killed: 'stopped', cancelled: 'stopped' };
5
+ const NOTICES = { info: 'info', warning: 'warning', error: 'error' };
6
+ // Claude Code names its limit windows without their length, so the Kit holds the length each name stands for.
7
+ const WINDOW_MINUTES = { five_hour: 300, seven_day: 10_080 };
8
+ const WAKEUP = /Next wakeup scheduled for \d\d:\d\d:\d\d \(in (\d+)s\)/;
9
+ const CHILD_UPDATES = new Set(['tool_call', 'tool_call_update']);
10
+ function counted(reports) {
11
+ const whole = reports.every((tokens) => Object.values(tokens).every((count) => Number.isSafeInteger(count) && count >= 0));
12
+ return whole ? reports.map((tokens) => ({ kind: 'tokens', tokens })) : [];
69
13
  }
70
14
  function contentText(content) {
71
- const text = (content ?? [])
15
+ return (content ?? [])
72
16
  .map((entry) => (entry.type === 'content' && entry.content?.type === 'text' ? entry.content.text : ''))
73
17
  .filter((part) => part !== '')
74
18
  .join('\n');
75
- return text === '' ? null : text;
76
19
  }
77
- function plan(entries) {
78
- return entries.map((entry) => ({ content: entry.content, status: entry.status }));
20
+ function linesOf(text) {
21
+ return text === '' ? [] : text.replace(/\n$/, '').split('\n');
22
+ }
23
+ function count(value) {
24
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? value : null;
25
+ }
26
+ function instant(milliseconds) {
27
+ return new Date(milliseconds).toISOString();
28
+ }
29
+ function changeCounts(diff) {
30
+ let added = 0;
31
+ let removed = 0;
32
+ for (const line of diff.split('\n')) {
33
+ if (line.startsWith('+') && !line.startsWith('+++'))
34
+ added++;
35
+ if (line.startsWith('-') && !line.startsWith('---'))
36
+ removed++;
37
+ }
38
+ return { added, removed };
39
+ }
40
+ function wholeFile(path, sign, text) {
41
+ const lines = linesOf(text).length;
42
+ return sign === '+' ? { path, added: lines, removed: 0 } : { path, added: 0, removed: lines };
43
+ }
44
+ function patched(path, patch) {
45
+ let added = 0;
46
+ let removed = 0;
47
+ for (const line of patch.flatMap((hunk) => hunk.lines)) {
48
+ if (line.startsWith('+'))
49
+ added++;
50
+ if (line.startsWith('-'))
51
+ removed++;
52
+ }
53
+ return { path, added, removed };
54
+ }
55
+ function replacement(site) {
56
+ const before = linesOf((site.line_prefix ?? '') + (site.old_string ?? ''));
57
+ const after = linesOf((site.line_prefix ?? '') + (site.new_string ?? ''));
58
+ let head = 0;
59
+ while (head < before.length && head < after.length && before[head] === after[head])
60
+ head++;
61
+ let tail = 0;
62
+ while (tail < before.length - head && tail < after.length - head && before.at(-1 - tail) === after.at(-1 - tail))
63
+ tail++;
64
+ return { added: after.length - head - tail, removed: before.length - head - tail };
65
+ }
66
+ function replaced(entry) {
67
+ const sites = entry._meta?.details ?? [{ old_string: entry.oldText, new_string: entry.newText }];
68
+ const hunks = sites.map(replacement);
69
+ return {
70
+ path: entry.path,
71
+ added: hunks.reduce((sum, hunk) => sum + hunk.added, 0),
72
+ removed: hunks.reduce((sum, hunk) => sum + hunk.removed, 0),
73
+ };
74
+ }
75
+ function changedFiles(files) {
76
+ const changes = [...files.values()];
77
+ return {
78
+ count: files.size,
79
+ added: changes.reduce((sum, change) => sum + change.added, 0),
80
+ removed: changes.reduce((sum, change) => sum + change.removed, 0),
81
+ };
82
+ }
83
+ function turnDiffFiles(diff) {
84
+ const files = new Map();
85
+ for (const section of diff.split(/^diff --git /m).filter((one) => one.trim() !== '')) {
86
+ const header = section.split('\n')[0];
87
+ const path = /^\+\+\+ b\/(.+)$/m.exec(section)?.[1] ?? header.slice(header.indexOf(' b/') + 3);
88
+ files.set(path, changeCounts(section));
89
+ }
90
+ return changedFiles(files);
79
91
  }
80
92
  function merged(into, from) {
81
93
  if (from === null || from === undefined)
@@ -89,22 +101,25 @@ function merged(into, from) {
89
101
  }
90
102
  return result;
91
103
  }
92
- function names(input, ids) {
93
- const values = JSON.stringify(input ?? {});
94
- for (const id of ids)
95
- if (values.includes(id))
96
- return true;
97
- return false;
104
+ function heldStatus(held) {
105
+ if (!FINISHED.has(held.status))
106
+ return 'running';
107
+ return held.status === 'failed' ? 'failed' : 'done';
108
+ }
109
+ function backgroundKey(id) {
110
+ return `background ${id}`;
98
111
  }
99
112
  class Reader {
100
113
  session = null;
101
114
  calls = new Map();
102
- subagents = new Set();
103
- done = new Set();
115
+ owners = new Map();
116
+ backgrounds = new Map();
117
+ work = new Map();
104
118
  seenOptions = new Map();
105
119
  requestedOptions = new Map();
106
120
  compactions = new Set();
107
- jobs = new Map();
121
+ turns = new Set();
122
+ edits = new Map();
108
123
  read(message) {
109
124
  if (message.method === undefined)
110
125
  return this.answered(message.result);
@@ -114,22 +129,23 @@ class Reader {
114
129
  }
115
130
  return this.own(message);
116
131
  }
132
+ tap(_message) {
133
+ return [];
134
+ }
117
135
  requested(option, value) {
118
136
  this.requestedOptions.set(option, value);
119
137
  }
120
138
  refused(option) {
121
139
  this.requestedOptions.delete(option);
122
140
  }
141
+ began() {
142
+ this.edits.clear();
143
+ return this.editedFiles();
144
+ }
123
145
  closeTurn() {
124
- const events = [];
125
- for (const [id, call] of this.calls) {
126
- if (call.decided?.shown === 'subagent')
127
- continue;
128
- if (call.decided === null)
129
- events.push(...this.shown(call, this.decide(call, true)));
130
- this.calls.delete(id);
131
- }
132
- return events;
146
+ for (const [id, held] of this.calls)
147
+ if (held.counted !== 'subagent')
148
+ this.calls.delete(id);
133
149
  }
134
150
  answered(result) {
135
151
  if (typeof result?.sessionId === 'string' && this.session === null)
@@ -146,28 +162,26 @@ class Reader {
146
162
  own(message) {
147
163
  if (message.method !== 'session/update')
148
164
  return this.extension(message);
149
- return this.update(message.params.update);
165
+ return this.update(message.params.update, null);
150
166
  }
151
167
  extension(_message) {
152
168
  return [];
153
169
  }
154
- update(update) {
170
+ update(update, parent) {
155
171
  switch (update.sessionUpdate) {
156
172
  case 'agent_message_chunk':
173
+ if (parent !== null)
174
+ return [];
157
175
  if (update.content.type === 'image')
158
176
  return [{ kind: 'image', data: update.content.data, mediaType: update.content.mimeType }];
159
177
  return update.content.type === 'text' ? [{ kind: 'text', id: update.messageId ?? null, text: update.content.text }] : [];
160
- case 'agent_thought_chunk':
161
- return update.content.type === 'text' ? [{ kind: 'reasoning', id: update.messageId ?? null, text: update.content.text }] : [];
162
178
  case 'tool_call':
163
179
  case 'tool_call_update':
164
- return this.tool(update);
165
- case 'plan':
166
- return [{ kind: 'plan', entries: plan(update.entries) }];
180
+ return this.tool(update, parent);
167
181
  case 'usage_update':
168
- return [{ kind: 'context', used: update.used, window: update.size }];
182
+ return [{ kind: 'state', state: this.used(update) }];
169
183
  case 'current_mode_update':
170
- return [{ kind: 'marker', marker: 'mode', text: update.currentModeId }];
184
+ return [{ kind: 'notice', notice: 'mode', text: update.currentModeId }];
171
185
  case 'available_commands_update':
172
186
  return [{ kind: 'commands', commands: update.availableCommands }];
173
187
  case 'config_option_update':
@@ -176,201 +190,403 @@ class Reader {
176
190
  if (update.status !== 'completed' || this.compactions.has(update.compactionId))
177
191
  return [];
178
192
  this.compactions.add(update.compactionId);
179
- return [{ kind: 'marker', marker: 'compaction', text: '' }];
193
+ return [{ kind: 'notice', notice: 'compaction', text: '' }];
194
+ case 'session_info_update':
195
+ return this.info(update);
196
+ case 'notice': {
197
+ const said = [update.title, update.description].filter((text) => typeof text === 'string' && text !== '');
198
+ return [{ kind: 'notice', notice: NOTICES[update.severity] ?? 'info', text: said.join('\n') }];
199
+ }
180
200
  case 'async_task_spawned':
181
- return this.job(update.asyncTaskId, update.name ?? update.description ?? '', 'running');
201
+ if (update.taskType === 'turn') {
202
+ this.turns.add(update.asyncTaskId);
203
+ return [];
204
+ }
205
+ this.handedOff(update.toolCallId);
206
+ return this.background(update.asyncTaskId, update.taskType === 'shell' || update.taskType === 'monitor' ? update.taskType : 'task', 'running');
182
207
  case 'async_task_state_update':
183
- return RUNNING_JOB.has(update.state) ? [] : this.job(update.asyncTaskId, null, update.state);
208
+ if (this.turns.has(update.asyncTaskId)) {
209
+ if (!RUNNING_JOB.has(update.state))
210
+ this.turns.delete(update.asyncTaskId);
211
+ return [];
212
+ }
213
+ if (RUNNING_JOB.has(update.state) || !this.backgrounds.has(update.asyncTaskId))
214
+ return [];
215
+ return this.background(update.asyncTaskId, this.backgrounds.get(update.asyncTaskId), ENDED[update.state] ?? 'done');
184
216
  default:
185
217
  return [];
186
218
  }
187
219
  }
188
- job(id, name, state) {
189
- if (name !== null)
190
- this.jobs.set(id, name);
191
- const label = this.jobs.get(id) ?? '';
192
- if (state !== 'running')
193
- this.jobs.delete(id);
194
- return [{ kind: 'marker', marker: 'job', text: `${label}: ${state}` }];
220
+ used(update) {
221
+ return { context: { used: update.used, window: update.size, breakdown: [] } };
222
+ }
223
+ info(update) {
224
+ const suggestion = update._meta?.promptSuggestions?.suggestions?.[0]?.text;
225
+ const state = {
226
+ ...(typeof update.title === 'string' ? { title: update.title } : {}),
227
+ ...(typeof suggestion === 'string' ? { suggestion } : {}),
228
+ };
229
+ return Object.keys(state).length === 0 ? [] : [{ kind: 'state', state }];
230
+ }
231
+ handedOff(id) {
232
+ const held = id === undefined ? undefined : this.calls.get(id);
233
+ if (held !== undefined && !FINISHED.has(held.status))
234
+ held.status = 'completed';
235
+ }
236
+ background(id, kind, status) {
237
+ if (status === 'running')
238
+ this.backgrounds.set(id, kind);
239
+ else
240
+ this.backgrounds.delete(id);
241
+ return this.runs(backgroundKey(id), status === 'running' ? kind : null);
242
+ }
243
+ forget(id) {
244
+ this.backgrounds.delete(id);
245
+ return this.runs(backgroundKey(id), null);
246
+ }
247
+ runs(key, running) {
248
+ const before = this.work.get(key) ?? null;
249
+ if (running === null)
250
+ this.work.delete(key);
251
+ else
252
+ this.work.set(key, running);
253
+ if (before === running)
254
+ return [];
255
+ const counts = new Map();
256
+ for (const kind of this.work.values())
257
+ counts.set(kind, (counts.get(kind) ?? 0) + 1);
258
+ return [{ kind: 'state', state: { running: [...counts].map(([kind, count]) => ({ kind, count })) } }];
195
259
  }
196
260
  optionsChanged(options) {
197
261
  const events = [];
198
262
  for (const option of options) {
199
- const marker = this.watchedOptions[option.id];
263
+ const notice = this.watchedOptions[option.id];
200
264
  const before = this.seenOptions.get(option.id);
201
265
  this.seenOptions.set(option.id, option.currentValue);
202
- if (marker === undefined || before === undefined || before === option.currentValue)
266
+ if (notice === undefined || before === undefined || before === option.currentValue)
203
267
  continue;
204
268
  if (this.requestedOptions.get(option.id) === option.currentValue) {
205
269
  this.requestedOptions.delete(option.id);
206
270
  continue;
207
271
  }
208
- events.push({ kind: 'marker', marker, text: String(option.currentValue) });
272
+ events.push({ kind: 'notice', notice, text: String(option.currentValue) });
209
273
  }
210
274
  return events;
211
275
  }
212
- tool(update) {
213
- let call = this.calls.get(update.toolCallId);
214
- if (call === undefined) {
276
+ tool(update, parent) {
277
+ let held = this.calls.get(update.toolCallId);
278
+ if (held === undefined) {
215
279
  if (update.sessionUpdate !== 'tool_call')
216
280
  return [];
217
- call = { id: update.toolCallId, decided: null, meta: {}, imaged: false, status: 'in_progress' };
218
- this.calls.set(call.id, call);
281
+ held = { id: update.toolCallId, parent, counted: null, meta: {}, imaged: false, status: 'in_progress' };
282
+ this.calls.set(held.id, held);
219
283
  }
220
284
  if (update.kind !== undefined)
221
- call.kind = update.kind;
285
+ held.kind = update.kind;
222
286
  if (update.title !== undefined)
223
- call.title = update.title;
224
- if (update.status !== undefined)
225
- call.status = update.status;
287
+ held.title = update.title;
288
+ if (update.status !== undefined && !FINISHED.has(held.status))
289
+ held.status = update.status;
226
290
  if (update.rawInput !== undefined)
227
- call.rawInput = merged(call.rawInput ?? {}, update.rawInput);
291
+ held.rawInput = merged(held.rawInput ?? {}, update.rawInput);
292
+ if (update.rawOutput !== undefined)
293
+ held.rawOutput = update.rawOutput;
228
294
  if (update.content !== undefined)
229
- call.content = update.content;
230
- call.meta = merged(call.meta, update._meta);
231
- const events = [];
232
- const finished = FINISHED.has(call.status);
233
- if (call.decided === null) {
234
- const decided = this.decide(call, finished);
235
- if (decided !== null)
236
- events.push(...this.shown(call, decided));
237
- }
238
- events.push(...this.produced(call));
239
- if (call.decided?.shown === 'subagent' && finished)
240
- events.push(...this.subagentFinished(call));
241
- else if (finished)
242
- this.calls.delete(call.id);
243
- return events;
295
+ held.content = update.content;
296
+ held.meta = merged(held.meta, (update._meta ?? {}));
297
+ return this.shown(held);
298
+ }
299
+ shown(held) {
300
+ const first = held.counted === null;
301
+ held.counted ??= this.kindOf(held);
302
+ if (held.counted === 'plan')
303
+ return [];
304
+ if (held.counted === 'subagent')
305
+ return this.subagent(held.id, held.parent, this.subagentStatus(held), first);
306
+ const call = { kind: held.counted, files: held.counted === 'edit' ? this.filesOf(held) : [], failed: this.failed(held) };
307
+ return [{ kind: 'call', key: held.id, parent: held.parent, first, call, running: null }, ...this.edited(held.id, call), ...this.produced(held)];
308
+ }
309
+ subagent(key, parent, status, first) {
310
+ if (!this.owners.has(key))
311
+ this.owners.set(key, parent);
312
+ const running = status === 'running';
313
+ const call = { kind: 'other', files: [], failed: status === 'failed' };
314
+ return [
315
+ { kind: 'call', key, parent: this.owners.get(key), first, call, running },
316
+ ...this.runs(key, running ? 'subagent' : null),
317
+ ];
318
+ }
319
+ subagentStatus(held) {
320
+ return heldStatus(held);
321
+ }
322
+ failed(held) {
323
+ if (held.status === 'failed')
324
+ return true;
325
+ const exit = held.rawOutput?.exit_code;
326
+ return held.counted === 'command' && FINISHED.has(held.status) && typeof exit === 'number' && exit !== 0;
244
327
  }
245
- shown(call, decided) {
246
- call.decided = decided;
247
- switch (decided.shown) {
248
- case 'command':
249
- return [{ kind: 'command' }];
250
- case 'hidden':
251
- return [];
252
- case 'message':
253
- return [{ kind: 'message', command: decided.command, target: decided.target }];
254
- case 'marker':
255
- return [{ kind: 'marker', marker: decided.marker, text: decided.text }];
256
- case 'subagent':
257
- this.subagents.add(call.id);
258
- return [{ kind: 'subagent', id: call.id, description: decided.description }];
328
+ filesFromEdits() {
329
+ return true;
330
+ }
331
+ edited(key, call) {
332
+ if (call.kind !== 'edit' || !this.filesFromEdits())
333
+ return [];
334
+ this.edits.set(key, call.files);
335
+ return this.editedFiles();
336
+ }
337
+ editedFiles() {
338
+ const files = new Map();
339
+ for (const change of [...this.edits.values()].flat()) {
340
+ const held = files.get(change.path);
341
+ files.set(change.path, { added: (held?.added ?? 0) + change.added, removed: (held?.removed ?? 0) + change.removed });
259
342
  }
343
+ return [{ kind: 'state', state: { files: changedFiles(files) } }];
260
344
  }
261
345
  produced(_call) {
262
346
  return [];
263
347
  }
264
- subagentFinished(call) {
265
- this.calls.delete(call.id);
266
- return this.finish(call.id, contentText(call.content));
267
- }
268
- finish(id, result) {
269
- if (!this.subagents.has(id) || this.done.has(id))
270
- return [];
271
- this.done.add(id);
272
- this.calls.delete(id);
273
- return [{ kind: 'subagent-done', id, result }];
274
- }
275
348
  }
276
349
  class ClaudeReader extends Reader {
277
350
  watchedOptions = { model: 'model' };
278
- tasks = new Map();
351
+ settled = new Map();
352
+ answers = new Map();
353
+ windows = new Map();
354
+ crons = new Map();
355
+ wakeups = new Map();
356
+ breakdown = [];
279
357
  stop = null;
280
- own(message) {
281
- if (message.params?.update?._meta?.claudeCode?.parentToolUseId !== undefined)
282
- return [];
283
- return super.own(message);
358
+ answered(result) {
359
+ const models = (result?._meta?.quota?.model_usage ?? []);
360
+ const spent = counted(models.map(({ token_count: count }) => ({
361
+ input: count?.inputTokens,
362
+ output: count?.outputTokens,
363
+ cache_read: count?.cachedInputTokens,
364
+ cache_write: count?.cachedWriteTokens,
365
+ })));
366
+ return [...spent, ...super.answered(result)];
367
+ }
368
+ began() {
369
+ const fired = [...this.wakeups].filter(([, next]) => next <= Date.now()).map(([id]) => id);
370
+ for (const id of fired)
371
+ this.wakeups.delete(id);
372
+ return [...super.began(), ...fired.flatMap((id) => this.forget(id))];
284
373
  }
285
- update(update) {
374
+ own(message) {
375
+ const update = message.params?.update;
376
+ const parent = update?._meta?.claudeCode?.parentToolUseId;
377
+ if (parent === undefined)
378
+ return super.own(message);
379
+ return update.sessionUpdate === 'tool_call' || update.sessionUpdate === 'tool_call_update' ? this.tool(update, parent) : [];
380
+ }
381
+ used(update) {
382
+ const cost = update.cost;
383
+ return {
384
+ context: { used: update.used, window: update.size, breakdown: this.breakdown },
385
+ ...(typeof cost?.amount === 'number' ? { cost: { amount: cost.amount, currency: cost.currency } } : {}),
386
+ };
387
+ }
388
+ update(update, parent) {
286
389
  if (update.sessionUpdate === 'usage_update' && update._meta?.['_claude/origin'] !== undefined) {
287
390
  const stop = this.stop;
288
391
  this.stop = null;
289
- return [...super.update(update), { kind: 'ended', stop }];
392
+ return [...super.update(update, parent), { kind: 'ended', stop }];
290
393
  }
291
394
  if (update.sessionUpdate === 'session_info_update' && update._meta?.jetbrains?.air?.sessionFailure !== undefined) {
292
- return [{ kind: 'marker', marker: 'retry', text: update._meta.jetbrains.air.sessionFailure.title }];
395
+ return [{ kind: 'notice', notice: 'retry', text: update._meta.jetbrains.air.sessionFailure.title }];
293
396
  }
294
- return super.update(update);
397
+ return super.update(update, parent);
295
398
  }
296
399
  extension(message) {
297
400
  if (message.method !== '_claude/sdkMessage')
298
401
  return [];
299
402
  const sdk = message.params.message;
300
- if (sdk.type === 'result') {
301
- if (AUTONOMOUS_ORIGINS.has(sdk.origin?.kind))
302
- this.stop = null;
303
- else
304
- this.stop = sdk.stop_reason === 'refusal' ? 'refusal' : sdk.is_error === true ? null : 'end_turn';
305
- return [];
306
- }
307
- switch (sdk.subtype) {
308
- case 'task_started':
309
- if (sdk.tool_use_id !== undefined)
310
- this.tasks.set(sdk.task_id, sdk.tool_use_id);
311
- return [];
312
- case 'task_notification':
313
- return sdk.tool_use_id === undefined ? [] : this.finish(sdk.tool_use_id, sdk.summary ?? null);
314
- case 'task_progress':
315
- if (!this.subagents.has(sdk.tool_use_id) || this.done.has(sdk.tool_use_id) || typeof sdk.description !== 'string')
316
- return [];
317
- return [{ kind: 'subagent-activity', id: sdk.tool_use_id, activity: sdk.description }];
318
- default:
319
- return [];
403
+ switch (sdk.type) {
404
+ case 'result':
405
+ if (AUTONOMOUS_ORIGINS.has(sdk.origin?.kind))
406
+ this.stop = null;
407
+ else
408
+ this.stop = sdk.stop_reason === 'refusal' ? 'refusal' : sdk.is_error === true ? null : 'end_turn';
409
+ return count(sdk.duration_ms) === null ? [] : [{ kind: 'state', state: { duration: sdk.duration_ms } }];
410
+ case 'assistant':
411
+ return this.assistant(sdk);
412
+ case 'user':
413
+ return this.user(sdk);
414
+ case 'rate_limit_event':
415
+ return this.limited(sdk.rate_limit_info);
320
416
  }
417
+ if (typeof sdk.tool_use_id !== 'string' || sdk.subtype !== 'task_notification')
418
+ return [];
419
+ return this.settle(sdk.tool_use_id, ENDED[sdk.status] ?? 'done');
420
+ }
421
+ settle(key, status) {
422
+ const held = this.calls.get(key);
423
+ if (held?.counted !== 'subagent' && held !== undefined)
424
+ return [];
425
+ this.settled.set(key, status);
426
+ return held === undefined ? [] : this.shown(held);
321
427
  }
322
- decide(call, final) {
323
- const tool = call.meta.claudeCode?.toolName;
324
- if (tool === 'Agent' || tool === 'Task' || call.meta.jetbrains?.air?.subagent === true) {
325
- const description = call.rawInput?.description;
326
- if (description === undefined && !final)
327
- return null;
328
- return { shown: 'subagent', description: description ?? call.title ?? '' };
428
+ assistant(sdk) {
429
+ const usage = sdk.context_usage;
430
+ if (usage === undefined)
431
+ return [];
432
+ this.breakdown = usage.categories.map((category) => ({ name: category.name, tokens: category.tokens }));
433
+ return [{ kind: 'state', state: { context: { used: usage.total_tokens, window: usage.raw_max_tokens, breakdown: this.breakdown } } }];
434
+ }
435
+ user(sdk) {
436
+ const content = sdk.message?.content;
437
+ if (!Array.isArray(content))
438
+ return [];
439
+ const events = [];
440
+ for (const block of content) {
441
+ if (block.type !== 'tool_result')
442
+ continue;
443
+ this.answers.set(block.tool_use_id, (sdk.tool_use_result ?? {}));
444
+ const held = this.calls.get(block.tool_use_id);
445
+ if (held !== undefined)
446
+ events.push(...this.shown(held));
329
447
  }
330
- if (tool === 'TodoWrite' || tool === 'CronCreate')
331
- return HIDDEN;
332
- if (tool === 'ScheduleWakeup') {
333
- if (call.rawInput === undefined)
334
- return final ? COMMAND : null;
335
- return call.rawInput.stop === true ? COMMAND : HIDDEN;
448
+ return events;
449
+ }
450
+ limited(info) {
451
+ for (const [name, window] of Object.entries((info?.unifiedWindows ?? {}))) {
452
+ const minutes = WINDOW_MINUTES[name] ?? WINDOW_MINUTES[name.replace(/_[a-z]+$/, '')];
453
+ if (typeof window.utilization !== 'number' || minutes === undefined)
454
+ continue;
455
+ this.windows.set(name, {
456
+ name: name in WINDOW_MINUTES ? null : name,
457
+ minutes,
458
+ percent: Math.round(window.utilization * 1000) / 10,
459
+ resets: typeof window.resetsAt === 'number' ? instant(window.resetsAt * 1000) : null,
460
+ });
336
461
  }
337
- if (call.kind === 'switch_mode')
338
- return { shown: 'marker', marker: 'mode', text: call.title ?? '' };
462
+ return this.windows.size === 0 ? [] : [{ kind: 'state', state: { limits: [...this.windows.values()] } }];
463
+ }
464
+ toolName(held) {
465
+ return held.meta.claudeCode?.toolName ?? '';
466
+ }
467
+ kindOf(held) {
468
+ const tool = this.toolName(held);
469
+ if (tool === 'Agent' || tool === 'Task' || held.meta.jetbrains?.air?.subagent === true)
470
+ return 'subagent';
471
+ if (tool.startsWith('mcp__'))
472
+ return 'other';
339
473
  if (tool === 'Bash')
340
- return decidedByLine(call.rawInput?.command, final);
341
- if (tool === 'SendMessage' || tool === 'TaskStop') {
342
- if (call.rawInput === undefined)
343
- return final ? COMMAND : null;
344
- return names(call.rawInput, this.tasks.keys()) ? HIDDEN : COMMAND;
474
+ return 'command';
475
+ return held.kind === 'edit' ? 'edit' : 'other';
476
+ }
477
+ subagentStatus(held) {
478
+ const settled = this.settled.get(held.id);
479
+ if (settled !== undefined)
480
+ return settled;
481
+ const answered = this.answers.get(held.id);
482
+ const launched = held.meta.claudeCode?.toolResponse?.isAsync === true || answered?.status === 'async_launched';
483
+ if (launched || (!FINISHED.has(held.status) && answered === undefined))
484
+ return 'running';
485
+ return held.status === 'failed' ? 'failed' : 'done';
486
+ }
487
+ filesOf(held) {
488
+ const result = this.answers.get(held.id) ?? {};
489
+ const path = result.filePath ?? held.rawInput?.file_path;
490
+ if (typeof path !== 'string')
491
+ return [];
492
+ if (Array.isArray(result.structuredPatch) && result.structuredPatch.length > 0)
493
+ return [patched(path, result.structuredPatch)];
494
+ if (result.type === 'create' && typeof result.content === 'string')
495
+ return [wholeFile(path, '+', result.content)];
496
+ return [{ path, added: 0, removed: 0 }];
497
+ }
498
+ produced(held) {
499
+ if (held.status !== 'completed')
500
+ return [];
501
+ const tool = this.toolName(held);
502
+ const result = this.answers.get(held.id) ?? {};
503
+ if (tool === 'CronCreate' && typeof result.id === 'string' && !this.crons.has(result.id)) {
504
+ this.crons.set(result.id, held.id);
505
+ return this.background(held.id, 'schedule', 'running');
345
506
  }
346
- return COMMAND;
347
- }
348
- produced(call) {
349
- const tool = call.meta.claudeCode?.toolName;
350
- if (call.status !== 'completed')
507
+ if (tool === 'CronDelete' && typeof held.rawInput?.id === 'string' && this.crons.has(held.rawInput.id)) {
508
+ const created = this.crons.get(held.rawInput.id);
509
+ this.crons.delete(held.rawInput.id);
510
+ return this.background(created, 'schedule', 'stopped');
511
+ }
512
+ if (tool !== 'ScheduleWakeup' || this.wakeups.has(held.id))
351
513
  return [];
352
- if (tool === 'CronCreate' || (tool === 'ScheduleWakeup' && call.rawInput?.stop !== true)) {
353
- return [{ kind: 'marker', marker: 'job', text: `${call.rawInput?.prompt ?? call.title ?? ''}: scheduled` }];
514
+ if (held.rawInput?.stop === true) {
515
+ const stopped = [...this.wakeups.keys()];
516
+ this.wakeups.clear();
517
+ return stopped.flatMap((id) => this.background(id, 'schedule', 'stopped'));
354
518
  }
355
- return [];
356
- }
357
- subagentFinished(call) {
358
- if (call.meta.claudeCode?.toolResponse?.isAsync === true)
519
+ const seconds = WAKEUP.exec(contentText(held.content))?.[1];
520
+ if (seconds === undefined)
359
521
  return [];
360
- return super.subagentFinished(call);
522
+ const next = Date.now() + Number(seconds) * 1000;
523
+ this.wakeups.set(held.id, next);
524
+ return this.background(held.id, 'schedule', 'running');
361
525
  }
362
526
  }
363
- const COLLABORATION = new Set(['spawnAgent', 'sendInput', 'resumeAgent', 'wait', 'closeAgent', 'followupTask']);
364
527
  class CodexReader extends Reader {
365
528
  watchedOptions = { mode: 'mode', collaboration_mode: 'mode' };
366
- children = new Map();
529
+ children = new Set();
530
+ items = new Map();
531
+ answered(result) {
532
+ const usage = result?.usage;
533
+ const spent = usage === null || usage === undefined
534
+ ? []
535
+ : counted([
536
+ {
537
+ input: usage.inputTokens,
538
+ output: usage.outputTokens,
539
+ cache_read: usage.cachedReadTokens,
540
+ cache_write: usage.cachedWriteTokens,
541
+ },
542
+ ]);
543
+ return [...spent, ...super.answered(result)];
544
+ }
545
+ filesFromEdits() {
546
+ return false;
547
+ }
548
+ tap(message) {
549
+ const params = (message.params ?? {});
550
+ if (message.method === 'account/rateLimits/updated')
551
+ return this.limited(params.rateLimits);
552
+ if (params.threadId !== this.session && !this.children.has(params.threadId))
553
+ return [];
554
+ switch (message.method) {
555
+ case 'item/started':
556
+ case 'item/completed': {
557
+ this.items.set(params.item.id, params.item);
558
+ const held = this.calls.get(params.item.id);
559
+ return held === undefined ? [] : this.shown(held);
560
+ }
561
+ case 'turn/completed':
562
+ return params.threadId === this.session && count(params.turn?.durationMs) !== null ? [{ kind: 'state', state: { duration: params.turn.durationMs } }] : [];
563
+ case 'turn/diff/updated':
564
+ return params.threadId === this.session ? [{ kind: 'state', state: { files: turnDiffFiles(params.diff) } }] : [];
565
+ default:
566
+ return [];
567
+ }
568
+ }
569
+ limited(limits) {
570
+ const windows = [limits?.primary, limits?.secondary].filter((window) => typeof window?.usedPercent === 'number');
571
+ if (windows.length === 0)
572
+ return [];
573
+ const name = typeof limits.limitName === 'string' ? limits.limitName : null;
574
+ const limited = windows.map((window) => ({
575
+ name,
576
+ // Codex sends each window's length; a limit always carries one, so a window Codex sends without it has 0.
577
+ minutes: count(window.windowDurationMins) ?? 0,
578
+ percent: window.usedPercent,
579
+ resets: typeof window.resetsAt === 'number' ? instant(window.resetsAt * 1000) : null,
580
+ }));
581
+ return [{ kind: 'state', state: { limits: limited } }];
582
+ }
367
583
  own(message) {
368
584
  if (message.method === 'session/request_permission' && message.params.toolCall?.kind === 'switch_mode') {
369
- return [{ kind: 'started' }, { kind: 'marker', marker: 'mode', text: message.params.toolCall.title ?? '' }];
585
+ return [{ kind: 'started' }, { kind: 'notice', notice: 'mode', text: message.params.toolCall.title ?? '' }];
370
586
  }
371
587
  return super.own(message);
372
588
  }
373
- update(update) {
589
+ update(update, parent) {
374
590
  switch (update.sessionUpdate) {
375
591
  case 'session_info_update': {
376
592
  const codex = update._meta?.codex;
@@ -379,62 +595,64 @@ class CodexReader extends Reader {
379
595
  if (codex?.threadStatus?.type === 'idle')
380
596
  return [{ kind: 'ended', stop: null }];
381
597
  if (codex?.error !== undefined)
382
- return [{ kind: 'marker', marker: 'retry', text: codex.error.message ?? '' }];
383
- return [];
598
+ return [{ kind: 'notice', notice: 'retry', text: codex.error.message ?? '' }];
599
+ return super.update(update, parent);
600
+ }
601
+ case 'subagent_spawned': {
602
+ const first = !this.children.has(update.subagentSessionId);
603
+ this.children.add(update.subagentSessionId);
604
+ return this.subagent(update.subagentSessionId, parent, 'running', first);
384
605
  }
385
- case 'notice':
386
- return update.severity === 'info' ? [{ kind: 'marker', marker: 'model', text: update.description ?? update.title }] : [];
387
- case 'subagent_spawned':
388
- this.children.set(update.subagentSessionId, { id: null, text: '' });
389
- this.subagents.add(update.subagentSessionId);
390
- return [{ kind: 'subagent', id: update.subagentSessionId, description: update.name }];
391
606
  case 'subagent_state_update':
392
- return this.finish(update.subagentSessionId, this.children.get(update.subagentSessionId)?.text || null);
607
+ if (!this.children.has(update.subagentSessionId))
608
+ return [];
609
+ return this.subagent(update.subagentSessionId, parent, ENDED[update.state] ?? 'failed', false);
393
610
  default:
394
- return super.update(update);
611
+ return super.update(update, parent);
395
612
  }
396
613
  }
397
614
  elsewhere(session, message) {
398
- const child = this.children.get(session);
399
615
  const update = message.params?.update;
400
- if (child === undefined || update === undefined)
616
+ if (!this.children.has(session) || update === undefined)
401
617
  return [];
402
- if (update.sessionUpdate === 'agent_message_chunk' && update.content.type === 'text') {
403
- const id = update.messageId ?? null;
404
- if (child.id !== id)
405
- child.text = '';
406
- child.id = id;
407
- child.text += update.content.text;
408
- }
409
- return [];
410
- }
411
- decide(call) {
412
- const air = call.meta.jetbrains?.air;
413
- if (COLLABORATION.has(call.title ?? ''))
414
- return HIDDEN;
415
- if (air?.subagent !== undefined)
416
- return { shown: 'subagent', description: call.title ?? '' };
417
- if (call.kind === 'switch_mode')
418
- return { shown: 'marker', marker: 'mode', text: call.title ?? '' };
419
- if (call.kind === 'execute')
420
- return decidedByLine(call.rawInput?.command, true);
421
- if (call.title === 'Image generation')
422
- return HIDDEN;
423
- return COMMAND;
424
- }
425
- produced(call) {
426
- if (call.imaged || call.kind === 'read')
618
+ if (update.sessionUpdate === 'subagent_spawned' || update.sessionUpdate === 'subagent_state_update')
619
+ return this.update(update, session);
620
+ return CHILD_UPDATES.has(update.sessionUpdate) ? this.update(update, session) : [];
621
+ }
622
+ kindOf(held) {
623
+ if (held.meta.is_mcp_tool_call === true)
624
+ return 'other';
625
+ if (held.kind === 'execute')
626
+ return 'command';
627
+ return held.kind === 'edit' ? 'edit' : 'other';
628
+ }
629
+ filesOf(held) {
630
+ const item = this.items.get(held.id);
631
+ if (item?.type !== 'fileChange')
427
632
  return [];
428
- const image = (call.content ?? []).find((entry) => entry.type === 'content' && entry.content?.type === 'image');
633
+ return item.changes.map((change) => {
634
+ if (change.kind?.type === 'add')
635
+ return wholeFile(change.path, '+', change.diff);
636
+ if (change.kind?.type === 'delete')
637
+ return wholeFile(change.path, '-', change.diff);
638
+ return { path: change.kind?.move_path ?? change.path, ...changeCounts(change.diff) };
639
+ });
640
+ }
641
+ produced(held) {
642
+ if (held.imaged || held.kind === 'read' || held.parent !== null)
643
+ return [];
644
+ const image = (held.content ?? []).find((entry) => entry.type === 'content' && entry.content?.type === 'image');
429
645
  if (image === undefined)
430
646
  return [];
431
- call.imaged = true;
647
+ held.imaged = true;
432
648
  return [{ kind: 'image', data: image.content.data, mediaType: image.content.mimeType }];
433
649
  }
434
650
  }
435
651
  class GrokReader extends Reader {
436
652
  watchedOptions = {};
437
653
  children = new Map();
654
+ settled = new Map();
655
+ schedules = new Set();
438
656
  models = [];
439
657
  model = null;
440
658
  answered(result) {
@@ -450,7 +668,9 @@ class GrokReader extends Reader {
450
668
  return (message.params.runningPromptId ?? null) !== null && session === this.session ? [{ kind: 'started' }] : [];
451
669
  }
452
670
  if (message.params?.update?.sessionUpdate === 'turn_completed') {
453
- return session === this.session ? [{ kind: 'ended', stop: null }] : [];
671
+ if (session !== this.session)
672
+ return [];
673
+ return [...this.spent(message.params.update.usage), { kind: 'ended', stop: null }];
454
674
  }
455
675
  if (message.method === '_x.ai/models/update') {
456
676
  this.offered(message.params);
@@ -458,6 +678,20 @@ class GrokReader extends Reader {
458
678
  }
459
679
  return super.read(message);
460
680
  }
681
+ elsewhere(session, message) {
682
+ const parent = this.children.get(session);
683
+ const update = message.params?.update;
684
+ if (typeof parent !== 'string' || message.method !== 'session/update' || !CHILD_UPDATES.has(update?.sessionUpdate))
685
+ return [];
686
+ return this.update(update, parent);
687
+ }
688
+ spent(usage) {
689
+ if (usage === null || usage === undefined)
690
+ return [];
691
+ const { inputTokens, outputTokens, cachedReadTokens, cacheCreationTokens } = usage;
692
+ const input = inputTokens - cachedReadTokens - cacheCreationTokens;
693
+ return counted([{ input, output: outputTokens, cache_read: cachedReadTokens, cache_write: cacheCreationTokens }]);
694
+ }
461
695
  offered(models) {
462
696
  this.models = models.availableModels ?? this.models;
463
697
  this.model = models.currentModelId ?? this.model;
@@ -469,11 +703,18 @@ class GrokReader extends Reader {
469
703
  const update = message.params?.update;
470
704
  switch (message.method) {
471
705
  case '_x.ai/task_backgrounded':
472
- return this.job(update.task_id, update.description ?? update.command ?? '', 'running');
473
- case '_x.ai/task_completed':
474
- return this.job(update.task_snapshot.task_id, null, update.task_snapshot.exit_code === 0 ? 'completed' : 'failed');
475
- case '_x.ai/scheduled_task_created':
476
- return [{ kind: 'marker', marker: 'job', text: `${update.prompt}: next run ${update.next_fire_at}` }];
706
+ this.handedOff(update.tool_call_id);
707
+ return this.background(update.task_id, 'shell', 'running');
708
+ case '_x.ai/task_completed': {
709
+ const snapshot = update.task_snapshot;
710
+ return this.background(snapshot.task_id, 'shell', snapshot.exit_code === 0 ? 'done' : 'failed');
711
+ }
712
+ case '_x.ai/scheduled_task_created': {
713
+ this.schedules.add(update.task_id);
714
+ return this.background(update.task_id, 'schedule', 'running');
715
+ }
716
+ case '_x.ai/scheduled_task_deleted':
717
+ return this.schedules.delete(update.task_id) ? this.background(update.task_id, 'schedule', 'stopped') : [];
477
718
  case '_x.ai/session_notification':
478
719
  return this.notification(update);
479
720
  default:
@@ -488,49 +729,55 @@ class GrokReader extends Reader {
488
729
  if (window === null)
489
730
  return [];
490
731
  const used = usage.input_tokens + (usage.cache_read_input_tokens ?? 0) + (usage.cache_creation_input_tokens ?? 0) + usage.output_tokens;
491
- return [{ kind: 'context', used, window }];
732
+ return [{ kind: 'state', state: { context: { used, window, breakdown: [] } } }];
492
733
  }
493
734
  case 'subagent_spawned': {
494
- const call = [...this.calls.values()].find((candidate) => candidate.decided?.shown === 'subagent' &&
495
- ![...this.children.values()].includes(candidate.id) &&
496
- candidate.decided.description === update.description) ??
497
- [...this.calls.values()].find((candidate) => candidate.decided?.shown === 'subagent' && ![...this.children.values()].includes(candidate.id));
498
- this.children.set(update.child_session_id, call?.id ?? null);
735
+ const linked = [...this.children.values()];
736
+ const unlinked = [...this.calls.values()].filter((candidate) => candidate.counted === 'subagent' && !linked.includes(candidate.id));
737
+ const held = unlinked.find((candidate) => candidate.rawInput?.description === update.description);
738
+ this.children.set(update.child_session_id, held?.id ?? null);
499
739
  return [];
500
740
  }
501
741
  case 'subagent_finished': {
502
- const call = this.children.get(update.child_session_id);
503
- return typeof call === 'string' ? this.finish(call, update.output ?? null) : [];
742
+ const key = this.children.get(update.child_session_id);
743
+ if (typeof key !== 'string')
744
+ return [];
745
+ this.settled.set(key, ENDED[update.status] ?? 'failed');
746
+ const held = this.calls.get(key);
747
+ return held === undefined ? [] : this.shown(held);
504
748
  }
505
749
  case 'auto_compact_completed':
506
- return [{ kind: 'marker', marker: 'compaction', text: '' }];
750
+ return [{ kind: 'notice', notice: 'compaction', text: '' }];
507
751
  case 'model_auto_switched':
508
752
  this.model = update.new_model_id;
509
- return [{ kind: 'marker', marker: 'model', text: update.new_model_id }];
753
+ return [{ kind: 'notice', notice: 'model', text: update.new_model_id }];
510
754
  case 'retry_state':
511
- return [{ kind: 'marker', marker: 'retry', text: update.message ?? update.reason ?? update.error_type ?? '' }];
755
+ return [{ kind: 'notice', notice: 'retry', text: update.message ?? update.reason ?? update.error_type ?? '' }];
512
756
  default:
513
757
  return [];
514
758
  }
515
759
  }
516
- decide(call) {
517
- const tool = (call.meta['x.ai/tool'] ?? {});
518
- if (tool.name === 'spawn_subagent' || tool.kind === 'task') {
519
- return { shown: 'subagent', description: call.rawInput?.description ?? call.title ?? '' };
520
- }
521
- if (tool.name === 'todo_write' || tool.name === 'scheduler_create')
522
- return HIDDEN;
523
- if (tool.name === 'enter_plan_mode' || tool.name === 'exit_plan_mode') {
524
- return { shown: 'marker', marker: 'mode', text: tool.name };
525
- }
526
- if (tool.name === 'kill_command_or_subagent')
527
- return names(call.rawInput, this.children.keys()) ? HIDDEN : COMMAND;
760
+ xai(held) {
761
+ return (held.meta['x.ai/tool'] ?? {});
762
+ }
763
+ kindOf(held) {
764
+ const tool = this.xai(held);
765
+ if (tool.name === 'spawn_subagent' || tool.kind === 'task')
766
+ return 'subagent';
767
+ if (tool.kind === 'plan')
768
+ return 'plan';
528
769
  if (tool.name === 'run_terminal_command')
529
- return decidedByLine(call.rawInput?.command, true);
530
- return COMMAND;
770
+ return 'command';
771
+ const kind = tool.kind ?? held.kind;
772
+ if (kind === 'execute')
773
+ return 'command';
774
+ return kind === 'write' || kind === 'edit' ? 'edit' : 'other';
531
775
  }
532
- subagentFinished(_call) {
533
- return [];
776
+ subagentStatus(held) {
777
+ return this.settled.get(held.id) ?? (held.status === 'failed' ? 'failed' : 'running');
778
+ }
779
+ filesOf(held) {
780
+ return (held.content ?? []).filter((entry) => entry.type === 'diff').map(replaced);
534
781
  }
535
782
  }
536
783
  export function answeredFailure(answer) {