create-ccc-tutor 0.1.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 (106) hide show
  1. package/README.md +41 -0
  2. package/bin/cli.js +76 -0
  3. package/package.json +28 -0
  4. package/template/.claude/commands/abandon.md +7 -0
  5. package/template/.claude/commands/add-anti-flag.md +7 -0
  6. package/template/.claude/commands/add-constitution-clause.md +7 -0
  7. package/template/.claude/commands/audit-spec.md +7 -0
  8. package/template/.claude/commands/commit.md +7 -0
  9. package/template/.claude/commands/constitution-edit.md +7 -0
  10. package/template/.claude/commands/db-schema.md +7 -0
  11. package/template/.claude/commands/exam.md +66 -0
  12. package/template/.claude/commands/execution-plan.md +7 -0
  13. package/template/.claude/commands/feature-draft.md +7 -0
  14. package/template/.claude/commands/handoff.md +7 -0
  15. package/template/.claude/commands/implement.md +7 -0
  16. package/template/.claude/commands/init.md +7 -0
  17. package/template/.claude/commands/next.md +7 -0
  18. package/template/.claude/commands/offload.md +7 -0
  19. package/template/.claude/commands/pickup.md +7 -0
  20. package/template/.claude/commands/recall.md +7 -0
  21. package/template/.claude/commands/remember.md +7 -0
  22. package/template/.claude/commands/slide.md +87 -0
  23. package/template/.claude/commands/spec-finalize.md +7 -0
  24. package/template/.claude/commands/test-fix.md +7 -0
  25. package/template/.claude/commands/uninstall.md +7 -0
  26. package/template/.claude/settings.json +161 -0
  27. package/template/.claude-plugin/plugin.json +41 -0
  28. package/template/.codex/config.toml +24 -0
  29. package/template/.codex/hooks.json +4 -0
  30. package/template/.codex/install-skills.sh +18 -0
  31. package/template/.codex/skills/exam/SKILL.md +61 -0
  32. package/template/.codex/skills/slide/SKILL.md +69 -0
  33. package/template/.harness/agents/README.md +70 -0
  34. package/template/.harness/agents/_template/junior-agent-template.md +116 -0
  35. package/template/.harness/agents/backend-reviewer.md +153 -0
  36. package/template/.harness/agents/frontend-reviewer.md +158 -0
  37. package/template/.harness/agents/security-reviewer.md +148 -0
  38. package/template/.harness/agents/test-fixer.md +147 -0
  39. package/template/.harness/docs/doc-sync.md +29 -0
  40. package/template/.harness/docs/git-hygiene.md +56 -0
  41. package/template/.harness/docs/spec-model.md +47 -0
  42. package/template/.harness/docs/tool-map.md +120 -0
  43. package/template/.harness/docs/workflow.md +59 -0
  44. package/template/.harness/scripts/README.md +70 -0
  45. package/template/.harness/scripts/auditor-gate.sh +388 -0
  46. package/template/.harness/scripts/bootstrap-check.sh +103 -0
  47. package/template/.harness/scripts/budget-monitor.sh +223 -0
  48. package/template/.harness/scripts/check-prereqs.sh +165 -0
  49. package/template/.harness/scripts/checkpoint-recall.sh +136 -0
  50. package/template/.harness/scripts/checkpoint-write.sh +281 -0
  51. package/template/.harness/scripts/decision-log-append.sh +90 -0
  52. package/template/.harness/scripts/env-check.sh +286 -0
  53. package/template/.harness/scripts/format-edit.sh +80 -0
  54. package/template/.harness/scripts/lint-bans.sh +110 -0
  55. package/template/.harness/scripts/memory-archive.sh +129 -0
  56. package/template/.harness/scripts/memory-recall.sh +197 -0
  57. package/template/.harness/scripts/memory-snapshot.sh +124 -0
  58. package/template/.harness/scripts/post-migration.sh +58 -0
  59. package/template/.harness/scripts/precommit-cycles.sh +74 -0
  60. package/template/.harness/scripts/precommit-typecheck.sh +69 -0
  61. package/template/.harness/scripts/scratchpad-recall.sh +83 -0
  62. package/template/.harness/scripts/scratchpad-update.sh +39 -0
  63. package/template/.harness/scripts/standalone-bootstrap.md +443 -0
  64. package/template/.harness/skills/abandon/SKILL.md +157 -0
  65. package/template/.harness/skills/add-anti-flag/SKILL.md +205 -0
  66. package/template/.harness/skills/add-constitution-clause/SKILL.md +244 -0
  67. package/template/.harness/skills/audit-spec/SKILL.md +395 -0
  68. package/template/.harness/skills/commit/SKILL.md +270 -0
  69. package/template/.harness/skills/constitution-edit/SKILL.md +292 -0
  70. package/template/.harness/skills/db-schema/SKILL.md +145 -0
  71. package/template/.harness/skills/db-schema/references/methodology.md +202 -0
  72. package/template/.harness/skills/execution-plan/SKILL.md +346 -0
  73. package/template/.harness/skills/feature-draft/SKILL.md +426 -0
  74. package/template/.harness/skills/handoff/SKILL.md +211 -0
  75. package/template/.harness/skills/implement/SKILL.md +355 -0
  76. package/template/.harness/skills/init/SKILL.md +805 -0
  77. package/template/.harness/skills/next/SKILL.md +245 -0
  78. package/template/.harness/skills/offload/SKILL.md +134 -0
  79. package/template/.harness/skills/pickup/SKILL.md +213 -0
  80. package/template/.harness/skills/recall/SKILL.md +159 -0
  81. package/template/.harness/skills/remember/SKILL.md +205 -0
  82. package/template/.harness/skills/spec-finalize/SKILL.md +196 -0
  83. package/template/.harness/skills/test-fix/SKILL.md +363 -0
  84. package/template/.harness/skills/uninstall/SKILL.md +370 -0
  85. package/template/.harness/state/install.json +83 -0
  86. package/template/AGENTS.md +262 -0
  87. package/template/CCC_MAGI_LICENSE +201 -0
  88. package/template/CCC_MAGI_README.md +986 -0
  89. package/template/CLAUDE.md +658 -0
  90. package/template/codex.md +39 -0
  91. package/template/constitution.md +164 -0
  92. package/template/course/README.md +15 -0
  93. package/template/course/course_code(example)/exam/README.md +2 -0
  94. package/template/course/course_code(example)/slide/slide_example-1.pdf +40 -0
  95. package/template/course/course_code(example)/slide/slide_example-2.pdf +40 -0
  96. package/template/docs/features/slide-query-implementation.md +79 -0
  97. package/template/docs/features/slide-query.md +211 -0
  98. package/template/docs-harness/README.md +42 -0
  99. package/template/docs-harness/adoption-playbook.md +373 -0
  100. package/template/docs-harness/ccc-step1-driver-template.md +288 -0
  101. package/template/docs-harness/cli-configs-README.md +78 -0
  102. package/template/docs-harness/context-architecture-v2.md +249 -0
  103. package/template/docs-harness/design-spec.md +437 -0
  104. package/template/docs-harness/memory-layer.md +135 -0
  105. package/template/docs-harness/retrospective-notes.md +204 -0
  106. package/template/gitignore +106 -0
