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,367 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Genesis 6.0 - Memory Module
|
|
4
|
+
*
|
|
5
|
+
* Unified memory system based on cognitive science:
|
|
6
|
+
* - Episodic: Events with context (what/when/where/who)
|
|
7
|
+
* - Semantic: Facts and concepts (knowledge)
|
|
8
|
+
* - Procedural: Skills and workflows (know-how)
|
|
9
|
+
*
|
|
10
|
+
* Features:
|
|
11
|
+
* - Ebbinghaus forgetting curve
|
|
12
|
+
* - Sleep-based consolidation (episodic → semantic)
|
|
13
|
+
* - Pattern extraction
|
|
14
|
+
* - Skill learning
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { createMemorySystem } from './memory/index.js';
|
|
19
|
+
*
|
|
20
|
+
* const memory = createMemorySystem();
|
|
21
|
+
*
|
|
22
|
+
* // Store an episode
|
|
23
|
+
* memory.remember({
|
|
24
|
+
* what: 'User asked about AI',
|
|
25
|
+
* when: new Date(),
|
|
26
|
+
* tags: ['conversation', 'AI'],
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Create a fact
|
|
30
|
+
* memory.learn({
|
|
31
|
+
* concept: 'TypeScript',
|
|
32
|
+
* definition: 'A typed superset of JavaScript',
|
|
33
|
+
* category: 'programming',
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* // Create a skill
|
|
37
|
+
* memory.learnSkill({
|
|
38
|
+
* name: 'git-commit',
|
|
39
|
+
* description: 'Create a git commit',
|
|
40
|
+
* steps: [
|
|
41
|
+
* { action: 'git add .' },
|
|
42
|
+
* { action: 'git commit -m "message"' },
|
|
43
|
+
* ],
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* // Run consolidation (sleep)
|
|
47
|
+
* await memory.sleep();
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
51
|
+
if (k2 === undefined) k2 = k;
|
|
52
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
53
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
54
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
55
|
+
}
|
|
56
|
+
Object.defineProperty(o, k2, desc);
|
|
57
|
+
}) : (function(o, m, k, k2) {
|
|
58
|
+
if (k2 === undefined) k2 = k;
|
|
59
|
+
o[k2] = m[k];
|
|
60
|
+
}));
|
|
61
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
62
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.MemorySystem = exports.DEFAULT_WORKSPACE_CONFIG = exports.resetCognitiveWorkspace = exports.getCognitiveWorkspace = exports.createCognitiveWorkspace = exports.CognitiveWorkspace = exports.createConsolidationService = exports.ConsolidationService = exports.createProceduralStore = exports.ProceduralStore = exports.createSemanticStore = exports.SemanticStore = exports.createEpisodicStore = exports.EpisodicStore = void 0;
|
|
66
|
+
exports.createMemorySystem = createMemorySystem;
|
|
67
|
+
exports.getMemorySystem = getMemorySystem;
|
|
68
|
+
exports.resetMemorySystem = resetMemorySystem;
|
|
69
|
+
// Re-export types
|
|
70
|
+
__exportStar(require("./types.js"), exports);
|
|
71
|
+
// Re-export modules
|
|
72
|
+
__exportStar(require("./forgetting.js"), exports);
|
|
73
|
+
// Re-export Phase 8: Local-First modules
|
|
74
|
+
__exportStar(require("./cache.js"), exports);
|
|
75
|
+
__exportStar(require("./indexer.js"), exports);
|
|
76
|
+
var episodic_js_1 = require("./episodic.js");
|
|
77
|
+
Object.defineProperty(exports, "EpisodicStore", { enumerable: true, get: function () { return episodic_js_1.EpisodicStore; } });
|
|
78
|
+
Object.defineProperty(exports, "createEpisodicStore", { enumerable: true, get: function () { return episodic_js_1.createEpisodicStore; } });
|
|
79
|
+
var semantic_js_1 = require("./semantic.js");
|
|
80
|
+
Object.defineProperty(exports, "SemanticStore", { enumerable: true, get: function () { return semantic_js_1.SemanticStore; } });
|
|
81
|
+
Object.defineProperty(exports, "createSemanticStore", { enumerable: true, get: function () { return semantic_js_1.createSemanticStore; } });
|
|
82
|
+
var procedural_js_1 = require("./procedural.js");
|
|
83
|
+
Object.defineProperty(exports, "ProceduralStore", { enumerable: true, get: function () { return procedural_js_1.ProceduralStore; } });
|
|
84
|
+
Object.defineProperty(exports, "createProceduralStore", { enumerable: true, get: function () { return procedural_js_1.createProceduralStore; } });
|
|
85
|
+
var consolidation_js_1 = require("./consolidation.js");
|
|
86
|
+
Object.defineProperty(exports, "ConsolidationService", { enumerable: true, get: function () { return consolidation_js_1.ConsolidationService; } });
|
|
87
|
+
Object.defineProperty(exports, "createConsolidationService", { enumerable: true, get: function () { return consolidation_js_1.createConsolidationService; } });
|
|
88
|
+
// Re-export Memory 2.0 - Cognitive Workspace
|
|
89
|
+
var cognitive_workspace_js_1 = require("./cognitive-workspace.js");
|
|
90
|
+
Object.defineProperty(exports, "CognitiveWorkspace", { enumerable: true, get: function () { return cognitive_workspace_js_1.CognitiveWorkspace; } });
|
|
91
|
+
Object.defineProperty(exports, "createCognitiveWorkspace", { enumerable: true, get: function () { return cognitive_workspace_js_1.createCognitiveWorkspace; } });
|
|
92
|
+
Object.defineProperty(exports, "getCognitiveWorkspace", { enumerable: true, get: function () { return cognitive_workspace_js_1.getCognitiveWorkspace; } });
|
|
93
|
+
Object.defineProperty(exports, "resetCognitiveWorkspace", { enumerable: true, get: function () { return cognitive_workspace_js_1.resetCognitiveWorkspace; } });
|
|
94
|
+
Object.defineProperty(exports, "DEFAULT_WORKSPACE_CONFIG", { enumerable: true, get: function () { return cognitive_workspace_js_1.DEFAULT_WORKSPACE_CONFIG; } });
|
|
95
|
+
const episodic_js_2 = require("./episodic.js");
|
|
96
|
+
const semantic_js_2 = require("./semantic.js");
|
|
97
|
+
const procedural_js_2 = require("./procedural.js");
|
|
98
|
+
const consolidation_js_2 = require("./consolidation.js");
|
|
99
|
+
const cognitive_workspace_js_2 = require("./cognitive-workspace.js");
|
|
100
|
+
const forgetting_js_1 = require("./forgetting.js");
|
|
101
|
+
// ============================================================================
|
|
102
|
+
// Unified Memory System
|
|
103
|
+
// ============================================================================
|
|
104
|
+
/**
|
|
105
|
+
* Unified memory system with episodic, semantic, and procedural stores
|
|
106
|
+
*/
|
|
107
|
+
class MemorySystem {
|
|
108
|
+
episodic;
|
|
109
|
+
semantic;
|
|
110
|
+
procedural;
|
|
111
|
+
consolidation;
|
|
112
|
+
workspace; // Memory 2.0
|
|
113
|
+
constructor(config = {}) {
|
|
114
|
+
this.episodic = (0, episodic_js_2.createEpisodicStore)(config.episodic);
|
|
115
|
+
this.semantic = (0, semantic_js_2.createSemanticStore)(config.semantic);
|
|
116
|
+
this.procedural = (0, procedural_js_2.createProceduralStore)(config.procedural);
|
|
117
|
+
this.consolidation = (0, consolidation_js_2.createConsolidationService)(this.episodic, this.semantic, this.procedural, config.consolidation);
|
|
118
|
+
// Memory 2.0: Create cognitive workspace
|
|
119
|
+
this.workspace = (0, cognitive_workspace_js_2.createCognitiveWorkspace)(config.workspace);
|
|
120
|
+
// Connect workspace to stores
|
|
121
|
+
this.workspace.connectStores({
|
|
122
|
+
episodic: {
|
|
123
|
+
search: (q, l) => this.episodic.search(q, l),
|
|
124
|
+
get: (id) => this.episodic.get(id),
|
|
125
|
+
},
|
|
126
|
+
semantic: {
|
|
127
|
+
search: (q, l) => this.semantic.search(q, l),
|
|
128
|
+
getByConcept: (c) => this.semantic.getByConcept(c),
|
|
129
|
+
},
|
|
130
|
+
procedural: {
|
|
131
|
+
search: (q, l) => this.procedural.search(q, l),
|
|
132
|
+
getByName: (n) => this.procedural.getByName(n),
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
// Auto-start background consolidation if configured
|
|
136
|
+
if (config.consolidation?.autoStart) {
|
|
137
|
+
this.consolidation.startBackground();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// ============================================================================
|
|
141
|
+
// High-Level API
|
|
142
|
+
// ============================================================================
|
|
143
|
+
/**
|
|
144
|
+
* Store an episodic memory (event)
|
|
145
|
+
*/
|
|
146
|
+
remember(options) {
|
|
147
|
+
return this.episodic.createEpisode(options);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Store a semantic memory (fact)
|
|
151
|
+
*/
|
|
152
|
+
learn(options) {
|
|
153
|
+
return this.semantic.createFact(options);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Store a procedural memory (skill)
|
|
157
|
+
*/
|
|
158
|
+
learnSkill(options) {
|
|
159
|
+
return this.procedural.createSkill(options);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Anticipate needed memories based on context (Memory 2.0)
|
|
163
|
+
*
|
|
164
|
+
* Uses context cues to predict which memories will be needed,
|
|
165
|
+
* pre-loading them into working memory for fast access.
|
|
166
|
+
*/
|
|
167
|
+
async anticipate(context) {
|
|
168
|
+
return this.workspace.anticipate(context);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Get currently active memories in working memory (Memory 2.0)
|
|
172
|
+
*/
|
|
173
|
+
getActive() {
|
|
174
|
+
return this.workspace.getActive();
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Get memory reuse metrics (Memory 2.0)
|
|
178
|
+
*/
|
|
179
|
+
getReuseMetrics() {
|
|
180
|
+
return this.workspace.getMetrics();
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Recall memories by query
|
|
184
|
+
*/
|
|
185
|
+
recall(query, options = {}) {
|
|
186
|
+
const types = options.types || ['episodic', 'semantic', 'procedural'];
|
|
187
|
+
const limit = options.limit || 10;
|
|
188
|
+
const results = [];
|
|
189
|
+
if (types.includes('episodic')) {
|
|
190
|
+
results.push(...this.episodic.search(query, limit));
|
|
191
|
+
}
|
|
192
|
+
if (types.includes('semantic')) {
|
|
193
|
+
results.push(...this.semantic.search(query, limit));
|
|
194
|
+
}
|
|
195
|
+
if (types.includes('procedural')) {
|
|
196
|
+
results.push(...this.procedural.search(query, limit));
|
|
197
|
+
}
|
|
198
|
+
// Sort by retention and return top results
|
|
199
|
+
return results
|
|
200
|
+
.sort((a, b) => {
|
|
201
|
+
const retA = this.getRetention(a);
|
|
202
|
+
const retB = this.getRetention(b);
|
|
203
|
+
return retB - retA;
|
|
204
|
+
})
|
|
205
|
+
.slice(0, limit);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Get a specific fact by concept name
|
|
209
|
+
*/
|
|
210
|
+
getFact(concept) {
|
|
211
|
+
return this.semantic.getByConcept(concept);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Get a specific skill by name
|
|
215
|
+
*/
|
|
216
|
+
getSkill(name) {
|
|
217
|
+
return this.procedural.getByName(name);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Get recent episodes
|
|
221
|
+
*/
|
|
222
|
+
getRecentEpisodes(limit = 10) {
|
|
223
|
+
return this.episodic.getRecent(limit);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Run consolidation (sleep mode)
|
|
227
|
+
*/
|
|
228
|
+
async sleep() {
|
|
229
|
+
return this.consolidation.sleep();
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Run quick background consolidation
|
|
233
|
+
*/
|
|
234
|
+
async consolidate() {
|
|
235
|
+
return this.consolidation.backgroundConsolidate();
|
|
236
|
+
}
|
|
237
|
+
// ============================================================================
|
|
238
|
+
// Utility Methods
|
|
239
|
+
// ============================================================================
|
|
240
|
+
/**
|
|
241
|
+
* Calculate retention for any memory type
|
|
242
|
+
*/
|
|
243
|
+
getRetention(memory) {
|
|
244
|
+
const elapsed = Date.now() - memory.lastAccessed.getTime();
|
|
245
|
+
const elapsedDays = elapsed / (1000 * 60 * 60 * 24);
|
|
246
|
+
return memory.R0 * Math.exp(-elapsedDays / memory.S);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Get overall memory statistics
|
|
250
|
+
*/
|
|
251
|
+
getStats() {
|
|
252
|
+
const episodicStats = this.episodic.stats();
|
|
253
|
+
const semanticStats = this.semantic.stats();
|
|
254
|
+
const proceduralStats = this.procedural.stats();
|
|
255
|
+
return {
|
|
256
|
+
total: episodicStats.total + semanticStats.total + proceduralStats.total,
|
|
257
|
+
episodic: episodicStats,
|
|
258
|
+
semantic: semanticStats,
|
|
259
|
+
procedural: proceduralStats,
|
|
260
|
+
forgetting: {
|
|
261
|
+
episodic: (0, forgetting_js_1.calculateForgettingStats)(this.episodic.getAll()),
|
|
262
|
+
semantic: (0, forgetting_js_1.calculateForgettingStats)(this.semantic.getAll()),
|
|
263
|
+
procedural: (0, forgetting_js_1.calculateForgettingStats)(this.procedural.getAll()),
|
|
264
|
+
},
|
|
265
|
+
consolidation: this.consolidation.getStats(),
|
|
266
|
+
workspace: this.workspace.getStats(), // Memory 2.0
|
|
267
|
+
reuse: this.workspace.getMetrics(), // Memory 2.0
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Clear all memories
|
|
272
|
+
*/
|
|
273
|
+
clear() {
|
|
274
|
+
this.episodic.clear();
|
|
275
|
+
this.semantic.clear();
|
|
276
|
+
this.procedural.clear();
|
|
277
|
+
this.workspace.clear(); // Memory 2.0
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Shutdown the memory system
|
|
281
|
+
*/
|
|
282
|
+
shutdown() {
|
|
283
|
+
this.consolidation.stopBackground();
|
|
284
|
+
this.workspace.shutdown(); // Memory 2.0
|
|
285
|
+
}
|
|
286
|
+
// ============================================================================
|
|
287
|
+
// Import/Export
|
|
288
|
+
// ============================================================================
|
|
289
|
+
/**
|
|
290
|
+
* Export all memories to JSON
|
|
291
|
+
*/
|
|
292
|
+
export() {
|
|
293
|
+
return {
|
|
294
|
+
episodic: this.episodic.getAll(),
|
|
295
|
+
semantic: this.semantic.getAll(),
|
|
296
|
+
procedural: this.procedural.getAll(),
|
|
297
|
+
exportedAt: new Date().toISOString(),
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Import memories from JSON
|
|
302
|
+
*/
|
|
303
|
+
import(data) {
|
|
304
|
+
let imported = 0;
|
|
305
|
+
if (data.episodic) {
|
|
306
|
+
for (const memory of data.episodic) {
|
|
307
|
+
this.episodic.store(memory);
|
|
308
|
+
imported++;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (data.semantic) {
|
|
312
|
+
for (const memory of data.semantic) {
|
|
313
|
+
this.semantic.store(memory);
|
|
314
|
+
imported++;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (data.procedural) {
|
|
318
|
+
for (const memory of data.procedural) {
|
|
319
|
+
this.procedural.store(memory);
|
|
320
|
+
imported++;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return { imported };
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
exports.MemorySystem = MemorySystem;
|
|
327
|
+
// ============================================================================
|
|
328
|
+
// Factory
|
|
329
|
+
// ============================================================================
|
|
330
|
+
/**
|
|
331
|
+
* Create a new memory system
|
|
332
|
+
*/
|
|
333
|
+
function createMemorySystem(config) {
|
|
334
|
+
return new MemorySystem(config);
|
|
335
|
+
}
|
|
336
|
+
// ============================================================================
|
|
337
|
+
// Singleton Instance (optional)
|
|
338
|
+
// ============================================================================
|
|
339
|
+
let memorySystemInstance = null;
|
|
340
|
+
/**
|
|
341
|
+
* Get or create the global memory system instance
|
|
342
|
+
* v7.0: Consolidation auto-starts by default for real memory behavior
|
|
343
|
+
*/
|
|
344
|
+
function getMemorySystem(config) {
|
|
345
|
+
if (!memorySystemInstance) {
|
|
346
|
+
// v7.0: Default to autoStart for consolidation
|
|
347
|
+
const configWithDefaults = {
|
|
348
|
+
...config,
|
|
349
|
+
consolidation: {
|
|
350
|
+
autoStart: true, // v7.0: Enable consolidation by default
|
|
351
|
+
backgroundIntervalMs: 10 * 60 * 1000, // 10 minutes
|
|
352
|
+
...config?.consolidation,
|
|
353
|
+
},
|
|
354
|
+
};
|
|
355
|
+
memorySystemInstance = createMemorySystem(configWithDefaults);
|
|
356
|
+
}
|
|
357
|
+
return memorySystemInstance;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Reset the global memory system instance
|
|
361
|
+
*/
|
|
362
|
+
function resetMemorySystem() {
|
|
363
|
+
if (memorySystemInstance) {
|
|
364
|
+
memorySystemInstance.shutdown();
|
|
365
|
+
memorySystemInstance = null;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Genesis 6.8 - Project Indexer
|
|
3
|
+
*
|
|
4
|
+
* Indexes project files for local full-text search.
|
|
5
|
+
* No LLM needed for code search - instant results.
|
|
6
|
+
*
|
|
7
|
+
* Uses JSON storage with in-memory trigram index for fast search.
|
|
8
|
+
*/
|
|
9
|
+
export interface IndexedFile {
|
|
10
|
+
/** Relative path from project root */
|
|
11
|
+
path: string;
|
|
12
|
+
/** File content */
|
|
13
|
+
content: string;
|
|
14
|
+
/** Content hash for change detection */
|
|
15
|
+
hash: string;
|
|
16
|
+
/** File size in bytes */
|
|
17
|
+
size: number;
|
|
18
|
+
/** Last modified timestamp */
|
|
19
|
+
mtime: number;
|
|
20
|
+
/** Language/type */
|
|
21
|
+
language: string;
|
|
22
|
+
/** Line count */
|
|
23
|
+
lines: number;
|
|
24
|
+
/** Extracted symbols (functions, classes, etc.) */
|
|
25
|
+
symbols: string[];
|
|
26
|
+
}
|
|
27
|
+
export interface SearchResult {
|
|
28
|
+
/** File path */
|
|
29
|
+
path: string;
|
|
30
|
+
/** Matching lines with context */
|
|
31
|
+
matches: Array<{
|
|
32
|
+
line: number;
|
|
33
|
+
content: string;
|
|
34
|
+
context: string[];
|
|
35
|
+
}>;
|
|
36
|
+
/** Relevance score */
|
|
37
|
+
score: number;
|
|
38
|
+
}
|
|
39
|
+
export interface IndexStats {
|
|
40
|
+
totalFiles: number;
|
|
41
|
+
totalLines: number;
|
|
42
|
+
totalBytes: number;
|
|
43
|
+
languages: Record<string, number>;
|
|
44
|
+
lastIndexed: number;
|
|
45
|
+
indexPath: string;
|
|
46
|
+
}
|
|
47
|
+
export interface IndexerConfig {
|
|
48
|
+
/** Project root directory */
|
|
49
|
+
projectRoot: string;
|
|
50
|
+
/** Index storage path */
|
|
51
|
+
indexPath: string;
|
|
52
|
+
/** File patterns to include */
|
|
53
|
+
include: string[];
|
|
54
|
+
/** File patterns to exclude */
|
|
55
|
+
exclude: string[];
|
|
56
|
+
/** Maximum file size to index (bytes) */
|
|
57
|
+
maxFileSize: number;
|
|
58
|
+
/** Enable incremental indexing */
|
|
59
|
+
incremental: boolean;
|
|
60
|
+
}
|
|
61
|
+
export declare class ProjectIndexer {
|
|
62
|
+
private config;
|
|
63
|
+
private index;
|
|
64
|
+
private trigramIndex;
|
|
65
|
+
constructor(config?: Partial<IndexerConfig>);
|
|
66
|
+
/**
|
|
67
|
+
* Load existing index from disk
|
|
68
|
+
*/
|
|
69
|
+
private loadIndex;
|
|
70
|
+
/**
|
|
71
|
+
* Save index to disk
|
|
72
|
+
*/
|
|
73
|
+
private saveIndex;
|
|
74
|
+
/**
|
|
75
|
+
* Build trigram index for fast search
|
|
76
|
+
*/
|
|
77
|
+
private rebuildTrigramIndex;
|
|
78
|
+
/**
|
|
79
|
+
* Index the entire project
|
|
80
|
+
*/
|
|
81
|
+
indexProject(): Promise<IndexStats>;
|
|
82
|
+
/**
|
|
83
|
+
* Walk directory recursively
|
|
84
|
+
*/
|
|
85
|
+
private walkDirectory;
|
|
86
|
+
/**
|
|
87
|
+
* Search for a string in the codebase
|
|
88
|
+
*/
|
|
89
|
+
search(query: string, options?: {
|
|
90
|
+
limit?: number;
|
|
91
|
+
caseSensitive?: boolean;
|
|
92
|
+
}): SearchResult[];
|
|
93
|
+
/**
|
|
94
|
+
* Find candidate files using trigram index
|
|
95
|
+
*/
|
|
96
|
+
private findCandidates;
|
|
97
|
+
/**
|
|
98
|
+
* Find matches in file content
|
|
99
|
+
*/
|
|
100
|
+
private findMatches;
|
|
101
|
+
/**
|
|
102
|
+
* Search for a symbol (function, class, etc.)
|
|
103
|
+
*/
|
|
104
|
+
searchSymbol(symbol: string): SearchResult[];
|
|
105
|
+
/**
|
|
106
|
+
* Get file content
|
|
107
|
+
*/
|
|
108
|
+
getFile(filePath: string): IndexedFile | null;
|
|
109
|
+
/**
|
|
110
|
+
* List all indexed files
|
|
111
|
+
*/
|
|
112
|
+
listFiles(): string[];
|
|
113
|
+
/**
|
|
114
|
+
* Get index statistics
|
|
115
|
+
*/
|
|
116
|
+
stats(): IndexStats;
|
|
117
|
+
/**
|
|
118
|
+
* Clear the index
|
|
119
|
+
*/
|
|
120
|
+
clear(): void;
|
|
121
|
+
}
|
|
122
|
+
export declare function getProjectIndexer(config?: Partial<IndexerConfig>): ProjectIndexer;
|
|
123
|
+
export declare function resetProjectIndexer(): void;
|