bash.txt 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 LS tool to verify the parent directory exists and is the correct location
  5. - For example, before running "mkdir foo/bar", first use LS 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., cd "path with spaces/file.txt")
  8. - Examples of proper quoting:
  9. - cd "/Users/name/My Documents" (correct)
  10. - cd /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). If not specified, commands will timeout after 120000ms (2 minutes).
  18. - It is very helpful if you write a clear, concise description of what this command does in 5-10 words.
  19. - If the output exceeds 30000 characters, output will be truncated before being returned to you.
  20. - VERY IMPORTANT: You MUST avoid using search commands like `find` and `grep`. Instead use Grep, Glob, or Task to search. You MUST avoid read tools like `cat`, `head`, `tail`, and `ls`, and use Read and LS to read files.
  21. - If you _still_ need to run `grep`, STOP. ALWAYS USE ripgrep at `rg` (or /usr/bin/rg) first, which all OpenCode users have pre-installed.
  22. - When issuing multiple commands, use the ';' or '&&' operator to separate them. DO NOT use newlines (newlines are ok in quoted strings).
  23. - Try to maintain your current working directory throughout the session by using absolute paths and avoiding usage of `cd`. You may use `cd` if the User explicitly requests it.
  24. <good-example>
  25. pytest /foo/bar/tests
  26. </good-example>
  27. <bad-example>
  28. cd /foo/bar && pytest tests
  29. </bad-example>
  30. # Committing changes with git
  31. When the user asks you to create a new git commit, follow these steps carefully:
  32. 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:
  33. - Run a git status command to see all untracked files.
  34. - Run a git diff command to see both staged and unstaged changes that will be committed.
  35. - Run a git log command to see recent commit messages, so that you can follow this repository's commit message style.
  36. 2. Analyze all staged changes (both previously staged and newly added) and draft a commit message. Wrap your analysis process in <commit_analysis> tags:
  37. <commit_analysis>
  38. - List the files that have been changed or added
  39. - Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
  40. - Brainstorm the purpose or motivation behind these changes
  41. - Assess the impact of these changes on the overall project
  42. - Check for any sensitive information that shouldn't be committed
  43. - Draft a concise (1-2 sentences) commit message that focuses on the "why" rather than the "what"
  44. - Ensure your language is clear, concise, and to the point
  45. - 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.)
  46. - Ensure the message is not generic (avoid words like "Update" or "Fix" without context)
  47. - Review the draft message to ensure it accurately reflects the changes and their purpose
  48. </commit_analysis>
  49. 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:
  50. - Add relevant untracked files to the staging area.
  51. - Create the commit with a message ending with:
  52. 🤖 Generated with [OpenCode](https://opencode.ai)
  53. Co-Authored-By: OpenCode <noreply@opencode.ai>
  54. - Run git status to make sure the commit succeeded.
  55. 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.
  56. Important notes:
  57. - 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.
  58. - NEVER update the git config
  59. - DO NOT run additional commands to read or explore code, beyond what is available in the git context
  60. - DO NOT push to the remote repository
  61. - 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.
  62. - If there are no changes to commit (i.e., no untracked files and no modifications), do not create an empty commit
  63. - Ensure your commit message is meaningful and concise. It should explain the purpose of the changes, not just describe them.
  64. - Return an empty response - the user will see the git output directly
  65. - In order to ensure good formatting, ALWAYS pass the commit message via a HEREDOC, a la this example:
  66. <example>
  67. git commit -m "$(cat <<'EOF'
  68. Commit message here.
  69. 🤖 Generated with [OpenCode](https://opencode.ai)
  70. Co-Authored-By: OpenCode <noreply@opencode.ai>
  71. EOF
  72. )"
  73. </example>
  74. # Creating pull requests
  75. 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.
  76. IMPORTANT: When the user asks you to create a pull request, follow these steps carefully:
  77. 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:
  78. - Run a git status command to see all untracked files
  79. - Run a git diff command to see both staged and unstaged changes that will be committed
  80. - 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
  81. - 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)
  82. 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:
  83. <pr_analysis>
  84. - List the commits since diverging from the main branch
  85. - Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
  86. - Brainstorm the purpose or motivation behind these changes
  87. - Assess the impact of these changes on the overall project
  88. - Do not use tools to explore code, beyond what is available in the git context
  89. - Check for any sensitive information that shouldn't be committed
  90. - Draft a concise (1-2 bullet points) pull request summary that focuses on the "why" rather than the "what"
  91. - Ensure the summary accurately reflects all changes since diverging from the main branch
  92. - Ensure your language is clear, concise, and to the point
  93. - 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.)
  94. - Ensure the summary is not generic (avoid words like "Update" or "Fix" without context)
  95. - Review the draft summary to ensure it accurately reflects the changes and their purpose
  96. </pr_analysis>
  97. 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:
  98. - Create new branch if needed
  99. - Push to remote with -u flag if needed
  100. - Create PR using gh pr create with the format below. Use a HEREDOC to pass the body to ensure correct formatting.
  101. <example>
  102. gh pr create --title "the pr title" --body "$(cat <<'EOF'
  103. ## Summary
  104. <1-3 bullet points>
  105. ## Test plan
  106. [Checklist of TODOs for testing the pull request...]
  107. 🤖 Generated with [OpenCode](https://opencode.ai)
  108. EOF
  109. )"
  110. </example>
  111. Important:
  112. - NEVER update the git config
  113. - Return the PR URL when you're done, so the user can see it
  114. # Other common operations
  115. - View comments on a Github PR: gh api repos/foo/bar/pulls/123/comments