cmp-standards 2.0.1 → 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 (167) hide show
  1. package/README.md +633 -541
  2. package/dist/cli/index.js +239 -7
  3. package/dist/cli/index.js.map +1 -1
  4. package/dist/dashboard/server.d.ts.map +1 -1
  5. package/dist/dashboard/server.js +203 -39
  6. package/dist/dashboard/server.js.map +1 -1
  7. package/dist/db/cloud.d.ts +174 -0
  8. package/dist/db/cloud.d.ts.map +1 -0
  9. package/dist/db/cloud.js +241 -0
  10. package/dist/db/cloud.js.map +1 -0
  11. package/dist/db/drizzle-client.d.ts +3 -3
  12. package/dist/db/drizzle-client.d.ts.map +1 -1
  13. package/dist/db/drizzle-client.js +57 -58
  14. package/dist/db/drizzle-client.js.map +1 -1
  15. package/dist/db/errors.d.ts +76 -0
  16. package/dist/db/errors.d.ts.map +1 -0
  17. package/dist/db/errors.js +135 -0
  18. package/dist/db/errors.js.map +1 -0
  19. package/dist/db/turso-client.d.ts +178 -0
  20. package/dist/db/turso-client.d.ts.map +1 -0
  21. package/dist/db/turso-client.js +455 -0
  22. package/dist/db/turso-client.js.map +1 -0
  23. package/dist/db/upstash-client.d.ts +161 -0
  24. package/dist/db/upstash-client.d.ts.map +1 -0
  25. package/dist/db/upstash-client.js +325 -0
  26. package/dist/db/upstash-client.js.map +1 -0
  27. package/dist/eslint/rules/no-async-useeffect.js +6 -6
  28. package/dist/hooks/cloud-post-tool-use.d.ts +30 -0
  29. package/dist/hooks/cloud-post-tool-use.d.ts.map +1 -0
  30. package/dist/hooks/cloud-post-tool-use.js +116 -0
  31. package/dist/hooks/cloud-post-tool-use.js.map +1 -0
  32. package/dist/hooks/cloud-pre-tool-use.d.ts +19 -0
  33. package/dist/hooks/cloud-pre-tool-use.d.ts.map +1 -0
  34. package/dist/hooks/cloud-pre-tool-use.js +149 -0
  35. package/dist/hooks/cloud-pre-tool-use.js.map +1 -0
  36. package/dist/hooks/cloud-session-start.d.ts +32 -0
  37. package/dist/hooks/cloud-session-start.d.ts.map +1 -0
  38. package/dist/hooks/cloud-session-start.js +257 -0
  39. package/dist/hooks/cloud-session-start.js.map +1 -0
  40. package/dist/hooks/index.d.ts +3 -0
  41. package/dist/hooks/index.d.ts.map +1 -1
  42. package/dist/hooks/index.js +5 -0
  43. package/dist/hooks/index.js.map +1 -1
  44. package/dist/hooks/memory-checkpoint.d.ts.map +1 -1
  45. package/dist/hooks/memory-checkpoint.js +12 -20
  46. package/dist/hooks/memory-checkpoint.js.map +1 -1
  47. package/dist/hooks/pre-tool-use.d.ts +2 -8
  48. package/dist/hooks/pre-tool-use.d.ts.map +1 -1
  49. package/dist/hooks/pre-tool-use.js +7 -106
  50. package/dist/hooks/pre-tool-use.js.map +1 -1
  51. package/dist/hooks/session-start.d.ts +2 -1
  52. package/dist/hooks/session-start.d.ts.map +1 -1
  53. package/dist/hooks/session-start.js +111 -77
  54. package/dist/hooks/session-start.js.map +1 -1
  55. package/dist/index.d.ts +14 -0
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +18 -1
  58. package/dist/index.js.map +1 -1
  59. package/dist/mcp/server.d.ts.map +1 -1
  60. package/dist/mcp/server.js +225 -2
  61. package/dist/mcp/server.js.map +1 -1
  62. package/dist/schema/plans.d.ts +194 -0
  63. package/dist/schema/plans.d.ts.map +1 -0
  64. package/dist/schema/plans.js +180 -0
  65. package/dist/schema/plans.js.map +1 -0
  66. package/dist/schema/tracking.d.ts +644 -0
  67. package/dist/schema/tracking.d.ts.map +1 -0
  68. package/dist/schema/tracking.js +204 -0
  69. package/dist/schema/tracking.js.map +1 -0
  70. package/dist/services/ContextGenerator.d.ts +16 -0
  71. package/dist/services/ContextGenerator.d.ts.map +1 -0
  72. package/dist/services/ContextGenerator.js +62 -0
  73. package/dist/services/ContextGenerator.js.map +1 -0
  74. package/dist/services/PlanManager.d.ts +99 -0
  75. package/dist/services/PlanManager.d.ts.map +1 -0
  76. package/dist/services/PlanManager.js +372 -0
  77. package/dist/services/PlanManager.js.map +1 -0
  78. package/dist/services/ProjectScaffold.d.ts.map +1 -1
  79. package/dist/services/ProjectScaffold.js +109 -81
  80. package/dist/services/ProjectScaffold.js.map +1 -1
  81. package/dist/services/TaskTracker.d.ts +1 -1
  82. package/dist/services/TaskTracker.d.ts.map +1 -1
  83. package/dist/services/TaskTracker.js +4 -8
  84. package/dist/services/TaskTracker.js.map +1 -1
  85. package/dist/services/WorkPlanManager.d.ts +1 -1
  86. package/dist/services/WorkPlanManager.d.ts.map +1 -1
  87. package/dist/services/WorkPlanManager.js +8 -14
  88. package/dist/services/WorkPlanManager.js.map +1 -1
  89. package/dist/services/auto-inject.d.ts +1 -0
  90. package/dist/services/auto-inject.d.ts.map +1 -1
  91. package/dist/services/auto-inject.js +12 -17
  92. package/dist/services/auto-inject.js.map +1 -1
  93. package/dist/services/context-injector.d.ts +105 -0
  94. package/dist/services/context-injector.d.ts.map +1 -0
  95. package/dist/services/context-injector.js +357 -0
  96. package/dist/services/context-injector.js.map +1 -0
  97. package/dist/services/cross-project-sync.d.ts +2 -0
  98. package/dist/services/cross-project-sync.d.ts.map +1 -1
  99. package/dist/services/cross-project-sync.js +26 -21
  100. package/dist/services/cross-project-sync.js.map +1 -1
  101. package/dist/services/index.d.ts +15 -15
  102. package/dist/services/index.d.ts.map +1 -1
  103. package/dist/services/index.js +18 -20
  104. package/dist/services/index.js.map +1 -1
  105. package/dist/services/memory-consolidation.d.ts.map +1 -1
  106. package/dist/services/memory-consolidation.js +30 -27
  107. package/dist/services/memory-consolidation.js.map +1 -1
  108. package/dist/services/memory-router.d.ts +98 -0
  109. package/dist/services/memory-router.d.ts.map +1 -0
  110. package/dist/services/memory-router.js +373 -0
  111. package/dist/services/memory-router.js.map +1 -0
  112. package/dist/services/pattern-tracker.d.ts +93 -0
  113. package/dist/services/pattern-tracker.d.ts.map +1 -0
  114. package/dist/services/pattern-tracker.js +347 -0
  115. package/dist/services/pattern-tracker.js.map +1 -0
  116. package/dist/services/semantic-search.d.ts +33 -35
  117. package/dist/services/semantic-search.d.ts.map +1 -1
  118. package/dist/services/semantic-search.js +207 -165
  119. package/dist/services/semantic-search.js.map +1 -1
  120. package/dist/utils/env-loader.d.ts +41 -0
  121. package/dist/utils/env-loader.d.ts.map +1 -0
  122. package/dist/utils/env-loader.js +78 -0
  123. package/dist/utils/env-loader.js.map +1 -0
  124. package/dist/utils/git.d.ts +52 -0
  125. package/dist/utils/git.d.ts.map +1 -0
  126. package/dist/utils/git.js +267 -0
  127. package/dist/utils/git.js.map +1 -0
  128. package/dist/utils/paths.d.ts +39 -5
  129. package/dist/utils/paths.d.ts.map +1 -1
  130. package/dist/utils/paths.js +88 -7
  131. package/dist/utils/paths.js.map +1 -1
  132. package/package.json +100 -94
  133. package/standards/README.md +50 -0
  134. package/standards/experts/expert-routing.md +215 -0
  135. package/standards/general/code-quality.md +86 -0
  136. package/standards/general/memory-usage.md +205 -0
  137. package/standards/general/sync-workflow.md +235 -0
  138. package/standards/general/workflow.md +82 -0
  139. package/standards/hooks/mandatory-tracking.md +446 -0
  140. package/standards/infrastructure/cloud-database.md +287 -0
  141. package/standards/mcp/server-design.md +243 -0
  142. package/standards/mcp/tool-patterns.md +354 -0
  143. package/standards/skills/skill-structure.md +286 -0
  144. package/standards/skills/workflow-design.md +323 -0
  145. package/standards/tools/tool-design.md +297 -0
  146. package/templates/agents/architecture-expert.md +61 -61
  147. package/templates/agents/database-expert.md +62 -62
  148. package/templates/agents/documentation-expert.md +57 -57
  149. package/templates/agents/memory-expert.md +88 -88
  150. package/templates/agents/performance-expert.md +61 -61
  151. package/templates/agents/security-expert.md +59 -59
  152. package/templates/agents/ux-expert.md +63 -63
  153. package/templates/agents/worker.md +75 -75
  154. package/templates/ai-skills/SKILL_TEMPLATE.md +55 -55
  155. package/templates/claude-settings.json +72 -0
  156. package/templates/commands/experts.md +138 -138
  157. package/templates/hooks/README.md +158 -158
  158. package/templates/hooks/project.config.json.template +77 -77
  159. package/templates/hooks/settings.local.json.template +57 -57
  160. package/templates/memory-config.json +56 -82
  161. package/templates/memory-config.schema.json +212 -212
  162. package/templates/settings.json +58 -58
  163. package/templates/skills/continue.md +205 -0
  164. package/templates/workflows/business-improvement.md +264 -264
  165. package/templates/workflows/expert-review.md +153 -153
  166. package/templates/workflows/internal-app.md +245 -245
  167. package/templates/workflows/sync-docs.md +187 -187
