@metago-ai/engine 1.0.7 → 2.0.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/CHANGES.md +2 -2
- package/README.md +3 -3
- package/RUNTIME/dist/evolution-engine.d.ts +58 -29
- package/RUNTIME/dist/evolution-engine.d.ts.map +1 -1
- package/RUNTIME/dist/evolution-engine.js +397 -85
- package/RUNTIME/dist/evolution-engine.js.map +1 -1
- package/RUNTIME/dist/index.d.ts +47 -3
- package/RUNTIME/dist/index.d.ts.map +1 -1
- package/RUNTIME/dist/index.js +83 -4
- package/RUNTIME/dist/index.js.map +1 -1
- package/RUNTIME/dist/kmwi-memory.d.ts +259 -0
- package/RUNTIME/dist/kmwi-memory.d.ts.map +1 -0
- package/RUNTIME/dist/kmwi-memory.js +897 -0
- package/RUNTIME/dist/kmwi-memory.js.map +1 -0
- package/RUNTIME/dist/skill-generator.d.ts +148 -0
- package/RUNTIME/dist/skill-generator.d.ts.map +1 -0
- package/RUNTIME/dist/skill-generator.js +683 -0
- package/RUNTIME/dist/skill-generator.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,897 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MetaGO Engine - KMWI 四层记忆管理
|
|
4
|
+
* KMWI Four-Layer Memory Management
|
|
5
|
+
*
|
|
6
|
+
* 对应技能:metago-memory-manage
|
|
7
|
+
* 对应公理:A1 溯源公理、A2 闭环公理
|
|
8
|
+
* 对应文档:卷2第六章 KMWI 四层记忆管理
|
|
9
|
+
*
|
|
10
|
+
* KMWI 将记忆从单一存储升级为四层递进结构:
|
|
11
|
+
* K(Knowledge 知识层)—— 事实与概念,是原料
|
|
12
|
+
* M(Memory 记忆层)—— 短期与长期记忆,是载体
|
|
13
|
+
* W(Wisdom 智慧层)—— 经验性洞察与模式,是提炼
|
|
14
|
+
* I(Intuition 直觉层)—— 隐性知识与判断力,是升华
|
|
15
|
+
*
|
|
16
|
+
* 四层之间存在两条流:
|
|
17
|
+
* 自下而上转化流:K → M → W → I(知识内化为直觉)
|
|
18
|
+
* 自上而下反哺流:I → W → M → K(直觉反哺知识更新)
|
|
19
|
+
*
|
|
20
|
+
* 健康度公式:H = (K + M + W + I) / 4
|
|
21
|
+
* 衰减率公式:R = (历史值 - 当前值) / 历史值 × 100%
|
|
22
|
+
*
|
|
23
|
+
* @author 易霄 / MetaGO Lightyear
|
|
24
|
+
* @version 1.0.0
|
|
25
|
+
*/
|
|
26
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
27
|
+
if (k2 === undefined) k2 = k;
|
|
28
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
29
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
30
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
31
|
+
}
|
|
32
|
+
Object.defineProperty(o, k2, desc);
|
|
33
|
+
}) : (function(o, m, k, k2) {
|
|
34
|
+
if (k2 === undefined) k2 = k;
|
|
35
|
+
o[k2] = m[k];
|
|
36
|
+
}));
|
|
37
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
38
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
39
|
+
}) : function(o, v) {
|
|
40
|
+
o["default"] = v;
|
|
41
|
+
});
|
|
42
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
43
|
+
var ownKeys = function(o) {
|
|
44
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
45
|
+
var ar = [];
|
|
46
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
47
|
+
return ar;
|
|
48
|
+
};
|
|
49
|
+
return ownKeys(o);
|
|
50
|
+
};
|
|
51
|
+
return function (mod) {
|
|
52
|
+
if (mod && mod.__esModule) return mod;
|
|
53
|
+
var result = {};
|
|
54
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
55
|
+
__setModuleDefault(result, mod);
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
58
|
+
})();
|
|
59
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
|
+
exports.KMWIMemory = void 0;
|
|
61
|
+
const fs = __importStar(require("fs"));
|
|
62
|
+
const path = __importStar(require("path"));
|
|
63
|
+
// ============================================================================
|
|
64
|
+
// KMWI 四层记忆管理器
|
|
65
|
+
// ============================================================================
|
|
66
|
+
/**
|
|
67
|
+
* KMWI 四层记忆管理器
|
|
68
|
+
*
|
|
69
|
+
* 实现四层递进结构与双向流动:
|
|
70
|
+
* - 转化流(自下而上):K → M → W → I
|
|
71
|
+
* - 反哺流(自上而下):I → W → M → K
|
|
72
|
+
*
|
|
73
|
+
* 持久化到 JSON 文件,支持跨会话恢复。
|
|
74
|
+
*/
|
|
75
|
+
class KMWIMemory {
|
|
76
|
+
constructor(filePath) {
|
|
77
|
+
this.knowledge = new Map();
|
|
78
|
+
this.memories = new Map();
|
|
79
|
+
this.wisdom = new Map();
|
|
80
|
+
this.intuitions = new Map();
|
|
81
|
+
this.history = [];
|
|
82
|
+
this.baseline = null;
|
|
83
|
+
this.maxHistorySize = 200;
|
|
84
|
+
this.maxItemsPerLayer = 5000;
|
|
85
|
+
this.promotionCooldown = new Map();
|
|
86
|
+
this.filePath = filePath || path.join(process.cwd(), '.metago-kmwi.json');
|
|
87
|
+
this.load();
|
|
88
|
+
}
|
|
89
|
+
// ============================================================================
|
|
90
|
+
// 持久化
|
|
91
|
+
// ============================================================================
|
|
92
|
+
load() {
|
|
93
|
+
if (!fs.existsSync(this.filePath))
|
|
94
|
+
return;
|
|
95
|
+
try {
|
|
96
|
+
const content = fs.readFileSync(this.filePath, 'utf-8');
|
|
97
|
+
const snapshot = JSON.parse(content);
|
|
98
|
+
for (const item of snapshot.knowledge || [])
|
|
99
|
+
this.knowledge.set(item.id, item);
|
|
100
|
+
for (const item of snapshot.memories || [])
|
|
101
|
+
this.memories.set(item.id, item);
|
|
102
|
+
for (const item of snapshot.wisdom || [])
|
|
103
|
+
this.wisdom.set(item.id, item);
|
|
104
|
+
for (const item of snapshot.intuitions || [])
|
|
105
|
+
this.intuitions.set(item.id, item);
|
|
106
|
+
this.history = snapshot.history || [];
|
|
107
|
+
this.baseline = snapshot.baseline || null;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// 损坏的快照视为空记忆,不阻塞主流程
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
save() {
|
|
114
|
+
try {
|
|
115
|
+
const snapshot = {
|
|
116
|
+
version: '1.0.0',
|
|
117
|
+
timestamp: new Date().toISOString(),
|
|
118
|
+
knowledge: Array.from(this.knowledge.values()),
|
|
119
|
+
memories: Array.from(this.memories.values()),
|
|
120
|
+
wisdom: Array.from(this.wisdom.values()),
|
|
121
|
+
intuitions: Array.from(this.intuitions.values()),
|
|
122
|
+
history: this.history,
|
|
123
|
+
baseline: this.baseline || this.createBaseline(),
|
|
124
|
+
};
|
|
125
|
+
fs.writeFileSync(this.filePath, JSON.stringify(snapshot, null, 2), 'utf-8');
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
// 持久化失败不阻塞主流程
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
createBaseline() {
|
|
132
|
+
const stats = this.computeStats();
|
|
133
|
+
return {
|
|
134
|
+
K: stats.K,
|
|
135
|
+
M: stats.M,
|
|
136
|
+
W: stats.W,
|
|
137
|
+
I: stats.I,
|
|
138
|
+
H: stats.H,
|
|
139
|
+
recordedAt: new Date().toISOString(),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
// ============================================================================
|
|
143
|
+
// 写入 - 四层各自入口
|
|
144
|
+
// ============================================================================
|
|
145
|
+
addKnowledge(content, category, tags = [], source = 'external') {
|
|
146
|
+
const id = `K-${Date.now()}-${Math.random().toString(36).substring(2, 6)}`;
|
|
147
|
+
const now = new Date().toISOString();
|
|
148
|
+
const item = {
|
|
149
|
+
id,
|
|
150
|
+
content,
|
|
151
|
+
category,
|
|
152
|
+
tags,
|
|
153
|
+
source,
|
|
154
|
+
confidence: 0.8,
|
|
155
|
+
createdAt: now,
|
|
156
|
+
lastAccessedAt: now,
|
|
157
|
+
accessCount: 0,
|
|
158
|
+
linkedMemoryIds: [],
|
|
159
|
+
};
|
|
160
|
+
this.knowledge.set(id, item);
|
|
161
|
+
this.enforceLayerLimit('K');
|
|
162
|
+
this.recordHistory(`Added knowledge: ${content.substring(0, 60)}`);
|
|
163
|
+
this.save();
|
|
164
|
+
return id;
|
|
165
|
+
}
|
|
166
|
+
addMemory(content, context, tags = [], source = 'experience') {
|
|
167
|
+
const id = `M-${Date.now()}-${Math.random().toString(36).substring(2, 6)}`;
|
|
168
|
+
const now = new Date().toISOString();
|
|
169
|
+
const item = {
|
|
170
|
+
id,
|
|
171
|
+
content,
|
|
172
|
+
context,
|
|
173
|
+
type: 'short_term',
|
|
174
|
+
tags,
|
|
175
|
+
source,
|
|
176
|
+
createdAt: now,
|
|
177
|
+
lastAccessedAt: now,
|
|
178
|
+
accessCount: 0,
|
|
179
|
+
recallStrength: 0.5,
|
|
180
|
+
linkedWisdomIds: [],
|
|
181
|
+
};
|
|
182
|
+
this.memories.set(id, item);
|
|
183
|
+
this.enforceLayerLimit('M');
|
|
184
|
+
this.recordHistory(`Added memory: ${content.substring(0, 60)}`);
|
|
185
|
+
this.save();
|
|
186
|
+
return id;
|
|
187
|
+
}
|
|
188
|
+
addWisdom(pattern, description, causeEffect, tags = [], source = 'synthesis') {
|
|
189
|
+
const id = `W-${Date.now()}-${Math.random().toString(36).substring(2, 6)}`;
|
|
190
|
+
const now = new Date().toISOString();
|
|
191
|
+
const item = {
|
|
192
|
+
id,
|
|
193
|
+
pattern,
|
|
194
|
+
description,
|
|
195
|
+
causeEffect,
|
|
196
|
+
applicability: 'general',
|
|
197
|
+
antiPattern: false,
|
|
198
|
+
tags,
|
|
199
|
+
source,
|
|
200
|
+
usageCount: 0,
|
|
201
|
+
successRate: 0.5,
|
|
202
|
+
createdAt: now,
|
|
203
|
+
lastAppliedAt: now,
|
|
204
|
+
linkedIntuitionIds: [],
|
|
205
|
+
};
|
|
206
|
+
this.wisdom.set(id, item);
|
|
207
|
+
this.enforceLayerLimit('W');
|
|
208
|
+
this.recordHistory(`Added wisdom: ${pattern.substring(0, 60)}`);
|
|
209
|
+
this.save();
|
|
210
|
+
return id;
|
|
211
|
+
}
|
|
212
|
+
addIntuition(insight, implicitKnowledge, tags = [], source = 'internalization') {
|
|
213
|
+
const id = `I-${Date.now()}-${Math.random().toString(36).substring(2, 6)}`;
|
|
214
|
+
const now = new Date().toISOString();
|
|
215
|
+
const item = {
|
|
216
|
+
id,
|
|
217
|
+
insight,
|
|
218
|
+
implicitKnowledge,
|
|
219
|
+
explicitForm: '',
|
|
220
|
+
failureScenarios: [],
|
|
221
|
+
accuracy: 0.5,
|
|
222
|
+
tags,
|
|
223
|
+
source,
|
|
224
|
+
createdAt: now,
|
|
225
|
+
lastValidatedAt: now,
|
|
226
|
+
validationCount: 0,
|
|
227
|
+
};
|
|
228
|
+
this.intuitions.set(id, item);
|
|
229
|
+
this.enforceLayerLimit('I');
|
|
230
|
+
this.recordHistory(`Added intuition: ${insight.substring(0, 60)}`);
|
|
231
|
+
this.save();
|
|
232
|
+
return id;
|
|
233
|
+
}
|
|
234
|
+
// ============================================================================
|
|
235
|
+
// 转化流(自下而上):K → M → W → I
|
|
236
|
+
// ============================================================================
|
|
237
|
+
/**
|
|
238
|
+
* K → M:知识转化为记忆
|
|
239
|
+
* 当一条知识被反复访问、应用到实践中,就转化为经验性记忆
|
|
240
|
+
*/
|
|
241
|
+
promoteToMemory(knowledgeId) {
|
|
242
|
+
const kItem = this.knowledge.get(knowledgeId);
|
|
243
|
+
if (!kItem) {
|
|
244
|
+
return this.failedPromotion('K', 'M', knowledgeId, 'Knowledge item not found');
|
|
245
|
+
}
|
|
246
|
+
if (kItem.accessCount < 3) {
|
|
247
|
+
return this.failedPromotion('K', 'M', knowledgeId, `Access count too low (${kItem.accessCount}/3)`);
|
|
248
|
+
}
|
|
249
|
+
if (this.isOnCooldown(knowledgeId)) {
|
|
250
|
+
return this.failedPromotion('K', 'M', knowledgeId, 'On promotion cooldown');
|
|
251
|
+
}
|
|
252
|
+
const memoryId = this.addMemory(kItem.content, `Promoted from knowledge: ${kItem.category}`, kItem.tags, `promotion:K→M:${kItem.id}`);
|
|
253
|
+
const mItem = this.memories.get(memoryId);
|
|
254
|
+
mItem.type = 'long_term';
|
|
255
|
+
mItem.recallStrength = Math.min(1, 0.5 + kItem.accessCount * 0.1);
|
|
256
|
+
this.memories.set(memoryId, mItem);
|
|
257
|
+
kItem.linkedMemoryIds.push(memoryId);
|
|
258
|
+
this.knowledge.set(knowledgeId, kItem);
|
|
259
|
+
this.setCooldown(knowledgeId);
|
|
260
|
+
this.recordHistory(`Promoted K→M: ${kItem.content.substring(0, 40)}`);
|
|
261
|
+
this.save();
|
|
262
|
+
return {
|
|
263
|
+
success: true,
|
|
264
|
+
fromLayer: 'K',
|
|
265
|
+
toLayer: 'M',
|
|
266
|
+
sourceId: knowledgeId,
|
|
267
|
+
newId: memoryId,
|
|
268
|
+
reason: `Accessed ${kItem.accessCount} times, promoted to long-term memory`,
|
|
269
|
+
timestamp: new Date().toISOString(),
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* M → W:记忆提炼为智慧
|
|
274
|
+
* 当多条相关记忆积累到一定数量,系统从中提炼可复用的模式
|
|
275
|
+
*/
|
|
276
|
+
promoteToWisdom(memoryId) {
|
|
277
|
+
const mItem = this.memories.get(memoryId);
|
|
278
|
+
if (!mItem) {
|
|
279
|
+
return this.failedPromotion('M', 'W', memoryId, 'Memory item not found');
|
|
280
|
+
}
|
|
281
|
+
if (mItem.recallStrength < 0.7) {
|
|
282
|
+
return this.failedPromotion('M', 'W', memoryId, `Recall strength too low (${mItem.recallStrength.toFixed(2)}/0.70)`);
|
|
283
|
+
}
|
|
284
|
+
const relatedMemories = this.findRelatedMemories(mItem);
|
|
285
|
+
if (relatedMemories.length < 2) {
|
|
286
|
+
return this.failedPromotion('M', 'W', memoryId, `Not enough related memories (${relatedMemories.length}/2)`);
|
|
287
|
+
}
|
|
288
|
+
const pattern = this.synthesizePattern(mItem, relatedMemories);
|
|
289
|
+
const wisdomId = this.addWisdom(pattern, `Synthesized from ${relatedMemories.length + 1} memories`, `${mItem.context} + ${relatedMemories.length} related`, mItem.tags, `promotion:M→W:${mItem.id}`);
|
|
290
|
+
const wItem = this.wisdom.get(wisdomId);
|
|
291
|
+
wItem.successRate = Math.min(1, 0.5 + mItem.recallStrength * 0.3);
|
|
292
|
+
this.wisdom.set(wisdomId, wItem);
|
|
293
|
+
mItem.linkedWisdomIds.push(wisdomId);
|
|
294
|
+
this.memories.set(memoryId, mItem);
|
|
295
|
+
this.setCooldown(memoryId);
|
|
296
|
+
this.recordHistory(`Promoted M→W: pattern="${pattern.substring(0, 40)}"`);
|
|
297
|
+
this.save();
|
|
298
|
+
return {
|
|
299
|
+
success: true,
|
|
300
|
+
fromLayer: 'M',
|
|
301
|
+
toLayer: 'W',
|
|
302
|
+
sourceId: memoryId,
|
|
303
|
+
newId: wisdomId,
|
|
304
|
+
reason: `Synthesized from ${relatedMemories.length + 1} memories with recall strength ${mItem.recallStrength.toFixed(2)}`,
|
|
305
|
+
timestamp: new Date().toISOString(),
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* W → I:智慧内化为直觉
|
|
310
|
+
* 当一个模式被反复成功应用,且能被显性化表达,就内化为直觉
|
|
311
|
+
*/
|
|
312
|
+
promoteToIntuition(wisdomId) {
|
|
313
|
+
const wItem = this.wisdom.get(wisdomId);
|
|
314
|
+
if (!wItem) {
|
|
315
|
+
return this.failedPromotion('W', 'I', wisdomId, 'Wisdom item not found');
|
|
316
|
+
}
|
|
317
|
+
if (wItem.usageCount < 5) {
|
|
318
|
+
return this.failedPromotion('W', 'I', wisdomId, `Usage count too low (${wItem.usageCount}/5)`);
|
|
319
|
+
}
|
|
320
|
+
if (wItem.successRate < 0.8) {
|
|
321
|
+
return this.failedPromotion('W', 'I', wisdomId, `Success rate too low (${wItem.successRate.toFixed(2)}/0.80)`);
|
|
322
|
+
}
|
|
323
|
+
const intuitionId = this.addIntuition(wItem.pattern, wItem.description, wItem.tags, `promotion:W→I:${wItem.id}`);
|
|
324
|
+
const iItem = this.intuitions.get(intuitionId);
|
|
325
|
+
iItem.explicitForm = wItem.causeEffect;
|
|
326
|
+
iItem.accuracy = wItem.successRate;
|
|
327
|
+
iItem.failureScenarios = wItem.antiPattern ? [wItem.applicability] : [];
|
|
328
|
+
this.intuitions.set(intuitionId, iItem);
|
|
329
|
+
wItem.linkedIntuitionIds.push(intuitionId);
|
|
330
|
+
this.wisdom.set(wisdomId, wItem);
|
|
331
|
+
this.setCooldown(wisdomId);
|
|
332
|
+
this.recordHistory(`Promoted W→I: insight="${wItem.pattern.substring(0, 40)}"`);
|
|
333
|
+
this.save();
|
|
334
|
+
return {
|
|
335
|
+
success: true,
|
|
336
|
+
fromLayer: 'W',
|
|
337
|
+
toLayer: 'I',
|
|
338
|
+
sourceId: wisdomId,
|
|
339
|
+
newId: intuitionId,
|
|
340
|
+
reason: `Applied ${wItem.usageCount} times with ${(wItem.successRate * 100).toFixed(0)}% success rate`,
|
|
341
|
+
timestamp: new Date().toISOString(),
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
// ============================================================================
|
|
345
|
+
// 反哺流(自上而下):I → W → M → K
|
|
346
|
+
// ============================================================================
|
|
347
|
+
/**
|
|
348
|
+
* I → W:直觉反哺智慧层
|
|
349
|
+
* 直觉被显性化后,可以更新或创建新的智慧模式
|
|
350
|
+
*/
|
|
351
|
+
feedbackToWisdom(intuitionId) {
|
|
352
|
+
const iItem = this.intuitions.get(intuitionId);
|
|
353
|
+
if (!iItem) {
|
|
354
|
+
return this.failedPromotion('I', 'W', intuitionId, 'Intuition item not found');
|
|
355
|
+
}
|
|
356
|
+
if (iItem.validationCount < 3) {
|
|
357
|
+
return this.failedPromotion('I', 'W', intuitionId, `Validation count too low (${iItem.validationCount}/3)`);
|
|
358
|
+
}
|
|
359
|
+
const wisdomId = this.addWisdom(`Refined: ${iItem.insight}`, `Feedback from intuition: ${iItem.explicitForm}`, iItem.implicitKnowledge, iItem.tags, `feedback:I→W:${iItem.id}`);
|
|
360
|
+
this.recordHistory(`Feedback I→W: ${iItem.insight.substring(0, 40)}`);
|
|
361
|
+
this.save();
|
|
362
|
+
return {
|
|
363
|
+
success: true,
|
|
364
|
+
fromLayer: 'I',
|
|
365
|
+
toLayer: 'W',
|
|
366
|
+
sourceId: intuitionId,
|
|
367
|
+
newId: wisdomId,
|
|
368
|
+
reason: `Validated ${iItem.validationCount} times with ${(iItem.accuracy * 100).toFixed(0)}% accuracy`,
|
|
369
|
+
timestamp: new Date().toISOString(),
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* W → M:智慧反哺记忆层
|
|
374
|
+
* 智慧模式可以生成新的记忆条目,指导未来的记忆存储
|
|
375
|
+
*/
|
|
376
|
+
feedbackToMemory(wisdomId) {
|
|
377
|
+
const wItem = this.wisdom.get(wisdomId);
|
|
378
|
+
if (!wItem) {
|
|
379
|
+
return this.failedPromotion('W', 'M', wisdomId, 'Wisdom item not found');
|
|
380
|
+
}
|
|
381
|
+
const memoryId = this.addMemory(`Pattern: ${wItem.pattern}`, `Feedback from wisdom: ${wItem.description}`, wItem.tags, `feedback:W→M:${wItem.id}`);
|
|
382
|
+
this.recordHistory(`Feedback W→M: ${wItem.pattern.substring(0, 40)}`);
|
|
383
|
+
this.save();
|
|
384
|
+
return {
|
|
385
|
+
success: true,
|
|
386
|
+
fromLayer: 'W',
|
|
387
|
+
toLayer: 'M',
|
|
388
|
+
sourceId: wisdomId,
|
|
389
|
+
newId: memoryId,
|
|
390
|
+
reason: 'Wisdom pattern converted to memory for future reference',
|
|
391
|
+
timestamp: new Date().toISOString(),
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* M → K:记忆反哺知识层
|
|
396
|
+
* 长期记忆中的稳定事实可以沉淀为知识
|
|
397
|
+
*/
|
|
398
|
+
feedbackToKnowledge(memoryId) {
|
|
399
|
+
const mItem = this.memories.get(memoryId);
|
|
400
|
+
if (!mItem) {
|
|
401
|
+
return this.failedPromotion('M', 'K', memoryId, 'Memory item not found');
|
|
402
|
+
}
|
|
403
|
+
if (mItem.type !== 'long_term' || mItem.recallStrength < 0.9) {
|
|
404
|
+
return this.failedPromotion('M', 'K', memoryId, 'Memory not stable enough for knowledge');
|
|
405
|
+
}
|
|
406
|
+
const knowledgeId = this.addKnowledge(mItem.content, 'crystallized', mItem.tags, `feedback:M→K:${mItem.id}`);
|
|
407
|
+
const kItem = this.knowledge.get(knowledgeId);
|
|
408
|
+
kItem.confidence = mItem.recallStrength;
|
|
409
|
+
this.knowledge.set(knowledgeId, kItem);
|
|
410
|
+
this.recordHistory(`Feedback M→K: ${mItem.content.substring(0, 40)}`);
|
|
411
|
+
this.save();
|
|
412
|
+
return {
|
|
413
|
+
success: true,
|
|
414
|
+
fromLayer: 'M',
|
|
415
|
+
toLayer: 'K',
|
|
416
|
+
sourceId: memoryId,
|
|
417
|
+
newId: knowledgeId,
|
|
418
|
+
reason: `Long-term memory with ${(mItem.recallStrength * 100).toFixed(0)}% recall strength crystallized to knowledge`,
|
|
419
|
+
timestamp: new Date().toISOString(),
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
// ============================================================================
|
|
423
|
+
// 查询与访问
|
|
424
|
+
// ============================================================================
|
|
425
|
+
query(layer, filter) {
|
|
426
|
+
let items;
|
|
427
|
+
switch (layer) {
|
|
428
|
+
case 'K':
|
|
429
|
+
items = Array.from(this.knowledge.values());
|
|
430
|
+
break;
|
|
431
|
+
case 'M':
|
|
432
|
+
items = Array.from(this.memories.values());
|
|
433
|
+
break;
|
|
434
|
+
case 'W':
|
|
435
|
+
items = Array.from(this.wisdom.values());
|
|
436
|
+
break;
|
|
437
|
+
case 'I':
|
|
438
|
+
items = Array.from(this.intuitions.values());
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
if (filter?.tags && filter.tags.length > 0) {
|
|
442
|
+
items = items.filter(item => {
|
|
443
|
+
const tags = item.tags || [];
|
|
444
|
+
return filter.tags.some(t => tags.includes(t));
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
if (filter?.category && layer === 'K') {
|
|
448
|
+
items = items.filter(item => item.category === filter.category);
|
|
449
|
+
}
|
|
450
|
+
if (filter?.keyword) {
|
|
451
|
+
const kw = filter.keyword.toLowerCase();
|
|
452
|
+
items = items.filter(item => {
|
|
453
|
+
const content = item.content || item.pattern || item.insight || '';
|
|
454
|
+
return content.toLowerCase().includes(kw);
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
if (filter?.limit && filter.limit > 0) {
|
|
458
|
+
items = items.slice(0, filter.limit);
|
|
459
|
+
}
|
|
460
|
+
// 更新访问计数与时间
|
|
461
|
+
const now = new Date().toISOString();
|
|
462
|
+
for (const item of items) {
|
|
463
|
+
item.accessCount = (item.accessCount || 0) + 1;
|
|
464
|
+
item.lastAccessedAt = now;
|
|
465
|
+
}
|
|
466
|
+
return items;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* 访问某条记忆(更新访问计数,用于转化流判定)
|
|
470
|
+
*/
|
|
471
|
+
access(layer, id) {
|
|
472
|
+
let item = null;
|
|
473
|
+
switch (layer) {
|
|
474
|
+
case 'K':
|
|
475
|
+
item = this.knowledge.get(id) || null;
|
|
476
|
+
break;
|
|
477
|
+
case 'M':
|
|
478
|
+
item = this.memories.get(id) || null;
|
|
479
|
+
break;
|
|
480
|
+
case 'W':
|
|
481
|
+
item = this.wisdom.get(id) || null;
|
|
482
|
+
break;
|
|
483
|
+
case 'I':
|
|
484
|
+
item = this.intuitions.get(id) || null;
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
if (!item)
|
|
488
|
+
return null;
|
|
489
|
+
const now = new Date().toISOString();
|
|
490
|
+
item.accessCount = (item.accessCount || 0) + 1;
|
|
491
|
+
item.lastAccessedAt = now;
|
|
492
|
+
switch (layer) {
|
|
493
|
+
case 'K':
|
|
494
|
+
this.knowledge.set(id, item);
|
|
495
|
+
break;
|
|
496
|
+
case 'M':
|
|
497
|
+
this.memories.set(id, item);
|
|
498
|
+
break;
|
|
499
|
+
case 'W':
|
|
500
|
+
this.wisdom.set(id, item);
|
|
501
|
+
break;
|
|
502
|
+
case 'I':
|
|
503
|
+
this.intuitions.set(id, item);
|
|
504
|
+
break;
|
|
505
|
+
}
|
|
506
|
+
this.save();
|
|
507
|
+
return item;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* 应用一个智慧模式(增加使用计数,用于转化流判定)
|
|
511
|
+
*/
|
|
512
|
+
applyWisdom(wisdomId, success) {
|
|
513
|
+
const item = this.wisdom.get(wisdomId);
|
|
514
|
+
if (!item)
|
|
515
|
+
return;
|
|
516
|
+
item.usageCount++;
|
|
517
|
+
const prevSuccess = item.successRate * (item.usageCount - 1);
|
|
518
|
+
item.successRate = (prevSuccess + (success ? 1 : 0)) / item.usageCount;
|
|
519
|
+
item.lastAppliedAt = new Date().toISOString();
|
|
520
|
+
this.wisdom.set(wisdomId, item);
|
|
521
|
+
this.save();
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* 验证一个直觉(增加验证计数,用于反哺流判定)
|
|
525
|
+
*/
|
|
526
|
+
validateIntuition(intuitionId, accurate) {
|
|
527
|
+
const item = this.intuitions.get(intuitionId);
|
|
528
|
+
if (!item)
|
|
529
|
+
return;
|
|
530
|
+
item.validationCount++;
|
|
531
|
+
const prevAccuracy = item.accuracy * (item.validationCount - 1);
|
|
532
|
+
item.accuracy = (prevAccuracy + (accurate ? 1 : 0)) / item.validationCount;
|
|
533
|
+
item.lastValidatedAt = new Date().toISOString();
|
|
534
|
+
this.intuitions.set(intuitionId, item);
|
|
535
|
+
this.save();
|
|
536
|
+
}
|
|
537
|
+
// ============================================================================
|
|
538
|
+
// 健康度评估
|
|
539
|
+
// ============================================================================
|
|
540
|
+
getHealth() {
|
|
541
|
+
const stats = this.computeStats();
|
|
542
|
+
return stats;
|
|
543
|
+
}
|
|
544
|
+
computeStats() {
|
|
545
|
+
const kStats = this.computeLayerStats('K');
|
|
546
|
+
const mStats = this.computeLayerStats('M');
|
|
547
|
+
const wStats = this.computeLayerStats('W');
|
|
548
|
+
const iStats = this.computeLayerStats('I');
|
|
549
|
+
// K 层健康度:知识覆盖度 × 知识时效性
|
|
550
|
+
const kFreshness = this.computeFreshness('K');
|
|
551
|
+
const K = kStats.total === 0 ? 0 : Math.round(kStats.avgConfidence * 50 + kFreshness * 50);
|
|
552
|
+
// M 层健康度:转化率 × 召回准确率
|
|
553
|
+
const M = mStats.total === 0 ? 0 : Math.round(this.computeConversionRate('M') * 50 + mStats.avgRecallStrength * 50);
|
|
554
|
+
// W 层健康度:模式数量 × 模式复用率
|
|
555
|
+
const W = wStats.total === 0 ? 0 : Math.round(Math.min(100, wStats.total * 2) * 0.5 + wStats.avgSuccessRate * 50);
|
|
556
|
+
// I 层健康度:直觉准确率 × 显性化程度
|
|
557
|
+
const explicitRatio = this.computeExplicitRatio();
|
|
558
|
+
const I = iStats.total === 0 ? 0 : Math.round(iStats.avgAccuracy * 50 + explicitRatio * 50);
|
|
559
|
+
// 综合健康度:H = (K + M + W + I) / 4
|
|
560
|
+
const H = Math.round((K + M + W + I) / 4);
|
|
561
|
+
return {
|
|
562
|
+
K: Math.min(100, Math.max(0, K)),
|
|
563
|
+
M: Math.min(100, Math.max(0, M)),
|
|
564
|
+
W: Math.min(100, Math.max(0, W)),
|
|
565
|
+
I: Math.min(100, Math.max(0, I)),
|
|
566
|
+
H: Math.min(100, Math.max(0, H)),
|
|
567
|
+
details: { K: kStats, M: mStats, W: wStats, I: iStats },
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
computeLayerStats(layer) {
|
|
571
|
+
let items;
|
|
572
|
+
switch (layer) {
|
|
573
|
+
case 'K':
|
|
574
|
+
items = Array.from(this.knowledge.values());
|
|
575
|
+
break;
|
|
576
|
+
case 'M':
|
|
577
|
+
items = Array.from(this.memories.values());
|
|
578
|
+
break;
|
|
579
|
+
case 'W':
|
|
580
|
+
items = Array.from(this.wisdom.values());
|
|
581
|
+
break;
|
|
582
|
+
case 'I':
|
|
583
|
+
items = Array.from(this.intuitions.values());
|
|
584
|
+
break;
|
|
585
|
+
}
|
|
586
|
+
if (items.length === 0) {
|
|
587
|
+
return {
|
|
588
|
+
total: 0,
|
|
589
|
+
avgConfidence: 0,
|
|
590
|
+
avgRecallStrength: 0,
|
|
591
|
+
avgSuccessRate: 0,
|
|
592
|
+
avgAccuracy: 0,
|
|
593
|
+
categories: 0,
|
|
594
|
+
lastUpdated: new Date().toISOString(),
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
const categories = new Set();
|
|
598
|
+
let confidenceSum = 0, recallSum = 0, successSum = 0, accuracySum = 0;
|
|
599
|
+
let lastUpdated = '';
|
|
600
|
+
for (const item of items) {
|
|
601
|
+
if (layer === 'K') {
|
|
602
|
+
confidenceSum += item.confidence || 0;
|
|
603
|
+
categories.add(item.category);
|
|
604
|
+
}
|
|
605
|
+
else if (layer === 'M') {
|
|
606
|
+
recallSum += item.recallStrength || 0;
|
|
607
|
+
}
|
|
608
|
+
else if (layer === 'W') {
|
|
609
|
+
successSum += item.successRate || 0;
|
|
610
|
+
}
|
|
611
|
+
else if (layer === 'I') {
|
|
612
|
+
accuracySum += item.accuracy || 0;
|
|
613
|
+
}
|
|
614
|
+
const ts = item.lastAccessedAt || item.lastAppliedAt || item.lastValidatedAt || item.createdAt;
|
|
615
|
+
if (ts > lastUpdated)
|
|
616
|
+
lastUpdated = ts;
|
|
617
|
+
}
|
|
618
|
+
return {
|
|
619
|
+
total: items.length,
|
|
620
|
+
avgConfidence: layer === 'K' ? confidenceSum / items.length : 0,
|
|
621
|
+
avgRecallStrength: layer === 'M' ? recallSum / items.length : 0,
|
|
622
|
+
avgSuccessRate: layer === 'W' ? successSum / items.length : 0,
|
|
623
|
+
avgAccuracy: layer === 'I' ? accuracySum / items.length : 0,
|
|
624
|
+
categories: categories.size,
|
|
625
|
+
lastUpdated,
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
computeFreshness(layer) {
|
|
629
|
+
let items;
|
|
630
|
+
switch (layer) {
|
|
631
|
+
case 'K':
|
|
632
|
+
items = Array.from(this.knowledge.values());
|
|
633
|
+
break;
|
|
634
|
+
default: return 1;
|
|
635
|
+
}
|
|
636
|
+
if (items.length === 0)
|
|
637
|
+
return 1;
|
|
638
|
+
const now = Date.now();
|
|
639
|
+
const weekMs = 7 * 24 * 60 * 60 * 1000;
|
|
640
|
+
let freshCount = 0;
|
|
641
|
+
for (const item of items) {
|
|
642
|
+
const age = now - new Date(item.lastAccessedAt || item.createdAt).getTime();
|
|
643
|
+
if (age < weekMs * 4)
|
|
644
|
+
freshCount++; // 4周内视为新鲜
|
|
645
|
+
}
|
|
646
|
+
return freshCount / items.length;
|
|
647
|
+
}
|
|
648
|
+
computeConversionRate(layer) {
|
|
649
|
+
// M 层转化率:长期记忆 / 总记忆
|
|
650
|
+
if (layer !== 'M')
|
|
651
|
+
return 0.5;
|
|
652
|
+
const memories = Array.from(this.memories.values());
|
|
653
|
+
if (memories.length === 0)
|
|
654
|
+
return 0;
|
|
655
|
+
const longTerm = memories.filter(m => m.type === 'long_term').length;
|
|
656
|
+
return longTerm / memories.length;
|
|
657
|
+
}
|
|
658
|
+
computeExplicitRatio() {
|
|
659
|
+
const intuitions = Array.from(this.intuitions.values());
|
|
660
|
+
if (intuitions.length === 0)
|
|
661
|
+
return 0;
|
|
662
|
+
const explicit = intuitions.filter(i => i.explicitForm.length > 0).length;
|
|
663
|
+
return explicit / intuitions.length;
|
|
664
|
+
}
|
|
665
|
+
// ============================================================================
|
|
666
|
+
// 衰减检测
|
|
667
|
+
// ============================================================================
|
|
668
|
+
getDecayRates() {
|
|
669
|
+
if (!this.baseline) {
|
|
670
|
+
this.baseline = this.createBaseline();
|
|
671
|
+
}
|
|
672
|
+
const current = this.computeStats();
|
|
673
|
+
const baseline = this.baseline;
|
|
674
|
+
// R = (历史值 - 当前值) / 历史值 × 100%
|
|
675
|
+
const computeDecay = (current, baseline) => {
|
|
676
|
+
if (baseline === 0)
|
|
677
|
+
return current === 0 ? 0 : 100;
|
|
678
|
+
return Math.round(((baseline - current) / baseline) * 100);
|
|
679
|
+
};
|
|
680
|
+
const K = Math.max(0, computeDecay(current.K, baseline.K));
|
|
681
|
+
const M = Math.max(0, computeDecay(current.M, baseline.M));
|
|
682
|
+
const W = Math.max(0, computeDecay(current.W, baseline.W));
|
|
683
|
+
const I = Math.max(0, computeDecay(current.I, baseline.I));
|
|
684
|
+
const overall = Math.max(0, computeDecay(current.H, baseline.H));
|
|
685
|
+
const needsAttention = [];
|
|
686
|
+
if (K > 20)
|
|
687
|
+
needsAttention.push('K'); // 知识过时率 >20%
|
|
688
|
+
if (M > 30)
|
|
689
|
+
needsAttention.push('M'); // 长期记忆遗忘率 >30%
|
|
690
|
+
if (W > 15)
|
|
691
|
+
needsAttention.push('W'); // 模式失效率 >15%
|
|
692
|
+
if (I > 25)
|
|
693
|
+
needsAttention.push('I'); // 直觉钝化率 >25%
|
|
694
|
+
return { K, M, W, I, overall, needsAttention };
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* 更新基线(建议在每次重要进化后调用)
|
|
698
|
+
*/
|
|
699
|
+
refreshBaseline() {
|
|
700
|
+
this.baseline = this.createBaseline();
|
|
701
|
+
this.save();
|
|
702
|
+
}
|
|
703
|
+
// ============================================================================
|
|
704
|
+
// 强化建议
|
|
705
|
+
// ============================================================================
|
|
706
|
+
getStrengthenSuggestions() {
|
|
707
|
+
const suggestions = [];
|
|
708
|
+
const stats = this.computeStats();
|
|
709
|
+
const decay = this.getDecayRates();
|
|
710
|
+
if (decay.K > 20) {
|
|
711
|
+
suggestions.push({
|
|
712
|
+
layer: 'K',
|
|
713
|
+
action: `知识层衰减 ${decay.K}%,需要补充新知识或更新过时知识(当前 ${stats.details.K.total} 条)`,
|
|
714
|
+
priority: 'high',
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
if (decay.M > 30) {
|
|
718
|
+
suggestions.push({
|
|
719
|
+
layer: 'M',
|
|
720
|
+
action: `记忆层衰减 ${decay.M}%,需要强化长期记忆转化(当前转化率 ${Math.round(this.computeConversionRate('M') * 100)}%)`,
|
|
721
|
+
priority: 'high',
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
if (stats.details.W.total < 10) {
|
|
725
|
+
suggestions.push({
|
|
726
|
+
layer: 'W',
|
|
727
|
+
action: `智慧层条目过少(${stats.details.W.total} 条),需要从记忆层提炼更多模式`,
|
|
728
|
+
priority: 'medium',
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
if (decay.I > 25) {
|
|
732
|
+
suggestions.push({
|
|
733
|
+
layer: 'I',
|
|
734
|
+
action: `直觉层钝化 ${decay.I}%,需要通过场景验证重新激活直觉判断`,
|
|
735
|
+
priority: 'high',
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
if (stats.H < 60) {
|
|
739
|
+
suggestions.push({
|
|
740
|
+
layer: 'K',
|
|
741
|
+
action: `综合健康度 ${stats.H}/100,建议全层强化`,
|
|
742
|
+
priority: 'high',
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
return suggestions;
|
|
746
|
+
}
|
|
747
|
+
// ============================================================================
|
|
748
|
+
// 私有辅助方法
|
|
749
|
+
// ============================================================================
|
|
750
|
+
findRelatedMemories(memory) {
|
|
751
|
+
const all = Array.from(this.memories.values());
|
|
752
|
+
return all
|
|
753
|
+
.filter(m => m.id !== memory.id)
|
|
754
|
+
.filter(m => {
|
|
755
|
+
const sharedTags = m.tags.filter(t => memory.tags.includes(t));
|
|
756
|
+
return sharedTags.length > 0;
|
|
757
|
+
})
|
|
758
|
+
.sort((a, b) => {
|
|
759
|
+
const aShared = a.tags.filter(t => memory.tags.includes(t)).length;
|
|
760
|
+
const bShared = b.tags.filter(t => memory.tags.includes(t)).length;
|
|
761
|
+
return bShared - aShared;
|
|
762
|
+
})
|
|
763
|
+
.slice(0, 5);
|
|
764
|
+
}
|
|
765
|
+
synthesizePattern(primary, related) {
|
|
766
|
+
const allTags = new Set();
|
|
767
|
+
primary.tags.forEach(t => allTags.add(t));
|
|
768
|
+
related.forEach(m => m.tags.forEach(t => allTags.add(t)));
|
|
769
|
+
const tagStr = Array.from(allTags).slice(0, 3).join(' · ');
|
|
770
|
+
return `[${tagStr}] ${primary.content.substring(0, 50)} (+${related.length} related)`;
|
|
771
|
+
}
|
|
772
|
+
enforceLayerLimit(layer) {
|
|
773
|
+
const maxItems = this.maxItemsPerLayer;
|
|
774
|
+
let map;
|
|
775
|
+
switch (layer) {
|
|
776
|
+
case 'K':
|
|
777
|
+
map = this.knowledge;
|
|
778
|
+
break;
|
|
779
|
+
case 'M':
|
|
780
|
+
map = this.memories;
|
|
781
|
+
break;
|
|
782
|
+
case 'W':
|
|
783
|
+
map = this.wisdom;
|
|
784
|
+
break;
|
|
785
|
+
case 'I':
|
|
786
|
+
map = this.intuitions;
|
|
787
|
+
break;
|
|
788
|
+
}
|
|
789
|
+
if (map.size > maxItems) {
|
|
790
|
+
// 移除最旧的条目(按 createdAt 排序)
|
|
791
|
+
const sorted = Array.from(map.entries()).sort((a, b) => {
|
|
792
|
+
const aTime = new Date(a[1].createdAt).getTime();
|
|
793
|
+
const bTime = new Date(b[1].createdAt).getTime();
|
|
794
|
+
return aTime - bTime;
|
|
795
|
+
});
|
|
796
|
+
const toRemove = sorted.slice(0, map.size - maxItems);
|
|
797
|
+
for (const [id] of toRemove)
|
|
798
|
+
map.delete(id);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
recordHistory(action) {
|
|
802
|
+
const stats = this.computeStats();
|
|
803
|
+
this.history.push({
|
|
804
|
+
timestamp: new Date().toISOString(),
|
|
805
|
+
stats: { K: stats.K, M: stats.M, W: stats.W, I: stats.I, H: stats.H },
|
|
806
|
+
action,
|
|
807
|
+
});
|
|
808
|
+
if (this.history.length > this.maxHistorySize) {
|
|
809
|
+
this.history = this.history.slice(-this.maxHistorySize);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
isOnCooldown(id) {
|
|
813
|
+
const last = this.promotionCooldown.get(id);
|
|
814
|
+
if (!last)
|
|
815
|
+
return false;
|
|
816
|
+
// 1 小时冷却
|
|
817
|
+
return Date.now() - last < 60 * 60 * 1000;
|
|
818
|
+
}
|
|
819
|
+
setCooldown(id) {
|
|
820
|
+
this.promotionCooldown.set(id, Date.now());
|
|
821
|
+
}
|
|
822
|
+
failedPromotion(from, to, sourceId, reason) {
|
|
823
|
+
return {
|
|
824
|
+
success: false,
|
|
825
|
+
fromLayer: from,
|
|
826
|
+
toLayer: to,
|
|
827
|
+
sourceId,
|
|
828
|
+
newId: '',
|
|
829
|
+
reason,
|
|
830
|
+
timestamp: new Date().toISOString(),
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
// ============================================================================
|
|
834
|
+
// 导出与统计
|
|
835
|
+
// ============================================================================
|
|
836
|
+
getHistory() {
|
|
837
|
+
return this.history;
|
|
838
|
+
}
|
|
839
|
+
getSummary() {
|
|
840
|
+
const stats = this.computeStats();
|
|
841
|
+
const decay = this.getDecayRates();
|
|
842
|
+
const lines = [
|
|
843
|
+
'【KMWI 记忆管理报告】',
|
|
844
|
+
`■ K 层知识:完备度=${stats.K} 条目数=${stats.details.K.total} 类别数=${stats.details.K.categories}`,
|
|
845
|
+
`■ M 层记忆:转化率=${Math.round(this.computeConversionRate('M') * 100)}% 召回强度=${stats.details.M.avgRecallStrength.toFixed(2)}`,
|
|
846
|
+
`■ W 层智慧:模式数=${stats.details.W.total} 复用率=${(stats.details.W.avgSuccessRate * 100).toFixed(0)}%`,
|
|
847
|
+
`■ I 层直觉:准确率=${(stats.details.I.avgAccuracy * 100).toFixed(0)}% 显性化=${(this.computeExplicitRatio() * 100).toFixed(0)}%`,
|
|
848
|
+
`■ 综合健康度:H = ${stats.H}`,
|
|
849
|
+
`■ 衰减检测:K=${decay.K}% M=${decay.M}% W=${decay.W}% I=${decay.I}%`,
|
|
850
|
+
];
|
|
851
|
+
if (decay.needsAttention.length > 0) {
|
|
852
|
+
lines.push(`■ 需关注:${decay.needsAttention.join(', ')}`);
|
|
853
|
+
}
|
|
854
|
+
const suggestions = this.getStrengthenSuggestions();
|
|
855
|
+
if (suggestions.length > 0) {
|
|
856
|
+
lines.push(`■ 强化建议:`);
|
|
857
|
+
for (const s of suggestions) {
|
|
858
|
+
lines.push(` [${s.priority}] ${s.layer} 层 - ${s.action}`);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
return lines.join('\n');
|
|
862
|
+
}
|
|
863
|
+
clear() {
|
|
864
|
+
this.knowledge.clear();
|
|
865
|
+
this.memories.clear();
|
|
866
|
+
this.wisdom.clear();
|
|
867
|
+
this.intuitions.clear();
|
|
868
|
+
this.history = [];
|
|
869
|
+
this.baseline = null;
|
|
870
|
+
this.save();
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* 获取用于元进化引擎的相关模式(从 W 层和 I 层提取)
|
|
874
|
+
* 这是 KMWI 与元进化引擎的耦合点
|
|
875
|
+
*/
|
|
876
|
+
extractPatternsForEvolution(domain, limit = 5) {
|
|
877
|
+
const domainLower = domain.toLowerCase();
|
|
878
|
+
const wisdom = Array.from(this.wisdom.values())
|
|
879
|
+
.filter(w => {
|
|
880
|
+
const text = `${w.pattern} ${w.description} ${w.tags.join(' ')}`.toLowerCase();
|
|
881
|
+
return text.includes(domainLower) || w.tags.some(t => t.toLowerCase().includes(domainLower));
|
|
882
|
+
})
|
|
883
|
+
.sort((a, b) => b.successRate * b.usageCount - a.successRate * a.usageCount)
|
|
884
|
+
.slice(0, limit);
|
|
885
|
+
const intuitions = Array.from(this.intuitions.values())
|
|
886
|
+
.filter(i => {
|
|
887
|
+
const text = `${i.insight} ${i.implicitKnowledge} ${i.tags.join(' ')}`.toLowerCase();
|
|
888
|
+
return text.includes(domainLower) || i.tags.some(t => t.toLowerCase().includes(domainLower));
|
|
889
|
+
})
|
|
890
|
+
.sort((a, b) => b.accuracy * b.validationCount - a.accuracy * a.validationCount)
|
|
891
|
+
.slice(0, limit);
|
|
892
|
+
return { wisdom, intuitions };
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
exports.KMWIMemory = KMWIMemory;
|
|
896
|
+
exports.default = KMWIMemory;
|
|
897
|
+
//# sourceMappingURL=kmwi-memory.js.map
|