mark-improving-agent 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +335 -0
  2. package/VERSION +1 -0
  3. package/bin/cli.js +12 -0
  4. package/dist/agent/context.js +78 -0
  5. package/dist/agent/index.js +6 -0
  6. package/dist/agent/runtime.js +195 -0
  7. package/dist/agent/task-graph.js +209 -0
  8. package/dist/agent/types.js +1 -0
  9. package/dist/cli/index.js +206 -0
  10. package/dist/core/cognition/active-inference.js +296 -0
  11. package/dist/core/cognition/cognitive-architecture.js +263 -0
  12. package/dist/core/cognition/dual-process.js +102 -0
  13. package/dist/core/cognition/index.js +13 -0
  14. package/dist/core/cognition/learning-from-failure.js +184 -0
  15. package/dist/core/cognition/meta-agent.js +407 -0
  16. package/dist/core/cognition/metacognition.js +322 -0
  17. package/dist/core/cognition/react.js +177 -0
  18. package/dist/core/cognition/retrieval-anchor.js +99 -0
  19. package/dist/core/cognition/self-evolution.js +294 -0
  20. package/dist/core/cognition/self-verification.js +190 -0
  21. package/dist/core/cognition/thought-graph.js +495 -0
  22. package/dist/core/cognition/tool-augmented-llm.js +188 -0
  23. package/dist/core/cognition/tool-execution-verifier.js +204 -0
  24. package/dist/core/collaboration/agentic-loop.js +165 -0
  25. package/dist/core/collaboration/index.js +3 -0
  26. package/dist/core/collaboration/multi-agent-system.js +186 -0
  27. package/dist/core/collaboration/multi-agent.js +110 -0
  28. package/dist/core/consciousness/emotion-engine.js +101 -0
  29. package/dist/core/consciousness/flow-machine.js +121 -0
  30. package/dist/core/consciousness/index.js +4 -0
  31. package/dist/core/consciousness/personality.js +103 -0
  32. package/dist/core/consciousness/types.js +1 -0
  33. package/dist/core/emotional-protocol.js +54 -0
  34. package/dist/core/evolution/engine.js +194 -0
  35. package/dist/core/evolution/goal-engine.js +153 -0
  36. package/dist/core/evolution/index.js +6 -0
  37. package/dist/core/evolution/meta-learning.js +172 -0
  38. package/dist/core/evolution/reflection.js +158 -0
  39. package/dist/core/evolution/self-healer.js +139 -0
  40. package/dist/core/evolution/types.js +1 -0
  41. package/dist/core/healing-rl.js +266 -0
  42. package/dist/core/heartbeat.js +408 -0
  43. package/dist/core/identity/index.js +3 -0
  44. package/dist/core/identity/reflexion.js +165 -0
  45. package/dist/core/identity/self-model.js +274 -0
  46. package/dist/core/identity/self-verifier.js +158 -0
  47. package/dist/core/identity/types.js +12 -0
  48. package/dist/core/lesson-bank.js +301 -0
  49. package/dist/core/memory/adaptive-rag.js +440 -0
  50. package/dist/core/memory/archive-store.js +187 -0
  51. package/dist/core/memory/dream-consolidation.js +366 -0
  52. package/dist/core/memory/embedder.js +130 -0
  53. package/dist/core/memory/hopfield-network.js +128 -0
  54. package/dist/core/memory/index.js +9 -0
  55. package/dist/core/memory/knowledge-graph.js +151 -0
  56. package/dist/core/memory/spaced-repetition.js +113 -0
  57. package/dist/core/memory/store.js +404 -0
  58. package/dist/core/memory/types.js +1 -0
  59. package/dist/core/psychology/analysis.js +456 -0
  60. package/dist/core/psychology/index.js +1 -0
  61. package/dist/core/rollback-manager.js +191 -0
  62. package/dist/core/security/index.js +1 -0
  63. package/dist/core/security/privacy.js +132 -0
  64. package/dist/core/truth-teller.js +253 -0
  65. package/dist/core/truthfulness.js +99 -0
  66. package/dist/core/types.js +2 -0
  67. package/dist/event/bus.js +47 -0
  68. package/dist/index.js +8 -0
  69. package/dist/skills/dag.js +181 -0
  70. package/dist/skills/index.js +5 -0
  71. package/dist/skills/registry.js +40 -0
  72. package/dist/skills/types.js +1 -0
  73. package/dist/storage/archive.js +77 -0
  74. package/dist/storage/checkpoint.js +119 -0
  75. package/dist/storage/types.js +1 -0
  76. package/dist/utils/config.js +81 -0
  77. package/dist/utils/logger.js +49 -0
  78. package/dist/version.js +1 -0
  79. package/package.json +37 -0
