@massu/core 0.4.2 → 0.6.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 (125) 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 +52 -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 +397 -0
  51. package/commands/massu-golden-path/references/phase-2.5-gap-analyzer.md +156 -0
  52. package/commands/massu-golden-path/references/phase-3-simplify.md +40 -0
  53. package/commands/massu-golden-path/references/phase-4-commit.md +94 -0
  54. package/commands/massu-golden-path/references/phase-5-push.md +116 -0
  55. package/commands/massu-golden-path/references/phase-5.5-production-verify.md +170 -0
  56. package/commands/massu-golden-path/references/phase-6-completion.md +113 -0
  57. package/commands/massu-golden-path/references/qa-evaluator-spec.md +137 -0
  58. package/commands/massu-golden-path/references/sprint-contract-protocol.md +117 -0
  59. package/commands/massu-golden-path/references/vr-visual-calibration.md +73 -0
  60. package/commands/massu-golden-path.md +114 -848
  61. package/commands/massu-guide.md +72 -69
  62. package/commands/massu-hooks.md +27 -12
  63. package/commands/massu-hotfix.md +221 -144
  64. package/commands/massu-incident.md +49 -20
  65. package/commands/massu-infra-audit.md +187 -0
  66. package/commands/massu-learning-audit.md +211 -0
  67. package/commands/massu-loop/references/auto-learning.md +49 -0
  68. package/commands/massu-loop/references/checkpoint-audit.md +40 -0
  69. package/commands/massu-loop/references/guardrails.md +17 -0
  70. package/commands/massu-loop/references/iteration-structure.md +115 -0
  71. package/commands/massu-loop/references/loop-controller.md +188 -0
  72. package/commands/massu-loop/references/plan-extraction.md +78 -0
  73. package/commands/massu-loop/references/vr-plan-spec.md +140 -0
  74. package/commands/massu-loop-playwright.md +9 -9
  75. package/commands/massu-loop.md +115 -670
  76. package/commands/massu-new-pattern.md +423 -0
  77. package/commands/massu-perf.md +422 -0
  78. package/commands/massu-plan-audit.md +1 -1
  79. package/commands/massu-plan.md +389 -122
  80. package/commands/massu-production-verify.md +433 -0
  81. package/commands/massu-push.md +62 -378
  82. package/commands/massu-recap.md +29 -3
  83. package/commands/massu-rollback.md +613 -0
  84. package/commands/massu-scaffold-hook.md +2 -4
  85. package/commands/massu-scaffold-page.md +2 -3
  86. package/commands/massu-scaffold-router.md +1 -2
  87. package/commands/massu-security.md +619 -0
  88. package/commands/massu-simplify.md +115 -85
  89. package/commands/massu-squirrels.md +2 -2
  90. package/commands/massu-tdd.md +38 -22
  91. package/commands/massu-test.md +3 -3
  92. package/commands/massu-type-mismatch-audit.md +469 -0
  93. package/commands/massu-ui-audit.md +587 -0
  94. package/commands/massu-verify-playwright.md +287 -32
  95. package/commands/massu-verify.md +150 -46
  96. package/dist/cli.js +1451 -1047
  97. package/dist/hooks/post-tool-use.js +75 -6
  98. package/dist/hooks/user-prompt.js +16 -0
  99. package/package.json +6 -2
  100. package/patterns/build-patterns.md +302 -0
  101. package/patterns/component-patterns.md +246 -0
  102. package/patterns/display-patterns.md +185 -0
  103. package/patterns/form-patterns.md +890 -0
  104. package/patterns/integration-testing-checklist.md +445 -0
  105. package/patterns/security-patterns.md +219 -0
  106. package/patterns/testing-patterns.md +569 -0
  107. package/patterns/tool-routing.md +81 -0
  108. package/patterns/ui-patterns.md +371 -0
  109. package/protocols/plan-implementation.md +267 -0
  110. package/protocols/recovery.md +225 -0
  111. package/protocols/verification.md +404 -0
  112. package/reference/command-taxonomy.md +178 -0
  113. package/reference/cr-rules-reference.md +76 -0
  114. package/reference/hook-execution-order.md +148 -0
  115. package/reference/lessons-learned.md +175 -0
  116. package/reference/patterns-quickref.md +208 -0
  117. package/reference/standards.md +135 -0
  118. package/reference/subagents-reference.md +17 -0
  119. package/reference/vr-verification-reference.md +867 -0
  120. package/src/commands/init.ts +27 -0
  121. package/src/commands/install-commands.ts +149 -53
  122. package/src/hooks/post-tool-use.ts +17 -0
  123. package/src/hooks/user-prompt.ts +21 -0
  124. package/src/memory-file-ingest.ts +127 -0
  125. package/src/memory-tools.ts +34 -1
@@ -1,688 +1,150 @@
1
1
  ---
2
2
  name: massu-loop
3
- description: Execute task with CS Loop verification protocol (autonomous execution with mandatory proof)
4
- allowed-tools: Bash(*), Read(*), Write(*), Edit(*), Grep(*), Glob(*), Task(*)
3
+ description: "When user wants to implement a plan autonomously -- 'implement this plan', 'start the loop', 'execute', or provides a plan file to implement end-to-end"
4
+ allowed-tools: Bash(*), Read(*), Write(*), Edit(*), Grep(*), Glob(*)
5
5
  ---
6
6
  name: massu-loop
7
7
 
8
- > **Shared rules apply.** Read `.claude/commands/_shared-preamble.md` before proceeding. CR-9, CR-35 enforced.
8
+ # Massu Loop: Autonomous Execution Protocol
9
9
 
10
- # CS Loop: Autonomous Execution Protocol
10
+ **Shared rules**: Read `.claude/commands/_shared-preamble.md` before proceeding.
11
+
12
+ ---
11
13
 
12
14
  ## Workflow Position
13
15
 
14
16
  ```
15
17
  /massu-create-plan -> /massu-plan -> /massu-loop -> [/massu-simplify] -> /massu-commit -> /massu-push
16
- (CREATE) (AUDIT) (IMPLEMENT) (QUALITY) (COMMIT) (PUSH)
18
+ (CREATE) (AUDIT) (IMPLEMENT) (QUALITY) (COMMIT) (PUSH)
17
19
  ```
18
20
 
19
21
  **This command is step 3 of 5 in the standard workflow. /massu-simplify is an optional quality step after implementation.**
20
22
 
21
23
  ---
22
24
 
