mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-28 03:30:40 +00:00
fix(core): add shell argument quoting guidance to prevent special char errors (#3327)
* fix(core): add shell argument quoting guidance to prevent special char errors When models pass arguments containing special characters (parentheses, backticks, single quotes, dollar signs, etc.) to shell commands like `gh pr create --body '...'`, bash can misinterpret them as shell syntax, causing the command to fail with cryptic errors. Add an explicit quoting guide to `getShellToolDescription()` covering: - Single quotes: pass everything literally but cannot contain `'` - ANSI-C quoting (`$'...'`): supports escape sequences including `\'` - Heredoc: the most robust approach for multi-line or mixed-quote text, with a concrete `gh pr create` example Fixes #3300 * test: update shell tool description snapshots
This commit is contained in:
parent
89167618d8
commit
875f3ffeb4
2 changed files with 36 additions and 0 deletions
|
|
@ -17,6 +17,18 @@ IMPORTANT: This tool is for terminal operations like git, npm, docker, etc. DO N
|
|||
- Edit files: Use edit (NOT sed/awk)
|
||||
- Write files: Use write_file (NOT echo >/cat <<EOF)
|
||||
- Communication: Output text directly (NOT echo/printf)
|
||||
- **Shell argument quoting and special characters**: When passing arguments that contain special characters (parentheses \`()\`, backticks \`\`\`\`, dollar signs \`$\`, backslashes \`\\\`, semicolons \`;\`, pipes \`|\`, angle brackets \`<>\`, ampersands \`&\`, exclamation marks \`!\`, etc.), you MUST ensure they are properly quoted to prevent the shell from misinterpreting them as shell syntax:
|
||||
- **Single quotes** \`'...'\` pass everything literally, but cannot contain a literal single quote.
|
||||
- **ANSI-C quoting** \`$'...'\` supports escape sequences (e.g. \`\\n\` for newline, \`\\'\` for single quote) and is the safest approach for multi-line strings or strings with single quotes.
|
||||
- **Heredoc** is the most robust approach for large, multi-line text with mixed quotes:
|
||||
\`\`\`bash
|
||||
gh pr create --title "My Title" --body "$(cat <<'HEREDOC'
|
||||
Multi-line body with (parentheses), \`backticks\`, and 'single-quotes'.
|
||||
HEREDOC
|
||||
)"
|
||||
\`\`\`
|
||||
- NEVER use unescaped single quotes inside single-quoted strings (e.g. \`'it\\'s'\` is wrong; use \`$'it\\'s'\` or \`"it's"\` instead).
|
||||
- If unsure, prefer double-quoting arguments and escape inner double-quotes as \`\\"\`.
|
||||
- When issuing multiple commands:
|
||||
- If the commands are independent and can run in parallel, make multiple run_shell_command tool calls in a single message. For example, if you need to run "git status" and "git diff", send a single message with two run_shell_command tool calls in parallel.
|
||||
- If the commands depend on each other and must run sequentially, use a single run_shell_command call with '&&' to chain them together (e.g., \`git add . && git commit -m "message" && git push\`). For instance, if one operation must complete before another starts (like mkdir before cp, Write before run_shell_command for git operations, or git add before git commit), run these operations sequentially instead.
|
||||
|
|
@ -66,6 +78,18 @@ IMPORTANT: This tool is for terminal operations like git, npm, docker, etc. DO N
|
|||
- Edit files: Use edit (NOT sed/awk)
|
||||
- Write files: Use write_file (NOT echo >/cat <<EOF)
|
||||
- Communication: Output text directly (NOT echo/printf)
|
||||
- **Shell argument quoting and special characters**: When passing arguments that contain special characters (parentheses \`()\`, backticks \`\`\`\`, dollar signs \`$\`, backslashes \`\\\`, semicolons \`;\`, pipes \`|\`, angle brackets \`<>\`, ampersands \`&\`, exclamation marks \`!\`, etc.), you MUST ensure they are properly quoted to prevent the shell from misinterpreting them as shell syntax:
|
||||
- **Single quotes** \`'...'\` pass everything literally, but cannot contain a literal single quote.
|
||||
- **ANSI-C quoting** \`$'...'\` supports escape sequences (e.g. \`\\n\` for newline, \`\\'\` for single quote) and is the safest approach for multi-line strings or strings with single quotes.
|
||||
- **Heredoc** is the most robust approach for large, multi-line text with mixed quotes:
|
||||
\`\`\`bash
|
||||
gh pr create --title "My Title" --body "$(cat <<'HEREDOC'
|
||||
Multi-line body with (parentheses), \`backticks\`, and 'single-quotes'.
|
||||
HEREDOC
|
||||
)"
|
||||
\`\`\`
|
||||
- NEVER use unescaped single quotes inside single-quoted strings (e.g. \`'it\\'s'\` is wrong; use \`$'it\\'s'\` or \`"it's"\` instead).
|
||||
- If unsure, prefer double-quoting arguments and escape inner double-quotes as \`\\"\`.
|
||||
- When issuing multiple commands:
|
||||
- If the commands are independent and can run in parallel, make multiple run_shell_command tool calls in a single message. For example, if you need to run "git status" and "git diff", send a single message with two run_shell_command tool calls in parallel.
|
||||
- If the commands depend on each other and must run sequentially, use a single run_shell_command call with '&&' to chain them together (e.g., \`git add . && git commit -m "message" && git push\`). For instance, if one operation must complete before another starts (like mkdir before cp, Write before run_shell_command for git operations, or git add before git commit), run these operations sequentially instead.
|
||||
|
|
|
|||
|
|
@ -559,6 +559,18 @@ IMPORTANT: This tool is for terminal operations like git, npm, docker, etc. DO N
|
|||
- Edit files: Use ${ToolNames.EDIT} (NOT sed/awk)
|
||||
- Write files: Use ${ToolNames.WRITE_FILE} (NOT echo >/cat <<EOF)
|
||||
- Communication: Output text directly (NOT echo/printf)
|
||||
- **Shell argument quoting and special characters**: When passing arguments that contain special characters (parentheses \`()\`, backticks \`\`\`\`, dollar signs \`$\`, backslashes \`\\\`, semicolons \`;\`, pipes \`|\`, angle brackets \`<>\`, ampersands \`&\`, exclamation marks \`!\`, etc.), you MUST ensure they are properly quoted to prevent the shell from misinterpreting them as shell syntax:
|
||||
- **Single quotes** \`'...'\` pass everything literally, but cannot contain a literal single quote.
|
||||
- **ANSI-C quoting** \`$'...'\` supports escape sequences (e.g. \`\\n\` for newline, \`\\'\` for single quote) and is the safest approach for multi-line strings or strings with single quotes.
|
||||
- **Heredoc** is the most robust approach for large, multi-line text with mixed quotes:
|
||||
\`\`\`bash
|
||||
gh pr create --title "My Title" --body "$(cat <<'HEREDOC'
|
||||
Multi-line body with (parentheses), \`backticks\`, and 'single-quotes'.
|
||||
HEREDOC
|
||||
)"
|
||||
\`\`\`
|
||||
- NEVER use unescaped single quotes inside single-quoted strings (e.g. \`'it\\'s'\` is wrong; use \`$'it\\'s'\` or \`"it's"\` instead).
|
||||
- If unsure, prefer double-quoting arguments and escape inner double-quotes as \`\\"\`.
|
||||
- When issuing multiple commands:
|
||||
- If the commands are independent and can run in parallel, make multiple run_shell_command tool calls in a single message. For example, if you need to run "git status" and "git diff", send a single message with two run_shell_command tool calls in parallel.
|
||||
- If the commands depend on each other and must run sequentially, use a single run_shell_command call with '&&' to chain them together (e.g., \`git add . && git commit -m "message" && git push\`). For instance, if one operation must complete before another starts (like mkdir before cp, Write before run_shell_command for git operations, or git add before git commit), run these operations sequentially instead.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue