@claude-flow/cli 3.0.0-alpha.100 → 3.0.0-alpha.102
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/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp-tools/hooks-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/hooks-tools.js +443 -54
- package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
- package/dist/src/memory/ewc-consolidation.d.ts +271 -0
- package/dist/src/memory/ewc-consolidation.d.ts.map +1 -0
- package/dist/src/memory/ewc-consolidation.js +542 -0
- package/dist/src/memory/ewc-consolidation.js.map +1 -0
- package/dist/src/memory/sona-optimizer.d.ts +227 -0
- package/dist/src/memory/sona-optimizer.d.ts.map +1 -0
- package/dist/src/memory/sona-optimizer.js +633 -0
- package/dist/src/memory/sona-optimizer.js.map +1 -0
- package/dist/src/ruvector/flash-attention.d.ts +162 -0
- package/dist/src/ruvector/flash-attention.d.ts.map +1 -0
- package/dist/src/ruvector/flash-attention.js +426 -0
- package/dist/src/ruvector/flash-attention.js.map +1 -0
- package/dist/src/ruvector/index.d.ts +5 -0
- package/dist/src/ruvector/index.d.ts.map +1 -1
- package/dist/src/ruvector/index.js +5 -0
- package/dist/src/ruvector/index.js.map +1 -1
- package/dist/src/ruvector/lora-adapter.d.ts +218 -0
- package/dist/src/ruvector/lora-adapter.d.ts.map +1 -0
- package/dist/src/ruvector/lora-adapter.js +455 -0
- package/dist/src/ruvector/lora-adapter.js.map +1 -0
- package/dist/src/ruvector/moe-router.d.ts +206 -0
- package/dist/src/ruvector/moe-router.d.ts.map +1 -0
- package/dist/src/ruvector/moe-router.js +626 -0
- package/dist/src/ruvector/moe-router.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EWC++ (Elastic Weight Consolidation) Implementation
|
|
3
|
+
* Prevents catastrophic forgetting of important patterns during continual learning
|
|
4
|
+
*
|
|
5
|
+
* Algorithm:
|
|
6
|
+
* L_total = L_new + (lambda/2) * sum_i(F_i * (theta_i - theta_old_i)^2)
|
|
7
|
+
*
|
|
8
|
+
* Where:
|
|
9
|
+
* - L_new is the loss on new data
|
|
10
|
+
* - lambda is the importance weight (ewcLambda)
|
|
11
|
+
* - F_i is the Fisher information for parameter i
|
|
12
|
+
* - theta_i is the current parameter value
|
|
13
|
+
* - theta_old_i is the previous parameter value
|
|
14
|
+
*
|
|
15
|
+
* Features:
|
|
16
|
+
* - Fisher Information Matrix computation from gradient history
|
|
17
|
+
* - Online EWC updates for streaming patterns
|
|
18
|
+
* - Selective consolidation based on pattern importance
|
|
19
|
+
* - Persistent storage in .swarm/ewc-fisher.json
|
|
20
|
+
*
|
|
21
|
+
* @module v3/cli/memory/ewc-consolidation
|
|
22
|
+
*/
|
|
23
|
+
import * as fs from 'fs';
|
|
24
|
+
import * as path from 'path';
|
|
25
|
+
// ============================================================================
|
|
26
|
+
// Default Configuration
|
|
27
|
+
// ============================================================================
|
|
28
|
+
const DEFAULT_EWC_CONFIG = {
|
|
29
|
+
lambda: 0.4,
|
|
30
|
+
maxPatterns: 1000,
|
|
31
|
+
fisherDecayRate: 0.01,
|
|
32
|
+
importanceThreshold: 0.3,
|
|
33
|
+
storagePath: path.join(process.cwd(), '.swarm', 'ewc-fisher.json'),
|
|
34
|
+
onlineMode: true,
|
|
35
|
+
dimensions: 384
|
|
36
|
+
};
|
|
37
|
+
// ============================================================================
|
|
38
|
+
// EWC Consolidator Class
|
|
39
|
+
// ============================================================================
|
|
40
|
+
/**
|
|
41
|
+
* EWC++ Consolidator
|
|
42
|
+
* Implements Elastic Weight Consolidation with online updates
|
|
43
|
+
* for preventing catastrophic forgetting in continual learning
|
|
44
|
+
*/
|
|
45
|
+
export class EWCConsolidator {
|
|
46
|
+
config;
|
|
47
|
+
patterns = new Map();
|
|
48
|
+
gradientHistory = [];
|
|
49
|
+
globalFisher = [];
|
|
50
|
+
consolidationHistory = [];
|
|
51
|
+
initialized = false;
|
|
52
|
+
constructor(config) {
|
|
53
|
+
this.config = { ...DEFAULT_EWC_CONFIG, ...config };
|
|
54
|
+
this.globalFisher = new Array(this.config.dimensions).fill(0);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Initialize the consolidator by loading persisted state
|
|
58
|
+
*/
|
|
59
|
+
async initialize() {
|
|
60
|
+
if (this.initialized)
|
|
61
|
+
return true;
|
|
62
|
+
try {
|
|
63
|
+
await this.loadFromDisk();
|
|
64
|
+
this.initialized = true;
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// Start fresh if no persisted state
|
|
69
|
+
this.initialized = true;
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Compute Fisher Information Matrix from gradient history
|
|
75
|
+
* Uses diagonal approximation for efficiency: F_i = E[g_i^2]
|
|
76
|
+
*
|
|
77
|
+
* @param patterns - Array of patterns with their gradients/embeddings
|
|
78
|
+
* @returns Fisher information diagonal
|
|
79
|
+
*/
|
|
80
|
+
computeFisherMatrix(patterns) {
|
|
81
|
+
const fisher = new Array(this.config.dimensions).fill(0);
|
|
82
|
+
let sampleCount = 0;
|
|
83
|
+
for (const pattern of patterns) {
|
|
84
|
+
if (!pattern.embedding || pattern.embedding.length === 0)
|
|
85
|
+
continue;
|
|
86
|
+
// Only use successful patterns for Fisher computation
|
|
87
|
+
// (we want to preserve what worked)
|
|
88
|
+
if (!pattern.success)
|
|
89
|
+
continue;
|
|
90
|
+
sampleCount++;
|
|
91
|
+
// Fisher diagonal is expectation of squared gradients
|
|
92
|
+
// For embeddings, we use the embedding values as proxy for gradients
|
|
93
|
+
const len = Math.min(pattern.embedding.length, this.config.dimensions);
|
|
94
|
+
for (let i = 0; i < len; i++) {
|
|
95
|
+
// Accumulate squared values (gradient proxy)
|
|
96
|
+
fisher[i] += pattern.embedding[i] * pattern.embedding[i];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Normalize by sample count
|
|
100
|
+
if (sampleCount > 0) {
|
|
101
|
+
for (let i = 0; i < this.config.dimensions; i++) {
|
|
102
|
+
fisher[i] /= sampleCount;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// Update global Fisher with exponential moving average (EWC++)
|
|
106
|
+
if (this.config.onlineMode) {
|
|
107
|
+
const decay = this.config.fisherDecayRate;
|
|
108
|
+
for (let i = 0; i < this.config.dimensions; i++) {
|
|
109
|
+
this.globalFisher[i] = (1 - decay) * this.globalFisher[i] + decay * fisher[i];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return fisher;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Consolidate new patterns with old patterns without forgetting
|
|
116
|
+
* Applies EWC penalty to preserve important weights
|
|
117
|
+
*
|
|
118
|
+
* @param newPatterns - New patterns to incorporate
|
|
119
|
+
* @param oldPatterns - Existing patterns to preserve
|
|
120
|
+
* @returns Consolidated patterns with modified weights
|
|
121
|
+
*/
|
|
122
|
+
consolidate(newPatterns, oldPatterns) {
|
|
123
|
+
const startTime = performance.now();
|
|
124
|
+
const result = {
|
|
125
|
+
success: false,
|
|
126
|
+
patternsConsolidated: 0,
|
|
127
|
+
totalPenalty: 0,
|
|
128
|
+
modifiedPatterns: [],
|
|
129
|
+
protectedPatterns: [],
|
|
130
|
+
duration: 0
|
|
131
|
+
};
|
|
132
|
+
try {
|
|
133
|
+
// Use stored patterns if no old patterns provided
|
|
134
|
+
const existingPatterns = oldPatterns || Array.from(this.patterns.values());
|
|
135
|
+
// Compute Fisher from successful existing patterns
|
|
136
|
+
const fisherInput = existingPatterns
|
|
137
|
+
.filter(p => p.successCount > p.failureCount)
|
|
138
|
+
.map(p => ({
|
|
139
|
+
id: p.id,
|
|
140
|
+
embedding: p.weights,
|
|
141
|
+
success: true
|
|
142
|
+
}));
|
|
143
|
+
const fisher = this.computeFisherMatrix(fisherInput);
|
|
144
|
+
// Process each new pattern
|
|
145
|
+
for (const newPattern of newPatterns) {
|
|
146
|
+
if (!newPattern.embedding || newPattern.embedding.length === 0)
|
|
147
|
+
continue;
|
|
148
|
+
const existingPattern = this.patterns.get(newPattern.id);
|
|
149
|
+
if (existingPattern) {
|
|
150
|
+
// Calculate EWC penalty for updating existing pattern
|
|
151
|
+
const penalty = this.getPenalty(existingPattern.weights, newPattern.embedding, fisher);
|
|
152
|
+
// Determine if update is allowed based on penalty
|
|
153
|
+
const importanceScore = this.calculateImportance(existingPattern);
|
|
154
|
+
if (importanceScore > this.config.importanceThreshold && penalty > this.config.lambda) {
|
|
155
|
+
// Protect high-importance patterns with high penalty
|
|
156
|
+
result.protectedPatterns.push(newPattern.id);
|
|
157
|
+
// Apply constrained update: blend old and new based on importance
|
|
158
|
+
const blendFactor = 1 - importanceScore;
|
|
159
|
+
const blendedWeights = this.blendWeights(existingPattern.weights, newPattern.embedding, blendFactor, fisher);
|
|
160
|
+
existingPattern.weights = blendedWeights;
|
|
161
|
+
existingPattern.lastUpdated = Date.now();
|
|
162
|
+
result.modifiedPatterns.push(newPattern.id);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
// Low importance or low penalty: allow full update
|
|
166
|
+
existingPattern.weights = newPattern.embedding.slice(0, this.config.dimensions);
|
|
167
|
+
existingPattern.lastUpdated = Date.now();
|
|
168
|
+
result.modifiedPatterns.push(newPattern.id);
|
|
169
|
+
}
|
|
170
|
+
// Update Fisher diagonal for this pattern
|
|
171
|
+
existingPattern.fisherDiagonal = fisher;
|
|
172
|
+
result.totalPenalty += penalty;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
// New pattern: add directly
|
|
176
|
+
const weights = {
|
|
177
|
+
id: newPattern.id,
|
|
178
|
+
weights: newPattern.embedding.slice(0, this.config.dimensions),
|
|
179
|
+
fisherDiagonal: fisher,
|
|
180
|
+
importance: 0.5,
|
|
181
|
+
successCount: 0,
|
|
182
|
+
failureCount: 0,
|
|
183
|
+
lastUpdated: Date.now(),
|
|
184
|
+
type: newPattern.type,
|
|
185
|
+
description: newPattern.description
|
|
186
|
+
};
|
|
187
|
+
this.patterns.set(newPattern.id, weights);
|
|
188
|
+
result.modifiedPatterns.push(newPattern.id);
|
|
189
|
+
}
|
|
190
|
+
result.patternsConsolidated++;
|
|
191
|
+
}
|
|
192
|
+
// Prune old patterns if exceeding limit
|
|
193
|
+
if (this.patterns.size > this.config.maxPatterns) {
|
|
194
|
+
this.pruneOldPatterns();
|
|
195
|
+
}
|
|
196
|
+
// Record consolidation
|
|
197
|
+
this.consolidationHistory.push({
|
|
198
|
+
timestamp: Date.now(),
|
|
199
|
+
penalty: result.totalPenalty,
|
|
200
|
+
patterns: result.patternsConsolidated
|
|
201
|
+
});
|
|
202
|
+
// Persist to disk
|
|
203
|
+
this.saveToDisk();
|
|
204
|
+
result.success = true;
|
|
205
|
+
result.duration = performance.now() - startTime;
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
result.error = error instanceof Error ? error.message : String(error);
|
|
210
|
+
result.duration = performance.now() - startTime;
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Calculate EWC regularization penalty
|
|
216
|
+
*
|
|
217
|
+
* L_ewc = (lambda/2) * sum_i(F_i * (theta_i - theta_old_i)^2)
|
|
218
|
+
*
|
|
219
|
+
* @param oldWeights - Previous weight values
|
|
220
|
+
* @param newWeights - New weight values
|
|
221
|
+
* @param fisher - Fisher information diagonal (optional, uses global if not provided)
|
|
222
|
+
* @returns Regularization penalty value
|
|
223
|
+
*/
|
|
224
|
+
getPenalty(oldWeights, newWeights, fisher) {
|
|
225
|
+
const fisherDiag = fisher || this.globalFisher;
|
|
226
|
+
const len = Math.min(oldWeights.length, newWeights.length, fisherDiag.length);
|
|
227
|
+
let penalty = 0;
|
|
228
|
+
for (let i = 0; i < len; i++) {
|
|
229
|
+
const diff = newWeights[i] - oldWeights[i];
|
|
230
|
+
penalty += fisherDiag[i] * diff * diff;
|
|
231
|
+
}
|
|
232
|
+
return (this.config.lambda / 2) * penalty;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Get consolidation statistics
|
|
236
|
+
*/
|
|
237
|
+
getConsolidationStats() {
|
|
238
|
+
let totalFisher = 0;
|
|
239
|
+
let maxFisher = 0;
|
|
240
|
+
let highImportance = 0;
|
|
241
|
+
for (let i = 0; i < this.globalFisher.length; i++) {
|
|
242
|
+
totalFisher += this.globalFisher[i];
|
|
243
|
+
if (this.globalFisher[i] > maxFisher) {
|
|
244
|
+
maxFisher = this.globalFisher[i];
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
for (const pattern of this.patterns.values()) {
|
|
248
|
+
if (this.calculateImportance(pattern) > this.config.importanceThreshold) {
|
|
249
|
+
highImportance++;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const totalPenalty = this.consolidationHistory.reduce((sum, h) => sum + h.penalty, 0);
|
|
253
|
+
const avgPenalty = this.consolidationHistory.length > 0
|
|
254
|
+
? totalPenalty / this.consolidationHistory.length
|
|
255
|
+
: 0;
|
|
256
|
+
// Estimate storage size
|
|
257
|
+
let storageSizeBytes = 0;
|
|
258
|
+
try {
|
|
259
|
+
if (fs.existsSync(this.config.storagePath)) {
|
|
260
|
+
const stats = fs.statSync(this.config.storagePath);
|
|
261
|
+
storageSizeBytes = stats.size;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
// Ignore stat errors
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
totalPatterns: this.patterns.size,
|
|
269
|
+
highImportancePatterns: highImportance,
|
|
270
|
+
avgFisherValue: this.globalFisher.length > 0 ? totalFisher / this.globalFisher.length : 0,
|
|
271
|
+
maxFisherValue: maxFisher,
|
|
272
|
+
consolidationCount: this.consolidationHistory.length,
|
|
273
|
+
lastConsolidation: this.consolidationHistory.length > 0
|
|
274
|
+
? this.consolidationHistory[this.consolidationHistory.length - 1].timestamp
|
|
275
|
+
: null,
|
|
276
|
+
avgPenalty,
|
|
277
|
+
storageSizeBytes
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Record a gradient sample for Fisher computation
|
|
282
|
+
*/
|
|
283
|
+
recordGradient(patternId, gradients, success) {
|
|
284
|
+
this.gradientHistory.push({
|
|
285
|
+
patternId,
|
|
286
|
+
gradients,
|
|
287
|
+
timestamp: Date.now(),
|
|
288
|
+
success
|
|
289
|
+
});
|
|
290
|
+
// Keep only recent gradients
|
|
291
|
+
const maxGradients = this.config.maxPatterns * 2;
|
|
292
|
+
if (this.gradientHistory.length > maxGradients) {
|
|
293
|
+
this.gradientHistory = this.gradientHistory.slice(-maxGradients);
|
|
294
|
+
}
|
|
295
|
+
// Update pattern success/failure counts
|
|
296
|
+
const pattern = this.patterns.get(patternId);
|
|
297
|
+
if (pattern) {
|
|
298
|
+
if (success) {
|
|
299
|
+
pattern.successCount++;
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
pattern.failureCount++;
|
|
303
|
+
}
|
|
304
|
+
pattern.importance = this.calculateImportance(pattern);
|
|
305
|
+
}
|
|
306
|
+
// Online Fisher update from this gradient
|
|
307
|
+
if (this.config.onlineMode && success) {
|
|
308
|
+
const decay = this.config.fisherDecayRate;
|
|
309
|
+
const len = Math.min(gradients.length, this.config.dimensions);
|
|
310
|
+
for (let i = 0; i < len; i++) {
|
|
311
|
+
this.globalFisher[i] = (1 - decay) * this.globalFisher[i] + decay * gradients[i] * gradients[i];
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Get pattern weights by ID
|
|
317
|
+
*/
|
|
318
|
+
getPatternWeights(id) {
|
|
319
|
+
return this.patterns.get(id);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Get all stored patterns
|
|
323
|
+
*/
|
|
324
|
+
getAllPatterns() {
|
|
325
|
+
return Array.from(this.patterns.values());
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Update EWC lambda (regularization strength)
|
|
329
|
+
*/
|
|
330
|
+
setLambda(lambda) {
|
|
331
|
+
this.config.lambda = lambda;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Get current lambda value
|
|
335
|
+
*/
|
|
336
|
+
getLambda() {
|
|
337
|
+
return this.config.lambda;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Reset Fisher matrix (use with caution - allows forgetting)
|
|
341
|
+
*/
|
|
342
|
+
resetFisher() {
|
|
343
|
+
this.globalFisher = new Array(this.config.dimensions).fill(0);
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Clear all patterns and history (full reset)
|
|
347
|
+
*/
|
|
348
|
+
clear() {
|
|
349
|
+
this.patterns.clear();
|
|
350
|
+
this.gradientHistory = [];
|
|
351
|
+
this.globalFisher = new Array(this.config.dimensions).fill(0);
|
|
352
|
+
this.consolidationHistory = [];
|
|
353
|
+
// Remove persisted file
|
|
354
|
+
try {
|
|
355
|
+
if (fs.existsSync(this.config.storagePath)) {
|
|
356
|
+
fs.unlinkSync(this.config.storagePath);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
catch {
|
|
360
|
+
// Ignore deletion errors
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
// ============================================================================
|
|
364
|
+
// Private Methods
|
|
365
|
+
// ============================================================================
|
|
366
|
+
/**
|
|
367
|
+
* Calculate importance score for a pattern based on usage
|
|
368
|
+
*/
|
|
369
|
+
calculateImportance(pattern) {
|
|
370
|
+
const total = pattern.successCount + pattern.failureCount;
|
|
371
|
+
if (total === 0)
|
|
372
|
+
return 0.5;
|
|
373
|
+
// Success rate with Laplace smoothing
|
|
374
|
+
const successRate = (pattern.successCount + 1) / (total + 2);
|
|
375
|
+
// Recency factor: recent patterns are more important
|
|
376
|
+
const hoursSinceUpdate = (Date.now() - pattern.lastUpdated) / (1000 * 60 * 60);
|
|
377
|
+
const recencyFactor = Math.exp(-hoursSinceUpdate / 168); // 1 week half-life
|
|
378
|
+
// Combine factors
|
|
379
|
+
return successRate * 0.7 + recencyFactor * 0.3;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Blend old and new weights using Fisher-weighted interpolation
|
|
383
|
+
*/
|
|
384
|
+
blendWeights(oldWeights, newWeights, blendFactor, fisher) {
|
|
385
|
+
const len = Math.min(oldWeights.length, newWeights.length, this.config.dimensions);
|
|
386
|
+
const result = new Array(len);
|
|
387
|
+
// Normalize Fisher for per-weight blend factors
|
|
388
|
+
let maxF = 0;
|
|
389
|
+
for (let i = 0; i < len; i++) {
|
|
390
|
+
if (fisher[i] > maxF)
|
|
391
|
+
maxF = fisher[i];
|
|
392
|
+
}
|
|
393
|
+
const normFactor = maxF > 0 ? 1 / maxF : 1;
|
|
394
|
+
for (let i = 0; i < len; i++) {
|
|
395
|
+
// Higher Fisher = more weight on old value
|
|
396
|
+
const fisherWeight = fisher[i] * normFactor;
|
|
397
|
+
const adjustedBlend = blendFactor * (1 - fisherWeight * 0.5);
|
|
398
|
+
result[i] = oldWeights[i] * (1 - adjustedBlend) + newWeights[i] * adjustedBlend;
|
|
399
|
+
}
|
|
400
|
+
return result;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Prune old, low-importance patterns to stay within limit
|
|
404
|
+
*/
|
|
405
|
+
pruneOldPatterns() {
|
|
406
|
+
if (this.patterns.size <= this.config.maxPatterns)
|
|
407
|
+
return;
|
|
408
|
+
// Sort by importance (ascending)
|
|
409
|
+
const sortedPatterns = Array.from(this.patterns.entries())
|
|
410
|
+
.map(([id, pattern]) => ({ id, importance: this.calculateImportance(pattern) }))
|
|
411
|
+
.sort((a, b) => a.importance - b.importance);
|
|
412
|
+
// Remove lowest importance patterns
|
|
413
|
+
const toRemove = this.patterns.size - this.config.maxPatterns;
|
|
414
|
+
for (let i = 0; i < toRemove; i++) {
|
|
415
|
+
this.patterns.delete(sortedPatterns[i].id);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Save state to disk
|
|
420
|
+
*/
|
|
421
|
+
saveToDisk() {
|
|
422
|
+
try {
|
|
423
|
+
const dir = path.dirname(this.config.storagePath);
|
|
424
|
+
if (!fs.existsSync(dir)) {
|
|
425
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
426
|
+
}
|
|
427
|
+
const state = {
|
|
428
|
+
version: '1.0.0',
|
|
429
|
+
config: {
|
|
430
|
+
lambda: this.config.lambda,
|
|
431
|
+
dimensions: this.config.dimensions,
|
|
432
|
+
fisherDecayRate: this.config.fisherDecayRate
|
|
433
|
+
},
|
|
434
|
+
globalFisher: this.globalFisher,
|
|
435
|
+
patterns: Array.from(this.patterns.entries()),
|
|
436
|
+
consolidationHistory: this.consolidationHistory.slice(-100),
|
|
437
|
+
savedAt: Date.now()
|
|
438
|
+
};
|
|
439
|
+
fs.writeFileSync(this.config.storagePath, JSON.stringify(state, null, 2));
|
|
440
|
+
}
|
|
441
|
+
catch {
|
|
442
|
+
// Silently fail - persistence is best-effort
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Load state from disk
|
|
447
|
+
*/
|
|
448
|
+
async loadFromDisk() {
|
|
449
|
+
if (!fs.existsSync(this.config.storagePath)) {
|
|
450
|
+
throw new Error('No persisted state found');
|
|
451
|
+
}
|
|
452
|
+
const content = fs.readFileSync(this.config.storagePath, 'utf-8');
|
|
453
|
+
const state = JSON.parse(content);
|
|
454
|
+
// Validate version
|
|
455
|
+
if (state.version !== '1.0.0') {
|
|
456
|
+
throw new Error(`Unsupported state version: ${state.version}`);
|
|
457
|
+
}
|
|
458
|
+
// Restore state
|
|
459
|
+
this.globalFisher = state.globalFisher || new Array(this.config.dimensions).fill(0);
|
|
460
|
+
// Restore patterns
|
|
461
|
+
this.patterns.clear();
|
|
462
|
+
if (state.patterns) {
|
|
463
|
+
for (const [id, pattern] of state.patterns) {
|
|
464
|
+
this.patterns.set(id, pattern);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
// Restore history
|
|
468
|
+
this.consolidationHistory = state.consolidationHistory || [];
|
|
469
|
+
// Update config from persisted values
|
|
470
|
+
if (state.config) {
|
|
471
|
+
this.config.lambda = state.config.lambda ?? this.config.lambda;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
// ============================================================================
|
|
476
|
+
// Singleton Instance
|
|
477
|
+
// ============================================================================
|
|
478
|
+
let ewcConsolidatorInstance = null;
|
|
479
|
+
/**
|
|
480
|
+
* Get the singleton EWC Consolidator instance
|
|
481
|
+
*
|
|
482
|
+
* @param config - Optional configuration overrides
|
|
483
|
+
* @returns EWC Consolidator instance
|
|
484
|
+
*/
|
|
485
|
+
export async function getEWCConsolidator(config) {
|
|
486
|
+
if (!ewcConsolidatorInstance) {
|
|
487
|
+
ewcConsolidatorInstance = new EWCConsolidator(config);
|
|
488
|
+
await ewcConsolidatorInstance.initialize();
|
|
489
|
+
}
|
|
490
|
+
return ewcConsolidatorInstance;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Reset the singleton instance (for testing)
|
|
494
|
+
*/
|
|
495
|
+
export function resetEWCConsolidator() {
|
|
496
|
+
if (ewcConsolidatorInstance) {
|
|
497
|
+
ewcConsolidatorInstance.clear();
|
|
498
|
+
ewcConsolidatorInstance = null;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
// ============================================================================
|
|
502
|
+
// Utility Functions
|
|
503
|
+
// ============================================================================
|
|
504
|
+
/**
|
|
505
|
+
* Quick consolidation helper for common use case
|
|
506
|
+
* Consolidates new patterns with existing ones using EWC
|
|
507
|
+
*
|
|
508
|
+
* @param newPatterns - New patterns to add
|
|
509
|
+
* @returns Consolidation result
|
|
510
|
+
*/
|
|
511
|
+
export async function consolidatePatterns(newPatterns) {
|
|
512
|
+
const consolidator = await getEWCConsolidator();
|
|
513
|
+
return consolidator.consolidate(newPatterns);
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Record pattern usage outcome
|
|
517
|
+
* Updates Fisher information and pattern importance
|
|
518
|
+
*
|
|
519
|
+
* @param patternId - Pattern identifier
|
|
520
|
+
* @param embedding - Pattern embedding (used as gradient proxy)
|
|
521
|
+
* @param success - Whether the pattern was successful
|
|
522
|
+
*/
|
|
523
|
+
export async function recordPatternOutcome(patternId, embedding, success) {
|
|
524
|
+
const consolidator = await getEWCConsolidator();
|
|
525
|
+
consolidator.recordGradient(patternId, embedding, success);
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Get EWC statistics
|
|
529
|
+
*/
|
|
530
|
+
export async function getEWCStats() {
|
|
531
|
+
const consolidator = await getEWCConsolidator();
|
|
532
|
+
return consolidator.getConsolidationStats();
|
|
533
|
+
}
|
|
534
|
+
export default {
|
|
535
|
+
EWCConsolidator,
|
|
536
|
+
getEWCConsolidator,
|
|
537
|
+
resetEWCConsolidator,
|
|
538
|
+
consolidatePatterns,
|
|
539
|
+
recordPatternOutcome,
|
|
540
|
+
getEWCStats
|
|
541
|
+
};
|
|
542
|
+
//# sourceMappingURL=ewc-consolidation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ewc-consolidation.js","sourceRoot":"","sources":["../../../src/memory/ewc-consolidation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAoH7B,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E,MAAM,kBAAkB,GAAc;IACpC,MAAM,EAA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