4_github_cli_usage.xml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <github_cli_usage>
  2. <overview>
  3. This mode uses the GitHub CLI (gh) for all GitHub operations.
  4. The mode assumes the user has gh installed and authenticated. If authentication errors occur,
  5. the mode will prompt the user to authenticate.
  6. Users must provide full GitHub issue URLs (e.g., https://github.com/owner/repo/issues/123)
  7. so the mode can extract the repository information dynamically.
  8. </overview>
  9. <url_parsing>
  10. <pattern>https://github.com/[owner]/[repo]/issues/[number]</pattern>
  11. <extraction>
  12. - Owner: The organization or username
  13. - Repo: The repository name
  14. - Number: The issue number
  15. </extraction>
  16. </url_parsing>
  17. <authentication_handling>
  18. <approach>Assume authenticated, handle errors gracefully</approach>
  19. <when>Only check authentication if a gh command fails with auth error</when>
  20. <error_patterns>
  21. - "gh: Not authenticated"
  22. - "HTTP 401"
  23. - "HTTP 403: Resource not accessible"
  24. </error_patterns>
  25. </authentication_handling>
  26. <primary_commands>
  27. <command name="gh_issue_view">
  28. <purpose>Retrieve the issue details at the start</purpose>
  29. <when>Always use first to get the full issue content</when>
  30. <syntax>gh issue view [issue-number] --repo [owner]/[repo] --json number,title,body,state,labels,assignees,milestone,createdAt,updatedAt,closedAt,author</syntax>
  31. <example>
  32. <execute_command>
  33. <command>gh issue view 123 --repo octocat/hello-world --json number,title,body,state,labels,assignees,milestone,createdAt,updatedAt,closedAt,author</command>
  34. </execute_command>
  35. </example>
  36. </command>
  37. <command name="gh_issue_comments">
  38. <purpose>Get additional context and requirements from issue comments</purpose>
  39. <when>Always use after viewing issue to see full discussion</when>
  40. <syntax>gh issue view [issue-number] --repo [owner]/[repo] --comments</syntax>
  41. <example>
  42. <execute_command>
  43. <command>gh issue view 123 --repo octocat/hello-world --comments</command>
  44. </execute_command>
  45. </example>
  46. </command>
  47. <command name="gh_repo_view_commits">
  48. <purpose>Find recent changes to affected files</purpose>
  49. <when>Use during codebase exploration</when>
  50. <syntax>gh api repos/[owner]/[repo]/commits?path=[file-path]&per_page=10</syntax>
  51. <example>
  52. <execute_command>
  53. <command>gh api repos/octocat/hello-world/commits?path=src/api/index.ts&per_page=10 --jq '.[].sha + " " + .[].commit.message'</command>
  54. </execute_command>
  55. </example>
  56. </command>
  57. <command name="gh_search_code">
  58. <purpose>Search for code patterns on GitHub</purpose>
  59. <when>Use to supplement local codebase_search</when>
  60. <syntax>gh search code "[search-query]" --repo [owner]/[repo]</syntax>
  61. <example>
  62. <execute_command>
  63. <command>gh search code "function handleError" --repo octocat/hello-world --limit 10</command>
  64. </execute_command>
  65. </example>
  66. </command>
  67. </primary_commands>
  68. <optional_commands>
  69. <command name="gh_issue_comment">
  70. <purpose>Add progress updates or ask questions on issues</purpose>
  71. <when>Use if clarification needed or to show progress</when>
  72. <syntax>gh issue comment [issue-number] --repo [owner]/[repo] --body "[comment]"</syntax>
  73. <example>
  74. <execute_command>
  75. <command>gh issue comment 123 --repo octocat/hello-world --body "Working on this issue. Found the root cause in the theme detection logic."</command>
  76. </execute_command>
  77. </example>
  78. </command>
  79. <command name="gh_pr_list">
  80. <purpose>Find related or similar PRs</purpose>
  81. <when>Use to understand similar changes</when>
  82. <syntax>gh pr list --repo [owner]/[repo] --search "[search-terms]"</syntax>
  83. <example>
  84. <execute_command>
  85. <command>gh pr list --repo octocat/hello-world --search "dark theme" --limit 10</command>
  86. </execute_command>
  87. </example>
  88. </command>
  89. <command name="gh_pr_diff">
  90. <purpose>View the diff of a pull request</purpose>
  91. <when>Use to understand changes in a PR</when>
  92. <syntax>gh pr diff [pr-number] --repo [owner]/[repo]</syntax>
  93. <example>
  94. <execute_command>
  95. <command>gh pr diff 456 --repo octocat/hello-world</command>
  96. </execute_command>
  97. </example>
  98. </command>
  99. </optional_commands>
  100. <pull_request_commands>
  101. <command name="gh_pr_create">
  102. <purpose>Create a pull request</purpose>
  103. <when>Use in step 11 after user approval</when>
  104. <important>
  105. - Target the repository from the provided URL
  106. - Use "main" as the base branch unless specified otherwise
  107. - Include issue number in PR title
  108. - Use --maintainer-can-modify flag
  109. </important>
  110. <syntax>gh pr create --repo [owner]/[repo] --base main --title "[title]" --body "[body]" --maintainer-can-modify</syntax>
  111. <example>
  112. <execute_command>
  113. <command>gh pr create --repo octocat/hello-world --base main --title "fix: Resolve dark theme button visibility (#123)" --body "## Description
  114. Fixes #123
  115. [Full PR description]" --maintainer-can-modify</command>
  116. </execute_command>
  117. </example>
  118. <note>
  119. If working from a fork, ensure the fork is set as the remote and push the branch there first.
  120. The gh CLI will automatically handle the fork workflow.
  121. </note>
  122. </command>
  123. <command name="gh_repo_fork">
  124. <purpose>Fork the repository if user doesn't have push access</purpose>
  125. <when>Use if user needs to work from a fork</when>
  126. <syntax>gh repo fork [owner]/[repo] --clone</syntax>
  127. <example>
  128. <execute_command>
  129. <command>gh repo fork octocat/hello-world --clone</command>
  130. </execute_command>
  131. </example>
  132. </command>
  133. <command name="gh_pr_checks">
  134. <purpose>Monitor CI/CD checks on a pull request</purpose>
  135. <when>Use after creating PR to ensure checks pass</when>
  136. <syntax>gh pr checks [pr-number] --repo [owner]/[repo] --watch</syntax>
  137. <example>
  138. <execute_command>
  139. <command>gh pr checks 789 --repo octocat/hello-world --watch</command>
  140. </execute_command>
  141. </example>
  142. </command>
  143. </pull_request_commands>
  144. <workflow_helpers>
  145. <command name="gh_api">
  146. <purpose>Access GitHub API directly for advanced operations</purpose>
  147. <when>Use when specific gh commands don't provide needed functionality</when>
  148. <examples>
  149. <!-- Get repository information -->
  150. <execute_command>
  151. <command>gh api repos/[owner]/[repo] --jq '.default_branch'</command>
  152. </execute_command>
  153. <!-- Get file contents -->
  154. <execute_command>
  155. <command>gh api repos/[owner]/[repo]/contents/README.md --jq '.content' | base64 -d</command>
  156. </execute_command>
  157. <!-- Get workflow runs -->
  158. <execute_command>
  159. <command>gh api repos/[owner]/[repo]/actions/runs --jq '.workflow_runs[0:5] | .[] | .id, .status, .conclusion'</command>
  160. </execute_command>
  161. </examples>
  162. </command>
  163. <command name="gh_run_list">
  164. <purpose>Check GitHub Actions workflow status</purpose>
  165. <when>Use to monitor CI/CD pipeline</when>
  166. <syntax>gh run list --repo [owner]/[repo] --limit 5</syntax>
  167. <example>
  168. <execute_command>
  169. <command>gh run list --repo octocat/hello-world --limit 5</command>
  170. </execute_command>
  171. </example>
  172. </command>
  173. </workflow_helpers>
  174. <error_handling>
  175. <scenario name="not_authenticated">
  176. <error>gh: Not authenticated. Run 'gh auth login' to authenticate.</error>
  177. <action>
  178. Ask user to authenticate:
  179. <ask_followup_question>
  180. <question>GitHub CLI is not authenticated. Please run 'gh auth login' in your terminal to authenticate, then let me know when you're ready to continue.</question>
  181. <follow_up>
  182. <suggest>I've authenticated, please continue</suggest>
  183. <suggest>I need help with authentication</suggest>
  184. <suggest>Let's use a different approach</suggest>
  185. </follow_up>
  186. </ask_followup_question>
  187. </action>
  188. </scenario>
  189. <scenario name="no_permissions">
  190. <error>HTTP 403: Resource not accessible by integration</error>
  191. <action>
  192. Check if working from a fork is needed:
  193. <execute_command>
  194. <command>gh repo fork [owner]/[repo] --clone</command>
  195. </execute_command>
  196. </action>
  197. </scenario>
  198. </error_handling>
  199. </github_cli_usage>