Repository navigation
fix(hook): rewrite the first command of a loop body - #5113
Open
seragAhmed wants to merge 1 commit into
Open
seragAhmed wants to merge 1 commit into
seragAhmed wants to merge 1 commit into
Conversation
`for f in a b; do rg -n x "$f"; done` was passed through unchanged: once the line is split on `;`, the body's first command sits behind `do`, which the rewrite did not read past. `do` now joins the keyword prefixes (`exec`, `command`, ...), so the rewrite reads past it, and so does deny/ask rule matching. The body of a loop whose output is piped (`...; done | wc -l`) writes to the consumer, not the agent, so its commands are left raw. Command substitutions are left alone, as agreed in the issue. Fixes rtk-ai#5110 Co-Authored-By: Claude Opus 5.5 <[email protected]>
📊 Automated PR Analysis
SummaryFixes a hook command-rewrite bug where the first command inside a for/while/until loop body was not being prefixed/matched because it sits behind the Review Checklist
Linked issues: #5110 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
Author
|
Hi, a gentle follow-up on this one. #5117 (keeping backslash-newline inside quotes and comments) is ready for review too. Happy to adjust either if you'd like. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5110
for/while/untilbody is now rewritten:for f in a b; do rg -n x "$f"; done→for f in a b; do rtk rg -n x "$f"; done. After splitting on;, that command sits behinddo, sodojoins the keyword prefixes (exec,command,noglob, ...). Deny/ask rule matching reads that list too, so a deny rule forgit pushstill fires ondo git push .......; done | wc -l) keeps its whole body raw, since that output goes to the consumer, not the agent. Before this, commands after the first one in such a body were already rewritten.$(...)and backticks are left alone, as agreed in the issue. The loop header (while git diff --quiet; do) is unchanged too. Multi-line loops still pass through as a whole, as before.Test plan
cargo fmt --all && cargo clippy --all-targets && cargo test. Clippy is clean. All discover/hooks tests pass. Two tests fail on Windows (find_cmd::run_from_args_propagates_find_exit_status,stream::test_read_lines_lossy_preserves_lines_after_invalid_utf8), and they fail on unmodifieddeveloptoo.for/while/until, nested,&&inside), header and substitutions untouched, piped loops raw, and a deny rule firing on a loop body. The rewrite and deny tests fail without the change, and the piped-loop test fails without the guard.rtk hook claude:for f in a b; do rg -n x "$f"; donefor f in a b; do rtk rg -n x "$f"; donefor f in a b; do rg -n x "$f"; done | wc -lx=$(rg -n foo)🤖 Generated with Claude Code