diff --git a/packages/core/src/tools/__snapshots__/shell.test.ts.snap b/packages/core/src/tools/__snapshots__/shell.test.ts.snap index 9dfd54cf0..5f14000f0 100644 --- a/packages/core/src/tools/__snapshots__/shell.test.ts.snap +++ b/packages/core/src/tools/__snapshots__/shell.test.ts.snap @@ -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 <\`, 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 <\`, 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. diff --git a/packages/core/src/tools/shell.ts b/packages/core/src/tools/shell.ts index 0300f7bec..6d62e1fa3 100644 --- a/packages/core/src/tools/shell.ts +++ b/packages/core/src/tools/shell.ts @@ -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 <\`, 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.