codebyplan 1.5.1 → 1.8.0

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 (205) hide show
  1. package/dist/cli.js +4462 -748
  2. package/package.json +5 -1
  3. package/templates/.gitkeep +0 -0
  4. package/templates/README.md +20 -0
  5. package/templates/agents/cbp-cc-executor.md +213 -0
  6. package/templates/agents/cbp-database-agent.md +229 -0
  7. package/templates/agents/cbp-improve-claude.md +245 -0
  8. package/templates/agents/cbp-improve-round.md +284 -0
  9. package/templates/agents/cbp-mechanical-edits.md +111 -0
  10. package/templates/agents/cbp-research.md +282 -0
  11. package/templates/agents/cbp-round-executor.md +604 -0
  12. package/templates/agents/cbp-security-agent.md +134 -0
  13. package/templates/agents/cbp-task-check.md +213 -0
  14. package/templates/agents/cbp-task-planner.md +582 -0
  15. package/templates/agents/cbp-test-e2e-agent.md +363 -0
  16. package/templates/agents/cbp-testing-qa-agent.md +400 -0
  17. package/templates/context/mcp-docs.md +139 -0
  18. package/templates/hooks/README.md +236 -0
  19. package/templates/hooks/cbp-auto-test-hooks.sh +44 -0
  20. package/templates/hooks/cbp-lint-format-on-edit.sh +159 -0
  21. package/templates/hooks/cbp-maestro-yaml-validate.sh +100 -0
  22. package/templates/hooks/cbp-mcp-migration-guard.sh +32 -0
  23. package/templates/hooks/cbp-mcp-round-sync.sh +79 -0
  24. package/templates/hooks/cbp-mcp-worktree-inject.sh +76 -0
  25. package/templates/hooks/cbp-notify.sh +68 -0
  26. package/templates/hooks/cbp-plugin-dispatch.sh +29 -0
  27. package/templates/hooks/cbp-pre-commit-quality-gate.sh +204 -0
  28. package/templates/hooks/cbp-statusline.sh +347 -0
  29. package/templates/hooks/cbp-subagent-statusline.sh +182 -0
  30. package/templates/hooks/cbp-test-coverage-gate.sh +144 -0
  31. package/templates/hooks/cbp-test-hooks.sh +320 -0
  32. package/templates/hooks/hooks.json +85 -0
  33. package/templates/hooks/validate-context-usage.sh +59 -0
  34. package/templates/hooks/validate-git-commit.sh +78 -0
  35. package/templates/hooks/validate-git-stash-deny.sh +32 -0
  36. package/templates/hooks/validate-structure-lengths.sh +57 -0
  37. package/templates/hooks/validate-structure-lib.sh +104 -0
  38. package/templates/hooks/validate-structure-patterns.sh +54 -0
  39. package/templates/hooks/validate-structure-scope.sh +33 -0
  40. package/templates/hooks/validate-structure-smoke.sh +95 -0
  41. package/templates/hooks/validate-structure-templates.sh +34 -0
  42. package/templates/hooks/validate-structure.sh +69 -0
  43. package/templates/rules/.gitkeep +0 -0
  44. package/templates/rules/README.md +47 -0
  45. package/templates/rules/context-file-loading.md +52 -0
  46. package/templates/rules/scope-vocabulary.md +64 -0
  47. package/templates/rules/todo-backend.md +109 -0
  48. package/templates/settings.project.base.json +55 -0
  49. package/templates/settings.user.base.json +25 -0
  50. package/templates/skills/cbp-build-cc-agent/SKILL.md +139 -0
  51. package/templates/skills/cbp-build-cc-agent/examples/read-only-reviewer.md +32 -0
  52. package/templates/skills/cbp-build-cc-agent/examples/with-hooks.md +41 -0
  53. package/templates/skills/cbp-build-cc-agent/examples/with-skills-preload.md +25 -0
  54. package/templates/skills/cbp-build-cc-agent/reference/cbp-quality.md +153 -0
  55. package/templates/skills/cbp-build-cc-agent/reference/frontmatter-fields.md +37 -0
  56. package/templates/skills/cbp-build-cc-agent/reference/permission-modes.md +18 -0
  57. package/templates/skills/cbp-build-cc-agent/scripts/validate-agent.sh +67 -0
  58. package/templates/skills/cbp-build-cc-agent/templates/agent.md +66 -0
  59. package/templates/skills/cbp-build-cc-claude-file/SKILL.md +178 -0
  60. package/templates/skills/cbp-build-cc-claude-file/examples/minimal-project.md +33 -0
  61. package/templates/skills/cbp-build-cc-claude-file/examples/monorepo-with-imports.md +39 -0
  62. package/templates/skills/cbp-build-cc-claude-file/reference/imports.md +72 -0
  63. package/templates/skills/cbp-build-cc-claude-file/reference/what-belongs.md +39 -0
  64. package/templates/skills/cbp-build-cc-claude-file/templates/project-claude-md.md +48 -0
  65. package/templates/skills/cbp-build-cc-claude-file/templates/user-claude-md.md +22 -0
  66. package/templates/skills/cbp-build-cc-memory/SKILL.md +201 -0
  67. package/templates/skills/cbp-build-cc-memory/examples/feedback-memory.md +11 -0
  68. package/templates/skills/cbp-build-cc-memory/examples/project-memory.md +11 -0
  69. package/templates/skills/cbp-build-cc-memory/examples/reference-memory.md +13 -0
  70. package/templates/skills/cbp-build-cc-memory/examples/user-memory.md +14 -0
  71. package/templates/skills/cbp-build-cc-memory/reference/memory-types.md +59 -0
  72. package/templates/skills/cbp-build-cc-memory/reference/when-to-save.md +62 -0
  73. package/templates/skills/cbp-build-cc-memory/templates/MEMORY-index.md +4 -0
  74. package/templates/skills/cbp-build-cc-memory/templates/memory-entry.md +15 -0
  75. package/templates/skills/cbp-build-cc-mode/SKILL.md +99 -0
  76. package/templates/skills/cbp-build-cc-rule/SKILL.md +176 -0
  77. package/templates/skills/cbp-build-cc-rule/examples/global-rule.md +19 -0
  78. package/templates/skills/cbp-build-cc-rule/examples/scoped-rule.md +41 -0
  79. package/templates/skills/cbp-build-cc-rule/reference/paths-patterns.md +48 -0
  80. package/templates/skills/cbp-build-cc-rule/templates/rule.md +32 -0
  81. package/templates/skills/cbp-build-cc-settings/SKILL.md +220 -0
  82. package/templates/skills/cbp-build-cc-settings/examples/hooks-config.json +64 -0
  83. package/templates/skills/cbp-build-cc-settings/examples/permissions-config.json +34 -0
  84. package/templates/skills/cbp-build-cc-settings/examples/sandbox-config.json +42 -0
  85. package/templates/skills/cbp-build-cc-settings/reference/cbp-conventions.md +104 -0
  86. package/templates/skills/cbp-build-cc-settings/reference/permission-rules.md +61 -0
  87. package/templates/skills/cbp-build-cc-settings/reference/scope-precedence.md +73 -0
  88. package/templates/skills/cbp-build-cc-settings/reference/settings-fields.md +166 -0
  89. package/templates/skills/cbp-build-cc-settings/templates/settings.json +23 -0
  90. package/templates/skills/cbp-build-cc-settings/templates/settings.local.json +10 -0
  91. package/templates/skills/cbp-build-cc-skill/SKILL.md +154 -0
  92. package/templates/skills/cbp-build-cc-skill/examples/dynamic-context.md +31 -0
  93. package/templates/skills/cbp-build-cc-skill/examples/fork-skill.md +22 -0
  94. package/templates/skills/cbp-build-cc-skill/examples/knowledge-skill.md +25 -0
  95. package/templates/skills/cbp-build-cc-skill/examples/task-skill.md +29 -0
  96. package/templates/skills/cbp-build-cc-skill/reference/cbp-quality.md +157 -0
  97. package/templates/skills/cbp-build-cc-skill/reference/frontmatter-fields.md +35 -0
  98. package/templates/skills/cbp-build-cc-skill/reference/string-substitutions.md +60 -0
  99. package/templates/skills/cbp-build-cc-skill/scripts/validate-skill.sh +90 -0
  100. package/templates/skills/cbp-build-cc-skill/templates/skill.md +51 -0
  101. package/templates/skills/cbp-checkpoint-check/SKILL.md +156 -0
  102. package/templates/skills/cbp-checkpoint-complete/SKILL.md +109 -0
  103. package/templates/skills/cbp-checkpoint-create/SKILL.md +287 -0
  104. package/templates/skills/cbp-checkpoint-end/SKILL.md +241 -0
  105. package/templates/skills/cbp-checkpoint-update/SKILL.md +115 -0
  106. package/templates/skills/cbp-frontend-a11y/SKILL.md +109 -0
  107. package/templates/skills/cbp-frontend-a11y/reference/aria-roles-states.md +130 -0
  108. package/templates/skills/cbp-frontend-a11y/reference/contrast-visual.md +122 -0
  109. package/templates/skills/cbp-frontend-a11y/reference/keyboard-patterns.md +154 -0
  110. package/templates/skills/cbp-frontend-a11y/reference/semantic-html.md +111 -0
  111. package/templates/skills/cbp-frontend-design/SKILL.md +145 -0
  112. package/templates/skills/cbp-frontend-design/reference/nextjs-scss.md +118 -0
  113. package/templates/skills/cbp-frontend-design/reference/rn-expo.md +101 -0
  114. package/templates/skills/cbp-frontend-design/reference/tauri-react.md +82 -0
  115. package/templates/skills/cbp-frontend-ui/SKILL.md +262 -0
  116. package/templates/skills/cbp-frontend-ui/reference/ui-label-maps.md +42 -0
  117. package/templates/skills/cbp-frontend-ui/reference/ui-layout-patterns.md +105 -0
  118. package/templates/skills/cbp-frontend-ui/reference/variant-defaults.md +149 -0
  119. package/templates/skills/cbp-frontend-ux/SKILL.md +181 -0
  120. package/templates/skills/cbp-git-branch-feat-create/SKILL.md +115 -0
  121. package/templates/skills/cbp-git-commit/SKILL.md +278 -0
  122. package/templates/skills/cbp-git-worktree-create/SKILL.md +226 -0
  123. package/templates/skills/cbp-git-worktree-remove/SKILL.md +145 -0
  124. package/templates/skills/cbp-merge-main/SKILL.md +228 -0
  125. package/templates/skills/cbp-round-check/SKILL.md +104 -0
  126. package/templates/skills/cbp-round-end/SKILL.md +183 -0
  127. package/templates/skills/cbp-round-end/reference/findings-presentation.md +44 -0
  128. package/templates/skills/cbp-round-end/reference/inline-fallback.md +35 -0
  129. package/templates/skills/cbp-round-execute/SKILL.md +211 -0
  130. package/templates/skills/cbp-round-execute/reference/inline-fallback.md +59 -0
  131. package/templates/skills/cbp-round-input/SKILL.md +165 -0
  132. package/templates/skills/cbp-round-start/SKILL.md +222 -0
  133. package/templates/skills/cbp-round-update/SKILL.md +163 -0
  134. package/templates/skills/cbp-session-end/SKILL.md +187 -0
  135. package/templates/skills/cbp-session-start/SKILL.md +155 -0
  136. package/templates/skills/cbp-ship/SKILL.md +332 -0
  137. package/templates/skills/cbp-ship/reference/changesets-overview.md +120 -0
  138. package/templates/skills/cbp-ship/reference/eas-cli-overview.md +60 -0
  139. package/templates/skills/cbp-ship/reference/gh-cli-overview.md +135 -0
  140. package/templates/skills/cbp-ship/reference/gh-cli-shipment-commands.md +283 -0
  141. package/templates/skills/cbp-ship/reference/npm-publish-monorepo.md +252 -0
  142. package/templates/skills/cbp-ship/reference/npm-publish-oidc-trusted.md +157 -0
  143. package/templates/skills/cbp-ship/reference/npm-publish-overview.md +171 -0
  144. package/templates/skills/cbp-ship/reference/preflight-checklist.md +88 -0
  145. package/templates/skills/cbp-ship/reference/railway-nestjs-deployment.md +169 -0
  146. package/templates/skills/cbp-ship/reference/railway-overview.md +120 -0
  147. package/templates/skills/cbp-ship/reference/railway-troubleshooting.md +168 -0
  148. package/templates/skills/cbp-ship/reference/release-please-overview.md +99 -0
  149. package/templates/skills/cbp-ship/reference/surface-expo-eas.md +155 -0
  150. package/templates/skills/cbp-ship/reference/surface-npm.md +180 -0
  151. package/templates/skills/cbp-ship/reference/surface-railway.md +152 -0
  152. package/templates/skills/cbp-ship/reference/surface-supabase.md +178 -0
  153. package/templates/skills/cbp-ship/reference/surface-tauri.md +138 -0
  154. package/templates/skills/cbp-ship/reference/surface-vercel.md +124 -0
  155. package/templates/skills/cbp-ship/reference/surface-vscode-ext.md +144 -0
  156. package/templates/skills/cbp-ship/reference/surfaces.md +60 -0
  157. package/templates/skills/cbp-ship/reference/testflight-automation.md +215 -0
  158. package/templates/skills/cbp-ship/reference/testflight-internal-vs-external.md +69 -0
  159. package/templates/skills/cbp-ship/reference/testflight-overview.md +98 -0
  160. package/templates/skills/cbp-ship/reference/versioning.md +116 -0
  161. package/templates/skills/cbp-ship/scripts/detect-surfaces.sh +217 -0
  162. package/templates/skills/cbp-ship/scripts/verify-expo-eas.sh +35 -0
  163. package/templates/skills/cbp-ship/scripts/verify-npm.sh +21 -0
  164. package/templates/skills/cbp-ship/scripts/verify-railway.sh +41 -0
  165. package/templates/skills/cbp-ship/scripts/verify-supabase.sh +19 -0
  166. package/templates/skills/cbp-ship/scripts/verify-tauri.sh +24 -0
  167. package/templates/skills/cbp-ship/scripts/verify-vercel.sh +32 -0
  168. package/templates/skills/cbp-ship/scripts/verify-vscode-ext.sh +25 -0
  169. package/templates/skills/cbp-ship/templates/eas.json +66 -0
  170. package/templates/skills/cbp-ship/templates/railway.toml +15 -0
  171. package/templates/skills/cbp-ship/templates/release-please-config.json +17 -0
  172. package/templates/skills/cbp-ship/templates/vercel.json +19 -0
  173. package/templates/skills/cbp-ship/templates/vscodeignore +21 -0
  174. package/templates/skills/cbp-ship/templates/workflow-changesets.yml +41 -0
  175. package/templates/skills/cbp-ship/templates/workflow-eas-submit.yml +53 -0
  176. package/templates/skills/cbp-ship/templates/workflow-npm-publish.yml +36 -0
  177. package/templates/skills/cbp-ship/templates/workflow-release-please.yml +21 -0
  178. package/templates/skills/cbp-ship/templates/workflow-tauri-release.yml +69 -0
  179. package/templates/skills/cbp-ship/templates/workflow-vsce-publish.yml +31 -0
  180. package/templates/skills/cbp-ship-configure/SKILL.md +296 -0
  181. package/templates/skills/cbp-ship-configure/reference/expo-mobile.md +204 -0
  182. package/templates/skills/cbp-ship-configure/reference/npm-package.md +165 -0
  183. package/templates/skills/cbp-ship-configure/reference/railway-backend.md +199 -0
  184. package/templates/skills/cbp-ship-configure/reference/supabase.md +200 -0
  185. package/templates/skills/cbp-ship-configure/reference/tauri-desktop.md +181 -0
  186. package/templates/skills/cbp-ship-configure/reference/vercel.md +117 -0
  187. package/templates/skills/cbp-ship-configure/reference/vscode-ext.md +155 -0
  188. package/templates/skills/cbp-ship-main/SKILL.md +65 -0
  189. package/templates/skills/cbp-supabase-branch-check/SKILL.md +337 -0
  190. package/templates/skills/cbp-supabase-branch-check/reference/dag-steps.md +29 -0
  191. package/templates/skills/cbp-supabase-migrate/SKILL.md +314 -0
  192. package/templates/skills/cbp-supabase-migrate/reference/advisor-triage.md +70 -0
  193. package/templates/skills/cbp-supabase-migrate/reference/cli-fallback.md +87 -0
  194. package/templates/skills/cbp-supabase-migrate/reference/preflight-dry-run.md +58 -0
  195. package/templates/skills/cbp-supabase-setup/SKILL.md +239 -0
  196. package/templates/skills/cbp-supabase-setup/reference/branching-setup.md +121 -0
  197. package/templates/skills/cbp-supabase-setup/reference/cli-fallback.md +109 -0
  198. package/templates/skills/cbp-task-check/SKILL.md +166 -0
  199. package/templates/skills/cbp-task-complete/SKILL.md +206 -0
  200. package/templates/skills/cbp-task-complete/reference/checkpoint-done-branching.md +48 -0
  201. package/templates/skills/cbp-task-complete/reference/next-step-heuristic.md +56 -0
  202. package/templates/skills/cbp-task-create/SKILL.md +167 -0
  203. package/templates/skills/cbp-task-start/SKILL.md +239 -0
  204. package/templates/skills/cbp-task-testing/SKILL.md +277 -0
  205. package/templates/skills/cbp-todo/SKILL.md +97 -0
