Skip to content

Terminal auto-approve: a partially-failed tree-sitter parse can still auto-approve #328108

Open

Description

Follow up to #328052 and #328107. Workbench runInTerminal path, live on main.

Problem

When tree-sitter cannot fully parse a command line it still produces a partial tree, and extractSubCommands happily returns the captures it found. Those partial captures can omit executable parts of the line, so the sub-commands that were captured can all match allow rules and the line auto-approves — while the parts the parser dropped still run.

Evidence

Measured against the real PowerShell grammar:

'ls; ./x.sh'              hasError=true   captures = ["ls"]        <- "./x.sh" dropped
'ls; npm run test -- --foo' hasError=true captures = ["ls"]        <- rest dropped
'echo hi; $x='            hasError=true   captures = ["echo hi"]   <- rest dropped

ls matches the default allow rule, so the line auto-approves and ./x.sh executes without confirmation.

Both triggers are common in agent-emitted commands:

  • a bare -- separator (npm run test -- --grep x)
  • ./path at command position (./scripts/test.sh)

Existing precedent

The Agent Host auto-approver already guards this — commandAutoApprover.ts returns undefined (→ requires confirmation) when tree.rootNode.hasError is set for a PowerShell parse, with the rationale that an erroring parse can produce truncated captures that hide part of the command line from rule matching.

The workbench has no equivalent gate: commandLineAutoApproveAnalyzer.ts only bails when !subCommands?.length, i.e. when the parse produced nothing. A partial parse proceeds normally.

Suggested fix

Treat an errored parse as unanalyzable and require confirmation, matching the Agent Host.

Two consequences worth designing for:

  1. Roughly 8% of realistic agent-emitted commands fail to parse under the PowerShell grammar (measured 3/36 on a sample of plausible commands), so this will add prompts. Tracked separately as tree-sitter PowerShell grammar cannot parse ~8% of realistic agent commands, blocking auto-approve suggestions #328110.
  2. Users need an escape hatch for those commands. See the companion issue about honouring explicit matchCommandLine rules before parsing.

Activity

  1. added
    bug
    terminal
    on Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugterminal

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions