You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(bots): accept shlex-quoted shell wrappers so Look around can save Codex suggestions - #48660
When a Codex bot runs Look around and wants to save a suggestion like orca bot suggest --title 'Follow up', Codex hands Orca the command wrapped in /bin/zsh -lc ... with extra quoting. Orca only knew one style of that quoting, so it couldn't see the real command and refused it. Now Orca reads the quoting Codex actually uses, then checks the real command the same way as before.
Files
Added
Deleted
Net
Test
1
$\color{#1a7f37}{\Huge{\mathbf{+}}}$21
0
$\color{#1a7f37}{\Huge{\mathbf{+}}}$21
Prod
1
$\color{#1a7f37}{\Huge{\mathbf{+}}}$13
$\color{#cf222e}{\Huge{\mathbf{−}}}$4
$\color{#1a7f37}{\Huge{\mathbf{+}}}$9
What Changed
Before: Any Codex Look around command with a quoted multi-word value (orca bot suggest --title 'Follow up' --why '...' --ask '...', gh pr list --search 'a b') stayed wrapped as /bin/zsh -lc ..., so the read-only policy saw /bin/zsh and refused it. Suggestions were never saved.
After: Those commands are unwrapped to the script and pass the same read-only checks as an unwrapped command. Anything that still isn't a plain read (; rm x, $(id), backticks, !) is refused as before.
Mechanism: Codex builds the approval text with shlex_join(["/bin/zsh", "-lc", script]) (codex-rs/app-server/src/bespoke_event_handling.rs). shlex double-quotes a script that contains a ', or splits it into '...' and "..." runs. SHELL_WRAPPER in src/main/bots/bot-look-around-shell-syntax.ts now accepts the wrapped word as a sequence of literal runs: 'single', "double" with no $, ` or ! and only the \" and \\ escapes, and \'. unwrapShell decodes those runs to the script. Adjacent single-quoted runs ('a''b') are not accepted, because zsh's RC_QUOTES reads '' as a literal '. That would make the decoded text differ from what zsh runs.
Why
The approval text is the only thing Orca sees, and it is produced by shlex, not by Orca's earlier '\''-only assumption. Decoding just the literal subset of shlex output keeps the policy strict: any form that could expand or run something in bash, zsh (with or without RC_QUOTES) or dash stays wrapped and is refused. The other options were less safe. Loosening the read-only allow-list would let more commands through, and a general shell parser could get expansions wrong.
N/A. This changes how the main-process approval policy parses a command string. There is no UI change, and the evidence is the parser output below (before: refused, after: unwrapped and allowed).
Testing
Repro: replayed the issue's command /bin/zsh -lc 'orca bot suggest --title '"'"'Follow up'"'"' ...' and the double-quoted shlex form against unwrapShell and the Look around policy. On main it stays wrapped and is refused as "/bin/zsh" isn't a read. On this branch it unwraps to orca bot suggest --title 'Follow up' ... and is allowed.
Added 17 cases to src/main/bots/bot-look-around-policy.test.ts. They cover double-quoted and split-run shlex output, chained ${ORCA_CLI_COMMAND:-orca} calls with \", and \\ and ! runs. Refusals cover ; rm x, $(id), backticks, \" and ! inside double quotes, unbalanced runs, and the RC_QUOTES 'a'';rm y;' bypass. The new allow cases fail on main.
Probe (not committed): shlex 1.3.0 joins of generated scripts decoded exactly (74,388 unwrapped, 0 misdecodes). Accepted random words decoded identically under bash, zsh -f, zsh -f -o rc_quotes and dash.
vitest run src/main/bots/bot-look-around-policy.test.ts: 158 passed. oxlint, oxfmt, anti-slop, code-quality native plugins, ast-grep and the changed-code quality gate are clean on both files.
Platforms: macOS. The code path is POSIX-shell only (shell === 'bash'). PowerShell handling is unchanged.
Performance
None, because unwrapShell runs once per Look around command approval in the main process. That path is not hot: it doesn't run per render, per keystroke, on terminal output or on a poll. It adds no I/O or subprocesses. Micro-benchmark, old vs new regex plus decode:
typical /bin/zsh -lc 'git status': 0.07 µs vs 0.16 µs per call
issue command (86 chars): 0.02 µs vs 0.39 µs per call
adversarial 30–100 KB inputs (thousands of alternating runs, long \\ chains, 100 KB unterminated quote): worst case 0.26 ms. No catastrophic backtracking, because each alternative starts on a different character. The 100 KB unterminated case is faster than the old regex (77 µs vs 192 µs).
Risk
Level: Low. The riskiest part is the policy boundary: a decoding mismatch could let a non-read through. Mitigations: only literal runs are accepted, the decoded script still goes through every existing check, and decoding was cross-checked against four shells. A plain revert restores the old behavior, where Codex suggestions are refused again.
Review
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
… Codex suggestions
Codex sends a command approval as shlex_join(["/bin/zsh", "-lc", script]).
shlex double-quotes a script that contains a single quote, or splits it
into '...' and "..." runs, so every Look around command with a quoted
value (orca bot suggest --title 'Follow up' ...) stayed wrapped and was
refused.
Read the wrapped word as literal runs: '...', "..." with no $, ` or !
and only shlex's \" and \\ escapes, and \'. Adjacent single-quoted runs
stay wrapped because zsh's RC_QUOTES reads '' as a quote. The decoded
script then goes through the same read-only checks as before.
Fixes#48624
No actionable comments were generated in the recent review.
Walkthrough
unwrapShell now decodes wrapped commands composed of adjacent single-quoted, restricted double-quoted, and escaped-single-quote runs. The policy tests cover valid read commands and commands that remain denied, including commands with rm or command substitution.
Severity of issue fixed: Medium
Merge Risk: Minimal · up to 6ebbd
This change lets Look around save suggestions with multi-word quoted arguments while keeping shell expansion and chaining refused. No concrete merge-blocking risk was found in the reviewed parser or its policy path.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: Look around can now save Codex suggestions because shlex-quoted shell wrappers are accepted. It matches the raw summary, which describes unwrapShell accepting Codex sh…
Linked Issues check
[#48624] requires a Codex-backed Look around run to save a suggestion with spaces under the existing read-only policy. The reported repro uses a zsh-wrapped command with double-quoted apostrophes (`'"…
Out of Scope Changes check
The whole-PR change (merge base 7f2a281 to head 6ebbdc6) touches the shell-wrapper parsing in bot-look-around-shell-syntax.ts and its policy tests. Both directly implement the #48624 objective of un…
Description check
The description follows the repository template closely. It has an ELI5, a detailed What Changed section with before and after behavior and mechanism, a Why section that explains the chosen approach a…
Full details: Title check
Explanation
The title names the main change: Look around can now save Codex suggestions because shlex-quoted shell wrappers are accepted. It matches the raw summary, which describes unwrapShell accepting Codex shell-wrapper commands made of adjacent literal quoted runs, and the policy test additions. The title uses the fix(bots) convention and is specific, so it passes.
Full details: Linked Issues check
Explanation
[#48624] requires a Codex-backed Look around run to save a suggestion with spaces under the existing read-only policy. The reported repro uses a zsh-wrapped command with double-quoted apostrophes ('"'"'). At head, SHELL_WRAPPER in src/main/bots/bot-look-around-shell-syntax.ts accepts adjacent single-quoted runs, double-quoted runs without $, backtick, or !, and \' escapes. unwrapShell decodes those runs with LITERAL_RUN, so the wrapped orca bot suggest ... command reaches the existing read-only checks. The previous '\'' form is still decoded. Adjacent single-quoted runs ('a''b') are rejected, which keeps the decoded text aligned with zsh's RC_QUOTES reading. The PR also reports 17 added policy test cases in src/main/bots/bot-look-around-policy.test.ts. I did not re-run those tests. I did not re-read the Rust shlex_join source in codex-rs, so the match between the Codex output and the accepted grammar rests on the reported probe and the issue's repro.
Full details: Out of Scope Changes check
Explanation
The whole-PR change (merge base 7f2a281 to head 6ebbdc6) touches the shell-wrapper parsing in bot-look-around-shell-syntax.ts and its policy tests. Both directly implement the #48624 objective of unwrapping Codex-quoted commands. The change does not loosen the read-only allow-list, and PowerShell handling is unchanged. The related issues #46064, #48395, and #48411 are not targeted, and the PR does not claim to address them. The PR description's agent-skill checkbox is non-code and does not affect the diff.
Full details: Description check
Explanation
The description follows the repository template closely. It has an ELI5, a detailed What Changed section with before and after behavior and mechanism, a Why section that explains the chosen approach and the alternatives rejected, a linked issue (Fixes #48624), and a Visual Proof section marked N/A with a reason. The Testing section lists the reproduction steps, the 17 added test cases, the cross-shell probe, the vitest result, and the platform tested (macOS). The Performance section gives a one-line justification with measurements. The Risk section states the level (Low), names the riskiest part, and explains the revert path. The Agent skill upstream boundary box is checked. Minor gaps: the AI Disclosure section is blank, the Testing checkboxes are not ticked, and the Checklist is not reflected in the body. None of these is critical. The description is mostly complete.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 804ae879-e24d-41df-a6bb-ab70abf17eca
Commits
Reviewing files that changed from the base of the PR and between 4843fe1 and 6ebbdc6.
Files selected for processing: 2
src/main/bots/bot-look-around-policy.test.ts
src/main/bots/bot-look-around-shell-syntax.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
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
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.
ELI5
When a Codex bot runs Look around and wants to save a suggestion like
orca bot suggest --title 'Follow up', Codex hands Orca the command wrapped in/bin/zsh -lc ...with extra quoting. Orca only knew one style of that quoting, so it couldn't see the real command and refused it. Now Orca reads the quoting Codex actually uses, then checks the real command the same way as before.What Changed
orca bot suggest --title 'Follow up' --why '...' --ask '...',gh pr list --search 'a b') stayed wrapped as/bin/zsh -lc ..., so the read-only policy saw/bin/zshand refused it. Suggestions were never saved.; rm x,$(id), backticks,!) is refused as before.shlex_join(["/bin/zsh", "-lc", script])(codex-rs/app-server/src/bespoke_event_handling.rs). shlex double-quotes a script that contains a', or splits it into'...'and"..."runs.SHELL_WRAPPERinsrc/main/bots/bot-look-around-shell-syntax.tsnow accepts the wrapped word as a sequence of literal runs:'single',"double"with no$,`or!and only the\"and\\escapes, and\'.unwrapShelldecodes those runs to the script. Adjacent single-quoted runs ('a''b') are not accepted, because zsh'sRC_QUOTESreads''as a literal'. That would make the decoded text differ from what zsh runs.Why
The approval text is the only thing Orca sees, and it is produced by shlex, not by Orca's earlier
'\''-only assumption. Decoding just the literal subset of shlex output keeps the policy strict: any form that could expand or run something in bash, zsh (with or without RC_QUOTES) or dash stays wrapped and is refused. The other options were less safe. Loosening the read-only allow-list would let more commands through, and a general shell parser could get expansions wrong.Linked Issue
Fixes #48624
Visual Proof
N/A. This changes how the main-process approval policy parses a command string. There is no UI change, and the evidence is the parser output below (before: refused, after: unwrapped and allowed).
Testing
/bin/zsh -lc 'orca bot suggest --title '"'"'Follow up'"'"' ...'and the double-quoted shlex form againstunwrapShelland the Look around policy. On main it stays wrapped and is refused as"/bin/zsh" isn't a read. On this branch it unwraps toorca bot suggest --title 'Follow up' ...and is allowed.src/main/bots/bot-look-around-policy.test.ts. They cover double-quoted and split-run shlex output, chained${ORCA_CLI_COMMAND:-orca}calls with\", and\\and!runs. Refusals cover; rm x,$(id), backticks,\"and!inside double quotes, unbalanced runs, and the RC_QUOTES'a'';rm y;'bypass. The new allow cases fail on main.zsh -f,zsh -f -o rc_quotesand dash.vitest run src/main/bots/bot-look-around-policy.test.ts: 158 passed. oxlint, oxfmt, anti-slop, code-quality native plugins, ast-grep and the changed-code quality gate are clean on both files.shell === 'bash'). PowerShell handling is unchanged.Performance
None, because
unwrapShellruns once per Look around command approval in the main process. That path is not hot: it doesn't run per render, per keystroke, on terminal output or on a poll. It adds no I/O or subprocesses. Micro-benchmark, old vs new regex plus decode:/bin/zsh -lc 'git status': 0.07 µs vs 0.16 µs per call\\chains, 100 KB unterminated quote): worst case 0.26 ms. No catastrophic backtracking, because each alternative starts on a different character. The 100 KB unterminated case is faster than the old regex (77 µs vs 192 µs).Risk
Level: Low. The riskiest part is the policy boundary: a decoding mismatch could let a non-read through. Mitigations: only literal runs are accepted, the decoded script still goes through every existing check, and decoding was cross-checked against four shells. A plain revert restores the old behavior, where Codex suggestions are refused again.
Review
Agent skill upstream boundary
Notes
Reported by @Hello-Pig