GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): make the portable PowerShell scanner sound against real pwsh by kitlangton · Pull Request #53404 · anomalyco/opencode

Conversation

@kitlangton

@kitlangton kitlangton commented Oct 5, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Why

Following #53277 (which unified the Bash/POSIX portable shell scanner into a single recursive-descent parser), the PowerShell side of packages/core/src/shell/scan.ts still relied on three separate lexers (scanPowerShellNested, powerShellBlock, and powerShellExpansions) that independently decided where $(...), {...}, (...), [...], @"..."@, and comments end. Whenever the pre-scanner and the command scanner disagreed on a block, quote, or comment boundary, commands and Set-Location directory changes executed by real PowerShell were silently swallowed as comments or string literals:

$x = "$(switch ${x}#)
{ default { Invoke-ProbeA; Set-Location /outside } })"

${x}<# comment #>; Invoke-ProbeA; Set-Location /outside
"$("a""; Invoke-ProbeA; "b"")"
${a`u{0041}'}; Invoke-ProbeA; Set-Location /outside; #'
$probe[-$(Invoke-ProbeA)]

Conversely, mid-token @' / @" (ssh user@'host'), \n"@ inside @"..."@ subexpressions, and bareword switch conditions containing # (switch ('a#b') { a#b { ... } }) failed with false opacity.

What Changes

scanPowerShell is now a single cursor-based recursive-descent parser (scanPowerShellList), and powerShellBlock and powerShellExpansions are deleted (scan.ts grows by only 13 lines net while closing all known desyncs):

Input Before After
$x = "$(switch ${x}#)\n{ default { Invoke-ProbeA } })" [] Invoke-ProbeA
${x}<# comment #>; Invoke-ProbeA [] Invoke-ProbeA
"$("a""; Invoke-ProbeA; "b"")" [] Invoke-ProbeA
${a`u{0041}'}; Invoke-ProbeA; #' [] Invoke-ProbeA
$probe[-$(Invoke-ProbeA)] [] Invoke-ProbeA
Write-Output [a; Invoke-ProbeA; Write-Output ] Write-Output only Write-Output, Invoke-ProbeA, Write-Output
ssh user@'host' opaque (fails) ssh
Set-Location -p:/outside, -l:/outside, '-outside', /out`side directories: [] directories: ["/outside"] (or ["-outside"])
ForEach-Object -InputObject $proc -MemberName Kill commands: [] ForEach-Object

Recursive Parsing & Token Alignment

  • In-place recursion: ( ... ), { ... }, [ ... ], $( ... ), @( ... ), @{ ... }, and "..." / @"..."@ subexpressions recurse directly into scanPowerShellList(input, start, depth, budget, close, hash) and end where the inner parse ends.
  • Single-pass @"..."@ & ${...} escapes: expandable here-strings scan ` escapes, ${...} (via powerShellBracedVariable, including `u{...}), and $(...) inline while searching for the closing \n"@, so \n"@ inside a subexpression cannot close the outer here-string early.
  • Doubled quotes inside "$(...)": tracks inDoubleQuote across subexpressions inside "..." so "" closes inner double-quoted strings and """" represents an escaped quote, matching PowerShell's lexer.
  • Contextual keywords & comment boundaries: until, else/elseif, catch/finally, and param only enter compound headers in their valid syntactic context; <# ... #> is recognized after expression tokens without misclassifying mid-word # in bareword switch conditions or data -SupportedCommand arguments.
  • Sticky regexes & consolidated clause state: replaces per-character input.slice(index) regexes with hoisted sticky /.../y regexes and collapses the 5 compound-header booleans into one clause state.

Scope

This PR touches only the PowerShell scanner in packages/core/src/shell/scan.ts (the Bash section is byte-identical to v2), PowerShell directory/command handling in packages/core/src/shell/parse.ts, and the PowerShell test suites. Tree-sitter remains the default behind experimental.portable_shell_scanner.

Verification

cd packages/core
SHELL_SCAN_PWSH=/path/to/pwsh SHELL_ORACLE_STRICT=1 bun run test test/shell-scan test/shell-parse-parity.test.ts test/shell-parse-compatibility.test.ts test/shell-parse-syntax.test.ts test/shell-parse.test.ts test/tool-shell.test.ts
bun typecheck
cd ../.. && bun run check
  • Test suites (with PowerShell 7.6.6 and Bash 3.2/5.3, Zsh 5.9, Dash): 3,479 pass, 0 fail.
  • PowerShell AST & runtime oracle (powershell-runtime.test.ts): verified against [System.Management.Automation.Language.Parser]::ParseInput and runtime execution in PowerShell 7.6.6.
  • Repo check: bun run check passes all 36/36 tasks.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
kitlangton added 4 commits October 5, 2026 10:07
@kitlangton
fix(core): unify PowerShell scanner into recursive-descent parser
bcc9677
@kitlangton
test(core): add PowerShell scanner and parser regressions
562f1e8
@kitlangton
fix(core): harden PowerShell scanner and directory extraction
6a9e1c9
@kitlangton
test(core): cover PowerShell scanner and directory edge cases
e965027
@github-actions github-actions Bot added the contributor label Oct 5, 2026
kitlangton added 2 commits October 5, 2026 12:34
@kitlangton
fix(core): align PowerShell subexpression, token, and directory scann…
68fab14
…ing with pwsh
@kitlangton
fix(core): align PowerShell subexpression escapes, stop-parsing, and …
9fbb571
…member access with pwsh
@kitlangton
kitlangton merged commit 9d387f6 into v2 Oct 5, 2026
10 of 13 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@kitlangton
kitlangton deleted the powershell-scan-parser branch October 5, 2026 21:07
@kitlangton kitlangton mentioned this pull request Oct 6, 2026
feat(core): enable portable shell scanner on local and dev channels #53479
Merged
@neriousy neriousy mentioned this pull request Oct 21, 2026
core: shell permission scanning on runtimes without tree-sitter WASM (workerd) #42184
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

contributor

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@kitlangton
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.