@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,511 @@
1
+ ---
2
+ name: massu-new-feature
3
+ description: Feature scaffolding with correct patterns pre-applied and verification gates
4
+ allowed-tools: Bash(*), Read(*), Write(*), Edit(*), Grep(*), Glob(*)
5
+ ---
6
+ name: massu-new-feature
7
+
8
+ > **Shared rules apply.** Read `.claude/commands/_shared-preamble.md` before proceeding. CR-9, CR-35 enforced.
9
+
10
+ # Massu New Feature: Pattern-Compliant Feature Scaffolding
11
+
12
+ ## Workflow Position
13
+
14
+ ```
15
+ /massu-create-plan -> /massu-plan -> /massu-loop / /massu-new-feature -> /massu-commit -> /massu-push
16
+ (PLAN) (AUDIT) (IMPLEMENT) (SCAFFOLD) (COMMIT) (PUSH)
17
+ ```
18
+
19
+ **This command can be used standalone or as part of /massu-loop for feature scaffolding.**
20
+
21
+ ---
22
+
23
+ ## Objective
24
+
25
+ Scaffold new features with **all CLAUDE.md patterns pre-applied**, ensuring correct architecture from the start. Verify each component before proceeding.
26
+
27
+ ---
28
+
29
+ ## NON-NEGOTIABLE RULES
30
+
31
+ - **Read CLAUDE.md first** - Know the patterns before writing code
32
+ - **Load domain patterns** - Read relevant pattern files
33
+ - **Verify each step** - VR-* checks after each component
34
+ - **No shortcuts** - Every feature needs all layers properly built
35
+ - **Pattern scanner must pass** - Before any commit
36
+ - **FIX ALL ISSUES ENCOUNTERED (CR-9)** - If ANY issue is discovered during feature development - whether from current changes OR pre-existing - fix it immediately. "Not in scope" and "pre-existing" are NEVER valid reasons to skip a fix. When fixing a bug, search entire codebase for same pattern and fix ALL instances.
37
+
38
+ ---
39
+
40
+ ## ZERO-GAP AUDIT LOOP
41
+
42
+ **Feature implementation does NOT complete until a SINGLE COMPLETE AUDIT finds ZERO issues.**
43
+
44
+ ### The Rule
45
+
46
+ ```
47
+ FEATURE VERIFICATION LOOP:
48
+ 1. Implement feature component
49
+ 2. Run ALL verification checks (patterns, types, build, tests)
50
+ 3. Count issues found
51
+ 4. IF issues > 0:
52
+ - Fix ALL issues
53
+ - Re-run ENTIRE verification from Step 2
54
+ 5. IF issues == 0:
55
+ - Component verified, proceed to next
56
+ 6. After ALL components: Final full audit
57
+ 7. IF final audit gaps > 0:
58
+ - Fix ALL gaps
59
+ - Re-run ENTIRE final audit
60
+ 8. IF final audit gaps == 0:
61
+ - FEATURE COMPLETE
62
+ ```
63
+
64
+ ### Completion Requirement
65
+
66
+ | Scenario | Action |
67
+ |----------|--------|
68
+ | Component fails verification | Fix issues, re-verify ENTIRE component |
69
+ | Final audit finds 2 issues | Fix both, re-run ENTIRE final audit |
70
+ | Final audit finds 0 issues | **NOW** feature complete |
71
+
72
+ **Partial verification is NOT valid. ALL checks must pass in a SINGLE run.**
73
+
74
+ ---
75
+
76
+ ## MANDATORY PATTERN ALIGNMENT GATE (PRE-SCAFFOLDING)
77
+
78
+ **BEFORE writing any code, verify the feature design aligns with ALL established patterns.**
79
+
80
+ ### The Law
81
+
82
+ ```
83
+ +-----------------------------------------------------------------------------+
84
+ | |
85
+ | EVERY NEW FEATURE MUST ALIGN WITH ESTABLISHED PATTERNS BEFORE CODING. |
86
+ | If no pattern exists, CREATE and SAVE it first (with user approval). |
87
+ | Writing code before pattern alignment = bugs designed into the feature. |
88
+ | |
89
+ +-----------------------------------------------------------------------------+
90
+ ```
91
+
92
+ ### Step 1: Read ALL Applicable Pattern Files
93
+
94
+ | Feature Type | Pattern Files to Read |
95
+ |--------------|----------------------|
96
+ | ANY feature | `.claude/CLAUDE.md` |
97
+ | Has MCP tools | Tool registration pattern in CLAUDE.md |
98
+ | Has hooks | Hook stdin/stdout pattern in CLAUDE.md |
99
+ | Has config changes | Config access pattern in CLAUDE.md |
100
+ | Has DB operations | SQLite database pattern in CLAUDE.md |
101
+
102
+ ### Step 2: Build Pattern Alignment Matrix
103
+
104
+ ```markdown
105
+ ### FEATURE PATTERN ALIGNMENT: [Feature Name]
106
+
107
+ | Pattern ID | Pattern Requirement | Applies to Feature | How Feature Will Comply |
108
+ |------------|---------------------|-------------------|------------------------|
109
+ | TOOL-001 | 3-function registration pattern | YES/NO | [approach] |
110
+ | TOOL-002 | Config-driven prefix | YES/NO | [approach] |
111
+ | TOOL-003 | Wire into tools.ts | YES/NO | [approach] |
112
+ | CONFIG-001 | Use getConfig() not direct YAML | YES/NO | [approach] |
113
+ | DB-001 | getMemoryDb() with try/finally | YES/NO | [approach] |
114
+ | DB-002 | getCodeGraphDb() read-only | YES/NO | [approach] |
115
+ | HOOK-001 | JSON stdin/stdout | YES/NO | [approach] |
116
+ | HOOK-002 | esbuild compatible | YES/NO | [approach] |
117
+ ```
118
+
119
+ ### Step 3: Identify Pattern Gaps
120
+
121
+ If the feature needs functionality with NO existing pattern:
122
+
123
+ ```markdown
124
+ ### NEW PATTERN NEEDED
125
+
126
+ | Aspect | Details |
127
+ |--------|---------|
128
+ | **Feature Need** | [What the feature requires] |
129
+ | **Existing Patterns Checked** | [List what was checked] |
130
+ | **Why Existing Don't Work** | [Specific reasons] |
131
+ | **Proposed New Pattern** | [Description] |
132
+
133
+ **WRONG (Never Do This):**
134
+ ```[code example]```
135
+
136
+ **CORRECT (Always Do This):**
137
+ ```[code example]```
138
+
139
+ **Error if violated:**
140
+ [What breaks]
141
+ ```
142
+
143
+ ### Step 4: If New Pattern Needed
144
+
145
+ 1. **Present to user for approval**
146
+ 2. **Save to appropriate location BEFORE implementation**
147
+ 3. **Reference saved pattern** in feature design
148
+
149
+ ### Pattern Alignment Gate Verification
150
+
151
+ ```markdown
152
+ ### PATTERN ALIGNMENT GATE
153
+
154
+ | Check | Status |
155
+ |-------|--------|
156
+ | Read ALL applicable pattern files | YES/NO |
157
+ | Built Pattern Alignment Matrix | YES/NO |
158
+ | All applicable patterns have compliance approach | YES/NO |
159
+ | New patterns (if any) approved and saved | YES/NO |
160
+
161
+ **PATTERN ALIGNMENT GATE: PASS / FAIL**
162
+
163
+ If FAIL: Cannot begin implementation until all patterns addressed.
164
+ ```
165
+
166
+ ---
167
+
168
+ ## FEATURE CHECKLIST
169
+
170
+ Before starting, determine what the feature needs:
171
+
172
+ ```markdown
173
+ ### Feature: [FEATURE_NAME]
174
+
175
+ #### Components Needed
176
+ - [ ] Tool module file (packages/core/src/[feature].ts)
177
+ - [ ] Tool definitions (getXToolDefinitions)
178
+ - [ ] Tool name matcher (isXTool)
179
+ - [ ] Tool handler (handleXToolCall)
180
+ - [ ] Wire into tools.ts
181
+ - [ ] Input schemas
182
+ - [ ] Config integration
183
+ - [ ] Tests (packages/core/src/__tests__/[feature].test.ts)
184
+ - [ ] Documentation
185
+
186
+ #### Patterns to Apply (MANDATORY)
187
+
188
+ **Tool Registration Patterns:**
189
+ - [ ] 3-function pattern (getDefs + isTool + handleCall)
190
+ - [ ] Config-driven tool prefix via getConfig().toolPrefix
191
+ - [ ] Wire definitions into getToolDefinitions() in tools.ts
192
+ - [ ] Wire handler into handleToolCall() in tools.ts
193
+ - [ ] stripPrefix() for base name matching
194
+
195
+ **Database Patterns:**
196
+ - [ ] getMemoryDb() with try/finally for memory operations
197
+ - [ ] getCodeGraphDb() for read-only CodeGraph queries
198
+ - [ ] getDataDb() for data DB operations
199
+ - [ ] Never write to CodeGraph DB
200
+
201
+ **Config Patterns:**
202
+ - [ ] getConfig() from config.ts (never parse YAML directly)
203
+ - [ ] Config-driven values (no hardcoding)
204
+
205
+ **Hook Patterns (if applicable):**
206
+ - [ ] JSON stdin/stdout
207
+ - [ ] esbuild compatible imports
208
+ - [ ] Exit within 5 seconds
209
+ - [ ] No heavy dependencies
210
+ ```
211
+
212
+ ---
213
+
214
+ ## DOMAIN-SPECIFIC PATTERN LOADING
215
+
216
+ Based on feature type, load relevant patterns from CLAUDE.md:
217
+
218
+ | Domain | Section | Load When |
219
+ |--------|---------|-----------|
220
+ | Tool modules | Tool Registration Pattern | Adding MCP tools |
221
+ | Hooks | Hook stdin/stdout Pattern | Adding hooks |
222
+ | Config | Config Access Pattern | Changing config |
223
+ | Database | SQLite Database Pattern | Adding DB operations |
224
+
225
+ ---
226
+
227
+ ## COMPONENT REUSE REQUIREMENTS
228
+
229
+ **Before creating ANY new module, you MUST check for existing modules.**
230
+
231
+ ### 1. Search for Existing Modules
232
+ ```bash
233
+ # Find similar modules by name
234
+ ls packages/core/src/*[feature]* 2>/dev/null
235
+
236
+ # Find modules with similar functionality
237
+ grep -rln "[functionality]" packages/core/src/ | head -20
238
+
239
+ # Check existing tool modules
240
+ grep "ToolDefinitions" packages/core/src/*.ts
241
+ ```
242
+
243
+ ### 2. Reuse Priority
244
+ | Priority | Action |
245
+ |----------|--------|
246
+ | 1st | Use existing module as-is |
247
+ | 2nd | Extend existing module with new tools |
248
+ | 3rd | Compose from smaller existing modules |
249
+ | 4th | Create new module ONLY if nothing suitable exists |
250
+
251
+ ### 3. Module Creation Checklist
252
+ Before creating new module:
253
+ - [ ] Searched for similar existing modules
254
+ - [ ] Checked if existing module can be extended
255
+ - [ ] Documented WHY new module is necessary
256
+
257
+ ---
258
+
259
+ ## PHASE 1: TOOL MODULE
260
+
261
+ ### 1.1 Module Template
262
+ ```typescript
263
+ // packages/core/src/[feature].ts
264
+ import { getConfig, stripPrefix } from './config.ts';
265
+ import type { ToolDefinition, ToolResult } from './types.ts';
266
+
267
+ export function getFeatureToolDefinitions(): ToolDefinition[] {
268
+ const p = (name: string) => `${getConfig().toolPrefix}_${name}`;
269
+ return [
270
+ {
271
+ name: p('feature_action'),
272
+ description: 'Does the feature action',
273
+ inputSchema: {
274
+ type: 'object',
275
+ properties: {
276
+ param: { type: 'string', description: 'The parameter' },
277
+ },
278
+ required: ['param'],
279
+ },
280
+ },
281
+ ];
282
+ }
283
+
284
+ export function isFeatureTool(name: string): boolean {
285
+ const base = stripPrefix(name);
286
+ return base.startsWith('feature_');
287
+ }
288
+
289
+ export function handleFeatureToolCall(
290
+ name: string,
291
+ args: Record<string, unknown>,
292
+ memDb: Database.Database
293
+ ): ToolResult {
294
+ const baseName = stripPrefix(name);
295
+ switch (baseName) {
296
+ case 'feature_action':
297
+ return { content: [{ type: 'text', text: 'result' }] };
298
+ default:
299
+ return { content: [{ type: 'text', text: `Unknown tool: ${name}` }] };
300
+ }
301
+ }
302
+ ```
303
+
304
+ ### 1.2 Register in tools.ts
305
+ ```typescript
306
+ // packages/core/src/tools.ts
307
+ import { getFeatureToolDefinitions, isFeatureTool, handleFeatureToolCall } from './[feature].ts';
308
+
309
+ // In getToolDefinitions():
310
+ ...getFeatureToolDefinitions(),
311
+
312
+ // In handleToolCall():
313
+ if (isFeatureTool(name)) {
314
+ const memDb = getMemoryDb();
315
+ try { return handleFeatureToolCall(name, args, memDb); }
316
+ finally { memDb.close(); }
317
+ }
318
+ ```
319
+
320
+ ### 1.3 Verify Tool Module
321
+ ```bash
322
+ # Verify module exists
323
+ ls -la packages/core/src/[feature].ts
324
+
325
+ # Verify exports
326
+ grep -n "export.*function" packages/core/src/[feature].ts
327
+
328
+ # Verify registered in tools.ts
329
+ grep -n "getFeatureToolDefinitions\|isFeatureTool\|handleFeatureToolCall" packages/core/src/tools.ts
330
+
331
+ # Verify config-driven prefix
332
+ grep -n "getConfig().toolPrefix\|p(" packages/core/src/[feature].ts
333
+ ```
334
+
335
+ ---
336
+
337
+ ## PHASE 2: TESTS
338
+
339
+ ### 2.1 Test Template
340
+ ```typescript
341
+ // packages/core/src/__tests__/[feature].test.ts
342
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
343
+ import { getFeatureToolDefinitions, isFeatureTool, handleFeatureToolCall } from '../[feature].ts';
344
+
345
+ describe('[feature] tools', () => {
346
+ it('should return tool definitions', () => {
347
+ const defs = getFeatureToolDefinitions();
348
+ expect(defs.length).toBeGreaterThan(0);
349
+ expect(defs[0].name).toContain('feature_action');
350
+ });
351
+
352
+ it('should match tool names correctly', () => {
353
+ expect(isFeatureTool('massu_feature_action')).toBe(true);
354
+ expect(isFeatureTool('massu_other_action')).toBe(false);
355
+ });
356
+ });
357
+ ```
358
+
359
+ ### 2.2 Verify Tests
360
+ ```bash
361
+ # Run tests
362
+ npm test
363
+
364
+ # Verify test file exists
365
+ ls -la packages/core/src/__tests__/[feature].test.ts
366
+ ```
367
+
368
+ ---
369
+
370
+ ## PHASE 3: VERIFICATION
371
+
372
+ ### 3.1 Full Verification Suite
373
+ ```bash
374
+ # Pattern scanner
375
+ bash scripts/massu-pattern-scanner.sh
376
+
377
+ # Type check
378
+ cd packages/core && npx tsc --noEmit
379
+
380
+ # Build (includes hook compilation)
381
+ npm run build
382
+
383
+ # Hook build
384
+ cd packages/core && npm run build:hooks
385
+
386
+ # Tests
387
+ npm test
388
+ ```
389
+
390
+ ### 3.2 Tool Registration Verification (VR-TOOL-REG)
391
+
392
+ **MANDATORY for any feature with new MCP tools:**
393
+
394
+ | Tool Item | Verification |
395
+ |-----------|--------------|
396
+ | Tool definitions exported | grep in module file |
397
+ | Tool matcher exported | grep in module file |
398
+ | Tool handler exported | grep in module file |
399
+ | Definitions spread in tools.ts | grep getXToolDefinitions |
400
+ | Handler wired in tools.ts | grep handleXToolCall |
401
+
402
+ ### 3.3 Pattern Compliance
403
+ ```bash
404
+ # All patterns must pass
405
+ bash scripts/massu-pattern-scanner.sh
406
+ # Expected: Exit 0
407
+ ```
408
+
409
+ ---
410
+
411
+ ## FEATURE SCAFFOLDING REPORT
412
+
413
+ ```markdown
414
+ ## MASSU NEW FEATURE REPORT
415
+
416
+ ### Feature: [NAME]
417
+ - **Date**: [timestamp]
418
+ - **Type**: [Tool Module / Hook / Config Extension]
419
+
420
+ ### Components Created
421
+
422
+ #### Tool Module
423
+ - [ ] Module: packages/core/src/[feature].ts
424
+ - [ ] Tools: [list of tool names]
425
+ - [ ] Registered in tools.ts: YES
426
+
427
+ #### Tests
428
+ - [ ] Test file: packages/core/src/__tests__/[feature].test.ts
429
+ - [ ] All tests passing: YES
430
+
431
+ ### Verification
432
+ | Check | Result | Status |
433
+ |-------|--------|--------|
434
+ | Pattern scanner | Exit 0 | PASS |
435
+ | Type check | 0 errors | PASS |
436
+ | Build | Exit 0 | PASS |
437
+ | Hook build | Exit 0 | PASS |
438
+ | Tests | ALL pass | PASS |
439
+
440
+ **FEATURE SCAFFOLDING COMPLETE**
441
+ ```
442
+
443
+ ---
444
+
445
+ ## MANDATORY PLAN DOCUMENT UPDATE
446
+
447
+ **AFTER feature is complete, UPDATE the plan document with completion status.**
448
+
449
+ If this feature is part of a plan:
450
+ 1. Open the plan document
451
+ 2. Add/update completion table at TOP:
452
+
453
+ ```markdown
454
+ # IMPLEMENTATION STATUS
455
+
456
+ **Plan**: [Plan Name]
457
+ **Status**: COMPLETE / IN_PROGRESS / PARTIAL
458
+ **Last Updated**: [YYYY-MM-DD HH:MM]
459
+
460
+ ## Task Completion Summary
461
+
462
+ | # | Task/Phase | Status | Verification | Date |
463
+ |---|------------|--------|--------------|------|
464
+ | [N] | [This feature] | 100% COMPLETE | Dual Verification Gate PASS | [date] |
465
+ ```
466
+
467
+ 3. Record verification evidence:
468
+ ```markdown
469
+ ## Verification Evidence
470
+
471
+ ### Feature: [Name]
472
+ - Dual Verification Gate: PASS
473
+ - Code Quality: Build, types, patterns all pass
474
+ - Plan Coverage: 100% items verified
475
+ ```
476
+
477
+ ---
478
+
479
+ ## SESSION STATE UPDATE
480
+
481
+ After feature creation, update `session-state/CURRENT.md`:
482
+
483
+ ```markdown
484
+ ## NEW FEATURE SESSION
485
+
486
+ ### Feature
487
+ - **Name**: [feature name]
488
+ - **Status**: COMPLETE
489
+
490
+ ### Files Created
491
+ - [list of files]
492
+
493
+ ### Verification
494
+ - All checks passed
495
+ ```
496
+
497
+ ---
498
+
499
+ ## START NOW
500
+
501
+ 1. Define feature requirements
502
+ 2. Load relevant patterns from CLAUDE.md
503
+ 3. Build pattern alignment matrix
504
+ 4. Create tool module with 3-function pattern
505
+ 5. Wire into tools.ts
506
+ 6. Create tests
507
+ 7. Run full verification suite
508
+ 8. Update session state
509
+ 9. Produce feature report
510
+
511
+ **Remember: Patterns from the start, not fixed later.**