@jspg-ai/coding-bb 0.0.1 → 0.0.2-beta.22

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 (145) hide show
  1. package/cbb/bin/cbb.js +6 -0
  2. package/cbb/bin/cbbm.js +6 -0
  3. package/cbb/dev-standards/rules/cbb-ai-behavior.md +103 -103
  4. package/cbb/dev-standards/rules/cbb-priority.md +55 -55
  5. package/cbb/lib/install/claude-code.js +2 -0
  6. package/cbb/lib/install/init.js +496 -290
  7. package/cbb/lib/install/opencode.js +31 -0
  8. package/cbb/lib/install/qoder.js +2 -0
  9. package/cbb/lib/install/workspaces.js +53 -13
  10. package/cbb/lib/openspec/index.js +3 -3
  11. package/cbb/lib/superpowers/index.js +1 -1
  12. package/cbb/lib/utils/check-update.js +16 -14
  13. package/cbb/lib/utils/gitignore.js +2 -1
  14. package/cbb/lib/utils/output.js +92 -4
  15. package/cbb/lib/utils/version.js +2 -31
  16. package/cbb/lib/wiki/cli.js +25 -25
  17. package/cbb/lib/wiki/index.js +16 -16
  18. package/cbb/tools/cbb-design-to-wiki/SKILL.md +14 -14
  19. package/cbb/tools/cbb-wiki-ops/SKILL.md +22 -22
  20. package/cbb/worktrees/_shared/scripts/find-target-worktree.js +2 -2
  21. package/cbb/worktrees/_shared/scripts/find-workspace-root.js +7 -7
  22. package/cbb/worktrees/_shared/scripts/push-core.js +18 -0
  23. package/cbb/worktrees/commands/{close.md → worktree-close.md} +8 -8
  24. package/cbb/worktrees/commands/{init.md → worktree-init.md} +9 -9
  25. package/cbb/worktrees/commands/{push.md → worktree-push.md} +3 -3
  26. package/cbb/worktrees/skills/{openspec-close-worktree → cbb-worktree-close}/SKILL.md +20 -20
  27. package/cbb/worktrees/skills/{openspec-close-worktree → cbb-worktree-close}/scripts/check-env.js +4 -4
  28. package/cbb/worktrees/skills/{openspec-close-worktree → cbb-worktree-close}/scripts/check-unarchived.js +1 -1
  29. package/cbb/worktrees/skills/{openspec-close-worktree → cbb-worktree-close}/scripts/delete-branches.js +3 -3
  30. package/cbb/worktrees/skills/{openspec-close-worktree → cbb-worktree-close}/scripts/discover-apps.js +6 -6
  31. package/cbb/worktrees/skills/{openspec-extend-worktree → cbb-worktree-close}/scripts/find-target-worktree.js +2 -2
  32. package/cbb/worktrees/skills/{openspec-push-worktrees → cbb-worktree-close}/scripts/find-workspace-root.js +7 -7
  33. package/cbb/worktrees/skills/{openspec-close-worktree → cbb-worktree-close}/scripts/remove-worktrees.js +4 -4
  34. package/cbb/worktrees/skills/{openspec-close-worktree → cbb-worktree-close}/scripts/safety-check.js +4 -4
  35. package/cbb/worktrees/skills/{openspec-init-worktree → cbb-worktree-init}/SKILL.md +81 -107
  36. package/cbb/worktrees/skills/{openspec-init-worktree → cbb-worktree-init}/scripts/auto-open.js +1 -1
  37. package/cbb/worktrees/skills/{openspec-init-worktree → cbb-worktree-init}/scripts/check-env-deep.js +4 -4
  38. package/cbb/worktrees/skills/{openspec-init-worktree → cbb-worktree-init}/scripts/check-env.js +6 -6
  39. package/cbb/worktrees/skills/{openspec-init-worktree → cbb-worktree-init}/scripts/check-repos.js +4 -4
  40. package/cbb/worktrees/skills/{openspec-init-worktree → cbb-worktree-init}/scripts/create-branches.js +4 -4
  41. package/cbb/worktrees/skills/{openspec-init-worktree → cbb-worktree-init}/scripts/create-worktrees.js +8 -7
  42. package/cbb/worktrees/skills/{openspec-close-worktree → cbb-worktree-init}/scripts/find-workspace-root.js +7 -7
  43. package/cbb/worktrees/skills/{openspec-init-worktree → cbb-worktree-init}/scripts/install-ai.js +33 -33
  44. package/cbb/worktrees/skills/{openspec-init-worktree → cbb-worktree-init}/scripts/parse-config.js +7 -7
  45. package/cbb/worktrees/skills/{openspec-init-worktree → cbb-worktree-init}/scripts/push-branches.js +9 -7
  46. package/cbb/worktrees/skills/{openspec-extend-worktree → cbb-worktree-init}/scripts/push-core.js +18 -0
  47. package/cbb/worktrees/skills/{openspec-init-worktree → cbb-worktree-init}/scripts/sync-repos.js +10 -12
  48. package/cbb/worktrees/skills/{openspec-init-worktree → cbb-worktree-init}/scripts/update-gitignore.js +19 -6
  49. package/cbb/worktrees/skills/{openspec-push-worktrees → cbb-worktree-push}/SKILL.md +16 -16
  50. package/cbb/worktrees/skills/{openspec-push-worktrees → cbb-worktree-push}/scripts/commit-worktrees.js +2 -2
  51. package/cbb/worktrees/skills/{openspec-push-worktrees → cbb-worktree-push}/scripts/find-target-worktree.js +2 -2
  52. package/cbb/worktrees/skills/{openspec-extend-worktree → cbb-worktree-push}/scripts/find-workspace-root.js +7 -7
  53. package/cbb/worktrees/skills/{openspec-push-worktrees → cbb-worktree-push}/scripts/push-core.js +18 -0
  54. package/cbb/worktrees/skills/{openspec-push-worktrees → cbb-worktree-push}/scripts/push-worktrees.js +7 -5
  55. package/config/workspace-config.sample.json +18 -0
  56. package/config/workspaces.json +11 -6
  57. package/openspec/.version +6 -6
  58. package/openspec/commands/apply.md +7 -7
  59. package/openspec/commands/archive.md +7 -7
  60. package/openspec/commands/bulk-archive.md +7 -7
  61. package/openspec/commands/continue.md +7 -7
  62. package/openspec/commands/explore.md +7 -7
  63. package/openspec/commands/ff.md +7 -7
  64. package/openspec/commands/new.md +7 -7
  65. package/openspec/commands/onboard.md +7 -7
  66. package/openspec/commands/propose.md +7 -7
  67. package/openspec/commands/sync.md +7 -7
  68. package/openspec/commands/update.md +7 -7
  69. package/openspec/commands/verify.md +7 -7
  70. package/openspec/skills/openspec-apply-change/SKILL.md +187 -187
  71. package/openspec/skills/openspec-archive-change/SKILL.md +181 -181
  72. package/openspec/skills/openspec-bulk-archive-change/SKILL.md +338 -338
  73. package/openspec/skills/openspec-continue-change/SKILL.md +117 -117
  74. package/openspec/skills/openspec-explore/SKILL.md +342 -342
  75. package/openspec/skills/openspec-ff-change/SKILL.md +116 -116
  76. package/openspec/skills/openspec-new-change/SKILL.md +76 -76
  77. package/openspec/skills/openspec-onboard/SKILL.md +560 -560
  78. package/openspec/skills/openspec-propose/SKILL.md +162 -162
  79. package/openspec/skills/openspec-sync-specs/SKILL.md +261 -261
  80. package/openspec/skills/openspec-update-change/SKILL.md +90 -90
  81. package/openspec/skills/openspec-verify-change/SKILL.md +174 -174
  82. package/package.json +4 -3
  83. package/superpowers/.version +6 -6
  84. package/superpowers/skills/brainstorming/SKILL.md +250 -250
  85. package/superpowers/skills/brainstorming/scripts/helper.js +167 -167
  86. package/superpowers/skills/brainstorming/scripts/start-server.sh +209 -209
  87. package/superpowers/skills/brainstorming/scripts/stop-server.sh +120 -120
  88. package/superpowers/skills/brainstorming/spec-document-reviewer-prompt.md +49 -49
  89. package/superpowers/skills/brainstorming/visual-companion.md +299 -299
  90. package/superpowers/skills/dispatching-parallel-agents/SKILL.md +167 -167
  91. package/superpowers/skills/executing-plans/SKILL.md +64 -64
  92. package/superpowers/skills/finishing-a-development-branch/SKILL.md +225 -225
  93. package/superpowers/skills/receiving-code-review/SKILL.md +205 -205
  94. package/superpowers/skills/requesting-code-review/SKILL.md +95 -95
  95. package/superpowers/skills/requesting-code-review/code-reviewer.md +181 -181
  96. package/superpowers/skills/subagent-driven-development/SKILL.md +568 -568
  97. package/superpowers/skills/subagent-driven-development/implementer-prompt.md +154 -154
  98. package/superpowers/skills/subagent-driven-development/re-review-prompt.md +115 -115
  99. package/superpowers/skills/subagent-driven-development/task-reviewer-prompt.md +207 -207
  100. package/superpowers/skills/systematic-debugging/CREATION-LOG.md +119 -119
  101. package/superpowers/skills/systematic-debugging/SKILL.md +283 -283
  102. package/superpowers/skills/systematic-debugging/condition-based-waiting-example.ts +158 -158
  103. package/superpowers/skills/systematic-debugging/condition-based-waiting.md +115 -115
  104. package/superpowers/skills/systematic-debugging/defense-in-depth.md +122 -122
  105. package/superpowers/skills/systematic-debugging/find-polluter.sh +72 -72
  106. package/superpowers/skills/systematic-debugging/root-cause-tracing.md +169 -169
  107. package/superpowers/skills/systematic-debugging/test-academic.md +14 -14
  108. package/superpowers/skills/systematic-debugging/test-pressure-1.md +58 -58
  109. package/superpowers/skills/systematic-debugging/test-pressure-2.md +68 -68
  110. package/superpowers/skills/systematic-debugging/test-pressure-3.md +69 -69
  111. package/superpowers/skills/test-driven-development/SKILL.md +320 -320
  112. package/superpowers/skills/test-driven-development/writing-good-tests.md +198 -198
  113. package/superpowers/skills/using-git-worktrees/SKILL.md +167 -167
  114. package/superpowers/skills/using-superpowers/SKILL.md +63 -63
  115. package/superpowers/skills/using-superpowers/references/antigravity-tools.md +23 -23
  116. package/superpowers/skills/using-superpowers/references/codex-tools.md +108 -108
  117. package/superpowers/skills/using-superpowers/references/gemini-tools.md +63 -63
  118. package/superpowers/skills/using-superpowers/references/hermes-tools.md +56 -56
  119. package/superpowers/skills/using-superpowers/references/pi-tools.md +16 -16
  120. package/superpowers/skills/verification-before-completion/SKILL.md +120 -120
  121. package/superpowers/skills/writing-plans/SKILL.md +171 -171
  122. package/superpowers/skills/writing-plans/plan-document-reviewer-prompt.md +49 -49
  123. package/superpowers/skills/writing-skills/SKILL.md +679 -679
  124. package/superpowers/skills/writing-skills/anthropic-best-practices.md +1150 -1150
  125. package/superpowers/skills/writing-skills/examples/CLAUDE_MD_TESTING.md +189 -189
  126. package/superpowers/skills/writing-skills/persuasion-principles.md +187 -187
  127. package/superpowers/skills/writing-skills/render-graphs.js +169 -169
  128. package/superpowers/skills/writing-skills/testing-skills-with-subagents.md +384 -384
  129. package/cbb/worktrees/commands/extend.md +0 -65
  130. package/cbb/worktrees/skills/openspec-close-worktree/scripts/find-target-worktree.js +0 -96
  131. package/cbb/worktrees/skills/openspec-extend-worktree/SKILL.md +0 -390
  132. package/cbb/worktrees/skills/openspec-extend-worktree/scripts/check-env.js +0 -95
  133. package/cbb/worktrees/skills/openspec-extend-worktree/scripts/check-repos.js +0 -98
  134. package/cbb/worktrees/skills/openspec-extend-worktree/scripts/create-branches-and-worktrees.js +0 -135
  135. package/cbb/worktrees/skills/openspec-extend-worktree/scripts/install-ai.js +0 -150
  136. package/cbb/worktrees/skills/openspec-extend-worktree/scripts/list-available-apps.js +0 -88
  137. package/cbb/worktrees/skills/openspec-extend-worktree/scripts/sync-repos.js +0 -93
  138. package/cbb/worktrees/skills/openspec-init-worktree/scripts/find-workspace-root.js +0 -67
  139. package/cbb/worktrees/skills/openspec-init-worktree/scripts/generate-app-options.js +0 -93
  140. package/cbb/worktrees/skills/openspec-init-worktree/scripts/push-core.js +0 -136
  141. package/cbb/worktrees/skills/openspec-push-worktrees/scripts/silence-popup.js +0 -23
  142. package/config/config.sample.json +0 -16
  143. /package/cbb/worktrees/skills/{openspec-close-worktree → cbb-worktree-close}/scripts/silence-popup.js +0 -0
  144. /package/cbb/worktrees/skills/{openspec-extend-worktree → cbb-worktree-init}/scripts/silence-popup.js +0 -0
  145. /package/cbb/worktrees/skills/{openspec-init-worktree → cbb-worktree-push}/scripts/silence-popup.js +0 -0