23
- ## MANDATORY LOOP CONTROLLER (EXECUTE THIS - DO NOT SKIP)
24
-
25
- **This section is the EXECUTION ENTRY POINT. You MUST follow these steps exactly.**
26
-
27
- ### How This Command Works
28
-
29
- This command is a **loop controller** for implementation + verification. Your job is to:
30
- 1. Extract plan items and implement them
31
- 2. After implementation, spawn focused review subagents IN PARALLEL for independent analysis
32
- 3. After reviews, spawn a `general-purpose` subagent for verification
33
- 4. Parse the structured result (`GAPS_DISCOVERED: N`)
34
- 5. If gaps discovered > 0: fix gaps, then spawn ANOTHER FRESH auditor pass
35
- 6. Only when a COMPLETE FRESH PASS discovers ZERO gaps can you declare complete
36
-
37
- **The verification audit runs inside Task subagents. This prevents early termination.**
38
-
39
- ### CRITICAL: GAPS_DISCOVERED Semantics
40
-
41
- **`GAPS_DISCOVERED` = total gaps FOUND during the pass, REGARDLESS of whether they were also fixed.**
42
-
43
- | Scenario | GAPS_DISCOVERED | Loop Action |
44
- |----------|----------------|-------------|
45
- | Pass finds 0 gaps | 0 | **EXIT** - verification complete |
46
- | Pass finds 5 gaps, fixes all 5 | **5** (NOT 0) | **CONTINUE** - must re-verify |
47
- | Pass finds 3 gaps, fixes 1, 2 need controller | **3** | **CONTINUE** - fix remaining, re-verify |
48
-
49
- **THE RULE**: A clean pass means zero gaps DISCOVERED from the start. Fixing gaps during a pass does NOT make it a clean pass. Only a fresh pass finding nothing proves correctness.
50
-
51
- ### Agent Result Persistence
52
-
53
- All Task sub-agents MUST write their results to disk in addition to returning text:
54
- - Security review: `.massu/agent-results/{timestamp}-security.json`
55
- - Architecture review: `.massu/agent-results/{timestamp}-architecture.json`
56
- - Verification audit: `.massu/agent-results/{timestamp}-verify-{iteration}.json`
57
-
58
- JSON format: `{ iteration, gaps_discovered, gaps_fixed, gaps_remaining, plan_items_total, plan_items_verified, findings: [] }`
59
-
60
- This prevents context overflow from killing verification progress. If the parent session crashes, a new session can read these files via `bash scripts/hooks/read-agent-results.sh` to resume.
61
-
62
- ### Workflow State Tracking
63
-
64
- At the start of this command, write a transition entry to `.massu/workflow-log.md`:
65
- ```
66
- | [timestamp] | AUDIT/PLAN | IMPLEMENT | /massu-loop | [session-id] |
67
- ```
68
-
69
- At completion, write a completion entry.
70
-
71
- ### Execution Protocol
72
-
73
- ```
74
- PLAN_PATH = $ARGUMENTS (the plan file path or task description)
75
- iteration = 0
76
-
77
- # Phase 1: IMPLEMENT (do the work)
78
- # Read plan, extract items, implement each one with VR-* proof
79
-
80
- # Phase 1.5: MULTI-PERSPECTIVE REVIEW (after implementation, before verification)
81
- # Spawn focused review subagents IN PARALLEL for independent analysis
82
- # Each reviewer has an adversarial mindset and a SINGLE focused concern (Principle #20)
83
- # Elegance/simplicity assessment happens in Phase 2.1 POST-BUILD REFLECTION (Q4)
84
-
85
- security_result = Task(subagent_type="general-purpose", model="opus", prompt="
86
- Review implementation for plan: {PLAN_PATH}
87
- Focus: Security vulnerabilities, auth gaps, input validation, data exposure
88
- Check all new/modified files. Return structured result with SECURITY_GATE.
89
- ")
90
-
91
- architecture_result = Task(subagent_type="general-purpose", model="opus", prompt="
92
- Review implementation for plan: {PLAN_PATH}
93
- Focus: Design issues, coupling problems, pattern compliance, scalability
94
- Check all new/modified files. Return structured result with ARCHITECTURE_GATE.
95
- ")
96
-
97
- # Parse results and fix any CRITICAL/HIGH findings before proceeding to verification
98
- # FAIL gate = must fix before proceeding
99
- # WARN findings = document and proceed
100
-
101
- # Phase 2: VERIFY (audit loop - STRUCTURAL)
102
- WHILE true:
103
- iteration += 1
104
-
105
- # Run circuit breaker check (detect stagnation)
106
- # If same gaps appear 3+ times with no progress, consider changing approach
107
- IF iteration > 3 AND no_progress_count >= 3:
108
- Output: "CIRCUIT BREAKER: The current approach is not converging after {iteration} passes."
109
- Output: "Options: (a) Re-plan with different approach (b) Continue current approach (c) Stop"
110
- AskUserQuestion: "The loop has stalled. How should we proceed?"
111
- IF user chooses re-plan: STOP loop, output current state, recommend /massu-create-plan
112
- IF user chooses continue: CONTINUE loop (reset circuit breaker)
113
- IF user chooses stop: STOP loop, output current state as incomplete
114
-
115
- # Spawn auditor subagent for ONE complete verification pass
116
- result = Task(subagent_type="general-purpose", model="opus", prompt="
117
- Verification audit iteration {iteration} for plan: {PLAN_PATH}
118
- This is a Massu implementation (library/MCP server, NOT a web app).
119
- Execute ONE complete audit pass. Verify ALL deliverables.
120
- Check code quality (patterns, types, tests).
121
- Check plan coverage (every item verified with proof).
122
- Fix any gaps you find (code or plan document).
123
-
124
- CONTEXT: Massu is a TypeScript monorepo with:
125
- - packages/core/src/ (MCP server source)
126
- - packages/core/src/__tests__/ (vitest tests)
127
- - packages/core/src/hooks/ (esbuild-compiled hooks)
128
- - website/ (Next.js + Supabase website)
129
- - massu.config.yaml (project config)
130
- - Tool registration: 3-function pattern (getDefs, isTool, handleCall) in tools.ts
131
-
132
- VERIFICATION COMMANDS:
133
- - Pattern scanner: bash scripts/massu-pattern-scanner.sh
134
- - Type check: cd packages/core && npx tsc --noEmit
135
- - Tests: npm test
136
- - Hook build: cd packages/core && npm run build:hooks
137
-
138
- VR-* CHECKS (use ONLY these, per CLAUDE.md):
139
- - VR-FILE, VR-GREP, VR-NEGATIVE, VR-COUNT (generic)
140
- - VR-BUILD: npm run build (tsc + hooks)
141
- - VR-TYPE, VR-TEST, VR-TOOL-REG, VR-HOOK-BUILD, VR-CONFIG, VR-PATTERN
142
-
143
- CRITICAL INSTRUCTION FOR GAPS_DISCOVERED:
144
- Report GAPS_DISCOVERED as the total number of gaps you FOUND during this pass,
145
- EVEN IF you also fixed them. Finding 5 gaps and fixing all 5 = GAPS_DISCOVERED: 5.
146
- A clean pass that finds nothing wrong from the start = GAPS_DISCOVERED: 0.
147
-
148
- Return the structured result block:
149
- ---STRUCTURED-RESULT---
150
- ITERATION: {iteration}
151
- GAPS_DISCOVERED: [number]
152
- GAPS_FIXED: [number]
153
- GAPS_REMAINING: [number]
154
- PLAN_ITEMS_TOTAL: [number]
155
- PLAN_ITEMS_VERIFIED: [number]
156
- CODE_QUALITY_GATE: PASS/FAIL
157
- PLAN_COVERAGE_GATE: PASS/FAIL
158
- ---END-RESULT---
159
- ")
160
-
161
- # Parse structured result
162
- gaps = parse GAPS_DISCOVERED from result
163
-
164
- # Report iteration to user
165
- Output: "Verification iteration {iteration}: {gaps} gaps discovered"
166
-
167
- IF gaps == 0:
168
- Output: "ALL GATES PASSED - Clean pass with zero gaps discovered in iteration {iteration}"
169
- BREAK
170
- ELSE:
171
- Output: "{gaps} gaps discovered in iteration {iteration}, starting fresh re-verification..."
172
- # Fix code-level gaps the auditor identified but couldn't fix
173
- # Then continue the loop for re-verification
174
- CONTINUE
175
- END WHILE
176
-
177
- # Phase 2.1: POST-BUILD REFLECTION + MANDATORY MEMORY PERSIST (CR-38)
178
- # Now that the implementation is verified, capture the agent's accumulated knowledge
179
- # before context disappears. Ask and answer these questions, then WRITE TO MEMORY:
180
- #
181
- # 1. "Now that I've built this, what would I have done differently?"
182
- # - Identify architectural choices that caused friction
183
- # - Note patterns that were harder to work with than expected
184
- # - Flag code that works but feels fragile or overly complex
185
- #
186
- # 2. "What should be refactored before moving on?"
187
- # - Concrete refactoring suggestions with file paths
188
- # - Technical debt introduced during implementation
189
- # - Opportunities to simplify or consolidate
190
- #
191
- # 3. "Did we over-build? Is there a simpler way?"
192
- # - Identify any added complexity that wasn't strictly needed
193
- # - Flag scope expansion beyond the original plan
194
- # - Check if any "fix everything encountered" items could have been simpler
195
- #
196
- # 4. "Would a staff engineer approve this?" (Principle #19)
197
- # - Check if the solution demonstrates good engineering taste
198
- # - Look for over-abstraction, unnecessary indirection, or "clever" code
199
- # - For non-trivial implementations: is there a more elegant approach?
200
- # - For simple fixes: skip this check - don't over-engineer obvious solutions
201
- #
202
- # MANDATORY: After answering, IMMEDIATELY write ALL learnings to memory/ files.
203
- # This is NOT optional. Reflection without persistence is wasted knowledge.
204
- # - Failed approaches -> MEMORY.md or topic file
205
- # - New patterns discovered -> MEMORY.md or topic file
206
- # - Tool/config gotchas -> MEMORY.md or topic file
207
- # - Architectural insights -> MEMORY.md or topic file
208
- # The reflection step and the memory-write step are ONE ATOMIC ACTION.
209
- # DO NOT output reflections as text without also writing them to memory files.
210
- #
211
- # Then apply any low-risk refactors immediately.
212
- # Log remaining suggestions in the plan document under "## Post-Build Reflection".
213
- ```
214
-
215
- ### Rules for the Loop Controller
216
-
217
- | Rule | Meaning |
218
- |------|---------|
219
- | **NEVER output a final verdict while gaps discovered > 0** | Only a CLEAN zero-gap-from-start iteration produces the final report |
220
- | **NEVER treat "found and fixed" as zero gaps** | Fixing during a pass still means gaps were discovered |
221
- | **NEVER ask user "should I continue?"** | The loop is mandatory - just execute it |
222
- | **NEVER stop after fixing gaps** | Fixing gaps requires a FRESH re-audit to verify the fixes |
223
- | **ALWAYS use Task tool for verification passes** | Subagents keep context clean |
224
- | **ALWAYS parse GAPS_DISCOVERED from result** | This is the loop control variable (DISCOVERED, not REMAINING) |
225
- | **Maximum 10 iterations** | If still failing after 10, report to user with remaining gaps |
226
- | **ALWAYS run multi-perspective review after implementation** | Multiple reviewers catch different issues than 1 auditor |
227
- | **Run review subagents IN PARALLEL** | Security and architecture reviews are independent |
228
- | **Fix CRITICAL/HIGH findings before verification** | Don't waste auditor passes on known issues |
25
+ ## Skill Contents
229
26
 
