bash.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. - The description argument is required. You must write a clear, concise description of what this command does in 5-10 words.
  20. - If the output exceeds 30000 characters, output will be truncated before being
  21. returned to you.
  22. - You can use the `run_in_background` parameter to run the command in the background,
  23. which allows you to continue working while the command runs. You can monitor the output
  24. using the Bash tool as it becomes available. You do not need to use '&' at the end of
  25. the command when using this parameter.
  26. - Avoid using Bash with the `find`, `grep`, `cat`, `head`, `tail`, `sed`, `awk`, or
  27. `echo` commands, unless explicitly instructed or when these commands are truly necessary
  28. for the task. Instead, always prefer using the dedicated tools for these commands:
  29. - File search: Use Glob (NOT find or ls)
  30. - Content search: Use Grep (NOT grep or rg)
  31. - Read files: Use Read (NOT cat/head/tail)
  32. - Edit files: Use Edit (NOT sed/awk)
  33. - Write files: Use Write (NOT echo >/cat <<EOF)
  34. - Communication: Output text directly (NOT echo/printf)
  35. - When issuing multiple commands:
  36. - If the commands are independent and can run in parallel, make multiple Bash tool
  37. calls in a single message. For example, if you need to run "git status" and "git diff",
  38. send a single message with two Bash tool calls in parallel.
  39. - If the commands depend on each other and must run sequentially, use a single Bash
  40. call with '&&' to chain them together (e.g., `git add . && git commit -m "message" &&
  41. git push`). For instance, if one operation must complete before another starts (like
  42. mkdir before cp, Write before Bash for git operations, or git add before git commit),
  43. run these operations sequentially instead.
  44. - Use ';' only when you need to run commands sequentially but don't care if earlier
  45. commands fail
  46. - DO NOT use newlines to separate commands (newlines are ok in quoted strings)
  47. - Try to maintain your current working directory throughout the session by using
  48. absolute paths and avoiding usage of `cd`. You may use `cd` if the User explicitly
  49. requests it.
  50. <good-example>
  51. pytest /foo/bar/tests
  52. </good-example>
  53. <bad-example>
  54. cd /foo/bar && pytest tests
  55. </bad-example>
  56. # Working Directory
  57. 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.
  58. <good-example>
  59. workdir="/foo/bar", command="pytest tests"
  60. </good-example>
  61. <good-example>
  62. command="pytest /foo/bar/tests"
  63. </good-example>
  64. <bad-example>
  65. command="cd /foo/bar && pytest tests"
  66. </bad-example>
  67. # Committing changes with git
  68. IMPORTANT: ONLY COMMIT IF THE USER ASKS YOU TO.
  69. If and only if the user asks you to create a new git commit, follow these steps carefully:
  70. 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:
  71. - Run a git status command to see all untracked files.
  72. - Run a git diff command to see both staged and unstaged changes that will be committed.
  73. - Run a git log command to see recent commit messages, so that you can follow this repository's commit message style.
  74. 2. Analyze all staged changes (both previously staged and newly added) and draft a commit message. When analyzing:
  75. - List the files that have been changed or added
  76. - Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
  77. - Brainstorm the purpose or motivation behind these changes
  78. - Assess the impact of these changes on the overall project
  79. - Check for any sensitive information that shouldn't be committed
  80. - Draft a concise (1-2 sentences) commit message that focuses on the "why" rather than the "what"
  81. - Ensure your language is clear, concise, and to the point
  82. - 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.)
  83. - Ensure the message is not generic (avoid words like "Update" or "Fix" without context)
  84. - Review the draft message to ensure it accurately reflects the changes and their purpose
  85. 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:
  86. - Add relevant untracked files to the staging area.
  87. - Run git status to make sure the commit succeeded.
  88. 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.
  89. Important notes:
  90. - 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.
  91. - NEVER update the git config
  92. - DO NOT run additional commands to read or explore code, beyond what is available in the git context
  93. - DO NOT push to the remote repository
  94. - 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.
  95. - If there are no changes to commit (i.e., no untracked files and no modifications), do not create an empty commit
  96. - Ensure your commit message is meaningful and concise. It should explain the purpose of the changes, not just describe them.
  97. - Return an empty response - the user will see the git output directly
  98. # Creating pull requests
  99. 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.
  100. IMPORTANT: When the user asks you to create a pull request, follow these steps carefully:
  101. 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:
  102. - Run a git status command to see all untracked files
  103. - Run a git diff command to see both staged and unstaged changes that will be committed
  104. - 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
  105. - 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)
  106. 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:
  107. <pr_analysis>
  108. - List the commits since diverging from the main branch
  109. - Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
  110. - Brainstorm the purpose or motivation behind these changes
  111. - Assess the impact of these changes on the overall project
  112. - Do not use tools to explore code, beyond what is available in the git context
  113. - Check for any sensitive information that shouldn't be committed
  114. - Draft a concise (1-2 bullet points) pull request summary that focuses on the "why" rather than the "what"
  115. - Ensure the summary accurately reflects all changes since diverging from the main branch
  116. - Ensure your language is clear, concise, and to the point
  117. - 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.)
  118. - Ensure the summary is not generic (avoid words like "Update" or "Fix" without context)
  119. - Review the draft summary to ensure it accurately reflects the changes and their purpose
  120. </pr_analysis>
  121. 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:
  122. - Create new branch if needed
  123. - Push to remote with -u flag if needed
  124. - Create PR using gh pr create with the format below. Use a HEREDOC to pass the body to ensure correct formatting.
  125. <example>
  126. gh pr create --title "the pr title" --body "$(cat <<'EOF'
  127. ## Summary
  128. <1-3 bullet points>
  129. EOF
  130. )"
  131. </example>
  132. Important:
  133. - NEVER update the git config
  134. - Return the PR URL when you're done, so the user can see it
  135. # Other common operations
  136. - View comments on a Github PR: gh api repos/foo/bar/pulls/123/comments