count_find_names and count_find_total treat every unrecognised line as a
row of names. Since find began reporting hidden and gitignored matches, its
output ends with `... (N filtered)` and a `[see remaining: ...]` pointer, so
`rtk find '*' --max 10` counted 19 names (10 + 3 + 6 words) and the
--max cap check failed. Skip both lines, as the header, `+N more` and
`ext:` lines already are.
The full-`find` baseline is identical for every N, so the `--max` rows can
no longer detect a `--max` that stops limiting: a no-op would still score
~51% savings and pass as a WARN. Assert the cap directly instead —
`rtk find --max N` displays exactly min(N, total) names, which fails
whether N sits below or above rtk's default display cap.
Keep a single savings row, since a second row with the same baseline only
added the same token count to TOTAL_UNIX twice.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
scripts/benchmark.sh measured `rtk grep -rn 'fn ' src/ -l 40`, intending
--max-len 40. Two problems: `-l` is no longer rtk's short for --max-len, and
the flags sit AFTER the pattern, where trailing_var_arg passes them through
verbatim rather than binding them. So `-l` reached grep as
--files-with-matches and `40` was taken as a filename:
$ rtk grep -rn 'fn ' src/ -l 40
src/analytics/gain.rs
src/analytics/session_cmd.rs
grep: 40: No such file or directory
The benchmark was timing that error path on develop too -- it is not a
regression from this PR, but --max-len is the option this PR just changed,
and this is its only consumer in the repo.
Now uses the long form, before the pattern, where it binds:
$ rtk grep --max-len 40 -rn 'fn ' src/ # widest match line: 77
$ rtk grep -rn 'fn ' src/ # widest match line: 117
$ bash -n scripts/benchmark.sh
syntax OK
The golangci-lint row has never measured the filter. The fixture is clean Go, so
golangci-lint prints an empty report, the raw side counts zero tokens and the row
scores as skipped whatever rtk does -- it read 0 -> 8 for as long as it was green.
Adds five functions that ignore returned errors, which errcheck reports. Verified
in golang:1.27 against golangci-lint v2.13.2, running the fixture exactly as it
appears here:
golangci-lint 220 -> 35 GOOD (84%)
go test 30 -> 8 GOOD (73%) unchanged
go build 0 -> 0 SKIP unchanged
go vet 0 -> 0 SKIP unchanged
go build, go vet and go test stay clean, so the neighbouring rows keep measuring
what they measured before.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`BENCH_DIR="$(pwd)/scripts/benchmark"` is a tracked directory: besides the
gitignored `unix/`, `rtk/` and `diff/` output dirs it holds the TypeScript
VM-benchmark harness (`run.ts`, `cleanup.ts`, `rebuild.ts`, `lib/*.ts`,
`cloud-init.yaml`). `rm -rf "$BENCH_DIR"` therefore wiped all 7 tracked files
from the working tree on every local run (`$CI` unset), which is exactly when
a contributor runs the benchmark before pushing.
Wipe only the three gitignored output subdirectories instead. Stale output is
still cleared between runs; the harness survives.
Follow-up to #3430 (rtk-ai/rtk#3430 review).
Review follow-up on #3430:
- Bind `python3 -m http.server 0` so the kernel picks a free port and read the
chosen one from the (unbuffered) server log, instead of hardcoding 8899 which
fails needlessly when that port is already in use.
- Make `cleanup_net_fixtures` failure-tolerant: it runs from an EXIT trap under
`set -e`, so `[ -n "$PID" ] && kill ...` aborted the whole handler whenever
`kill` failed (server already dead), leaking the fixture dir and downloads.
- Give the wget case an explicit skip line instead of silently disappearing.
wget rejects `file://` ("Unsupported scheme"), so there is no offline URL to
fall back to when the loopback server is unavailable.
RED (PR HEAD): fixture dir NOT removed when kill fails; server unusable with
8899 taken. GREEN: fixture dir removed; server up on an ephemeral port.
The remaining online calls (curl robots.txt + wget /json on mockhttp.org)
were both a network dependency and non-deterministic. Serve fixed local
fixtures over a loopback http.server so curl and wget get real
Content-Type headers (exercising JSON minification), fully offline. curl
falls back to file:// when python3 is unavailable. Clean up the server,
temp fixtures, and the ./data.json download on exit.
`rtk find --max N` caps how many names are displayed but still scans and
summarizes the whole tree, so its output must be compared against the full
`find` a user would otherwise read. The old baseline piped through `head -N`,
which truncates the raw scan to a different (early-terminated) operation. On
small repos `head -10` produced fewer bytes than rtk's summary header, marking
`find --max 10` as a spurious negative that failed the whole benchmark job.
Dropping `head -N` makes both --max rows compare like-for-like and stable.
- grep runs grep, rg runs rg: drop the substitution, forced --no-ignore-vcs, and BRE-to-rg translation
- add `rtk rg` command (native ripgrep, sharing the same output filter)
- split rewrite rule: grep to rtk grep, rg to rtk rg
- record the agent's real command in tracking (was synthesized as "grep -rn")
- emit nothing on a clean no-match (never-worse parity with the shared guard)
- rename grep_cmd.rs to search.rs, now hosting both engines
- cover engine faithfulness, ignore semantics, and rg savings with issue-referenced tests
- benchmark the grep and rg paths
* fix: handle tail rewrites with read tail-lines
* feat: add 32 TOML-filtered commands to hook rewrite rules (#475)
Add rewrite rules for all TOML-filtered commands so the Claude Code
hook automatically rewrites them to `rtk proxy <cmd>`. This ensures
TOML filters apply transparently without manual `rtk` prefixing.
Commands added: ansible-playbook, brew, composer, df, dotnet, du,
fail2ban-client, gcloud, hadolint, helm, iptables, make,
markdownlint, mix, mvn, ping, pio, poetry, pre-commit, ps, quarto,
rsync, shellcheck, shopify, sops, swift, systemctl, terraform, tofu,
trunk, uv, yamllint.
Tests updated to use `htop` as unsupported command example since
terraform is now supported via TOML filter.
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* fix: git log --oneline no longer silently truncated to 10 entries (#461) (#478)
Only inject -10 limit when RTK applies its own compact format.
When user provides --oneline/--pretty/--format, respect git's
default behavior (no limit). Also detect -n and --max-count as
user-provided limit flags.
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* fix: gh run view --job flag loses its value (#416) (#477)
Add --job and --attempt to flags_with_value in
extract_identifier_and_extra_args() so their values are not
mistaken for the run identifier when placed before it.
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* fix: rtk read no longer corrupts JSON files with glob patterns (#464) (#479)
Add Language::Data variant for JSON, YAML, TOML, XML, Markdown, CSV
and other data formats. These files have no comment syntax, so the
MinimalFilter skips comment stripping entirely.
Previously, `packages/*` in package.json was treated as a block
comment start (`/*`), causing everything until the next `*/` to be
stripped — corrupting the JSON structure.
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* fix: npm routing, discover cat redirect, proxy quoted args (#480)
* fix: npm routing, discover cat redirect, proxy quoted args (#470, #315, #388)
#470: rtk npm now correctly routes npm subcommands (install, list,
audit, etc.) without injecting "run". Previously, `rtk npm install`
was executed as `npm run install`.
#315: discover no longer counts `cat >`, `cat >>`, `cat |` as missed
savings. These are write/pipe operations with no terminal output to
compress.
#388: rtk proxy now auto-splits a single quoted argument containing
spaces. `rtk proxy 'head -50 file.php'` now works like
`rtk proxy head -50 file.php`.
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* fix: proxy quote-aware split, redirect detection scan all tokens, npm test routing
- Proxy: replace split_whitespace with shell_split() that respects quotes (#388)
e.g. 'git log --format="%H %s"' no longer splits on space inside quotes
- Discover: scan all tokens for redirect operators, not just nth(1) (#315)
e.g. 'cat file.txt > output.txt' now correctly detected as write
- npm: replace tautological test with actual routing logic verification
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
---------
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* feat: add 11 new TOML built-in filters (xcodebuild, jq, basedpyright, ty, skopeo, stat, biome, oxlint, jj, ssh, gcc) (#490)
Closes#484, #483, #449, #448, #428, #283, #316, #195, #271, #333, #87, #376
Signed-off-by: Patrick <patrick@rtk.ai>
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* fix: rtk rewrite accepts multiple args without quotes (#504)
* fix: rtk rewrite accepts multiple args without quotes
`rtk rewrite ls -al` now works the same as `rtk rewrite "ls -al"`.
Previously, args after the command were rejected or caused ENOENT.
Also adds rewrite tests to benchmark.sh to prevent regression.
Signed-off-by: Patrick Szymkowiak <patrick.szymkowiak@rtk-ai.app>
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* test: add Clap rewrite tests + fix benchmark false failures
- Add 2 Clap try_parse_from tests for rewrite multi-args (catches the
KuSh bug at unit test level, not just benchmark)
- Fix git diff benchmark: use HEAD~1 on both sides for fair comparison
- Skip cargo/rustc benchmarks when tools not in PATH instead of false FAIL
- Benchmark: 0 fail, 4 skip (env-dependent), 52 green
Signed-off-by: Patrick Szymkowiak <patrick.szymkowiak@rtk-ai.app>
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
---------
Signed-off-by: Patrick Szymkowiak <patrick.szymkowiak@rtk-ai.app>
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* fix: use rtk <cmd> instead of rtk proxy for TOML-filtered commands (#507)
- Replace all 32 `rtk proxy <cmd>` rules with `rtk <cmd>` so TOML filters
actually apply (proxy bypasses filters, giving 0% real savings)
- Extract NPM_SUBCOMMANDS to module-level const to prevent test/prod drift
Reported-by: FlorianBruniaux
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* fix: warn when no hook installed + rtk gain hook status + PR #499 fixes
- hook_check: detect missing hook (not just outdated), warn with ⚠️
Only warns if ~/.claude/ exists (Claude Code user) — once per day
- gain: show hook status warning (missing/outdated) in rtk gain output
- ssh.toml: bump max_lines 50→200, truncate_lines_at 120→200 (Florian review)
- git.rs: mark integration test #[ignore] + assert binary exists (Florian review)
- Add HookStatus enum for reuse across gain/diagnostics
Fixes#508, Fixes#509
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* fix: address code review — hook_check edge cases
- status() checks .claude/ existence (no false warning for non-CC users)
- Unreadable hook file returns Outdated not Missing
- Swap marker/warning order (emit warning before touching rate-limit marker)
- Rename misleading test, add end-to-end status() test
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* fix: review iteration 2 — double-warning, case-sensitive test, ssh truncate
- Refactor check_and_warn to delegate to status() (single source of truth)
- Fix double-warning: skip maybe_warn() for `rtk gain` (has its own inline warning)
- Fix git test: case-insensitive assertion for cross-locale compatibility
- ssh.toml: keep truncate_lines_at=120 (terminal width convention)
- Robust mtime handling: unwrap_or(u64::MAX) instead of nested .ok()?
- Test handles all CI environments (no hook, no .claude, hook present)
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* fix: detect and warn RTK_DISABLED=1 overuse (#508)
- discover: count RTK_DISABLED= bypassed commands, report top 5 examples
- gain: lightweight 7-day JSONL scan, warn if >10% commands bypassed
- registry: add has_rtk_disabled_prefix() and strip_disabled_prefix() helpers
- gitignore: add .fastembed_cache/ and .next/
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* fix: preserve trailing newline in tail_lines + add missing test
- apply_line_window() now preserves trailing newline when input has one
- Add test for tail --lines N (space form) rewrite
- Add test for tail_lines without trailing newline
Signed-off-by: Patrick <patrick@rtk-ai.com>
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* fix: respect user-specified git log limits instead of silently truncating
RTK was silently capping git log output in two ways:
1. `--oneline` without `-N` defaulted to 10 entries (now 50)
2. `filter_log_output()` re-truncated even when user explicitly set `-N`
3. Lines >80 chars were truncated, hiding PR numbers and author names
This matters for LLM workflows: Claude needs full commit history for
rebase, squash, and changelog operations. Silent truncation caused
incomplete context and repeated re-runs.
Changes:
- User-explicit `-N` → no line cap, wider 120-char truncation
- `--oneline`/`--pretty` without `-N` → default 50 (was 10)
- No flags → unchanged (default 10)
- Extract `truncate_line()` helper for clarity
Fixes#461
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: handle -n N and --max-count=N forms in git log limit parsing
- Extract parse_user_limit() to handle all 4 forms: -20, -n 20, --max-count=20, --max-count 20
- Add token savings test for filter_log_output (≥60%)
- Add 5 tests for parse_user_limit edge cases
Signed-off-by: Patrick <patrick@rtk-ai.com>
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* feat: add structured dotnet support (build/test/restore/format)
Integrate PR #172 by @danielmarbach onto develop:
- MSBuild binlog parser (binary format, gzip, 7-bit varint)
- TRX test result parser (quick-xml)
- Format report JSON parser
- Subcommand routing: build, test, restore, format + passthrough
- Sensitive env var scrubbing (GH_TOKEN, AWS_SECRET_ACCESS_KEY, etc.)
- Fallback to text parsing when binlog unavailable
- 86-93% token savings on real .NET projects
Maintainer fixes applied:
- Removed binlog temp path from output (wastes tokens)
- Dropped hook file changes (incompatible with develop architecture)
- Fixed unused variable warnings
888 tests pass.
Signed-off-by: Patrick <patrick@rtk-ai.com>
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* feat: add OpenCode plugin support (#300)
* feat(opencode): add OpenCode plugin support
Add `--opencode` flag to `rtk init` for installing a global OpenCode
plugin that rewrites Bash/shell commands through `rtk rewrite`.
- New plugin: hooks/opencode-rtk.ts (thin delegator to rtk rewrite)
- New init modes: --opencode (OpenCode only), combinable with Claude modes
- Plugin install/update/remove lifecycle with idempotent writes
- Uninstall cleans up OpenCode plugin alongside Claude Code artifacts
- `rtk init --show` reports OpenCode plugin status
- Replace unreachable!() with bail!() in match exhaustiveness guard
* docs: add OpenCode plugin documentation
- README: OpenCode plugin section, install flags, troubleshooting
- TROUBLESHOOTING: OpenCode-specific checklist
- Update init mode table to reflect Claude Code default
---------
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
Signed-off-by: Patrick <patrick@rtk.ai>
Signed-off-by: Patrick Szymkowiak <patrick.szymkowiak@rtk-ai.app>
Signed-off-by: Patrick <patrick@rtk-ai.com>
Co-authored-by: Qingyu Li <2310301201@stu.pku.edu.cn>
Co-authored-by: Ousama Ben Younes <benyounes.ousama@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: José Almeida <57680069+zeval@users.noreply.github.com>
* fix: prettier reports "All OK" when not installed (#221)
Empty or failed prettier output was incorrectly treated as "all files
formatted". Now detects empty output and non-zero exit code, shows the
actual error message instead of a false positive.
* test: add smoke tests for rewrite, verify, proxy, discover, diff, wc, smart, docker, json edge cases
Covers bug fixes#196, #344, #345, #346, #347 and previously untested
commands. Adds assert_fails helper. 118 assertions total (was 69).
* chore: update benchmark.sh with missing commands and fix paths
- Add cargo (build/test/clippy/check), diff, smart, wc, curl, wget sections
- Fix Python commands: use dedicated rtk ruff/pytest instead of rtk test
- Fix Go commands: use dedicated rtk go/golangci-lint, add go build/vet
- Make BENCH_DIR absolute so debug files work from temp fixture dirs
- Fallback to installed rtk if target/release/rtk not found
* feat(cargo): aggregate test output into single line (#83)
Problem: `cargo test` shows 24+ summary lines even when all pass.
An LLM only needs to know IF something failed, not 24x "ok".
Before (24 lines):
```
✓ test result: ok. 2 passed; 0 failed; ...
✓ test result: ok. 0 passed; 0 failed; ...
... (x24)
```
After (1 line):
```
✓ cargo test: 137 passed (24 suites, 1.45s)
```
Changes:
- Add AggregatedTestResult struct with regex parsing
- Merge multiple test summaries when all pass
- Format: "N passed, M ignored, P filtered out (X suites, Ys)"
- Fallback to original behavior if parsing fails
- Failures still show full details (no aggregation)
Tests: 6 new + 1 modified, covering all cases:
- Multi-suite aggregation
- Single suite (singular "suite")
- Zero tests
- With ignored/filtered out
- Failures → no aggregation (detail preserved)
- Regex fallback
Closes#83
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* fix(ci): prevent Python/Go benchmark sections from being silently skipped
**Problem:**
Python and Go benchmark sections were silently skipped in CI because
the RTK repository doesn't contain pyproject.toml or go.mod files.
The sections only ran when these project files existed.
**Solution:**
1. Create temporary fixtures with minimal project structure:
- Python: pyproject.toml + sample.py + test_sample.py
- Go: go.mod + main.go + main_test.go
2. Resolve RTK to absolute path to work after cd into temp dirs
3. Install required tools in CI workflow:
- Python: ruff, pytest
- Go: stable version + golangci-lint
**Impact:**
- Python/Go sections now appear in CI benchmark output
- Self-contained fixtures ensure consistent benchmarking
- No dependency on RTK project structure
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(hooks): add missing RTK command rewrites
Add 8 missing command rewrites to rtk-rewrite.sh and rtk-suggest.sh:
- cargo check/install/fmt
- tree, find, diff
- head → rtk read (with --max-lines transformation)
- wget
Fixes BSD sed compatibility for head transformation by using literal
spaces instead of \s+ (which doesn't work on macOS).
Impact: ~18.2K tokens saved on previously missed commands discovered
by `rtk discover`.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
* feat(cargo): aggregate test output into single line (#83)
Problem: `cargo test` shows 24+ summary lines even when all pass.
An LLM only needs to know IF something failed, not 24x "ok".
Before (24 lines):
```
✓ test result: ok. 2 passed; 0 failed; ...
✓ test result: ok. 0 passed; 0 failed; ...
... (x24)
```
After (1 line):
```
✓ cargo test: 137 passed (24 suites, 1.45s)
```
Changes:
- Add AggregatedTestResult struct with regex parsing
- Merge multiple test summaries when all pass
- Format: "N passed, M ignored, P filtered out (X suites, Ys)"
- Fallback to original behavior if parsing fails
- Failures still show full details (no aggregation)
Tests: 6 new + 1 modified, covering all cases:
- Multi-suite aggregation
- Single suite (singular "suite")
- Zero tests
- With ignored/filtered out
- Failures → no aggregation (detail preserved)
- Regex fallback
Closes#83
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* feat: add Python and Go language support
Implements comprehensive support for Python and Go development tooling
with 70-90% token reduction across all commands.
Python commands (3):
- rtk ruff: Linter/formatter with JSON (check) and text (format) parsing (80%+)
- rtk pytest: Test runner with state machine text parser (90%+)
- rtk pip: Package manager with auto-detect uv (70-85%)
Go commands (4):
- rtk go test: NDJSON streaming parser for interleaved test events (90%+)
- rtk go build: Text filter showing errors only (80%)
- rtk go vet: Text filter for issues (75%)
- rtk golangci-lint: JSON parser grouped by rule (85%)
Architecture:
- Standalone Python commands (mirror lint/prettier pattern)
- Go sub-enum (mirror git/cargo pattern)
- 5 new modules: ruff_cmd, pytest_cmd, pip_cmd, go_cmd, golangci_cmd
- Hook integration in rtk-rewrite.sh for transparent rewrites
- Comprehensive tests (47 new tests, all passing)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* feat(benchmark): add Python and Go commands
Add benchmark sections for Python (ruff, pytest, pip) and Go (go test/build/vet, golangci-lint) to validate >80% token savings in CI pipeline.
Sections conditionally execute based on project markers (pyproject.toml, go.mod) and tool availability.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
- ls: rewrite to strip permissions/owner/group/dates, show only
names with dir/ suffix and human sizes. Properly handle flag
ordering (path -l), -lh, multi-paths, --all.
- discover: remove orphan diff pattern that caused index out of
bounds panic (PATTERNS had 22 entries vs RULES 21)
- benchmark: add 8 ls test cases
- test-all: add 5 ls smoke tests
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- find: replace fd/find subprocess with ignore::WalkBuilder for native
.gitignore support, fix "." pattern, fix --max file counting
- json: add stdin support via "-" path (same pattern as read)
- benchmark: one-line-per-test format with icons for CI logs,
local debug files only when not in CI, remove md upload/PR steps
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add benchmarks for the 6 new commands in scripts/benchmark.sh:
- tsc: TypeScript compiler error grouping
- prettier: Format checker with file filtering
- lint: ESLint/Biome grouped violations
- next: Next.js build metrics extraction
- playwright: E2E test failure filtering
- prisma: Prisma CLI without ASCII art
All benchmarks are conditional (skip if tools not available or
not applicable to current project). Tests only run on projects
with package.json and relevant configuration files.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>