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.
- package/.env.example +78 -0
- package/README.md +282 -0
- package/dist/src/active-inference/actions.d.ts +75 -0
- package/dist/src/active-inference/actions.js +250 -0
- package/dist/src/active-inference/autonomous-loop.d.ts +103 -0
- package/dist/src/active-inference/autonomous-loop.js +289 -0
- package/dist/src/active-inference/core.d.ts +85 -0
- package/dist/src/active-inference/core.js +555 -0
- package/dist/src/active-inference/demo-autonomous-loop.d.ts +8 -0
- package/dist/src/active-inference/demo-autonomous-loop.js +338 -0
- package/dist/src/active-inference/demo-value-integration.d.ts +8 -0
- package/dist/src/active-inference/demo-value-integration.js +174 -0
- package/dist/src/active-inference/index.d.ts +32 -0
- package/dist/src/active-inference/index.js +88 -0
- package/dist/src/active-inference/integration.d.ts +114 -0
- package/dist/src/active-inference/integration.js +698 -0
- package/dist/src/active-inference/memory-integration.d.ts +51 -0
- package/dist/src/active-inference/memory-integration.js +232 -0
- package/dist/src/active-inference/observations.d.ts +67 -0
- package/dist/src/active-inference/observations.js +147 -0
- package/dist/src/active-inference/test-active-inference.d.ts +8 -0
- package/dist/src/active-inference/test-active-inference.js +320 -0
- package/dist/src/active-inference/test-value-integration.d.ts +6 -0
- package/dist/src/active-inference/test-value-integration.js +168 -0
- package/dist/src/active-inference/types.d.ts +150 -0
- package/dist/src/active-inference/types.js +59 -0
- package/dist/src/active-inference/value-integration.d.ts +164 -0
- package/dist/src/active-inference/value-integration.js +459 -0
- package/dist/src/agents/base-agent.d.ts +53 -0
- package/dist/src/agents/base-agent.js +178 -0
- package/dist/src/agents/builder.d.ts +67 -0
- package/dist/src/agents/builder.js +537 -0
- package/dist/src/agents/critic.d.ts +35 -0
- package/dist/src/agents/critic.js +322 -0
- package/dist/src/agents/ethicist.d.ts +54 -0
- package/dist/src/agents/ethicist.js +393 -0
- package/dist/src/agents/explorer.d.ts +26 -0
- package/dist/src/agents/explorer.js +216 -0
- package/dist/src/agents/feeling.d.ts +41 -0
- package/dist/src/agents/feeling.js +320 -0
- package/dist/src/agents/index.d.ts +111 -0
- package/dist/src/agents/index.js +222 -0
- package/dist/src/agents/memory.d.ts +69 -0
- package/dist/src/agents/memory.js +404 -0
- package/dist/src/agents/message-bus.d.ts +88 -0
- package/dist/src/agents/message-bus.js +267 -0
- package/dist/src/agents/narrator.d.ts +90 -0
- package/dist/src/agents/narrator.js +473 -0
- package/dist/src/agents/planner.d.ts +38 -0
- package/dist/src/agents/planner.js +341 -0
- package/dist/src/agents/predictor.d.ts +73 -0
- package/dist/src/agents/predictor.js +506 -0
- package/dist/src/agents/sensor.d.ts +88 -0
- package/dist/src/agents/sensor.js +377 -0
- package/dist/src/agents/test-agents.d.ts +6 -0
- package/dist/src/agents/test-agents.js +73 -0
- package/dist/src/agents/types.d.ts +194 -0
- package/dist/src/agents/types.js +7 -0
- package/dist/src/brain/index.d.ts +185 -0
- package/dist/src/brain/index.js +843 -0
- package/dist/src/brain/trace.d.ts +91 -0
- package/dist/src/brain/trace.js +327 -0
- package/dist/src/brain/types.d.ts +165 -0
- package/dist/src/brain/types.js +51 -0
- package/dist/src/cli/chat.d.ts +237 -0
- package/dist/src/cli/chat.js +1959 -0
- package/dist/src/cli/dispatcher.d.ts +182 -0
- package/dist/src/cli/dispatcher.js +718 -0
- package/dist/src/cli/human-loop.d.ts +170 -0
- package/dist/src/cli/human-loop.js +543 -0
- package/dist/src/cli/index.d.ts +12 -0
- package/dist/src/cli/index.js +28 -0
- package/dist/src/cli/interactive.d.ts +141 -0
- package/dist/src/cli/interactive.js +757 -0
- package/dist/src/cli/ui.d.ts +205 -0
- package/dist/src/cli/ui.js +632 -0
- package/dist/src/consciousness/attention-schema.d.ts +154 -0
- package/dist/src/consciousness/attention-schema.js +432 -0
- package/dist/src/consciousness/global-workspace.d.ts +149 -0
- package/dist/src/consciousness/global-workspace.js +422 -0
- package/dist/src/consciousness/index.d.ts +186 -0
- package/dist/src/consciousness/index.js +476 -0
- package/dist/src/consciousness/phi-calculator.d.ts +119 -0
- package/dist/src/consciousness/phi-calculator.js +445 -0
- package/dist/src/consciousness/phi-decisions.d.ts +169 -0
- package/dist/src/consciousness/phi-decisions.js +383 -0
- package/dist/src/consciousness/phi-monitor.d.ts +153 -0
- package/dist/src/consciousness/phi-monitor.js +465 -0
- package/dist/src/consciousness/types.d.ts +260 -0
- package/dist/src/consciousness/types.js +44 -0
- package/dist/src/daemon/dream-mode.d.ts +115 -0
- package/dist/src/daemon/dream-mode.js +470 -0
- package/dist/src/daemon/index.d.ts +162 -0
- package/dist/src/daemon/index.js +542 -0
- package/dist/src/daemon/maintenance.d.ts +139 -0
- package/dist/src/daemon/maintenance.js +549 -0
- package/dist/src/daemon/process.d.ts +82 -0
- package/dist/src/daemon/process.js +442 -0
- package/dist/src/daemon/scheduler.d.ts +90 -0
- package/dist/src/daemon/scheduler.js +494 -0
- package/dist/src/daemon/types.d.ts +213 -0
- package/dist/src/daemon/types.js +50 -0
- package/dist/src/epistemic/index.d.ts +74 -0
- package/dist/src/epistemic/index.js +225 -0
- package/dist/src/grounding/epistemic-stack.d.ts +100 -0
- package/dist/src/grounding/epistemic-stack.js +408 -0
- package/dist/src/grounding/feedback.d.ts +98 -0
- package/dist/src/grounding/feedback.js +276 -0
- package/dist/src/grounding/index.d.ts +123 -0
- package/dist/src/grounding/index.js +224 -0
- package/dist/src/grounding/verifier.d.ts +149 -0
- package/dist/src/grounding/verifier.js +484 -0
- package/dist/src/healing/detector.d.ts +110 -0
- package/dist/src/healing/detector.js +436 -0
- package/dist/src/healing/fixer.d.ts +138 -0
- package/dist/src/healing/fixer.js +572 -0
- package/dist/src/healing/index.d.ts +23 -0
- package/dist/src/healing/index.js +43 -0
- package/dist/src/hooks/index.d.ts +135 -0
- package/dist/src/hooks/index.js +317 -0
- package/dist/src/index.d.ts +23 -0
- package/dist/src/index.js +1266 -0
- package/dist/src/kernel/index.d.ts +155 -0
- package/dist/src/kernel/index.js +795 -0
- package/dist/src/kernel/invariants.d.ts +153 -0
- package/dist/src/kernel/invariants.js +355 -0
- package/dist/src/kernel/test-kernel.d.ts +6 -0
- package/dist/src/kernel/test-kernel.js +108 -0
- package/dist/src/kernel/test-real-mcp.d.ts +10 -0
- package/dist/src/kernel/test-real-mcp.js +295 -0
- package/dist/src/llm/index.d.ts +146 -0
- package/dist/src/llm/index.js +428 -0
- package/dist/src/llm/router.d.ts +136 -0
- package/dist/src/llm/router.js +510 -0
- package/dist/src/mcp/index.d.ts +85 -0
- package/dist/src/mcp/index.js +657 -0
- package/dist/src/mcp/resilient.d.ts +139 -0
- package/dist/src/mcp/resilient.js +417 -0
- package/dist/src/memory/cache.d.ts +118 -0
- package/dist/src/memory/cache.js +356 -0
- package/dist/src/memory/cognitive-workspace.d.ts +231 -0
- package/dist/src/memory/cognitive-workspace.js +521 -0
- package/dist/src/memory/consolidation.d.ts +99 -0
- package/dist/src/memory/consolidation.js +443 -0
- package/dist/src/memory/episodic.d.ts +114 -0
- package/dist/src/memory/episodic.js +394 -0
- package/dist/src/memory/forgetting.d.ts +134 -0
- package/dist/src/memory/forgetting.js +324 -0
- package/dist/src/memory/index.d.ts +211 -0
- package/dist/src/memory/index.js +367 -0
- package/dist/src/memory/indexer.d.ts +123 -0
- package/dist/src/memory/indexer.js +479 -0
- package/dist/src/memory/procedural.d.ts +136 -0
- package/dist/src/memory/procedural.js +479 -0
- package/dist/src/memory/semantic.d.ts +132 -0
- package/dist/src/memory/semantic.js +497 -0
- package/dist/src/memory/types.d.ts +193 -0
- package/dist/src/memory/types.js +15 -0
- package/dist/src/orchestrator.d.ts +65 -0
- package/dist/src/orchestrator.js +317 -0
- package/dist/src/persistence/index.d.ts +257 -0
- package/dist/src/persistence/index.js +763 -0
- package/dist/src/pipeline/executor.d.ts +51 -0
- package/dist/src/pipeline/executor.js +695 -0
- package/dist/src/pipeline/index.d.ts +7 -0
- package/dist/src/pipeline/index.js +11 -0
- package/dist/src/self-production.d.ts +67 -0
- package/dist/src/self-production.js +205 -0
- package/dist/src/subagents/executor.d.ts +58 -0
- package/dist/src/subagents/executor.js +283 -0
- package/dist/src/subagents/index.d.ts +37 -0
- package/dist/src/subagents/index.js +53 -0
- package/dist/src/subagents/registry.d.ts +23 -0
- package/dist/src/subagents/registry.js +167 -0
- package/dist/src/subagents/types.d.ts +79 -0
- package/dist/src/subagents/types.js +14 -0
- package/dist/src/tools/bash.d.ts +139 -0
- package/dist/src/tools/bash.js +583 -0
- package/dist/src/tools/edit.d.ts +125 -0
- package/dist/src/tools/edit.js +424 -0
- package/dist/src/tools/git.d.ts +179 -0
- package/dist/src/tools/git.js +504 -0
- package/dist/src/tools/index.d.ts +21 -0
- package/dist/src/tools/index.js +163 -0
- package/dist/src/types.d.ts +145 -0
- package/dist/src/types.js +7 -0
- package/dist/src/world-model/decoder.d.ts +163 -0
- package/dist/src/world-model/decoder.js +517 -0
- package/dist/src/world-model/digital-twin.d.ts +219 -0
- package/dist/src/world-model/digital-twin.js +695 -0
- package/dist/src/world-model/encoder.d.ts +141 -0
- package/dist/src/world-model/encoder.js +564 -0
- package/dist/src/world-model/index.d.ts +221 -0
- package/dist/src/world-model/index.js +772 -0
- package/dist/src/world-model/predictor.d.ts +161 -0
- package/dist/src/world-model/predictor.js +681 -0
- package/dist/src/world-model/test-value-jepa.d.ts +8 -0
- package/dist/src/world-model/test-value-jepa.js +430 -0
- package/dist/src/world-model/types.d.ts +341 -0
- package/dist/src/world-model/types.js +69 -0
- package/dist/src/world-model/value-jepa.d.ts +247 -0
- package/dist/src/world-model/value-jepa.js +622 -0
- package/dist/test/brain.test.d.ts +11 -0
- package/dist/test/brain.test.js +358 -0
- package/dist/test/cli/dispatcher.test.d.ts +4 -0
- package/dist/test/cli/dispatcher.test.js +332 -0
- package/dist/test/cli/human-loop.test.d.ts +4 -0
- package/dist/test/cli/human-loop.test.js +270 -0
- package/dist/test/grounding/feedback.test.d.ts +4 -0
- package/dist/test/grounding/feedback.test.js +462 -0
- package/dist/test/grounding/verifier.test.d.ts +4 -0
- package/dist/test/grounding/verifier.test.js +442 -0
- package/dist/test/grounding.test.d.ts +6 -0
- package/dist/test/grounding.test.js +246 -0
- package/dist/test/healing/detector.test.d.ts +4 -0
- package/dist/test/healing/detector.test.js +266 -0
- package/dist/test/healing/fixer.test.d.ts +4 -0
- package/dist/test/healing/fixer.test.js +369 -0
- package/dist/test/integration.test.d.ts +5 -0
- package/dist/test/integration.test.js +290 -0
- package/dist/test/tools/bash.test.d.ts +4 -0
- package/dist/test/tools/bash.test.js +348 -0
- package/dist/test/tools/edit.test.d.ts +4 -0
- package/dist/test/tools/edit.test.js +350 -0
- package/dist/test/tools/git.test.d.ts +4 -0
- package/dist/test/tools/git.test.js +350 -0
- 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
|
+
};
|