cmp-standards 2.4.0 → 2.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 (91) hide show
  1. package/README.md +633 -611
  2. package/dist/db/drizzle-client.d.ts +3 -3
  3. package/dist/db/drizzle-client.d.ts.map +1 -1
  4. package/dist/db/drizzle-client.js +57 -58
  5. package/dist/db/drizzle-client.js.map +1 -1
  6. package/dist/db/turso-client.js +11 -11
  7. package/dist/eslint/rules/no-async-useeffect.js +6 -6
  8. package/dist/hooks/cloud-pre-tool-use.js +20 -20
  9. package/dist/hooks/cloud-session-start.d.ts +15 -3
  10. package/dist/hooks/cloud-session-start.d.ts.map +1 -1
  11. package/dist/hooks/cloud-session-start.js +135 -8
  12. package/dist/hooks/cloud-session-start.js.map +1 -1
  13. package/dist/hooks/session-start.d.ts +2 -1
  14. package/dist/hooks/session-start.d.ts.map +1 -1
  15. package/dist/hooks/session-start.js +99 -74
  16. package/dist/hooks/session-start.js.map +1 -1
  17. package/dist/index.d.ts +4 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +4 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/mcp/server.js +2 -2
  22. package/dist/mcp/server.js.map +1 -1
  23. package/dist/schema/plans.d.ts +194 -0
  24. package/dist/schema/plans.d.ts.map +1 -0
  25. package/dist/schema/plans.js +180 -0
  26. package/dist/schema/plans.js.map +1 -0
  27. package/dist/services/ContextGenerator.d.ts +16 -0
  28. package/dist/services/ContextGenerator.d.ts.map +1 -0
  29. package/dist/services/ContextGenerator.js +62 -0
  30. package/dist/services/ContextGenerator.js.map +1 -0
  31. package/dist/services/PlanManager.d.ts +99 -0
  32. package/dist/services/PlanManager.d.ts.map +1 -0
  33. package/dist/services/PlanManager.js +372 -0
  34. package/dist/services/PlanManager.js.map +1 -0
  35. package/dist/services/ProjectScaffold.js +76 -76
  36. package/dist/services/context-injector.d.ts +105 -0
  37. package/dist/services/context-injector.d.ts.map +1 -0
  38. package/dist/services/context-injector.js +357 -0
  39. package/dist/services/context-injector.js.map +1 -0
  40. package/dist/services/index.d.ts +15 -15
  41. package/dist/services/index.d.ts.map +1 -1
  42. package/dist/services/index.js +18 -20
  43. package/dist/services/index.js.map +1 -1
  44. package/dist/services/memory-router.d.ts +98 -0
  45. package/dist/services/memory-router.d.ts.map +1 -0
  46. package/dist/services/memory-router.js +373 -0
  47. package/dist/services/memory-router.js.map +1 -0
  48. package/dist/services/pattern-tracker.d.ts +93 -0
  49. package/dist/services/pattern-tracker.d.ts.map +1 -0
  50. package/dist/services/pattern-tracker.js +347 -0
  51. package/dist/services/pattern-tracker.js.map +1 -0
  52. package/dist/services/semantic-search.d.ts +33 -35
  53. package/dist/services/semantic-search.d.ts.map +1 -1
  54. package/dist/services/semantic-search.js +207 -165
  55. package/dist/services/semantic-search.js.map +1 -1
  56. package/package.json +100 -100
  57. package/standards/README.md +50 -50
  58. package/standards/experts/expert-routing.md +215 -215
  59. package/standards/general/code-quality.md +86 -86
  60. package/standards/general/memory-usage.md +205 -205
  61. package/standards/general/sync-workflow.md +235 -235
  62. package/standards/general/workflow.md +82 -82
  63. package/standards/hooks/mandatory-tracking.md +446 -446
  64. package/standards/infrastructure/cloud-database.md +287 -287
  65. package/standards/mcp/server-design.md +243 -243
  66. package/standards/mcp/tool-patterns.md +354 -354
  67. package/standards/skills/skill-structure.md +286 -286
  68. package/standards/skills/workflow-design.md +323 -323
  69. package/standards/tools/tool-design.md +297 -297
  70. package/templates/agents/architecture-expert.md +61 -61
  71. package/templates/agents/database-expert.md +62 -62
  72. package/templates/agents/documentation-expert.md +57 -57
  73. package/templates/agents/memory-expert.md +88 -88
  74. package/templates/agents/performance-expert.md +61 -61
  75. package/templates/agents/security-expert.md +59 -59
  76. package/templates/agents/ux-expert.md +63 -63
  77. package/templates/agents/worker.md +75 -75
  78. package/templates/ai-skills/SKILL_TEMPLATE.md +55 -55
  79. package/templates/claude-settings.json +72 -72
  80. package/templates/commands/experts.md +138 -138
  81. package/templates/hooks/README.md +158 -158
  82. package/templates/hooks/project.config.json.template +77 -77
  83. package/templates/hooks/settings.local.json.template +57 -57
  84. package/templates/memory-config.json +56 -56
  85. package/templates/memory-config.schema.json +212 -212
  86. package/templates/settings.json +58 -58
  87. package/templates/skills/continue.md +205 -205
  88. package/templates/workflows/business-improvement.md +264 -264
  89. package/templates/workflows/expert-review.md +153 -153
  90. package/templates/workflows/internal-app.md +245 -245
  91. package/templates/workflows/sync-docs.md +187 -187
