Repository navigation
feat(codex): discover --codex + AGENTS.md gap patterns + proxy nudge (#53) - #54
Merged
Merged
Conversation
…53) Three-part attack on the codex 84.3%→95%+ compliance gap measured post-v0.1.8. ## What 1. **`contextcrawler discover --codex`** — new subcommand scanning `~/.claude/plugins/data/codex-openai-codex/state/*/jobs/*.log` for `Running command:` lines. Reports `wrapped / total` %, canonicalised gap patterns, and top raw examples. Reproduces the 84.3% hand-count exactly. `is_wrapped()` accepts: direct `contextcrawler ` prefix, `cd <dir> && contextcrawler ...` compositions, and standalone nav builtins. Documented limitation: a wrapped command piped into a raw filter is counted as wrapped (avoids mishandling quoted `|` inside `contextcrawler awk '$1|$2'`). 2. **AGENTS.md WRONG/RIGHT additions** in `hooks/codex/rtk-awareness.md` — explicit pairs for the 3 gap patterns: `git -C <dir>`, `rg -n`, `nl -ba … | sed -n`. Adds a follow-up sentence calling out that these look "different enough" that codex might not register them as wrappable. 3. **Proxy bypass nudge** — when `contextcrawler proxy <tool>` is invoked for a tool that HAS a wrapped equivalent (sed/nl/grep/awk/git/rg/etc.), emit a one-line stderr note pointing at the wrapped form. Suppressible via `CONTEXTCRAWLER_NO_PROXY_NUDGE=1`. Don't auto-rewrite yet — measure adoption first, upgrade in a follow-up if needed. ## Why now Post-v0.1.8 measurement: global savings jumped 24.8% → 70.6% in 24h, but `proxy` became the new #1 leak — 307K input @ 0% on 394 calls. Codex driving most of that volume with `proxy sed`/`proxy nl` for read-with-line-numbers. The nudge + template patterns hit the codex side of the same problem from two angles. ## Pinning tests - `test_codex_template_pins_gap_patterns` — fails if `git -C`, `rg -n`, or `nl -ba` disappears from the template - `test_proxy_wrapped_equivalent_known_tools` — sanity check per-tool coverage - `test_proxy_wrapped_equivalent_message_does_not_recurse` — catches the "contextcrawler contextcrawler read" bug from the first implementation draft - 15 new unit tests in `discover::codex` ## Verified - `cargo build` clean - `cargo test --bin contextcrawler` — 2134 pass, 0 fail - All 7 integration suites green - Empirical: `discover --codex` matches hand-count to 1 command - Empirical: nudge fires on `proxy sed`, suppressed via env, silent on `proxy whoami` ## Success criteria (post-merge) After deploy + 24h codex use, re-run `contextcrawler discover --codex` and confirm ≥95% compliance (lift target +10.7pp from 84.3%). Re-check `proxy` row in dashboard for absolute token-leak shrink. Closes #53 (partial — auto-rewrite + read --range deferred to follow-ups).
Pre-PR independent code review surfaced 4 must-fix items, all addressed. ## Critical - canonicalise_pattern: case-fold collapsed `git -c <key=val>` (config override) into the `git -C <dir>` gap bucket. Every CI script using `git -c core.X=Y` was being mis-attributed. Switched the `-C` / `-c` checks to the original-cased `trimmed`, added separate `git -c <key=val>` bucket so the two are reported distinctly. - Pinning test: `canonicalise_git_lowercase_c_is_separate_bucket` ## Important - truncate_for_display: byte-index slice across multibyte UTF-8 boundary panics. Switched to `char_indices().nth(MAX)`. Test: `truncate_for_display_handles_multibyte` exercises a Japanese path. - main.rs proxy nudge: comment claimed CI/non-tty suppression but code only checked env var. Extracted `should_emit_proxy_nudge()` with three independent silence conditions: 1. `CONTEXTCRAWLER_NO_PROXY_NUDGE=*` (explicit opt-out) 2. `CI=*` (pipeline marker) 3. stderr not a tty (script/pipe consumer) Also dropped the user-facing `(issue #53)` ref — internal-tracker noise, kept in the code comment instead. - is_wrapped: `"; "` connector required a trailing space, so `pwd;contextcrawler ls` (tightly packed) fell through to "standalone nav builtin" and falsely reported wrapped. Added bare `";"` to the connector list AND fixed first-word extraction to split on punctuation (was splitting on whitespace only, so `pwd;contextcrawler` was one token, missed the nav-builtin lookup). Tests: `is_wrapped_handles_tightly_packed_semicolons`. ## Integration coverage gap (reviewer-flagged) Unit tests only covered `proxy_wrapped_equivalent()` in isolation; the env→nudge→suppression integration path was only verified manually. New `tests/proxy_nudge.rs` integration suite (3 tests) proves: - `CONTEXTCRAWLER_NO_PROXY_NUDGE=1` silences the nudge - `CI=true` silences the nudge - non-tty stderr silences the nudge ## Empirical re-verification - All 2137 bin tests pass (was 2134; +3 new pinning tests) - All 8 integration suites green (was 7; new: proxy_nudge) - `discover --codex` still reports 84.3% compliance on real logs (post-fix, the gap_patterns are now cleanly distinct between `git -C` and `git -c <key=val>`)
This was referenced May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three-part attack on the codex 84.3% → 95%+ compliance gap measured post-v0.1.8.
contextcrawler discover --codex— scans~/.claude/plugins/data/codex-openai-codex/state/*/jobs/*.log, reportswrapped/total%, canonicalised gap patterns, top raw examples. Matches my hand-count to 1 command.hooks/codex/rtk-awareness.mdfor the 3 measured gap patterns:git -C <dir>,rg -n,nl -ba … | sed -n.contextcrawler proxy <wrapped-tool>is invoked, emit a one-line stderr nudge pointing at the wrapped equivalent. Three independent suppression knobs:CONTEXTCRAWLER_NO_PROXY_NUDGE=*,CI=*, non-tty stderr.Why now
24h post-v0.1.8 measurement: global savings 24.8% → 70.6% (+45.8pp), but
proxybecame the new #1 token leak — 307K input @ 0% on 394 calls. Codex driving most of that volume withproxy sed/proxy nlfor read-with-line-numbers. The nudge + template patterns hit the codex side from two angles.Pre-PR review fixes (commit
a76e40b)Pre-merge code review caught 4 must-fix items, all addressed:
canonicalise_patterncase-foldedgit -c <key=val>into thegit -C <dir>bucket. CI scripts usinggit -c core.X=Ywere being mis-attributed. Now case-sensitive + distinct bucket for-c <key=val>.truncate_for_displaybyte-index slice could panic on multibyte UTF-8 paths. Now useschar_indices().nth(MAX).should_emit_proxy_nudge()with all three knobs (CONTEXTCRAWLER_NO_PROXY_NUDGE,CI,IsTerminal).is_wrapped"; "connector required trailing space;pwd;contextcrawler lsfalsely reported as wrapped. Fixed connector list + first-word extraction.tests/proxy_nudge.rsintegration suite proves the env→nudge→suppression integration path (was only verified manually before).Pinning tests added
test_codex_template_pins_gap_patterns— fails ifgit -C,rg -n, ornl -badisappears from the codex templatetest_proxy_wrapped_equivalent_known_tools— sanity coveragetest_proxy_wrapped_equivalent_message_does_not_recurse— catches the "contextcrawler contextcrawler" template bugcanonicalise_git_lowercase_c_is_separate_bucket— pins the-Cvs-cdistinctiontruncate_for_display_handles_multibyte— pins the UTF-8 fixis_wrapped_handles_tightly_packed_semicolons— pins the connector fixVerified
cargo buildcleancargo test --bin contextcrawler— 2137 pass, 0 failbranding_lint,git_hardening,cargo_hardening,node_hardening,runtime_hardening,cloud_hardening,harness_standalone, newproxy_nudge)discover --codex --since 2returns 84.3% compliance matching hand-countSuccess criteria (post-merge)
After deploy + 24h codex use, re-run
contextcrawler discover --codexand confirm ≥95% compliance (target +10.7pp from 84.3%). Re-checkproxyrow in the dashboard for absolute token-leak shrink.Deferred (separate follow-ups)
contextcrawler read --range A,B[;C,D]to fully replacenl|sedcomposed pipes (codex sometimes composes multi-range selectors — non-trivial)Closes #53 (partial).