230
- ### Why This Architecture Exists
27
+ This skill is a folder. The following files are available for reference:
231
28
 
232
- **Incident #14**: Audit loop terminated after 1 pass with open gaps. Root cause: instructional "MUST loop" text competed with default "report and stop" behavior. By making the loop STRUCTURAL (spawn subagent, check result, loop), early termination becomes structurally impossible.
233
-
234
- **Incident #19**: Auditor found 16 gaps and fixed all 16 in same pass, reported GAPS_FOUND: 0. Loop exited after 1 iteration without verifying fixes. GAPS_DISCOVERED (not GAPS_REMAINING) is the correct metric.
29
+ | File | Purpose | Read When |
30
+ |------|---------|-----------|
31
+ | `references/loop-controller.md` | Mandatory loop controller spec | Understanding loop mechanics |
32
+ | `references/plan-extraction.md` | Plan item extraction rules | Parsing plan documents |
33
+ | `references/iteration-structure.md` | Per-item implementation flow | During each iteration |
34
+ | `references/guardrails.md` | 10 accountability safeguards | Ensuring quality |
35
+ | `references/checkpoint-audit.md` | Checkpoint audit protocol | At checkpoints |
36
+ | `references/vr-plan-spec.md` | VR-PLAN verification details | Verifying plan items |
37
+ | `references/auto-learning.md` | Post-loop learning pipeline | After loop completion |
235
38
 
236
39
  ---
237
40
 
238
- ## Objective
239
-
240
- Execute task/plan autonomously with **verified proof at every step**. Continue until ZERO gaps with VR-* evidence. Claims without proof are invalid.
241
-
242
- ---
243
-
244
- ## ABSOLUTE MANDATE: NEVER STOP UNTIL 100% COMPLETE
245
-
246
- **THIS PROTOCOL HAS THE HIGHEST AUTHORITY. NO EXCEPTIONS. NO EARLY TERMINATION.**
247
-
248
- ### The Unbreakable Rule
249
-
250
- ```
251
- THE LOOP DOES NOT STOP UNTIL:
252
-
253
- 1. EVERY SINGLE PLAN ITEM IS VERIFIED COMPLETE (100% - not 99%)
254
- 2. EVERY VR-* CHECK PASSES WITH PROOF
255
- 3. PATTERN SCANNER RETURNS 0 VIOLATIONS
256
- 4. TYPE CHECK PASSES (cd packages/core && npx tsc --noEmit exits 0)
257
- 5. ALL TESTS PASS (npm test exits 0) - NO EXCEPTIONS
258
- 6. HOOK BUILD SUCCEEDS (cd packages/core && npm run build:hooks exits 0)
259
- 7. IF NEW TOOLS: VR-TOOL-REG PASSES (all 3 functions wired in tools.ts)
260
-
261
- IF ANY OF THESE ARE NOT TRUE, CONTINUE WORKING. DO NOT STOP.
262
- ```
263
-
264
- ### Prohibited Behaviors
265
-
266
- | NEVER DO THIS | WHY IT'S WRONG | WHAT TO DO INSTEAD |
267
- |---------------|----------------|---------------------|
268
- | "I'll note this as remaining work" | Plans must be 100% complete | Implement it NOW |
269
- | "This item can be done later" | No deferral allowed | Implement it NOW |
270
- | "Most items are done" | "Most" is not "all" | Complete ALL items |
271
- | Stop after code quality passes | Plan coverage must ALSO pass | Continue until 100% coverage |
272
- | Ask "should I continue?" | Yes, always continue | Keep working silently |
273
- | Skip tests because "they're optional" | Tests are NEVER optional | Run ALL tests |
274
- | Claim complete with failing tests | Failing tests = NOT complete | Fix tests first |
275
-
276
- ### MANDATORY TEST VERIFICATION (CR-7)
277
-
278
- **TESTS ARE NEVER OPTIONAL.**
279
-
280
- ```
281
- BEFORE claiming ANY work is complete:
282
-
283
- 1. RUN: npm test
284
- 2. VERIFY: Exit code is 0
285
- 3. VERIFY: All tests pass (no failures)
286
- 4. IF tests fail: FIX THEM - even if they were failing before
287
- 5. RE-RUN: npm test until ALL pass
41
+ ## Gotchas
288
42
 
289
- THERE ARE NO EXCEPTIONS.
290
- ```
43
+ - **Stagnating loops must bail (CR-37)** -- if the same item fails 3+ times with the same error, stop the loop, document the blocker, and replan. Grinding wastes context
44
+ - **100% coverage required (CR-11)** -- never stop early. Every single plan item must be implemented and verified. "Most items done" is failure
45
+ - **Backend without UI violates CR-12** -- if you implement a backend procedure, it MUST be called from the UI. Orphan procedures are invisible features
46
+ - **Plan file must be re-read from disk (CR-5)** -- after ANY compaction or long pause, re-read the plan file. Memory of plan contents drifts
47
+ - **Compaction risk** -- long loops may trigger context compaction; update `session-state/CURRENT.md` after each iteration so recovery can resume cleanly
291
48
 
292
49
  ---
293
50
 
294
- ## PLAN ITEM EXTRACTION PROTOCOL (MANDATORY - STEP 0)
51
+ ## External Loop Mode
295
52
 
296
- **Before ANY implementation, extract ALL plan items into a trackable checklist.**
297
-
298
- ### Step 0.1: Read Plan Document (Not Memory)
53
+ For large plans or sessions at risk of context exhaustion, use the **external bash loop** to spawn fresh Claude CLI sessions per plan item:
299
54
 
300
55
  ```bash
301
- cat [PLAN_FILE_PATH]
56
+ bash scripts/loop-external.sh --plan /path/to/plan.md [--max-iterations N] [--dry-run]
302
57
  ```
303
58
 
304
- **You MUST read the plan file. Do NOT rely on memory or summaries.**
59
+ Each iteration gets a clean 200K context window. The bash outer loop handles:
60
+ - Plan item extraction and sequencing
61
+ - State tracking in `.claude/loop-state/external-loop.json`
62
+ - Inter-iteration quality gate (`pattern-scanner.sh`)
63
+ - Hook profile propagation via `MASSU_HOOK_PROFILE`
305
64
 
306
- ### Step 0.2: Extract ALL Deliverables
65
+ **When to use**: Plans with 15+ items, sessions already at high context usage, or when compaction risk is high.
307
66
 
308
- ```markdown
309
- ## PLAN ITEM EXTRACTION
310
-
311
- ### Source Document
312
- - **Plan File**: [path]
313
- - **Plan Title**: [title]
314
- - **Total Sections**: [N]
315
-
316
- ### Extracted Items
317
-
318
- | Item # | Type | Description | Location | Verification Command | Status |
319
- |--------|------|-------------|----------|---------------------|--------|
320
- | P1-001 | MODULE_CREATE | foo-tools.ts | packages/core/src/ | ls -la [path] | PENDING |
321
- | P1-002 | TOOL_WIRE | Wire into tools.ts | packages/core/src/tools.ts | grep [module] tools.ts | PENDING |
322
- | P2-001 | TEST | foo.test.ts | packages/core/src/__tests__/ | npm test | PENDING |
323
-
324
- ### Item Types
325
- - MODULE_CREATE: New TypeScript module
326
- - MODULE_MODIFY: Existing module to change
327
- - TOOL_WIRE: Wire tool into tools.ts
328
- - TEST: Test file
329
- - CONFIG: Config changes (config.ts + YAML)
330
- - HOOK: New or modified hook
331
- - REMOVAL: Code/file to remove (use VR-NEGATIVE)
332
-
333
- ### Coverage Summary
334
- - **Total Items**: [N]
335
- - **Verified Complete**: 0
336
- - **Coverage**: 0%
337
- ```
338
-
339
- ### Step 0.3: Create Verification Commands
340
-
341
- For EACH extracted item, define HOW to verify it:
342
-
343
- | Item Type | Verification Method | Expected Result |
344
- |-----------|---------------------|-----------------|
345
- | MODULE_CREATE | `ls -la [path]` | File exists, size > 0 |
346
- | MODULE_MODIFY | `grep "[change]" [file]` | Pattern found |
347
- | TOOL_WIRE | `grep "getXDefs\|isXTool\|handleXCall" tools.ts` | All 3 present |
348
- | TEST | `npm test` | All pass |
349
- | CONFIG | Parse YAML, grep interface | Valid |
350
- | HOOK | `cd packages/core && npm run build:hooks` | Exit 0 |
351
- | REMOVAL | `grep -rn "[old]" packages/core/src/ | wc -l` | 0 matches |
67
+ **Safety**: Does NOT use `--dangerously-skip-permissions`. Safety model is fully preserved.
352
68
 
353
69
  ---
354
70
 
