agent-run-inspector 0.10.5 → 0.10.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-run-inspector",
3
- "version": "0.10.5",
3
+ "version": "0.10.6",
4
4
  "description": "Local, read-only inspector for Claude Code and Codex CLI agent runs.",
5
5
  "keywords": [
6
6
  "claude-code",
@@ -1,7 +1,7 @@
1
1
  import { providerOf } from '../../model/provider.js';
2
2
  import { ClaudeCodeSession } from './index.js';
3
3
  import { AGENT_TOOLS } from './tools.js';
4
- import { OrcaDispatches } from './orca.js';
4
+ import { OrcaDispatches, dispatchIdsIn } from './orca.js';
5
5
  import { MSG } from '../../strings.js';
6
6
 
7
7
  const RECENT_MS = 10 * 60 * 1000;
@@ -170,6 +170,9 @@ export class AgentCollector {
170
170
  });
171
171
  }
172
172
  for (const [task, c] of this.orca.tasks) {
173
+ // another id of a worker that has its own card (printed both ways, or the task given out again): no second card
174
+ const found = lookup?.find(undefined, task);
175
+ if (found && found.agentId !== task) continue;
173
176
  out.push(this.#mateSpan(task, c, c.name ?? c.folder ?? task, { lookup, now, base, ref: { fileId: this.ctx.fileId, line: c.line }, orca: true }));
174
177
  }
175
178
  return out;
@@ -218,6 +221,7 @@ export class AgentLookup {
218
221
  this.entries.push(entry);
219
222
  if (str(entry.meta?.toolUseId)) this.byToolUse.set(entry.meta.toolUseId, entry);
220
223
  this.byAgent.set(entry.agentId, entry);
224
+ for (const id of entry.aliases ?? []) if (!this.byAgent.has(id)) this.byAgent.set(id, entry);
221
225
  }
222
226
  find(toolUseId, agentId) {
223
227
  return this.byToolUse.get(toolUseId) ?? (agentId ? this.byAgent.get(agentId) : undefined);
@@ -251,7 +255,8 @@ export function buildSessionTree({ main, subagents = [], now }) {
251
255
  const s = new ClaudeCodeSession({ fileId: f.fileId, sessionId: sid, parentId: spanId, depth, now: clock });
252
256
  s.push(f.text);
253
257
  const lastLlm = s.llm.lastModel();
254
- const entry = { agentId: f.agentId, meta, title: s.title, lastTs: s.lastTs, firstTs: s.firstTs, mtime: f.mtime, model: lastLlm, fileId: f.fileId, ...(f.mate ? { mate: true, turnEnded: s.turnEnded, shutDown: s.shutDown } : {}) };
258
+ const aliases = f.aliases ? [...new Set([...f.aliases, ...dispatchIdsIn(f.text)])] : undefined; // an Orca worker's other ids
259
+ const entry = { agentId: f.agentId, ...(aliases ? { aliases } : {}), meta, title: s.title, lastTs: s.lastTs, firstTs: s.firstTs, mtime: f.mtime, model: lastLlm, fileId: f.fileId, ...(f.mate ? { mate: true, turnEnded: s.turnEnded, shutDown: s.shutDown } : {}) };
255
260
  lookup.add(entry);
256
261
  parsed.push({ f, s, entry, spanId, depth });
257
262
  }
@@ -55,6 +55,7 @@ export class OrcaDispatches {
55
55
  constructor() {
56
56
  this.calls = new Map(); // worker-start tool_use id -> { name, start, line }
57
57
  this.tasks = new Map();
58
+ this.seen = new Set(); // every dispatch and task id already keyed: one worker printed both ways is one worker
58
59
  }
59
60
 
60
61
  onAssistant(rec, ts, line) {
@@ -77,13 +78,19 @@ export class OrcaDispatches {
77
78
  for (const m of textOf(b.content).matchAll(DISPATCHED)) {
78
79
  // no --name: the worker's own title names it, else its workspace folder (see agents.js)
79
80
  const folder = m[3]?.split(/[\\/]/).filter(Boolean).at(-1);
80
- const key = m[2] ?? m[1];
81
- if (!this.tasks.has(key)) this.tasks.set(key, { ...call, ...(folder ? { folder } : {}) });
81
+ const ids = m[2] ? [m[1], m[2]] : [m[1]];
82
+ if (ids.some((id) => this.seen.has(id))) { ids.forEach((id) => this.seen.add(id)); continue; }
83
+ ids.forEach((id) => this.seen.add(id));
84
+ this.tasks.set(m[2] ?? m[1], { ...call, ...(folder ? { folder } : {}) });
82
85
  }
83
86
  }
84
87
  }
85
88
  }
86
89
 
90
+ /** Every dispatch id an Orca worker's file was given: the bot can send more work to a running worker. */
91
+ // ponytail: a plain text search; a worker quoting another worker's `--dispatch-id` would take that id too.
92
+ export const dispatchIdsIn = (text) => [...new Set([...text.matchAll(/--dispatch-id\s+(ctx_[0-9a-z]+)/g)].map((m) => m[1]))];
93
+
87
94
  /** Raw-byte prefilter for lines worth parsing with OrcaDispatches. */
88
95
  export const DISPATCH_MARKS = [Buffer.from('worker-start'), Buffer.from('dispatchId=ctx_')];
89
96
  export const WORKER_MARKS = [Buffer.from(WORKER_PROMPT), Buffer.from(HELPER_START)];
package/src/index/scan.js CHANGED
@@ -306,7 +306,9 @@ function linkOrcaWorkers(list, store, cache) {
306
306
  const o = owner.get(key);
307
307
  if (!o) { rest.push(e); continue; }
308
308
  // the worker's own sub-agents come along (linked to its Agent calls by tool_use id)
309
- o.lead.subs.push({ ...e.main, agentId: key, metaFileId: null, mate: true, name: folder }, ...e.subs);
309
+ // its other id (the bot may print the dispatch alone, or give the task out again) finds the same worker
310
+ const aliases = [task, dispatch].filter((id) => id && id !== key);
311
+ o.lead.subs.push({ ...e.main, agentId: key, aliases, metaFileId: null, mate: true, name: folder }, ...e.subs);
310
312
  o.lead.lastWrite = Math.max(o.lead.lastWrite, e.lastWrite);
311
313
  linked.set(task, { o, key }).set(dispatch, { o, key });
312
314
  }
@@ -220,6 +220,7 @@ export function openEntry(entry, store, now) {
220
220
  fileId: String(s.fileId), agentId: s.agentId, text: readText(store, s.fileId, s.size),
221
221
  meta: s.meta ?? (s.name ? { name: s.name } : readMeta(store, s)), mtime: s.mtimeMs, ...(s.mate ? { mate: true } : {}),
222
222
  ...(s.parent ? { parent: s.parent } : {}),
223
+ ...(s.aliases ? { aliases: s.aliases } : {}), // an Orca worker's other ids
223
224
  }));
224
225
  const snap = buildSessionTree({
225
226
  main: { fileId: String(entry.main.fileId), text: readText(store, entry.main.fileId, entry.main.size) },