@massu/core 0.5.0 → 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 (118) 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 +146 -95
  97. package/package.json +6 -2
  98. package/patterns/build-patterns.md +302 -0
  99. package/patterns/component-patterns.md +246 -0
  100. package/patterns/display-patterns.md +185 -0
  101. package/patterns/form-patterns.md +890 -0
  102. package/patterns/integration-testing-checklist.md +445 -0
  103. package/patterns/security-patterns.md +219 -0
  104. package/patterns/testing-patterns.md +569 -0
  105. package/patterns/tool-routing.md +81 -0
  106. package/patterns/ui-patterns.md +371 -0
  107. package/protocols/plan-implementation.md +267 -0
  108. package/protocols/recovery.md +225 -0
  109. package/protocols/verification.md +404 -0
  110. package/reference/command-taxonomy.md +178 -0
  111. package/reference/cr-rules-reference.md +76 -0
  112. package/reference/hook-execution-order.md +148 -0
  113. package/reference/lessons-learned.md +175 -0
  114. package/reference/patterns-quickref.md +208 -0
  115. package/reference/standards.md +135 -0
  116. package/reference/subagents-reference.md +17 -0
  117. package/reference/vr-verification-reference.md +867 -0
  118. package/src/commands/install-commands.ts +149 -53
@@ -1,17 +1,17 @@
1
1
  ---
2
2
  name: massu-dead-code
3
- description: Detect and remove dead code orphaned modules, unused exports, unused dependencies
3
+ description: "When user asks about unused code, says 'find dead code', 'clean up unused', or wants to reduce codebase size by removing unreferenced exports"
4
4
  allowed-tools: Bash(*), Read(*), Write(*), Edit(*), Grep(*), Glob(*)
5
5
  ---
6
6
  name: massu-dead-code
7
7
 
8
- > **Shared rules apply.** Read `.claude/commands/_shared-preamble.md` before proceeding. CR-9 enforced.
8
+ > **Shared rules apply.** Read `.claude/commands/_shared-preamble.md` before proceeding.
9
9
 
10
10
  # Massu Dead Code: Automated Dead Code Detection & Removal
11
11
 
12
12
  ## Objective
13
13
 
14
- Identify and safely remove dead code (orphaned modules, unused exports, unused dependencies, unreferenced files) using manual verification and codebase analysis.
14
+ Identify and safely remove dead code (orphaned components, unused exports, unused dependencies, unreferenced files) using a combination of knip, audit-dead-code.sh, and manual verification.
15
15
 
16
16
  ---
17
17
 