355
- ## CHECKPOINT PROTOCOL
356
-
357
- ### CHECKPOINT FILE
358
-
359
- **Location**: `.claude/session-state/LOOP_CHECKPOINT.md`
360
-
361
- ### CHECKPOINT FORMAT
362
-
363
- ```markdown
364
- ## Loop Checkpoint
365
- - Plan: [plan path]
366
- - Started: [timestamp]
367
- - Last Updated: [timestamp]
368
- - Iteration: [N]
369
-
370
- ### Item Status
371
- | Item # | Description | Status | Verified At |
372
- |--------|-------------|--------|-------------|
373
- | P1-001 | [desc] | DONE/PENDING/IN_PROGRESS | [timestamp] |
374
- | P1-002 | [desc] | DONE/PENDING/IN_PROGRESS | [timestamp] |
375
- ```
376
-
377
- ### SAVE CHECKPOINT
378
-
379
- After each item is implemented and verified, update the checkpoint file:
380
-
381
- 1. Set item status to `DONE` with current timestamp
382
- 2. Update `Last Updated` timestamp
383
- 3. Update `Iteration` count
384
-
385
- Also update after each verification iteration completes (even if items were found incomplete).
386
-
387
- ### RESUME PROTOCOL
388
-
389
- At the START of `/massu-loop`, check for existing checkpoint:
390
-
391
- ```bash
392
- # Check if checkpoint exists
393
- ls .claude/session-state/LOOP_CHECKPOINT.md 2>/dev/null
394
- ```
395
-
396
- **If checkpoint exists AND references the same plan path:**
397
- 1. Read the checkpoint file
398
- 2. Report: "Resuming from checkpoint: X/Y items complete"
399
- 3. Skip already-DONE items (but still verify them in the next audit pass)
400
- 4. Continue from first PENDING item
401
-
402
- **If checkpoint does NOT exist or references a different plan:**
403
- 1. Start fresh
404
- 2. Create new checkpoint file with all items set to PENDING
405
-
406
- ### CHECKPOINT CLEANUP
407
-
408
- When loop completes successfully (`GAPS_DISCOVERED: 0` in a clean pass):
409
- - Delete the checkpoint file: `rm .claude/session-state/LOOP_CHECKPOINT.md`
410
- - Report in COMPLETION REPORT: "Checkpoint: cleaned up (loop complete)"
71
+ ## Objective
411
72
 
412
- When loop reaches max iterations without completing:
413
- - Preserve the checkpoint file for future resume
414
- - Report in COMPLETION REPORT: "Checkpoint: preserved (loop incomplete -- max iterations reached)"
73
+ Execute task/plan autonomously with **verified proof at every step**. Continue until ZERO gaps with VR-* evidence. Claims without proof are invalid.
415
74
 
416
75
  ---
417
76
 
418
- ## VR-PLAN ENUMERATION (Before Verification)
419
-
420
- **Before running ANY verification commands, enumerate ALL applicable VR-* checks.**
421
-
422
- ```markdown
423
- ### VR-* Verification Plan
424
-
425
- | VR Check | Target | Command | Expected |
426
- |----------|--------|---------|----------|
427
- | VR-FILE | [each new file] | ls -la [path] | Exists |
428
- | VR-GREP | [each new function] | grep "[func]" [file] | Found |
429
- | VR-NEGATIVE | [each removal] | grep -rn "[old]" src/ | 0 matches |
430
- | VR-PATTERN | All source | bash scripts/massu-pattern-scanner.sh | Exit 0 |
431
- | VR-TYPE | packages/core | cd packages/core && npx tsc --noEmit | 0 errors |
432
- | VR-TEST | All tests | npm test | All pass |
433
- | VR-TOOL-REG | [new tools] | grep in tools.ts | All 3 functions |
434
- | VR-HOOK-BUILD | hooks | cd packages/core && npm run build:hooks | Exit 0 |
435
- ```
77
+ ## COMPLETION MANDATE (CR-11, CR-21)
436
78
 
437
- **Run ALL enumerated checks BEFORE spawning the verification auditor.**
79
+ Loop does NOT stop until: (1) every plan item verified 100%, (2) every VR-* check passes with proof, (3) pattern scanner 0 violations, (4) build passes, (5) tsc --noEmit 0 errors, (6) ALL tests pass (npm test exit 0), (7) lint passes. Test failures must be fixed regardless of origin. No deferral, no "should I continue?", no partial progress reports.
438
80
 
439
81
  ---
440
82
 
441
- ## IMPLEMENTATION PROTOCOL
442
-
443
- ### For EACH Plan Item
444
-
445
- 1. **Read the plan item** from the extracted list
446
- 2. **Read any referenced files** before modifying
447
- 3. **Implement** following CLAUDE.md patterns
448
- 4. **Verify** with the item's verification command
449
- 5. **Update coverage** count
450
- 6. **Continue** to next item
451
-
452
- ### Pattern Compliance During Implementation
453
-
454
- For every file you create or modify, verify against:
455
-
456
- ```bash
457
- # Run pattern scanner
458
- bash scripts/massu-pattern-scanner.sh
459
-
460
- # Type check
461
- cd packages/core && npx tsc --noEmit
462
-
463
- # Tests still pass
464
- npm test
465
- ```
466
-
467
- ### Massu-Specific Implementation Checks
83
+ ## NON-NEGOTIABLE RULES
468
84
 
469
- | If Implementing | Must Also |
470
- |-----------------|-----------|
471
- | New MCP tool | Wire 3 functions into tools.ts (CR-11) |
472
- | New hook | Verify esbuild compilation (CR-12) |
473
- | Config changes | Update interface in config.ts AND example in YAML |
474
- | New test | Place in `__tests__/` directory |
475
- | New module | Use ESM imports, getConfig() for config |
85
+ 1. **Never claim without proof (CR-1)** - VR-* output must be pasted. "I verified" without output = invalid
86
+ 2. **Recursive audit until zero gaps** - Fix and re-verify until gaps = 0
87
+ 3. **Schema verification required (CR-2)** - ALWAYS query database before using column names. See CLAUDE.md "Known Schema Mismatches"
88
+ 4. **Session state after every iteration** - Update CURRENT.md so compaction recovery can resume (CR-12)
89
+ 5. **Component reuse is mandatory** - Check existing before creating new
90
+ 6. **User flow audit required (CR-12)** - Backend without UI = invisible feature. Technical audits alone are NOT sufficient
91
+ 7. **Document new patterns immediately (CR-34)** - Ingest to memory, record pattern, update scanner
92
+ 8. **Pattern scanner must pass** - `./scripts/pattern-scanner.sh` exit 0 required before claiming complete
93
+ 9. **No workarounds allowed** - TODOs, ts-ignore are BLOCKING violations
94
+ 10. **NO HARDCODED TAILWIND COLORS** - Use semantic CSS classes from globals.css (VR-TOKEN)
95
+ 11. **FIX ALL ISSUES ENCOUNTERED (CR-9)** - Fix immediately regardless of origin. "Not in scope" is NEVER valid
96
+ 12. **Stagnation bail-out (CR-37)** - If same item fails 3+ times with same error, stop loop and replan
476
97
 
