@jeiemgi/cckit 0.1.6

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 (191) hide show
  1. package/.claude-plugin/plugin.json +22 -0
  2. package/AGENTS.md +101 -0
  3. package/LICENSE-APACHE +202 -0
  4. package/LICENSE-MIT +21 -0
  5. package/README.md +143 -0
  6. package/SECURITY.md +22 -0
  7. package/bin/cckit +215 -0
  8. package/cckit.config.json +34 -0
  9. package/commands/kit-add.md +42 -0
  10. package/commands/kit-docs.md +45 -0
  11. package/commands/kit-doctor.md +52 -0
  12. package/commands/kit-export-project.md +58 -0
  13. package/commands/kit-export-training.md +49 -0
  14. package/commands/kit-init.md +126 -0
  15. package/commands/kit-routines.md +59 -0
  16. package/commands/kit-update.md +132 -0
  17. package/docs/kit-annotate/01-explainer.html +225 -0
  18. package/docs/kit-annotate/02-implementation-plan.html +196 -0
  19. package/docs/media/.onboarding-capture.cast +5 -0
  20. package/docs/media/README.md +43 -0
  21. package/docs/media/build-demo.sh +63 -0
  22. package/docs/media/build-kit-init.sh +51 -0
  23. package/docs/media/build-onboarding.sh +51 -0
  24. package/docs/media/kit-dry-run.cast +107 -0
  25. package/docs/media/kit-dry-run.gif +0 -0
  26. package/docs/media/kit-init.cast +56 -0
  27. package/docs/media/kit-init.gif +0 -0
  28. package/docs/media/kit-onboarding.cast +148 -0
  29. package/docs/media/kit-onboarding.gif +0 -0
  30. package/githooks/pre-commit +18 -0
  31. package/kit.config.schema.json +105 -0
  32. package/package.json +54 -0
  33. package/privacy-denylist.example +8 -0
  34. package/profiles/automation.json +36 -0
  35. package/profiles/content.json +41 -0
  36. package/profiles/minimal.json +31 -0
  37. package/profiles/research.json +37 -0
  38. package/profiles/software.json +32 -0
  39. package/scripts/annotate-setup.sh +149 -0
  40. package/scripts/autopilot.sh +50 -0
  41. package/scripts/capture-project-ids.sh +53 -0
  42. package/scripts/check.sh +66 -0
  43. package/scripts/contribute.sh +48 -0
  44. package/scripts/debug.sh +54 -0
  45. package/scripts/init-upgrade-test.sh +99 -0
  46. package/scripts/init.sh +827 -0
  47. package/scripts/install.sh +24 -0
  48. package/scripts/kit-add-test.sh +62 -0
  49. package/scripts/kit-add.sh +115 -0
  50. package/scripts/kit-adopt-test.sh +61 -0
  51. package/scripts/kit-adopt.sh +122 -0
  52. package/scripts/kit-bump-version.sh +79 -0
  53. package/scripts/kit-digest.sh +126 -0
  54. package/scripts/kit-doctor.sh +663 -0
  55. package/scripts/kit-export-project-test.sh +82 -0
  56. package/scripts/kit-export-project.sh +245 -0
  57. package/scripts/kit-export-training-test.sh +51 -0
  58. package/scripts/kit-export-training.sh +175 -0
  59. package/scripts/kit-migrate-test.sh +80 -0
  60. package/scripts/kit-migrate.sh +190 -0
  61. package/scripts/kit-onboard-test.sh +63 -0
  62. package/scripts/kit-onboard.sh +69 -0
  63. package/scripts/kit-promote-test.sh +54 -0
  64. package/scripts/kit-promote.sh +102 -0
  65. package/scripts/kit-remove-test.sh +61 -0
  66. package/scripts/kit-remove.sh +84 -0
  67. package/scripts/kit-routines.sh +322 -0
  68. package/scripts/kit-version-check.sh +91 -0
  69. package/scripts/kit-wire-test.sh +54 -0
  70. package/scripts/kit-wire.sh +132 -0
  71. package/scripts/knowledge-lint.sh +96 -0
  72. package/scripts/lib/cckit-output.sh +36 -0
  73. package/scripts/lib/effort-metrics.sh +452 -0
  74. package/scripts/lib/effort-ops-test.sh +83 -0
  75. package/scripts/lib/effort-ops.sh +132 -0
  76. package/scripts/lib/effort-plan.sh +104 -0
  77. package/scripts/lib/effort.sh +191 -0
  78. package/scripts/lib/engine-adapter.sh +92 -0
  79. package/scripts/lib/gh-log.sh +58 -0
  80. package/scripts/lib/gh-project.sh +212 -0
  81. package/scripts/lib/handoff.sh +35 -0
  82. package/scripts/lib/kit-cli-test.sh +42 -0
  83. package/scripts/lib/kit-cli.sh +32 -0
  84. package/scripts/lib/kit-config-resolve.sh +145 -0
  85. package/scripts/lib/kit-config.sh +88 -0
  86. package/scripts/lib/kit-engine-test.sh +107 -0
  87. package/scripts/lib/kit-events.sh +62 -0
  88. package/scripts/lib/kit-gc.sh +117 -0
  89. package/scripts/lib/kit-interview-test.sh +77 -0
  90. package/scripts/lib/kit-interview.sh +203 -0
  91. package/scripts/lib/kit-local.sh +79 -0
  92. package/scripts/lib/kit-manifest.sh +127 -0
  93. package/scripts/lib/kit-mode-test.sh +49 -0
  94. package/scripts/lib/kit-mode.sh +67 -0
  95. package/scripts/lib/kit-operate.sh +105 -0
  96. package/scripts/lib/kit-profile-test.sh +62 -0
  97. package/scripts/lib/kit-profile.sh +115 -0
  98. package/scripts/lib/kit-task-ops-test.sh +63 -0
  99. package/scripts/lib/kit-task-ops.sh +341 -0
  100. package/scripts/lib/pr-evidence.sh +173 -0
  101. package/scripts/lib/project-scan.sh +16 -0
  102. package/scripts/lib/react-detect.sh +78 -0
  103. package/scripts/lib/role-identity.sh +47 -0
  104. package/scripts/lib/secret-guard.sh +96 -0
  105. package/scripts/lib/toon.sh +35 -0
  106. package/scripts/lib/ui.sh +42 -0
  107. package/scripts/lib/version-bump.sh +59 -0
  108. package/scripts/lib/worktree-issue-test.sh +45 -0
  109. package/scripts/lib/worktree-issue.sh +73 -0
  110. package/scripts/lib/worktree-start.sh +280 -0
  111. package/scripts/orchestrate.sh +160 -0
  112. package/scripts/portable-test.sh +53 -0
  113. package/scripts/publish.sh +94 -0
  114. package/scripts/setup-labels.sh +25 -0
  115. package/scripts/setup-milestones.sh +17 -0
  116. package/scripts/showcase.sh +64 -0
  117. package/scripts/status.sh +44 -0
  118. package/scripts/task-sync.sh +59 -0
  119. package/scripts/test.sh +48 -0
  120. package/scripts/web-install.sh +22 -0
  121. package/skills/kit-annotate/SKILL.md +107 -0
  122. package/skills/kit-autopilot/SKILL.md +108 -0
  123. package/skills/kit-contribute/SKILL.md +134 -0
  124. package/skills/kit-customize/SKILL.md +134 -0
  125. package/skills/kit-dev/SKILL.md +67 -0
  126. package/skills/kit-digest/SKILL.md +41 -0
  127. package/skills/kit-effort-close/SKILL.md +156 -0
  128. package/skills/kit-effort-new/SKILL.md +173 -0
  129. package/skills/kit-effort-pr/SKILL.md +139 -0
  130. package/skills/kit-effort-start/SKILL.md +85 -0
  131. package/skills/kit-gc/SKILL.md +80 -0
  132. package/skills/kit-onboard/SKILL.md +50 -0
  133. package/skills/kit-security-sweep/SKILL.md +57 -0
  134. package/skills/kit-ship/SKILL.md +43 -0
  135. package/skills/kit-task-close/SKILL.md +66 -0
  136. package/skills/kit-task-new/SKILL.md +51 -0
  137. package/skills/kit-task-pr/SKILL.md +43 -0
  138. package/skills/kit-task-pr-auto/SKILL.md +27 -0
  139. package/skills/kit-task-pr-merge/SKILL.md +53 -0
  140. package/skills/kit-task-start/SKILL.md +76 -0
  141. package/skills/kit-task-sync/SKILL.md +37 -0
  142. package/templates/CLAUDE.md.tmpl +106 -0
  143. package/templates/agents/analyst.md +55 -0
  144. package/templates/agents/auto-dev.md +93 -0
  145. package/templates/agents/backend.md +59 -0
  146. package/templates/agents/designer.md +73 -0
  147. package/templates/agents/devops.md +57 -0
  148. package/templates/agents/editor.md +48 -0
  149. package/templates/agents/frontend.md +81 -0
  150. package/templates/agents/generalist.md +46 -0
  151. package/templates/agents/local-delegate.md +70 -0
  152. package/templates/agents/n8n.md +65 -0
  153. package/templates/agents/pm.md +69 -0
  154. package/templates/agents/qa.md +66 -0
  155. package/templates/agents/researcher.md +57 -0
  156. package/templates/agents/security.md +65 -0
  157. package/templates/agents/tech-lead.md +75 -0
  158. package/templates/hooks/guard-base-branch-commit.sh.tmpl +45 -0
  159. package/templates/hooks/kit-local-status.sh.tmpl +34 -0
  160. package/templates/hooks/kit_version_check.sh.tmpl +6 -0
  161. package/templates/hooks/mempal_followup.sh.tmpl +97 -0
  162. package/templates/hooks/mempal_precompact.sh.tmpl +4 -0
  163. package/templates/hooks/mempal_save.sh.tmpl +4 -0
  164. package/templates/hooks/mempal_session_start.sh.tmpl +8 -0
  165. package/templates/hooks/prepush_gate.sh.tmpl +36 -0
  166. package/templates/hooks/repo-hygiene.sh.tmpl +72 -0
  167. package/templates/kit.config.json.tmpl +32 -0
  168. package/templates/knowledge-INDEX.md.tmpl +12 -0
  169. package/templates/lib/kit-sigil.sh.tmpl +124 -0
  170. package/templates/rules/branch-naming.md +104 -0
  171. package/templates/rules/communication-style.md +22 -0
  172. package/templates/rules/delegation-brief.md +40 -0
  173. package/templates/rules/design-routing.md +35 -0
  174. package/templates/rules/effort-model.md +122 -0
  175. package/templates/rules/knowledge-base.md +41 -0
  176. package/templates/rules/mempalace.md +110 -0
  177. package/templates/rules/plan-output-format.md +58 -0
  178. package/templates/rules/react-annotate.md +69 -0
  179. package/templates/rules/risk-tiered-review.md +62 -0
  180. package/templates/rules/skill-gaps.md +48 -0
  181. package/templates/rules/task-management.md +42 -0
  182. package/templates/settings/settings.local.json.tmpl +27 -0
  183. package/templates/skills/NAMESPACED +13 -0
  184. package/templates/skills/copywriting/SKILL.md +252 -0
  185. package/templates/skills/copywriting/references/copy-frameworks.md +344 -0
  186. package/templates/skills/copywriting/references/natural-transitions.md +272 -0
  187. package/templates/skills/feature-build-refine/SKILL.md +367 -0
  188. package/templates/skills/karpathy-guidelines/SKILL.md +69 -0
  189. package/templates/skills/morning-briefing/SKILL.md +46 -0
  190. package/templates/skills/speckit/SKILL.md +239 -0
  191. package/templates/skills/supabase-patterns/SKILL.md +88 -0