@@ -27,36 +27,31 @@ Identify and safely remove dead code (orphaned modules, unused exports, unused d
27
27
 
28
28
  ## PROTOCOL
29
29
 
30
- ### Step 1: Inventory Source Files
30
+ ### Step 1: Run knip
31
31
 
32
32
  ```bash
33
- # List all source files
34
- find packages/core/src -name "*.ts" -not -path "*/__tests__/*" -not -path "*/node_modules/*" | sort
35
-
36
- # List all exports
37
- grep -rn "export " packages/core/src/ --include="*.ts" | grep -v "__tests__" | grep -v "node_modules"
33
+ npm run knip 2>&1 | tee /tmp/knip-output.txt
38
34
  ```
39
35
 
40
- ### Step 2: Find Unused Exports
36
+ Capture counts: unused files, unused dependencies, unused exports, unused types.
41
37
 
42
- For each exported function/class/constant, check if it's imported elsewhere:
38
+ ### Step 2: Run audit-dead-code.sh
43
39
 
44
40
  ```bash
45
- # For each export, verify it has importers
46
- grep -rn "import.*[name]" packages/core/src/ --include="*.ts"
41
+ ./scripts/audit-dead-code.sh 2>&1 | tee /tmp/dead-code-audit.txt
47
42
  ```
48
43
 
49
- Cross-reference with `tools.ts` registrations - tool definitions and handlers are always "used" even if not directly imported elsewhere.
44
+ Cross-reference with knip findings.
50
45
 
51
46
  ### Step 3: Categorize Findings
52
47
 
53
48
  | Category | Source | Action |
54
49
  |----------|--------|--------|
55
- | ORPHANED_MODULE | No imports found | Verify not dynamically loaded, remove if truly orphaned |
56
- | UNUSED_EXPORT | No importers | Check if used via re-export, remove if dead |
57
- | UNUSED_DEPENDENCY | package.json | `npm uninstall` after verifying not dynamically required |
58
- | UNUSED_FILE | No references | Verify no require() or dynamic import(), remove if dead |
59
- | DEAD_FUNCTION | Never called | Verify not exported for external use, remove if dead |
50
+ | ORPHANED_COMPONENT | knip + audit | Verify no dynamic imports, remove if truly orphaned |
51
+ | UNUSED_EXPORT | knip | Check if used via barrel re-export, remove if dead |
52
+ | UNUSED_DEPENDENCY | knip | `npm uninstall` after verifying not dynamically required |
53
+ | UNUSED_FILE | knip | Verify no require() or dynamic import(), remove if dead |
54
+ | DEAD_PROCEDURE | audit | Verify not called from any UI, remove if dead |
60
55
 
61
56
  ### Step 4: Verify Each Finding
62
57
 
@@ -64,10 +59,10 @@ For EACH candidate removal:
64
59
 
65
60
  ```bash
66
61
  # Check for all possible import patterns
67
- grep -rn "import.*[name]" packages/core/src/ --include="*.ts"
68
- grep -rn "require.*[name]" packages/core/src/ --include="*.ts"
69
- grep -rn "[name]" packages/core/src/tools.ts
70
- grep -rn "[name]" massu.config.yaml
62
+ grep -rn "import.*[name]" src/ --include="*.ts" --include="*.tsx"
63
+ grep -rn "require.*[name]" src/ --include="*.ts" --include="*.tsx"
64
+ grep -rn "dynamic.*import.*[name]" src/ --include="*.ts" --include="*.tsx"
65
+ grep -rn "<[ComponentName]" src/ --include="*.tsx"
71
66
  ```
72
67
 
73
68
  If ANY reference found: KEEP (mark as false positive).
@@ -80,7 +75,7 @@ If NO references found: candidate for removal.
80
75
 
81
76
  | # | File/Export | Category | References Found | Action | Risk |
82
77
  |---|------------|----------|-----------------|--------|------|
83
- | 1 | packages/core/src/X.ts | ORPHAN | 0 | REMOVE | Low |
78
+ | 1 | src/components/X.tsx | ORPHAN | 0 | REMOVE | Low |
84
79
  | 2 | lodash (dep) | UNUSED_DEP | 0 direct | UNINSTALL | Medium |
85
80
  ```
86
81
 
@@ -91,9 +86,9 @@ If NO references found: candidate for removal.
91
86
  After user approval:
92
87
  1. Remove files/exports/dependencies
93
88
  2. Run `npm run build` (VR-BUILD)
94
- 3. Run `cd packages/core && npx tsc --noEmit` (VR-TYPE)
89
+ 3. Run `npx tsc --noEmit` (VR-TYPE)
95
90
  4. Run `npm test` (VR-TEST)
96
- 5. Run `bash scripts/massu-pattern-scanner.sh`
91
+ 5. Run `./scripts/pattern-scanner.sh`
97
92
 
98
93
  ### Step 7: Report
99
94
 
@@ -113,17 +108,17 @@ After user approval:
113
108
  ## QUICK COMMANDS
114
109
 
115
110
  ```bash
116
- # Check for unused dependencies
117
- npx depcheck packages/core
111
+ # Full knip report
112
+ npm run knip
118
113
 
119
- # Pattern scanner (verify no violations introduced)
120
- bash scripts/massu-pattern-scanner.sh
114
+ # Strict mode (fails on any issue)
115
+ npm run knip:strict
121
116
 
122
- # Full build verification
123
- npm run build
117
+ # Existing dead code audit
118
+ ./scripts/audit-dead-code.sh
124
119
 
125
- # Full test suite
126
- npm test
120
+ # Pattern scanner (verify no violations introduced)
121
+ ./scripts/pattern-scanner.sh
127
122
  ```
128
123
 
129
124
  ---
@@ -0,0 +1,61 @@
1
+ # Auto-Learning Protocol
2
+
3
+ **MANDATORY after every bug fix.** The system MUST automatically learn from every fix. This is NOT optional.
4
+
5
+ ---
6
+
7
+ ## Step 1: Ingest Failure + Fix into Memory
8
+
9
+ ```
10
+ Use mcp__massu-codegraph__massu_memory_ingest with:
11
+ - type: "bugfix"
12
+ - description: "[What was wrong] -> [What fixed it]"
13
+ - files: [list of files changed]
14
+ - importance: 5 (if caused data exposure or production error), 3 (if caused build/type error), 2 (if cosmetic)
15
+ ```
16
+
17
+ ---
18
+
19
+ ## Step 2: Record Correct vs Incorrect Pattern
20
+
21
+ Update `memory/MEMORY.md` with:
22
+
23
+ ```markdown
24
+ ## [Category] Pattern (discovered [date])
25
+ - WRONG: [the incorrect pattern that caused the bug]
26
+ - CORRECT: [the pattern that fixed it]
27
+ - File(s): [where it was found]
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Step 3: Add to Pattern Scanner (if grep-able)
33
+
34
+ If the incorrect pattern can be detected by grep, add it to `scripts/pattern-scanner.sh`:
35
+
36
+ ```bash
37
+ # Check for [description of bad pattern]
38
+ BAD_PATTERN=$(grep -rn "[bad_pattern]" src/ --include="*.ts" --include="*.tsx" | grep -v node_modules | wc -l)
39
+ if [ "$BAD_PATTERN" -gt 0 ]; then
40
+ echo "[FAIL] [description]"
41
+ CRITICAL=$((CRITICAL + 1))
42
+ fi
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Step 4: Search for Same Pattern Codebase-Wide (CR-9)
48
+
49
+ ```bash
50
+ grep -rn "[bad_pattern]" src/ --include="*.ts" --include="*.tsx"
51
+ ```
52
+
53
+ Fix ALL instances found, not just the one that was reported.
54
+
55
+ ---
56
+
57
+ ## When to Skip
58
+
59
+ - **NEVER** skip Steps 1-2 (memory recording)
60
+ - Skip Step 3 only if the pattern cannot be expressed as a grep pattern
61
+ - **NEVER** skip Step 4 (codebase-wide search)
@@ -0,0 +1,80 @@
1
+ # Codegraph-Enhanced Tracing
2
+
3
+ How to use codegraph MCP tools for dependency tracing and understanding the full context before debugging.
4
+
5
+ ---
6
+
7
+ ## Tools and When to Use Them
8
+
9
+ | Tool | Purpose | Use When |
10
+ |------|---------|----------|
11
+ | `mcp__codegraph__codegraph_callers` | Who calls the buggy function? | Find all entry points that could trigger the bug |
12
+ | `mcp__codegraph__codegraph_callees` | What does the buggy function call? | Find all dependencies that might be the real source |
13
+ | `mcp__codegraph__codegraph_context` | Full context (CRs, patterns, schema) for a file | Get CLAUDE.md-aware context for the file being debugged |
14
+ | `mcp__massu-codegraph__massu_context` | Massu-specific context for the affected file | Schema alerts, pattern warnings specific to this file |
15
+ | `mcp__codegraph__codegraph_impact` | What would be affected by changes to this file? | Before making a fix, understand blast radius |
16
+ | `mcp__codegraph__codegraph_search` | Search for symbols/patterns across the codebase | When you need to find all instances of a pattern |
17
+
18
+ ---
19
+
20
+ ## Recommended Workflow
21
+
22
+ ### Step 1: Identify the Buggy File/Function
23
+
24
+ From the error trace or user report, identify the file and function where the error originates.
25
+
26
+ ### Step 2: Get Full Context
27
+
28
+ ```
29
+ mcp__codegraph__codegraph_context(file: "src/server/api/routers/[router].ts")
30
+ ```
31
+
32
+ This returns:
33
+ - Applicable CRs (Canonical Rules) for this file
34
+ - Known patterns that apply
35
+ - Schema information if database-related
36
+ - Import dependencies
37
+
38
+ ### Step 3: Trace Callers (Upstream)
39
+
40
+ ```
41
+ mcp__codegraph__codegraph_callers(symbol: "procedureName", file: "src/server/api/routers/[router].ts")
42
+ ```
43
+
44
+ This reveals:
45
+ - Which UI components call this procedure
46
+ - Which other routers depend on it
47
+ - Entry points from API routes or cron jobs
48
+
49
+ ### Step 4: Trace Callees (Downstream)
50
+
51
+ ```
52
+ mcp__codegraph__codegraph_callees(symbol: "procedureName", file: "src/server/api/routers/[router].ts")
53
+ ```
54
+
55
+ This reveals:
56
+ - What database operations the function performs
57
+ - What utility functions it depends on
58
+ - External service calls
59
+
60
+ ### Step 5: Check Impact Before Fixing
61
+
62
+ ```
63
+ mcp__codegraph__codegraph_impact(file: "src/server/api/routers/[router].ts")
64
+ ```
65
+
66
+ Before applying a fix, understand what else could break.
67
+
68
+ ---
69
+
70
+ ## Key Principle
71
+
72
+ **Use these tools BEFORE forming hypotheses.** Understanding the full call graph prevents fixing symptoms instead of root causes.
73
+
74
+ A bug in the UI might actually originate in:
75
+ - The tRPC router (wrong query)
76
+ - The database layer (missing RLS)
77
+ - A utility function (incorrect transformation)
78
+ - The middleware (wrong routing)
79
+
80
+ Tracing callers and callees reveals the true source.
@@ -0,0 +1,98 @@
1
+ # Common Debugging Shortcuts
2
+
3
+ Quick diagnosis patterns for common error types.
4
+
5
+ ---
6
+
7
+ ## Quick Error Checks
8
+
9
+ ```bash
10
+ # All console errors in components
11
+ grep -rn "console.error" src/components/
12
+
13
+ # All try/catch blocks
14
+ grep -rn "catch\s*(" src/server/
15
+
16
+ # All error boundaries
17
+ grep -rn "ErrorBoundary\|error.tsx" src/
18
+
19
+ # Recent server logs (Supabase)
20
+ # Use mcp__supabase__[ENV]__get_logs for each environment
21
+ ```
22
+
23
+ ---
24
+
25
+ ## Quick Pattern Violations
26
+
27
+ ```bash
28
+ # Run full pattern check
29
+ ./scripts/pattern-scanner.sh
30
+
31
+ # Quick manual checks
32
+ grep -rn "ctx.prisma" src/server/ | wc -l # Should be 0
33
+ grep -rn "ctx.db.users" src/ | wc -l # Should be 0
34
+ grep -rn "include:" src/server/ | wc -l # Should be 0
35
+ grep -rn "publicProcedure.mutation" src/ | wc -l # Should be 0
36
+ ```
37
+
38
+ ---
39
+
40
+ ## 500 Internal Server Error
41
+
42
+ 1. Check server logs: `mcp__supabase__[ENV]__get_logs`
43
+ 2. VR-SCHEMA-PRE: Verify table/column existence
44
+ 3. Check for `ctx.prisma` (should be `ctx.db`)
45
+ 4. Check for `include:` (should use 3-step queries)
46
+ 5. Check for `ctx.db.users` (should be `ctx.db.user_profiles`)
47
+ 6. Check BigInt serialization (use `Number()` on return)
48
+ 7. Check Decimal serialization (use `serializeUnifiedProduct()`)
49
+
50
+ ---
51
+
52
+ ## 403 Forbidden / 401 Unauthorized
53
+
54
+ 1. Check RLS policies: `scripts/check-rls-policies.sh [table]`
55
+ 2. Verify service_role grants exist
56
+ 3. Check `protectedProcedure` vs `publicProcedure`
57
+ 4. Check middleware routing in `middleware.ts`
58
+ 5. Check portal_access.portal_type alignment
59
+ 6. Verify session token validity
60
+
61
+ ---
62
+
63
+ ## React Crash / TypeError
64
+
65
+ 1. Check for `value=""` in any `<Select>` or `<SelectItem>` (use `__none__`)
66
+ 2. Check null guards on nullable string methods: `(status || "pending").replace()`
67
+ 3. Check Suspense boundaries for `use(params)` pages
68
+ 4. Check for `onSuccess` in `useQuery` options (removed in React Query v5)
69
+ 5. Check useCallback dependency stability (use specific function refs, not parent objects)
70
+
71
+ ---
72
+
73
+ ## Build Failures
74
+
75
+ 1. Check for static jsdom/cheerio imports (must use `await import()`)
76
+ 2. Check client/server boundary violations (`@/lib/db` in client components)
77
+ 3. Check `next-intl` setup (plugin + request.ts + Provider)
78
+ 4. Run `NODE_OPTIONS="--max-old-space-size=8192" npx tsc --noEmit`
79
+ 5. Check for circular dependencies in import chains
80
+
81
+ ---
82
+
83
+ ## "No Data" / Empty Results
84
+
85
+ 1. VR-DATA: Query actual config values and compare keys to code expectations
86
+ 2. Check RLS policies allow the operation for the current user role
87
+ 3. Check grants exist for service_role
88
+ 4. Verify table exists in the target environment (schema drift)
89
+ 5. Check if `findManyGeneric` has any hidden default limit
90
+
91
+ ---
92
+
93
+ ## Realtime / Subscription Failures
94
+
95
+ 1. Check query key format: `queryKey: [['router', 'procedure']]` (double brackets)
96
+ 2. Verify RLS policies exist for the table
97
+ 3. Check realtime is enabled for the table in Supabase dashboard
98
+ 4. Verify the subscription channel name matches
@@ -0,0 +1,294 @@
1
+ # Investigation Phases (0-7)
2
+
3
+ Full detail for each investigation phase in the massu-debug protocol.
4
+
5
+ ---
6
+
7
+ ## PHASE 0: REPRODUCE THE FAILURE (MANDATORY)
8
+
9
+ Before investigating root cause, CONFIRM you can trigger the exact error.
10
+
11
+ 1. Identify the exact reproduction steps from user report
12
+ 2. Execute those steps (or equivalent verification commands)
13
+ 3. Capture the actual error output
14
+ 4. If you CANNOT reproduce: document that and investigate why
15
+
16
+ WHY: Debugging without reproduction is guessing. Fixes without
17
+ reproduction cannot be verified.
18
+
19
+ ### 0.1 Check Memory for Related Failures
20
+
21
+ Before investigating, check if this error has been seen before:
22
+
23
+ Use `mcp__massu-codegraph__massu_memory_failures` with keywords from
24
+ the error message.
25
+ Use `mcp__massu-codegraph__massu_memory_search` with the affected
26
+ file/feature name.
27
+
28
+ If a match is found:
29
+ - The previous root cause and fix are documented
30
+ - Check if the previous fix regressed
31
+ - Do NOT retry previously failed approaches (check recurrence_count)
32
+
33
+ ---
34
+
35
+ ## PHASE 1: SYMPTOM CAPTURE
36
+
37
+ ### 1.1 Document the Issue
38
+ ```markdown
39
+ ## Bug Report
40
+
41
+ ### Symptom
42
+ - **What happens**: [exact behavior observed]
43
+ - **Expected**: [what should happen]
44
+ - **Environment**: DEV / PROD
45
+ - **Reproducible**: Always / Sometimes / Once
46
+
47
+ ### Error Messages
48
+ - **Console errors**: [exact text]
49
+ - **Network errors**: [status codes, responses]
50
+ - **Server logs**: [relevant log entries]
51
+
52
+ ### Reproduction Steps
53
+ 1. [Step 1]
54
+ 2. [Step 2]
55
+ 3. [Bug occurs]
56
+ ```
57
+
58
+ ### 1.2 Collect Initial Evidence
59
+ ```bash
60
+ # Recent changes that might be related
61
+ git log --oneline -10
62
+
63
+ # Check for recent file changes in affected area
64
+ git diff HEAD~5 --name-only | grep -E "(component|router|page)"
65
+
66
+ # Check build status
67
+ npm run build 2>&1 | tail -20
68
+
69
+ # Check for type errors
70
+ npx tsc --noEmit 2>&1 | head -30
71
+ ```
72
+
73
+ ---
74
+
75
+ ## PHASE 2: CATEGORIZE & LOAD PATTERNS
76
+
77
+ ### 2.1 Error Category Matrix
78
+
79
+ | Error Type | Likely Cause | Pattern File | First Check |
80
+ |------------|--------------|--------------|-------------|
81
+ | 500 Internal | DB/API error | database-patterns.md | Server logs |
82
+ | 403 Forbidden | RLS/Auth | auth-patterns.md | RLS policies |
83
+ | 401 Unauthorized | Session | auth-patterns.md | Token validity |
84
+ | TypeError | Null/undefined | ui-patterns.md | Null guards |
85
+ | React crash | Component error | ui-patterns.md | Error boundary |
86
+ | Build fail | Import/config | build-patterns.md | tsc output |
87
+ | Network timeout | API/DB slow | database-patterns.md | Query performance |
88
+
89
+ ### 2.2 Load Relevant Patterns
90
+ Based on error category, read the appropriate pattern file and extract:
91
+ - Common causes for this error type
92
+ - Required verification checks
93
+ - Known gotchas from CLAUDE.md
94
+
95
+ ---
96
+
97
+ ## PHASE 3: TRACE THE PATH
98
+
99
+ ### 3.1 UI Layer Investigation
100
+ ```bash
101
+ # Find the component
102
+ grep -rn "[ComponentName]" src/components/ src/app/
103
+
104
+ # Check for event handlers
105
+ grep -A 10 "onClick\|onSubmit\|onChange" [component_file]
106
+
107
+ # Check for API calls
108
+ grep -n "api\.\|useMutation\|useQuery" [component_file]
109
+
110
+ # Check for null guards (CLAUDE.md rule)
111
+ grep -n "?\.\||| \"\"\|?? " [component_file]
112
+ ```
113
+
114
+ ### 3.2 API Layer Investigation
115
+ ```bash
116
+ # Find the router/procedure
117
+ grep -rn "[procedureName]" src/server/api/routers/
118
+
119
+ # Check procedure protection
120
+ grep -B 5 "[procedureName]" src/server/api/routers/ | grep "protected\|public"
121
+
122
+ # Check input validation
123
+ grep -A 15 "[procedureName]:" src/server/api/routers/ | grep -A 10 "input"
124
+
125
+ # Check for CLAUDE.md violations
126
+ grep -n "ctx.prisma\|include:\|ctx.db.users" [router_file]
127
+ ```
128
+
129
+ ### 3.3 Database Layer Investigation
130
+ ```sql
131
+ -- Check table exists
132
+ SELECT tablename FROM pg_tables WHERE schemaname = 'public' AND tablename = '[TABLE]';
133
+
134
+ -- Check column types
135
+ SELECT column_name, data_type, is_nullable
136
+ FROM information_schema.columns
137
+ WHERE table_name = '[TABLE]';
138
+
139
+ -- Check RLS policies
140
+ SELECT polname, polcmd, polroles::text
141
+ FROM pg_policies
142
+ WHERE tablename = '[TABLE]';
143
+
144
+ -- Check grants
145
+ SELECT grantee, privilege_type
146
+ FROM information_schema.table_privileges
147
+ WHERE table_name = '[TABLE]';
148
+
149
+ -- Test query directly
150
+ SELECT * FROM [TABLE] WHERE [condition] LIMIT 5;
151
+ ```
152
+
153
+ ---
154
+
155
+ ## PHASE 4: HYPOTHESIS TESTING
156
+
157
+ ### 4.1 Hypothesis Template
158
+ ```markdown
159
+ ### Hypothesis [N]
160
+
161
+ **Theory**: [What you think is wrong]
162
+ **Evidence Supporting**: [Why you think this]
163
+ **Test**: [How to verify]
164
+ **Result**: [What happened]
165
+ **Verdict**: CONFIRMED / REJECTED
166
+ ```
167
+
168
+ ### 4.2 Common Hypothesis Checklist
169
+
170
+ #### Database Issues
171
+ - [ ] Table exists in all environments?
172
+ - [ ] Column types match Prisma schema?
173
+ - [ ] RLS policies allow this operation?
174
+ - [ ] service_role grants exist?
175
+ - [ ] Using `ctx.db` not `ctx.prisma`?
176
+ - [ ] Using `user_profiles` not `users`?
177
+ - [ ] No `include:` statements (3-step pattern)?
178
+
179
+ #### Auth Issues
180
+ - [ ] Session valid and not expired?
181
+ - [ ] User has required role/permissions?
182
+ - [ ] protectedProcedure used for mutations?
183
+ - [ ] Middleware routing correct?
184
+
185
+ #### UI Issues
186
+ - [ ] Null guards present (`?.` or `|| ""`)?
187
+ - [ ] Loading state handled?
188
+ - [ ] Error state handled?
189
+ - [ ] Mobile responsive (`sm:page-container`)?
190
+ - [ ] No `value=""` in Select.Item?
191
+
192
+ #### Build Issues
193
+ - [ ] All imports resolve?
194
+ - [ ] No circular dependencies?
195
+ - [ ] jsdom dynamically imported?
196
+ - [ ] No client/server boundary violations?
197
+
198
+ ---
199
+
200
+ ## PHASE 5: ROOT CAUSE IDENTIFICATION
201
+
202
+ ### 5.1 Document Root Cause
203
+ ```markdown
204
+ ## Root Cause Analysis
205
+
206
+ ### The Problem
207
+ [Exact technical cause]
208
+
209
+ ### Why It Happened
210
+ [How this bug was introduced]
211
+
212
+ ### CLAUDE.md Violation (If Any)
213
+ - Rule violated: [CR-X or pattern]
214
+ - Correct pattern: [from CLAUDE.md]
215
+
216
+ ### Files Affected
217
+ - [file1:line]
218
+ - [file2:line]
219
+ ```
220
+
221
+ ### 5.2 Verify Root Cause
222
+ ```bash
223
+ # Prove the root cause with VR-* protocol
224
+ # VR-GREP: Show the problematic code
225
+ grep -n "[problematic pattern]" [file]
226
+
227
+ # VR-NEGATIVE: Confirm violation exists
228
+ grep -rn "[violation]" src/ | wc -l
229
+ # Should be > 0 if this is the cause
230
+ ```
231
+
232
+ ---
233
+
234
+ ## PHASE 6: FIX & VERIFY
235
+
236
+ ### 6.1 Apply Fix
237
+ Follow CLAUDE.md patterns exactly:
238
+ - Read relevant pattern file
239
+ - Apply minimal correct fix
240
+ - Do NOT over-engineer
241
+
242
+ ### 6.2 Verify Fix (MANDATORY)
243
+
244
+ ```bash
245
+ # VR-NEGATIVE: Violation removed
246
+ grep -rn "[old_violation]" src/ | wc -l
247
+ # Expected: 0
248
+
249
+ # VR-GREP: Correct pattern present
250
+ grep -n "[correct_pattern]" [file]
251
+ # Expected: Match found
252
+
253
+ # VR-BUILD: Build passes
254
+ npm run build
255
+
256
+ # VR-TYPE: Types pass
257
+ npx tsc --noEmit
258
+
259
+ # Pattern scanner
260
+ ./scripts/pattern-scanner.sh
261
+
262
+ # VR-COUPLING: Backend-frontend sync (CRITICAL - Added Jan 2026)
263
+ ./scripts/check-coupling.sh
264
+ # Expected: Exit 0 - all backend features exposed in UI
265
+ ```
266
+
267
+ ### 6.3 Environment Verification
268
+ If DB-related, verify fix in all environments:
269
+ ```sql
270
+ -- Run same query that was failing
271
+ -- Verify it now succeeds
272
+ ```
273
+
274
+ ---
275
+
276
+ ## PHASE 7: REGRESSION CHECK
277
+
278
+ ### 7.1 Related Functionality
279
+ ```bash
280
+ # Find all uses of modified code
281
+ grep -rn "[modified_function]" src/
282
+
283
+ # Check for other places with same pattern
284
+ grep -rn "[similar_pattern]" src/
285
+ ```
286
+
287
+ ### 7.2 Test User Flow
288
+ Verify the original user flow now works:
289
+ ```markdown
290
+ | Step | Action | Expected | Actual | Status |
291
+ |------|--------|----------|--------|--------|
292
+ | 1 | [action] | [expected] | [actual] | PASS |
293
+ | 2 | [action] | [expected] | [actual] | PASS |
294
+ ```