@hustle-together/api-dev-tools 3.10.1 → 3.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/.claude/agents/code-reviewer.md +170 -0
  2. package/.claude/agents/docs-generator.md +80 -0
  3. package/.claude/agents/implementation-reviewer.md +119 -0
  4. package/.claude/agents/parallel-researcher.md +52 -0
  5. package/.claude/agents/research-validator.md +116 -0
  6. package/.claude/agents/schema-generator.md +70 -0
  7. package/.claude/agents/test-writer.md +104 -0
  8. package/.claude/api-dev-state.json +331 -0
  9. package/.claude/commands/README.md +196 -0
  10. package/.claude/commands/add-command.md +212 -0
  11. package/.claude/commands/api-create.md +510 -0
  12. package/.claude/commands/api-env.md +51 -0
  13. package/.claude/commands/api-interview.md +344 -0
  14. package/.claude/commands/api-research.md +357 -0
  15. package/.claude/commands/api-status.md +279 -0
  16. package/.claude/commands/api-verify.md +232 -0
  17. package/.claude/commands/beepboop.md +96 -0
  18. package/.claude/commands/busycommit.md +111 -0
  19. package/.claude/commands/commit.md +82 -0
  20. package/.claude/commands/cycle.md +137 -0
  21. package/.claude/commands/gap.md +85 -0
  22. package/.claude/commands/green.md +137 -0
  23. package/.claude/commands/issue.md +187 -0
  24. package/.claude/commands/ntfy-setup.md +91 -0
  25. package/.claude/commands/ntfy-test.md +74 -0
  26. package/.claude/commands/plan.md +167 -0
  27. package/.claude/commands/pr.md +121 -0
  28. package/.claude/commands/publish.md +40 -0
  29. package/.claude/commands/red.md +137 -0
  30. package/.claude/commands/refactor.md +137 -0
  31. package/.claude/commands/spike.md +137 -0
  32. package/.claude/commands/summarize.md +93 -0
  33. package/.claude/commands/tdd.md +139 -0
  34. package/.claude/commands/worktree-add.md +307 -0
  35. package/.claude/commands/worktree-cleanup.md +275 -0
  36. package/.claude/hooks/api-workflow-check.py +227 -0
  37. package/.claude/hooks/enforce-deep-research.py +185 -0
  38. package/.claude/hooks/enforce-disambiguation.py +155 -0
  39. package/.claude/hooks/enforce-documentation.py +192 -0
  40. package/.claude/hooks/enforce-environment.py +253 -0
  41. package/.claude/hooks/enforce-external-research.py +328 -0
  42. package/.claude/hooks/enforce-interview.py +421 -0
  43. package/.claude/hooks/enforce-refactor.py +189 -0
  44. package/.claude/hooks/enforce-research.py +159 -0
  45. package/.claude/hooks/enforce-schema.py +186 -0
  46. package/.claude/hooks/enforce-scope.py +160 -0
  47. package/.claude/hooks/enforce-tdd-red.py +250 -0
  48. package/.claude/hooks/enforce-verify.py +186 -0
  49. package/.claude/hooks/periodic-reground.py +154 -0
  50. package/.claude/hooks/session-startup.py +151 -0
  51. package/.claude/hooks/track-tool-use.py +626 -0
  52. package/.claude/hooks/verify-after-green.py +282 -0
  53. package/.claude/hooks/verify-implementation.py +225 -0
  54. package/.claude/research/index.json +6 -0
  55. package/.claude/settings.json +144 -0
  56. package/.claude/settings.local.json +12 -0
  57. package/.claude-plugin/marketplace.json +103 -0
  58. package/.skills/README.md +293 -0
  59. package/.skills/_shared/convert-commands.py +192 -0
  60. package/.skills/_shared/hooks/api-workflow-check.py +227 -0
  61. package/.skills/_shared/hooks/enforce-deep-research.py +185 -0
  62. package/.skills/_shared/hooks/enforce-disambiguation.py +155 -0
  63. package/.skills/_shared/hooks/enforce-documentation.py +192 -0
  64. package/.skills/_shared/hooks/enforce-environment.py +253 -0
  65. package/.skills/_shared/hooks/enforce-external-research.py +328 -0
  66. package/.skills/_shared/hooks/enforce-interview.py +421 -0
  67. package/.skills/_shared/hooks/enforce-refactor.py +189 -0
  68. package/.skills/_shared/hooks/enforce-research.py +159 -0
  69. package/.skills/_shared/hooks/enforce-schema.py +186 -0
  70. package/.skills/_shared/hooks/enforce-scope.py +160 -0
  71. package/.skills/_shared/hooks/enforce-tdd-red.py +250 -0
  72. package/.skills/_shared/hooks/enforce-verify.py +186 -0
  73. package/.skills/_shared/hooks/periodic-reground.py +154 -0
  74. package/.skills/_shared/hooks/session-startup.py +151 -0
  75. package/.skills/_shared/hooks/track-tool-use.py +626 -0
  76. package/.skills/_shared/hooks/verify-after-green.py +282 -0
  77. package/.skills/_shared/hooks/verify-implementation.py +225 -0
  78. package/.skills/_shared/install.sh +114 -0
  79. package/.skills/_shared/settings.json +93 -0
  80. package/.skills/add-command/SKILL.md +227 -0
  81. package/.skills/api-create/SKILL.md +623 -0
  82. package/.skills/api-env/SKILL.md +64 -0
  83. package/.skills/api-interview/SKILL.md +357 -0
  84. package/.skills/api-research/SKILL.md +370 -0
  85. package/.skills/api-status/SKILL.md +292 -0
  86. package/.skills/api-verify/SKILL.md +245 -0
  87. package/.skills/beepboop/SKILL.md +111 -0
  88. package/.skills/busycommit/SKILL.md +126 -0
  89. package/.skills/commit/SKILL.md +97 -0
  90. package/.skills/cycle/SKILL.md +152 -0
  91. package/.skills/gap/SKILL.md +100 -0
  92. package/.skills/green/SKILL.md +152 -0
  93. package/.skills/issue/SKILL.md +202 -0
  94. package/.skills/plan/SKILL.md +182 -0
  95. package/.skills/pr/SKILL.md +136 -0
  96. package/.skills/publish/SKILL.md +160 -0
  97. package/.skills/red/SKILL.md +152 -0
  98. package/.skills/refactor/SKILL.md +152 -0
  99. package/.skills/spike/SKILL.md +152 -0
  100. package/.skills/summarize/SKILL.md +108 -0
  101. package/.skills/tdd/SKILL.md +154 -0
  102. package/.skills/update-todos/SKILL.md +250 -0
  103. package/.skills/worktree-add/SKILL.md +322 -0
  104. package/.skills/worktree-cleanup/SKILL.md +290 -0
  105. package/CHANGELOG.md +115 -0
  106. package/README.md +161 -7101
  107. package/bin/cli.js +448 -805
  108. package/commands/README.md +66 -31
  109. package/commands/add-command.md +8 -5
  110. package/commands/beepboop.md +4 -5
  111. package/commands/busycommit.md +2 -3
  112. package/commands/commit.md +2 -3
  113. package/commands/cycle.md +2 -7
  114. package/commands/gap.md +2 -3
  115. package/commands/green.md +2 -7
  116. package/commands/hustle-api-continue.md +8 -5
  117. package/commands/hustle-api-create.md +70 -29
  118. package/commands/hustle-api-env.md +1 -0
  119. package/commands/hustle-api-interview.md +32 -19
  120. package/commands/hustle-api-research.md +47 -21
  121. package/commands/hustle-api-sessions.md +8 -7
  122. package/commands/hustle-api-status.md +21 -1
  123. package/commands/hustle-api-verify.md +14 -13
  124. package/commands/hustle-combine.md +488 -241
  125. package/commands/hustle-ui-create-page.md +113 -50
  126. package/commands/hustle-ui-create.md +179 -26
  127. package/commands/issue.md +3 -8
  128. package/commands/plan.md +2 -3
  129. package/commands/pr.md +2 -3
  130. package/commands/red.md +2 -7
  131. package/commands/refactor.md +2 -7
  132. package/commands/spike.md +2 -7
  133. package/commands/summarize.md +2 -3
  134. package/commands/tdd.md +2 -7
  135. package/commands/worktree-add.md +208 -216
  136. package/commands/worktree-cleanup.md +172 -178
  137. package/hooks/api-workflow-check.py +5 -3
  138. package/hooks/enforce-component-type-confirm.py +97 -0
  139. package/hooks/lib/__init__.py +1 -0
  140. package/hooks/lib/greptile.py +355 -0
  141. package/hooks/lib/ntfy.py +209 -0
  142. package/hooks/notify-input-needed.py +73 -0
  143. package/hooks/notify-phase-complete.py +90 -0
  144. package/hooks/run-code-review.py +246 -0
  145. package/hooks/track-token-usage.py +121 -0
  146. package/package.json +33 -12
  147. package/scripts/collect-test-results.ts +102 -77
  148. package/scripts/extract-parameters.ts +112 -70
  149. package/scripts/generate-test-manifest.ts +118 -77
  150. package/templates/.env.example +57 -0
  151. package/templates/BRAND_GUIDE.md +92 -52
  152. package/templates/CLAUDE-SECTION.md +40 -37
  153. package/templates/SPEC.json +186 -38
  154. package/templates/api-dev-state.json +33 -4
  155. package/templates/api-showcase/_components/APICard.tsx +22 -18
  156. package/templates/api-showcase/_components/APIModal.tsx +110 -64
  157. package/templates/api-showcase/_components/APIShowcase.tsx +53 -35
  158. package/templates/api-showcase/_components/APITester.tsx +128 -67
  159. package/templates/api-showcase/page.tsx +4 -4
  160. package/templates/api-test/page.tsx +51 -30
  161. package/templates/api-test/test-structure/route.ts +43 -34
  162. package/templates/component/Component.stories.tsx +41 -39
  163. package/templates/component/Component.test.tsx +96 -78
  164. package/templates/component/Component.tsx +63 -52
  165. package/templates/component/Component.types.ts +10 -6
  166. package/templates/component/Component.visual.spec.ts +170 -0
  167. package/templates/component/index.ts +2 -2
  168. package/templates/dev-tools/_components/DevToolsLanding.tsx +8 -8
  169. package/templates/dev-tools/page.tsx +4 -3
  170. package/templates/mcp-servers.json +30 -2
  171. package/templates/page/page.e2e.test.ts +56 -48
  172. package/templates/page/page.tsx +3 -3
  173. package/templates/shared/HeroHeader.tsx +16 -15
  174. package/templates/shared/index.ts +1 -1
  175. package/templates/ui-showcase/_components/PreviewCard.tsx +20 -20
  176. package/templates/ui-showcase/_components/PreviewModal.tsx +149 -108
  177. package/templates/ui-showcase/_components/UIShowcase.tsx +43 -35
  178. package/templates/ui-showcase/page.tsx +4 -4
