cmp-standards 2.7.0 → 2.8.0-alpha

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 (114) hide show
  1. package/README.md +633 -633
  2. package/dist/cache/EmbeddingCache.d.ts +109 -0
  3. package/dist/cache/EmbeddingCache.d.ts.map +1 -0
  4. package/dist/cache/EmbeddingCache.js +239 -0
  5. package/dist/cache/EmbeddingCache.js.map +1 -0
  6. package/dist/cache/index.d.ts +6 -0
  7. package/dist/cache/index.d.ts.map +1 -0
  8. package/dist/cache/index.js +6 -0
  9. package/dist/cache/index.js.map +1 -0
  10. package/dist/cli/index.js +0 -0
  11. package/dist/db/turso-client.js +11 -11
  12. package/dist/eslint/rules/no-async-useeffect.js +6 -6
  13. package/dist/events/EventBus.d.ts +87 -0
  14. package/dist/events/EventBus.d.ts.map +1 -0
  15. package/dist/events/EventBus.js +200 -0
  16. package/dist/events/EventBus.js.map +1 -0
  17. package/dist/events/index.d.ts +7 -0
  18. package/dist/events/index.d.ts.map +1 -0
  19. package/dist/events/index.js +9 -0
  20. package/dist/events/index.js.map +1 -0
  21. package/dist/events/types.d.ts +989 -0
  22. package/dist/events/types.d.ts.map +1 -0
  23. package/dist/events/types.js +136 -0
  24. package/dist/events/types.js.map +1 -0
  25. package/dist/experts/ConsensusEngine.d.ts +57 -0
  26. package/dist/experts/ConsensusEngine.d.ts.map +1 -0
  27. package/dist/experts/ConsensusEngine.js +146 -0
  28. package/dist/experts/ConsensusEngine.js.map +1 -0
  29. package/dist/experts/ExpertPanelService.d.ts +84 -0
  30. package/dist/experts/ExpertPanelService.d.ts.map +1 -0
  31. package/dist/experts/ExpertPanelService.js +204 -0
  32. package/dist/experts/ExpertPanelService.js.map +1 -0
  33. package/dist/experts/ExpertRouter.d.ts +68 -0
  34. package/dist/experts/ExpertRouter.d.ts.map +1 -0
  35. package/dist/experts/ExpertRouter.js +374 -0
  36. package/dist/experts/ExpertRouter.js.map +1 -0
  37. package/dist/experts/VoteCollector.d.ts +58 -0
  38. package/dist/experts/VoteCollector.d.ts.map +1 -0
  39. package/dist/experts/VoteCollector.js +146 -0
  40. package/dist/experts/VoteCollector.js.map +1 -0
  41. package/dist/experts/index.d.ts +9 -0
  42. package/dist/experts/index.d.ts.map +1 -0
  43. package/dist/experts/index.js +13 -0
  44. package/dist/experts/index.js.map +1 -0
  45. package/dist/hooks/cloud-pre-tool-use.js +20 -20
  46. package/dist/hooks/expert-review.d.ts +74 -0
  47. package/dist/hooks/expert-review.d.ts.map +1 -0
  48. package/dist/hooks/expert-review.js +220 -0
  49. package/dist/hooks/expert-review.js.map +1 -0
  50. package/dist/hooks/index.d.ts +1 -0
  51. package/dist/hooks/index.d.ts.map +1 -1
  52. package/dist/hooks/index.js +2 -0
  53. package/dist/hooks/index.js.map +1 -1
  54. package/dist/index.d.ts +13 -0
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +22 -0
  57. package/dist/index.js.map +1 -1
  58. package/dist/performance/Debouncer.d.ts +91 -0
  59. package/dist/performance/Debouncer.d.ts.map +1 -0
  60. package/dist/performance/Debouncer.js +198 -0
  61. package/dist/performance/Debouncer.js.map +1 -0
  62. package/dist/performance/MemoryDecay.d.ts +82 -0
  63. package/dist/performance/MemoryDecay.d.ts.map +1 -0
  64. package/dist/performance/MemoryDecay.js +153 -0
  65. package/dist/performance/MemoryDecay.js.map +1 -0
  66. package/dist/performance/index.d.ts +7 -0
  67. package/dist/performance/index.d.ts.map +1 -0
  68. package/dist/performance/index.js +9 -0
  69. package/dist/performance/index.js.map +1 -0
  70. package/dist/schema/expert-types.d.ts +395 -0
  71. package/dist/schema/expert-types.d.ts.map +1 -0
  72. package/dist/schema/expert-types.js +250 -0
  73. package/dist/schema/expert-types.js.map +1 -0
  74. package/dist/services/ContextGenerator.js +7 -7
  75. package/dist/services/ProjectScaffold.js +76 -76
  76. package/dist/services/memory-router.js +35 -35
  77. package/dist/services/pattern-tracker.js +90 -90
  78. package/dist/services/semantic-search.js +2 -2
  79. package/package.json +105 -104
  80. package/standards/README.md +50 -50
  81. package/standards/experts/expert-routing.md +215 -215
  82. package/standards/general/code-quality.md +86 -86
  83. package/standards/general/memory-usage.md +205 -205
  84. package/standards/general/sync-workflow.md +235 -235
  85. package/standards/general/workflow.md +82 -82
  86. package/standards/hooks/mandatory-tracking.md +446 -446
  87. package/standards/infrastructure/cloud-database.md +287 -287
  88. package/standards/mcp/server-design.md +243 -243
  89. package/standards/mcp/tool-patterns.md +354 -354
  90. package/standards/skills/skill-structure.md +286 -286
  91. package/standards/skills/workflow-design.md +323 -323
  92. package/standards/tools/tool-design.md +297 -297
  93. package/templates/agents/architecture-expert.md +61 -61
  94. package/templates/agents/database-expert.md +62 -62
  95. package/templates/agents/documentation-expert.md +57 -57
  96. package/templates/agents/memory-expert.md +88 -88
  97. package/templates/agents/performance-expert.md +61 -61
  98. package/templates/agents/security-expert.md +59 -59
  99. package/templates/agents/ux-expert.md +63 -63
  100. package/templates/agents/worker.md +75 -75
  101. package/templates/ai-skills/SKILL_TEMPLATE.md +55 -55
  102. package/templates/claude-settings.json +72 -72
  103. package/templates/commands/experts.md +138 -138
  104. package/templates/hooks/README.md +158 -158
  105. package/templates/hooks/project.config.json.template +77 -77
  106. package/templates/hooks/settings.local.json.template +57 -57
  107. package/templates/memory-config.json +56 -56
  108. package/templates/memory-config.schema.json +212 -212
  109. package/templates/settings.json +58 -58
  110. package/templates/skills/continue.md +205 -205
  111. package/templates/workflows/business-improvement.md +264 -264
  112. package/templates/workflows/expert-review.md +153 -153
  113. package/templates/workflows/internal-app.md +245 -245
  114. package/templates/workflows/sync-docs.md +187 -187
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,QAAQ;AACR,cAAc,kBAAkB,CAAA;AAEhC,QAAQ;AACR,OAAO,EAAE,gBAAgB,EAAE,MAAM,0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uBAAuB,GACxB,MAAM,oBAAoB,CAAA;AAyB3B,wCAAwC;AACxC,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,2BAA2B,EAC3B,iCAAiC,EACjC,wBAAwB,EACxB,uBAAuB,EACvB,4BAA4B,EAC5B,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,0BAA0B,CAAA;AAajC,gFAAgF;AAChF,0CAA0C;AAC1C,gFAAgF;AAEhF,aAAa;AACb,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,GAChB,MAAM,wBAAwB,CAAA;AAO/B,eAAe;AACf,OAAO,EACL,WAAW,EACX,cAAc,EACd,gBAAgB,GACjB,MAAM,wBAAwB,CAAA;AAQ/B,qBAAqB;AACrB,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,GACf,MAAM,kBAAkB,CAAA"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @file Debouncer - Hook debouncing for performance optimization
3
+ * @description Prevents redundant operations by tracking recent calls
4
+ *
5
+ * Features:
6
+ * - Time-based debouncing (skip if same operation within window)
7
+ * - Hash-based key generation
8
+ * - Auto-cleanup of expired entries
9
+ * - Statistics tracking
10
+ */
11
+ export interface DebouncerConfig {
12
+ /** Debounce window in milliseconds */
13
+ windowMs: number;
14
+ /** Max entries to track (memory limit) */
15
+ maxEntries: number;
16
+ /** Enable debug logging */
17
+ debug: boolean;
18
+ }
19
+ export interface DebouncerStats {
20
+ totalCalls: number;
21
+ skipped: number;
22
+ executed: number;
23
+ skipRate: number;
24
+ activeEntries: number;
25
+ }
26
+ export declare class Debouncer {
27
+ private config;
28
+ private entries;
29
+ private stats;
30
+ constructor(config?: Partial<DebouncerConfig>);
31
+ /**
32
+ * Check if operation should be skipped
33
+ * Returns true if same operation was called within debounce window
34
+ */
35
+ shouldSkip(key: string): boolean;
36
+ /**
37
+ * Generate hash key from tool name and params
38
+ */
39
+ createKey(toolName: string, params: Record<string, unknown>): string;
40
+ /**
41
+ * Check if tool call should skip embedding lookup
42
+ */
43
+ shouldSkipEmbedding(toolName: string, params: Record<string, unknown>): boolean;
44
+ /**
45
+ * Check if expert review should be skipped
46
+ */
47
+ shouldSkipReview(files: string[]): boolean;
48
+ /**
49
+ * Mark operation as complete (update timestamp)
50
+ */
51
+ markComplete(key: string): void;
52
+ /**
53
+ * Remove expired entries
54
+ */
55
+ cleanup(): number;
56
+ /**
57
+ * Get statistics
58
+ */
59
+ getStats(): DebouncerStats;
60
+ /**
61
+ * Reset all state
62
+ */
63
+ reset(): void;
64
+ /**
65
+ * Get config
66
+ */
67
+ getConfig(): DebouncerConfig;
68
+ /**
69
+ * Update config
70
+ */
71
+ setConfig(config: Partial<DebouncerConfig>): void;
72
+ }
73
+ /**
74
+ * Debouncer for embedding lookups
75
+ */
76
+ export declare class EmbeddingDebouncer extends Debouncer {
77
+ constructor(config?: Partial<DebouncerConfig>);
78
+ shouldSkipLookup(text: string): boolean;
79
+ }
80
+ /**
81
+ * Debouncer for hook operations
82
+ */
83
+ export declare class HookDebouncer extends Debouncer {
84
+ constructor(config?: Partial<DebouncerConfig>);
85
+ shouldSkipHook(hookName: string, context: Record<string, unknown>): boolean;
86
+ }
87
+ export declare function getDebouncer(config?: Partial<DebouncerConfig>): Debouncer;
88
+ export declare function getEmbeddingDebouncer(config?: Partial<DebouncerConfig>): EmbeddingDebouncer;
89
+ export declare function getHookDebouncer(config?: Partial<DebouncerConfig>): HookDebouncer;
90
+ export declare function resetDebouncers(): void;
91
+ //# sourceMappingURL=Debouncer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Debouncer.d.ts","sourceRoot":"","sources":["../../src/performance/Debouncer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH,MAAM,WAAW,eAAe;IAC9B,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAA;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M,GAAG,OAAO;CAIxC;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,SAAS;gBAC9B,MAAM,GAAE,OAAO,CAAC,eAAe,CAAM;IAQjD,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO;CAI5E;AAUD,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,SAAS,CAKzE;AAED,wBAAgB,qBAAqB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,kBAAkB,CAK3F;AAED,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,aAAa,CAKjF;AAED,wBAAgB,eAAe,IAAI,IAAI,CAItC"}
@@ -0,0 +1,198 @@
1
+ /**
2
+ * @file Debouncer - Hook debouncing for performance optimization
3
+ * @description Prevents redundant operations by tracking recent calls
4
+ *
5
+ * Features:
6
+ * - Time-based debouncing (skip if same operation within window)
7
+ * - Hash-based key generation
8
+ * - Auto-cleanup of expired entries
9
+ * - Statistics tracking
10
+ */
11
+ import { createHash } from 'crypto';
12
+ const DEFAULT_CONFIG = {
13
+ windowMs: 5000, // 5 seconds
14
+ maxEntries: 500,
15
+ debug: false,
16
+ };
17
+ // =============================================================================
18
+ // Debouncer Implementation
19
+ // =============================================================================
20
+ export class Debouncer {
21
+ config;
22
+ entries = new Map();
23
+ stats = {
24
+ totalCalls: 0,
25
+ skipped: 0,
26
+ };
27
+ constructor(config = {}) {
28
+ this.config = { ...DEFAULT_CONFIG, ...config };
29
+ }
30
+ /**
31
+ * Check if operation should be skipped
32
+ * Returns true if same operation was called within debounce window
33
+ */
34
+ shouldSkip(key) {
35
+ this.stats.totalCalls++;
36
+ const now = Date.now();
37
+ const entry = this.entries.get(key);
38
+ if (entry && now - entry.lastCall < this.config.windowMs) {
39
+ this.stats.skipped++;
40
+ entry.callCount++;
41
+ if (this.config.debug) {
42
+ console.log(`[Debouncer] Skipping (called ${entry.callCount}x in window)`);
43
+ }
44
+ return true;
45
+ }
46
+ // Update or create entry
47
+ this.entries.set(key, { lastCall: now, callCount: 1 });
48
+ // Cleanup if needed
49
+ if (this.entries.size > this.config.maxEntries) {
50
+ this.cleanup();
51
+ }
52
+ return false;
53
+ }
54
+ /**
55
+ * Generate hash key from tool name and params
56
+ */
57
+ createKey(toolName, params) {
58
+ const paramsStr = JSON.stringify(params, Object.keys(params).sort());
59
+ const content = `${toolName}:${paramsStr}`;
60
+ return createHash('md5').update(content).digest('hex');
61
+ }
62
+ /**
63
+ * Check if tool call should skip embedding lookup
64
+ */
65
+ shouldSkipEmbedding(toolName, params) {
66
+ const key = this.createKey(toolName, params);
67
+ return this.shouldSkip(`embed:${key}`);
68
+ }
69
+ /**
70
+ * Check if expert review should be skipped
71
+ */
72
+ shouldSkipReview(files) {
73
+ const filesKey = files.sort().join('|');
74
+ const key = createHash('md5').update(filesKey).digest('hex');
75
+ return this.shouldSkip(`review:${key}`);
76
+ }
77
+ /**
78
+ * Mark operation as complete (update timestamp)
79
+ */
80
+ markComplete(key) {
81
+ this.entries.set(key, { lastCall: Date.now(), callCount: 1 });
82
+ }
83
+ /**
84
+ * Remove expired entries
85
+ */
86
+ cleanup() {
87
+ const now = Date.now();
88
+ let removed = 0;
89
+ for (const [key, entry] of this.entries) {
90
+ if (now - entry.lastCall > this.config.windowMs) {
91
+ this.entries.delete(key);
92
+ removed++;
93
+ }
94
+ }
95
+ if (this.config.debug && removed > 0) {
96
+ console.log(`[Debouncer] Cleaned up ${removed} expired entries`);
97
+ }
98
+ return removed;
99
+ }
100
+ /**
101
+ * Get statistics
102
+ */
103
+ getStats() {
104
+ return {
105
+ totalCalls: this.stats.totalCalls,
106
+ skipped: this.stats.skipped,
107
+ executed: this.stats.totalCalls - this.stats.skipped,
108
+ skipRate: this.stats.totalCalls > 0
109
+ ? this.stats.skipped / this.stats.totalCalls
110
+ : 0,
111
+ activeEntries: this.entries.size,
112
+ };
113
+ }
114
+ /**
115
+ * Reset all state
116
+ */
117
+ reset() {
118
+ this.entries.clear();
119
+ this.stats = { totalCalls: 0, skipped: 0 };
120
+ }
121
+ /**
122
+ * Get config
123
+ */
124
+ getConfig() {
125
+ return { ...this.config };
126
+ }
127
+ /**
128
+ * Update config
129
+ */
130
+ setConfig(config) {
131
+ this.config = { ...this.config, ...config };
132
+ }
133
+ }
134
+ // =============================================================================
135
+ // Specialized Debouncers
136
+ // =============================================================================
137
+ /**
138
+ * Debouncer for embedding lookups
139
+ */
140
+ export class EmbeddingDebouncer extends Debouncer {
141
+ constructor(config = {}) {
142
+ super({
143
+ windowMs: 5000,
144
+ maxEntries: 200,
145
+ ...config,
146
+ });
147
+ }
148
+ shouldSkipLookup(text) {
149
+ const key = createHash('md5').update(text.toLowerCase().trim()).digest('hex');
150
+ return this.shouldSkip(`embed:${key}`);
151
+ }
152
+ }
153
+ /**
154
+ * Debouncer for hook operations
155
+ */
156
+ export class HookDebouncer extends Debouncer {
157
+ constructor(config = {}) {
158
+ super({
159
+ windowMs: 2000,
160
+ maxEntries: 100,
161
+ ...config,
162
+ });
163
+ }
164
+ shouldSkipHook(hookName, context) {
165
+ const key = this.createKey(hookName, context);
166
+ return this.shouldSkip(`hook:${key}`);
167
+ }
168
+ }
169
+ // =============================================================================
170
+ // Singleton Instances
171
+ // =============================================================================
172
+ let globalDebouncer = null;
173
+ let globalEmbeddingDebouncer = null;
174
+ let globalHookDebouncer = null;
175
+ export function getDebouncer(config) {
176
+ if (!globalDebouncer) {
177
+ globalDebouncer = new Debouncer(config);
178
+ }
179
+ return globalDebouncer;
180
+ }
181
+ export function getEmbeddingDebouncer(config) {
182
+ if (!globalEmbeddingDebouncer) {
183
+ globalEmbeddingDebouncer = new EmbeddingDebouncer(config);
184
+ }
185
+ return globalEmbeddingDebouncer;
186
+ }
187
+ export function getHookDebouncer(config) {
188
+ if (!globalHookDebouncer) {
189
+ globalHookDebouncer = new HookDebouncer(config);
190
+ }
191
+ return globalHookDebouncer;
192
+ }
193
+ export function resetDebouncers() {
194
+ globalDebouncer = null;
195
+ globalEmbeddingDebouncer = null;
196
+ globalHookDebouncer = null;
197
+ }
198
+ //# sourceMappingURL=Debouncer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Debouncer.js","sourceRoot":"","sources":["../../src/performance/Debouncer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AA4BnC,MAAM,cAAc,GAAoB;IACtC,QAAQ,EAAE,IAAI,EAAE,YAAY;IAC5B,UAAU,EAAE,GAAG;IACf,KAAK,EAAE,KAAK;CACb,CAAA;AAED,gFAAgF;AAChF,2BAA2B;AAC3B,gFAAgF;AAEhF,MAAM,OAAO,SAAS;IACZ,MAAM,CAAiB;IACvB,OAAO,GAAgC,IAAI,GAAG,EAAE,CAAA;IAChD,KAAK,GAAG;QACd,UAAU,EAAE,CAAC;QACb,OAAO,EAAE,CAAC;KACX,CAAA;IAED,YAAY,SAAmC,EAAE;QAC/C,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAA;IAChD,CAAC;IAED;;;OAGG;IACH,UAAU,CAAC,GAAW;QACpB,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAA;QACvB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAEtB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAEnC,IAAI,KAAK,IAAI,GAAG,GAAG,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YACzD,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAA;YACpB,KAAK,CAAC,SAAS,EAAE,CAAA;YAEjB,IAAI,IAAI,CAAC,MAAM,CAA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EAAE,OAAgC;QAC/D,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;QAC7C,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,GAAG,EAAE,CAAC,CAAA;IACvC,CAAC;CACF;AAED,gFAAgF;AAChF,sBAAsB;AACtB,gFAAgF;AAEhF,IAAI,eAAe,GAAqB,IAAI,CAAA;AAC5C,IAAI,wBAAwB,GAA8B,IAAI,CAAA;AAC9D,IAAI,mBAAmB,GAAyB,IAAI,CAAA;AAEpD,MAAM,UAAU,YAAY,CAAC,MAAiC;IAC5D,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,eAAe,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,CAAA;IACzC,CAAC;IACD,OAAO,eAAe,CAAA;AACxB,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,MAAiC;IACrE,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC9B,wBAAwB,GAAG,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAA;IAC3D,CAAC;IACD,OAAO,wBAAwB,CAAA;AACjC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAiC;IAChE,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,mBAAmB,GAAG,IAAI,aAAa,CAAC,MAAM,CAAC,CAAA;IACjD,CAAC;IACD,OAAO,mBAAmB,CAAA;AAC5B,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,eAAe,GAAG,IAAI,CAAA;IACtB,wBAAwB,GAAG,IAAI,CAAA;IAC/B,mBAAmB,GAAG,IAAI,CAAA;AAC5B,CAAC"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @file MemoryDecay - Memory scoring with exponential decay
3
+ * @description Calculates relevance scores for memories based on age, usage, and feedback
4
+ *
5
+ * Formula:
6
+ * score = (feedbackScore * decayFactor) + usageBoost + pinBonus
7
+ *
8
+ * Where:
9
+ * - decayFactor = exp(-age / halfLife)
10
+ * - usageBoost = min(accessCount * 0.05, 0.3)
11
+ * - pinBonus = 0.5 if pinned
12
+ */
13
+ export interface MemoryForScoring {
14
+ id: string;
15
+ createdAt: string | Date;
16
+ /** Base relevance score (0-1) */
17
+ feedbackScore?: number;
18
+ /** Number of times accessed */
19
+ accessCount?: number;
20
+ /** Is memory pinned (never decays) */
21
+ pinned?: boolean;
22
+ /** Last accessed timestamp */
23
+ lastAccessedAt?: string | Date;
24
+ }
25
+ export interface ScoredMemory extends MemoryForScoring {
26
+ calculatedScore: number;
27
+ ageInDays: number;
28
+ decayFactor: number;
29
+ }
30
+ export interface DecayConfig {
31
+ /** Half-life in days (default 90) */
32
+ halfLifeDays: number;
33
+ /** Maximum usage boost (default 0.3) */
34
+ maxUsageBoost: number;
35
+ /** Boost per access (default 0.05) */
36
+ perAccessBoost: number;
37
+ /** Bonus for pinned memories (default 0.5) */
38
+ pinBonus: number;
39
+ /** Recent access bonus (accessed in last 7 days) */
40
+ recentAccessBonus: number;
41
+ /** Days considered "recent" */
42
+ recentDays: number;
43
+ }
44
+ export declare class MemoryDecay {
45
+ private config;
46
+ constructor(config?: Partial<DecayConfig>);
47
+ /**
48
+ * Calculate score for a single memory
49
+ */
50
+ calculateScore(memory: MemoryForScoring): ScoredMemory;
51
+ /**
52
+ * Score and sort memories by relevance
53
+ */
54
+ rankMemories(memories: MemoryForScoring[]): ScoredMemory[];
55
+ /**
56
+ * Filter memories by minimum score
57
+ */
58
+ filterByScore(memories: MemoryForScoring[], minScore?: number): ScoredMemory[];
59
+ /**
60
+ * Get stale memories (low scores)
61
+ */
62
+ getStaleMemories(memories: MemoryForScoring[], threshold?: number): ScoredMemory[];
63
+ /**
64
+ * Calculate what score a memory will have at a future date
65
+ */
66
+ projectScore(memory: MemoryForScoring, daysInFuture: number): number;
67
+ /**
68
+ * Estimate days until memory falls below threshold
69
+ */
70
+ estimateDaysUntilStale(memory: MemoryForScoring, threshold?: number): number | null;
71
+ /**
72
+ * Get config
73
+ */
74
+ getConfig(): DecayConfig;
75
+ /**
76
+ * Update config
77
+ */
78
+ setConfig(config: Partial<DecayConfig>): void;
79
+ }
80
+ export declare function getMemoryDecay(config?: Partial<DecayConfig>): MemoryDecay;
81
+ export declare function resetMemoryDecay(): void;
82
+ //# sourceMappingURL=MemoryDecay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemoryDecay.d.ts","sourceRoot":"","sources":["../../src/performance/MemoryDecay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,iCAAiC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,+BAA+B;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,sCAAsC;IACtC,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,8BAA8B;IAC9B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC/B;AAED,MAAM,WAAW,YAAa,SAAQ,gBAAgB;IACpD,eAAe,EAAE,MAAM,CAAA;IACvB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,qCAAqC;IACrC,YAAY,EAAE,MAAM,CAAA;IACpB,wCAAwC;IACxC,aAAa,EAAE,MAAM,CAAA;IACrB,sCAAsC;IACtC,cAAc,EAAE,MAAM,CAAA;IACtB,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAA;IAChB,oDAAoD;IACpD,iBAAiB,EAAE,MAAM,CAAA;IACzB,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAA;CACnB;AAeD,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAa;gBAEf,MAAM,GAAE,OAAO,CAAC,WAAW,CAAM;IAI7C;;OAEG;IACH,cAAc,CAAC,MAAM,EAAE,gBAAgB,GAAG,YAAY;IA6CtD;;OAEG;IACH,YAAY,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,YAAY,EAAE;IAM1D;;OAEG;IACH,aAAa,CACX,QAAQ,EAAE,gBAAgB,EAAE,EAC5B,QAAQ,GAAE,MAAY,GACrB,YAAY,EAAE;IAIjB;;OAEG;IACH,gBAAgB,CACd,QAAQ,EAAE,gBAAgB,EAAE,EAC5B,SAAS,GAAE,MAAY,GACtB,YAAY,EAAE;IAMjB;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM;IAmBpE;;OAEG;IACH,sBAAsB,CACpB,MAAM,EAAE,gBAAgB,EACxB,SAAS,GAAE,MAAY,GACtB,MAAM,GAAG,IAAI;IAwBhB;;OAEG;IACH,SAAS,IAAI,WAAW;IAIxB;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI;CAG9C;AAQD,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,WAAW,CAKzE;AAED,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC"}
@@ -0,0 +1,153 @@
1
+ /**
2
+ * @file MemoryDecay - Memory scoring with exponential decay
3
+ * @description Calculates relevance scores for memories based on age, usage, and feedback
4
+ *
5
+ * Formula:
6
+ * score = (feedbackScore * decayFactor) + usageBoost + pinBonus
7
+ *
8
+ * Where:
9
+ * - decayFactor = exp(-age / halfLife)
10
+ * - usageBoost = min(accessCount * 0.05, 0.3)
11
+ * - pinBonus = 0.5 if pinned
12
+ */
13
+ const DEFAULT_CONFIG = {
14
+ halfLifeDays: 90,
15
+ maxUsageBoost: 0.3,
16
+ perAccessBoost: 0.05,
17
+ pinBonus: 0.5,
18
+ recentAccessBonus: 0.1,
19
+ recentDays: 7,
20
+ };
21
+ // =============================================================================
22
+ // MemoryDecay Implementation
23
+ // =============================================================================
24
+ export class MemoryDecay {
25
+ config;
26
+ constructor(config = {}) {
27
+ this.config = { ...DEFAULT_CONFIG, ...config };
28
+ }
29
+ /**
30
+ * Calculate score for a single memory
31
+ */
32
+ calculateScore(memory) {
33
+ const now = Date.now();
34
+ const createdAt = new Date(memory.createdAt).getTime();
35
+ const ageInDays = (now - createdAt) / (1000 * 60 * 60 * 24);
36
+ // Base score from feedback (default 0.5)
37
+ const feedbackScore = memory.feedbackScore ?? 0.5;
38
+ // Decay factor (pinned = no decay)
39
+ const decayFactor = memory.pinned
40
+ ? 1.0
41
+ : Math.exp(-ageInDays / this.config.halfLifeDays);
42
+ // Usage boost
43
+ const usageBoost = memory.accessCount
44
+ ? Math.min(memory.accessCount * this.config.perAccessBoost, this.config.maxUsageBoost)
45
+ : 0;
46
+ // Recent access bonus
47
+ let recentBonus = 0;
48
+ if (memory.lastAccessedAt) {
49
+ const lastAccess = new Date(memory.lastAccessedAt).getTime();
50
+ const daysSinceAccess = (now - lastAccess) / (1000 * 60 * 60 * 24);
51
+ if (daysSinceAccess < this.config.recentDays) {
52
+ recentBonus = this.config.recentAccessBonus;
53
+ }
54
+ }
55
+ // Pin bonus
56
+ const pinBonus = memory.pinned ? this.config.pinBonus : 0;
57
+ // Final score
58
+ const calculatedScore = Math.min((feedbackScore * decayFactor) + usageBoost + recentBonus + pinBonus, 1.0);
59
+ return {
60
+ ...memory,
61
+ calculatedScore,
62
+ ageInDays,
63
+ decayFactor,
64
+ };
65
+ }
66
+ /**
67
+ * Score and sort memories by relevance
68
+ */
69
+ rankMemories(memories) {
70
+ return memories
71
+ .map(m => this.calculateScore(m))
72
+ .sort((a, b) => b.calculatedScore - a.calculatedScore);
73
+ }
74
+ /**
75
+ * Filter memories by minimum score
76
+ */
77
+ filterByScore(memories, minScore = 0.1) {
78
+ return this.rankMemories(memories).filter(m => m.calculatedScore >= minScore);
79
+ }
80
+ /**
81
+ * Get stale memories (low scores)
82
+ */
83
+ getStaleMemories(memories, threshold = 0.2) {
84
+ return this.rankMemories(memories).filter(m => m.calculatedScore < threshold && !m.pinned);
85
+ }
86
+ /**
87
+ * Calculate what score a memory will have at a future date
88
+ */
89
+ projectScore(memory, daysInFuture) {
90
+ const scored = this.calculateScore(memory);
91
+ if (memory.pinned) {
92
+ return scored.calculatedScore;
93
+ }
94
+ // Project decay
95
+ const futureAge = scored.ageInDays + daysInFuture;
96
+ const futureDecay = Math.exp(-futureAge / this.config.halfLifeDays);
97
+ const feedbackScore = memory.feedbackScore ?? 0.5;
98
+ const usageBoost = memory.accessCount
99
+ ? Math.min(memory.accessCount * this.config.perAccessBoost, this.config.maxUsageBoost)
100
+ : 0;
101
+ return Math.min((feedbackScore * futureDecay) + usageBoost, 1.0);
102
+ }
103
+ /**
104
+ * Estimate days until memory falls below threshold
105
+ */
106
+ estimateDaysUntilStale(memory, threshold = 0.2) {
107
+ if (memory.pinned)
108
+ return null;
109
+ const currentScore = this.calculateScore(memory).calculatedScore;
110
+ if (currentScore < threshold)
111
+ return 0;
112
+ // Binary search for the day when score drops below threshold
113
+ let low = 0;
114
+ let high = 365 * 5; // 5 years max
115
+ while (high - low > 1) {
116
+ const mid = Math.floor((low + high) / 2);
117
+ const projectedScore = this.projectScore(memory, mid);
118
+ if (projectedScore >= threshold) {
119
+ low = mid;
120
+ }
121
+ else {
122
+ high = mid;
123
+ }
124
+ }
125
+ return high;
126
+ }
127
+ /**
128
+ * Get config
129
+ */
130
+ getConfig() {
131
+ return { ...this.config };
132
+ }
133
+ /**
134
+ * Update config
135
+ */
136
+ setConfig(config) {
137
+ this.config = { ...this.config, ...config };
138
+ }
139
+ }
140
+ // =============================================================================
141
+ // Singleton
142
+ // =============================================================================
143
+ let globalDecay = null;
144
+ export function getMemoryDecay(config) {
145
+ if (!globalDecay) {
146
+ globalDecay = new MemoryDecay(config);
147
+ }
148
+ return globalDecay;
149
+ }
150
+ export function resetMemoryDecay() {
151
+ globalDecay = null;
152
+ }
153
+ //# sourceMappingURL=MemoryDecay.js.map
@@ -0,0 +1 @@
1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1,7 @@
1
+ /**
2
+ * @file Performance Module - cmp-standards v2.8
3
+ * @description Performance optimization utilities
4
+ */
5
+ export { Debouncer, DebouncerConfig, DebouncerStats, EmbeddingDebouncer, HookDebouncer, getDebouncer, getEmbeddingDebouncer, getHookDebouncer, resetDebouncers, } from './Debouncer.js';
6
+ export { MemoryDecay, MemoryForScoring, ScoredMemory, DecayConfig, getMemoryDecay, resetMemoryDecay, } from './MemoryDecay.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/performance/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,SAAS,EACT,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,GAChB,MAAM,gBAAgB,CAAA;AAGvB,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,cAAc,EACd,gBAAgB,GACjB,MAAM,kBAAkB,CAAA"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @file Performance Module - cmp-standards v2.8
3
+ * @description Performance optimization utilities
4
+ */
5
+ // Debouncing
6
+ export { Debouncer, EmbeddingDebouncer, HookDebouncer, getDebouncer, getEmbeddingDebouncer, getHookDebouncer, resetDebouncers, } from './Debouncer.js';
7
+ // Memory Decay
8
+ export { MemoryDecay, getMemoryDecay, resetMemoryDecay, } from './MemoryDecay.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/performance/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,aAAa;AACb,OAAO,EACL,SAAS,EAGT,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,GAChB,MAAM,gBAAgB,CAAA;AAEvB,eAAe;AACf,OAAO,EACL,WAAW,EAIX,cAAc,EACd,gBAAgB,GACjB,MAAM,kBAAkB,CAAA"}