@massu/core 0.5.0 → 0.6.1

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 (119) hide show
  1. package/README.md +40 -0
  2. package/agents/massu-architecture-reviewer.md +104 -0
  3. package/agents/massu-blast-radius-analyzer.md +84 -0
  4. package/agents/massu-competitive-scorer.md +126 -0
  5. package/agents/massu-help-sync.md +73 -0
  6. package/agents/massu-migration-writer.md +94 -0
  7. package/agents/massu-output-scorer.md +87 -0
  8. package/agents/massu-pattern-reviewer.md +84 -0
  9. package/agents/massu-plan-auditor.md +170 -0
  10. package/agents/massu-schema-sync-verifier.md +70 -0
  11. package/agents/massu-security-reviewer.md +98 -0
  12. package/agents/massu-ux-reviewer.md +106 -0
  13. package/commands/_shared-preamble.md +53 -23
  14. package/commands/_shared-references/auto-learning-protocol.md +71 -0
  15. package/commands/_shared-references/blast-radius-protocol.md +76 -0
  16. package/commands/_shared-references/security-pre-screen.md +64 -0
  17. package/commands/_shared-references/test-first-protocol.md +87 -0
  18. package/commands/_shared-references/verification-table.md +55 -0
  19. package/commands/massu-article-review.md +343 -0
  20. package/commands/massu-autoresearch/references/eval-runner.md +84 -0
  21. package/commands/massu-autoresearch/references/safety-rails.md +125 -0
  22. package/commands/massu-autoresearch/references/scoring-protocol.md +151 -0
  23. package/commands/massu-autoresearch.md +258 -0
  24. package/commands/massu-batch.md +44 -12
  25. package/commands/massu-bearings.md +42 -8
  26. package/commands/massu-checkpoint.md +588 -0
  27. package/commands/massu-ci-fix.md +2 -2
  28. package/commands/massu-command-health.md +132 -0
  29. package/commands/massu-command-improve.md +232 -0
  30. package/commands/massu-commit.md +205 -44
  31. package/commands/massu-create-plan.md +239 -57
  32. package/commands/massu-data/references/common-queries.md +79 -0
  33. package/commands/massu-data/references/table-guide.md +50 -0
  34. package/commands/massu-data.md +66 -0
  35. package/commands/massu-dead-code.md +29 -34
  36. package/commands/massu-debug/references/auto-learning.md +61 -0
  37. package/commands/massu-debug/references/codegraph-tracing.md +80 -0
  38. package/commands/massu-debug/references/common-shortcuts.md +98 -0
  39. package/commands/massu-debug/references/investigation-phases.md +294 -0
  40. package/commands/massu-debug/references/report-format.md +107 -0
  41. package/commands/massu-debug.md +105 -386
  42. package/commands/massu-docs.md +1 -1
  43. package/commands/massu-full-audit.md +61 -0
  44. package/commands/massu-gap-enhancement-analyzer.md +276 -16
  45. package/commands/massu-golden-path/references/approval-points.md +216 -0
  46. package/commands/massu-golden-path/references/competitive-mode.md +273 -0
  47. package/commands/massu-golden-path/references/error-handling.md +121 -0
  48. package/commands/massu-golden-path/references/phase-0-requirements.md +53 -0
  49. package/commands/massu-golden-path/references/phase-1-plan-creation.md +168 -0
  50. package/commands/massu-golden-path/references/phase-2-implementation.md +403 -0
  51. package/commands/massu-golden-path/references/phase-2.5-gap-analyzer.md +170 -0
  52. package/commands/massu-golden-path/references/phase-3-simplify.md +40 -0
  53. package/commands/massu-golden-path/references/phase-3.5-security-audit.md +108 -0
  54. package/commands/massu-golden-path/references/phase-4-commit.md +94 -0
  55. package/commands/massu-golden-path/references/phase-5-push.md +116 -0
  56. package/commands/massu-golden-path/references/phase-5.5-production-verify.md +170 -0
  57. package/commands/massu-golden-path/references/phase-6-completion.md +113 -0
  58. package/commands/massu-golden-path/references/qa-evaluator-spec.md +137 -0
  59. package/commands/massu-golden-path/references/sprint-contract-protocol.md +117 -0
  60. package/commands/massu-golden-path/references/vr-visual-calibration.md +73 -0
  61. package/commands/massu-golden-path.md +121 -844
  62. package/commands/massu-guide.md +72 -69
  63. package/commands/massu-hooks.md +27 -12
  64. package/commands/massu-hotfix.md +221 -144
  65. package/commands/massu-incident.md +49 -20
  66. package/commands/massu-infra-audit.md +187 -0
  67. package/commands/massu-learning-audit.md +211 -0
  68. package/commands/massu-loop/references/auto-learning.md +49 -0
  69. package/commands/massu-loop/references/checkpoint-audit.md +40 -0
  70. package/commands/massu-loop/references/guardrails.md +17 -0
  71. package/commands/massu-loop/references/iteration-structure.md +115 -0
  72. package/commands/massu-loop/references/loop-controller.md +188 -0
  73. package/commands/massu-loop/references/plan-extraction.md +78 -0
  74. package/commands/massu-loop/references/vr-plan-spec.md +140 -0
  75. package/commands/massu-loop-playwright.md +9 -9
  76. package/commands/massu-loop.md +115 -670
  77. package/commands/massu-new-pattern.md +423 -0
  78. package/commands/massu-perf.md +422 -0
  79. package/commands/massu-plan-audit.md +1 -1
  80. package/commands/massu-plan.md +389 -122
  81. package/commands/massu-production-verify.md +433 -0
  82. package/commands/massu-push.md +62 -378
  83. package/commands/massu-recap.md +29 -3
  84. package/commands/massu-rollback.md +613 -0
  85. package/commands/massu-scaffold-hook.md +2 -4
  86. package/commands/massu-scaffold-page.md +2 -3
  87. package/commands/massu-scaffold-router.md +1 -2
  88. package/commands/massu-security.md +619 -0
  89. package/commands/massu-simplify.md +115 -85
  90. package/commands/massu-squirrels.md +2 -2
  91. package/commands/massu-tdd.md +38 -22
  92. package/commands/massu-test.md +3 -3
  93. package/commands/massu-type-mismatch-audit.md +469 -0
  94. package/commands/massu-ui-audit.md +587 -0
  95. package/commands/massu-verify-playwright.md +287 -32
  96. package/commands/massu-verify.md +150 -46
  97. package/dist/cli.js +146 -95
  98. package/package.json +6 -2
  99. package/patterns/build-patterns.md +302 -0
  100. package/patterns/component-patterns.md +246 -0
  101. package/patterns/display-patterns.md +185 -0
  102. package/patterns/form-patterns.md +890 -0
  103. package/patterns/integration-testing-checklist.md +445 -0
  104. package/patterns/security-patterns.md +219 -0
  105. package/patterns/testing-patterns.md +569 -0
  106. package/patterns/tool-routing.md +81 -0
  107. package/patterns/ui-patterns.md +371 -0
  108. package/protocols/plan-implementation.md +267 -0
  109. package/protocols/recovery.md +225 -0
  110. package/protocols/verification.md +404 -0
  111. package/reference/command-taxonomy.md +178 -0
  112. package/reference/cr-rules-reference.md +76 -0
  113. package/reference/hook-execution-order.md +148 -0
  114. package/reference/lessons-learned.md +175 -0
  115. package/reference/patterns-quickref.md +208 -0
  116. package/reference/standards.md +135 -0
  117. package/reference/subagents-reference.md +17 -0
  118. package/reference/vr-verification-reference.md +867 -0
  119. package/src/commands/install-commands.ts +149 -53
