@massu/core 0.1.1 → 0.4.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.
- package/commands/_shared-preamble.md +76 -0
- package/commands/massu-audit-deps.md +211 -0
- package/commands/massu-changelog.md +174 -0
- package/commands/massu-cleanup.md +315 -0
- package/commands/massu-commit.md +481 -0
- package/commands/massu-create-plan.md +752 -0
- package/commands/massu-dead-code.md +131 -0
- package/commands/massu-debug.md +484 -0
- package/commands/massu-deploy.md +91 -0
- package/commands/massu-deps.md +374 -0
- package/commands/massu-doc-gen.md +279 -0
- package/commands/massu-docs.md +364 -0
- package/commands/massu-estimate.md +313 -0
- package/commands/massu-golden-path.md +973 -0
- package/commands/massu-guide.md +167 -0
- package/commands/massu-hotfix.md +480 -0
- package/commands/massu-loop-playwright.md +837 -0
- package/commands/massu-loop.md +775 -0
- package/commands/massu-new-feature.md +511 -0
- package/commands/massu-parity.md +214 -0
- package/commands/massu-plan.md +456 -0
- package/commands/massu-push-light.md +207 -0
- package/commands/massu-push.md +434 -0
- package/commands/massu-refactor.md +410 -0
- package/commands/massu-release.md +363 -0
- package/commands/massu-review.md +238 -0
- package/commands/massu-simplify.md +281 -0
- package/commands/massu-status.md +278 -0
- package/commands/massu-tdd.md +201 -0
- package/commands/massu-test.md +516 -0
- package/commands/massu-verify-playwright.md +281 -0
- package/commands/massu-verify.md +667 -0
- package/dist/cli.js +7772 -3140
- package/dist/hooks/cost-tracker.js +103 -40
- package/dist/hooks/post-edit-context.js +74 -8
- package/dist/hooks/post-tool-use.js +268 -106
- package/dist/hooks/pre-compact.js +167 -43
- package/dist/hooks/pre-delete-check.js +159 -42
- package/dist/hooks/quality-event.js +103 -40
- package/dist/hooks/security-gate.js +29 -0
- package/dist/hooks/session-end.js +143 -84
- package/dist/hooks/session-start.js +186 -49
- package/dist/hooks/user-prompt.js +189 -43
- package/package.json +10 -15
- package/src/adr-generator.ts +9 -2
- package/src/analytics.ts +9 -3
- package/src/audit-trail.ts +10 -3
- package/src/backfill-sessions.ts +5 -4
- package/src/cli.ts +6 -0
- package/src/cloud-sync.ts +14 -18
- package/src/commands/doctor.ts +193 -6
- package/src/commands/init.ts +230 -5
- package/src/commands/install-commands.ts +137 -0
- package/src/config.ts +68 -2
- package/src/cost-tracker.ts +11 -6
- package/src/db.ts +115 -2
- package/src/dependency-scorer.ts +9 -2
- package/src/docs-tools.ts +21 -16
- package/src/hooks/post-edit-context.ts +4 -4
- package/src/hooks/post-tool-use.ts +130 -0
- package/src/hooks/pre-compact.ts +23 -1
- package/src/hooks/pre-delete-check.ts +92 -4
- package/src/hooks/security-gate.ts +32 -0
- package/src/hooks/session-end.ts +3 -3
- package/src/hooks/session-start.ts +99 -6
- package/src/hooks/user-prompt.ts +46 -1
- package/src/import-resolver.ts +2 -1
- package/src/knowledge-db.ts +169 -0
- package/src/knowledge-indexer.ts +704 -0
- package/src/knowledge-tools.ts +1413 -0
- package/src/license.ts +482 -0
- package/src/memory-db.ts +1364 -23
- package/src/memory-tools.ts +14 -15
- package/src/observability-tools.ts +13 -2
- package/src/observation-extractor.ts +11 -4
- package/src/page-deps.ts +3 -2
- package/src/prompt-analyzer.ts +9 -2
- package/src/python/coupling-detector.ts +124 -0
- package/src/python/domain-enforcer.ts +83 -0
- package/src/python/impact-analyzer.ts +95 -0
- package/src/python/import-parser.ts +244 -0
- package/src/python/import-resolver.ts +135 -0
- package/src/python/migration-indexer.ts +115 -0
- package/src/python/migration-parser.ts +332 -0
- package/src/python/model-indexer.ts +70 -0
- package/src/python/model-parser.ts +279 -0
- package/src/python/route-indexer.ts +58 -0
- package/src/python/route-parser.ts +317 -0
- package/src/python-tools.ts +629 -0
- package/src/regression-detector.ts +9 -3
- package/src/security-scorer.ts +9 -2
- package/src/sentinel-db.ts +45 -89
- package/src/sentinel-tools.ts +8 -11
- package/src/server.ts +29 -7
- package/src/session-archiver.ts +4 -5
- package/src/team-knowledge.ts +9 -2
- package/src/tools.ts +1032 -44
- package/src/validate-features-runner.ts +0 -1
- package/src/validation-engine.ts +9 -2
- package/README.md +0 -40
- package/dist/server.js +0 -7008
- package/src/__tests__/adr-generator.test.ts +0 -260
- package/src/__tests__/analytics.test.ts +0 -282
- package/src/__tests__/audit-trail.test.ts +0 -382
- package/src/__tests__/backfill-sessions.test.ts +0 -690
- package/src/__tests__/cli.test.ts +0 -290
- package/src/__tests__/cloud-sync.test.ts +0 -261
- package/src/__tests__/config-sections.test.ts +0 -359
- package/src/__tests__/config.test.ts +0 -732
- package/src/__tests__/cost-tracker.test.ts +0 -348
- package/src/__tests__/db.test.ts +0 -177
- package/src/__tests__/dependency-scorer.test.ts +0 -325
- package/src/__tests__/docs-integration.test.ts +0 -178
- package/src/__tests__/docs-tools.test.ts +0 -199
- package/src/__tests__/domains.test.ts +0 -236
- package/src/__tests__/hooks.test.ts +0 -221
- package/src/__tests__/import-resolver.test.ts +0 -95
- package/src/__tests__/integration/path-traversal.test.ts +0 -134
- package/src/__tests__/integration/pricing-consistency.test.ts +0 -88
- package/src/__tests__/integration/tool-registration.test.ts +0 -146
- package/src/__tests__/memory-db.test.ts +0 -404
- package/src/__tests__/memory-enhancements.test.ts +0 -316
- package/src/__tests__/memory-tools.test.ts +0 -199
- package/src/__tests__/middleware-tree.test.ts +0 -177
- package/src/__tests__/observability-tools.test.ts +0 -595
- package/src/__tests__/observability.test.ts +0 -437
- package/src/__tests__/observation-extractor.test.ts +0 -167
- package/src/__tests__/page-deps.test.ts +0 -60
- package/src/__tests__/prompt-analyzer.test.ts +0 -298
- package/src/__tests__/regression-detector.test.ts +0 -295
- package/src/__tests__/rules.test.ts +0 -87
- package/src/__tests__/schema-mapper.test.ts +0 -29
- package/src/__tests__/security-scorer.test.ts +0 -238
- package/src/__tests__/security-utils.test.ts +0 -175
- package/src/__tests__/sentinel-db.test.ts +0 -491
- package/src/__tests__/sentinel-scanner.test.ts +0 -750
- package/src/__tests__/sentinel-tools.test.ts +0 -324
- package/src/__tests__/sentinel-types.test.ts +0 -750
- package/src/__tests__/server.test.ts +0 -452
- package/src/__tests__/session-archiver.test.ts +0 -524
- package/src/__tests__/session-state-generator.test.ts +0 -900
- package/src/__tests__/team-knowledge.test.ts +0 -327
- package/src/__tests__/tools.test.ts +0 -340
- package/src/__tests__/transcript-parser.test.ts +0 -195
- package/src/__tests__/trpc-index.test.ts +0 -25
- package/src/__tests__/validate-features-runner.test.ts +0 -517
- package/src/__tests__/validation-engine.test.ts +0 -300
- package/src/core-tools.ts +0 -685
- package/src/memory-queries.ts +0 -804
- package/src/memory-schema.ts +0 -546
- package/src/tool-helpers.ts +0 -41
|
@@ -0,0 +1,775 @@
|
|
|
1
|
+
---
|
|
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(*)
|
|
5
|
+
---
|
|
6
|
+
name: massu-loop
|
|
7
|
+
|
|
8
|
+
> **Shared rules apply.** Read `.claude/commands/_shared-preamble.md` before proceeding. CR-9, CR-35 enforced.
|
|
9
|
+
|
|
10
|
+
# CS Loop: Autonomous Execution Protocol
|
|
11
|
+
|
|
12
|
+
## Workflow Position
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
/massu-create-plan -> /massu-plan -> /massu-loop -> [/massu-simplify] -> /massu-commit -> /massu-push
|
|
16
|
+
(CREATE) (AUDIT) (IMPLEMENT) (QUALITY) (COMMIT) (PUSH)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**This command is step 3 of 5 in the standard workflow. /massu-simplify is an optional quality step after implementation.**
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
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 |
|
|
229
|
+
|
|
230
|
+
### Why This Architecture Exists
|
|
231
|
+
|
|
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.
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
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
|
|
288
|
+
|
|
289
|
+
THERE ARE NO EXCEPTIONS.
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## PLAN ITEM EXTRACTION PROTOCOL (MANDATORY - STEP 0)
|
|
295
|
+
|
|
296
|
+
**Before ANY implementation, extract ALL plan items into a trackable checklist.**
|
|
297
|
+
|
|
298
|
+
### Step 0.1: Read Plan Document (Not Memory)
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
cat [PLAN_FILE_PATH]
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
**You MUST read the plan file. Do NOT rely on memory or summaries.**
|
|
305
|
+
|
|
306
|
+
### Step 0.2: Extract ALL Deliverables
|
|
307
|
+
|
|
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 |
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
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)"
|
|
411
|
+
|
|
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)"
|
|
415
|
+
|
|
416
|
+
---
|
|
417
|
+
|
|
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
|
+
```
|
|
436
|
+
|
|
437
|
+
**Run ALL enumerated checks BEFORE spawning the verification auditor.**
|
|
438
|
+
|
|
439
|
+
---
|
|
440
|
+
|
|
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
|
|
468
|
+
|
|
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 |
|
|
476
|
+
|
|
477
|
+
---
|
|
478
|
+
|
|
479
|
+
## GUARDRAIL CHECKS (Every Iteration)
|
|
480
|
+
|
|
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
|
|
500
|
+
|
|
501
|
+
```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
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
---
|
|
511
|
+
|
|
512
|
+
## ITERATION OUTPUT FORMAT
|
|
513
|
+
|
|
514
|
+
```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]
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
---
|
|
540
|
+
|
|
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.
|
|
559
|
+
|
|
560
|
+
---
|
|
561
|
+
|
|
562
|
+
## PLAN DOCUMENT COMPLETION TRACKING (MANDATORY)
|
|
563
|
+
|
|
564
|
+
Add completion table to TOP of plan document with status for each task:
|
|
565
|
+
|
|
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
|
|
577
|
+
|
|
578
|
+
```bash
|
|
579
|
+
grep "IMPLEMENTATION STATUS" [plan_file]
|
|
580
|
+
grep -c "100% COMPLETE\|DONE\|\*\*DONE\*\*" [plan_file]
|
|
581
|
+
```
|
|
582
|
+
|
|
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
|
+
```
|
|
680
|
+
|
|
681
|
+
---
|
|
682
|
+
|
|
683
|
+
## START NOW
|
|
684
|
+
|
|
685
|
+
**Step 0: Write AUTHORIZED_COMMAND to session state (CR-35)**
|
|
686
|
+
|
|
687
|
+
Before any other work, update `session-state/CURRENT.md` to include:
|
|
688
|
+
```
|
|
689
|
+
AUTHORIZED_COMMAND: massu-loop
|
|
690
|
+
```
|
|
691
|
+
This ensures that if the session compacts, the recovery protocol knows `/massu-loop` was authorized.
|
|
692
|
+
|
|
693
|
+
**Execute the LOOP CONTROLLER at the top of this file.**
|
|
694
|
+
|
|
695
|
+
### Phase 0: Pre-Implementation Memory Check
|
|
696
|
+
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
|
|
700
|
+
- If matches found: read the previous failures and avoid repeating them
|
|
701
|
+
|
|
702
|
+
### Phase 1: Implement
|
|
703
|
+
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
|
|
706
|
+
4. Update session state after each major step
|
|
707
|
+
|
|
708
|
+
### 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
|
|
711
|
+
|
|
712
|
+
### 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
|
|
718
|
+
|
|
719
|
+
### 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.
|
|
749
|
+
|
|
750
|
+
### Phase 3: Auto-Learning (MANDATORY)
|
|
751
|
+
12. **Execute AUTO-LEARNING PROTOCOL** before reporting completion
|
|
752
|
+
|
|
753
|
+
**The auditor subagent handles**: reading the plan, verifying all deliverables, checking patterns/build/types, fixing plan document gaps, and returning structured results.
|
|
754
|
+
|
|
755
|
+
**You (the loop controller) handle**: implementation, spawning auditors, parsing results, fixing code-level gaps, looping, learning, and documentation.
|
|
756
|
+
|
|
757
|
+
**Remember: Claims without proof are invalid. Show the verification output.**
|
|
758
|
+
|
|
759
|
+
---
|
|
760
|
+
|
|
761
|
+
## AUTO-LEARNING PROTOCOL (MANDATORY after every loop completion)
|
|
762
|
+
|
|
763
|
+
After Loop Completes (Zero Gaps):
|
|
764
|
+
|
|
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
|
|
773
|
+
|
|
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.**
|