package/README.md CHANGED
@@ -1,611 +1,633 @@
1
- # cmp-standards
2
-
3
- > Unified standards, memory, ESLint rules & workflow system for Claude Code projects
4
-
5
- ## Features
6
-
7
- ### Core
8
- - **ESLint Plugin** - 11+ custom rules for code quality
9
- - **Task Tracking** - Automatic task registration in database
10
- - **Idea Capture** - Collect ideas and improvements during work
11
- - **Work Plans** - Persistent work plans across sessions
12
- - **Memory System** - Session context and memory management
13
- - **Auto-Improvement** - Pattern detection and ESLint rule generation
14
- - **Dashboard** - Web UI for visualization
15
- - **MCP Server** - Model Context Protocol integration
16
- - **Analytics** - Usage tracking and insights
17
-
18
- ### Cloud Infrastructure (v2.2.0+)
19
- - **Turso** (SQLite Edge) - Tasks, improvements, memories
20
- - **Upstash Redis** - Session cache, rate limiting
21
- - **Upstash Vector** - Semantic search with embeddings
22
- - **Cloud Hooks** - Session tracking across IDE restarts
23
-
24
- ## Cloud Quick Start
25
-
26
- ```typescript
27
- import { cloud } from 'cmp-standards'
28
-
29
- // Initialize cloud services
30
- await cloud.init()
31
-
32
- // Start work session
33
- const session = await cloud.startWorkSession('MYPROJECT')
34
- console.log(`Active tasks: ${session.activeTasks.length}`)
35
-
36
- // Start task
37
- const taskId = await cloud.startTask('MYPROJECT', session.sessionId, {
38
- title: 'Implement feature X',
39
- plan: ['Step 1', 'Step 2'],
40
- domain: 'features'
41
- })
42
-
43
- // Complete task (requires at least 1 improvement)
44
- await cloud.completeTask(taskId, {
45
- result: 'success',
46
- improvements: [{
47
- area: 'features',
48
- title: 'Add caching',
49
- description: 'Could cache API responses',
50
- priority: 'medium'
51
- }],
52
- lessons: ['Pattern X works better']
53
- })
54
- ```
55
-
56
- ## Environment Variables
57
-
58
- ```env
59
- # Turso (SQLite Edge)
60
- TURSO_DATABASE_URL=libsql://your-db.turso.io
61
- TURSO_AUTH_TOKEN=your-token
62
-
63
- # Upstash Redis
64
- UPSTASH_REDIS_REST_URL=https://your-redis.upstash.io
65
- UPSTASH_REDIS_REST_TOKEN=your-token
66
-
67
- # Upstash Vector
68
- UPSTASH_VECTOR_REST_URL=https://your-vector.upstash.io
69
- UPSTASH_VECTOR_REST_TOKEN=your-token
70
- ```
71
-
72
- ## Installation
73
-
74
- ```bash
75
- npm install cmp-standards
76
- ```
77
-
78
- ## Quick Start
79
-
80
- ```bash
81
- # Initialize in project
82
- cmp-standards init --system MYPROJECT --name "My Project"
83
-
84
- # Check status
85
- cmp-standards status
86
-
87
- # Start dashboard
88
- cmp-standards dashboard
89
- ```
90
-
91
- ## CLI Commands
92
-
93
- ### `cmp-standards init`
94
-
95
- Initialize the system in current project.
96
-
97
- ```bash
98
- cmp-standards init [options]
99
-
100
- Options:
101
- -s, --system <system> System identifier (SWARMSCALE, PANEL)
102
- -n, --name <name> Project name
103
- -f, --force Overwrite existing configuration
104
- ```
105
-
106
- ### `cmp-standards generate`
107
-
108
- Generate embedding registry from documentation.
109
-
110
- ```bash
111
- cmp-standards generate [options]
112
-
113
- Options:
114
- -i, --incremental Only update changed files
115
- --files <files> Specific files (comma-separated)
116
- ```
117
-
118
- ### `cmp-standards scan`
119
-
120
- Scan codebase for patterns.
121
-
122
- ```bash
123
- cmp-standards scan [options]
124
-
125
- Options:
126
- -d, --dir <directory> Directory to scan (default: src)
127
- -t, --threshold <n> Pattern threshold (default: 3)
128
- ```
129
-
130
- ### `cmp-standards improve`
131
-
132
- Run auto-improvement for triggered patterns.
133
-
134
- ```bash
135
- cmp-standards improve [options]
136
-
137
- Options:
138
- --dry-run Show without making changes
139
- -p, --pattern <id> Specific pattern to improve
140
- ```
141
-
142
- ### `cmp-standards status`
143
-
144
- Show memory system status.
145
-
146
- ### `cmp-standards dashboard`
147
-
148
- Start the memory dashboard web UI.
149
-
150
- ```bash
151
- cmp-standards dashboard [options]
152
-
153
- Options:
154
- -p, --port <port> Port to run on (default: 3847)
155
- --no-open Don't open browser automatically
156
- ```
157
-
158
- ### `cmp-standards analytics`
159
-
160
- Show analytics and system health.
161
-
162
- ```bash
163
- cmp-standards analytics [options]
164
-
165
- Options:
166
- -p, --period <period> Time period (day, week, month)
167
- --json Output as JSON
168
- ```
169
-
170
- ### `cmp-standards feedback`
171
-
172
- View feedback statistics.
173
-
174
- ### `cmp-standards mcp`
175
-
176
- Start the MCP server for Claude integration.
177
-
178
- ---
179
-
180
- ## Workflow Commands
181
-
182
- ### `cmp-standards tasks`
183
-
184
- View and manage tasks.
185
-
186
- ```bash
187
- cmp-standards tasks [options]
188
-
189
- Options:
190
- -a, --all Show all tasks including completed
191
- -l, --limit <number> Limit number of tasks (default: 10)
192
- ```
193
-
194
- ### `cmp-standards ideas`
195
-
196
- View captured ideas.
197
-
198
- ```bash
199
- cmp-standards ideas [options]
200
-
201
- Options:
202
- -c, --category <cat> Filter by category (feature, refactor, bug, optimization, documentation)
203
- -p, --priority <pri> Filter by priority (high, medium, low)
204
- -l, --limit <number> Limit number of ideas (default: 20)
205
- ```
206
-
207
- ### `cmp-standards improvements`
208
-
209
- View suggested improvements.
210
-
211
- ```bash
212
- cmp-standards improvements [options]
213
-
214
- Options:
215
- -t, --type <type> Filter by type (code_quality, performance, security, ux, architecture)
216
- -e, --effort <effort> Filter by effort (small, medium, large)
217
- -l, --limit <number> Limit number (default: 20)
218
- ```
219
-
220
- ### `cmp-standards plan`
221
-
222
- Manage work plans.
223
-
224
- ```bash
225
- cmp-standards plan [options]
226
-
227
- Options:
228
- -s, --status Show current plan status
229
- -c, --complete Complete current task
230
- -n, --next Move to next task
231
- -h, --history Show plan history
232
- ```
233
-
234
- ### `cmp-standards capture <text>`
235
-
236
- Quick capture an idea or improvement. Auto-categorizes based on content.
237
-
238
- ```bash
239
- cmp-standards capture "Consider adding caching to API calls"
240
- ```
241
-
242
- ### `cmp-standards export`
243
-
244
- Export ideas and improvements as markdown.
245
-
246
- ```bash
247
- cmp-standards export [options]
248
-
249
- Options:
250
- -o, --output <file> Output file (default: IDEAS_AND_IMPROVEMENTS.md)
251
- ```
252
-
253
- ---
254
-
255
- ## Architecture
256
-
257
- ```
258
- cmp-standards
259
- ├── src/
260
- │ ├── hooks/
261
- │ │ ├── session-start.ts # Context loader on session start
262
- │ │ ├── pre-tool-use.ts # Guards + embedding injection
263
- │ │ ├── post-tool-use.ts # Record changes after Edit/Write
264
- │ │ └── memory-checkpoint.ts # Record learnings after changes
265
- │ ├── eslint/
266
- │ │ ├── index.ts # ESLint plugin entry
267
- │ │ ├── rules/ # Custom ESLint rules
268
- │ │ └── config-builder.ts # Dynamic config generation
269
- │ ├── services/
270
- │ │ ├── TaskTracker.ts # Task tracking
271
- │ │ ├── IdeaCollector.ts # Idea/improvement capture
272
- │ │ ├── WorkPlanManager.ts # Work plan management
273
- │ │ └── ... # Other services
274
- │ ├── registry/
275
- │ │ ├── generator.ts # Parse docs → embeddings
276
- │ │ └── embeddings.ts # OpenAI/Gemini embedding service
277
- │ ├── auto-improve/
278
- │ │ ├── pattern-detector.ts # Detect repeated violations
279
- │ │ └── eslint-generator.ts # Generate ESLint rules
280
- │ ├── db/
281
- │ │ ├── client.ts # DEV_Items database client (mock)
282
- │ └── drizzle-client.ts # Real Drizzle ORM client
283
- │ ├── mcp/
284
- │ │ └── server.ts # MCP server for Claude tools
285
- │ ├── dashboard/
286
- │ │ ├── server.ts # Express dashboard server
287
- │ └── ui.ts # React UI generator
288
- │ ├── utils/
289
- │ │ ├── config.ts # Configuration management
290
- │ │ ├── paths.ts # Path utilities with traversal protection
291
- │ └── git.ts # Safe git operations (simple-git)
292
- │ ├── types/
293
- │ │ └── index.ts # Type definitions
294
- │ ├── cli/
295
- │ │ └── index.ts # CLI commands
296
- └── index.ts # Main exports
297
- ```
298
-
299
- ## Configuration
300
-
301
- ### `.claude/memory-config.json`
302
-
303
- ```json
304
- {
305
- "system": "SWARMSCALE",
306
- "projectName": "SwarmScale",
307
- "domains": ["video-studio", "avatars", "campaigns"],
308
- "guards": {
309
- "enabled": true,
310
- "rules": [
311
- {
312
- "id": "schema-protection",
313
- "type": "block",
314
- "filePattern": "src/server/schema/auth.ts",
315
- "message": "PANEL_* tables are READ-ONLY"
316
- }
317
- ]
318
- },
319
- "embedding": {
320
- "enabled": true,
321
- "threshold": 0.60,
322
- "maxSections": 3
323
- },
324
- "autoImprovement": {
325
- "enabled": true,
326
- "violationThreshold": 3,
327
- "generateEslintRules": true
328
- }
329
- }
330
- ```
331
-
332
- ### `.claude/settings.json`
333
-
334
- ```json
335
- {
336
- "hooks": {
337
- "PreToolUse": [
338
- {
339
- "matcher": "Task",
340
- "hooks": [{
341
- "type": "command",
342
- "command": "npx tsx node_modules/cmp-standards/dist/hooks/pre-tool-use.js"
343
- }]
344
- }
345
- ],
346
- "SessionStart": [
347
- {
348
- "matcher": "",
349
- "hooks": [{
350
- "type": "command",
351
- "command": "npx tsx node_modules/cmp-standards/dist/hooks/session-start.js"
352
- }]
353
- }
354
- ]
355
- },
356
- "plugins": {
357
- "cmp-standards": {
358
- "version": "2.0.0",
359
- "enabled": true
360
- }
361
- }
362
- }
363
- ```
364
-
365
- ## Hooks
366
-
367
- ### SessionStart Hook
368
-
369
- Executes on session start:
370
- 1. Detects module from `git diff` (last 24h)
371
- 2. Queries DEV_Items for relevant memories
372
- 3. Returns formatted context
373
-
374
- ```typescript
375
- import { SessionStartHook } from 'cmp-standards/hooks'
376
-
377
- const hook = new SessionStartHook()
378
- const result = await hook.execute()
379
- // result.context contains session context
380
- ```
381
-
382
- ### PreToolUse Hook
383
-
384
- Executes before Edit/Write/Task tools:
385
- 1. **Edit/Write**: Validates against guard rules
386
- 2. **Task**: Injects relevant knowledge via embeddings
387
-
388
- ```typescript
389
- import { PreToolUseHook } from 'cmp-standards/hooks'
390
-
391
- const hook = new PreToolUseHook()
392
- const result = await hook.execute({
393
- tool_name: 'Edit',
394
- parameters: { file_path: 'src/file.ts', new_string: '...' }
395
- })
396
-
397
- if (result.mode === 'block') {
398
- // Guard violation - block operation
399
- }
400
- ```
401
-
402
- ## ESLint Plugin
403
-
404
- The package includes a custom ESLint plugin with 11+ rules.
405
-
406
- ### Using the ESLint Plugin
407
-
408
- ```javascript
409
- // eslint.config.mjs
410
- import cmpStandards from 'cmp-standards/eslint'
411
-
412
- export default [
413
- ...cmpStandards.configs.recommended,
414
- ]
415
- ```
416
-
417
- ### Dynamic Configuration
418
-
419
- ```typescript
420
- import { generateConfig } from 'cmp-standards/eslint'
421
-
422
- // Generate config based on project structure
423
- const config = await generateConfig(process.cwd())
424
- ```
425
-
426
- ## Auto-Improvement
427
-
428
- ### Pattern Detection
429
-
430
- Built-in patterns detected:
431
- - `any-type` - Using `any` type
432
- - `console-log` - Console.log in production
433
- - `eslint-disable` - ESLint disable comments
434
- - `hardcoded-string` - UI strings not using i18n
435
- - `direct-db-query` - Database queries in components
436
- - `inline-style` - Inline styles instead of Tailwind
437
-
438
- ### ESLint Rule Generation
439
-
440
- When a pattern is detected 3+ times:
441
-
442
- ```bash
443
- # Scan for patterns
444
- cmp-standards scan
445
-
446
- # Output:
447
- # any-type [high]
448
- # Count: 5, Files: 3
449
- # Patterns ready for auto-improvement
450
-
451
- # Generate ESLint rule
452
- cmp-standards improve
453
-
454
- # Creates: eslint-plugin-charter/rules/no-any-type.js
455
- ```
456
-
457
- ## Programmatic Usage
458
-
459
- ```typescript
460
- import {
461
- loadConfig,
462
- PatternDetector,
463
- ESLintGenerator,
464
- RegistryGenerator
465
- } from 'cmp-standards'
466
-
467
- // Load config
468
- const config = await loadConfig(process.cwd())
469
-
470
- // Detect patterns
471
- const detector = new PatternDetector(config)
472
- const patterns = detector.scan(fileContent, filePath)
473
- const results = detector.getResults()
474
-
475
- // Generate ESLint rules
476
- const generator = new ESLintGenerator()
477
- await generator.generateAllRules(results.triggered)
478
-
479
- // Generate registry
480
- const registry = new RegistryGenerator()
481
- await registry.generate()
482
- ```
483
-
484
- ## System Isolation
485
-
486
- Data is isolated by `system` field in DEV_Items:
487
-
488
- | System | Project |
489
- |--------|---------|
490
- | `SWARMSCALE` | SwarmScale |
491
- | `PANEL` | TheCharterPanel |
492
- | `ECOSYSTEM` | Cross-project |
493
-
494
- Always filter by system:
495
-
496
- ```typescript
497
- // Correct
498
- db.select().from(devItems).where(eq(devItems.system, 'SWARMSCALE'))
499
-
500
- // Wrong - returns ALL projects' data
501
- db.select().from(devItems)
502
- ```
503
-
504
- ## Security Features
505
-
506
- ### Path Traversal Protection
507
-
508
- All path operations are validated to prevent directory traversal attacks:
509
-
510
- ```typescript
511
- import { validateSafePath, safeJoin } from 'cmp-standards'
512
-
513
- // Throws PathTraversalError if path escapes base
514
- validateSafePath(projectRoot, userPath)
515
-
516
- // Safe path joining with validation
517
- const safePath = safeJoin(projectRoot, 'subdir', filename)
518
- ```
519
-
520
- ### Safe Git Operations
521
-
522
- Git operations use `simple-git` instead of shell commands to prevent command injection:
523
-
524
- ```typescript
525
- import { getCurrentBranch, getRecentChanges } from 'cmp-standards'
526
-
527
- // Safe - uses simple-git internally
528
- const branch = await getCurrentBranch(projectRoot)
529
- const changes = await getRecentChanges(projectRoot, { commits: 10 })
530
- ```
531
-
532
- ## Environment Variables
533
-
534
- ```bash
535
- # Required for embedding generation
536
- OPENAI_API_KEY=sk-... # Preferred
537
- GEMINI_API_KEY=... # Fallback
538
-
539
- # Optional
540
- MEMORY_DEBUG=true # Enable debug logging
541
- ```
542
-
543
- ## Development
544
-
545
- ```bash
546
- # Install dependencies
547
- npm install
548
-
549
- # Build
550
- npm run build
551
-
552
- # Watch mode
553
- npm run dev
554
-
555
- # Run tests
556
- npm test
557
-
558
- # Link for local development
559
- npm link
560
- ```
561
-
562
- ## MCP Server
563
-
564
- The MCP (Model Context Protocol) server exposes memory tools that Claude can use directly:
565
-
566
- ```bash
567
- # Start MCP server
568
- cmp-standards mcp
569
- ```
570
-
571
- **Available Tools:**
572
- - `memory_search` - Search memories by query
573
- - `memory_write` - Write new memory/learning
574
- - `memory_list` - List recent memories
575
- - `pattern_check` - Check for detected patterns
576
- - `pattern_report` - Report a new pattern occurrence
577
- - `session_context` - Get current session context
578
- - `feedback_submit` - Submit feedback on a memory
579
-
580
- ## Dashboard
581
-
582
- Start the standalone web dashboard:
583
-
584
- ```bash
585
- cmp-standards dashboard
586
- # Opens http://localhost:3847
587
- ```
588
-
589
- **Features:**
590
- - View all memories with search and filtering
591
- - Browse detected patterns
592
- - See session history
593
- - Submit feedback on memories
594
- - Create new memories
595
- - View analytics and system health
596
-
597
- ## Database Configuration
598
-
599
- Set environment variables for database connection:
600
-
601
- ```bash
602
- DATABASE_HOST=localhost
603
- DATABASE_PORT=3306
604
- DATABASE_USER=root
605
- DATABASE_PASSWORD=your-password
606
- DATABASE_NAME=metanautical
607
- ```
608
-
609
- ## License
610
-
611
- MIT - Carlos Martin Pavon
1
+ # CMP - Collective Memory Protocol
2
+
3
+ > **The Development Intelligence Layer** - Persistent memory, cross-project learning, and multi-agent collaboration for AI-assisted development.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/cmp-standards.svg)](https://www.npmjs.com/package/cmp-standards)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ---
9
+
10
+ ## Philosophy
11
+
12
+ | Principle | Meaning |
13
+ |-----------|---------|
14
+ | **Evidence > Assumptions** | Never assume. Always verify. Read before writing. |
15
+ | **Cloud > Local** | Memory lives in the cloud. Sessions are ephemeral, knowledge is permanent. |
16
+ | **Collective > Individual** | One project's learnings benefit all projects. |
17
+ | **Continuity > Restarts** | Work survives IDE restarts, machine changes, and agent switches. |
18
+
19
+ ---
20
+
21
+ ## Features
22
+
23
+ ### Core
24
+ - **Plans with Checkpoints** - Persistent objectives with semantic matching and multi-agent handoffs
25
+ - **ESLint Plugin** - 11+ custom rules for code quality
26
+ - **Task Tracking** - Automatic task registration in database
27
+ - **Idea Capture** - Collect ideas and improvements during work
28
+ - **Memory System** - Session context and memory management
29
+ - **Auto-Improvement** - Pattern detection and ESLint rule generation
30
+ - **Dashboard** - Web UI for visualization
31
+ - **MCP Server** - Model Context Protocol integration
32
+ - **Analytics** - Usage tracking and insights
33
+
34
+ ### Cloud Infrastructure
35
+ - **Turso** (SQLite Edge) - Plans, tasks, improvements, memories
36
+ - **Upstash Redis** - Session cache, rate limiting, real-time sync
37
+ - **Upstash Vector** - Semantic search with embeddings
38
+ - **Cloud Hooks** - Session continuity across IDE restarts
39
+
40
+ ### Multi-Agent Continuity (v2.5.0+)
41
+ - **Plan Detection** - Semantic matching finds related plans at session start
42
+ - **Checkpoints** - Save points that record progress, decisions, and next steps
43
+ - **Agent Handoffs** - One agent can resume where another left off
44
+ - **Cross-Session** - Plans persist across IDE restarts and machine changes
45
+
46
+ ## Cloud Quick Start
47
+
48
+ ```typescript
49
+ import { cloud } from 'cmp-standards'
50
+
51
+ // Initialize cloud services
52
+ await cloud.init()
53
+
54
+ // Start work session
55
+ const session = await cloud.startWorkSession('MYPROJECT')
56
+ console.log(`Active tasks: ${session.activeTasks.length}`)
57
+
58
+ // Start task
59
+ const taskId = await cloud.startTask('MYPROJECT', session.sessionId, {
60
+ title: 'Implement feature X',
61
+ plan: ['Step 1', 'Step 2'],
62
+ domain: 'features'
63
+ })
64
+
65
+ // Complete task (requires at least 1 improvement)
66
+ await cloud.completeTask(taskId, {
67
+ result: 'success',
68
+ improvements: [{
69
+ area: 'features',
70
+ title: 'Add caching',
71
+ description: 'Could cache API responses',
72
+ priority: 'medium'
73
+ }],
74
+ lessons: ['Pattern X works better']
75
+ })
76
+ ```
77
+
78
+ ## Environment Variables
79
+
80
+ ```env
81
+ # Turso (SQLite Edge)
82
+ TURSO_DATABASE_URL=libsql://your-db.turso.io
83
+ TURSO_AUTH_TOKEN=your-token
84
+
85
+ # Upstash Redis
86
+ UPSTASH_REDIS_REST_URL=https://your-redis.upstash.io
87
+ UPSTASH_REDIS_REST_TOKEN=your-token
88
+
89
+ # Upstash Vector
90
+ UPSTASH_VECTOR_REST_URL=https://your-vector.upstash.io
91
+ UPSTASH_VECTOR_REST_TOKEN=your-token
92
+ ```
93
+
94
+ ## Installation
95
+
96
+ ```bash
97
+ npm install cmp-standards
98
+ ```
99
+
100
+ ## Quick Start
101
+
102
+ ```bash
103
+ # Initialize in project
104
+ cmp-standards init --system MYPROJECT --name "My Project"
105
+
106
+ # Check status
107
+ cmp-standards status
108
+
109
+ # Start dashboard
110
+ cmp-standards dashboard
111
+ ```
112
+
113
+ ## CLI Commands
114
+
115
+ ### `cmp-standards init`
116
+
117
+ Initialize the system in current project.
118
+
119
+ ```bash
120
+ cmp-standards init [options]
121
+
122
+ Options:
123
+ -s, --system <system> System identifier (SWARMSCALE, PANEL)
124
+ -n, --name <name> Project name
125
+ -f, --force Overwrite existing configuration
126
+ ```
127
+
128
+ ### `cmp-standards generate`
129
+
130
+ Generate embedding registry from documentation.
131
+
132
+ ```bash
133
+ cmp-standards generate [options]
134
+
135
+ Options:
136
+ -i, --incremental Only update changed files
137
+ --files <files> Specific files (comma-separated)
138
+ ```
139
+
140
+ ### `cmp-standards scan`
141
+
142
+ Scan codebase for patterns.
143
+
144
+ ```bash
145
+ cmp-standards scan [options]
146
+
147
+ Options:
148
+ -d, --dir <directory> Directory to scan (default: src)
149
+ -t, --threshold <n> Pattern threshold (default: 3)
150
+ ```
151
+
152
+ ### `cmp-standards improve`
153
+
154
+ Run auto-improvement for triggered patterns.
155
+
156
+ ```bash
157
+ cmp-standards improve [options]
158
+
159
+ Options:
160
+ --dry-run Show without making changes
161
+ -p, --pattern <id> Specific pattern to improve
162
+ ```
163
+
164
+ ### `cmp-standards status`
165
+
166
+ Show memory system status.
167
+
168
+ ### `cmp-standards dashboard`
169
+
170
+ Start the memory dashboard web UI.
171
+
172
+ ```bash
173
+ cmp-standards dashboard [options]
174
+
175
+ Options:
176
+ -p, --port <port> Port to run on (default: 3847)
177
+ --no-open Don't open browser automatically
178
+ ```
179
+
180
+ ### `cmp-standards analytics`
181
+
182
+ Show analytics and system health.
183
+
184
+ ```bash
185
+ cmp-standards analytics [options]
186
+
187
+ Options:
188
+ -p, --period <period> Time period (day, week, month)
189
+ --json Output as JSON
190
+ ```
191
+
192
+ ### `cmp-standards feedback`
193
+
194
+ View feedback statistics.
195
+
196
+ ### `cmp-standards mcp`
197
+
198
+ Start the MCP server for Claude integration.
199
+
200
+ ---
201
+
202
+ ## Workflow Commands
203
+
204
+ ### `cmp-standards tasks`
205
+
206
+ View and manage tasks.
207
+
208
+ ```bash
209
+ cmp-standards tasks [options]
210
+
211
+ Options:
212
+ -a, --all Show all tasks including completed
213
+ -l, --limit <number> Limit number of tasks (default: 10)
214
+ ```
215
+
216
+ ### `cmp-standards ideas`
217
+
218
+ View captured ideas.
219
+
220
+ ```bash
221
+ cmp-standards ideas [options]
222
+
223
+ Options:
224
+ -c, --category <cat> Filter by category (feature, refactor, bug, optimization, documentation)
225
+ -p, --priority <pri> Filter by priority (high, medium, low)
226
+ -l, --limit <number> Limit number of ideas (default: 20)
227
+ ```
228
+
229
+ ### `cmp-standards improvements`
230
+
231
+ View suggested improvements.
232
+
233
+ ```bash
234
+ cmp-standards improvements [options]
235
+
236
+ Options:
237
+ -t, --type <type> Filter by type (code_quality, performance, security, ux, architecture)
238
+ -e, --effort <effort> Filter by effort (small, medium, large)
239
+ -l, --limit <number> Limit number (default: 20)
240
+ ```
241
+
242
+ ### `cmp-standards plan`
243
+
244
+ Manage work plans.
245
+
246
+ ```bash
247
+ cmp-standards plan [options]
248
+
249
+ Options:
250
+ -s, --status Show current plan status
251
+ -c, --complete Complete current task
252
+ -n, --next Move to next task
253
+ -h, --history Show plan history
254
+ ```
255
+
256
+ ### `cmp-standards capture <text>`
257
+
258
+ Quick capture an idea or improvement. Auto-categorizes based on content.
259
+
260
+ ```bash
261
+ cmp-standards capture "Consider adding caching to API calls"
262
+ ```
263
+
264
+ ### `cmp-standards export`
265
+
266
+ Export ideas and improvements as markdown.
267
+
268
+ ```bash
269
+ cmp-standards export [options]
270
+
271
+ Options:
272
+ -o, --output <file> Output file (default: IDEAS_AND_IMPROVEMENTS.md)
273
+ ```
274
+
275
+ ---
276
+
277
+ ## Architecture
278
+
279
+ ```
280
+ cmp-standards
281
+ ├── src/
282
+ ├── hooks/
283
+ ├── session-start.ts # Context loader on session start
284
+ │ │ ├── pre-tool-use.ts # Guards + embedding injection
285
+ ├── post-tool-use.ts # Record changes after Edit/Write
286
+ │ │ └── memory-checkpoint.ts # Record learnings after changes
287
+ ├── eslint/
288
+ ├── index.ts # ESLint plugin entry
289
+ │ │ ├── rules/ # Custom ESLint rules
290
+ │ │ └── config-builder.ts # Dynamic config generation
291
+ ├── services/
292
+ ├── TaskTracker.ts # Task tracking
293
+ │ │ ├── IdeaCollector.ts # Idea/improvement capture
294
+ ├── WorkPlanManager.ts # Work plan management
295
+ │ │ └── ... # Other services
296
+ ├── registry/
297
+ │ │ ├── generator.ts # Parse docs → embeddings
298
+ │ │ └── embeddings.ts # OpenAI/Gemini embedding service
299
+ │ ├── auto-improve/
300
+ │ │ ├── pattern-detector.ts # Detect repeated violations
301
+ │ │ └── eslint-generator.ts # Generate ESLint rules
302
+ │ ├── db/
303
+ │ │ ├── client.ts # DEV_Items database client (mock)
304
+ │ │ └── drizzle-client.ts # Real Drizzle ORM client
305
+ │ ├── mcp/
306
+ │ │ └── server.ts # MCP server for Claude tools
307
+ │ ├── dashboard/
308
+ │ │ ├── server.ts # Express dashboard server
309
+ │ │ └── ui.ts # React UI generator
310
+ │ ├── utils/
311
+ │ │ ├── config.ts # Configuration management
312
+ │ │ ├── paths.ts # Path utilities with traversal protection
313
+ │ │ └── git.ts # Safe git operations (simple-git)
314
+ │ ├── types/
315
+ │ │ └── index.ts # Type definitions
316
+ │ ├── cli/
317
+ │ │ └── index.ts # CLI commands
318
+ │ └── index.ts # Main exports
319
+ ```
320
+
321
+ ## Configuration
322
+
323
+ ### `.claude/memory-config.json`
324
+
325
+ ```json
326
+ {
327
+ "system": "SWARMSCALE",
328
+ "projectName": "SwarmScale",
329
+ "domains": ["video-studio", "avatars", "campaigns"],
330
+ "guards": {
331
+ "enabled": true,
332
+ "rules": [
333
+ {
334
+ "id": "schema-protection",
335
+ "type": "block",
336
+ "filePattern": "src/server/schema/auth.ts",
337
+ "message": "PANEL_* tables are READ-ONLY"
338
+ }
339
+ ]
340
+ },
341
+ "embedding": {
342
+ "enabled": true,
343
+ "threshold": 0.60,
344
+ "maxSections": 3
345
+ },
346
+ "autoImprovement": {
347
+ "enabled": true,
348
+ "violationThreshold": 3,
349
+ "generateEslintRules": true
350
+ }
351
+ }
352
+ ```
353
+
354
+ ### `.claude/settings.json`
355
+
356
+ ```json
357
+ {
358
+ "hooks": {
359
+ "PreToolUse": [
360
+ {
361
+ "matcher": "Task",
362
+ "hooks": [{
363
+ "type": "command",
364
+ "command": "npx tsx node_modules/cmp-standards/dist/hooks/pre-tool-use.js"
365
+ }]
366
+ }
367
+ ],
368
+ "SessionStart": [
369
+ {
370
+ "matcher": "",
371
+ "hooks": [{
372
+ "type": "command",
373
+ "command": "npx tsx node_modules/cmp-standards/dist/hooks/session-start.js"
374
+ }]
375
+ }
376
+ ]
377
+ },
378
+ "plugins": {
379
+ "cmp-standards": {
380
+ "version": "2.0.0",
381
+ "enabled": true
382
+ }
383
+ }
384
+ }
385
+ ```
386
+
387
+ ## Hooks
388
+
389
+ ### SessionStart Hook
390
+
391
+ Executes on session start:
392
+ 1. Detects module from `git diff` (last 24h)
393
+ 2. Queries DEV_Items for relevant memories
394
+ 3. Returns formatted context
395
+
396
+ ```typescript
397
+ import { SessionStartHook } from 'cmp-standards/hooks'
398
+
399
+ const hook = new SessionStartHook()
400
+ const result = await hook.execute()
401
+ // result.context contains session context
402
+ ```
403
+
404
+ ### PreToolUse Hook
405
+
406
+ Executes before Edit/Write/Task tools:
407
+ 1. **Edit/Write**: Validates against guard rules
408
+ 2. **Task**: Injects relevant knowledge via embeddings
409
+
410
+ ```typescript
411
+ import { PreToolUseHook } from 'cmp-standards/hooks'
412
+
413
+ const hook = new PreToolUseHook()
414
+ const result = await hook.execute({
415
+ tool_name: 'Edit',
416
+ parameters: { file_path: 'src/file.ts', new_string: '...' }
417
+ })
418
+
419
+ if (result.mode === 'block') {
420
+ // Guard violation - block operation
421
+ }
422
+ ```
423
+
424
+ ## ESLint Plugin
425
+
426
+ The package includes a custom ESLint plugin with 11+ rules.
427
+
428
+ ### Using the ESLint Plugin
429
+
430
+ ```javascript
431
+ // eslint.config.mjs
432
+ import cmpStandards from 'cmp-standards/eslint'
433
+
434
+ export default [
435
+ ...cmpStandards.configs.recommended,
436
+ ]
437
+ ```
438
+
439
+ ### Dynamic Configuration
440
+
441
+ ```typescript
442
+ import { generateConfig } from 'cmp-standards/eslint'
443
+
444
+ // Generate config based on project structure
445
+ const config = await generateConfig(process.cwd())
446
+ ```
447
+
448
+ ## Auto-Improvement
449
+
450
+ ### Pattern Detection
451
+
452
+ Built-in patterns detected:
453
+ - `any-type` - Using `any` type
454
+ - `console-log` - Console.log in production
455
+ - `eslint-disable` - ESLint disable comments
456
+ - `hardcoded-string` - UI strings not using i18n
457
+ - `direct-db-query` - Database queries in components
458
+ - `inline-style` - Inline styles instead of Tailwind
459
+
460
+ ### ESLint Rule Generation
461
+
462
+ When a pattern is detected 3+ times:
463
+
464
+ ```bash
465
+ # Scan for patterns
466
+ cmp-standards scan
467
+
468
+ # Output:
469
+ # any-type [high]
470
+ # Count: 5, Files: 3
471
+ # Patterns ready for auto-improvement
472
+
473
+ # Generate ESLint rule
474
+ cmp-standards improve
475
+
476
+ # Creates: eslint-plugin-charter/rules/no-any-type.js
477
+ ```
478
+
479
+ ## Programmatic Usage
480
+
481
+ ```typescript
482
+ import {
483
+ loadConfig,
484
+ PatternDetector,
485
+ ESLintGenerator,
486
+ RegistryGenerator
487
+ } from 'cmp-standards'
488
+
489
+ // Load config
490
+ const config = await loadConfig(process.cwd())
491
+
492
+ // Detect patterns
493
+ const detector = new PatternDetector(config)
494
+ const patterns = detector.scan(fileContent, filePath)
495
+ const results = detector.getResults()
496
+
497
+ // Generate ESLint rules
498
+ const generator = new ESLintGenerator()
499
+ await generator.generateAllRules(results.triggered)
500
+
501
+ // Generate registry
502
+ const registry = new RegistryGenerator()
503
+ await registry.generate()
504
+ ```
505
+
506
+ ## System Isolation
507
+
508
+ Data is isolated by `system` field in DEV_Items:
509
+
510
+ | System | Project |
511
+ |--------|---------|
512
+ | `SWARMSCALE` | SwarmScale |
513
+ | `PANEL` | TheCharterPanel |
514
+ | `ECOSYSTEM` | Cross-project |
515
+
516
+ Always filter by system:
517
+
518
+ ```typescript
519
+ // Correct
520
+ db.select().from(devItems).where(eq(devItems.system, 'SWARMSCALE'))
521
+
522
+ // Wrong - returns ALL projects' data
523
+ db.select().from(devItems)
524
+ ```
525
+
526
+ ## Security Features
527
+
528
+ ### Path Traversal Protection
529
+
530
+ All path operations are validated to prevent directory traversal attacks:
531
+
532
+ ```typescript
533
+ import { validateSafePath, safeJoin } from 'cmp-standards'
534
+
535
+ // Throws PathTraversalError if path escapes base
536
+ validateSafePath(projectRoot, userPath)
537
+
538
+ // Safe path joining with validation
539
+ const safePath = safeJoin(projectRoot, 'subdir', filename)
540
+ ```
541
+
542
+ ### Safe Git Operations
543
+
544
+ Git operations use `simple-git` instead of shell commands to prevent command injection:
545
+
546
+ ```typescript
547
+ import { getCurrentBranch, getRecentChanges } from 'cmp-standards'
548
+
549
+ // Safe - uses simple-git internally
550
+ const branch = await getCurrentBranch(projectRoot)
551
+ const changes = await getRecentChanges(projectRoot, { commits: 10 })
552
+ ```
553
+
554
+ ## Environment Variables
555
+
556
+ ```bash
557
+ # Required for embedding generation
558
+ OPENAI_API_KEY=sk-... # Preferred
559
+ GEMINI_API_KEY=... # Fallback
560
+
561
+ # Optional
562
+ MEMORY_DEBUG=true # Enable debug logging
563
+ ```
564
+
565
+ ## Development
566
+
567
+ ```bash
568
+ # Install dependencies
569
+ npm install
570
+
571
+ # Build
572
+ npm run build
573
+
574
+ # Watch mode
575
+ npm run dev
576
+
577
+ # Run tests
578
+ npm test
579
+
580
+ # Link for local development
581
+ npm link
582
+ ```
583
+
584
+ ## MCP Server
585
+
586
+ The MCP (Model Context Protocol) server exposes memory tools that Claude can use directly:
587
+
588
+ ```bash
589
+ # Start MCP server
590
+ cmp-standards mcp
591
+ ```
592
+
593
+ **Available Tools:**
594
+ - `memory_search` - Search memories by query
595
+ - `memory_write` - Write new memory/learning
596
+ - `memory_list` - List recent memories
597
+ - `pattern_check` - Check for detected patterns
598
+ - `pattern_report` - Report a new pattern occurrence
599
+ - `session_context` - Get current session context
600
+ - `feedback_submit` - Submit feedback on a memory
601
+
602
+ ## Dashboard
603
+
604
+ Start the standalone web dashboard:
605
+
606
+ ```bash
607
+ cmp-standards dashboard
608
+ # Opens http://localhost:3847
609
+ ```
610
+
611
+ **Features:**
612
+ - View all memories with search and filtering
613
+ - Browse detected patterns
614
+ - See session history
615
+ - Submit feedback on memories
616
+ - Create new memories
617
+ - View analytics and system health
618
+
619
+ ## Database Configuration
620
+
621
+ Set environment variables for database connection:
622
+
623
+ ```bash
624
+ DATABASE_HOST=localhost
625
+ DATABASE_PORT=3306
626
+ DATABASE_USER=root
627
+ DATABASE_PASSWORD=your-password
628
+ DATABASE_NAME=metanautical
629
+ ```
630
+
631
+ ## License
632
+
633
+ MIT - Carlos Martin Pavon