Skip to content

feat(core): make portable shell scanner authoritative - #42581

Merged
kitlangton merged 3 commits into
v2from
shell-scanner-parity
Aug 14, 2026
Merged

kitlangton merged 3 commits into
v2from
shell-scanner-parity

Conversation

@kitlangton

@kitlangton kitlangton commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

What

Reintroduce the portable Bash and PowerShell permission scanner behind the disabled-by-default experimental.portable_shell_scanner flag.

When enabled, the portable scanner is authoritative: tree-sitter is neither loaded nor run. Supported syntax preserves the default scanner's ordered command resources, reusable save patterns, and inferred directories. Unsupported syntax requests normal shell authorization for the untouched command and infers no external directories.

Before / After

Before

The previous scanner replacement treated a static heredoc as opaque, converted that uncertainty into an unknown directory, and requested external_directory: "*". A scoped external-directory deny then blocked the command even when shell access was allowed. The first guarded version of this PR avoided that regression by always running tree-sitter and using it as a runtime fallback.

After

With the experiment enabled, OpenCode uses only the portable scanner. Opaque input is authorized as the original shell command and never invents an external-directory wildcard. With the experiment disabled, the existing tree-sitter path is unchanged.

How

  • packages/schema and Core config normalization add the opt-in experimental flag.
  • packages/core/src/shell/parse.ts branches before tree-sitter initialization and adapts portable structural output into legacy-compatible ordered resources, source-shaped save patterns, and directories.
  • packages/core/src/tool/plugin/shell.ts selects the portable path from effective config while preserving the default.
  • packages/shell-scan scans static Bash and PowerShell command positions, marks unsupported syntax opaque, and preserves nested-command discovery order.
  • packages/core/test/shell-parse-parity.test.ts compares 21,863 deterministic supported cases directly against tree-sitter.
  • Disposable research scripts and their CI steps were removed from the shipped package.

Scope

  • Does not remove or change the default tree-sitter scanner.
  • Does not use tree-sitter as a compatibility check or runtime fallback when the experiment is enabled.
  • Does not infer directories from opaque commands.
  • Does not add wildcard authorization for uncertain paths.
  • Does not change ordered last-match-wins permission evaluation.

Testing

  • Bounded differential search: 330,667 Bash and PowerShell programs; 329,803 supported scans; 864 intentionally opaque; 0 supported mismatches.
  • Real-shell dispatch check: 3,275 generated programs on Bash 5.3, Bash 3.2, and zsh 5.9; 0 missing dispatched commands.
  • packages/core: bun run test (1,761 passed, 16 skipped), bun typecheck.
  • packages/shell-scan: bun run test (274 passed), bun typecheck.
  • Changed files: Prettier check and git diff --check pass.
  • Repository-wide bun run lint and bun run lint:effect-patterns remain red on pre-existing unrelated diagnostics; targeted Oxlint reports 0 errors.

Flow

flowchart TD
  A[Shell invocation] --> B{portable_shell_scanner?}
  B -- false --> C[Load and run tree-sitter]
  B -- true --> D[Run portable scanner]
  D --> E{Supported syntax?}
  E -- yes --> F[Authorize compatible command resources and directories]
  E -- no --> G[Authorize untouched shell command]
  G --> H[Infer no directories]
  C --> I[Apply ordered permission rules]
  F --> I
  H --> I
Loading

@kitlangton
kitlangton force-pushed the shell-scanner-parity branch from 65922c8 to 3b82a3e Compare August 14, 2026 14:14
@kitlangton kitlangton changed the title feat(core): add guarded portable shell scanner feat(core): make portable shell scanner authoritative Aug 14, 2026
@kitlangton
kitlangton merged commit b0480a6 into v2 Aug 14, 2026
12 of 14 checks passed
@kitlangton
kitlangton deleted the shell-scanner-parity branch August 14, 2026 15:06
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant