feat: support PowerShell 7 for Windows local shell - #9622
Draft
wcqqq1214 wants to merge 6 commits into
Draft
Conversation
|
好快的写(`ヮ´) |
Co-authored-by: Donoym <prober13c14@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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, keepingpowershell.exeas the default.Modifications / 改动点
astrbot/core/config/default.py: adds theprovider_settings.windows_shelloption with valuespowershell.exe/pwsh.exe, labelled "Windows PowerShell 5.1" / "PowerShell 7", defaulting topowershell.exe, and shown only whencomputer_use_runtimeislocal.astrbot/core/computer/booters/local.py: the win32 branches ofexec()andexec_managed()now launch the configured PowerShell. When the configured executable is not on PATH (checked only whenos.name == "nt"), a clearRuntimeErroris raised instead of silently falling back to another shell.astrbot/core/tools/computer_tools/shell.py:ExecuteShellToolreads the umo-scoped config value and forwards it toexec_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_shellresolves topowershell.exe), and non-Windows code paths are untouched.Screenshots or Test Results / 运行截图或测试结果
The new option in the WebUI, shown under Provider Settings when
computer_use_runtimeis set tolocal:The dropdown offers "Windows PowerShell 5.1" and "PowerShell 7", defaulting to the former. It is gated on
computer_use_runtime == "local"via the existingconditionmechanism, 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.namevia
monkeypatch.The full project test suite also passes locally:
Windows end-to-end validation
Manual validation was performed by @Donoym on:
3.12.137.6.4Configuration:
computer_use_runtime = localwindows_shell = powershell.exeResults:
windows_shell = pwsh.exe: PowerShell7.6.4windows_shell = powershell.exe: Windows PowerShell5.1.26100.8972Write-Output 'a' && Write-Output 'b': output wasa,bThe 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:
The failures were caused by platform-specific test assumptions involving Windows
CRLFoutput, Windows path separators, and incomplete platform simulation.Local verification after the test fixes:
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.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.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:
Enhancements:
Tests: