Repository navigation
Description
Symptom
`contextcrawler discover` reports large "missed savings" for commands that the PreToolUse hook is in fact rewriting at runtime.
Example (current local data, 30d window):
| Reported as missed | Live hook test |
|---|---|
| `grep -n` × 227 | rewrites to `contextcrawler grep -n …` |
| `git add` × 343 | rewrites to `contextcrawler git add …` |
| `cat /private/tmp/...` × 62 | rewrites to `contextcrawler read …` |
| `gh pr` × 49 | rewrites to `contextcrawler gh pr …` |
| `cargo test` × 104 | rewrites to `contextcrawler cargo test` |
| `ls -la` × 51 | rewrites to `contextcrawler ls -la` |
| `CONTEXTZIP_DISABLED=1 curl …` × 2 | rewrites to `CONTEXTZIP_DISABLED=1 contextcrawler curl …` |
Root cause
`src/discover/provider.rs:204` reads `/input/command` from each `tool_use` block. Claude Code's PreToolUse hook returns an `updatedInput.command` but the JSONL log still records the original command Claude attempted — so discover sees the un-rewritten text and concludes it was a miss.
Impact
The "MISSED SAVINGS" table is the headline output of `discover`. As written, it conflates:
- genuine misses (commands the hook can't rewrite — e.g. discover: MISSED SAVINGS is structurally misleading — reads pre-hook command #82 env-prefix, /usr/bin/env <cmd> not classified or rewritten (130 calls/30d) #83 git-subcommand gap)
- successful rewrites that simply look like the original command in the transcript
Operators reading this output draw the wrong conclusion ("the hook is broken") and waste time chasing ghosts.
Proposed fix
Two options, can be combined:
-
Reconcile against runtime tracking DB. `core::tracking` records every executed `contextcrawler` command with a timestamp. For each `tool_use` in the JSONL, look up the matching execution (same minute, same tail-arguments). If found → mark as "already RTK". If not → genuine miss.
-
Mark hook installed → discount the section. If `hooks::hook_check` reports the hook is healthy globally, add a banner above MISSED SAVINGS clarifying that anything appearing here either (a) ran before the hook was installed, (b) ran in a subagent/Codex session without the hook, or (c) is a true classifier miss (cross-reference discover: MISSED SAVINGS is structurally misleading — reads pre-hook command #82, /usr/bin/env <cmd> not classified or rewritten (130 calls/30d) #83).
Preferred: option 1 (real data) with option 2 as fallback banner when the DB has no overlapping window.
Acceptance
- New `discover` integration test: install hook, run `git status` through the simulated Claude flow, dump JSONL, run `discover` → should report it as already-RTK, not a miss.
- Existing "MISSED SAVINGS" line stays but only for commands without a matching execution in the tracking DB.
Activity
merge: F discover-reconcile (#82)
fix(discover): reconcile JSONL tool_uses against runtime tracking DB (t…