@@ -0,0 +1,292 @@
1
+ ---
2
+ name: constitution-edit
3
+ description: Edit the project constitution.md and update its Sync Impact Report. Use when the user wants to add, modify, or remove a principle in Section 2 (Project Identity), Section 3 (Project Red Lines), or the slot registry. CANNOT modify Section 1 (Universal Core) — those are harness-guaranteed invariants that no edit can remove. Generates a versioned Sync Impact Report at the top of constitution.md. Trigger when the user invokes /constitution-edit, says "edit the constitution", "add a red line", "update project identity", or similar intent.
4
+ allowed-tools: Read, Edit, Bash(date:*), Bash(grep:*), Bash(git diff:*), Bash(git status:*)
5
+ argument-hint: <description of the change>
6
+ ---
7
+
8
+ # /constitution-edit
9
+
10
+ Edit `constitution.md` Section 2 (Project Identity), Section 3 (Project Red Lines), or the slot registry, and prepend a versioned Sync Impact Report HTML comment that documents the change.
11
+
12
+ > *Spec-Kit-pattern audit trail. The Sync Impact Report turns ad-hoc constitution edits into versioned, semver-bumped, auditable changes — without burdening the file with full history (that's what `git log` is for).*
13
+
14
+ ## Language Awareness
15
+
16
+ This skill's instructions are in English. When you talk to the user (proposing the change, asking for confirmations, summarizing results), use the user's OS locale language. See `CLAUDE.md § Language Awareness`. The text written INTO `constitution.md` stays verbatim per what the user approves; do not translate user-entered content.
17
+
18
+ ## What this skill produces
19
+
20
+ A modified `constitution.md` with:
21
+
22
+ 1. The approved edit applied to Section 2, Section 3, or the slot registry.
23
+ 2. A Sync Impact Report HTML comment prepended at the top of the file, immediately after the title heading and before the existing file-description comment. Format:
24
+
25
+ ```html
26
+ <!-- Sync Impact Report
27
+ Version: <old> → <new> (<MAJOR|MINOR|PATCH> — <short description>)
28
+ Modified items:
29
+ - <section name> — <what changed>
30
+ - <section name> — <what changed>
31
+ Templates needing update:
32
+ - <file path> — <status: ✅ updated / ⚠ pending review / N/A>
33
+ Generated: <ISO 8601 UTC timestamp>
34
+ -->
35
+ ```
36
+
37
+ Only one Sync Impact Report block lives in the file at a time — the most recent one. Prior versions live in `git log`.
38
+
39
+ ## Semver rules
40
+
41
+ - **MAJOR** — removes or substantively changes a principle that was already in Section 2 / Section 3 / slot registry
42
+ - **MINOR** — adds a new principle to Section 2 / Section 3, or adds a new slot to the registry
43
+ - **PATCH** — wording / clarification / typo / non-semantic refactor
44
+
45
+ If multiple changes apply in one `/constitution-edit` invocation, take the highest applicable bump.
46
+
47
+ If no prior Sync Impact Report block exists in `constitution.md`, treat the current state as version `1.0.0`.
48
+
49
+ ---
50
+
51
+ ## Step 0 — Pre-flight
52
+
53
+ 1. Verify `constitution.md` exists at project root:
54
+
55
+ ```bash
56
+ test -f constitution.md
57
+ ```
58
+
59
+ If missing, fail with the message:
60
+
61
+ ```
62
+ constitution.md not found — run /init first.
63
+ ```
64
+
65
+ Halt the skill.
66
+
67
+ 2. Read `constitution.md` fully (Read tool).
68
+
69
+ 3. Extract the current version from any existing Sync Impact Report block at the top:
70
+
71
+ ```bash
72
+ grep -m1 -oE 'Version: [0-9]+\.[0-9]+\.[0-9]+ →' constitution.md
73
+ ```
74
+
75
+ If no Sync Impact Report block exists, treat the current state as `1.0.0`.
76
+
77
+ ---
78
+
79
+ ## Step 1 — Understand the change
80
+
81
+ 1. Parse `$ARGUMENTS` as the change description (free text from the user).
82
+
83
+ 2. If `$ARGUMENTS` is empty, ask the user:
84
+
85
+ ```
86
+ What do you want to change in the constitution? Examples:
87
+ - "add a red line about no third-party trackers"
88
+ - "reword the audience to mention enterprises"
89
+ - "add a slot for retry-policy"
90
+ ```
91
+
92
+ **Wait for user response before continuing.**
93
+
94
+ 3. Identify which section(s) the change will affect:
95
+
96
+ - **Section 1 (Universal Core)** → REJECT with the message below and halt:
97
+
98
+ ```
99
+ /constitution-edit cannot modify Section 1 (Universal Core). These are harness-guaranteed invariants that no project edit can remove. If you want to ADD a new project-level red line, use Section 3 instead.
100
+
101
+ If you genuinely need a constitutional change at the harness level, modify outcome/constitution.md directly in the harness source — but understand that doing so changes the harness itself, not your project.
102
+ ```
103
+
104
+ - **Section 2 (Project Identity)** → proceed
105
+ - **Section 3 (Project Red Lines)** → proceed
106
+ - **Slot registry** (the HTML comment block at the top of `constitution.md`) → proceed
107
+
108
+ ---
109
+
110
+ ## Step 2 — Propose the edit
111
+
112
+ 1. Based on the change description, propose the EXACT text to add / modify / remove.
113
+
114
+ 2. Format the proposal as a diff-style preview, in the user's locale:
115
+
116
+ ```
117
+ Proposed change to <section>:
118
+
119
+ <diff-style preview: -old / +new>
120
+
121
+ Type:
122
+ [a] approve as proposed
123
+ [b] modify (tell me what to change)
124
+ [c] cancel
125
+ ```
126
+
127
+ 3. **Wait for user response before continuing.**
128
+
129
+ - `[a]` → proceed to Step 3
130
+ - `[b]` → accept the user's revisions; re-show the proposal; loop until `[a]` or `[c]`
131
+ - `[c]` → abort silently; write nothing
132
+
133
+ ---
134
+
135
+ ## Step 3 — Determine semver bump
136
+
137
+ Auto-detect the bump type from the approved change:
138
+
139
+ | Change shape | Proposed bump |
140
+ |--------------|---------------|
141
+ | Adding new content (new principle / new slot) | MINOR |
142
+ | Removing existing content | MAJOR |
143
+ | Substantively rewording existing content (meaning changes) | MAJOR |
144
+ | Typo / clarification / non-semantic rewording | PATCH |
145
+
146
+ Show to the user:
147
+
148
+ ```
149
+ Bump type: <type>. Override?
150
+ [Enter] accept
151
+ [m] major
152
+ [n] minor
153
+ [p] patch
154
+ ```
155
+
156
+ **Wait for user response before continuing.**
157
+
158
+ Compute the new version from the old one (`X.Y.Z`):
159
+
160
+ - MAJOR → `(X+1).0.0`
161
+ - MINOR → `X.(Y+1).0`
162
+ - PATCH → `X.Y.(Z+1)`
163
+
164
+ ---
165
+
166
+ ## Step 4 — Apply the edit
167
+
168
+ Use the Edit tool to apply the approved change from Step 2 to `constitution.md`. This is the content edit only; the Sync Impact Report block is prepended later in Step 7.
169
+
170
+ ---
171
+
172
+ ## Step 5 — Detect affected templates
173
+
174
+ For each affected slot or principle, identify downstream files that may need review:
175
+
176
+ 1. **If a slot was added or changed**: search for `{{<slot_name>}}` references across the running scope (the harness installation root — typically the project root containing `constitution.md`, `CLAUDE.md`, `AGENTS.md`, and `.harness/`):
177
+
178
+ ```bash
179
+ grep -rln "{{<slot_name>}}" .
180
+ ```
181
+
182
+ Capture matching file paths.
183
+
184
+ 2. **If a Section 2 or Section 3 principle was added**: identify SKILL.md files that consume constitution rules. Heuristic — any SKILL.md referencing `constitution.md` in its body:
185
+
186
+ ```bash
187
+ grep -rln "constitution.md" .harness/skills/ 2>/dev/null
188
+ ```
189
+
190
+ Mark them as needing review.
191
+
192
+ If no affected templates can be confidently identified, list:
193
+
194
+ ```
195
+ (none detected — review SKILL.md files manually if change is structural)
196
+ ```
197
+
198
+ ---
199
+
200
+ ## Step 6 — Generate Sync Impact Report block
201
+
202
+ Build the report block. Use `date -u +%Y-%m-%dT%H:%M:%SZ` for the timestamp:
203
+
204
+ ```html
205
+ <!-- Sync Impact Report
206
+ Version: <old> → <new> (<bump> — <one-line description>)
207
+ Modified items:
208
+ - <section> — <what changed>
209
+ Templates needing update:
210
+ - <file path> — <status>
211
+ Generated: <ISO 8601 UTC timestamp>
212
+ -->
213
+ ```
214
+
215
+ Status values for "Templates needing update":
216
+
217
+ - `✅ updated` — only used if the skill itself edited the template (this skill does NOT auto-edit templates; reserved for future use)
218
+ - `⚠ pending review` — default for any detected template
219
+ - `N/A` — no templates affected
220
+
221
+ ---
222
+
223
+ ## Step 7 — Prepend to constitution.md
224
+
225
+ 1. If an existing Sync Impact Report block already lives at the top of `constitution.md` (immediately after the title heading), **REPLACE** it with the new block. Do not preserve historic blocks in the file — `git log` is the audit trail.
226
+
227
+ 2. Otherwise, **INSERT** the new block immediately after the title line (`# <project> — Constitution`) and before the next content (typically the existing file-description HTML comment).
228
+
229
+ Use the Edit tool. After writing, read back and show the top 30 lines of `constitution.md` to the user for visual confirmation.
230
+
231
+ ---
232
+
233
+ ## Step 8 — Wrap up
234
+
235
+ Display to the user (in their locale):
236
+
237
+ ```
238
+ ✓ Constitution updated to version <new>.
239
+
240
+ Sync Impact Report prepended to constitution.md.
241
+
242
+ Affected templates (if any) marked ⚠ pending review:
243
+ - <file1>
244
+ - <file2>
245
+
246
+ Next steps:
247
+ 1. Review and update marked templates as needed.
248
+ 2. Commit when ready (use /commit).
249
+ ```
250
+
251
+ If no templates were detected, omit the "Affected templates" list and replace with:
252
+
253
+ ```
254
+ No downstream templates detected as affected.
255
+ ```
256
+
257
+ ---
258
+
259
+ ## Rules / Anti-patterns
260
+
261
+ - **Never edit Section 1 (Universal Core)** — reject at Step 1 with the explicit message.
262
+ - **Never auto-edit downstream templates** — only mark them ⚠ for human review. Auto-modification risks silent corruption.
263
+ - **Never skip the user confirmation at Step 2** — the proposed edit must be approved before it lands.
264
+ - **Never preserve historic Sync Impact Report blocks** in `constitution.md` — exactly one block always; `git log` carries the history.
265
+ - **Never run `git commit` or `git push` from this skill** — edits land as working-tree changes. The user commits via `/commit` when ready.
266
+ - **Never translate user-entered constitution content** — write verbatim what the user approved at Step 2.
267
+
268
+ ---
269
+
270
+ ## Trust contract
271
+
272
+ - This skill modifies **exactly one file**: `constitution.md`.
273
+ - It never reads, modifies, or deletes any other project file (it MAY read SKILL.md files in Step 5 detection, but does not write to them).
274
+ - Section 1 of `constitution.md` is treated as read-only by this skill.
275
+ - If the user cancels at Step 2, nothing is written.
276
+ - The Sync Impact Report is always prepended fresh — only one block at a time in the file.
277
+
278
+ ---
279
+
280
+ ## Completion criteria
281
+
282
+ `/constitution-edit` is complete when:
283
+
284
+ - Step 0 has run (pre-flight checks pass)
285
+ - Step 1 has run (change identified and section confirmed; Section 1 attempts rejected)
286
+ - Step 2 has been approved by the user (or cancelled — in which case nothing else runs)
287
+ - Step 3 has determined the new semver version
288
+ - Step 4 has applied the content edit
289
+ - Step 5 has detected affected templates (or determined none)
290
+ - Step 6 has built the Sync Impact Report block
291
+ - Step 7 has prepended the block to `constitution.md` and shown the result to the user
292
+ - Step 8 has displayed the wrap-up message
@@ -0,0 +1,145 @@
1
+ ---
2
+ name: db-schema
3
+ description: This skill should be used whenever the project's database schema is being designed, extended, or reviewed. The skill drives stage 3 of the feature workflow and pairs with the project's backend rule doc (referenced via {{rule_sources}}) and the detailed methodology in references/methodology.md. Trigger when the user invokes /db-schema, says "design the schema", "plan the database changes", when a feature spec introduces new data requirements, when writing or reviewing any file under the project's migration directory, when evaluating whether to add a column or create a new table, when designing access-control policies, or when deciding on indexes.
4
+ argument-hint: [feature-name]
5
+ optional: true
6
+ requires: backend_db_type
7
+ ---
8
+
9
+ # /db-schema
10
+
11
+ Drive stage 3 of the feature workflow: assess the current database schema, design the delta for the feature, and produce a migration.
12
+
13
+ > **⟦OPTIONAL PLUGIN⟧** This skill is **only loaded when `backend_db_type` is configured** (i.e., the project has a relational data layer the harness manages). If the project has no backend, no managed database, or uses a NoSQL store where `/db-schema` does not apply, the harness should skip this stage entirely and `/spec-finalize` should route directly to `/execution-plan`. /init confirms this at setup.
14
+
15
+ > **Backend dialect note:** the methodology and examples below default to relational SQL with Postgres-flavored syntax. Adapt the SQL primitives (RLS expressions, type names, UUID generation) to your backend per the slots: `{{rls_auth_function}}`, your DB's timezone-aware timestamp type, your UUID primitive. If your backend's access-control model differs fundamentally (NoSQL document permissions, mesh authz, etc.), the discipline still applies but the syntax does not — adapt the methodology, keep the process.
16
+
17
+ ## Invocation
18
+
19
+ - Typical: `/db-schema <feature-name>` (e.g., `/db-schema messaging`)
20
+ - The feature name is passed as `$ARGUMENTS` and identifies the spec file at `{{spec_dir}}$ARGUMENTS.md`.
21
+
22
+ ## Authoritative sources
23
+
24
+ Before doing anything, load:
25
+
26
+ 1. **The project's backend rule doc** — referenced from `{{rule_sources}}` (project-specific hard rules: RLS enabled by default, the `{{rls_auth_function}}` pattern for the project's backend, forward-only migrations, secrets handling, PII flagging, search-index sync, type regeneration, etc.)
27
+ 2. **`references/methodology.md`** (in this skill directory) — the full 12-step design process
28
+ 3. **`{{spec_dir}}$ARGUMENTS.md`** — the **CEO spec** (Stage 2 artifact, plain language)
29
+ 4. **`{{implementation_dir}}$ARGUMENTS-implementation.md`** — the **implementation notes** (Stage 1/2 artifact, manager domain), if it exists. May contain explicit data-shape decisions; read it but don't take it as canonical — the CEO spec is canonical.
30
+
31
+ The CEO spec drives the data requirements (every persistent entity, access pattern, retention rule). The implementation notes file may contain prior tech decisions; treat them as input, not gospel.
32
+
33
+ ## Workflow for this stage
34
+
35
+ 1. **Survey existing schema** (read-only) — read every file under `{{migration_dir}}`, then the project's typed-DB-bindings file (if any), then query the live DB via the configured backend MCP / database client to confirm migrations and types are in sync. If drift is found, stop and report to the user before proceeding.
36
+
37
+ 2. **Read the feature spec** — extract every data requirement (entities, relationships, access patterns, retention, search/indexing).
38
+
39
+ 3. **Compute the delta** — for each data requirement, decide: reuse existing / add column / add index / new table / modify access-control policy / add access-control policy. Follow the decision table in `references/methodology.md` § 3.
40
+
41
+ 4. **Design per methodology** — follow steps 4–10 in `references/methodology.md`: new tables, indexes, access-control policies, storage, triggers, search-index sync (if applicable), PII flagging.
42
+
43
+ 5. **Present the proposal to the user** — tables to add, columns, indexes, access-control policies, PII comments. Wait for discussion and approval before writing files. **Wait for user response before continuing.**
44
+
45
+ 6. **On approval, write the migration file** — `{{migration_dir}}<timestamp>_$ARGUMENTS.<ext>` using the project's migration generator. Follow the file structure in `references/methodology.md` § 11.
46
+
47
+ 7. **Invoke backend reviewer agent** to review the migration before it is committed. The reviewer is a **mechanical rule reviewer** — it cites rules from the project's backend rule doc (in `{{rule_sources}}`) and `references/methodology.md`. Judgment about whether the migration is _good_ belongs to the auditor in step 9.
48
+
49
+ 8. **Invoke security/privacy reviewer agent** to review the migration. **Mandatory for every migration** — invocation is not conditional on the writer's self-assessment of whether PII / auth / access-control is touched. Self-assessment is a bias source; mechanical invocation removes it. On a migration that does not touch its scope, the reviewer will return `PASS` quickly; that is the cost of removing the bias.
50
+
51
+ 9. **Auditor cross-model review (judgment layer).** After both junior reviewers return `PASS` (or `CONCERNS`, which advances with a warning), invoke the gate with the adversarial preset. The preset wraps the focus text below with skeptical-review framing and a code-shaped attack surface (auth, data loss, idempotency, races, partial failure, schema drift) that maps directly onto migration hazards.
52
+
53
+ ```bash
54
+ AUDITOR_GATE_PRESET=adversarial \
55
+ AUDITOR_GATE_TARGET_LABEL="<feature-name> Stage 3 migration" \
56
+ bash .harness/scripts/auditor-gate.sh review <feature-name> 3 \
57
+ "Review this migration. Junior reviewers from {{junior_reviewers}} have approved project-rule conformance. Your job: catch what they may share blind spots on. Beyond the preset's attack surface, weigh migration-specific traps: access-control holes (a policy that compiles but doesn't enforce what the spec needs — missing 'with check' on insert/update on backends that support it, an 'OR' in the policy that grants more than intended, a USING expression that lets through rows the spec excludes); missing indexes on policy columns or foreign keys; irreversibility traps (a column add that can't be safely rolled forward without data loss, a backfill DEFAULT that is wrong for some pre-existing rows); PII gaps (a personal-data column without a PII comment, or with overly permissive access-control); enum/type evolution pitfalls (adding values is usually fine; renaming or removing values is painful). Do NOT flag: project conventions per the backend rule doc (forward-only migrations, the {{rls_auth_function}} pattern, type conventions, NOT NULL defaults, RLS-enabled-on-every-table)." \
58
+ {{migration_dir}}<the-migration-file>
59
+ ```
60
+
61
+ - **Exit 0 (PASS / CONCERNS / WAIVED)** → proceed to step 10. For CONCERNS, surface the logged warning path (`.harness/audits/concerns-*.json`) and remind the CEO to review before commit. For WAIVED, surface the `waiver_reason`.
62
+ - **Exit 2 (FAIL)** → surface every blocking item verbatim, halt. Do not apply the migration. The user fixes the issues and re-invokes `/db-schema`, or applies fixes inline and re-runs the gate manually.
63
+ - **Exit 1 (script error / Universal Core WAIVED rejected / missing waiver_reason / legacy verdict)** → surface stderr, halt.
64
+
65
+ 10. **Remind the user** to run `bash .harness/scripts/post-migration.sh` after applying the migration **locally**. The script does whatever the project needs after a migration:
66
+ - **Refresh / reload backend caches** that don't auto-reload on `migration up` (e.g., schema caches in some setups).
67
+ - **Regenerate typed bindings** from the live local DB. Stage 4 (execution-plan) and any feature code that imports from the typed bindings cannot proceed with stale types.
68
+ The exact contents of `post-migration.sh` are project-specific; /init seeds it based on the configured `backend_db_type` and `tech_stack`.
69
+
70
+ 11. **Check whether the app is hitting a remote backend project.** Inspect the project's `.env` (or equivalent) for the backend URL. If it points at anything other than a local instance, the migration must ALSO be pushed to the remote project — otherwise smoke-testing the feature in Stage 7 will fail against the remote, even though the local stack is healthy. Apply via the backend's MCP / CLI tool. Managed backends usually auto-refresh their schema cache after a migration applies — no separate restart needed there. Confirm per your backend's documentation.
71
+
72
+ ## Trust contract
73
+
74
+ - **Surface every reviewer verdict verbatim.** No "reviewer says it's fine, proceeding." The user sees each reviewer's findings and verdict line in full before any next step is taken.
75
+ - **Reviewer invocation is mandatory and ordered.** Backend reviewer first, security/privacy reviewer second (always, not conditional on self-assessment), auditor third. Skill has no judgment authority to skip a reviewer "because the migration looks simple."
76
+ - **Auditor verdict is parsed deterministically from the gate's exit code.** No prose interpretation. The four verdicts are `PASS` (advance silently), `CONCERNS` (advance with logged warning at `.harness/audits/concerns-*.json` for CEO commit-time review), `FAIL` (halt), and `WAIVED` (CEO override only; rejected by the gate if any blocking item cites Universal Core).
77
+ - **On disagreement** (junior reviewers approve, auditor requests changes): auditor wins by default. Surface both views; user overrides explicitly if they disagree.
78
+ - **Migration is not applied locally until all three reviewers advance (PASS, CONCERNS, or — for the auditor only — a CEO-issued WAIVED with valid `waiver_reason`).** Halt-on-FAIL means actually halting; do not "apply locally to test, then fix later." CONCERNS advances but the warning must be surfaced to the CEO before commit.
79
+
80
+ ## Completion criteria
81
+
82
+ Stage 3 is complete when:
83
+
84
+ - A new migration file exists under `{{migration_dir}}` and has been applied locally
85
+ - `bash .harness/scripts/post-migration.sh` has been run (cache refreshed + types regenerated)
86
+ - Backend reviewer has returned `PASS` or `CONCERNS` (FAIL halts)
87
+ - Security/privacy reviewer has returned `PASS` or `CONCERNS` (mandatory for every migration, not conditional; FAIL halts)
88
+ - `.harness/scripts/auditor-gate.sh` returned exit 0 for stage 3 (`PASS`, `CONCERNS`, or `WAIVED`) — `.harness/state/auditor-approvals/<feature>-stage3.json` exists with a non-FAIL `verdict`
89
+ - Search-index sync mechanism is documented (if applicable)
90
+
91
+ ## Anti-patterns to reject
92
+
93
+ See `references/methodology.md` § "Anti-patterns to reject" for the full list. Common ones:
94
+
95
+ - `select *` in any code
96
+ - Access-control disabled on a table
97
+ - "We'll add access-control later"
98
+ - Renaming a column in place (always additive)
99
+ - Business logic in triggers when the app layer can do it
100
+
101
+ ---
102
+
103
+ ## Checkpoint + decision-log integration (MAGI Archivist)
104
+
105
+ If schema work happened:
106
+
107
+ ```bash
108
+ .harness/scripts/checkpoint-write.sh \
109
+ --feature <feature-slug> \
110
+ --stage 4 \
111
+ --stage-complete 3 \
112
+ --artifact-schema <path-to-migration-file> \
113
+ --append-audit "$(jq -c '{stage:3, verdict, risk:.risk_score, at:now|todate}' .harness/state/auditor-approvals/<feature>-stage3.json)"
114
+ ```
115
+
116
+ If skipped (no backend configured):
117
+
118
+ ```bash
119
+ .harness/scripts/checkpoint-write.sh \
120
+ --feature <feature-slug> \
121
+ --stage 4 \
122
+ --stage-skip 3 --skip-reason "no backend_db_type configured"
123
+ ```
124
+
125
+ MAGI Archivist surfaces skipped stages in the `/pickup` report so users can see deliberate skips vs forgotten stages.
126
+
127
+ ---
128
+
129
+ ## Final message to CEO (natural-language, not slash-command)
130
+
131
+ After Stage 3 completes (schema designed + migration written + auditor verdict), display (in CEO's OS locale):
132
+
133
+ ```
134
+ ✅ Stage 3 完成 — <feature> 的数据库改动设计好了
135
+ 迁移文件: <path>
136
+ MAGI Verdict: <PASS/CONCERNS/WAIVED>, risk = N
137
+
138
+ 接下来可以:
139
+ 👉 「继续」/「下一步」 — 我做执行计划 (Stage 4 — 列出要改的每个文件)
140
+ 👉 「看迁移」 — 我把迁移文件念给你听
141
+ 👉 「改 schema」+ 说改什么 — 重做 Stage 3
142
+ 👉 「放弃」 — 不做这个功能了
143
+ ```
144
+
145
+ On "继续" → invoke `/execution-plan <feature>` silently.
@@ -0,0 +1,202 @@
1
+ # DB Schema Methodology
2
+
3
+ Reference document for designing, reviewing, and evolving the project's database schema. Loaded by `/db-schema` and the project's backend reviewer agent.
4
+
5
+ > **Dialect note:** the methodology is written for **relational databases with row-level access control** (the most common shape for harness-managed backends). SQL examples below use Postgres-flavored syntax; adapt to your `backend_db_type`. The discipline (12-step process, decision table, design principles) is database-agnostic — the syntax is illustrative.
6
+
7
+ This document is the **how**. The **what** (hard rules) lives in the project's backend rule doc (referenced via `{{rule_sources}}`) — read both together. Do not restate rules from there; reference them.
8
+
9
+ ## Order of operations
10
+
11
+ Follow this order every time. Skipping a step causes schema drift or duplicate modeling.
12
+
13
+ ### 1. Survey the existing schema — READ-ONLY
14
+
15
+ Before proposing anything, know what is already there.
16
+
17
+ Read in this order:
18
+
19
+ 1. **Every file under `{{migration_dir}}`** — source of truth for schema history. Read every file, not just the latest.
20
+ 2. **The project's typed-DB-bindings file** (if any) — generated typed view of the current schema. Confirms what the app currently sees.
21
+ 3. **The backend MCP / database client (read-only)** — query the live database to confirm migrations and types are in sync. Flag any drift to the user immediately; do not proceed until resolved.
22
+
23
+ At the end of this step, produce a **one-paragraph summary** of the schema areas relevant to the feature:
24
+
25
+ - Which existing tables are related?
26
+ - Which existing columns might be reused?
27
+ - Which access-control policies already cover the relevant rows?
28
+
29
+ ### 2. Read the feature spec
30
+
31
+ Read `{{spec_dir}}<feature>.md` (Stage 2 artifact). Extract every data requirement:
32
+
33
+ - Entities that need to be stored
34
+ - Relationships between entities
35
+ - Access patterns (who reads what, who writes what, query shape)
36
+ - Retention / deletion behavior
37
+ - Search / indexing needs
38
+
39
+ If the spec does not answer one of these, stop and ask the user. Do not guess.
40
+
41
+ ### 3. Compute the delta
42
+
43
+ Decide, for each data requirement from step 2, one of:
44
+
45
+ | Outcome | When |
46
+ | ----------------------------------------------- | ----------------------------------------------------------- |
47
+ | **Reuse existing table/column as-is** | Existing model already fits |
48
+ | **Add columns to existing table** | New attribute of an existing entity |
49
+ | **Add index to existing table** | New query pattern on existing data |
50
+ | **Add new table** | New entity with no existing home |
51
+ | **Modify existing access-control policy** | New access pattern changes who can read/write existing rows |
52
+ | **Add new access-control policy** | New table or new CRUD verb on existing table |
53
+
54
+ **Never**:
55
+
56
+ - Rename or drop a column in a single migration — write an additive migration, let the app switch, then drop in a later migration.
57
+ - Reshape an existing table to "fit" a new feature if a new table is cleaner. Solo-maintainable beats clever reuse.
58
+
59
+ ### 4. Design new tables (if any)
60
+
61
+ For each new table, decide in this order:
62
+
63
+ 1. **Name** — plural, snake_case (or your stack's convention), domain-prefixed only if needed to avoid ambiguity.
64
+ 2. **Primary key** — UUID with the backend's generator (e.g., `id uuid primary key default gen_random_uuid()` in Postgres) is the default. Use a composite PK only for pure junction tables.
65
+ 3. **Foreign keys** — every relationship declared explicitly. Decide `on delete` per relationship: `cascade` for owned children, `set null` for soft references, `restrict` when deletion should be blocked.
66
+ 4. **Timestamps** — `created_at` (timezone-aware) on every table, with default `now()`. `updated_at` only if the app reads it; maintain via trigger (see step 8).
67
+ 5. **Columns** — pick the narrowest correct type. Prefer timezone-aware timestamps over naive ones. Prefer unbounded text types over arbitrary length caps unless you genuinely need the cap.
68
+ 6. **Constraints** — `not null` by default; only omit when nullability is meaningful. `check` constraints for enumerations and ranges. Unique constraints for business keys.
69
+
70
+ ### 5. Design indexes
71
+
72
+ For every `WHERE`, `ORDER BY`, and `JOIN` column the app will use, decide:
73
+
74
+ - **Single-column index** — default for simple equality / range filters.
75
+ - **Composite index** — when queries filter on multiple columns together. Column order matters: equality columns first, then range.
76
+ - **Partial index** — when queries always filter on a boolean/enum (`WHERE is_active = true`). Reduces index size.
77
+ - **No index** — justify in a comment in the migration. Small tables (< ~1000 rows expected) may skip indexes.
78
+
79
+ Cross-reference the project's backend rule doc for any project-specific indexing rules. Every `WHERE` column either has an index or a justified exclusion comment.
80
+
81
+ ### 6. Design access-control policies
82
+
83
+ For every table, for every CRUD verb the app uses, write an explicit policy.
84
+
85
+ Postgres + RLS pattern (adapt to your backend's access-control model):
86
+
87
+ ```sql
88
+ create policy "<verb> own <resource>"
89
+ on <table> for <select|insert|update|delete>
90
+ to authenticated
91
+ using ( <row matches caller via {{rls_auth_function}}> )
92
+ with check ( <row being written matches caller via {{rls_auth_function}}> );
93
+ ```
94
+
95
+ Rules:
96
+
97
+ - Use the project's configured `{{rls_auth_function}}` for the auth-context expression (set at /init based on `backend_db_type`).
98
+ - Default deny. If a verb has no policy, it is denied.
99
+ - Split "own rows" and "others' rows" into separate policies when access rules differ — clearer than one complex `using` expression.
100
+ - Anonymous policies only when the feature explicitly requires public access; call this out to the user.
101
+
102
+ ### 7. Storage buckets (if the feature uploads files)
103
+
104
+ If the feature uploads images or files and the backend supports file storage:
105
+
106
+ 1. Declare the bucket in the migration.
107
+ 2. Set the file_size_limit and allowed_mime_types in bucket metadata — do not leave these open-ended.
108
+ 3. Write storage access-control policies for each CRUD verb the app uses, same pattern as table-level policies.
109
+ 4. Reference the project's backend rule doc for the exact constraints.
110
+
111
+ If the backend doesn't manage file storage natively, document the chosen file-storage approach in the feature's implementation notes.
112
+
113
+ ### 8. Triggers (if needed)
114
+
115
+ Only add a trigger when the invariant cannot be enforced at the app layer reliably.
116
+
117
+ Common cases:
118
+
119
+ - `updated_at` auto-maintenance.
120
+ - Derived/denormalized columns that must stay in sync.
121
+ - Search-index sync (see step 9).
122
+
123
+ Every trigger declares in a comment:
124
+
125
+ - **Purpose** — what invariant it enforces
126
+ - **Firing event** — `before insert`, `after update of <cols>`, etc.
127
+ - **Privilege mode** — invoker by default; definer only with a justification comment and security/privacy review.
128
+
129
+ ### 9. Search-index sync (if the table is search-indexed)
130
+
131
+ If the new/modified table feeds an external search index (Meilisearch, Elasticsearch, Algolia, etc.), document the sync mechanism in the migration file or a sibling `.md`:
132
+
133
+ - **Trigger-based** — DB trigger writes to an outbox table; an ingest worker / edge function drains it.
134
+ - **Direct push from function** — backend function synchronously updates the search index on mutation.
135
+ - **Periodic job** — only for eventual-consistency-tolerant data.
136
+
137
+ State which one and why. Required if the project's backend rule doc mandates it.
138
+
139
+ ### 10. PII and security review
140
+
141
+ If the table contains any of:
142
+
143
+ - Phone numbers, email addresses, real names
144
+ - Location data (coordinates, addresses)
145
+ - Chat messages or private content
146
+ - Reports, moderation data
147
+ - Payment information
148
+ - Any other personal data per the project's PII definition
149
+
150
+ **Flag for security/privacy reviewer.** Add a `-- PII: <what>` comment (or your backend's equivalent annotation) above the relevant columns in the migration. The security/privacy reviewer is called at the end of Stage 3 — mandatorily, not conditionally.
151
+
152
+ ### 11. Write the migration
153
+
154
+ One migration file per logical change. Prefer one migration per feature; split only when the feature has clearly separable phases (e.g., schema first, then seed data).
155
+
156
+ File name: `{{migration_dir}}<timestamp>_<feature_or_change>.<ext>` — generate with the project's migration tool.
157
+
158
+ Structure inside the file, in this order:
159
+
160
+ 1. Create new tables
161
+ 2. Alter existing tables (add columns, constraints)
162
+ 3. Create indexes
163
+ 4. Enable access-control on new tables
164
+ 5. Create access-control policies
165
+ 6. Create functions and triggers
166
+ 7. Storage bucket declarations + storage policies (if applicable)
167
+ 8. Comments documenting PII, trigger purposes, non-obvious decisions
168
+
169
+ **Forward-only.** Never write a down migration. To undo, write a new forward migration.
170
+
171
+ ### 12. Regenerate types
172
+
173
+ After the migration is applied, run the project's type-regeneration command (configured in `.harness/scripts/post-migration.sh`).
174
+
175
+ This step is part of Stage 3 completion. A feature cannot advance to Stage 4 with stale types.
176
+
177
+ ## Output of a `/db-schema` run
178
+
179
+ At the end of Stage 3, the following must exist:
180
+
181
+ - One or more new files under `{{migration_dir}}`, applied locally.
182
+ - An updated typed-DB-bindings file (if the project uses one).
183
+ - Confirmation to the user that search-index sync (if applicable) is documented.
184
+ - Backend reviewer review complete (PASS or CONCERNS; FAIL halts).
185
+ - Security/privacy reviewer review complete (PASS or CONCERNS, mandatory; FAIL halts).
186
+ - Auditor review complete (PASS, CONCERNS, or WAIVED; FAIL halts).
187
+
188
+ ## Anti-patterns to reject
189
+
190
+ - `select *` in any code — always list columns.
191
+ - Access-control disabled on a table — never. Every table ships with access-control enabled.
192
+ - "We'll add access-control later" — rejected. Policies ship with the table.
193
+ - Rationalizing a missing index with "the table will be small" without a row-count estimate.
194
+ - A policy that mixes "own" and "others'" rules in one `using` expression when splitting would be clearer.
195
+ - Renaming a column to "clean up" — always additive, never in-place.
196
+ - Business logic in database triggers when the app layer can do it — triggers are for invariants, not convenience.
197
+
198
+ ## Reference
199
+
200
+ - The project's backend rule doc (in `{{rule_sources}}`) — hard rules (access-control enabled, the `{{rls_auth_function}}` pattern, forward-only, secrets, etc.)
201
+ - The project's auth rule doc (in `{{rule_sources}}`) — auth context for access-control policies
202
+ - The project's env rule doc (in `{{rule_sources}}`) — secret handling for backend functions that read/write the DB