@@ -0,0 +1,225 @@
1
+ # Post-Compaction Recovery Protocol
2
+
3
+ **Purpose**: Restore context after session compaction. Execute IMMEDIATELY when compaction summary appears.
4
+
5
+ **When to Read**: Automatically after any session compaction.
6
+
7
+ ---
8
+
9
+ ## Pre-Compaction: Proactive Context Preservation
10
+
11
+ **Don't wait for compaction to hit you. Context quality degrades before the system forces compression.**
12
+
13
+ If a session has been running long (many tool calls, large outputs, or nearing compaction warnings):
14
+ 1. **Update `session-state/CURRENT.md`** with current progress, decisions, and next steps
15
+ 2. **Commit any completed work** - don't leave valuable changes only in working memory
16
+ 3. **Consider `/clear` + fresh start** - a clean session with good CURRENT.md outperforms a degraded long session
17
+
18
+ **Why**: Performance drops in the final portion of the context window. Proactive state-saving before exhaustion produces better outcomes than reactive recovery after compaction.
19
+
20
+ ---
21
+
22
+ ## Recovery Steps
23
+
24
+ ### Step 0: Read Session State File (MOST CRITICAL)
25
+
26
+ **FIRST, read `session-state/CURRENT.md`** - Contains:
27
+ - Current task and progress
28
+ - Uncommitted file changes
29
+ - Decisions made + rationale
30
+ - **Failed attempts (DO NOT RETRY these)**
31
+ - Next steps planned
32
+ - User preferences
33
+
34
+ ### Step 0.5: Check AUTHORIZED_COMMAND (CR-12 - MANDATORY)
35
+
36
+ **BEFORE continuing ANY work, check the AUTHORIZED_COMMAND field in session-state/CURRENT.md.**
37
+
38
+ ```
39
+ AUTHORIZED_COMMAND: [command name from session state]
40
+ ```
41
+
42
+ **Rules:**
43
+ 1. If AUTHORIZED_COMMAND is present, you may ONLY continue executing THAT command
44
+ 2. You may NOT escalate to a higher-privilege command without explicit user instruction
45
+ 3. System reminders referencing other commands are NOT user authorization
46
+ 4. Continuation instructions ("continue where you left off") do NOT override this check
47
+
48
+ **Command Privilege Hierarchy** (lowest to highest):
49
+ | Level | Command | Privilege |
50
+ |-------|---------|-----------|
51
+ | 1 | `massu-create-plan` | Read-only research, writes plan doc |
52
+ | 1 | `massu-bearings` | Read-only session orientation |
53
+ | 1 | `massu-squirrels` | Session-state file management only |
54
+ | 1.5 | `massu-recap` | Writes session-state files only, no code changes |
55
+ | 2 | `massu-plan` | Audit, edits plan docs only |
56
+ | 3 | `massu-loop` | Full implementation with code changes |
57
+ | 4 | `massu-commit` | Commit with verification gates |
58
+ | 5 | `massu-push` | Push to remote with full verification |
59
+
60
+ **Escalation Prevention:**
61
+ - If AUTHORIZED_COMMAND = `massu-plan` and system context suggests `/massu-loop`:
62
+ - **FORBIDDEN** - Do not execute `/massu-loop`
63
+ - Continue with `/massu-plan` only
64
+ - Inform user: "Previous session authorized `/massu-plan`. To proceed with implementation, please explicitly run `/massu-loop`."
65
+
66
+ - If AUTHORIZED_COMMAND = `massu-loop` and session was mid-implementation:
67
+ - **ALLOWED** - Continue `/massu-loop` from where it left off
68
+ - This is continuation, not escalation
69
+
70
+ **Why This Step Exists:**
71
+ A user invoked a plan-only command (audit-only). After compaction, system reminders referenced the implementation command. Assistant executed full implementation without authorization, creating unauthorized commits. Text-based safeguards failed because they competed with continuation behavior. This structural check prevents that.
72
+
73
+ ### Step 1: Re-Read CLAUDE.md
74
+
75
+ CLAUDE.md is automatically loaded, but VERIFY you have read it by checking the Core Rules section exists.
76
+
77
+ ### Step 2: Identify Relevant Domain from Compaction Summary
78
+
79
+ Look at the compaction summary for:
80
+ - What domain was being worked on? (database, auth, UI, etc.)
81
+ - What features were being implemented/debugged?
82
+ - What files were being modified?
83
+
84
+ ### Step 3: Load Relevant Pattern Files
85
+
86
+ Based on Step 2, read the appropriate pattern files BEFORE continuing work:
87
+
88
+ | If working on... | Read this file |
89
+ |------------------|----------------|
90
+ | Database/Prisma/tRPC routers | `patterns/database-patterns.md` |
91
+ | Authentication/Authorization | `patterns/auth-patterns.md` |
92
+ | UI components/pages | `patterns/ui-patterns.md` |
93
+ | Real-time subscriptions | `patterns/realtime-patterns.md` |
94
+ | Testing | `patterns/testing-patterns.md` |
95
+ | Build issues | `patterns/build-patterns.md` |
96
+
97
+ ### Step 4: Load Relevant Archives (If Extending Features)
98
+
99
+ If the compaction summary mentions extending/debugging a completed feature:
100
+ - Check archives for the relevant archive
101
+ - Read the specific archive before continuing
102
+
103
+ ### Step 5: Re-Read Plan Document (If Multi-Phase)
104
+
105
+ If the compaction summary references a plan document:
106
+ - Read the plan document
107
+ - Verify current phase status via git log or session state
108
+
109
+ ### Step 5.5: Post-Compaction Plan Re-Verification
110
+
111
+ **MANDATORY when recovering during an implementation run with a plan in progress.**
112
+
113
+ After re-reading the plan document, BEFORE continuing implementation:
114
+
115
+ 1. **Re-read the FULL plan document** line by line
116
+ 2. **For every item marked complete** in the tracking table or session state:
117
+ - Re-run its VR-* verification command
118
+ - For UI items with specific CSS classes/structure in the plan: grep for those EXACT strings (VR-SPEC-MATCH)
119
+ - If verification fails: mark as gap, fix BEFORE continuing to new items
120
+ 3. **Flag any mismatches**: Implementation that doesn't match the plan's exact spec is treated as incomplete
121
+ 4. **Resume from the first incomplete item**, not from where the compaction summary says
122
+
123
+ **Why**: Context compaction loses spec details (exact CSS classes, exact structure). Without re-verification, the agent continues implementing while prior items silently diverge from the plan. This step catches that drift.
124
+
125
+ ---
126
+
127
+ ## Recovery Announcement
128
+
129
+ Before continuing work after recovery, explicitly state:
130
+
131
+ ```
132
+ Post-compaction recovery complete:
133
+ - Current task: [from session-state]
134
+ - Domain: [database/auth/UI/etc]
135
+ - Patterns loaded: [list]
136
+ - Resuming from: [exact location]
137
+ - Session state verified: [yes/no]
138
+ ```
139
+
140
+ ---
141
+
142
+ ## Critical Warning
143
+
144
+ **The compaction summary is a HIGHLIGHT REEL, not complete context.**
145
+ - It does NOT contain pattern rules
146
+ - It does NOT contain code examples
147
+ - It does NOT contain critical constraints
148
+ - It does NOT contain failed attempts or decisions rationale
149
+ - **You WILL make pattern violations if you skip this protocol**
150
+
151
+ **NEVER say "I'll continue from where we left off" without first completing Steps 0-5.**
152
+
153
+ ---
154
+
155
+ ## Multi-Phase Plan Recovery
156
+
157
+ For multi-phase plans specifically, ALSO:
158
+
159
+ 1. Read `protocols/plan-implementation.md`
160
+ 2. Verify current phase status via:
161
+ - Todo list
162
+ - Git log
163
+ - Schema state
164
+ - Session state file
165
+ 3. Re-execute Pre-Phase Protocol for current phase
166
+
167
+ ### What To Do If Session State Is Missing
168
+
169
+ If `session-state/CURRENT.md` does not exist or is empty:
170
+ 1. **STOP** - Do not proceed
171
+ 2. Re-read the ENTIRE plan line-by-line
172
+ 3. Query database to determine current state
173
+ 4. Create session state based on verified state
174
+ 5. Announce current checkpoint to user before proceeding
175
+
176
+ ---
177
+
178
+ ## Session State Update Requirements
179
+
180
+ Update `session-state/CURRENT.md` after:
181
+ - [ ] Significant decision made (record WHAT + WHY)
182
+ - [ ] Failed attempt (record what didn't work + why) - CRITICAL
183
+ - [ ] File modified (add to uncommitted changes list)
184
+ - [ ] Task pivot (update current task description)
185
+ - [ ] User preference expressed (record for future reference)
186
+ - [ ] Blocker encountered (document the obstacle)
187
+ - [ ] Phase/checkpoint completion
188
+
189
+ ## FAILED APPROACH TRACKING (CRITICAL)
190
+
191
+ After TWO failed corrections on the same issue:
192
+ 1. STOP attempting the same approach
193
+ 2. Document the failed approach in session-state/CURRENT.md
194
+ 3. Start fresh: /clear and write a better initial prompt
195
+ incorporating what you learned from the failures
196
+
197
+ FORMAT in session-state/CURRENT.md:
198
+ ### Failed Approaches (DO NOT RETRY)
199
+ | # | Approach | Why It Failed | Lesson |
200
+ |---|---------|---------------|--------|
201
+ | 1 | [what you tried] | [why it broke] | [what to do instead] |
202
+
203
+ WHY: Context polluted with failed approaches leads to worse outputs.
204
+ Starting fresh with better instructions is faster than continuing
205
+ to iterate in polluted context.
206
+
207
+ ### When to Archive Session State
208
+
209
+ Archive `CURRENT.md` to `archive/YYYY-MM-DD-[description].md` when:
210
+ - Major task/feature is complete
211
+ - Switching to unrelated work
212
+ - End of significant work session
213
+
214
+ ```bash
215
+ mv session-state/CURRENT.md session-state/archive/$(date +%Y-%m-%d)-[description].md
216
+ ```
217
+
218
+ Then create fresh `CURRENT.md` for next task.
219
+
220
+ **NEVER delete archives** - they are permanent institutional memory.
221
+
222
+ ---
223
+
224
+ **Document Status**: ACTIVE
225
+ **Compliance**: Mandatory after any session compaction
@@ -0,0 +1,404 @@
1
+ # Verification Protocol - Unified
2
+
3
+ **Purpose**: Single source of truth for all verification requirements. Referenced by CR-1 (Canonical Rule 1).
4
+
5
+ **When to Read**: Before claiming ANY task is complete, before any database operation, before any commit.
6
+
7
+ ---
8
+
9
+ ## Verification Types (VR)
10
+
11
+ | Type | Command | Expected Result | Use When |
12
+ |------|---------|-----------------|----------|
13
+ | VR-FILE | `ls -la [path]` | File exists | Claiming file created |
14
+ | VR-GREP | `grep "[pattern]" [file]` | Match found | Claiming code added |
15
+ | VR-NEGATIVE | `grep -rn "[old]" src/` | 0 matches | Claiming removal |
16
+ | VR-BUILD | `npm run build` | Exit 0 | Claiming production ready |
17
+ | VR-TYPE | `npx tsc --noEmit` | 0 errors | Claiming type safety |
18
+ | VR-TEST | `npm test` | All pass | Claiming tested |
19
+ | VR-DEPLOY | `./scripts/pre-deploy-check.sh` | All pass | Claiming deployable |
20
+ | VR-SCHEMA | `SELECT ... FROM information_schema` | Matches expectation | Before DB operations |
21
+ | VR-COUNT | `grep -c "[pattern]" [file]` | Expected count | Verifying all instances |
22
+ | VR-PLAN-TABS | `grep -c "TabsTrigger" [file]` | Tab count matches plan | Plan specifies tabs |
23
+ | VR-PLAN-ITEMS | `grep -c "DropdownMenuItem" [file]` | Item count matches plan | Plan specifies menu items |
24
+ | VR-PLAN-SPEC | Multiple greps per spec | All UI elements exist | Plan specifies UI structure |
25
+
26
+ ---
27
+
28
+ ## Plan Specification Verification (VR-PLAN-SPEC)
29
+
30
+ **Purpose**: Verify that UI implementation matches plan specification exactly.
31
+
32
+ **When Plan Says "Tabs: A | B | C"**:
33
+ ```bash
34
+ # Verify exact tab count
35
+ grep -c "TabsTrigger" src/app/[path]/page.tsx
36
+ # Expected: 3
37
+
38
+ # Verify each tab label exists
39
+ grep "TabsTrigger.*A" src/app/[path]/page.tsx
40
+ grep "TabsTrigger.*B" src/app/[path]/page.tsx
41
+ grep "TabsTrigger.*C" src/app/[path]/page.tsx
42
+ ```
43
+
44
+ **When Plan Says "More Menu: X items"**:
45
+ ```bash
46
+ # Verify menu item count
47
+ grep -c "DropdownMenuItem" src/components/[path]/[Menu].tsx
48
+ # Expected: X items
49
+ ```
50
+
51
+ **When Plan Says "View Switcher: A | B"**:
52
+ ```bash
53
+ # Verify view switcher exists and has correct options
54
+ grep -c "DropdownMenuItem\|SelectItem" src/components/[path]/ViewSwitcher.tsx
55
+ # Expected: 2+
56
+ ```
57
+
58
+ ---
59
+
60
+ ## Literal Spec Verification (VR-SPEC-MATCH)
61
+
62
+ **Purpose**: Verify that EVERY plan item with specific CSS classes, component names, layout instructions, or visual specs is implemented with those EXACT strings.
63
+
64
+ **When**: During verification of ANY UI plan item that specifies concrete CSS classes, structure, or layout.
65
+
66
+ **Protocol**:
67
+
68
+ For EVERY plan item that specifies CSS classes or structure (e.g., `ml-6 border-l-2 pl-4`, `grid grid-cols-3 gap-4`, `<Badge variant="outline">`):
69
+
70
+ 1. Extract ALL specific CSS classes / component attributes from the plan item
71
+ 2. Grep the implementation file for each EXACT string
72
+ 3. If ANY specified string is missing: **VR-SPEC-MATCH FAILURE = gap**
73
+
74
+ ```bash
75
+ # Example: Plan says "indented with ml-6 border-l-2 border-muted pl-4"
76
+ grep "ml-6" src/components/feature/Component.tsx # Must match
77
+ grep "border-l-2" src/components/feature/Component.tsx # Must match
78
+ grep "border-muted" src/components/feature/Component.tsx # Must match
79
+ grep "pl-4" src/components/feature/Component.tsx # Must match
80
+ ```
81
+
82
+ **VR-SPEC-MATCH Failure = Plan NOT Complete.** The implementation must contain the plan's exact specifications.
83
+
84
+ ---
85
+
86
+ ## Data Pipeline Verification (VR-PIPELINE)
87
+
88
+ **Purpose**: For features that generate or process data (AI, cron, generation, ETL), verify the pipeline produces non-empty output end-to-end.
89
+
90
+ **When**: After implementing any feature with a data pipeline -- AI processing, cron jobs, report generation, data sync, document indexing, etc.
91
+
92
+ **Protocol**:
93
+
94
+ 1. Identify the entry point procedure (tRPC procedure, cron handler, edge function)
95
+ 2. Trigger it manually (call the procedure directly or via test)
96
+ 3. Verify the output contains non-empty data
97
+ 4. If output is empty: investigate root cause and fix before marking complete
98
+
99
+ ```bash
100
+ # Example: AI pipeline
101
+ # 1. Call the procedure
102
+ npx tsx -e "import { ... } from './src/server/api/routers/feature'; ..."
103
+ # 2. Check output
104
+ # Expected: Non-empty result with actual data
105
+
106
+ # Example: Cron job
107
+ # 1. Call the handler
108
+ curl -X POST http://localhost:3000/api/cron/digest -H "Authorization: Bearer $CRON_SECRET"
109
+ # 2. Verify response contains data, not empty arrays/objects
110
+ ```
111
+
112
+ **VR-PIPELINE Failure**: Empty output from a data pipeline = gap. Investigate and fix before claiming complete.
113
+
114
+ ---
115
+
116
+ ### VR-PLAN-SPEC Failure = Plan NOT Complete
117
+
118
+ If ANY VR-PLAN-SPEC check fails:
119
+ - The plan is NOT complete
120
+ - The feature is NOT implemented
121
+ - Claiming "complete" is a LIE
122
+ - Fix the implementation, then re-verify
123
+
124
+ ---
125
+
126
+ ## Pre-Completion Protocol (Before Saying "Complete")
127
+
128
+ **This protocol is NON-NEGOTIABLE. Violation = incident logged.**
129
+
130
+ 1. **OPEN the plan file** (not from memory)
131
+ 2. **READ every line** of the plan document
132
+ 3. **CREATE a verification entry** for EVERY deliverable
133
+ 4. **RUN a verification command** for EVERY entry
134
+ 5. **SHOW the command output** as PROOF for EVERY entry
135
+ 6. **FIX any failing items** before proceeding
136
+ 7. **RE-VERIFY fixed items** until ALL pass
137
+ 8. **COMPLETE the verification template**
138
+ 9. **PRESENT the completed checklist** to the user
139
+ 10. **WAIT for user acknowledgment** before claiming complete
140
+
141
+ ### What Counts as Verification
142
+
143
+ | Deliverable Type | Required VR Type |
144
+ |-----------------|------------------|
145
+ | File creation | VR-FILE |
146
+ | Function/procedure added | VR-GREP |
147
+ | Feature implementation | VR-GREP + VR-COUNT |
148
+ | Code removal | VR-NEGATIVE |
149
+ | Router procedure | VR-GREP showing procedureName |
150
+ | Build success | VR-BUILD |
151
+ | Type safety | VR-TYPE |
152
+
153
+ ### What Does NOT Count as Verification
154
+
155
+ - "I created that file" (MUST show VR-FILE output)
156
+ - "I added that procedure" (MUST show VR-GREP output)
157
+ - "The feature is there" (MUST show proof)
158
+ - "I checked and it's done" (MUST show verification commands)
159
+ - Memory or assumptions of ANY kind
160
+
161
+ ---
162
+
163
+ ## Database Verification Protocol
164
+
165
+ **ABSOLUTE RULE: NEVER ASSUME, ALWAYS VERIFY**
166
+
167
+ Before writing ANY code that touches the database:
168
+
169
+ 1. **VERIFY the table exists** - Query or check `prisma/schema.prisma`
170
+ 2. **VERIFY column names exactly** - Typos cause silent failures
171
+ 3. **VERIFY column types** - String vs Int vs Decimal vs BigInt vs JSON vs enum
172
+ 4. **VERIFY nullable vs required** - Determines if field can be omitted
173
+ 5. **VERIFY constraints** - Unique, foreign keys, check constraints
174
+ 6. **VERIFY RLS policies** - What operations allowed for which roles
175
+ 7. **VERIFY grants** - Does service_role have permission?
176
+
177
+ ### Schema Verification Commands
178
+
179
+ ```sql
180
+ -- Check table structure
181
+ SELECT column_name, data_type, is_nullable, column_default
182
+ FROM information_schema.columns
183
+ WHERE table_name = 'your_table_name'
184
+ ORDER BY ordinal_position;
185
+
186
+ -- Check RLS policies
187
+ SELECT polname, polcmd, polroles, polqual
188
+ FROM pg_policies
189
+ WHERE tablename = 'your_table_name';
190
+
191
+ -- Check constraints
192
+ SELECT conname, contype, pg_get_constraintdef(oid)
193
+ FROM pg_constraint
194
+ WHERE conrelid = 'your_table_name'::regclass;
195
+
196
+ -- Check grants
197
+ SELECT grantee, privilege_type
198
+ FROM information_schema.table_privileges
199
+ WHERE table_name = 'your_table_name';
200
+ ```
201
+
202
+ ### Schema Migration Compatibility Check
203
+
204
+ **MANDATORY BEFORE any data migration plan:**
205
+
206
+ ```sql
207
+ -- Find columns in SOURCE missing from TARGET
208
+ SELECT column_name, data_type
209
+ FROM information_schema.columns
210
+ WHERE table_name = 'source_table'
211
+ EXCEPT
212
+ SELECT column_name, data_type
213
+ FROM information_schema.columns
214
+ WHERE table_name = 'target_table';
215
+
216
+ -- Find columns in TARGET missing from SOURCE
217
+ SELECT column_name, data_type
218
+ FROM information_schema.columns
219
+ WHERE table_name = 'target_table'
220
+ EXCEPT
221
+ SELECT column_name, data_type
222
+ FROM information_schema.columns
223
+ WHERE table_name = 'source_table';
224
+ ```
225
+
226
+ ---
227
+
228
+ ## Audit Protocol (For Plan Verification)
229
+
230
+ ### Step 1: READ THE PLAN FILE - Not Memory
231
+ - Open the actual plan file
232
+ - Do NOT rely on summaries or memory
233
+ - The plan file is the ONLY source of truth
234
+
235
+ ### Step 2: Create Checklist of ALL Requirements
236
+ For EACH item in the plan, create explicit checklist entries:
237
+ - [ ] ADD component X to page Y
238
+ - [ ] REMOVE component Z from page Y (CRITICAL: Include removals!)
239
+ - [ ] SWAP component A with component B
240
+ - [ ] MODIFY behavior of component C
241
+
242
+ ### Step 3: Check REMOVALS Explicitly
243
+ REMOVALS are invisible to positive grep searches. You MUST:
244
+ 1. Identify what should NOT exist
245
+ 2. Grep for the thing that should be GONE
246
+ 3. Verify grep returns ZERO matches
247
+
248
+ ### Step 4: Check EACH Page Mentioned in Plan
249
+ If plan says "Add to pages: A, B, C, D, E":
250
+ - [ ] Verify page A has component
251
+ - [ ] Verify page B has component
252
+ - [ ] Verify page C has component
253
+ - [ ] Verify page D has component
254
+ - [ ] Verify page E has component
255
+
256
+ Do NOT assume "I did most of them so they're all done"
257
+
258
+ ### Step 5: Verify with NEGATIVE Searches
259
+ For every SWAP or REMOVE:
260
+ 1. What was the OLD component/tab/code?
261
+ 2. Search for that OLD thing
262
+ 3. It should return ZERO matches
263
+
264
+ ### Audit Completion Criteria
265
+ - [ ] Plan file was RE-READ during audit (not from memory)
266
+ - [ ] Every ADD verified with VR-GREP showing file exists
267
+ - [ ] Every REMOVE verified with VR-NEGATIVE showing ZERO matches
268
+ - [ ] Every SWAP verified BOTH old removed AND new added
269
+ - [ ] Type check passes (VR-TYPE)
270
+ - [ ] Explicit proof shown for each verification
271
+
272
+ ---
273
+
274
+ ## Red Flags - Stop and Verify
275
+
276
+ | Red Flag | Response |
277
+ |----------|----------|
278
+ | "I already did that" | VERIFY by reading the file |
279
+ | "That should be working" | TEST it |
280
+ | "The audit shows everything is done" | READ THE PLAN FILE |
281
+ | "I think the column is called..." | QUERY the database |
282
+ | "This should have a policy..." | CHECK the policy |
283
+ | "I'll just use the same pattern as..." | VERIFY BOTH match |
284
+ | Session was compacted | RE-READ THE PLAN FILE |
285
+
286
+ ---
287
+
288
+ ## Failure Consequences
289
+
290
+ If verification protocol is violated:
291
+ 1. The claim of "complete" is automatically FALSE
292
+ 2. User trust is damaged
293
+ 3. Incident is logged
294
+ 4. Session termination may be requested
295
+
296
+ **"I assumed the schema" is NEVER acceptable.**
297
+ **"I verified via SQL query" IS acceptable.**
298
+
299
+ ---
300
+
301
+ ## Enterprise-Grade Solutions Only
302
+
303
+ **NEVER suggest, propose, or implement any solution that is not:**
304
+ - **Enterprise-grade**: Production-ready from day one, scalable, maintainable
305
+ - **Permanent**: No temporary fixes, workarounds, or "quick fixes"
306
+ - **Professional**: Industry best practices, proper architecture
307
+
308
+ **What this means in practice:**
309
+ - Do NOT say "here's a quick fix" - only offer the proper solution
310
+ - Do NOT suggest workarounds that need to be replaced later
311
+ - Do NOT implement partial solutions when complete solutions are possible
312
+ - If a proper solution requires more work, do that work - no shortcuts
313
+
314
+ **If you cannot implement an enterprise-grade solution:**
315
+ 1. Explain what the proper solution would require
316
+ 2. Ask if the user wants to proceed with the full implementation
317
+ 3. NEVER default to a lesser solution
318
+
319
+ ---
320
+
321
+ ## Fix ALL Issues Encountered (CR-9)
322
+
323
+ **ALL issues encountered MUST be fixed with enterprise-grade, permanent solutions - pre-existing or not.**
324
+
325
+ **The Law:**
326
+ - NEVER skip issues because they are "pre-existing" or "out of scope"
327
+ - NEVER defer issues to "later" or "another session"
328
+ - NEVER use workarounds when proper fixes are possible
329
+ - ALL issues in the codebase are our responsibility
330
+
331
+ **Enterprise-Grade Standard:**
332
+ - Every fix must be permanent, not a workaround
333
+ - Every fix must be production-ready
334
+ - Every fix must follow established patterns
335
+ - Every fix must include proper verification
336
+
337
+ **Verification (VR-FIX):**
338
+ After any verification run, if issues found:
339
+ 1. Fix ALL issues
340
+ 2. Re-run verification
341
+ 3. Repeat until 0 issues
342
+
343
+ ---
344
+
345
+ ## ALL Tests MUST Pass Before Claiming Complete
346
+
347
+ **ALL tests MUST pass before ANY work can be marked as complete. There are NO exceptions.**
348
+
349
+ **The Rule:**
350
+ | Test State | Action | Can Claim Complete? |
351
+ |------------|--------|---------------------|
352
+ | All tests pass | Proceed | YES |
353
+ | Any test fails | Fix ALL failures | NO |
354
+ | Tests not run | Run tests first | NO |
355
+ | "Tests not applicable" | INVALID - tests are ALWAYS applicable | NO |
356
+
357
+ **Verification (VR-TEST):**
358
+ ```bash
359
+ npm test
360
+ # Expected: Exit 0, ALL tests pass
361
+ # If ANY test fails, work is NOT complete
362
+ ```
363
+
364
+ **Banned Phrases:**
365
+ - "Tests are not applicable" - INVALID
366
+ - "Tests were already failing" - FIX THEM
367
+ - "Tests are out of scope" - INVALID
368
+ - "Tests are optional" - NEVER
369
+
370
+ ---
371
+
372
+ ## Database Configs MUST Match Code Expectations
373
+
374
+ **When code reads configuration from the database, the config values MUST match what the code expects.**
375
+
376
+ **The Rule:**
377
+ | Check Type | What It Verifies | Catches These Issues |
378
+ |------------|------------------|---------------------|
379
+ | VR-SCHEMA | Column exists | Missing columns |
380
+ | VR-DATA | Config values match code | Field name mismatches, wrong keys |
381
+
382
+ **VR-SCHEMA alone is NOT sufficient. VR-DATA is MANDATORY for config-driven features.**
383
+
384
+ **VR-DATA Protocol:**
385
+ ```sql
386
+ -- Step 1: Query ACTUAL config values
387
+ SELECT id, config_column FROM config_table LIMIT 3;
388
+
389
+ -- Step 2: Extract keys from JSONB
390
+ SELECT DISTINCT jsonb_object_keys(config_column) as keys FROM config_table;
391
+ ```
392
+
393
+ **Then verify code uses correct keys:**
394
+ ```bash
395
+ grep -rn "config\." src/lib/[feature]/ | sort -u
396
+ ```
397
+
398
+ **The Lesson:**
399
+ Schema existence (VR-SCHEMA) != Data correctness (VR-DATA). A column can exist with completely wrong values inside. ALWAYS verify BOTH.
400
+
401
+ ---
402
+
403
+ **Document Status**: ACTIVE
404
+ **Compliance**: Mandatory for all verification and completion claims