fix(agent-guard): scope Segment.raw to its own tokens, not the whole command - #1151
Open
AmirF194 wants to merge 1 commit into
Open
fix(agent-guard): scope Segment.raw to its own tokens, not the whole command#1151AmirF194 wants to merge 1 commit into
AmirF194 wants to merge 1 commit into
Conversation
…command split_segments() passed the entire compound command as `raw` for every segment it produced, so guard_commit_trailer's Co-Authored-By scan could fire on a segment whose own text never mentioned it. raw is now shlex.join(current), a reconstruction of that segment's own tokens. Fixes apache#1150 Generated-by: Claude Code (Sonnet 5)
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.
split_segments()builds everySegmentin a compound command asSegment(current, command), passing the whole input string asrawregardless of which segment it is.guard_commit_trailersearchesseg.rawforco-authored-by:, so it was really searching the entire line, not the commit's own message. Agit commitwith a clean message gets denied if an unrelated earlier segment (a comment, a grep, an echo) happens to contain that phrase.Fixed by giving each segment
raw = shlex.join(current), a reconstruction of that segment's own tokens only. It still supports the heredoc-survival case the docstring describes:shlex.splitdoesn't parse<<specially, so a heredoc's delimiter and body just become ordinary tokens attached to the segment they trail, andshlex.joinputs them back as one searchable string. Checked the field's only other reader,GuardContext.raw: none of the fourguards.d/skill-contributed guards use it, so the fix's blast radius is exactly the one guard this issue is about.Added
test_compound_command_other_segment_not_denied, the new test breaks without the change and passes with it. Fulltools/agent-guardsuite (92 tests), ruff, ruff format and mypy all come back clean in apython:3.11-slimcontainer.Fixes #1150