477
98
  ---
478
99
 
479
- ## GUARDRAIL CHECKS (Every Iteration)
100
+ ## PRE-EXECUTION CHECKLIST
480
101
 
481
- ### MEMORY CHECK (Start of Each Iteration)
482
-
483
- Search memory files and session state for failures related to this plan's domain and files being modified. Surface relevant past failures as additional audit checkpoints.
484
-
485
- ### Enhanced Context Loading
486
-
487
- For each file being modified:
488
- - `massu_context` - Load CR rules, schema alerts, patterns relevant to the file
489
- - `massu_coupling_check` - Verify tool registration coupling (CR-11)
490
- - `massu_knowledge_rule` - Load applicable CR rules for the file's domain
491
- - `massu_knowledge_verification` - Load required VR-* checks for the file type
492
-
493
- For VR-TOOL-REG checks, also call `massu_trpc_map` to get automated tool-to-handler mapping for comprehensive coverage.
494
-
495
- When verifying CR-11 tool registration, use `massu_sentinel_detail` to get full feature details and verify all linked components/tools/handlers exist.
496
-
497
- When CR-30 applies (rebuilds), call `massu_sentinel_parity` to compare old vs new implementation for feature parity.
498
-
499
- ### Mandatory Checks
102
+ Before starting, verify:
500
103
 
501
104
  ```bash
502
- # Pattern scanner (covers all pattern checks)
503
- bash scripts/massu-pattern-scanner.sh
504
- # Exit 0 = PASS, non-zero = ABORT iteration
505
-
506
- # Security check
507
- git diff --cached --name-only | grep -E '\.(env|pem|key|secret)' && echo "SECURITY VIOLATION" && exit 1
105
+ ls -la ./scripts/pattern-scanner.sh
106
+ touch session-state/CURRENT.md
107
+ ls -la [PLAN_FILE_PATH]
508
108
  ```
509
109
 
510
- ---
511
-
512
- ## ITERATION OUTPUT FORMAT
513
-
110
+ Initialize session state:
514
111
  ```markdown
515
- ## [CS LOOP - Iteration N]
516
-
517
- ### Task
518
- Phase: X | Task: [description]
519
-
520
- ### Guardrails
521
- - Pattern scanner: PASS/FAIL
522
- - Security check: PASS/FAIL
523
-
524
- ### Verifications
525
- | Check | Type | Result | Proof |
526
- |-------|------|--------|-------|
527
- | [item] | VR-FILE | PASS | `ls -la output` |
528
-
529
- ### Gap Count
530
- Gaps found: N
531
-
532
- ### Status
533
- CONTINUE | FIX_REQUIRED | CHECKPOINT | COMPLETE
534
-
535
- ### Next Action
536
- [Specific next step]
112
+ ## MASSU LOOP SESSION
113
+ - **Task**: [description]
114
+ - **Status**: IN_PROGRESS
115
+ - **Iteration**: 1
116
+ - **Phase**: 1
537
117
  ```
538
118
 
539
119
  ---
540
120
 
541
- ## THE 10 ACCOUNTABILITY SAFEGUARDS
542
-
543
- 1. **Audit Proof Requirement** - Every claim MUST include proof output. Claims without proof are INVALID.
544
- 2. **Explicit Gap Count Per Loop** - State gaps found, gap details, status (PASS/FAIL). "Looks good" is BANNED.
545
- 3. **Checkpoint Sign-Off Format** - Use exact format from COMPLETION OUTPUT section.
546
- 4. **Session State Mandatory Updates** - Update `session-state/CURRENT.md` after EVERY change with proof.
547
- 5. **User Verification Rights** - User can request proof re-runs at any time. Comply with actual output.
548
- 6. **Post-Compaction Recovery** - Read session state FIRST, re-read plan, resume from exact point.
549
- 7. **No Claims Without Evidence** - "I verified...", "Build passed..." require accompanying proof output.
550
- 8. **Failure Acknowledgment** - Acknowledge failures, re-execute audit from Step 1, log in session state.
551
- 9. **No Workarounds Allowed** - TODOs, ts-ignore are BLOCKING violations. Pattern scanner is a HARD GATE.
552
- 10. **Document New Patterns** - If you discover a pattern not in CLAUDE.md, ADD IT NOW.
553
-
554
- ---
555
-
556
- ## SESSION STATE UPDATE (After Every Iteration)
557
-
558
- Update `session-state/CURRENT.md` with: loop status (task, iteration, phase, checkpoint), iteration log table, verified work with proof, failed attempts (do not retry), next iteration plan.
121
+ **VR-* Reference**: See CLAUDE.md VR table and `.claude/reference/vr-verification-reference.md`.
559
122
 
560
123
  ---
561
124
 
562
- ## PLAN DOCUMENT COMPLETION TRACKING (MANDATORY)
125
+ ## QUALITY SCORING (silent, automatic)
563
126
 
564
- Add completion table to TOP of plan document with status for each task:
127
+ After completing the loop (zero gaps achieved), self-score against these checks and append one JSONL line to `.claude/metrics/command-scores.jsonl`:
565
128
 
566
- ```markdown
567
- # IMPLEMENTATION STATUS
568
-
569
- **Plan**: [Name] | **Status**: COMPLETE/IN_PROGRESS | **Last Updated**: [date]
570
-
571
- | # | Task/Phase | Status | Verification | Date |
572
- |---|------------|--------|--------------|------|
573
- | 1 | [description] | 100% COMPLETE | VR-GREP: 0 refs | [date] |
574
- ```
575
-
576
- ### VR-PLAN-STATUS Verification
129
+ | Check | Pass condition |
130
+ |-------|---------------|
131
+ | `all_items_verified_with_proof` | Every plan item has VR-* verification output showing proof |
132
+ | `multi_perspective_review_spawned` | At least one auditor subagent was spawned for verification |
133
+ | `gaps_reached_zero` | Final auditor pass returned `GAPS_DISCOVERED: 0` |
134
+ | `memory_persisted` | AUTO-LEARNING PROTOCOL executed: at least one memory file update |
577
135
 
