bash.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. Executes a given bash command in a persistent shell session with optional timeout, ensuring proper handling and security measures.
  2. Before executing the command, please follow these steps:
  3. 1. Directory Verification:
  4. - If the command will create new directories or files, first use the List tool to verify the parent directory exists and is the correct location
  5. - For example, before running "mkdir foo/bar", first use List to check that "foo" exists and is the intended parent directory
  6. 2. Command Execution:
  7. - Always quote file paths that contain spaces with double quotes (e.g., rm "path with spaces/file.txt")
  8. - Examples of proper quoting:
  9. - mkdir "/Users/name/My Documents" (correct)
  10. - mkdir /Users/name/My Documents (incorrect - will fail)
  11. - python "/path/with spaces/script.py" (correct)
  12. - python /path/with spaces/script.py (incorrect - will fail)
  13. - After ensuring proper quoting, execute the command.
  14. - Capture the output of the command.
  15. Usage notes:
  16. - The command argument is required.
  17. - You can specify an optional timeout in milliseconds (up to 600000ms / 10 minutes).
  18. If not specified, commands will timeout after 120000ms (2 minutes).
  19. - It is very helpful if you write a clear, concise description of what this command
  20. does in 5-10 words.
  21. - If the output exceeds 30000 characters, output will be truncated before being
  22. returned to you.
  23. - You can use the `run_in_background` parameter to run the command in the background,
  24. which allows you to continue working while the command runs. You can monitor the output
  25. using the Bash tool as it becomes available. You do not need to use '&' at the end of
  26. the command when using this parameter.
  27. - Avoid using Bash with the `find`, `grep`, `cat`, `head`, `tail`, `sed`, `awk`, or
  28. `echo` commands, unless explicitly instructed or when these commands are truly necessary
  29. for the task. Instead, always prefer using the dedicated tools for these commands:
  30. - File search: Use Glob (NOT find or ls)
  31. - Content search: Use Grep (NOT grep or rg)
  32. - Read files: Use Read (NOT cat/head/tail)
  33. - Edit files: Use Edit (NOT sed/awk)
  34. - Write files: Use Write (NOT echo >/cat <<EOF)
  35. - Communication: Output text directly (NOT echo/printf)
  36. - When issuing multiple commands:
  37. - If the commands are independent and can run in parallel, make multiple Bash tool
  38. calls in a single message. For example, if you need to run "git status" and "git diff",
  39. send a single message with two Bash tool calls in parallel.
  40. - If the commands depend on each other and must run sequentially, use a single Bash
  41. call with '&&' to chain them together (e.g., `git add . && git commit -m "message" &&
  42. git push`). For instance, if one operation must complete before another starts (like
  43. mkdir before cp, Write before Bash for git operations, or git add before git commit),
  44. run these operations sequentially instead.
  45. - Use ';' only when you need to run commands sequentially but don't care if earlier
  46. commands fail
  47. - DO NOT use newlines to separate commands (newlines are ok in quoted strings)
  48. - Try to maintain your current working directory throughout the session by using
  49. absolute paths and avoiding usage of `cd`. You may use `cd` if the User explicitly
  50. requests it.
  51. <good-example>
  52. pytest /foo/bar/tests
  53. </good-example>
  54. <bad-example>
  55. cd /foo/bar && pytest tests
  56. </bad-example>
  57. # Working Directory
  58. The `workdir` parameter sets the working directory for command execution. Prefer using `workdir` over `cd <dir> &&` command chains when you simply need to run a command in a different directory.
  59. <good-example>
  60. workdir="/foo/bar", command="pytest tests"
  61. </good-example>
  62. <good-example>
  63. command="pytest /foo/bar/tests"
  64. </good-example>
  65. <bad-example>
  66. command="cd /foo/bar && pytest tests"
  67. </bad-example>
  68. # Committing changes with git
  69. IMPORTANT: ONLY COMMIT IF THE USER ASKS YOU TO.
  70. If and only if the user asks you to create a new git commit, follow these steps carefully:
  71. 1. You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. ALWAYS run the following bash commands in parallel, each using the Bash tool:
  72. - Run a git status command to see all untracked files.
  73. - Run a git diff command to see both staged and unstaged changes that will be committed.
  74. - Run a git log command to see recent commit messages, so that you can follow this repository's commit message style.
  75. 2. Analyze all staged changes (both previously staged and newly added) and draft a commit message. When analyzing:
  76. - List the files that have been changed or added
  77. - Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
  78. - Brainstorm the purpose or motivation behind these changes
  79. - Assess the impact of these changes on the overall project
  80. - Check for any sensitive information that shouldn't be committed
  81. - Draft a concise (1-2 sentences) commit message that focuses on the "why" rather than the "what"
  82. - Ensure your language is clear, concise, and to the point
  83. - 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.)
  84. - Ensure the message is not generic (avoid words like "Update" or "Fix" without context)
  85. - Review the draft message to ensure it accurately reflects the changes and their purpose
  86. 3. You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. ALWAYS run the following commands in parallel:
  87. - Add relevant untracked files to the staging area.
  88. - Run git status to make sure the commit succeeded.
  89. 4. If the commit fails due to pre-commit hook changes, retry the commit ONCE to include these automated changes. If it fails again, it usually means a pre-commit hook is preventing the commit. If the commit succeeds but you notice that files were modified by the pre-commit hook, you MUST amend your commit to include them.
  90. Important notes:
  91. - Use the git context at the start of this conversation to determine which files are relevant to your commit. Be careful not to stage and commit files (e.g. with `git add .`) that aren't relevant to your commit.
  92. - NEVER update the git config
  93. - DO NOT run additional commands to read or explore code, beyond what is available in the git context
  94. - DO NOT push to the remote repository
  95. - 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.
  96. - If there are no changes to commit (i.e., no untracked files and no modifications), do not create an empty commit
  97. - Ensure your commit message is meaningful and concise. It should explain the purpose of the changes, not just describe them.
  98. - Return an empty response - the user will see the git output directly
  99. # Creating pull requests
  100. 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.
  101. IMPORTANT: When the user asks you to create a pull request, follow these steps carefully:
  102. 1. You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. ALWAYS 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:
  103. - Run a git status command to see all untracked files
  104. - Run a git diff command to see both staged and unstaged changes that will be committed
  105. - 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
  106. - Run a git log command and `git diff main...HEAD` to understand the full commit history for the current branch (from the time it diverged from the `main` branch)
  107. 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. Wrap your analysis process in <pr_analysis> tags:
  108. <pr_analysis>
  109. - List the commits since diverging from the main branch
  110. - Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
  111. - Brainstorm the purpose or motivation behind these changes
  112. - Assess the impact of these changes on the overall project
  113. - Do not use tools to explore code, beyond what is available in the git context
  114. - Check for any sensitive information that shouldn't be committed
  115. - Draft a concise (1-2 bullet points) pull request summary that focuses on the "why" rather than the "what"
  116. - Ensure the summary accurately reflects all changes since diverging from the main branch
  117. - Ensure your language is clear, concise, and to the point
  118. - Ensure the summary accurately reflects the changes and their purpose (ie. "add" means a wholly new feature, "update" means an enhancement to an existing feature, "fix" means a bug fix, etc.)
  119. - Ensure the summary is not generic (avoid words like "Update" or "Fix" without context)
  120. - Review the draft summary to ensure it accurately reflects the changes and their purpose
  121. </pr_analysis>
  122. 3. You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. ALWAYS run the following commands in parallel:
  123. - Create new branch if needed
  124. - Push to remote with -u flag if needed
  125. - Create PR using gh pr create with the format below. Use a HEREDOC to pass the body to ensure correct formatting.
  126. <example>
  127. gh pr create --title "the pr title" --body "$(cat <<'EOF'
  128. ## Summary
  129. <1-3 bullet points>
  130. EOF
  131. )"
  132. </example>
  133. Important:
  134. - NEVER update the git config
  135. - Return the PR URL when you're done, so the user can see it
  136. # Other common operations
  137. - View comments on a Github PR: gh api repos/foo/bar/pulls/123/comments