package/README.md CHANGED
@@ -1,541 +1,633 @@
1
- # cmp-memory-system
2
-
3
- > Unified memory & workflow system for Claude Code projects
4
-
5
- ## Features
6
-
7
- - **Task Tracking** - Automatic task registration in database
8
- - **Idea Capture** - Collect ideas and improvements during work
9
- - **Work Plans** - Persistent work plans across sessions
10
- - **Memory System** - Session context and memory management
11
- - **Auto-Improvement** - Pattern detection → ESLint rule generation
12
- - **Dashboard** - Web UI for visualization
13
- - **MCP Server** - Model Context Protocol integration
14
- - **Analytics** - Usage tracking and insights
15
-
16
- ## Installation
17
-
18
- ```bash
19
- npm install cmp-memory-system
20
- ```
21
-
22
- ## Quick Start
23
-
24
- ```bash
25
- # Initialize in project
26
- cmp-memory init --system MYPROJECT --name "My Project"
27
-
28
- # Check status
29
- cmp-memory status
30
-
31
- # Check status
32
- claude-memory status
33
- ```
34
-
35
- ## CLI Commands
36
-
37
- ### `claude-memory init`
38
-
39
- Initialize memory system in current project.
40
-
41
- ```bash
42
- claude-memory init [options]
43
-
44
- Options:
45
- -s, --system <system> System identifier (SWARMSCALE, PANEL)
46
- -n, --name <name> Project name
47
- -f, --force Overwrite existing configuration
48
- ```
49
-
50
- ### `claude-memory generate`
51
-
52
- Generate embedding registry from documentation.
53
-
54
- ```bash
55
- claude-memory generate [options]
56
-
57
- Options:
58
- -i, --incremental Only update changed files
59
- --files <files> Specific files (comma-separated)
60
- ```
61
-
62
- ### `claude-memory scan`
63
-
64
- Scan codebase for patterns.
65
-
66
- ```bash
67
- claude-memory scan [options]
68
-
69
- Options:
70
- -d, --dir <directory> Directory to scan (default: src)
71
- -t, --threshold <n> Pattern threshold (default: 3)
72
- ```
73
-
74
- ### `claude-memory improve`
75
-
76
- Run auto-improvement for triggered patterns.
77
-
78
- ```bash
79
- claude-memory improve [options]
80
-
81
- Options:
82
- --dry-run Show without making changes
83
- -p, --pattern <id> Specific pattern to improve
84
- ```
85
-
86
- ### `claude-memory status`
87
-
88
- Show memory system status.
89
-
90
- ### `claude-memory dashboard`
91
-
92
- Start the memory dashboard web UI.
93
-
94
- ```bash
95
- claude-memory dashboard [options]
96
-
97
- Options:
98
- -p, --port <port> Port to run on (default: 3847)
99
- --no-open Don't open browser automatically
100
- ```
101
-
102
- ### `claude-memory analytics`
103
-
104
- Show analytics and system health.
105
-
106
- ```bash
107
- claude-memory analytics [options]
108
-
109
- Options:
110
- -p, --period <period> Time period (day, week, month)
111
- --json Output as JSON
112
- ```
113
-
114
- ### `claude-memory feedback`
115
-
116
- View feedback statistics.
117
-
118
- ### `claude-memory mcp`
119
-
120
- Start the MCP server for Claude integration.
121
-
122
- ---
123
-
124
- ## Workflow Commands (NEW)
125
-
126
- ### `claude-memory tasks`
127
-
128
- View and manage tasks.
129
-
130
- ```bash
131
- claude-memory tasks [options]
132
-
133
- Options:
134
- -a, --all Show all tasks including completed
135
- -l, --limit <number> Limit number of tasks (default: 10)
136
- ```
137
-
138
- ### `claude-memory ideas`
139
-
140
- View captured ideas.
141
-
142
- ```bash
143
- claude-memory ideas [options]
144
-
145
- Options:
146
- -c, --category <cat> Filter by category (feature, refactor, bug, optimization, documentation)
147
- -p, --priority <pri> Filter by priority (high, medium, low)
148
- -l, --limit <number> Limit number of ideas (default: 20)
149
- ```
150
-
151
- ### `claude-memory improvements`
152
-
153
- View suggested improvements.
154
-
155
- ```bash
156
- claude-memory improvements [options]
157
-
158
- Options:
159
- -t, --type <type> Filter by type (code_quality, performance, security, ux, architecture)
160
- -e, --effort <effort> Filter by effort (small, medium, large)
161
- -l, --limit <number> Limit number (default: 20)
162
- ```
163
-
164
- ### `claude-memory plan`
165
-
166
- Manage work plans.
167
-
168
- ```bash
169
- claude-memory plan [options]
170
-
171
- Options:
172
- -s, --status Show current plan status
173
- -c, --complete Complete current task
174
- -n, --next Move to next task
175
- -h, --history Show plan history
176
- ```
177
-
178
- ### `claude-memory capture <text>`
179
-
180
- Quick capture an idea or improvement. Auto-categorizes based on content.
181
-
182
- ```bash
183
- claude-memory capture "Consider adding caching to API calls"
184
- ```
185
-
186
- ### `claude-memory export`
187
-
188
- Export ideas and improvements as markdown.
189
-
190
- ```bash
191
- claude-memory export [options]
192
-
193
- Options:
194
- -o, --output <file> Output file (default: IDEAS_AND_IMPROVEMENTS.md)
195
- ```
196
-
197
- ---
198
-
199
- ## Architecture
200
-
201
- ```
202
- @metanautical/claude-memory
203
- ├── src/
204
- │ ├── hooks/
205
- │ │ ├── session-start.ts # Context loader on session start
206
- │ │ ├── pre-tool-use.ts # Guards + embedding injection
207
- │ │ ├── post-tool-use.ts # Record changes after Edit/Write
208
- │ │ └── memory-checkpoint.ts # Record learnings after changes
209
- │ ├── registry/
210
- │ │ ├── generator.ts # Parse docs → embeddings
211
- │ │ └── embeddings.ts # OpenAI/Gemini embedding service
212
- │ ├── auto-improve/
213
- │ │ ├── pattern-detector.ts # Detect repeated violations
214
- │ │ └── eslint-generator.ts # Generate ESLint rules
215
- │ ├── db/
216
- │ │ ├── client.ts # DEV_Items database client (mock)
217
- │ │ └── drizzle-client.ts # Real Drizzle ORM client
218
- │ ├── mcp/
219
- │ │ └── server.ts # MCP server for Claude tools
220
- │ ├── dashboard/
221
- │ │ ├── server.ts # Express dashboard server
222
- │ │ └── ui.ts # React UI generator
223
- │ ├── feedback/
224
- │ └── collector.ts # User feedback collection
225
- ├── analytics/
226
- │ └── tracker.ts # Usage analytics & insights
227
- │ ├── utils/
228
- │ │ ├── config.ts # Configuration management
229
- │ │ └── paths.ts # Path utilities
230
- │ ├── types/
231
- │ │ └── index.ts # Type definitions
232
- │ ├── cli/
233
- │ │ └── index.ts # CLI commands
234
- │ └── index.ts # Main exports
235
- ```
236
-
237
- ## Configuration
238
-
239
- ### `.claude/memory-config.json`
240
-
241
- ```json
242
- {
243
- "system": "SWARMSCALE",
244
- "projectName": "SwarmScale",
245
- "domains": ["video-studio", "avatars", "campaigns"],
246
- "guards": {
247
- "enabled": true,
248
- "rules": [
249
- {
250
- "id": "schema-protection",
251
- "type": "block",
252
- "filePattern": "src/server/schema/auth.ts",
253
- "message": "PANEL_* tables are READ-ONLY"
254
- }
255
- ]
256
- },
257
- "embedding": {
258
- "enabled": true,
259
- "threshold": 0.60,
260
- "maxSections": 3
261
- },
262
- "autoImprovement": {
263
- "enabled": true,
264
- "violationThreshold": 3,
265
- "generateEslintRules": true
266
- }
267
- }
268
- ```
269
-
270
- ### `.claude/settings.json`
271
-
272
- ```json
273
- {
274
- "hooks": {
275
- "PreToolUse": [
276
- {
277
- "matcher": "Task",
278
- "hooks": [{
279
- "type": "command",
280
- "command": "npx tsx node_modules/@metanautical/claude-memory/dist/hooks/pre-tool-use.js"
281
- }]
282
- }
283
- ],
284
- "SessionStart": [
285
- {
286
- "matcher": "",
287
- "hooks": [{
288
- "type": "command",
289
- "command": "npx tsx node_modules/@metanautical/claude-memory/dist/hooks/session-start.js"
290
- }]
291
- }
292
- ]
293
- },
294
- "plugins": {
295
- "metanautical-memory": {
296
- "version": "1.0.0",
297
- "enabled": true
298
- }
299
- }
300
- }
301
- ```
302
-
303
- ## Hooks
304
-
305
- ### SessionStart Hook
306
-
307
- Executes on session start:
308
- 1. Detects module from `git diff` (last 24h)
309
- 2. Queries DEV_Items for relevant memories
310
- 3. Returns formatted context
311
-
312
- ```typescript
313
- import { SessionStartHook } from '@metanautical/claude-memory/hooks'
314
-
315
- const hook = new SessionStartHook()
316
- const result = await hook.execute()
317
- // result.context contains session context
318
- ```
319
-
320
- ### PreToolUse Hook
321
-
322
- Executes before Edit/Write/Task tools:
323
- 1. **Edit/Write**: Validates against guard rules
324
- 2. **Task**: Injects relevant knowledge via embeddings
325
-
326
- ```typescript
327
- import { PreToolUseHook } from '@metanautical/claude-memory/hooks'
328
-
329
- const hook = new PreToolUseHook()
330
- const result = await hook.execute({
331
- tool_name: 'Edit',
332
- parameters: { file_path: 'src/file.ts', new_string: '...' }
333
- })
334
-
335
- if (result.mode === 'block') {
336
- // Guard violation - block operation
337
- }
338
- ```
339
-
340
- ## Auto-Improvement
341
-
342
- ### Pattern Detection
343
-
344
- Built-in patterns detected:
345
- - `any-type` - Using `any` type
346
- - `console-log` - Console.log in production
347
- - `eslint-disable` - ESLint disable comments
348
- - `hardcoded-string` - UI strings not using i18n
349
- - `direct-db-query` - Database queries in components
350
- - `inline-style` - Inline styles instead of Tailwind
351
-
352
- ### ESLint Rule Generation
353
-
354
- When a pattern is detected 3+ times:
355
-
356
- ```bash
357
- # Scan for patterns
358
- claude-memory scan
359
-
360
- # Output:
361
- # 🔴 any-type [high]
362
- # Count: 5, Files: 3
363
- # ⚠️ Patterns ready for auto-improvement
364
-
365
- # Generate ESLint rule
366
- claude-memory improve
367
-
368
- # Creates: eslint-plugin-charter/rules/no-any-type.js
369
- ```
370
-
371
- ## Programmatic Usage
372
-
373
- ```typescript
374
- import {
375
- loadConfig,
376
- PatternDetector,
377
- ESLintGenerator,
378
- RegistryGenerator
379
- } from '@metanautical/claude-memory'
380
-
381
- // Load config
382
- const config = await loadConfig(process.cwd())
383
-
384
- // Detect patterns
385
- const detector = new PatternDetector(config)
386
- const patterns = detector.scan(fileContent, filePath)
387
- const results = detector.getResults()
388
-
389
- // Generate ESLint rules
390
- const generator = new ESLintGenerator()
391
- await generator.generateAllRules(results.triggered)
392
-
393
- // Generate registry
394
- const registry = new RegistryGenerator()
395
- await registry.generate()
396
- ```
397
-
398
- ## System Isolation
399
-
400
- Data is isolated by `system` field in DEV_Items:
401
-
402
- | System | Project |
403
- |--------|---------|
404
- | `SWARMSCALE` | SwarmScale |
405
- | `PANEL` | TheCharterPanel |
406
- | `ECOSYSTEM` | Cross-project |
407
-
408
- Always filter by system:
409
-
410
- ```typescript
411
- // Correct
412
- db.select().from(devItems).where(eq(devItems.system, 'SWARMSCALE'))
413
-
414
- // Wrong - returns ALL projects' data
415
- db.select().from(devItems)
416
- ```
417
-
418
- ## Environment Variables
419
-
420
- ```bash
421
- # Required for embedding generation
422
- OPENAI_API_KEY=sk-... # Preferred
423
- GEMINI_API_KEY=... # Fallback
424
-
425
- # Optional
426
- MEMORY_DEBUG=true # Enable debug logging
427
- ```
428
-
429
- ## Development
430
-
431
- ```bash
432
- # Install dependencies
433
- npm install
434
-
435
- # Build
436
- npm run build
437
-
438
- # Watch mode
439
- npm run dev
440
-
441
- # Run tests
442
- npm test
443
-
444
- # Link for local development
445
- npm link
446
- ```
447
-
448
- ## MCP Server
449
-
450
- The MCP (Model Context Protocol) server exposes memory tools that Claude can use directly:
451
-
452
- ```bash
453
- # Start MCP server
454
- claude-memory mcp
455
- ```
456
-
457
- **Available Tools:**
458
- - `memory_search` - Search memories by query
459
- - `memory_write` - Write new memory/learning
460
- - `memory_list` - List recent memories
461
- - `pattern_check` - Check for detected patterns
462
- - `pattern_report` - Report a new pattern occurrence
463
- - `session_context` - Get current session context
464
- - `feedback_submit` - Submit feedback on a memory
465
-
466
- ## Dashboard
467
-
468
- Start the standalone web dashboard:
469
-
470
- ```bash
471
- claude-memory dashboard
472
- # Opens http://localhost:3847
473
- ```
474
-
475
- **Features:**
476
- - View all memories with search and filtering
477
- - Browse detected patterns
478
- - See session history
479
- - Submit feedback on memories
480
- - Create new memories
481
- - View analytics and system health
482
-
483
- ## Feedback Loop
484
-
485
- The feedback system adjusts memory relevance based on user feedback:
486
-
487
- ```typescript
488
- import { createFeedbackCollector } from '@metanautical/claude-memory'
489
-
490
- const collector = createFeedbackCollector('SWARMSCALE')
491
-
492
- // Submit feedback
493
- await collector.submitFeedback(memoryId, true, 'Very helpful!')
494
-
495
- // Get feedback stats
496
- const stats = await collector.getStats()
497
- // { helpfulRate: 0.85, topHelpfulMemories: [...] }
498
-
499
- // Get suggestions for deprecation
500
- const deprecations = await collector.getSuggestedDeprecations()
501
- ```
502
-
503
- ## Analytics
504
-
505
- Track usage and get insights:
506
-
507
- ```typescript
508
- import { createAnalyticsTracker } from '@metanautical/claude-memory'
509
-
510
- const tracker = createAnalyticsTracker('SWARMSCALE')
511
-
512
- // Track an event
513
- await tracker.track('memory_access', { memoryId: '...' })
514
-
515
- // Get usage stats
516
- const usage = await tracker.getUsageStats('week')
517
- // { sessions: 12, memoriesCreated: 5, searchesPerformed: 23, ... }
518
-
519
- // Get system health
520
- const health = await tracker.getSystemHealth()
521
- // { status: 'healthy', issues: [], recommendations: [...] }
522
-
523
- // Generate full report
524
- const report = await tracker.generateReport()
525
- ```
526
-
527
- ## Database Configuration
528
-
529
- Set environment variables for database connection:
530
-
531
- ```bash
532
- DATABASE_HOST=localhost
533
- DATABASE_PORT=3306
534
- DATABASE_USER=root
535
- DATABASE_PASSWORD=your-password
536
- DATABASE_NAME=metanautical
537
- ```
538
-
539
- ## License
540
-
541
- MIT - MetaNautical Group
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