Skip to content

fix(discover): exclude hook-rewritten commands from missed savings (#1055)#1195

Open
ousamabenyounes wants to merge 1 commit into
rtk-ai:developfrom
ousamabenyounes:fix/issue-1055
Open

fix(discover): exclude hook-rewritten commands from missed savings (#1055)#1195
ousamabenyounes wants to merge 1 commit into
rtk-ai:developfrom
ousamabenyounes:fix/issue-1055

Conversation

@ousamabenyounes
Copy link
Copy Markdown
Contributor

@ousamabenyounes ousamabenyounes commented Apr 10, 2026

Summary

Fixes #1055

  • When the Ora Studio PreToolUse hook is active, rtk discover was reporting hook-rewritten commands (e.g. git diff, cargo test) as "missed savings" — even though the hook was already rewriting them to rtk git diff, rtk cargo test, etc.
  • Root cause: the JSONL session log records the pre-rewrite command; discover saw git diff and classified it as Supported (missed).
  • Fix: before the scan loop, detect hook status via hook_check::status(); when active, test each Supported command with rewrite_command(). If the hook would rewrite it, count it as hook_rewritten (excluded from missed-savings) and show a Hook-handled: N commands line in the output.

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test
  • 4 new tests: test_supported_git_commands_are_rewriteable_by_hook, test_supported_cargo_commands_are_rewriteable_by_hook, test_hook_rewritten_count_shown_when_nonzero, test_hook_rewritten_count_hidden_when_zero
  • 1377 pass, 0 regressions (baseline: 1373)
  • Manual: rtk discover output now shows "Hook-handled: N commands" instead of listing them as missed savings when the hook is installed

Files changed

File Change
src/discover/mod.rs detect hook status; route hook-rewritten commands to new counter
src/discover/report.rs add hook_rewritten_count/hook_rewritten_tokens to DiscoverReport; show in text output
src/discover/registry.rs 2 regression tests verifying rewriteable-by-hook invariant
CHANGELOG.md entry under [Unreleased]

Generated by Ora Studio
Vibe coded by ousamabenyounes


Vibe Coded by Ousama Ben Younes
Developed With Ora Studio (Claude Code)

@pszymkowiak pszymkowiak added bug Something isn't working effort-medium 1-2 jours, quelques fichiers filter-quality Filter produces incorrect/truncated signal labels Apr 10, 2026
@pszymkowiak
Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes the discover command incorrectly reporting hook-rewritten commands (e.g. git diff, cargo test) as 'missed savings' when the Claude Code PreToolUse hook is active. The fix detects hook status before scanning, routes hook-handled commands to a separate counter, and displays them as 'Hook-handled' in output. Also fixes git log --format output truncation that was corrupting programmatic output like SHAs.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #1055


Analyzed automatically by wshm · This is an automated analysis, not a human review.

…tk-ai#1055)

When the Claude Code PreToolUse hook (rtk-rewrite.sh) is active, it
silently rewrites commands like `git diff` → `rtk git diff` before
execution. The JSONL session log records the original command, so
`rtk discover` classified all these as "missed savings" — even though
the hook was already handling them.

Fix: before the scan loop, detect hook status via hook_check::status().
When the hook is active, each Supported command is tested against
rewrite_command(); if it would be rewritten, it is counted in a new
hook_rewritten_count bucket instead of the missed-savings bucket. The
report now shows a "Hook-handled: N commands" line so users understand
the hook is doing its job.

Generated by Claude Code
Vibe coded by ousamabenyounes

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working effort-medium 1-2 jours, quelques fichiers filter-quality Filter produces incorrect/truncated signal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants