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,356 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Genesis 6.8 - SQLite Fix Cache
|
|
4
|
+
*
|
|
5
|
+
* Stores successful fixes from Self-Healing module for instant reuse.
|
|
6
|
+
* Uses better-sqlite3 for synchronous, high-performance operations.
|
|
7
|
+
*
|
|
8
|
+
* Key: SHA256(error_message + file_path + context)
|
|
9
|
+
* Value: Applied fix with metadata
|
|
10
|
+
*/
|
|
11
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc);
|
|
18
|
+
}) : (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
}));
|
|
22
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
23
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
24
|
+
}) : function(o, v) {
|
|
25
|
+
o["default"] = v;
|
|
26
|
+
});
|
|
27
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
+
var ownKeys = function(o) {
|
|
29
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
+
var ar = [];
|
|
31
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
return ownKeys(o);
|
|
35
|
+
};
|
|
36
|
+
return function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
+
__setModuleDefault(result, mod);
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.FixCache = void 0;
|
|
46
|
+
exports.getFixCache = getFixCache;
|
|
47
|
+
exports.resetFixCache = resetFixCache;
|
|
48
|
+
exports.getCachedFixOrGenerate = getCachedFixOrGenerate;
|
|
49
|
+
const crypto = __importStar(require("crypto"));
|
|
50
|
+
const fs = __importStar(require("fs"));
|
|
51
|
+
const path = __importStar(require("path"));
|
|
52
|
+
// ============================================================================
|
|
53
|
+
// Default Config
|
|
54
|
+
// ============================================================================
|
|
55
|
+
const DEFAULT_CONFIG = {
|
|
56
|
+
dbPath: path.join(process.env.HOME || '/tmp', '.genesis', 'fix-cache.db'),
|
|
57
|
+
maxFixes: 10000,
|
|
58
|
+
minSuccessCount: 1,
|
|
59
|
+
enableFTS: true,
|
|
60
|
+
};
|
|
61
|
+
// ============================================================================
|
|
62
|
+
// Pure Node.js SQLite Wrapper (no native dependencies)
|
|
63
|
+
// ============================================================================
|
|
64
|
+
/**
|
|
65
|
+
* Simple JSON file-based cache as SQLite fallback
|
|
66
|
+
* Works without native dependencies
|
|
67
|
+
*/
|
|
68
|
+
class JSONCache {
|
|
69
|
+
data = new Map();
|
|
70
|
+
dbPath;
|
|
71
|
+
hits = 0;
|
|
72
|
+
misses = 0;
|
|
73
|
+
constructor(dbPath) {
|
|
74
|
+
this.dbPath = dbPath.replace('.db', '.json');
|
|
75
|
+
this.load();
|
|
76
|
+
}
|
|
77
|
+
load() {
|
|
78
|
+
try {
|
|
79
|
+
if (fs.existsSync(this.dbPath)) {
|
|
80
|
+
const raw = fs.readFileSync(this.dbPath, 'utf-8');
|
|
81
|
+
const parsed = JSON.parse(raw);
|
|
82
|
+
this.data = new Map(Object.entries(parsed.fixes || {}));
|
|
83
|
+
this.hits = parsed.hits || 0;
|
|
84
|
+
this.misses = parsed.misses || 0;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
this.data = new Map();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
save() {
|
|
92
|
+
try {
|
|
93
|
+
const dir = path.dirname(this.dbPath);
|
|
94
|
+
if (!fs.existsSync(dir)) {
|
|
95
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
96
|
+
}
|
|
97
|
+
fs.writeFileSync(this.dbPath, JSON.stringify({
|
|
98
|
+
fixes: Object.fromEntries(this.data),
|
|
99
|
+
hits: this.hits,
|
|
100
|
+
misses: this.misses,
|
|
101
|
+
}, null, 2));
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
console.error('[Cache] Failed to save:', e);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
get(id) {
|
|
108
|
+
const fix = this.data.get(id);
|
|
109
|
+
if (fix) {
|
|
110
|
+
this.hits++;
|
|
111
|
+
fix.successCount++;
|
|
112
|
+
fix.lastUsed = Date.now();
|
|
113
|
+
this.save();
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
this.misses++;
|
|
117
|
+
}
|
|
118
|
+
return fix;
|
|
119
|
+
}
|
|
120
|
+
set(fix) {
|
|
121
|
+
this.data.set(fix.id, fix);
|
|
122
|
+
this.save();
|
|
123
|
+
}
|
|
124
|
+
delete(id) {
|
|
125
|
+
const result = this.data.delete(id);
|
|
126
|
+
if (result)
|
|
127
|
+
this.save();
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
all() {
|
|
131
|
+
return Array.from(this.data.values());
|
|
132
|
+
}
|
|
133
|
+
search(query) {
|
|
134
|
+
const lower = query.toLowerCase();
|
|
135
|
+
return this.all().filter(f => f.errorMessage.toLowerCase().includes(lower) ||
|
|
136
|
+
f.fix.toLowerCase().includes(lower) ||
|
|
137
|
+
f.context.toLowerCase().includes(lower));
|
|
138
|
+
}
|
|
139
|
+
size() {
|
|
140
|
+
return this.data.size;
|
|
141
|
+
}
|
|
142
|
+
stats() {
|
|
143
|
+
const fixes = this.all();
|
|
144
|
+
const errorTypes = new Map();
|
|
145
|
+
let totalLatency = 0;
|
|
146
|
+
let latencyCount = 0;
|
|
147
|
+
for (const fix of fixes) {
|
|
148
|
+
errorTypes.set(fix.errorType, (errorTypes.get(fix.errorType) || 0) + 1);
|
|
149
|
+
if (fix.latencyMs) {
|
|
150
|
+
totalLatency += fix.latencyMs;
|
|
151
|
+
latencyCount++;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const topErrors = Array.from(errorTypes.entries())
|
|
155
|
+
.map(([type, count]) => ({ type, count }))
|
|
156
|
+
.sort((a, b) => b.count - a.count)
|
|
157
|
+
.slice(0, 5);
|
|
158
|
+
let dbSize = 0;
|
|
159
|
+
try {
|
|
160
|
+
if (fs.existsSync(this.dbPath)) {
|
|
161
|
+
dbSize = fs.statSync(this.dbPath).size;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch { }
|
|
165
|
+
return {
|
|
166
|
+
totalFixes: fixes.length,
|
|
167
|
+
totalHits: this.hits,
|
|
168
|
+
hitRate: this.hits / Math.max(1, this.hits + this.misses),
|
|
169
|
+
avgLatencySaved: latencyCount > 0 ? totalLatency / latencyCount : 0,
|
|
170
|
+
topErrors,
|
|
171
|
+
dbSizeBytes: dbSize,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
clear() {
|
|
175
|
+
this.data.clear();
|
|
176
|
+
this.hits = 0;
|
|
177
|
+
this.misses = 0;
|
|
178
|
+
this.save();
|
|
179
|
+
}
|
|
180
|
+
close() {
|
|
181
|
+
this.save();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// ============================================================================
|
|
185
|
+
// Fix Cache Class
|
|
186
|
+
// ============================================================================
|
|
187
|
+
class FixCache {
|
|
188
|
+
config;
|
|
189
|
+
cache;
|
|
190
|
+
constructor(config) {
|
|
191
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
192
|
+
// Ensure directory exists
|
|
193
|
+
const dir = path.dirname(this.config.dbPath);
|
|
194
|
+
if (!fs.existsSync(dir)) {
|
|
195
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
196
|
+
}
|
|
197
|
+
// Use JSON cache (no native dependencies)
|
|
198
|
+
this.cache = new JSONCache(this.config.dbPath);
|
|
199
|
+
}
|
|
200
|
+
// ==========================================================================
|
|
201
|
+
// Core Operations
|
|
202
|
+
// ==========================================================================
|
|
203
|
+
/**
|
|
204
|
+
* Generate cache key from error details
|
|
205
|
+
*/
|
|
206
|
+
generateKey(errorMessage, filePath, context = '') {
|
|
207
|
+
const normalized = `${errorMessage.trim()}|${filePath}|${context.slice(0, 500)}`;
|
|
208
|
+
return crypto.createHash('sha256').update(normalized).digest('hex').slice(0, 16);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Look up a cached fix
|
|
212
|
+
*/
|
|
213
|
+
lookup(errorMessage, filePath, context = '') {
|
|
214
|
+
const key = this.generateKey(errorMessage, filePath, context);
|
|
215
|
+
return this.cache.get(key) || null;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Store a successful fix
|
|
219
|
+
*/
|
|
220
|
+
store(params) {
|
|
221
|
+
const id = this.generateKey(params.errorMessage, params.filePath, params.context);
|
|
222
|
+
const existing = this.cache.get(id);
|
|
223
|
+
if (existing) {
|
|
224
|
+
// Update existing
|
|
225
|
+
existing.successCount++;
|
|
226
|
+
existing.lastUsed = Date.now();
|
|
227
|
+
this.cache.set(existing);
|
|
228
|
+
return existing;
|
|
229
|
+
}
|
|
230
|
+
const fix = {
|
|
231
|
+
id,
|
|
232
|
+
errorMessage: params.errorMessage,
|
|
233
|
+
errorType: params.errorType,
|
|
234
|
+
filePath: params.filePath,
|
|
235
|
+
context: params.context.slice(0, 2000), // Limit context size
|
|
236
|
+
fix: params.fix,
|
|
237
|
+
successCount: 1,
|
|
238
|
+
lastUsed: Date.now(),
|
|
239
|
+
createdAt: Date.now(),
|
|
240
|
+
provider: params.provider,
|
|
241
|
+
latencyMs: params.latencyMs,
|
|
242
|
+
};
|
|
243
|
+
this.cache.set(fix);
|
|
244
|
+
this.evictIfNeeded();
|
|
245
|
+
return fix;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Search for similar errors
|
|
249
|
+
*/
|
|
250
|
+
searchSimilar(query, limit = 5) {
|
|
251
|
+
return this.cache.search(query).slice(0, limit);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Get all cached fixes
|
|
255
|
+
*/
|
|
256
|
+
getAll() {
|
|
257
|
+
return this.cache.all();
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Get cache statistics
|
|
261
|
+
*/
|
|
262
|
+
stats() {
|
|
263
|
+
return this.cache.stats();
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Clear all cached fixes
|
|
267
|
+
*/
|
|
268
|
+
clear() {
|
|
269
|
+
this.cache.clear();
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Delete a specific fix
|
|
273
|
+
*/
|
|
274
|
+
delete(id) {
|
|
275
|
+
return this.cache.delete(id);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Close the cache (save to disk)
|
|
279
|
+
*/
|
|
280
|
+
close() {
|
|
281
|
+
this.cache.close();
|
|
282
|
+
}
|
|
283
|
+
// ==========================================================================
|
|
284
|
+
// Eviction
|
|
285
|
+
// ==========================================================================
|
|
286
|
+
evictIfNeeded() {
|
|
287
|
+
const fixes = this.cache.all();
|
|
288
|
+
if (fixes.length <= this.config.maxFixes)
|
|
289
|
+
return;
|
|
290
|
+
// Sort by LRU (least recently used first)
|
|
291
|
+
const sorted = fixes
|
|
292
|
+
.filter(f => f.successCount < this.config.minSuccessCount)
|
|
293
|
+
.sort((a, b) => a.lastUsed - b.lastUsed);
|
|
294
|
+
// Evict oldest 10%
|
|
295
|
+
const toEvict = Math.ceil(sorted.length * 0.1);
|
|
296
|
+
for (let i = 0; i < toEvict && i < sorted.length; i++) {
|
|
297
|
+
this.cache.delete(sorted[i].id);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
exports.FixCache = FixCache;
|
|
302
|
+
// ============================================================================
|
|
303
|
+
// Singleton
|
|
304
|
+
// ============================================================================
|
|
305
|
+
let fixCacheInstance = null;
|
|
306
|
+
function getFixCache(config) {
|
|
307
|
+
if (!fixCacheInstance) {
|
|
308
|
+
fixCacheInstance = new FixCache(config);
|
|
309
|
+
}
|
|
310
|
+
return fixCacheInstance;
|
|
311
|
+
}
|
|
312
|
+
function resetFixCache() {
|
|
313
|
+
if (fixCacheInstance) {
|
|
314
|
+
fixCacheInstance.close();
|
|
315
|
+
fixCacheInstance = null;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
// ============================================================================
|
|
319
|
+
// Integration with Self-Healing
|
|
320
|
+
// ============================================================================
|
|
321
|
+
/**
|
|
322
|
+
* Try to get a cached fix before calling LLM
|
|
323
|
+
*/
|
|
324
|
+
async function getCachedFixOrGenerate(errorMessage, errorType, filePath, context, generateFix) {
|
|
325
|
+
const cache = getFixCache();
|
|
326
|
+
// Try cache first
|
|
327
|
+
const cached = cache.lookup(errorMessage, filePath, context);
|
|
328
|
+
if (cached) {
|
|
329
|
+
console.log(`[Cache] HIT: Reusing fix for ${errorType} error (${cached.successCount} uses)`);
|
|
330
|
+
return {
|
|
331
|
+
fix: cached.fix,
|
|
332
|
+
cached: true,
|
|
333
|
+
latencyMs: 0, // Instant!
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
// Cache miss - generate new fix
|
|
337
|
+
console.log(`[Cache] MISS: Generating new fix for ${errorType} error...`);
|
|
338
|
+
const startTime = Date.now();
|
|
339
|
+
const result = await generateFix();
|
|
340
|
+
const latencyMs = Date.now() - startTime;
|
|
341
|
+
// Store for future use
|
|
342
|
+
cache.store({
|
|
343
|
+
errorMessage,
|
|
344
|
+
errorType,
|
|
345
|
+
filePath,
|
|
346
|
+
context,
|
|
347
|
+
fix: result.fix,
|
|
348
|
+
provider: result.provider,
|
|
349
|
+
latencyMs,
|
|
350
|
+
});
|
|
351
|
+
return {
|
|
352
|
+
fix: result.fix,
|
|
353
|
+
cached: false,
|
|
354
|
+
latencyMs,
|
|
355
|
+
};
|
|
356
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Genesis 6.3 - Cognitive Workspace (Memory 2.0)
|
|
3
|
+
*
|
|
4
|
+
* Working memory with attention-based selection and anticipatory retrieval.
|
|
5
|
+
*
|
|
6
|
+
* Based on:
|
|
7
|
+
* - Baddeley's Working Memory Model (central executive + buffers)
|
|
8
|
+
* - Global Workspace Theory (Baars) - capacity-limited broadcast
|
|
9
|
+
* - Active Inference (anticipatory recall)
|
|
10
|
+
*
|
|
11
|
+
* Key features:
|
|
12
|
+
* - Capacity-limited buffer (like human 7±2 items)
|
|
13
|
+
* - Attention-based selection and eviction
|
|
14
|
+
* - Anticipatory pre-loading based on context
|
|
15
|
+
* - Integration with episodic/semantic/procedural stores
|
|
16
|
+
*
|
|
17
|
+
* Architecture:
|
|
18
|
+
* ```
|
|
19
|
+
* Context → anticipate() → Pre-load
|
|
20
|
+
* ↓
|
|
21
|
+
* [Working Memory Buffer]
|
|
22
|
+
* ↓
|
|
23
|
+
* curate() → Select/Evict
|
|
24
|
+
* ↓
|
|
25
|
+
* [Active Items for Reasoning]
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
import { Memory, EpisodicMemory, SemanticMemory, ProceduralMemory, MemoryType } from './types.js';
|
|
29
|
+
/**
|
|
30
|
+
* Store interface for episodic memories
|
|
31
|
+
*/
|
|
32
|
+
export interface EpisodicStoreInterface {
|
|
33
|
+
search: (query: string, limit: number) => EpisodicMemory[];
|
|
34
|
+
get: (id: string) => EpisodicMemory | undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Store interface for semantic memories
|
|
38
|
+
*/
|
|
39
|
+
export interface SemanticStoreInterface {
|
|
40
|
+
search: (query: string, limit: number) => SemanticMemory[];
|
|
41
|
+
getByConcept: (concept: string) => SemanticMemory | undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Store interface for procedural memories
|
|
45
|
+
*/
|
|
46
|
+
export interface ProceduralStoreInterface {
|
|
47
|
+
search: (query: string, limit: number) => ProceduralMemory[];
|
|
48
|
+
getByName: (name: string) => ProceduralMemory | undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Item in working memory with activation level
|
|
52
|
+
*/
|
|
53
|
+
export interface WorkingMemoryItem {
|
|
54
|
+
id: string;
|
|
55
|
+
memory: Memory;
|
|
56
|
+
activation: number;
|
|
57
|
+
relevance: number;
|
|
58
|
+
accessCount: number;
|
|
59
|
+
addedAt: Date;
|
|
60
|
+
lastAccessed: Date;
|
|
61
|
+
source: 'anticipate' | 'recall' | 'association' | 'manual';
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Context for anticipatory retrieval
|
|
65
|
+
*/
|
|
66
|
+
export interface AnticipationContext {
|
|
67
|
+
task?: string;
|
|
68
|
+
goal?: string;
|
|
69
|
+
recentActions?: string[];
|
|
70
|
+
recentTopics?: string[];
|
|
71
|
+
activeAgents?: string[];
|
|
72
|
+
activeLocation?: string;
|
|
73
|
+
emotionalState?: {
|
|
74
|
+
valence: number;
|
|
75
|
+
arousal: number;
|
|
76
|
+
};
|
|
77
|
+
keywords?: string[];
|
|
78
|
+
tags?: string[];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Configuration for cognitive workspace
|
|
82
|
+
*/
|
|
83
|
+
export interface CognitiveWorkspaceConfig {
|
|
84
|
+
maxItems: number;
|
|
85
|
+
maxTokens: number;
|
|
86
|
+
decayRate: number;
|
|
87
|
+
boostOnAccess: number;
|
|
88
|
+
minActivation: number;
|
|
89
|
+
anticipationDepth: number;
|
|
90
|
+
associationStrength: number;
|
|
91
|
+
curationInterval: number;
|
|
92
|
+
autoCurate: boolean;
|
|
93
|
+
}
|
|
94
|
+
export declare const DEFAULT_WORKSPACE_CONFIG: CognitiveWorkspaceConfig;
|
|
95
|
+
/**
|
|
96
|
+
* Memory reuse metrics for tracking efficiency
|
|
97
|
+
*/
|
|
98
|
+
export interface MemoryReuseMetrics {
|
|
99
|
+
totalRecalls: number;
|
|
100
|
+
cacheHits: number;
|
|
101
|
+
storeHits: number;
|
|
102
|
+
newCreations: number;
|
|
103
|
+
anticipationHits: number;
|
|
104
|
+
anticipationMisses: number;
|
|
105
|
+
reuseRate: number;
|
|
106
|
+
anticipationAccuracy: number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Working memory with attention-based selection and anticipatory retrieval
|
|
110
|
+
*/
|
|
111
|
+
export declare class CognitiveWorkspace {
|
|
112
|
+
private config;
|
|
113
|
+
private buffer;
|
|
114
|
+
private episodicStore?;
|
|
115
|
+
private semanticStore?;
|
|
116
|
+
private proceduralStore?;
|
|
117
|
+
private metrics;
|
|
118
|
+
private anticipatedIds;
|
|
119
|
+
private curationTimer?;
|
|
120
|
+
constructor(config?: Partial<CognitiveWorkspaceConfig>);
|
|
121
|
+
/**
|
|
122
|
+
* Connect to memory stores for retrieval
|
|
123
|
+
*/
|
|
124
|
+
connectStores(stores: {
|
|
125
|
+
episodic?: EpisodicStoreInterface;
|
|
126
|
+
semantic?: SemanticStoreInterface;
|
|
127
|
+
procedural?: ProceduralStoreInterface;
|
|
128
|
+
}): void;
|
|
129
|
+
/**
|
|
130
|
+
* Anticipate needed memories based on context
|
|
131
|
+
*
|
|
132
|
+
* Uses context cues to predict which memories will be needed,
|
|
133
|
+
* and pre-loads them into working memory.
|
|
134
|
+
*/
|
|
135
|
+
anticipate(context: AnticipationContext): Promise<WorkingMemoryItem[]>;
|
|
136
|
+
/**
|
|
137
|
+
* Calculate relevance of a memory to the current context
|
|
138
|
+
*/
|
|
139
|
+
private calculateRelevance;
|
|
140
|
+
/**
|
|
141
|
+
* Add a memory to working memory buffer
|
|
142
|
+
*/
|
|
143
|
+
addToBuffer(memory: Memory, source?: WorkingMemoryItem['source'], relevance?: number): WorkingMemoryItem;
|
|
144
|
+
/**
|
|
145
|
+
* Access a memory in working memory (boosts activation)
|
|
146
|
+
*/
|
|
147
|
+
access(id: string): WorkingMemoryItem | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Recall a memory (from buffer or stores)
|
|
150
|
+
*/
|
|
151
|
+
recall(id: string): Memory | undefined;
|
|
152
|
+
/**
|
|
153
|
+
* Get all items currently in working memory
|
|
154
|
+
*/
|
|
155
|
+
getActive(): WorkingMemoryItem[];
|
|
156
|
+
/**
|
|
157
|
+
* Get items by type
|
|
158
|
+
*/
|
|
159
|
+
getByType(type: MemoryType): WorkingMemoryItem[];
|
|
160
|
+
/**
|
|
161
|
+
* Check if a memory is in working memory
|
|
162
|
+
*/
|
|
163
|
+
isActive(id: string): boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Get working memory size
|
|
166
|
+
*/
|
|
167
|
+
size(): number;
|
|
168
|
+
/**
|
|
169
|
+
* Curate working memory: decay activations and evict low-activation items
|
|
170
|
+
*/
|
|
171
|
+
curate(): {
|
|
172
|
+
decayed: number;
|
|
173
|
+
evicted: string[];
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Start automatic curation
|
|
177
|
+
*/
|
|
178
|
+
startAutoCuration(): void;
|
|
179
|
+
/**
|
|
180
|
+
* Stop automatic curation
|
|
181
|
+
*/
|
|
182
|
+
stopAutoCuration(): void;
|
|
183
|
+
/**
|
|
184
|
+
* Maintain working memory capacity by evicting low-activation items
|
|
185
|
+
*/
|
|
186
|
+
private maintainCapacity;
|
|
187
|
+
/**
|
|
188
|
+
* Evict the item with lowest activation
|
|
189
|
+
*/
|
|
190
|
+
private evictLowest;
|
|
191
|
+
/**
|
|
192
|
+
* Update computed metrics
|
|
193
|
+
*/
|
|
194
|
+
private updateMetrics;
|
|
195
|
+
/**
|
|
196
|
+
* Get memory reuse metrics
|
|
197
|
+
*/
|
|
198
|
+
getMetrics(): MemoryReuseMetrics;
|
|
199
|
+
/**
|
|
200
|
+
* Record a new memory creation (for metrics)
|
|
201
|
+
*/
|
|
202
|
+
recordNewCreation(): void;
|
|
203
|
+
/**
|
|
204
|
+
* Reset metrics
|
|
205
|
+
*/
|
|
206
|
+
resetMetrics(): void;
|
|
207
|
+
/**
|
|
208
|
+
* Get workspace statistics
|
|
209
|
+
*/
|
|
210
|
+
getStats(): {
|
|
211
|
+
itemCount: number;
|
|
212
|
+
maxItems: number;
|
|
213
|
+
estimatedTokens: number;
|
|
214
|
+
maxTokens: number;
|
|
215
|
+
avgActivation: number;
|
|
216
|
+
avgRelevance: number;
|
|
217
|
+
byType: Record<MemoryType, number>;
|
|
218
|
+
bySource: Record<WorkingMemoryItem['source'], number>;
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* Clear working memory
|
|
222
|
+
*/
|
|
223
|
+
clear(): void;
|
|
224
|
+
/**
|
|
225
|
+
* Shutdown workspace
|
|
226
|
+
*/
|
|
227
|
+
shutdown(): void;
|
|
228
|
+
}
|
|
229
|
+
export declare function createCognitiveWorkspace(config?: Partial<CognitiveWorkspaceConfig>): CognitiveWorkspace;
|
|
230
|
+
export declare function getCognitiveWorkspace(config?: Partial<CognitiveWorkspaceConfig>): CognitiveWorkspace;
|
|
231
|
+
export declare function resetCognitiveWorkspace(): void;
|