@timmeck/brain-core 2.25.1 → 2.27.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/causal/engine.d.ts +47 -0
- package/dist/causal/engine.js +142 -0
- package/dist/causal/engine.js.map +1 -1
- package/dist/codegen/code-generator.d.ts +17 -0
- package/dist/codegen/code-generator.js +61 -0
- package/dist/codegen/code-generator.js.map +1 -1
- package/dist/codegen/index.d.ts +1 -0
- package/dist/codegen/index.js.map +1 -1
- package/dist/curiosity/curiosity-engine.d.ts +29 -0
- package/dist/curiosity/curiosity-engine.js +147 -0
- package/dist/curiosity/curiosity-engine.js.map +1 -1
- package/dist/curiosity/index.d.ts +1 -1
- package/dist/debate/debate-engine.d.ts +27 -0
- package/dist/debate/debate-engine.js +169 -0
- package/dist/debate/debate-engine.js.map +1 -1
- package/dist/debate/index.d.ts +1 -1
- package/dist/dream/dream-engine.d.ts +16 -1
- package/dist/dream/dream-engine.js +190 -0
- package/dist/dream/dream-engine.js.map +1 -1
- package/dist/dream/index.d.ts +1 -1
- package/dist/dream/types.d.ts +18 -0
- package/dist/emergence/emergence-engine.d.ts +19 -0
- package/dist/emergence/emergence-engine.js +118 -0
- package/dist/emergence/emergence-engine.js.map +1 -1
- package/dist/hypothesis/engine.d.ts +38 -0
- package/dist/hypothesis/engine.js +167 -0
- package/dist/hypothesis/engine.js.map +1 -1
- package/dist/index.d.ts +20 -5
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/metacognition/auto-experiment-engine.d.ts +72 -0
- package/dist/metacognition/auto-experiment-engine.js +272 -0
- package/dist/metacognition/auto-experiment-engine.js.map +1 -0
- package/dist/metacognition/index.d.ts +12 -0
- package/dist/metacognition/index.js +7 -0
- package/dist/metacognition/index.js.map +1 -0
- package/dist/metacognition/meta-cognition-layer.d.ts +112 -0
- package/dist/metacognition/meta-cognition-layer.js +402 -0
- package/dist/metacognition/meta-cognition-layer.js.map +1 -0
- package/dist/metacognition/parameter-registry.d.ts +71 -0
- package/dist/metacognition/parameter-registry.js +162 -0
- package/dist/metacognition/parameter-registry.js.map +1 -0
- package/dist/metacognition/self-test-engine.d.ts +52 -0
- package/dist/metacognition/self-test-engine.js +210 -0
- package/dist/metacognition/self-test-engine.js.map +1 -0
- package/dist/metacognition/simulation-engine.d.ts +71 -0
- package/dist/metacognition/simulation-engine.js +267 -0
- package/dist/metacognition/simulation-engine.js.map +1 -0
- package/dist/metacognition/teach-engine.d.ts +63 -0
- package/dist/metacognition/teach-engine.js +185 -0
- package/dist/metacognition/teach-engine.js.map +1 -0
- package/dist/research/data-scout.d.ts +68 -0
- package/dist/research/data-scout.js +254 -0
- package/dist/research/data-scout.js.map +1 -0
- package/dist/research/research-orchestrator.d.ts +32 -1
- package/dist/research/research-orchestrator.js +344 -4
- package/dist/research/research-orchestrator.js.map +1 -1
- package/dist/transfer/index.d.ts +1 -1
- package/dist/transfer/transfer-engine.d.ts +38 -0
- package/dist/transfer/transfer-engine.js +138 -0
- package/dist/transfer/transfer-engine.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
import type { ThoughtStream } from '../consciousness/thought-stream.js';
|
|
3
|
+
import type { KnowledgeDistiller } from '../research/knowledge-distiller.js';
|
|
4
|
+
import type { PredictionEngine } from '../prediction/prediction-engine.js';
|
|
5
|
+
import type { HypothesisEngine } from '../hypothesis/engine.js';
|
|
6
|
+
export interface SelfTest {
|
|
7
|
+
id?: number;
|
|
8
|
+
principleStatement: string;
|
|
9
|
+
derivedPrediction: string;
|
|
10
|
+
predictionResult: 'untested' | 'confirmed' | 'contradicted' | 'inconclusive';
|
|
11
|
+
understandingDepth: number;
|
|
12
|
+
testedAt: string;
|
|
13
|
+
}
|
|
14
|
+
export interface UnderstandingReport {
|
|
15
|
+
totalTested: number;
|
|
16
|
+
deepUnderstanding: number;
|
|
17
|
+
shallowUnderstanding: number;
|
|
18
|
+
untested: number;
|
|
19
|
+
avgDepth: number;
|
|
20
|
+
weakestPrinciples: SelfTest[];
|
|
21
|
+
}
|
|
22
|
+
export interface SelfTestStatus {
|
|
23
|
+
totalTests: number;
|
|
24
|
+
confirmed: number;
|
|
25
|
+
contradicted: number;
|
|
26
|
+
inconclusive: number;
|
|
27
|
+
avgDepth: number;
|
|
28
|
+
}
|
|
29
|
+
export declare function runSelfTestMigration(db: Database.Database): void;
|
|
30
|
+
export declare class SelfTestEngine {
|
|
31
|
+
private db;
|
|
32
|
+
private log;
|
|
33
|
+
private thoughtStream;
|
|
34
|
+
private distiller;
|
|
35
|
+
private predictionEngine;
|
|
36
|
+
private hypothesisEngine;
|
|
37
|
+
constructor(db: Database.Database);
|
|
38
|
+
setThoughtStream(stream: ThoughtStream): void;
|
|
39
|
+
setKnowledgeDistiller(distiller: KnowledgeDistiller): void;
|
|
40
|
+
setPredictionEngine(engine: PredictionEngine): void;
|
|
41
|
+
setHypothesisEngine(engine: HypothesisEngine): void;
|
|
42
|
+
/** Test if brain truly understands a principle by checking predictions + hypotheses. */
|
|
43
|
+
testPrinciple(statement: string): SelfTest;
|
|
44
|
+
/** Test all confirmed principles from KnowledgeDistiller. */
|
|
45
|
+
testAll(): SelfTest[];
|
|
46
|
+
/** Generate an understanding report. */
|
|
47
|
+
getUnderstandingReport(): UnderstandingReport;
|
|
48
|
+
/** Get status summary. */
|
|
49
|
+
getStatus(): SelfTestStatus;
|
|
50
|
+
private toSelfTest;
|
|
51
|
+
private extractKeywords;
|
|
52
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { getLogger } from '../utils/logger.js';
|
|
2
|
+
// ── Migration ───────────────────────────────────────────
|
|
3
|
+
export function runSelfTestMigration(db) {
|
|
4
|
+
db.exec(`
|
|
5
|
+
CREATE TABLE IF NOT EXISTS self_tests (
|
|
6
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
7
|
+
principle_statement TEXT NOT NULL,
|
|
8
|
+
derived_prediction TEXT NOT NULL DEFAULT '',
|
|
9
|
+
prediction_result TEXT NOT NULL DEFAULT 'untested',
|
|
10
|
+
understanding_depth REAL NOT NULL DEFAULT 0,
|
|
11
|
+
tested_at TEXT DEFAULT (datetime('now'))
|
|
12
|
+
);
|
|
13
|
+
CREATE INDEX IF NOT EXISTS idx_self_tests_result ON self_tests(prediction_result);
|
|
14
|
+
`);
|
|
15
|
+
}
|
|
16
|
+
// ── Engine ──────────────────────────────────────────────
|
|
17
|
+
export class SelfTestEngine {
|
|
18
|
+
db;
|
|
19
|
+
log = getLogger();
|
|
20
|
+
thoughtStream = null;
|
|
21
|
+
distiller = null;
|
|
22
|
+
predictionEngine = null;
|
|
23
|
+
hypothesisEngine = null;
|
|
24
|
+
constructor(db) {
|
|
25
|
+
this.db = db;
|
|
26
|
+
runSelfTestMigration(db);
|
|
27
|
+
}
|
|
28
|
+
setThoughtStream(stream) {
|
|
29
|
+
this.thoughtStream = stream;
|
|
30
|
+
}
|
|
31
|
+
setKnowledgeDistiller(distiller) {
|
|
32
|
+
this.distiller = distiller;
|
|
33
|
+
}
|
|
34
|
+
setPredictionEngine(engine) {
|
|
35
|
+
this.predictionEngine = engine;
|
|
36
|
+
}
|
|
37
|
+
setHypothesisEngine(engine) {
|
|
38
|
+
this.hypothesisEngine = engine;
|
|
39
|
+
}
|
|
40
|
+
/** Test if brain truly understands a principle by checking predictions + hypotheses. */
|
|
41
|
+
testPrinciple(statement) {
|
|
42
|
+
const keywords = this.extractKeywords(statement);
|
|
43
|
+
let matchingConfirmed = 0;
|
|
44
|
+
let matchingPredictions = 0;
|
|
45
|
+
let hypothesisConfidence = 0;
|
|
46
|
+
let derivedPrediction = '';
|
|
47
|
+
// 1. Check predictions that match the principle keywords
|
|
48
|
+
if (this.predictionEngine) {
|
|
49
|
+
try {
|
|
50
|
+
const predictions = this.predictionEngine.list(undefined, undefined, 100);
|
|
51
|
+
for (const pred of predictions) {
|
|
52
|
+
const predText = `${pred.metric} ${pred.reasoning ?? ''}`.toLowerCase();
|
|
53
|
+
const matchCount = keywords.filter(kw => predText.includes(kw)).length;
|
|
54
|
+
if (matchCount >= 1) {
|
|
55
|
+
matchingPredictions++;
|
|
56
|
+
if (pred.status === 'correct') {
|
|
57
|
+
matchingConfirmed++;
|
|
58
|
+
if (!derivedPrediction) {
|
|
59
|
+
derivedPrediction = `Prediction "${pred.metric}" (${pred.predicted_direction}) matches this principle`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch { /* predictions table might not exist */ }
|
|
66
|
+
}
|
|
67
|
+
// 2. Check hypotheses that relate to this principle
|
|
68
|
+
if (this.hypothesisEngine) {
|
|
69
|
+
try {
|
|
70
|
+
const hypotheses = this.hypothesisEngine.list(undefined, 100);
|
|
71
|
+
let totalConf = 0;
|
|
72
|
+
let matchCount = 0;
|
|
73
|
+
for (const hyp of hypotheses) {
|
|
74
|
+
const hypText = `${hyp.statement} ${hyp.type}`.toLowerCase();
|
|
75
|
+
const kwMatches = keywords.filter(kw => hypText.includes(kw)).length;
|
|
76
|
+
if (kwMatches >= 1) {
|
|
77
|
+
matchCount++;
|
|
78
|
+
totalConf += hyp.confidence;
|
|
79
|
+
if (hyp.status === 'confirmed' && !derivedPrediction) {
|
|
80
|
+
derivedPrediction = `Hypothesis "${hyp.statement}" confirms understanding`;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
hypothesisConfidence = matchCount > 0 ? totalConf / matchCount : 0;
|
|
85
|
+
}
|
|
86
|
+
catch { /* hypotheses table might not exist */ }
|
|
87
|
+
}
|
|
88
|
+
// 3. Calculate understanding depth
|
|
89
|
+
// depth = (matchingConfirmed * 0.5 + matchingPredictions * 0.3 + hypothesisConfidence * 0.2) normalized 0-1
|
|
90
|
+
const rawDepth = matchingConfirmed * 0.5 + matchingPredictions * 0.3 + hypothesisConfidence * 0.2;
|
|
91
|
+
const understandingDepth = Math.min(1, Math.max(0, rawDepth));
|
|
92
|
+
// 4. Determine result
|
|
93
|
+
let predictionResult;
|
|
94
|
+
if (understandingDepth >= 0.6) {
|
|
95
|
+
predictionResult = 'confirmed';
|
|
96
|
+
}
|
|
97
|
+
else if (understandingDepth <= 0.2) {
|
|
98
|
+
predictionResult = 'contradicted';
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
predictionResult = 'inconclusive';
|
|
102
|
+
}
|
|
103
|
+
if (!derivedPrediction) {
|
|
104
|
+
derivedPrediction = `Depth ${understandingDepth.toFixed(2)}: ${matchingPredictions} predictions, ${matchingConfirmed} confirmed, hypothesis confidence ${hypothesisConfidence.toFixed(2)}`;
|
|
105
|
+
}
|
|
106
|
+
// 5. Persist
|
|
107
|
+
const result = this.db.prepare(`
|
|
108
|
+
INSERT INTO self_tests (principle_statement, derived_prediction, prediction_result, understanding_depth)
|
|
109
|
+
VALUES (?, ?, ?, ?)
|
|
110
|
+
`).run(statement, derivedPrediction, predictionResult, understandingDepth);
|
|
111
|
+
const selfTest = {
|
|
112
|
+
id: result.lastInsertRowid,
|
|
113
|
+
principleStatement: statement,
|
|
114
|
+
derivedPrediction: derivedPrediction,
|
|
115
|
+
predictionResult,
|
|
116
|
+
understandingDepth,
|
|
117
|
+
testedAt: new Date().toISOString(),
|
|
118
|
+
};
|
|
119
|
+
// 6. Emit thought
|
|
120
|
+
this.thoughtStream?.emit('self-test', 'reflecting', `Self-tested principle: "${statement.slice(0, 80)}..." → ${predictionResult} (depth: ${understandingDepth.toFixed(2)})`, predictionResult === 'confirmed' ? 'notable' : 'routine');
|
|
121
|
+
this.log.debug(`[self-test] Tested: "${statement.slice(0, 60)}..." → ${predictionResult} (depth=${understandingDepth.toFixed(3)})`);
|
|
122
|
+
return selfTest;
|
|
123
|
+
}
|
|
124
|
+
/** Test all confirmed principles from KnowledgeDistiller. */
|
|
125
|
+
testAll() {
|
|
126
|
+
if (!this.distiller)
|
|
127
|
+
return [];
|
|
128
|
+
const principles = this.distiller.getPrinciples(undefined, 100);
|
|
129
|
+
const results = [];
|
|
130
|
+
for (const p of principles) {
|
|
131
|
+
const test = this.testPrinciple(p.statement);
|
|
132
|
+
results.push(test);
|
|
133
|
+
}
|
|
134
|
+
this.log.info(`[self-test] Tested ${results.length} principles: ${results.filter(t => t.predictionResult === 'confirmed').length} confirmed, ${results.filter(t => t.predictionResult === 'contradicted').length} contradicted`);
|
|
135
|
+
return results;
|
|
136
|
+
}
|
|
137
|
+
/** Generate an understanding report. */
|
|
138
|
+
getUnderstandingReport() {
|
|
139
|
+
const allTests = this.db.prepare(`
|
|
140
|
+
SELECT * FROM self_tests ORDER BY tested_at DESC
|
|
141
|
+
`).all();
|
|
142
|
+
const tests = allTests.map(r => this.toSelfTest(r));
|
|
143
|
+
const confirmed = tests.filter(t => t.predictionResult === 'confirmed');
|
|
144
|
+
const contradicted = tests.filter(t => t.predictionResult === 'contradicted');
|
|
145
|
+
const inconclusive = tests.filter(t => t.predictionResult === 'inconclusive');
|
|
146
|
+
const untested = tests.filter(t => t.predictionResult === 'untested');
|
|
147
|
+
const avgDepth = tests.length > 0
|
|
148
|
+
? tests.reduce((s, t) => s + t.understandingDepth, 0) / tests.length
|
|
149
|
+
: 0;
|
|
150
|
+
// Weakest = lowest depth, exclude untested
|
|
151
|
+
const testedTests = tests.filter(t => t.predictionResult !== 'untested');
|
|
152
|
+
testedTests.sort((a, b) => a.understandingDepth - b.understandingDepth);
|
|
153
|
+
return {
|
|
154
|
+
totalTested: testedTests.length,
|
|
155
|
+
deepUnderstanding: confirmed.length,
|
|
156
|
+
shallowUnderstanding: inconclusive.length,
|
|
157
|
+
untested: untested.length,
|
|
158
|
+
avgDepth,
|
|
159
|
+
weakestPrinciples: testedTests.slice(0, 5),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/** Get status summary. */
|
|
163
|
+
getStatus() {
|
|
164
|
+
const total = this.db.prepare('SELECT COUNT(*) as c FROM self_tests').get().c;
|
|
165
|
+
const confirmed = this.db.prepare("SELECT COUNT(*) as c FROM self_tests WHERE prediction_result = 'confirmed'").get().c;
|
|
166
|
+
const contradicted = this.db.prepare("SELECT COUNT(*) as c FROM self_tests WHERE prediction_result = 'contradicted'").get().c;
|
|
167
|
+
const inconclusive = this.db.prepare("SELECT COUNT(*) as c FROM self_tests WHERE prediction_result = 'inconclusive'").get().c;
|
|
168
|
+
const avgRow = this.db.prepare('SELECT AVG(understanding_depth) as avg FROM self_tests').get();
|
|
169
|
+
return {
|
|
170
|
+
totalTests: total,
|
|
171
|
+
confirmed,
|
|
172
|
+
contradicted,
|
|
173
|
+
inconclusive,
|
|
174
|
+
avgDepth: avgRow.avg ?? 0,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
// ── Private ─────────────────────────────────────────────
|
|
178
|
+
toSelfTest(row) {
|
|
179
|
+
return {
|
|
180
|
+
id: row.id,
|
|
181
|
+
principleStatement: row.principle_statement,
|
|
182
|
+
derivedPrediction: row.derived_prediction,
|
|
183
|
+
predictionResult: row.prediction_result,
|
|
184
|
+
understandingDepth: row.understanding_depth,
|
|
185
|
+
testedAt: row.tested_at,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
extractKeywords(statement) {
|
|
189
|
+
const stopwords = new Set([
|
|
190
|
+
'the', 'a', 'an', 'is', 'are', 'was', 'were', 'be', 'been', 'being',
|
|
191
|
+
'have', 'has', 'had', 'do', 'does', 'did', 'will', 'would', 'could',
|
|
192
|
+
'should', 'may', 'might', 'can', 'shall', 'to', 'of', 'in', 'for',
|
|
193
|
+
'on', 'with', 'at', 'by', 'from', 'as', 'into', 'through', 'during',
|
|
194
|
+
'before', 'after', 'above', 'below', 'between', 'out', 'off', 'over',
|
|
195
|
+
'under', 'again', 'further', 'then', 'once', 'here', 'there', 'when',
|
|
196
|
+
'where', 'why', 'how', 'all', 'each', 'every', 'both', 'few', 'more',
|
|
197
|
+
'most', 'other', 'some', 'such', 'no', 'nor', 'not', 'only', 'own',
|
|
198
|
+
'same', 'so', 'than', 'too', 'very', 'just', 'because', 'but', 'and',
|
|
199
|
+
'or', 'if', 'while', 'that', 'this', 'these', 'those', 'it', 'its',
|
|
200
|
+
'der', 'die', 'das', 'ein', 'eine', 'und', 'oder', 'aber', 'wenn',
|
|
201
|
+
'ist', 'sind', 'war', 'hat', 'mit', 'auf', 'fur', 'von', 'bei',
|
|
202
|
+
]);
|
|
203
|
+
return statement
|
|
204
|
+
.toLowerCase()
|
|
205
|
+
.replace(/[^a-z0-9\s_-]/g, ' ')
|
|
206
|
+
.split(/\s+/)
|
|
207
|
+
.filter(w => w.length > 2 && !stopwords.has(w));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=self-test-engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"self-test-engine.js","sourceRoot":"","sources":["../../src/metacognition/self-test-engine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAkC/C,2DAA2D;AAE3D,MAAM,UAAU,oBAAoB,CAAC,EAAqB;IACxD,EAAE,CAAC,IAAI,CAAC;;;;;;;;;;GAUP,CAAC,CAAC;AACL,CAAC;AAED,2DAA2D;AAE3D,MAAM,OAAO,cAAc;IACjB,EAAE,CAAoB;IACtB,GAAG,GAAG,SAAS,EAAE,CAAC;IAClB,aAAa,GAAyB,IAAI,CAAC;IAC3C,SAAS,GAA8B,IAAI,CAAC;IAC5C,gBAAgB,GAA4B,IAAI,CAAC;IACjD,gBAAgB,GAA4B,IAAI,CAAC;IAEzD,YAAY,EAAqB;QAC/B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,oBAAoB,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC;IAED,gBAAgB,CAAC,MAAqB;QACpC,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC;IAC9B,CAAC;IAED,qBAAqB,CAAC,SAA6B;QACjD,IAAI,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,CAAC,CAAC;QAEH,OAAO,SAAS;aACb,WAAW,EAAE;aACb,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC;aAC9B,KAAK,CAAC,KAAK,CAAC;aACZ,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC;CACF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
import type { ThoughtStream } from '../consciousness/thought-stream.js';
|
|
3
|
+
import type { PredictionEngine } from '../prediction/prediction-engine.js';
|
|
4
|
+
import type { CausalGraph } from '../causal/engine.js';
|
|
5
|
+
import type { MetaCognitionLayer } from './meta-cognition-layer.js';
|
|
6
|
+
export interface SimulationOutcome {
|
|
7
|
+
metric: string;
|
|
8
|
+
predicted: number;
|
|
9
|
+
direction: 'increase' | 'decrease' | 'stable';
|
|
10
|
+
confidence: number;
|
|
11
|
+
}
|
|
12
|
+
export interface Simulation {
|
|
13
|
+
id?: number;
|
|
14
|
+
scenario: string;
|
|
15
|
+
parameters: Record<string, unknown>;
|
|
16
|
+
predictedOutcomes: SimulationOutcome[];
|
|
17
|
+
actualOutcomes: SimulationOutcome[] | null;
|
|
18
|
+
accuracy: number | null;
|
|
19
|
+
simulatedAt: string;
|
|
20
|
+
validatedAt: string | null;
|
|
21
|
+
}
|
|
22
|
+
export interface SimulationStatus {
|
|
23
|
+
totalSimulations: number;
|
|
24
|
+
validatedCount: number;
|
|
25
|
+
avgAccuracy: number;
|
|
26
|
+
recentSimulations: Simulation[];
|
|
27
|
+
}
|
|
28
|
+
export declare function runSimulationMigration(db: Database.Database): void;
|
|
29
|
+
export declare class SimulationEngine {
|
|
30
|
+
private db;
|
|
31
|
+
private thoughtStream;
|
|
32
|
+
private predictionEngine;
|
|
33
|
+
private causalGraph;
|
|
34
|
+
private metaCognition;
|
|
35
|
+
private log;
|
|
36
|
+
constructor(db: Database.Database);
|
|
37
|
+
setThoughtStream(stream: ThoughtStream): void;
|
|
38
|
+
setPredictionEngine(engine: PredictionEngine): void;
|
|
39
|
+
setCausalGraph(graph: CausalGraph): void;
|
|
40
|
+
setMetaCognitionLayer(layer: MetaCognitionLayer): void;
|
|
41
|
+
/**
|
|
42
|
+
* Simulate a scenario: parse key metrics, find downstream causal effects,
|
|
43
|
+
* predict directions and magnitudes, persist and return.
|
|
44
|
+
*/
|
|
45
|
+
simulate(scenario: string): Simulation;
|
|
46
|
+
/** Shortcut: simulate what happens when a metric changes by a multiplier. */
|
|
47
|
+
whatIf(metric: string, multiplier: number): Simulation;
|
|
48
|
+
/** Validate a simulation against actual outcomes. */
|
|
49
|
+
validateSimulation(id: number, actualOutcomes: SimulationOutcome[]): Simulation | null;
|
|
50
|
+
/** List recent simulations. */
|
|
51
|
+
listSimulations(limit?: number): Simulation[];
|
|
52
|
+
/** Get overall accuracy metrics. */
|
|
53
|
+
getAccuracy(): {
|
|
54
|
+
avgAccuracy: number;
|
|
55
|
+
validatedCount: number;
|
|
56
|
+
totalSimulations: number;
|
|
57
|
+
};
|
|
58
|
+
/** Get status summary. */
|
|
59
|
+
getStatus(): SimulationStatus;
|
|
60
|
+
private toSimulation;
|
|
61
|
+
/**
|
|
62
|
+
* Parse a scenario string into metric+multiplier pairs.
|
|
63
|
+
* Supports patterns like:
|
|
64
|
+
* "error_rate doubles" → { metric: 'error_rate', multiplier: 2 }
|
|
65
|
+
* "error_rate triples" → { metric: 'error_rate', multiplier: 3 }
|
|
66
|
+
* "error_rate halves" → { metric: 'error_rate', multiplier: 0.5 }
|
|
67
|
+
* "error_rate increases by 50%" → { metric: 'error_rate', multiplier: 1.5 }
|
|
68
|
+
* "error_rate decreases by 30%" → { metric: 'error_rate', multiplier: 0.7 }
|
|
69
|
+
*/
|
|
70
|
+
private parseScenario;
|
|
71
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { getLogger } from '../utils/logger.js';
|
|
2
|
+
// ── Migration ───────────────────────────────────────────
|
|
3
|
+
export function runSimulationMigration(db) {
|
|
4
|
+
db.exec(`
|
|
5
|
+
CREATE TABLE IF NOT EXISTS simulations (
|
|
6
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
7
|
+
scenario TEXT NOT NULL,
|
|
8
|
+
parameters TEXT NOT NULL DEFAULT '{}',
|
|
9
|
+
predicted_outcomes TEXT NOT NULL DEFAULT '[]',
|
|
10
|
+
actual_outcomes TEXT DEFAULT NULL,
|
|
11
|
+
accuracy REAL DEFAULT NULL,
|
|
12
|
+
simulated_at TEXT DEFAULT (datetime('now')),
|
|
13
|
+
validated_at TEXT
|
|
14
|
+
);
|
|
15
|
+
CREATE INDEX IF NOT EXISTS idx_simulations_accuracy ON simulations(accuracy);
|
|
16
|
+
`);
|
|
17
|
+
}
|
|
18
|
+
// ── SimulationEngine ───────────────────────────────────
|
|
19
|
+
export class SimulationEngine {
|
|
20
|
+
db;
|
|
21
|
+
thoughtStream = null;
|
|
22
|
+
predictionEngine = null;
|
|
23
|
+
causalGraph = null;
|
|
24
|
+
metaCognition = null;
|
|
25
|
+
log = getLogger();
|
|
26
|
+
constructor(db) {
|
|
27
|
+
this.db = db;
|
|
28
|
+
runSimulationMigration(db);
|
|
29
|
+
}
|
|
30
|
+
setThoughtStream(stream) {
|
|
31
|
+
this.thoughtStream = stream;
|
|
32
|
+
}
|
|
33
|
+
setPredictionEngine(engine) {
|
|
34
|
+
this.predictionEngine = engine;
|
|
35
|
+
}
|
|
36
|
+
setCausalGraph(graph) {
|
|
37
|
+
this.causalGraph = graph;
|
|
38
|
+
}
|
|
39
|
+
setMetaCognitionLayer(layer) {
|
|
40
|
+
this.metaCognition = layer;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Simulate a scenario: parse key metrics, find downstream causal effects,
|
|
44
|
+
* predict directions and magnitudes, persist and return.
|
|
45
|
+
*/
|
|
46
|
+
simulate(scenario) {
|
|
47
|
+
const parsed = this.parseScenario(scenario);
|
|
48
|
+
const predictedOutcomes = [];
|
|
49
|
+
// Gather baseline from PredictionEngine if available
|
|
50
|
+
const baselineMetrics = {};
|
|
51
|
+
if (this.predictionEngine) {
|
|
52
|
+
try {
|
|
53
|
+
const summary = this.predictionEngine.getSummary();
|
|
54
|
+
if (summary.recent) {
|
|
55
|
+
for (const pred of summary.recent) {
|
|
56
|
+
baselineMetrics[pred.metric] = pred.predicted_value;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// No baseline available
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// For each parsed scenario component, find downstream causal effects
|
|
65
|
+
for (const { metric, multiplier } of parsed) {
|
|
66
|
+
if (this.causalGraph) {
|
|
67
|
+
const effects = this.causalGraph.getEffects(metric);
|
|
68
|
+
for (const edge of effects) {
|
|
69
|
+
// Predict direction based on edge direction and multiplier
|
|
70
|
+
const effectiveDirection = edge.direction * (multiplier >= 1 ? 1 : -1);
|
|
71
|
+
const direction = effectiveDirection > 0 ? 'increase' : effectiveDirection < 0 ? 'decrease' : 'stable';
|
|
72
|
+
// Predict magnitude based on multiplier and edge strength
|
|
73
|
+
const baseline = baselineMetrics[edge.effect] ?? 1;
|
|
74
|
+
const delta = (multiplier - 1) * edge.strength;
|
|
75
|
+
const predicted = baseline * (1 + delta * edge.direction);
|
|
76
|
+
// Confidence is based on edge strength, confidence, and sample size
|
|
77
|
+
const sampleFactor = Math.min(1, edge.sample_size / 20);
|
|
78
|
+
const confidence = edge.strength * edge.confidence * sampleFactor;
|
|
79
|
+
predictedOutcomes.push({
|
|
80
|
+
metric: edge.effect,
|
|
81
|
+
predicted: Math.round(predicted * 1000) / 1000,
|
|
82
|
+
direction,
|
|
83
|
+
confidence: Math.round(confidence * 1000) / 1000,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Also add the direct metric itself
|
|
88
|
+
const baseline = baselineMetrics[metric] ?? 1;
|
|
89
|
+
const predicted = baseline * multiplier;
|
|
90
|
+
predictedOutcomes.push({
|
|
91
|
+
metric,
|
|
92
|
+
predicted: Math.round(predicted * 1000) / 1000,
|
|
93
|
+
direction: multiplier > 1 ? 'increase' : multiplier < 1 ? 'decrease' : 'stable',
|
|
94
|
+
confidence: 0.8, // Direct metric — high confidence
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
// If no causal graph and no parsed metrics, generate a generic outcome
|
|
98
|
+
if (predictedOutcomes.length === 0) {
|
|
99
|
+
predictedOutcomes.push({
|
|
100
|
+
metric: 'unknown',
|
|
101
|
+
predicted: 0,
|
|
102
|
+
direction: 'stable',
|
|
103
|
+
confidence: 0.1,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const parameters = {
|
|
107
|
+
parsedMetrics: parsed,
|
|
108
|
+
baselineAvailable: Object.keys(baselineMetrics).length > 0,
|
|
109
|
+
causalEdgesUsed: predictedOutcomes.length - parsed.length,
|
|
110
|
+
};
|
|
111
|
+
// Persist
|
|
112
|
+
const result = this.db.prepare(`
|
|
113
|
+
INSERT INTO simulations (scenario, parameters, predicted_outcomes)
|
|
114
|
+
VALUES (?, ?, ?)
|
|
115
|
+
`).run(scenario, JSON.stringify(parameters), JSON.stringify(predictedOutcomes));
|
|
116
|
+
const simulation = {
|
|
117
|
+
id: result.lastInsertRowid,
|
|
118
|
+
scenario,
|
|
119
|
+
parameters,
|
|
120
|
+
predictedOutcomes,
|
|
121
|
+
actualOutcomes: null,
|
|
122
|
+
accuracy: null,
|
|
123
|
+
simulatedAt: new Date().toISOString(),
|
|
124
|
+
validatedAt: null,
|
|
125
|
+
};
|
|
126
|
+
this.log.info(`[simulation] Simulated "${scenario}": ${predictedOutcomes.length} predicted outcomes`);
|
|
127
|
+
this.thoughtStream?.emit('simulation-engine', 'analyzing', `Simulated scenario: "${scenario}" → ${predictedOutcomes.length} outcomes predicted`, predictedOutcomes.length >= 3 ? 'notable' : 'routine', { simulationId: simulation.id, outcomes: predictedOutcomes.length });
|
|
128
|
+
return simulation;
|
|
129
|
+
}
|
|
130
|
+
/** Shortcut: simulate what happens when a metric changes by a multiplier. */
|
|
131
|
+
whatIf(metric, multiplier) {
|
|
132
|
+
const scenario = multiplier >= 1
|
|
133
|
+
? `${metric} increases by ${Math.round((multiplier - 1) * 100)}%`
|
|
134
|
+
: `${metric} decreases by ${Math.round((1 - multiplier) * 100)}%`;
|
|
135
|
+
return this.simulate(scenario);
|
|
136
|
+
}
|
|
137
|
+
/** Validate a simulation against actual outcomes. */
|
|
138
|
+
validateSimulation(id, actualOutcomes) {
|
|
139
|
+
const row = this.db.prepare('SELECT * FROM simulations WHERE id = ?').get(id);
|
|
140
|
+
if (!row)
|
|
141
|
+
return null;
|
|
142
|
+
const sim = this.toSimulation(row);
|
|
143
|
+
const predicted = sim.predictedOutcomes;
|
|
144
|
+
// Compute accuracy: matching directions / total predicted
|
|
145
|
+
let matches = 0;
|
|
146
|
+
let compared = 0;
|
|
147
|
+
for (const pred of predicted) {
|
|
148
|
+
const actual = actualOutcomes.find(a => a.metric === pred.metric);
|
|
149
|
+
if (actual) {
|
|
150
|
+
compared++;
|
|
151
|
+
if (actual.direction === pred.direction) {
|
|
152
|
+
matches++;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const accuracy = compared > 0 ? matches / compared : 0;
|
|
157
|
+
this.db.prepare(`
|
|
158
|
+
UPDATE simulations SET actual_outcomes = ?, accuracy = ?, validated_at = datetime('now')
|
|
159
|
+
WHERE id = ?
|
|
160
|
+
`).run(JSON.stringify(actualOutcomes), accuracy, id);
|
|
161
|
+
this.log.info(`[simulation] Validated #${id}: accuracy=${(accuracy * 100).toFixed(1)}% (${matches}/${compared} correct)`);
|
|
162
|
+
this.thoughtStream?.emit('simulation-engine', 'analyzing', `Simulation #${id} validated: ${(accuracy * 100).toFixed(1)}% accuracy`, accuracy >= 0.7 ? 'notable' : 'routine', { simulationId: id, accuracy, matches, compared });
|
|
163
|
+
return {
|
|
164
|
+
...sim,
|
|
165
|
+
actualOutcomes,
|
|
166
|
+
accuracy,
|
|
167
|
+
validatedAt: new Date().toISOString(),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/** List recent simulations. */
|
|
171
|
+
listSimulations(limit = 20) {
|
|
172
|
+
const rows = this.db.prepare('SELECT * FROM simulations ORDER BY id DESC LIMIT ?').all(limit);
|
|
173
|
+
return rows.map(r => this.toSimulation(r));
|
|
174
|
+
}
|
|
175
|
+
/** Get overall accuracy metrics. */
|
|
176
|
+
getAccuracy() {
|
|
177
|
+
const total = this.db.prepare('SELECT COUNT(*) as c FROM simulations').get().c;
|
|
178
|
+
const validated = this.db.prepare('SELECT COUNT(*) as c, AVG(accuracy) as avg FROM simulations WHERE accuracy IS NOT NULL').get();
|
|
179
|
+
return {
|
|
180
|
+
avgAccuracy: validated.avg ?? 0,
|
|
181
|
+
validatedCount: validated.c,
|
|
182
|
+
totalSimulations: total,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/** Get status summary. */
|
|
186
|
+
getStatus() {
|
|
187
|
+
const accuracy = this.getAccuracy();
|
|
188
|
+
const recent = this.listSimulations(10);
|
|
189
|
+
return {
|
|
190
|
+
totalSimulations: accuracy.totalSimulations,
|
|
191
|
+
validatedCount: accuracy.validatedCount,
|
|
192
|
+
avgAccuracy: accuracy.avgAccuracy,
|
|
193
|
+
recentSimulations: recent,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
// ── Private ──────────────────────────────────────────────
|
|
197
|
+
toSimulation(row) {
|
|
198
|
+
return {
|
|
199
|
+
id: row.id,
|
|
200
|
+
scenario: row.scenario,
|
|
201
|
+
parameters: JSON.parse(row.parameters || '{}'),
|
|
202
|
+
predictedOutcomes: JSON.parse(row.predicted_outcomes || '[]'),
|
|
203
|
+
actualOutcomes: row.actual_outcomes ? JSON.parse(row.actual_outcomes) : null,
|
|
204
|
+
accuracy: row.accuracy,
|
|
205
|
+
simulatedAt: row.simulated_at,
|
|
206
|
+
validatedAt: row.validated_at ?? null,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Parse a scenario string into metric+multiplier pairs.
|
|
211
|
+
* Supports patterns like:
|
|
212
|
+
* "error_rate doubles" → { metric: 'error_rate', multiplier: 2 }
|
|
213
|
+
* "error_rate triples" → { metric: 'error_rate', multiplier: 3 }
|
|
214
|
+
* "error_rate halves" → { metric: 'error_rate', multiplier: 0.5 }
|
|
215
|
+
* "error_rate increases by 50%" → { metric: 'error_rate', multiplier: 1.5 }
|
|
216
|
+
* "error_rate decreases by 30%" → { metric: 'error_rate', multiplier: 0.7 }
|
|
217
|
+
*/
|
|
218
|
+
parseScenario(scenario) {
|
|
219
|
+
const results = [];
|
|
220
|
+
const lower = scenario.toLowerCase();
|
|
221
|
+
// Pattern: "X doubles/triples/halves"
|
|
222
|
+
const simpleMatch = lower.match(/(\w[\w._-]*)\s+(doubles?|triples?|halves?)/g);
|
|
223
|
+
if (simpleMatch) {
|
|
224
|
+
for (const m of simpleMatch) {
|
|
225
|
+
const parts = m.match(/(\w[\w._-]*)\s+(doubles?|triples?|halves?)/);
|
|
226
|
+
if (parts) {
|
|
227
|
+
const metric = parts[1];
|
|
228
|
+
const verb = parts[2];
|
|
229
|
+
let multiplier = 1;
|
|
230
|
+
if (verb.startsWith('double'))
|
|
231
|
+
multiplier = 2;
|
|
232
|
+
else if (verb.startsWith('triple'))
|
|
233
|
+
multiplier = 3;
|
|
234
|
+
else if (verb.startsWith('halv'))
|
|
235
|
+
multiplier = 0.5;
|
|
236
|
+
results.push({ metric, multiplier });
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// Pattern: "X increases/decreases by N%"
|
|
241
|
+
const pctMatch = lower.match(/(\w[\w._-]*)\s+(increases?|decreases?)\s+by\s+(\d+)%/g);
|
|
242
|
+
if (pctMatch) {
|
|
243
|
+
for (const m of pctMatch) {
|
|
244
|
+
const parts = m.match(/(\w[\w._-]*)\s+(increases?|decreases?)\s+by\s+(\d+)%/);
|
|
245
|
+
if (parts) {
|
|
246
|
+
const metric = parts[1];
|
|
247
|
+
const dir = parts[2];
|
|
248
|
+
const pct = parseInt(parts[3], 10);
|
|
249
|
+
const multiplier = dir.startsWith('increase')
|
|
250
|
+
? 1 + pct / 100
|
|
251
|
+
: 1 - pct / 100;
|
|
252
|
+
results.push({ metric, multiplier });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// Fallback: treat entire scenario as a single metric with no change
|
|
257
|
+
if (results.length === 0) {
|
|
258
|
+
// Try to extract any word-like metric name
|
|
259
|
+
const words = scenario.replace(/[^a-zA-Z0-9_.-]/g, ' ').split(/\s+/).filter(w => w.length > 2);
|
|
260
|
+
if (words.length > 0) {
|
|
261
|
+
results.push({ metric: words[0], multiplier: 1.5 }); // Default: assume 50% increase
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return results;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
//# sourceMappingURL=simulation-engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simulation-engine.js","sourceRoot":"","sources":["../../src/metacognition/simulation-engine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAiC/C,2DAA2D;AAE3D,MAAM,UAAU,sBAAsB,CAAC,EAAqB;IAC1D,EAAE,CAAC,IAAI,CAAC;;;;;;;;;;;;GAYP,CAAC,CAAC;AACL,CAAC;AAED,0DAA0D;AAE1D,MAAM,OAAO,gBAAgB;IACnB,EAAE,CAAoB;IACtB,aAAa,GAAyB,IAAI,CAAC;IAC3C,gBAAgB,GAA4B,IAAI,CAAC;IACjD,WAAW,GAAuB,IAAI,CAAC;IACvC,aAAa,GAA8B,IAAI,CAAC;IAChD,GAAG,GAAG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