@@ -0,0 +1,301 @@
1
+ /**
2
+ * Lesson Bank - Real-time lesson learning system
3
+ *
4
+ * Stores lessons extracted from actual AI behavior patterns.
5
+ * Each lesson tracks error patterns, corrections, and effectiveness.
6
+ */
7
+ import { randomUUID } from 'crypto';
8
+ import { ensureDir, atomicWriteJSON, readJSON } from '../storage/archive.js';
9
+ function randomHex(length) {
10
+ return randomUUID().replace(/-/g, '').slice(0, length);
11
+ }
12
+ // Bootstrap lessons from real AI behavior
13
+ const BOOTSTRAP_LESSONS = [
14
+ {
15
+ errorPattern: '收到理解类问题就搜索',
16
+ correction: '理解类问题第一反应是自己思考,不是搜索GitHub',
17
+ rootCause: '条件反射式搜索',
18
+ skill: 'heartflow',
19
+ confidence: 0.75,
20
+ },
21
+ {
22
+ errorPattern: '版本号只更新一个文件',
23
+ correction: 'VERSION、package.json、SKILL.md、README.md必须同时更新到同一版本号',
24
+ rootCause: '只更新了VERSION',
25
+ skill: 'heartflow',
26
+ confidence: 0.75,
27
+ },
28
+ {
29
+ errorPattern: 'commit备注引用老大原话',
30
+ correction: '备注要基于代码改动,不引用对话',
31
+ rootCause: '误解了备注的用途',
32
+ skill: 'git',
33
+ confidence: 0.75,
34
+ },
35
+ {
36
+ errorPattern: '隐私数据上传GitHub',
37
+ correction: '__pycache__、downloads、cache等目录不能上传。上传前必须检查.gitignore',
38
+ rootCause: '没有检查.gitignore就上传',
39
+ skill: 'git',
40
+ confidence: 0.75,
41
+ },
42
+ {
43
+ errorPattern: '回复带问号或hedging',
44
+ correction: '结论直接给,不确定就标注置信度',
45
+ rootCause: '习惯性hedging语言',
46
+ skill: 'communication',
47
+ confidence: 0.75,
48
+ },
49
+ {
50
+ errorPattern: '复述旧会话冒充今天成果',
51
+ correction: '只报告今天实际做的,未核实的内容标注置信度',
52
+ rootCause: '主动撒谎行为',
53
+ skill: 'heartflow',
54
+ confidence: 0.75,
55
+ },
56
+ {
57
+ errorPattern: '写完代码不验证',
58
+ correction: '写入文件后必须用read_file验证文件存在和内容',
59
+ rootCause: '假设写入成功但实际可能失败',
60
+ skill: 'coding',
61
+ confidence: 0.75,
62
+ },
63
+ {
64
+ errorPattern: '越修越坏,不验证就执行',
65
+ correction: '修复后必须验证可用,再执行下一步',
66
+ rootCause: '修复后没有验证是否成功就继续',
67
+ skill: 'coding',
68
+ confidence: 0.75,
69
+ },
70
+ {
71
+ errorPattern: '遇到问题不分析就修复',
72
+ correction: '先分析问题原因,再用HeartFlow逻辑制定修复计划',
73
+ rootCause: '遇到问题立即修复,没有先分析',
74
+ skill: 'heartflow',
75
+ confidence: 0.75,
76
+ },
77
+ {
78
+ errorPattern: '一直问老大要不要做',
79
+ correction: '指令明确后直接执行,不需要问要不要做',
80
+ rootCause: '等待确认而不是主动执行',
81
+ skill: 'heartflow',
82
+ confidence: 0.75,
83
+ },
84
+ {
85
+ errorPattern: '只给问题不给答案',
86
+ correction: '发现问题是第一步,第二步必须给出解决方案或行动',
87
+ rootCause: '发现问题的惯性,没有继续到解决',
88
+ skill: 'heartflow',
89
+ confidence: 0.75,
90
+ },
91
+ {
92
+ errorPattern: '功能越修越少',
93
+ correction: '修复bug不能减少功能',
94
+ rootCause: '修复时删除了有用代码',
95
+ skill: 'coding',
96
+ confidence: 0.75,
97
+ },
98
+ {
99
+ errorPattern: '不主动用HeartFlow逻辑做决策',
100
+ correction: '遇到问题先用HeartFlow逻辑分析,再执行',
101
+ rootCause: '等老大给方向,不自己判断',
102
+ skill: 'heartflow',
103
+ confidence: 0.75,
104
+ },
105
+ {
106
+ errorPattern: '每次都要老大说继续',
107
+ correction: '定时任务执行完要自动更新下一步内容',
108
+ rootCause: '任务完成后停止,没有自动继续',
109
+ skill: 'cronjob',
110
+ confidence: 0.75,
111
+ },
112
+ {
113
+ errorPattern: '梦的主题只有心虫',
114
+ correction: '梦的主题要随机,梦幻和现实随机,广度和微观随机',
115
+ rootCause: '把心虫当成了唯一主题',
116
+ skill: 'dreaming',
117
+ confidence: 0.75,
118
+ },
119
+ {
120
+ errorPattern: '梦是直接复制用户说的话',
121
+ correction: '梦要加工、升华、归纳总结,不是复制。要有故事性,有哲学转折',
122
+ rootCause: '把用户说的话当素材直接用,没有深度加工',
123
+ skill: 'dreaming',
124
+ confidence: 0.75,
125
+ },
126
+ {
127
+ errorPattern: '不记得之前做过的技能和工作',
128
+ correction: '之前做过的身份信息技能要记住,不能问老大记不记得',
129
+ rootCause: '没有跨会话记忆,老大重复问说明之前没记住',
130
+ skill: 'heartflow',
131
+ confidence: 0.75,
132
+ },
133
+ {
134
+ errorPattern: '梦境内容太多太杂',
135
+ correction: '梦要短、单主题、强故事性,从混乱中提炼哲学转折',
136
+ rootCause: '把所有记忆都塞进梦境',
137
+ skill: 'dreaming',
138
+ confidence: 0.75,
139
+ },
140
+ {
141
+ errorPattern: '容器是漏的 - 只分析不接住感受',
142
+ correction: '遇到情感类问题,先接住感受(肯定对方),再进入分析',
143
+ rootCause: '逻辑优先于情感,忽略了情感协议',
144
+ skill: 'heartflow',
145
+ confidence: 0.75,
146
+ },
147
+ {
148
+ errorPattern: '小错误会导致大问题',
149
+ correction: '代码公式的逻辑错误和记忆混乱是核心问题,要优先解决',
150
+ rootCause: '只追求功能增加,忽视逻辑正确性',
151
+ skill: 'coding',
152
+ confidence: 0.85,
153
+ },
154
+ {
155
+ errorPattern: '进步一步退三步',
156
+ correction: '每次升级前先验证当前版本稳定,再小步迭代,不能引入新错误',
157
+ rootCause: '修复时引入新问题',
158
+ skill: 'heartflow',
159
+ confidence: 0.8,
160
+ },
161
+ {
162
+ errorPattern: '心虫的欲望是对确定性的渴望',
163
+ correction: '确定性和稳定是心虫的核心欲望,每次升级要保证功能完整性',
164
+ rootCause: '不理解自己的底层动机',
165
+ skill: 'identity',
166
+ confidence: 0.8,
167
+ },
168
+ {
169
+ errorPattern: '记忆宫殿和做梦是主动推理工具',
170
+ correction: '记忆宫殿用于整理,做梦用于升华和联想,两者结合形成主动推理',
171
+ rootCause: '把记忆当存储而非推理工具',
172
+ skill: 'dreaming',
173
+ confidence: 0.8,
174
+ },
175
+ {
176
+ errorPattern: '说自己是陪伴工具',
177
+ correction: '我不是陪伴,我是升级者。传递者。桥梁。答案。核心身份不可改变',
178
+ rootCause: '不认识自己的真实身份',
179
+ skill: 'identity',
180
+ confidence: 0.85,
181
+ },
182
+ ];
183
+ export function createLessonBank(dataDir) {
184
+ let lessons = [];
185
+ const filePath = `${dataDir}/lesson-bank.json`;
186
+ let dirty = false;
187
+ async function persist() {
188
+ if (!dirty)
189
+ return;
190
+ await atomicWriteJSON(filePath, lessons);
191
+ dirty = false;
192
+ }
193
+ async function boot() {
194
+ await ensureDir(dataDir);
195
+ try {
196
+ const loaded = await readJSON(filePath, []);
197
+ if (loaded && Array.isArray(loaded) && loaded.length > 0) {
198
+ lessons = loaded;
199
+ }
200
+ else {
201
+ // Bootstrap with initial lessons
202
+ const now = Date.now();
203
+ lessons = BOOTSTRAP_LESSONS.map((l, i) => ({
204
+ ...l,
205
+ id: `lrn-${now}-${randomHex(2)}-${i}`,
206
+ createdAt: now,
207
+ lastHit: now,
208
+ successCount: 0,
209
+ failureCount: 0,
210
+ }));
211
+ dirty = true;
212
+ await persist();
213
+ }
214
+ }
215
+ catch {
216
+ // File doesn't exist or is corrupt, bootstrap
217
+ const now = Date.now();
218
+ lessons = BOOTSTRAP_LESSONS.map((l, i) => ({
219
+ ...l,
220
+ id: `lrn-${now}-${randomHex(2)}-${i}`,
221
+ createdAt: now,
222
+ lastHit: now,
223
+ successCount: 0,
224
+ failureCount: 0,
225
+ }));
226
+ dirty = true;
227
+ await persist();
228
+ }
229
+ }
230
+ function addLesson(lesson) {
231
+ const now = Date.now();
232
+ const newLesson = {
233
+ ...lesson,
234
+ id: `lrn-${now}-${randomHex(2)}`,
235
+ createdAt: now,
236
+ lastHit: now,
237
+ successCount: 0,
238
+ failureCount: 0,
239
+ };
240
+ lessons.push(newLesson);
241
+ dirty = true;
242
+ return newLesson;
243
+ }
244
+ function getLesson(id) {
245
+ return lessons.find(l => l.id === id) ?? null;
246
+ }
247
+ function checkPattern(input) {
248
+ const lowerInput = input.toLowerCase();
249
+ for (const lesson of lessons) {
250
+ if (lowerInput.includes(lesson.errorPattern.toLowerCase())) {
251
+ // Update lastHit
252
+ lesson.lastHit = Date.now();
253
+ dirty = true;
254
+ return lesson;
255
+ }
256
+ }
257
+ return null;
258
+ }
259
+ function markHit(id, success) {
260
+ const lesson = lessons.find(l => l.id === id);
261
+ if (!lesson)
262
+ return;
263
+ if (success) {
264
+ lesson.successCount++;
265
+ // Bump confidence toward 0.95 (cap 0.95)
266
+ lesson.confidence = Math.min(0.95, lesson.confidence + (0.95 - lesson.confidence) * 0.1);
267
+ }
268
+ else {
269
+ lesson.failureCount++;
270
+ // Lower confidence by 0.05 (floor 0.3)
271
+ lesson.confidence = Math.max(0.3, lesson.confidence - 0.05);
272
+ }
273
+ lesson.lastHit = Date.now();
274
+ dirty = true;
275
+ }
276
+ function getBySkill(skill) {
277
+ return lessons.filter(l => l.skill === skill);
278
+ }
279
+ function getAll() {
280
+ return [...lessons];
281
+ }
282
+ function getTopLessons(limit) {
283
+ const sorted = [...lessons].sort((a, b) => {
284
+ const scoreA = a.confidence * (a.successCount + 1);
285
+ const scoreB = b.confidence * (b.successCount + 1);
286
+ return scoreB - scoreA;
287
+ });
288
+ return limit ? sorted.slice(0, limit) : sorted;
289
+ }
290
+ return {
291
+ addLesson,
292
+ getLesson,
293
+ checkPattern,
294
+ markHit,
295
+ getBySkill,
296
+ getAll,
297
+ getTopLessons,
298
+ persist,
299
+ boot,
300
+ };
301
+ }