fix(shell): escape spaces in skill paths returned by ShellPathPolicy#1983
Open
zouyx wants to merge 2 commits into
Open
fix(shell): escape spaces in skill paths returned by ShellPathPolicy#1983zouyx wants to merge 2 commits into
zouyx wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes shell-command ambiguity caused by unescaped spaces in the filesRoot paths emitted to the LLM (both in <available_skills><files-root> and in SkillLoadTool “Files root:” output) by having ShellPathPolicy return a space-escaped representation for shell modes.
Changes:
- Update
ShellPathPolicyto escape spaces (via backslash) in resolvedfilesRootpaths for both workspace skills and cached skills. - Add
SkillRuntimeTestcoverage forShellPathPolicyacross SANDBOX / LOCAL_WITH_SHELL / NO_SHELL, plus a prompt-rendering assertion that the escaped path is preserved in<files-root>.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| agentscope-harness/src/main/java/io/agentscope/harness/agent/skill/runtime/ShellPathPolicy.java | Escapes spaces in resolved skill/cache paths so LLM-constructed shell commands don’t break on word-splitting. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/skill/runtime/SkillRuntimeTest.java | Adds regression tests for space-escaping behavior and ensures escaped <files-root> is rendered into the prompt. |
Comment on lines
+87
to
+92
| void escapeSpacesReplacesWithBackslashSpace() { | ||
| assertEquals("hello", ShellPathPolicy.escapeSpaces("hello")); | ||
| assertEquals("hello\\ world", ShellPathPolicy.escapeSpaces("hello world")); | ||
| assertEquals("V2Ray\\ 代理配置助手", ShellPathPolicy.escapeSpaces("V2Ray 代理配置助手")); | ||
| assertEquals("a\\ b\\ c", ShellPathPolicy.escapeSpaces("a b c")); | ||
| } |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.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.
AgentScope-Java Version
2.0.0
Description:
Closes #1893
When a skill name contains spaces (e.g.,
V2Ray 代理配置助手), the<files-root>path emitted in<available_skills>and the"Files root: "line inload_skill_through_pathresponses are both consumed by the LLM to construct shell commands. Without escaping, the space makes the path ambiguous and causes shell execution failures.filesRootpropagates fromShellPathPolicyto the LLM prompt through two call sites:SkillPromptBuilder— renders<files-root>inside<available_skills>SkillLoadTool— renders"Files root: "in skill/resource load responsesChanges:
ShellPathPolicy: AddedescapeSpaces()to replace spaces with\in bothjoinSkills()andjoinCache(), covering all three modes (SANDBOX,LOCAL_WITH_SHELL,NO_SHELL).SkillRuntimeTest: AddedShellPathPolicyTestswith tests for paths with/without spaces, multiple spaces, Chinese characters, sandbox/localWithShell/noShell modes, and null/NONEstage inputs. Added aSkillPromptBuildertest case for XML rendering with escaped spaces.Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)