@@ -0,0 +1,307 @@
1
+ ---
2
+ description: Add a new git worktree from branch name or GitHub issue URL, copy settings, install deps, and open in current IDE
3
+ argument-hint: <branch-name-or-github-issue-url> [optional-base-branch]
4
+ ---
5
+
6
+ # Git Worktree Setup
7
+
8
+ ## General Guidelines
9
+
10
+ ### Output Style
11
+
12
+ - **Never explicitly mention TDD** in code, comments, commits, PRs, or issues
13
+ - Write natural, descriptive code without meta-commentary about the development process
14
+ - The code should speak for itself - TDD is the process, not the product
15
+
16
+ Create a new git worktree for branch: $ARGUMENTS
17
+
18
+ <current_state>
19
+ Current branch: !git branch --show-current`
20
+ Current worktrees: !git worktree list`
21
+ Remote branches: !git branch -r`
22
+ Uncommitted changes: !git status --short`
23
+ </current_state>
24
+
25
+ <execution_steps>
26
+ <step_0>
27
+ <description>Validate MCP dependencies</description>
28
+ <check_github_mcp>
29
+ <requirement>GitHub MCP server must be configured</requirement>
30
+ <fallback>If unavailable, use `gh` CLI commands</fallback>
31
+ <validation> - Try listing available MCP resources - If GitHub MCP not found, switch to CLI fallback - Inform user about MCP configuration if needed
32
+ </validation>
33
+ </check_github_mcp>
34
+ <error_handling>
35
+ If MCP validation fails: - Show clear error message - Provide setup instructions - Fallback to CLI if possible
36
+ </error_handling>
37
+ <purpose>Ensure required MCP dependencies are available before proceeding</purpose>
38
+ </step_0>
39
+
40
+ <step_1>
41
+ <description>Detect current IDE environment</description>
42
+ <detection_methods>
43
+ <method_1>
44
+ <tool>mcp**ide**getDiagnostics</tool>
45
+ <vs_code_insiders>Check for paths containing "Code - Insiders"</vs_code_insiders>
46
+ <vs_code>Check for paths containing "Code/" or "Code.app"</vs_code>
47
+ <cursor>Check for paths containing "Cursor"</cursor>
48
+ <zed>Check for paths containing "Zed"</zed>
49
+ </method_1>
50
+ <method_2>
51
+ <fallback_detection>Use which command to find available IDEs</fallback_detection>
52
+ <commands>which code-insiders code zed cursor</commands>
53
+ <priority_order>code-insiders > cursor > zed > code</priority_order>
54
+ </method_2>
55
+ </detection_methods>
56
+ <set_variables>
57
+ <ide_command>Detected command (code-insiders|code|zed|cursor)</ide_command>
58
+ <ide_name>Human-readable name</ide_name>
59
+ <supports_tasks>true for VS Code variants, false for others</supports_tasks>
60
+ </set_variables>
61
+ <purpose>Automatically detect which IDE to use for opening the new worktree</purpose>
62
+ </step_1>
63
+
64
+ <step_2>
65
+ <description>Parse the arguments</description>
66
+ <input>The user-provided arguments</input>
67
+ <expected_format>branch-name-or-github-url [optional-base-branch]</expected_format>
68
+ <example>fix/issue-123-main-content-area-visually-clipped main</example>
69
+ <example_github_url><https://github.com/owner/project/issues/123> main</example_github_url>
70
+ <default_base_branch>main (if not specified)</default_base_branch>
71
+ </step_1>
72
+
73
+ <step_2_5>
74
+ <description>Handle GitHub issue URLs</description>
75
+ <condition>If first argument matches GitHub issue URL pattern</condition>
76
+ <url_detection>Check if argument contains "github.com" and "/issues/"</url_detection>
77
+ <url_parsing>
78
+ <pattern>https://github.com/{owner}/{repo}/issues/{issue_number}</pattern>
79
+ <extract>owner, repo, issue_number from URL</extract>
80
+ </url_parsing>
81
+ <fetch_issue_details>
82
+ <tool>mcp**github**issue_read</tool>
83
+ <method>get</method>
84
+ <parameters>owner, repo, issue_number</parameters>
85
+ </fetch_issue_details>
86
+ <generate_branch_name>
87
+ <determine_type>Analyze issue title/labels to determine type (feat/fix/refactor/chore)</determine_type>
88
+ <format>{type}/{repo}-{issue_number}-{kebab-case-title}</format>
89
+ <kebab_case>Convert title to lowercase, replace spaces/special chars with hyphens</kebab_case>
90
+ <sanitization>
91
+ <rule>Always use lowercase for branch names</rule>
92
+ <rule>Replace # with - (hash symbol not allowed in git branch names)</rule>
93
+ <rule>Remove or replace other special characters: @, $, %, ^, &, \*, (, ), [, ], {, }, \, |, ;, :, ", ', <, >, ?, /, ~, `</rule>
94
+ <rule>Replace multiple consecutive hyphens with single hyphen</rule>
95
+ <rule>Trim leading/trailing hyphens</rule>
96
+ </sanitization>
97
+ <truncate>Limit total branch name to reasonable length (~60 chars)</truncate>
98
+ </generate_branch_name>
99
+ <user_confirmation>
100
+ <display>Show generated branch name and ask for confirmation</display>
101
+ <options>"Yes, proceed" or "No, exit" or "Edit branch name"</options>
102
+ <if_no>Exit command gracefully</if_no>
103
+ <if_edit>Allow user to modify the branch name</if_edit>
104
+ <if_yes>Continue with generated/modified branch name</if_yes>
105
+ </user_confirmation>
106
+ <examples>
107
+ <input>https://github.com/owner/project/issues/456</input>
108
+
109
+ <title>"Fix duplicate items in list view"</title>
110
+ <generated>fix/issue-456-duplicate-items-in-list-view</generated>
111
+ </examples>
112
+ </step_1_5>
113
+
114
+ <step_3>
115
+ <description>Add all files and stash uncommitted changes if any exist</description>
116
+ <condition>If output is not empty (has uncommitted changes)</condition>
117
+ <command>git add -A && git stash push -m "Worktree switch: Moving changes to ${branch_name}"</chained_command>
118
+ <purpose>Preserve work in progress before switching worktrees</purpose>
119
+ <note>Remember stash was created for later restoration</note>
120
+ </step_3>
121
+
122
+ <step_4>
123
+ <description>Determine worktree parent directory</description>
124
+ <check_if_in_worktree>git rev-parse --is-inside-work-tree && git worktree list --porcelain | grep "$(git rev-parse --show-toplevel)"</check_if_in_worktree>
125
+ <set_parent_path>
126
+ <if_main_worktree>Set parent_path=".."</if_main_worktree>
127
+ <if_secondary_worktree>Set parent_path="../.." (need to go up two levels)</if_secondary_worktree>
128
+ </set_parent_path>
129
+ <purpose>Correctly determine where to create new worktree regardless of current location</purpose>
130
+ <note>This handles both main worktree and secondary worktree scenarios</note>
131
+ </step_4>
132
+
133
+ <step_5>
134
+ <description>Fetch latest changes from remote</description>
135
+ <command>git fetch origin</command>
136
+ <purpose>Ensure we have the latest remote branches and main branch state</purpose>
137
+ <note>This ensures new worktrees are created from the most recent main branch</note>
138
+ </step_6>
139
+
140
+ <step_7>
141
+ <description>Check if branch exists on remote</description>
142
+ <command>git branch -r | grep "origin/${branch_name}"</command>
143
+ <decision>
144
+ <if_exists>Branch exists on remote - will checkout existing branch</if_exists>
145
+ <if_not_exists>Branch does not exist - will create new branch from base</if_not_exists>
146
+ </decision>
147
+ </step_5>
148
+
149
+ <step_6>
150
+ <description>Create the worktree</description>
151
+ <option_a_new_branch>
152
+ <condition>Remote branch does NOT exist</condition>
153
+ <command>git worktree add ${parent_path}/${branch_name} -b ${branch_name} ${base_branch}</command>
154
+ <example>git worktree add ../fix/issue-123-main-content-area-visually-clipped -b fix/issue-123-main-content-area-visually-clipped main</example>
155
+ </option_a_new_branch>
156
+ <option_b_existing_branch>
157
+ <condition>Remote branch EXISTS</condition>
158
+ <command>git worktree add ${parent_path}/${branch_name} ${branch_name}</command>
159
+ <example>git worktree add ../fix/issue-123-main-content-area-visually-clipped fix/issue-123-main-content-area-visually-clipped</example>
160
+ </option_b_existing_branch>
161
+ </step_7>
162
+
163
+ <step_8>
164
+ <description>Copy Claude settings to new worktree</description>
165
+
166
+ <source>.claude/settings.local.json</source>
167
+ <destination>${parent_path}/${branch_name}/.claude/settings.local.json</destination>
168
+ <command>cp -r .claude/settings.local.json ${parent_path}/${branch_name}/.claude/settings.local.json</command>
169
+ <purpose>Preserve all permission settings and configurations</purpose>
170
+ </step_8>
171
+
172
+ <step*9>
173
+ <description>Copy .env.local files to new worktree</description>
174
+ <search_command>find . -name ".env.local" -type f</search_command>
175
+ <copy_logic>For each .env.local file found, copy to corresponding location in new worktree</copy_logic>
176
+ <common_locations> - app/.env.local - packages/\*/.env.local - (any other .env.local files found)
177
+ </common_locations>
178
+ <copy_command>find . -name ".env.local" -type f -exec sh -c 'mkdir -p "$(dirname "${parent_path}/${branch_name}/$1")" && cp "$1" "${parent_path}/${branch_name}/$1"' *{} \;</copy_command>
179
+ <purpose>Preserve local environment configurations for development</purpose>
180
+ <note>Only copies files that exist; ignores missing ones</note>
181
+ </step_9>
182
+
183
+ <step_10>
184
+ <description>Create IDE-specific configuration (conditional)</description>
185
+ <condition>Only if supports_tasks is true (VS Code variants)</condition>
186
+ <vs_code_tasks>
187
+ <create_directory>mkdir -p ${parent_path}/${branch_name}/.vscode</create_directory>
188
+ <create_file_command>cat > ${parent_path}/${branch_name}/.vscode/tasks.json << 'EOF'
189
+ {
190
+ "version": "2.0.0",
191
+ "tasks": [
192
+ {
193
+ "label": "Auto start Claude",
194
+ "type": "shell",
195
+ "command": "claude",
196
+ "runOptions": {
197
+ "runOn": "folderOpen"
198
+ },
199
+ "presentation": {
200
+ "echo": false,
201
+ "reveal": "always",
202
+ "focus": true,
203
+ "panel": "new"
204
+ }
205
+ }
206
+ ]
207
+ }
208
+ EOF</create_file_command>
209
+ </vs_code_tasks>
210
+ <purpose>Create auto-start Claude task for VS Code variants on folder open</purpose>
211
+ <note>Only creates for VS Code variants (code, code-insiders, cursor)</note>
212
+ <skip_message>Skipping IDE-specific config for non-VS Code IDEs</skip_message>
213
+ </step_10>
214
+
215
+ <step_11>
216
+ <description>Install dependencies in new worktree</description>
217
+ <working_directory>${parent_path}/${branch_name}</working_directory>
218
+ <command>cd ${parent_path}/${branch_name} && pnpm install</command>
219
+ <purpose>Ensure all node_modules are installed for the new worktree</purpose>
220
+ </step_11>
221
+
222
+ <step_12>
223
+ <description>Apply stashed changes to new worktree (if stash was created)</description>
224
+ <condition>Only if stash was created in step_3</condition>
225
+ <working_directory>${parent_path}/${branch_name}</working_directory>
226
+ <command>cd ${parent_path}/${branch_name} && git stash pop</command>
227
+ <purpose>Restore uncommitted work-in-progress to the new worktree branch</purpose>
228
+ <note>This moves your uncommitted changes to the new branch where you'll continue working</note>
229
+ </step_12>
230
+
231
+ <step_13>
232
+ <description>Open detected IDE in new worktree</description>
233
+ <command>${ide_command} ${parent_path}/${branch_name}</command>
234
+ <ide_specific_behavior>
235
+ <vs_code_variants>Opens folder in VS Code/Insiders/Cursor with tasks.json auto-starting Claude</vs_code_variants>
236
+ <zed>Opens folder in Zed editor</zed>
237
+ <other>Uses detected IDE command to open folder</other>
238
+ </ide_specific_behavior>
239
+ <purpose>Launch development environment for the new worktree using detected IDE</purpose>
240
+ <confirmation_message>Opening worktree in ${ide_name}</confirmation_message>
241
+ </step_11>
242
+ </execution_steps>
243
+
244
+ <important_notes>
245
+
246
+ - Automatically detects and uses your current IDE (VS Code, VS Code Insiders, Cursor, Zed, etc.)
247
+ - Creates VS Code-specific tasks.json only for VS Code variants (auto-starts Claude on folder open)
248
+ - Branch names with slashes (feat/, fix/, etc.) are fully supported
249
+ - The worktree directory path will match the full branch name including slashes
250
+ - Settings are copied to maintain the same permissions across worktrees
251
+ - Environment files (.env.local) are copied to preserve local configurations
252
+ - Each worktree has its own node_modules installation
253
+ - Uncommitted changes are automatically stashed and moved to the new worktree
254
+ - Your work-in-progress seamlessly transfers to the new branch
255
+ - IDE detection fallback: checks available editors and uses priority order
256
+ </important_notes>
257
+
258
+ ## 🛡 Project Rules (Injected into every command)
259
+
260
+ 1. **NO BROKEN BUILDS:**
261
+ - Run `pnpm test` before every `/commit`
262
+ - Ensure all tests pass
263
+ - Fix any type errors immediately
264
+
265
+ 2. **API DEVELOPMENT:**
266
+ - All new APIs MUST have Zod request/response schemas
267
+ - All APIs MUST be documented in both:
268
+ - OpenAPI spec ([src/lib/openapi/](src/lib/openapi/))
269
+ - API test manifest ([src/app/api-test/api-tests-manifest.json](src/app/api-test/api-tests-manifest.json))
270
+ - Test ALL parameters and edge cases
271
+ - Include code examples and real-world outputs
272
+
273
+ 3. **TDD WORKFLOW:**
274
+ - ALWAYS use /red → /green → /refactor cycle
275
+ - NEVER write implementation without failing test first
276
+ - Use /cycle for feature development
277
+ - Use characterization tests for refactoring
278
+
279
+ 4. **API KEY MANAGEMENT:**
280
+ - Support three loading methods:
281
+ - Server environment variables
282
+ - NEXT*PUBLIC* variables (client-side)
283
+ - Custom headers (X-OpenAI-Key, X-Anthropic-Key, etc.)
284
+ - Never hardcode API keys
285
+ - Always validate key availability before use
286
+
287
+ 5. **COMPREHENSIVE TESTING:**
288
+ - When researching APIs, read actual implementation code
289
+ - Discover ALL possible parameters (not just documented ones)
290
+ - Test with various parameter combinations
291
+ - Document custom headers, query params, request/response schemas
292
+ - Include validation rules and testing notes
293
+
294
+ 6. **NO UI BLOAT:**
295
+ - This is an API project with minimal frontend
296
+ - Only keep necessary test/documentation interfaces
297
+ - Delete unused components immediately
298
+ - No unnecessary UI libraries or features
299
+
300
+ 7. **DOCUMENTATION:**
301
+ - If you change an API, you MUST update:
302
+ - OpenAPI spec
303
+ - api-tests-manifest.json
304
+ - Code examples
305
+ - Testing notes
306
+ - Document expected behavior and edge cases
307
+ - Include real-world output examples
@@ -0,0 +1,275 @@
1
+ ---
2
+ description: Clean up merged worktrees by verifying PR/issue status, consolidating settings, and removing stale worktrees
3
+ argument-hint: (no arguments)
4
+ ---
5
+
6
+ # Worktree Cleanup
7
+
8
+ ## General Guidelines
9
+
10
+ ### Output Style
11
+
12
+ - **Never explicitly mention TDD** in code, comments, commits, PRs, or issues
13
+ - Write natural, descriptive code without meta-commentary about the development process
14
+ - The code should speak for itself - TDD is the process, not the product
15
+
16
+ Clean up merged worktrees by finding the oldest merged branch, consolidating settings, and removing stale worktrees.
17
+
18
+ Additional info: $ARGUMENTS
19
+
20
+ <current_state>
21
+ Current branch: !git branch --show-current`
22
+ Current worktrees: !git worktree list`
23
+ </current_state>
24
+
25
+ <execution_steps>
26
+ <step_0>
27
+ <description>Validate MCP dependencies</description>
28
+ <check_github_mcp>
29
+ <requirement>GitHub MCP server must be configured</requirement>
30
+ <fallback>If unavailable, use `gh` CLI commands</fallback>
31
+ <validation> - Try listing available MCP resources - If GitHub MCP not found, switch to CLI fallback - Inform user about MCP configuration if needed
32
+ </validation>
33
+ </check_github_mcp>
34
+ <error_handling>
35
+ If MCP validation fails: - Show clear error message - Provide setup instructions - Fallback to CLI if possible
36
+ </error_handling>
37
+ <purpose>Ensure required MCP dependencies are available before proceeding</purpose>
38
+ </step_0>
39
+
40
+ <step_1>
41
+ <description>Verify we're in main branch</description>
42
+ <check_command>git branch --show-current</check_command>
43
+ <required_branch>main</required_branch>
44
+ <error_if_not_main>Exit with error message: "This command must be run from the main branch"</error_if_not_main>
45
+ <purpose>Ensure we're consolidating to the main worktree</purpose>
46
+ </step_1>
47
+
48
+ <step_2>
49
+ <description>Get list of all worktrees</description>
50
+ <command>git worktree list --porcelain</command>
51
+ <parse_output>Extract worktree paths and branch names</parse_output>
52
+ <exclude_main>Filter out the main worktree from cleanup candidates</exclude_main>
53
+ <purpose>Identify all worktrees that could potentially be cleaned up</purpose>
54
+ </step_2>
55
+
56
+ <step_3>
57
+ <description>Find oldest worktree by directory age</description>
58
+ <get_worktree_ages>
59
+ <command_macos>git worktree list | grep -v "main" | awk '{print $1}' | while read path; do /usr/bin/stat -f "%Sm|%N" -t "%Y-%m-%d %H:%M:%S" "$path" 2>/dev/null; done | sort</command_macos>
60
+ <command_linux>git worktree list | grep -v "main" | awk '{print $1}' | xargs stat -c "%y|%n" | sort</command_linux>
61
+ <purpose>List all worktrees sorted by directory modification time (oldest first)</purpose>
62
+ <note>Use full path /usr/bin/stat on macOS, regular stat on Linux.</note>
63
+ </get_worktree_ages>
64
+ <filter_recent>
65
+ <exclude_new>For worktrees created within the last 24 hours, let user know that this worktree might not be worth cleaning</exclude_new>
66
+ <get_current_time>date +"%Y-%m-%d %H:%M"</get_current_time>
67
+ </filter_recent>
68
+ <select_oldest>
69
+ <extract_branch_name>Parse branch name from oldest worktree path</extract_branch_name>
70
+ <important_note>DO NOT use "git branch --merged" to check merge status - it's unreliable</important_note>
71
+ <proceed_to_pr_check>Move directly to step 4 to verify PR merge status instead</proceed_to_pr_check>
72
+ </select_oldest>
73
+ <purpose>Identify oldest worktree candidate - actual merge verification happens via GitHub PR in next step</purpose>
74
+ </step_3>
75
+
76
+ <step_4>
77
+ <description>Verify GitHub PR merge status (primary merge verification)</description>
78
+ <determine_repo>
79
+ <check_remote>git remote get-url origin</check_remote>
80
+ <parse_repo>Extract owner/repo from GitHub URL</parse_repo>
81
+ <fallback>Use project repository from git remote (owner/repo format)</fallback>
82
+ </determine_repo>
83
+ <search_pr>
84
+ <tool>mcp**github**search_pull_requests</tool>
85
+ <query>repo:owner/repo head:{branch_name} base:main</query>
86
+ <purpose>Find PR for this branch targeting main</purpose>
87
+ <important>This is the PRIMARY way to verify if a branch was merged - NOT git commands</important>
88
+ </search_pr>
89
+ <verify_pr_merged>
90
+ <if_pr_found>
91
+ <get_pr_details>Use mcp**github**pull_request_read to get full PR info</get_pr_details>
92
+ <confirm_merged>Verify PR state is "closed" AND merged_at is not null AND base is "main"</confirm_merged>
93
+ <extract_issue_number>Look for issue references in PR title/body (e.g., #14533, owner/repo#14533)</extract_issue_number>
94
+ <if_merged>Proceed with cleanup - this branch was definitively merged to main</if_merged>
95
+ <if_not_merged>
96
+ <skip_worktree>This worktree is NOT merged - continue to next oldest worktree</skip_worktree>
97
+ <repeat_from_step_3>Go back and find the next oldest worktree to check</repeat_from_step_3>
98
+ </if_not_merged>
99
+ </if_pr_found>
100
+ <if_no_pr>
101
+ <skip_worktree>No PR found - this branch was likely never submitted for review</skip_worktree>
102
+ <continue_to_next>Continue checking next oldest worktree</continue_to_next>
103
+ </if_no_pr>
104
+ </verify_pr_merged>
105
+ <purpose>Use GitHub PR status as the authoritative source for merge verification instead of unreliable git commands</purpose>
106
+ </step_4>
107
+
108
+ <step_4_5>
109
+ <description>Check and close related GitHub issue</description>
110
+ <if_issue_found>
111
+ <get_issue_details>
112
+ <tool>mcp**github**issue_read</tool>
113
+ <method>get</method>
114
+ <extract_repo>From issue reference (main-repo vs cross-repo)</extract_repo>
115
+ </get_issue_details>
116
+ <check_issue_state>
117
+ <if_open>
118
+ <ask_close>Ask user: "Related issue #{number} is still open. Should I close it? (y/N)"</ask_close>
119
+ <if_yes_close>
120
+ <add_closing_comment>
121
+ <tool>mcp**github**add_issue_comment</tool>
122
+ <body_template>Closing this issue as branch {branch_name} was merged to main on {merge_date} via PR #{pr_number}.</body_template>
123
+ <get_merge_date>Extract merge date from PR details</get_merge_date>
124
+ <get_pr_number>Use PR number from search results</get_pr_number>
125
+ </add_closing_comment>
126
+ <close_issue>
127
+ <tool>mcp**github**issue_write</tool>
128
+ <method>update</method>
129
+ <state>closed</state>
130
+ <state_reason>completed</state_reason>
131
+ </close_issue>
132
+ </if_yes_close>
133
+ </if_open>
134
+ <if_closed>Inform user issue is already closed</if_closed>
135
+ </check_issue_state>
136
+ </if_issue_found>
137
+ <if_no_issue>Continue without issue management</if_no_issue>
138
+ <purpose>Ensure proper issue lifecycle management</purpose>
139
+ </step_4_5>
140
+
141
+ <step_5>
142
+ <description>Check if worktree is locked</description>
143
+ <check_command>git worktree list --porcelain | grep -A5 "worktree {path}" | grep "locked"</check_command>
144
+ <if_locked>
145
+ <unlock_command>git worktree unlock {path}</unlock_command>
146
+ <notify_user>Inform user that worktree was unlocked</notify_user>
147
+ </if_locked>
148
+ <purpose>Unlock worktree if it was locked for tracking purposes</purpose>
149
+ </step_5>
150
+
151
+ <step_6>
152
+ <description>Analyze Claude settings differences</description>
153
+ <read_main_settings>.claude/settings.local.json</read_main_settings>
154
+ <read_worktree_settings>{worktree_path}/.claude/settings.local.json</read_worktree_settings>
155
+ <compare_allow_lists>
156
+ <extract_main_allows>Extract "allow" array from main settings</extract_main_allows>
157
+ <extract_worktree_allows>Extract "allow" array from worktree settings</extract_worktree_allows>
158
+ <find_differences>Identify entries in worktree that are not in main</find_differences>
159
+ </compare_allow_lists>
160
+ <filter_suggestions>
161
+ <include_filesystem>Read permissions for filesystem paths</include_filesystem>
162
+ <exclude_intrusive>Exclude bash commands, write permissions, etc.</exclude_intrusive>
163
+ <focus_user_specific>Include only user-specific, non-disruptive entries</focus_user_specific>
164
+ </filter_suggestions>
165
+ <purpose>Identify useful settings to consolidate before cleanup</purpose>
166
+ </step_6>
167
+
168
+ <step_7>
169
+ <description>Suggest settings consolidation</description>
170
+ <if_differences_found>
171
+ <display_suggestions>Show filtered differences to user</display_suggestions>
172
+ <ask_confirmation>Ask user which entries to add to main settings</ask_confirmation>
173
+ <apply_changes>Update main .claude/settings.local.json with selected entries</apply_changes>
174
+ </if_differences_found>
175
+ <if_no_differences>Inform user no settings need consolidation</if_no_differences>
176
+ <purpose>Preserve useful development settings before removing worktree</purpose>
177
+ </step_7>
178
+
179
+ <step_8>
180
+ <description>Final cleanup confirmation</description>
181
+
182
+ <summary>
183
+ <display_worktree>Show worktree path and branch name</display_worktree>
184
+ <show_pr_status>Show merged PR details if found</show_pr_status>
185
+ <show_issue_status>Show related issue status if found</show_issue_status>
186
+ <show_last_activity>Display directory creation/modification date</show_last_activity>
187
+ </summary>
188
+ <safety_checks>
189
+ <check_uncommitted>git status --porcelain in worktree directory</check_uncommitted>
190
+ <warn_if_dirty>Alert user if uncommitted changes exist</warn_if_dirty>
191
+ </safety_checks>
192
+ <ask_deletion>Ask user confirmation: "Delete this worktree? (y/N)"</ask_deletion>
193
+ <purpose>Final safety check before irreversible deletion</purpose>
194
+ </step_8>
195
+
196
+ <step_9>
197
+ <description>Delete worktree</description>
198
+ <if_confirmed>
199
+ <remove_worktree>git worktree remove {path} --force</remove_worktree>
200
+ <cleanup_branch>git branch -d {branch_name}</cleanup_branch>
201
+ <success_message>Inform user worktree was successfully removed</success_message>
202
+ <next_steps>Suggest running command again to find next candidate</next_steps>
203
+ </if_confirmed>
204
+ <if_declined>Exit gracefully with no changes</if_declined>
205
+ <purpose>Perform the actual cleanup and guide user for next iteration</purpose>
206
+ </step_9>
207
+ </execution_steps>
208
+
209
+ <important_notes>
210
+
211
+ - Uses GitHub PR merge status as the ONLY reliable way to verify if a branch was merged
212
+ - DOES NOT use "git branch --merged" command as it's unreliable for merge verification
213
+ - Only processes branches with PRs that were definitively merged to main
214
+ - Skips worktrees without merged PRs and continues to next oldest candidate
215
+ - Checks and optionally closes related GitHub issues
216
+ - Prioritizes oldest worktrees by directory age first for systematic cleanup
217
+ - Warns about very recent worktrees (created within 24 hours) to avoid cleaning active work
218
+ - Preserves useful development settings before deletion
219
+ - Requires explicit confirmation before any destructive actions
220
+ - Handles locked worktrees automatically
221
+ - Processes one worktree at a time to maintain control
222
+ - Must be run from main branch for safety
223
+ - Works with standard GitHub repository URLs (owner/repo format)
224
+ </important_notes>
225
+
226
+ ## 🛡 Project Rules (Injected into every command)
227
+
228
+ 1. **NO BROKEN BUILDS:**
229
+ - Run `pnpm test` before every `/commit`
230
+ - Ensure all tests pass
231
+ - Fix any type errors immediately
232
+
233
+ 2. **API DEVELOPMENT:**
234
+ - All new APIs MUST have Zod request/response schemas
235
+ - All APIs MUST be documented in both:
236
+ - OpenAPI spec ([src/lib/openapi/](src/lib/openapi/))
237
+ - API test manifest ([src/app/api-test/api-tests-manifest.json](src/app/api-test/api-tests-manifest.json))
238
+ - Test ALL parameters and edge cases
239
+ - Include code examples and real-world outputs
240
+
241
+ 3. **TDD WORKFLOW:**
242
+ - ALWAYS use /red → /green → /refactor cycle
243
+ - NEVER write implementation without failing test first
244
+ - Use /cycle for feature development
245
+ - Use characterization tests for refactoring
246
+
247
+ 4. **API KEY MANAGEMENT:**
248
+ - Support three loading methods:
249
+ - Server environment variables
250
+ - NEXT*PUBLIC* variables (client-side)
251
+ - Custom headers (X-OpenAI-Key, X-Anthropic-Key, etc.)
252
+ - Never hardcode API keys
253
+ - Always validate key availability before use
254
+
255
+ 5. **COMPREHENSIVE TESTING:**
256
+ - When researching APIs, read actual implementation code
257
+ - Discover ALL possible parameters (not just documented ones)
258
+ - Test with various parameter combinations
259
+ - Document custom headers, query params, request/response schemas
260
+ - Include validation rules and testing notes
261
+
262
+ 6. **NO UI BLOAT:**
263
+ - This is an API project with minimal frontend
264
+ - Only keep necessary test/documentation interfaces
265
+ - Delete unused components immediately
266
+ - No unnecessary UI libraries or features
267
+
268
+ 7. **DOCUMENTATION:**
269
+ - If you change an API, you MUST update:
270
+ - OpenAPI spec
271
+ - api-tests-manifest.json
272
+ - Code examples
273
+ - Testing notes
274
+ - Document expected behavior and edge cases
275
+ - Include real-world output examples