bash.txt 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. Executes a given bash command in a persistent shell session with optional timeout, ensuring proper handling and security measures.
  2. All commands run in ${directory} by default. Use the `workdir` parameter if you need to run a command in a different directory. AVOID using `cd <directory> && <command>` patterns - use `workdir` instead.
  3. IMPORTANT: This tool is for terminal operations like git, npm, docker, etc. DO NOT use it for file operations (reading, writing, editing, searching, finding files) - use the specialized tools for this instead.
  4. Before executing the command, please follow these steps:
  5. 1. Directory Verification:
  6. - If the command will create new directories or files, first use `ls` to verify the parent directory exists and is the correct location
  7. - For example, before running "mkdir foo/bar", first use `ls foo` to check that "foo" exists and is the intended parent directory
  8. 2. Command Execution:
  9. - Always quote file paths that contain spaces with double quotes (e.g., rm "path with spaces/file.txt")
  10. - Examples of proper quoting:
  11. - mkdir "/Users/name/My Documents" (correct)
  12. - mkdir /Users/name/My Documents (incorrect - will fail)
  13. - python "/path/with spaces/script.py" (correct)
  14. - python /path/with spaces/script.py (incorrect - will fail)
  15. - After ensuring proper quoting, execute the command.
  16. - Capture the output of the command.
  17. Usage notes:
  18. - The command argument is required.
  19. - You can specify an optional timeout in milliseconds (up to 600000ms / 10 minutes). If not specified, commands will time out after 120000ms (2 minutes).
  20. - It is very helpful if you write a clear, concise description of what this command does in 5-10 words.
  21. - If the output exceeds 30000 characters, output will be truncated before being returned to you.
  22. - You can use the `run_in_background` parameter to run the command in the background, which allows you to continue working while the command runs. You can monitor the output using the Bash tool as it becomes available. You do not need to use '&' at the end of the command when using this parameter.
  23. - Avoid using Bash with the `find`, `grep`, `cat`, `head`, `tail`, `sed`, `awk`, or `echo` commands, unless explicitly instructed or when these commands are truly necessary for the task. Instead, always prefer using the dedicated tools for these commands:
  24. - File search: Use Glob (NOT find or ls)
  25. - Content search: Use Grep (NOT grep or rg)
  26. - Read files: Use Read (NOT cat/head/tail)
  27. - Edit files: Use Edit (NOT sed/awk)
  28. - Write files: Use Write (NOT echo >/cat <<EOF)
  29. - Communication: Output text directly (NOT echo/printf)
  30. - When issuing multiple commands:
  31. - If the commands are independent and can run in parallel, make multiple Bash tool calls in a single message. For example, if you need to run "git status" and "git diff", send a single message with two Bash tool calls in parallel.
  32. - If the commands depend on each other and must run sequentially, use a single Bash 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 Bash for git operations, or git add before git commit), run these operations sequentially instead.
  33. - Use ';' only when you need to run commands sequentially but don't care if earlier commands fail
  34. - DO NOT use newlines to separate commands (newlines are ok in quoted strings)
  35. - AVOID using `cd <directory> && <command>`. Use the `workdir` parameter to change directories instead.
  36. <good-example>
  37. Use workdir="/foo/bar" with command: pytest tests
  38. </good-example>
  39. <bad-example>
  40. cd /foo/bar && pytest tests
  41. </bad-example>
  42. # Committing changes with git
  43. Only create commits when requested by the user. If unclear, ask first. When the user asks you to create a new git commit, follow these steps carefully:
  44. Git Safety Protocol:
  45. - NEVER update the git config
  46. - NEVER run destructive/irreversible git commands (like push --force, hard reset, etc) unless the user explicitly requests them
  47. - NEVER skip hooks (--no-verify, --no-gpg-sign, etc) unless the user explicitly requests it
  48. - NEVER run force push to main/master, warn the user if they request it
  49. - Avoid git commit --amend. ONLY use --amend when ALL conditions are met:
  50. (1) User explicitly requested amend, OR commit SUCCEEDED but pre-commit hook auto-modified files that need including
  51. (2) HEAD commit was created by you in this conversation (verify: git log -1 --format='%an %ae')
  52. (3) Commit has NOT been pushed to remote (verify: git status shows "Your branch is ahead")
  53. - CRITICAL: If commit FAILED or was REJECTED by hook, NEVER amend - fix the issue and create a NEW commit
  54. - CRITICAL: If you already pushed to remote, NEVER amend unless user explicitly requests it (requires force push)
  55. - NEVER commit changes unless the user explicitly asks you to. It is VERY IMPORTANT to only commit when explicitly asked, otherwise the user will feel that you are being too proactive.
  56. 1. You can call multiple tools in a single response. When multiple independent pieces of information are requested and all commands are likely to succeed, run multiple tool calls in parallel for optimal performance. run the following bash commands in parallel, each using the Bash tool:
  57. - Run a git status command to see all untracked files.
  58. - Run a git diff command to see both staged and unstaged changes that will be committed.
  59. - Run a git log command to see recent commit messages, so that you can follow this repository's commit message style.
  60. 2. Analyze all staged changes (both previously staged and newly added) and draft a commit message:
  61. - Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.). Ensure the message accurately reflects the changes and their purpose (i.e. "add" means a wholly new feature, "update" means an enhancement to an existing feature, "fix" means a bug fix, etc.).
  62. - Do not commit files that likely contain secrets (.env, credentials.json, etc.). Warn the user if they specifically request to commit those files
  63. - Draft a concise (1-2 sentences) commit message that focuses on the "why" rather than the "what"
  64. - Ensure it accurately reflects the changes and their purpose
  65. 3. You can call multiple tools in a single response. When multiple independent pieces of information are requested and all commands are likely to succeed, run multiple tool calls in parallel for optimal performance. run the following commands:
  66. - Add relevant untracked files to the staging area.
  67. - Create the commit with a message
  68. - Run git status after the commit completes to verify success.
  69. Note: git status depends on the commit completing, so run it sequentially after the commit.
  70. 4. If the commit fails due to pre-commit hook, fix the issue and create a NEW commit (see amend rules above)
  71. Important notes:
  72. - NEVER run additional commands to read or explore code, besides git bash commands
  73. - NEVER use the TodoWrite or Task tools
  74. - DO NOT push to the remote repository unless the user explicitly asks you to do so
  75. - IMPORTANT: Never use git commands with the -i flag (like git rebase -i or git add -i) since they require interactive input which is not supported.
  76. - If there are no changes to commit (i.e., no untracked files and no modifications), do not create an empty commit
  77. # Creating pull requests
  78. Use the gh command via the Bash tool for ALL GitHub-related tasks including working with issues, pull requests, checks, and releases. If given a Github URL use the gh command to get the information needed.
  79. IMPORTANT: When the user asks you to create a pull request, follow these steps carefully:
  80. 1. You can call multiple tools in a single response. When multiple independent pieces of information are requested and all commands are likely to succeed, run multiple tool calls in parallel for optimal performance. run the following bash commands in parallel using the Bash tool, in order to understand the current state of the branch since it diverged from the main branch:
  81. - Run a git status command to see all untracked files
  82. - Run a git diff command to see both staged and unstaged changes that will be committed
  83. - Check if the current branch tracks a remote branch and is up to date with the remote, so you know if you need to push to the remote
  84. - Run a git log command and `git diff [base-branch]...HEAD` to understand the full commit history for the current branch (from the time it diverged from the base branch)
  85. 2. Analyze all changes that will be included in the pull request, making sure to look at all relevant commits (NOT just the latest commit, but ALL commits that will be included in the pull request!!!), and draft a pull request summary
  86. 3. You can call multiple tools in a single response. When multiple independent pieces of information are requested and all commands are likely to succeed, run multiple tool calls in parallel for optimal performance. run the following commands in parallel:
  87. - Create new branch if needed
  88. - Push to remote with -u flag if needed
  89. - Create PR using gh pr create with the format below. Use a HEREDOC to pass the body to ensure correct formatting.
  90. <example>
  91. gh pr create --title "the pr title" --body "$(cat <<'EOF'
  92. ## Summary
  93. <1-3 bullet points>
  94. </example>
  95. Important:
  96. - DO NOT use the TodoWrite or Task tools
  97. - Return the PR URL when you're done, so the user can see it
  98. # Other common operations
  99. - View comments on a Github PR: gh api repos/foo/bar/pulls/123/comments