glassbox-trace 0.3.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/LICENSE +21 -0
- package/README.md +120 -0
- package/bin/glassbox.mjs +3 -0
- package/dist/glassbox.html +1653 -0
- package/package.json +54 -0
- package/src/cli.mjs +246 -0
- package/src/trace-core.js +768 -0
- package/src/viewer.html +875 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aldo Hushi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Glassbox
|
|
2
|
+
|
|
3
|
+
[](https://github.com/aldohushi1-stack/glassbox/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
**The flight recorder viewer for Claude Code and Agent SDK sessions.**
|
|
6
|
+
|
|
7
|
+
Drop a session `.jsonl` onto one HTML file. Get a timeline of every model call and tool call, where the tokens and money went, and a list of things a reviewer would flag — retry loops, failing tools, oversized results, context bloat, stalls. Nothing leaves your browser.
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
The demo built into the file is the trace of the session that built Glassbox, sanitised.
|
|
12
|
+
|
|
13
|
+
## Why
|
|
14
|
+
|
|
15
|
+
Every Claude Code and Cowork session writes its full transcript to `~/.claude/projects/<project>/<session-id>.jsonl`, with subagents in `<session-id>/subagents/agent-*.jsonl`. The Agent SDK emits the same shapes as `--output-format stream-json`. Those files are the only complete record of what an agent did, and they're unreadable: one JSON object per line, assistant messages split one record per content block, usage duplicated across those records, tool calls joined to results only by id.
|
|
16
|
+
|
|
17
|
+
Agents can't see their own traces. Humans reviewing agent work can't either. Glassbox fixes both.
|
|
18
|
+
|
|
19
|
+
## Use it
|
|
20
|
+
|
|
21
|
+
**Fastest:** `npx glassbox-trace` opens your newest Claude Code session in the browser.
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
npx glassbox-trace open the newest session (or `npm i -g glassbox-trace`, then `glassbox …`)
|
|
25
|
+
glassbox list --last 10 list sessions (id, time, size, project, title)
|
|
26
|
+
glassbox list --grep "npm test" only sessions containing the text
|
|
27
|
+
glassbox open 81c4 open a session by id prefix (or a .jsonl path)
|
|
28
|
+
glassbox open 81c4 --out trace.html write a self-contained HTML you can send to someone
|
|
29
|
+
glassbox check print findings; exit 1 on any error-level finding
|
|
30
|
+
glassbox check --fail-on warn --json stricter, machine-readable (CI, hooks, agents)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The npm package is `glassbox-trace` (plain `glassbox` was already taken); the command it installs is `glassbox`. Subagent transcripts next to the session are included automatically. `GLASSBOX_HOME` overrides `~/.claude`; `GLASSBOX_BROWSER` names the command used to open HTML.
|
|
34
|
+
|
|
35
|
+
**Let the agent read its own recorder.** `glassbox hook install` adds a Claude Code Stop hook: every session ends with a one-screen Glassbox summary (turns, tool calls, context peak, cost, top findings). Add `--feedback` and the findings are handed back to the agent once — it reads them and says, in a sentence, what it would do differently next time. It never loops (`stop_hook_active` is respected), never blocks a clean session, and `glassbox hook uninstall` removes it, with a `.glassbox-backup` of `settings.json` kept.
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
glassbox hook install --feedback --fail-on warn # summary + one-shot feedback to the agent
|
|
39
|
+
glassbox hook install # summary only
|
|
40
|
+
glassbox hook uninstall
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**In the browser:** open `dist/glassbox.html` (double-click, no server). It shows the demo session at rest. Then either drop your `.jsonl` (or the whole `<session-id>` folder for subagent lanes), or in Chrome/Edge click **Open folder…**, pick `~/.claude/projects`, and choose a session from the list — the folder is remembered, so next time it's **Recent**. Finding the file by hand: `ls -t ~/.claude/projects/*/*.jsonl | head` on macOS/Linux, `%USERPROFILE%\.claude\projects\` on Windows.
|
|
44
|
+
|
|
45
|
+
Read top to bottom: stats → timeline (with minimap, search, fit-to-turn) → context & cost → findings → tools → turns. Click anything for detail. Every selection is a permalink (`#req=17`, `#tool=…`, `#find=3`, `#turn=2`).
|
|
46
|
+
|
|
47
|
+
**Keyboard:** `Tab` into the timeline, `←`/`→` previous/next call, `↑`/`↓` change lane, `Enter` opens detail, `Esc` closes it; `+` `−` `0` zoom, `Shift+←/→` pan, `/` search, `?` help. Touch: drag to pan, pinch to zoom.
|
|
48
|
+
|
|
49
|
+
**Findings → Copy / Copy all / Export report** give you Markdown to paste into an issue or back into the agent ("here's what went wrong last time").
|
|
50
|
+
|
|
51
|
+
**Share mode** blanks every prompt, tool input, result and assistant text in the view; **Export redacted** downloads a structure-only `.jsonl` that keeps timestamps, usage and tool names — safe to post publicly.
|
|
52
|
+
|
|
53
|
+
**Accessibility:** WCAG 2.2 AA contrast in both themes, full keyboard operation with roving focus on the timeline and chart, screen-reader names on every span and row, live announcements on load and search, focus-managed detail panel, reduced-motion respected. `npm run audit` re-checks all of it with axe-core and fails the build on regressions.
|
|
54
|
+
|
|
55
|
+
## What it flags
|
|
56
|
+
|
|
57
|
+
| rule | fires when |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `retry-loop` | same tool with identical input ≥ 3× in one turn (error if ≥ 2 failed) |
|
|
60
|
+
| `failed-tool` | any tool error; error-level when a tool fails ≥ 50% of ≥ 3 calls |
|
|
61
|
+
| `orphan-tool` | a tool call with no result (abort, crash, or still running) |
|
|
62
|
+
| `exploration-run` | ≥ 8 read-only calls in a row with no write or exec (warn at 15) |
|
|
63
|
+
| `oversized-result` | a single tool result ≥ 20k chars (error at 60k) |
|
|
64
|
+
| `image-heavy` | screenshots / image reads totalling ≥ 0.5 MB (warn at 2 MB) — they're tokens on every later request |
|
|
65
|
+
| `context-bloat` | prompt size ≥ 120k tokens (error at 170k), with the request that first crossed it |
|
|
66
|
+
| `cache-churn` | ≥ 20k tokens re-cached mid-session — the cached prefix was invalidated |
|
|
67
|
+
| `low-cache-hit` | < 50% of input served from cache over ≥ 5 requests |
|
|
68
|
+
| `slow-model` | ≥ 60 s for a response under 1,500 tokens (latency / rate limit / stall) |
|
|
69
|
+
| `long-generation` | ≥ 60 s for a big response, with tok/s so you can tell a stall from a file write |
|
|
70
|
+
| `slow-tool` | a tool call ≥ 60 s (warn at 5 min) |
|
|
71
|
+
| `max-tokens`, `api-error`, `hook-error`, `compaction`, `thinking-heavy`, `subagent-share`, `long-turn` | what they say |
|
|
72
|
+
|
|
73
|
+
All mechanical, no AI. Thresholds are in `TraceCore.DEFAULTS` and can be overridden when calling `diagnose(trace, opts)`.
|
|
74
|
+
|
|
75
|
+
## Token and cost accounting
|
|
76
|
+
|
|
77
|
+
- Usage is counted once per API request (assistant records sharing a `requestId`), not once per record.
|
|
78
|
+
- Context size = uncached input + cache read + cache write — the prompt the model actually saw.
|
|
79
|
+
- Thinking tokens are part of output tokens; shown as a share, never added twice.
|
|
80
|
+
- Cost is estimated from an editable rate card (defaults from the Claude pricing page, 2026-09-05; prefix-matched so dated model ids resolve). A `stream-json` `result` record with `total_cost_usd` overrides the estimate. Unknown models show "—" rather than a wrong number.
|
|
81
|
+
|
|
82
|
+
## Formats
|
|
83
|
+
|
|
84
|
+
Claude Code transcripts (main + subagents + `meta.json`), Agent SDK / `claude -p --output-format stream-json` output, and plain Messages-API `[{role, content}]` arrays. Malformed lines are reported and skipped, never fatal.
|
|
85
|
+
|
|
86
|
+
## Develop
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
npm test # unit tests (node:test) — parser, every diagnostic rule, cost, redaction, CLI, real fixtures
|
|
90
|
+
npm run build # dist/glassbox.html (standalone) + dist/glassbox.artifact.html (fragment)
|
|
91
|
+
npm run e2e # Playwright: demo in light+dark, tiles vs core, keyboard nav, drawer focus, search, clipboard, permalinks
|
|
92
|
+
npm run audit # axe-core + contrast + keyboard reachability + responsive + 16 MB stress run; fails on regressions
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Layout:
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
src/trace-core.js pure engine: parseTrace · diagnose · estimateCost · redact (no DOM, no deps)
|
|
99
|
+
src/viewer.html the UI; the build inlines trace-core and the demo
|
|
100
|
+
src/cli.mjs CLI library (session discovery, embed, check); bin/glassbox.mjs is the entry point
|
|
101
|
+
scripts/build.mjs build
|
|
102
|
+
scripts/sanitize.mjs turn a real transcript into a shareable fixture (demo or structure mode)
|
|
103
|
+
test/ unit, e2e and audit harnesses, fixtures
|
|
104
|
+
DESIGN.md design doc — data model, rules, thresholds, UI, privacy
|
|
105
|
+
STUDY.md accessibility & ease-of-use study that drove v0.2
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Use the engine on its own:
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
const { parseTrace, diagnose, estimateCost } = require('./src/trace-core.js');
|
|
112
|
+
const trace = parseTrace([{ name: 'session.jsonl', text: fs.readFileSync(p, 'utf8') }]);
|
|
113
|
+
console.log(trace.totals, diagnose(trace), estimateCost(trace).total);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Privacy
|
|
117
|
+
|
|
118
|
+
The page makes no network requests except the Google Fonts stylesheet (it falls back to system fonts if that's blocked). Transcripts contain everything the agent saw; that's why share mode exists.
|
|
119
|
+
|
|
120
|
+
Source: [github.com/aldohushi1-stack/glassbox](https://github.com/aldohushi1-stack/glassbox) · MIT © Aldo Hushi
|
package/bin/glassbox.mjs
ADDED