Repository navigation
Conversation
…ack (#1911) ## Summary When the guard's primary tokenizer cannot parse a command's quoting, most often because an apostrophe sits in a trailing comment, the fallback split each line plainly and saw no operators. A loop like `while ! <check>; do sleep 30; done # the PR's checks` then went unseen (#1635). - The per-line fallback now isolates operators on any line that parses on its own. A line that does not parse falls back to plain splitting, as before. - `_strip_comments` strips every comment over the whole command, and carries plain-quote state across lines as bash does. The stripped text is parsed before the per-line fallback runs. - The strip is skipped wherever bash nests a context the scan does not model: a heredoc, `((`, an extglob opener, backslashes, backticks, and `$(`, `${`, `$'` and `$"`. - When the strip is used, develop's plain per-line tokens are appended after its tokens. The strip can then reveal a command the base fallback missed, but can never hide one it saw. - `_heredoc_opener` keeps the base tokenizer, with no comment stripping. The line flagged `comment-added` by the prose gate is the existing `shlex` commenters comment, moved unchanged into the shared `_operator_lex` helper. ## Verification - The self-test passes. It includes new cases for a quote spanning lines, arithmetic and extglob `#`, and a `=~` regex `#`, each proven to fail without its fix. - A differential fuzz against develop ran 30,000 generated commands per run. None went from deny to allow on the final head. - Across all runs, bash with stubbed `gh` and `git` confirmed that every earlier deny-to-allow flip was a write inside a real comment. Bash never runs any of them. - No deny appears that develop would not make and the previous head allowed. The remaining allow-to-deny cases are the #1635 fix: unbounded loops that develop missed. - Three recorded local strict-review passes. The last found only a false deny in the per-line fallback, filed as #1910. Closes on promotion: #1635 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved shell command handling when quotes are malformed or comments appear, so operators and subsequent commands are interpreted more reliably. * Improved recognition of heredoc openers and wait loops with trailing comments, while preserving the behavior of quoted operators. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
|
Warning Review limit reachedNext included review available in 52 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository: ptr727/ProjectTemplate/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
|
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The new comment-stripping fallback is currently skipped for many common commands (e.g., those containing $(, ${...}, or \\), which still allows unbounded wait loops to bypass Rule 7 when an apostrophe appears in a trailing # comment.
Review effort: Lite
Findings: 1
What changed in this PR
This promotion PR brings the updated gh-write-guard.py shell-token fallback from develop to main, aiming to prevent unbounded-wait-loop bypasses when shlex fails on apostrophes in trailing # comments by stripping comments and isolating operators during fallback tokenization.
Changes:
- Add a whole-command comment-stripping fallback (
_strip_comments) and operator-isolating tokenization helpers to improve detection when primary tokenization fails. - Adjust heredoc opener parsing to explicitly disable comment stripping for that path.
- Expand the self-test corpus with cases covering comment stripping, quote carryover across lines, and the original apostrophe-in-comment bypass shape.
| File | Description |
|---|---|
| host-setup/agent-safety/claude/gh-write-guard.py | Improves fallback shell tokenization by stripping comments and isolating operators, plus additional self-tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Summary
Promotes develop to main. It carries one change:
When
gh-write-guard.py's primary tokenizer cannot parse a command's quoting, most often because of an apostrophe in a trailing comment, the fallback now strips comments over the whole command, carrying quote state across lines, before parsing it again. Where the strip is used, develop's plain per-line tokens are appended after its result, so the strip can reveal a loop or write the old fallback missed but never hide one it saw. A line that parses on its own also gets its operators isolated. A differential fuzz found no command that develop denies and this change allows.Fixes #1635
Follow-ups filed from its reviews
=~regex#that still hides a loop, and a backslash inside a comment that turns the strip off. None is a regression against develop.Review coverage
CodeRabbit rate-limited its review of this pull request, so this promotion rests on its review of #1911, which read
0341099a. The content is identical, and any reader can re-run both checks:git rev-parse 0341099a^{tree}andgit rev-parse 9bd3f231^{tree}both print23b0f7d9b8ac6c5a347deef924e65ce662e945de.git diff 9bd3f231^ 9bd3f231 | sha256sumandgit diff origin/main origin/develop | sha256summatch.Copilot reviewed this head in full. Its one finding, another shape the skip list leaves uncovered and not a regression, is deferred to #1910.
Needs the maintainer
🤖 Generated with Claude Code