Skip to content

feat: add PowerShell Core (pwsh) tool#13648

Open
ilude wants to merge 3 commits intoanomalyco:devfrom
ilude:feat/pwsh-tool-pr
Open

feat: add PowerShell Core (pwsh) tool#13648
ilude wants to merge 3 commits intoanomalyco:devfrom
ilude:feat/pwsh-tool-pr

Conversation

@ilude
Copy link
Copy Markdown

@ilude ilude commented Feb 14, 2026

Summary

Adds a dedicated pwsh tool alongside the existing bash tool. Works on any platform where PowerShell Core is installed. Uses tree-sitter-powershell for AST-based permission analysis and spawns pwsh -NoProfile -NonInteractive -Command.

What changed

  • pwsh tool (pwsh.ts): tree-sitter parsing, path resolution, permission/auto-approval logic

  • Windows security (pwsh-windows.ts): Windows-only hardening gated behind process.platform === "win32" — encoded command detection, execution policy bypass, download-and-execute cradles, registry critical-path blocking, provider-aware read/write checks, BLOCK > ASK > ALLOW decision model

  • Permission analysis (pwsh-arity.ts): PowerShell-specific arity table for cmdlets, aliases, and external tools

  • UI wiring: routes pwsh through existing bash rendering paths in TUI, web share view, and i18n labels across 15 locales

Verification

From packages/opencode:

  • bun test test/tool/pwsh.test.ts — 32 pass, 0 fail
  • bun test test/tool/pwsh-windows.test.ts — 82 pass, 0 fail
  • bun test test/permission/pwsh-arity.test.ts — 12 pass, 0 fail
  • bun run typecheck — clean

Fixes #8924
Fixes #6703
Refs #8136
Refs #4683
Refs #11288

If the linked issues aren't sufficient to justify this feature, happy to open a design discussion first, just let me know.

Add a dedicated pwsh tool alongside the existing bash tool for Windows
PowerShell support. The tool uses tree-sitter-powershell for AST-based
permission analysis, mirrors bash tool patterns for truncation and
external_directory checks, and spawns pwsh with -NoProfile
-NonInteractive -Command.

Core tool:
- pwsh.ts: full tool with tree-sitter parsing, path resolution,
  permission patterns, and auto-approval logic
- pwsh.txt: tool description template
- pwsh-arity.ts: PowerShell-specific arity table for permission patterns
- shell.ts: pwsh detection via Bun.which
- registry.ts: conditional PwshTool registration behind feature flag

Windows security (pwsh-windows.ts):
- Bypass detection: encoded commands, execution policy bypass,
  download-and-execute cradles, hidden windows, remoting, scheduled
  tasks, AMSI bypass, Add-Type/assembly loading
- cmd.exe nested command analysis with destructive pattern checks
- Registry protection: critical path block list, provider-aware
  read/write checks for HKCU/HKLM/Cert/WSMan/Env
- Decision model: BLOCK > ASK > ALLOW, fail-closed on parse ambiguity

UI support:
- TUI: route pwsh tool through bash-style rendering
- UI: PowerShell syntax highlighting for pwsh tool output
- Web: handle pwsh in share view
- i18n: add pwsh tool label across all 15 locales

Fixes anomalyco#8924
Refs anomalyco#6703
Tests:
- pwsh tool: execution, permissions, external_directory, Set-Location,
  redirections, path forms, tilde/$HOME, MSYS paths, truncation
- pwsh-windows: bypass techniques, cmd.exe patterns, registry/provider
  path checks, evaluate precedence (173 tests total)
- pwsh-arity: cmdlet, alias, and external tool arity tables

Fix test infrastructure: close SQLite database in preload afterAll
before deleting temp directory. The lazy Database singleton holds file
locks on .db/.db-shm/.db-wal which cause EBUSY on Windows cleanup.
@ilude ilude force-pushed the feat/pwsh-tool-pr branch from 751869b to 4022843 Compare February 15, 2026 03:05
@Blues-star
Copy link
Copy Markdown

"It seems like the CI has been running for a while. Is it stuck?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants