genesis-ai-cli 7.4.5

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 (227) hide show
  1. package/.env.example +78 -0
  2. package/README.md +282 -0
  3. package/dist/src/active-inference/actions.d.ts +75 -0
  4. package/dist/src/active-inference/actions.js +250 -0
  5. package/dist/src/active-inference/autonomous-loop.d.ts +103 -0
  6. package/dist/src/active-inference/autonomous-loop.js +289 -0
  7. package/dist/src/active-inference/core.d.ts +85 -0
  8. package/dist/src/active-inference/core.js +555 -0
  9. package/dist/src/active-inference/demo-autonomous-loop.d.ts +8 -0
  10. package/dist/src/active-inference/demo-autonomous-loop.js +338 -0
  11. package/dist/src/active-inference/demo-value-integration.d.ts +8 -0
  12. package/dist/src/active-inference/demo-value-integration.js +174 -0
  13. package/dist/src/active-inference/index.d.ts +32 -0
  14. package/dist/src/active-inference/index.js +88 -0
  15. package/dist/src/active-inference/integration.d.ts +114 -0
  16. package/dist/src/active-inference/integration.js +698 -0
  17. package/dist/src/active-inference/memory-integration.d.ts +51 -0
  18. package/dist/src/active-inference/memory-integration.js +232 -0
  19. package/dist/src/active-inference/observations.d.ts +67 -0
  20. package/dist/src/active-inference/observations.js +147 -0
  21. package/dist/src/active-inference/test-active-inference.d.ts +8 -0
  22. package/dist/src/active-inference/test-active-inference.js +320 -0
  23. package/dist/src/active-inference/test-value-integration.d.ts +6 -0
  24. package/dist/src/active-inference/test-value-integration.js +168 -0
  25. package/dist/src/active-inference/types.d.ts +150 -0
  26. package/dist/src/active-inference/types.js +59 -0
  27. package/dist/src/active-inference/value-integration.d.ts +164 -0
  28. package/dist/src/active-inference/value-integration.js +459 -0
  29. package/dist/src/agents/base-agent.d.ts +53 -0
  30. package/dist/src/agents/base-agent.js +178 -0
  31. package/dist/src/agents/builder.d.ts +67 -0
  32. package/dist/src/agents/builder.js +537 -0
  33. package/dist/src/agents/critic.d.ts +35 -0
  34. package/dist/src/agents/critic.js +322 -0
  35. package/dist/src/agents/ethicist.d.ts +54 -0
  36. package/dist/src/agents/ethicist.js +393 -0
  37. package/dist/src/agents/explorer.d.ts +26 -0
  38. package/dist/src/agents/explorer.js +216 -0
  39. package/dist/src/agents/feeling.d.ts +41 -0
  40. package/dist/src/agents/feeling.js +320 -0
  41. package/dist/src/agents/index.d.ts +111 -0
  42. package/dist/src/agents/index.js +222 -0
  43. package/dist/src/agents/memory.d.ts +69 -0
  44. package/dist/src/agents/memory.js +404 -0
  45. package/dist/src/agents/message-bus.d.ts +88 -0
  46. package/dist/src/agents/message-bus.js +267 -0
  47. package/dist/src/agents/narrator.d.ts +90 -0
  48. package/dist/src/agents/narrator.js +473 -0
  49. package/dist/src/agents/planner.d.ts +38 -0
  50. package/dist/src/agents/planner.js +341 -0
  51. package/dist/src/agents/predictor.d.ts +73 -0
  52. package/dist/src/agents/predictor.js +506 -0
  53. package/dist/src/agents/sensor.d.ts +88 -0
  54. package/dist/src/agents/sensor.js +377 -0
  55. package/dist/src/agents/test-agents.d.ts +6 -0
  56. package/dist/src/agents/test-agents.js +73 -0
  57. package/dist/src/agents/types.d.ts +194 -0
  58. package/dist/src/agents/types.js +7 -0
  59. package/dist/src/brain/index.d.ts +185 -0
  60. package/dist/src/brain/index.js +843 -0
  61. package/dist/src/brain/trace.d.ts +91 -0
  62. package/dist/src/brain/trace.js +327 -0
  63. package/dist/src/brain/types.d.ts +165 -0
  64. package/dist/src/brain/types.js +51 -0
  65. package/dist/src/cli/chat.d.ts +237 -0
  66. package/dist/src/cli/chat.js +1959 -0
  67. package/dist/src/cli/dispatcher.d.ts +182 -0
  68. package/dist/src/cli/dispatcher.js +718 -0
  69. package/dist/src/cli/human-loop.d.ts +170 -0
  70. package/dist/src/cli/human-loop.js +543 -0
  71. package/dist/src/cli/index.d.ts +12 -0
  72. package/dist/src/cli/index.js +28 -0
  73. package/dist/src/cli/interactive.d.ts +141 -0
  74. package/dist/src/cli/interactive.js +757 -0
  75. package/dist/src/cli/ui.d.ts +205 -0
  76. package/dist/src/cli/ui.js +632 -0
  77. package/dist/src/consciousness/attention-schema.d.ts +154 -0
  78. package/dist/src/consciousness/attention-schema.js +432 -0
  79. package/dist/src/consciousness/global-workspace.d.ts +149 -0
  80. package/dist/src/consciousness/global-workspace.js +422 -0
  81. package/dist/src/consciousness/index.d.ts +186 -0
  82. package/dist/src/consciousness/index.js +476 -0
  83. package/dist/src/consciousness/phi-calculator.d.ts +119 -0
  84. package/dist/src/consciousness/phi-calculator.js +445 -0
  85. package/dist/src/consciousness/phi-decisions.d.ts +169 -0
  86. package/dist/src/consciousness/phi-decisions.js +383 -0
  87. package/dist/src/consciousness/phi-monitor.d.ts +153 -0
  88. package/dist/src/consciousness/phi-monitor.js +465 -0
  89. package/dist/src/consciousness/types.d.ts +260 -0
  90. package/dist/src/consciousness/types.js +44 -0
  91. package/dist/src/daemon/dream-mode.d.ts +115 -0
  92. package/dist/src/daemon/dream-mode.js +470 -0
  93. package/dist/src/daemon/index.d.ts +162 -0
  94. package/dist/src/daemon/index.js +542 -0
  95. package/dist/src/daemon/maintenance.d.ts +139 -0
  96. package/dist/src/daemon/maintenance.js +549 -0
  97. package/dist/src/daemon/process.d.ts +82 -0
  98. package/dist/src/daemon/process.js +442 -0
  99. package/dist/src/daemon/scheduler.d.ts +90 -0
  100. package/dist/src/daemon/scheduler.js +494 -0
  101. package/dist/src/daemon/types.d.ts +213 -0
  102. package/dist/src/daemon/types.js +50 -0
  103. package/dist/src/epistemic/index.d.ts +74 -0
  104. package/dist/src/epistemic/index.js +225 -0
  105. package/dist/src/grounding/epistemic-stack.d.ts +100 -0
  106. package/dist/src/grounding/epistemic-stack.js +408 -0
  107. package/dist/src/grounding/feedback.d.ts +98 -0
  108. package/dist/src/grounding/feedback.js +276 -0
  109. package/dist/src/grounding/index.d.ts +123 -0
  110. package/dist/src/grounding/index.js +224 -0
  111. package/dist/src/grounding/verifier.d.ts +149 -0
  112. package/dist/src/grounding/verifier.js +484 -0
  113. package/dist/src/healing/detector.d.ts +110 -0
  114. package/dist/src/healing/detector.js +436 -0
  115. package/dist/src/healing/fixer.d.ts +138 -0
  116. package/dist/src/healing/fixer.js +572 -0
  117. package/dist/src/healing/index.d.ts +23 -0
  118. package/dist/src/healing/index.js +43 -0
  119. package/dist/src/hooks/index.d.ts +135 -0
  120. package/dist/src/hooks/index.js +317 -0
  121. package/dist/src/index.d.ts +23 -0
  122. package/dist/src/index.js +1266 -0
  123. package/dist/src/kernel/index.d.ts +155 -0
  124. package/dist/src/kernel/index.js +795 -0
  125. package/dist/src/kernel/invariants.d.ts +153 -0
  126. package/dist/src/kernel/invariants.js +355 -0
  127. package/dist/src/kernel/test-kernel.d.ts +6 -0
  128. package/dist/src/kernel/test-kernel.js +108 -0
  129. package/dist/src/kernel/test-real-mcp.d.ts +10 -0
  130. package/dist/src/kernel/test-real-mcp.js +295 -0
  131. package/dist/src/llm/index.d.ts +146 -0
  132. package/dist/src/llm/index.js +428 -0
  133. package/dist/src/llm/router.d.ts +136 -0
  134. package/dist/src/llm/router.js +510 -0
  135. package/dist/src/mcp/index.d.ts +85 -0
  136. package/dist/src/mcp/index.js +657 -0
  137. package/dist/src/mcp/resilient.d.ts +139 -0
  138. package/dist/src/mcp/resilient.js +417 -0
  139. package/dist/src/memory/cache.d.ts +118 -0
  140. package/dist/src/memory/cache.js +356 -0
  141. package/dist/src/memory/cognitive-workspace.d.ts +231 -0
  142. package/dist/src/memory/cognitive-workspace.js +521 -0
  143. package/dist/src/memory/consolidation.d.ts +99 -0
  144. package/dist/src/memory/consolidation.js +443 -0
  145. package/dist/src/memory/episodic.d.ts +114 -0
  146. package/dist/src/memory/episodic.js +394 -0
  147. package/dist/src/memory/forgetting.d.ts +134 -0
  148. package/dist/src/memory/forgetting.js +324 -0
  149. package/dist/src/memory/index.d.ts +211 -0
  150. package/dist/src/memory/index.js +367 -0
  151. package/dist/src/memory/indexer.d.ts +123 -0
  152. package/dist/src/memory/indexer.js +479 -0
  153. package/dist/src/memory/procedural.d.ts +136 -0
  154. package/dist/src/memory/procedural.js +479 -0
  155. package/dist/src/memory/semantic.d.ts +132 -0
  156. package/dist/src/memory/semantic.js +497 -0
  157. package/dist/src/memory/types.d.ts +193 -0
  158. package/dist/src/memory/types.js +15 -0
  159. package/dist/src/orchestrator.d.ts +65 -0
  160. package/dist/src/orchestrator.js +317 -0
  161. package/dist/src/persistence/index.d.ts +257 -0
  162. package/dist/src/persistence/index.js +763 -0
  163. package/dist/src/pipeline/executor.d.ts +51 -0
  164. package/dist/src/pipeline/executor.js +695 -0
  165. package/dist/src/pipeline/index.d.ts +7 -0
  166. package/dist/src/pipeline/index.js +11 -0
  167. package/dist/src/self-production.d.ts +67 -0
  168. package/dist/src/self-production.js +205 -0
  169. package/dist/src/subagents/executor.d.ts +58 -0
  170. package/dist/src/subagents/executor.js +283 -0
  171. package/dist/src/subagents/index.d.ts +37 -0
  172. package/dist/src/subagents/index.js +53 -0
  173. package/dist/src/subagents/registry.d.ts +23 -0
  174. package/dist/src/subagents/registry.js +167 -0
  175. package/dist/src/subagents/types.d.ts +79 -0
  176. package/dist/src/subagents/types.js +14 -0
  177. package/dist/src/tools/bash.d.ts +139 -0
  178. package/dist/src/tools/bash.js +583 -0
  179. package/dist/src/tools/edit.d.ts +125 -0
  180. package/dist/src/tools/edit.js +424 -0
  181. package/dist/src/tools/git.d.ts +179 -0
  182. package/dist/src/tools/git.js +504 -0
  183. package/dist/src/tools/index.d.ts +21 -0
  184. package/dist/src/tools/index.js +163 -0
  185. package/dist/src/types.d.ts +145 -0
  186. package/dist/src/types.js +7 -0
  187. package/dist/src/world-model/decoder.d.ts +163 -0
  188. package/dist/src/world-model/decoder.js +517 -0
  189. package/dist/src/world-model/digital-twin.d.ts +219 -0
  190. package/dist/src/world-model/digital-twin.js +695 -0
  191. package/dist/src/world-model/encoder.d.ts +141 -0
  192. package/dist/src/world-model/encoder.js +564 -0
  193. package/dist/src/world-model/index.d.ts +221 -0
  194. package/dist/src/world-model/index.js +772 -0
  195. package/dist/src/world-model/predictor.d.ts +161 -0
  196. package/dist/src/world-model/predictor.js +681 -0
  197. package/dist/src/world-model/test-value-jepa.d.ts +8 -0
  198. package/dist/src/world-model/test-value-jepa.js +430 -0
  199. package/dist/src/world-model/types.d.ts +341 -0
  200. package/dist/src/world-model/types.js +69 -0
  201. package/dist/src/world-model/value-jepa.d.ts +247 -0
  202. package/dist/src/world-model/value-jepa.js +622 -0
  203. package/dist/test/brain.test.d.ts +11 -0
  204. package/dist/test/brain.test.js +358 -0
  205. package/dist/test/cli/dispatcher.test.d.ts +4 -0
  206. package/dist/test/cli/dispatcher.test.js +332 -0
  207. package/dist/test/cli/human-loop.test.d.ts +4 -0
  208. package/dist/test/cli/human-loop.test.js +270 -0
  209. package/dist/test/grounding/feedback.test.d.ts +4 -0
  210. package/dist/test/grounding/feedback.test.js +462 -0
  211. package/dist/test/grounding/verifier.test.d.ts +4 -0
  212. package/dist/test/grounding/verifier.test.js +442 -0
  213. package/dist/test/grounding.test.d.ts +6 -0
  214. package/dist/test/grounding.test.js +246 -0
  215. package/dist/test/healing/detector.test.d.ts +4 -0
  216. package/dist/test/healing/detector.test.js +266 -0
  217. package/dist/test/healing/fixer.test.d.ts +4 -0
  218. package/dist/test/healing/fixer.test.js +369 -0
  219. package/dist/test/integration.test.d.ts +5 -0
  220. package/dist/test/integration.test.js +290 -0
  221. package/dist/test/tools/bash.test.d.ts +4 -0
  222. package/dist/test/tools/bash.test.js +348 -0
  223. package/dist/test/tools/edit.test.d.ts +4 -0
  224. package/dist/test/tools/edit.test.js +350 -0
  225. package/dist/test/tools/git.test.d.ts +4 -0
  226. package/dist/test/tools/git.test.js +350 -0
  227. package/package.json +60 -0