@@ -1,225 +1,225 @@
1
- ---
2
- name: finishing-a-development-branch
3
- description: Use when implementation is complete, all tests pass, and you need to decide how to integrate the work
4
- ---
5
-
6
- # Finishing a Development Branch
7
-
8
- ## Overview
9
-
10
- **Core principle:** Verify tests → Detect environment → Present options → Execute choice → Clean up.
11
-
12
- **Announce at start:** "I'm using the finishing-a-development-branch skill to complete this work."
13
-
14
- ## Step 1: Verify Tests
15
-
16
- Run the project's full test suite (`npm test` / `cargo test` / `pytest` / `go test ./...`).
17
-
18
- **If tests fail**, report the failures and stop — the menu comes after a green suite:
19
-
20
- ```
21
- Tests failing (<N> failures). Must fix before completing:
22
-
23
- [Show failures]
24
- ```
25
-
26
- **If tests pass:** continue to Step 2.
27
-
28
- ## Step 2: Detect Environment
29
-
30
- ```bash
31
- GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
32
- GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
33
- # Capture now, while still inside the workspace — Step 5 changes directory
34
- # before cleanup (Step 6) needs this value
35
- WORKTREE_PATH=$(git rev-parse --show-toplevel)
36
- ```
37
-
38
- This determines which menu to show and how cleanup works:
39
-
40
- | State | Menu | Cleanup |
41
- |-------|------|---------|
42
- | `GIT_DIR == GIT_COMMON` (normal repo) | Standard 3 options | No worktree to clean up |
43
- | `GIT_DIR != GIT_COMMON`, named branch | Standard 3 options | Provenance-based (see Step 6) |
44
- | `GIT_DIR != GIT_COMMON`, detached HEAD | Reduced 2 options (no merge) | Externally managed — leave in place |
45
-
46
- ## Step 3: Determine Base Branch
47
-
48
- The base branch is whatever this work forked from — usually named in the
49
- plan, the conversation, or the branch's upstream. If it is not already
50
- known, ask: "This branch split from <your best guess> - is that correct?"
51
- Confirm before merging: merging into the wrong base is expensive to undo.
52
-
53
- ## Step 4: Present Options
54
-
55
- **Normal repo and named-branch worktree — present exactly these 3 options:**
56
-
57
- ```
58
- Implementation complete. What would you like to do?
59
-
60
- 1. Merge back to <base-branch> locally
61
- 2. Push and create a Pull Request
62
- 3. Keep the branch as-is (I'll handle it later)
63
-
64
- Which option?
65
- ```
66
-
67
- **Detached HEAD — present exactly these 2 options:**
68
-
69
- ```
70
- Implementation complete. You're on a detached HEAD (externally managed workspace).
71
-
72
- 1. Push as new branch and create a Pull Request
73
- 2. Keep as-is (I'll handle it later)
74
-
75
- Which option?
76
- ```
77
-
78
- Present the menu exactly as written — concise, with every option coming
79
- from the list above. Discarding the work happens only in response to your
80
- human partner explicitly asking for it (see "If your human partner asks to
81
- discard the work" below). Wait for their answer; the integration decision
82
- is theirs.
83
-
84
- ## Step 5: Execute Choice
85
-
86
- ### Option 1: Merge Locally
87
-
88
- ```bash
89
- # Get main repo root for CWD safety
90
- MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel)
91
- cd "$MAIN_ROOT"
92
-
93
- # Merge first — verify success before removing anything
94
- git checkout <base-branch>
95
- git pull
96
- git merge <feature-branch>
97
-
98
- # Verify tests on merged result
99
- <test command>
100
- ```
101
-
102
- If tests fail on the merged result: stop, leave the worktree and branch in
103
- place, and investigate — nothing has been pushed, so the merge is local
104
- and recoverable.
105
-
106
- Once the merged result is green: clean up the worktree (Step 6), then
107
- delete the branch:
108
-
109
- ```bash
110
- git branch -d <feature-branch>
111
- ```
112
-
113
- ### Option 2: Push and Create PR
114
-
115
- ```bash
116
- git push -u origin <feature-branch>
117
- # From a detached HEAD, name the new branch on the remote:
118
- # git push origin HEAD:refs/heads/<new-branch>
119
- ```
120
-
121
- Then create the pull/merge request against <base-branch> with the forge's
122
- tooling — its CLI if one is available, or the creation URL most forges
123
- print when you push — following the repo's PR template and conventions if
124
- present, and report the URL to your human partner.
125
-
126
- Keep the worktree — your human partner iterates on PR feedback there.
127
-
128
- ### Option 3: Keep As-Is
129
-
130
- Report: "Keeping branch <name>. Worktree preserved at <path>."
131
-
132
- ### If your human partner asks to discard the work
133
-
134
- This path exists only as a response to an explicit request to throw the
135
- work away. Confirm first:
136
-
137
- ```
138
- This will permanently delete:
139
- - Branch <name>
140
- - All commits: <commit-list>
141
- - Worktree at <path>
142
-
143
- Type 'discard' to confirm.
144
- ```
145
-
146
- Wait for that exact confirmation. When it arrives:
147
-
148
- ```bash
149
- MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel)
150
- cd "$MAIN_ROOT"
151
- ```
152
-
153
- Then clean up the worktree (Step 6) and force-delete the branch:
154
-
155
- ```bash
156
- git branch -D <feature-branch>
157
- ```
158
-
159
- ## Step 6: Cleanup Workspace
160
-
161
- **Runs for Option 1 and confirmed discards.** Options 2 and 3 always
162
- preserve the worktree. Both callers have already changed directory to the
163
- main repo root — worktree removal must run from outside the worktree —
164
- and use the `GIT_DIR`/`GIT_COMMON`/`WORKTREE_PATH` values captured in
165
- Step 2, from before that directory change.
166
-
167
- **If `GIT_DIR == GIT_COMMON`:** Normal repo, no worktree to clean up. Done.
168
-
169
- **If `WORKTREE_PATH` is under `.worktrees/` or `worktrees/`:** Superpowers
170
- created this worktree — we own cleanup:
171
-
172
- ```bash
173
- git worktree remove "$WORKTREE_PATH"
174
- git worktree prune # Self-healing: clean up any stale registrations
175
- ```
176
-
177
- **If removal is refused** (`contains modified or untracked files`): the
178
- worktree holds files that exist nowhere else — uncommitted plans, notes,
179
- or scratch work. Never `--force` on your own initiative. Show your human
180
- partner what is at stake and ask:
181
-
182
- ```bash
183
- git -C "$WORKTREE_PATH" status --porcelain -uall
184
- ```
185
-
186
- ```
187
- Worktree removal refused — these files were never committed:
188
-
189
- <file list>
190
-
191
- 1. Commit them to <branch> before cleanup
192
- 2. Move them into <main repo root>
193
- 3. Delete them (unrecoverable)
194
-
195
- Which?
196
- ```
197
-
198
- Carry out the choice, then remove the worktree.
199
-
200
- **Otherwise:** The host environment owns this workspace — leave it in
201
- place. If your platform provides a workspace-exit tool, use it.
202
-
203
- ## Quick Reference
204
-
205
- | Option | Merge | Push | Keep Worktree | Cleanup Branch |
206
- |--------|-------|------|---------------|----------------|
207
- | 1. Merge locally | yes | - | - | yes |
208
- | 2. Create PR | - | yes | yes | - |
209
- | 3. Keep as-is | - | - | yes | - |
210
- | Discard (explicit request only) | - | - | - | yes (force) |
211
-
212
- ## Common Rationalizations
213
-
214
- | Excuse | Reality |
215
- |--------|---------|
216
- | "Tests passed earlier this session" | Run the suite on the tree you are about to integrate. A green run only proves the tree it ran on. |
217
- | "They obviously want it merged" | Integration is your human partner's decision. Present the menu and wait. |
218
- | "They seem done with this feature — I'll offer to discard it" | The menu is complete as written. Discard happens only when your human partner asks for it in so many words. |
219
- | "'Yeah, get rid of it' counts as confirmation" | Only the typed word `discard` authorizes deletion. |
220
- | "The PR is up, so the worktree is clutter now" | PR feedback gets fixed in that worktree. It stays until the work lands. |
221
- | "This other worktree looks stale — I'll clean it too" | Clean up only worktrees under `.worktrees/` or `worktrees/`. Everything else belongs to the host. |
222
- | "Removal refused — `--force` is just finishing the cleanup" | The refusal means files exist only in that worktree. `--force` destroys them permanently. Show your human partner and ask. |
223
- | "The merged-result failure is probably flaky" | A failing merged result stops everything. Branch and worktree stay put while you investigate. |
224
- | "The base branch is obviously main" | Confirm the fork point or ask. Merging into the wrong base is expensive to undo. |
225
- | "The push was rejected — force-push will fix it" | A rejected push means the remote moved. Investigate; force-push only on your human partner's explicit request. |
1
+ ---
2
+ name: finishing-a-development-branch
3
+ description: Use when implementation is complete, all tests pass, and you need to decide how to integrate the work
4
+ ---
5
+
6
+ # Finishing a Development Branch
7
+
8
+ ## Overview
9
+
10
+ **Core principle:** Verify tests → Detect environment → Present options → Execute choice → Clean up.
11
+
12
+ **Announce at start:** "I'm using the finishing-a-development-branch skill to complete this work."
13
+
14
+ ## Step 1: Verify Tests
15
+
16
+ Run the project's full test suite (`npm test` / `cargo test` / `pytest` / `go test ./...`).
17
+
18
+ **If tests fail**, report the failures and stop — the menu comes after a green suite:
19
+
20
+ ```
21
+ Tests failing (<N> failures). Must fix before completing:
22
+
23
+ [Show failures]
24
+ ```
25
+
26
+ **If tests pass:** continue to Step 2.
27
+
28
+ ## Step 2: Detect Environment
29
+
30
+ ```bash
31
+ GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
32
+ GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
33
+ # Capture now, while still inside the workspace — Step 5 changes directory
34
+ # before cleanup (Step 6) needs this value
35
+ WORKTREE_PATH=$(git rev-parse --show-toplevel)
36
+ ```
37
+
38
+ This determines which menu to show and how cleanup works:
39
+
40
+ | State | Menu | Cleanup |
41
+ |-------|------|---------|
42
+ | `GIT_DIR == GIT_COMMON` (normal repo) | Standard 3 options | No worktree to clean up |
43
+ | `GIT_DIR != GIT_COMMON`, named branch | Standard 3 options | Provenance-based (see Step 6) |
44
+ | `GIT_DIR != GIT_COMMON`, detached HEAD | Reduced 2 options (no merge) | Externally managed — leave in place |
45
+
46
+ ## Step 3: Determine Base Branch
47
+
48
+ The base branch is whatever this work forked from — usually named in the
49
+ plan, the conversation, or the branch's upstream. If it is not already
50
+ known, ask: "This branch split from <your best guess> - is that correct?"
51
+ Confirm before merging: merging into the wrong base is expensive to undo.
52
+
53
+ ## Step 4: Present Options
54
+
55
+ **Normal repo and named-branch worktree — present exactly these 3 options:**
56
+
57
+ ```
58
+ Implementation complete. What would you like to do?
59
+
60
+ 1. Merge back to <base-branch> locally
61
+ 2. Push and create a Pull Request
62
+ 3. Keep the branch as-is (I'll handle it later)
63
+
64
+ Which option?
65
+ ```
66
+
67
+ **Detached HEAD — present exactly these 2 options:**
68
+
69
+ ```
70
+ Implementation complete. You're on a detached HEAD (externally managed workspace).
71
+
72
+ 1. Push as new branch and create a Pull Request
73
+ 2. Keep as-is (I'll handle it later)
74
+
75
+ Which option?
76
+ ```
77
+
78
+ Present the menu exactly as written — concise, with every option coming
79
+ from the list above. Discarding the work happens only in response to your
80
+ human partner explicitly asking for it (see "If your human partner asks to
81
+ discard the work" below). Wait for their answer; the integration decision
82
+ is theirs.
83
+
84
+ ## Step 5: Execute Choice
85
+
86
+ ### Option 1: Merge Locally
87
+
88
+ ```bash
89
+ # Get main repo root for CWD safety
90
+ MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel)
91
+ cd "$MAIN_ROOT"
92
+
93
+ # Merge first — verify success before removing anything
94
+ git checkout <base-branch>
95
+ git pull
96
+ git merge <feature-branch>
97
+
98
+ # Verify tests on merged result
99
+ <test command>
100
+ ```
101
+
102
+ If tests fail on the merged result: stop, leave the worktree and branch in
103
+ place, and investigate — nothing has been pushed, so the merge is local
104
+ and recoverable.
105
+
106
+ Once the merged result is green: clean up the worktree (Step 6), then
107
+ delete the branch:
108
+
109
+ ```bash
110
+ git branch -d <feature-branch>
111
+ ```
112
+
113
+ ### Option 2: Push and Create PR
114
+
115
+ ```bash
116
+ git push -u origin <feature-branch>
117
+ # From a detached HEAD, name the new branch on the remote:
118
+ # git push origin HEAD:refs/heads/<new-branch>
119
+ ```
120
+
121
+ Then create the pull/merge request against <base-branch> with the forge's
122
+ tooling — its CLI if one is available, or the creation URL most forges
123
+ print when you push — following the repo's PR template and conventions if
124
+ present, and report the URL to your human partner.
125
+
126
+ Keep the worktree — your human partner iterates on PR feedback there.
127
+
128
+ ### Option 3: Keep As-Is
129
+
130
+ Report: "Keeping branch <name>. Worktree preserved at <path>."
131
+
132
+ ### If your human partner asks to discard the work
133
+
134
+ This path exists only as a response to an explicit request to throw the
135
+ work away. Confirm first:
136
+
137
+ ```
138
+ This will permanently delete:
139
+ - Branch <name>
140
+ - All commits: <commit-list>
141
+ - Worktree at <path>
142
+
143
+ Type 'discard' to confirm.
144
+ ```
145
+
146
+ Wait for that exact confirmation. When it arrives:
147
+
148
+ ```bash
149
+ MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel)
150
+ cd "$MAIN_ROOT"
151
+ ```
152
+
153
+ Then clean up the worktree (Step 6) and force-delete the branch:
154
+
155
+ ```bash
156
+ git branch -D <feature-branch>
157
+ ```
158
+
159
+ ## Step 6: Cleanup Workspace
160
+
161
+ **Runs for Option 1 and confirmed discards.** Options 2 and 3 always
162
+ preserve the worktree. Both callers have already changed directory to the
163
+ main repo root — worktree removal must run from outside the worktree —
164
+ and use the `GIT_DIR`/`GIT_COMMON`/`WORKTREE_PATH` values captured in
165
+ Step 2, from before that directory change.
166
+
167
+ **If `GIT_DIR == GIT_COMMON`:** Normal repo, no worktree to clean up. Done.
168
+
169
+ **If `WORKTREE_PATH` is under `.worktrees/` or `worktrees/`:** Superpowers
170
+ created this worktree — we own cleanup:
171
+
172
+ ```bash
173
+ git worktree remove "$WORKTREE_PATH"
174
+ git worktree prune # Self-healing: clean up any stale registrations
175
+ ```
176
+
177
+ **If removal is refused** (`contains modified or untracked files`): the
178
+ worktree holds files that exist nowhere else — uncommitted plans, notes,
179
+ or scratch work. Never `--force` on your own initiative. Show your human
180
+ partner what is at stake and ask:
181
+
182
+ ```bash
183
+ git -C "$WORKTREE_PATH" status --porcelain -uall
184
+ ```
185
+
186
+ ```
187
+ Worktree removal refused — these files were never committed:
188
+
189
+ <file list>
190
+
191
+ 1. Commit them to <branch> before cleanup
192
+ 2. Move them into <main repo root>
193
+ 3. Delete them (unrecoverable)
194
+
195
+ Which?
196
+ ```
197
+
198
+ Carry out the choice, then remove the worktree.
199
+
200
+ **Otherwise:** The host environment owns this workspace — leave it in
201
+ place. If your platform provides a workspace-exit tool, use it.
202
+
203
+ ## Quick Reference
204
+
205
+ | Option | Merge | Push | Keep Worktree | Cleanup Branch |
206
+ |--------|-------|------|---------------|----------------|
207
+ | 1. Merge locally | yes | - | - | yes |
208
+ | 2. Create PR | - | yes | yes | - |
209
+ | 3. Keep as-is | - | - | yes | - |
210
+ | Discard (explicit request only) | - | - | - | yes (force) |
211
+
212
+ ## Common Rationalizations
213
+
214
+ | Excuse | Reality |
215
+ |--------|---------|
216
+ | "Tests passed earlier this session" | Run the suite on the tree you are about to integrate. A green run only proves the tree it ran on. |
217
+ | "They obviously want it merged" | Integration is your human partner's decision. Present the menu and wait. |
218
+ | "They seem done with this feature — I'll offer to discard it" | The menu is complete as written. Discard happens only when your human partner asks for it in so many words. |
219
+ | "'Yeah, get rid of it' counts as confirmation" | Only the typed word `discard` authorizes deletion. |
220
+ | "The PR is up, so the worktree is clutter now" | PR feedback gets fixed in that worktree. It stays until the work lands. |
221
+ | "This other worktree looks stale — I'll clean it too" | Clean up only worktrees under `.worktrees/` or `worktrees/`. Everything else belongs to the host. |
222
+ | "Removal refused — `--force` is just finishing the cleanup" | The refusal means files exist only in that worktree. `--force` destroys them permanently. Show your human partner and ask. |
223
+ | "The merged-result failure is probably flaky" | A failing merged result stops everything. Branch and worktree stay put while you investigate. |
224
+ | "The base branch is obviously main" | Confirm the fork point or ask. Merging into the wrong base is expensive to undo. |
225
+ | "The push was rejected — force-push will fix it" | A rejected push means the remote moved. Investigate; force-push only on your human partner's explicit request. |