@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
@@ -0,0 +1,469 @@
1
+ ---
2
+ name: massu-type-mismatch-audit
3
+ description: "When user says 'type audit', 'type mismatch', 'check types', or suspects type inconsistencies between frontend, backend, and database columns"
4
+ allowed-tools: Bash(*), Read(*), Grep(*), Glob(*), Task(*)
5
+ disable-model-invocation: true
6
+ ---
7
+ name: massu-type-mismatch-audit
8
+
9
+ > **Shared rules apply.** Read `.claude/commands/_shared-preamble.md` before proceeding. CR-14, CR-5, CR-12 enforced.
10
+
11
+ # Massu Type Mismatch Audit: Comprehensive Type Safety Verification
12
+
13
+ ## Objective
14
+
15
+ Audit the ENTIRE codebase for type mismatches between:
16
+ 1. Frontend form schemas and backend router schemas
17
+ 2. Backend code and database column types
18
+ 3. `as any` casts hiding real type issues in API calls
19
+ 4. Array vs string mismatches on array-type database columns
20
+ 5. Number/date/boolean coercion gaps in form submissions
21
+ 6. Return type mismatches (serialization, BigInt, Decimal)
22
+
23
+ **This audit catches bugs that TypeScript CANNOT catch** - runtime Zod validation failures, database insert failures from wrong column types, and `as any` casts that hide structural mismatches.
24
+
25
+ ---
26
+
27
+ ## NON-NEGOTIABLE RULES
28
+
29
+ - **Trace the full path** - Frontend form -> API call -> Zod schema -> DB column
30
+ - **Verify against DB schema** - ALWAYS query `information_schema` for column types
31
+ - **`as any` = suspect** - Every `as any` in an API call context is a potential hidden mismatch
32
+ - **Array columns are special** - `text[]` columns MUST receive arrays, not strings
33
+ - **Show proof** - Every finding must include file:line and the exact mismatch
34
+
35
+ ---
36
+
37
+ ## ZERO-GAP AUDIT LOOP
38
+
39
+ **Type mismatch audit does NOT complete until a SINGLE COMPLETE AUDIT finds ZERO new issues.**
40
+
41
+ ```
42
+ TYPE MISMATCH AUDIT LOOP:
43
+ 1. Run ALL 8 audit sections
44
+ 2. Count total mismatches found
45
+ 3. IF mismatches > 0:
46
+ - Document ALL mismatches in plan file
47
+ - Fix ALL mismatches
48
+ - Re-run ENTIRE audit from Section 1
49
+ 4. IF mismatches == 0:
50
+ - TYPE SAFETY VERIFIED
51
+ ```
52
+
53
+ ---
54
+
55
+ ## ARGUMENTS
56
+
57
+ This command accepts an optional scope argument:
58
+
59
+ - No argument: Full codebase audit (all 8 sections)
60
+ - `[router-name]`: Audit a specific router and its frontend consumers
61
+
62
+ ---
63
+
64
+ ## SECTION 1: DATABASE ARRAY COLUMN INVENTORY
65
+
66
+ **Goal**: Identify ALL array-type columns and verify code sends arrays (not strings) to them.
67
+
68
+ ### 1.1 Query Array Columns from Prisma Schema
69
+ ```bash
70
+ # Find all array fields in Prisma schema
71
+ grep -n "\[\]" prisma/schema.prisma | grep -v "//"
72
+ ```
73
+
74
+ ### 1.2 Query Array Columns from Database
75
+ ```sql
76
+ -- Run on database
77
+ SELECT table_name, column_name, data_type, column_default
78
+ FROM information_schema.columns
79
+ WHERE data_type = 'ARRAY'
80
+ AND table_schema = 'public'
81
+ ORDER BY table_name, column_name;
82
+ ```
83
+
84
+ ### 1.3 For EACH Array Column, Verify All Writes
85
+
86
+ For every array column found, search for all places that SET that column:
87
+
88
+ ```bash
89
+ # Pattern: find all assignments to this column in create/update operations
90
+ grep -rn "column_name:" src/server/api/routers/ | grep -v "where\|orderBy\|select"
91
+ ```
92
+
93
+ **CHECK**: Is the value being assigned actually an array? Or a single string/number?
94
+
95
+ ### 1.4 Array Column Verification Matrix
96
+
97
+ ```markdown
98
+ | Table | Column | DB Type | Code Sends | Mismatch? | File:Line |
99
+ |-------|--------|---------|------------|-----------|-----------|
100
+ | tasks | department | text[] | ['admin'] | NO | tasks.ts:30 |
101
+ | tasks | department | text[] | 'admin' | YES - BUG | tasks.ts:922 |
102
+ ```
103
+
104
+ ---
105
+
106
+ ## SECTION 2: FRONTEND-BACKEND ZOD SCHEMA COMPARISON
107
+
108
+ **Goal**: Compare Zod schemas in frontend forms against backend router input schemas for the SAME procedure.
109
+
110
+ ### 2.1 Inventory All Frontend Form Schemas
111
+
112
+ ```bash
113
+ # Find all Zod schemas in components and app pages
114
+ grep -rn "z\.object(" src/components/ src/app/ | grep -v node_modules | grep -v "server/"
115
+ ```
116
+
117
+ ### 2.2 Inventory All Backend Input Schemas
118
+
119
+ ```bash
120
+ # Find all .input() schemas in routers
121
+ grep -rn "\.input(z\.\|\.input(" src/server/api/routers/
122
+ ```
123
+
124
+ ### 2.3 Match Frontend to Backend
125
+
126
+ For each frontend form that calls a mutation:
127
+ 1. Find the mutation call: `api.[router].[procedure].useMutation`
128
+ 2. Find the corresponding backend `.input()` schema
129
+ 3. Compare field-by-field:
130
+ - Same field names?
131
+ - Same types? (string vs array, number vs string, enum values match?)
132
+ - Same optionality? (required vs optional)
133
+
134
+ ### 2.4 Schema Comparison Matrix
135
+
136
+ ```markdown
137
+ | Frontend File | Backend Router | Procedure | Field | Frontend Type | Backend Type | Match? |
138
+ |---------------|---------------|-----------|-------|---------------|--------------|--------|
139
+ | NewTaskSheet.tsx | tasks.ts | create | department | z.enum() | z.array(z.enum()) | NO |
140
+ ```
141
+
142
+ ---
143
+
144
+ ## SECTION 3: `as any` CAST AUDIT
145
+
146
+ **Goal**: Find ALL `as any` casts in API call contexts and determine if they hide real type mismatches.
147
+
148
+ ### 3.1 Find All `as any` in API Calls
149
+
150
+ ```bash
151
+ # as any near mutateAsync/mutate calls
152
+ grep -rn "as any" src/components/ src/app/ | grep -v node_modules | grep -v "\.d\.ts"
153
+ ```
154
+
155
+ ### 3.2 Categorize Each Cast
156
+
157
+ For each `as any` found, determine:
158
+
159
+ | Category | Risk | Action |
160
+ |----------|------|--------|
161
+ | **Structural mismatch** (string sent where array expected) | P0 - CRASH | Fix immediately |
162
+ | **Enum narrowing** (string sent where union expected) | P1 - Type safety | Type the state properly |
163
+ | **Return type access** (`(result as any).field`) | P1 - Type safety | Fix return type |
164
+ | **Cosmetic** (types match at runtime, cast for convenience) | P2 - Cleanup | Remove cast |
165
+
166
+ ### 3.3 `as any` Audit Matrix
167
+
168
+ ```markdown
169
+ | File:Line | Context | What's Cast | Category | Risk | Fix |
170
+ |-----------|---------|-------------|----------|------|-----|
171
+ | NewTaskSheet.tsx:151 | mutateAsync arg | department: string -> array | Structural | P0 | Wrap in [] |
172
+ ```
173
+
174
+ ---
175
+
176
+ ## SECTION 4: NUMBER/DATE/BOOLEAN COERCION AUDIT
177
+
178
+ **Goal**: Verify all form fields are properly converted before sending to API.
179
+
180
+ ### 4.1 Number Fields
181
+
182
+ ```bash
183
+ # Find number inputs in forms
184
+ grep -rn 'type="number"\|type={"number"}\|amount\|price\|quantity\|hours\|weight' src/components/ src/app/ | grep -v node_modules
185
+ ```
186
+
187
+ For each, verify:
188
+ - Is `parseFloat()` or `parseInt()` called before the API call?
189
+ - Does the backend expect `z.number()` or `z.string()`?
190
+ - Could the conversion produce `NaN`? Is that handled?
191
+
192
+ ### 4.2 Date Fields
193
+
194
+ ```bash
195
+ # Find date fields
196
+ grep -rn "DatePicker\|type=\"date\"\|toISOString\|due_date\|start_date\|end_date" src/components/ src/app/ | grep -v node_modules
197
+ ```
198
+
199
+ For each, verify:
200
+ - Is the date converted to ISO string before the API call?
201
+ - Does the backend expect `z.string().datetime()` or `z.date()`?
202
+ - Are null dates handled? (`undefined` vs `null` vs empty string)
203
+
204
+ ### 4.3 Boolean Fields
205
+
206
+ ```bash
207
+ # Find boolean/toggle fields
208
+ grep -rn "is_active\|enabled\|checked\|toggle\|Switch\|Checkbox" src/components/ src/app/ | grep -v node_modules | head -30
209
+ ```
210
+
211
+ For each, verify:
212
+ - Is a string `"true"/"false"` being sent where boolean is expected?
213
+ - Are checkbox values properly typed?
214
+
215
+ ### 4.4 Coercion Audit Matrix
216
+
217
+ ```markdown
218
+ | File:Line | Field | Form Type | API Type | Conversion | OK? |
219
+ |-----------|-------|-----------|----------|------------|-----|
220
+ | new/page.tsx:125 | estimated_hours | string (input) | z.number() | parseFloat() | YES |
221
+ ```
222
+
223
+ ---
224
+
225
+ ## SECTION 5: RETURN TYPE / SERIALIZATION AUDIT
226
+
227
+ **Goal**: Verify API responses can be serialized (no BigInt, Decimal, or circular references).
228
+
229
+ ### 5.1 BigInt Serialization
230
+
231
+ ```bash
232
+ # Find BigInt usage
233
+ grep -rn "BigInt\|bigint" src/server/api/routers/
234
+ ```
235
+
236
+ Verify: Are BigInt values converted to `Number()` before return?
237
+
238
+ ### 5.2 Decimal Serialization
239
+
240
+ ```bash
241
+ # Find Decimal usage (Prisma)
242
+ grep -rn "Decimal\|decimal\|convertDecimalToNumber" src/server/api/routers/
243
+ ```
244
+
245
+ Verify: Are Decimal columns converted before return?
246
+
247
+ ### 5.3 Date Serialization
248
+
249
+ ```bash
250
+ # Find Date returns
251
+ grep -rn "new Date()\|Date.now()" src/server/api/routers/
252
+ ```
253
+
254
+ Verify: Are dates returned as ISO strings (not Date objects)?
255
+
256
+ ---
257
+
258
+ ## SECTION 6: ENUM VALUE ALIGNMENT
259
+
260
+ **Goal**: Verify enum values in frontend match enum values in backend and database.
261
+
262
+ ### 6.1 Find All Enum Definitions
263
+
264
+ ```bash
265
+ # Backend enums
266
+ grep -rn "z\.enum(\[" src/server/api/routers/ | head -40
267
+
268
+ # Frontend enums
269
+ grep -rn "z\.enum(\[" src/components/ src/app/ | head -40
270
+ ```
271
+
272
+ ### 6.2 Compare Enum Values
273
+
274
+ For each enum field used in both frontend and backend:
275
+ - Do the allowed values match exactly?
276
+ - Is the frontend using a value that the backend doesn't accept?
277
+ - Has a new enum value been added to the backend but not the frontend (or vice versa)?
278
+
279
+ ---
280
+
281
+ ## SECTION 7: QUERY PARAMETER TYPE VERIFICATION
282
+
283
+ **Goal**: Verify filter/query parameters match between frontend and backend.
284
+
285
+ ### 7.1 Find All useQuery Calls with Parameters
286
+
287
+ ```bash
288
+ # Find parameterized queries
289
+ grep -rn "useQuery(" src/components/ src/app/ | grep -v "enabled\|refetch" | head -30
290
+ ```
291
+
292
+ ### 7.2 Compare Query Inputs
293
+
294
+ For each useQuery with parameters:
295
+ - Does the frontend send the correct types?
296
+ - Are enum filters typed properly (not `string`)?
297
+ - Are UUID parameters validated?
298
+ - Are pagination params (limit, offset) numbers (not strings)?
299
+
300
+ ---
301
+
302
+ ## SECTION 8: RECURRING PATTERN DETECTION
303
+
304
+ **Goal**: Find systematic patterns of type mismatches that affect multiple files.
305
+
306
+ ### 8.1 Structural Cast Patterns
307
+
308
+ ```bash
309
+ # Find the currentUser as any pattern
310
+ grep -rn "(currentUser as any)" src/
311
+ grep -rn "(data\?\.entity as any)" src/
312
+ ```
313
+
314
+ **These indicate a missing return type** on the procedure. Fix at the source (add return type) to fix all consumers.
315
+
316
+ ### 8.2 `useState<string>` for Enum Filters
317
+
318
+ ```bash
319
+ # Find string state used for enum filters
320
+ grep -rn "useState<string>" src/app/ src/components/ | grep -i "filter\|status\|type\|category"
321
+ ```
322
+
323
+ **These should be typed as the proper union** to eliminate `as any` at the call site.
324
+
325
+ ### 8.3 Missing `.transform()` or `.preprocess()` in Schemas
326
+
327
+ ```bash
328
+ # Find schemas that might need transforms
329
+ grep -rn "z\.preprocess\|z\.transform\|z\.coerce" src/server/api/routers/
330
+ ```
331
+
332
+ ---
333
+
334
+ ## OUTPUT FORMAT
335
+
336
+ ### Type Mismatch Audit Report
337
+
338
+ ```markdown
339
+ ## MASSU TYPE MISMATCH AUDIT REPORT
340
+
341
+ ### Date: [timestamp]
342
+ ### Scope: [Full / Specific router]
343
+
344
+ ### Summary
345
+
346
+ | Section | Issues Found | P0 | P1 | P2 |
347
+ |---------|-------------|----|----|-----|
348
+ | 1. Array columns | N | N | N | N |
349
+ | 2. Schema comparison | N | N | N | N |
350
+ | 3. as any casts | N | N | N | N |
351
+ | 4. Coercion gaps | N | N | N | N |
352
+ | 5. Serialization | N | N | N | N |
353
+ | 6. Enum alignment | N | N | N | N |
354
+ | 7. Query parameters | N | N | N | N |
355
+ | 8. Recurring patterns | N | N | N | N |
356
+ | **TOTAL** | **N** | **N** | **N** | **N** |
357
+
358
+ ### P0 Issues (Runtime Crashes)
359
+
360
+ | # | File:Line | Issue | Fix |
361
+ |---|-----------|-------|-----|
362
+ | 1 | [file:line] | [string sent to array column] | [wrap in array] |
363
+
364
+ ### P1 Issues (Type Safety)
365
+
366
+ | # | File:Line | Issue | Fix |
367
+ |---|-----------|-------|-----|
368
+ | 1 | [file:line] | [as any hiding mismatch] | [type state properly] |
369
+
370
+ ### P2 Issues (Cleanup)
371
+
372
+ | # | File:Line | Issue | Fix |
373
+ |---|-----------|-------|-----|
374
+ | 1 | [file:line] | [unnecessary cast] | [remove as any] |
375
+
376
+ ### Verified Correct (No Issues)
377
+
378
+ - [Area]: [description of what was checked and passed]
379
+
380
+ ### TYPE MISMATCH AUDIT STATUS: PASS / FAIL
381
+ ```
382
+
383
+ ---
384
+
385
+ ## SESSION STATE UPDATE
386
+
387
+ After audit, update `session-state/CURRENT.md`:
388
+
389
+ ```markdown
390
+ ## TYPE MISMATCH AUDIT SESSION
391
+
392
+ ### Audit
393
+ - **Date**: [timestamp]
394
+ - **Scope**: Full / [specific area]
395
+
396
+ ### Findings
397
+ - P0 (crashes): [N]
398
+ - P1 (type safety): [N]
399
+ - P2 (cleanup): [N]
400
+ - Total: [N]
401
+
402
+ ### Fixes Applied
403
+ [List or "None - audit only, plan saved for review"]
404
+
405
+ ### Status
406
+ - Build: PASS/FAIL
407
+ - Type check: PASS/FAIL
408
+ ```
409
+
410
+ ---
411
+
412
+ ## WHEN TO RUN
413
+
414
+ - After ANY schema migration (new columns, type changes)
415
+ - After adding new API procedures
416
+ - After adding new form components
417
+ - Before major releases
418
+ - When debugging "Expected X, received Y" Zod errors
419
+ - When debugging 400/500 errors on form submissions
420
+ - As part of periodic codebase audits
421
+
422
+ ---
423
+
424
+ ## SUBAGENT STRATEGY
425
+
426
+ For a full codebase audit, use parallel subagents to maximize coverage:
427
+
428
+ 1. **Subagent 1**: Sections 1-2 (Array columns + Schema comparison)
429
+ 2. **Subagent 2**: Sections 3-4 (`as any` casts + Coercion)
430
+ 3. **Subagent 3**: Sections 5-6 (Serialization + Enum alignment)
431
+ 4. **Subagent 4**: Sections 7-8 (Query params + Recurring patterns)
432
+
433
+ Merge results into single report.
434
+
435
+ ---
436
+
437
+ ## AUTO-LEARNING PROTOCOL (MANDATORY after every fix/finding)
438
+
439
+ **After EVERY fix or finding, the system MUST automatically learn. This is NOT optional.**
440
+
441
+ ### Step 1: Ingest into Memory
442
+ Use `massu_memory_ingest` with type="bugfix"|"pattern", description of what was found/fixed, affected files, and importance (5=security/data, 3=build/type, 2=cosmetic).
443
+
444
+ ### Step 2: Record Correct vs Incorrect Pattern
445
+ Update `memory/MEMORY.md` with the WRONG vs CORRECT pattern discovered.
446
+
447
+ ### Step 3: Add to Pattern Scanner (if grep-able)
448
+ If the bad pattern is detectable by grep, add check to pattern scanner.
449
+
450
+ ### Step 4: Search Codebase-Wide (CR-9)
451
+ `grep -rn "[bad_pattern]" src/` - fix ALL instances of the same issue.
452
+
453
+ ---
454
+
455
+ ## START NOW
456
+
457
+ 1. Query database for ALL array columns (Section 1)
458
+ 2. Inventory frontend form schemas (Section 2)
459
+ 3. Find ALL `as any` in API contexts (Section 3)
460
+ 4. Check number/date/boolean coercion (Section 4)
461
+ 5. Verify serialization safety (Section 5)
462
+ 6. Compare enum values (Section 6)
463
+ 7. Check query parameter types (Section 7)
464
+ 8. Detect recurring patterns (Section 8)
465
+ 9. Produce Type Mismatch Audit Report
466
+ 10. Save fix plan if issues found
467
+ 11. Update session state
468
+
469
+ **Remember: `as any` is a red flag, not a solution. Every cast hides a potential runtime crash.**