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,497 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Genesis 6.0 - Semantic Memory Store
|
|
4
|
+
*
|
|
5
|
+
* Stores facts and concepts - encyclopedic knowledge.
|
|
6
|
+
* "What things mean, general knowledge"
|
|
7
|
+
*
|
|
8
|
+
* Key features:
|
|
9
|
+
* - Concept hierarchy (superordinates, subordinates)
|
|
10
|
+
* - Category-based organization
|
|
11
|
+
* - Confidence tracking
|
|
12
|
+
* - Contradiction detection
|
|
13
|
+
*
|
|
14
|
+
* Reference: Tulving, E. (1972). Episodic and semantic memory.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.SemanticStore = void 0;
|
|
18
|
+
exports.createSemanticStore = createSemanticStore;
|
|
19
|
+
const crypto_1 = require("crypto");
|
|
20
|
+
const forgetting_js_1 = require("./forgetting.js");
|
|
21
|
+
// ============================================================================
|
|
22
|
+
// Semantic Store
|
|
23
|
+
// ============================================================================
|
|
24
|
+
class SemanticStore {
|
|
25
|
+
memories = new Map();
|
|
26
|
+
config;
|
|
27
|
+
// Indexes for efficient querying
|
|
28
|
+
byConcept = new Map(); // concept name -> id
|
|
29
|
+
byCategory = new Map();
|
|
30
|
+
byTag = new Map();
|
|
31
|
+
hierarchy = new Map(); // parent -> children
|
|
32
|
+
constructor(config = {}) {
|
|
33
|
+
this.config = {
|
|
34
|
+
maxSize: 50000,
|
|
35
|
+
autoForget: true,
|
|
36
|
+
forgetThreshold: forgetting_js_1.FORGETTING_THRESHOLDS.FORGET,
|
|
37
|
+
defaultStability: 30, // Semantic memories are more stable
|
|
38
|
+
minConfidence: 0.3,
|
|
39
|
+
...config,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// ============================================================================
|
|
43
|
+
// Store
|
|
44
|
+
// ============================================================================
|
|
45
|
+
store(input) {
|
|
46
|
+
const now = new Date();
|
|
47
|
+
const id = (0, crypto_1.randomUUID)();
|
|
48
|
+
const memory = {
|
|
49
|
+
...input,
|
|
50
|
+
id,
|
|
51
|
+
created: now,
|
|
52
|
+
lastAccessed: now,
|
|
53
|
+
accessCount: 1,
|
|
54
|
+
};
|
|
55
|
+
// Check for existing concept
|
|
56
|
+
const existingId = this.byConcept.get(memory.content.concept.toLowerCase());
|
|
57
|
+
if (existingId) {
|
|
58
|
+
// Merge with existing
|
|
59
|
+
return this.mergeWith(existingId, memory);
|
|
60
|
+
}
|
|
61
|
+
this.memories.set(id, memory);
|
|
62
|
+
this.updateIndexes(memory);
|
|
63
|
+
this.maintainSize();
|
|
64
|
+
return memory;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Convenience method to create a semantic memory from options
|
|
68
|
+
*/
|
|
69
|
+
createFact(options) {
|
|
70
|
+
const now = new Date();
|
|
71
|
+
const params = (0, forgetting_js_1.calculateInitialParams)({
|
|
72
|
+
importance: options.importance,
|
|
73
|
+
complexity: 0.3, // Facts are generally less complex than episodes
|
|
74
|
+
priorKnowledge: (options.related?.length || 0) > 0,
|
|
75
|
+
});
|
|
76
|
+
// Higher stability for semantic memories
|
|
77
|
+
params.S = this.config.defaultStability;
|
|
78
|
+
return this.store({
|
|
79
|
+
type: 'semantic',
|
|
80
|
+
content: {
|
|
81
|
+
concept: options.concept,
|
|
82
|
+
definition: options.definition,
|
|
83
|
+
properties: options.properties || {},
|
|
84
|
+
},
|
|
85
|
+
category: options.category,
|
|
86
|
+
superordinates: options.superordinates || [],
|
|
87
|
+
subordinates: options.subordinates || [],
|
|
88
|
+
related: options.related || [],
|
|
89
|
+
confidence: options.confidence || 0.8,
|
|
90
|
+
sources: options.sources || [],
|
|
91
|
+
contradictions: [],
|
|
92
|
+
usageCount: 0,
|
|
93
|
+
lastUsed: now,
|
|
94
|
+
R0: params.R0,
|
|
95
|
+
S: params.S,
|
|
96
|
+
importance: options.importance || 0.5,
|
|
97
|
+
emotionalValence: 0, // Facts are neutral
|
|
98
|
+
associations: options.associations || [],
|
|
99
|
+
tags: options.tags || [],
|
|
100
|
+
consolidated: true, // Semantic memories are already consolidated
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Merge new information with existing concept
|
|
105
|
+
*/
|
|
106
|
+
mergeWith(existingId, newMemory) {
|
|
107
|
+
const existing = this.memories.get(existingId);
|
|
108
|
+
if (!existing) {
|
|
109
|
+
return newMemory;
|
|
110
|
+
}
|
|
111
|
+
// Merge properties
|
|
112
|
+
existing.content.properties = {
|
|
113
|
+
...existing.content.properties,
|
|
114
|
+
...newMemory.content.properties,
|
|
115
|
+
};
|
|
116
|
+
// Update definition if new one provided
|
|
117
|
+
if (newMemory.content.definition) {
|
|
118
|
+
existing.content.definition = newMemory.content.definition;
|
|
119
|
+
}
|
|
120
|
+
// Merge relationships
|
|
121
|
+
existing.superordinates = [...new Set([...existing.superordinates, ...newMemory.superordinates])];
|
|
122
|
+
existing.subordinates = [...new Set([...existing.subordinates, ...newMemory.subordinates])];
|
|
123
|
+
existing.related = [...new Set([...existing.related, ...newMemory.related])];
|
|
124
|
+
existing.sources = [...new Set([...existing.sources, ...newMemory.sources])];
|
|
125
|
+
existing.tags = [...new Set([...existing.tags, ...newMemory.tags])];
|
|
126
|
+
// Update confidence (weighted average)
|
|
127
|
+
existing.confidence = (existing.confidence + newMemory.confidence) / 2;
|
|
128
|
+
// Strengthen memory
|
|
129
|
+
existing.S = (0, forgetting_js_1.updateStabilityOnRecall)(existing, true);
|
|
130
|
+
existing.lastAccessed = new Date();
|
|
131
|
+
existing.usageCount++;
|
|
132
|
+
return existing;
|
|
133
|
+
}
|
|
134
|
+
// ============================================================================
|
|
135
|
+
// Get / Update / Delete
|
|
136
|
+
// ============================================================================
|
|
137
|
+
get(id) {
|
|
138
|
+
const memory = this.memories.get(id);
|
|
139
|
+
if (memory) {
|
|
140
|
+
this.accessMemory(memory);
|
|
141
|
+
}
|
|
142
|
+
return memory;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get by concept name
|
|
146
|
+
*/
|
|
147
|
+
getByConcept(concept) {
|
|
148
|
+
const id = this.byConcept.get(concept.toLowerCase());
|
|
149
|
+
if (id) {
|
|
150
|
+
return this.get(id);
|
|
151
|
+
}
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Get without updating access (for internal use)
|
|
156
|
+
*/
|
|
157
|
+
peek(id) {
|
|
158
|
+
return this.memories.get(id);
|
|
159
|
+
}
|
|
160
|
+
update(id, updates) {
|
|
161
|
+
const memory = this.memories.get(id);
|
|
162
|
+
if (!memory)
|
|
163
|
+
return undefined;
|
|
164
|
+
// Remove from indexes before update
|
|
165
|
+
this.removeFromIndexes(memory);
|
|
166
|
+
// Apply updates
|
|
167
|
+
Object.assign(memory, updates);
|
|
168
|
+
// Re-add to indexes
|
|
169
|
+
this.updateIndexes(memory);
|
|
170
|
+
return memory;
|
|
171
|
+
}
|
|
172
|
+
delete(id) {
|
|
173
|
+
const memory = this.memories.get(id);
|
|
174
|
+
if (!memory)
|
|
175
|
+
return false;
|
|
176
|
+
this.removeFromIndexes(memory);
|
|
177
|
+
this.memories.delete(id);
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
// ============================================================================
|
|
181
|
+
// Query
|
|
182
|
+
// ============================================================================
|
|
183
|
+
query(filter) {
|
|
184
|
+
let results = this.getAll();
|
|
185
|
+
if (filter.minImportance !== undefined) {
|
|
186
|
+
results = results.filter((m) => m.importance >= filter.minImportance);
|
|
187
|
+
}
|
|
188
|
+
if (filter.maxAge !== undefined) {
|
|
189
|
+
const cutoff = Date.now() - filter.maxAge * 24 * 60 * 60 * 1000;
|
|
190
|
+
results = results.filter((m) => m.created.getTime() >= cutoff);
|
|
191
|
+
}
|
|
192
|
+
if (filter.minRetention !== undefined) {
|
|
193
|
+
results = results.filter((m) => {
|
|
194
|
+
const retention = (0, forgetting_js_1.calculateRetention)({ R0: m.R0, S: m.S }, m.lastAccessed.getTime());
|
|
195
|
+
return retention >= filter.minRetention;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
if (filter.tags && filter.tags.length > 0) {
|
|
199
|
+
results = results.filter((m) => filter.tags.some((t) => m.tags.includes(t)));
|
|
200
|
+
}
|
|
201
|
+
if (filter.custom) {
|
|
202
|
+
results = results.filter(filter.custom);
|
|
203
|
+
}
|
|
204
|
+
return results;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Search by keyword in concept and definition
|
|
208
|
+
*/
|
|
209
|
+
search(queryStr, limit = 10) {
|
|
210
|
+
const keywords = queryStr.toLowerCase().split(/\s+/);
|
|
211
|
+
const results = this.getAll().filter((m) => {
|
|
212
|
+
const searchable = [
|
|
213
|
+
m.content.concept,
|
|
214
|
+
m.content.definition || '',
|
|
215
|
+
m.category,
|
|
216
|
+
...m.tags,
|
|
217
|
+
].join(' ').toLowerCase();
|
|
218
|
+
return keywords.some((k) => searchable.includes(k));
|
|
219
|
+
});
|
|
220
|
+
// Sort by confidence * retention
|
|
221
|
+
results.sort((a, b) => {
|
|
222
|
+
const scoreA = a.confidence * (0, forgetting_js_1.calculateRetention)({ R0: a.R0, S: a.S }, a.lastAccessed.getTime());
|
|
223
|
+
const scoreB = b.confidence * (0, forgetting_js_1.calculateRetention)({ R0: b.R0, S: b.S }, b.lastAccessed.getTime());
|
|
224
|
+
return scoreB - scoreA;
|
|
225
|
+
});
|
|
226
|
+
return results.slice(0, limit);
|
|
227
|
+
}
|
|
228
|
+
// ============================================================================
|
|
229
|
+
// Category and Hierarchy Queries
|
|
230
|
+
// ============================================================================
|
|
231
|
+
/**
|
|
232
|
+
* Get all facts in a category
|
|
233
|
+
*/
|
|
234
|
+
getByCategory(category) {
|
|
235
|
+
const ids = this.byCategory.get(category);
|
|
236
|
+
if (!ids)
|
|
237
|
+
return [];
|
|
238
|
+
return Array.from(ids)
|
|
239
|
+
.map((id) => this.memories.get(id))
|
|
240
|
+
.filter((m) => m !== undefined);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Get all categories
|
|
244
|
+
*/
|
|
245
|
+
getCategories() {
|
|
246
|
+
return Array.from(this.byCategory.keys());
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Get superordinate concepts (more general)
|
|
250
|
+
*/
|
|
251
|
+
getSuperordinates(id) {
|
|
252
|
+
const memory = this.memories.get(id);
|
|
253
|
+
if (!memory)
|
|
254
|
+
return [];
|
|
255
|
+
return memory.superordinates
|
|
256
|
+
.map((name) => this.getByConcept(name))
|
|
257
|
+
.filter((m) => m !== undefined);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Get subordinate concepts (more specific)
|
|
261
|
+
*/
|
|
262
|
+
getSubordinates(id) {
|
|
263
|
+
const memory = this.memories.get(id);
|
|
264
|
+
if (!memory)
|
|
265
|
+
return [];
|
|
266
|
+
return memory.subordinates
|
|
267
|
+
.map((name) => this.getByConcept(name))
|
|
268
|
+
.filter((m) => m !== undefined);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Get related concepts
|
|
272
|
+
*/
|
|
273
|
+
getRelated(id) {
|
|
274
|
+
const memory = this.memories.get(id);
|
|
275
|
+
if (!memory)
|
|
276
|
+
return [];
|
|
277
|
+
return memory.related
|
|
278
|
+
.map((name) => this.getByConcept(name))
|
|
279
|
+
.filter((m) => m !== undefined);
|
|
280
|
+
}
|
|
281
|
+
// ============================================================================
|
|
282
|
+
// Contradiction Detection
|
|
283
|
+
// ============================================================================
|
|
284
|
+
/**
|
|
285
|
+
* Check if a new fact contradicts existing knowledge
|
|
286
|
+
*/
|
|
287
|
+
findContradictions(concept, properties) {
|
|
288
|
+
const existing = this.getByConcept(concept);
|
|
289
|
+
if (!existing)
|
|
290
|
+
return [];
|
|
291
|
+
const contradictions = [];
|
|
292
|
+
// Check for property conflicts
|
|
293
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
294
|
+
if (existing.content.properties[key] !== undefined &&
|
|
295
|
+
existing.content.properties[key] !== value) {
|
|
296
|
+
contradictions.push(existing);
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return contradictions;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Get all facts with contradictions
|
|
304
|
+
*/
|
|
305
|
+
getContradictedFacts() {
|
|
306
|
+
return this.getAll().filter((m) => m.contradictions && m.contradictions.length > 0);
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Record a contradiction
|
|
310
|
+
*/
|
|
311
|
+
addContradiction(id, contradictingId) {
|
|
312
|
+
const memory = this.memories.get(id);
|
|
313
|
+
if (!memory)
|
|
314
|
+
return;
|
|
315
|
+
if (!memory.contradictions) {
|
|
316
|
+
memory.contradictions = [];
|
|
317
|
+
}
|
|
318
|
+
if (!memory.contradictions.includes(contradictingId)) {
|
|
319
|
+
memory.contradictions.push(contradictingId);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
// ============================================================================
|
|
323
|
+
// Bulk Operations
|
|
324
|
+
// ============================================================================
|
|
325
|
+
getAll() {
|
|
326
|
+
return Array.from(this.memories.values());
|
|
327
|
+
}
|
|
328
|
+
clear() {
|
|
329
|
+
this.memories.clear();
|
|
330
|
+
this.byConcept.clear();
|
|
331
|
+
this.byCategory.clear();
|
|
332
|
+
this.byTag.clear();
|
|
333
|
+
this.hierarchy.clear();
|
|
334
|
+
}
|
|
335
|
+
count() {
|
|
336
|
+
return this.memories.size;
|
|
337
|
+
}
|
|
338
|
+
// ============================================================================
|
|
339
|
+
// Stats
|
|
340
|
+
// ============================================================================
|
|
341
|
+
stats() {
|
|
342
|
+
const all = this.getAll();
|
|
343
|
+
let totalRetention = 0;
|
|
344
|
+
let totalImportance = 0;
|
|
345
|
+
let consolidated = 0;
|
|
346
|
+
let oldest;
|
|
347
|
+
let newest;
|
|
348
|
+
for (const memory of all) {
|
|
349
|
+
totalRetention += (0, forgetting_js_1.calculateRetention)({ R0: memory.R0, S: memory.S }, memory.lastAccessed.getTime());
|
|
350
|
+
totalImportance += memory.importance;
|
|
351
|
+
if (memory.consolidated)
|
|
352
|
+
consolidated++;
|
|
353
|
+
if (!oldest || memory.created < oldest)
|
|
354
|
+
oldest = memory.created;
|
|
355
|
+
if (!newest || memory.created > newest)
|
|
356
|
+
newest = memory.created;
|
|
357
|
+
}
|
|
358
|
+
return {
|
|
359
|
+
total: all.length,
|
|
360
|
+
byType: {
|
|
361
|
+
episodic: 0,
|
|
362
|
+
semantic: all.length,
|
|
363
|
+
procedural: 0,
|
|
364
|
+
},
|
|
365
|
+
consolidated,
|
|
366
|
+
avgRetention: all.length > 0 ? totalRetention / all.length : 0,
|
|
367
|
+
avgImportance: all.length > 0 ? totalImportance / all.length : 0,
|
|
368
|
+
oldestMemory: oldest,
|
|
369
|
+
newestMemory: newest,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Get additional semantic-specific stats
|
|
374
|
+
*/
|
|
375
|
+
semanticStats() {
|
|
376
|
+
const all = this.getAll();
|
|
377
|
+
let totalConfidence = 0;
|
|
378
|
+
let contradictions = 0;
|
|
379
|
+
for (const m of all) {
|
|
380
|
+
totalConfidence += m.confidence;
|
|
381
|
+
if (m.contradictions && m.contradictions.length > 0) {
|
|
382
|
+
contradictions++;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
const mostUsed = [...all]
|
|
386
|
+
.sort((a, b) => b.usageCount - a.usageCount)
|
|
387
|
+
.slice(0, 10);
|
|
388
|
+
return {
|
|
389
|
+
totalFacts: all.length,
|
|
390
|
+
categories: this.byCategory.size,
|
|
391
|
+
avgConfidence: all.length > 0 ? totalConfidence / all.length : 0,
|
|
392
|
+
contradictions,
|
|
393
|
+
mostUsed,
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
// ============================================================================
|
|
397
|
+
// Forgetting Integration
|
|
398
|
+
// ============================================================================
|
|
399
|
+
/**
|
|
400
|
+
* Get facts that should be forgotten (low retention AND low confidence)
|
|
401
|
+
*/
|
|
402
|
+
getForgotten() {
|
|
403
|
+
return this.getAll().filter((m) => {
|
|
404
|
+
const retention = (0, forgetting_js_1.calculateRetention)({ R0: m.R0, S: m.S }, m.lastAccessed.getTime());
|
|
405
|
+
return retention < this.config.forgetThreshold &&
|
|
406
|
+
m.confidence < this.config.minConfidence;
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Run forgetting cycle
|
|
411
|
+
*/
|
|
412
|
+
runForgetting() {
|
|
413
|
+
const toForget = this.getForgotten();
|
|
414
|
+
const ids = toForget.map((m) => m.id);
|
|
415
|
+
for (const id of ids) {
|
|
416
|
+
this.delete(id);
|
|
417
|
+
}
|
|
418
|
+
return { forgotten: ids.length, ids };
|
|
419
|
+
}
|
|
420
|
+
// ============================================================================
|
|
421
|
+
// Private Methods
|
|
422
|
+
// ============================================================================
|
|
423
|
+
accessMemory(memory) {
|
|
424
|
+
memory.lastAccessed = new Date();
|
|
425
|
+
memory.lastUsed = new Date();
|
|
426
|
+
memory.accessCount++;
|
|
427
|
+
memory.usageCount++;
|
|
428
|
+
memory.S = (0, forgetting_js_1.updateStabilityOnRecall)(memory, true);
|
|
429
|
+
}
|
|
430
|
+
updateIndexes(memory) {
|
|
431
|
+
// Concept index
|
|
432
|
+
this.byConcept.set(memory.content.concept.toLowerCase(), memory.id);
|
|
433
|
+
// Category index
|
|
434
|
+
if (!this.byCategory.has(memory.category)) {
|
|
435
|
+
this.byCategory.set(memory.category, new Set());
|
|
436
|
+
}
|
|
437
|
+
this.byCategory.get(memory.category).add(memory.id);
|
|
438
|
+
// Tag index
|
|
439
|
+
for (const tag of memory.tags) {
|
|
440
|
+
if (!this.byTag.has(tag)) {
|
|
441
|
+
this.byTag.set(tag, new Set());
|
|
442
|
+
}
|
|
443
|
+
this.byTag.get(tag).add(memory.id);
|
|
444
|
+
}
|
|
445
|
+
// Hierarchy index
|
|
446
|
+
for (const parent of memory.superordinates) {
|
|
447
|
+
if (!this.hierarchy.has(parent)) {
|
|
448
|
+
this.hierarchy.set(parent, new Set());
|
|
449
|
+
}
|
|
450
|
+
this.hierarchy.get(parent).add(memory.content.concept);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
removeFromIndexes(memory) {
|
|
454
|
+
this.byConcept.delete(memory.content.concept.toLowerCase());
|
|
455
|
+
this.byCategory.get(memory.category)?.delete(memory.id);
|
|
456
|
+
for (const tag of memory.tags) {
|
|
457
|
+
this.byTag.get(tag)?.delete(memory.id);
|
|
458
|
+
}
|
|
459
|
+
for (const parent of memory.superordinates) {
|
|
460
|
+
this.hierarchy.get(parent)?.delete(memory.content.concept);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
maintainSize() {
|
|
464
|
+
if (!this.config.autoForget)
|
|
465
|
+
return;
|
|
466
|
+
if (this.memories.size <= this.config.maxSize)
|
|
467
|
+
return;
|
|
468
|
+
// First, forget low-confidence memories
|
|
469
|
+
this.runForgetting();
|
|
470
|
+
// If still over limit, remove lowest confidence * retention
|
|
471
|
+
while (this.memories.size > this.config.maxSize) {
|
|
472
|
+
let weakest = null;
|
|
473
|
+
let weakestScore = Infinity;
|
|
474
|
+
for (const memory of this.memories.values()) {
|
|
475
|
+
const retention = (0, forgetting_js_1.calculateRetention)({ R0: memory.R0, S: memory.S }, memory.lastAccessed.getTime());
|
|
476
|
+
const score = memory.confidence * retention;
|
|
477
|
+
if (score < weakestScore) {
|
|
478
|
+
weakestScore = score;
|
|
479
|
+
weakest = memory;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
if (weakest) {
|
|
483
|
+
this.delete(weakest.id);
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
break;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
exports.SemanticStore = SemanticStore;
|
|
492
|
+
// ============================================================================
|
|
493
|
+
// Factory
|
|
494
|
+
// ============================================================================
|
|
495
|
+
function createSemanticStore(config) {
|
|
496
|
+
return new SemanticStore(config);
|
|
497
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Genesis 6.0 - Memory Module Types
|
|
3
|
+
*
|
|
4
|
+
* Based on cognitive science memory architecture:
|
|
5
|
+
* - Episodic: Events with when/where/who (autobiographical)
|
|
6
|
+
* - Semantic: Facts and concepts (encyclopedic)
|
|
7
|
+
* - Procedural: Skills and workflows (know-how)
|
|
8
|
+
*
|
|
9
|
+
* References:
|
|
10
|
+
* - Tulving (1972): Episodic vs Semantic distinction
|
|
11
|
+
* - Ebbinghaus (1885): Forgetting curve R = e^(-t/S)
|
|
12
|
+
* - FSRS: Free Spaced Repetition Scheduler
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Memory type classification (Tulving model)
|
|
16
|
+
*/
|
|
17
|
+
export type MemoryType = 'episodic' | 'semantic' | 'procedural';
|
|
18
|
+
/**
|
|
19
|
+
* Base interface for all memory items
|
|
20
|
+
*/
|
|
21
|
+
export interface BaseMemory {
|
|
22
|
+
id: string;
|
|
23
|
+
type: MemoryType;
|
|
24
|
+
created: Date;
|
|
25
|
+
lastAccessed: Date;
|
|
26
|
+
accessCount: number;
|
|
27
|
+
R0: number;
|
|
28
|
+
S: number;
|
|
29
|
+
importance: number;
|
|
30
|
+
emotionalValence: number;
|
|
31
|
+
associations: string[];
|
|
32
|
+
tags: string[];
|
|
33
|
+
consolidated: boolean;
|
|
34
|
+
source?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Episodic memories are events with context
|
|
38
|
+
* "What happened, when, where, who was involved"
|
|
39
|
+
*/
|
|
40
|
+
export interface EpisodicMemory extends BaseMemory {
|
|
41
|
+
type: 'episodic';
|
|
42
|
+
content: {
|
|
43
|
+
what: string;
|
|
44
|
+
details: any;
|
|
45
|
+
};
|
|
46
|
+
when: {
|
|
47
|
+
timestamp: Date;
|
|
48
|
+
duration?: number;
|
|
49
|
+
sequence?: number;
|
|
50
|
+
};
|
|
51
|
+
where?: {
|
|
52
|
+
location: string;
|
|
53
|
+
context: string;
|
|
54
|
+
};
|
|
55
|
+
who?: {
|
|
56
|
+
agents: string[];
|
|
57
|
+
roles: Record<string, string>;
|
|
58
|
+
};
|
|
59
|
+
feeling?: {
|
|
60
|
+
valence: number;
|
|
61
|
+
arousal: number;
|
|
62
|
+
label?: string;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Semantic memories are facts and concepts
|
|
67
|
+
* "What things mean, general knowledge"
|
|
68
|
+
*/
|
|
69
|
+
export interface SemanticMemory extends BaseMemory {
|
|
70
|
+
type: 'semantic';
|
|
71
|
+
content: {
|
|
72
|
+
concept: string;
|
|
73
|
+
definition?: string;
|
|
74
|
+
properties: Record<string, any>;
|
|
75
|
+
};
|
|
76
|
+
category: string;
|
|
77
|
+
superordinates: string[];
|
|
78
|
+
subordinates: string[];
|
|
79
|
+
related: string[];
|
|
80
|
+
confidence: number;
|
|
81
|
+
sources: string[];
|
|
82
|
+
contradictions?: string[];
|
|
83
|
+
usageCount: number;
|
|
84
|
+
lastUsed: Date;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Procedural memories are skills and workflows
|
|
88
|
+
* "How to do things"
|
|
89
|
+
*/
|
|
90
|
+
export interface ProceduralMemory extends BaseMemory {
|
|
91
|
+
type: 'procedural';
|
|
92
|
+
content: {
|
|
93
|
+
name: string;
|
|
94
|
+
description: string;
|
|
95
|
+
steps: ProceduralStep[];
|
|
96
|
+
};
|
|
97
|
+
requires: string[];
|
|
98
|
+
inputs: ParameterDef[];
|
|
99
|
+
outputs: ParameterDef[];
|
|
100
|
+
successRate: number;
|
|
101
|
+
avgDuration: number;
|
|
102
|
+
executionCount: number;
|
|
103
|
+
version: number;
|
|
104
|
+
improvements: string[];
|
|
105
|
+
}
|
|
106
|
+
export interface ProceduralStep {
|
|
107
|
+
order: number;
|
|
108
|
+
action: string;
|
|
109
|
+
params?: Record<string, any>;
|
|
110
|
+
condition?: string;
|
|
111
|
+
fallback?: string;
|
|
112
|
+
}
|
|
113
|
+
export interface ParameterDef {
|
|
114
|
+
name: string;
|
|
115
|
+
type: string;
|
|
116
|
+
required: boolean;
|
|
117
|
+
default?: any;
|
|
118
|
+
description?: string;
|
|
119
|
+
}
|
|
120
|
+
export type Memory = EpisodicMemory | SemanticMemory | ProceduralMemory;
|
|
121
|
+
/**
|
|
122
|
+
* Interface for memory stores
|
|
123
|
+
*/
|
|
124
|
+
export interface IMemoryStore<T extends BaseMemory> {
|
|
125
|
+
store(memory: Omit<T, 'id' | 'created' | 'lastAccessed' | 'accessCount'>): T;
|
|
126
|
+
get(id: string): T | undefined;
|
|
127
|
+
update(id: string, updates: Partial<T>): T | undefined;
|
|
128
|
+
delete(id: string): boolean;
|
|
129
|
+
query(filter: MemoryFilter<T>): T[];
|
|
130
|
+
search(query: string, limit?: number): T[];
|
|
131
|
+
getAll(): T[];
|
|
132
|
+
clear(): void;
|
|
133
|
+
count(): number;
|
|
134
|
+
stats(): StoreStats;
|
|
135
|
+
}
|
|
136
|
+
export interface MemoryFilter<T extends BaseMemory> {
|
|
137
|
+
type?: MemoryType;
|
|
138
|
+
minImportance?: number;
|
|
139
|
+
maxAge?: number;
|
|
140
|
+
minRetention?: number;
|
|
141
|
+
tags?: string[];
|
|
142
|
+
consolidated?: boolean;
|
|
143
|
+
custom?: (memory: T) => boolean;
|
|
144
|
+
}
|
|
145
|
+
export interface StoreStats {
|
|
146
|
+
total: number;
|
|
147
|
+
byType: Record<MemoryType, number>;
|
|
148
|
+
consolidated: number;
|
|
149
|
+
avgRetention: number;
|
|
150
|
+
avgImportance: number;
|
|
151
|
+
oldestMemory?: Date;
|
|
152
|
+
newestMemory?: Date;
|
|
153
|
+
}
|
|
154
|
+
export type ConsolidationMode = 'background' | 'sleep' | 'immediate';
|
|
155
|
+
export interface ConsolidationResult {
|
|
156
|
+
mode: ConsolidationMode;
|
|
157
|
+
timestamp: Date;
|
|
158
|
+
duration: number;
|
|
159
|
+
episodicProcessed: number;
|
|
160
|
+
semanticCreated: number;
|
|
161
|
+
proceduralUpdated: number;
|
|
162
|
+
forgotten: number;
|
|
163
|
+
merged: number;
|
|
164
|
+
newFacts: string[];
|
|
165
|
+
updatedSkills: string[];
|
|
166
|
+
}
|
|
167
|
+
export interface ConsolidationConfig {
|
|
168
|
+
retentionThreshold: number;
|
|
169
|
+
consolidationThreshold: number;
|
|
170
|
+
mergeThreshold: number;
|
|
171
|
+
backgroundIntervalMs: number;
|
|
172
|
+
sleepDurationMs: number;
|
|
173
|
+
maxEpisodicAge: number;
|
|
174
|
+
maxSemanticSize: number;
|
|
175
|
+
}
|
|
176
|
+
export interface ForgettingParams {
|
|
177
|
+
R0: number;
|
|
178
|
+
S: number;
|
|
179
|
+
}
|
|
180
|
+
export interface RetentionResult {
|
|
181
|
+
retention: number;
|
|
182
|
+
elapsedDays: number;
|
|
183
|
+
predictedHalfLife: number;
|
|
184
|
+
shouldForget: boolean;
|
|
185
|
+
}
|
|
186
|
+
export type MemoryEventType = 'STORE' | 'ACCESS' | 'UPDATE' | 'DELETE' | 'CONSOLIDATE' | 'FORGET' | 'MERGE' | 'ASSOCIATE';
|
|
187
|
+
export interface MemoryEvent {
|
|
188
|
+
type: MemoryEventType;
|
|
189
|
+
memoryId: string;
|
|
190
|
+
memoryType: MemoryType;
|
|
191
|
+
timestamp: Date;
|
|
192
|
+
details?: Record<string, any>;
|
|
193
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Genesis 6.0 - Memory Module Types
|
|
4
|
+
*
|
|
5
|
+
* Based on cognitive science memory architecture:
|
|
6
|
+
* - Episodic: Events with when/where/who (autobiographical)
|
|
7
|
+
* - Semantic: Facts and concepts (encyclopedic)
|
|
8
|
+
* - Procedural: Skills and workflows (know-how)
|
|
9
|
+
*
|
|
10
|
+
* References:
|
|
11
|
+
* - Tulving (1972): Episodic vs Semantic distinction
|
|
12
|
+
* - Ebbinghaus (1885): Forgetting curve R = e^(-t/S)
|
|
13
|
+
* - FSRS: Free Spaced Repetition Scheduler
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|