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
feat(intercept): richer find-usages in the Grep packet (ADR-0004)
The session bench showed the grep packet was a file list that contained the
investigated symbol ZERO times — high effective-P (low recall-sufficiency) that
caps the real saving. The handler now scans the resolved caller files at query
time (no graph/miner change) and returns the actual call-site lines
(file:line: code), deduplicated and capped, plus the rg -n escalation — so the
agent gets the usage context it grepped for and rarely re-greps.
An adversarial audit then caught that the naive version was a token REGRESSION
on most greps (bigger than a default filenames grep always; bigger than a
content grep for low-usage symbols, where ~50 tok of boilerplate dominates).
Two gates fix it so every interception that fires is a genuine win:
- output_mode === 'content' only (the default files_with_matches / count modes
return filenames / a number — cheaper than any packet → passthrough).
- callerFiles.length >= 4 (below that a content grep is small enough that the
packet would cost more → passthrough).
Measured on engram's own repo (content mode): init 573 vs 9,317 tok, parse 578
vs 2,152, getStore 531 vs 1,781 — all smaller; files-mode + low-usage → passthrough.
Also from the audit: word boundaries via lookarounds (so $-identifiers anchor),
and the cap note no longer claims a specific (wrong) omitted-file count. Caps:
15 caller files scanned, 25 lines, 140 chars/line, files > 1 MB skipped.
Best-effort, never throws; 0 call sites found (dynamic dispatch) → passthrough.
Audit: tsc clean; full suite 1100/1100 (+3 grep tests: call-site format, cap,
two gate passthroughs); e2e re-measured (content→smaller, files-mode→passthrough,
low-usage→passthrough); adversarial review SHIP-WITH-FIXES → all 3 fixes applied.
Leak-scan 0 hits.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
0 commit comments