@@ -0,0 +1,394 @@
1
+ "use strict";
2
+ /**
3
+ * Genesis 6.0 - Episodic Memory Store
4
+ *
5
+ * Stores autobiographical memories - events with context.
6
+ * "What happened, when, where, who was involved"
7
+ *
8
+ * Key features:
9
+ * - Temporal ordering and sequencing
10
+ * - Context binding (where, who)
11
+ * - Emotional coloring
12
+ * - Forgetting curve integration
13
+ *
14
+ * Reference: Tulving, E. (1972). Episodic and semantic memory.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.EpisodicStore = void 0;
18
+ exports.createEpisodicStore = createEpisodicStore;
19
+ const crypto_1 = require("crypto");
20
+ const forgetting_js_1 = require("./forgetting.js");
21
+ // ============================================================================
22
+ // Episodic Store
23
+ // ============================================================================
24
+ class EpisodicStore {
25
+ memories = new Map();
26
+ config;
27
+ // Indexes for efficient querying
28
+ byTime = []; // Sorted by when.timestamp
29
+ byLocation = new Map();
30
+ byAgent = new Map();
31
+ byTag = new Map();
32
+ constructor(config = {}) {
33
+ this.config = {
34
+ maxSize: 10000,
35
+ autoForget: true,
36
+ forgetThreshold: forgetting_js_1.FORGETTING_THRESHOLDS.FORGET,
37
+ defaultStability: forgetting_js_1.FORGETTING_THRESHOLDS.DEFAULT_STABILITY,
38
+ ...config,
39
+ };
40
+ }
41
+ // ============================================================================
42
+ // Store
43
+ // ============================================================================
44
+ store(input) {
45
+ const now = new Date();
46
+ const id = (0, crypto_1.randomUUID)();
47
+ const memory = {
48
+ ...input,
49
+ id,
50
+ created: now,
51
+ lastAccessed: now,
52
+ accessCount: 1,
53
+ };
54
+ this.memories.set(id, memory);
55
+ this.updateIndexes(memory);
56
+ this.maintainSize();
57
+ return memory;
58
+ }
59
+ /**
60
+ * Convenience method to create an episodic memory from options
61
+ */
62
+ createEpisode(options) {
63
+ const now = new Date();
64
+ const params = (0, forgetting_js_1.calculateInitialParams)({
65
+ importance: options.importance,
66
+ emotionalValence: options.feeling?.valence,
67
+ });
68
+ return this.store({
69
+ type: 'episodic',
70
+ content: {
71
+ what: options.what,
72
+ details: options.details || {},
73
+ },
74
+ when: {
75
+ timestamp: options.when || now,
76
+ duration: options.duration,
77
+ },
78
+ where: options.where,
79
+ who: options.who ? {
80
+ agents: options.who.agents,
81
+ roles: options.who.roles || {},
82
+ } : undefined,
83
+ feeling: options.feeling,
84
+ R0: params.R0,
85
+ S: params.S,
86
+ importance: options.importance || 0.5,
87
+ emotionalValence: options.feeling?.valence || 0,
88
+ associations: options.associations || [],
89
+ tags: options.tags || [],
90
+ consolidated: false,
91
+ source: options.source,
92
+ });
93
+ }
94
+ // ============================================================================
95
+ // Get / Update / Delete
96
+ // ============================================================================
97
+ get(id) {
98
+ const memory = this.memories.get(id);
99
+ if (memory) {
100
+ this.accessMemory(memory);
101
+ }
102
+ return memory;
103
+ }
104
+ /**
105
+ * Get without updating access (for internal use)
106
+ */
107
+ peek(id) {
108
+ return this.memories.get(id);
109
+ }
110
+ update(id, updates) {
111
+ const memory = this.memories.get(id);
112
+ if (!memory)
113
+ return undefined;
114
+ // Remove from indexes before update
115
+ this.removeFromIndexes(memory);
116
+ // Apply updates
117
+ Object.assign(memory, updates);
118
+ // Re-add to indexes
119
+ this.updateIndexes(memory);
120
+ return memory;
121
+ }
122
+ delete(id) {
123
+ const memory = this.memories.get(id);
124
+ if (!memory)
125
+ return false;
126
+ this.removeFromIndexes(memory);
127
+ this.memories.delete(id);
128
+ return true;
129
+ }
130
+ // ============================================================================
131
+ // Query
132
+ // ============================================================================
133
+ query(filter) {
134
+ let results = this.getAll();
135
+ if (filter.minImportance !== undefined) {
136
+ results = results.filter((m) => m.importance >= filter.minImportance);
137
+ }
138
+ if (filter.maxAge !== undefined) {
139
+ const cutoff = Date.now() - filter.maxAge * 24 * 60 * 60 * 1000;
140
+ results = results.filter((m) => m.created.getTime() >= cutoff);
141
+ }
142
+ if (filter.minRetention !== undefined) {
143
+ results = results.filter((m) => {
144
+ const retention = (0, forgetting_js_1.calculateRetention)({ R0: m.R0, S: m.S }, m.lastAccessed.getTime());
145
+ return retention >= filter.minRetention;
146
+ });
147
+ }
148
+ if (filter.tags && filter.tags.length > 0) {
149
+ results = results.filter((m) => filter.tags.some((t) => m.tags.includes(t)));
150
+ }
151
+ if (filter.consolidated !== undefined) {
152
+ results = results.filter((m) => m.consolidated === filter.consolidated);
153
+ }
154
+ if (filter.custom) {
155
+ results = results.filter(filter.custom);
156
+ }
157
+ return results;
158
+ }
159
+ /**
160
+ * Search by keyword in content
161
+ */
162
+ search(queryStr, limit = 10) {
163
+ const keywords = queryStr.toLowerCase().split(/\s+/);
164
+ const results = this.getAll().filter((m) => {
165
+ const contentStr = JSON.stringify(m.content).toLowerCase();
166
+ return keywords.some((k) => contentStr.includes(k));
167
+ });
168
+ // Sort by retention (strongest first)
169
+ results.sort((a, b) => {
170
+ const retA = (0, forgetting_js_1.calculateRetention)({ R0: a.R0, S: a.S }, a.lastAccessed.getTime());
171
+ const retB = (0, forgetting_js_1.calculateRetention)({ R0: b.R0, S: b.S }, b.lastAccessed.getTime());
172
+ return retB - retA;
173
+ });
174
+ return results.slice(0, limit);
175
+ }
176
+ // ============================================================================
177
+ // Time-based Queries
178
+ // ============================================================================
179
+ /**
180
+ * Get episodes in a time range
181
+ */
182
+ getByTimeRange(start, end) {
183
+ return this.byTime.filter((m) => m.when.timestamp >= start && m.when.timestamp <= end);
184
+ }
185
+ /**
186
+ * Get recent episodes
187
+ */
188
+ getRecent(limit = 10) {
189
+ return this.byTime.slice(-limit).reverse();
190
+ }
191
+ /**
192
+ * Get episodes from today
193
+ */
194
+ getToday() {
195
+ const today = new Date();
196
+ today.setHours(0, 0, 0, 0);
197
+ const tomorrow = new Date(today);
198
+ tomorrow.setDate(tomorrow.getDate() + 1);
199
+ return this.getByTimeRange(today, tomorrow);
200
+ }
201
+ /**
202
+ * Get episodes involving a specific agent
203
+ */
204
+ getByAgent(agentId) {
205
+ const ids = this.byAgent.get(agentId);
206
+ if (!ids)
207
+ return [];
208
+ return Array.from(ids)
209
+ .map((id) => this.memories.get(id))
210
+ .filter((m) => m !== undefined);
211
+ }
212
+ /**
213
+ * Get episodes at a location
214
+ */
215
+ getByLocation(location) {
216
+ const ids = this.byLocation.get(location);
217
+ if (!ids)
218
+ return [];
219
+ return Array.from(ids)
220
+ .map((id) => this.memories.get(id))
221
+ .filter((m) => m !== undefined);
222
+ }
223
+ // ============================================================================
224
+ // Bulk Operations
225
+ // ============================================================================
226
+ getAll() {
227
+ return Array.from(this.memories.values());
228
+ }
229
+ clear() {
230
+ this.memories.clear();
231
+ this.byTime = [];
232
+ this.byLocation.clear();
233
+ this.byAgent.clear();
234
+ this.byTag.clear();
235
+ }
236
+ count() {
237
+ return this.memories.size;
238
+ }
239
+ // ============================================================================
240
+ // Stats
241
+ // ============================================================================
242
+ stats() {
243
+ const all = this.getAll();
244
+ let totalRetention = 0;
245
+ let totalImportance = 0;
246
+ let consolidated = 0;
247
+ let oldest;
248
+ let newest;
249
+ for (const memory of all) {
250
+ totalRetention += (0, forgetting_js_1.calculateRetention)({ R0: memory.R0, S: memory.S }, memory.lastAccessed.getTime());
251
+ totalImportance += memory.importance;
252
+ if (memory.consolidated)
253
+ consolidated++;
254
+ if (!oldest || memory.created < oldest)
255
+ oldest = memory.created;
256
+ if (!newest || memory.created > newest)
257
+ newest = memory.created;
258
+ }
259
+ return {
260
+ total: all.length,
261
+ byType: {
262
+ episodic: all.length,
263
+ semantic: 0,
264
+ procedural: 0,
265
+ },
266
+ consolidated,
267
+ avgRetention: all.length > 0 ? totalRetention / all.length : 0,
268
+ avgImportance: all.length > 0 ? totalImportance / all.length : 0,
269
+ oldestMemory: oldest,
270
+ newestMemory: newest,
271
+ };
272
+ }
273
+ // ============================================================================
274
+ // Forgetting Integration
275
+ // ============================================================================
276
+ /**
277
+ * Get episodes that should be forgotten
278
+ */
279
+ getForgotten() {
280
+ return this.getAll().filter((m) => (0, forgetting_js_1.shouldForget)(m, this.config.forgetThreshold));
281
+ }
282
+ /**
283
+ * Get episodes ready for consolidation (strong retention, not yet consolidated)
284
+ */
285
+ getReadyForConsolidation(threshold = 0.7) {
286
+ return this.getAll().filter((m) => {
287
+ if (m.consolidated)
288
+ return false;
289
+ const retention = (0, forgetting_js_1.calculateRetention)({ R0: m.R0, S: m.S }, m.lastAccessed.getTime());
290
+ return retention >= threshold;
291
+ });
292
+ }
293
+ /**
294
+ * Run forgetting cycle - remove memories below threshold
295
+ */
296
+ runForgetting() {
297
+ const toForget = this.getForgotten();
298
+ const ids = toForget.map((m) => m.id);
299
+ for (const id of ids) {
300
+ this.delete(id);
301
+ }
302
+ return { forgotten: ids.length, ids };
303
+ }
304
+ // ============================================================================
305
+ // Private Methods
306
+ // ============================================================================
307
+ accessMemory(memory) {
308
+ memory.lastAccessed = new Date();
309
+ memory.accessCount++;
310
+ memory.S = (0, forgetting_js_1.updateStabilityOnRecall)(memory, true);
311
+ }
312
+ updateIndexes(memory) {
313
+ // Time index
314
+ this.byTime.push(memory);
315
+ this.byTime.sort((a, b) => a.when.timestamp.getTime() - b.when.timestamp.getTime());
316
+ // Location index
317
+ if (memory.where) {
318
+ if (!this.byLocation.has(memory.where.location)) {
319
+ this.byLocation.set(memory.where.location, new Set());
320
+ }
321
+ this.byLocation.get(memory.where.location).add(memory.id);
322
+ }
323
+ // Agent index
324
+ if (memory.who) {
325
+ for (const agent of memory.who.agents) {
326
+ if (!this.byAgent.has(agent)) {
327
+ this.byAgent.set(agent, new Set());
328
+ }
329
+ this.byAgent.get(agent).add(memory.id);
330
+ }
331
+ }
332
+ // Tag index
333
+ for (const tag of memory.tags) {
334
+ if (!this.byTag.has(tag)) {
335
+ this.byTag.set(tag, new Set());
336
+ }
337
+ this.byTag.get(tag).add(memory.id);
338
+ }
339
+ }
340
+ removeFromIndexes(memory) {
341
+ // Time index
342
+ const timeIndex = this.byTime.findIndex((m) => m.id === memory.id);
343
+ if (timeIndex !== -1) {
344
+ this.byTime.splice(timeIndex, 1);
345
+ }
346
+ // Location index
347
+ if (memory.where) {
348
+ this.byLocation.get(memory.where.location)?.delete(memory.id);
349
+ }
350
+ // Agent index
351
+ if (memory.who) {
352
+ for (const agent of memory.who.agents) {
353
+ this.byAgent.get(agent)?.delete(memory.id);
354
+ }
355
+ }
356
+ // Tag index
357
+ for (const tag of memory.tags) {
358
+ this.byTag.get(tag)?.delete(memory.id);
359
+ }
360
+ }
361
+ maintainSize() {
362
+ if (!this.config.autoForget)
363
+ return;
364
+ if (this.memories.size <= this.config.maxSize)
365
+ return;
366
+ // First, forget memories below threshold
367
+ this.runForgetting();
368
+ // If still over limit, remove weakest memories
369
+ while (this.memories.size > this.config.maxSize) {
370
+ let weakest = null;
371
+ let weakestRetention = Infinity;
372
+ for (const memory of this.memories.values()) {
373
+ const retention = (0, forgetting_js_1.calculateRetention)({ R0: memory.R0, S: memory.S }, memory.lastAccessed.getTime());
374
+ if (retention < weakestRetention) {
375
+ weakestRetention = retention;
376
+ weakest = memory;
377
+ }
378
+ }
379
+ if (weakest) {
380
+ this.delete(weakest.id);
381
+ }
382
+ else {
383
+ break;
384
+ }
385
+ }
386
+ }
387
+ }
388
+ exports.EpisodicStore = EpisodicStore;
389
+ // ============================================================================
390
+ // Factory
391
+ // ============================================================================
392
+ function createEpisodicStore(config) {
393
+ return new EpisodicStore(config);
394
+ }
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Genesis 6.0 - Forgetting Module
3
+ *
4
+ * Implements Ebbinghaus forgetting curve: R(t) = R0 * e^(-t/S)
5
+ *
6
+ * Where:
7
+ * - R = retention (0-1)
8
+ * - R0 = initial retention strength
9
+ * - t = time elapsed (days)
10
+ * - S = stability (days until 50% forgotten)
11
+ *
12
+ * Enhanced with FSRS-style stability updates on recall.
13
+ *
14
+ * References:
15
+ * - Ebbinghaus, H. (1885). Memory: A Contribution to Experimental Psychology
16
+ * - Wozniak, P. (2020). Free Spaced Repetition Scheduler (FSRS)
17
+ */
18
+ import { BaseMemory, ForgettingParams, RetentionResult } from './types.js';
19
+ /**
20
+ * Forgetting thresholds
21
+ */
22
+ export declare const FORGETTING_THRESHOLDS: {
23
+ /** Below this retention, memory is effectively forgotten */
24
+ FORGET: number;
25
+ /** Below this, memory is weak and at risk */
26
+ WEAK: number;
27
+ /** Above this, memory is strong */
28
+ STRONG: number;
29
+ /** Default initial stability (days) */
30
+ DEFAULT_STABILITY: number;
31
+ /** Maximum stability (years worth of days) */
32
+ MAX_STABILITY: number;
33
+ };
34
+ /**
35
+ * Stability multipliers for reinforcement
36
+ */
37
+ export declare const STABILITY_MULTIPLIERS: {
38
+ /** Base multiplier on successful recall */
39
+ RECALL_SUCCESS: number;
40
+ /** Bonus for high importance memories */
41
+ IMPORTANCE_HIGH: number;
42
+ /** Bonus for emotionally charged memories */
43
+ EMOTIONAL: number;
44
+ /** Decay factor for failed recall */
45
+ RECALL_FAILURE: number;
46
+ /** Bonus for repeated access within short time */
47
+ SPACED_REPETITION: number;
48
+ };
49
+ /**
50
+ * Calculate current retention using Ebbinghaus formula
51
+ * R(t) = R0 * e^(-t/S)
52
+ *
53
+ * @param params - Forgetting parameters (R0, S)
54
+ * @param lastAccessedMs - Timestamp of last access (ms)
55
+ * @param nowMs - Current timestamp (ms), defaults to now
56
+ * @returns Current retention value (0-1)
57
+ */
58
+ export declare function calculateRetention(params: ForgettingParams, lastAccessedMs: number, nowMs?: number): number;
59
+ /**
60
+ * Calculate detailed retention result for a memory
61
+ */
62
+ export declare function getRetentionDetails(memory: BaseMemory, nowMs?: number): RetentionResult;
63
+ /**
64
+ * Check if a memory should be forgotten
65
+ */
66
+ export declare function shouldForget(memory: BaseMemory, threshold?: number): boolean;
67
+ /**
68
+ * Get memories that should be forgotten from a list
69
+ */
70
+ export declare function getMemoriesToForget<T extends BaseMemory>(memories: T[], threshold?: number): T[];
71
+ /**
72
+ * Update stability after successful recall
73
+ * Stability increases, making the memory more resistant to forgetting
74
+ */
75
+ export declare function updateStabilityOnRecall(memory: BaseMemory, success?: boolean): number;
76
+ /**
77
+ * Calculate optimal review time (when to access again)
78
+ * Returns the time in days when retention will drop to target level
79
+ */
80
+ export declare function calculateOptimalReviewTime(memory: BaseMemory, targetRetention?: number): number;
81
+ /**
82
+ * Get spaced repetition schedule for a memory
83
+ * Returns array of review times (days from now)
84
+ */
85
+ export declare function getReviewSchedule(memory: BaseMemory, targetRetention?: number, numReviews?: number): number[];
86
+ /**
87
+ * Calculate initial forgetting parameters for a new memory
88
+ */
89
+ export declare function calculateInitialParams(options: {
90
+ importance?: number;
91
+ emotionalValence?: number;
92
+ complexity?: number;
93
+ priorKnowledge?: boolean;
94
+ }): ForgettingParams;
95
+ /**
96
+ * Simulate retention over time
97
+ * Useful for visualization and analysis
98
+ */
99
+ export declare function simulateDecay(params: ForgettingParams, days: number, intervalHours?: number): Array<{
100
+ day: number;
101
+ retention: number;
102
+ }>;
103
+ /**
104
+ * Compare decay curves for multiple memories
105
+ */
106
+ export declare function compareDecayCurves(memories: BaseMemory[], days?: number): Map<string, Array<{
107
+ day: number;
108
+ retention: number;
109
+ }>>;
110
+ /**
111
+ * Calculate retention for multiple memories efficiently
112
+ */
113
+ export declare function batchCalculateRetention(memories: BaseMemory[], nowMs?: number): Map<string, number>;
114
+ /**
115
+ * Sort memories by retention (weakest first)
116
+ */
117
+ export declare function sortByRetention<T extends BaseMemory>(memories: T[], ascending?: boolean): T[];
118
+ /**
119
+ * Get memories that need review (retention below threshold)
120
+ */
121
+ export declare function getMemoriesNeedingReview<T extends BaseMemory>(memories: T[], threshold?: number): T[];
122
+ /**
123
+ * Calculate forgetting statistics for a set of memories
124
+ */
125
+ export declare function calculateForgettingStats(memories: BaseMemory[]): {
126
+ total: number;
127
+ forgotten: number;
128
+ weak: number;
129
+ strong: number;
130
+ avgRetention: number;
131
+ avgStability: number;
132
+ avgAge: number;
133
+ needsReview: number;
134
+ };