@@ -0,0 +1,239 @@
1
+ ---
2
+ name: speckit
3
+ description: Install or identify Spec Kit (Spec-Driven Development) in this project and drive the SDD lifecycle — constitution → specify → clarify → plan → tasks → analyze → implement. Authors the constitution + template overrides from a Stack Interview, wiring the project's build standard as the feature-module override.
4
+ when_to_use: When the user wants spec-driven development, asks to "install spec kit", "set up SDD", mentions /speckit-* commands, or wants a feature built through spec → plan → tasks → implement with review gates. Also when checking whether Spec Kit is already initialized in the repo.
5
+ ---
6
+
7
+ # speckit — Spec Kit setup & SDD lifecycle
8
+
9
+ ## First: identify, don't reinstall
10
+
11
+ Before anything, check whether Spec Kit is already here:
12
+
13
+ ```bash
14
+ ls .specify 2>/dev/null && echo "Spec Kit present" || echo "not initialized"
15
+ specify --version 2>/dev/null || echo "specify CLI not installed"
16
+ cat .specify/init-options.json 2>/dev/null # how it was initialized
17
+ cat .specify/feature.json 2>/dev/null # currently-active feature
18
+ ```
19
+
20
+ - If `.specify/` exists → **do not re-init**. Read `init-options.json` + `integration.json`
21
+ (for the invoke separator) and continue at the lifecycle (§4).
22
+ - If absent → go to Installation (§2), then run the Stack Interview (§7).
23
+
24
+ ## Kit integration (read this project's config + stack)
25
+
26
+ ```bash
27
+ source scripts/lib/kit-config.sh && load_kit_config 2>/dev/null
28
+ # Context file is CLAUDE.md (the kit already maintains it)
29
+ cat package.json 2>/dev/null # detect which stack-gated build skills apply
30
+ ```
31
+
32
+ If a **stack convention skill applies to this project's stack** (e.g. `feature-build-refine` when
33
+ `@refinedev/*` is in `package.json`, or `supabase-patterns` when `@supabase/supabase-js` is), use
34
+ its content as the Spec Kit `feature-module.md` override (§6b) instead of authoring a new one. If
35
+ none match the stack, author the override fresh from the Stack Interview (§7).
36
+
37
+ ---
38
+
39
+ ## 1. What Spec Kit Is
40
+
41
+ Spec Kit is a toolkit for **Spec-Driven Development (SDD)**: you write an executable
42
+ specification first, refine it into a plan and a task list, then let an AI agent implement
43
+ against those artifacts with explicit human review gates between phases.
44
+
45
+ ```
46
+ constitution → specify → clarify → plan → tasks → analyze → (checklist) → implement
47
+ │ │ │ │ │ │ │ │
48
+ project feature resolve design ordered consistency optional execute
49
+ rules spec ambiguity plan tasks audit QA gate tasks
50
+ ```
51
+
52
+ Each step is a slash command / skill (e.g. `/speckit-specify`). Steps write Markdown artifacts
53
+ into a per-feature folder; humans approve at gates; the agent never silently jumps ahead.
54
+
55
+ ## 2. Installation
56
+
57
+ Spec Kit ships as the `specify` CLI (from `github/spec-kit`), a Python package run via `uv`.
58
+
59
+ ```bash
60
+ # One-off (no install) — recommended for init:
61
+ uvx --from git+https://github.com/github/spec-kit.git specify init --here
62
+
63
+ # Or install persistently:
64
+ uv tool install specify-cli --from git+https://github.com/github/spec-kit.git
65
+ specify init --here
66
+ ```
67
+
68
+ `specify init` is interactive. Script it with the answers from the Stack Interview (§7, F):
69
+
70
+ | Option | Typical | Meaning |
71
+ |---|---|---|
72
+ | `ai` | `claude` | Target AI assistant (claude / copilot / gemini) |
73
+ | `integration` | `claude` | Which assistant integration to install commands for |
74
+ | `ai_skills` | `true` | Install the commands as agent skills |
75
+ | `script` | `sh` | Helper scripts use bash (`sh`) not PowerShell (`ps`) |
76
+ | `branch_numbering`| `sequential` | Feature branches `001-`, `002-`, … (alt: `timestamp`) |
77
+ | `context_file` | `CLAUDE.md` | Agent context file the project already uses |
78
+ | `here` | `true` | Initialize into the current directory |
79
+
80
+ Verify: `specify --version` and `ls .specify`.
81
+
82
+ ## 3. What init creates — `.specify/` layout
83
+
84
+ ```
85
+ .specify/
86
+ ├── memory/constitution.md # ★ project's non-negotiable rules (STACK-SPECIFIC — you author)
87
+ ├── templates/
88
+ │ ├── constitution-template.md
89
+ │ ├── spec-template.md
90
+ │ ├── plan-template.md # ★ pre-fill Technical Context with your stack defaults
91
+ │ ├── tasks-template.md
92
+ │ ├── checklist-template.md
93
+ │ └── overrides/ # ★ STACK-SPECIFIC pattern docs the plan/tasks steps cite
94
+ │ ├── api-route.md
95
+ │ ├── integration-test.md
96
+ │ └── feature-module.md # ← use this project's build standard verbatim
97
+ ├── scripts/bash/
98
+ ├── specs/NNN-feature-name/ # one folder per feature (spec.md, plan.md, research.md, data-model.md, tasks.md)
99
+ ├── extensions/ + extensions.yml # optional add-ons (e.g. git auto-commit)
100
+ ├── init-options.json + integration.json + feature.json
101
+ ```
102
+
103
+ **The two files you customize per project:** `memory/constitution.md` and `templates/overrides/*`.
104
+
105
+ ## 4. Command lifecycle
106
+
107
+ Invoked as skills/slash commands; the integration sets the separator (`-` → `/speckit-specify`).
108
+
109
+ | Command | Purpose | Writes |
110
+ |---|---|---|
111
+ | `/speckit-constitution` | Create/update governing rules | `memory/constitution.md` |
112
+ | `/speckit-specify` | NL feature → spec; creates feature branch + folder | `specs/NNN-*/spec.md` |
113
+ | `/speckit-clarify` | Up to 5 targeted questions; encode answers into spec | `spec.md` |
114
+ | `/speckit-plan` | Plan + research + data model; runs Constitution Check gate | `plan.md`, `research.md`, `data-model.md` |
115
+ | `/speckit-tasks` | Ordered, dependency-aware task list | `tasks.md` |
116
+ | `/speckit-analyze` | Non-destructive spec ↔ plan ↔ tasks consistency audit | report only |
117
+ | `/speckit-checklist` | Custom QA checklist | `checklist.md` |
118
+ | `/speckit-implement` | Execute tasks against the codebase | source code |
119
+ | `/speckit-taskstoissues` | Convert tasks into GitHub issues | GitHub issues |
120
+
121
+ **Order:** `constitution` once per project → then per feature
122
+ `specify → clarify → plan → tasks → analyze → implement`. `analyze` is a cheap safety net before `implement`.
123
+
124
+ **Review gates:** `.specify/workflows/speckit/workflow.yml` chains specify→plan→tasks→implement
125
+ with approve/reject gates after spec and after plan. Reject aborts. Keep the human in the loop
126
+ at the two highest-leverage moments.
127
+
128
+ ## 5. Git extension (optional)
129
+
130
+ The git extension (`.specify/extensions.yml`, `auto_execute_hooks: true`) auto-runs git around
131
+ each command: `before_specify` → create the feature branch; `after_*` → commit that step's
132
+ artifacts. Net: every SDD step lands as its own reviewable commit on a per-feature branch.
133
+ Set `enabled: false` / `optional: true` per hook to taste.
134
+
135
+ > Note: this overlaps the kit's own `task-start` / `task-pr` branch flow. Pick one branch
136
+ > authority per project — either Spec Kit's git extension OR the kit's `task-*` skills — and
137
+ > disable the other's branch creation to avoid double-branching.
138
+
139
+ ## 6. The stack-specific layer
140
+
141
+ Only two things change between projects (the constitution + the overrides) — but the build standard
142
+ they encode is only legitimate if the repo actually follows it. A constitution that mandates rules
143
+ the shipped code violates is a broken gate. **Audit conformance first**, then author.
144
+
145
+ ### Conformance audit (run BEFORE 6a–6c — do not skip)
146
+
147
+ The matching stack convention skill (`feature-build-refine`, `supabase-patterns`, …) describes a
148
+ *target* architecture. The repo may already follow it, partially follow it, or use a coherent but
149
+ **different** architecture. Authoring a constitution from the skill without checking is how you end
150
+ up asserting MUST-rules the code breaks on day one.
151
+
152
+ 1. **Map reality.** Inspect the actual structure against the skill's prescriptions — directory
153
+ layout, module boundaries, the canonical form/component/handler patterns, data-access shape, and
154
+ the items from the Stack Interview (§7). Cheap, high-signal probes: `ls src/`, find the feature
155
+ or route folders, grep for the patterns the skill mandates (e.g. `"use server"`, the prescribed
156
+ client paths, shared primitive dirs).
157
+ 2. **Classify drift** per dimension as **conforms / partial / divergent (different architecture)**,
158
+ with a one-line severity. Distinguish "incomplete" (missing pieces of the same pattern) from
159
+ "divergent" (a different, internally-consistent pattern) — they reconcile differently.
160
+ 3. **Decide the reconciliation** — this is the user's call when drift is non-trivial, because it
161
+ changes what the constitution may assert. Offer:
162
+ - **Migrate repo → standard** — refactor the code to the skill; constitution stands as authored.
163
+ - **Amend standard → repo** — rewrite the skill + the constitution principle + `feature-module.md`
164
+ to document the repo's actual architecture as the standard; no code moves.
165
+ - **Hybrid** — adopt the high-value, low-risk parts of the standard, keep the rest; amend the
166
+ constitution to bless what stays.
167
+ 4. **Don't author against reality.** Never write a principle the code violates without either (a) a
168
+ migration plan that makes it true, or (b) amending the principle to match. If the repo conforms,
169
+ say so and proceed to 6a–6c unchanged.
170
+ 5. **On migrate/hybrid, produce a migration plan** — a phased, build-green plan written per the
171
+ `plan-output-format` rule (a file in `docs/plans`), and offer to open tracked issues (`task-new`
172
+ / `gh`) per phase. The constitution then references the plan for the not-yet-true principles.
173
+
174
+ > This audit is also the right reflex at `/kit-init` time: the stack-gated build skills
175
+ > self-activate from `package.json` whether or not Spec Kit is installed, so drift between skill and
176
+ > repo exists the moment the kit is scaffolded — Spec Kit just makes it enforceable.
177
+
178
+ ### 6a. Constitution (`memory/constitution.md`)
179
+ Supreme rule set, semver-versioned with a Sync Impact Report comment. Declares: Core Principles
180
+ (named, declarative, MUST/MUST NOT + rationale), Technology Stack, Domain Model & Business Rules,
181
+ Mandatory code patterns (pointing at overrides), Definition of Done, Governance (precedence +
182
+ amendment). The plan step runs a Constitution Check against these — vague principles = vague gates.
183
+
184
+ ### 6b. Template overrides (`templates/overrides/*.md`)
185
+ Concrete, copy-exactly pattern references the plan/tasks/implement steps cite:
186
+ - `api-route.md` — canonical handler (auth → authz → validate → execute → typed errors)
187
+ - `integration-test.md` — test harness (what's mocked, what hits real infra, cleanup)
188
+ - `feature-module.md` — **use the matching stack convention skill verbatim** (`feature-build-refine`,
189
+ `supabase-patterns`, …) when one applies to the stack; otherwise author from the Stack Interview
190
+
191
+ ### 6c. Pre-fill the plan template
192
+ Edit `templates/plan-template.md` Technical Context with stack defaults and wire the
193
+ Constitution Check checkboxes to the actual Core Principles, so every plan starts correct.
194
+
195
+ ## 7. Stack Interview (run before authoring the constitution + overrides)
196
+
197
+ Skip any question answered by inspecting the repo (`package.json`, lockfiles, config, and
198
+ `.claude/kit.config.json`). Ask the rest:
199
+
200
+ **A. Runtime & framework** — language+version; framework+rendering model; monorepo/single + package manager.
201
+ **B. Data & backend** — database + access layer; auth model + role hierarchy; hard domain invariants / common traps.
202
+ **C. API & boundaries** — API style (REST/server-actions/tRPC/GraphQL); mandatory request sequence; input validation + where types live.
203
+ **D. UI & forms** (skip if backend-only) — component system; styling + tokens; forms + validation lib; i18n locales + default + key location; animation/interaction constraints.
204
+ **E. Testing & quality** — test framework + layers (unit/integration/e2e), mocked vs real; quality gate / Definition of Done.
205
+ **F. Process** — branch naming/numbering; git auto-commit extension + which hooks; AI integration + context file name.
206
+
207
+ Convert answers into: **Core Principles** (B5,B6,C8,D14,E16) · **Technology Stack** (A,B,C9,D) ·
208
+ **Override docs** (C7/C8→`api-route.md`; E15→`integration-test.md`; D10–13→`feature-module.md`,
209
+ or reuse the kit build standard) · **Definition of Done** (E16) · align `init-options.json` /
210
+ `extensions.yml` (F17–19).
211
+
212
+ ## 8. Quick start (new project)
213
+
214
+ ```bash
215
+ uvx --from git+https://github.com/github/spec-kit.git specify init --here --ai claude --script sh
216
+ # run the Stack Interview (§7) AND the conformance audit (§6) — reconcile any drift first
217
+ /speckit-constitution # writes memory/constitution.md (after audit + Stack Interview)
218
+ # then author templates/overrides/*.md (use the build standard for feature-module.md) + pre-fill plan-template.md
219
+ /speckit-specify "Add per-user API tokens with rotation"
220
+ /speckit-clarify
221
+ /speckit-plan
222
+ /speckit-tasks
223
+ /speckit-analyze
224
+ /speckit-implement
225
+ ```
226
+
227
+ ## 9. Conventions & rules
228
+
229
+ - **Audit before you author.** Never write a constitution principle the repo's code violates
230
+ (§6 Conformance audit). Reconcile drift first — migrate, amend, or hybrid — then author.
231
+ - **Constitution is supreme.** On conflict: constitution → domain docs → build standard. Amend
232
+ (version bump + Sync Impact Report) rather than working around it.
233
+ - **One feature = one folder = one branch.** `specs/NNN-feature-name/` + matching branch.
234
+ - **Don't skip gates.** Approve the spec before planning, the plan before tasking.
235
+ - **Overrides are copy-exactly.** They reproduce the *one* correct pattern, not a variant.
236
+ - **Run `/speckit-analyze` before `/speckit-implement`** on anything non-trivial.
237
+ - **Keep `init-options.json`, `integration.json`, `extensions.yml` accurate** — source of truth
238
+ for how commands are invoked and what fires around them.
239
+ - **Stack changes live in two places only** — the constitution and the overrides.
@@ -0,0 +1,88 @@
1
+ ---
2
+ name: supabase-patterns
3
+ description: Supabase access conventions for any project on Supabase (Postgres + Auth + RLS) — the three-client model, the server-action auth/authz guard, RLS-first data access, typed queries, and error handling. Self-gating.
4
+ when_to_use: "STACK-GATED. Use when reading/writing data, auth, or storage AND the project uses Supabase — detect by checking package.json for @supabase/supabase-js (or @supabase/ssr). If Supabase is NOT in package.json, this skill does NOT apply — ignore it. Framework-agnostic: applies with or without RefineDev."
5
+ ---
6
+
7
+ # Supabase patterns
8
+
9
+ > **Applicability check first.** Read `package.json`. If there is no `@supabase/supabase-js`
10
+ > (or `@supabase/ssr`), STOP — this skill does not apply. Otherwise follow it.
11
+
12
+ ## 1. Three clients, by execution context — never mix them up
13
+
14
+ | Client | Import | Use in | Auth |
15
+ |---|---|---|---|
16
+ | Browser | `@/lib/supabase/client` (`createClient`) | client components | anon key, user session via cookies |
17
+ | Server | `@/lib/supabase/server` (`createClient`, async) | server components, route handlers, **server actions** | anon key, user session from cookies |
18
+ | Admin | `@/lib/supabase/admin` (`createAdminClient`) | privileged server-only ops | **service-role key — bypasses RLS** |
19
+
20
+ - The **server** client is `async` (it awaits cookies). Always `const supabase = await createClient()`.
21
+ - The **admin** client bypasses RLS — use it only for deliberate privileged operations (user
22
+ provisioning, cross-tenant jobs), never as a convenience to dodge a policy. Never import it into
23
+ client code; the service-role key must never reach the browser bundle.
24
+
25
+ ## 2. RLS is the security boundary — not the app code
26
+
27
+ - Every table has **Row Level Security enabled** with explicit policies. The app assumes RLS is on.
28
+ - Do **not** rely on client-side filtering for authorization — a missing/`USING (true)` policy is a
29
+ vulnerability even if the UI hides the row.
30
+ - App-level role checks (below) are defense-in-depth **on top of** RLS, not a replacement.
31
+
32
+ ## 3. Server-action auth/authz guard — one shared guard per file
33
+
34
+ Every mutating server action authenticates and authorizes before touching data:
35
+
36
+ ```typescript
37
+ "use server";
38
+ import { createClient } from "@/lib/supabase/server";
39
+
40
+ async function requireRole(/* allowed roles */) {
41
+ const supabase = await createClient();
42
+ const { data: { user } } = await supabase.auth.getUser(); // getUser(), NOT getSession() server-side
43
+ if (!user) throw new Error("No autorizado");
44
+ // role check via the profiles table; throw on insufficient role
45
+ return { supabase, userId: user.id };
46
+ }
47
+
48
+ export async function createThingAction(input: CreateThingInput): Promise<{ id: string }> {
49
+ const { supabase } = await requireRole();
50
+ const { data, error } = await supabase.from("things").insert(input).select("id").single();
51
+ if (error) throw error; // surface Postgres/RLS errors, never swallow
52
+ return { id: data.id };
53
+ }
54
+ ```
55
+
56
+ - Use `supabase.auth.getUser()` on the server (it revalidates the token), not `getSession()`.
57
+ - Validate input with your schema layer (Zod/etc.) **before** the insert — don't trust the client.
58
+
59
+ ## 4. Typed queries
60
+
61
+ - Generate DB types: `supabase gen types typescript` → `src/lib/supabase/database.types.ts`, and
62
+ type the clients with `createClient<Database>()`. Don't hand-write row types that drift from schema.
63
+ - Select only the columns you need (`.select("id, name")`), and use `.single()` / `.maybeSingle()`
64
+ deliberately — `.single()` throws on 0 or >1 rows.
65
+
66
+ ## 5. Errors & edge cases
67
+
68
+ - Always destructure `{ data, error }` and handle `error` — never assume success.
69
+ - Map Postgres error codes to user-facing messages at the boundary (e.g. `23505` unique violation),
70
+ through `t()` if the project is localized. Don't leak raw DB errors to the UI.
71
+ - Storage: signed URLs for private buckets; never expose the service-role key to generate them client-side.
72
+
73
+ ## 6. Secrets
74
+
75
+ - `NEXT_PUBLIC_SUPABASE_URL` + `NEXT_PUBLIC_SUPABASE_ANON_KEY` are public (anon, RLS-guarded).
76
+ - `SUPABASE_SERVICE_ROLE_KEY` is server-only — never `NEXT_PUBLIC_`, never committed, never in client code.
77
+
78
+ ## 7. Migrations — local-first discipline
79
+
80
+ - **Local-first.** All DDL lands in `supabase/migrations/`; apply + validate locally. Never push DDL straight to prod.
81
+ - **Validate the whole chain before a PR:** `supabase db reset` replays every migration + seed from scratch. A green reset is the gate to open the PR.
82
+ - **Group a coupled chain into ONE PR/issue.** Don't fragment a sequenced migration set into a PR-per-file. Split only for genuinely independent migrations or a step needing its own review gate (data backfill, RLS behavior change). A single PR also has no siblings to silently revert.
83
+ - **Enum `ADD VALUE` is forward-only** and can't run in the same transaction that uses the new label — isolate it as its own earlier migration.
84
+ - **Type regen is deliberate, not automatic.** `supabase gen types` may target a *remote* project (check the script) — running it blindly can hit prod or emit types from a stale schema. Regenerate after the chain applies, type-check, then commit the generated file (last / its own PR).
85
+ - **Human-gate DDL merges** — review the SQL; don't auto-merge agent-authored migrations.
86
+
87
+ > If this project also uses RefineDev, the `feature-build-refine` skill covers feature/form/page
88
+ > architecture; this skill covers the Supabase data boundary. They compose.