Skip to content

fix(harness): support Windows shell execution - #2304

Merged
jujn merged 5 commits into
agentscope-ai:mainfrom
zouyx:featrue/fix-windows-shell-2268
Jul 27, 2026
Merged

fix(harness): support Windows shell execution#2304
jujn merged 5 commits into
agentscope-ai:mainfrom
zouyx:featrue/fix-windows-shell-2268

Conversation

@zouyx

@zouyx zouyx commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

AgentScope-Java Version

2.0.1-SNAPSHOT

Description

Fixes #2268.

  • Generate cmd-compatible working-directory commands on Windows.
  • Decode local shell output with the JVM native encoding on Windows, with a default-charset fallback.
  • Preserve UTF-8 decoding on non-Windows platforms.
  • Add unit tests for platform-specific command construction and output-charset selection.

Validated with:

mvn -q -pl agentscope-harness -am \
  -Dtest=ShellExecuteToolTest,LocalFilesystemWithShellTest \
  -DfailIfNoTests=false test

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

Copilot AI review requested due to automatic review settings July 19, 2026 13:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 LocalFilesystemWithShell process 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

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ent/filesystem/local/LocalFilesystemWithShell.java 88.88% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This PR contains 376 lines of changes. Review in progress.


Automated review by github-manager-bot

@AgentScopeJavaBot AgentScopeJavaBot added enhancement New feature or request area/examples agentscope-examples labels Jul 20, 2026
@jujn
jujn merged commit 8f50a66 into agentscope-ai:main Jul 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/examples agentscope-examples enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:AgentScope2.0版本 ShellExecuteTool和LocalFilesystemWithShell win10下无法执行脚本命令

5 participants