@timmeck/brain-core 2.36.64 → 2.36.66

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.
Files changed (33) hide show
  1. package/README.md +6 -2
  2. package/command-center.html +59 -2
  3. package/dist/dashboard/command-center-server.d.ts +1 -0
  4. package/dist/dashboard/command-center-server.js +13 -1
  5. package/dist/dashboard/command-center-server.js.map +1 -1
  6. package/dist/dream/consolidator.js +2 -2
  7. package/dist/dream/dream-engine.d.ts +4 -0
  8. package/dist/dream/dream-engine.js +28 -3
  9. package/dist/dream/dream-engine.js.map +1 -1
  10. package/dist/dream/types.d.ts +5 -5
  11. package/dist/governance/engine-registry.d.ts +61 -0
  12. package/dist/governance/engine-registry.js +301 -0
  13. package/dist/governance/engine-registry.js.map +1 -0
  14. package/dist/governance/governance-layer.d.ts +75 -0
  15. package/dist/governance/governance-layer.js +231 -0
  16. package/dist/governance/governance-layer.js.map +1 -0
  17. package/dist/governance/index.d.ts +8 -0
  18. package/dist/governance/index.js +5 -0
  19. package/dist/governance/index.js.map +1 -0
  20. package/dist/governance/loop-detector.d.ts +46 -0
  21. package/dist/governance/loop-detector.js +266 -0
  22. package/dist/governance/loop-detector.js.map +1 -0
  23. package/dist/governance/runtime-influence-tracker.d.ts +50 -0
  24. package/dist/governance/runtime-influence-tracker.js +163 -0
  25. package/dist/governance/runtime-influence-tracker.js.map +1 -0
  26. package/dist/index.d.ts +8 -0
  27. package/dist/index.js +5 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/prediction/prediction-engine.js +1 -1
  30. package/dist/research/research-orchestrator.d.ts +12 -0
  31. package/dist/research/research-orchestrator.js +122 -0
  32. package/dist/research/research-orchestrator.js.map +1 -1
  33. package/package.json +1 -1
@@ -73,7 +73,7 @@ export class PredictionEngine {
73
73
  ewmaAlpha: config.ewmaAlpha ?? 0.3,
74
74
  trendBeta: config.trendBeta ?? 0.1,
75
75
  minDataPoints: config.minDataPoints ?? 5,
76
- minConfidence: config.minConfidence ?? 0.5,
76
+ minConfidence: config.minConfidence ?? 0.3,
77
77
  maxPredictionsPerCycle: config.maxPredictionsPerCycle ?? 5,
78
78
  resolveIntervalMs: config.resolveIntervalMs ?? 60_000,
79
79
  };
