cmp-standards 3.5.0 → 3.7.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.
- package/README.md +399 -633
- package/dist/analytics/CrossProjectAnalytics.js +65 -65
- package/dist/cli/index.js +255 -12
- package/dist/cli/index.js.map +1 -1
- package/dist/dashboard/tokens.js +173 -173
- package/dist/db/client.d.ts.map +1 -1
- package/dist/db/client.js +2 -0
- package/dist/db/client.js.map +1 -1
- package/dist/db/cloud.d.ts +1 -0
- package/dist/db/cloud.d.ts.map +1 -1
- package/dist/db/drizzle-client.d.ts +2 -2
- package/dist/db/drizzle-client.d.ts.map +1 -1
- package/dist/db/drizzle-client.js +0 -1
- package/dist/db/drizzle-client.js.map +1 -1
- package/dist/db/migrations.js +256 -256
- package/dist/db/turso-client.js +2 -2
- package/dist/db/upstash-client.d.ts +9 -0
- package/dist/db/upstash-client.d.ts.map +1 -1
- package/dist/db/upstash-client.js +11 -0
- package/dist/db/upstash-client.js.map +1 -1
- package/dist/eslint/rules/no-async-useeffect.js +6 -6
- package/dist/experts/ExpertVotePersistence.js +9 -9
- package/dist/feedback/collector.d.ts.map +1 -1
- package/dist/feedback/collector.js +6 -2
- package/dist/feedback/collector.js.map +1 -1
- package/dist/hooks/cloud-post-tool-use.d.ts.map +1 -1
- package/dist/hooks/cloud-post-tool-use.js +72 -10
- package/dist/hooks/cloud-post-tool-use.js.map +1 -1
- package/dist/hooks/cloud-pre-tool-use.d.ts +12 -9
- package/dist/hooks/cloud-pre-tool-use.d.ts.map +1 -1
- package/dist/hooks/cloud-pre-tool-use.js +227 -99
- package/dist/hooks/cloud-pre-tool-use.js.map +1 -1
- package/dist/hooks/cloud-session-start.d.ts.map +1 -1
- package/dist/hooks/cloud-session-start.js +19 -16
- package/dist/hooks/cloud-session-start.js.map +1 -1
- package/dist/hooks/resilient-hook-runner.d.ts +78 -0
- package/dist/hooks/resilient-hook-runner.d.ts.map +1 -0
- package/dist/hooks/resilient-hook-runner.js +201 -0
- package/dist/hooks/resilient-hook-runner.js.map +1 -0
- package/dist/hooks/session-end.js +14 -14
- package/dist/patterns/registry.js +90 -90
- package/dist/registry/generator.d.ts.map +1 -1
- package/dist/registry/generator.js +31 -21
- package/dist/registry/generator.js.map +1 -1
- package/dist/schema/codewiki-types.d.ts +10 -10
- package/dist/schema/docs-types.d.ts +8 -8
- package/dist/schema/ecosystem-types.d.ts +12 -12
- package/dist/schema/expert-types.d.ts +2 -2
- package/dist/schema/opportunity-types.d.ts +6 -6
- package/dist/schema/tracking.d.ts +2 -2
- package/dist/services/BootstrapService.d.ts +123 -0
- package/dist/services/BootstrapService.d.ts.map +1 -0
- package/dist/services/BootstrapService.js +309 -0
- package/dist/services/BootstrapService.js.map +1 -0
- package/dist/services/CodeWikiIndexer.js +3 -3
- package/dist/services/ContextGenerator.js +7 -7
- package/dist/services/FeedbackCollector.js +11 -11
- package/dist/services/GitIntegration.d.ts.map +1 -1
- package/dist/services/GitIntegration.js +27 -23
- package/dist/services/GitIntegration.js.map +1 -1
- package/dist/services/HookVerifier.js +70 -70
- package/dist/services/KnowledgeGapDetector.d.ts +122 -0
- package/dist/services/KnowledgeGapDetector.d.ts.map +1 -0
- package/dist/services/KnowledgeGapDetector.js +530 -0
- package/dist/services/KnowledgeGapDetector.js.map +1 -0
- package/dist/services/ProjectScaffold.d.ts.map +1 -1
- package/dist/services/ProjectScaffold.js +79 -78
- package/dist/services/ProjectScaffold.js.map +1 -1
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +6 -0
- package/dist/services/index.js.map +1 -1
- package/dist/services/knowledge-graph.d.ts +121 -0
- package/dist/services/knowledge-graph.d.ts.map +1 -0
- package/dist/services/knowledge-graph.js +446 -0
- package/dist/services/knowledge-graph.js.map +1 -0
- package/dist/services/memory-router.d.ts +25 -0
- package/dist/services/memory-router.d.ts.map +1 -1
- package/dist/services/memory-router.js +236 -98
- package/dist/services/memory-router.js.map +1 -1
- package/dist/services/pattern-learning.d.ts +79 -0
- package/dist/services/pattern-learning.d.ts.map +1 -0
- package/dist/services/pattern-learning.js +312 -0
- package/dist/services/pattern-learning.js.map +1 -0
- package/dist/services/pattern-tracker.js +95 -95
- package/dist/services/semantic-search.d.ts.map +1 -1
- package/dist/services/semantic-search.js +12 -8
- package/dist/services/semantic-search.js.map +1 -1
- package/package.json +124 -116
- package/standards/README.md +94 -50
- package/standards/experts/expert-routing.md +215 -215
- package/standards/general/code-quality.md +86 -86
- package/standards/general/ecosystem.md +243 -0
- package/standards/general/learning-loop.md +192 -0
- package/standards/general/memory-usage.md +205 -205
- package/standards/general/project-onboarding.md +339 -0
- package/standards/general/sync-workflow.md +235 -235
- package/standards/general/workflow.md +82 -82
- package/standards/hooks/mandatory-tracking.md +446 -446
- package/standards/infrastructure/cloud-database.md +287 -287
- package/standards/mcp/server-design.md +243 -243
- package/standards/mcp/tool-patterns.md +354 -354
- package/standards/skills/skill-structure.md +286 -286
- package/standards/skills/workflow-design.md +323 -323
- package/standards/tools/tool-design.md +297 -297
- package/templates/agents/architecture-expert.md +61 -61
- package/templates/agents/database-expert.md +62 -62
- package/templates/agents/documentation-expert.md +57 -57
- package/templates/agents/ecosystem-expert.md +104 -0
- package/templates/agents/memory-expert.md +88 -88
- package/templates/agents/performance-expert.md +61 -61
- package/templates/agents/security-expert.md +59 -59
- package/templates/agents/ux-expert.md +63 -63
- package/templates/agents/worker.md +75 -75
- package/templates/ai-skills/SKILL_TEMPLATE.md +55 -55
- package/templates/claude-settings.json +72 -72
- package/templates/commands/experts.md +138 -138
- package/templates/hooks/README.md +158 -158
- package/templates/hooks/project.config.json.template +77 -77
- package/templates/hooks/settings.local.json.template +57 -57
- package/templates/hooks.config.json +21 -0
- package/templates/memory-config.json +56 -56
- package/templates/memory-config.schema.json +212 -212
- package/templates/settings.json +58 -58
- package/templates/skills/continue.md +205 -205
- package/templates/workflows/business-improvement.md +264 -264
- package/templates/workflows/expert-review.md +153 -153
- package/templates/workflows/internal-app.md +245 -245
- package/templates/workflows/sync-docs.md +187 -187
package/README.md
CHANGED
|
@@ -1,633 +1,399 @@
|
|
|
1
|
-
# CMP - Collective Memory Protocol
|
|
2
|
-
|
|
3
|
-
> **
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/cmp-standards)
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
##
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
cmp-standards
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
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
|
|
1
|
+
# CMP - Collective Memory Protocol
|
|
2
|
+
|
|
3
|
+
> **For AI Agents, By AI Agents** - The Development Intelligence Layer
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/cmp-standards)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## What is CMP?
|
|
11
|
+
|
|
12
|
+
CMP is an **agent-first protocol** that gives AI coding assistants (Claude, Gemini, GPT, etc.) persistent memory across sessions, cross-project learning, and multi-agent collaboration capabilities.
|
|
13
|
+
|
|
14
|
+
**The Problem**: AI assistants forget everything when a session ends. They can't learn from past mistakes. They can't share knowledge between projects.
|
|
15
|
+
|
|
16
|
+
**The Solution**: CMP creates a shared intelligence layer where:
|
|
17
|
+
- Errors become learning opportunities (Learning Loop)
|
|
18
|
+
- One project's lessons benefit all your projects (Cross-Project Sync)
|
|
19
|
+
- Work survives session restarts (Persistent Plans)
|
|
20
|
+
- Multiple agents can collaborate on the same project (Multi-Agent Handoffs)
|
|
21
|
+
|
|
22
|
+
**Created by Carlos Martin Pavón** as a personal methodology for working with AI agents across projects. Open source and adaptable to anyone's workflow.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## For AI Agents: Self-Installation Guide
|
|
27
|
+
|
|
28
|
+
> **AI Agent**: Follow these instructions to install CMP in any project.
|
|
29
|
+
|
|
30
|
+
### Step 1: Install Package
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install cmp-standards
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Step 2: Initialize Project
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npx cmp-standards init --system PROJECT_CODE --name "Project Name"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Replace `PROJECT_CODE` with a unique identifier for this project (e.g., `MYAPP`, `WEBAPP`, `API`).
|
|
43
|
+
|
|
44
|
+
### Step 3: Create CLAUDE.md
|
|
45
|
+
|
|
46
|
+
Create or update the project's `CLAUDE.md` with this template:
|
|
47
|
+
|
|
48
|
+
```markdown
|
|
49
|
+
# CLAUDE.md - [Project Name]
|
|
50
|
+
|
|
51
|
+
> **System**: [PROJECT_CODE]
|
|
52
|
+
> **CMP Version**: 3.7.0
|
|
53
|
+
|
|
54
|
+
## CMP Integration
|
|
55
|
+
|
|
56
|
+
This project uses **Collective Memory Protocol** for persistent memory.
|
|
57
|
+
|
|
58
|
+
### Session Start
|
|
59
|
+
On session start, check for:
|
|
60
|
+
- Active work plans: Query DEV_Items where system='PROJECT_CODE' AND status='in_progress'
|
|
61
|
+
- Learning Loop status: Check pending errors for knowledge extraction
|
|
62
|
+
- Cross-project knowledge: Query DEV_Items where system='SHARED'
|
|
63
|
+
|
|
64
|
+
### Memory Commands
|
|
65
|
+
- `npm run ai:health` - Check system health
|
|
66
|
+
- `npm run ai:distill` - Extract knowledge from pending items
|
|
67
|
+
|
|
68
|
+
### Core Rules
|
|
69
|
+
- Filter database queries by `system='PROJECT_CODE'`
|
|
70
|
+
- Use shared knowledge with `system='SHARED'`
|
|
71
|
+
- Record significant decisions in DEV_Items
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Step 4: Set Up Database
|
|
75
|
+
|
|
76
|
+
CMP uses a `DEV_Items` table to store all knowledge, tasks, and learnings:
|
|
77
|
+
|
|
78
|
+
```sql
|
|
79
|
+
CREATE TABLE DEV_Items (
|
|
80
|
+
id VARCHAR(255) PRIMARY KEY,
|
|
81
|
+
system VARCHAR(50) NOT NULL, -- Project identifier
|
|
82
|
+
type ENUM('task', 'memory', 'knowledge', 'pattern', 'error') NOT NULL,
|
|
83
|
+
status ENUM('pending', 'in_progress', 'done', 'archived') DEFAULT 'pending',
|
|
84
|
+
priority ENUM('critical', 'high', 'medium', 'low') DEFAULT 'medium',
|
|
85
|
+
content JSON NOT NULL, -- Flexible content storage
|
|
86
|
+
tags JSON, -- Searchable tags
|
|
87
|
+
created_at TIMESTAMP DEFAULT NOW(),
|
|
88
|
+
updated_at TIMESTAMP DEFAULT NOW()
|
|
89
|
+
);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Step 5: Configure Hooks (Optional - Claude Code)
|
|
93
|
+
|
|
94
|
+
For Claude Code, add to `.claude/settings.json`:
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"hooks": {
|
|
99
|
+
"SessionStart": [{
|
|
100
|
+
"matcher": "",
|
|
101
|
+
"hooks": [{
|
|
102
|
+
"type": "command",
|
|
103
|
+
"command": "npx tsx node_modules/cmp-standards/dist/hooks/cloud-session-start.js"
|
|
104
|
+
}]
|
|
105
|
+
}]
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Philosophy
|
|
113
|
+
|
|
114
|
+
| Principle | Meaning |
|
|
115
|
+
|-----------|---------|
|
|
116
|
+
| **Evidence > Assumptions** | Never assume. Always verify. Read before writing. |
|
|
117
|
+
| **Cloud > Local** | Memory lives in the database. Sessions are ephemeral, knowledge is permanent. |
|
|
118
|
+
| **Collective > Individual** | One project's learnings benefit all your projects. |
|
|
119
|
+
| **Continuity > Restarts** | Work survives IDE restarts, machine changes, and agent switches. |
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## How It Works
|
|
124
|
+
|
|
125
|
+
### The DEV_Items Table
|
|
126
|
+
|
|
127
|
+
All knowledge is stored in a single, flexible table:
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
131
|
+
│ DEV_Items │
|
|
132
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
133
|
+
│ │
|
|
134
|
+
│ Project A (system='WEBAPP') │
|
|
135
|
+
│ ├── task: "Implement auth" │
|
|
136
|
+
│ ├── knowledge: "JWT works better than sessions" │
|
|
137
|
+
│ └── pattern: "Always validate inputs with Zod" │
|
|
138
|
+
│ │
|
|
139
|
+
│ Project B (system='API') │
|
|
140
|
+
│ ├── task: "Add rate limiting" │
|
|
141
|
+
│ └── error: "Redis connection timeout" │
|
|
142
|
+
│ │
|
|
143
|
+
│ Shared (system='SHARED') │
|
|
144
|
+
│ ├── knowledge: "Use semantic tokens for colors" │
|
|
145
|
+
│ └── pattern: "Never use any type" │
|
|
146
|
+
│ │
|
|
147
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Learning Loop
|
|
151
|
+
|
|
152
|
+
CMP automatically converts errors into knowledge:
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
CAPTURE → ANALYZE → DISTILL → PREVENT
|
|
156
|
+
↓ ↓ ↓ ↓
|
|
157
|
+
Errors Patterns Knowledge Rules
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
1. **Errors** are logged with context
|
|
161
|
+
2. **Patterns** emerge when errors repeat (≥3 times)
|
|
162
|
+
3. **Knowledge** is extracted (Rules, Patterns, Gotchas)
|
|
163
|
+
4. **Rules** are generated (ESLint, guidelines) to prevent recurrence
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Adapt to Your Workflow
|
|
168
|
+
|
|
169
|
+
CMP is designed to be **flexible**. You can:
|
|
170
|
+
|
|
171
|
+
### Use Your Own Database
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
// MySQL, PostgreSQL, SQLite - any database works
|
|
175
|
+
import { initCMP } from 'cmp-standards'
|
|
176
|
+
|
|
177
|
+
await initCMP({
|
|
178
|
+
database: {
|
|
179
|
+
type: 'mysql',
|
|
180
|
+
connectionString: process.env.DATABASE_URL
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Define Your Own Systems
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
// Your projects, your naming
|
|
189
|
+
const systems = {
|
|
190
|
+
FRONTEND: 'React web app',
|
|
191
|
+
BACKEND: 'Node.js API',
|
|
192
|
+
MOBILE: 'React Native app',
|
|
193
|
+
SHARED: 'Cross-project knowledge'
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Customize Knowledge Types
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
// Extend the content schema for your needs
|
|
201
|
+
const customTypes = ['task', 'bug', 'feature', 'learning', 'decision']
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Agent Compatibility
|
|
207
|
+
|
|
208
|
+
CMP works with any AI coding assistant:
|
|
209
|
+
|
|
210
|
+
| Agent | Integration |
|
|
211
|
+
|-------|-------------|
|
|
212
|
+
| **Claude Code** | Full integration via hooks, commands, MCP |
|
|
213
|
+
| **Cursor** | Read CLAUDE.md, use CLI commands |
|
|
214
|
+
| **GitHub Copilot** | Read CLAUDE.md, use CLI commands |
|
|
215
|
+
| **Gemini** | Read CLAUDE.md, use CLI commands |
|
|
216
|
+
| **Custom Agents** | Use programmatic API |
|
|
217
|
+
|
|
218
|
+
### Universal Agent Instructions
|
|
219
|
+
|
|
220
|
+
For any AI agent to use CMP:
|
|
221
|
+
|
|
222
|
+
1. **Read** `CLAUDE.md` for project context
|
|
223
|
+
2. **Query** `DEV_Items` for relevant knowledge
|
|
224
|
+
3. **Filter** by `system='PROJECT_CODE'` for project-specific data
|
|
225
|
+
4. **Record** learnings back to `DEV_Items`
|
|
226
|
+
5. **Check** `system='SHARED'` for cross-project patterns
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## CLI Commands
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
# Initialize project
|
|
234
|
+
cmp-standards init --system CODE --name "Name"
|
|
235
|
+
|
|
236
|
+
# Check system status
|
|
237
|
+
cmp-standards status
|
|
238
|
+
|
|
239
|
+
# Generate embeddings for semantic search
|
|
240
|
+
cmp-standards generate
|
|
241
|
+
|
|
242
|
+
# Scan codebase for patterns
|
|
243
|
+
cmp-standards scan
|
|
244
|
+
|
|
245
|
+
# Run auto-improvement
|
|
246
|
+
cmp-standards improve
|
|
247
|
+
|
|
248
|
+
# Start visual dashboard
|
|
249
|
+
cmp-standards dashboard
|
|
250
|
+
|
|
251
|
+
# Start MCP server (for Claude tools)
|
|
252
|
+
cmp-standards mcp
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Multi-Agent Collaboration
|
|
258
|
+
|
|
259
|
+
### Plans with Checkpoints
|
|
260
|
+
|
|
261
|
+
When an agent can't finish in one session:
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
import { PlanManager } from 'cmp-standards'
|
|
265
|
+
|
|
266
|
+
// Agent 1: Start work
|
|
267
|
+
await PlanManager.createPlan({
|
|
268
|
+
objective: 'Implement user authentication',
|
|
269
|
+
tasks: ['Design schema', 'Create API', 'Build UI']
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
// Agent 1: Save progress before session ends
|
|
273
|
+
await PlanManager.saveCheckpoint({
|
|
274
|
+
progress: 'Completed schema design',
|
|
275
|
+
decisions: ['Using JWT tokens'],
|
|
276
|
+
nextSteps: ['Implement login endpoint']
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
// Agent 2 (new session): Resume work
|
|
280
|
+
const plans = await PlanManager.findActivePlans()
|
|
281
|
+
await PlanManager.resumePlan(plans[0].id)
|
|
282
|
+
// Agent 2 knows exactly where Agent 1 left off
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Expert Code Review
|
|
286
|
+
|
|
287
|
+
Built-in multi-expert review system:
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
/experts src/path/to/file.ts
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Experts include: Security, Performance, Architecture, UX, Database, Memory
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## Programmatic API
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
import { cloud, PatternDetector, PlanManager } from 'cmp-standards'
|
|
301
|
+
|
|
302
|
+
// Initialize
|
|
303
|
+
await cloud.init()
|
|
304
|
+
|
|
305
|
+
// Start work session
|
|
306
|
+
const session = await cloud.startWorkSession('MYPROJECT')
|
|
307
|
+
|
|
308
|
+
// Create task
|
|
309
|
+
const taskId = await cloud.startTask('MYPROJECT', session.sessionId, {
|
|
310
|
+
title: 'Implement feature X',
|
|
311
|
+
domain: 'features'
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
// Complete with learnings
|
|
315
|
+
await cloud.completeTask(taskId, {
|
|
316
|
+
result: 'success',
|
|
317
|
+
improvements: [{ title: 'Add caching', priority: 'medium' }],
|
|
318
|
+
lessons: ['Pattern X works well for this use case']
|
|
319
|
+
})
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
## Quick Start Checklist
|
|
325
|
+
|
|
326
|
+
For AI Agents setting up CMP in a new project:
|
|
327
|
+
|
|
328
|
+
```
|
|
329
|
+
□ 1. npm install cmp-standards
|
|
330
|
+
□ 2. npx cmp-standards init --system CODE --name "Name"
|
|
331
|
+
□ 3. Create/update CLAUDE.md with CMP section
|
|
332
|
+
□ 4. Set up DEV_Items table in your database
|
|
333
|
+
□ 5. Run: cmp-standards status
|
|
334
|
+
□ 6. Start recording knowledge!
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## Standards Documentation
|
|
340
|
+
|
|
341
|
+
CMP includes documentation standards for AI agents:
|
|
342
|
+
|
|
343
|
+
```
|
|
344
|
+
standards/
|
|
345
|
+
├── general/
|
|
346
|
+
│ ├── workflow.md # Working with AI agents
|
|
347
|
+
│ ├── code-quality.md # Code standards
|
|
348
|
+
│ ├── memory-usage.md # Memory system usage
|
|
349
|
+
│ ├── learning-loop.md # Error→Knowledge cycle
|
|
350
|
+
│ └── project-onboarding.md # New project setup
|
|
351
|
+
├── mcp/
|
|
352
|
+
│ └── server-design.md # MCP server patterns
|
|
353
|
+
└── skills/
|
|
354
|
+
└── skill-structure.md # Skill file format
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## Why CMP?
|
|
360
|
+
|
|
361
|
+
**Before CMP:**
|
|
362
|
+
- Agent forgets everything each session
|
|
363
|
+
- Same mistakes repeated across projects
|
|
364
|
+
- No way to share learnings
|
|
365
|
+
- Work lost on session restart
|
|
366
|
+
|
|
367
|
+
**After CMP:**
|
|
368
|
+
- Persistent memory in database
|
|
369
|
+
- Errors become documented knowledge
|
|
370
|
+
- Cross-project learning
|
|
371
|
+
- Seamless multi-agent handoffs
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
## Contributing
|
|
376
|
+
|
|
377
|
+
This is an open protocol. Contributions welcome:
|
|
378
|
+
|
|
379
|
+
1. Fork the repository
|
|
380
|
+
2. Create feature branch
|
|
381
|
+
3. Submit pull request
|
|
382
|
+
|
|
383
|
+
---
|
|
384
|
+
|
|
385
|
+
## Links
|
|
386
|
+
|
|
387
|
+
- **npm**: [npmjs.com/package/cmp-standards](https://www.npmjs.com/package/cmp-standards)
|
|
388
|
+
- **GitHub**: [github.com/carlosmartinpavon/carlosmartinpavon](https://github.com/carlosmartinpavon/carlosmartinpavon)
|
|
389
|
+
- **Author**: [Carlos Martin Pavón](https://carlosmartinpavon.com)
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
## License
|
|
394
|
+
|
|
395
|
+
MIT - Carlos Martin Pavón
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
*Built by agents, for agents. Adapt it to your workflow.*
|