When RTK runs via Claude Code's PreToolUse hook, grep/rg subprocesses
inherit the hook's open stdin pipe. They block waiting for EOF and never
terminate, accumulating memory unboundedly (reported: 514GB on 96GB Mac,
kernel panic).
Fix: set stdin(Stdio::null()) on both rg and grep fallback commands so
subprocesses get immediate EOF instead of inheriting the parent pipe.
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
Add check-test-presence.sh script and CI job that fails if any *_cmd.rs
file added or modified in a PR is missing a #[cfg(test)] block.
- New CI job runs with no dependencies (parallel to all other jobs, <10s)
- Uses --diff-filter=AM to catch both added files and test deletions
- --self-test mode for local verification
- Add missing tests to wget_cmd.rs (17 tests) and env_cmd.rs (12 tests)
covering pure functions: compact_url, format_size, parse_error,
extract_filename, mask_value, is_lang_var, is_cloud_var, etc.
Fixes the enforcement gap: CONTRIBUTING.md required tests but CI did not
check. Now 34/34 *_cmd.rs modules have #[cfg(test)].
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Florian BRUNIAUX <florian@bruniaux.com>
LGTM after code review. truncate() correctly imported, error_details block placed before rule frequency table, test covers the main case. Minor duplication for error[Exxxx] style but not a bug.
As of go v1.24, tools such as golanci-lint can be managed via the mod
file and called directly on the go binary via the tool subcommand.
When called via tools, we now apply the same logic to compact the
results as in the directly called command.
Signed-off-by: shwoop <monkey.mambo.al.ferguson@gmail.com>
cat flags like -v, -A, -e, -t, -s have different semantics than
rtk read flags (-v means verbose, -n means line numbers). Blindly
forwarding flags caused incorrect behavior (e.g. cat -A file →
rtk read -A file which fails).
Only skip rewrite for incompatible flags. cat -n (line numbers) maps
correctly to rtk read -n, so it is still rewritten for token savings.
Plain `cat file` continues to rewrite to `rtk read file` as before.
rtk ls | wc -l returned N+2 instead of N because the summary line
(📊 X files, Y dirs) and blank line were always written to stdout.
Now uses std::io::stdout().is_terminal() to suppress the summary
when piped, following standard Unix convention (ls, grep, find all
do this).
Fixes#482
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Ousama Ben Younes <benyounes.ousama@gmail.com>
Verifies that `rtk rewrite "RTK_DISABLED=1 git status"` emits the
warning on stderr, not just that rewrite_command returns None.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Ousama Ben Younes <benyounes.ousama@gmail.com>
When the rewrite hook sees RTK_DISABLED=1, it now prints a warning to
stderr before skipping the rewrite. This educates AI agents to stop
overusing the bypass — a real session showed 30% of commands using
RTK_DISABLED=1 unnecessarily, dropping savings from ~65% to 48%.
The warning is on stderr (not stdout) so it doesn't affect command
output or piping. The bypass still works exactly as before.
Fixes#508
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Ousama Ben Younes <benyounes.ousama@gmail.com>
- Run cargo fmt on diff_cmd.rs and init.rs (line length violations)
- Add Unreleased section to CHANGELOG.md with the two bug fixes
from this PR (required by doc review CI gate)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Florian BRUNIAUX <florian@bruniaux.com>
Keep truncation accuracy fix (HEAD) — accurate overflow counts in
condense_unified_diff. Drop test_condense_unified_no_truncation from
develop (incompatible). Add test_no_truncation_large_diff and
test_long_lines_not_truncated from develop (test compute_diff, no conflict).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Two silent truncation bugs in git.rs:
1. compact_diff: hunk truncation showed "... (truncated)" with no count.
An LLM had no way to know if 5 or 450 lines were dropped. Replace
with "... (N lines truncated)" by tracking hunk_skipped separately
from hunk_shown — flush the count at each hunk/file boundary.
2. filter_log_output: commit body beyond 3 lines was silently dropped.
A 20-line body explaining a breaking change would show 3 lines with
no indicator that 17 were omitted. Now appends "[+N lines omitted]"
when body_omitted > 0.
Adds 2 RED-then-GREEN tests to lock in the new behavior.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Florian BRUNIAUX <florian@bruniaux.com>