feat(opencode): auto-approve safe bash commands using tree-sitter classification#20301
Open
AndresCdo wants to merge 4 commits intoanomalyco:devfrom
Open
feat(opencode): auto-approve safe bash commands using tree-sitter classification#20301AndresCdo wants to merge 4 commits intoanomalyco:devfrom
AndresCdo wants to merge 4 commits intoanomalyco:devfrom
Conversation
…ssification Add a classify() function that analyzes the parsed command AST to determine if a bash command is safe to auto-approve without prompting the user. Uses three-tier classification: 1. Dangerous patterns override everything (pipe to shell, rm -rf /) 2. Dangerous command blacklist (rm, dd, kill, shutdown) 3. Safe command whitelist (ls, cat, grep, find, git status, etc.) Context-aware subcommand checks for git, npm, pnpm, yarn, bun, go, and cargo to distinguish safe subcommands from destructive ones. Commands classified as safe skip the permission prompt entirely, dramatically improving UX during codebase exploration and read-only operations. Closes anomalyco#20298
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found one potentially related PR: PR #12684: feat: add --yolo flag for auto-approving permissions in web/serve mode Why it's related: This PR also addresses auto-approval of permissions, though it uses a broad These are complementary approaches rather than strict duplicates—one is a global permission flag, the other is context-aware command analysis. |
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.
Issue for this PR
Closes #20298
Type of change
What does this PR do?
Adds an auto-approval classifier for bash commands that uses the existing tree-sitter parser to identify safe, read-only commands and skip permission prompts for them.
How it works: The
classify()function analyzes the parsed command AST using three tiers:rm -rf /, redirect to disk device)rm,dd,kill,shutdown,chmod, etc.)ls,cat,grep,find,wc,head,tail,git status/log/diff,echo,pwd, etc.)Context-aware subcommand checks for
git,npm,pnpm,yarn,bun,go, andcargoto distinguish safe subcommands from destructive ones (e.g.,git statusis safe,git pushis not).Impact: Eliminates permission prompts for safe read-only operations, dramatically improving UX during codebase exploration and diagnostic operations.
How did you verify your code works?
bun typecheckpasses (zero errors in changed files)tool/bash.tsScreenshots / recordings
Not a UI change.
Checklist