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