You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Architecture map — pure/edge split, the anti-corruption boundary, and the three data flows
#46
There's no single picture of how the pieces fit, so reasoning about a change means
re-holding the whole thing in your head. This is that picture — derived from the actual import graph in src/, not memory — and it makes legible the two
invariants the architecture rests on: the pure-core / I-O-edge split and the anti-corruption boundary (payload.ts / aggregate.ts).
The map
flowchart TB
CC([Claude Code])
OP([operator · off-session])
subgraph EDGES["I/O edges — own stdin · filesystem · node:sqlite"]
direction TB
SL["statusline.ts"]
SH["summary-hook.ts"]
IH["index-hook.ts"]
RC["report-cli.ts"]
IS["index-store.ts"]
DB["db.ts"]
LOC["location.ts"]
STDIN["stdin.ts"]
end
subgraph CORE["Pure core — values in → strings/numbers out · no clock · no fs · no process"]
direction TB
PAY["payload.ts ⟂ ACL"]
AGG["aggregate.ts ⟂ ACL"]
REN["render.ts"]
FR["fleet-render.ts"]
REP["report.ts"]
SUM["summary.ts"]
PRI["pricing.ts"]
BARS["bars.ts"]
FMT["format.ts"]
ANSI["ansi.ts"]
end
TR[("~/.claude/projects/**.jsonl<br/>session transcripts")]
IDX[("~/.claude/usage-meter/index.db<br/>node:sqlite · 1 row per session")]
%% --- flow 1: live statusline ---
CC -- "payload (stdin JSON)" --> SL
SL --> STDIN
SL -- "narrow unknown → ParsedPayload" --> PAY
SL -- "cwd → repo · branch · worktree" --> LOC
SL -- "updateIndex" --> IS
SL --> REN --> FR
REN ==> OUT1["3-row statusline (stdout)"]
%% --- flow 2: after-task summary + event write (Stop hook) ---
CC -- "writes" --> TR
CC -- "Stop hook" --> SH
CC -- "Stop hook" --> IH
SH -- "reads just-finished transcript" --> TR
SH --> AGG --> SUM ==> OUT2["after-task summary (stdout)"]
IH --> IS
%% --- flow 3: off-session report ---
OP -- "runs report" --> RC
RC --> IS
RC --> REP ==> OUT3["report dashboard (stdout)"]
%% --- shared persistence + pricing ---
IS -- "read incrementally" --> TR
IS -- "fold lines → ModelUsage" --> AGG
IS <--> DB
DB <--> IDX
IS -- "CrossSessionIndex" --> REN
IS -- "CrossSessionIndex" --> REP
PRI -.priced by.-> IS
PRI -.priced by.-> SUM
classDef edge fill:#0d3b66,stroke:#7aa7d8,color:#fff;
classDef core fill:#1b4332,stroke:#74c69d,color:#fff;
classDef acl fill:#5a3e1b,stroke:#e0a458,color:#fff,stroke-width:2px;
classDef store fill:#3a3a3a,stroke:#aaa,color:#fff;
class SL,SH,IH,RC,IS,DB,LOC,STDIN edge;
class REN,FR,REP,SUM,PRI,BARS,FMT,ANSI core;
class PAY,AGG acl;
class TR,IDX store;
Loading
How to read it
Blue = I/O edge. Owns stdin, the filesystem, and the SQLite store: every
side effect lives here. statusline.ts, summary-hook.ts, index-hook.ts, report-cli.ts, index-store.ts, db.ts, location.ts, stdin.ts.
Green = pure core. Data in, string/number out — no clock, no fs, no process; "now" is always a parameter. render.ts, fleet-render.ts, report.ts, summary.ts, pricing.ts, bars.ts, format.ts, ansi.ts.
This is the line every test runs against with a fixed nowMs.
Amber ⟂ = the anti-corruption layer.payload.ts (statusline payload) and aggregate.ts (transcript lines) are the only places untrusted JSON becomes
trusted domain types, via unknown + narrowing. They are the one place that
types explicitly — and the one place that must never throw on bad input
(skip-and-count, never crash the bar).
Grey cylinders = on-disk state, both under ~/.claude: the append-only transcripts Claude Code writes, and our node:sqlite index (one row per
session, atomic upsert, WAL).
The three data flows
Live statusline — Claude Code pipes the payload on stdin; statusline.ts
narrows it through payload.ts, resolves the location off .git via location.ts, folds the cross-session index via index-store.ts, and hands
pure values to render.ts → fleet-render.ts. Re-runs on refreshInterval, so
every hop is cheap and total — a missing field shortens the line, never throws.
After-task summary + event write — on the Stop hook, summary-hook.ts
aggregates the just-finished transcript (aggregate.ts → summary.ts) and
prints the per-model cost/token breakdown; index-hook.ts persists that
session's row through index-store.ts → db.ts (the event-driven write, ADR-0003).
Off-session report — report-cli.ts reads the whole node:sqlite index via index-store.ts and renders the retrospective dashboard with report.ts.
Where the SQLite index sits
index-store.ts is the only module that both reads transcripts and writes the
store; db.ts is the thin node:sqlite boundary (atomic upsert, WAL + retried WAL
switch). The index is written on the Stop event and refreshed on statusline
render, and read back by render.ts (fleet/spend cells) and report.ts
(dashboard) as a plain CrossSessionIndex value — the readers never touch SQLite.
A subagent runs in its own transcript (isSidechain) but is not a separate
user session. In the fold inside index-store.ts / aggregate.ts:
its cost rolls into the parent session's ses total (ADR-0002: spend follows
the real model that was billed — a Haiku subagent shows as Haiku spend, never
relabelled to the parent's class), while
the session counts (fleet's N Σ total and the live active ● tally)
count only top-level sessions, so a subagent is never tallied as a session
(ADR-0001).
This is why fleet counts and spend legitimately diverge (e.g. 0 haiku sessions
yet nonzero haiku spend) — the attribution rule, not a bug.
On location.ts importing render.ts
The lone edge→core import is type-only: location.ts imports the Location interface declared in render.ts. No runtime dependency crosses the boundary the
wrong way — the edge produces the pure value type the core consumes.
Home of this doc: per CLAUDE.md ("docs live in GitHub"), this is the long-form
Design Discussion. No binding in-repo copy is added — the prose architecture in
CLAUDE.md remains the in-context constraint; an implementing agent who needs the
visual follows the pointer on #36/#34 to here. (If a future change makes the map
something an agent must read while coding, that's the trigger to promote a short
pointer into the repo — argued, not by default.)
This is the substrate for the refactor proposal (#37): the candidate refactors are
named against these boundaries.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Ticket: #36 · Story: #34 · Epic: #13
There's no single picture of how the pieces fit, so reasoning about a change means
re-holding the whole thing in your head. This is that picture — derived from the
actual
importgraph insrc/, not memory — and it makes legible the twoinvariants the architecture rests on: the pure-core / I-O-edge split and the
anti-corruption boundary (
payload.ts/aggregate.ts).The map
flowchart TB CC([Claude Code]) OP([operator · off-session]) subgraph EDGES["I/O edges — own stdin · filesystem · node:sqlite"] direction TB SL["statusline.ts"] SH["summary-hook.ts"] IH["index-hook.ts"] RC["report-cli.ts"] IS["index-store.ts"] DB["db.ts"] LOC["location.ts"] STDIN["stdin.ts"] end subgraph CORE["Pure core — values in → strings/numbers out · no clock · no fs · no process"] direction TB PAY["payload.ts ⟂ ACL"] AGG["aggregate.ts ⟂ ACL"] REN["render.ts"] FR["fleet-render.ts"] REP["report.ts"] SUM["summary.ts"] PRI["pricing.ts"] BARS["bars.ts"] FMT["format.ts"] ANSI["ansi.ts"] end TR[("~/.claude/projects/**.jsonl<br/>session transcripts")] IDX[("~/.claude/usage-meter/index.db<br/>node:sqlite · 1 row per session")] %% --- flow 1: live statusline --- CC -- "payload (stdin JSON)" --> SL SL --> STDIN SL -- "narrow unknown → ParsedPayload" --> PAY SL -- "cwd → repo · branch · worktree" --> LOC SL -- "updateIndex" --> IS SL --> REN --> FR REN ==> OUT1["3-row statusline (stdout)"] %% --- flow 2: after-task summary + event write (Stop hook) --- CC -- "writes" --> TR CC -- "Stop hook" --> SH CC -- "Stop hook" --> IH SH -- "reads just-finished transcript" --> TR SH --> AGG --> SUM ==> OUT2["after-task summary (stdout)"] IH --> IS %% --- flow 3: off-session report --- OP -- "runs report" --> RC RC --> IS RC --> REP ==> OUT3["report dashboard (stdout)"] %% --- shared persistence + pricing --- IS -- "read incrementally" --> TR IS -- "fold lines → ModelUsage" --> AGG IS <--> DB DB <--> IDX IS -- "CrossSessionIndex" --> REN IS -- "CrossSessionIndex" --> REP PRI -.priced by.-> IS PRI -.priced by.-> SUM classDef edge fill:#0d3b66,stroke:#7aa7d8,color:#fff; classDef core fill:#1b4332,stroke:#74c69d,color:#fff; classDef acl fill:#5a3e1b,stroke:#e0a458,color:#fff,stroke-width:2px; classDef store fill:#3a3a3a,stroke:#aaa,color:#fff; class SL,SH,IH,RC,IS,DB,LOC,STDIN edge; class REN,FR,REP,SUM,PRI,BARS,FMT,ANSI core; class PAY,AGG acl; class TR,IDX store;How to read it
side effect lives here.
statusline.ts,summary-hook.ts,index-hook.ts,report-cli.ts,index-store.ts,db.ts,location.ts,stdin.ts.fs, noprocess; "now" is always a parameter.render.ts,fleet-render.ts,report.ts,summary.ts,pricing.ts,bars.ts,format.ts,ansi.ts.This is the line every test runs against with a fixed
nowMs.payload.ts(statusline payload) andaggregate.ts(transcript lines) are the only places untrusted JSON becomestrusted domain types, via
unknown+ narrowing. They are the one place thattypes explicitly — and the one place that must never throw on bad input
(skip-and-count, never crash the bar).
~/.claude: the append-onlytranscripts Claude Code writes, and our
node:sqliteindex (one row persession, atomic upsert, WAL).
The three data flows
statusline.tsnarrows it through
payload.ts, resolves the location off.gitvialocation.ts, folds the cross-sessionindexviaindex-store.ts, and handspure values to
render.ts→fleet-render.ts. Re-runs onrefreshInterval, soevery hop is cheap and total — a missing field shortens the line, never throws.
summary-hook.tsaggregates the just-finished transcript (
aggregate.ts→summary.ts) andprints the per-model cost/token breakdown;
index-hook.tspersists thatsession's row through
index-store.ts→db.ts(the event-driven write, ADR-0003).report-cli.tsreads the wholenode:sqliteindex viaindex-store.tsand renders the retrospective dashboard withreport.ts.Where the SQLite index sits
index-store.tsis the only module that both reads transcripts and writes thestore;
db.tsis the thinnode:sqliteboundary (atomic upsert, WAL + retried WALswitch). The index is written on the Stop event and refreshed on statusline
render, and read back by
render.ts(fleet/spend cells) andreport.ts(dashboard) as a plain
CrossSessionIndexvalue — the readers never touch SQLite.Subagent → parent attribution (ADR-0001 / ADR-0002)
A subagent runs in its own transcript (
isSidechain) but is not a separateuser session. In the fold inside
index-store.ts/aggregate.ts:sestotal (ADR-0002: spend followsthe real model that was billed — a Haiku subagent shows as Haiku spend, never
relabelled to the parent's class), while
fleet'sN Σ totaland the liveactive ●tally)count only top-level sessions, so a subagent is never tallied as a session
(ADR-0001).
This is why fleet counts and spend legitimately diverge (e.g.
0haiku sessionsyet nonzero haiku spend) — the attribution rule, not a bug.
On
location.tsimportingrender.tsThe lone edge→core import is type-only:
location.tsimports theLocationinterface declared in
render.ts. No runtime dependency crosses the boundary thewrong way — the edge produces the pure value type the core consumes.
Home of this doc: per CLAUDE.md ("docs live in GitHub"), this is the long-form
Design Discussion. No binding in-repo copy is added — the prose architecture in
CLAUDE.md remains the in-context constraint; an implementing agent who needs the
visual follows the pointer on #36/#34 to here. (If a future change makes the map
something an agent must read while coding, that's the trigger to promote a short
pointer into the repo — argued, not by default.)
This is the substrate for the refactor proposal (#37): the candidate refactors are
named against these boundaries.
All reactions