Skip to content

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

Open
zouyx wants to merge 2 commits into
agentscope-ai:mainfrom
zouyx:feature/fixSkill
Open

fix(shell): escape spaces in skill paths returned by ShellPathPolicy#1983
zouyx wants to merge 2 commits into
agentscope-ai:mainfrom
zouyx:feature/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 15:08

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 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 ShellPathPolicy to escape spaces (via backslash) in resolved filesRoot paths for both workspace skills and cached skills.
  • Add SkillRuntimeTest coverage for ShellPathPolicy across 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>
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 命令歧义

2 participants