fix(harness): support Windows shell execution - #2304
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Windows-specific shell execution issues in the harness by generating cmd-compatible cd commands and selecting an appropriate charset for decoding local shell output on Windows, while preserving UTF-8 behavior on non-Windows systems.
Changes:
- Add
ShellExecuteTool.commandWithWorkingDirectory(...)to build Windows (cd /d "...") vs Unix (cd '...') working-directory prefixes. - Decode
LocalFilesystemWithShellprocess output using a Windows-native charset (with fallback) while keeping UTF-8 on non-Windows. - Add unit tests covering platform-specific command construction and charset selection.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| agentscope-harness/src/main/java/io/agentscope/harness/agent/tool/ShellExecuteTool.java | Uses a new helper to build Windows- vs Unix-compatible working-directory command prefixes. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/local/LocalFilesystemWithShell.java | Selects platform-appropriate output decoding charset for shell execution results. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/tool/ShellExecuteToolTest.java | Adds tests for Windows vs Unix command prefix construction. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/filesystem/local/LocalFilesystemWithShellTest.java | Adds tests for Windows native-encoding selection and UTF-8 on non-Windows. |
Comment on lines
57
to
61
| if (workingDirectory != null && !workingDirectory.isBlank()) { | ||
| String wd = workingDirectory.strip(); | ||
| if (wd.startsWith("/") || wd.startsWith("~") || wd.contains("..")) { | ||
| return "Error: working_directory must be a relative path within the workspace" | ||
| + " (absolute paths, '~', and '..' are not allowed)."; |
Comment on lines
+439
to
+448
| static Charset outputCharset(String osName, String nativeEncoding) { | ||
| if (!osName.toLowerCase(Locale.ROOT).contains("win")) { | ||
| return StandardCharsets.UTF_8; | ||
| } | ||
|
|
||
| if (nativeEncoding != null && Charset.isSupported(nativeEncoding)) { | ||
| return Charset.forName(nativeEncoding); | ||
| } | ||
| return Charset.defaultCharset(); | ||
| } |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
oss-maintainer
approved these changes
Jul 19, 2026
oss-maintainer
left a comment
Collaborator
There was a problem hiding this comment.
Summary
This PR contains 376 lines of changes. Review in progress.
Automated review by github-manager-bot
jujn
approved these changes
Jul 27, 2026
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.0.1-SNAPSHOT
Description
Fixes #2268.
Validated with:
mvn -q -pl agentscope-harness -am \ -Dtest=ShellExecuteToolTest,LocalFilesystemWithShellTest \ -DfailIfNoTests=false testChecklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)