Skip to content

feat(codex): discover --codex + AGENTS.md gap patterns + proxy nudge (#53) - #54

Merged
thehoff merged 2 commits into
developfrom
feat/codex-compliance-gap-53
May 18, 2026
Merged

thehoff merged 2 commits into
developfrom
feat/codex-compliance-gap-53

Conversation

@thehoff

@thehoff thehoff commented May 18, 2026

Copy link
Copy Markdown
Owner

Summary

Three-part attack on the codex 84.3% → 95%+ compliance gap measured post-v0.1.8.

  1. contextcrawler discover --codex — scans ~/.claude/plugins/data/codex-openai-codex/state/*/jobs/*.log, reports wrapped/total %, canonicalised gap patterns, top raw examples. Matches my hand-count to 1 command.
  2. AGENTS.md WRONG/RIGHT additions in hooks/codex/rtk-awareness.md for the 3 measured gap patterns: git -C <dir>, rg -n, nl -ba … | sed -n.
  3. Proxy bypass nudge — when 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 proxy became the new #1 token 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 from two angles.

Pre-PR review fixes (commit a76e40b)

Pre-merge code review caught 4 must-fix items, all addressed:

  • Critical: canonicalise_pattern case-folded git -c <key=val> into the git -C <dir> bucket. CI scripts using git -c core.X=Y were being mis-attributed. Now case-sensitive + distinct bucket for -c <key=val>.
  • Important: truncate_for_display byte-index slice could panic on multibyte UTF-8 paths. Now uses char_indices().nth(MAX).
  • Important: nudge comment claimed CI/non-tty suppression that wasn't implemented. Now extracted should_emit_proxy_nudge() with all three knobs (CONTEXTCRAWLER_NO_PROXY_NUDGE, CI, IsTerminal).
  • Important: is_wrapped "; " connector required trailing space; pwd;contextcrawler ls falsely reported as wrapped. Fixed connector list + first-word extraction.
  • Coverage gap: new tests/proxy_nudge.rs integration suite proves the env→nudge→suppression integration path (was only verified manually before).

Pinning tests added

  • test_codex_template_pins_gap_patterns — fails if git -C, rg -n, or nl -ba disappears from the codex template
  • test_proxy_wrapped_equivalent_known_tools — sanity coverage
  • test_proxy_wrapped_equivalent_message_does_not_recurse — catches the "contextcrawler contextcrawler" template bug
  • canonicalise_git_lowercase_c_is_separate_bucket — pins the -C vs -c distinction
  • truncate_for_display_handles_multibyte — pins the UTF-8 fix
  • is_wrapped_handles_tightly_packed_semicolons — pins the connector fix

Verified

  • cargo build clean
  • cargo test --bin contextcrawler — 2137 pass, 0 fail
  • All 8 integration suites green (branding_lint, git_hardening, cargo_hardening, node_hardening, runtime_hardening, cloud_hardening, harness_standalone, new proxy_nudge)
  • Empirical: discover --codex --since 2 returns 84.3% compliance matching hand-count

Success criteria (post-merge)

After deploy + 24h codex use, re-run contextcrawler discover --codex and confirm ≥95% compliance (target +10.7pp from 84.3%). Re-check proxy row in the dashboard for absolute token-leak shrink.

Deferred (separate follow-ups)

  • contextcrawler read --range A,B[;C,D] to fully replace nl|sed composed pipes (codex sometimes composes multi-range selectors — non-trivial)
  • Auto-rewrite (vs. nudge-only) for proxy-wraps-wrapped-tool — unlock once nudge adoption is measured

Closes #53 (partial).

thehoff added 2 commits May 18, 2026 20:31
…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>`)
@thehoff
thehoff merged commit 624042b into develop May 18, 2026
3 checks passed
@thehoff
thehoff deleted the feat/codex-compliance-gap-53 branch May 18, 2026 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(codex): close 84%→95%+ compliance gap (nl|sed, git -C, rg -n) + proxy bypass nudge + discover --codex meter

1 participant