Compare commits

..
Author SHA1 Message Date
Patrick szymkowiak 05fa9b416f feat: rewrite engine, OpenCode support, hook system improvements
Includes all changes from develop → master merge (#499):
- rtk rewrite engine with shell_split + rewrite_segment
- OpenCode plugin support (rtk init -g --opencode)
- Hook check warnings and RTK_DISABLED detection
- TOML filter DSL with 14 built-in filters
- Improved gh, git log, proxy quote handling

Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
2026-03-12 16:15:50 +01:00
d0396da1ce chore: merge develop into master (#499)
* 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>
2026-03-12 13:49:08 +01:00
37 changed files with 298 additions and 731 deletions

No files matched your search

+1
View File
@@ -4,6 +4,7 @@ on:
pull_request:
paths:
- 'src/**/*.rs'
- 'Cargo.toml'
- '**.md'
- '.claude/hooks/*.sh'
push:
-1
View File
@@ -38,7 +38,6 @@ benchmark-report.md
*.sqlite3
rtk_tracking.db
claudedocs
.omc
# Vitals provenance data
.vitals/
Generated
+70 -270
View File
@@ -90,9 +90,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.102"
version = "1.0.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61"
[[package]]
name = "autocfg"
@@ -108,9 +108,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
[[package]]
name = "bitflags"
version = "2.11.0"
version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
[[package]]
name = "block-buffer"
@@ -133,15 +133,15 @@ dependencies = [
[[package]]
name = "bumpalo"
version = "3.20.2"
version = "3.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb"
checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510"
[[package]]
name = "cc"
version = "1.2.56"
version = "1.2.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2"
checksum = "6354c81bbfd62d9cfa9cb3c773c2b7b2a3a482d569de977fd0e961f6e7c00583"
dependencies = [
"find-msvc-tools",
"shlex",
@@ -155,9 +155,9 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "chrono"
version = "0.4.44"
version = "0.4.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0"
checksum = "fac4744fb15ae8337dc853fee7fb3f4e48c0fbaa23d0afe49c447b4fab126118"
dependencies = [
"iana-time-zone",
"js-sys",
@@ -168,9 +168,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.5.60"
version = "4.5.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2797f34da339ce31042b27d23607e051786132987f595b02ba4f6a6dffb7030a"
checksum = "c6e6ff9dcd79cff5cd969a17a545d79e84ab086e444102a591e288a8aa3ce394"
dependencies = [
"clap_builder",
"clap_derive",
@@ -178,9 +178,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.5.60"
version = "4.5.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24a241312cea5059b13574bb9b3861cabf758b879c15190b37b6d6fd63ab6876"
checksum = "fa42cf4d2b7a41bc8f663a7cab4031ebafa1bf3875705bfaf8466dc60ab52c00"
dependencies = [
"anstream",
"anstyle",
@@ -190,9 +190,9 @@ dependencies = [
[[package]]
name = "clap_derive"
version = "4.5.55"
version = "4.5.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a92793da1a46a5f2a02a6f4c46c6496b28c43638adea8306fcb0caa1634f24e5"
checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671"
dependencies = [
"heck",
"proc-macro2",
@@ -202,9 +202,9 @@ dependencies = [
[[package]]
name = "clap_lex"
version = "1.0.0"
version = "0.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a822ea5bc7590f9d40f1ba12c0dc3c2760f3482c6984db1573ad11031420831"
checksum = "c3e64b0cc0439b12df2fa678eae89a1c56a529fd067a9115f7827f1fffd22b32"
[[package]]
name = "colorchoice"
@@ -323,12 +323,6 @@ dependencies = [
"syn",
]
[[package]]
name = "env_home"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7f84e12ccf0a7ddc17a6c41c93326024c42920d7ee630d04950e6926645c0fe"
[[package]]
name = "equivalent"
version = "1.0.2"
@@ -365,9 +359,9 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]]
name = "find-msvc-tools"
version = "0.1.9"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
checksum = "8591b0bcc8a98a64310a2fae1bb3e9b8564dd10e381e6e28010fde8e8e8568db"
[[package]]
name = "flate2"
@@ -379,12 +373,6 @@ dependencies = [
"miniz_oxide",
]
[[package]]
name = "foldhash"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]]
name = "form_urlencoded"
version = "1.2.2"
@@ -417,15 +405,14 @@ dependencies = [
[[package]]
name = "getrandom"
version = "0.4.2"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555"
checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
dependencies = [
"cfg-if",
"libc",
"r-efi",
"wasip2",
"wasip3",
]
[[package]]
@@ -450,15 +437,6 @@ dependencies = [
"ahash",
]
[[package]]
name = "hashbrown"
version = "0.15.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
dependencies = [
"foldhash",
]
[[package]]
name = "hashbrown"
version = "0.16.1"
@@ -493,9 +471,9 @@ dependencies = [
[[package]]
name = "iana-time-zone"
version = "0.1.65"
version = "0.1.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470"
checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb"
dependencies = [
"android_system_properties",
"core-foundation-sys",
@@ -596,12 +574,6 @@ dependencies = [
"zerovec",
]
[[package]]
name = "id-arena"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
[[package]]
name = "idna"
version = "1.1.0"
@@ -647,8 +619,6 @@ checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017"
dependencies = [
"equivalent",
"hashbrown 0.16.1",
"serde",
"serde_core",
]
[[package]]
@@ -665,9 +635,9 @@ checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
[[package]]
name = "js-sys"
version = "0.3.91"
version = "0.3.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c"
checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3"
dependencies = [
"once_cell",
"wasm-bindgen",
@@ -679,24 +649,19 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "leb128fmt"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
[[package]]
name = "libc"
version = "0.2.182"
version = "0.2.180"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"
[[package]]
name = "libredox"
version = "0.1.14"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1744e39d1d6a9948f4f388969627434e31128196de472883b39f148769bfe30a"
checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616"
dependencies = [
"bitflags",
"libc",
]
@@ -713,9 +678,9 @@ dependencies = [
[[package]]
name = "linux-raw-sys"
version = "0.12.1"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039"
[[package]]
name = "litemap"
@@ -731,9 +696,9 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
[[package]]
name = "memchr"
version = "2.8.0"
version = "2.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
[[package]]
name = "miniz_oxide"
@@ -793,16 +758,6 @@ dependencies = [
"zerovec",
]
[[package]]
name = "prettyplease"
version = "0.2.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"
dependencies = [
"proc-macro2",
"syn",
]
[[package]]
name = "proc-macro2"
version = "1.0.106"
@@ -823,18 +778,18 @@ dependencies = [
[[package]]
name = "quote"
version = "1.0.45"
version = "1.0.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a"
dependencies = [
"proc-macro2",
]
[[package]]
name = "r-efi"
version = "6.0.0"
version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
[[package]]
name = "redox_users"
@@ -849,9 +804,9 @@ dependencies = [
[[package]]
name = "regex"
version = "1.12.3"
version = "1.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276"
checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4"
dependencies = [
"aho-corasick",
"memchr",
@@ -861,9 +816,9 @@ dependencies = [
[[package]]
name = "regex-automata"
version = "0.4.14"
version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f"
checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c"
dependencies = [
"aho-corasick",
"memchr",
@@ -872,9 +827,9 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.8.10"
version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
[[package]]
name = "ring"
@@ -914,7 +869,6 @@ dependencies = [
"toml",
"ureq",
"walkdir",
"which",
]
[[package]]
@@ -933,9 +887,9 @@ dependencies = [
[[package]]
name = "rustix"
version = "1.1.4"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190"
checksum = "146c9e247ccc180c1f61615433868c99f3de3ae256a30a43b49f67c2d9171f34"
dependencies = [
"bitflags",
"errno",
@@ -994,12 +948,6 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "semver"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
[[package]]
name = "serde"
version = "1.0.228"
@@ -1102,9 +1050,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "syn"
version = "2.0.117"
version = "2.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a"
dependencies = [
"proc-macro2",
"quote",
@@ -1124,12 +1072,12 @@ dependencies = [
[[package]]
name = "tempfile"
version = "3.26.0"
version = "3.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82a72c767771b47409d2345987fda8628641887d5466101319899796367354a0"
checksum = "655da9c7eb6305c55742045d5a8d2037996d61d8de95806335c7c86ce0f82e9c"
dependencies = [
"fastrand",
"getrandom 0.4.2",
"getrandom 0.3.4",
"once_cell",
"rustix",
"windows-sys 0.61.2",
@@ -1214,15 +1162,9 @@ checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
[[package]]
name = "unicode-ident"
version = "1.0.24"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
[[package]]
name = "unicode-xid"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
[[package]]
name = "untrusted"
@@ -1307,20 +1249,11 @@ dependencies = [
"wit-bindgen",
]
[[package]]
name = "wasip3"
version = "0.4.0+wasi-0.3.0-rc-2026-01-06"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5"
dependencies = [
"wit-bindgen",
]
[[package]]
name = "wasm-bindgen"
version = "0.2.114"
version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e"
checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566"
dependencies = [
"cfg-if",
"once_cell",
@@ -1331,9 +1264,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.114"
version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6"
checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@@ -1341,9 +1274,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.114"
version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3"
checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55"
dependencies = [
"bumpalo",
"proc-macro2",
@@ -1354,47 +1287,13 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.114"
version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16"
checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12"
dependencies = [
"unicode-ident",
]
[[package]]
name = "wasm-encoder"
version = "0.244.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319"
dependencies = [
"leb128fmt",
"wasmparser",
]
[[package]]
name = "wasm-metadata"
version = "0.244.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909"
dependencies = [
"anyhow",
"indexmap",
"wasm-encoder",
"wasmparser",
]
[[package]]
name = "wasmparser"
version = "0.244.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe"
dependencies = [
"bitflags",
"hashbrown 0.15.5",
"indexmap",
"semver",
]
[[package]]
name = "webpki-roots"
version = "0.26.11"
@@ -1413,17 +1312,6 @@ dependencies = [
"rustls-pki-types",
]
[[package]]
name = "which"
version = "8.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a824aeba0fbb27264f815ada4cff43d65b1741b7a4ed7629ff9089148c4a4e0"
dependencies = [
"env_home",
"rustix",
"winsafe",
]
[[package]]
name = "winapi-util"
version = "0.1.11"
@@ -1651,106 +1539,18 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "winnow"
version = "0.7.15"
version = "0.7.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945"
checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829"
dependencies = [
"memchr",
]
[[package]]
name = "winsafe"
version = "0.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904"
[[package]]
name = "wit-bindgen"
version = "0.51.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"
dependencies = [
"wit-bindgen-rust-macro",
]
[[package]]
name = "wit-bindgen-core"
version = "0.51.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc"
dependencies = [
"anyhow",
"heck",
"wit-parser",
]
[[package]]
name = "wit-bindgen-rust"
version = "0.51.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21"
dependencies = [
"anyhow",
"heck",
"indexmap",
"prettyplease",
"syn",
"wasm-metadata",
"wit-bindgen-core",
"wit-component",
]
[[package]]
name = "wit-bindgen-rust-macro"
version = "0.51.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a"
dependencies = [
"anyhow",
"prettyplease",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
]
[[package]]
name = "wit-component"
version = "0.244.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2"
dependencies = [
"anyhow",
"bitflags",
"indexmap",
"log",
"serde",
"serde_derive",
"serde_json",
"wasm-encoder",
"wasm-metadata",
"wasmparser",
"wit-parser",
]
[[package]]
name = "wit-parser"
version = "0.244.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736"
dependencies = [
"anyhow",
"id-arena",
"indexmap",
"log",
"semver",
"serde",
"serde_derive",
"serde_json",
"unicode-xid",
"wasmparser",
]
[[package]]
name = "writeable"
@@ -1783,18 +1583,18 @@ dependencies = [
[[package]]
name = "zerocopy"
version = "0.8.40"
version = "0.8.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a789c6e490b576db9f7e6b6d661bcc9799f7c0ac8352f56ea20193b2681532e5"
checksum = "668f5168d10b9ee831de31933dc111a459c97ec93225beb307aed970d1372dfd"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.40"
version = "0.8.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f65c489a7071a749c849713807783f70672b28094011623e200cb86dcb835953"
checksum = "2c7962b26b0a8685668b671ee4b54d007a67d4eaf05fda79ac0ecf41e32270f1"
dependencies = [
"proc-macro2",
"quote",
@@ -1863,6 +1663,6 @@ dependencies = [
[[package]]
name = "zmij"
version = "1.0.21"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
checksum = "dfcd145825aace48cff44a8844de64bf75feec3080e0aa5cdbde72961ae51a65"
-1
View File
@@ -32,7 +32,6 @@ ureq = "2"
hostname = "0.4"
flate2 = "1.0"
quick-xml = "0.37"
which = "8"
[build-dependencies]
toml = "0.8"
-28
View File
@@ -200,34 +200,6 @@ rtk init --show # Should show "OpenCode: plugin installed"
---
## Problem: RTK commands fail on Windows ("program not found" or "No such file")
### Symptom
```
rtk vitest --run
# Error: program not found
# Or: The system cannot find the file specified
rtk lint .
# Error: No such file or directory
```
### Root Cause
On Windows, Node.js tools (vitest, eslint, tsc, etc.) are installed as `.CMD` or `.BAT` wrapper scripts, not as native `.exe` binaries. Rust's `std::process::Command::new("vitest")` does not honor the Windows `PATHEXT` environment variable, so it cannot find `vitest.CMD` even when it's on PATH.
### Solution
Update to rtk v0.23.1+ which resolves this via the `which` crate for proper PATH+PATHEXT resolution. All 16+ command modules now use `resolved_command()` instead of `Command::new()`.
```bash
cargo install --git https://github.com/rtk-ai/rtk
rtk --version # Should be 0.23.1+
```
### Affected Commands
All commands that spawn external tools: `rtk vitest`, `rtk lint`, `rtk tsc`, `rtk pnpm`, `rtk playwright`, `rtk prisma`, `rtk next`, `rtk prettier`, `rtk ruff`, `rtk pytest`, `rtk pip`, `rtk mypy`, `rtk golangci-lint`, and others.
---
## Problem: "command not found: rtk" after installation
### Symptom
+17 -1
View File
@@ -3,7 +3,23 @@ set -e
echo "🔍 Validating RTK documentation consistency..."
# 1. Nombre de modules cohérent
# 1. Version Cargo.toml == tous les fichiers doc
CARGO_VERSION=$(grep '^version = ' Cargo.toml | cut -d'"' -f2)
echo "📦 Cargo.toml version: $CARGO_VERSION"
for file in README.md CLAUDE.md ARCHITECTURE.md; do
if [ ! -f "$file" ]; then
echo "⚠️ $file not found, skipping"
continue
fi
if ! grep -q "$CARGO_VERSION" "$file"; then
echo "❌ $file ne mentionne pas version $CARGO_VERSION"
exit 1
fi
done
echo "✅ Version consistency: all docs mention $CARGO_VERSION"
# 2. Nombre de modules cohérent
MAIN_MODULES=$(grep -c '^mod ' src/main.rs)
echo "📊 Module count in main.rs: $MAIN_MODULES"
+5 -4
View File
@@ -5,9 +5,10 @@
use crate::json_cmd;
use crate::tracking;
use crate::utils::{join_with_overflow, resolved_command, truncate_iso_date};
use crate::utils::{join_with_overflow, truncate_iso_date};
use anyhow::{Context, Result};
use serde_json::Value;
use std::process::Command;
const MAX_ITEMS: usize = 20;
const JSON_COMPRESS_DEPTH: usize = 4;
@@ -61,7 +62,7 @@ fn is_structured_operation(args: &[String]) -> bool {
fn run_generic(subcommand: &str, args: &[String], verbose: u8, full_sub: &str) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("aws");
let mut cmd = Command::new("aws");
cmd.arg(subcommand);
let mut has_output_flag = false;
@@ -125,7 +126,7 @@ fn run_aws_json(
extra_args: &[String],
verbose: u8,
) -> Result<(String, String, std::process::ExitStatus)> {
let mut cmd = resolved_command("aws");
let mut cmd = Command::new("aws");
for arg in sub_args {
cmd.arg(arg);
}
@@ -196,7 +197,7 @@ fn run_s3_ls(extra_args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
// s3 ls doesn't support --output json, run as-is and filter text
let mut cmd = resolved_command("aws");
let mut cmd = Command::new("aws");
cmd.args(["s3", "ls"]);
for arg in extra_args {
cmd.arg(arg);
+4 -3
View File
@@ -1,8 +1,9 @@
use crate::tracking;
use crate::utils::resolved_command;
use crate::utils::truncate;
use anyhow::{Context, Result};
use std::collections::HashMap;
use std::ffi::OsString;
use std::process::Command;
use std::sync::OnceLock;
#[derive(Debug, Clone)]
@@ -67,7 +68,7 @@ where
{
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("cargo");
let mut cmd = Command::new("cargo");
cmd.arg(subcommand);
let restored_args = restore_double_dash(args);
@@ -964,7 +965,7 @@ pub fn run_passthrough(args: &[OsString], verbose: u8) -> Result<()> {
if verbose > 0 {
eprintln!("cargo passthrough: {:?}", args);
}
let status = resolved_command("cargo")
let status = Command::new("cargo")
.args(args)
.status()
.context("Failed to run cargo")?;
+8 -5
View File
@@ -4,7 +4,6 @@
//! Claude Code API usage metrics. Handles subprocess execution, JSON parsing,
//! and graceful degradation when ccusage is unavailable.
use crate::utils::{resolved_command, tool_exists};
use anyhow::{Context, Result};
use serde::Deserialize;
use std::process::Command;
@@ -85,17 +84,21 @@ struct MonthlyEntry {
/// Check if ccusage binary exists in PATH
fn binary_exists() -> bool {
tool_exists("ccusage")
Command::new("which")
.arg("ccusage")
.output()
.map(|o| o.status.success())
.unwrap_or(false)
}
/// Build the ccusage command, falling back to npx if binary not in PATH
fn build_command() -> Option<Command> {
if binary_exists() {
return Some(resolved_command("ccusage"));
return Some(Command::new("ccusage"));
}
// Fallback: try npx
let npx_check = resolved_command("npx")
let npx_check = Command::new("npx")
.arg("ccusage")
.arg("--help")
.stdout(std::process::Stdio::null())
@@ -103,7 +106,7 @@ fn build_command() -> Option<Command> {
.status();
if npx_check.map(|s| s.success()).unwrap_or(false) {
let mut cmd = resolved_command("npx");
let mut cmd = Command::new("npx");
cmd.arg("ccusage");
return Some(cmd);
}
+16 -16
View File
@@ -1,7 +1,7 @@
use crate::tracking;
use crate::utils::resolved_command;
use anyhow::{Context, Result};
use std::ffi::OsString;
use std::process::Command;
#[derive(Debug, Clone, Copy)]
pub enum ContainerCmd {
@@ -27,13 +27,13 @@ pub fn run(cmd: ContainerCmd, args: &[String], verbose: u8) -> Result<()> {
fn docker_ps(_verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let raw = resolved_command("docker")
let raw = Command::new("docker")
.args(["ps"])
.output()
.map(|o| String::from_utf8_lossy(&o.stdout).to_string())
.unwrap_or_default();
let output = resolved_command("docker")
let output = Command::new("docker")
.args([
"ps",
"--format",
@@ -84,13 +84,13 @@ fn docker_ps(_verbose: u8) -> Result<()> {
fn docker_images(_verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let raw = resolved_command("docker")
let raw = Command::new("docker")
.args(["images"])
.output()
.map(|o| String::from_utf8_lossy(&o.stdout).to_string())
.unwrap_or_default();
let output = resolved_command("docker")
let output = Command::new("docker")
.args(["images", "--format", "{{.Repository}}:{{.Tag}}\t{{.Size}}"])
.output()
.context("Failed to run docker images")?;
@@ -160,7 +160,7 @@ fn docker_logs(args: &[String], _verbose: u8) -> Result<()> {
return Ok(());
}
let output = resolved_command("docker")
let output = Command::new("docker")
.args(["logs", "--tail", "100", container])
.output()
.context("Failed to run docker logs")?;
@@ -184,7 +184,7 @@ fn docker_logs(args: &[String], _verbose: u8) -> Result<()> {
fn kubectl_pods(args: &[String], _verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("kubectl");
let mut cmd = Command::new("kubectl");
cmd.args(["get", "pods", "-o", "json"]);
for arg in args {
cmd.arg(arg);
@@ -285,7 +285,7 @@ fn kubectl_pods(args: &[String], _verbose: u8) -> Result<()> {
fn kubectl_services(args: &[String], _verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("kubectl");
let mut cmd = Command::new("kubectl");
cmd.args(["get", "services", "-o", "json"]);
for arg in args {
cmd.arg(arg);
@@ -365,7 +365,7 @@ fn kubectl_logs(args: &[String], _verbose: u8) -> Result<()> {
return Ok(());
}
let mut cmd = resolved_command("kubectl");
let mut cmd = Command::new("kubectl");
cmd.args(["logs", "--tail", "100", pod]);
for arg in args.iter().skip(1) {
cmd.arg(arg);
@@ -529,7 +529,7 @@ pub fn run_docker_passthrough(args: &[OsString], verbose: u8) -> Result<()> {
if verbose > 0 {
eprintln!("docker passthrough: {:?}", args);
}
let status = resolved_command("docker")
let status = Command::new("docker")
.args(args)
.status()
.context("Failed to run docker")?;
@@ -551,7 +551,7 @@ pub fn run_compose_ps(verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
// Raw output for token tracking
let raw_output = resolved_command("docker")
let raw_output = Command::new("docker")
.args(["compose", "ps"])
.output()
.context("Failed to run docker compose ps")?;
@@ -564,7 +564,7 @@ pub fn run_compose_ps(verbose: u8) -> Result<()> {
let raw = String::from_utf8_lossy(&raw_output.stdout).to_string();
// Structured output for parsing (same pattern as docker_ps)
let output = resolved_command("docker")
let output = Command::new("docker")
.args([
"compose",
"ps",
@@ -595,7 +595,7 @@ pub fn run_compose_ps(verbose: u8) -> Result<()> {
pub fn run_compose_logs(service: Option<&str>, verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("docker");
let mut cmd = Command::new("docker");
cmd.args(["compose", "logs", "--tail", "100"]);
if let Some(svc) = service {
cmd.arg(svc);
@@ -633,7 +633,7 @@ pub fn run_compose_logs(service: Option<&str>, verbose: u8) -> Result<()> {
pub fn run_compose_build(service: Option<&str>, verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("docker");
let mut cmd = Command::new("docker");
cmd.args(["compose", "build"]);
if let Some(svc) = service {
cmd.arg(svc);
@@ -674,7 +674,7 @@ pub fn run_compose_passthrough(args: &[OsString], verbose: u8) -> Result<()> {
if verbose > 0 {
eprintln!("docker compose passthrough: {:?}", args);
}
let status = resolved_command("docker")
let status = Command::new("docker")
.arg("compose")
.args(args)
.status()
@@ -699,7 +699,7 @@ pub fn run_kubectl_passthrough(args: &[OsString], verbose: u8) -> Result<()> {
if verbose > 0 {
eprintln!("kubectl passthrough: {:?}", args);
}
let status = resolved_command("kubectl")
let status = Command::new("kubectl")
.args(args)
.status()
.context("Failed to run kubectl")?;
+3 -2
View File
@@ -1,11 +1,12 @@
use crate::json_cmd;
use crate::tracking;
use crate::utils::{resolved_command, truncate};
use crate::utils::truncate;
use anyhow::{Context, Result};
use std::process::Command;
pub fn run(args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("curl");
let mut cmd = Command::new("curl");
cmd.arg("-s"); // Silent mode (no progress bar)
for arg in args {
+5 -4
View File
@@ -2,10 +2,11 @@ use crate::binlog;
use crate::dotnet_format_report;
use crate::dotnet_trx;
use crate::tracking;
use crate::utils::{resolved_command, truncate};
use crate::utils::truncate;
use anyhow::{Context, Result};
use std::ffi::OsString;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::sync::atomic::{AtomicU64, Ordering};
use std::time::{SystemTime, UNIX_EPOCH};
@@ -28,7 +29,7 @@ pub fn run_restore(args: &[String], verbose: u8) -> Result<()> {
pub fn run_format(args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let (report_path, cleanup_report_path) = resolve_format_report_path(args);
let mut cmd = resolved_command("dotnet");
let mut cmd = Command::new("dotnet");
cmd.env(DOTNET_CLI_UI_LANGUAGE, DOTNET_CLI_UI_LANGUAGE_VALUE);
cmd.arg("format");
@@ -79,7 +80,7 @@ pub fn run_passthrough(args: &[OsString], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let subcommand = args[0].to_string_lossy().to_string();
let mut cmd = resolved_command("dotnet");
let mut cmd = Command::new("dotnet");
cmd.env(DOTNET_CLI_UI_LANGUAGE, DOTNET_CLI_UI_LANGUAGE_VALUE);
cmd.arg(&subcommand);
for arg in &args[1..] {
@@ -123,7 +124,7 @@ fn run_dotnet_with_binlog(subcommand: &str, args: &[String], verbose: u8) -> Res
// For test commands, prefer user-provided results directory; otherwise create isolated one.
let (trx_results_dir, cleanup_trx_results_dir) = resolve_trx_results_dir(subcommand, args);
let mut cmd = resolved_command("dotnet");
let mut cmd = Command::new("dotnet");
cmd.env(DOTNET_CLI_UI_LANGUAGE, DOTNET_CLI_UI_LANGUAGE_VALUE);
cmd.arg(subcommand);
+4 -3
View File
@@ -1,9 +1,10 @@
use crate::prettier_cmd;
use crate::ruff_cmd;
use crate::tracking;
use crate::utils::{package_manager_exec, resolved_command};
use crate::utils::package_manager_exec;
use anyhow::{Context, Result};
use std::path::Path;
use std::process::Command;
/// Detect formatter from project files or explicit argument
fn detect_formatter(args: &[String]) -> String {
@@ -71,9 +72,9 @@ pub fn run(args: &[String], verbose: u8) -> Result<()> {
// Build command based on formatter
let mut cmd = match formatter.as_str() {
"prettier" => package_manager_exec("prettier"),
"black" | "ruff" => resolved_command(formatter.as_str()),
"black" | "ruff" => Command::new(formatter.as_str()),
"biome" => package_manager_exec("biome"),
_ => resolved_command(formatter.as_str()),
_ => Command::new(formatter.as_str()),
};
// Add formatter-specific flags
+17 -16
View File
@@ -5,11 +5,12 @@
use crate::git;
use crate::tracking;
use crate::utils::{ok_confirmation, resolved_command, truncate};
use crate::utils::{ok_confirmation, truncate};
use anyhow::{Context, Result};
use lazy_static::lazy_static;
use regex::Regex;
use serde_json::Value;
use std::process::Command;
lazy_static! {
static ref HTML_COMMENT_RE: Regex = Regex::new(r"(?s)<!--.*?-->").unwrap();
@@ -202,7 +203,7 @@ fn run_pr(args: &[String], verbose: u8, ultra_compact: bool) -> Result<()> {
fn list_prs(args: &[String], _verbose: u8, ultra_compact: bool) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("gh");
let mut cmd = Command::new("gh");
cmd.args([
"pr",
"list",
@@ -303,7 +304,7 @@ fn view_pr(args: &[String], _verbose: u8, ultra_compact: bool) -> Result<()> {
return run_passthrough_with_extra("gh", &["pr", "view", &pr_number], &extra_args);
}
let mut cmd = resolved_command("gh");
let mut cmd = Command::new("gh");
cmd.args([
"pr",
"view",
@@ -474,7 +475,7 @@ fn pr_checks(args: &[String], _verbose: u8, _ultra_compact: bool) -> Result<()>
None => return Err(anyhow::anyhow!("PR number required")),
};
let mut cmd = resolved_command("gh");
let mut cmd = Command::new("gh");
cmd.args(["pr", "checks", &pr_number]);
for arg in &extra_args {
cmd.arg(arg);
@@ -557,7 +558,7 @@ fn pr_checks(args: &[String], _verbose: u8, _ultra_compact: bool) -> Result<()>
fn pr_status(_verbose: u8, _ultra_compact: bool) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("gh");
let mut cmd = Command::new("gh");
cmd.args([
"pr",
"status",
@@ -613,7 +614,7 @@ fn run_issue(args: &[String], verbose: u8, ultra_compact: bool) -> Result<()> {
fn list_issues(args: &[String], _verbose: u8, ultra_compact: bool) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("gh");
let mut cmd = Command::new("gh");
cmd.args(["issue", "list", "--json", "number,title,state,author"]);
for arg in args {
@@ -685,7 +686,7 @@ fn view_issue(args: &[String], _verbose: u8) -> Result<()> {
None => return Err(anyhow::anyhow!("Issue number required")),
};
let mut cmd = resolved_command("gh");
let mut cmd = Command::new("gh");
cmd.args([
"issue",
"view",
@@ -781,7 +782,7 @@ fn run_workflow(args: &[String], verbose: u8, ultra_compact: bool) -> Result<()>
fn list_runs(args: &[String], _verbose: u8, ultra_compact: bool) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("gh");
let mut cmd = Command::new("gh");
cmd.args([
"run",
"list",
@@ -883,7 +884,7 @@ fn view_run(args: &[String], _verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("gh");
let mut cmd = Command::new("gh");
cmd.args(["run", "view", &run_id]);
for arg in &extra_args {
cmd.arg(arg);
@@ -959,7 +960,7 @@ fn run_repo(args: &[String], _verbose: u8, _ultra_compact: bool) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("gh");
let mut cmd = Command::new("gh");
cmd.arg("repo").arg("view");
for arg in rest_args {
@@ -1029,7 +1030,7 @@ fn run_repo(args: &[String], _verbose: u8, _ultra_compact: bool) -> Result<()> {
fn pr_create(args: &[String], _verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("gh");
let mut cmd = Command::new("gh");
cmd.args(["pr", "create"]);
for arg in args {
cmd.arg(arg);
@@ -1067,7 +1068,7 @@ fn pr_create(args: &[String], _verbose: u8) -> Result<()> {
fn pr_merge(args: &[String], _verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("gh");
let mut cmd = Command::new("gh");
cmd.args(["pr", "merge"]);
for arg in args {
cmd.arg(arg);
@@ -1125,7 +1126,7 @@ fn pr_diff(args: &[String], _verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("gh");
let mut cmd = Command::new("gh");
cmd.args(["pr", "diff"]);
for arg in gh_args.iter() {
cmd.arg(arg);
@@ -1160,7 +1161,7 @@ fn pr_action(action: &str, args: &[String], _verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let subcmd = &args[0];
let mut cmd = resolved_command("gh");
let mut cmd = Command::new("gh");
cmd.arg("pr");
for arg in args {
cmd.arg(arg);
@@ -1220,7 +1221,7 @@ fn run_api(args: &[String], _verbose: u8) -> Result<()> {
fn run_passthrough_with_extra(cmd: &str, base_args: &[&str], extra_args: &[String]) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut command = resolved_command(cmd);
let mut command = Command::new(cmd);
for arg in base_args {
command.arg(arg);
}
@@ -1251,7 +1252,7 @@ fn run_passthrough_with_extra(cmd: &str, base_args: &[&str], extra_args: &[Strin
fn run_passthrough(cmd: &str, subcommand: &str, args: &[String]) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut command = resolved_command(cmd);
let mut command = Command::new(cmd);
command.arg(subcommand);
for arg in args {
command.arg(arg);
+1 -2
View File
@@ -1,5 +1,4 @@
use crate::tracking;
use crate::utils::{resolved_command, truncate};
use anyhow::{Context, Result};
use std::ffi::OsString;
use std::process::Command;
@@ -23,7 +22,7 @@ pub enum GitCommand {
/// Create a git Command with global options (e.g. -C, -c, --git-dir, --work-tree)
/// prepended before any subcommand arguments.
fn git_cmd(global_args: &[String]) -> Command {
let mut cmd = resolved_command("git");
let mut cmd = Command::new("git");
for arg in global_args {
cmd.arg(arg);
}
+6 -5
View File
@@ -1,9 +1,10 @@
use crate::tracking;
use crate::utils::{resolved_command, truncate};
use crate::utils::truncate;
use anyhow::{Context, Result};
use serde::Deserialize;
use std::collections::HashMap;
use std::ffi::OsString;
use std::process::Command;
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
@@ -39,7 +40,7 @@ struct PackageResult {
pub fn run_test(args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("go");
let mut cmd = Command::new("go");
cmd.arg("test");
// Force JSON output if not already specified
@@ -98,7 +99,7 @@ pub fn run_test(args: &[String], verbose: u8) -> Result<()> {
pub fn run_build(args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("go");
let mut cmd = Command::new("go");
cmd.arg("build");
for arg in args {
@@ -151,7 +152,7 @@ pub fn run_build(args: &[String], verbose: u8) -> Result<()> {
pub fn run_vet(args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("go");
let mut cmd = Command::new("go");
cmd.arg("vet");
for arg in args {
@@ -209,7 +210,7 @@ pub fn run_other(args: &[OsString], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let subcommand = args[0].to_string_lossy();
let mut cmd = resolved_command("go");
let mut cmd = Command::new("go");
cmd.arg(&*subcommand);
for arg in &args[1..] {
+3 -2
View File
@@ -1,8 +1,9 @@
use crate::tracking;
use crate::utils::{resolved_command, truncate};
use crate::utils::truncate;
use anyhow::{Context, Result};
use serde::Deserialize;
use std::collections::HashMap;
use std::process::Command;
#[derive(Debug, Deserialize)]
struct Position {
@@ -33,7 +34,7 @@ struct GolangciOutput {
pub fn run(args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("golangci-lint");
let mut cmd = Command::new("golangci-lint");
// Force JSON output
let has_format = args
+4 -8
View File
@@ -1,8 +1,8 @@
use crate::tracking;
use crate::utils::resolved_command;
use anyhow::{Context, Result};
use regex::Regex;
use std::collections::HashMap;
use std::process::Command;
pub fn run(
pattern: &str,
@@ -23,7 +23,7 @@ pub fn run(
// Fix: convert BRE alternation \| → | for rg (which uses PCRE-style regex)
let rg_pattern = pattern.replace(r"\|", "|");
let mut rg_cmd = resolved_command("rg");
let mut rg_cmd = Command::new("rg");
rg_cmd.args(["-n", "--no-heading", &rg_pattern, path]);
if let Some(ft) = file_type {
@@ -40,11 +40,7 @@ pub fn run(
let output = rg_cmd
.output()
.or_else(|_| {
resolved_command("grep")
.args(["-rn", pattern, path])
.output()
})
.or_else(|_| Command::new("grep").args(["-rn", pattern, path]).output())
.context("grep/rg failed")?;
let stdout = String::from_utf8_lossy(&output.stdout);
@@ -278,7 +274,7 @@ mod tests {
fn test_rg_always_has_line_numbers() {
// grep_cmd::run() always passes "-n" to rg (line 24).
// This test documents that -n is built-in, so the clap flag is safe to ignore.
let mut cmd = resolved_command("rg");
let mut cmd = std::process::Command::new("rg");
cmd.args(["-n", "--no-heading", "NONEXISTENT_PATTERN_12345", "."]);
// If rg is available, it should accept -n without error (exit 1 = no match, not error)
if let Ok(output) = cmd.output() {
+4 -3
View File
@@ -1,9 +1,10 @@
use crate::tracking;
use crate::utils::{ok_confirmation, resolved_command, strip_ansi, truncate};
use crate::utils::{ok_confirmation, strip_ansi, truncate};
use anyhow::{Context, Result};
use lazy_static::lazy_static;
use regex::Regex;
use std::ffi::OsString;
use std::process::Command;
lazy_static! {
static ref EMAIL_RE: Regex =
@@ -26,7 +27,7 @@ fn run_gt_filtered(
) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("gt");
let mut cmd = Command::new("gt");
for part in subcmd {
cmd.arg(part);
}
@@ -170,7 +171,7 @@ pub fn run_other(args: &[OsString], verbose: u8) -> Result<()> {
fn passthrough_gt(subcommand: &str, args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("gt");
let mut cmd = Command::new("gt");
cmd.arg(subcommand);
for arg in args {
cmd.arg(arg);
+5 -3
View File
@@ -1,10 +1,12 @@
use crate::mypy_cmd;
use crate::ruff_cmd;
use crate::tracking;
use crate::utils::{package_manager_exec, resolved_command, truncate};
use crate::utils::{package_manager_exec, truncate};
use anyhow::{Context, Result};
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::process::Command;
#[derive(Debug, Deserialize, Serialize)]
struct EslintMessage {
@@ -88,10 +90,10 @@ pub fn run(args: &[String], verbose: u8) -> Result<()> {
let (linter, explicit) = detect_linter(effective_args);
// Python linters use resolved_command() directly (they're on PATH via pip/pipx)
// Python linters use Command::new() directly (they're on PATH via pip/pipx)
// JS linters use package_manager_exec (npx/pnpm exec)
let mut cmd = if is_python_linter(linter) {
resolved_command(linter)
Command::new(linter)
} else {
package_manager_exec(linter)
};
+2 -2
View File
@@ -1,6 +1,6 @@
use crate::tracking;
use crate::utils::resolved_command;
use anyhow::{Context, Result};
use std::process::Command;
/// Noise directories commonly excluded from LLM context
const NOISE_DIRS: &[&str] = &[
@@ -51,7 +51,7 @@ pub fn run(args: &[String], verbose: u8) -> Result<()> {
// Build ls -la + any extra flags the user passed (e.g. -R)
// Strip -l, -a, -h (we handle all of these ourselves)
let mut cmd = resolved_command("ls");
let mut cmd = Command::new("ls");
cmd.arg("-la");
for flag in &flags {
if flag.starts_with("--") {
+6 -6
View File
@@ -1044,7 +1044,7 @@ fn run_fallback(parse_error: clap::Error) -> Result<()> {
if let Some(filter) = toml_match {
// TOML match: capture stdout for filtering
let result = utils::resolved_command(&args[0])
let result = std::process::Command::new(&args[0])
.args(&args[1..])
.stdin(std::process::Stdio::inherit())
.stdout(std::process::Stdio::piped()) // capture
@@ -1089,7 +1089,7 @@ fn run_fallback(parse_error: clap::Error) -> Result<()> {
}
} else {
// No TOML match: original passthrough behaviour (Stdio::inherit, streaming)
let status = utils::resolved_command(&args[0])
let status = std::process::Command::new(&args[0])
.args(&args[1..])
.stdin(std::process::Stdio::inherit())
.stdout(std::process::Stdio::inherit())
@@ -1848,7 +1848,7 @@ fn main() -> Result<()> {
_ => {
// Passthrough other prisma subcommands
let timer = tracking::TimedExecution::start();
let mut cmd = utils::resolved_command("npx");
let mut cmd = std::process::Command::new("npx");
for arg in &args {
cmd.arg(arg);
}
@@ -1865,7 +1865,7 @@ fn main() -> Result<()> {
}
} else {
let timer = tracking::TimedExecution::start();
let status = utils::resolved_command("npx")
let status = std::process::Command::new("npx")
.arg("prisma")
.status()
.context("Failed to run npx prisma")?;
@@ -1961,7 +1961,7 @@ fn main() -> Result<()> {
Commands::Proxy { args } => {
use std::io::{Read, Write};
use std::process::Stdio;
use std::process::{Command, Stdio};
use std::thread;
if args.is_empty() {
@@ -1997,7 +1997,7 @@ fn main() -> Result<()> {
eprintln!("Proxy mode: {} {}", cmd_name, cmd_args.join(" "));
}
let mut child = utils::resolved_command(cmd_name.as_ref())
let mut child = Command::new(&cmd_name)
.args(&cmd_args)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
+16 -4
View File
@@ -1,16 +1,17 @@
use crate::tracking;
use crate::utils::{resolved_command, strip_ansi, tool_exists, truncate};
use crate::utils::{strip_ansi, truncate};
use anyhow::{Context, Result};
use regex::Regex;
use std::collections::HashMap;
use std::process::Command;
pub fn run(args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = if tool_exists("mypy") {
resolved_command("mypy")
let mut cmd = if which_command("mypy").is_some() {
Command::new("mypy")
} else {
let mut c = resolved_command("python3");
let mut c = Command::new("python3");
c.arg("-m").arg("mypy");
c
};
@@ -46,6 +47,17 @@ pub fn run(args: &[String], verbose: u8) -> Result<()> {
std::process::exit(output.status.code().unwrap_or(1));
}
fn which_command(cmd: &str) -> Option<String> {
Command::new("which")
.arg(cmd)
.output()
.ok()
.filter(|o| o.status.success())
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
}
struct MypyError {
file: String,
line: usize,
+9 -4
View File
@@ -1,18 +1,23 @@
use crate::tracking;
use crate::utils::{resolved_command, strip_ansi, tool_exists, truncate};
use crate::utils::{strip_ansi, truncate};
use anyhow::{Context, Result};
use regex::Regex;
use std::process::Command;
pub fn run(args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
// Try next directly first, fallback to npx if not found
let next_exists = tool_exists("next");
let next_exists = Command::new("which")
.arg("next")
.output()
.map(|o| o.status.success())
.unwrap_or(false);
let mut cmd = if next_exists {
resolved_command("next")
Command::new("next")
} else {
let mut c = resolved_command("npx");
let mut c = Command::new("npx");
c.arg("next");
c
};
+2 -2
View File
@@ -1,6 +1,6 @@
use crate::tracking;
use crate::utils::resolved_command;
use anyhow::{Context, Result};
use std::process::Command;
/// Known npm subcommands that should NOT get "run" injected.
/// Shared between production code and tests to avoid drift.
@@ -74,7 +74,7 @@ const NPM_SUBCOMMANDS: &[&str] = &[
pub fn run(args: &[String], verbose: u8, skip_env: bool) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("npm");
let mut cmd = Command::new("npm");
// Determine if this is "npm run <script>" or another npm subcommand (install, list, etc.)
// Only inject "run" when args look like a script name, not a known npm subcommand.
+17 -5
View File
@@ -1,7 +1,7 @@
use crate::tracking;
use crate::utils::{resolved_command, tool_exists};
use anyhow::{Context, Result};
use serde::Deserialize;
use std::process::Command;
#[derive(Debug, Deserialize)]
struct Package {
@@ -15,7 +15,7 @@ pub fn run(args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
// Auto-detect uv vs pip
let use_uv = tool_exists("uv");
let use_uv = which_command("uv").is_some();
let base_cmd = if use_uv { "uv" } else { "pip" };
if verbose > 0 && use_uv {
@@ -51,7 +51,7 @@ pub fn run(args: &[String], verbose: u8) -> Result<()> {
}
fn run_list(base_cmd: &str, args: &[String], verbose: u8) -> Result<(String, String)> {
let mut cmd = resolved_command(base_cmd);
let mut cmd = Command::new(base_cmd);
if base_cmd == "uv" {
cmd.arg("pip");
@@ -86,7 +86,7 @@ fn run_list(base_cmd: &str, args: &[String], verbose: u8) -> Result<(String, Str
}
fn run_outdated(base_cmd: &str, args: &[String], verbose: u8) -> Result<(String, String)> {
let mut cmd = resolved_command(base_cmd);
let mut cmd = Command::new(base_cmd);
if base_cmd == "uv" {
cmd.arg("pip");
@@ -121,7 +121,7 @@ fn run_outdated(base_cmd: &str, args: &[String], verbose: u8) -> Result<(String,
}
fn run_passthrough(base_cmd: &str, args: &[String], verbose: u8) -> Result<(String, String)> {
let mut cmd = resolved_command(base_cmd);
let mut cmd = Command::new(base_cmd);
if base_cmd == "uv" {
cmd.arg("pip");
@@ -153,6 +153,18 @@ fn run_passthrough(base_cmd: &str, args: &[String], verbose: u8) -> Result<(Stri
Ok((raw.clone(), raw))
}
/// Check if a command exists in PATH
fn which_command(cmd: &str) -> Option<String> {
Command::new("which")
.arg(cmd)
.output()
.ok()
.filter(|o| o.status.success())
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
}
/// Filter pip list JSON output
fn filter_pip_list(output: &str) -> String {
let packages: Vec<Package> = match serde_json::from_str(output) {
+4 -4
View File
@@ -1,5 +1,5 @@
use crate::tracking;
use crate::utils::{detect_package_manager, resolved_command, strip_ansi};
use crate::utils::{detect_package_manager, strip_ansi};
use anyhow::{Context, Result};
use regex::Regex;
use serde::Deserialize;
@@ -246,17 +246,17 @@ pub fn run(args: &[String], verbose: u8) -> Result<()> {
let pm = detect_package_manager();
let mut cmd = match pm {
"pnpm" => {
let mut c = resolved_command("pnpm");
let mut c = std::process::Command::new("pnpm");
c.arg("exec").arg("--").arg("playwright");
c
}
"yarn" => {
let mut c = resolved_command("yarn");
let mut c = std::process::Command::new("yarn");
c.arg("exec").arg("--").arg("playwright");
c
}
_ => {
let mut c = resolved_command("npx");
let mut c = std::process::Command::new("npx");
c.arg("--no-install").arg("--").arg("playwright");
c
}
+5 -5
View File
@@ -1,9 +1,9 @@
use crate::tracking;
use crate::utils::resolved_command;
use anyhow::{Context, Result};
use serde::Deserialize;
use std::collections::HashMap;
use std::ffi::OsString;
use std::process::Command;
use crate::parser::{
emit_degradation_warning, emit_passthrough_warning, truncate_output, Dependency,
@@ -294,7 +294,7 @@ pub fn run(cmd: PnpmCommand, args: &[String], verbose: u8) -> Result<()> {
fn run_list(depth: usize, args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("pnpm");
let mut cmd = Command::new("pnpm");
cmd.arg("list");
cmd.arg(format!("--depth={}", depth));
cmd.arg("--json");
@@ -350,7 +350,7 @@ fn run_list(depth: usize, args: &[String], verbose: u8) -> Result<()> {
fn run_outdated(args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("pnpm");
let mut cmd = Command::new("pnpm");
cmd.arg("outdated");
cmd.arg("--format");
cmd.arg("json");
@@ -411,7 +411,7 @@ fn run_install(packages: &[String], args: &[String], verbose: u8) -> Result<()>
}
}
let mut cmd = resolved_command("pnpm");
let mut cmd = Command::new("pnpm");
cmd.arg("install");
for pkg in packages {
@@ -495,7 +495,7 @@ pub fn run_passthrough(args: &[OsString], verbose: u8) -> Result<()> {
if verbose > 0 {
eprintln!("pnpm passthrough: {:?}", args);
}
let status = resolved_command("pnpm")
let status = Command::new("pnpm")
.args(args)
.status()
.context("Failed to run pnpm")?;
+9 -4
View File
@@ -1,5 +1,4 @@
use crate::tracking;
use crate::utils::{resolved_command, tool_exists};
use anyhow::{Context, Result};
use std::process::Command;
@@ -27,10 +26,16 @@ pub fn run(cmd: PrismaCommand, args: &[String], verbose: u8) -> Result<()> {
/// Create a Command that will run prisma (tries global first, then npx)
fn create_prisma_command() -> Command {
if tool_exists("prisma") {
resolved_command("prisma")
let prisma_exists = Command::new("which")
.arg("prisma")
.output()
.map(|o| o.status.success())
.unwrap_or(false);
if prisma_exists {
Command::new("prisma")
} else {
let mut c = resolved_command("npx");
let mut c = Command::new("npx");
c.arg("prisma");
c
}
+1 -2
View File
@@ -4,7 +4,6 @@
//! and produces compact tab-separated or key=value output.
use crate::tracking;
use crate::utils::resolved_command;
use anyhow::{Context, Result};
use lazy_static::lazy_static;
use regex::Regex;
@@ -22,7 +21,7 @@ lazy_static! {
pub fn run(args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("psql");
let mut cmd = std::process::Command::new("psql");
for arg in args {
cmd.arg(arg);
}
+17 -4
View File
@@ -1,6 +1,7 @@
use crate::tracking;
use crate::utils::{resolved_command, tool_exists, truncate};
use crate::utils::truncate;
use anyhow::{Context, Result};
use std::process::Command;
#[derive(Debug, PartialEq)]
enum ParseState {
@@ -14,11 +15,11 @@ pub fn run(args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
// Try to detect pytest command (could be "pytest", "python -m pytest", etc.)
let mut cmd = if tool_exists("pytest") {
resolved_command("pytest")
let mut cmd = if which_command("pytest").is_some() {
Command::new("pytest")
} else {
// Fallback to python -m pytest
let mut c = resolved_command("python");
let mut c = Command::new("python");
c.arg("-m").arg("pytest");
c
};
@@ -82,6 +83,18 @@ pub fn run(args: &[String], verbose: u8) -> Result<()> {
Ok(())
}
/// Check if a command exists in PATH
fn which_command(cmd: &str) -> Option<String> {
Command::new("which")
.arg(cmd)
.output()
.ok()
.filter(|o| o.status.success())
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
}
/// Parse pytest output using state machine
fn filter_pytest_output(output: &str) -> String {
let mut state = ParseState::Header;
+3 -2
View File
@@ -1,8 +1,9 @@
use crate::tracking;
use crate::utils::{resolved_command, truncate};
use crate::utils::truncate;
use anyhow::{Context, Result};
use serde::Deserialize;
use std::collections::HashMap;
use std::process::Command;
#[derive(Debug, Deserialize)]
struct RuffLocation {
@@ -37,7 +38,7 @@ pub fn run(args: &[String], verbose: u8) -> Result<()> {
let is_format = args.iter().any(|a| a == "format");
let mut cmd = resolved_command("ruff");
let mut cmd = Command::new("ruff");
if is_check {
// Force JSON output for check command
+4 -3
View File
@@ -7,8 +7,8 @@
//! unless -a flag is present (respecting user intent).
use crate::tracking;
use crate::utils::{resolved_command, tool_exists};
use anyhow::{Context, Result};
use std::process::Command;
/// Noise directories commonly excluded from LLM context
const NOISE_DIRS: &[&str] = &[
@@ -44,7 +44,8 @@ pub fn run(args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
// Check if tree is installed
if !tool_exists("tree") {
let tree_check = Command::new("which").arg("tree").output();
if tree_check.is_err() || !tree_check.unwrap().status.success() {
anyhow::bail!(
"tree command not found. Install it first:\n\
- macOS: brew install tree\n\
@@ -54,7 +55,7 @@ pub fn run(args: &[String], verbose: u8) -> Result<()> {
);
}
let mut cmd = resolved_command("tree");
let mut cmd = Command::new("tree");
// Determine if user wants all files or default behavior
let show_all = args.iter().any(|a| a == "-a" || a == "--all");
+9 -4
View File
@@ -1,19 +1,24 @@
use crate::tracking;
use crate::utils::{resolved_command, tool_exists, truncate};
use crate::utils::truncate;
use anyhow::{Context, Result};
use regex::Regex;
use std::collections::HashMap;
use std::process::Command;
pub fn run(args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
// Try tsc directly first, fallback to npx if not found
let tsc_exists = tool_exists("tsc");
let tsc_exists = Command::new("which")
.arg("tsc")
.output()
.map(|o| o.status.success())
.unwrap_or(false);
let mut cmd = if tsc_exists {
resolved_command("tsc")
Command::new("tsc")
} else {
let mut c = resolved_command("npx");
let mut c = Command::new("npx");
c.arg("tsc");
c
};
+16 -298
View File
@@ -7,7 +7,6 @@
use anyhow::{Context, Result};
use regex::Regex;
use std::path::PathBuf;
use std::process::Command;
/// Truncates a string to `max_len` characters, appending `...` if needed.
@@ -34,7 +33,7 @@ pub fn truncate(s: &str, max_len: usize) -> String {
}
}
/// Strip ANSI escape codes (colors, styles) from a string.
/// Strips ANSI escape codes (colors, styles) from a string.
///
/// # Arguments
/// * `text` - Text potentially containing ANSI escape codes
@@ -55,7 +54,7 @@ pub fn strip_ansi(text: &str) -> String {
/// Executes a command and returns cleaned stdout/stderr.
///
/// # Arguments
/// * `cmd` - Command to execute (e.g., "eslint")
/// * `cmd` - Command to execute (e.g. "eslint")
/// * `args` - Command arguments
///
/// # Returns
@@ -69,7 +68,7 @@ pub fn strip_ansi(text: &str) -> String {
/// ```
#[allow(dead_code)]
pub fn execute_command(cmd: &str, args: &[&str]) -> Result<(String, String, i32)> {
let output = resolved_command(cmd)
let output = Command::new(cmd)
.args(args)
.output()
.context(format!("Failed to execute {}", cmd))?;
@@ -84,10 +83,10 @@ pub fn execute_command(cmd: &str, args: &[&str]) -> Result<(String, String, i32)
/// Formats a token count with K/M suffixes for readability.
///
/// # Arguments
/// * `n` - Number of tokens
/// * `n` - Token count
///
/// # Returns
/// Formatted string (e.g., "1.2M", "59.2K", "694")
/// Formatted string (e.g. "1.2M", "59.2K", "694")
///
/// # Examples
/// ```
@@ -230,23 +229,29 @@ pub fn detect_package_manager() -> &'static str {
/// Build a Command using the detected package manager's exec mechanism.
/// Returns a Command ready to have tool-specific args appended.
pub fn package_manager_exec(tool: &str) -> Command {
if tool_exists(tool) {
resolved_command(tool)
let tool_exists = Command::new("which")
.arg(tool)
.output()
.map(|o| o.status.success())
.unwrap_or(false);
if tool_exists {
Command::new(tool)
} else {
let pm = detect_package_manager();
match pm {
"pnpm" => {
let mut c = resolved_command("pnpm");
let mut c = Command::new("pnpm");
c.arg("exec").arg("--").arg(tool);
c
}
"yarn" => {
let mut c = resolved_command("yarn");
let mut c = Command::new("yarn");
c.arg("exec").arg("--").arg(tool);
c
}
_ => {
let mut c = resolved_command("npx");
let mut c = Command::new("npx");
c.arg("--no-install").arg("--").arg(tool);
c
}
@@ -254,68 +259,6 @@ pub fn package_manager_exec(tool: &str) -> Command {
}
}
/// Resolve a binary name to its full path, honoring PATHEXT on Windows.
///
/// On Windows, Node.js tools are installed as `.CMD`/`.BAT`/`.PS1` shims.
/// Rust's `std::process::Command::new()` does NOT honor PATHEXT, so
/// `Command::new("vitest")` fails even when `vitest.CMD` is on PATH.
///
/// This function uses the `which` crate to perform proper PATH+PATHEXT resolution.
///
/// # Arguments
/// * `name` - Binary name (e.g., "vitest", "eslint", "tsc")
///
/// # Returns
/// Full path to the resolved binary, or error if not found.
pub fn resolve_binary(name: &str) -> Result<PathBuf> {
which::which(name).context(format!("Binary '{}' not found on PATH", name))
}
/// Create a `Command` with PATHEXT-aware binary resolution.
///
/// Drop-in replacement for `Command::new(name)` that works on Windows
/// with `.CMD`/`.BAT`/`.PS1` wrappers.
///
/// Falls back to `Command::new(name)` if resolution fails, so native
/// commands (git, cargo) still work even if `which` can't find them.
///
/// # Arguments
/// * `name` - Binary name (e.g., "vitest", "eslint")
///
/// # Returns
/// A `Command` configured with the resolved binary path.
pub fn resolved_command(name: &str) -> Command {
match resolve_binary(name) {
Ok(path) => Command::new(path),
Err(e) => {
// On Windows, resolution failure likely means a .CMD/.BAT wrapper
// wasn't found — always warn so users have a signal.
// On Unix, this is less common; only log in debug builds.
#[cfg(target_os = "windows")]
eprintln!(
"rtk: Failed to resolve '{}' via PATH, falling back to direct exec: {}",
name, e
);
#[cfg(not(target_os = "windows"))]
{
#[cfg(debug_assertions)]
eprintln!(
"rtk: Failed to resolve '{}' via PATH, falling back to direct exec: {}",
name, e
);
}
Command::new(name)
}
}
}
/// Check if a tool exists on PATH (PATHEXT-aware on Windows).
///
/// Replaces manual `Command::new("which").arg(tool)` checks that fail on Windows.
pub fn tool_exists(name: &str) -> bool {
which::which(name).is_ok()
}
#[cfg(test)]
mod tests {
use super::*;
@@ -486,229 +429,4 @@ mod tests {
let result = truncate(cjk, 6);
assert!(result.ends_with("..."));
}
// ===== resolve_binary tests (issue #212) =====
#[test]
fn test_resolve_binary_finds_known_command() {
// "cargo" must be on PATH in any Rust dev environment
let result = resolve_binary("cargo");
assert!(
result.is_ok(),
"resolve_binary('cargo') should succeed, got: {:?}",
result.err()
);
}
#[test]
fn test_resolve_binary_returns_absolute_path() {
let path = resolve_binary("cargo").expect("cargo should be resolvable");
assert!(
path.is_absolute(),
"resolve_binary should return absolute path, got: {:?}",
path
);
}
#[test]
fn test_resolve_binary_fails_for_unknown() {
let result = resolve_binary("nonexistent_binary_xyz_99999");
assert!(
result.is_err(),
"resolve_binary should fail for nonexistent binary"
);
}
#[test]
fn test_resolve_binary_path_contains_binary_name() {
let path = resolve_binary("cargo").expect("cargo should be resolvable");
let filename = path
.file_name()
.expect("should have filename")
.to_string_lossy();
// On Windows this could be "cargo.exe", on Unix just "cargo"
assert!(
filename.starts_with("cargo"),
"resolved path filename should start with 'cargo', got: {}",
filename
);
}
// ===== resolved_command tests (issue #212) =====
#[test]
fn test_resolved_command_executes_known_command() {
let output = resolved_command("cargo")
.arg("--version")
.output()
.expect("resolved_command('cargo') should execute");
assert!(
output.status.success(),
"cargo --version should succeed via resolved_command"
);
}
// ===== tool_exists tests (issue #212) =====
#[test]
fn test_tool_exists_finds_cargo() {
assert!(
tool_exists("cargo"),
"tool_exists('cargo') should return true"
);
}
#[test]
fn test_tool_exists_rejects_unknown() {
assert!(
!tool_exists("nonexistent_binary_xyz_99999"),
"tool_exists should return false for nonexistent binary"
);
}
#[test]
fn test_tool_exists_finds_git() {
assert!(tool_exists("git"), "tool_exists('git') should return true");
}
// ===== Windows-specific PATHEXT resolution tests (issue #212) =====
#[cfg(target_os = "windows")]
mod windows_tests {
use super::super::*;
use std::fs;
/// Create a temporary .cmd wrapper to simulate Node.js tool installation
fn create_temp_cmd_wrapper(dir: &std::path::Path, name: &str) -> std::path::PathBuf {
let cmd_path = dir.join(format!("{}.cmd", name));
fs::write(&cmd_path, "@echo off\r\necho fake-tool-output\r\n")
.expect("failed to create .cmd wrapper");
cmd_path
}
/// Build a PATH string that includes the temp dir
fn path_with_dir(dir: &std::path::Path) -> std::ffi::OsString {
let original = std::env::var_os("PATH").unwrap_or_default();
let mut new_path = std::ffi::OsString::from(dir.as_os_str());
new_path.push(";");
new_path.push(&original);
new_path
}
#[test]
fn test_resolve_binary_finds_cmd_wrapper() {
let temp_dir = tempfile::tempdir().expect("failed to create temp dir");
create_temp_cmd_wrapper(temp_dir.path(), "fake-tool-test");
// Use which::which_in to avoid mutating global PATH (thread-safe)
let search_path = path_with_dir(temp_dir.path());
let result = which::which_in(
"fake-tool-test",
Some(search_path),
std::env::current_dir().unwrap(),
);
assert!(
result.is_ok(),
"which_in should find .cmd wrapper on Windows, got: {:?}",
result.err()
);
let path = result.unwrap();
let ext = path
.extension()
.unwrap_or_default()
.to_string_lossy()
.to_lowercase();
assert!(
ext == "cmd" || ext == "bat",
"resolved path should have .cmd/.bat extension, got: {:?}",
path
);
}
#[test]
fn test_resolve_binary_finds_bat_wrapper() {
let temp_dir = tempfile::tempdir().expect("failed to create temp dir");
let bat_path = temp_dir.path().join("fake-bat-tool.bat");
fs::write(&bat_path, "@echo off\r\necho bat-output\r\n")
.expect("failed to create .bat wrapper");
let search_path = path_with_dir(temp_dir.path());
let result = which::which_in(
"fake-bat-tool",
Some(search_path),
std::env::current_dir().unwrap(),
);
assert!(
result.is_ok(),
"which_in should find .bat wrapper on Windows, got: {:?}",
result.err()
);
}
#[test]
fn test_resolved_command_executes_cmd_wrapper() {
let temp_dir = tempfile::tempdir().expect("failed to create temp dir");
create_temp_cmd_wrapper(temp_dir.path(), "fake-exec-test");
// Resolve the full path, then execute it directly (no PATH mutation)
let search_path = path_with_dir(temp_dir.path());
let resolved = which::which_in(
"fake-exec-test",
Some(search_path),
std::env::current_dir().unwrap(),
)
.expect("should resolve fake-exec-test");
let output = Command::new(&resolved).output();
assert!(
output.is_ok(),
"Command with resolved path should execute .cmd wrapper on Windows"
);
let output = output.unwrap();
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
stdout.contains("fake-tool-output"),
"should get output from .cmd wrapper, got: {}",
stdout
);
}
#[test]
fn test_resolved_command_fallback_on_unknown_binary() {
// When resolve_binary fails, resolved_command should fall back to
// Command::new(name) instead of panicking. On Windows this also
// prints a warning to stderr.
let mut cmd = resolved_command("nonexistent_binary_xyz_99999");
// The Command should be created (not panic). Attempting to run it
// will fail, but that's expected — we just verify the fallback path
// produces a usable Command.
let result = cmd.output();
assert!(
result.is_err() || !result.unwrap().status.success(),
"nonexistent binary should fail to execute, but resolved_command must not panic"
);
}
#[test]
fn test_tool_exists_finds_cmd_wrapper() {
let temp_dir = tempfile::tempdir().expect("failed to create temp dir");
create_temp_cmd_wrapper(temp_dir.path(), "fake-exists-test");
let search_path = path_with_dir(temp_dir.path());
let result = which::which_in(
"fake-exists-test",
Some(search_path),
std::env::current_dir().unwrap(),
);
assert!(
result.is_ok(),
"which_in should find .cmd wrapper on Windows"
);
}
}
}
+2 -2
View File
@@ -7,13 +7,13 @@
/// - `wc -c file.py` → `978`
/// - `wc -l *.py` → table with common path prefix stripped
use crate::tracking;
use crate::utils::resolved_command;
use anyhow::{Context, Result};
use std::process::Command;
pub fn run(args: &[String], verbose: u8) -> Result<()> {
let timer = tracking::TimedExecution::start();
let mut cmd = resolved_command("wc");
let mut cmd = Command::new("wc");
for arg in args {
cmd.arg(arg);
}
+3 -3
View File
@@ -1,6 +1,6 @@
use crate::tracking;
use crate::utils::resolved_command;
use anyhow::{Context, Result};
use std::process::Command;
/// Compact wget - strips progress bars, shows only result
pub fn run(url: &str, args: &[String], verbose: u8) -> Result<()> {
@@ -19,7 +19,7 @@ pub fn run(url: &str, args: &[String], verbose: u8) -> Result<()> {
}
cmd_args.push(url);
let output = resolved_command("wget")
let output = Command::new("wget")
.args(&cmd_args)
.output()
.context("Failed to run wget")?;
@@ -64,7 +64,7 @@ pub fn run_stdout(url: &str, args: &[String], verbose: u8) -> Result<()> {
}
cmd_args.push(url);
let output = resolved_command("wget")
let output = Command::new("wget")
.args(&cmd_args)
.output()
.context("Failed to run wget")?;