`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.
- 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
rtk diff treated files whose changes were all classified as modified
(similar lines, e.g. "a: 1" vs "a: 2" in YAML/JSON) as identical,
because the identical check only looked at added/removed counts.
Report any non-empty change set as a difference, and exit 1 when
files differ per diff convention (0 when identical).
Fixes#2364
The installer previously ran `tar -xzf` on the downloaded archive with no
pre-extraction verification. A malicious mirror could ship a tarball with
`../` components or absolute paths and write files anywhere on the user's
filesystem (CWE-22).
Add a pre-extraction check that lists archive contents with `tar -tzf`
and rejects any entry whose name starts with `/` or contains a `..` path
component. The check is POSIX-compliant and adds negligible overhead for
the single-binary RTK release tarball.
Covered by scripts/test-install.sh, which exercises one safe archive
and four crafted malicious archives (leading `..`, absolute path,
mid-path `..`, trailing `..`) plus a regression guard that ensures the
check remains in install.sh.
Co-Authored-By: Claude <noreply@anthropic.com>
- Run cargo test directly through testCmd instead of faking results
- Add 60s per-test timeout on vmExec to prevent hung suite
- Make report path configurable via --report flag (default: project root)
- Fix shell injection in testRewrite by escaping single quotes
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
- Strict exit codes: cargo/python/go tests expect exact exit codes
instead of "any" (catches real regressions)
- Binary size limit documented: 8MB for ARM Linux VM vs 5MB x86 stripped
- --phase NaN guard: error message instead of silent no-op
- Verdict: 0 failures = READY, any failure = NOT READY (no more "minor issues" budget)
- rtk err exit code bug tracked in #846
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>
Two issues:
1. Module count compared top-level `mod` in main.rs (8) against
"Total: 64 modules" in ARCHITECTURE.md -- incompatible metrics,
always fails. Replaced with a simple .rs source file count (informational only).
2. CLAUDE.md check for Python/Go commands was too strict -- these
commands belong in README.md (user-facing), not CLAUDE.md (Claude Code guidance).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Florian BRUNIAUX <florian@bruniaux.com>
Call skip_test instead of nonexistent skip function, consistent
with all other conditional sections (Python, Go, tree, etc.).
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
Release-please bumps Cargo.toml but not docs, causing the version
grep to fail after every release. The check adds no value since docs
don't need to track the exact patch version.
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
* 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: 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: passthrough fallback when Clap parse fails
When RTK cannot parse a command (e.g. `rtk git -C /path status`),
instead of exiting with error code 2, it now falls back to running
the raw command directly. This keeps developer workflows unbroken.
- Replace Cli::parse() with try_parse() + run_fallback()
- Add parse_failures SQLite table for failure analytics
- Add `rtk gain --failures` / `-F` to view failure log
- Fallback preserves stdin/stdout/stderr via Stdio::inherit()
- --help and --version still work normally
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: guard RTK meta-commands from fallback to raw execution
When Clap fails to parse a meta-command like `rtk gain --badtypo`,
show the Clap error directly instead of trying to execute `gain`
as a binary from $PATH. Adds RTK_META_COMMANDS constant listing
gain, discover, learn, init, config, proxy, hook-audit, cc-economics.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: move timer start before command execution in fallback
TimedExecution::start() was called after the command finished,
so all fallback commands showed ~0ms in rtk gain --history.
Now the timer captures actual command runtime.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: add cleanup_old() call to record_parse_failure()
The parse_failures table was never cleaned up because only record()
called cleanup_old(). Now parse failures also trigger 90-day retention
cleanup.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: strip ANSI codes from Clap error before SQLite storage
Clap errors may contain terminal color codes. Strip them with
utils::strip_ansi() before storing in the parse_failures table
to avoid garbled output and wasted space.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: smoke test cargo test assertion and missing skip_test calls
- cargo test check now matches RTK's filtered output format ("passed")
in addition to raw "test result:" and "FAILURES"
- Fix undefined `skip` calls to use existing `skip_test` function
with proper (name, reason) arguments
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* chore: fmt upstream files after rebase
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: update version refs to 0.23.0 and module count to 51
Upstream v0.23.0 release bumped Cargo.toml version and added mypy_cmd
module. Update docs to match for CI validation.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <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>
* 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>
- Build from source automatically instead of requiring a pre-built binary
- Default install dir to ~/.cargo/bin
- Skip rebuild when binary is up to date
- Warn if install dir is not in PATH
* 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>
- Remove rtk diff from docs, tests, discover registry (command exists
but was over-promoted)
- docker ps: include container ID in compact output
- diff_cmd: widen truncation from 35 to 70 chars per side
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 ability to read from stdin using the special path "-", following
Unix conventions. Also fixes a pre-existing bug in git.rs push output.
Changes:
- src/main.rs: Check for Path::new("-") and route to run_stdin()
- src/read.rs: Add run_stdin() function for stdin processing
- src/read.rs: Use Language::Unknown for stdin (no file extension)
- src/git.rs: Fix unused format! result in push command
- Unit test: test_stdin_support_signature verifies function exists
- Smoke tests: 1 assertion for stdin pipe
Usage:
echo "code" | rtk read -
cat file.txt | rtk read - --level aggressive
somecommand | rtk read - -n
Note: Stdin detection requires explicit "-" path to avoid hanging.
No automatic stdin detection is performed.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add support for passing additional ripgrep arguments to rtk grep
while preserving RTK's token-optimized output formatting.
Changes:
- src/main.rs: Add extra_args field to Grep command variant
- src/main.rs: Pass extra_args to grep_cmd::run()
- src/grep_cmd.rs: Add extra_args parameter to run() signature
- src/grep_cmd.rs: Inject extra_args into ripgrep command
- Unit test: test_extra_args_accepted verifies parameter exists
- Smoke tests: 2 assertions for -i and -A flags
Usage note: Extra args must come AFTER pattern and path:
✓ rtk grep "pattern" src/ -i
✗ rtk grep "pattern" -i (clap interprets -i as path)
This enables full ripgrep functionality (case-insensitive, context
lines, word boundaries, globs) while maintaining RTK's compact output.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add external_subcommand variant to PnpmCommands enum to handle
unsupported pnpm operations by passing them through directly.
Changes:
- src/pnpm_cmd.rs: Add run_passthrough() function with OsString support
- src/pnpm_cmd.rs: Add OsString import
- src/main.rs: Add PnpmCommands::Other variant with external_subcommand
- src/main.rs: Add match arm for pnpm passthrough
- Unit test: test_run_passthrough_accepts_args verifies signature
- Smoke tests: Conditional test for pnpm help if pnpm is available
This maintains compatibility with all pnpm commands while preserving
RTK's token-optimized versions for list/outdated/install.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add external_subcommand variant to GitCommands enum to handle
unsupported git operations (tag, remote, rev-parse, etc.) by
passing them through directly to git.
Changes:
- src/git.rs: Add run_passthrough() function with OsString support
- src/main.rs: Add GitCommands::Other variant with external_subcommand
- src/main.rs: Add OsString import and match arm for passthrough
- Unit test: test_run_passthrough_accepts_args verifies signature
- Smoke tests: 3 new assertions for tag, remote, rev-parse
This preserves all git functionality while maintaining RTK's
token-optimized commands for supported operations.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>