@timmeck/brain-core 2.36.54 → 2.36.56
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/command-center.html +111 -0
- package/dist/causal/causal-planner.d.ts +45 -0
- package/dist/causal/causal-planner.js +135 -0
- package/dist/causal/causal-planner.js.map +1 -0
- package/dist/creative/creative-engine.d.ts +81 -0
- package/dist/creative/creative-engine.js +289 -0
- package/dist/creative/creative-engine.js.map +1 -0
- package/dist/creative/index.d.ts +2 -0
- package/dist/creative/index.js +2 -0
- package/dist/creative/index.js.map +1 -0
- package/dist/dashboard/command-center-server.d.ts +6 -0
- package/dist/dashboard/command-center-server.js +58 -1
- package/dist/dashboard/command-center-server.js.map +1 -1
- package/dist/goals/research-roadmap.d.ts +73 -0
- package/dist/goals/research-roadmap.js +231 -0
- package/dist/goals/research-roadmap.js.map +1 -0
- package/dist/guardrails/guardrail-engine.d.ts +82 -0
- package/dist/guardrails/guardrail-engine.js +279 -0
- package/dist/guardrails/guardrail-engine.js.map +1 -0
- package/dist/guardrails/index.d.ts +2 -0
- package/dist/guardrails/index.js +2 -0
- package/dist/guardrails/index.js.map +1 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/llm/anthropic-provider.d.ts +2 -0
- package/dist/llm/anthropic-provider.js +27 -2
- package/dist/llm/anthropic-provider.js.map +1 -1
- package/dist/llm/index.d.ts +2 -2
- package/dist/llm/ollama-provider.d.ts +3 -0
- package/dist/llm/ollama-provider.js +28 -6
- package/dist/llm/ollama-provider.js.map +1 -1
- package/dist/llm/provider.d.ts +3 -1
- package/dist/llm/provider.js.map +1 -1
- package/dist/llm/structured-output.d.ts +6 -1
- package/dist/llm/structured-output.js.map +1 -1
- package/dist/mcp/vision-tools.d.ts +64 -0
- package/dist/mcp/vision-tools.js +106 -0
- package/dist/mcp/vision-tools.js.map +1 -0
- package/dist/research/research-orchestrator.d.ts +12 -0
- package/dist/research/research-orchestrator.js +103 -2
- package/dist/research/research-orchestrator.js.map +1 -1
- package/dist/self-modification/self-modification-engine.js +14 -1
- package/dist/self-modification/self-modification-engine.js.map +1 -1
- package/package.json +1 -1
package/command-center.html
CHANGED
|
@@ -306,6 +306,28 @@ canvas{display:block;width:100%;height:100%}
|
|
|
306
306
|
</div>
|
|
307
307
|
</div>
|
|
308
308
|
|
|
309
|
+
<!-- Guardrail Ampel -->
|
|
310
|
+
<div class="section">
|
|
311
|
+
<div class="section-title"><span class="icon">🛡️</span> Guardrails</div>
|
|
312
|
+
<div class="card" id="guardrailCard">
|
|
313
|
+
<div class="grid grid-3" style="text-align:center">
|
|
314
|
+
<div>
|
|
315
|
+
<div id="guardrailAmpel" style="width:24px;height:24px;border-radius:50%;margin:0 auto 6px;background:var(--text-dim)"></div>
|
|
316
|
+
<div style="font-size:11px;color:var(--text-dim)" data-t="Health Score">Health Score</div>
|
|
317
|
+
<div id="guardrailScore" style="font-size:18px;font-weight:700">--</div>
|
|
318
|
+
</div>
|
|
319
|
+
<div>
|
|
320
|
+
<div style="font-size:11px;color:var(--text-dim)">Circuit Breaker</div>
|
|
321
|
+
<div id="guardrailBreaker" style="font-size:14px;font-weight:600">--</div>
|
|
322
|
+
</div>
|
|
323
|
+
<div>
|
|
324
|
+
<div style="font-size:11px;color:var(--text-dim)" data-t="Geschützte Pfade">Geschützte Pfade</div>
|
|
325
|
+
<div id="guardrailPaths" style="font-size:14px;font-weight:600">--</div>
|
|
326
|
+
</div>
|
|
327
|
+
</div>
|
|
328
|
+
</div>
|
|
329
|
+
</div>
|
|
330
|
+
|
|
309
331
|
<!-- Error Log -->
|
|
310
332
|
<div class="section">
|
|
311
333
|
<div class="section-title"><span class="icon">⚠</span> <span data-t="Letzte Fehler & Warnungen">Letzte Fehler & Warnungen</span> <span id="errorCount" style="color:var(--text-dim);font-weight:400;font-size:12px"></span></div>
|
|
@@ -605,6 +627,20 @@ canvas{display:block;width:100%;height:100%}
|
|
|
605
627
|
<div class="card" style="text-align:center"><div class="card-value" id="int-tr-cost" style="color:var(--magenta)">$0.00</div><div class="card-sub" data-t="Gesamtkosten">Gesamtkosten</div></div>
|
|
606
628
|
</div>
|
|
607
629
|
</div>
|
|
630
|
+
|
|
631
|
+
<!-- Research Roadmaps (DAG) -->
|
|
632
|
+
<div class="section">
|
|
633
|
+
<div class="section-title"><span class="icon">🗺️</span> Research Roadmaps — <span data-t="Forschungs-Pläne">Forschungs-Pläne</span></div>
|
|
634
|
+
<p style="font-size:12px;color:var(--text-dim);margin-bottom:12px" data-t="Multi-step Forschungspläne mit Abhängigkeiten. Grün=erreicht, Blau=aktiv, Grau=blockiert.">Multi-step Forschungspläne mit Abhängigkeiten. Grün=erreicht, Blau=aktiv, Grau=blockiert.</p>
|
|
635
|
+
<div id="roadmapList"><div class="empty" data-t="Keine Roadmaps">Keine Roadmaps</div></div>
|
|
636
|
+
</div>
|
|
637
|
+
|
|
638
|
+
<!-- Creative Insights -->
|
|
639
|
+
<div class="section">
|
|
640
|
+
<div class="section-title"><span class="icon">✨</span> Creative Insights — <span data-t="Kreative Verbindungen">Kreative Verbindungen</span></div>
|
|
641
|
+
<p style="font-size:12px;color:var(--text-dim);margin-bottom:12px" data-t="Cross-Domain Ideen mit Neuheits- und Plausibilitäts-Scores.">Cross-Domain Ideen mit Neuheits- und Plausibilitäts-Scores.</p>
|
|
642
|
+
<div id="creativeInsightsList"><div class="empty" data-t="Keine Creative Insights">Keine Creative Insights</div></div>
|
|
643
|
+
</div>
|
|
608
644
|
</div>
|
|
609
645
|
|
|
610
646
|
<!-- ════ Page 6: Cross-Brain & Borg ═════════════════ -->
|
|
@@ -860,6 +896,12 @@ const translations = { en: {
|
|
|
860
896
|
'Traces & Spans':'Traces & Spans','Traces gesamt':'Total Traces','Aktiv':'Active','Spans gesamt':'Total Spans','Gesamtkosten':'Total Cost',
|
|
861
897
|
'Noch keine Feature-Wünsche — Brain analysiert automatisch':'No feature wishes yet — Brain analyzes automatically',
|
|
862
898
|
'Brain erkennt was ihm fehlt und sucht nach passenden Features aus absorbierten Repos.':'Brain detects what it needs and searches for matching features from absorbed repos.',
|
|
899
|
+
'Geschützte Pfade':'Protected Paths','Forschungs-Pläne':'Research Plans',
|
|
900
|
+
'Multi-step Forschungspläne mit Abhängigkeiten. Grün=erreicht, Blau=aktiv, Grau=blockiert.':'Multi-step research plans with dependencies. Green=achieved, Blue=active, Gray=blocked.',
|
|
901
|
+
'Keine Roadmaps':'No roadmaps','erreicht':'achieved',
|
|
902
|
+
'Kreative Verbindungen':'Creative Connections',
|
|
903
|
+
'Cross-Domain Ideen mit Neuheits- und Plausibilitäts-Scores.':'Cross-domain ideas with novelty and plausibility scores.',
|
|
904
|
+
'Keine Creative Insights':'No creative insights','Neuheit':'Novelty','Plausibilität':'Plausibility',
|
|
863
905
|
}};
|
|
864
906
|
let currentLang = localStorage.getItem('brain-lang') || 'en';
|
|
865
907
|
function t(text) { if (currentLang === 'en' && translations.en[text]) return translations.en[text]; return text; }
|
|
@@ -931,6 +973,9 @@ function connectSSE() {
|
|
|
931
973
|
es.addEventListener('knowledge', e => { state.knowledge = JSON.parse(e.data); renderKnowledge(); });
|
|
932
974
|
es.addEventListener('debates', e => { state.debates = JSON.parse(e.data); renderDebates(); });
|
|
933
975
|
es.addEventListener('emotional', e => { state.emotional = JSON.parse(e.data); });
|
|
976
|
+
es.addEventListener('guardrail-health', e => { state.guardrailHealth = JSON.parse(e.data); renderGuardrails(); });
|
|
977
|
+
es.addEventListener('roadmaps', e => { state.roadmaps = JSON.parse(e.data); renderRoadmaps(); });
|
|
978
|
+
es.addEventListener('creative-insights', e => { state.creativeInsights = JSON.parse(e.data); renderCreativeInsights(); });
|
|
934
979
|
es.onerror = () => { state.connected = false; updateConnection(); };
|
|
935
980
|
}
|
|
936
981
|
|
|
@@ -951,10 +996,14 @@ async function loadInitial() {
|
|
|
951
996
|
state.missions = data.missions; state.knowledge = data.knowledge; state.repoAbsorber = data.repoAbsorber; state.intelligence = data.intelligence;
|
|
952
997
|
state.debates = data.debates;
|
|
953
998
|
state.emotional = data.emotional;
|
|
999
|
+
state.guardrailHealth = data.guardrailHealth;
|
|
1000
|
+
state.roadmaps = data.roadmaps;
|
|
1001
|
+
state.creativeInsights = data.creativeInsights;
|
|
954
1002
|
if (data.thoughts) { state.thoughts = data.thoughts; renderThoughts(); }
|
|
955
1003
|
renderEcosystem(); renderEngines(); renderWatchdog(); renderPlugins();
|
|
956
1004
|
renderBorg(); renderAnalytics(); renderLLM(); renderErrors();
|
|
957
1005
|
renderSelfMod(); renderMissions(); renderRepoAbsorber(); renderIntelligence(); renderKnowledge(); renderDebates();
|
|
1006
|
+
renderGuardrails(); renderRoadmaps(); renderCreativeInsights();
|
|
958
1007
|
} catch {}
|
|
959
1008
|
}
|
|
960
1009
|
|
|
@@ -1682,6 +1731,68 @@ function renderDebates() {
|
|
|
1682
1731
|
}
|
|
1683
1732
|
}
|
|
1684
1733
|
|
|
1734
|
+
// ── Guardrails ───────────────────────────────────────────
|
|
1735
|
+
function renderGuardrails() {
|
|
1736
|
+
const d = state.guardrailHealth; if (!d) return;
|
|
1737
|
+
const score = d.score ?? d.healthScore ?? 0;
|
|
1738
|
+
const ampel = document.getElementById('guardrailAmpel');
|
|
1739
|
+
const scoreEl = document.getElementById('guardrailScore');
|
|
1740
|
+
const breakerEl = document.getElementById('guardrailBreaker');
|
|
1741
|
+
const pathsEl = document.getElementById('guardrailPaths');
|
|
1742
|
+
if (ampel) {
|
|
1743
|
+
const col = score > 0.8 ? 'var(--green)' : score > 0.5 ? 'var(--yellow)' : 'var(--red)';
|
|
1744
|
+
ampel.style.background = col;
|
|
1745
|
+
ampel.style.boxShadow = `0 0 12px ${col}`;
|
|
1746
|
+
}
|
|
1747
|
+
if (scoreEl) scoreEl.textContent = (score * 100).toFixed(0) + '%';
|
|
1748
|
+
if (breakerEl) {
|
|
1749
|
+
const tripped = d.circuitBreakerTripped ?? d.circuitBreaker?.tripped ?? false;
|
|
1750
|
+
breakerEl.textContent = tripped ? 'TRIPPED' : 'OK';
|
|
1751
|
+
breakerEl.style.color = tripped ? 'var(--red)' : 'var(--green)';
|
|
1752
|
+
}
|
|
1753
|
+
if (pathsEl) pathsEl.textContent = d.protectedPaths ?? d.protected ?? '-';
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
// ── Roadmaps ─────────────────────────────────────────────
|
|
1757
|
+
function renderRoadmaps() {
|
|
1758
|
+
const list = state.roadmaps; if (!list) return;
|
|
1759
|
+
const el = document.getElementById('roadmapList'); if (!el) return;
|
|
1760
|
+
const items = Array.isArray(list) ? list : [];
|
|
1761
|
+
if (!items.length) { el.innerHTML = `<div class="empty">${t('Keine Roadmaps')}</div>`; return; }
|
|
1762
|
+
el.innerHTML = items.map(rm => {
|
|
1763
|
+
const statusCol = rm.status === 'completed' ? 'var(--green)' : rm.status === 'active' ? 'var(--cyan)' : 'var(--text-dim)';
|
|
1764
|
+
return `<div class="card" style="margin-bottom:8px;padding:10px 14px">
|
|
1765
|
+
<div style="display:flex;justify-content:space-between;align-items:center">
|
|
1766
|
+
<strong style="color:var(--cyan)">#${rm.id}: ${(rm.title||'').substring(0,80)}</strong>
|
|
1767
|
+
<span style="color:${statusCol};font-size:11px;text-transform:uppercase">${rm.status||'?'}</span>
|
|
1768
|
+
</div>
|
|
1769
|
+
${rm.goalCount ? `<div style="font-size:11px;color:var(--text-dim);margin-top:4px">${rm.goalCount} Goals | ${rm.achievedCount ?? 0} ${t('erreicht')}</div>` : ''}
|
|
1770
|
+
</div>`;
|
|
1771
|
+
}).join('');
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1774
|
+
// ── Creative Insights ────────────────────────────────────
|
|
1775
|
+
function renderCreativeInsights() {
|
|
1776
|
+
const list = state.creativeInsights; if (!list) return;
|
|
1777
|
+
const el = document.getElementById('creativeInsightsList'); if (!el) return;
|
|
1778
|
+
const items = Array.isArray(list) ? list : [];
|
|
1779
|
+
if (!items.length) { el.innerHTML = `<div class="empty">${t('Keine Creative Insights')}</div>`; return; }
|
|
1780
|
+
el.innerHTML = items.slice(0, 10).map(ins => {
|
|
1781
|
+
const novelty = ins.noveltyScore ?? ins.novelty ?? 0;
|
|
1782
|
+
const plaus = ins.plausibility ?? 0;
|
|
1783
|
+
const nCol = novelty > 0.7 ? 'var(--green)' : novelty > 0.4 ? 'var(--yellow)' : 'var(--text-dim)';
|
|
1784
|
+
const pCol = plaus > 0.7 ? 'var(--green)' : plaus > 0.4 ? 'var(--yellow)' : 'var(--text-dim)';
|
|
1785
|
+
return `<div class="card" style="margin-bottom:6px;padding:8px 14px">
|
|
1786
|
+
<div style="font-size:13px;color:var(--text)">${(ins.title ?? ins.description ?? '').substring(0,120)}</div>
|
|
1787
|
+
<div style="font-size:11px;color:var(--text-dim);margin-top:4px">
|
|
1788
|
+
${t('Neuheit')}: <span style="color:${nCol}">${(novelty*100).toFixed(0)}%</span> |
|
|
1789
|
+
${t('Plausibilität')}: <span style="color:${pCol}">${(plaus*100).toFixed(0)}%</span> |
|
|
1790
|
+
Status: ${ins.status || '-'}
|
|
1791
|
+
</div>
|
|
1792
|
+
</div>`;
|
|
1793
|
+
}).join('');
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1685
1796
|
// ── Quick Actions ─────────────────────────────────────────
|
|
1686
1797
|
document.querySelectorAll('.action-btn').forEach(btn => {
|
|
1687
1798
|
btn.addEventListener('click', async () => {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { CausalGraph } from './engine.js';
|
|
2
|
+
import type { GoalEngine, Goal } from '../goals/goal-engine.js';
|
|
3
|
+
export interface CausalDiagnosis {
|
|
4
|
+
metric: string;
|
|
5
|
+
rootCauses: Array<{
|
|
6
|
+
event: string;
|
|
7
|
+
strength: number;
|
|
8
|
+
lag_ms: number;
|
|
9
|
+
confidence: number;
|
|
10
|
+
}>;
|
|
11
|
+
confounders: string[];
|
|
12
|
+
suggestedInterventions: Intervention[];
|
|
13
|
+
}
|
|
14
|
+
export interface Intervention {
|
|
15
|
+
action: string;
|
|
16
|
+
targetEvent: string;
|
|
17
|
+
expectedEffect: number;
|
|
18
|
+
confidence: number;
|
|
19
|
+
sideEffects: string[];
|
|
20
|
+
}
|
|
21
|
+
export interface PredictedOutcome {
|
|
22
|
+
intervention: Intervention;
|
|
23
|
+
predictedMetricDelta: number;
|
|
24
|
+
confidence: number;
|
|
25
|
+
reasoning: string;
|
|
26
|
+
}
|
|
27
|
+
export declare class CausalPlanner {
|
|
28
|
+
private readonly causalGraph;
|
|
29
|
+
private readonly log;
|
|
30
|
+
private goalEngine;
|
|
31
|
+
constructor(causalGraph: CausalGraph);
|
|
32
|
+
setGoalEngine(engine: GoalEngine): void;
|
|
33
|
+
/** Find root causes for a metric being off-target. */
|
|
34
|
+
diagnose(goalMetric: string): CausalDiagnosis;
|
|
35
|
+
/** Generate intervention suggestions based on causal analysis. */
|
|
36
|
+
suggestInterventions(goalMetric: string): Intervention[];
|
|
37
|
+
private suggestInterventionsFromCauses;
|
|
38
|
+
/** Predict what happens if an intervention is applied. */
|
|
39
|
+
predictOutcome(intervention: Intervention): PredictedOutcome;
|
|
40
|
+
/** Diagnose stagnant goals and suggest causal interventions. */
|
|
41
|
+
diagnoseStagnantGoals(): Array<{
|
|
42
|
+
goal: Goal;
|
|
43
|
+
diagnosis: CausalDiagnosis;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { getLogger } from '../utils/logger.js';
|
|
2
|
+
// ── CausalPlanner ────────────────────────────────────────
|
|
3
|
+
export class CausalPlanner {
|
|
4
|
+
causalGraph;
|
|
5
|
+
log = getLogger();
|
|
6
|
+
goalEngine = null;
|
|
7
|
+
constructor(causalGraph) {
|
|
8
|
+
this.causalGraph = causalGraph;
|
|
9
|
+
}
|
|
10
|
+
setGoalEngine(engine) { this.goalEngine = engine; }
|
|
11
|
+
// ── Diagnose ───────────────────────────────────────────
|
|
12
|
+
/** Find root causes for a metric being off-target. */
|
|
13
|
+
diagnose(goalMetric) {
|
|
14
|
+
const causes = this.causalGraph.getCauses(goalMetric);
|
|
15
|
+
// Sort by strength × confidence for strongest causes first
|
|
16
|
+
const ranked = causes
|
|
17
|
+
.sort((a, b) => (b.strength * b.confidence) - (a.strength * a.confidence))
|
|
18
|
+
.slice(0, 10);
|
|
19
|
+
const rootCauses = ranked.map(edge => ({
|
|
20
|
+
event: edge.cause,
|
|
21
|
+
strength: edge.strength,
|
|
22
|
+
lag_ms: edge.lag_ms,
|
|
23
|
+
confidence: edge.confidence,
|
|
24
|
+
}));
|
|
25
|
+
// Find deeper root causes via chains
|
|
26
|
+
const deepRoots = [];
|
|
27
|
+
const allChains = this.causalGraph.findChains();
|
|
28
|
+
for (const cause of rootCauses.slice(0, 3)) {
|
|
29
|
+
// Filter chains that contain our cause and the goalMetric
|
|
30
|
+
const relevant = allChains.filter(c => c.chain.includes(cause.event) && c.chain.includes(goalMetric));
|
|
31
|
+
for (const chain of relevant) {
|
|
32
|
+
if (chain.chain.length > 2) {
|
|
33
|
+
const origin = chain.chain[0];
|
|
34
|
+
if (!rootCauses.some(r => r.event === origin) && !deepRoots.some(r => r.event === origin)) {
|
|
35
|
+
deepRoots.push({
|
|
36
|
+
event: origin,
|
|
37
|
+
strength: chain.totalStrength,
|
|
38
|
+
lag_ms: chain.totalLag,
|
|
39
|
+
confidence: chain.totalStrength, // approximate
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Find confounders between each cause and the metric
|
|
46
|
+
const confounders = [];
|
|
47
|
+
for (const cause of rootCauses.slice(0, 5)) {
|
|
48
|
+
try {
|
|
49
|
+
const cf = this.causalGraph.detectConfounders(cause.event, goalMetric);
|
|
50
|
+
for (const c of cf) {
|
|
51
|
+
if (!confounders.includes(c))
|
|
52
|
+
confounders.push(c);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch { /* no confounders */ }
|
|
56
|
+
}
|
|
57
|
+
const allRootCauses = [...rootCauses, ...deepRoots];
|
|
58
|
+
const interventions = this.suggestInterventionsFromCauses(allRootCauses, goalMetric);
|
|
59
|
+
this.log.info(`[causal-planner] Diagnosed ${goalMetric}: ${allRootCauses.length} root causes, ${confounders.length} confounders`);
|
|
60
|
+
return {
|
|
61
|
+
metric: goalMetric,
|
|
62
|
+
rootCauses: allRootCauses,
|
|
63
|
+
confounders,
|
|
64
|
+
suggestedInterventions: interventions,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// ── Suggest Interventions ──────────────────────────────
|
|
68
|
+
/** Generate intervention suggestions based on causal analysis. */
|
|
69
|
+
suggestInterventions(goalMetric) {
|
|
70
|
+
const diagnosis = this.diagnose(goalMetric);
|
|
71
|
+
return diagnosis.suggestedInterventions;
|
|
72
|
+
}
|
|
73
|
+
suggestInterventionsFromCauses(rootCauses, targetMetric) {
|
|
74
|
+
const interventions = [];
|
|
75
|
+
for (const cause of rootCauses.slice(0, 5)) {
|
|
76
|
+
// Determine action based on edge direction
|
|
77
|
+
const effects = this.causalGraph.getEffects(cause.event);
|
|
78
|
+
const targetEdge = effects.find(e => e.effect === targetMetric);
|
|
79
|
+
// direction is number: +1 = positive, -1 = negative
|
|
80
|
+
const directionNum = targetEdge?.direction ?? 1;
|
|
81
|
+
const action = directionNum >= 0
|
|
82
|
+
? `increase_${cause.event}`
|
|
83
|
+
: `decrease_${cause.event}`;
|
|
84
|
+
// Find potential side effects — other things caused by this event
|
|
85
|
+
const sideEffects = effects
|
|
86
|
+
.filter(e => e.effect !== targetMetric)
|
|
87
|
+
.map(e => `${e.direction >= 0 ? '+' : '-'}${e.effect} (strength: ${e.strength.toFixed(2)})`);
|
|
88
|
+
interventions.push({
|
|
89
|
+
action,
|
|
90
|
+
targetEvent: cause.event,
|
|
91
|
+
expectedEffect: cause.strength * directionNum,
|
|
92
|
+
confidence: cause.confidence,
|
|
93
|
+
sideEffects,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return interventions;
|
|
97
|
+
}
|
|
98
|
+
// ── Predict Outcome ────────────────────────────────────
|
|
99
|
+
/** Predict what happens if an intervention is applied. */
|
|
100
|
+
predictOutcome(intervention) {
|
|
101
|
+
const predictedDelta = intervention.expectedEffect;
|
|
102
|
+
const confidence = intervention.confidence;
|
|
103
|
+
const reasoning = `Direct causal effect of ${intervention.action} on ${intervention.targetEvent}`;
|
|
104
|
+
return {
|
|
105
|
+
intervention,
|
|
106
|
+
predictedMetricDelta: predictedDelta,
|
|
107
|
+
confidence,
|
|
108
|
+
reasoning,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
// ── Goal Integration ───────────────────────────────────
|
|
112
|
+
/** Diagnose stagnant goals and suggest causal interventions. */
|
|
113
|
+
diagnoseStagnantGoals() {
|
|
114
|
+
if (!this.goalEngine)
|
|
115
|
+
return [];
|
|
116
|
+
const results = [];
|
|
117
|
+
const activeGoals = this.goalEngine.listGoals('active');
|
|
118
|
+
for (const goal of activeGoals) {
|
|
119
|
+
const progress = this.goalEngine.getProgress(goal.id);
|
|
120
|
+
if (progress && progress.trend === 'stagnant') {
|
|
121
|
+
try {
|
|
122
|
+
const diagnosis = this.diagnose(goal.metricName);
|
|
123
|
+
if (diagnosis.rootCauses.length > 0) {
|
|
124
|
+
results.push({ goal, diagnosis });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
// No causal data for this metric
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return results;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=causal-planner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"causal-planner.js","sourceRoot":"","sources":["../../src/causal/causal-planner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AA+B/C,4DAA4D;AAE5D,MAAM,OAAO,aAAa;IAC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C,IAAI,CAAC,EAAG,CAAC,CAAC;YACvD,IAAI,QAAQ,IAAI,QAAQ,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;gBAC9C,IAAI,CAAC;oBACH,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBACjD,IAAI,SAAS,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBACpC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;oBACpC,CAAC;gBACH,CAAC;gBAAC,MAAM,CAAC;oBACP,iCAAiC;gBACnC,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
import type { KnowledgeDistiller } from '../research/knowledge-distiller.js';
|
|
3
|
+
import type { HypothesisEngine } from '../hypothesis/engine.js';
|
|
4
|
+
import type { ThoughtStream } from '../consciousness/thought-stream.js';
|
|
5
|
+
import type { LLMService } from '../llm/llm-service.js';
|
|
6
|
+
export interface CreativeInsight {
|
|
7
|
+
id?: number;
|
|
8
|
+
type: 'cross_pollination' | 'analogy' | 'speculation' | 'imagination';
|
|
9
|
+
sourceA: {
|
|
10
|
+
domain: string;
|
|
11
|
+
principle: string;
|
|
12
|
+
};
|
|
13
|
+
sourceB: {
|
|
14
|
+
domain: string;
|
|
15
|
+
principle: string;
|
|
16
|
+
};
|
|
17
|
+
insight: string;
|
|
18
|
+
noveltyScore: number;
|
|
19
|
+
plausibility: number;
|
|
20
|
+
status: 'raw' | 'tested' | 'confirmed' | 'rejected';
|
|
21
|
+
createdAt?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface Analogy {
|
|
24
|
+
concept: string;
|
|
25
|
+
analogousConcept: string;
|
|
26
|
+
sourceDomain: string;
|
|
27
|
+
targetDomain: string;
|
|
28
|
+
similarity: number;
|
|
29
|
+
explanation: string;
|
|
30
|
+
}
|
|
31
|
+
export interface SpeculativeHypothesis {
|
|
32
|
+
hypothesis: string;
|
|
33
|
+
basedOn: string[];
|
|
34
|
+
novelty: number;
|
|
35
|
+
plausibility: number;
|
|
36
|
+
}
|
|
37
|
+
export interface CreativeEngineConfig {
|
|
38
|
+
brainName: string;
|
|
39
|
+
/** Max insights per cross-pollination cycle. Default: 5 */
|
|
40
|
+
maxInsightsPerCycle?: number;
|
|
41
|
+
/** Topic overlap threshold (< this = sufficiently different). Default: 0.3 */
|
|
42
|
+
overlapThreshold?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface CreativeEngineStatus {
|
|
45
|
+
totalInsights: number;
|
|
46
|
+
byType: Record<string, number>;
|
|
47
|
+
byStatus: Record<string, number>;
|
|
48
|
+
topInsights: CreativeInsight[];
|
|
49
|
+
}
|
|
50
|
+
export declare function runCreativeMigration(db: Database.Database): void;
|
|
51
|
+
export declare class CreativeEngine {
|
|
52
|
+
private readonly db;
|
|
53
|
+
private readonly config;
|
|
54
|
+
private readonly log;
|
|
55
|
+
private distiller;
|
|
56
|
+
private hypothesisEngine;
|
|
57
|
+
private llmService;
|
|
58
|
+
private ts;
|
|
59
|
+
constructor(db: Database.Database, config: CreativeEngineConfig);
|
|
60
|
+
setKnowledgeDistiller(distiller: KnowledgeDistiller): void;
|
|
61
|
+
setHypothesisEngine(engine: HypothesisEngine): void;
|
|
62
|
+
setLLMService(service: LLMService): void;
|
|
63
|
+
setThoughtStream(stream: ThoughtStream): void;
|
|
64
|
+
/** Cross-pollinate principles from different domains. */
|
|
65
|
+
crossPollinate(): CreativeInsight[];
|
|
66
|
+
/** Find analogies for a concept across different domains. */
|
|
67
|
+
findAnalogies(concept: string): Analogy[];
|
|
68
|
+
/** Generate speculative hypotheses by combining principles. */
|
|
69
|
+
speculate(): SpeculativeHypothesis[];
|
|
70
|
+
/** Generate imaginative scenarios from a premise. */
|
|
71
|
+
imagine(premise: string): CreativeInsight[];
|
|
72
|
+
/** Convert top insights into testable hypotheses. */
|
|
73
|
+
convertTopInsights(minNovelty?: number): number;
|
|
74
|
+
getInsights(limit?: number, status?: string): CreativeInsight[];
|
|
75
|
+
getStatus(): CreativeEngineStatus;
|
|
76
|
+
private loadPrinciples;
|
|
77
|
+
private computeOverlap;
|
|
78
|
+
private tokenize;
|
|
79
|
+
private generateCrossPollination;
|
|
80
|
+
private storeInsight;
|
|
81
|
+
}
|