@massu/core 0.1.2 → 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.
Files changed (84) hide show
  1. package/commands/_shared-preamble.md +76 -0
  2. package/commands/massu-audit-deps.md +211 -0
  3. package/commands/massu-changelog.md +174 -0
  4. package/commands/massu-cleanup.md +315 -0
  5. package/commands/massu-commit.md +481 -0
  6. package/commands/massu-create-plan.md +752 -0
  7. package/commands/massu-dead-code.md +131 -0
  8. package/commands/massu-debug.md +484 -0
  9. package/commands/massu-deploy.md +91 -0
  10. package/commands/massu-deps.md +374 -0
  11. package/commands/massu-doc-gen.md +279 -0
  12. package/commands/massu-docs.md +364 -0
  13. package/commands/massu-estimate.md +313 -0
  14. package/commands/massu-golden-path.md +973 -0
  15. package/commands/massu-guide.md +167 -0
  16. package/commands/massu-hotfix.md +480 -0
  17. package/commands/massu-loop-playwright.md +837 -0
  18. package/commands/massu-loop.md +775 -0
  19. package/commands/massu-new-feature.md +511 -0
  20. package/commands/massu-parity.md +214 -0
  21. package/commands/massu-plan.md +456 -0
  22. package/commands/massu-push-light.md +207 -0
  23. package/commands/massu-push.md +434 -0
  24. package/commands/massu-refactor.md +410 -0
  25. package/commands/massu-release.md +363 -0
  26. package/commands/massu-review.md +238 -0
  27. package/commands/massu-simplify.md +281 -0
  28. package/commands/massu-status.md +278 -0
  29. package/commands/massu-tdd.md +201 -0
  30. package/commands/massu-test.md +516 -0
  31. package/commands/massu-verify-playwright.md +281 -0
  32. package/commands/massu-verify.md +667 -0
  33. package/dist/cli.js +12522 -0
  34. package/dist/hooks/cost-tracker.js +80 -5
  35. package/dist/hooks/post-edit-context.js +72 -6
  36. package/dist/hooks/post-tool-use.js +234 -57
  37. package/dist/hooks/pre-compact.js +144 -5
  38. package/dist/hooks/pre-delete-check.js +141 -11
  39. package/dist/hooks/quality-event.js +80 -5
  40. package/dist/hooks/security-gate.js +29 -0
  41. package/dist/hooks/session-end.js +83 -8
  42. package/dist/hooks/session-start.js +153 -7
  43. package/dist/hooks/user-prompt.js +166 -5
  44. package/package.json +6 -5
  45. package/src/backfill-sessions.ts +5 -4
  46. package/src/cli.ts +6 -0
  47. package/src/commands/doctor.ts +193 -6
  48. package/src/commands/init.ts +235 -6
  49. package/src/commands/install-commands.ts +137 -0
  50. package/src/config.ts +68 -2
  51. package/src/db.ts +115 -2
  52. package/src/docs-tools.ts +8 -6
  53. package/src/hooks/post-edit-context.ts +1 -1
  54. package/src/hooks/post-tool-use.ts +130 -0
  55. package/src/hooks/pre-compact.ts +23 -1
  56. package/src/hooks/pre-delete-check.ts +92 -4
  57. package/src/hooks/security-gate.ts +32 -0
  58. package/src/hooks/session-start.ts +97 -4
  59. package/src/hooks/user-prompt.ts +46 -1
  60. package/src/import-resolver.ts +2 -1
  61. package/src/knowledge-db.ts +169 -0
  62. package/src/knowledge-indexer.ts +704 -0
  63. package/src/knowledge-tools.ts +1413 -0
  64. package/src/license.ts +482 -0
  65. package/src/memory-db.ts +14 -1
  66. package/src/observation-extractor.ts +11 -4
  67. package/src/page-deps.ts +3 -2
  68. package/src/python/coupling-detector.ts +124 -0
  69. package/src/python/domain-enforcer.ts +83 -0
  70. package/src/python/impact-analyzer.ts +95 -0
  71. package/src/python/import-parser.ts +244 -0
  72. package/src/python/import-resolver.ts +135 -0
  73. package/src/python/migration-indexer.ts +115 -0
  74. package/src/python/migration-parser.ts +332 -0
  75. package/src/python/model-indexer.ts +70 -0
  76. package/src/python/model-parser.ts +279 -0
  77. package/src/python/route-indexer.ts +58 -0
  78. package/src/python/route-parser.ts +317 -0
  79. package/src/python-tools.ts +629 -0
  80. package/src/sentinel-db.ts +2 -1
  81. package/src/server.ts +29 -6
  82. package/src/session-archiver.ts +4 -5
  83. package/src/tools.ts +283 -31
  84. package/README.md +0 -40
