Repository navigation
feat(harness): let the local shell be configured instead of following the host OS - #4136
Open
ningmao-hlyz wants to merge 6 commits into
Open
ningmao-hlyz wants to merge 6 commits into
ningmao-hlyz wants to merge 6 commits into
Conversation
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
ningmao-hlyz
force-pushed
the
fix/windows-shell-discovery
branch
5 times, most recently
from
November 14, 2026 10:43
d4950f4 to
e837d7c
Compare
This was referenced Nov 14, 2026
… the host OS `execute()` picked the shell from `os.name`: `cmd.exe /c` on Windows, `sh -c` everywhere else. The `cmd.exe` branch removed the reported crash, but a command written in POSIX syntax then fails differently instead of working, and there was no way to switch (agentscope-ai#1396). `LocalFilesystemSpec.shellPath(String)` takes a path or a bare executable name. A name is looked up on `PATH`, and on Windows also in the Git for Windows install directories, so `shellPath("bash")` is enough. The flag that passes the command follows the executable: `-c`, `/c`, or `-Command`. The default stays the shell the host provides, because switching it would run every existing cmd command, and this project's own Windows tests, under a POSIX shell. `execute()` is not the only place that assumed the host shell: `ShellExecuteTool` prefixed `working_directory` with `cd /d "..." &&` and the workspace prompt told the model `cmd.exe /c`, both from `os.name`. Both now ask the filesystem through `ShellSyntax`, which wrappers report from the backend that runs the command. The same change fixes a defect a configured shell would not have survived. With a non-empty `env` and `inheritEnv(false)`, `execute()` cleared the environment and kept only the caller's variables, which dropped `PATH`: ProcessBuilder("cmd.exe", "/c", "where git") with a cleared environment -> 'where' is not recognized as an internal or external command A caller that only wanted to add one variable lost the whole toolchain. The variables needed to start a process and resolve its own executables are restored before `env` is applied; `env` still overrides them, and home/profile directories stay dropped, which is what `inheritEnv(false)` asks for. Fixes agentscope-ai#1396.
ningmao-hlyz
force-pushed
the
fix/windows-shell-discovery
branch
from
November 15, 2026 06:24
43472b1 to
33da426
Compare
ningmao-hlyz
force-pushed
the
fix/windows-shell-discovery
branch
from
November 15, 2026 06:53
33da426 to
a87045f
Compare
Contributor
Author
|
@jujn Could you review this PR when you have time? |
Resolutions: - LocalFilesystemWithShell keeps main's StreamCapture/BoundedOutput pipeline (spooled output, digests, saveOutput, previewOutput) and only swaps the decode charset for resolvedShell.outputCharset(...), which is what a configured PowerShell needs. The host-level outputCharset(String) helper is kept and now delegates to ShellResolver, so main's fixture assumption still reads the same value. - Constructor javadocs: the short note stays on the nine-argument overload; the long javadoc (already carrying @PARAM shellPath) stays on the ten-argument one. - Tests: union imports, and drop the duplicate isWindows() helper that both sides added. mvn -pl agentscope-harness -am test for the shell, overlay, routed and workspace-context classes passes (189 tests, 7 skipped for unavailable shells). spotless:check clean.
Three points in the configured-shell path:
- The workspace paragraph asked ShellSyntax.of(fs) for the family. A bare
OverlayFilesystem does not implement AbstractSandboxFilesystem, so a caller
that constructs one directly around a local shell answers POSIX even when that
shell is cmd.exe. OverlayFilesystem.of() already returns a ShellAwareOverlay
that answers correctly, so this only hardens the direct-construction path:
ask the detected local upper, which is the layer that executes.
- A Store-installed pwsh is an app-execution alias: Files.isRegularFile and
Files.exists both report it absent although the JVM launches it fine.
Requiring a regular file rejected shellPath("pwsh") on a working shell.
Accept any executable that is not a directory instead.
- pwsh-preview.exe fell through to POSIX, so it launched with -c and without the
UTF-8 console prefix. Match every name starting with pwsh.
Verified on Windows 11 with pwsh from the Microsoft Store: the alias resolves,
and "[Console]::OutputEncoding = UTF8; Set-Location -LiteralPath ...; cmd /c
echo <CJK>" returns UTF-8 bytes (E4 B8 AD ...) with exit 0. cmd.exe and Windows
PowerShell 5.1 keep their existing behaviour.
mvn -pl agentscope-harness -am test for the shell, middleware and spec classes
passes (159 tests, 0 failures, 6 skipped for unavailable shells).
This branch has not been deployed
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.
AgentScope-Java Version
2.1.0-SNAPSHOT, based on main at
3f6ff9e6(#4261).Description
Fixes #1396.
Expose
LocalFilesystemSpec.shellPath(String)so applications can select an executable path or a shell name onPATH, with Git for Windows lookup for bare names. Defaults remainshon POSIX andcmd.exeon Windows; an invalid configured shell fails when the filesystem is built.Use the selected shell family for command flags,
working_directoryprefixes and workspace prompts, including through overlay and routed filesystems. Shell resolution also selects output decoding: PowerShell commands set console output to UTF-8; POSIX shells use UTF-8 and Windowscmd.exeretains native decoding. A custom environment keeps the small bootstrap set needed to find commands, and caller values take precedence.Resolution accepts any executable that is not a directory, because a Store-installed
pwshis a runnable app-execution alias:Files.existsandFiles.isRegularFileboth report it absent while the JVM launches it. Names starting withpwshselect PowerShell, so preview builds get-Commandand the UTF-8 console prefix. The workspace paragraph asks the detected local upper for its syntax, so a directly constructedOverlayFilesystemno longer reports POSIX for a non-POSIX upper.This branch is updated for #4154:
RoutedSandboxFilesystemretains the newjournalStorage()API as well as shell delegation. Onlydocs/devis updated. Other shell implementations such asShellCommandToolandLocalHandsToolExecutorare outside this change.Validation on Windows, Java 17:
pwshalias fails the previousisRegularFile && isExecutablepredicate and passes the new one;cmd.exeand Windows PowerShell 5.1 are unchanged.[Console]::OutputEncoding = UTF8; Set-Location -LiteralPath '...'; cmd /c echo <CJK>returnsE4 B8 AD ...with exit 0. Without the prefix the same command returns GBK (D6 D0 CE C4), so the console prefix also covers native commands.clean verifyon this branch passed 13,003 tests. This revision changes only shell resolution and the workspace prompt, covered above.git diff --checkpassed.Checklist