@timmeck/brain-core 2.5.0 → 2.7.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/dashboard/research-server.d.ts +11 -0
- package/dist/dashboard/research-server.js +47 -0
- package/dist/dashboard/research-server.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -1
- package/dist/research/adaptive-strategy.d.ts +56 -0
- package/dist/research/adaptive-strategy.js +236 -0
- package/dist/research/adaptive-strategy.js.map +1 -0
- package/dist/research/agenda-engine.d.ts +46 -0
- package/dist/research/agenda-engine.js +264 -0
- package/dist/research/agenda-engine.js.map +1 -0
- package/dist/research/anomaly-detective.d.ts +62 -0
- package/dist/research/anomaly-detective.js +318 -0
- package/dist/research/anomaly-detective.js.map +1 -0
- package/dist/research/counterfactual-engine.d.ts +63 -0
- package/dist/research/counterfactual-engine.js +263 -0
- package/dist/research/counterfactual-engine.js.map +1 -0
- package/dist/research/cross-domain-engine.d.ts +52 -0
- package/dist/research/cross-domain-engine.js +283 -0
- package/dist/research/cross-domain-engine.js.map +1 -0
- package/dist/research/experiment-engine.d.ts +77 -0
- package/dist/research/experiment-engine.js +328 -0
- package/dist/research/experiment-engine.js.map +1 -0
- package/dist/research/journal.d.ts +62 -0
- package/dist/research/journal.js +262 -0
- package/dist/research/journal.js.map +1 -0
- package/dist/research/knowledge-distiller.d.ts +95 -0
- package/dist/research/knowledge-distiller.js +426 -0
- package/dist/research/knowledge-distiller.js.map +1 -0
- package/dist/research/research-orchestrator.d.ts +68 -0
- package/dist/research/research-orchestrator.js +228 -0
- package/dist/research/research-orchestrator.js.map +1 -0
- package/dist/research/self-observer.d.ts +55 -0
- package/dist/research/self-observer.js +268 -0
- package/dist/research/self-observer.js.map +1 -0
- package/package.json +1 -1
- package/research-dashboard.html +735 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"journal.js","sourceRoot":"","sources":["../../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number;
|
|
7
|
+
sample_size: number;
|
|
8
|
+
confidence: number;
|
|
9
|
+
source: string;
|
|
10
|
+
}
|
|
11
|
+
export interface AntiPattern {
|
|
12
|
+
id: string;
|
|
13
|
+
domain: string;
|
|
14
|
+
statement: string;
|
|
15
|
+
failure_rate: number;
|
|
16
|
+
sample_size: number;
|
|
17
|
+
confidence: number;
|
|
18
|
+
alternative: string;
|
|
19
|
+
}
|
|
20
|
+
export interface Strategy {
|
|
21
|
+
id: string;
|
|
22
|
+
domain: string;
|
|
23
|
+
description: string;
|
|
24
|
+
conditions: string[];
|
|
25
|
+
effectiveness: number;
|
|
26
|
+
evidence_count: number;
|
|
27
|
+
}
|
|
28
|
+
export interface KnowledgePackage {
|
|
29
|
+
id: string;
|
|
30
|
+
created: number;
|
|
31
|
+
domain: string;
|
|
32
|
+
principles: Principle[];
|
|
33
|
+
anti_patterns: AntiPattern[];
|
|
34
|
+
strategies: Strategy[];
|
|
35
|
+
confidence: number;
|
|
36
|
+
evidence_summary: string;
|
|
37
|
+
applicable_when: string[];
|
|
38
|
+
transferable_to: string[];
|
|
39
|
+
}
|
|
40
|
+
export interface KnowledgeEvolution {
|
|
41
|
+
domain: string;
|
|
42
|
+
period: string;
|
|
43
|
+
principles_added: number;
|
|
44
|
+
principles_removed: number;
|
|
45
|
+
anti_patterns_discovered: number;
|
|
46
|
+
strategies_changed: number;
|
|
47
|
+
confidence_trend: 'rising' | 'stable' | 'falling';
|
|
48
|
+
highlights: string[];
|
|
49
|
+
}
|
|
50
|
+
export interface KnowledgeDistillerConfig {
|
|
51
|
+
brainName: string;
|
|
52
|
+
/** Minimum evidence to extract a principle. Default: 5 */
|
|
53
|
+
minEvidence?: number;
|
|
54
|
+
/** Minimum success rate for a principle. Default: 0.7 */
|
|
55
|
+
minSuccessRate?: number;
|
|
56
|
+
/** Minimum failure rate for an anti-pattern. Default: 0.6 */
|
|
57
|
+
minFailureRate?: number;
|
|
58
|
+
}
|
|
59
|
+
export declare function runKnowledgeDistillerMigration(db: Database.Database): void;
|
|
60
|
+
export declare class KnowledgeDistiller {
|
|
61
|
+
private db;
|
|
62
|
+
private config;
|
|
63
|
+
private log;
|
|
64
|
+
constructor(db: Database.Database, config: KnowledgeDistillerConfig);
|
|
65
|
+
/** Distill knowledge from confirmed hypotheses, research discoveries, and strategy adaptations. */
|
|
66
|
+
distill(): {
|
|
67
|
+
principles: Principle[];
|
|
68
|
+
antiPatterns: AntiPattern[];
|
|
69
|
+
strategies: Strategy[];
|
|
70
|
+
};
|
|
71
|
+
/** Get summary of all distilled knowledge. */
|
|
72
|
+
getSummary(): {
|
|
73
|
+
principles: number;
|
|
74
|
+
antiPatterns: number;
|
|
75
|
+
strategies: number;
|
|
76
|
+
topPrinciples: Principle[];
|
|
77
|
+
avgConfidence: number;
|
|
78
|
+
};
|
|
79
|
+
/** Get principles, optionally filtered by domain. */
|
|
80
|
+
getPrinciples(domain?: string, limit?: number): Principle[];
|
|
81
|
+
/** Get anti-patterns. */
|
|
82
|
+
getAntiPatterns(domain?: string, limit?: number): AntiPattern[];
|
|
83
|
+
/** Build a transferable knowledge package for a domain. */
|
|
84
|
+
getPackage(domain: string): KnowledgePackage;
|
|
85
|
+
/** Track how knowledge has evolved over time. */
|
|
86
|
+
getEvolution(domain?: string, periods?: number): KnowledgeEvolution[];
|
|
87
|
+
private extractPrinciples;
|
|
88
|
+
private extractAntiPatterns;
|
|
89
|
+
private extractStrategies;
|
|
90
|
+
private suggestTransferDomains;
|
|
91
|
+
private upsertPrinciple;
|
|
92
|
+
private upsertAntiPattern;
|
|
93
|
+
private upsertStrategy;
|
|
94
|
+
private hashString;
|
|
95
|
+
}
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
import { getLogger } from '../utils/logger.js';
|
|
2
|
+
// ── Migration ───────────────────────────────────────────
|
|
3
|
+
export function runKnowledgeDistillerMigration(db) {
|
|
4
|
+
db.exec(`
|
|
5
|
+
CREATE TABLE IF NOT EXISTS knowledge_principles (
|
|
6
|
+
id TEXT PRIMARY KEY,
|
|
7
|
+
domain TEXT NOT NULL,
|
|
8
|
+
statement TEXT NOT NULL,
|
|
9
|
+
success_rate REAL NOT NULL,
|
|
10
|
+
sample_size INTEGER NOT NULL,
|
|
11
|
+
confidence REAL NOT NULL,
|
|
12
|
+
source TEXT NOT NULL,
|
|
13
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
14
|
+
updated_at TEXT DEFAULT (datetime('now'))
|
|
15
|
+
);
|
|
16
|
+
CREATE INDEX IF NOT EXISTS idx_kp_domain ON knowledge_principles(domain);
|
|
17
|
+
|
|
18
|
+
CREATE TABLE IF NOT EXISTS knowledge_anti_patterns (
|
|
19
|
+
id TEXT PRIMARY KEY,
|
|
20
|
+
domain TEXT NOT NULL,
|
|
21
|
+
statement TEXT NOT NULL,
|
|
22
|
+
failure_rate REAL NOT NULL,
|
|
23
|
+
sample_size INTEGER NOT NULL,
|
|
24
|
+
confidence REAL NOT NULL,
|
|
25
|
+
alternative TEXT NOT NULL,
|
|
26
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
27
|
+
updated_at TEXT DEFAULT (datetime('now'))
|
|
28
|
+
);
|
|
29
|
+
CREATE INDEX IF NOT EXISTS idx_kap_domain ON knowledge_anti_patterns(domain);
|
|
30
|
+
|
|
31
|
+
CREATE TABLE IF NOT EXISTS knowledge_strategies (
|
|
32
|
+
id TEXT PRIMARY KEY,
|
|
33
|
+
domain TEXT NOT NULL,
|
|
34
|
+
description TEXT NOT NULL,
|
|
35
|
+
conditions TEXT NOT NULL,
|
|
36
|
+
effectiveness REAL NOT NULL,
|
|
37
|
+
evidence_count INTEGER NOT NULL,
|
|
38
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
39
|
+
updated_at TEXT DEFAULT (datetime('now'))
|
|
40
|
+
);
|
|
41
|
+
CREATE INDEX IF NOT EXISTS idx_ks_domain ON knowledge_strategies(domain);
|
|
42
|
+
|
|
43
|
+
CREATE TABLE IF NOT EXISTS knowledge_snapshots (
|
|
44
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
45
|
+
timestamp INTEGER NOT NULL,
|
|
46
|
+
domain TEXT NOT NULL,
|
|
47
|
+
principles_count INTEGER NOT NULL,
|
|
48
|
+
anti_patterns_count INTEGER NOT NULL,
|
|
49
|
+
strategies_count INTEGER NOT NULL,
|
|
50
|
+
avg_confidence REAL NOT NULL,
|
|
51
|
+
created_at TEXT DEFAULT (datetime('now'))
|
|
52
|
+
);
|
|
53
|
+
`);
|
|
54
|
+
}
|
|
55
|
+
// ── Engine ──────────────────────────────────────────────
|
|
56
|
+
export class KnowledgeDistiller {
|
|
57
|
+
db;
|
|
58
|
+
config;
|
|
59
|
+
log = getLogger();
|
|
60
|
+
constructor(db, config) {
|
|
61
|
+
this.db = db;
|
|
62
|
+
this.config = {
|
|
63
|
+
brainName: config.brainName,
|
|
64
|
+
minEvidence: config.minEvidence ?? 5,
|
|
65
|
+
minSuccessRate: config.minSuccessRate ?? 0.7,
|
|
66
|
+
minFailureRate: config.minFailureRate ?? 0.6,
|
|
67
|
+
};
|
|
68
|
+
runKnowledgeDistillerMigration(db);
|
|
69
|
+
}
|
|
70
|
+
/** Distill knowledge from confirmed hypotheses, research discoveries, and strategy adaptations. */
|
|
71
|
+
distill() {
|
|
72
|
+
const principles = this.extractPrinciples();
|
|
73
|
+
const antiPatterns = this.extractAntiPatterns();
|
|
74
|
+
const strategies = this.extractStrategies();
|
|
75
|
+
// Take snapshot for evolution tracking
|
|
76
|
+
this.db.prepare(`
|
|
77
|
+
INSERT INTO knowledge_snapshots (timestamp, domain, principles_count, anti_patterns_count, strategies_count, avg_confidence)
|
|
78
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
79
|
+
`).run(Date.now(), this.config.brainName, principles.length, antiPatterns.length, strategies.length, principles.length > 0 ? principles.reduce((s, p) => s + p.confidence, 0) / principles.length : 0);
|
|
80
|
+
return { principles, antiPatterns, strategies };
|
|
81
|
+
}
|
|
82
|
+
/** Get summary of all distilled knowledge. */
|
|
83
|
+
getSummary() {
|
|
84
|
+
const pCount = this.db.prepare(`SELECT COUNT(*) as c FROM knowledge_principles`).get().c;
|
|
85
|
+
const apCount = this.db.prepare(`SELECT COUNT(*) as c FROM knowledge_anti_patterns`).get().c;
|
|
86
|
+
const sCount = this.db.prepare(`SELECT COUNT(*) as c FROM knowledge_strategies`).get().c;
|
|
87
|
+
const topPrinciples = this.getPrinciples(undefined, 5);
|
|
88
|
+
const avgConf = topPrinciples.length > 0 ? topPrinciples.reduce((s, p) => s + p.confidence, 0) / topPrinciples.length : 0;
|
|
89
|
+
return {
|
|
90
|
+
principles: pCount,
|
|
91
|
+
antiPatterns: apCount,
|
|
92
|
+
strategies: sCount,
|
|
93
|
+
topPrinciples,
|
|
94
|
+
avgConfidence: avgConf,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Get principles, optionally filtered by domain. */
|
|
98
|
+
getPrinciples(domain, limit = 20) {
|
|
99
|
+
let sql = `SELECT * FROM knowledge_principles`;
|
|
100
|
+
const params = [];
|
|
101
|
+
if (domain) {
|
|
102
|
+
sql += ` WHERE domain = ?`;
|
|
103
|
+
params.push(domain);
|
|
104
|
+
}
|
|
105
|
+
sql += ` ORDER BY confidence DESC, success_rate DESC LIMIT ?`;
|
|
106
|
+
params.push(limit);
|
|
107
|
+
return this.db.prepare(sql).all(...params).map(r => ({
|
|
108
|
+
id: r.id,
|
|
109
|
+
domain: r.domain,
|
|
110
|
+
statement: r.statement,
|
|
111
|
+
success_rate: r.success_rate,
|
|
112
|
+
sample_size: r.sample_size,
|
|
113
|
+
confidence: r.confidence,
|
|
114
|
+
source: r.source,
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
/** Get anti-patterns. */
|
|
118
|
+
getAntiPatterns(domain, limit = 20) {
|
|
119
|
+
let sql = `SELECT * FROM knowledge_anti_patterns`;
|
|
120
|
+
const params = [];
|
|
121
|
+
if (domain) {
|
|
122
|
+
sql += ` WHERE domain = ?`;
|
|
123
|
+
params.push(domain);
|
|
124
|
+
}
|
|
125
|
+
sql += ` ORDER BY failure_rate DESC LIMIT ?`;
|
|
126
|
+
params.push(limit);
|
|
127
|
+
return this.db.prepare(sql).all(...params).map(r => ({
|
|
128
|
+
id: r.id,
|
|
129
|
+
domain: r.domain,
|
|
130
|
+
statement: r.statement,
|
|
131
|
+
failure_rate: r.failure_rate,
|
|
132
|
+
sample_size: r.sample_size,
|
|
133
|
+
confidence: r.confidence,
|
|
134
|
+
alternative: r.alternative,
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
/** Build a transferable knowledge package for a domain. */
|
|
138
|
+
getPackage(domain) {
|
|
139
|
+
const principles = this.getPrinciples(domain, 15);
|
|
140
|
+
const antiPatterns = this.getAntiPatterns(domain, 10);
|
|
141
|
+
const strategies = this.db.prepare(`
|
|
142
|
+
SELECT * FROM knowledge_strategies WHERE domain = ? ORDER BY effectiveness DESC LIMIT 10
|
|
143
|
+
`).all(domain).map(r => ({
|
|
144
|
+
id: r.id,
|
|
145
|
+
domain: r.domain,
|
|
146
|
+
description: r.description,
|
|
147
|
+
conditions: JSON.parse(r.conditions),
|
|
148
|
+
effectiveness: r.effectiveness,
|
|
149
|
+
evidence_count: r.evidence_count,
|
|
150
|
+
}));
|
|
151
|
+
const allConf = [...principles.map(p => p.confidence), ...antiPatterns.map(a => a.confidence)];
|
|
152
|
+
const avgConf = allConf.length > 0 ? allConf.reduce((a, b) => a + b, 0) / allConf.length : 0;
|
|
153
|
+
return {
|
|
154
|
+
id: `${domain}-${Date.now()}`,
|
|
155
|
+
created: Date.now(),
|
|
156
|
+
domain,
|
|
157
|
+
principles,
|
|
158
|
+
anti_patterns: antiPatterns,
|
|
159
|
+
strategies,
|
|
160
|
+
confidence: avgConf,
|
|
161
|
+
evidence_summary: `${principles.length} principles, ${antiPatterns.length} anti-patterns, ${strategies.length} strategies from ${this.config.brainName}`,
|
|
162
|
+
applicable_when: [`Working with ${domain} tasks`, `Debugging ${domain} issues`],
|
|
163
|
+
transferable_to: this.suggestTransferDomains(domain),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/** Track how knowledge has evolved over time. */
|
|
167
|
+
getEvolution(domain, periods = 5) {
|
|
168
|
+
const snapshots = this.db.prepare(`
|
|
169
|
+
SELECT * FROM knowledge_snapshots
|
|
170
|
+
${domain ? 'WHERE domain = ?' : ''}
|
|
171
|
+
ORDER BY timestamp DESC LIMIT ?
|
|
172
|
+
`).all(...(domain ? [domain, periods * 2] : [periods * 2]));
|
|
173
|
+
if (snapshots.length < 2)
|
|
174
|
+
return [];
|
|
175
|
+
const evolutions = [];
|
|
176
|
+
for (let i = 0; i < snapshots.length - 1; i++) {
|
|
177
|
+
const current = snapshots[i];
|
|
178
|
+
const previous = snapshots[i + 1];
|
|
179
|
+
const principlesDelta = current.principles_count - previous.principles_count;
|
|
180
|
+
const antiPatternsDelta = current.anti_patterns_count - previous.anti_patterns_count;
|
|
181
|
+
const strategyDelta = current.strategies_count - previous.strategies_count;
|
|
182
|
+
const confCurrent = current.avg_confidence;
|
|
183
|
+
const confPrev = previous.avg_confidence;
|
|
184
|
+
const confTrend = confCurrent > confPrev + 0.02 ? 'rising' :
|
|
185
|
+
confCurrent < confPrev - 0.02 ? 'falling' : 'stable';
|
|
186
|
+
const highlights = [];
|
|
187
|
+
if (principlesDelta > 0)
|
|
188
|
+
highlights.push(`+${principlesDelta} new principles`);
|
|
189
|
+
if (principlesDelta < 0)
|
|
190
|
+
highlights.push(`${principlesDelta} principles removed (outdated)`);
|
|
191
|
+
if (antiPatternsDelta > 0)
|
|
192
|
+
highlights.push(`+${antiPatternsDelta} anti-patterns discovered`);
|
|
193
|
+
if (strategyDelta !== 0)
|
|
194
|
+
highlights.push(`${strategyDelta > 0 ? '+' : ''}${strategyDelta} strategy changes`);
|
|
195
|
+
evolutions.push({
|
|
196
|
+
domain: current.domain,
|
|
197
|
+
period: new Date(current.timestamp).toLocaleDateString(),
|
|
198
|
+
principles_added: Math.max(0, principlesDelta),
|
|
199
|
+
principles_removed: Math.abs(Math.min(0, principlesDelta)),
|
|
200
|
+
anti_patterns_discovered: Math.max(0, antiPatternsDelta),
|
|
201
|
+
strategies_changed: Math.abs(strategyDelta),
|
|
202
|
+
confidence_trend: confTrend,
|
|
203
|
+
highlights,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return evolutions;
|
|
207
|
+
}
|
|
208
|
+
extractPrinciples() {
|
|
209
|
+
const principles = [];
|
|
210
|
+
// Extract from confirmed hypotheses
|
|
211
|
+
try {
|
|
212
|
+
const confirmed = this.db.prepare(`
|
|
213
|
+
SELECT statement, type, variables, confidence, evidence_for, evidence_against
|
|
214
|
+
FROM hypotheses
|
|
215
|
+
WHERE status = 'confirmed' AND evidence_for >= ?
|
|
216
|
+
ORDER BY confidence DESC
|
|
217
|
+
`).all(this.config.minEvidence);
|
|
218
|
+
for (const h of confirmed) {
|
|
219
|
+
const total = h.evidence_for + h.evidence_against;
|
|
220
|
+
const successRate = h.evidence_for / Math.max(total, 1);
|
|
221
|
+
if (successRate < this.config.minSuccessRate)
|
|
222
|
+
continue;
|
|
223
|
+
const id = `hyp-${this.hashString(h.statement)}`;
|
|
224
|
+
const principle = {
|
|
225
|
+
id,
|
|
226
|
+
domain: h.type || this.config.brainName,
|
|
227
|
+
statement: h.statement,
|
|
228
|
+
success_rate: successRate,
|
|
229
|
+
sample_size: total,
|
|
230
|
+
confidence: h.confidence,
|
|
231
|
+
source: 'confirmed_hypothesis',
|
|
232
|
+
};
|
|
233
|
+
this.upsertPrinciple(principle);
|
|
234
|
+
principles.push(principle);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
catch { /* hypotheses table might not exist */ }
|
|
238
|
+
// Extract from research discoveries
|
|
239
|
+
try {
|
|
240
|
+
const discoveries = this.db.prepare(`
|
|
241
|
+
SELECT title, description, confidence, type, data
|
|
242
|
+
FROM research_discoveries
|
|
243
|
+
WHERE confidence >= 0.6 AND type IN ('confirmed_hypothesis', 'causal_chain')
|
|
244
|
+
ORDER BY confidence DESC LIMIT 20
|
|
245
|
+
`).all();
|
|
246
|
+
for (const d of discoveries) {
|
|
247
|
+
const id = `disc-${this.hashString(d.title)}`;
|
|
248
|
+
const principle = {
|
|
249
|
+
id,
|
|
250
|
+
domain: this.config.brainName,
|
|
251
|
+
statement: d.title,
|
|
252
|
+
success_rate: d.confidence,
|
|
253
|
+
sample_size: 1,
|
|
254
|
+
confidence: d.confidence,
|
|
255
|
+
source: `research_discovery:${d.type}`,
|
|
256
|
+
};
|
|
257
|
+
this.upsertPrinciple(principle);
|
|
258
|
+
principles.push(principle);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
catch { /* research_discoveries table might not exist */ }
|
|
262
|
+
return principles;
|
|
263
|
+
}
|
|
264
|
+
extractAntiPatterns() {
|
|
265
|
+
const antiPatterns = [];
|
|
266
|
+
// Extract from rejected hypotheses (things that don't work)
|
|
267
|
+
try {
|
|
268
|
+
const rejected = this.db.prepare(`
|
|
269
|
+
SELECT statement, type, evidence_for, evidence_against, confidence
|
|
270
|
+
FROM hypotheses
|
|
271
|
+
WHERE status = 'rejected' AND evidence_against >= ?
|
|
272
|
+
ORDER BY evidence_against DESC
|
|
273
|
+
`).all(this.config.minEvidence);
|
|
274
|
+
for (const h of rejected) {
|
|
275
|
+
const total = h.evidence_for + h.evidence_against;
|
|
276
|
+
const failureRate = h.evidence_against / Math.max(total, 1);
|
|
277
|
+
if (failureRate < this.config.minFailureRate)
|
|
278
|
+
continue;
|
|
279
|
+
const id = `anti-${this.hashString(h.statement)}`;
|
|
280
|
+
const anti = {
|
|
281
|
+
id,
|
|
282
|
+
domain: h.type || this.config.brainName,
|
|
283
|
+
statement: `NOT: ${h.statement}`,
|
|
284
|
+
failure_rate: failureRate,
|
|
285
|
+
sample_size: total,
|
|
286
|
+
confidence: h.confidence,
|
|
287
|
+
alternative: 'See confirmed principles for what works instead.',
|
|
288
|
+
};
|
|
289
|
+
this.upsertAntiPattern(anti);
|
|
290
|
+
antiPatterns.push(anti);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
catch { /* hypotheses table might not exist */ }
|
|
294
|
+
// Extract from reverted strategy adaptations
|
|
295
|
+
try {
|
|
296
|
+
const reverted = this.db.prepare(`
|
|
297
|
+
SELECT strategy, parameter, old_value, new_value, reason, revert_reason
|
|
298
|
+
FROM strategy_adaptations
|
|
299
|
+
WHERE reverted = 1
|
|
300
|
+
ORDER BY timestamp DESC LIMIT 20
|
|
301
|
+
`).all();
|
|
302
|
+
for (const r of reverted) {
|
|
303
|
+
const id = `revert-${r.strategy}-${r.parameter}`;
|
|
304
|
+
const anti = {
|
|
305
|
+
id,
|
|
306
|
+
domain: r.strategy,
|
|
307
|
+
statement: `Changing ${r.parameter} from ${r.old_value} to ${r.new_value} degrades performance`,
|
|
308
|
+
failure_rate: 1.0,
|
|
309
|
+
sample_size: 1,
|
|
310
|
+
confidence: 0.7,
|
|
311
|
+
alternative: `Keep ${r.parameter} at ${r.old_value}. Reason: ${r.revert_reason ?? r.reason}`,
|
|
312
|
+
};
|
|
313
|
+
this.upsertAntiPattern(anti);
|
|
314
|
+
antiPatterns.push(anti);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
catch { /* strategy_adaptations table might not exist */ }
|
|
318
|
+
return antiPatterns;
|
|
319
|
+
}
|
|
320
|
+
extractStrategies() {
|
|
321
|
+
const strategies = [];
|
|
322
|
+
// Extract from successful strategy adaptations
|
|
323
|
+
try {
|
|
324
|
+
const successful = this.db.prepare(`
|
|
325
|
+
SELECT strategy, parameter, old_value, new_value, reason, evidence,
|
|
326
|
+
performance_before, performance_after
|
|
327
|
+
FROM strategy_adaptations
|
|
328
|
+
WHERE reverted = 0 AND performance_after IS NOT NULL
|
|
329
|
+
AND performance_after > performance_before
|
|
330
|
+
ORDER BY (performance_after - performance_before) DESC LIMIT 20
|
|
331
|
+
`).all();
|
|
332
|
+
for (const s of successful) {
|
|
333
|
+
const improvement = s.performance_after - s.performance_before;
|
|
334
|
+
const id = `strat-${s.strategy}-${s.parameter}-${Date.now()}`;
|
|
335
|
+
const strategy = {
|
|
336
|
+
id,
|
|
337
|
+
domain: s.strategy,
|
|
338
|
+
description: `Set ${s.parameter} to ${s.new_value} (from ${s.old_value}) for ${(improvement * 100).toFixed(1)}% improvement`,
|
|
339
|
+
conditions: [s.reason],
|
|
340
|
+
effectiveness: improvement,
|
|
341
|
+
evidence_count: 1,
|
|
342
|
+
};
|
|
343
|
+
this.upsertStrategy(strategy);
|
|
344
|
+
strategies.push(strategy);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
catch { /* strategy_adaptations table might not exist */ }
|
|
348
|
+
// Extract from meta-learning optimizations
|
|
349
|
+
try {
|
|
350
|
+
const optimizations = this.db.prepare(`
|
|
351
|
+
SELECT param_name, old_value, new_value, reason, improvement
|
|
352
|
+
FROM meta_learning_optimizations
|
|
353
|
+
WHERE improvement > 0
|
|
354
|
+
ORDER BY improvement DESC LIMIT 10
|
|
355
|
+
`).all();
|
|
356
|
+
for (const o of optimizations) {
|
|
357
|
+
const id = `meta-${o.param_name}`;
|
|
358
|
+
const strategy = {
|
|
359
|
+
id,
|
|
360
|
+
domain: 'meta_learning',
|
|
361
|
+
description: `Optimize ${o.param_name} to ${o.new_value} for ${(o.improvement * 100).toFixed(1)}% gain`,
|
|
362
|
+
conditions: [o.reason],
|
|
363
|
+
effectiveness: o.improvement,
|
|
364
|
+
evidence_count: 1,
|
|
365
|
+
};
|
|
366
|
+
this.upsertStrategy(strategy);
|
|
367
|
+
strategies.push(strategy);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
catch { /* meta_learning_optimizations table might not exist */ }
|
|
371
|
+
return strategies;
|
|
372
|
+
}
|
|
373
|
+
suggestTransferDomains(domain) {
|
|
374
|
+
const allDomains = new Set();
|
|
375
|
+
try {
|
|
376
|
+
const rows = this.db.prepare(`SELECT DISTINCT domain FROM knowledge_principles`).all();
|
|
377
|
+
for (const r of rows)
|
|
378
|
+
allDomains.add(r.domain);
|
|
379
|
+
}
|
|
380
|
+
catch { /* ignore */ }
|
|
381
|
+
allDomains.delete(domain);
|
|
382
|
+
return [...allDomains].slice(0, 5);
|
|
383
|
+
}
|
|
384
|
+
upsertPrinciple(p) {
|
|
385
|
+
this.db.prepare(`
|
|
386
|
+
INSERT INTO knowledge_principles (id, domain, statement, success_rate, sample_size, confidence, source)
|
|
387
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
388
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
389
|
+
success_rate = excluded.success_rate,
|
|
390
|
+
sample_size = excluded.sample_size,
|
|
391
|
+
confidence = excluded.confidence,
|
|
392
|
+
updated_at = datetime('now')
|
|
393
|
+
`).run(p.id, p.domain, p.statement, p.success_rate, p.sample_size, p.confidence, p.source);
|
|
394
|
+
}
|
|
395
|
+
upsertAntiPattern(a) {
|
|
396
|
+
this.db.prepare(`
|
|
397
|
+
INSERT INTO knowledge_anti_patterns (id, domain, statement, failure_rate, sample_size, confidence, alternative)
|
|
398
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
399
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
400
|
+
failure_rate = excluded.failure_rate,
|
|
401
|
+
sample_size = excluded.sample_size,
|
|
402
|
+
confidence = excluded.confidence,
|
|
403
|
+
updated_at = datetime('now')
|
|
404
|
+
`).run(a.id, a.domain, a.statement, a.failure_rate, a.sample_size, a.confidence, a.alternative);
|
|
405
|
+
}
|
|
406
|
+
upsertStrategy(s) {
|
|
407
|
+
this.db.prepare(`
|
|
408
|
+
INSERT INTO knowledge_strategies (id, domain, description, conditions, effectiveness, evidence_count)
|
|
409
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
410
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
411
|
+
effectiveness = excluded.effectiveness,
|
|
412
|
+
evidence_count = knowledge_strategies.evidence_count + 1,
|
|
413
|
+
updated_at = datetime('now')
|
|
414
|
+
`).run(s.id, s.domain, s.description, JSON.stringify(s.conditions), s.effectiveness, s.evidence_count);
|
|
415
|
+
}
|
|
416
|
+
hashString(s) {
|
|
417
|
+
let hash = 0;
|
|
418
|
+
for (let i = 0; i < s.length; i++) {
|
|
419
|
+
const char = s.charCodeAt(i);
|
|
420
|
+
hash = ((hash << 5) - hash) + char;
|
|
421
|
+
hash = hash & hash;
|
|
422
|
+
}
|
|
423
|
+
return Math.abs(hash).toString(36);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
//# sourceMappingURL=knowledge-distiller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knowledge-distiller.js","sourceRoot":"","sources":["../../src/research/knowledge-distiller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAmE/C,2DAA2D;AAE3D,MAAM,UAAU,8BAA8B,CAAC,EAAqB;IAClE,EAAE,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDP,CAAC,CAAC;AACL,CAAC;AAED,2DAA2D;AAE3D,MAAM,OAAO,kBAAkB;IACrB,EAAE,CAAoB;IACtB,MAAM,CAAqC;IAC3C,GAAG,GAAG,SAAS,EAAE,CAAC;IAE1B,YAAY,EAAqB,EAAE,MAAgC;QACjE,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,MAAM,GAAG;YACZ,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,CAAC;YACpC,cAAc,EAAE,MAAM,CAAC,cAAc,IAAI,GAAG;YAC5C,cAAc,EAAE,MAAM,CAAC,cAAc,IAAI,GAAG;SAC7C,CAAC;QACF,8BAA8B,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;IAED,mGAAmG;IACnG,OAAO;QACL,MAAM,UAA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C,WAAW,CAAC,CAAC;IAClG,CAAC;IAEO,cAAc,CAAC,CAAW;QAChC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC;;;;;;;KAOf,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC,cAAc,CAAC,CAAC;IACzG,CAAC;IAEO,UAAU,CAAC,CAAS;QAC1B,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAClC,MAAM,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC7B,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;YACnC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;QACrB,CAAC;QACD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;CACF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
import { SelfObserver } from './self-observer.js';
|
|
3
|
+
import { AdaptiveStrategyEngine } from './adaptive-strategy.js';
|
|
4
|
+
import { ExperimentEngine } from './experiment-engine.js';
|
|
5
|
+
import { CrossDomainEngine } from './cross-domain-engine.js';
|
|
6
|
+
import { CounterfactualEngine } from './counterfactual-engine.js';
|
|
7
|
+
import { KnowledgeDistiller } from './knowledge-distiller.js';
|
|
8
|
+
import { ResearchAgendaEngine } from './agenda-engine.js';
|
|
9
|
+
import { AnomalyDetective } from './anomaly-detective.js';
|
|
10
|
+
import { ResearchJournal } from './journal.js';
|
|
11
|
+
import type { CausalGraph } from '../causal/engine.js';
|
|
12
|
+
import type { ResearchCycleReport } from './autonomous-scheduler.js';
|
|
13
|
+
export interface ResearchOrchestratorConfig {
|
|
14
|
+
brainName: string;
|
|
15
|
+
/** Feedback loop interval in ms. Default: 300_000 (5 min) */
|
|
16
|
+
feedbackIntervalMs?: number;
|
|
17
|
+
/** Knowledge distillation every N cycles. Default: 5 */
|
|
18
|
+
distillEvery?: number;
|
|
19
|
+
/** Research agenda regeneration every N cycles. Default: 3 */
|
|
20
|
+
agendaEvery?: number;
|
|
21
|
+
/** Journal reflection every N cycles. Default: 10 */
|
|
22
|
+
reflectEvery?: number;
|
|
23
|
+
}
|
|
24
|
+
export declare class ResearchOrchestrator {
|
|
25
|
+
readonly selfObserver: SelfObserver;
|
|
26
|
+
readonly adaptiveStrategy: AdaptiveStrategyEngine;
|
|
27
|
+
readonly experimentEngine: ExperimentEngine;
|
|
28
|
+
readonly crossDomain: CrossDomainEngine;
|
|
29
|
+
readonly counterfactual: CounterfactualEngine;
|
|
30
|
+
readonly knowledgeDistiller: KnowledgeDistiller;
|
|
31
|
+
readonly researchAgenda: ResearchAgendaEngine;
|
|
32
|
+
readonly anomalyDetective: AnomalyDetective;
|
|
33
|
+
readonly journal: ResearchJournal;
|
|
34
|
+
private brainName;
|
|
35
|
+
private feedbackTimer;
|
|
36
|
+
private cycleCount;
|
|
37
|
+
private distillEvery;
|
|
38
|
+
private agendaEvery;
|
|
39
|
+
private reflectEvery;
|
|
40
|
+
private log;
|
|
41
|
+
constructor(db: Database.Database, config: ResearchOrchestratorConfig, causalGraph?: CausalGraph);
|
|
42
|
+
/** Start the autonomous feedback loop timer. */
|
|
43
|
+
start(intervalMs?: number): void;
|
|
44
|
+
/** Stop the feedback loop. */
|
|
45
|
+
stop(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Feed a domain event from the brain's EventBus.
|
|
48
|
+
* Routes to: SelfObserver, AnomalyDetective, CrossDomain.
|
|
49
|
+
*/
|
|
50
|
+
onEvent(eventType: string, data?: Record<string, unknown>): void;
|
|
51
|
+
/**
|
|
52
|
+
* Feed a cross-brain event from CrossBrainSubscription.
|
|
53
|
+
* Routes to: CrossDomainEngine, AnomalyDetective.
|
|
54
|
+
*/
|
|
55
|
+
onCrossBrainEvent(sourceBrain: string, eventType: string, data?: Record<string, unknown>): void;
|
|
56
|
+
/**
|
|
57
|
+
* Hook into AutonomousResearchScheduler cycle completion.
|
|
58
|
+
* Records discoveries in journal and feeds metrics to anomaly detection.
|
|
59
|
+
*/
|
|
60
|
+
onResearchCycleComplete(report: ResearchCycleReport): void;
|
|
61
|
+
/**
|
|
62
|
+
* Run one autonomous feedback cycle.
|
|
63
|
+
* This is where the engines talk to each other.
|
|
64
|
+
*/
|
|
65
|
+
runFeedbackCycle(): void;
|
|
66
|
+
/** Get a comprehensive research summary for dashboards/API. */
|
|
67
|
+
getSummary(): Record<string, unknown>;
|
|
68
|
+
}
|