@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,315 @@
1
+ ---
2
+ name: massu-cleanup
3
+ description: Dead code removal — unused imports, orphaned files, dead exports, and stale references
4
+ allowed-tools: Bash(*), Read(*), Write(*), Edit(*), Grep(*), Glob(*)
5
+ ---
6
+ name: massu-cleanup
7
+
8
+ > **Shared rules apply.** Read `.claude/commands/_shared-preamble.md` before proceeding. CR-9, CR-35 enforced.
9
+
10
+ # CS Cleanup: Dead Code Removal
11
+
12
+ ## Objective
13
+
14
+ Identify and remove dead code across the codebase: unused imports, orphaned files, dead exports, and stale references. Changes are applied by category with verification after each batch. If any removal causes test regressions, the batch is reverted and investigated.
15
+
16
+ **Usage**: `/massu-cleanup` (full scan) or `/massu-cleanup [area]` (focused: imports, exports, files, deps)
17
+
18
+ ---
19
+
20
+ ## NON-NEGOTIABLE RULES
21
+
22
+ - **Never delete without verifying zero references** — grep before every removal
23
+ - **Run tests after each category** — a passing baseline MUST be maintained
24
+ - **Revert on regression** — if a batch breaks tests, revert before continuing
25
+ - **FIX ALL ISSUES ENCOUNTERED (CR-9)** — pre-existing issues found during cleanup MUST be fixed
26
+ - **No config or public API removals** — scope only to internal dead code
27
+ - **Proof > reasoning. Commands > assumptions.**
28
+
29
+ ---
30
+
31
+ ## SCOPE GUARD (MANDATORY)
32
+
33
+ **This command is for INTERNAL dead code only. If ANY of these are true, ABORT:**
34
+
35
+ | Condition | Why It's Too Big | Alternative |
36
+ |-----------|-----------------|-------------|
37
+ | Removal touches exported public API | Needs blast radius plan | `/massu-create-plan` |
38
+ | Removes MCP tool name | Affects all consumers | `/massu-create-plan` |
39
+ | Removes config interface fields | Affects all config users | `/massu-create-plan` |
40
+ | Touches > 20 files | Needs structured plan | `/massu-create-plan` |
41
+
42
+ ---
43
+
44
+ ## STEP 1: BASELINE SNAPSHOT
45
+
46
+ Capture the behavioral baseline BEFORE making any changes:
47
+
48
+ ### 1a. Test Baseline
49
+
50
+ ```bash
51
+ npm test 2>&1
52
+ ```
53
+
54
+ Record:
55
+ ```markdown
56
+ ### Test Baseline
57
+ | Metric | Value |
58
+ |--------|-------|
59
+ | Total tests | [N] |
60
+ | Passing | [N] |
61
+ | Failing | [N] |
62
+ ```
63
+
64
+ ### 1b. Type Check Baseline
65
+
66
+ ```bash
67
+ cd packages/core && npx tsc --noEmit 2>&1
68
+ ```
69
+
70
+ Record:
71
+ ```markdown
72
+ ### Type Check Baseline
73
+ | Metric | Value |
74
+ |--------|-------|
75
+ | Type errors | [N] |
76
+ ```
77
+
78
+ **This baseline is the behavioral contract. After cleanup:**
79
+ - Test count MUST be >= baseline
80
+ - Passing count MUST be >= baseline
81
+ - Type error count MUST be <= baseline
82
+
83
+ ---
84
+
85
+ ## STEP 2: DISCOVERY
86
+
87
+ Scan all categories in parallel. Do NOT remove anything yet.
88
+
89
+ ### 2a. Unused Imports
90
+
91
+ ```bash
92
+ # TypeScript unused imports (ts error 6133)
93
+ cd packages/core && npx tsc --noEmit 2>&1 | grep "is declared but"
94
+
95
+ # ESLint-style: imports never referenced in file body
96
+ grep -rn "^import" packages/core/src/ --include="*.ts" | head -50
97
+ ```
98
+
99
+ ### 2b. Dead Exports
100
+
101
+ ```bash
102
+ # Exported symbols with zero external references
103
+ grep -rn "^export " packages/core/src/ --include="*.ts" | grep -v "__tests__" | while IFS=: read file line content; do
104
+ name=$(echo "$content" | grep -oP '(?<=export (function|const|class|type|interface|enum) )\w+' | head -1)
105
+ if [ -n "$name" ]; then
106
+ count=$(grep -rn "$name" packages/core/src/ --include="*.ts" | grep -v "^$file:" | grep -v "__tests__" | wc -l)
107
+ if [ "$count" -eq 0 ]; then
108
+ echo "DEAD EXPORT: $name in $file"
109
+ fi
110
+ fi
111
+ done
112
+ ```
113
+
114
+ ### 2c. Orphaned Files
115
+
116
+ ```bash
117
+ # Source files not imported anywhere
118
+ for f in packages/core/src/*.ts; do
119
+ base=$(basename "$f" .ts)
120
+ # Skip entry points and test files
121
+ if [[ "$base" == "server" || "$base" == "index" || "$f" == *"__tests__"* ]]; then
122
+ continue
123
+ fi
124
+ count=$(grep -rn "from.*['\"]\./${base}" packages/core/src/ --include="*.ts" | grep -v "__tests__" | wc -l)
125
+ if [ "$count" -eq 0 ]; then
126
+ echo "POSSIBLY ORPHANED: $f"
127
+ fi
128
+ done
129
+ ```
130
+
131
+ ### 2d. Unused Dependencies
132
+
133
+ ```bash
134
+ # List all dependencies
135
+ cat packages/core/package.json | grep -A 50 '"dependencies"'
136
+
137
+ # Check each dependency usage
138
+ grep -rn "from.*'better-sqlite3'\|require.*better-sqlite3" packages/core/src/ --include="*.ts" | wc -l
139
+ grep -rn "from.*'yaml'\|require.*yaml" packages/core/src/ --include="*.ts" | wc -l
140
+ ```
141
+
142
+ ### 2e. TODO/FIXME/HACK Comments
143
+
144
+ ```bash
145
+ # Enumerate all stale markers — informational only (no auto-removal)
146
+ grep -rn "TODO\|FIXME\|HACK\|XXX\|DEPRECATED" packages/core/src/ --include="*.ts" | grep -v "__tests__"
147
+ ```
148
+
149
+ ---
150
+
151
+ ## STEP 3: CLASSIFICATION
152
+
153
+ For every candidate found in Step 2, classify each as:
154
+
155
+ ```markdown
156
+ ### Cleanup Inventory
157
+
158
+ | Category | Item | File | References | Action | Reason |
159
+ |----------|------|------|-----------|--------|--------|
160
+ | Unused import | [name] | [file] | 0 | REMOVE | Never used after import |
161
+ | Dead export | [name] | [file] | 0 | INVESTIGATE → REMOVE/KEEP | [context] |
162
+ | Orphaned file | [file] | - | 0 | INVESTIGATE → REMOVE/KEEP | [context] |
163
+ | Stale dep | [pkg] | package.json | [N] | REMOVE/KEEP | [reason] |
164
+ ```
165
+
166
+ **Rules:**
167
+ - Zero INVESTIGATE items allowed before implementation starts
168
+ - Every REMOVE item must be verified with negative grep
169
+ - Every KEEP item must have a documented reason
170
+
171
+ ---
172
+
173
+ ## STEP 4: CLEANUP
174
+
175
+ Apply removals by category. Maximum 1 category per batch.
176
+
177
+ ```
178
+ CLEANUP LOOP:
179
+ FOR EACH category in [imports, exports, files, deps]:
180
+ 1. Select all REMOVE items in this category
181
+ 2. Apply removals
182
+ 3. Run type check:
183
+ cd packages/core && npx tsc --noEmit 2>&1
184
+ 4. Run tests:
185
+ npm test 2>&1
186
+ 5. Compare against baseline:
187
+ - Type errors must be <= baseline
188
+ - Passing tests must be >= baseline
189
+ 6. IF regression detected:
190
+ - REVERT the entire category batch
191
+ - Document failure reason
192
+ - Skip this category
193
+ 7. IF clean:
194
+ - Record category as successful
195
+ - Proceed to next category
196
+ ```
197
+
198
+ ### Category Record Template
199
+
200
+ ```markdown
201
+ ### Category: [imports/exports/files/deps]
202
+
203
+ | Item | File | Action | Verification |
204
+ |------|------|--------|-------------|
205
+ | [item] | [file] | REMOVED | grep returned 0 |
206
+
207
+ | Check | Before | After | Status |
208
+ |-------|--------|-------|--------|
209
+ | Type errors | [N] | [N] | EQUIVALENT/IMPROVED |
210
+ | Tests passing | [N] | [N] | EQUIVALENT/IMPROVED |
211
+ ```
212
+
213
+ ---
214
+
215
+ ## STEP 5: NEGATIVE VERIFICATION (VR-NEGATIVE)
216
+
217
+ For every removed item, confirm it is gone:
218
+
219
+ ```bash
220
+ # Unused import removed
221
+ grep -rn "[import_name]" packages/core/src/ --include="*.ts"
222
+ # MUST return 0 matches (or only in unrelated contexts)
223
+
224
+ # Dead export removed
225
+ grep -rn "export.*[export_name]" packages/core/src/ --include="*.ts"
226
+ # MUST return 0 matches
227
+
228
+ # Orphaned file removed
229
+ ls [removed_file_path]
230
+ # MUST fail (file should not exist)
231
+ ```
232
+
233
+ ```markdown
234
+ ### Negative Verification
235
+
236
+ | Item | Grep Result | Status |
237
+ |------|-------------|--------|
238
+ | [name] | 0 matches | CLEAN |
239
+ | [file] | File not found | CLEAN |
240
+ ```
241
+
242
+ **If ANY stale reference remains:** Fix it before proceeding.
243
+
244
+ ---
245
+
246
+ ## STEP 6: FINAL VERIFICATION
247
+
248
+ ### Gate 1: Pattern Scanner (VR-PATTERN)
249
+ ```bash
250
+ bash scripts/massu-pattern-scanner.sh
251
+ # MUST exit 0
252
+ ```
253
+
254
+ ### Gate 2: Type Check (VR-TYPE)
255
+ ```bash
256
+ cd packages/core && npx tsc --noEmit
257
+ # MUST show 0 errors (or <= baseline)
258
+ ```
259
+
260
+ ### Gate 3: All Tests (VR-TEST)
261
+ ```bash
262
+ npm test
263
+ # MUST exit 0, all tests pass
264
+ ```
265
+
266
+ ### Gate 4: Hook Build (VR-HOOK-BUILD)
267
+ ```bash
268
+ cd packages/core && npm run build:hooks
269
+ # MUST exit 0
270
+ ```
271
+
272
+ ---
273
+
274
+ ## COMPLETION REPORT
275
+
276
+ ```markdown
277
+ ## CS CLEANUP COMPLETE
278
+
279
+ ### Scope
280
+ - **Files modified**: [N]
281
+ - **Files deleted**: [N]
282
+ - **Categories processed**: [N]
283
+
284
+ ### Items Removed
285
+ | Category | Count | Examples |
286
+ |----------|-------|---------|
287
+ | Unused imports | [N] | [examples] |
288
+ | Dead exports | [N] | [examples] |
289
+ | Orphaned files | [N] | [names] |
290
+ | Unused dependencies | [N] | [names] |
291
+
292
+ ### Items Kept (with reason)
293
+ | Item | Reason |
294
+ |------|--------|
295
+ | [item] | [reason — e.g., used in tests, reserved for upcoming feature] |
296
+
297
+ ### Behavioral Equivalence
298
+ | Metric | Before | After | Delta | Status |
299
+ |--------|--------|-------|-------|--------|
300
+ | Tests passing | [N] | [N] | [0] | EQUIVALENT |
301
+ | Type errors | [N] | [N] | [0] | EQUIVALENT/IMPROVED |
302
+
303
+ ### Verification Gates
304
+ | Gate | Status |
305
+ |------|--------|
306
+ | Pattern Scanner | PASS |
307
+ | Type Safety | PASS |
308
+ | Tests | PASS ([N] passed) |
309
+ | Hook Build | PASS |
310
+ | Negative Verification | PASS (0 stale references) |
311
+
312
+ ### Next Steps
313
+ - Review changes: `git diff`
314
+ - Commit: `/massu-commit`
315
+ ```