@timmeck/brain-core 2.29.0 → 2.30.0
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/dist/dream/dream-engine.d.ts +5 -0
- package/dist/dream/dream-engine.js +75 -0
- package/dist/dream/dream-engine.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/reasoning/index.d.ts +2 -0
- package/dist/reasoning/index.js +2 -0
- package/dist/reasoning/index.js.map +1 -0
- package/dist/reasoning/reasoning-engine.d.ts +185 -0
- package/dist/reasoning/reasoning-engine.js +515 -0
- package/dist/reasoning/reasoning-engine.js.map +1 -0
- package/dist/research/research-orchestrator.d.ts +11 -0
- package/dist/research/research-orchestrator.js +288 -44
- package/dist/research/research-orchestrator.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
import { getLogger } from '../utils/logger.js';
|
|
2
|
+
// ── Migration ───────────────────────────────────────────
|
|
3
|
+
export function runReasoningMigration(db) {
|
|
4
|
+
db.exec(`
|
|
5
|
+
CREATE TABLE IF NOT EXISTS inference_rules (
|
|
6
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
7
|
+
antecedent TEXT NOT NULL,
|
|
8
|
+
consequent TEXT NOT NULL,
|
|
9
|
+
confidence REAL NOT NULL DEFAULT 0.5,
|
|
10
|
+
source_type TEXT NOT NULL,
|
|
11
|
+
source_id TEXT NOT NULL,
|
|
12
|
+
domain TEXT NOT NULL DEFAULT 'general',
|
|
13
|
+
keywords TEXT NOT NULL DEFAULT '[]',
|
|
14
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
15
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
16
|
+
UNIQUE(source_type, source_id)
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
CREATE TABLE IF NOT EXISTS inference_chains (
|
|
20
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
21
|
+
query TEXT NOT NULL,
|
|
22
|
+
chain_type TEXT NOT NULL DEFAULT 'forward',
|
|
23
|
+
rule_ids TEXT NOT NULL DEFAULT '[]',
|
|
24
|
+
steps TEXT NOT NULL DEFAULT '[]',
|
|
25
|
+
final_confidence REAL NOT NULL DEFAULT 0,
|
|
26
|
+
conclusion TEXT NOT NULL DEFAULT '',
|
|
27
|
+
temporal_estimate_ms REAL DEFAULT NULL,
|
|
28
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
CREATE TABLE IF NOT EXISTS reasoning_log (
|
|
32
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
33
|
+
query TEXT NOT NULL,
|
|
34
|
+
reasoning_type TEXT NOT NULL,
|
|
35
|
+
result_summary TEXT NOT NULL DEFAULT '',
|
|
36
|
+
chain_id INTEGER DEFAULT NULL,
|
|
37
|
+
confidence REAL NOT NULL DEFAULT 0,
|
|
38
|
+
duration_ms INTEGER NOT NULL DEFAULT 0,
|
|
39
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
CREATE INDEX IF NOT EXISTS idx_inference_rules_source ON inference_rules(source_type, source_id);
|
|
43
|
+
CREATE INDEX IF NOT EXISTS idx_inference_rules_confidence ON inference_rules(confidence DESC);
|
|
44
|
+
CREATE INDEX IF NOT EXISTS idx_inference_chains_type ON inference_chains(chain_type);
|
|
45
|
+
CREATE INDEX IF NOT EXISTS idx_reasoning_log_type ON reasoning_log(reasoning_type);
|
|
46
|
+
`);
|
|
47
|
+
}
|
|
48
|
+
// ── Engine ──────────────────────────────────────────────
|
|
49
|
+
export class ReasoningEngine {
|
|
50
|
+
db;
|
|
51
|
+
config;
|
|
52
|
+
log = getLogger();
|
|
53
|
+
ts = null;
|
|
54
|
+
sources = {};
|
|
55
|
+
startTime = Date.now();
|
|
56
|
+
// Prepared statements
|
|
57
|
+
stmtUpsertRule;
|
|
58
|
+
stmtGetRules;
|
|
59
|
+
stmtGetRulesByKeywords;
|
|
60
|
+
stmtInsertChain;
|
|
61
|
+
stmtGetChain;
|
|
62
|
+
stmtListChains;
|
|
63
|
+
stmtInsertLog;
|
|
64
|
+
stmtCountRules;
|
|
65
|
+
stmtCountChains;
|
|
66
|
+
stmtAvgConfidence;
|
|
67
|
+
stmtDomains;
|
|
68
|
+
stmtRecentChains;
|
|
69
|
+
constructor(db, config) {
|
|
70
|
+
this.db = db;
|
|
71
|
+
this.config = {
|
|
72
|
+
brainName: config.brainName,
|
|
73
|
+
maxDepth: config.maxDepth ?? 5,
|
|
74
|
+
minConfidence: config.minConfidence ?? 0.1,
|
|
75
|
+
dampening: config.dampening ?? 0.95,
|
|
76
|
+
minSimilarity: config.minSimilarity ?? 0.15,
|
|
77
|
+
};
|
|
78
|
+
runReasoningMigration(db);
|
|
79
|
+
this.stmtUpsertRule = db.prepare(`
|
|
80
|
+
INSERT INTO inference_rules (antecedent, consequent, confidence, source_type, source_id, domain, keywords, updated_at)
|
|
81
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, datetime('now'))
|
|
82
|
+
ON CONFLICT(source_type, source_id) DO UPDATE SET
|
|
83
|
+
antecedent = excluded.antecedent,
|
|
84
|
+
consequent = excluded.consequent,
|
|
85
|
+
confidence = excluded.confidence,
|
|
86
|
+
domain = excluded.domain,
|
|
87
|
+
keywords = excluded.keywords,
|
|
88
|
+
updated_at = datetime('now')
|
|
89
|
+
`);
|
|
90
|
+
this.stmtGetRules = db.prepare('SELECT * FROM inference_rules WHERE confidence >= ? ORDER BY confidence DESC LIMIT ?');
|
|
91
|
+
this.stmtGetRulesByKeywords = db.prepare('SELECT * FROM inference_rules WHERE confidence >= ? ORDER BY confidence DESC');
|
|
92
|
+
this.stmtInsertChain = db.prepare(`
|
|
93
|
+
INSERT INTO inference_chains (query, chain_type, rule_ids, steps, final_confidence, conclusion, temporal_estimate_ms)
|
|
94
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
95
|
+
`);
|
|
96
|
+
this.stmtGetChain = db.prepare('SELECT * FROM inference_chains WHERE id = ?');
|
|
97
|
+
this.stmtListChains = db.prepare('SELECT * FROM inference_chains ORDER BY created_at DESC LIMIT ?');
|
|
98
|
+
this.stmtInsertLog = db.prepare(`
|
|
99
|
+
INSERT INTO reasoning_log (query, reasoning_type, result_summary, chain_id, confidence, duration_ms)
|
|
100
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
101
|
+
`);
|
|
102
|
+
this.stmtCountRules = db.prepare('SELECT COUNT(*) as cnt FROM inference_rules');
|
|
103
|
+
this.stmtCountChains = db.prepare('SELECT COUNT(*) as cnt FROM inference_chains');
|
|
104
|
+
this.stmtAvgConfidence = db.prepare('SELECT AVG(confidence) as avg FROM inference_rules');
|
|
105
|
+
this.stmtDomains = db.prepare('SELECT DISTINCT domain FROM inference_rules ORDER BY domain');
|
|
106
|
+
this.stmtRecentChains = db.prepare("SELECT COUNT(*) as cnt FROM inference_chains WHERE created_at >= datetime('now', '-1 day')");
|
|
107
|
+
}
|
|
108
|
+
// ── Setters ─────────────────────────────────────────────
|
|
109
|
+
setThoughtStream(stream) { this.ts = stream; }
|
|
110
|
+
setDataSources(sources) { this.sources = sources; }
|
|
111
|
+
// ── 1. buildRules() ─────────────────────────────────────
|
|
112
|
+
/** Extract inference rules from hypotheses, principles, and causal edges. */
|
|
113
|
+
buildRules() {
|
|
114
|
+
let added = 0;
|
|
115
|
+
let updated = 0;
|
|
116
|
+
// 1a. Confirmed hypotheses → IF variables/condition THEN statement
|
|
117
|
+
try {
|
|
118
|
+
const hypotheses = this.sources.getConfirmedHypotheses?.() ?? [];
|
|
119
|
+
for (const h of hypotheses) {
|
|
120
|
+
const antecedent = h.variables.length > 0
|
|
121
|
+
? `IF ${h.variables.join(' AND ')}`
|
|
122
|
+
: `IF ${h.condition.type}`;
|
|
123
|
+
const consequent = h.statement;
|
|
124
|
+
const keywords = this.tokenize(antecedent + ' ' + consequent);
|
|
125
|
+
const result = this.stmtUpsertRule.run(antecedent, consequent, h.confidence, 'hypothesis', String(h.id ?? 0), 'hypothesis', JSON.stringify(keywords));
|
|
126
|
+
if (result.changes > 0) {
|
|
127
|
+
if (result.lastInsertRowid)
|
|
128
|
+
added++;
|
|
129
|
+
else
|
|
130
|
+
updated++;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
this.log.warn(`[reasoning] buildRules hypotheses error: ${err.message}`);
|
|
136
|
+
}
|
|
137
|
+
// 1b. High-confidence principles → statement as rule
|
|
138
|
+
try {
|
|
139
|
+
const principles = this.sources.getPrinciples?.('', 200) ?? [];
|
|
140
|
+
for (const p of principles) {
|
|
141
|
+
if (p.confidence < 0.5)
|
|
142
|
+
continue;
|
|
143
|
+
const parts = p.statement.split(/→|->|leads to|causes|implies/i);
|
|
144
|
+
let antecedent;
|
|
145
|
+
let consequent;
|
|
146
|
+
if (parts.length >= 2) {
|
|
147
|
+
antecedent = parts[0].trim();
|
|
148
|
+
consequent = parts.slice(1).join('→').trim();
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
antecedent = 'OBSERVE';
|
|
152
|
+
consequent = p.statement;
|
|
153
|
+
}
|
|
154
|
+
const keywords = this.tokenize(antecedent + ' ' + consequent);
|
|
155
|
+
const result = this.stmtUpsertRule.run(antecedent, consequent, p.confidence, 'principle', p.id, p.domain || 'general', JSON.stringify(keywords));
|
|
156
|
+
if (result.changes > 0) {
|
|
157
|
+
if (result.lastInsertRowid)
|
|
158
|
+
added++;
|
|
159
|
+
else
|
|
160
|
+
updated++;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
this.log.warn(`[reasoning] buildRules principles error: ${err.message}`);
|
|
166
|
+
}
|
|
167
|
+
// 1c. Causal edges → cause→effect with strength×confidence
|
|
168
|
+
try {
|
|
169
|
+
const edges = this.sources.getCausalEdges?.(0.2) ?? [];
|
|
170
|
+
for (const e of edges) {
|
|
171
|
+
const antecedent = e.cause;
|
|
172
|
+
const consequent = e.effect;
|
|
173
|
+
const confidence = e.strength * e.confidence;
|
|
174
|
+
const keywords = this.tokenize(antecedent + ' ' + consequent);
|
|
175
|
+
const result = this.stmtUpsertRule.run(antecedent, consequent, confidence, 'causal', `${e.cause}→${e.effect}`, 'causal', JSON.stringify(keywords));
|
|
176
|
+
if (result.changes > 0) {
|
|
177
|
+
if (result.lastInsertRowid)
|
|
178
|
+
added++;
|
|
179
|
+
else
|
|
180
|
+
updated++;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
this.log.warn(`[reasoning] buildRules causal error: ${err.message}`);
|
|
186
|
+
}
|
|
187
|
+
const total = this.stmtCountRules.get().cnt;
|
|
188
|
+
this.ts?.emit('reasoning', 'analyzing', `Built ${added} new + ${updated} updated rules (${total} total)`, 'routine');
|
|
189
|
+
this.log.info(`[reasoning] buildRules: +${added} new, ~${updated} updated, ${total} total`);
|
|
190
|
+
return { added, updated, total };
|
|
191
|
+
}
|
|
192
|
+
// ── 2. infer(query) — Forward Chaining ──────────────────
|
|
193
|
+
/** Forward chaining inference: find logical chains starting from query keywords. */
|
|
194
|
+
infer(query) {
|
|
195
|
+
const start = Date.now();
|
|
196
|
+
const queryKeywords = this.tokenize(query);
|
|
197
|
+
if (queryKeywords.length === 0)
|
|
198
|
+
return null;
|
|
199
|
+
const allRules = this.stmtGetRulesByKeywords.all(this.config.minConfidence);
|
|
200
|
+
const rules = allRules.map(r => ({ ...r, keywords: JSON.parse(r.keywords) }));
|
|
201
|
+
// Find best starting rule by matching antecedent keywords
|
|
202
|
+
const steps = [];
|
|
203
|
+
const visited = new Set();
|
|
204
|
+
let currentKeywords = queryKeywords;
|
|
205
|
+
let cumulativeConfidence = 1.0;
|
|
206
|
+
for (let depth = 0; depth < this.config.maxDepth; depth++) {
|
|
207
|
+
const bestRule = this.findBestMatch(currentKeywords, rules, visited, 'antecedent');
|
|
208
|
+
if (!bestRule)
|
|
209
|
+
break;
|
|
210
|
+
cumulativeConfidence *= bestRule.confidence * this.config.dampening;
|
|
211
|
+
if (cumulativeConfidence < this.config.minConfidence)
|
|
212
|
+
break;
|
|
213
|
+
visited.add(bestRule.id);
|
|
214
|
+
steps.push({
|
|
215
|
+
ruleId: bestRule.id,
|
|
216
|
+
antecedent: bestRule.antecedent,
|
|
217
|
+
consequent: bestRule.consequent,
|
|
218
|
+
confidence: bestRule.confidence,
|
|
219
|
+
cumulativeConfidence,
|
|
220
|
+
source: `${bestRule.source_type}:${bestRule.source_id}`,
|
|
221
|
+
});
|
|
222
|
+
// Next iteration: match consequent keywords against new antecedents
|
|
223
|
+
currentKeywords = this.tokenize(bestRule.consequent);
|
|
224
|
+
}
|
|
225
|
+
if (steps.length === 0) {
|
|
226
|
+
this.stmtInsertLog.run(query, 'forward', 'no chain found', null, 0, Date.now() - start);
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
const conclusion = steps.length > 1
|
|
230
|
+
? `${steps[0].antecedent} → ${steps.map(s => s.consequent).join(' → ')}`
|
|
231
|
+
: `${steps[0].antecedent} → ${steps[0].consequent}`;
|
|
232
|
+
const chain = {
|
|
233
|
+
query,
|
|
234
|
+
chain_type: 'forward',
|
|
235
|
+
steps,
|
|
236
|
+
rule_ids: steps.map(s => s.ruleId),
|
|
237
|
+
final_confidence: cumulativeConfidence,
|
|
238
|
+
conclusion,
|
|
239
|
+
};
|
|
240
|
+
// Persist
|
|
241
|
+
const result = this.stmtInsertChain.run(query, 'forward', JSON.stringify(chain.rule_ids), JSON.stringify(chain.steps), chain.final_confidence, chain.conclusion, null);
|
|
242
|
+
chain.id = Number(result.lastInsertRowid);
|
|
243
|
+
this.stmtInsertLog.run(query, 'forward', conclusion, chain.id, chain.final_confidence, Date.now() - start);
|
|
244
|
+
this.ts?.emit('reasoning', 'discovering', `Inferred: ${conclusion} (conf=${chain.final_confidence.toFixed(3)})`, chain.final_confidence > 0.5 ? 'notable' : 'routine');
|
|
245
|
+
return chain;
|
|
246
|
+
}
|
|
247
|
+
// ── 3. abduce(observation) — Abductive Reasoning ────────
|
|
248
|
+
/** Abductive reasoning: find possible explanations for an observation. */
|
|
249
|
+
abduce(observation) {
|
|
250
|
+
const start = Date.now();
|
|
251
|
+
const obsKeywords = this.tokenize(observation);
|
|
252
|
+
if (obsKeywords.length === 0)
|
|
253
|
+
return [];
|
|
254
|
+
const allRules = this.stmtGetRulesByKeywords.all(this.config.minConfidence);
|
|
255
|
+
const rules = allRules.map(r => ({ ...r, keywords: JSON.parse(r.keywords) }));
|
|
256
|
+
const explanations = [];
|
|
257
|
+
for (const rule of rules) {
|
|
258
|
+
// Match observation keywords against CONSEQUENTS (backwards!)
|
|
259
|
+
const consequentKeywords = this.tokenize(rule.consequent);
|
|
260
|
+
const overlap = this.keywordOverlap(obsKeywords, consequentKeywords);
|
|
261
|
+
if (overlap === 0)
|
|
262
|
+
continue;
|
|
263
|
+
const coverage = obsKeywords.length > 0 ? overlap / obsKeywords.length : 0;
|
|
264
|
+
const score = rule.confidence * coverage;
|
|
265
|
+
if (score >= this.config.minConfidence) {
|
|
266
|
+
explanations.push({
|
|
267
|
+
ruleId: rule.id,
|
|
268
|
+
antecedent: rule.antecedent,
|
|
269
|
+
consequent: rule.consequent,
|
|
270
|
+
confidence: rule.confidence,
|
|
271
|
+
coverage,
|
|
272
|
+
score,
|
|
273
|
+
source: `${rule.source_type}:${rule.source_id}`,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
// Sort by score, top 5
|
|
278
|
+
explanations.sort((a, b) => b.score - a.score);
|
|
279
|
+
const top = explanations.slice(0, 5);
|
|
280
|
+
const summary = top.length > 0
|
|
281
|
+
? `${top.length} explanations: ${top.map(e => e.antecedent).join(', ')}`
|
|
282
|
+
: 'no explanations found';
|
|
283
|
+
this.stmtInsertLog.run(observation, 'abductive', summary, null, top[0]?.score ?? 0, Date.now() - start);
|
|
284
|
+
if (top.length > 0) {
|
|
285
|
+
this.ts?.emit('reasoning', 'exploring', `Abduce "${observation}": ${top.length} explanations found`, 'routine');
|
|
286
|
+
}
|
|
287
|
+
return top;
|
|
288
|
+
}
|
|
289
|
+
// ── 4. temporalInfer(eventType) — Temporal Chains ───────
|
|
290
|
+
/** Temporal inference: trace causal chains with time delays. */
|
|
291
|
+
temporalInfer(eventType) {
|
|
292
|
+
const start = Date.now();
|
|
293
|
+
if (!this.sources.getCausalEffects)
|
|
294
|
+
return null;
|
|
295
|
+
const steps = [];
|
|
296
|
+
const visited = new Set();
|
|
297
|
+
let current = eventType;
|
|
298
|
+
let cumulativeLag = 0;
|
|
299
|
+
let cumulativeConf = 1.0;
|
|
300
|
+
visited.add(current);
|
|
301
|
+
for (let depth = 0; depth < this.config.maxDepth; depth++) {
|
|
302
|
+
const effects = this.sources.getCausalEffects(current);
|
|
303
|
+
if (!effects || effects.length === 0)
|
|
304
|
+
break;
|
|
305
|
+
// Pick strongest effect not yet visited
|
|
306
|
+
const best = effects.find(e => !visited.has(e.effect));
|
|
307
|
+
if (!best)
|
|
308
|
+
break;
|
|
309
|
+
visited.add(best.effect);
|
|
310
|
+
cumulativeLag += best.lag_ms;
|
|
311
|
+
cumulativeConf *= best.confidence * this.config.dampening;
|
|
312
|
+
if (cumulativeConf < this.config.minConfidence)
|
|
313
|
+
break;
|
|
314
|
+
steps.push({
|
|
315
|
+
cause: best.cause,
|
|
316
|
+
effect: best.effect,
|
|
317
|
+
lag_ms: best.lag_ms,
|
|
318
|
+
cumulative_lag_ms: cumulativeLag,
|
|
319
|
+
confidence: best.confidence,
|
|
320
|
+
cumulative_confidence: cumulativeConf,
|
|
321
|
+
});
|
|
322
|
+
current = best.effect;
|
|
323
|
+
}
|
|
324
|
+
if (steps.length === 0) {
|
|
325
|
+
this.stmtInsertLog.run(eventType, 'temporal', 'no temporal chain', null, 0, Date.now() - start);
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
// Build narrative
|
|
329
|
+
const parts = [eventType];
|
|
330
|
+
for (const s of steps) {
|
|
331
|
+
parts.push(`→(${s.lag_ms}ms)→ ${s.effect}`);
|
|
332
|
+
}
|
|
333
|
+
const narrative = parts.join(' ');
|
|
334
|
+
const chain = {
|
|
335
|
+
eventType,
|
|
336
|
+
steps,
|
|
337
|
+
total_lag_ms: cumulativeLag,
|
|
338
|
+
final_confidence: cumulativeConf,
|
|
339
|
+
narrative,
|
|
340
|
+
};
|
|
341
|
+
// Persist as inference chain
|
|
342
|
+
const result = this.stmtInsertChain.run(eventType, 'temporal', JSON.stringify(steps.map((_, i) => i)), JSON.stringify(steps), cumulativeConf, narrative, cumulativeLag);
|
|
343
|
+
this.stmtInsertLog.run(eventType, 'temporal', narrative, Number(result.lastInsertRowid), cumulativeConf, Date.now() - start);
|
|
344
|
+
this.ts?.emit('reasoning', 'analyzing', `Temporal: ${narrative}`, 'routine');
|
|
345
|
+
return chain;
|
|
346
|
+
}
|
|
347
|
+
// ── 5. counterfactual(event) — "What if X never happened?" ─
|
|
348
|
+
/** Counterfactual reasoning: what downstream effects would be lost if event never happened. */
|
|
349
|
+
counterfactual(event) {
|
|
350
|
+
const start = Date.now();
|
|
351
|
+
const affected = [];
|
|
352
|
+
const queue = [event];
|
|
353
|
+
const visited = new Set();
|
|
354
|
+
visited.add(event);
|
|
355
|
+
// BFS over causal graph
|
|
356
|
+
while (queue.length > 0) {
|
|
357
|
+
const current = queue.shift();
|
|
358
|
+
const effects = this.sources.getCausalEffects?.(current) ?? [];
|
|
359
|
+
for (const e of effects) {
|
|
360
|
+
if (!visited.has(e.effect)) {
|
|
361
|
+
visited.add(e.effect);
|
|
362
|
+
affected.push(e.effect);
|
|
363
|
+
queue.push(e.effect);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
const narrative = affected.length > 0
|
|
368
|
+
? `Without "${event}", ${affected.length} downstream effects would not have occurred: ${affected.join(', ')}`
|
|
369
|
+
: `"${event}" has no known downstream effects.`;
|
|
370
|
+
const result = {
|
|
371
|
+
event,
|
|
372
|
+
affected_effects: affected,
|
|
373
|
+
depth: visited.size - 1,
|
|
374
|
+
narrative,
|
|
375
|
+
};
|
|
376
|
+
// Persist
|
|
377
|
+
const chainResult = this.stmtInsertChain.run(event, 'counterfactual', JSON.stringify([]), JSON.stringify(affected), affected.length > 0 ? 1.0 : 0.0, narrative, null);
|
|
378
|
+
this.stmtInsertLog.run(event, 'counterfactual', narrative, Number(chainResult.lastInsertRowid), affected.length > 0 ? 1.0 : 0.0, Date.now() - start);
|
|
379
|
+
if (affected.length > 0) {
|
|
380
|
+
this.ts?.emit('reasoning', 'exploring', `Counterfactual: without "${event}" → ${affected.length} effects lost`, 'notable');
|
|
381
|
+
}
|
|
382
|
+
return result;
|
|
383
|
+
}
|
|
384
|
+
// ── 6. getProofTree(chainId) ────────────────────────────
|
|
385
|
+
/** Retrieve a stored proof tree / inference chain by ID. */
|
|
386
|
+
getProofTree(chainId) {
|
|
387
|
+
const row = this.stmtGetChain.get(chainId);
|
|
388
|
+
if (!row)
|
|
389
|
+
return null;
|
|
390
|
+
return this.toChain(row);
|
|
391
|
+
}
|
|
392
|
+
// ── 7. getRules(limit?, minConfidence?) ─────────────────
|
|
393
|
+
/** Get inference rules, optionally filtered. */
|
|
394
|
+
getRules(limit = 50, minConfidence = 0) {
|
|
395
|
+
const rows = this.stmtGetRules.all(minConfidence, limit);
|
|
396
|
+
return rows.map(r => this.toRule(r));
|
|
397
|
+
}
|
|
398
|
+
// ── 8. getStatus() ──────────────────────────────────────
|
|
399
|
+
/** Engine status and stats. */
|
|
400
|
+
getStatus() {
|
|
401
|
+
const ruleCount = this.stmtCountRules.get().cnt;
|
|
402
|
+
const chainCount = this.stmtCountChains.get().cnt;
|
|
403
|
+
const avgConf = this.stmtAvgConfidence.get().avg ?? 0;
|
|
404
|
+
const domains = this.stmtDomains.all().map(d => d.domain);
|
|
405
|
+
const recentChains = this.stmtRecentChains.get().cnt;
|
|
406
|
+
return {
|
|
407
|
+
ruleCount,
|
|
408
|
+
chainCount,
|
|
409
|
+
avgConfidence: avgConf,
|
|
410
|
+
domains,
|
|
411
|
+
recentChains,
|
|
412
|
+
uptime: Date.now() - this.startTime,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
// ── Private helpers ─────────────────────────────────────
|
|
416
|
+
/** Tokenize text into bigram-aware keywords. */
|
|
417
|
+
tokenize(text) {
|
|
418
|
+
const words = text.toLowerCase()
|
|
419
|
+
.replace(/[^a-z0-9äöüß_\-]/g, ' ')
|
|
420
|
+
.split(/\s+/)
|
|
421
|
+
.filter(w => w.length > 2 && !STOP_WORDS.has(w));
|
|
422
|
+
// Deduplicate
|
|
423
|
+
return [...new Set(words)];
|
|
424
|
+
}
|
|
425
|
+
/** Jaccard similarity between two keyword sets. */
|
|
426
|
+
jaccard(a, b) {
|
|
427
|
+
if (a.length === 0 || b.length === 0)
|
|
428
|
+
return 0;
|
|
429
|
+
const setA = new Set(a);
|
|
430
|
+
const setB = new Set(b);
|
|
431
|
+
let intersection = 0;
|
|
432
|
+
for (const w of setA) {
|
|
433
|
+
if (setB.has(w))
|
|
434
|
+
intersection++;
|
|
435
|
+
}
|
|
436
|
+
const union = setA.size + setB.size - intersection;
|
|
437
|
+
return union > 0 ? intersection / union : 0;
|
|
438
|
+
}
|
|
439
|
+
/** Count keyword overlap. */
|
|
440
|
+
keywordOverlap(a, b) {
|
|
441
|
+
const setB = new Set(b);
|
|
442
|
+
let count = 0;
|
|
443
|
+
for (const w of a) {
|
|
444
|
+
if (setB.has(w))
|
|
445
|
+
count++;
|
|
446
|
+
}
|
|
447
|
+
return count;
|
|
448
|
+
}
|
|
449
|
+
/** Find best matching rule for given keywords. */
|
|
450
|
+
findBestMatch(queryKeywords, rules, visited, matchField) {
|
|
451
|
+
let bestRule = null;
|
|
452
|
+
let bestScore = 0;
|
|
453
|
+
for (const rule of rules) {
|
|
454
|
+
if (visited.has(rule.id))
|
|
455
|
+
continue;
|
|
456
|
+
const fieldKeywords = matchField === 'antecedent'
|
|
457
|
+
? this.tokenize(rule.antecedent)
|
|
458
|
+
: this.tokenize(rule.consequent);
|
|
459
|
+
const sim = this.jaccard(queryKeywords, fieldKeywords);
|
|
460
|
+
if (sim < this.config.minSimilarity)
|
|
461
|
+
continue;
|
|
462
|
+
const score = sim * rule.confidence;
|
|
463
|
+
if (score > bestScore) {
|
|
464
|
+
bestScore = score;
|
|
465
|
+
bestRule = rule;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return bestRule;
|
|
469
|
+
}
|
|
470
|
+
/** Convert DB row to InferenceChain. */
|
|
471
|
+
toChain(row) {
|
|
472
|
+
return {
|
|
473
|
+
id: row.id,
|
|
474
|
+
query: row.query,
|
|
475
|
+
chain_type: row.chain_type,
|
|
476
|
+
steps: JSON.parse(row.steps || '[]'),
|
|
477
|
+
rule_ids: JSON.parse(row.rule_ids || '[]'),
|
|
478
|
+
final_confidence: row.final_confidence,
|
|
479
|
+
conclusion: row.conclusion,
|
|
480
|
+
temporal_estimate_ms: row.temporal_estimate_ms,
|
|
481
|
+
created_at: row.created_at,
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
/** Convert DB row to InferenceRule. */
|
|
485
|
+
toRule(row) {
|
|
486
|
+
return {
|
|
487
|
+
id: row.id,
|
|
488
|
+
antecedent: row.antecedent,
|
|
489
|
+
consequent: row.consequent,
|
|
490
|
+
confidence: row.confidence,
|
|
491
|
+
source_type: row.source_type,
|
|
492
|
+
source_id: row.source_id,
|
|
493
|
+
domain: row.domain,
|
|
494
|
+
keywords: JSON.parse(row.keywords || '[]'),
|
|
495
|
+
created_at: row.created_at,
|
|
496
|
+
updated_at: row.updated_at,
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
// ── Stop Words ──────────────────────────────────────────
|
|
501
|
+
const STOP_WORDS = new Set([
|
|
502
|
+
'the', 'and', 'for', 'are', 'but', 'not', 'you', 'all', 'can', 'had',
|
|
503
|
+
'her', 'was', 'one', 'our', 'out', 'has', 'have', 'been', 'will', 'with',
|
|
504
|
+
'this', 'that', 'from', 'they', 'were', 'each', 'which', 'their', 'then',
|
|
505
|
+
'them', 'these', 'other', 'than', 'when', 'some', 'what', 'there', 'also',
|
|
506
|
+
'into', 'more', 'its', 'only', 'could', 'would', 'should', 'about',
|
|
507
|
+
'does', 'did', 'just', 'how', 'where', 'who', 'may', 'most', 'over',
|
|
508
|
+
'such', 'after', 'because', 'through', 'between', 'very', 'being',
|
|
509
|
+
'those', 'still', 'while', 'both', 'same', 'way', 'any', 'many',
|
|
510
|
+
'der', 'die', 'das', 'den', 'dem', 'des', 'ein', 'eine', 'einer',
|
|
511
|
+
'und', 'ist', 'hat', 'nicht', 'sich', 'mit', 'auf', 'für', 'von',
|
|
512
|
+
'als', 'auch', 'noch', 'nach', 'bei', 'aus', 'wenn', 'dass', 'oder',
|
|
513
|
+
'aber', 'wie', 'wird', 'sind', 'vor', 'nur', 'über', 'kann', 'schon',
|
|
514
|
+
]);
|
|
515
|
+
//# sourceMappingURL=reasoning-engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reasoning-engine.js","sourceRoot":"","sources":["../../src/reasoning/reasoning-engine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AA6G/C,2DAA2D;AAE3D,MAAM,UAAU,qBAAqB,CAAC,EAAqB;IACzD,EAAE,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CP,CAAC,CAAC;AACL,CAAC;AAED,2DAA2D;AAE3D,MAAM,OAAO,eAAe;IACT,EAAE,CAAoB;IACtB,MAAM,CAAkC;IACxC,GAAG,GAAG,SAAS,EAAE,CAAC;IAC3B,EAAE,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AAM;IACzE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO;IAClE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM;IACnE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO;IACjE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM;IAC/D,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO;IAChE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK;IAChE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IACnE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO;CACrE,CAAC,CAAC"}
|
|
@@ -34,6 +34,7 @@ import type { SimulationEngine } from '../metacognition/simulation-engine.js';
|
|
|
34
34
|
import type { MemoryPalace } from '../memory-palace/memory-palace.js';
|
|
35
35
|
import type { GoalEngine } from '../goals/goal-engine.js';
|
|
36
36
|
import type { EvolutionEngine } from '../metacognition/evolution-engine.js';
|
|
37
|
+
import type { ReasoningEngine } from '../reasoning/reasoning-engine.js';
|
|
37
38
|
import { AutoResponder } from './auto-responder.js';
|
|
38
39
|
export interface ResearchOrchestratorConfig {
|
|
39
40
|
brainName: string;
|
|
@@ -81,6 +82,7 @@ export declare class ResearchOrchestrator {
|
|
|
81
82
|
private memoryPalace;
|
|
82
83
|
private goalEngine;
|
|
83
84
|
private evolutionEngine;
|
|
85
|
+
private reasoningEngine;
|
|
84
86
|
private brainName;
|
|
85
87
|
private feedbackTimer;
|
|
86
88
|
private cycleCount;
|
|
@@ -138,6 +140,8 @@ export declare class ResearchOrchestrator {
|
|
|
138
140
|
setGoalEngine(engine: GoalEngine): void;
|
|
139
141
|
/** Set the EvolutionEngine — evolves parameter configurations via genetic algorithm. */
|
|
140
142
|
setEvolutionEngine(engine: EvolutionEngine): void;
|
|
143
|
+
/** Set the ReasoningEngine — multi-step logical inference chains. */
|
|
144
|
+
setReasoningEngine(engine: ReasoningEngine): void;
|
|
141
145
|
/** Set the PredictionEngine — wires journal into it. */
|
|
142
146
|
setPredictionEngine(engine: PredictionEngine): void;
|
|
143
147
|
/** Start the autonomous feedback loop timer. */
|
|
@@ -170,6 +174,13 @@ export declare class ResearchOrchestrator {
|
|
|
170
174
|
/** Pick a debate topic from recent attention, anomalies, or journal insights. */
|
|
171
175
|
private pickDebateTopic;
|
|
172
176
|
private generateSelfImprovementSuggestions;
|
|
177
|
+
/** Check which optional engines are actually installed. */
|
|
178
|
+
getInstalledCapabilities(): {
|
|
179
|
+
installed: string[];
|
|
180
|
+
missing: string[];
|
|
181
|
+
};
|
|
182
|
+
/** Generate dynamic meta-suggestions based on actual engine state instead of hardcoded feature requests. */
|
|
183
|
+
private generateDynamicMetaSuggestions;
|
|
173
184
|
/** Auto-propose an experiment on Brain's own parameters. */
|
|
174
185
|
private proposeAutoExperiment;
|
|
175
186
|
/** Feed cycle measurements into running experiments. */
|