@@ -0,0 +1,410 @@
1
+ ---
2
+ name: massu-refactor
3
+ description: Safe refactoring with behavioral equivalence, incremental transforms, and automatic rollback
4
+ allowed-tools: Bash(*), Read(*), Write(*), Edit(*), Grep(*), Glob(*)
5
+ ---
6
+ name: massu-refactor
7
+
8
+ > **Shared rules apply.** Read `.claude/commands/_shared-preamble.md` before proceeding. CR-9, CR-35 enforced.
9
+
10
+ # CS Refactor: Safe Refactoring Workflow
11
+
12
+ ## Objective
13
+
14
+ Restructure code safely, ensuring behavioral equivalence at every step. Changes are applied incrementally with verification after each batch. If behavioral equivalence cannot be maintained, the refactoring is aborted.
15
+
16
+ **Usage**: `/massu-refactor [description of the refactoring]`
17
+
18
+ ## Workflow Position
19
+
20
+ ```
21
+ /massu-create-plan -> /massu-plan -> /massu-refactor -> /massu-commit -> /massu-push
22
+ (PLAN) (AUDIT PLAN) (EXECUTE REFACTOR) (COMMIT) (PUSH)
23
+ ```
24
+
25
+ ---
26
+
27
+ ## NON-NEGOTIABLE RULES
28
+
29
+ - **Behavioral equivalence is MANDATORY** — tests passing before MUST still pass after
30
+ - **Incremental batches only** — max 3 files per batch, verify after each
31
+ - **Never skip verification** — every batch gets type check + test run
32
+ - **Revert on regression** — if a batch breaks tests, revert it before continuing
33
+ - **FIX ALL ISSUES ENCOUNTERED (CR-9)** — pre-existing issues found during refactoring MUST be fixed
34
+ - **Proof > reasoning. Commands > assumptions.**
35
+
36
+ ---
37
+
38
+ ## SCOPE GUARD (MANDATORY)
39
+
40
+ **This command is for MEDIUM refactorings. If ANY of these are true, ABORT:**
41
+
42
+ | Condition | Why It's Too Big | Alternative |
43
+ |-----------|-----------------|-------------|
44
+ | Refactoring touches > 20 files | Needs structured plan | `/massu-create-plan` |
45
+ | Changes database schema | Needs migration workflow | `/massu-internal-migrate` |
46
+ | Changes public API contracts | Needs blast radius plan | `/massu-create-plan` |
47
+ | Renames MCP tool names | Affects all consumers | `/massu-create-plan` |
48
+ | Changes config interface fields | Affects all config users | `/massu-create-plan` |
49
+
50
+ ```
51
+ SCOPE CHECK:
52
+ 1. Read the target code
53
+ 2. Grep for all references to exports/functions/types being changed
54
+ 3. Count affected files
55
+ 4. IF affected_files > 20:
56
+ OUTPUT: "Refactoring scope is too large ([N] files). Use /massu-create-plan instead."
57
+ ABORT
58
+ 5. IF changes database schema:
59
+ OUTPUT: "Refactoring involves schema changes. Use /massu-internal-migrate instead."
60
+ ABORT
61
+ 6. IF changes public API contracts:
62
+ OUTPUT: "Refactoring changes public API. Use /massu-create-plan for blast radius analysis."
63
+ ABORT
64
+ ```
65
+
66
+ ---
67
+
68
+ ## STEP 1: SCOPE ANALYSIS
69
+
70
+ ### 1a. Read Target Code
71
+
72
+ Read every file that will be modified to understand current structure:
73
+
74
+ ```bash
75
+ # Read the primary target file(s)
76
+ # Read all files that import from or reference the target
77
+ ```
78
+
79
+ ### 1b. Reference Analysis
80
+
81
+ For each export, function, type, or constant being changed:
82
+
83
+ ```bash
84
+ # Find all references in the codebase
85
+ grep -rn "[export_name]" packages/core/src/ --include="*.ts"
86
+ grep -rn "[export_name]" packages/ --include="*.ts" --include="*.tsx"
87
+ grep -rn "[export_name]" .claude/commands/ --include="*.md"
88
+ grep -rn "[export_name]" scripts/ --include="*.sh"
89
+ ```
90
+
91
+ ### 1c. Impact Matrix
92
+
93
+ ```markdown
94
+ ### Impact Matrix
95
+
96
+ | File | References | Type | Action |
97
+ |------|-----------|------|--------|
98
+ | [file_1] | [function/type names] | CHANGE | [what changes] |
99
+ | [file_2] | [function/type names] | CHANGE | [what changes] |
100
+ | [file_3] | [function/type names] | KEEP | [why no change needed] |
101
+
102
+ **Total files affected: [N]**
103
+ **Scope check: [PASS if <= 20 / ABORT if > 20]**
104
+ ```
105
+
106
+ ---
107
+
108
+ ## STEP 2: BASELINE SNAPSHOT
109
+
110
+ Capture the behavioral baseline BEFORE making any changes:
111
+
112
+ ### 2a. Test Baseline
113
+
114
+ ```bash
115
+ npm test 2>&1
116
+ ```
117
+
118
+ Record:
119
+ ```markdown
120
+ ### Test Baseline
121
+ | Metric | Value |
122
+ |--------|-------|
123
+ | Total tests | [N] |
124
+ | Passing | [N] |
125
+ | Failing | [N] |
126
+ | Skipped | [N] |
127
+ ```
128
+
129
+ ### 2b. Type Check Baseline
130
+
131
+ ```bash
132
+ cd packages/core && npx tsc --noEmit 2>&1
133
+ ```
134
+
135
+ Record:
136
+ ```markdown
137
+ ### Type Check Baseline
138
+ | Metric | Value |
139
+ |--------|-------|
140
+ | Type errors | [N] |
141
+ ```
142
+
143
+ **This baseline is the behavioral contract. After refactoring:**
144
+ - Test count MUST be >= baseline (can add tests, not lose them)
145
+ - Passing count MUST be >= baseline
146
+ - Type error count MUST be <= baseline (can fix errors, not add them)
147
+
148
+ ---
149
+
150
+ ## STEP 3: BLAST RADIUS ANALYSIS (CR-10)
151
+
152
+ **For EVERY export, function, type, or constant being renamed or moved:**
153
+
154
+ ```bash
155
+ # Grep entire codebase for the old name
156
+ grep -rn "[old_name]" packages/ website/ scripts/ .claude/ --include="*.ts" --include="*.tsx" --include="*.md" --include="*.sh" --include="*.yaml"
157
+ ```
158
+
159
+ ### Categorize Every Occurrence
160
+
161
+ ```markdown
162
+ ### Blast Radius — [old_name] → [new_name]
163
+
164
+ | File:Line | Occurrence | Category | Reason |
165
+ |-----------|-----------|----------|--------|
166
+ | [file:NN] | [context] | CHANGE | Will be updated |
167
+ | [file:NN] | [context] | KEEP | [reason — e.g., string literal, comment, different variable] |
168
+ ```
169
+
170
+ **Requirements:**
171
+ - Zero INVESTIGATE items — every occurrence must be categorized as CHANGE or KEEP
172
+ - Every CHANGE item must be tracked in the transformation plan
173
+ - If any occurrence cannot be categorized, STOP and investigate before proceeding
174
+
175
+ ---
176
+
177
+ ## STEP 4: INCREMENTAL TRANSFORMATION
178
+
179
+ Apply changes in small batches. **Maximum 3 files per batch.**
180
+
181
+ ```
182
+ TRANSFORMATION LOOP:
183
+ batch_number = 1
184
+ WHILE files_remaining > 0:
185
+ 1. Select next batch (max 3 files)
186
+ 2. Apply changes to batch
187
+ 3. Run type check:
188
+ cd packages/core && npx tsc --noEmit 2>&1
189
+ 4. Run tests:
190
+ npm test 2>&1
191
+ 5. Compare against baseline:
192
+ - Type errors must be <= baseline
193
+ - Passing tests must be >= baseline
194
+ 6. IF check degrades from baseline:
195
+ - REVERT the batch: git checkout -- [batch files]
196
+ - Investigate why the batch caused regression
197
+ - Fix the approach and retry (max 3 retries per batch)
198
+ 7. IF check maintains or improves baseline:
199
+ - Record batch as successful
200
+ - Proceed to next batch
201
+ batch_number++
202
+ ```
203
+
204
+ ### Batch Record
205
+
206
+ ```markdown
207
+ ### Batch [N]: [description]
208
+
209
+ | File | Change |
210
+ |------|--------|
211
+ | [file_1] | [what was changed] |
212
+ | [file_2] | [what was changed] |
213
+
214
+ | Check | Before | After | Status |
215
+ |-------|--------|-------|--------|
216
+ | Type errors | [N] | [N] | EQUIVALENT/IMPROVED |
217
+ | Tests passing | [N] | [N] | EQUIVALENT/IMPROVED |
218
+ ```
219
+
220
+ ---
221
+
222
+ ## STEP 5: NEGATIVE VERIFICATION
223
+
224
+ **For every renamed or removed export, function, type, or constant:**
225
+
226
+ ```bash
227
+ # Verify old name no longer exists in source
228
+ grep -rn "[old_name]" packages/core/src/ --include="*.ts"
229
+ # MUST return 0 matches
230
+ ```
231
+
232
+ **For moved files:**
233
+
234
+ ```bash
235
+ # Verify old file no longer exists
236
+ ls [old_file_path]
237
+ # MUST fail (file should not exist)
238
+ ```
239
+
240
+ ```markdown
241
+ ### Negative Verification
242
+
243
+ | Old Name/Path | Grep Result | Status |
244
+ |--------------|-------------|--------|
245
+ | [old_name] | 0 matches | CLEAN |
246
+ | [old_path] | File not found | CLEAN |
247
+ ```
248
+
249
+ **If ANY old reference remains:** Fix it before proceeding.
250
+
251
+ ---
252
+
253
+ ## STEP 6: FINAL VERIFICATION
254
+
255
+ Run the full gate sequence:
256
+
257
+ ### Gate 1: Pattern Scanner (VR-PATTERN)
258
+ ```bash
259
+ bash scripts/massu-pattern-scanner.sh
260
+ # MUST exit 0
261
+ ```
262
+
263
+ ### Gate 2: Type Check (VR-TYPE)
264
+ ```bash
265
+ cd packages/core && npx tsc --noEmit
266
+ # MUST show 0 errors (or <= baseline)
267
+ ```
268
+
269
+ ### Gate 3: All Tests (VR-TEST)
270
+ ```bash
271
+ npm test
272
+ # MUST exit 0, all tests pass
273
+ ```
274
+
275
+ ### Gate 4: Hook Build (VR-HOOK-BUILD)
276
+ ```bash
277
+ cd packages/core && npm run build:hooks
278
+ # MUST exit 0
279
+ ```
280
+
281
+ ### Compare Against Baseline
282
+
283
+ ```markdown
284
+ ### Baseline Comparison
285
+
286
+ | Metric | Before | After | Delta | Status |
287
+ |--------|--------|-------|-------|--------|
288
+ | Tests passing | [N] | [N] | [+/-N] | EQUIVALENT/IMPROVED |
289
+ | Tests total | [N] | [N] | [+/-N] | EQUIVALENT/IMPROVED |
290
+ | Type errors | [N] | [N] | [+/-N] | EQUIVALENT/IMPROVED |
291
+ | Pattern violations | [N] | [N] | [+/-N] | EQUIVALENT/IMPROVED |
292
+ ```
293
+
294
+ ---
295
+
296
+ ## STEP 7: BEHAVIORAL EQUIVALENCE PROOF
297
+
298
+ Generate the formal proof table:
299
+
300
+ ```markdown
301
+ ### Behavioral Equivalence Proof
302
+
303
+ | Metric | Before | After | Delta | Status |
304
+ |--------|--------|-------|-------|--------|
305
+ | Tests passing | [N] | [N] | 0 | EQUIVALENT |
306
+ | Tests total | [N] | [N] | 0 | EQUIVALENT |
307
+ | Type errors | [N] | [N] | 0 | EQUIVALENT |
308
+ | Pattern violations | 0 | 0 | 0 | EQUIVALENT |
309
+ | Hook build | Exit 0 | Exit 0 | - | EQUIVALENT |
310
+
311
+ **BEHAVIORAL EQUIVALENCE: PROVEN / NOT PROVEN**
312
+ ```
313
+
314
+ **If NOT PROVEN:** Document the delta and determine if it's acceptable (e.g., test count increased because new tests were added — this is an IMPROVEMENT, not a regression).
315
+
316
+ ---
317
+
318
+ ## ABORT PROTOCOL
319
+
320
+ **If at any point the refactoring causes test regressions that cannot be resolved within 3 attempts per batch:**
321
+
322
+ ```bash
323
+ # Revert ALL uncommitted changes
324
+ git checkout -- .
325
+ ```
326
+
327
+ ```markdown
328
+ ### REFACTORING ABORTED
329
+
330
+ - **Reason**: [why the refactoring failed]
331
+ - **Batch that failed**: [batch N]
332
+ - **Error**: [what went wrong]
333
+ - **Files reverted**: ALL uncommitted changes
334
+ - **Recommendation**: [suggest /massu-create-plan with specific details about what needs careful planning]
335
+ ```
336
+
337
+ ---
338
+
339
+ ## MANDATORY PLAN DOCUMENT UPDATE (If Refactor From Plan)
340
+
341
+ **If this refactoring was part of a plan, update the plan document with completion status.**
342
+
343
+ ```markdown
344
+ # IMPLEMENTATION STATUS
345
+
346
+ **Plan**: [Plan Name]
347
+ **Status**: REFACTOR COMPLETE
348
+ **Last Updated**: [YYYY-MM-DD HH:MM]
349
+
350
+ ## Refactoring Applied
351
+
352
+ | # | Description | Status | Verification | Date |
353
+ |---|-------------|--------|--------------|------|
354
+ | 1 | [Refactoring desc] | COMPLETE | Behavioral Equivalence: PROVEN | [date] |
355
+ ```
356
+
357
+ ---
358
+
359
+ ## AUTO-LEARNING PROTOCOL
360
+
361
+ After refactoring, if any issues were discovered:
362
+
363
+ 1. **Record the pattern** - What went wrong and how it was fixed
364
+ 2. **Check if pattern scanner should be updated** - Can the check be automated?
365
+ 3. **Update session state** - Record in `.claude/session-state/CURRENT.md`
366
+ 4. **Search codebase-wide** - Verify no other instances of same bad pattern (CR-9)
367
+
368
+ ---
369
+
370
+ ## COMPLETION REPORT
371
+
372
+ ```markdown
373
+ ## CS REFACTOR COMPLETE
374
+
375
+ ### Scope
376
+ - **Description**: [what was refactored]
377
+ - **Files changed**: [N]
378
+ - **Batches**: [N]
379
+
380
+ ### Blast Radius
381
+ | Category | Count |
382
+ |----------|-------|
383
+ | Files changed | [N] |
384
+ | References updated | [N] |
385
+ | References kept (with reason) | [N] |
386
+
387
+ ### Behavioral Equivalence Proof
388
+ | Metric | Before | After | Delta | Status |
389
+ |--------|--------|-------|-------|--------|
390
+ | Tests passing | [N] | [N] | [0] | EQUIVALENT |
391
+ | Type errors | [N] | [N] | [0] | EQUIVALENT |
392
+
393
+ ### Verification Gates
394
+ | Gate | Status |
395
+ |------|--------|
396
+ | Pattern Scanner | PASS |
397
+ | Type Safety | PASS |
398
+ | Tests | PASS ([N] passed) |
399
+ | Hook Build | PASS |
400
+ | Negative Verification | PASS (0 stale references) |
401
+
402
+ ### Changes Summary
403
+ | File | Change |
404
+ |------|--------|
405
+ | [file] | [description] |
406
+
407
+ ### Next Steps
408
+ - Review changes: `git diff`
409
+ - Commit: `/massu-commit`
410
+ ```