Repository navigation
Conversation
Execute positional run, err, test, and summary commands directly instead of reconstructing them for sh -c. Add explicit shell selection for command strings while retaining the platform defaults for run -c. BREAKING CHANGE: positional arguments for run, err, test, and summary no longer receive implicit shell expansion; use -c or --shell with one quoted script when shell syntax is required.
Treat bare parentheses, command-position control keywords, and incomplete quoting as unattestable so hooks neither rewrite nor auto-allow commands whose shell semantics are uncertain.
Rewrite portable commands inside exact sh, bash, zsh, and fish -c scripts while preserving their original quoting and suffix arguments. Require confirmation for wrapper rewrites and evaluate deny rules against parsed inner command segments. Refs: rtk-ai#2767
|
I cannot test for now, but thanks. I'm curious about feedbacks that you will get |
|
@pashifika — heads up that I rebased this work onto current What changed in the rebase:
I would rather not step on your PR. If you would prefer to refresh this one yourself, say so and I will close #3828 — happy either way, and no attribution concerns from my side. If you have no plans to pick it back up, #3828 is ready and should close this when it lands. |
|
@SindriFr thanks for the rebase — no attribution concerns here either, and dropping the Closing this in favour of #3828 plus #3911, which is the rest of this PR rebased onto your branch: the argv-boundary work, the fish-aware unattestable gate, |
Summary
This pull request makes RTK's shell boundary explicit across CLI execution and hook rewriting. Generic runners now preserve argv through direct execution, intentional scripts require an explicit command-string mode, ambiguous shell syntax defers unchanged, and exact quoted
sh,bash,zsh, andfishwrappers can safely rewrite portable inner commands.This addresses four related limitations in the current execution model:
rtk run,rtk err,rtk test, andrtk summaryrebuilt positional arguments with spaces and executed the result throughsh -con Unix orcmd /Con Windows, which lost argument boundaries and enabled unintended shell expansion.$SHELLwhile evaluating commands with zsh or a POSIX-compatible shell, so guessing the parser from the environment is unreliable.bash -c "head foo && grep -R bar ."were treated as opaque wrapper arguments, so the portable commands inside them could not use RTK rewrites as reported inrtk bash -candrtk fish -cwrapping #2767.The host still owns the shell that evaluates hook output. This change makes RTK's own execution and rewrite boundaries explicit; it does not translate syntax between fish, zsh, and POSIX shells or change the host executor.
Execution model and migration
The updated CLI separates direct argv execution from intentional command-string execution:
rtk run <cmd> [args...],rtk err <cmd> [args...],rtk test <cmd> [args...], andrtk summary <cmd> [args...]execute the supplied program directly and preserve every argument boundary.rtk run -c '<script>'retains the existing platform default ofsh -con Unix andcmd /Con Windows.rtk run --shell fish -c '<script>'selects a shell explicitly. PowerShell andpwshuse-Command; other named shells use-c.rtk err,rtk test, andrtk summaryaccept--shell <name> '<script>'when filtering an intentional shell command.rtk run --shell <name> -c '<script>'for shell-specific scripts and portable syntax otherwise.This is a breaking behavior change for callers that relied on implicit shell expansion in positional arguments. Those callers must move shell syntax to
rtk run -c '<script>'or use--shell <name>with one quoted script.Conservative hook handling
The shared lexer now treats the following forms as unattestable before rewrite and permission decisions:
(...)syntax;and,or,if,switch, andendwhen they occur at a command boundary.Keyword detection is command-position aware, so ordinary arguments such as
rg and srcremain attestable. Ambiguous constructs defer to the host unchanged and resolve toAskrather thanAllow, even when a wildcard allow rule is configured.Quoted shell wrapper rewriting
The rewrite pipeline now recognizes a deliberately narrow command-string wrapper subset:
sh -c,bash -c,zsh -c, andfish -cwrappers are eligible when the script is one balanced single- or double-quoted argument.$expansion, backticks, or backslash escapes to evaluate.The wrapper parser is shared by rewriting and permission evaluation so the two paths cannot disagree about the supported boundary. Agent protocol tests cover Claude, Cursor, Gemini, Droid, and Copilot behavior.
Key files changed
The following files are the main review entry points:
src/core/shell.rssrc/main.rs--shellCLI surface and routes positional commands through direct argv execution.src/discover/lexer.rssrc/discover/shell_wrapper.rs-cwrapper subset and exposes byte spans without decoding or re-quoting scripts.src/discover/registry.rssrc/hooks/permissions.rsAsk.src/hooks/hook_cmd.rshooks/codex/rtk-awareness.mdtests/run_shell_test.rstests/rewrite_shell_wrapper_test.rsTest plan
cargo fmt --all --check.cargo clippy --all-targets -- -D warnings.tests/rewrite_shell_wrapper_test.rs.env RIPGREP_CONFIG_PATH=/dev/null cargo test --all(2,478 unit tests passed, 8 ignored; all integration suites passed).env RIPGREP_CONFIG_PATH=/dev/null cargo test --all -- --ignored --nocapture(8 ignored integration tests passed).cargo build --release.sh,zsh, andfishexecution, and quotedbash -candfish -crewriting on macOS.cmd /C, PowerShell flag selection, and platform-independent wrapper parsing.The local ripgrep configuration injects
--max-columns=150, which shortens the raw comparison output used by the existingbulky_grep_yields_token_savingstest. The unsanitizedcargo test --allrun therefore fails that unrelated assertion; the complete suite passes whenRIPGREP_CONFIG_PATHis cleared as shown above. This pull request does not change search behavior.The broad
scripts/test-all.shsuite was not run because it uses an installed binary and includesgit fetch, external HTTP calls, and unrelated ecosystem commands.🤖 Generated with Codex