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,324 @@
1
+ "use strict";
2
+ /**
3
+ * Genesis 6.0 - Forgetting Module
4
+ *
5
+ * Implements Ebbinghaus forgetting curve: R(t) = R0 * e^(-t/S)
6
+ *
7
+ * Where:
8
+ * - R = retention (0-1)
9
+ * - R0 = initial retention strength
10
+ * - t = time elapsed (days)
11
+ * - S = stability (days until 50% forgotten)
12
+ *
13
+ * Enhanced with FSRS-style stability updates on recall.
14
+ *
15
+ * References:
16
+ * - Ebbinghaus, H. (1885). Memory: A Contribution to Experimental Psychology
17
+ * - Wozniak, P. (2020). Free Spaced Repetition Scheduler (FSRS)
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.STABILITY_MULTIPLIERS = exports.FORGETTING_THRESHOLDS = void 0;
21
+ exports.calculateRetention = calculateRetention;
22
+ exports.getRetentionDetails = getRetentionDetails;
23
+ exports.shouldForget = shouldForget;
24
+ exports.getMemoriesToForget = getMemoriesToForget;
25
+ exports.updateStabilityOnRecall = updateStabilityOnRecall;
26
+ exports.calculateOptimalReviewTime = calculateOptimalReviewTime;
27
+ exports.getReviewSchedule = getReviewSchedule;
28
+ exports.calculateInitialParams = calculateInitialParams;
29
+ exports.simulateDecay = simulateDecay;
30
+ exports.compareDecayCurves = compareDecayCurves;
31
+ exports.batchCalculateRetention = batchCalculateRetention;
32
+ exports.sortByRetention = sortByRetention;
33
+ exports.getMemoriesNeedingReview = getMemoriesNeedingReview;
34
+ exports.calculateForgettingStats = calculateForgettingStats;
35
+ // ============================================================================
36
+ // Constants
37
+ // ============================================================================
38
+ /**
39
+ * Forgetting thresholds
40
+ */
41
+ exports.FORGETTING_THRESHOLDS = {
42
+ /** Below this retention, memory is effectively forgotten */
43
+ FORGET: 0.01,
44
+ /** Below this, memory is weak and at risk */
45
+ WEAK: 0.3,
46
+ /** Above this, memory is strong */
47
+ STRONG: 0.7,
48
+ /** Default initial stability (days) */
49
+ DEFAULT_STABILITY: 1.0,
50
+ /** Maximum stability (years worth of days) */
51
+ MAX_STABILITY: 3650,
52
+ };
53
+ /**
54
+ * Stability multipliers for reinforcement
55
+ */
56
+ exports.STABILITY_MULTIPLIERS = {
57
+ /** Base multiplier on successful recall */
58
+ RECALL_SUCCESS: 2.5,
59
+ /** Bonus for high importance memories */
60
+ IMPORTANCE_HIGH: 1.5,
61
+ /** Bonus for emotionally charged memories */
62
+ EMOTIONAL: 2.0,
63
+ /** Decay factor for failed recall */
64
+ RECALL_FAILURE: 0.5,
65
+ /** Bonus for repeated access within short time */
66
+ SPACED_REPETITION: 1.2,
67
+ };
68
+ // ============================================================================
69
+ // Core Forgetting Functions
70
+ // ============================================================================
71
+ /**
72
+ * Calculate current retention using Ebbinghaus formula
73
+ * R(t) = R0 * e^(-t/S)
74
+ *
75
+ * @param params - Forgetting parameters (R0, S)
76
+ * @param lastAccessedMs - Timestamp of last access (ms)
77
+ * @param nowMs - Current timestamp (ms), defaults to now
78
+ * @returns Current retention value (0-1)
79
+ */
80
+ function calculateRetention(params, lastAccessedMs, nowMs = Date.now()) {
81
+ const elapsedDays = (nowMs - lastAccessedMs) / (1000 * 60 * 60 * 24);
82
+ if (elapsedDays <= 0) {
83
+ return params.R0;
84
+ }
85
+ const retention = params.R0 * Math.exp(-elapsedDays / params.S);
86
+ return Math.max(0, Math.min(1, retention));
87
+ }
88
+ /**
89
+ * Calculate detailed retention result for a memory
90
+ */
91
+ function getRetentionDetails(memory, nowMs = Date.now()) {
92
+ const lastAccessedMs = memory.lastAccessed.getTime();
93
+ const elapsedDays = (nowMs - lastAccessedMs) / (1000 * 60 * 60 * 24);
94
+ const retention = calculateRetention({ R0: memory.R0, S: memory.S }, lastAccessedMs, nowMs);
95
+ // Calculate half-life: when R = R0/2
96
+ // R0/2 = R0 * e^(-t/S)
97
+ // 0.5 = e^(-t/S)
98
+ // ln(0.5) = -t/S
99
+ // t = -S * ln(0.5) = S * ln(2)
100
+ const predictedHalfLife = memory.S * Math.LN2;
101
+ return {
102
+ retention,
103
+ elapsedDays,
104
+ predictedHalfLife,
105
+ shouldForget: retention < exports.FORGETTING_THRESHOLDS.FORGET,
106
+ };
107
+ }
108
+ /**
109
+ * Check if a memory should be forgotten
110
+ */
111
+ function shouldForget(memory, threshold = exports.FORGETTING_THRESHOLDS.FORGET) {
112
+ const retention = calculateRetention({ R0: memory.R0, S: memory.S }, memory.lastAccessed.getTime());
113
+ return retention < threshold;
114
+ }
115
+ /**
116
+ * Get memories that should be forgotten from a list
117
+ */
118
+ function getMemoriesToForget(memories, threshold = exports.FORGETTING_THRESHOLDS.FORGET) {
119
+ return memories.filter((m) => shouldForget(m, threshold));
120
+ }
121
+ // ============================================================================
122
+ // Stability Updates (FSRS-inspired)
123
+ // ============================================================================
124
+ /**
125
+ * Update stability after successful recall
126
+ * Stability increases, making the memory more resistant to forgetting
127
+ */
128
+ function updateStabilityOnRecall(memory, success = true) {
129
+ let newStability = memory.S;
130
+ if (success) {
131
+ // Base increase
132
+ newStability *= exports.STABILITY_MULTIPLIERS.RECALL_SUCCESS;
133
+ // Importance bonus
134
+ if (memory.importance > 0.7) {
135
+ newStability *= exports.STABILITY_MULTIPLIERS.IMPORTANCE_HIGH;
136
+ }
137
+ // Emotional bonus
138
+ if (Math.abs(memory.emotionalValence) > 0.5) {
139
+ newStability *= exports.STABILITY_MULTIPLIERS.EMOTIONAL;
140
+ }
141
+ }
142
+ else {
143
+ // Failed recall decreases stability
144
+ newStability *= exports.STABILITY_MULTIPLIERS.RECALL_FAILURE;
145
+ }
146
+ // Clamp to max
147
+ return Math.min(newStability, exports.FORGETTING_THRESHOLDS.MAX_STABILITY);
148
+ }
149
+ /**
150
+ * Calculate optimal review time (when to access again)
151
+ * Returns the time in days when retention will drop to target level
152
+ */
153
+ function calculateOptimalReviewTime(memory, targetRetention = 0.9) {
154
+ // Solve: targetRetention = R0 * e^(-t/S)
155
+ // t = -S * ln(targetRetention / R0)
156
+ const t = -memory.S * Math.log(targetRetention / memory.R0);
157
+ return Math.max(0, t);
158
+ }
159
+ /**
160
+ * Get spaced repetition schedule for a memory
161
+ * Returns array of review times (days from now)
162
+ */
163
+ function getReviewSchedule(memory, targetRetention = 0.9, numReviews = 5) {
164
+ const schedule = [];
165
+ let currentStability = memory.S;
166
+ let totalDays = 0;
167
+ for (let i = 0; i < numReviews; i++) {
168
+ // Time until next review
169
+ const interval = -currentStability * Math.log(targetRetention / memory.R0);
170
+ totalDays += interval;
171
+ schedule.push(totalDays);
172
+ // Simulate stability increase after review
173
+ currentStability *= exports.STABILITY_MULTIPLIERS.RECALL_SUCCESS;
174
+ currentStability = Math.min(currentStability, exports.FORGETTING_THRESHOLDS.MAX_STABILITY);
175
+ }
176
+ return schedule;
177
+ }
178
+ // ============================================================================
179
+ // Initial Parameters
180
+ // ============================================================================
181
+ /**
182
+ * Calculate initial forgetting parameters for a new memory
183
+ */
184
+ function calculateInitialParams(options) {
185
+ const { importance = 0.5, emotionalValence = 0, complexity = 0.5, priorKnowledge = false, } = options;
186
+ // Base initial retention
187
+ let R0 = 1.0;
188
+ // Importance affects initial strength
189
+ R0 += importance * 0.3;
190
+ // Emotional memories are stronger
191
+ R0 += Math.abs(emotionalValence) * 0.2;
192
+ // Normalize to 0-1
193
+ R0 = Math.min(1, R0);
194
+ // Base stability
195
+ let S = exports.FORGETTING_THRESHOLDS.DEFAULT_STABILITY;
196
+ // Complex memories decay faster initially
197
+ S *= 1 - complexity * 0.5;
198
+ // Prior knowledge helps
199
+ if (priorKnowledge) {
200
+ S *= 2;
201
+ }
202
+ // Emotional memories are more stable
203
+ S *= 1 + Math.abs(emotionalValence) * 0.5;
204
+ return { R0, S };
205
+ }
206
+ // ============================================================================
207
+ // Decay Simulation
208
+ // ============================================================================
209
+ /**
210
+ * Simulate retention over time
211
+ * Useful for visualization and analysis
212
+ */
213
+ function simulateDecay(params, days, intervalHours = 24) {
214
+ const points = [];
215
+ const intervalDays = intervalHours / 24;
216
+ for (let day = 0; day <= days; day += intervalDays) {
217
+ const retention = params.R0 * Math.exp(-day / params.S);
218
+ points.push({ day, retention });
219
+ }
220
+ return points;
221
+ }
222
+ /**
223
+ * Compare decay curves for multiple memories
224
+ */
225
+ function compareDecayCurves(memories, days = 30) {
226
+ const curves = new Map();
227
+ for (const memory of memories) {
228
+ curves.set(memory.id, simulateDecay({ R0: memory.R0, S: memory.S }, days));
229
+ }
230
+ return curves;
231
+ }
232
+ // ============================================================================
233
+ // Batch Operations
234
+ // ============================================================================
235
+ /**
236
+ * Calculate retention for multiple memories efficiently
237
+ */
238
+ function batchCalculateRetention(memories, nowMs = Date.now()) {
239
+ const retentions = new Map();
240
+ for (const memory of memories) {
241
+ const retention = calculateRetention({ R0: memory.R0, S: memory.S }, memory.lastAccessed.getTime(), nowMs);
242
+ retentions.set(memory.id, retention);
243
+ }
244
+ return retentions;
245
+ }
246
+ /**
247
+ * Sort memories by retention (weakest first)
248
+ */
249
+ function sortByRetention(memories, ascending = true) {
250
+ const nowMs = Date.now();
251
+ return [...memories].sort((a, b) => {
252
+ const retentionA = calculateRetention({ R0: a.R0, S: a.S }, a.lastAccessed.getTime(), nowMs);
253
+ const retentionB = calculateRetention({ R0: b.R0, S: b.S }, b.lastAccessed.getTime(), nowMs);
254
+ return ascending ? retentionA - retentionB : retentionB - retentionA;
255
+ });
256
+ }
257
+ /**
258
+ * Get memories that need review (retention below threshold)
259
+ */
260
+ function getMemoriesNeedingReview(memories, threshold = exports.FORGETTING_THRESHOLDS.WEAK) {
261
+ return sortByRetention(memories.filter((m) => {
262
+ const retention = calculateRetention({ R0: m.R0, S: m.S }, m.lastAccessed.getTime());
263
+ return retention < threshold && retention >= exports.FORGETTING_THRESHOLDS.FORGET;
264
+ }), true // weakest first
265
+ );
266
+ }
267
+ // ============================================================================
268
+ // Statistics
269
+ // ============================================================================
270
+ /**
271
+ * Calculate forgetting statistics for a set of memories
272
+ */
273
+ function calculateForgettingStats(memories) {
274
+ if (memories.length === 0) {
275
+ return {
276
+ total: 0,
277
+ forgotten: 0,
278
+ weak: 0,
279
+ strong: 0,
280
+ avgRetention: 0,
281
+ avgStability: 0,
282
+ avgAge: 0,
283
+ needsReview: 0,
284
+ };
285
+ }
286
+ const nowMs = Date.now();
287
+ let totalRetention = 0;
288
+ let totalStability = 0;
289
+ let totalAge = 0;
290
+ let forgotten = 0;
291
+ let weak = 0;
292
+ let strong = 0;
293
+ let needsReview = 0;
294
+ for (const memory of memories) {
295
+ const retention = calculateRetention({ R0: memory.R0, S: memory.S }, memory.lastAccessed.getTime(), nowMs);
296
+ const ageDays = (nowMs - memory.created.getTime()) / (1000 * 60 * 60 * 24);
297
+ totalRetention += retention;
298
+ totalStability += memory.S;
299
+ totalAge += ageDays;
300
+ if (retention < exports.FORGETTING_THRESHOLDS.FORGET) {
301
+ forgotten++;
302
+ }
303
+ else if (retention < exports.FORGETTING_THRESHOLDS.WEAK) {
304
+ weak++;
305
+ needsReview++;
306
+ }
307
+ else if (retention > exports.FORGETTING_THRESHOLDS.STRONG) {
308
+ strong++;
309
+ }
310
+ else {
311
+ needsReview++;
312
+ }
313
+ }
314
+ return {
315
+ total: memories.length,
316
+ forgotten,
317
+ weak,
318
+ strong,
319
+ avgRetention: totalRetention / memories.length,
320
+ avgStability: totalStability / memories.length,
321
+ avgAge: totalAge / memories.length,
322
+ needsReview,
323
+ };
324
+ }
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Genesis 6.0 - Memory Module
3
+ *
4
+ * Unified memory system based on cognitive science:
5
+ * - Episodic: Events with context (what/when/where/who)
6
+ * - Semantic: Facts and concepts (knowledge)
7
+ * - Procedural: Skills and workflows (know-how)
8
+ *
9
+ * Features:
10
+ * - Ebbinghaus forgetting curve
11
+ * - Sleep-based consolidation (episodic → semantic)
12
+ * - Pattern extraction
13
+ * - Skill learning
14
+ *
15
+ * Usage:
16
+ * ```typescript
17
+ * import { createMemorySystem } from './memory/index.js';
18
+ *
19
+ * const memory = createMemorySystem();
20
+ *
21
+ * // Store an episode
22
+ * memory.remember({
23
+ * what: 'User asked about AI',
24
+ * when: new Date(),
25
+ * tags: ['conversation', 'AI'],
26
+ * });
27
+ *
28
+ * // Create a fact
29
+ * memory.learn({
30
+ * concept: 'TypeScript',
31
+ * definition: 'A typed superset of JavaScript',
32
+ * category: 'programming',
33
+ * });
34
+ *
35
+ * // Create a skill
36
+ * memory.learnSkill({
37
+ * name: 'git-commit',
38
+ * description: 'Create a git commit',
39
+ * steps: [
40
+ * { action: 'git add .' },
41
+ * { action: 'git commit -m "message"' },
42
+ * ],
43
+ * });
44
+ *
45
+ * // Run consolidation (sleep)
46
+ * await memory.sleep();
47
+ * ```
48
+ */
49
+ export * from './types.js';
50
+ export * from './forgetting.js';
51
+ export * from './cache.js';
52
+ export * from './indexer.js';
53
+ export { EpisodicStore, createEpisodicStore, type CreateEpisodicOptions } from './episodic.js';
54
+ export { SemanticStore, createSemanticStore, type CreateSemanticOptions } from './semantic.js';
55
+ export { ProceduralStore, createProceduralStore, type CreateProceduralOptions } from './procedural.js';
56
+ export { ConsolidationService, createConsolidationService } from './consolidation.js';
57
+ export { CognitiveWorkspace, createCognitiveWorkspace, getCognitiveWorkspace, resetCognitiveWorkspace, type WorkingMemoryItem, type AnticipationContext, type CognitiveWorkspaceConfig, type MemoryReuseMetrics, DEFAULT_WORKSPACE_CONFIG, } from './cognitive-workspace.js';
58
+ import { EpisodicStore, CreateEpisodicOptions } from './episodic.js';
59
+ import { SemanticStore, CreateSemanticOptions } from './semantic.js';
60
+ import { ProceduralStore, CreateProceduralOptions } from './procedural.js';
61
+ import { ConsolidationService } from './consolidation.js';
62
+ import { CognitiveWorkspace, CognitiveWorkspaceConfig, AnticipationContext, WorkingMemoryItem, MemoryReuseMetrics } from './cognitive-workspace.js';
63
+ import { Memory, EpisodicMemory, SemanticMemory, ProceduralMemory, ConsolidationResult, StoreStats } from './types.js';
64
+ import { calculateForgettingStats } from './forgetting.js';
65
+ export interface MemorySystemConfig {
66
+ episodic?: {
67
+ maxSize?: number;
68
+ autoForget?: boolean;
69
+ };
70
+ semantic?: {
71
+ maxSize?: number;
72
+ autoForget?: boolean;
73
+ minConfidence?: number;
74
+ };
75
+ procedural?: {
76
+ maxSize?: number;
77
+ autoForget?: boolean;
78
+ minSuccessRate?: number;
79
+ };
80
+ consolidation?: {
81
+ backgroundIntervalMs?: number;
82
+ autoStart?: boolean;
83
+ };
84
+ workspace?: Partial<CognitiveWorkspaceConfig>;
85
+ }
86
+ /**
87
+ * Unified memory system with episodic, semantic, and procedural stores
88
+ */
89
+ export declare class MemorySystem {
90
+ readonly episodic: EpisodicStore;
91
+ readonly semantic: SemanticStore;
92
+ readonly procedural: ProceduralStore;
93
+ readonly consolidation: ConsolidationService;
94
+ readonly workspace: CognitiveWorkspace;
95
+ constructor(config?: MemorySystemConfig);
96
+ /**
97
+ * Store an episodic memory (event)
98
+ */
99
+ remember(options: CreateEpisodicOptions): EpisodicMemory;
100
+ /**
101
+ * Store a semantic memory (fact)
102
+ */
103
+ learn(options: CreateSemanticOptions): SemanticMemory;
104
+ /**
105
+ * Store a procedural memory (skill)
106
+ */
107
+ learnSkill(options: CreateProceduralOptions): ProceduralMemory;
108
+ /**
109
+ * Anticipate needed memories based on context (Memory 2.0)
110
+ *
111
+ * Uses context cues to predict which memories will be needed,
112
+ * pre-loading them into working memory for fast access.
113
+ */
114
+ anticipate(context: AnticipationContext): Promise<WorkingMemoryItem[]>;
115
+ /**
116
+ * Get currently active memories in working memory (Memory 2.0)
117
+ */
118
+ getActive(): WorkingMemoryItem[];
119
+ /**
120
+ * Get memory reuse metrics (Memory 2.0)
121
+ */
122
+ getReuseMetrics(): MemoryReuseMetrics;
123
+ /**
124
+ * Recall memories by query
125
+ */
126
+ recall(query: string, options?: {
127
+ types?: ('episodic' | 'semantic' | 'procedural')[];
128
+ limit?: number;
129
+ }): Memory[];
130
+ /**
131
+ * Get a specific fact by concept name
132
+ */
133
+ getFact(concept: string): SemanticMemory | undefined;
134
+ /**
135
+ * Get a specific skill by name
136
+ */
137
+ getSkill(name: string): ProceduralMemory | undefined;
138
+ /**
139
+ * Get recent episodes
140
+ */
141
+ getRecentEpisodes(limit?: number): EpisodicMemory[];
142
+ /**
143
+ * Run consolidation (sleep mode)
144
+ */
145
+ sleep(): Promise<ConsolidationResult>;
146
+ /**
147
+ * Run quick background consolidation
148
+ */
149
+ consolidate(): Promise<ConsolidationResult>;
150
+ /**
151
+ * Calculate retention for any memory type
152
+ */
153
+ private getRetention;
154
+ /**
155
+ * Get overall memory statistics
156
+ */
157
+ getStats(): {
158
+ total: number;
159
+ episodic: StoreStats;
160
+ semantic: StoreStats;
161
+ procedural: StoreStats;
162
+ forgetting: {
163
+ episodic: ReturnType<typeof calculateForgettingStats>;
164
+ semantic: ReturnType<typeof calculateForgettingStats>;
165
+ procedural: ReturnType<typeof calculateForgettingStats>;
166
+ };
167
+ consolidation: ReturnType<ConsolidationService['getStats']>;
168
+ workspace: ReturnType<CognitiveWorkspace['getStats']>;
169
+ reuse: MemoryReuseMetrics;
170
+ };
171
+ /**
172
+ * Clear all memories
173
+ */
174
+ clear(): void;
175
+ /**
176
+ * Shutdown the memory system
177
+ */
178
+ shutdown(): void;
179
+ /**
180
+ * Export all memories to JSON
181
+ */
182
+ export(): {
183
+ episodic: EpisodicMemory[];
184
+ semantic: SemanticMemory[];
185
+ procedural: ProceduralMemory[];
186
+ exportedAt: string;
187
+ };
188
+ /**
189
+ * Import memories from JSON
190
+ */
191
+ import(data: {
192
+ episodic?: EpisodicMemory[];
193
+ semantic?: SemanticMemory[];
194
+ procedural?: ProceduralMemory[];
195
+ }): {
196
+ imported: number;
197
+ };
198
+ }
199
+ /**
200
+ * Create a new memory system
201
+ */
202
+ export declare function createMemorySystem(config?: MemorySystemConfig): MemorySystem;
203
+ /**
204
+ * Get or create the global memory system instance
205
+ * v7.0: Consolidation auto-starts by default for real memory behavior
206
+ */
207
+ export declare function getMemorySystem(config?: MemorySystemConfig): MemorySystem;
208
+ /**
209
+ * Reset the global memory system instance
210
+ */
211
+ export declare function resetMemorySystem(): void;