Repository navigation
fix(hook): emit contextcrawler as rewrite prefix; finish rtk rebrand on UI strings - #1
Merged
Merged
Conversation
The v0.1.0–v0.1.2 rename missed three load-bearing emit codepaths, so
freshly-installed users still saw `rtk` as the rewrite prefix in hook
output (which then failed on machines with only the new binary on PATH:
"command not found: rtk").
Reproduction before, on both macOS and Ubuntu:
$ echo '{"tool_name":"Bash","tool_input":{"command":"git status"}}' \
| contextcrawler hook claude
{"hookSpecificOutput":{"updatedInput":{"command":"rtk git status"},...}}
After:
{"hookSpecificOutput":{"updatedInput":{"command":"contextcrawler git status"},
"permissionDecision":"allow",...}}
Source changes:
* src/discover/registry.rs
- Add display_rtk() helper that swaps the internal `rtk ` prefix on
a rule's rtk_cmd for the user-facing `contextcrawler ` form.
Internal classification keeps using rtk_cmd literals to keep
upstream rebase friction minimal.
- Wrap the three emit sites (rule.rtk_cmd format!, golangci-lint
hardcoded literal, head/tail rewrite_line_range) so all rewrite
output flows through the helper.
- Extend the "already rewritten" passthrough checks at both compound
(rewrite_command) and segment (rewrite_segment_inner) levels to
accept either `rtk ` or `contextcrawler ` prefixes — preserves
backward compatibility for users who already have allowlisted
`rtk *` patterns in their Claude Code permissions.
* src/analytics/gain.rs
- Header `RTK Token Savings` -> `ContextCrawler Token Savings`
(Project and Global scopes).
- Empty-state hint: "Run some rtk commands..." -> "Run some
contextcrawler commands...".
* src/analytics/cc_economics.rs
- Same empty-state hint rewording.
Test changes:
* src/hooks/hook_cmd.rs
- Update existing assertions for the new prefix.
- Add explicit `contextcrawler git status` passthrough case alongside
the legacy `rtk` one in test_gemini_hook_uses_rewrite_command.
* src/discover/registry.rs test module
- Flip ~100 rewrite-output assertions from `rtk X` to `contextcrawler X`.
- Already-rewritten passthrough tests (test_rewrite_already_rtk,
test_rewrite_mixed_compound_partial) keep `rtk` on the input side
and verify both legacy and current prefixes pass through unchanged.
Verified end-to-end: rebuilt the release binary and exercised the hook
with the same JSON payload Claude Code sends; rewrite output is now
`contextcrawler git status` (simple) and `contextcrawler git add . &&
contextcrawler cargo test` (compound). `cargo test` is green (1784
passed / 0 failed / 6 ignored).
Internal `rtk` identifiers (struct/field/module names, rtk_cmd: rule
values, rtk_equivalent classification keys) are intentionally untouched
to keep upstream rebases against rtk-ai/rtk small.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced May 14, 2026
This was referenced May 14, 2026
Merged
thehoff
added a commit
that referenced
this pull request
May 25, 2026
First runner job revealed two unrelated issues: 1. `dtolnay/rust-toolchain@stable` fetched Rust 1.95.0, way ahead of the declared `rust-version = "1.80"` MSRV. Rust 1.95's clippy added new lints (doc_lazy_continuation, type_complexity tightening) plus an `incompatible_msrv` error for the existing `std::iter::repeat_n` usage (stable since 1.82). The lints firing on a clean codebase are toolchain drift, not bugs. 2. The clippy job ran with `-- -D warnings`, escalating every new advisory to a build failure. Combined with #1 above, the workflow was effectively unbuildable. Fix: pin the toolchain to `1.82` (newest version still aligned with the actual MSRV the code uses — `repeat_n` works) and drop `-D warnings` from clippy so warnings are visible but non-fatal. Re-tighten after a dedicated lint-cleanup pass lands. Also collapses the duplicate `with:` block in the clippy job that slipped in during the previous edit. The `cargo test` job exited 143 (SIGTERM) on the previous run — that was collateral from the workflow's job-failure cascade, not a real test failure. Re-run with the fixed clippy gate will tell us if the test job lands clean. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
noogalabs
pushed a commit
to noogalabs/contextcrawler
that referenced
this pull request
Jun 4, 2026
…hehoff#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 thehoff#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 thehoff#53 (partial — auto-rewrite + read --range deferred to follow-ups).
noogalabs
pushed a commit
to noogalabs/contextcrawler
that referenced
this pull request
Jun 4, 2026
`check_forbidden_pytest_args` only caught `-p VALUE` (space form) and only when `looks_like_path(value)` returned true. Two bypass classes: 1. **Bare-relative path** -- the shared looks_like_path requires `./`, `/`, `~/`, `.\`, or a drive letter. `subdir/plugin.py` had no leading marker and fell through. Pytest loads it as a file regardless. 2. **Glued -p forms** -- argparse accepts `-pVALUE` and `-p=VALUE` in addition to `-p VALUE`. The old `a == "-p"` exact match missed both. ## Fix New `pytest_p_value_is_filesystem_path` (pytest-specific, stricter than shared `looks_like_path`): - Anything `looks_like_path` catches - Any value containing `/` or `\` (closes bypass thehoff#1) - Any value ending in `.py` (a dotted module name never ends in `.py`) New `pytest_p_value(a, next)` helper recognises: - `-p VALUE` -- consumes next - `-pVALUE` (glued) - `-p=VALUE` (equals) ## Deny message now cites thehoff#49 (review P3) Pre-PR review caught that `pyrbjvm_deny_message` hardcodes `(issue thehoff#36)` (the umbrella). New `pyrbjvm_deny_message_with_issue(...)` variant lets the `-p` deny cite thehoff#49 directly so operators land on the right tracker entry. Other pyrbjvmdotnet denies continue to cite thehoff#36. ## Accepted residual risk (documented) `pytest -p evil.payload` resolves through Python's import system. When pytest is invoked as `python -m pytest`, `.` is on sys.path and the attacker can plant `evil/payload.py` in cwd. We can't reject dotted names categorically (`pytest_django.plugin` etc. are legitimate). Documented in `pytest_p_value_is_filesystem_path`'s doc-comment as accepted residual risk; remaining defense is the agent threat model. ## Pinning tests (4 new unit + 4 new integration) Unit (src/core/utils.rs): - pytest_rejects_p_bare_relative_path (the main thehoff#49 bypass) - pytest_rejects_p_glued_and_equals_forms (the -pVALUE / -p=VALUE pair) - pytest_p_deny_cites_issue_49 (P3 pin: -p cites thehoff#49, --rootdir thehoff#36) - pytest_allows_p_with_module_name (extended negative coverage incl. dotted module names + glued legitimate forms) Integration (tests/runtime_hardening.rs): - pytest_p_bare_relative_path_is_rejected (asserts thehoff#49 in stderr) - pytest_p_glued_form_is_rejected - pytest_p_bare_py_extension_is_rejected - pytest_p_legitimate_module_names_still_allowed Updated existing `pytest_minus_p_with_path_is_rejected` to assert thehoff#49. ## Verified - cargo build clean - cargo test --bin contextcrawler: 2156 pass, 0 fail - All 8 integration suites green (runtime_hardening 16 pass, was 12) Closes thehoff#49.
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
What changed
Design choice — minimal-diff post-process at emit boundary
I deliberately did not touch the ~40 `rtk_cmd: "rtk X"` entries in `src/discover/rules.rs` or other internal `rtk` identifiers (struct/field/module names, `rtk_equivalent` classification keys). Those are kept as-is so the upstream-rebase surface against `rtk-ai/rtk` stays minimal — per the existing downstream design notes about retaining source-level `rtk` identifiers for rebase friction.
Instead, a new `display_rtk()` helper is applied at the three emit sites that produce user-visible rewrite strings. `rule.rtk_cmd` stays `"rtk git"` internally; the helper swaps the prefix on the way out.
Backward compatibility
The "already rewritten" passthrough checks (both compound-level and segment-level) were extended to recognize both `rtk ` and `contextcrawler ` prefixes. Users who already have `Bash(rtk:*)` allowlist entries in their CC permissions will keep working; the legacy prefix is still a valid form of "already rewritten" and is returned unchanged.
`test_rewrite_already_rtk` and `test_rewrite_mixed_compound_partial` explicitly cover this.
Test plan
Out of scope for this PR (filed as follow-ups)
🤖 Generated with Claude Code