fix(shell): escape spaces in skill paths returned by ShellPathPolicy#1982
Closed
zouyx wants to merge 4 commits into
Closed
fix(shell): escape spaces in skill paths returned by ShellPathPolicy#1982zouyx wants to merge 4 commits into
zouyx wants to merge 4 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes shell command ambiguity when skill names (or workspace roots) contain spaces by escaping spaces in filesRoot paths that are emitted to the LLM via <available_skills> and load_skill_through_path responses.
Changes:
- Escape spaces (
" " -> "\\ ") inShellPathPolicyfor both skill and cache path joins across SANDBOX and LOCAL_WITH_SHELL modes. - Add unit tests covering escaping behavior for sandbox/localWithShell/noShell modes and null/NONE stages.
- Add a prompt-rendering test to ensure
<files-root>includes the escaped path when spaces are present.
Reviewed changes
Copilot reviewed 87 out of 87 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| agentscope-harness/src/main/java/io/agentscope/harness/agent/skill/runtime/ShellPathPolicy.java | Escapes spaces in resolved filesRoot paths and adds an escaping helper. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/skill/runtime/SkillRuntimeTest.java | Adds coverage for space-escaping behavior and <files-root> rendering. |
| void escapeSpacesReplacesWithBackslashSpace() { | ||
| assertEquals("hello", ShellPathPolicy.escapeSpaces("hello")); | ||
| assertEquals("hello\\ world", ShellPathPolicy.escapeSpaces("hello world")); | ||
| assertEquals("V2Ray\\ 代理配置助手", ShellPathPolicy.escapeSpaces("V2Ray 代理配置助手")); |
Comment on lines
+97
to
+98
| String result = policy.resolve("V2Ray 代理配置助手", new StageResult.WorkspaceNative()); | ||
| assertEquals("/workspace/skills/V2Ray\\ 代理配置助手", result); |
Comment on lines
+171
to
+175
| skill("V2Ray 代理配置助手", "wkspace"), | ||
| null, | ||
| "/workspace/skills/V2Ray\\ 代理配置助手"); | ||
| String out = new SkillPromptBuilder().render(SkillCatalog.of(List.of(e))); | ||
| assertTrue(out.contains("<files-root>/workspace/skills/V2Ray\\ 代理配置助手</files-root>")); |
Comment on lines
+150
to
+153
| /** | ||
| * Escapes space characters with backslash so the path can be safely used in shell commands | ||
| * by the LLM. | ||
| */ |
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)