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,314 @@
1
+ ---
2
+ scope: org-shared
3
+ name: cbp-supabase-migrate
4
+ description: Scaffold or adopt a Supabase migration for the current PR branch, apply to the branch's preview DB, run advisor checks, regenerate TypeScript types. Includes a fresh-branch dry-run pre-flight that uses one persistent dry-run ephemeral branch per feature branch.
5
+ argument-hint: "[--new <name> | <path-to-sql>]"
6
+ allowed-tools: Read, Edit, Write, Bash(git *), Bash(supabase *), Bash(jq *), Bash(date *), Bash(which *), Bash(cp *), Bash(mv *), Bash(test *), Bash(ls *), mcp__supabase__apply_migration, mcp__supabase__list_migrations, mcp__supabase__get_advisors, mcp__supabase__generate_typescript_types, mcp__supabase__reset_branch, mcp__supabase__list_branches
7
+ model: sonnet
8
+ effort: xhigh
9
+ ---
10
+
11
+ # Supabase Migrate
12
+
13
+ Scaffold or adopt a migration for the current PR branch, apply it to that branch's preview
14
+ database, run security and performance advisor checks, and regenerate TypeScript types.
15
+
16
+ Run from a feature branch with an open PR. The skill targets the branch's isolated preview
17
+ database — never the main project database (unless an explicit override token is supplied).
18
+
19
+ ## When to Use
20
+
21
+ - You have a schema change (new table, altered column, new index, RLS policy) and need to
22
+ ship it with your PR.
23
+ - A migration file already exists on disk (e.g., from `supabase migration new`) and you
24
+ want to apply it to the preview DB and regenerate types.
25
+ - Run after `supabase db diff` produces output you want to formalise.
26
+
27
+ ## Arguments
28
+
29
+ Inspect `$ARGUMENTS`:
30
+
31
+ - `--new <name>` — scaffold a new timestamped migration file at
32
+ `supabase/migrations/<timestamp>_<name>.sql` and open it for editing.
33
+ - `<path-to-sql>` — adopt an existing file: apply it directly to the preview DB.
34
+ - _(bare / no arguments)_ — AskUserQuestion picker (see Step 5).
35
+
36
+ ## Step 1 — Pre-flight: Verify Git Branch
37
+
38
+ ```bash
39
+ git branch --show-current
40
+ ```
41
+
42
+ If the output is empty or the branch is in detached HEAD state, **stop immediately**:
43
+
44
+ ```
45
+ Cannot proceed: not on a named branch (detached HEAD or empty output).
46
+ Check out a feature branch first: git checkout -b feat/<name>
47
+ ```
48
+
49
+ Capture the branch name for use in Step 2.
50
+
51
+ ## Step 2 — Resolve Branch project_ref
52
+
53
+ Retrieve the branch's Supabase preview environment using the CLI:
54
+
55
+ ```bash
56
+ BRANCH=$(git branch --show-current)
57
+ supabase --experimental branches get "$BRANCH" -o env
58
+ ```
59
+
60
+ Parse the output for:
61
+ - `POSTGRES_URL_NON_POOLING` — direct connection string for the preview DB
62
+ - `project_ref` — the Supabase project ref for this branch's environment
63
+
64
+ Capture both values. The `project_ref` is used in Steps 3, 4, 6, 7, and 8. (Step 5.5 resolves its own separate dry-run branch `project_ref` — see [reference/preflight-dry-run.md](reference/preflight-dry-run.md).)
65
+
66
+ ## Step 2.5 — Empty project_ref Handling
67
+
68
+ If `project_ref` is empty after Step 2, AskUserQuestion:
69
+
70
+ ```
71
+ Could not resolve a Supabase project_ref for branch: <BRANCH>
72
+
73
+ Three known causes:
74
+ 1. No database-schema changes are in this PR (branching only provisions when DB paths change)
75
+ 2. The branch has not been pushed to remote yet (git push origin <BRANCH>)
76
+ 3. No open PR exists for this branch (Supabase branching requires an open PR on GitHub)
77
+
78
+ Options:
79
+ A) Scaffold-only mode — write the SQL file now, skip apply/advisors/types.
80
+ After push + open PR, re-run /cbp-supabase-migrate to apply and regenerate types.
81
+ B) Hard-refuse — stop here and fix the root cause first (see causes above).
82
+ C) Cancel — abort this invocation.
83
+ ```
84
+
85
+ On (A): continue to Step 5 (scaffold / adopt only), then exit after writing the file.
86
+ On (B): emit a summary of the three causes and stop.
87
+ On (C): stop silently.
88
+
89
+ ## Step 3 — Main-Project Guard
90
+
91
+ If `project_ref` is empty (scaffold-only mode chosen in Step 2.5), skip Steps 3 and 4 entirely and jump directly to Step 5.
92
+
93
+ Read `.codebyplan.json`:
94
+
95
+ ```bash
96
+ MAIN_PROJECT_REF=$(jq -r '.shipment.surfaces.supabase.project_ref' .codebyplan.json)
97
+ ```
98
+
99
+ `MAIN_PROJECT_REF` is consumed by Step 5.5's dry-run CLI calls (`branches create` and `branches get`) to pin those calls to the parent project rather than any linked preview branch.
100
+
101
+ If the resolved `project_ref` from Step 2 matches `$MAIN_PROJECT_REF`, the skill is targeting the
102
+ **main production database**. This is almost always unintentional during development.
103
+
104
+ Check `$ARGUMENTS` for the exact override token `I-UNDERSTAND-RUNNING-AGAINST-MAIN`.
105
+
106
+ If the token is **absent**, AskUserQuestion:
107
+
108
+ ```
109
+ WARNING: the resolved project_ref (<project_ref>) matches the main production project.
110
+
111
+ Applying migrations directly to production is destructive and bypasses PR review.
112
+ If you intended to target the branch preview DB, ensure:
113
+ - The branch is pushed to remote
114
+ - An open PR exists
115
+
116
+ To proceed anyway, re-invoke with:
117
+ /cbp-supabase-migrate I-UNDERSTAND-RUNNING-AGAINST-MAIN
118
+
119
+ Or cancel to abort.
120
+ ```
121
+
122
+ Stop and wait for the user. Do NOT proceed against the main project without the override token.
123
+
124
+ ## Step 4 — Idempotency Check
125
+
126
+ If `project_ref` is empty (scaffold-only mode), skip this step and jump to Step 5.
127
+
128
+ Before applying anything, check whether the migration is already present on the preview DB:
129
+
130
+ If `mcp__supabase__list_migrations` is available in your current toolset, call it with the
131
+ resolved `project_ref`. Scan the returned list for a filename or version prefix that matches
132
+ the file you are about to apply.
133
+
134
+ If a match is found:
135
+
136
+ ```
137
+ Migration already applied: <filename>
138
+ No-op — skipping apply. Types will still be regenerated if needed.
139
+ ```
140
+
141
+ Skip Steps 5.5 and 6 (dry-run pre-flight and apply) and proceed directly to Step 7 (advisors).
142
+
143
+ ## Step 5 — Scaffold or Adopt
144
+
145
+ Parse `$ARGUMENTS`:
146
+
147
+ ### Case A: `--new <name>`
148
+
149
+ Generate a timestamp strictly greater than the latest filename in `supabase/migrations/`:
150
+
151
+ ```bash
152
+ ls supabase/migrations/ | sort | tail -1
153
+ ```
154
+
155
+ Extract the numeric prefix from the `tail -1` output (e.g. `20260520000003` from `20260520000003_chk116_security_and_logging_fixes.sql`). Your `date -u +%Y%m%d%H%M%S` output must be strictly greater than that prefix. If two scaffolds happen in the same UTC second, append `_01`, `_02` to maintain monotonicity. Use the current wall-clock UTC time
156
+ via:
157
+
158
+ ```bash
159
+ date -u +%Y%m%d%H%M%S
160
+ ```
161
+
162
+ Create the file:
163
+
164
+ ```bash
165
+ TIMESTAMP=$(date -u +%Y%m%d%H%M%S)
166
+ touch "supabase/migrations/${TIMESTAMP}_<name>.sql"
167
+ ```
168
+
169
+ Open the file for editing — write the migration SQL now. Include both the intended change
170
+ and a comment block at the top:
171
+
172
+ ```sql
173
+ -- Migration: <name>
174
+ -- Created: <ISO timestamp>
175
+ -- Branch: <BRANCH>
176
+ -- Purpose: <one-line description>
177
+ ```
178
+
179
+ Record the created path as `MIGRATION_PATH`.
180
+
181
+ ### Case B: `<path-to-sql>`
182
+
183
+ Verify the file exists:
184
+
185
+ ```bash
186
+ test -f "$ARGUMENTS" && echo "ok" || echo "missing"
187
+ ```
188
+
189
+ If missing, stop with:
190
+ ```
191
+ File not found: <path>
192
+ Provide a valid path to an existing .sql file, or use --new <name> to scaffold.
193
+ ```
194
+
195
+ Set `MIGRATION_PATH="$ARGUMENTS"`.
196
+
197
+ ### Case C: bare (no arguments)
198
+
199
+ AskUserQuestion:
200
+
201
+ ```
202
+ No argument provided. What would you like to do?
203
+
204
+ A) --new <name> — scaffold a new migration file (I will name it)
205
+ B) <path-to-sql> — apply an existing file (I will provide the path)
206
+ C) Cancel
207
+ ```
208
+
209
+ On (A): prompt for the migration name, then follow Case A.
210
+ On (B): prompt for the file path, then follow Case B.
211
+ On (C): stop.
212
+
213
+ ## Step 5.5 — Fresh-Branch Dry-Run Pre-Flight
214
+
215
+ If `project_ref` is empty (scaffold-only mode from Step 2.5), skip this step — there is no preview environment to validate against.
216
+
217
+ Before applying `MIGRATION_PATH` to the real preview DB, validate the candidate migration on a persistent dry-run branch. The dry-run branch starts from main's migration baseline; `supabase db push` then advances it through the feature branch's local chain plus `MIGRATION_PATH`. This catches migration failures early — the GitHub Preview check (full replay from the feature branch) remains the authoritative gate. Full mechanics: [reference/preflight-dry-run.md](reference/preflight-dry-run.md).
218
+
219
+ Outcome gate:
220
+
221
+ | Dry-run result | Action |
222
+ |------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
223
+ | `FUNCTIONS_DEPLOYED` | Pre-flight passed — continue to Step 6. |
224
+ | `MIGRATIONS_FAILED` (db push exited non-zero) | Surface the verbatim CLI stderr from `supabase db push` and **stop**; do NOT apply to the PR preview DB. |
225
+ | `MIGRATIONS_FAILED` (db push exited 0, status poll reached MIGRATIONS_FAILED) | Platform-side failure after apply was accepted — see Supabase dashboard: **Branches → `DRY_RUN_BRANCH` → Migrations**; **stop**. |
226
+ | Timeout (up to ~5 min) | Surface a timeout message and **stop**. (Two 120 s poll loops + a 60 s stuck-branch guard.) |
227
+
228
+ ## Step 6 — Apply Migration
229
+
230
+ Apply `MIGRATION_PATH` to the branch preview database.
231
+
232
+ **MCP path (preferred)**: If `mcp__supabase__apply_migration` is available in your current
233
+ toolset, use it with the resolved `project_ref` and the SQL content from `MIGRATION_PATH`.
234
+
235
+ **CLI fallback**: If the MCP tool is not present, fall back to the CLI approach —
236
+ see [reference/cli-fallback.md](reference/cli-fallback.md) for the full procedure including
237
+ passing the branch connection string via `--db-url` and verification steps.
238
+
239
+ After applying, verify with `mcp__supabase__list_migrations` (or `supabase migration list`
240
+ on the CLI path) to confirm the migration appears in the list.
241
+
242
+ If verification fails after one retry, return `blocked`:
243
+
244
+ ```
245
+ Migration apply failed or could not be verified after retry.
246
+ Check: Supabase dashboard → Branches → <BRANCH> → Migrations
247
+ ```
248
+
249
+ ## Step 7 — Advisor Checks
250
+
251
+ Run advisor checks against the preview DB using the resolved `project_ref`.
252
+
253
+ Call `mcp__supabase__get_advisors` twice:
254
+ 1. `type: "security"` — security policy findings
255
+ 2. `type: "performance"` — query performance findings
256
+
257
+ Rank all findings by `level` in this order: **ERROR → WARN → INFO**.
258
+
259
+ Display a summary table:
260
+
261
+ ```
262
+ Advisor findings for <BRANCH> (<project_ref last 4 chars>):
263
+
264
+ | Level | Count | Examples |
265
+ |-------|-------|---------|
266
+ | ERROR | N | <first finding title> |
267
+ | WARN | N | <first finding title> |
268
+ | INFO | N | ... |
269
+ ```
270
+
271
+ No advisor finding blocks migration apply — output is advisory only.
272
+ See [reference/advisor-triage.md](reference/advisor-triage.md) for recommended actions per
273
+ severity level. Hard-block enforcement at ship time is owned by `cbp-supabase-branch-check`.
274
+
275
+ ## Step 8 — Regenerate TypeScript Types
276
+
277
+ Read the types output path from `.codebyplan.json`:
278
+
279
+ ```bash
280
+ jq -r '.shipment.surfaces.supabase.types_path' .codebyplan.json
281
+ ```
282
+
283
+ If the field is missing or empty, AskUserQuestion:
284
+
285
+ ```
286
+ types_path not found in .codebyplan.json under shipment.surfaces.supabase.types_path.
287
+ Enter the path where TypeScript types should be written (e.g., apps/web/src/lib/database.types.ts):
288
+ ```
289
+
290
+ Call `mcp__supabase__generate_typescript_types` with the resolved `project_ref`. Write the
291
+ returned content to the resolved `types_path` using the Write tool.
292
+
293
+ ## Step 9 — Final Summary
294
+
295
+ Emit a status block:
296
+
297
+ ```
298
+ ## Supabase Migrate — Complete
299
+
300
+ | Item | Value |
301
+ |-----------------------|--------------------------------------------|
302
+ | Migration file | <MIGRATION_PATH> |
303
+ | Preview project_ref | ....<last 4 chars of project_ref> |
304
+ | Advisors — ERROR | N |
305
+ | Advisors — WARN | N |
306
+ | Advisors — INFO | N |
307
+ | Types written to | <types_path> |
308
+
309
+ Next: open a PR (if not already open) and the Supabase Preview check will run automatically.
310
+ ```
311
+
312
+ ## Integration
313
+
314
+ Invoked by the developer or by `cbp-database-agent`'s routing rule. Companion: `/cbp-supabase-setup` (one-time enablement); ship-time hard-block lives in `cbp-supabase-branch-check`. References: [reference/advisor-triage.md](reference/advisor-triage.md) (severity), [reference/cli-fallback.md](reference/cli-fallback.md) (CLI apply).
@@ -0,0 +1,70 @@
1
+ # Advisor Triage — Supabase Migrate
2
+
3
+ Used by `/cbp-supabase-migrate` Step 7 after calling `mcp__supabase__get_advisors`.
4
+ Covers severity definitions, recommended actions per level, escalation criteria, and the
5
+ boundary between advisory output and hard-block enforcement.
6
+
7
+ ## Severity Table
8
+
9
+ | Level | Definition | Urgency | Example |
10
+ |-------|-----------|---------|---------|
11
+ | ERROR | Critical finding — policy gap, exposed data, or query that will fail at scale under load | Fix before merging this PR | RLS disabled on a table with user data; missing index on a FK used in a high-traffic JOIN |
12
+ | WARN | Suboptimal pattern — likely to cause performance degradation or security ambiguity as data grows | Review and decide before merge | Sequential scan on a table expected to exceed 100k rows; overly broad RLS `USING (true)` |
13
+ | INFO | Low-priority observation — best-practice deviation or minor inefficiency | Log for backlog; no merge gate | Unused index; column naming convention deviation |
14
+
15
+ ## Recommended Actions Per Level
16
+
17
+ ### ERROR
18
+
19
+ 1. Read the advisor finding detail (`title`, `description`, `metadata`).
20
+ 2. Determine whether the finding is caused by THIS migration or pre-existed.
21
+ - Pre-existing ERROR: note it in the PR description; it is NOT a merge blocker for this PR.
22
+ - New ERROR from this migration: fix it in the migration SQL before the PR is reviewed.
23
+ 3. Common fixes:
24
+ - **RLS not enabled**: add `ALTER TABLE <table> ENABLE ROW LEVEL SECURITY;` to the migration.
25
+ - **Missing FK index**: add `CREATE INDEX ON <table>(<fk_col>);` to the migration.
26
+ - **Policy always-true**: scope the `USING` predicate to `auth.uid()` or a specific role.
27
+ 4. Re-run `/cbp-supabase-migrate` after fixing to confirm the ERROR count drops.
28
+
29
+ ### WARN
30
+
31
+ 1. Read the finding and assess whether it is introduced by this migration or pre-existing.
32
+ 2. For new WARNs, evaluate impact:
33
+ - **Low-traffic table** (< 10k rows, internal use): note in PR description, defer fix.
34
+ - **High-traffic table or critical query path**: fix in this migration round.
35
+ 3. Document your decision as a comment in the PR description:
36
+ ```
37
+ Advisor WARN: <finding title> — deferred / fixed in <migration filename>
38
+ ```
39
+
40
+ ### INFO
41
+
42
+ - Log for the backlog. No action required before merge.
43
+ - If a batch of INFOs describes the same pattern (e.g., multiple missing naming conventions),
44
+ consider a dedicated cleanup task.
45
+
46
+ ## Escalation Criteria
47
+
48
+ Escalate to a synchronous review (team discussion, not just async PR comment) when:
49
+
50
+ - 3 or more **ERROR**-level findings are present on tables with user PII or financial data.
51
+ - A **WARN** involves an RLS policy on a table that stores session tokens, payment info, or
52
+ child account data.
53
+ - Any finding is flagged as `severity: critical` in the `metadata` field (not standard, but
54
+ some advisor versions use this field).
55
+
56
+ ## Advisory-Only Boundary
57
+
58
+ **No advisor finding blocks `cbp-supabase-migrate` from completing.**
59
+
60
+ The skill outputs findings for developer awareness and exits with a summary. Hard-block
61
+ enforcement — refusing to allow a PR to merge when ERRORs are present — is owned by
62
+ `cbp-supabase-branch-check` (TASK-3), which runs at ship time as part of the Supabase
63
+ Preview check gate.
64
+
65
+ This separation means:
66
+ - Developers can merge WIP migrations during active development without advisor-gate friction.
67
+ - Ship-time enforcement is consistent and automated — no manual override needed.
68
+
69
+ If you want to simulate ship-time behaviour locally, run `/cbp-supabase-branch-check`
70
+ (once implemented) against the current branch before opening the PR for review.
@@ -0,0 +1,87 @@
1
+ # CLI Fallback — Supabase Migrate
2
+
3
+ Used by `/cbp-supabase-migrate` Step 6 when `mcp__supabase__apply_migration` is not present
4
+ in the current toolset. Covers applying via `supabase db push --db-url` with the branch
5
+ connection string, verification, and troubleshooting common errors.
6
+
7
+ ## When This Path Applies
8
+
9
+ Use this path when `mcp__supabase__apply_migration` is NOT available in your current tool
10
+ list (e.g., running in a context where the Supabase MCP server is not connected, or during
11
+ local CLI-only development). The CLI path applies the migration directly via `psql`-compatible
12
+ connection to the branch preview database.
13
+
14
+ If MCP IS available, use it — it is the preferred path.
15
+
16
+ ## 1. Apply via supabase db push
17
+
18
+ Push the pending migration to the branch preview DB using the connection string captured
19
+ in Step 2 of the parent skill (`POSTGRES_URL_NON_POOLING`):
20
+
21
+ ```bash
22
+ supabase db push --db-url "$POSTGRES_URL_NON_POOLING"
23
+ ```
24
+
25
+ Expected output (success):
26
+
27
+ ```
28
+ Applying migration 20260520123456_your_migration_name.sql...
29
+ Migration applied successfully.
30
+ ```
31
+
32
+ The `--db-url` flag accepts a full connection string and routes the push to that database directly — bypassing the project configured in `supabase/config.toml`. The `--linked` and `--db-url` flags are mutually exclusive; do not combine them.
33
+
34
+ To push a single specific file rather than all pending migrations:
35
+
36
+ ```bash
37
+ supabase db push --db-url "$POSTGRES_URL_NON_POOLING" --file supabase/migrations/<filename>.sql
38
+ ```
39
+
40
+ ## 2. Verify the Migration Applied
41
+
42
+ After the push, confirm the migration is recorded:
43
+
44
+ ```bash
45
+ supabase migration list --db-url "$POSTGRES_URL_NON_POOLING"
46
+ ```
47
+
48
+ The migration filename should appear in the list. If it does not:
49
+
50
+ 1. Wait 10 seconds (remote provisioning can lag) and re-run `supabase migration list --db-url "$POSTGRES_URL_NON_POOLING"`.
51
+ 2. Check the Supabase dashboard: **Branches → <branch name> → Migrations**.
52
+ 3. If still absent, retry `supabase db push --db-url "$POSTGRES_URL_NON_POOLING"` once.
53
+
54
+ Once confirmed, continue with `/cbp-supabase-migrate` Step 7 (Advisor Checks).
55
+
56
+ ## 3. Troubleshooting
57
+
58
+ ### Auth failure: `FATAL: password authentication failed`
59
+
60
+ - Verify the connection string was captured correctly — it may contain special characters that need
61
+ URL-decoding (`%40` = `@`, `%21` = `!`).
62
+ - Re-fetch the connection string from the branch: `supabase --experimental branches get "$BRANCH" -o env`
63
+ - Confirm the branch is still active: `supabase --experimental branches list`
64
+
65
+ ### Connection refused: `could not connect to server`
66
+
67
+ - The branch preview DB may still be provisioning. Wait 30 seconds and retry.
68
+ - Verify the connection string has no extra characters.
69
+ - Check firewall / VPN — some networks block direct PostgreSQL connections to Supabase.
70
+
71
+ ### Migration already applied: `ERROR: relation already exists`
72
+
73
+ The migration file was already applied to this preview DB (possibly via MCP in a prior run).
74
+ This is safe to ignore. The idempotency check in `/cbp-supabase-migrate` Step 4 should have
75
+ caught this — if not, note the discrepancy and skip to Step 7.
76
+
77
+ ### CLI not found
78
+
79
+ ```
80
+ Supabase CLI not found. Install options:
81
+ brew install supabase/tap/supabase (macOS / Homebrew)
82
+ npm install -g supabase (npm global)
83
+ scoop install supabase (Windows Scoop)
84
+ https://supabase.com/docs/guides/local-development/cli/getting-started
85
+ ```
86
+
87
+ After installing, restart your shell and re-run `/cbp-supabase-migrate`.
@@ -0,0 +1,58 @@
1
+ # Pre-Flight Dry-Run Mechanics
2
+
3
+ Detailed procedure for `cbp-supabase-migrate` Step 5.5 — validating a new migration on a dry-run Supabase branch before applying it to the real PR preview DB.
4
+
5
+ ## Why
6
+
7
+ `supabase --experimental branches create` clones the connected repository at `git_ref=main` — it replays **main's** migration chain as a starting baseline, not the current feature branch's chain from zero. After the branch settles to `FUNCTIONS_DEPLOYED`, `supabase db push --db-url` advances it incrementally through the feature branch's local migrations (those not yet on main) plus the candidate `MIGRATION_PATH`. The dry-run catches migration failures early — at `/cbp-supabase-migrate` time rather than at PR-open time. It is a best-effort early check, not a from-zero feature-branch replay.
8
+
9
+ ## Dry-run branch lifecycle
10
+
11
+ The dry-run uses ONE persistent branch per feature branch — created on first use, reset on every subsequent use. Deterministic name:
12
+
13
+ DRY_RUN_BRANCH="${BRANCH}-cbp-migrate-dryrun"
14
+
15
+ The CLI `branches` sub-commands act on the project the CLI is *linked* to — mid-development that is often a preview branch, not the parent project. Pin every `branches` call to the parent with `--project-ref "$MAIN_PROJECT_REF"`, where `MAIN_PROJECT_REF` is the parent `project_ref` SKILL.md Step 3 already resolves from `.codebyplan.json` (`.shipment.surfaces.supabase.project_ref`). `mcp__supabase__list_branches` and `reset_branch` need no such flag — the MCP server is already bound to the parent project.
16
+
17
+ 1. Call `mcp__supabase__list_branches`. Look for an entry whose name equals `DRY_RUN_BRANCH`. If found, capture its `id` field as `DRY_RUN_BRANCH_ID` — `reset_branch` and every status poll below act on the branch id, not the name.
18
+ 2. **If absent** — run `supabase --experimental branches create "$DRY_RUN_BRANCH" --project-ref "$MAIN_PROJECT_REF" --yes`. The `--yes` flag is required: branch creation prompts for cost confirmation and the skill runs non-interactively, so the prompt would otherwise hang. The CLI create command is asynchronous and returns a human-readable message (not JSON with an `id`). After the CLI call, poll `mcp__supabase__list_branches` until an entry whose name equals `DRY_RUN_BRANCH` appears, then capture its `id` as `DRY_RUN_BRANCH_ID`. This poll both confirms the create succeeded and yields the id. Creation clones at `git_ref=main` and replays main's migration chain as a baseline — skip the reset in step 4 and go straight to step 5 (the initial provisioning already gave a main baseline).
19
+ 3. **If present and its `status` is any non-terminal value** (i.e., anything other than `FUNCTIONS_DEPLOYED` or `MIGRATIONS_FAILED`) — a prior run was interrupted mid-provision. Poll `mcp__supabase__list_branches` every 10 seconds, filtering to the entry with `id = DRY_RUN_BRANCH_ID`, for up to 60 seconds (6 polls). If it has not settled to a terminal status (`FUNCTIONS_DEPLOYED` or `MIGRATIONS_FAILED`) after 60 seconds, surface `Dry-run branch ${DRY_RUN_BRANCH} is stuck in ${status}. Resolve manually before retrying.` and stop. If the branch settles to `FUNCTIONS_DEPLOYED` during the poll, fall through to step 4 (reset). If it settles to `MIGRATIONS_FAILED`, main's chain is already broken before the new migration was applied — see the Supabase dashboard: **Branches → \<DRY_RUN_BRANCH\> → Migrations** for error details; stop. Note: a branch found already in `MIGRATIONS_FAILED` (from a prior failed run) does NOT enter this non-terminal poll — it is already terminal and falls through directly to step 4 (reset), which returns it to main's baseline so the retry can proceed.
20
+ 4. **If present** — call `mcp__supabase__reset_branch` with `DRY_RUN_BRANCH_ID`. Reset re-replays **main's** migration chain from zero, returning the dry-run branch to main's baseline.
21
+ 5. Poll `mcp__supabase__list_branches` every 10 seconds, filtering to the entry with `id = DRY_RUN_BRANCH_ID`, until status reaches `FUNCTIONS_DEPLOYED`, `MIGRATIONS_FAILED`, or 12 polls (120 seconds) have elapsed.
22
+
23
+ If main's chain itself reaches `MIGRATIONS_FAILED` at this stage, main's existing migrations are already broken — see the Supabase dashboard: **Branches → \<DRY_RUN_BRANCH\> → Migrations** for error details; stop. The new migration is not the cause.
24
+
25
+ ## Apply the new migration
26
+
27
+ Once the dry-run branch is `FUNCTIONS_DEPLOYED`:
28
+
29
+ 1. Resolve the dry-run branch connection string:
30
+ ```bash
31
+ supabase --experimental branches get "$DRY_RUN_BRANCH" --project-ref "$MAIN_PROJECT_REF" -o env
32
+ ```
33
+ Parse `POSTGRES_URL_NON_POOLING` from the output and set it as `DRY_RUN_CONN`.
34
+
35
+ 2. Apply the candidate migration:
36
+ ```bash
37
+ supabase db push --db-url "$DRY_RUN_CONN"
38
+ ```
39
+ `supabase db push` is an **incremental** apply — it inspects the branch's `schema_migrations` table, skips any migration already recorded there (i.e. those from main's chain), and applies only the feature branch's not-yet-on-main migrations plus `MIGRATION_PATH`. Exit 0 = apply accepted. Non-zero exit or stderr = apply rejected; the verbatim stderr IS the error surface (no `mcp__supabase__get_logs` call needed). This works for both `--new` (uncommitted file) and `<path-to-sql>` (adopt) modes, because the SQL is read from disk.
40
+
41
+ 3. Poll `mcp__supabase__list_branches` every 10 seconds, filtering to the entry with `id = DRY_RUN_BRANCH_ID`, until status reaches `FUNCTIONS_DEPLOYED`, `MIGRATIONS_FAILED`, or 12 polls (120 seconds) have elapsed.
42
+
43
+ ## Outcome
44
+
45
+ | Result | Meaning | Action |
46
+ |---------------------------------------------------------------|------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
47
+ | `FUNCTIONS_DEPLOYED` | New migration applies on top of main's chain | Return to Step 5.5 — continue to Step 6 |
48
+ | `MIGRATIONS_FAILED` (db push exited non-zero) | Migration rejected at apply time | The verbatim error is the CLI stderr from `supabase db push`; stop before Step 6 |
49
+ | `MIGRATIONS_FAILED` (db push exited 0, status poll reached MIGRATIONS_FAILED) | Platform-side failure after apply was accepted | See the Supabase dashboard: **Branches → `DRY_RUN_BRANCH` → Migrations** for error details; stop before Step 6 |
50
+ | Timeout (up to ~5 min) | Branch did not converge | Surface a timeout message; stop before Step 6. (Two 120 s poll loops + a 60 s stuck-branch guard.) |
51
+
52
+ ## Fidelity and limitations
53
+
54
+ The GitHub PR integration clones at `git_ref=<PR branch>` and replays from zero — that is the authoritative full-fidelity gate. The dry-run described here is a best-effort early check: it catches migrations that are syntactically invalid, reference missing objects, or violate ordering when applied on top of main's chain. Fidelity gap: in-place edits to migrations already recorded in main's `schema_migrations` are NOT re-applied by `db push`, so the dry-run cannot detect breakage from such edits (this is the bug class CHK-133 TASK-1 fixed in the `schema_migrations` PK collision and `remote_stub DELETE` guards). The live integration test of this dry-run design is deferred to post-CHK-133-TASK-3, once main's chain is fully healthy and `branches create` provisions successfully.
55
+
56
+ ## Platform cost
57
+
58
+ The dry-run branch is persistent — reused via `reset_branch` across invocations rather than created and deleted each time. Supabase counts it as one active branch against the project's branch limit for as long as the feature branch exists. This is intentional: branch creation is slow, reset is fast, and one long-lived dry-run branch per feature branch is cheaper than create/delete churn.