agent-run-inspector 0.8.1 → 0.9.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.
package/README.ko.md CHANGED
@@ -4,7 +4,8 @@
4
4
 
5
5
  [![CI](https://github.com/th-yong/agent-run-inspector/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/th-yong/agent-run-inspector/actions/workflows/ci.yml)
6
6
  [![License: MIT](https://img.shields.io/github/license/th-yong/agent-run-inspector)](LICENSE)
7
- [![Node](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fth-yong%2Fagent-run-inspector%2Fmain%2Fpackage.json&query=%24.engines.node&label=node&color=339933)](package.json)
7
+ [![npm](https://img.shields.io/npm/v/agent-run-inspector)](https://www.npmjs.com/package/agent-run-inspector)
8
+ [![Node](https://img.shields.io/node/v/agent-run-inspector)](package.json)
8
9
 
9
10
  Claude Code 와 Codex CLI 의 에이전트 실행을 로컬 브라우저에서 실시간으로 보는 읽기 전용 도구입니다. 누가 누구를 불렀는지, 호출마다 비용이 얼마인지, 어디서 실패했는지 한눈에 봅니다.
10
11
 
package/README.md CHANGED
@@ -4,7 +4,8 @@ English | [한국어](README.ko.md)
4
4
 
5
5
  [![CI](https://github.com/th-yong/agent-run-inspector/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/th-yong/agent-run-inspector/actions/workflows/ci.yml)
6
6
  [![License: MIT](https://img.shields.io/github/license/th-yong/agent-run-inspector)](LICENSE)
7
- [![Node](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fth-yong%2Fagent-run-inspector%2Fmain%2Fpackage.json&query=%24.engines.node&label=node&color=339933)](package.json)
7
+ [![npm](https://img.shields.io/npm/v/agent-run-inspector)](https://www.npmjs.com/package/agent-run-inspector)
8
+ [![Node](https://img.shields.io/node/v/agent-run-inspector)](package.json)
8
9
 
9
10
  A local, read-only inspector for Claude Code and Codex CLI agent runs: see who called whom, what each call cost and where it failed, live, in your browser.
10
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-run-inspector",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "description": "Local, read-only inspector for Claude Code and Codex CLI agent runs.",
5
5
  "keywords": [
6
6
  "claude-code",
@@ -1,5 +1,5 @@
1
1
  import { LlmCollector } from './llm.js';
2
- import { ToolCollector } from './tools.js';
2
+ import { ToolCollector, BackgroundTasks } from './tools.js';
3
3
  import { AgentCollector } from './agents.js';
4
4
  import { providerOf } from '../../model/provider.js';
5
5
  import { MSG } from '../../strings.js';
@@ -69,6 +69,7 @@ export class ClaudeCodeSession {
69
69
  });
70
70
  this.tools = new ToolCollector(this.llm.ctx);
71
71
  this.agents = new AgentCollector(this.llm.ctx);
72
+ this.bg = new BackgroundTasks();
72
73
  this.markers = [];
73
74
  this.turns = [];
74
75
  this.parentIdOverride = parentId;
@@ -121,9 +122,11 @@ export class ClaudeCodeSession {
121
122
  this.llm.onAssistant(rec, ts, line, this.prevTs);
122
123
  this.tools.onAssistant(rec, ts, line);
123
124
  this.agents.onAssistant(rec, ts, line);
125
+ this.bg.onAssistant(rec);
124
126
  break;
125
127
  case 'user':
126
128
  this.turnEnded = false;
129
+ this.bg.onUser(rec);
127
130
  this.tools.onUser(rec, ts);
128
131
  this.agents.onUser(rec, ts);
129
132
  break;
@@ -163,9 +166,14 @@ export class ClaudeCodeSession {
163
166
  const start = this.firstTs ?? 0;
164
167
  const end = this.lastTs ?? start;
165
168
  const now = this.now ?? Date.now();
166
- // Recent writes mean running, unless the last turn has ended (waiting for the user).
167
- const running = !this.turnEnded && now - end < DEFAULT_RUNNING_MS && now >= end;
169
+ // Recent writes mean running, unless the last turn has ended (waiting for the user) with no
170
+ // background task left open.
171
+ // ponytail: a background task is trusted only 10 min past the last write; a longer wait shows as done.
172
+ const recent = now - end < DEFAULT_RUNNING_MS && now >= end;
173
+ const running = recent && (!this.turnEnded || this.bg.open.size > 0);
168
174
  const status = children.some((s) => s.status === 'running') || running ? 'running' : 'ok';
175
+ // running only because of background work: the main thread itself waits for it
176
+ const background = status === 'running' && this.turnEnded;
169
177
  return {
170
178
  id: this.sessionId ?? '',
171
179
  parentId: null,
@@ -174,6 +182,7 @@ export class ClaudeCodeSession {
174
182
  kind: 'session',
175
183
  name: this.title ?? (project || MSG.untitledSession),
176
184
  status,
185
+ ...(background ? { background } : {}),
177
186
  start,
178
187
  end: status === 'running' ? null : end,
179
188
  ref: { fileId: this.fileId, line: 1 },
@@ -193,6 +202,7 @@ export class ClaudeCodeSession {
193
202
  kind: 'agent',
194
203
  name: model ?? MSG.mainAgent,
195
204
  status: session.status,
205
+ ...(session.background ? { background: true } : {}),
196
206
  start: session.start,
197
207
  end: session.end,
198
208
  ref: session.ref,
@@ -5,6 +5,45 @@ import { MSG } from '../../strings.js';
5
5
  // Sub-agent launches become agent spans (T11), not tool spans.
6
6
  export const AGENT_TOOLS = new Set(['agent', 'task']);
7
7
 
8
+ const FINAL_TASK = /<task-id>([^<]+)<\/task-id>[\s\S]*?<status>(?:completed|failed|stopped|killed)<\/status>/g;
9
+
10
+ /**
11
+ * Background tasks the session still waits on: run_in_background Bash (result `backgroundTaskId`) and
12
+ * Monitor (result `taskId`), open until a task-notification with a final status or a TaskStop/KillShell.
13
+ * Background agents are not here: their own files say whether they still work. Reads ids and status only.
14
+ */
15
+ export class BackgroundTasks {
16
+ constructor() {
17
+ this.open = new Set();
18
+ this.monitors = new Set(); // Monitor tool_use ids
19
+ }
20
+
21
+ onAssistant(rec) {
22
+ const content = rec.message?.content;
23
+ if (!Array.isArray(content)) return;
24
+ for (const b of content) {
25
+ if (b?.type !== 'tool_use') continue;
26
+ if (b.name === 'Monitor') this.monitors.add(b.id);
27
+ const stop = b.name === 'TaskStop' ? b.input?.task_id : b.name === 'KillShell' ? b.input?.shell_id : undefined;
28
+ if (typeof stop === 'string') this.open.delete(stop);
29
+ }
30
+ }
31
+
32
+ onUser(rec) {
33
+ const c = rec.message?.content;
34
+ if (rec.origin?.kind === 'task-notification') {
35
+ const text = typeof c === 'string' ? c : Array.isArray(c) ? c.map((x) => (typeof x?.text === 'string' ? x.text : '')).join('\n') : '';
36
+ for (const m of text.matchAll(FINAL_TASK)) this.open.delete(m[1]);
37
+ return;
38
+ }
39
+ const tur = rec.toolUseResult;
40
+ if (!Array.isArray(c) || !tur || typeof tur !== 'object') return;
41
+ const monitor = c.some((b) => b?.type === 'tool_result' && this.monitors.has(b.tool_use_id));
42
+ const id = typeof tur.backgroundTaskId === 'string' ? tur.backgroundTaskId : monitor && typeof tur.taskId === 'string' ? tur.taskId : undefined;
43
+ if (id) this.open.add(id);
44
+ }
45
+ }
46
+
8
47
  /**
9
48
  * Pairs tool_use / server_tool_use blocks with their results (tool_use_id) into tool spans.
10
49
  * Result bodies are never read: only the ids, flags and timestamps.
@@ -6,11 +6,12 @@
6
6
  // no markers and no `role` on the root; CC `turns` are duration points, Codex's are bands;
7
7
  // Codex sub-agent links may be inferred (linkApprox / startApprox).
8
8
  import { basename } from 'node:path';
9
- import { HEAD_BYTES, TAIL_BYTES, findLastTitle, readEnds, readHead } from './scan.js';
9
+ import { HEAD_BYTES, TAIL_BYTES, TITLE_SCAN_BYTES, findLastTitle, readEnds, readHead, readTail } from './scan.js';
10
10
  import { createCodexParser } from '../adapters/codex/index.js';
11
11
  import { linkCodexAgents } from '../adapters/codex/agents.js';
12
12
  import { AgentCollector, buildSessionTree } from '../adapters/claude-code/agents.js';
13
13
  import { ENDS_TURN, shutdownSignal } from '../adapters/claude-code/index.js';
14
+ import { BackgroundTasks } from '../adapters/claude-code/tools.js';
14
15
  import { mapUsage } from '../adapters/codex/llm.js';
15
16
  import { MSG } from '../strings.js';
16
17
 
@@ -107,7 +108,14 @@ function quickClaude(entry, store, now) {
107
108
  // ...but a sub-agent or teammate still writing keeps the run going (same rule as the full parse).
108
109
  const stopped = entry.subs.some((s) => s.mate) ? stoppedMates(tail) : new Map();
109
110
  const childRunning = entry.subs.some((s) => recent(s.mtimeMs) && (s.mate ? !mateDone(store, s, stopped) : !subFinished(store, s)));
110
- const running = (!turnEnded && recent(last)) || childRunning;
111
+ // A recently ended turn may still wait on a background task: look further back than the tail for its launch
112
+ // (only then, so the list stays cheap).
113
+ // ponytail: a launch more than 256 KB before the end is missed and the run shows as done, as before.
114
+ const bg = new BackgroundTasks();
115
+ if (turnEnded && recent(last) && !childRunning) {
116
+ for (const r of readTail(store, entry.main.fileId, entry.main.size, TITLE_SCAN_BYTES)) if (r.type === 'assistant') bg.onAssistant(r); else if (r.type === 'user') bg.onUser(r);
117
+ }
118
+ const running = (recent(last) && (!turnEnded || bg.open.size > 0)) || childRunning;
111
119
  return base(entry, {
112
120
  ...(title ? { title } : {}),
113
121
  project: lastSeg(cwd) || entry.project || '',
@@ -116,6 +124,7 @@ function quickClaude(entry, store, now) {
116
124
  start: first ?? entry.main.mtimeMs,
117
125
  end: running ? null : last,
118
126
  status: running ? 'running' : 'ok',
127
+ ...(running && turnEnded ? { background: true } : {}),
119
128
  agentCount: 1 + entry.subs.length,
120
129
  totals, models,
121
130
  });
@@ -259,6 +268,7 @@ export function fullSummary(entry, spans, meta) {
259
268
  start: session?.start ?? 0,
260
269
  end: session?.end ?? null,
261
270
  status: session?.status ?? 'unknown',
271
+ ...(session?.background ? { background: true } : {}),
262
272
  agentCount: agents, callCount: calls, errorCount: errors,
263
273
  totals, models, inferredLinks: inferred, detail: true,
264
274
  });
@@ -27,6 +27,7 @@
27
27
  * @property {SpanKind} kind
28
28
  * @property {string} name
29
29
  * @property {SpanStatus} status
30
+ * @property {boolean} [background] session / root agent: running only because background work is open (its turn ended).
30
31
  * @property {number} start Epoch ms.
31
32
  * @property {number | null} end Null while running.
32
33
  * @property {boolean} [startApprox]
package/web/app.css CHANGED
@@ -56,6 +56,7 @@ button:focus-visible, .sess:focus-visible { outline: 2px solid var(--accent); ou
56
56
  .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); display: inline-block; flex: none; }
57
57
  .dot.pulse { background: var(--run); animation: pulse 1.8s ease-in-out infinite; }
58
58
  .dot.off { background: var(--faint); }
59
+ .dot.pulse.bg { background: transparent; box-shadow: inset 0 0 0 1.5px var(--flow); } /* running, but only background work is open */
59
60
  @keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .35 } }
60
61
  .icon-btn { border: 1px solid var(--line); border-radius: 7px; padding: 4px 9px; color: var(--muted); }
61
62
  .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@@ -73,7 +74,8 @@ body.lost .app, body.lost .live { display: none; }
73
74
  .list-resizer:focus-visible { outline: none; }
74
75
  body.resizing { cursor: col-resize; user-select: none; }
75
76
  .list { border-right: 1px solid var(--line); background: var(--panel); overflow: auto; }
76
- .main { overflow: auto; min-width: 0; container: main / inline-size; }
77
+ .main { overflow: auto; min-width: 0; container: main / inline-size; display: flex; flex-direction: column; }
78
+ .main > .view { flex: 1 0 auto; } /* the view fills what the header leaves, so the agent panel can too */
77
79
 
78
80
  /* Session list */
79
81
  .list-head { padding: 12px 14px 8px; display: flex; flex-direction: column; gap: 8px; position: sticky; top: 0; z-index: 1; background: var(--panel); border-bottom: 1px solid var(--line-2); }
@@ -122,7 +124,7 @@ body.resizing { cursor: col-resize; user-select: none; }
122
124
  .badge { font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; letter-spacing: .02em; flex: none; }
123
125
  .badge.cc { background: var(--badge-cc-bg); color: var(--badge-cc); }
124
126
  .badge.cx { background: var(--badge-cx-bg); color: var(--badge-cx); }
125
- .st-err { color: var(--err); } .st-run { color: var(--run); }
127
+ .st-err { color: var(--err); } .st-run { color: var(--run); } .st-run.bg { color: var(--flow); }
126
128
  .note { padding: 16px 14px; color: var(--muted); }
127
129
 
128
130
  /* Run screen head, totals strip, tabs */
@@ -335,7 +337,7 @@ body.resizing { cursor: col-resize; user-select: none; }
335
337
  /* Graph detail column (web/agent-panel.js) and the call detail block (web/call-detail.js). */
336
338
  .view.with-panel { display: grid; }
337
339
  .view.with-panel > * { grid-area: 1 / 1; min-width: 0; }
338
- .g-panel { justify-self: end; align-self: start; z-index: 3; width: 360px; box-shadow: -8px 0 24px rgba(0,0,0,.18); max-height: calc(100vh - 48px); overflow: auto; position: sticky; top: 0; border-left: 1px solid var(--line); background: var(--panel); }
340
+ .g-panel { justify-self: end; align-self: start; z-index: 3; width: 360px; box-shadow: -8px 0 24px rgba(0,0,0,.18); contain: strict; height: 100%; max-height: calc(100vh - 48px); overflow: auto; position: sticky; top: 0; border-left: 1px solid var(--line); background: var(--panel); }
339
341
  .g-panel[hidden] { display: none; }
340
342
  .gp-h { display: flex; gap: 10px; align-items: center; padding: 14px 16px 6px; }
341
343
  .gp-who { min-width: 0; flex: 1; }
package/web/mini.js CHANGED
@@ -47,6 +47,11 @@ const dot = (status) => el('span', status === 'running' ? 'dot pulse' : status =
47
47
  function nowLine(s, now) {
48
48
  const n = nowOf(s.agents ?? []);
49
49
  const line = el('div', `mini-now${n?.waiting ? ' waiting' : ''}`);
50
+ // the main thread's turn ended and nothing deeper is working: it waits on a background task
51
+ if (s.background && (!n || (n.agent.depth === 0 && !n.tool))) {
52
+ line.append(el('span', 'dot pulse bg'), el('span', 'mini-tool', S.mini.background));
53
+ return line;
54
+ }
50
55
  if (!n) return line;
51
56
  const who = (s.agents?.length ?? 0) > 1 ? `${agentName(n.agent)} · ` : '';
52
57
  line.append(n.waiting ? el('span', 'mini-ico', '⏸') : dot('running'), el('span', 'mini-tool', `${who}${n.waiting ? S.mini.waiting : n.tool ?? S.mini.thinking}`));
package/web/run-header.js CHANGED
@@ -176,6 +176,8 @@ export function createRunHeader({ onBack, onTab, onShowAll, onHide }) {
176
176
  name.textContent = s ? s.title || S.list.untitled : '';
177
177
  const running = s?.status === 'running';
178
178
  dot.hidden = !running;
179
+ dot.classList.toggle('bg', Boolean(s?.background));
180
+ dot.title = s?.background ? S.status.background : S.status.running;
179
181
 
180
182
  const total = p.totals?.total ?? null;
181
183
  const haveTotals = Boolean(total);
@@ -123,8 +123,8 @@ export function sessionRow(s, { selected = false, now = Date.now(), group = null
123
123
  t.append(badge, el('span', 'name', s.title || S.list.untitled));
124
124
  if (group) t.append(el('span', 'grp-tag', group));
125
125
  if (s.status === 'running') {
126
- const dot = el('span', 'dot pulse');
127
- dot.title = S.status.running;
126
+ const dot = el('span', s.background ? 'dot pulse bg' : 'dot pulse');
127
+ dot.title = s.background ? S.status.background : S.status.running;
128
128
  t.append(dot);
129
129
  }
130
130
  const m = el('div', 'm');
@@ -144,7 +144,7 @@ export function sessionRow(s, { selected = false, now = Date.now(), group = null
144
144
  const tokens = (s.totals?.input ?? 0) + (s.totals?.output ?? 0) + (s.totals?.cacheRead ?? 0);
145
145
  if (tokens) m.append(el('span', 'num', S.list.tokens(fmtTokens(tokens))));
146
146
  if (s.status === 'running' || s.status === 'error') {
147
- m.append(el('span', s.status === 'error' ? 'st-err' : 'st-run', s.status === 'error' ? `▲ ${S.status.error}` : S.status.running));
147
+ m.append(el('span', s.status === 'error' ? 'st-err' : s.background ? 'st-run bg' : 'st-run', s.status === 'error' ? `▲ ${S.status.error}` : s.background ? S.status.background : S.status.running));
148
148
  }
149
149
  if (s.origin && s.origin !== 'default') {
150
150
  const o = el('span', 'origin', s.origin);
package/web/strings.js CHANGED
@@ -6,7 +6,7 @@ export const S = {
6
6
  mini: {
7
7
  none: 'Nothing running right now.', offline: 'The inspector service is not answering.',
8
8
  running: (n) => (n ? `Running · ${n}` : 'Running'),
9
- thinking: 'Thinking…', waiting: 'Waiting for you',
9
+ thinking: 'Thinking…', waiting: 'Waiting for you', background: 'Waiting on a background task',
10
10
  justNow: 'now', ago: (t) => `${t} ago`,
11
11
  tokens: (t) => `${t} tokens`,
12
12
  errors: (n) => `▲ ${n} failed`,
@@ -186,5 +186,5 @@ export const S = {
186
186
  source: { 'claude-code': 'Claude Code', codex: 'Codex CLI' },
187
187
  sourceBadge: { 'claude-code': 'CC', codex: 'CX' },
188
188
  sourceTip: (name) => `Tool: ${name}`,
189
- status: { running: 'Running', ok: 'Done', error: 'Failed', cancelled: 'Cancelled', unknown: 'Unknown' },
189
+ status: { running: 'Running', background: 'Background', ok: 'Done', error: 'Failed', cancelled: 'Cancelled', unknown: 'Unknown' },
190
190
  };