@@ -136,6 +136,10 @@ export declare class ResearchOrchestrator {
136
136
  private contentForge;
137
137
  private codeForge;
138
138
  private strategyForge;
139
+ private engineRegistry;
140
+ private runtimeInfluenceTracker;
141
+ private loopDetector;
142
+ private governanceLayer;
139
143
  private lastAutoMissionTime;
140
144
  private lastGoalMissionTime;
141
145
  private roadmapBootstrapped;
@@ -276,6 +280,14 @@ export declare class ResearchOrchestrator {
276
280
  setCodeForge(forge: import('../codegen/code-forge.js').CodeForge): void;
277
281
  /** Set the StrategyForge — autonomous strategy execution. */
278
282
  setStrategyForge(forge: import('../strategy/strategy-forge.js').StrategyForge): void;
283
+ /** Set the EngineRegistry — formal engine profiles for governance. */
284
+ setEngineRegistry(registry: import('../governance/engine-registry.js').EngineRegistry): void;
285
+ /** Set the RuntimeInfluenceTracker — before/after snapshots for influence tracking. */
286
+ setRuntimeInfluenceTracker(tracker: import('../governance/runtime-influence-tracker.js').RuntimeInfluenceTracker): void;
287
+ /** Set the LoopDetector — anti-pattern detection. */
288
+ setLoopDetector(detector: import('../governance/loop-detector.js').LoopDetector): void;
289
+ /** Set the GovernanceLayer — active engine control. */
290
+ setGovernanceLayer(layer: import('../governance/governance-layer.js').GovernanceLayer): void;
279
291
  /** Set the LLMService — propagates to all engines that can use LLM. */
280
292
  setLLMService(llm: LLMService): void;
281
293
  /** Get the LLMService instance. */
@@ -85,6 +85,10 @@ export class ResearchOrchestrator {
85
85
  contentForge = null;
86
86
  codeForge = null;
87
87
  strategyForge = null;
88
+ engineRegistry = null;
89
+ runtimeInfluenceTracker = null;
90
+ loopDetector = null;
91
+ governanceLayer = null;
88
92
  lastAutoMissionTime = 0;
89
93
  lastGoalMissionTime = 0;
90
94
  roadmapBootstrapped = false;
@@ -294,6 +298,14 @@ export class ResearchOrchestrator {
294
298
  setCodeForge(forge) { this.codeForge = forge; }
295
299
  /** Set the StrategyForge — autonomous strategy execution. */
296
300
  setStrategyForge(forge) { this.strategyForge = forge; }
301
+ /** Set the EngineRegistry — formal engine profiles for governance. */
302
+ setEngineRegistry(registry) { this.engineRegistry = registry; }
303
+ /** Set the RuntimeInfluenceTracker — before/after snapshots for influence tracking. */
304
+ setRuntimeInfluenceTracker(tracker) { this.runtimeInfluenceTracker = tracker; }
305
+ /** Set the LoopDetector — anti-pattern detection. */
306
+ setLoopDetector(detector) { this.loopDetector = detector; }
307
+ /** Set the GovernanceLayer — active engine control. */
308
+ setGovernanceLayer(layer) { this.governanceLayer = layer; }
297
309
  /** Set the LLMService — propagates to all engines that can use LLM. */
298
310
  setLLMService(llm) {
299
311
  this.llmService = llm;
@@ -876,6 +888,21 @@ export class ResearchOrchestrator {
876
888
  this.predictionEngine.recordMetric('knowledge_confidence', kSummary.avgConfidence, 'metric');
877
889
  }
878
890
  catch { /* skip */ }
891
+ // 11a. Error-domain metrics (only brain has errors table — try/catch)
892
+ try {
893
+ const errorTotal = this.db.prepare(`SELECT COUNT(*) as cnt FROM errors`).get().cnt;
894
+ const errorUnresolved = this.db.prepare(`SELECT COUNT(*) as cnt FROM errors WHERE resolved = 0`).get().cnt;
895
+ const oneHourAgo = Date.now() - 3_600_000;
896
+ const errorRate1h = this.db.prepare(`SELECT COUNT(*) as cnt FROM errors WHERE timestamp > ?`).get(oneHourAgo).cnt;
897
+ const solutionTotal = this.db.prepare(`SELECT COUNT(*) as cnt FROM solutions`).get().cnt;
898
+ const resolutionRate = errorTotal > 0 ? (errorTotal - errorUnresolved) / errorTotal : 0;
899
+ this.predictionEngine.recordMetric('error_total', errorTotal, 'error');
900
+ this.predictionEngine.recordMetric('error_unresolved', errorUnresolved, 'error');
901
+ this.predictionEngine.recordMetric('error_rate_1h', errorRate1h, 'error');
902
+ this.predictionEngine.recordMetric('solution_total', solutionTotal, 'error');
903
+ this.predictionEngine.recordMetric('error_resolution_rate', resolutionRate, 'error');
904
+ }
905
+ catch { /* errors/solutions tables don't exist in this brain — skip */ }
879
906
  ts?.emit('orchestrator', 'perceiving', `Self-metrics recorded: ${anomalies.length} anomalies, ${insights.length} insights, ${cycleDuration}ms`);
880
907
  // 11b. Re-resolve predictions now that fresh metrics are available
881
908
  // (Step 9 resolves before metrics are recorded, so we re-check here)
@@ -974,6 +1001,9 @@ export class ResearchOrchestrator {
974
1001
  this.predictionEngine.recordMetric('scanner_total_repos', status.total_repos, 'scanner');
975
1002
  this.predictionEngine.recordMetric('scanner_breakouts', status.by_level.breakout, 'scanner');
976
1003
  this.predictionEngine.recordMetric('scanner_signals', status.by_level.signal, 'scanner');
1004
+ this.predictionEngine.recordMetric('scanner_avg_score', status.avg_score ?? 0, 'scanner');
1005
+ this.predictionEngine.recordMetric('scanner_new_breakouts', scan.new_breakouts, 'scanner');
1006
+ this.predictionEngine.recordMetric('scanner_new_signals', scan.new_signals, 'scanner');
977
1007
  }
978
1008
  // Journal new breakouts
979
1009
  if (scan.new_breakouts > 0) {
@@ -1163,6 +1193,23 @@ export class ResearchOrchestrator {
1163
1193
  const gaps = this.curiosityEngine.detectGaps();
1164
1194
  if (gaps.length > 0) {
1165
1195
  ts?.emit('curiosity', 'discovering', `Found ${gaps.length} knowledge gap(s): ${gaps.slice(0, 3).map(g => `"${g.topic}" (${(g.gapScore * 100).toFixed(0)}%)`).join(', ')}`, gaps.some(g => g.gapType === 'dark_zone') ? 'notable' : 'routine');
1196
+ // Bridge: feed top-3 gaps as observations into HypothesisEngine → targeted hypotheses
1197
+ for (const gap of gaps.slice(0, 3)) {
1198
+ this.hypothesisEngine.observe({
1199
+ source: this.brainName,
1200
+ type: `knowledge_gap:${gap.topic}`,
1201
+ value: gap.gapScore,
1202
+ timestamp: now,
1203
+ metadata: { gapType: gap.gapType, attentionScore: gap.attentionScore, knowledgeScore: gap.knowledgeScore },
1204
+ });
1205
+ }
1206
+ // Bridge: feed gap metrics into PredictionEngine
1207
+ if (this.predictionEngine) {
1208
+ this.predictionEngine.recordMetric('knowledge_gap_count', gaps.length, 'metric');
1209
+ for (const gap of gaps.slice(0, 3)) {
1210
+ this.predictionEngine.recordMetric(`gap_score:${gap.topic}`, gap.gapScore, 'metric');
1211
+ }
1212
+ }
1166
1213
  // Journal dark zones (truly unknown territory)
1167
1214
  for (const gap of gaps.filter(g => g.gapType === 'dark_zone').slice(0, 2)) {
1168
1215
  this.journal.write({
@@ -1402,6 +1449,25 @@ export class ResearchOrchestrator {
1402
1449
  });
1403
1450
  }
1404
1451
  }
1452
+ // 22c. Sync DreamEngine params from ParameterRegistry
1453
+ if (this.parameterRegistry && this.dreamEngine) {
1454
+ const clusterSim = this.parameterRegistry.get('dream', 'cluster_similarity');
1455
+ const replayBatch = this.parameterRegistry.get('dream', 'replay_batch_size');
1456
+ const maxConsol = this.parameterRegistry.get('dream', 'max_consolidations');
1457
+ const pruneThreshold = this.parameterRegistry.get('dream', 'prune_threshold');
1458
+ const learningRate = this.parameterRegistry.get('dream', 'learning_rate');
1459
+ const decayRate = this.parameterRegistry.get('dream', 'importance_decay_rate');
1460
+ if (clusterSim !== undefined || replayBatch !== undefined || maxConsol !== undefined || pruneThreshold !== undefined || learningRate !== undefined || decayRate !== undefined) {
1461
+ this.dreamEngine.updateConfig({
1462
+ ...(clusterSim !== undefined ? { clusterSimilarityThreshold: clusterSim } : {}),
1463
+ ...(replayBatch !== undefined ? { replayBatchSize: replayBatch } : {}),
1464
+ ...(maxConsol !== undefined ? { maxConsolidationsPerCycle: maxConsol } : {}),
1465
+ ...(pruneThreshold !== undefined ? { dreamPruneThreshold: pruneThreshold } : {}),
1466
+ ...(learningRate !== undefined ? { dreamLearningRate: learningRate } : {}),
1467
+ ...(decayRate !== undefined ? { importanceDecayRate: decayRate } : {}),
1468
+ });
1469
+ }
1470
+ }
1405
1471
  // Step 23: Blind Spot Detection (every 5 cycles)
1406
1472
  if (this.curiosityEngine && this.cycleCount % 5 === 0) {
1407
1473
  try {
@@ -2741,6 +2807,62 @@ export class ResearchOrchestrator {
2741
2807
  this.log.warn(`[orchestrator] Step 65 (outcome review) error: ${err.message}`);
2742
2808
  }
2743
2809
  }
2810
+ // Step 66: RuntimeInfluenceTracker — feed into CausalGraph (every 10 cycles)
2811
+ if (this.runtimeInfluenceTracker && this.causalGraph && this.cycleCount % 10 === 0) {
2812
+ try {
2813
+ ts?.emit('governance', 'analyzing', 'Step 66: Feeding engine influences into CausalGraph...', 'routine');
2814
+ this.runtimeInfluenceTracker.feedIntoCausalGraph(this.causalGraph);
2815
+ if (this.metaCognitionLayer)
2816
+ this.metaCognitionLayer.recordStep('influence_tracker', this.cycleCount, { insights: 0 });
2817
+ }
2818
+ catch (err) {
2819
+ this.log.warn(`[orchestrator] Step 66 (influence tracker) error: ${err.message}`);
2820
+ }
2821
+ }
2822
+ // Step 67: LoopDetector — detect anti-patterns (every 10 cycles)
2823
+ if (this.loopDetector && this.cycleCount % 10 === 0) {
2824
+ try {
2825
+ ts?.emit('governance', 'analyzing', 'Step 67: Scanning for anti-patterns...', 'routine');
2826
+ const loopDetections = this.loopDetector.detect(this.cycleCount);
2827
+ if (loopDetections.length > 0) {
2828
+ ts?.emit('governance', 'discovering', `Step 67: ${loopDetections.length} anti-pattern(s) detected`, 'notable');
2829
+ this.journal.write({
2830
+ type: 'insight', title: `Loop Detector: ${loopDetections.length} anti-pattern(s)`,
2831
+ content: loopDetections.map(d => `${d.loopType}: ${d.description}`).join('\n'),
2832
+ tags: [this.brainName, 'governance', 'loop-detector'],
2833
+ references: [], significance: 'notable',
2834
+ data: { detections: loopDetections.length },
2835
+ });
2836
+ }
2837
+ if (this.metaCognitionLayer)
2838
+ this.metaCognitionLayer.recordStep('loop_detector', this.cycleCount, { insights: loopDetections.length });
2839
+ }
2840
+ catch (err) {
2841
+ this.log.warn(`[orchestrator] Step 67 (loop detector) error: ${err.message}`);
2842
+ }
2843
+ }
2844
+ // Step 68: GovernanceLayer — auto-governance review (every 10 cycles)
2845
+ if (this.governanceLayer && this.cycleCount % 10 === 0) {
2846
+ try {
2847
+ ts?.emit('governance', 'analyzing', 'Step 68: Governance review...', 'routine');
2848
+ const decisions = this.governanceLayer.review(this.cycleCount);
2849
+ if (decisions.length > 0) {
2850
+ ts?.emit('governance', 'responding', `Step 68: ${decisions.length} governance decision(s)`, 'notable');
2851
+ this.journal.write({
2852
+ type: 'insight', title: `Governance: ${decisions.length} decision(s)`,
2853
+ content: decisions.map(d => `${d.action} → ${d.engine}: ${d.reason}`).join('\n'),
2854
+ tags: [this.brainName, 'governance', 'decisions'],
2855
+ references: [], significance: 'notable',
2856
+ data: { decisions: decisions.length },
2857
+ });
2858
+ }
2859
+ if (this.metaCognitionLayer)
2860
+ this.metaCognitionLayer.recordStep('governance_layer', this.cycleCount, { insights: decisions.length });
2861
+ }
2862
+ catch (err) {
2863
+ this.log.warn(`[orchestrator] Step 68 (governance) error: ${err.message}`);
2864
+ }
2865
+ }
2744
2866
  const duration = Date.now() - start;
2745
2867
  ts?.emit('orchestrator', 'reflecting', `Feedback Cycle #${this.cycleCount} complete (${duration}ms)`);
2746
2868
  this.log.info(`[orchestrator] ─── Feedback Cycle #${this.cycleCount} complete (${duration}ms) ───`);