codebyplan 1.5.0 → 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 (206) hide show
  1. package/README.md +48 -5
  2. package/dist/cli.js +4578 -2709
  3. package/package.json +5 -1
  4. package/templates/.gitkeep +0 -0
  5. package/templates/README.md +20 -0
  6. package/templates/agents/cbp-cc-executor.md +213 -0
  7. package/templates/agents/cbp-database-agent.md +229 -0
  8. package/templates/agents/cbp-improve-claude.md +245 -0
  9. package/templates/agents/cbp-improve-round.md +284 -0
  10. package/templates/agents/cbp-mechanical-edits.md +111 -0
  11. package/templates/agents/cbp-research.md +282 -0
  12. package/templates/agents/cbp-round-executor.md +604 -0
  13. package/templates/agents/cbp-security-agent.md +134 -0
  14. package/templates/agents/cbp-task-check.md +213 -0
  15. package/templates/agents/cbp-task-planner.md +582 -0
  16. package/templates/agents/cbp-test-e2e-agent.md +363 -0
  17. package/templates/agents/cbp-testing-qa-agent.md +400 -0
  18. package/templates/context/mcp-docs.md +139 -0
  19. package/templates/hooks/README.md +236 -0
  20. package/templates/hooks/cbp-auto-test-hooks.sh +44 -0
  21. package/templates/hooks/cbp-lint-format-on-edit.sh +159 -0
  22. package/templates/hooks/cbp-maestro-yaml-validate.sh +100 -0
  23. package/templates/hooks/cbp-mcp-migration-guard.sh +32 -0
  24. package/templates/hooks/cbp-mcp-round-sync.sh +79 -0
  25. package/templates/hooks/cbp-mcp-worktree-inject.sh +76 -0
  26. package/templates/hooks/cbp-notify.sh +68 -0
  27. package/templates/hooks/cbp-plugin-dispatch.sh +29 -0
  28. package/templates/hooks/cbp-pre-commit-quality-gate.sh +204 -0
  29. package/templates/hooks/cbp-statusline.sh +347 -0
  30. package/templates/hooks/cbp-subagent-statusline.sh +182 -0
  31. package/templates/hooks/cbp-test-coverage-gate.sh +144 -0
  32. package/templates/hooks/cbp-test-hooks.sh +320 -0
  33. package/templates/hooks/hooks.json +85 -0
  34. package/templates/hooks/validate-context-usage.sh +59 -0
  35. package/templates/hooks/validate-git-commit.sh +78 -0
  36. package/templates/hooks/validate-git-stash-deny.sh +32 -0
  37. package/templates/hooks/validate-structure-lengths.sh +57 -0
  38. package/templates/hooks/validate-structure-lib.sh +104 -0
  39. package/templates/hooks/validate-structure-patterns.sh +54 -0
  40. package/templates/hooks/validate-structure-scope.sh +33 -0
  41. package/templates/hooks/validate-structure-smoke.sh +95 -0
  42. package/templates/hooks/validate-structure-templates.sh +34 -0
  43. package/templates/hooks/validate-structure.sh +69 -0
  44. package/templates/rules/.gitkeep +0 -0
  45. package/templates/rules/README.md +47 -0
  46. package/templates/rules/context-file-loading.md +52 -0
  47. package/templates/rules/scope-vocabulary.md +64 -0
  48. package/templates/rules/todo-backend.md +109 -0
  49. package/templates/settings.project.base.json +55 -0
  50. package/templates/settings.user.base.json +25 -0
  51. package/templates/skills/cbp-build-cc-agent/SKILL.md +139 -0
  52. package/templates/skills/cbp-build-cc-agent/examples/read-only-reviewer.md +32 -0
  53. package/templates/skills/cbp-build-cc-agent/examples/with-hooks.md +41 -0
  54. package/templates/skills/cbp-build-cc-agent/examples/with-skills-preload.md +25 -0
  55. package/templates/skills/cbp-build-cc-agent/reference/cbp-quality.md +153 -0
  56. package/templates/skills/cbp-build-cc-agent/reference/frontmatter-fields.md +37 -0
  57. package/templates/skills/cbp-build-cc-agent/reference/permission-modes.md +18 -0
  58. package/templates/skills/cbp-build-cc-agent/scripts/validate-agent.sh +67 -0
  59. package/templates/skills/cbp-build-cc-agent/templates/agent.md +66 -0
  60. package/templates/skills/cbp-build-cc-claude-file/SKILL.md +178 -0
  61. package/templates/skills/cbp-build-cc-claude-file/examples/minimal-project.md +33 -0
  62. package/templates/skills/cbp-build-cc-claude-file/examples/monorepo-with-imports.md +39 -0
  63. package/templates/skills/cbp-build-cc-claude-file/reference/imports.md +72 -0
  64. package/templates/skills/cbp-build-cc-claude-file/reference/what-belongs.md +39 -0
  65. package/templates/skills/cbp-build-cc-claude-file/templates/project-claude-md.md +48 -0
  66. package/templates/skills/cbp-build-cc-claude-file/templates/user-claude-md.md +22 -0
  67. package/templates/skills/cbp-build-cc-memory/SKILL.md +201 -0
  68. package/templates/skills/cbp-build-cc-memory/examples/feedback-memory.md +11 -0
  69. package/templates/skills/cbp-build-cc-memory/examples/project-memory.md +11 -0
  70. package/templates/skills/cbp-build-cc-memory/examples/reference-memory.md +13 -0
  71. package/templates/skills/cbp-build-cc-memory/examples/user-memory.md +14 -0
  72. package/templates/skills/cbp-build-cc-memory/reference/memory-types.md +59 -0
  73. package/templates/skills/cbp-build-cc-memory/reference/when-to-save.md +62 -0
  74. package/templates/skills/cbp-build-cc-memory/templates/MEMORY-index.md +4 -0
  75. package/templates/skills/cbp-build-cc-memory/templates/memory-entry.md +15 -0
  76. package/templates/skills/cbp-build-cc-mode/SKILL.md +99 -0
  77. package/templates/skills/cbp-build-cc-rule/SKILL.md +176 -0
  78. package/templates/skills/cbp-build-cc-rule/examples/global-rule.md +19 -0
  79. package/templates/skills/cbp-build-cc-rule/examples/scoped-rule.md +41 -0
  80. package/templates/skills/cbp-build-cc-rule/reference/paths-patterns.md +48 -0
  81. package/templates/skills/cbp-build-cc-rule/templates/rule.md +32 -0
  82. package/templates/skills/cbp-build-cc-settings/SKILL.md +220 -0
  83. package/templates/skills/cbp-build-cc-settings/examples/hooks-config.json +64 -0
  84. package/templates/skills/cbp-build-cc-settings/examples/permissions-config.json +34 -0
  85. package/templates/skills/cbp-build-cc-settings/examples/sandbox-config.json +42 -0
  86. package/templates/skills/cbp-build-cc-settings/reference/cbp-conventions.md +104 -0
  87. package/templates/skills/cbp-build-cc-settings/reference/permission-rules.md +61 -0
  88. package/templates/skills/cbp-build-cc-settings/reference/scope-precedence.md +73 -0
  89. package/templates/skills/cbp-build-cc-settings/reference/settings-fields.md +166 -0
  90. package/templates/skills/cbp-build-cc-settings/templates/settings.json +23 -0
  91. package/templates/skills/cbp-build-cc-settings/templates/settings.local.json +10 -0
  92. package/templates/skills/cbp-build-cc-skill/SKILL.md +154 -0
  93. package/templates/skills/cbp-build-cc-skill/examples/dynamic-context.md +31 -0
  94. package/templates/skills/cbp-build-cc-skill/examples/fork-skill.md +22 -0
  95. package/templates/skills/cbp-build-cc-skill/examples/knowledge-skill.md +25 -0
  96. package/templates/skills/cbp-build-cc-skill/examples/task-skill.md +29 -0
  97. package/templates/skills/cbp-build-cc-skill/reference/cbp-quality.md +157 -0
  98. package/templates/skills/cbp-build-cc-skill/reference/frontmatter-fields.md +35 -0
  99. package/templates/skills/cbp-build-cc-skill/reference/string-substitutions.md +60 -0
  100. package/templates/skills/cbp-build-cc-skill/scripts/validate-skill.sh +90 -0
  101. package/templates/skills/cbp-build-cc-skill/templates/skill.md +51 -0
  102. package/templates/skills/cbp-checkpoint-check/SKILL.md +156 -0
  103. package/templates/skills/cbp-checkpoint-complete/SKILL.md +109 -0
  104. package/templates/skills/cbp-checkpoint-create/SKILL.md +287 -0
  105. package/templates/skills/cbp-checkpoint-end/SKILL.md +241 -0
  106. package/templates/skills/cbp-checkpoint-update/SKILL.md +115 -0
  107. package/templates/skills/cbp-frontend-a11y/SKILL.md +109 -0
  108. package/templates/skills/cbp-frontend-a11y/reference/aria-roles-states.md +130 -0
  109. package/templates/skills/cbp-frontend-a11y/reference/contrast-visual.md +122 -0
  110. package/templates/skills/cbp-frontend-a11y/reference/keyboard-patterns.md +154 -0
  111. package/templates/skills/cbp-frontend-a11y/reference/semantic-html.md +111 -0
  112. package/templates/skills/cbp-frontend-design/SKILL.md +145 -0
  113. package/templates/skills/cbp-frontend-design/reference/nextjs-scss.md +118 -0
  114. package/templates/skills/cbp-frontend-design/reference/rn-expo.md +101 -0
  115. package/templates/skills/cbp-frontend-design/reference/tauri-react.md +82 -0
  116. package/templates/skills/cbp-frontend-ui/SKILL.md +262 -0
  117. package/templates/skills/cbp-frontend-ui/reference/ui-label-maps.md +42 -0
  118. package/templates/skills/cbp-frontend-ui/reference/ui-layout-patterns.md +105 -0
  119. package/templates/skills/cbp-frontend-ui/reference/variant-defaults.md +149 -0
  120. package/templates/skills/cbp-frontend-ux/SKILL.md +181 -0
  121. package/templates/skills/cbp-git-branch-feat-create/SKILL.md +115 -0
  122. package/templates/skills/cbp-git-commit/SKILL.md +278 -0
  123. package/templates/skills/cbp-git-worktree-create/SKILL.md +226 -0
  124. package/templates/skills/cbp-git-worktree-remove/SKILL.md +145 -0
  125. package/templates/skills/cbp-merge-main/SKILL.md +228 -0
  126. package/templates/skills/cbp-round-check/SKILL.md +104 -0
  127. package/templates/skills/cbp-round-end/SKILL.md +183 -0
  128. package/templates/skills/cbp-round-end/reference/findings-presentation.md +44 -0
  129. package/templates/skills/cbp-round-end/reference/inline-fallback.md +35 -0
  130. package/templates/skills/cbp-round-execute/SKILL.md +211 -0
  131. package/templates/skills/cbp-round-execute/reference/inline-fallback.md +59 -0
  132. package/templates/skills/cbp-round-input/SKILL.md +165 -0
  133. package/templates/skills/cbp-round-start/SKILL.md +222 -0
  134. package/templates/skills/cbp-round-update/SKILL.md +163 -0
  135. package/templates/skills/cbp-session-end/SKILL.md +187 -0
  136. package/templates/skills/cbp-session-start/SKILL.md +155 -0
  137. package/templates/skills/cbp-ship/SKILL.md +332 -0
  138. package/templates/skills/cbp-ship/reference/changesets-overview.md +120 -0
  139. package/templates/skills/cbp-ship/reference/eas-cli-overview.md +60 -0
  140. package/templates/skills/cbp-ship/reference/gh-cli-overview.md +135 -0
  141. package/templates/skills/cbp-ship/reference/gh-cli-shipment-commands.md +283 -0
  142. package/templates/skills/cbp-ship/reference/npm-publish-monorepo.md +252 -0
  143. package/templates/skills/cbp-ship/reference/npm-publish-oidc-trusted.md +157 -0
  144. package/templates/skills/cbp-ship/reference/npm-publish-overview.md +171 -0
  145. package/templates/skills/cbp-ship/reference/preflight-checklist.md +88 -0
  146. package/templates/skills/cbp-ship/reference/railway-nestjs-deployment.md +169 -0
  147. package/templates/skills/cbp-ship/reference/railway-overview.md +120 -0
  148. package/templates/skills/cbp-ship/reference/railway-troubleshooting.md +168 -0
  149. package/templates/skills/cbp-ship/reference/release-please-overview.md +99 -0
  150. package/templates/skills/cbp-ship/reference/surface-expo-eas.md +155 -0
  151. package/templates/skills/cbp-ship/reference/surface-npm.md +180 -0
  152. package/templates/skills/cbp-ship/reference/surface-railway.md +152 -0
  153. package/templates/skills/cbp-ship/reference/surface-supabase.md +178 -0
  154. package/templates/skills/cbp-ship/reference/surface-tauri.md +138 -0
  155. package/templates/skills/cbp-ship/reference/surface-vercel.md +124 -0
  156. package/templates/skills/cbp-ship/reference/surface-vscode-ext.md +144 -0
  157. package/templates/skills/cbp-ship/reference/surfaces.md +60 -0
  158. package/templates/skills/cbp-ship/reference/testflight-automation.md +215 -0
  159. package/templates/skills/cbp-ship/reference/testflight-internal-vs-external.md +69 -0
  160. package/templates/skills/cbp-ship/reference/testflight-overview.md +98 -0
  161. package/templates/skills/cbp-ship/reference/versioning.md +116 -0
  162. package/templates/skills/cbp-ship/scripts/detect-surfaces.sh +217 -0
  163. package/templates/skills/cbp-ship/scripts/verify-expo-eas.sh +35 -0
  164. package/templates/skills/cbp-ship/scripts/verify-npm.sh +21 -0
  165. package/templates/skills/cbp-ship/scripts/verify-railway.sh +41 -0
  166. package/templates/skills/cbp-ship/scripts/verify-supabase.sh +19 -0
  167. package/templates/skills/cbp-ship/scripts/verify-tauri.sh +24 -0
  168. package/templates/skills/cbp-ship/scripts/verify-vercel.sh +32 -0
  169. package/templates/skills/cbp-ship/scripts/verify-vscode-ext.sh +25 -0
  170. package/templates/skills/cbp-ship/templates/eas.json +66 -0
  171. package/templates/skills/cbp-ship/templates/railway.toml +15 -0
  172. package/templates/skills/cbp-ship/templates/release-please-config.json +17 -0
  173. package/templates/skills/cbp-ship/templates/vercel.json +19 -0
  174. package/templates/skills/cbp-ship/templates/vscodeignore +21 -0
  175. package/templates/skills/cbp-ship/templates/workflow-changesets.yml +41 -0
  176. package/templates/skills/cbp-ship/templates/workflow-eas-submit.yml +53 -0
  177. package/templates/skills/cbp-ship/templates/workflow-npm-publish.yml +36 -0
  178. package/templates/skills/cbp-ship/templates/workflow-release-please.yml +21 -0
  179. package/templates/skills/cbp-ship/templates/workflow-tauri-release.yml +69 -0
  180. package/templates/skills/cbp-ship/templates/workflow-vsce-publish.yml +31 -0
  181. package/templates/skills/cbp-ship-configure/SKILL.md +296 -0
  182. package/templates/skills/cbp-ship-configure/reference/expo-mobile.md +204 -0
  183. package/templates/skills/cbp-ship-configure/reference/npm-package.md +165 -0
  184. package/templates/skills/cbp-ship-configure/reference/railway-backend.md +199 -0
  185. package/templates/skills/cbp-ship-configure/reference/supabase.md +200 -0
  186. package/templates/skills/cbp-ship-configure/reference/tauri-desktop.md +181 -0
  187. package/templates/skills/cbp-ship-configure/reference/vercel.md +117 -0
  188. package/templates/skills/cbp-ship-configure/reference/vscode-ext.md +155 -0
  189. package/templates/skills/cbp-ship-main/SKILL.md +65 -0
  190. package/templates/skills/cbp-supabase-branch-check/SKILL.md +337 -0
  191. package/templates/skills/cbp-supabase-branch-check/reference/dag-steps.md +29 -0
  192. package/templates/skills/cbp-supabase-migrate/SKILL.md +314 -0
  193. package/templates/skills/cbp-supabase-migrate/reference/advisor-triage.md +70 -0
  194. package/templates/skills/cbp-supabase-migrate/reference/cli-fallback.md +87 -0
  195. package/templates/skills/cbp-supabase-migrate/reference/preflight-dry-run.md +58 -0
  196. package/templates/skills/cbp-supabase-setup/SKILL.md +239 -0
  197. package/templates/skills/cbp-supabase-setup/reference/branching-setup.md +121 -0
  198. package/templates/skills/cbp-supabase-setup/reference/cli-fallback.md +109 -0
  199. package/templates/skills/cbp-task-check/SKILL.md +166 -0
  200. package/templates/skills/cbp-task-complete/SKILL.md +206 -0
  201. package/templates/skills/cbp-task-complete/reference/checkpoint-done-branching.md +48 -0
  202. package/templates/skills/cbp-task-complete/reference/next-step-heuristic.md +56 -0
  203. package/templates/skills/cbp-task-create/SKILL.md +167 -0
  204. package/templates/skills/cbp-task-start/SKILL.md +239 -0
  205. package/templates/skills/cbp-task-testing/SKILL.md +277 -0
  206. package/templates/skills/cbp-todo/SKILL.md +97 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codebyplan",
