From 3ffd81f3a56b24c0684368a0c0cdca035358dc33 Mon Sep 17 00:00:00 2001 From: bchanot Date: Thu, 19 Nov 2026 18:10:47 +0100 Subject: [PATCH] chore(memory): Run C advisor usage, LRN-301 LRN-302, TODO:18 done, leak + timeout follow-ups --- .claude/memory/journal.md | 1 + .claude/memory/learnings.md | 12 ++ .claude/tasks/TODO.md | 4 +- .../2026-11-19-advisor-usage-1625.md | 49 +++++ .../plans/2026-11-19-advisor-usage-1625.md | 178 ++++++++++++++++++ 5 files changed, 243 insertions(+), 1 deletion(-) create mode 100644 .claude/tasks/contracts/2026-11-19-advisor-usage-1625.md create mode 100644 .claude/tasks/plans/2026-11-19-advisor-usage-1625.md diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index 3bfa7f9..1a621c2 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -785,3 +785,4 @@ rules: ## 2026-11-19 - /bugfix degraded-tool-line 9814720: 3 security readers read DEGRADED off TOOL line (BLK-051), BUGS-FOUND:134 FIXED, TODO:13 done, 2 pre-existing minors logged; CHANGELOG Fixed entry. - /feat x2 merge-reuse (af846d6, 87566e2, feature/advisor-merge-reuse): 6 gate-flow end lines restate effort-shift item 3 merge-reuse clause, loops-light 97; TODO:14 done, 3 follow-ups logged; run 1 GATE 0 ERROR = contract without EVIDENCE: pending (LRN-173 again). +- Run C /feat advisor-usage (c6f2dad + retention fix, feature/advisor-usage): FEEDBACK.md advisor usage table per caller/model, reconciled vs probe (156 calls, 21.7M); found general-purpose sub-agent advisor leak (30 calls, 7.1M) → TODO; LRN-301 (call = served iteration), LRN-302 (scratch develop ref); mods.test.sh timeout under load → BUGS-FOUND. diff --git a/.claude/memory/learnings.md b/.claude/memory/learnings.md index 298f864..58ad83b 100644 --- a/.claude/memory/learnings.md +++ b/.claude/memory/learnings.md @@ -2162,3 +2162,15 @@ Rule: when editing a doctrine file under structure locks, grep the test's lock s **Context**: advisor run B3 (2b7aeb8, 51f343f). feat/bugfix skip end-of-run advisor call when security PASS "(not DEGRADED)". security-auditor prints `SECURITY — VERDICT: PASS` on DEGRADED scan; DEGRADED only on `TOOL:` line (agents/security-auditor.md OUTPUT), while lib/verify-secure-loop.md teaches reading DEGRADED off VERDICT line → reader checks wrong line, wrong skip. 3 lenses + re-challenge missed it; opus STEP 6 caught it. **Pattern**: rule keyed on gate verdict must name the line its qualifier prints on. Agent OUTPUT format = source of truth, not the doctrine paraphrasing it. **Apply**: before writing a condition on an agent's verdict, grep that agent's OUTPUT block for where each qualifier prints; state the line at the site. + +## LRN-301 — Advisor call = served advisor_message iteration, not request block; reconcile usage table vs independent probe (2026-11-19) +- **Pattern**: advisor call = served `advisor_message` iteration in `message.usage.iterations[]`, not `server_tool_use` block named `advisor`. Block without iteration = request never run (sent beside client tool_use, re-issued next message) or `advisor_tool_result_error`. Count iterations, dedupe by `message.id`. Usage table built from transcripts: reconcile row by row against independent probe (other language, same window, same instant) before calling it right; gates re-running same code prove nothing about real numbers. +- **Context**: 2026-11-19 Run C (/memory-feedback advisor usage, c6f2dad). Real transcripts: 147 blocks vs 141 iterations (5 unrun, 1 error). Python probe vs bun table: 8 rows identical, 156 calls 21.7M input tok. First table exposed leak: general-purpose sub-agents 30 calls / 7.1M (16 after 6ef3069 rule), doc-syncer 4. +- **Apply**: any advisor cost/usage count: iterations not blocks; corrects LRN-295 call definition. Report generator on real data: independent probe + timing before FEAT COMPLETE. +- **Reference**: lib/memory-feedback/advisor.ts, LRN-295, BDR-150, TODO advisor doctrine leak + +## LRN-302 — Scratch clone -b lacks local develop: create ref before simulating develop-based oracles (2026-11-19) +- **Pattern**: `git clone -q -b . ` scratch copy has no local `develop` (only `origin/develop`): oracles naming `develop` (`git diff --quiet develop -- …`, floor-guard) fail `fatal: bad revision 'develop'` on scratch, pass in real repo. Before simulating contract CHECKs on clone: `git -C branch develop origin/develop`. +- **Context**: 2026-11-19 merge-reuse run 2 simulation (LRN-296 method): criterion 3 SKIP-INTACT failed only on scratch clone; fixed by creating ref. +- **Apply**: every LRN-296 scratch simulation from a non-develop branch: create local develop ref first, else false red. +- **Reference**: LRN-296, .claude/tasks/contracts/2026-11-19-merge-reuse-feat-bugfix-1450.md diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index d9d0840..790a89d 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -15,7 +15,9 @@ Done history before 2026-10-08 removed 2026-10-23 (git keeps it: `git log -p -- - [ ] lib/effort-shift.md § Advisor item 3 reuse clause has no fallback: end-of-run answer absent (advisor absent/error) or out of view at the merge signal → candidate "answer absent or out of view → the merge proposal runs the call" (source, not the sites); the merge happens at the gitflow finish gate (skills/gitflow/SKILL.md:68-89, 0 advisor mentions) where the rule is not loaded (merge-reuse challengers, low) - [ ] item 3 "names any code commit made after it" has no anchor: ADVISOR field records no HEAD SHA, commits made outside the session are invisible; candidate: record the short SHA with the answer (visible format change, user decision) (merge-reuse robustness challenger, low) - [ ] end-of-run sites restate the call but not "one end-of-run call per skill run": a fix that goes back through the gates re-enters the end step and may call again (merge-reuse robustness challenger, low) -- [ ] Run C /feat: advisor usage section in /memory-feedback (main loop vs sub-agents, model served, input tokens; dedupe usage rows by message.id, model from the `advisor_message` iteration) +- [x] DONE c6f2dad + 63f5fa4 (docs 7d09837) (/feat feature/advisor-usage; user 2026-11-19: FEEDBACK.md section, per agentType, all projects no repo, since last run, retention + drift lines). Was: Run C /feat: advisor usage section in /memory-feedback (main loop vs sub-agents, model served, input tokens; dedupe usage rows by message.id, model from the `advisor_message` iteration) +- [ ] Advisor doctrine leak: general-purpose sub-agents called the advisor 30× (7.1M input tok, the largest line of the first advisor usage table; 16 on 2026-11-18/19, after 6ef3069 2026-11-17 12:59 limited sub-agents to plan-challenger/verifier/security-auditor/analyzer), doc-syncer 4× (2026-11-16/17). Likely SDD implementers/reviewers dispatched as general-purpose: find why the "executors and every other sub-agent do not" rule does not reach them (brief, agent prompt or tool listing) (Run C first table, medium) +- [ ] lib/tests/mods.test.sh model-router plugin test runs ~121 s alone vs CLI_TIMEOUT=120 (load avg 26-31 on 2026-11-19): flaky red in make test, probable cause of run 1 feater's unexplained red; raise the bound or speed the test (Run C GATE 0, low) - [x] Stale citers after A: README/USAGE/CHANGELOG patched, BUGS-FOUND residual superseded + LOW logged, BDR-150 status, LRN-295 (LRN-294 kept: its lesson holds) ### BDR-125 close-out run (user 2026-11-12): no phase 0/0b/4a/1/5/2/4b/4c/4d line left in TODO or BUGS-FOUND diff --git a/.claude/tasks/contracts/2026-11-19-advisor-usage-1625.md b/.claude/tasks/contracts/2026-11-19-advisor-usage-1625.md new file mode 100644 index 0000000..1217a1f --- /dev/null +++ b/.claude/tasks/contracts/2026-11-19-advisor-usage-1625.md @@ -0,0 +1,49 @@ +# CONTRACT — advisor-usage (Run C) +- date: 2026-11-19 | flow: feat | branch: feature/advisor-usage +- status: active + +## REQUEST (verbatim — IMMUTABLE) +Merge et corrige le bug et fais les todo + +Scope of this run (main loop): TODO:18 Run C — advisor usage section in /memory-feedback (main loop vs sub-agents, model served, input tokens; dedupe usage rows by message.id, model from the `advisor_message` iteration). + +## CLARIFICATIONS +Q: placement / A: a "## Advisor usage ( → )" section appended to FEEDBACK.md by `reader.ts apply`, printed with the gates, even at 0 records [gated 2026-11-19] +Q: sub-agent breakdown / A: per agent type from subagents/agent-.meta.json `agentType`; unknown → "sub-agent (unknown)"; main thread = "main loop" [gated 2026-11-19] +Q: scope / A: every project under ~/.claude/projects summed, no repo name or tag in the table [gated 2026-11-19] +Q: window / A: since the last /memory-feedback run (state.json lastRun) to now; first run (lastRun 0) = everything on disk [gated 2026-11-19] +Q: retention note / A: when the window exceeds 7 days, "Transcripts kept 7 d: calls before may be missing." under the heading [gated 2026-11-19] +Q: shape drift / A: 0 calls but usage rows mention advisor_message → "N transcript lines mention advisor_message, none parsed: check the transcript shape." in place of the plain zero [gated 2026-11-19] +Q: challenge (3 lenses) changes: call = served advisor iteration (block without iteration not counted), per-dir skip, dated Unavailable heading, no 6th local in commit(), compact 999950 → 1.0M / A: main loop, internal [2026-11-19] + +Q: GATE 0 run 1 criterion 1 oracle broken (bun prints file names only on failure) / A: main loop, oracle corrected to run advisor.test.ts directly; criterion 4 red = mods.test.sh model-router plugin test timeout at load avg ~30 (121 s alone vs CLI_TIMEOUT 120), unrelated to the diff [2026-11-19] + +Q: retention note fires every weekly run (window just over 7 d, cut day = start day) / A: print it only when the cut day is later than the heading's start day [gated 2026-11-19] +Q: privacy wording / A: skills/memory-feedback/SKILL.md:12 "keeps IDs, enums and repo tags only" → also names advisor call counts [gated 2026-11-19] + +## ACCEPTANCE CRITERIA +1. The memory-feedback bun suite is green and advisor.test.ts runs at least 17 passing tests. + CHECK: cd /home/bchanot/Documents/claude/lib/memory-feedback && PATH=$HOME/.bun/bin:$PATH bun test advisor.test.ts 2>&1 | grep -qE '^ *(1[7-9]|[2-9][0-9]) pass' && cd /home/bchanot/Documents/claude && PATH=$HOME/.bun/bin:$PATH bash lib/tests/memory-feedback.test.sh 2>&1 | grep -qE '^ *0 fail' && echo MF-GREEN + EXPECT: MF-GREEN + EVIDENCE: MET exit=0 marker-found :: MF-GREEN +2. On real transcripts, advisorUsage + renderAdvisor read this machine's advisor calls: the section heading, a "main loop" row, a Fable-served row and the total row appear (total arithmetic: advisor.test.ts). + CHECK: cd /home/bchanot/Documents/claude/lib/memory-feedback && PATH=$HOME/.bun/bin:$PATH bun -e 'import {advisorUsage,renderAdvisor} from "./advisor.ts"; const p=require("os").homedir()+"/.claude/projects"; const t=advisorUsage(p,0,Date.now()); const u=t.uses; const s=renderAdvisor(t,0,Date.now()); const ok=s.startsWith("## Advisor usage (all on disk → ")&&u.some(x=>x.caller==="main loop")&&u.some(x=>x.model.startsWith("claude-fable"))&&s.includes("| total |"); console.log(ok?"ADV-SMOKE":"bad")' + EXPECT: ADV-SMOKE + EVIDENCE: MET exit=0 marker-found :: ADV-SMOKE +3. `reader.ts apply` writes the section into FEEDBACK.md (reader.test.ts locks it) and the skill's STEP 5 tells the user to show it. + CHECK: cd /home/bchanot/Documents/claude && grep -qF '## Advisor usage' lib/memory-feedback/reader.test.ts && grep -qF '`## Advisor usage`' skills/memory-feedback/SKILL.md && echo WIRED + EXPECT: WIRED + EVIDENCE: MET exit=0 marker-found :: WIRED +4. Full make test green (code-limits and the citers census included). + CHECK: cd /home/bchanot/Documents/claude && PATH=$HOME/.bun/bin:$PATH make test &1 | tail -1 + EXPECT: all suites green + EVIDENCE: MET exit=0 marker-found :: all suites green +5. Manual: the table carries no repo name, slug, path or prompt text (callers are agent types or the two fixed labels, models are id-shaped); rows are deduped by message.id; an unreadable transcript is skipped, a failure of the whole section never fails `apply`; new code within the global limits (25 logic lines/function, 80 cols, 5 params, 5 locals). + +6. The retention note prints only when its cut day is later than the heading's start day (advisor.test.ts test 13 covers a 7-day-plus-hours window with no note), and SKILL.md's data line names the advisor counts. + CHECK: cd /home/bchanot/Documents/claude/lib/memory-feedback && PATH=$HOME/.bun/bin:$PATH bun -e 'import {renderAdvisor} from "./advisor.ts"; const D=86400000, to=Date.UTC(2026,10,19,17); const t={uses:[],unparsed:0,files:1}; const wk=renderAdvisor(t,to-7*D-5*3600000,to), two=renderAdvisor(t,to-14*D,to); console.log(!wk.includes("Transcripts kept")&&two.includes("calls before 2026-11-12 may be missing.")?"RET-OK":"bad")' | grep -qF RET-OK && grep -qF 'advisor call counts' /home/bchanot/Documents/claude/skills/memory-feedback/SKILL.md && echo RET-OK + EXPECT: RET-OK + EVIDENCE: MET exit=0 marker-found :: RET-OK + +## FILE SCOPE +lib/memory-feedback/advisor.ts (new), lib/memory-feedback/advisor.test.ts (new), lib/memory-feedback/reader.ts, lib/memory-feedback/reader.test.ts, skills/memory-feedback/SKILL.md diff --git a/.claude/tasks/plans/2026-11-19-advisor-usage-1625.md b/.claude/tasks/plans/2026-11-19-advisor-usage-1625.md new file mode 100644 index 0000000..e2cb123 --- /dev/null +++ b/.claude/tasks/plans/2026-11-19-advisor-usage-1625.md @@ -0,0 +1,178 @@ +# Feat plan: advisor usage section in /memory-feedback (Run C, TODO:18) + +## Why +LRN-295 measured advisor use by hand (per caller, model, uncached input) and named Run C to +automate it. User choices 2026-11-19 [gated]: a section of FEEDBACK.md written by `reader.ts +apply`; sub-agents per agent type; all projects summed, no repo in the table; window = since +the last run; a retention note when the window exceeds 7 days; a shape-drift line in place of +a false zero. + +## Disposition +- honors LRN-295 (the method), with one correction: a call = one served advisor iteration, i.e. + one `message.usage.iterations[]` entry with `type == "advisor_message"` (model from that entry's + `model`, tokens = its `input_tokens`). A `server_tool_use` block named `advisor` with no + iteration is NOT a call: on real transcripts 147 blocks vs 141 iterations; the 6 gaps are + requests that never ran (re-issued next message) or an `advisor_tool_result_error`. Usage rows + repeat once per content block → dedupe by `message.id`. +- probe 2026-11-19 over all 1095 transcripts (136 calls then): 0 advisor iterations with + cache_read/cache_creation tokens, so `input_tokens` is the whole input; rows sharing an id + always carry identical advisor iterations, so first-seen is exact; no `isSidechain` row in a + main transcript; no advisor row outside the two path shapes; every meta `agentType` today is a + global or built-in agent name (general-purpose, plan-challenger, verifier, …). +- honors LRN-267: only `type == "assistant"` records count (blob replays and tool results never + do); sub-agent transcripts = `/subagents/agent-.jsonl`, meta beside it + (`agent-.meta.json`, field `agentType`). +- honors BDR-140: FEEDBACK.md stays local (~/.claude/memory-feedback, never git); the section + adds no repo name, slug, path or prompt text: callers are validated agent type strings or two + fixed labels, models validated id strings. A project-scoped agent's own name would appear + verbatim (none exists today). +- honors BDR-100: thresholds.ts untouched; no new gate. +- global code limits (our code): ≤ 25 logic lines/function, ≤ 80 cols, ≤ 5 params, ≤ 5 locals + (a destructured name counts as a local). Unexported helpers are allowed and expected; the + exported names below are final. + +## Files +1. lib/memory-feedback/advisor.ts (new) +2. lib/memory-feedback/advisor.test.ts (new) +3. lib/memory-feedback/reader.ts — `commit()` appends the section +4. lib/memory-feedback/reader.test.ts — the apply test asserts the section +5. skills/memory-feedback/SKILL.md — STEP 5 shows it + +## advisor.ts — exported API (names final) +```ts +// lib/memory-feedback/advisor.ts: advisor usage read from Claude Code +// transcripts (Run C, LRN-295): served calls and input tokens per caller +// and model, deduped by message.id, for the FEEDBACK.md section. +export type Use = { caller: string; model: string; calls: number; input: number } +export type Tally = { uses: Use[]; unparsed: number; files: number } +export type Source = { file: string; caller: string } +export const MAIN = 'main loop' +export const UNKNOWN_AGENT = 'sub-agent (unknown)' +export const RETENTION_DAYS = 7 +export function transcriptsOf(projects: string, from: number): Source[] +export function callerOf(jsonl: string): string +export function advisorUsage(projects: string, from: number, to: number): Tally +export function compact(n: number): string +export function renderAdvisor(t: Tally, from: number, to: number): string +export function advisorSection(projects: string, from: number, to: number): string +``` +Suggested private split (names free): a directory lister that never throws, a per-file line +reader that returns the counted records, a tally step for one record, the sort comparator. + +Behaviour: +- `transcriptsOf`: every directory read is wrapped (`readdirSync`/`lstatSync` in a try; an + unreadable or vanished directory or file is skipped, never thrown). `projects` missing → `[]`. + For each entry of `projects` that is a real directory (`lstat`, symlinks skipped): every + regular `*.jsonl` file directly inside → caller `MAIN`; for each real sub-directory ``, + its `subagents` entry when it is a real directory (lstat), every regular `agent-*.jsonl` inside + → caller `callerOf(file)`. A file whose `mtimeMs <= from` is skipped (a small saving: it can + hold no row in the window; the substring pre-filter below is what keeps the scan cheap). +- `callerOf`: lstats the sibling `.meta.json` first: not a regular file + (symlink, FIFO, dir) or larger than 64 KiB → `UNKNOWN_AGENT`; else reads it; its `agentType` when a string + matching `/^[A-Za-z0-9_.:-]{1,64}$/`, else `UNKNOWN_AGENT` (missing file, unparsable JSON, + non-object, bad type: never throws). +- `advisorUsage`: one `seen: Set` of message ids across all files, one tally + `Map` keyed `caller + '\t' + model`, one `unparsed` counter, `files` = the number + of sources `transcriptsOf` returned. Per source file + (read in a try: an unreadable file is skipped): split lines; a line is parsed only when it + contains `advisor_message` (pre-filter); JSON errors and non-objects skipped. A record is + considered when `type === 'assistant'`, `Date.parse(timestamp)` is in `(from, to]`, and + `message.id` is a non-empty string not yet in `seen` (then added). For each element of + `message.usage.iterations` (array, else none) with `type === 'advisor_message'`: model = its + `model` when a string matching `/^[A-Za-z0-9._:-]{1,80}$/`, else `'unknown'`; calls += 1; + input += `input_tokens` when a non-negative safe integer, else 0. A considered record whose + `JSON.stringify(message.usage ?? null)` contains `advisor_message` but which yielded no call + → `unparsed += 1` (shape drift; text that merely mentions the word is not in `usage`). + `uses` sorted: `MAIN` first, then calls descending, then caller, then model ascending. +- `compact(n)`: `n < 1000` → `String(n)`; `n < 999950` → `(n / 1e3).toFixed(1) + 'k'`; else + `(n / 1e6).toFixed(1) + 'M'` (so `999950` prints `1.0M`, never `1000.0k`). +- `renderAdvisor(t, from, to)`: lines, joined with `\n`, ending with `\n`: + 1. `## Advisor usage ( → )`, `` = `all on disk` when `from === 0`, else the + UTC day `YYYY-MM-DD` (`new Date(ms).toISOString().slice(0, 10)`, as metrics.ts `day`); + `` = that day of `to`. + 2. blank line. + 3. only when `from > 0` and `to - from > RETENTION_DAYS * 86400000`: the line + `Transcripts kept 7 d: calls before may be missing.` then a blank line. + 4. body: when `t.uses` is empty: `t.files === 0` → `No transcript modified since + under the projects dir: check the path.` (`` as in the heading); else `t.unparsed > 0` + → the drift line ` transcript lines mention advisor_message, none parsed: check + the transcript shape.`; else `No advisor call in the window.`. Otherwise the table, + followed (blank line between) by the same drift line when `t.unparsed > 0`: + ``` + | caller | model | calls | input tok | + |---|---|---|---| + | main loop | claude-fable-5-2 | 14 | 3.4M | + | total | | 41 | 5.1M | + ``` + (`input tok` via `compact`; the total row sums calls and input). +- `advisorSection(projects, from, to)`: first normalises `from` (outside the try, pure + arithmetic): a finite number in `[0, to]`, else `0` (state.json is hand-editable: `1e999`, + `1e17` or `NaN` must not reach `toISOString`). Then `renderAdvisor(advisorUsage(projects, f, + to), f, to)` in a try; on any throw returns `## Advisor usage ( → )` (same dates), a blank + line and `Unavailable: transcripts unreadable.` (fixed text: an error message could carry a + path), ending with `\n`. Never throws. + +## reader.ts +`commit()` gains no local (it has 5: `fresh, m, v, next, feedback`): the section call reads the +old `lastRun` inline, before any write: +```ts + const feedback = renderFeedback(m, v, now) + '\n' + + advisorSection(p.projects, readState(stateOf(p)).lastRun, now) +``` +(import `advisorSection` from `./advisor.ts`). The order stays as today: the scan runs while +`feedback` is built, before `appendRows`/`writeState`/`writeSafe`; a throw inside is caught by +`advisorSection`; a kill during the scan leaves nothing written, so a rerun is clean. The +section goes into FEEDBACK.md and the printed output (NEW lines still follow it). + +## SKILL.md STEP 5 +The sentence "It prints FEEDBACK.md: show the gate lines (`Post-fix prompt asks: k/20` included: +actions wait for 20 post-fix asks) and the Actions list to the user." becomes "It prints +FEEDBACK.md: show the gate lines (`Post-fix prompt asks: k/20` included: actions wait for 20 +post-fix asks), the Actions list and the `## Advisor usage` table (advisor calls since the last +run per caller and served model) to the user." Wrapped ≤ 80 cols like the file, with the +backticked span `` `## Advisor usage` `` kept whole on one line (contract CHECK 3 greps it). + +## Tests +advisor.test.ts (bun:test, fixtures in `fs.mkdtempSync(path.join(os.tmpdir(), 'mf-adv-'))`, +removed in afterAll, like reader.test.ts): +1. main transcript: two assistant rows sharing one `message.id`, one advisor iteration + (model claude-fable-5-2, input_tokens 1500) → one `main loop` row, calls 1, input 1500. +2. a row outside the window (timestamp ≤ from) and one after `to` → not counted. +3. a `user` record and a torn line, both containing `advisor_message` → ignored. +4. one message with two advisor iterations → calls 2. +5. iteration without `model` → model `unknown`. +6. sub-agent `agent-a1.jsonl` + meta `{"agentType":"verifier"}` → caller `verifier`; + `agent-a2.jsonl` without meta and `agent-a3.jsonl` with `agentType: "../x"` → + `sub-agent (unknown)`. +7. a transcript whose mtime ≤ from (`fs.utimesSync`) → skipped even with in-window rows. +8. missing projects dir → `{ uses: [], unparsed: 0, files: 0 }`; `advisorSection` on it → + heading + the `No transcript modified since … check the path.` line; a projects dir with one + in-window transcript holding no advisor row → `No advisor call in the window.` +9. render: `from 0` → `all on disk`; `compact` 999 → `999`, 1500 → `1.5k`, 999950 → `1.0M`, + 2500000 → `2.5M`; total row sums calls and input; sort order (main loop first, then calls + desc). +10. the rendered section never contains the fixture's project slug or its path. +11. a message with a `server_tool_use` block named `advisor` and no `advisor_message` iteration + (and no usage mention) → 0 calls, `unparsed` 0. +12. shape drift: an in-window assistant record whose `usage` holds `advisor_message` in a shape + the reader does not parse (e.g. `usage.advisor_message: {...}` with no `iterations`) → + `unparsed` 1, and the render prints the `none parsed` line instead of the plain zero. +13. retention: `from = to - 10 d` → the `Transcripts kept 7 d: calls before may be + missing.` line; `from = to - 3 d` and `from = 0` → no such line. +14. an unreadable sub-directory (`chmod 000` on a fixture dir, mode restored in a try/finally + inside the test itself; skip the assertion when running as root) → still returns the other + files' calls, no throw. +15. `advisorSection` with `from = Infinity`, `from = 1e17` and `from = NaN` → heading `all on + disk`, never throws. +16. drift under a table: one parsed call plus one drift record → the table, then the drift line. +17. `callerOf` with a meta that is a symlink (to a valid meta elsewhere) → `sub-agent (unknown)`. +reader.test.ts: the existing apply test (or one new apply test on the same fixture) asserts the +output and FEEDBACK.md contain `## Advisor usage`. + +## Edge cases +- `from` = state.lastRun = 0 on a first run → everything still on disk, heading `all on disk`. +- Huge files (largest 63 MB, 1.1 GB total): substring pre-filter before `JSON.parse`. +- A message id seen in two files (never seen in the probe) counts once. + +RISK: low — read-only reporting added after the existing FEEDBACK body; the labelling path and +its write order are unchanged.