Repository navigation
fix(core): explain unanalyzable shell commands - #54218
kitlangton wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Looks good. I reproduced the bare command-substitution error on the base with the portable scanner. With this PR, the same command is still refused, and the error now explains how to rewrite it. The single-quoted and "$(cat file)" forms scan the same way before and after, and PowerShell never gets the bash-specific backtick hint. The shell-parse, parity and tool-shell tests pass (132 passed, 42 skipped), and the packages/core typecheck passes.
Public API: unchanged, apart from the new error text and the internal ShellParse.opaqueMessage export.
One small point: in tool-shell.test.ts, the first two new tests (substitution passthrough and the cat * deny rule) cover behaviour that already worked on the base. The backtick test is the one that checks this change, so the other two can be dropped to keep the change minimal.
1ba28e7 to
983c71a
Compare
There was a problem hiding this comment.
The only change since my last review is a rebase onto the current base. It also updates one existing shell-parse.test.ts assertion that checked the old error text. Nothing new to raise. The shell-parse, parity and tool-shell tests pass in packages/core, and tsc -b passes. The package's typecheck script fails on the base as well, because the installed Bun has no bun check.
Public API: unchanged.
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Why
When the portable shell scanner can't analyze a command, the shell tool refuses it with only a reason code:
Agents most often hit this when they put Markdown in a double-quoted argument, for example
note add --body "uses `vec3(1.0)` here" Title. Bash treats those backticks as command substitution and would try to runvec3(1.0)as a command. Refusing is correct, but the error doesn't explain what went wrong or how to fix it, so agents keep retrying variations or give up.What Changes
The scanner still refuses commands it can't analyze, and they still never run. The error now says the command was not run, keeps the reason code, and explains how to rewrite the command.
Before
After
Every
OpaqueReasonnow has its own hint, such as "A quote is not closed." or "A redirection is missing its target or is not allowed here."note add --body "uses `vec3(1.0)` here" Tnote add --body 'uses `vec3(1.0)` here' Tnote add --body "$(cat notes.md)" Tnote add …andcat notes.mdare checked as separate resourcesnote add --body "$(cat notes.md)" Twithcat *deniedPermission Safety
I chose not to fall back to asking for approval. The default policy allows every
shellresource, so a whole-command fallback resource would be auto-allowed. That would let commands inside an unanalyzed substitution get past deny rules likecat *orrm *. The permissions docs also say tree-sitter is not a fallback and that there is no extra approval mode. This PR leaves those rules unchanged and updates the docs to describe the clearer error and how substitutions are checked.Scope
This PR changes only the scanner's error messages, adds tests and updates the docs. Adding a forced-approval fallback for unanalyzable commands would need a new Permission mode that ignores allow rules. That belongs in its own PR if we want it.
Verification
tool-shell.test.ts: 93 passed, 19 skipped (Windows and PowerShell). New end-to-end tests use the real Permission service and a realsh:printf '%s' "$(cat body.md)"reproduces a Markdown file containing backticks byte for byte.cat *deny rule blocks the same command, and its marker file is never written.`vec3(1.0)`returns the new message without running or asking for permission. The single-quoted rewrite runs.