Skip to content

fix(shell): escape spaces in skill paths returned by ShellPathPolicy#1982

Closed
zouyx wants to merge 4 commits into
agentscope-ai:mainfrom
zouyx:hotfix/fixSkill
Closed

fix(shell): escape spaces in skill paths returned by ShellPathPolicy#1982
zouyx wants to merge 4 commits into
agentscope-ai:mainfrom
zouyx:hotfix/fixSkill

Conversation

@zouyx

@zouyx zouyx commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

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 in load_skill_through_path responses are both consumed by the LLM to construct shell commands. Without escaping, the space makes the path ambiguous and causes shell execution failures.

filesRoot propagates from ShellPathPolicy to the LLM prompt through two call sites:

  1. SkillPromptBuilder — renders <files-root> inside <available_skills>
  2. SkillLoadTool — renders "Files root: " in skill/resource load responses

Changes:

  • ShellPathPolicy: Added escapeSpaces() to replace spaces with \ in both joinSkills() and joinCache(), covering all three modes (SANDBOX, LOCAL_WITH_SHELL, NO_SHELL).
  • SkillRuntimeTest: Added ShellPathPolicyTests with tests for paths with/without spaces, multiple spaces, Chinese characters, sandbox/localWithShell/noShell modes, and null/NONE stage inputs. Added a SkillPromptBuilder test case for XML rendering with escaped spaces.

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

@zouyx zouyx requested review from a team and Copilot July 1, 2026 14:53
@zouyx zouyx closed this Jul 1, 2026

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 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 (" " -> "\\ ") in ShellPathPolicy for 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.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:<files-root> 使用 Skill name 作为路径时,包含空格会导致 shell 命令歧义

5 participants