Skip to content

feat: support PowerShell 7 for Windows local shell - #9622

Draft
wcqqq1214 wants to merge 6 commits into
AstrBotDevs:masterfrom
wcqqq1214:feat/windows-shell-config
Draft

feat: support PowerShell 7 for Windows local shell#9622
wcqqq1214 wants to merge 6 commits into
AstrBotDevs:masterfrom
wcqqq1214:feat/windows-shell-config

Conversation

@wcqqq1214

@wcqqq1214 wcqqq1214 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #9614

On Windows, the Local runtime hardcodes powershell.exe (Windows PowerShell 5.1) when executing shell commands, so users who have PowerShell 7 installed cannot use its syntax features (such as && and ??). This PR lets users pick which PowerShell to use from the WebUI, keeping powershell.exe as the default.

Modifications / 改动点

  • astrbot/core/config/default.py: adds the provider_settings.windows_shell option with values powershell.exe / pwsh.exe, labelled "Windows PowerShell 5.1" / "PowerShell 7", defaulting to powershell.exe, and shown only when computer_use_runtime is local.
  • astrbot/core/computer/booters/local.py: the win32 branches of exec() and exec_managed() now launch the configured PowerShell. When the configured executable is not on PATH (checked only when os.name == "nt"), a clear RuntimeError is raised instead of silently falling back to another shell.
  • astrbot/core/tools/computer_tools/shell.py: ExecuteShellTool reads the umo-scoped config value and forwards it to exec_managed().
  • astrbot/core/astr_main_agent.py: the Local mode system prompt now distinguishes PowerShell 5.1 / PowerShell 7 / non-Windows, so the model does not emit syntax the target shell cannot parse.
  • dashboard/src/i18n/locales/{en-US,ru-RU,zh-CN}: translations for the new option.
  • tests/: 8 new cases covering the configured switch, the default value, the missing-executable error, non-Windows platforms being unaffected, and the system prompt branches.

No new dependencies. Default behaviour is identical to before this change (an absent windows_shell resolves to powershell.exe), and non-Windows code paths are untouched.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

The new option in the WebUI, shown under Provider Settings when computer_use_runtime is set to local:

Screenshot 2026-08-10 at 23 56 45

The dropdown offers "Windows PowerShell 5.1" and "PowerShell 7", defaulting to the former. It is gated on computer_use_runtime == "local" via the existing condition mechanism, so it stays hidden for users who are not on the Local runtime.

Local unit tests

The win32 branches are covered on macOS by faking sys.platform / os.name
via monkeypatch.

$ uv run python -m pytest tests/test_local_shell_component.py tests/unit/test_astr_main_agent.py tests/unit/test_func_tool_manager.py -q
149 passed, 3 warnings

The full project test suite also passes locally:

$ uv run pytest tests -q
2116 passed, 12 warnings

Windows end-to-end validation

Manual validation was performed by @Donoym on:

  • Windows 11 Pro 64-bit
  • DisplayVersion: 25H2
  • Build: 26200
  • Python: 3.12.13
  • PowerShell 7: 7.6.4

Configuration:

  • computer_use_runtime = local
  • Default windows_shell = powershell.exe

Results:

  • windows_shell = pwsh.exe: PowerShell 7.6.4
  • windows_shell = powershell.exe: Windows PowerShell 5.1.26100.8972
  • Write-Output 'a' && Write-Output 'b': output was a, b
  • Invalid executable path: returned a clear “executable was not found” error without silently falling back

The invalid-path test was followed by a separate model-level attempt to use Python to locate PowerShell. This was not a fallback performed by the shell runtime.

Cross-platform test findings

The initial Windows pytest run, before the portability fixes, reported:

  • 142 passed
  • 7 failed
  • 3 warnings

The failures were caused by platform-specific test assumptions involving Windows CRLF output, Windows path separators, and incomplete platform simulation.

Local verification after the test fixes:

  • Focused tests: 149 passed, 3 warnings
  • Full project tests: 2116 passed, 12 warnings

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Make the Windows local runtime shell configurable and propagate the selected PowerShell variant through execution and prompting logic.

New Features:

  • Add a provider setting to choose the Windows shell executable (Windows PowerShell 5.1 vs PowerShell 7) for local computer use runtime.
  • Update the local mode system prompt to describe the active shell differently for Windows PowerShell 5.1, PowerShell 7, and non-Windows environments.

Enhancements:

  • Use the configured Windows shell executable for both one-shot and managed local shell commands instead of always calling powershell.exe, and surface a clear error if the executable is missing from PATH.
  • Plumb the selected Windows shell configuration into the shell execution tool so that tool-driven commands honor the user’s shell choice.
  • Expose the new Windows shell setting in the dashboard configuration UI with localized labels and hints.

Tests:

  • Add unit tests covering selection of pwsh.exe, missing-executable error handling, non-Windows behavior, and system prompt branching based on the configured Windows shell.

@wcqqq1214 wcqqq1214 changed the title feat: make Windows local runtime PowerShell configurable feat: support PowerShell 7 for Windows local shell Aug 10, 2026
@C10H14N2O5

Copy link
Copy Markdown

好快的写(`ヮ´)

Co-authored-by: Donoym <prober13c14@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 希望 Windows 本地 Shell 在保留默认使用 PowerShell 5.1 的前提下支持配置 PowerShell 7

2 participants