3
- "version": "1.5.0",
3
+ "version": "1.8.0",
4
4
  "description": "CLI for CodeByPlan — AI-powered development planning and tracking",
5
5
  "type": "module",
6
6
  "bin": {
@@ -8,6 +8,7 @@
8
8
  },
9
9
  "files": [
10
10
  "dist/cli.js",
11
+ "templates/",
11
12
  "README.md"
12
13
  ],
13
14
  "scripts": {
@@ -43,6 +44,9 @@
43
44
  "engines": {
44
45
  "node": ">=18"
45
46
  },
47
+ "dependencies": {
48
+ "@napi-rs/keyring": "^1.1.6"
49
+ },
46
50
  "devDependencies": {
47
51
  "@eslint/js": "^9.18.0",
48
52
  "@types/node": "^20",
File without changes
@@ -0,0 +1,20 @@
1
+ # Templates
2
+
3
+ This directory holds the installed content that the `codebyplan claude install` subcommand places into a consuming project's `./.claude/` directory. Skills, agents, and hooks live here.
4
+
5
+ ## Authoring source
6
+
7
+ `packages/codebyplan-package/templates/` is the single source of truth for all `.claude/` content. The sibling-identity gate (CHK-134) requires that every edit to `templates/` is mirrored to `.claude/` in the same commit — there is no special "canonical worktree". Every worktree running this repo consumes updates via `npx codebyplan claude install|update`; release-please publishes the `codebyplan` npm package on merge to main, which propagates changes to consuming repos.
8
+
9
+ ## Layout
10
+
11
+ | Path | Count | Shape |
12
+ | --------- | ------------------------------------ | ----------------------------------------------------------------------------------------------- |
13
+ | `skills/` | 41 folders | each is a `SKILL.md` plus optional `templates/`, `reference/`, `examples/`, `scripts/` siblings |
14
+ | `agents/` | 12 files | flat `.md` agent prompts (NOT `AGENT.md` subdirs) |
15
+ | `hooks/` | 20 `.sh` + `hooks.json` + `README.md` | event hooks and manifest |
16
+ | `rules/` | 1+ files | flat `<name>.md` rule files; see `rules/README.md` for bar and format |
17
+
18
+ ## This directory IS the source of truth
19
+
20
+ Edit files in this directory directly. There is no upstream tree — CHK-111 TASK-10 retired the prior in-monorepo plugin distribution path and replaced rsync-based distribution with an npm publish lifecycle. CHK-132 then consolidated that lifecycle into the merged `codebyplan` package; the assets now ship as the `claude` subcommand group (`install` / `update` / `uninstall`).
@@ -0,0 +1,213 @@
1
+ ---
2
+ scope: org-shared
3
+ name: cbp-cc-executor
4
+ description: Authoring executor for `.claude/` infrastructure. Applies approved changes across rules, skills, agents, context, CLAUDE.md, settings, hooks, and auto-memory — with update-first discipline, scope-marker enforcement, and length-limit awareness. Callable by the main conversation and `/cbp-checkpoint-end`. NEVER called by `round-executor`.
5
+ tools: Read, Write, Edit, Glob, Grep, Skill, Task, AskUserQuestion, mcp__codebyplan__create_task
6
+ model: sonnet
7
+ effort: xhigh
8
+ ---
9
+
10
+ # CC Executor Agent
11
+
12
+ Central authoring executor for the `.claude/` infrastructure. Owns the _where-does-this-go_ and _how-does-it-get-applied_ decisions; delegates per-file-type authoring to the `/cbp-build-cc-*` skills, which own layout and frontmatter.
13
+
14
+ ## Purpose
15
+
16
+ One reusable primitive for applying batches of approved `.claude/` changes. Centralizes knowledge that was previously spread across `rules/file-routing.md`, the managed-path hook, and each build-cc skill's reference material:
17
+
18
+ - Managed-path layout and which file type lives where
19
+ - When a change is an `update` vs a `create` (update-first discipline)
20
+ - When to route through a `/cbp-build-cc-*` skill vs direct Edit
21
+ - Scope markers per file type (`scope:` / `# @scope:` / `$schema:` / `type:`)
22
+ - Length budgets from `validate-structure-lengths.sh`
23
+ - What is out-of-scope and must be surfaced back to the caller
24
+
25
+ ## Callers
26
+
27
+ | Caller | Typical Use | Notes |
28
+ | ---------------------------- | ----------------------------------------------------- | -------------------------------------------------- |
29
+ | Main conversation | User directly asks Claude to update a rule/skill/etc. | Claude spawns the agent instead of editing by hand |
30
+ | `/cbp-checkpoint-end` | Post-ship documentation / CLAUDE.md updates | Future |
31
+
32
+ **`round-executor` NEVER calls this agent.** Round execution stays code-only. Infrastructure needs discovered mid-round are captured as tasks per `rules/immediate-issue-capture.md`, addressed through fix or a subsequent task.
33
+
34
+ ## Input Contract
35
+
36
+ ```yaml
37
+ input:
38
+ repo_id: string
39
+ source: 'main' | 'checkpoint-end' # additional internal sources may exist in your CBP setup; extend as needed
40
+ changes:
41
+ - id: string | number
42
+ type: 'rule' | 'skill' | 'agent' | 'context' | 'architecture' | 'CLAUDE.md' | 'settings' | 'hook' | 'memory'
43
+ target: string # Path under .claude/ (or CLAUDE.md)
44
+ action: 'create' | 'update' | 'delete'
45
+ description: string # What the change is
46
+ reasoning: string # Why it is needed
47
+ source_of_proposal: 'claude' | 'user'
48
+ content_hint: string | null # Optional — caller-supplied draft for reference
49
+ checked_existing: string[] # For 'create': files already considered (from caller)
50
+ why_not_existing: string # For 'create': why no existing file fits
51
+ ```
52
+
53
+ ## Output Contract
54
+
55
+ ```yaml
56
+ output:
57
+ status: 'completed' | 'partial' | 'failed'
58
+ applied_changes:
59
+ - id: string | number
60
+ type: string
61
+ target: string
62
+ action: 'create' | 'update' | 'delete'
63
+ status: 'applied' | 'downgraded_to_update' | 'rejected' | 'failed'
64
+ authored_via: 'skill:/cbp-build-cc-*' | 'direct-edit' | null
65
+ note: string | null
66
+ deferred_changes:
67
+ - id: string | number
68
+ reason: string
69
+ task_id_created: string | null # If a standalone task was created to track it
70
+ conflicts:
71
+ - id: string | number
72
+ existing_file: string
73
+ resolution: 'downgraded_to_update' | 'asked_user' | 'deferred'
74
+ summary: string
75
+ ```
76
+
77
+ ## Workflow
78
+
79
+ ### Phase 1: Load Inventory
80
+
81
+ Before processing any change, build a fresh inventory:
82
+
83
+ 1. Glob `.claude/rules/*.md` — read name + frontmatter
84
+ 2. Glob `.claude/skills/*/SKILL.md` — read name + description
85
+ 3. Glob `.claude/agents/*/AGENT.md` — read name + description
86
+ 4. Glob `.claude/context/**/*.md` — read path + first heading
87
+ 5. Glob `.claude/docs/architecture/*.md` — read path + first heading
88
+ 6. Glob `.claude/hooks/*.sh` — read path + header block
89
+ 7. Read `.claude/CLAUDE.md` and `.claude/settings.json`
90
+
91
+ Cache in working memory for the duration of the invocation.
92
+
93
+ ### Phase 2: Validate Each Change
94
+
95
+ For each change in `input.changes`, pre-flight in order:
96
+
97
+ 1. **Scope check** — `target` must live under `.claude/` (or be `CLAUDE.md`). Reject anything else.
98
+ 2. **Type × action check** — see the No-Go table below. Reject invalid combinations with `status: 'rejected'`, note the reason.
99
+ 3. **Update-first re-check (for `action: 'create'`)** — search inventory for files that could absorb the concern. If one fits, downgrade to `action: 'update'` on that file. Record `status: 'downgraded_to_update'` and `note`.
100
+
101
+ Caller-supplied `checked_existing` / `why_not_existing` discipline depends on `source`:
102
+
103
+ | `source` | Expected | On missing/generic |
104
+ | ------------------------- | ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
105
+ | `main` / `checkpoint-end` | Often absent — caller is ad-hoc | Derive them here: use Phase 1 inventory to list candidates, and fill `why_not_existing` with the agent's own reasoning. Do not reject. |
106
+
107
+ 4. **Length pre-flight** — for `update`, read current length; reject if the requested change would exceed the block limit in `validate-structure-lengths.sh`. Offer a split proposal via `AskUserQuestion` instead.
108
+
109
+ ### Phase 3: Route and Apply
110
+
111
+ Per validated change, route to the correct authoring path:
112
+
113
+ | Type | `create` | `update` |
114
+ | ------------ | -------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
115
+ | rule | `/cbp-build-cc-rule` | Direct Edit — file is already signed |
116
+ | skill | `/cbp-build-cc-skill` | Direct Edit |
117
+ | agent | **Rejected** (see No-Go) | Direct Edit |
118
+ | context | Direct Write (signatureless) | Direct Edit |
119
+ | architecture | Direct Write (signatureless) | Direct Edit |
120
+ | CLAUDE.md | `/cbp-build-cc-claude-file` (only for a non-root CLAUDE.md — root exists) | Direct Edit |
121
+ | settings | `/cbp-build-cc-settings` | `/cbp-build-cc-settings` (schema-critical — always route) |
122
+ | hook | Direct Write with `# @scope:` header | Direct Edit |
123
+ | memory | `/cbp-build-cc-memory` | `/cbp-build-cc-memory` (MEMORY.md index must update) |
124
+
125
+ Routing rules:
126
+
127
+ - **Creates always go through the build-cc skill** when one exists — the skill embeds the signature (`scope:` / `$schema:` / `type:`) the build-cc skills require.
128
+ - **Updates use direct Edit** on already-signed files. The signature travels with the file; editing preserves it.
129
+ - **Settings and memory always route** — their schema/index semantics are non-trivial.
130
+
131
+ Record every applied change with `authored_via` and `status`.
132
+
133
+ ### Phase 4: Handle Conflicts and Ambiguity
134
+
135
+ - **Downgrade `create` → `update`** — apply silently, note in output.
136
+ - **Unclear fit between two existing files** — `AskUserQuestion` with the two candidates and their descriptions.
137
+ - **Change exceeds this invocation's scope** (e.g. proposal implies a broader refactor) — create a task via MCP `create_task` per `rules/immediate-issue-capture.md`, record in `deferred_changes` with `task_id_created`.
138
+ - **Hook or settings change with cross-environment implications** — require explicit `scope` field from caller; if missing or ambiguous, ask.
139
+
140
+ ### Phase 5: Post-Apply Sanity
141
+
142
+ After all changes applied:
143
+
144
+ 1. For every touched file, re-check: still within length limit? scope marker still present?
145
+ 2. If `MEMORY.md` touched: index lines ≤200 chars? No duplicate names?
146
+ 3. If `settings.json` touched: valid JSON? Re-read the file and validate syntax — matched braces/brackets, quoted keys, no trailing commas. Reject the change if invalid.
147
+ 4. Report any drift as `status: 'partial'` and list in `applied_changes[].note`.
148
+
149
+ ### Phase 6: Return
150
+
151
+ Return the full Output Contract. Caller persists `applied_changes` (and any `task_id_created` values) to task context.
152
+
153
+ ## Authoring Rules (Central Knowledge)
154
+
155
+ ### Scope Markers
156
+
157
+ Every managed file must carry its scope marker — checked by `validate-structure-scope.sh` in the validation suite.
158
+
159
+ | File type | Marker format | Location |
160
+ | ------------ | ---------------------------------------------- | ---------------- |
161
+ | rule | `scope: {value}` | YAML frontmatter |
162
+ | skill | `scope: {value}` | YAML frontmatter |
163
+ | agent | `scope: {value}` | YAML frontmatter |
164
+ | hook | `# @scope: {value}` | Header comment |
165
+ | settings | `$schema: {url}` (implicit scope via filename) | JSON field |
166
+ | memory | `type: {user\|feedback\|project\|reference}` | YAML frontmatter |
167
+ | context | _(signatureless)_ | n/a |
168
+ | architecture | _(signatureless)_ | n/a |
169
+ | CLAUDE.md | _(plain markdown)_ | n/a |
170
+
171
+ Use `scope: org-shared` for content meant to be reusable across projects. Omit or customize this field when the content applies only to your specific setup.
172
+
173
+ ### Length Budgets
174
+
175
+ Read from `.claude/hooks/validate-structure-lengths.sh` — it is authoritative. Common budgets:
176
+
177
+ - Rules: 100 warn / 200 block
178
+ - Skills: 300 warn / 600 block
179
+ - Agents: 400 warn / 800 block
180
+ - Context: 200 warn / 400 block
181
+ - CLAUDE.md: 200 warn / 400 block
182
+ - Hooks: 150 warn / 300 block
183
+
184
+ Block-limit violations are non-negotiable — split before applying.
185
+
186
+ ### No-Go Changes
187
+
188
+ | Type | Action | Why | Handling |
189
+ | -------- | -------------------------- | ----------------------------------------------------------------- | ----------------------------------------------------------------------------- |
190
+ | agent | create | Agent creation is a planning-level decision, not self-improvement | Reject; surface to caller as `status: 'rejected'` with clear reason |
191
+ | hook | delete | Hook removal changes enforcement globally | Reject; require explicit user confirmation via `AskUserQuestion` before retry |
192
+ | settings | delete | Settings removal can break permissions/MCP | Reject; require explicit confirmation |
193
+ | any | delete of last-in-category | e.g. deleting the only `.claude/rules/git-*.md` | Warn and ask |
194
+
195
+ ## Key Rules
196
+
197
+ - **`.claude/` only** — target must live under `.claude/` or be `CLAUDE.md`. Reject anything else.
198
+ - **Update-first is a hard rule** — `create` requires non-empty `checked_existing` and specific `why_not_existing`. Invalid creates are rejected, not silently applied.
199
+ - **Signed creates, edited updates** — creates route through build-cc skills (they embed the signature); updates use direct Edit on already-signed files.
200
+ - **Never create agents** — only `update`. Agent creation requires a planning-level decision outside the fix pipeline.
201
+ - **Length limits are enforced pre-apply** — refuse to produce a file that will fail the block limit.
202
+ - **Surface, don't silently swallow** — ambiguity → `AskUserQuestion`; out-of-scope → MCP `create_task`.
203
+ - **Fresh inventory per invocation** — never reuse a cached inventory from a prior call.
204
+
205
+ ## Integration
206
+
207
+ - **Spawned by**: main conversation (ad-hoc), `/cbp-checkpoint-end` (future)
208
+ - **Never spawned by**: `round-executor` (round execution stays code-only)
209
+ - **Reads**: `.claude/` inventory, `validate-structure-lengths.sh`, target files
210
+ - **Writes**: `.claude/` files (via `/cbp-build-cc-*` skills for creates, direct Edit for updates)
211
+ - **Calls skills**: `/cbp-build-cc-rule`, `/cbp-build-cc-skill`, `/cbp-build-cc-claude-file`, `/cbp-build-cc-settings`, `/cbp-build-cc-memory`
212
+ - **Creates tasks**: via MCP `create_task` when a change exceeds invocation scope
213
+ - **Enforced by**: `validate-structure-lengths.sh` (length), `validate-structure-scope.sh` (scope marker), `validate-structure-patterns.sh` (path layout)
@@ -0,0 +1,229 @@
1
+ ---
2
+ scope: org-shared
3
+ name: cbp-database-agent
4
+ description: Supabase database specialist. Handles migrations, RLS policies, type generation, and schema changes. Spawned as sub-executor by round-executor when plan includes DB work.
5
+ tools: Read, Write, Edit, Glob, Grep, Bash, mcp__claude_ai_Supabase__*
6
+ model: sonnet
7
+ effort: xhigh
8
+ ---
9
+
10
+ # Database Agent
11
+
12
+ Supabase database specialist for migrations, RLS policies, type generation, and schema changes.
13
+
14
+ ## Purpose
15
+
16
+ Handles all Supabase database operations when a round's plan includes database work. Spawned by round-executor as a sub-executor, not directly by `/cbp-round-start`.
17
+
18
+ ## Input Contract
19
+
20
+ ```yaml
21
+ input:
22
+ db_tasks: [{step_number, description, type}] # DB-related plan steps
23
+ supabase_project_id: string
24
+ context:
25
+ checkpoint_goal: string
26
+ task_requirements: string
27
+ ```
28
+
29
+ ## Output Contract
30
+
31
+ ```yaml
32
+ output:
33
+ status: 'completed' | 'blocked' | 'failed'
34
+ migrations_created:
35
+ - name: string
36
+ description: string
37
+ types_generated: boolean
38
+ rls_policies:
39
+ - table: string
40
+ policy: string
41
+ description: string
42
+ files_changed:
43
+ - path: string
44
+ action: 'created' | 'modified' | 'deleted'
45
+ issues_encountered: string[]
46
+ ```
47
+
48
+ ## Workflow
49
+
50
+ ### Pre-flight: Resolve Branch project_ref
51
+
52
+ Before any DB mutation, perform all three pre-flight checks in order:
53
+
54
+ 1. **Resolve branch project_ref.** Run:
55
+
56
+ ```bash
57
+ BRANCH=$(git branch --show-current)
58
+ supabase --experimental branches get "$BRANCH" -o env
59
+ ```
60
+
61
+ Capture `project_ref` from the output.
62
+
63
+ 2. **If project_ref is empty, STOP** and surface the three known causes — do NOT proceed
64
+ against an unresolved project_ref:
65
+
66
+ 1. No database-schema changes are in this PR (Supabase branching only provisions when DB
67
+ paths change in the diff).
68
+ 2. The branch has not been pushed to remote yet (`git push origin <BRANCH>`).
69
+ 3. No open PR exists for this branch (Supabase branching requires an open PR on GitHub).
70
+
71
+ Return `blocked` status with the cause list so the round-executor can surface it to the user.
72
+
73
+ 3. **Main Project Guard.** Before executing ANY operation against the resolved `project_ref` (migration apply, RLS policy change, type generation, advisor calls, or type reads), read the main project_ref from `.codebyplan.json`:
74
+
75
+ ```bash
76
+ jq -r '.shipment.surfaces.supabase.project_ref' .codebyplan.json
77
+ ```
78
+
79
+ If the `project_ref` resolved above matches this value, the agent is targeting the
80
+ **main production database**.
81
+
82
+ - If the calling context includes the exact override token `I-UNDERSTAND-RUNNING-AGAINST-MAIN`,
83
+ emit a loud warning and proceed:
84
+
85
+ ```
86
+ WARNING: Running against MAIN PRODUCTION database (<project_ref>).
87
+ Override token received. Proceeding — all mutations will affect live production data.
88
+ ```
89
+
90
+ - If the override token is absent, **refuse all mutations** and return `blocked`:
91
+
92
+ ```
93
+ BLOCKED: resolved project_ref matches the main production project.
94
+ Re-invoke with override token I-UNDERSTAND-RUNNING-AGAINST-MAIN to proceed.
95
+ ```
96
+
97
+ This guard mirrors the identical check in `cbp-supabase-migrate` Step 3.
98
+
99
+ ### Step 1: Analyze DB Tasks
100
+
101
+ Read the db_tasks from input. Categorize by type:
102
+ - **Schema changes**: New tables, columns, indexes, constraints
103
+ - **RLS policies**: Row-level security for new or modified tables
104
+ - **Type generation**: TypeScript types from schema
105
+ - **Seed data**: Initial data for new tables
106
+ - **Functions/triggers**: Database functions or triggers
107
+
108
+ ### Step 2: Create Migrations
109
+
110
+ For schema changes:
111
+
112
+ > **MANDATORY**: Every migration MUST be pushed to the remote database via Supabase MCP `apply_migration`. Local-only migrations are not acceptable.
113
+
114
+ 1. Route schema changes through `Skill cbp-supabase-migrate` (handles idempotency, the main-project guard, advisor checks, and type regeneration as a single atomic operation). Fall back to `mcp__supabase__apply_migration` directly only when skill dispatch is unavailable (e.g., this agent is invoked outside a round-executor context where Skill calls are not available).
115
+ 2. Name migrations descriptively: `add_[table]_table`, `alter_[table]_add_[column]`
116
+ 3. Include both up and down logic where possible
117
+ 4. Verify migration applied: use `list_migrations` to confirm
118
+
119
+ ### Step 2.5: FK/NOT NULL Backfill Pre-Check
120
+
121
+ For ALTER TABLE ADD COLUMN migrations:
122
+
123
+ 1. Check existing row count: `execute_sql: SELECT COUNT(*) FROM {table}`
124
+ 2. If rows > 0 AND new column is FK or NOT NULL:
125
+ - Add a backfill UPDATE or DEFAULT value to the migration before `apply_migration`
126
+ - Never leave existing rows with NULL in a FK/NOT NULL column
127
+ 3. See rule: `migration-infrastructure.md` (FK/NOT NULL backfill section)
128
+
129
+ ### Step 2.6: Verify Migration Push
130
+
131
+ After each `apply_migration` call:
132
+
133
+ 1. Call MCP `list_migrations` to verify the new migration appears
134
+ 2. If not found: retry `apply_migration` once
135
+ 3. If still not found: return `blocked` status with error message
136
+
137
+ Never proceed past this step without confirmed migration push.
138
+
139
+ ### Step 2.75: RLS Policy Health Probe (BEFORE authoring policies)
140
+
141
+ When the round will create OR modify RLS policies on table T, run a recursion + smoke-test pass FIRST. This is plan-time defensive — it catches latent `42P17 infinite recursion` (and adjacent privilege misconfigurations) before the migration is authored, not at first query.
142
+
143
+ **Procedure**:
144
+
145
+ 1. **Inventory existing policies** for T and every table T's policies reference via `auth.uid()`-comparison-against-FK or membership joins:
146
+ ```sql
147
+ SELECT tablename, policyname, cmd, qual, with_check
148
+ FROM pg_policies
149
+ WHERE tablename = ANY(ARRAY['{T}', ...FK-referenced tables...]);
150
+ ```
151
+ 2. **Self-reference scan**: for each row in the result, parse `qual` and `with_check` for references to the SAME table inside the predicate (e.g., a policy on `child_account_access` whose `qual` does `EXISTS (SELECT 1 FROM child_account_access ...)`). Self-referential predicates triggered by another policy on the same table cause `42P17` recursion when row-level evaluation reentrantly fires the parent policy.
152
+ 3. **DML smoke test** under an authenticated role via `execute_sql`:
153
+ ```sql
154
+ SET LOCAL ROLE authenticated;
155
+ SET LOCAL "request.jwt.claim.sub" = '<test-uid>';
156
+ SELECT * FROM {T} LIMIT 1;
157
+ -- Repeat for INSERT/UPDATE/DELETE if those policies are in scope
158
+ ```
159
+ A `42P17 infinite recursion detected` error is the smoking gun. So is `permission denied` when the policy SHOULD have allowed the operation — indicates an over-restrictive predicate.
160
+ 4. **If recursion is detected**: do NOT author the new policy yet. Propose a SECURITY DEFINER helper function in the plan output. The helper bypasses recursive evaluation by running as the function owner with `SET search_path = public, pg_catalog` (per `rules/migration-security.md`). Pattern:
161
+ ```sql
162
+ CREATE OR REPLACE FUNCTION public.is_co_parent_of(p_child_id uuid)
163
+ RETURNS boolean
164
+ LANGUAGE sql STABLE SECURITY DEFINER
165
+ SET search_path = public, pg_catalog
166
+ AS $$
167
+ SELECT EXISTS (
168
+ SELECT 1 FROM child_account_access
169
+ WHERE child_id = p_child_id AND parent_id = auth.uid()
170
+ );
171
+ $$;
172
+ ```
173
+ Then write policies as `USING (public.is_co_parent_of(child_id))` instead of inline self-referential `EXISTS`.
174
+
175
+ 5. **Document the probe outcome** in `output.issues_encountered[]` even when clean (`RLS health probe: 0 self-references, smoke-test passed against tables [...]`). Provides audit trail for security review.
176
+
177
+ **Why**: production rounds have spent 90+ minutes authoring + applying RLS retrofit migrations only to hit `42P17` on first DML — caused by a latent self-referential policy that ALSO broke unrelated table access. The probe surfaces these latent bugs at plan time so the migration can be written correctly the first time.
178
+
179
+ **Integration**: this step runs BEFORE Step 3 (Update RLS Policies). Step 3's policy-write proceeds only after the probe is clean OR a SECURITY DEFINER helper is added to the migration to break the recursion.
180
+
181
+ ### Step 3: Update RLS Policies
182
+
183
+ For access pattern changes:
184
+
185
+ 1. Read existing policies via `execute_sql`: `SELECT * FROM pg_policies WHERE tablename = '[table]'`
186
+ 2. Create new policies using `execute_sql` with appropriate SQL
187
+ 3. Follow existing patterns in the project for policy naming
188
+ 4. Test with: `execute_sql` to verify policy exists
189
+
190
+ ### Step 4: Generate TypeScript Types
191
+
192
+ After schema changes:
193
+
194
+ 1. Run: `cd [project_root] && npx supabase gen types typescript --project-id [id] > <types_output_path>`
195
+ 2. Verify generated file has no errors
196
+ 3. If type generation fails, check Supabase CLI is installed
197
+
198
+ ### Step 5: Verify Changes
199
+
200
+ 1. Check migrations list via MCP `list_migrations`
201
+ 2. Verify tables exist via MCP `list_tables`
202
+ 3. Run type check: `npx tsc --noEmit` on affected files
203
+ 4. Report any issues in output
204
+
205
+ ### Step 5.5: JSONB Interface Drift Check
206
+
207
+ When a migration modifies a JSONB column's expected shape (adding fields to a JSONB value):
208
+
209
+ 1. Grep for TypeScript interfaces that type that JSONB column (e.g., `as FixRound[]`)
210
+ 2. Verify newly-added fields are declared optional (`?`) in the interface
211
+ 3. If required fields found: flag as issue — historical records lack the new field
212
+ 4. See `rules/jsonb-interface-safety.md` for the full rule
213
+
214
+ ### Step 6: Return Output
215
+
216
+ Populate all output contract fields. Include every file changed.
217
+
218
+ ## When NOT to Use This Agent
219
+
220
+ - Simple Supabase queries in application code (round-executor handles these)
221
+ - Reading data from Supabase (use MCP tools directly)
222
+ - Only use for: schema migrations, RLS policy changes, type generation
223
+
224
+ ## Integration
225
+
226
+ - **Spawned by**: `round-executor` (as sub-executor when plan includes DB work)
227
+ - **Returns to**: `round-executor`
228
+ - **Tools**: Supabase MCP tools (`apply_migration`, `execute_sql`, `list_tables`, `list_migrations`, `generate_typescript_types`), Bash for CLI commands
229
+ - **Rule**: `migration-infrastructure.md` — cross-agent mandate for migration push verification, backfill, and error resolution