@@ -0,0 +1,226 @@
1
+ ---
2
+ scope: org-shared
3
+ name: cbp-git-worktree-create
4
+ description: Create git worktree with clean command setup and register in CodeByPlan
5
+ argument-hint: <branch-name> e.g. codebyplan-app
6
+ effort: low
7
+ ---
8
+
9
+ # Git Worktree Create
10
+
11
+ Create a git worktree as a sibling folder and register it in CodeByPlan. The worktree gets its own full copy of `.claude/` files on disk (rules, skills, hooks, agents, context) — git deduplicates at the object level so there's no real cost.
12
+
13
+ ## Arguments
14
+
15
+ `$ARGUMENTS`: branch name — becomes both the branch name and the folder name.
16
+
17
+ Examples:
18
+ - `codebyplan-app` → folder `../codebyplan-app/`, branch `codebyplan-app`
19
+ - `codebyplan-package` → folder `../codebyplan-package/`, branch `codebyplan-package`
20
+
21
+ ## Prerequisites
22
+
23
+ - Must run from the **main repo** (the non-worktree checkout)
24
+ - Working tree should be clean
25
+ - Branch should not already exist as a worktree
26
+
27
+ ## Instructions
28
+
29
+ ### Step 1: Verify Main Repo
30
+
31
+ ```bash
32
+ MAIN_REPO="$(git rev-parse --show-toplevel)"
33
+ ```
34
+
35
+ Verify this is the main repo (not itself a worktree):
36
+
37
+ ```bash
38
+ git rev-parse --git-dir
39
+ ```
40
+
41
+ If the result is a file (not `.git` directory), this is already a worktree. Stop:
42
+
43
+ ```
44
+ ## Error
45
+
46
+ Run this command from the main repo, not from a worktree.
47
+ Main repo: [path from git-common-dir parent]
48
+ ```
49
+
50
+ ### Step 2: Validate Arguments
51
+
52
+ If `$ARGUMENTS` is empty, ask the user:
53
+
54
+ ```
55
+ What should the worktree be called? (e.g. codebyplan-app)
56
+ ```
57
+
58
+ Set:
59
+ - `BRANCH_NAME` = `$ARGUMENTS`
60
+ - `WORKTREE_PATH` = `$MAIN_REPO/../$BRANCH_NAME`
61
+
62
+ ### Step 3: Check for Conflicts
63
+
64
+ Check if the worktree already exists:
65
+
66
+ ```bash
67
+ git worktree list | grep "$BRANCH_NAME"
68
+ ```
69
+
70
+ If it exists:
71
+ ```
72
+ ## Worktree Already Exists
73
+
74
+ Branch `[name]` is already checked out at [path].
75
+
76
+ Use `/cbp-git-worktree-remove [name]` to remove it first.
77
+ ```
78
+ Stop here.
79
+
80
+ Check if the folder already exists:
81
+
82
+ ```bash
83
+ ls -d "$WORKTREE_PATH" 2>/dev/null
84
+ ```
85
+
86
+ If it exists, stop and inform the user.
87
+
88
+ ### Step 4: Create Branch If Needed
89
+
90
+ Check if branch exists:
91
+
92
+ ```bash
93
+ git branch --list "$BRANCH_NAME"
94
+ ```
95
+
96
+ If branch does NOT exist, create it from current HEAD:
97
+
98
+ ```bash
99
+ git branch "$BRANCH_NAME"
100
+ ```
101
+
102
+ ### Step 5: Create Worktree
103
+
104
+ ```bash
105
+ git worktree add "$WORKTREE_PATH" "$BRANCH_NAME"
106
+ ```
107
+
108
+ ### Step 6: Set Up MCP Connection
109
+
110
+ Copy `.mcp.json` from the main repo to the worktree. The config points at the remote MCP endpoint (`https://codebyplan.com/mcp`) and reads the API key from the environment, so no path rewriting is needed:
111
+
112
+ ```bash
113
+ cp "$MAIN_REPO/.mcp.json" "$WORKTREE_PATH/.mcp.json"
114
+ ```
115
+
116
+ Expected shape (do NOT rewrite paths — this is remote HTTP):
117
+
118
+ ```json
119
+ {
120
+ "mcpServers": {
121
+ "codebyplan": {
122
+ "url": "https://codebyplan.com/mcp",
123
+ "headers": {
124
+ "x-api-key": "${CODEBYPLAN_API_KEY}"
125
+ }
126
+ }
127
+ }
128
+ }
129
+ ```
130
+
131
+ ### Step 7: Set Up Environment
132
+
133
+ Copy `.env.local` from the main repo to the worktree (contains `CODEBYPLAN_API_KEY` and any other local env):
134
+
135
+ ```bash
136
+ cp "$MAIN_REPO/.env.local" "$WORKTREE_PATH/.env.local"
137
+ ```
138
+
139
+ Verify `.env.local` is already in `.gitignore` (it should be via `.env.local` pattern). If not, add it.
140
+
141
+ ### Step 8: Push Branch
142
+
143
+ ```bash
144
+ cd "$WORKTREE_PATH" && git push -u origin "$BRANCH_NAME"
145
+ ```
146
+
147
+ ### Step 9: Register Worktree in CodeByPlan
148
+
149
+ Get the repo ID from CLAUDE.md (`Repo ID` in Key References table).
150
+
151
+ Use MCP `create_worktree` to register the worktree in the CodeByPlan database:
152
+
153
+ ```
154
+ MCP create_worktree:
155
+ repo_id: [repo-id from CLAUDE.md]
156
+ name: $BRANCH_NAME
157
+ path: $WORKTREE_PATH
158
+ status: "active"
159
+ ```
160
+
161
+ Save the returned `worktree_id` for reference.
162
+
163
+ ### Step 10: Write `.codebyplan/` directory
164
+
165
+ Create the `.codebyplan/` directory in the worktree root and write per-concern config stubs:
166
+
167
+ ```bash
168
+ mkdir -p "$WORKTREE_PATH/.codebyplan"
169
+ ```
170
+
171
+ Write `.codebyplan/repo.json` with the correct `repo_id`:
172
+
173
+ ```json
174
+ {
175
+ "repo_id": "[repo-id from CLAUDE.md]"
176
+ }
177
+ ```
178
+
179
+ Write stubs for the other per-concern files (populated by `npx codebyplan sync` on first run):
180
+
181
+ ```bash
182
+ # .codebyplan/server.json — server port and type config
183
+ echo '{}' > "$WORKTREE_PATH/.codebyplan/server.json"
184
+
185
+ # .codebyplan/git.json — branch config
186
+ echo '{}' > "$WORKTREE_PATH/.codebyplan/git.json"
187
+
188
+ # .codebyplan/shipment.json — surface shipment config
189
+ echo '{}' > "$WORKTREE_PATH/.codebyplan/shipment.json"
190
+
191
+ # .codebyplan/vendor.json — vendor docs path
192
+ echo '{}' > "$WORKTREE_PATH/.codebyplan/vendor.json"
193
+ ```
194
+
195
+ The `.codebyplan/device.local.json` file is created by `npx codebyplan setup` on the device (gitignored). The `worktree_id` is never persisted in any of these files — it is resolved at runtime via `npx codebyplan resolve-worktree` based on the device_id, filesystem path, and current git branch.
196
+
197
+ No need to mark as `skip-worktree` — the committed files are merge-safe per CHK-108 and CHK-120.
198
+
199
+ ### Step 11: Show Result
200
+
201
+ ```
202
+ ## Worktree Created
203
+
204
+ **Branch**: [branch-name]
205
+ **Path**: [worktree-path]
206
+ **Main repo**: [main-repo-path]
207
+ **CodeByPlan**: Registered (worktree ID: [id])
208
+
209
+ ### Setup
210
+ - MCP: connected (remote endpoint)
211
+ - API key: copied from main repo `.env.local`
212
+ - `.claude/` files: full copy on disk (rules, skills, hooks, agents, context)
213
+
214
+ ### Next Steps
215
+ - Open `[worktree-path]` in your editor
216
+ - Run `/cbp-session-start` to begin working
217
+ - Checkpoints can be assigned to this worktree via `worktree_id`
218
+
219
+ ### Existing Worktrees
220
+ [output of git worktree list]
221
+ ```
222
+
223
+ ## Integration
224
+
225
+ - **Related**: `/cbp-git-worktree-remove` (cleanup and deregister)
226
+ - **MCP tools**: `create_worktree`
@@ -0,0 +1,145 @@
1
+ ---
2
+ scope: org-shared
3
+ name: cbp-git-worktree-remove
4
+ description: Remove git worktree and deregister from CodeByPlan
5
+ argument-hint: <name> e.g. codebyplan-app
6
+ effort: low
7
+ ---
8
+
9
+ # Git Worktree Remove
10
+
11
+ Remove a git worktree folder, deregister it from CodeByPlan, and optionally delete its branch.
12
+
13
+ ## Arguments
14
+
15
+ `$ARGUMENTS`: worktree name or path to remove.
16
+
17
+ ## Prerequisites
18
+
19
+ - Must run from the **main repo** (not from the worktree being removed)
20
+
21
+ ## Instructions
22
+
23
+ ### Step 1: Verify Main Repo
24
+
25
+ ```bash
26
+ MAIN_REPO="$(git rev-parse --show-toplevel)"
27
+ ```
28
+
29
+ Verify not in a worktree (`.git` should be a directory, not a file).
30
+
31
+ ### Step 2: List Worktrees
32
+
33
+ ```bash
34
+ git worktree list
35
+ ```
36
+
37
+ If `$ARGUMENTS` is empty, show the list and ask which to remove.
38
+
39
+ ### Step 3: Resolve Worktree
40
+
41
+ Find matching worktree from the list. Match by:
42
+ 1. Exact path
43
+ 2. Folder name (e.g. `codebyplan-app`)
44
+ 3. Branch name
45
+
46
+ If no match found, show available worktrees and stop.
47
+
48
+ Set:
49
+ - `WORKTREE_PATH` = resolved path
50
+ - `BRANCH_NAME` = branch checked out in that worktree
51
+
52
+ ### Step 4: Look Up Worktree in CodeByPlan
53
+
54
+ Get the repo ID from CLAUDE.md (`Repo ID` in Key References table).
55
+
56
+ Use MCP `get_worktrees` to find the worktree record:
57
+
58
+ ```
59
+ MCP get_worktrees:
60
+ repo_id: [repo-id from CLAUDE.md]
61
+ status: "active"
62
+ ```
63
+
64
+ Match by `name` = `$BRANCH_NAME` or `path` = `$WORKTREE_PATH`.
65
+
66
+ Set `WORKTREE_ID` = matched worktree's `id`.
67
+
68
+ If not found in CodeByPlan, note it and continue with local removal.
69
+
70
+ ### Step 5: Check for Assigned Checkpoints
71
+
72
+ If `WORKTREE_ID` was found, warn if any checkpoints are assigned to this worktree:
73
+
74
+ ```
75
+ ⚠ This worktree has [N] checkpoint(s) assigned. They will become unassigned.
76
+ ```
77
+
78
+ ### Step 6: Confirm with User
79
+
80
+ ```
81
+ ## Remove Worktree
82
+
83
+ **Path**: [worktree-path]
84
+ **Branch**: [branch-name]
85
+ **CodeByPlan**: [registered | not registered]
86
+
87
+ Remove worktree and delete the branch? (The main repo is not affected)
88
+ ```
89
+
90
+ Ask:
91
+ 1. Remove worktree only (keep branch)
92
+ 2. Remove worktree and delete branch
93
+ 3. Cancel
94
+
95
+ ### Step 7: Deregister from CodeByPlan
96
+
97
+ If `WORKTREE_ID` was found, delete the worktree record:
98
+
99
+ ```
100
+ MCP delete_worktree:
101
+ worktree_id: [worktree-id]
102
+ ```
103
+
104
+ ### Step 8: Remove Git Worktree
105
+
106
+ ```bash
107
+ git worktree remove "$WORKTREE_PATH"
108
+ ```
109
+
110
+ If force needed (uncommitted changes):
111
+ ```bash
112
+ git worktree remove --force "$WORKTREE_PATH"
113
+ ```
114
+
115
+ Only use `--force` if the user confirms.
116
+
117
+ ### Step 9: Delete Branch (if requested)
118
+
119
+ **Protected branch check:** If `$BRANCH_NAME` is `main`, `development`, or `preview` — refuse deletion and stop.
120
+
121
+ **Checkpoint verification:** Before deleting a feat branch, verify that the associated checkpoint has completed via `/cbp-checkpoint-end`. If the checkpoint is still active, warn the user that unshipped work may be lost.
122
+
123
+ ```bash
124
+ git branch -d "$BRANCH_NAME" && git push origin --delete "$BRANCH_NAME"
125
+ ```
126
+
127
+ Use `-d` (not `-D`) to prevent deleting unmerged work. If it fails because the branch is not fully merged, inform the user and ask if they want to force delete with `-D`.
128
+
129
+ ### Step 10: Show Result
130
+
131
+ ```
132
+ ## Worktree Removed
133
+
134
+ **Removed**: [worktree-path]
135
+ **Branch**: [deleted | kept]
136
+ **CodeByPlan**: [deregistered | was not registered]
137
+
138
+ ### Remaining Worktrees
139
+ [output of git worktree list]
140
+ ```
141
+
142
+ ## Integration
143
+
144
+ - **Related**: `/cbp-git-worktree-create` (create and register)
145
+ - **MCP tools**: `get_worktrees`, `delete_worktree`
@@ -0,0 +1,228 @@
1
+ ---
2
+ scope: org-shared
3
+ name: cbp-merge-main
4
+ description: Merge main into the current feat branch with interactive per-conflict resolution and inline QA re-run
5
+ model: sonnet
6
+ effort: high
7
+ ---
8
+
9
+ # Merge Main into Feat Branch
10
+
11
+ Codifies the long-lived-branch-integration auto-memory rule (`[[feedback_long-lived-branch-integration]]`): when working on a feat branch that has diverged from main, merge main INTO the feat branch (not the reverse), resolve conflicts with the user, run a scoped QA pass, then return control to the caller — never rebase, never force-push, never push automatically.
12
+
13
+ Triggered by `/cbp-task-start` (Step 3.6, optional stale-check), `/cbp-task-complete` (Step 4.5, mandatory pre-complete), and `/cbp-checkpoint-end` (Step 0, mandatory pre-shipment). User can also invoke manually at any time.
14
+
15
+ ## When to Use
16
+
17
+ - **Auto-trigger (optional)**: `/cbp-task-start` Step 3.6 detects the feat branch is >10 commits behind `origin/{BASE}` OR the last fetch is >24h old.
18
+ - **Auto-trigger (mandatory)**: `/cbp-task-complete` Step 4.5 — always run before marking a task complete to ensure the feat branch includes the latest main work.
19
+ - **Auto-trigger (mandatory)**: `/cbp-checkpoint-end` Step 0 — always run before shipment to ensure no main drift reaches production.
20
+ - **Manual invocation**: user runs `/cbp-merge-main` directly when they know main has advanced and want to pull it in immediately.
21
+
22
+ ## Instructions
23
+
24
+ ### Step 0: Pre-flight
25
+
26
+ 1. Read `.codebyplan/git.json` → `branch_config.base` (default `"main"`, read defensively — file may be absent) and `branch_config.protected` (default `["main"]`). Do NOT reference a removed `branch_config.integration` key.
27
+ 2. Run `git branch --show-current` → `CURRENT`. If `CURRENT` is in `branch_config.protected` OR does NOT match `feat/*`, error and STOP:
28
+
29
+ ```
30
+ /cbp-merge-main must run on a feat branch. Current: {CURRENT}.
31
+ Switch to a feat branch first.
32
+ ```
33
+
34
+ 3. Working-tree gate:
35
+ - Run `git diff --quiet`; if exit code is non-zero, `unstaged_dirty=true`, else `unstaged_dirty=false`.
36
+ - Run `git diff --cached --quiet`; if exit code is non-zero, `staged_present=true`, else `staged_present=false`.
37
+
38
+ Decision matrix:
39
+ - `unstaged_dirty=true` → AskUserQuestion:
40
+ - **Commit current changes first** (recommended) — trigger `/cbp-git-commit`, then re-check tree, then proceed.
41
+ - **Proceed with dirty tree** — soft warning; the merge may interleave with uncommitted edits.
42
+ - **Cancel** — abort the skill.
43
+ - `unstaged_dirty=false AND staged_present=true` → print one informational line and proceed to Step 1:
44
+ `Staged changes detected — proceeding with merge.`
45
+ (Pre-staged files will be included in the merge commit at Step 2 — this is intentional; the caller already approved them via /cbp-round-update.)
46
+ - `unstaged_dirty=false AND staged_present=false` → proceed silently to Step 1.
47
+ - Either `git diff` command exits with code ≥ 2 (git hard error — not-a-repo, detached HEAD with no commits, index lock, corrupt object store): surface the raw error output and STOP. Do NOT proceed to Step 1.
48
+
49
+ NEVER `git stash` for any reason (per `[[feedback_no-git-stash]]`).
50
+
51
+ ### Step 1: Fetch Latest Main
52
+
53
+ 1. Run `git fetch origin {BASE}`. **If this fails (offline, auth, registry)**, abort:
54
+
55
+ ```
56
+ /cbp-merge-main cannot proceed offline — `git fetch origin {BASE}` failed.
57
+ Resolve connectivity and re-invoke.
58
+ ```
59
+
60
+ 2. Measure drift:
61
+
62
+ ```bash
63
+ BEHIND=$(git rev-list --count HEAD..origin/{BASE})
64
+ AHEAD=$(git rev-list --count origin/{BASE}..HEAD)
65
+ ```
66
+
67
+ 3. If `BEHIND == 0`: print one-line `Already up to date with origin/{BASE} ({AHEAD} ahead, 0 behind).` and RETURN SUCCESS to the caller. No merge needed.
68
+
69
+ ### Step 1.5: Migration Timestamp Collision Pre-Check
70
+
71
+ Supabase migrations are version-keyed by their numeric filename prefix. Two files sharing a prefix break `supabase db push`: the schema_migrations table records ONE version per prefix, the second file at the same prefix becomes orphaned, and every subsequent migration stalls — surfacing as the Supabase Preview check failing with `MIGRATIONS_FAILED`. Catch this BEFORE committing the merge, while a clean rollback is one `git merge --abort` away.
72
+
73
+ 1. Probe both sides of the would-be merge. Use `git ls-files` for the HEAD side so any in-progress `git mv` staged in the index (e.g. a rename produced by step 5 of a prior pass through this section) is reflected — `git ls-tree HEAD` would still see the committed-only state and re-trigger the collision. Use `git ls-tree origin/{BASE}` for the main side since we want the committed remote state, not anything locally staged:
74
+
75
+ ```bash
76
+ git ls-files supabase/migrations/ 2>/dev/null \
77
+ | sed 's|.*/||' | sort > /tmp/cbp-merge-our-names.txt
78
+ git ls-tree -r --name-only origin/{BASE} supabase/migrations/ 2>/dev/null \
79
+ | sed 's|.*/||' | sort > /tmp/cbp-merge-their-names.txt
80
+ ```
81
+
82
+ 2. A true collision is a numeric prefix that appears on BOTH sides with DIFFERENT filenames. A shared filename (same prefix, same basename — i.e. an already-merged migration) is NOT a collision. Compute the unique-to-each-side basenames first, then look for shared prefixes within that unique set:
83
+
84
+ ```bash
85
+ # Files unique to each side (same-named files are NOT collisions)
86
+ comm -23 /tmp/cbp-merge-our-names.txt /tmp/cbp-merge-their-names.txt > /tmp/cbp-merge-only-ours.txt
87
+ comm -13 /tmp/cbp-merge-our-names.txt /tmp/cbp-merge-their-names.txt > /tmp/cbp-merge-only-theirs.txt
88
+ # True collision: a prefix in only-ours also appears in only-theirs (same prefix, different basename)
89
+ COLLISIONS=$(cat /tmp/cbp-merge-only-ours.txt /tmp/cbp-merge-only-theirs.txt \
90
+ | sed 's|_.*||' | sort | uniq -d)
91
+ ```
92
+
93
+ 3. If `COLLISIONS` is empty, proceed silently to Step 2.
94
+
95
+ 4. If `COLLISIONS` is non-empty, for each colliding prefix list both file paths (one from `HEAD`, one from `origin/{BASE}`) and surface via AskUserQuestion:
96
+
97
+ - **Rename HEAD-side (Recommended when a main migration is already applied to a shared remote)** — rename the local file to a fresh, sequential timestamp that respects existing apply-order dependencies (probe `supabase migration list --db-url <preview>` if a preview branch exists, or inspect FK references in surrounding migrations). The orchestrator runs `git mv <old> <new>` itself; the rename lands in the git index and is picked up by the re-probe at step 5.
98
+ - **Rename main-side (manual, OUT-OF-SKILL)** — only when the main file definitely has not been applied anywhere yet AND the user has write access to `{BASE}`. This skill does NOT touch the main branch: it runs on a feat branch (Step 0 enforces this) and the Key Rules below forbid any push from this skill. The user must, in a separate terminal: `git checkout {BASE} && git mv <old> <new> && git commit -m "fix(migration): rename to resolve collision with feat/..." && git push origin {BASE}`. After that push is confirmed remote-side, re-invoke `/cbp-merge-main` — Step 1 will fetch the updated main tip and Step 1.5 will re-probe with the rename in place.
99
+ - **Defer to a new task in the active checkpoint** — `git merge --abort` is unnecessary because Step 2 has not started. Create a CHK-bound task per `infra-issue-absorption.md` "Resolve-in-Current-Scope by Default" and STOP `/cbp-merge-main`. Resume after the task completes.
100
+ - **Abort merge** — STOP the skill. User decides later.
101
+
102
+ 5. After any HEAD-side rename action, re-execute Step 1.5 (collisions may chain — fixing one can expose another). The HEAD-side probe at step 1 uses `git ls-files` rather than `git ls-tree HEAD`, so the freshly-staged `git mv` is visible without requiring a commit. Main-side renames require a fresh `/cbp-merge-main` invocation (the user manually fetched and re-ran per option 2 above), not an in-skill loop.
103
+
104
+ This check is intentionally placed BEFORE Step 2's `git merge`: catching collisions pre-merge means no merge commit to revert, no conflict-resolution work to throw away, no Supabase Preview poll to fail.
105
+
106
+ ### Step 2: Merge with `--no-ff --no-commit`
107
+
108
+ 1. Run:
109
+
110
+ ```
111
+ git merge origin/{BASE} --no-ff --no-commit
112
+ ```
113
+
114
+ `--no-commit` defers the merge commit so Step 3 can resolve conflicts before committing (or `git merge --abort` if the user cancels). NEVER use `--ff-only` or rebase semantics — per locked decision.
115
+
116
+ 2. If git reports `Automatic merge went well; stopped before committing as requested.` (no conflicts):
117
+ - Commit the merge: `git commit --no-edit` (uses git's default merge message). If that fails (e.g. no MERGE_MSG template), fall back to: `git commit -m "chore(merge): integrate origin/{BASE} into {CURRENT}"`.
118
+ - Skip to Step 4.
119
+
120
+ 3. If conflicts: continue to Step 3.
121
+
122
+ ### Step 3: Interactive Per-Conflict Resolution
123
+
124
+ 1. List conflicted files and lock the count: `N=$(git diff --name-only --diff-filter=U | wc -l)`. `N` is the canonical conflict count used by Step 3.5 fallback message and Step 5 output; it stays fixed at the initial value across loop-backs.
125
+
126
+ 2. Load cross-reference context. Via MCP, gather all active CHK/TASK file ownership:
127
+ - `get_checkpoints(repo_id)` filtered to `status IN ('pending', 'active', 'in_progress')`.
128
+ - For each active checkpoint, also call `get_tasks(checkpoint_id)` and collect every `task.files_changed[].path` — checkpoint-bound task file ownership lives here, NOT on the checkpoint itself.
129
+ - `get_tasks(repo_id, standalone: true)` filtered to `status IN ('pending', 'in_progress')` — adds standalone-task file ownership.
130
+
131
+ Build a map `path -> [referencing CHK-NNN TASK-N + brief context]` by matching each conflicted path against:
132
+ - `checkpoint.context.files_to_change[]` (checkpoint-level plan)
133
+ - `task.files_changed[].path` (both checkpoint-bound AND standalone task file ownership)
134
+ - `task.requirements` (substring match for the path)
135
+
136
+ 3. For each conflicted file, IN ORDER:
137
+
138
+ a. Show:
139
+ - Conflicted file path
140
+ - `BEHIND` / `AHEAD` summary
141
+ - Cross-reference matches (`This file is referenced by CHK-NNN TASK-N: <brief>`)
142
+ - A unified diff of the conflict markers (`git diff -- {path}`)
143
+
144
+ b. Surface AskUserQuestion with these options. The "Recommended" tag is computed from cross-reference data:
145
+ - **Take ours (feat branch)** — `git checkout --ours {path} && git add {path}`.
146
+ Recommended when the path appears in any active CHK/TASK files_changed (the feat branch's work owns this file).
147
+ - **Take theirs (main)** — `git checkout --theirs {path} && git add {path}`.
148
+ Recommended when the path is NOT referenced by any active CHK/TASK (main's evolution wins by default).
149
+ - **Manual edit** — pause the skill. Prompt: `Edit {path} to resolve, then reply 'done' to continue.` Wait. After 'done': run `grep -l '<<<<<<<' {path}` — if it matches, the file still has conflict markers; surface the same prompt again. When clean: `git add {path}` and move on.
150
+ - **Show full diff** — print `git diff -- {path}` (working copy vs HEAD). For per-side views, run each separately (the `--base` / `--ours` / `--theirs` flags are mutually exclusive — combining them in one `git diff` invocation is invalid): `git diff --base -- {path}` (ancestor), `git diff --ours -- {path}` (HEAD), `git diff --theirs -- {path}` (MERGE_HEAD). After printing, RE-ASK the question — this option is meta and does not progress.
151
+
152
+ c. **Deliberate override of `[[feedback_claude-dir-wholesale-on-merge]]`**: that auto-memory rule recommended a wholesale `.claude/` overwrite for one-off long-lived-branch migrations. THIS skill is the routine periodic-sync mechanism, and the user explicitly chose per-conflict review for ALL paths including `.claude/`. Do NOT add a `.claude/`-wholesale shortcut. If a future maintainer is tempted to optimize by re-introducing the wholesale rule, the comment in this step is the contract: per-conflict review is the policy.
153
+
154
+ 4. After all conflicts resolved, verify clean: `git diff --name-only --diff-filter=U` MUST return empty. If not, loop back to step 3 with the remaining conflicts.
155
+
156
+ 5. Commit the merge:
157
+
158
+ ```
159
+ git commit --no-edit
160
+ ```
161
+
162
+ If that fails (e.g. no merge message template), fall back to explicit message:
163
+
164
+ ```
165
+ git commit -m "chore(merge): integrate origin/{BASE} into {CURRENT} (resolved {N} conflicts)"
166
+ ```
167
+
168
+ ### Step 4: Inline Automated QA Re-run
169
+
170
+ Run a scoped subset of the testing-qa check matrix INLINE (no agent spawn — this skill stays lightweight):
171
+
172
+ 1. `pnpm -w lint` — always. On non-zero exit, surface stdout/stderr and AskUserQuestion:
173
+ - **Continue (commit-as-is)** — leave the merge committed; flag QA failure in output.
174
+ - **Abort merge** — `git reset --hard HEAD~1` to revert just the merge commit. Stop the skill.
175
+ - **Skip (mark warn)** — leave the merge committed; treat as warn, not fail.
176
+
177
+ 2. `pnpm exec tsc --noEmit` — only if any merged file matches `*.ts` or `*.tsx`. Same three-option prompt on failure.
178
+
179
+ 3. `pnpm test --run` — only if any merged file matches typical source globs (`src/**`, `apps/**/src/**`, `packages/**/src/**`). Same three-option prompt on failure.
180
+
181
+ 4. Build a `qa_summary` object:
182
+
183
+ ```
184
+ {
185
+ "lint": "pass" | "fail" | "warn" | "skipped",
186
+ "tsc": "pass" | "fail" | "warn" | "skipped",
187
+ "tests": "pass" | "fail" | "warn" | "skipped",
188
+ "merged_files_count": N,
189
+ "user_choice_on_failure": "continue" | "abort" | "skip" | null
190
+ }
191
+ ```
192
+
193
+ Do NOT auto-revert without user consent. User-driven gating is the contract.
194
+
195
+ ### Step 5: Output
196
+
197
+ Print:
198
+
199
+ ```
200
+ ## /cbp-merge-main complete
201
+
202
+ **Merged**: origin/{BASE} → {CURRENT}
203
+ **Commits pulled in**: {BEHIND}
204
+ **Conflicts resolved**: {N}
205
+ **QA**: {pass|warn|fail} ({passed}/{total})
206
+ ```
207
+
208
+ Return control to the caller. **This skill NEVER pushes** — the caller decides when to push (preserves merge-commit review opportunity for the user before it lands on remote).
209
+
210
+ ## Key Rules
211
+
212
+ - **Never rebase. Never force-push.** Merge-only via `--no-ff` (per `[[feedback_long-lived-branch-integration]]`).
213
+ - **Never `git stash`** (per `[[feedback_no-git-stash]]`). Dirty tree → commit or cancel.
214
+ - **Per-conflict user prompts — no shortcuts.** Deliberate override of `[[feedback_claude-dir-wholesale-on-merge]]`; that rule was scoped to a one-off migration.
215
+ - **Never push.** Caller pushes after reviewing the merge commit.
216
+ - **Abort on offline.** `git fetch` failure is a hard stop.
217
+
218
+ ## Integration
219
+
220
+ - **Triggered by**:
221
+ - `/cbp-task-start` Step 3.6 (optional stale-check: >10 commits behind OR >24h fetch age)
222
+ - `/cbp-task-complete` Step 4.5 (mandatory pre-complete)
223
+ - `/cbp-checkpoint-end` Step 0 (mandatory pre-shipment)
224
+ - User-invocable manually
225
+ - **Reads**: `.codebyplan/git.json`, MCP `get_checkpoints`, MCP `get_tasks`, git state
226
+ - **Writes**: git merge commit (no MCP writes; no remote push)
227
+ - **Spawns**: none (`/cbp-git-commit` is inline-triggered at Step 0 dirty-tree handling)
228
+ - **Network**: contacts `origin` via `git fetch`. Offline = abort.