Repository navigation
chore(cleanup): delete 6 orphan modules + wire legacy hook constants (zero cargo warnings) - #64
Merged
Merged
Conversation
…+ annotate scaffolding `cargo build` was emitting 80+ unused-* warnings, drowning real signal from genuine new dead-code introductions (e.g. PR #58 unused imports went unnoticed for a session). Zero-warning cargo build is the baseline. ## Orphan files deleted (-2953 lines) Audited as fully unreferenced (zero external `use crate::...::X` paths outside the file itself); confirmed by checking that all module-level items are unused in production and the deleted .rs files have no external test depending on their public API. - `src/analytics/security_cmd.rs` (617 lines) -- superseded by `src/hooks/tirith_gate.rs::run_security_dashboard` which backs the current `contextcrawler security` subcommand - `src/analytics/jsonl_rewriter.rs` (557 lines) - `src/analytics/session_compact_cmd.rs` (292 lines) -- session-compact feature inherited from the contextzip merge that never got wired - `src/analytics/ansi_filter.rs` (198 lines) -- only used by the jsonl_rewriter above - `src/cmds/cloud/web_cmd.rs` (472 lines) -- contextzip HTML extractor that was never wired through clap; `cmds/cloud/mod.rs` uses `automod::dir!` so the file got auto-imported as a module without a call site - `src/core/error_cmd.rs` (817 lines) -- language-specific stack-trace compactors that also never got wired Also dropped from mod.rs: - `src/analytics/mod.rs` -- 4 `pub mod` lines - `src/core/mod.rs` -- `pub mod error_cmd;` line ## Legacy hook constants WIRED (instead of deleted) `LEGACY_CLAUDE_HOOK_COMMAND` and `LEGACY_CURSOR_HOOK_COMMAND` were defined as constants but only ever referenced as literal strings elsewhere. Wiring them properly closes two latent bugs: - `src/hooks/integrity.rs::run_verify`: only checked the legacy literal "rtk hook claude" in `settings.json`. Freshly-installed users running the current `CLAUDE_HOOK_COMMAND` ("contextcrawler hook claude") saw "hook not installed" even after a successful `contextcrawler init -g`. Fixed: accept either current or legacy. - `src/hooks/init.rs` cursor hook detection (line 3083 + 3258): only matched the current command. Legacy installs got missed by the skip-install detector AND the uninstall remover. Fixed: accept both. ## Intentional scaffolding annotated #[allow(dead_code)] These are future-wired structures that earn their warnings by design. Annotating with intent so the next reader knows they're not orphans: - `core::utils::ToolPolicy` + `secure_command_with_policy` + `check_args_with_policy` + `policy_deny_message` -- the worked refactor target documented in the module header. Per-tool helpers will migrate onto it. - `main::web_ssrf_block_reason` -- IP classification helper from the deleted web_cmd.rs. Preserved for future SSRF wiring of curl/wget filter or a Rust HTTP client; the classification logic is the expensive part to re-derive. - `cmds::git::git::filter_branch_output` -- back-compat wrapper kept for the back-compat test surface (production switched to filter_branch_output_with_mode in #56). - `cmds::system::grep_cmd::has_format_flag_raw` -- OsString-typed sibling of the existing String-typed helper; one helper per arg-type so callers don't need to allocate. ## Unused imports removed - `src/cmds/js/lint_cmd.rs` -- `resolved_command` (replaced by `secure_python_command` / `package_manager_exec` earlier this session) - `src/cmds/system/grep_cmd.rs` -- `resolved_command` moved under `#[cfg(test)]` (production uses `secure_rg_command`, tests use the raw baseline) ## Verified - cargo build clean: **0 warnings** (was 80+) - cargo test --bin contextcrawler: 2116 pass / 0 fail (was 2156; delta is the ~40 tests inside the deleted orphan files) - All 9 integration suites green No production behaviour changes apart from the two latent-bug fixes (integrity check + cursor hook detection) which are pure improvements.
This was referenced May 18, 2026
noogalabs
pushed a commit
to noogalabs/contextcrawler
that referenced
this pull request
Jun 4, 2026
…contextcrawler X` (thehoff#62) The Claude Code hook (`hooks/claude/rtk-rewrite.sh`) shells out to `contextcrawler rewrite "$CMD"` and substitutes the result into Claude Code's `updatedInput.command`. Pre-fix this returned `rtk git status` (legacy prefix). Claude Code then attempted to exec `rtk git status` literally, which fails with "rtk: command not found" on any system where the binary is installed as `contextcrawler` (i.e. every system). The bug stayed hidden in the current session because most of the traffic flows via codex (which uses `contextcrawler X` directly per the AGENTS.md template) rather than the Claude Code rewrite path. Any user with raw-command Claude usage + this hook would have hit "command not found" on every rewrite. ## Empirical confirmation (pre-fix) ``` $ echo '{"tool_input":{"command":"git status"}}' | bash hooks/claude/rtk-rewrite.sh {"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow", "permissionDecisionReason":"ContextCrawler auto-rewrite", "updatedInput":{"command":"rtk git status"}}} $ which rtk rtk not found ``` ## Empirical confirmation (post-fix) ``` $ echo '{"tool_input":{"command":"git status"}}' | bash hooks/claude/rtk-rewrite.sh {... "updatedInput":{"command":"contextcrawler git status"}}} ``` ## Scope of changes 1. **73 RULES `rtk_cmd:` values** in `src/discover/rules.rs` rebranded from `"rtk X"` to `"contextcrawler X"`. 2. **5 inline `format!("rtk ...")` builders** in `src/discover/registry.rs` (head/tail/golangci/pnpm/npm cases). 3. **`classify_command`** now treats `contextcrawler X`-prefixed input as already-wrapped (added `"contextcrawler "` to IGNORED_PREFIXES). The legacy `"rtk "` entry stays for backcompat with historical hook captures. 4. **`rewrite_segment_inner` + `rewrite_command`** prefix-detect checks accept BOTH `contextcrawler ` and `rtk ` for backcompat. 5. **54 `format!("rtk ...")` tracking labels** across 17 cmd modules migrated to `format!("contextcrawler ...")`. 6. **53 plain-literal `"rtk X"` tracking labels** across 19 files migrated to `"contextcrawler X"`. 7. **2 inline log/track strings** in main.rs (`"rtk:toml ..."`, `"rtk grep (format-flag passthrough...)"`). 8. **`src/hooks/init.rs::show_claude_config`** + `show_cursor_config` hook-content detection: accept both legacy `rtk rewrite` and current `contextcrawler rewrite` markers, and both `command -v rtk` / `command -v contextcrawler` guards. 9. **`src/analytics/gain.rs::display_cmd`**: strips BOTH prefixes so historical `rtk X` rows + new `contextcrawler X` rows bucket together in the dashboard. ## What stays `rtk` (deliberate) - `LEGACY_CLAUDE_HOOK_COMMAND = "rtk hook claude"` / cursor — the legacy-detection constants wired in PR thehoff#64. - `IGNORED_PREFIXES` includes both `"rtk "` and `"contextcrawler "` so the rewriter doesn't double-wrap either form. - `RtkRule` / `RtkStatus` / `rtk_cmd` field names and the SQLite `rtk_cmd` column NAME — internal identifiers, not user-visible values. - `// branding-lint: allow legacy` markers retained where present. ## Migration / tracking-label transition `gain.rs::display_cmd` now strips both `"rtk "` and `"contextcrawler "` prefixes at display time. Historical rows in `~/Library/Application Support/rtk/history.db` continue to bucket correctly with new rows in the dashboard. No data migration required. ## Test churn ~180 test assertion strings rebranded across registry.rs + hook_cmd.rs test mods. All done via scoped Python replacement inside each file's `#[cfg(test)]` block to avoid touching production literals. ## Verified - cargo build clean: 0 warnings - cargo test --bin contextcrawler: 2119 pass / 0 fail - All 10 integration suites green - Empirical end-to-end: - `contextcrawler rewrite "git status"` -> `contextcrawler git status` - hook returns `{"updatedInput":{"command":"contextcrawler git status"}}` - `contextcrawler rewrite "rtk git status"` -> `rtk git status` (backcompat: legacy already-wrapped input passes through) - `contextcrawler rewrite "contextcrawler git status"` -> `contextcrawler git status` (new already-wrapped passes through) - `contextcrawler rewrite "htop"` -> empty + exit 1 (unsupported unchanged) - dashboard shows unified per-command rows (no rtk/contextcrawler duplicates) Closes thehoff#62.
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
cargo buildwas emitting 80+ unused- warnings*, drowning real signal — PR #58's unused-import leaks went unnoticed for a session because of the noise floor. Zero-warning build is the baseline.What this PR does
Deletes 6 orphan files (-2953 lines)
Audited as fully unreferenced — no external
use crate::...::Xpaths, no test dependencies outside the file itself.src/analytics/security_cmd.rs(617L) — superseded byhooks/tirith_gate.rs::run_security_dashboardwhich backs currentcontextcrawler securitysrc/analytics/jsonl_rewriter.rs(557L)src/analytics/session_compact_cmd.rs(292L)src/analytics/ansi_filter.rs(198L) — only consumer was jsonl_rewritersrc/cmds/cloud/web_cmd.rs(472L) —cmds/cloud/mod.rsusesautomod::dir!so the orphan got auto-modded without a call sitesrc/core/error_cmd.rs(817L) — never wiredAlso drops 4
pub modlines fromsrc/analytics/mod.rs+ 1 fromsrc/core/mod.rs.Wires
LEGACY_*_HOOK_COMMANDconstants (closes 2 latent bugs)The legacy hook constants were defined but never referenced — meanwhile the legacy-detection sites used string literals that only matched the OLD command:
hooks/integrity.rs::run_verify— was hardcoded to only detect the legacy"rtk hook claude". Freshly-installed users running currentcontextcrawler hook claudesaw "hook not installed" even after a successfulinit -g. Now accepts either.hooks/init.rscursor hook detection (line 3083 + 3258) — only matched current command, missed legacy installs on uninstall + skip-install paths. Now accepts both.Annotates intentional scaffolding
#[allow(dead_code)]Earnable warnings for future-wired structures, with comment explaining intent:
ToolPolicy+secure_command_with_policy+check_args_with_policy+policy_deny_message— the refactor target documented in the module headerweb_ssrf_block_reason— preserved for future SSRF wiring; the IP classification is the expensive part to re-derivefilter_branch_output— back-compat wrapper for the test surface (production switched to_with_modein perf(git): branch -r + log --no-merges + show blob filter (#55) — 3 leaks fixed #56)has_format_flag_raw— OsString-typed sibling, one helper per arg-typeRemoves 2 unused imports
src/cmds/js/lint_cmd.rs—resolved_command(PR harden(gh/glab/gt): zero-trust env strip + arg deny + passthrough fix (#50) #58 churn)src/cmds/system/grep_cmd.rs—resolved_commandmoved to#[cfg(test)]onlyVerified
cargo buildclean: 0 warnings (was 80+)cargo test --bin contextcrawler— 2116 pass / 0 fail (was 2156; delta is the ~40 tests inside the deleted orphan files testing the deleted orphan functions — no production coverage loss)No production behaviour changes apart from the 2 latent-bug fixes (integrity check + cursor hook detection) which are pure improvements — both genuinely close user-visible bugs from the dashboard's perspective.