@massu/core 0.1.2 → 0.4.1

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 +12521 -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 -1
  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,481 @@
1
+ ---
2
+ name: massu-commit
3
+ description: Pre-commit verification audit with zero-fail release gate
4
+ allowed-tools: Bash(*), Read(*), Write(*), Edit(*), Grep(*), Glob(*)
5
+ ---
6
+ name: massu-commit
7
+
8
+ > **Shared rules apply.** Read `.claude/commands/_shared-preamble.md` before proceeding. CR-9, CR-35 enforced.
9
+
10
+ # CS Commit: Pre-Commit Verification Gate
11
+
12
+ ## Objective
13
+
14
+ Run a continuous AUDIT -> FIX -> VERIFY -> RE-AUDIT loop that proves (with evidence, not assumptions) that the implementation is correct and complete.
15
+
16
+ ---
17
+
18
+ ## Workflow Position
19
+
20
+ ```
21
+ /massu-create-plan -> /massu-plan -> /massu-loop -> /massu-commit -> /massu-push
22
+ (CREATE) (AUDIT) (IMPLEMENT) (COMMIT) (PUSH)
23
+ ```
24
+
25
+ **This command is step 4 of 5 in the standard workflow.**
26
+
27
+ ---
28
+
29
+ ## RELATIONSHIP WITH /massu-push AND /massu-loop
30
+
31
+ | Command | Purpose | Speed | Runs Full Tests |
32
+ |---------|---------|-------|-----------------|
33
+ | `/massu-commit` | Fast quality gates for committing | ~1-2 min | YES (vitest is fast) |
34
+ | `/massu-push` | Full verification + security before pushing | ~5 min | YES + regression |
35
+ | `/massu-loop` | Autonomous execution with FULL verification | Varies | YES - MANDATORY |
36
+
37
+ **Philosophy**: Commit often (quality checks), push verified (full checks + security).
38
+
39
+ ---
40
+
41
+ ## Workflow State Tracking
42
+
43
+ Write a transition entry to `.massu/workflow-log.md`:
44
+ ```
45
+ | [timestamp] | IMPLEMENT | VERIFY | /massu-commit | [session-id] |
46
+ ```
47
+
48
+ ---
49
+
50
+ ## NON-NEGOTIABLE RULES
51
+
52
+ - Do NOT stop early
53
+ - Do NOT skip checks
54
+ - Do NOT downgrade failures to warnings
55
+ - Do NOT commit unless ALL gates pass
56
+ - Do NOT push unless user explicitly instructs
57
+ - **Proof > reasoning. Commands > assumptions.**
58
+ - **FIX ALL ISSUES ENCOUNTERED (CR-9)** - If ANY issue is discovered during verification - whether from current changes OR pre-existing - fix it immediately.
59
+
60
+ ---
61
+
62
+ ## ZERO-GAP AUDIT LOOP
63
+
64
+ **This commit does NOT proceed until a SINGLE COMPLETE AUDIT finds ZERO issues.**
65
+
66
+ ```
67
+ COMMIT AUDIT LOOP:
68
+ 1. Run ALL pre-commit checks (Gates 1-8)
69
+ 2. Count total gaps/failures found
70
+ 3. IF gaps > 0:
71
+ - Fix ALL gaps
72
+ - Re-run ENTIRE audit from Step 1
73
+ 4. IF gaps == 0:
74
+ - COMMIT ALLOWED
75
+ ```
76
+
77
+ | Scenario | Action |
78
+ |----------|--------|
79
+ | Pre-commit finds 3 issues | Fix all 3, re-run ENTIRE check |
80
+ | Re-check finds 1 issue | Fix it, re-run ENTIRE check |
81
+ | Re-check finds 0 issues | **NOW** commit can proceed |
82
+
83
+ **Partial re-checks are NOT valid. ALL gates must pass in a SINGLE run before commit.**
84
+
85
+ ---
86
+
87
+ ## CRITICAL: DUAL VERIFICATION REQUIREMENT
88
+
89
+ **Commits verify BOTH code quality AND plan coverage.**
90
+
91
+ | Verification | What It Checks | Required for Commit |
92
+ |--------------|----------------|---------------------|
93
+ | **Code Quality** | Is the code correct? | YES |
94
+ | **Plan Coverage** | Did we build everything? (if from plan) | YES |
95
+
96
+ **Code Quality: PASS + Plan Coverage: FAIL = COMMIT BLOCKED**
97
+
98
+ ---
99
+
100
+ ## DOMAIN-SPECIFIC PATTERN LOADING
101
+
102
+ Based on work being committed, load relevant pattern sections from CLAUDE.md:
103
+
104
+ | Domain | Section to Load | Load When |
105
+ |--------|----------------|-----------|
106
+ | Tool modules | Tool Registration Pattern | Adding/modifying MCP tools |
107
+ | Config | Config Access Pattern | Config changes |
108
+ | Hooks | Hook stdin/stdout Pattern | Adding/modifying hooks |
109
+ | Build | Build & Test Commands | Build-related changes |
110
+
111
+ ---
112
+
113
+ ## INPUTS (Read First, In Order)
114
+
115
+ ### Input 1: The Plan (if applicable)
116
+ - Read the entire Plan line-by-line
117
+ - Extract every requirement into a numbered checklist
118
+ - Store as: `REQUIREMENTS_CHECKLIST`
119
+
120
+ ### Input 2: CLAUDE.md
121
+ - Read fully: `.claude/CLAUDE.md`
122
+ - This IS the canonical source for all patterns and constraints
123
+ - Extract every rule/pattern into a checklist
124
+
125
+ ---
126
+
127
+ ## AUDIT MODE (TWO-PASS)
128
+
129
+ ### PASS A: Inventory & Mapping (NO FIXES)
130
+
131
+ #### A1. Plan -> Implementation Matrix (if from plan)
132
+
133
+ ```markdown
134
+ | Req ID | Requirement | Status | Evidence (file:line) | Verified |
135
+ |--------|-------------|--------|---------------------|----------|
136
+ | R-001 | [text] | Implemented/Partial/Missing | [paths] | YES/NO |
137
+ ```
138
+
139
+ #### A2. CLAUDE.md Compliance Matrix
140
+
141
+ Run pattern scanner first:
142
+ ```bash
143
+ bash scripts/massu-pattern-scanner.sh
144
+ # Exit 0 = PASS, non-zero = violations found
145
+ ```
146
+
147
+ Document each rule:
148
+ ```markdown
149
+ | Rule | Verification | Result | Status |
150
+ |------|--------------|--------|--------|
151
+ | ESM imports only | grep "require(" src/ | 0 | PASS |
152
+ | Config via getConfig() | grep "yaml.parse" src/ (excl. config.ts) | 0 | PASS |
153
+ | No process.exit() in lib | grep "process.exit" src/ (excl. server.ts) | 0 | PASS |
154
+ ```
155
+
156
+ #### A3. Tool Registration Audit (if new tools)
157
+
158
+ ```markdown
159
+ | Tool Name | Definition | Handler | Test | Status |
160
+ |-----------|------------|---------|------|--------|
161
+ | [name] | [file:line] | [file:line] | [test file] | PASS/FAIL |
162
+ ```
163
+
164
+ ---
165
+
166
+ ### PASS B: Verification & Breakage Hunting
167
+
168
+ #### B1. Type Integrity
169
+ - Types match between modules
170
+ - No `as any` workarounds for real type issues
171
+ - Config interfaces match YAML structure
172
+
173
+ #### B2. Data Layer Integrity
174
+ - SQLite schema matches code expectations
175
+ - Database module functions work correctly
176
+
177
+ #### B3. MCP Tool Registration Completeness (CRITICAL)
178
+ For every new tool in this commit:
179
+
180
+ ```bash
181
+ # Verify tool definition exists
182
+ grep "name:.*[tool_name]" packages/core/src/[module]-tools.ts
183
+
184
+ # Verify handler exists
185
+ grep "case.*[tool_name]" packages/core/src/[module]-tools.ts
186
+
187
+ # Verify wired into tools.ts
188
+ grep "[module]" packages/core/src/tools.ts
189
+ ```
190
+
191
+ #### B4. Hook Compilation
192
+ ```bash
193
+ cd packages/core && npm run build:hooks
194
+ # MUST exit 0
195
+ ```
196
+
197
+ #### B5. Regression Risk
198
+ - Review changes for side effects
199
+ - Check for incomplete refactors
200
+ - Verify no silent failures introduced
201
+
202
+ ---
203
+
204
+ ## FIX PROTOCOL
205
+
206
+ ### Fix Queue (by severity)
207
+
208
+ | Priority | Definition |
209
+ |----------|------------|
210
+ | **P0** | Broken tools, data loss, security gaps, secrets exposed |
211
+ | **P1** | Incorrect behavior, missing requirements, build failures |
212
+ | **P2** | Consistency issues, pattern violations, test failures |
213
+
214
+ ### For Each Fix
215
+ 1. Apply smallest correct fix matching CLAUDE.md patterns
216
+ 2. Run verification for that specific fix
217
+ 3. Update session-state/CURRENT.md with fix details
218
+
219
+ ---
220
+
221
+ ## AUTO-VERIFICATION COMMAND GATE (MANDATORY)
222
+
223
+ **After EVERY fix cycle and BEFORE any commit, run ALL of these.**
224
+
225
+ You may NOT proceed if ANY command fails.
226
+
227
+ ### Gate 1: Pattern Compliance
228
+ ```bash
229
+ bash scripts/massu-pattern-scanner.sh
230
+ # MUST exit 0
231
+ ```
232
+
233
+ ### Gate 2: Type Safety (VR-TYPE)
234
+ ```bash
235
+ cd packages/core && npx tsc --noEmit
236
+ # MUST show 0 errors
237
+ ```
238
+
239
+ ### Gate 3: All Tests Pass (VR-TEST)
240
+ ```bash
241
+ npm test
242
+ # MUST exit 0, all vitest tests pass
243
+ ```
244
+
245
+ ### Gate 4: Hook Compilation (VR-HOOK-BUILD)
246
+ ```bash
247
+ cd packages/core && npm run build:hooks
248
+ # MUST exit 0
249
+ ```
250
+
251
+ ### Gate 5: Generalization Compliance (VR-GENERIC)
252
+ ```bash
253
+ bash scripts/massu-generalization-scanner.sh
254
+ # MUST exit 0
255
+ ```
256
+
257
+ ### Gate 6: Security - No Secrets Staged
258
+ ```bash
259
+ git diff --cached --name-only | grep -E '\.(env|pem|key|secret)' && echo "FAIL: Secrets staged" && exit 1
260
+ echo "PASS: No secrets staged"
261
+ ```
262
+
263
+ ### Gate 7: Security - No Credentials in Code
264
+ ```bash
265
+ # Check packages/core/src/ for hardcoded credentials
266
+ grep -rn 'sk-[a-zA-Z0-9]\{20,\}\|password.*=.*["\x27][^"\x27]\{8,\}' --include="*.ts" --include="*.tsx" \
267
+ packages/core/src/ 2>/dev/null \
268
+ | grep -v "process.env" \
269
+ | grep -v 'RegExp\|regex\|REDACT\|redact\|sanitize\|mask' \
270
+ | grep -v '\.test\.ts:' \
271
+ | wc -l
272
+ # MUST be 0
273
+ ```
274
+
275
+ **Known false positive exclusions** (regex/redaction patterns, test fixtures):
276
+ - `security-utils.ts` - credential redaction regex
277
+ - `*.test.ts` - test fixtures with mock data
278
+
279
+ ### Gate 8: Plan Coverage (if from plan)
280
+ ```markdown
281
+ ### PLAN COVERAGE GATE
282
+
283
+ | Item # | Description | Status | Proof |
284
+ |--------|-------------|--------|-------|
285
+ | P1-001 | [desc] | DONE | [evidence] |
286
+ | P1-002 | [desc] | DONE | [evidence] |
287
+ | ... | ... | ... | ... |
288
+
289
+ **Coverage: X/X items = 100%**
290
+ **PLAN COVERAGE GATE: PASS / FAIL**
291
+ ```
292
+
293
+ ---
294
+
295
+ ## GATE SUMMARY
296
+
297
+ ```markdown
298
+ ### PRE-COMMIT GATE SUMMARY
299
+
300
+ | Gate | Command | Result | Status |
301
+ |------|---------|--------|--------|
302
+ | 1. Pattern Scanner | massu-pattern-scanner.sh | Exit [X] | PASS/FAIL |
303
+ | 2. Type Safety | tsc --noEmit | [X] errors | PASS/FAIL |
304
+ | 3. Tests | npm test | [X] pass, [X] fail | PASS/FAIL |
305
+ | 4. Hook Build | build:hooks | Exit [X] | PASS/FAIL |
306
+ | 5. Generalization | massu-generalization-scanner.sh | Exit [X] | PASS/FAIL |
307
+ | 6. No Secrets Staged | git diff --cached check | [result] | PASS/FAIL |
308
+ | 7. No Credentials | grep check | [X] found | PASS/FAIL |
309
+ | 8. Plan Coverage | item-by-item | [X]/[X] = [X]% | PASS/FAIL |
310
+
311
+ **OVERALL: PASS / FAIL**
312
+ ```
313
+
314
+ ### If ALL Gates Pass
315
+
316
+ ```bash
317
+ # Stage changes
318
+ git add [specific files]
319
+
320
+ # Commit with HEREDOC
321
+ git commit -m "$(cat <<'EOF'
322
+ [type]([scope]): [description]
323
+
324
+ [body - what changed and why]
325
+
326
+ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
327
+ EOF
328
+ )"
329
+
330
+ # Verify commit succeeded
331
+ git log -1 --oneline
332
+ ```
333
+
334
+ ### If ANY Gate Fails
335
+
336
+ 1. **Document ALL failures**
337
+ 2. **Fix EACH failure** following CLAUDE.md patterns
338
+ 3. **Re-run ENTIRE gate sequence** (not just failed gates)
339
+ 4. **Repeat until ALL gates pass in a SINGLE run**
340
+
341
+ ---
342
+
343
+ ## COMMIT MESSAGE INTELLIGENCE
344
+
345
+ ### CONVENTIONAL COMMIT ENFORCEMENT
346
+
347
+ Commit message MUST follow: `type(scope): description`
348
+
349
+ **Valid types**:
350
+
351
+ | Type | When |
352
+ |------|------|
353
+ | `feat` | New feature or capability |
354
+ | `fix` | Bug fix |
355
+ | `perf` | Performance improvement |
356
+ | `refactor` | Code restructuring (no behavior change) |
357
+ | `test` | Adding or modifying tests |
358
+ | `docs` | Documentation only |
359
+ | `chore` | Maintenance, dependencies, config |
360
+ | `style` | Formatting, whitespace (no logic change) |
361
+ | `ci` | CI/CD pipeline changes |
362
+ | `build` | Build system or tooling changes |
363
+
364
+ **If the commit message doesn't match the `type(scope): description` pattern, reformat it before committing.**
365
+
366
+ ### SCOPE AUTO-SUGGESTION
367
+
368
+ Analyze `git diff --cached --name-only` to determine scope:
369
+
370
+ | Changed Files Location | Suggested Scope |
371
+ |------------------------|-----------------|
372
+ | All in `packages/core/src/` | `core` |
373
+ | All in `website/` | `website` |
374
+ | All in `.claude/commands/` | `commands` |
375
+ | All in `scripts/` | `tooling` |
376
+ | All in `website/supabase/` | `supabase` |
377
+ | Mixed across areas | Most dominant area, or omit scope |
378
+
379
+ ### BREAKING CHANGE DETECTION
380
+
381
+ Check `git diff --cached` for breaking changes:
382
+
383
+ | Change Type | Indicator |
384
+ |-------------|-----------|
385
+ | Exported function signature changed | Parameters added/removed/retyped |
386
+ | Tool name pattern changed | `name:` value in tool definitions |
387
+ | Config interface fields changed | Fields in `Config` interface added/removed/renamed |
388
+ | Database schema changed | CREATE TABLE, ALTER TABLE, DROP in migrations |
389
+
390
+ **If breaking change detected:**
391
+ 1. Add `BREAKING CHANGE:` footer to commit message
392
+ 2. Warn user about the breaking change before committing
393
+
394
+ ### RELATED ISSUE LINKING
395
+
396
+ ```bash
397
+ # If branch name contains issue number (e.g., fix/123-bug, feature/456-new-tool)
398
+ branch=$(git branch --show-current)
399
+ issue_num=$(echo "$branch" | grep -oE '[0-9]+' | head -1)
400
+ # If found, suggest: "Closes #[issue_num]" in commit body
401
+ ```
402
+
403
+ ### COMMIT SPLITTING SUGGESTION
404
+
405
+ ```bash
406
+ # Check if staged changes span 3+ unrelated areas
407
+ git diff --cached --stat
408
+ ```
409
+
410
+ If changes span 3+ unrelated areas (e.g., `packages/core/` + `website/` + `scripts/`):
411
+ - Present: "Consider splitting this into N commits for cleaner history"
412
+ - List the suggested splits by area
413
+
414
+ ---
415
+
416
+ ## START NOW
417
+
418
+ **Step 0: Write AUTHORIZED_COMMAND to session state (CR-35)**
419
+
420
+ Update `session-state/CURRENT.md` to include `AUTHORIZED_COMMAND: massu-commit`.
421
+
422
+ 1. Check work to commit: `git status && git diff --stat`
423
+ 2. If Plan exists, begin PASS A
424
+ 3. If no Plan, audit against CLAUDE.md patterns only
425
+ 4. Run full audit loop until ZERO gaps
426
+ 5. Run ALL verification gates
427
+ 6. Execute AUTO-LEARNING PROTOCOL
428
+ 7. Commit only when ALL conditions met
429
+ 8. Report completion, await push instruction
430
+
431
+ ---
432
+
433
+ ## MANDATORY: PLAN DOCUMENT UPDATE (After Commit)
434
+
435
+ If commit is from a plan, update the plan document TOP with:
436
+ - IMPLEMENTATION STATUS table (status, last updated, commit hash)
437
+ - Task completion summary with verification evidence
438
+
439
+ Verify: `grep "IMPLEMENTATION STATUS" [plan_file]` returns match.
440
+
441
+ ---
442
+
443
+ ## AUTO-LEARNING PROTOCOL
444
+
445
+ After committing, if any issues were fixed during this audit:
446
+
447
+ 1. **Record the pattern** - What went wrong and how it was fixed
448
+ 2. **Check if pattern scanner should be updated** - Can the check be automated?
449
+ 3. **Update session state** - Record in `.claude/session-state/CURRENT.md`
450
+ 4. **Search codebase-wide** - Verify no other instances of same bad pattern (CR-9)
451
+
452
+ If a NEW pattern or utility was created during the commit:
453
+ 1. Record in session-state/CURRENT.md with file path and purpose
454
+
455
+ ---
456
+
457
+ ## COMPLETION REPORT
458
+
459
+ ```markdown
460
+ ## CS COMMIT COMPLETE
461
+
462
+ ### Commit Details
463
+ - **Hash**: [hash]
464
+ - **Message**: [message]
465
+ - **Files**: [count] files changed
466
+
467
+ ### Gates Passed
468
+ | Gate | Status |
469
+ |------|--------|
470
+ | Pattern Scanner | PASS |
471
+ | Type Safety | PASS |
472
+ | Tests | PASS ([X] passed) |
473
+ | Hook Build | PASS |
474
+ | Generalization | PASS |
475
+ | No Secrets | PASS |
476
+ | No Credentials | PASS |
477
+ | Plan Coverage | PASS (X/X = 100%) |
478
+
479
+ ### Next Steps
480
+ - Run `/massu-push` to push with full verification
481
+ ```