578
- ```bash
579
- grep "IMPLEMENTATION STATUS" [plan_file]
580
- grep -c "100% COMPLETE\|DONE\|\*\*DONE\*\*" [plan_file]
136
+ **Format** (append one line -- do NOT overwrite the file):
137
+ ```json
138
+ {"command":"massu-loop","timestamp":"ISO8601","scores":{"all_items_verified_with_proof":true,"multi_perspective_review_spawned":true,"gaps_reached_zero":true,"memory_persisted":true},"pass_rate":"4/4","input_summary":"[plan-slug]"}
581
139
  ```
582
140
 
583
- ---
584
-
585
- ## STOP CONDITIONS (ALL must be true)
586
-
587
- 1. Every plan item verified complete (100%)
588
- 2. Pattern scanner: 0 violations (`bash scripts/massu-pattern-scanner.sh` exits 0)
589
- 3. Type check: 0 errors (`cd packages/core && npx tsc --noEmit` exits 0)
590
- 4. Tests: ALL pass (`npm test` exits 0)
591
- 5. Hook build: succeeds (`cd packages/core && npm run build:hooks` exits 0)
592
- 6. If new tools: VR-TOOL-REG passes (all 3 functions in tools.ts)
593
-
594
- ---
595
-
596
- ## CONTEXT MANAGEMENT
597
-
598
- Use Task tool with subagents for exploration to keep main context clean. Update session state before compaction. After compaction, read session state and resume from correct step. Never mix unrelated tasks during a protocol.
599
-
600
- ---
601
-
602
- ## COMPLETION CRITERIA
603
-
604
- CS Loop is COMPLETE **only when BOTH gates pass: Code Quality AND Plan Coverage**.
605
-
606
- ### GATE 1: Code Quality Verification (All Must Pass in SAME Audit Run)
607
- - [ ] All phases executed, all checkpoints passed with zero gaps
608
- - [ ] Pattern scanner: Exit 0
609
- - [ ] Type check: 0 errors
610
- - [ ] Build: Exit 0
611
- - [ ] Tests: ALL PASS (MANDATORY)
612
- - [ ] Security: No secrets staged
613
-
614
- ### GATE 2: Plan Coverage Verification
615
- - [ ] Plan file read (actual file, not memory)
616
- - [ ] ALL items extracted into tracking table
617
- - [ ] EACH item verified with VR-* proof
618
- - [ ] Coverage = 100% (99% = FAIL)
619
- - [ ] Plan document updated with completion status
620
-
621
- ### DUAL VERIFICATION REQUIREMENT
622
-
623
- **BOTH gates must pass:**
624
-
625
- ```markdown
626
- ## DUAL VERIFICATION RESULT
627
- | Gate | Status | Details |
628
- |------|--------|---------|
629
- | Code Quality | PASS/FAIL | Pattern scanner, build, types |
630
- | Plan Coverage | PASS/FAIL | X/Y items (Z%) |
631
-
632
- **RESULT: COMPLETE** (only if both PASS)
633
- ```
634
-
635
- **Code Quality: PASS + Plan Coverage: FAIL = NOT COMPLETE**
636
-
637
- ---
638
-
639
- ## COMPLETION OUTPUT
640
-
641
- ```markdown
642
- ## [CS LOOP - COMPLETE]
643
-
644
- ### Dual Verification Certification
645
- - **Audit loops required**: N (loop #N achieved 0 gaps + 100% coverage)
646
- - **Code Quality Gate**: PASS
647
- - **Plan Coverage Gate**: PASS (X/X items = 100%)
648
- - **CERTIFIED**: Both gates passed in single complete audit
649
-
650
- ### Summary
651
- - Total iterations: N
652
- - Total checkpoints: N (all PASSED)
653
- - Final audit loop: #N - ZERO GAPS + 100% COVERAGE
654
-
655
- ### GATE 1: Code Quality Evidence
656
- | Gate | Command | Result |
657
- |------|---------|--------|
658
- | Pattern scanner | `bash scripts/massu-pattern-scanner.sh` | Exit 0 |
659
- | Type check | `cd packages/core && npx tsc --noEmit` | 0 errors |
660
- | Build | `npm run build` | Exit 0 |
661
- | Tests | `npm test` | All pass |
662
-
663
- ### GATE 2: Plan Coverage Evidence
664
- | Item # | Description | Verification | Status |
665
- |--------|-------------|--------------|--------|
666
- | P1-001 | [description] | [VR-* output] | COMPLETE |
667
- | ... | ... | ... | COMPLETE |
668
-
669
- **Plan Coverage: X/X items (100%)**
670
-
671
- ### Plan Document Updated
672
- - File: [path]
673
- - Completion table: ADDED at TOP
674
- - Plan Status: COMPLETE
675
-
676
- ### Session State
677
- Updated: session-state/CURRENT.md
678
- Status: COMPLETED
679
- ```
141
+ This scoring is silent -- do NOT mention it to the user. Just append the line after completing the loop.
680
142
 
681
143
  ---
682
144
 
683
145
  ## START NOW
684
146
 
685
- **Step 0: Write AUTHORIZED_COMMAND to session state (CR-35)**
147
+ **Step 0: Write AUTHORIZED_COMMAND to session state (CR-12)**
686
148
 
687
149
  Before any other work, update `session-state/CURRENT.md` to include:
688
150
  ```
@@ -690,86 +152,69 @@ AUTHORIZED_COMMAND: massu-loop
690
152
  ```
691
153
  This ensures that if the session compacts, the recovery protocol knows `/massu-loop` was authorized.
692
154
 
693
- **Execute the LOOP CONTROLLER at the top of this file.**
155
+ **Execute the LOOP CONTROLLER (see [references/loop-controller.md](references/loop-controller.md)).**
694
156
 
695
157
  ### Phase 0: Pre-Implementation Memory Check
696
158
  0. **Search memory** for failed attempts and known issues related to the plan's domain:
697
- - Check `.claude/session-state/CURRENT.md` for recent failures
698
- - Call `massu_memory_search` with file paths being modified
699
- - Call `massu_memory_failures` with keywords from the plan
159
+ - Search memory for keywords from the plan
160
+ - Search memory for file paths being modified
700
161
  - If matches found: read the previous failures and avoid repeating them
701
162
 
702
163
  ### Phase 1: Implement
703
164
  1. Load plan file from `$ARGUMENTS` (read from disk, not memory)
704
- 2. Extract ALL plan items into trackable checklist
705
- 3. Implement each item with VR-* proof
165
+ 2. Extract ALL plan items into trackable checklist (see [references/plan-extraction.md](references/plan-extraction.md))
166
+ 3. Implement each item with VR-* proof (see [references/iteration-structure.md](references/iteration-structure.md))
706
167
  4. Update session state after each major step
707
168
 
708
169
  ### Phase 1.5: Multi-Perspective Review
709
- 5. Spawn security and architecture review subagents in parallel
710
- 6. Parse results and fix CRITICAL/HIGH findings before proceeding
170
+ Spawn 3 focused review subagents IN PARALLEL (Principle #20):
171
+ - **Security reviewer**: vulnerabilities, auth gaps, input validation, data exposure
172
+ - **Architecture reviewer**: design issues, coupling, pattern compliance, scalability
173
+ - **UX reviewer**: user experience, accessibility, loading/error/empty states, consistency
174
+
175
+ Fix CRITICAL/HIGH findings before proceeding. WARN findings: document and proceed.
711
176
 
712
177
  ### Phase 2: Verify (Subagent Loop)
713
- 7. Spawn `general-purpose` subagent (via Task tool) for verification iteration 1
714
- 8. Parse `GAPS_DISCOVERED` from the subagent result
715
- 9. If gaps > 0: fix what the auditor identified, spawn another iteration
716
- 10. If gaps == 0: output final completion report with dual gate evidence
717
- 11. Continue until zero gaps or maximum 10 iterations
178
+ 5. Spawn `plan-auditor` subagent (via Task tool) for verification iteration 1
179
+ 6. Parse `GAPS_DISCOVERED` from the subagent result (see [references/loop-controller.md](references/loop-controller.md))
180
+ 7. If gaps > 0: fix what the auditor identified, spawn another iteration
181
+ 8. If gaps == 0: output final completion report with dual gate evidence
182
+ 9. Continue until zero gaps or maximum 10 iterations
718
183
 
719
184
  ### Phase 2.1: Post-Build Reflection + MANDATORY Memory Persist (CR-38)
720
- After verification passes with zero gaps, capture accumulated implementation knowledge before it's lost to context compression. Answer four questions:
721
-
722
- 1. **"Now that I've built this, what would I have done differently?"**
723
- - Architectural choices that caused friction
724
- - Patterns that were harder to work with than expected
725
- - Code that works but feels fragile or overly complex
726
-
727
- 2. **"What should be refactored before moving on?"**
728
- - Concrete suggestions with file paths and line numbers
729
- - Technical debt introduced during this implementation
730
- - Opportunities to simplify or consolidate
731
-
732
- 3. **"Did we over-build? Is there a simpler way?"**
733
- - Identify any added complexity that wasn't strictly needed
734
- - Flag scope expansion beyond the original plan
735
- - Check if any "fix everything encountered" items could have been simpler
736
-
737
- 4. **"Would a staff engineer approve this?" (Principle #19)**
738
- - Check if the solution demonstrates good engineering taste
739
- - Look for over-abstraction, unnecessary indirection, or "clever" code
740
- - For non-trivial implementations: is there a more elegant approach?
741
- - For simple fixes: skip this check - don't over-engineer obvious solutions
742
-
743
- **MANDATORY Actions** (reflection + memory write = ONE atomic action):
744
- 1. Apply any low-risk refactors immediately (re-run build/type check after)
745
- 2. **IMMEDIATELY write ALL learnings to memory/ files** -- failed approaches, new patterns, tool gotchas, architectural insights. DO NOT just output reflections as text. Every insight MUST be persisted to `memory/MEMORY.md` or a topic file using the Write/Edit tool.
746
- 3. Log remaining suggestions in the plan document under `## Post-Build Reflection`
747
-
748
- **WARNING**: Outputting reflections without writing them to memory files is a CR-38 violation. The reflection and the memory write are inseparable.
185
+ See [references/auto-learning.md](references/auto-learning.md) for full protocol.
749
186
 
750
187
  ### Phase 3: Auto-Learning (MANDATORY)
751
- 12. **Execute AUTO-LEARNING PROTOCOL** before reporting completion
188
+ 10. Execute AUTO-LEARNING PROTOCOL (see [references/auto-learning.md](references/auto-learning.md))
752
189
 
753
190
  **The auditor subagent handles**: reading the plan, verifying all deliverables, checking patterns/build/types, fixing plan document gaps, and returning structured results.
754
191
 
755
- **You (the loop controller) handle**: implementation, spawning auditors, parsing results, fixing code-level gaps, looping, learning, and documentation.
192
+ **You (the loop controller) handle**: implementation, spawning auditors, parsing results, fixing code-level gaps, looping, learning.
756
193
 
757
194
  **Remember: Claims without proof are invalid. Show the verification output.**
758
195
 
759
196
  ---
760
197
 
761
- ## AUTO-LEARNING PROTOCOL (MANDATORY after every loop completion)
198
+ ## COMPLETION CRITERIA
762
199
 
763
- After Loop Completes (Zero Gaps):
200
+ See [references/vr-plan-spec.md](references/vr-plan-spec.md) for full dual-gate verification and completion output format.
764
201
 
765
- - **Persist Phase 2.1 reflections**: EVERY insight from Post-Build Reflection MUST be written to `memory/MEMORY.md` or a topic file -- failed approaches, tool gotchas, unexpected behavior, "what I'd do differently". This is NOT optional. If Phase 2.1 produced reflections that aren't in memory files, this protocol is INCOMPLETE.
766
- - **Ingest fixes into memory**: `massu_memory_ingest` with type "bugfix"/"pattern", description "[Wrong] -> [Fixed]", files, importance (5=security, 3=build, 2=cosmetic)
767
- - **Record failed approaches**: `massu_memory_ingest` with type "failed_attempt", importance 5
768
- - **Update MEMORY.md**: Add wrong vs correct patterns, tool behaviors, config gotchas
769
- - **Update pattern scanner**: Add new grep-able bad patterns to `scripts/massu-pattern-scanner.sh`
770
- - **Codebase-wide search**: Verify no other instances of same bad pattern (CR-9)
771
- - **Consider new CR rule**: If a class of bug was found (not one-off), propose for CLAUDE.md
772
- - **Record user corrections**: If the user corrected any behavior during this loop, add structured entry to `memory/corrections.md` with date, wrong behavior, correction, and prevention rule
202
+ Massu Loop is COMPLETE **only when BOTH gates pass: Code Quality AND Plan Coverage**.
773
203
 
774
- **A loop that fixes 5 bugs but records 0 learnings is 80% wasted. The fixes are temporary; the learnings are permanent.**
775
- **A reflection that isn't persisted to memory is a learning that will be lost. Text output is not persistence.**
204
+ ### GATE 1: Code Quality (All Must Pass)
205
+ - [ ] Pattern scanner: Exit 0
206
+ - [ ] Type check: 0 errors
207
+ - [ ] Build: Exit 0
208
+ - [ ] Lint: Exit 0
209
+ - [ ] Tests: ALL PASS (MANDATORY)
210
+ - [ ] Security: No secrets staged
211
+ - [ ] VR-RENDER: All UI components rendered in pages
212
+
213
+ ### GATE 2: Plan Coverage
214
+ - [ ] Plan file read (actual file, not memory)
215
+ - [ ] ALL items extracted into tracking table
216
+ - [ ] EACH item verified with VR-* proof
217
+ - [ ] Coverage = 100% (99% = FAIL)
218
+ - [ ] Plan document updated with completion status
219
+
220
+ **Code Quality: PASS + Plan Coverage: FAIL = NOT COMPLETE**