@timmeck/brain 3.36.54 → 3.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/README.md +1 -1
- package/dist/brain.d.ts +0 -3
- package/dist/brain.js +47 -606
- package/dist/brain.js.map +1 -1
- package/dist/init/dashboard-init.d.ts +24 -0
- package/dist/init/dashboard-init.js +112 -0
- package/dist/init/dashboard-init.js.map +1 -0
- package/dist/init/engine-factory.d.ts +33 -0
- package/dist/init/engine-factory.js +348 -0
- package/dist/init/engine-factory.js.map +1 -0
- package/dist/init/events-init.d.ts +5 -0
- package/dist/init/events-init.js +104 -0
- package/dist/init/events-init.js.map +1 -0
- package/dist/init/lifecycle.d.ts +65 -0
- package/dist/init/lifecycle.js +117 -0
- package/dist/init/lifecycle.js.map +1 -0
- package/dist/ipc/router.d.ts +3 -0
- package/dist/ipc/router.js +28 -0
- package/dist/ipc/router.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { getLogger } from '../utils/logger.js';
|
|
2
|
+
import { getCurrentVersion } from '../cli/update-check.js';
|
|
3
|
+
import { RAGEngine, RAGIndexer, KnowledgeGraphEngine, FactExtractor, SemanticCompressor, FeedbackEngine, ToolTracker, ToolPatternAnalyzer, ProactiveEngine, UserModel, CodeHealthMonitor, TeachingProtocol, Curriculum, ConsensusEngine, ActiveLearner, RepoAbsorber, FeatureExtractor, FeatureRecommender, ContradictionResolver, CheckpointManager, TraceCollector, MessageRouter, TelegramBot, DiscordBot, BenchmarkSuite, AgentTrainer, ToolScopeManager, PluginMarketplace, CodeSandbox, GuardrailEngine, CausalPlanner, ResearchRoadmap, runRoadmapMigration, CreativeEngine, runCreativeMigration, ActionBridgeEngine, runActionBridgeMigration, ContentForge, runContentForgeMigration, CodeForge, runCodeForgeMigration, StrategyForge, runStrategyForgeMigration, CrossBrainSignalRouter, runSignalRouterMigration, ChatEngine, runChatMigration, SubAgentFactory, runSubAgentMigration, SignalScanner, CodeMiner, PatternExtractor, ContextBuilder, CodeGenerator, TechRadarEngine, runTechRadarMigration, NotificationService as MultiChannelNotificationService, runNotificationMigration, DiscordProvider, TelegramProvider, EmailProvider, } from '@timmeck/brain-core';
|
|
4
|
+
// ── Intelligence Upgrade (Sessions 55-76) ────────────────
|
|
5
|
+
export function createIntelligenceEngines(deps) {
|
|
6
|
+
const { db, config, services, embeddingEngine, orchestrator, researchScheduler, thoughtStream, llmService, notifier, goalEngine } = deps;
|
|
7
|
+
const logger = getLogger();
|
|
8
|
+
// 55. RAG Pipeline — vector search across all knowledge
|
|
9
|
+
const ragEngine = new RAGEngine(db, { brainName: 'brain' });
|
|
10
|
+
if (embeddingEngine)
|
|
11
|
+
ragEngine.setEmbeddingEngine(embeddingEngine);
|
|
12
|
+
ragEngine.setThoughtStream(thoughtStream);
|
|
13
|
+
if (llmService.isAvailable())
|
|
14
|
+
ragEngine.setLLMService(llmService);
|
|
15
|
+
services.ragEngine = ragEngine;
|
|
16
|
+
const ragIndexer = new RAGIndexer(db);
|
|
17
|
+
ragIndexer.setRAGEngine(ragEngine);
|
|
18
|
+
services.ragIndexer = ragIndexer;
|
|
19
|
+
// Background: initial RAG indexing after 30s startup delay
|
|
20
|
+
setTimeout(() => {
|
|
21
|
+
ragIndexer.indexAll().then(count => {
|
|
22
|
+
if (count > 0)
|
|
23
|
+
logger.info(`[RAG] Initial indexing: ${count} vectors`);
|
|
24
|
+
}).catch(err => logger.debug(`[RAG] Initial indexing skipped: ${err.message}`));
|
|
25
|
+
}, 30_000);
|
|
26
|
+
// 56. Knowledge Graph 2.0 — typed fact relations
|
|
27
|
+
const knowledgeGraph = new KnowledgeGraphEngine(db, { brainName: 'brain' });
|
|
28
|
+
knowledgeGraph.setThoughtStream(thoughtStream);
|
|
29
|
+
services.knowledgeGraph = knowledgeGraph;
|
|
30
|
+
const factExtractor = new FactExtractor(db, { brainName: 'brain' });
|
|
31
|
+
if (llmService.isAvailable())
|
|
32
|
+
factExtractor.setLLMService(llmService);
|
|
33
|
+
services.factExtractor = factExtractor;
|
|
34
|
+
// 57. Semantic Compression — deduplicate knowledge
|
|
35
|
+
const semanticCompressor = new SemanticCompressor(db, { brainName: 'brain' });
|
|
36
|
+
semanticCompressor.setRAGEngine(ragEngine);
|
|
37
|
+
if (llmService.isAvailable())
|
|
38
|
+
semanticCompressor.setLLMService(llmService);
|
|
39
|
+
semanticCompressor.setThoughtStream(thoughtStream);
|
|
40
|
+
services.semanticCompressor = semanticCompressor;
|
|
41
|
+
// 58. Feedback Learning — RLHF reward signals
|
|
42
|
+
const feedbackEngine = new FeedbackEngine(db, { brainName: 'brain' });
|
|
43
|
+
feedbackEngine.setThoughtStream(thoughtStream);
|
|
44
|
+
services.feedbackEngine = feedbackEngine;
|
|
45
|
+
// 59. Tool-Use Learning — track tool outcomes
|
|
46
|
+
const toolTracker = new ToolTracker(db, { brainName: 'brain' });
|
|
47
|
+
const toolPatternAnalyzer = new ToolPatternAnalyzer(db);
|
|
48
|
+
services.toolTracker = toolTracker;
|
|
49
|
+
services.toolPatternAnalyzer = toolPatternAnalyzer;
|
|
50
|
+
// 60. Proactive Suggestions — trigger-based improvement proposals
|
|
51
|
+
const proactiveEngine = new ProactiveEngine(db, { brainName: 'brain' });
|
|
52
|
+
proactiveEngine.setThoughtStream(thoughtStream);
|
|
53
|
+
services.proactiveEngine = proactiveEngine;
|
|
54
|
+
// 61. User Modeling — adaptive responses
|
|
55
|
+
const userModel = new UserModel(db, { brainName: 'brain' });
|
|
56
|
+
services.userModel = userModel;
|
|
57
|
+
// 62. Code Health Monitor — codebase quality tracking
|
|
58
|
+
const codeHealthMonitor = new CodeHealthMonitor(db, { brainName: 'brain' });
|
|
59
|
+
codeHealthMonitor.setThoughtStream(thoughtStream);
|
|
60
|
+
services.codeHealthMonitor = codeHealthMonitor;
|
|
61
|
+
// 63. Inter-Brain Teaching — knowledge transfer protocol
|
|
62
|
+
const teachingProtocol = new TeachingProtocol(db, { brainName: 'brain' });
|
|
63
|
+
services.teachingProtocol = teachingProtocol;
|
|
64
|
+
const curriculum = new Curriculum(db);
|
|
65
|
+
services.curriculum = curriculum;
|
|
66
|
+
// 64. Consensus Decisions — multi-brain voting
|
|
67
|
+
const consensusEngine = new ConsensusEngine(db, { brainName: 'brain' });
|
|
68
|
+
services.consensusEngine = consensusEngine;
|
|
69
|
+
// 65. Active Learning — gap identification & closing strategies
|
|
70
|
+
const activeLearner = new ActiveLearner(db, { brainName: 'brain' });
|
|
71
|
+
activeLearner.setThoughtStream(thoughtStream);
|
|
72
|
+
services.activeLearner = activeLearner;
|
|
73
|
+
// 66. RepoAbsorber — autonomous code learning from discovered repos
|
|
74
|
+
const repoAbsorber = new RepoAbsorber(db);
|
|
75
|
+
repoAbsorber.setThoughtStream(thoughtStream);
|
|
76
|
+
repoAbsorber.setRAGEngine(ragEngine);
|
|
77
|
+
repoAbsorber.setKnowledgeGraph(knowledgeGraph);
|
|
78
|
+
services.repoAbsorber = repoAbsorber;
|
|
79
|
+
// 67. FeatureExtractor — extract useful functions/patterns from absorbed repos
|
|
80
|
+
const featureExtractor = new FeatureExtractor(db);
|
|
81
|
+
featureExtractor.setRAGEngine(ragEngine);
|
|
82
|
+
featureExtractor.setKnowledgeGraph(knowledgeGraph);
|
|
83
|
+
if (services.llmService)
|
|
84
|
+
featureExtractor.setLLMService(services.llmService);
|
|
85
|
+
services.featureExtractor = featureExtractor;
|
|
86
|
+
repoAbsorber.setFeatureExtractor(featureExtractor);
|
|
87
|
+
// 68. FeatureRecommender — wishlist, connections, periodic need scanning
|
|
88
|
+
const featureRecommender = new FeatureRecommender(db);
|
|
89
|
+
featureRecommender.setFeatureExtractor(featureExtractor);
|
|
90
|
+
featureRecommender.setRAGEngine(ragEngine);
|
|
91
|
+
featureRecommender.setKnowledgeGraph(knowledgeGraph);
|
|
92
|
+
featureRecommender.setThoughtStream(thoughtStream);
|
|
93
|
+
services.featureRecommender = featureRecommender;
|
|
94
|
+
// 69. ContradictionResolver — resolve knowledge graph contradictions
|
|
95
|
+
const contradictionResolver = new ContradictionResolver(db);
|
|
96
|
+
contradictionResolver.setKnowledgeGraph(knowledgeGraph);
|
|
97
|
+
services.contradictionResolver = contradictionResolver;
|
|
98
|
+
// 70. CheckpointManager — workflow state persistence for crash recovery & time-travel
|
|
99
|
+
const checkpointManager = new CheckpointManager(db);
|
|
100
|
+
services.checkpointManager = checkpointManager;
|
|
101
|
+
// 71. TraceCollector — observability & tracing for all workflows
|
|
102
|
+
const traceCollector = new TraceCollector(db);
|
|
103
|
+
services.traceCollector = traceCollector;
|
|
104
|
+
// 72. Messaging Bots — bidirectional Telegram/Discord (optional, if tokens configured)
|
|
105
|
+
const messageRouter = new MessageRouter({ brainName: 'brain' });
|
|
106
|
+
services.messageRouter = messageRouter;
|
|
107
|
+
const telegramBot = new TelegramBot();
|
|
108
|
+
telegramBot.setRouter(messageRouter);
|
|
109
|
+
services.telegramBot = telegramBot;
|
|
110
|
+
const discordBot = new DiscordBot();
|
|
111
|
+
discordBot.setRouter(messageRouter);
|
|
112
|
+
services.discordBot = discordBot;
|
|
113
|
+
// 73. Agent Training — BenchmarkSuite + AgentTrainer (eval harness with curriculum learning)
|
|
114
|
+
const benchmarkSuite = new BenchmarkSuite(db);
|
|
115
|
+
const agentTrainer = new AgentTrainer(db);
|
|
116
|
+
agentTrainer.setBenchmarkSuite(benchmarkSuite);
|
|
117
|
+
services.benchmarkSuite = benchmarkSuite;
|
|
118
|
+
services.agentTrainer = agentTrainer;
|
|
119
|
+
// 74. Tool Scoping — dynamic tool availability per workflow phase (LangGraph-inspired)
|
|
120
|
+
const toolScopeManager = new ToolScopeManager(db);
|
|
121
|
+
toolScopeManager.registerDefaults();
|
|
122
|
+
services.toolScopeManager = toolScopeManager;
|
|
123
|
+
// 75. Plugin Marketplace — browse, install, rate plugins (OpenClaw-inspired)
|
|
124
|
+
const pluginMarketplace = new PluginMarketplace(db, { brainVersion: getCurrentVersion() });
|
|
125
|
+
services.pluginMarketplace = pluginMarketplace;
|
|
126
|
+
// 76. Code Sandbox — isolated code execution with Docker/local fallback (AutoGen-inspired)
|
|
127
|
+
const codeSandbox = new CodeSandbox(db);
|
|
128
|
+
services.codeSandbox = codeSandbox;
|
|
129
|
+
// Wire CodeSandbox into SelfModificationEngine for pre-validation
|
|
130
|
+
if (services.selfModificationEngine) {
|
|
131
|
+
services.selfModificationEngine.setSandbox(codeSandbox);
|
|
132
|
+
logger.info('SelfModificationEngine: Sandbox pre-validation enabled');
|
|
133
|
+
}
|
|
134
|
+
// 89. GuardrailEngine — self-protection: parameter bounds, circuit breaker, health checks
|
|
135
|
+
const guardrailEngine = new GuardrailEngine(db, { brainName: 'brain' });
|
|
136
|
+
guardrailEngine.setParameterRegistry(services.parameterRegistry);
|
|
137
|
+
if (goalEngine)
|
|
138
|
+
guardrailEngine.setGoalEngine(goalEngine);
|
|
139
|
+
guardrailEngine.setThoughtStream(thoughtStream);
|
|
140
|
+
services.guardrailEngine = guardrailEngine;
|
|
141
|
+
// 86. CausalPlanner — root-cause diagnosis + intervention planning
|
|
142
|
+
const causalPlanner = new CausalPlanner(researchScheduler.causalGraph);
|
|
143
|
+
causalPlanner.setGoalEngine(goalEngine);
|
|
144
|
+
services.causalPlanner = causalPlanner;
|
|
145
|
+
// 87. ResearchRoadmap — goal dependencies + multi-step research plans
|
|
146
|
+
runRoadmapMigration(db);
|
|
147
|
+
const researchRoadmap = new ResearchRoadmap(db, goalEngine);
|
|
148
|
+
researchRoadmap.setThoughtStream(thoughtStream);
|
|
149
|
+
services.researchRoadmap = researchRoadmap;
|
|
150
|
+
// 88. CreativeEngine — cross-domain idea generation
|
|
151
|
+
runCreativeMigration(db);
|
|
152
|
+
const creativeEngine = new CreativeEngine(db, { brainName: 'brain' });
|
|
153
|
+
creativeEngine.setKnowledgeDistiller(orchestrator.knowledgeDistiller);
|
|
154
|
+
creativeEngine.setHypothesisEngine(researchScheduler.hypothesisEngine);
|
|
155
|
+
if (llmService)
|
|
156
|
+
creativeEngine.setLLMService(llmService);
|
|
157
|
+
creativeEngine.setThoughtStream(thoughtStream);
|
|
158
|
+
services.creativeEngine = creativeEngine;
|
|
159
|
+
// 91. ActionBridgeEngine — risk-assessed auto-execution of proposed actions
|
|
160
|
+
runActionBridgeMigration(db);
|
|
161
|
+
const actionBridge = new ActionBridgeEngine(db, { brainName: 'brain' });
|
|
162
|
+
services.actionBridge = actionBridge;
|
|
163
|
+
// 92. ContentForge — autonomous content generation + publishing
|
|
164
|
+
runContentForgeMigration(db);
|
|
165
|
+
const contentForge = new ContentForge(db, { brainName: 'brain' });
|
|
166
|
+
if (llmService)
|
|
167
|
+
contentForge.setLLMService(llmService);
|
|
168
|
+
contentForge.setActionBridge(actionBridge);
|
|
169
|
+
services.contentForge = contentForge;
|
|
170
|
+
// 93. CodeForge — pattern extraction + auto-apply code changes
|
|
171
|
+
runCodeForgeMigration(db);
|
|
172
|
+
const codeForge = new CodeForge(db, { brainName: 'brain' });
|
|
173
|
+
codeForge.setActionBridge(actionBridge);
|
|
174
|
+
if (services.guardrailEngine)
|
|
175
|
+
codeForge.setGuardrailEngine(services.guardrailEngine);
|
|
176
|
+
if (services.selfModificationEngine)
|
|
177
|
+
codeForge.setSelfModificationEngine(services.selfModificationEngine);
|
|
178
|
+
if (services.codeHealthMonitor)
|
|
179
|
+
codeForge.setCodeHealthMonitor(services.codeHealthMonitor);
|
|
180
|
+
services.codeForge = codeForge;
|
|
181
|
+
// 94. StrategyForge — autonomous strategy creation + execution
|
|
182
|
+
runStrategyForgeMigration(db);
|
|
183
|
+
const strategyForge = new StrategyForge(db, { brainName: 'brain' });
|
|
184
|
+
strategyForge.setActionBridge(actionBridge);
|
|
185
|
+
strategyForge.setKnowledgeDistiller(orchestrator.knowledgeDistiller);
|
|
186
|
+
services.strategyForge = strategyForge;
|
|
187
|
+
// CrossBrainSignalRouter — bidirectional signal routing
|
|
188
|
+
runSignalRouterMigration(db);
|
|
189
|
+
const signalRouter = new CrossBrainSignalRouter(db, 'brain');
|
|
190
|
+
if (notifier)
|
|
191
|
+
signalRouter.setNotifier(notifier);
|
|
192
|
+
// Handle incoming trade signals → create insight
|
|
193
|
+
signalRouter.onSignal('trade_signal', (signal) => {
|
|
194
|
+
const symbol = signal.payload.symbol ?? 'unknown';
|
|
195
|
+
const direction = signal.payload.direction ?? 'neutral';
|
|
196
|
+
try {
|
|
197
|
+
services.research.createInsight({
|
|
198
|
+
title: `Trade signal: ${symbol} ${direction}`,
|
|
199
|
+
type: 'cross-brain',
|
|
200
|
+
description: `Received ${direction} signal for ${symbol} from ${signal.sourceBrain} (confidence: ${signal.confidence.toFixed(2)})`,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
catch { /* best effort */ }
|
|
204
|
+
logger.info(`[signal-router] Created insight from trade signal: ${symbol} ${direction}`);
|
|
205
|
+
});
|
|
206
|
+
// Handle incoming engagement signals → create insight
|
|
207
|
+
signalRouter.onSignal('engagement_signal', (signal) => {
|
|
208
|
+
const topic = signal.payload.topic ?? 'unknown';
|
|
209
|
+
try {
|
|
210
|
+
services.research.createInsight({
|
|
211
|
+
title: `Engagement signal: ${topic}`,
|
|
212
|
+
type: 'cross-brain',
|
|
213
|
+
description: `Engagement signal from ${signal.sourceBrain}: ${signal.payload.summary ?? topic}`,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
catch { /* best effort */ }
|
|
217
|
+
logger.info(`[signal-router] Created insight from engagement signal: ${topic}`);
|
|
218
|
+
});
|
|
219
|
+
services.signalRouter = signalRouter;
|
|
220
|
+
// 100. ChatEngine — NLU-routed chat interface
|
|
221
|
+
runChatMigration(db);
|
|
222
|
+
const chatEngine = new ChatEngine(db, { brainName: 'brain' });
|
|
223
|
+
services.chatEngine = chatEngine;
|
|
224
|
+
// 101. SubAgentFactory — spawn specialized sub-agents
|
|
225
|
+
runSubAgentMigration(db);
|
|
226
|
+
const subAgentFactory = new SubAgentFactory(db);
|
|
227
|
+
services.subAgentFactory = subAgentFactory;
|
|
228
|
+
// ── Wire intelligence engines into autonomous ResearchOrchestrator ──
|
|
229
|
+
orchestrator.setFactExtractor(factExtractor);
|
|
230
|
+
orchestrator.setKnowledgeGraph(knowledgeGraph);
|
|
231
|
+
orchestrator.setSemanticCompressor(semanticCompressor);
|
|
232
|
+
orchestrator.setProactiveEngine(proactiveEngine);
|
|
233
|
+
orchestrator.setActiveLearner(activeLearner);
|
|
234
|
+
orchestrator.setRAGIndexer(ragIndexer);
|
|
235
|
+
orchestrator.setTeachingProtocol(teachingProtocol);
|
|
236
|
+
orchestrator.setCodeHealthMonitor(codeHealthMonitor);
|
|
237
|
+
orchestrator.setRepoAbsorber(repoAbsorber);
|
|
238
|
+
orchestrator.setFeatureRecommender(featureRecommender);
|
|
239
|
+
orchestrator.setFeatureExtractor(featureExtractor);
|
|
240
|
+
orchestrator.setContradictionResolver(contradictionResolver);
|
|
241
|
+
orchestrator.setCheckpointManager(checkpointManager);
|
|
242
|
+
orchestrator.setFeedbackEngine(feedbackEngine);
|
|
243
|
+
orchestrator.setUserModel(userModel);
|
|
244
|
+
orchestrator.setConsensusEngine(consensusEngine);
|
|
245
|
+
orchestrator.setTraceCollector(traceCollector);
|
|
246
|
+
orchestrator.setGuardrailEngine(guardrailEngine);
|
|
247
|
+
orchestrator.setCausalPlanner(causalPlanner);
|
|
248
|
+
orchestrator.setResearchRoadmap(researchRoadmap);
|
|
249
|
+
orchestrator.setCreativeEngine(creativeEngine);
|
|
250
|
+
orchestrator.setActionBridge(actionBridge);
|
|
251
|
+
orchestrator.setContentForge(contentForge);
|
|
252
|
+
orchestrator.setCodeForge(codeForge);
|
|
253
|
+
orchestrator.setStrategyForge(strategyForge);
|
|
254
|
+
logger.info('Intelligence upgrade active (RAG, KG, Compression, Feedback, Tool-Learning, Proactive, UserModel, CodeHealth, Teaching, Consensus, ActiveLearning, RepoAbsorber, Guardrails, CausalPlanner, Roadmap, Creative — all wired into orchestrator)');
|
|
255
|
+
logger.info('Research orchestrator started (48+ steps, feedback loops active, DataMiner bootstrapped, Dream Mode active, Prediction Engine active)');
|
|
256
|
+
// 11k. Signal Scanner — GitHub/HN/Crypto signal tracking
|
|
257
|
+
if (config.scanner.enabled) {
|
|
258
|
+
const signalScanner = new SignalScanner(db, config.scanner);
|
|
259
|
+
orchestrator.setSignalScanner(signalScanner);
|
|
260
|
+
signalScanner.start();
|
|
261
|
+
services.signalScanner = signalScanner;
|
|
262
|
+
logger.info(`Signal scanner started (interval: ${config.scanner.scanIntervalMs}ms, token: ${config.scanner.githubToken ? 'yes' : 'NO — set GITHUB_TOKEN'})`);
|
|
263
|
+
}
|
|
264
|
+
// 11k2. TechRadar Engine — daily tech trend scanning + relevance analysis
|
|
265
|
+
try {
|
|
266
|
+
runTechRadarMigration(db);
|
|
267
|
+
const techRadar = new TechRadarEngine(db, {
|
|
268
|
+
githubToken: config.scanner.githubToken,
|
|
269
|
+
});
|
|
270
|
+
if (llmService)
|
|
271
|
+
techRadar.setLLMService(llmService);
|
|
272
|
+
techRadar.start();
|
|
273
|
+
services.techRadar = techRadar;
|
|
274
|
+
logger.info('TechRadar engine started');
|
|
275
|
+
}
|
|
276
|
+
catch (err) {
|
|
277
|
+
logger.warn(`TechRadar setup failed (non-critical): ${err.message}`);
|
|
278
|
+
}
|
|
279
|
+
// 11k3. NotificationService — multi-channel notifications
|
|
280
|
+
try {
|
|
281
|
+
runNotificationMigration(db);
|
|
282
|
+
const notificationService = new MultiChannelNotificationService(db);
|
|
283
|
+
// Auto-register available providers
|
|
284
|
+
const discordProv = new DiscordProvider();
|
|
285
|
+
const telegramProv = new TelegramProvider();
|
|
286
|
+
const emailProvider = new EmailProvider();
|
|
287
|
+
discordProv.isAvailable().then(ok => {
|
|
288
|
+
if (ok) {
|
|
289
|
+
notificationService.registerProvider(discordProv);
|
|
290
|
+
logger.info('Discord notification provider registered');
|
|
291
|
+
}
|
|
292
|
+
}).catch(() => { });
|
|
293
|
+
telegramProv.isAvailable().then(ok => {
|
|
294
|
+
if (ok) {
|
|
295
|
+
notificationService.registerProvider(telegramProv);
|
|
296
|
+
logger.info('Telegram notification provider registered');
|
|
297
|
+
}
|
|
298
|
+
}).catch(() => { });
|
|
299
|
+
emailProvider.isAvailable().then(ok => {
|
|
300
|
+
if (ok) {
|
|
301
|
+
notificationService.registerProvider(emailProvider);
|
|
302
|
+
logger.info('Email notification provider registered');
|
|
303
|
+
}
|
|
304
|
+
}).catch(() => { });
|
|
305
|
+
services.multiChannelNotifications = notificationService;
|
|
306
|
+
logger.info('NotificationService initialized');
|
|
307
|
+
}
|
|
308
|
+
catch (err) {
|
|
309
|
+
logger.warn(`NotificationService setup failed (non-critical): ${err.message}`);
|
|
310
|
+
}
|
|
311
|
+
// 11l. CodeMiner — mine repo contents from GitHub (needs GITHUB_TOKEN)
|
|
312
|
+
let patternExtractor;
|
|
313
|
+
if (config.scanner.githubToken) {
|
|
314
|
+
const codeMiner = new CodeMiner(db, { githubToken: config.scanner.githubToken });
|
|
315
|
+
patternExtractor = new PatternExtractor(db);
|
|
316
|
+
orchestrator.setCodeMiner(codeMiner);
|
|
317
|
+
services.codeMiner = codeMiner;
|
|
318
|
+
services.patternExtractor = patternExtractor;
|
|
319
|
+
void codeMiner.bootstrap();
|
|
320
|
+
logger.info('CodeMiner activated (GITHUB_TOKEN set)');
|
|
321
|
+
}
|
|
322
|
+
// 11m. CodeGenerator — autonomous code generation (needs ANTHROPIC_API_KEY)
|
|
323
|
+
if (process.env.ANTHROPIC_API_KEY) {
|
|
324
|
+
const codeGenerator = new CodeGenerator(db, { brainName: 'brain', apiKey: process.env.ANTHROPIC_API_KEY });
|
|
325
|
+
const contextBuilder = new ContextBuilder(orchestrator.knowledgeDistiller, orchestrator.journal, patternExtractor ?? null, services.signalScanner ?? null);
|
|
326
|
+
codeGenerator.setContextBuilder(contextBuilder);
|
|
327
|
+
codeGenerator.setThoughtStream(thoughtStream);
|
|
328
|
+
orchestrator.setCodeGenerator(codeGenerator);
|
|
329
|
+
services.codeGenerator = codeGenerator;
|
|
330
|
+
logger.info('CodeGenerator activated (ANTHROPIC_API_KEY set)');
|
|
331
|
+
// Wire ContextBuilder with SelfScanner into SelfModificationEngine
|
|
332
|
+
if (services.selfModificationEngine && services.selfScanner) {
|
|
333
|
+
const selfmodCtx = new ContextBuilder(orchestrator.knowledgeDistiller, orchestrator.journal, patternExtractor ?? null, services.signalScanner ?? null);
|
|
334
|
+
selfmodCtx.setSelfScanner(services.selfScanner);
|
|
335
|
+
services.selfModificationEngine.setContextBuilder(selfmodCtx);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return {
|
|
339
|
+
guardrailEngine,
|
|
340
|
+
causalPlanner,
|
|
341
|
+
researchRoadmap,
|
|
342
|
+
creativeEngine,
|
|
343
|
+
telegramBot,
|
|
344
|
+
discordBot,
|
|
345
|
+
patternExtractor,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
//# sourceMappingURL=engine-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-factory.js","sourceRoot":"","sources":["../../src/init/engine-factory.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EACL,SAAS,EAAE,UAAU,EAAE,oBAAoB,EAAE,aAAa,EAAE,kBAAkB,EAC9E,cAAc,EAAE,WAAW,EAAE,mBAAmB,EAAE,eAAe,EAAE,SAAS,EAC5E,iBAAiB,EAAE,gBAAgB,EAAE,UAAU,EAAE,eAAe,EAAE,aAAa,EAC/E,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,qBAAqB,EACzE,iBAAiB,EAAE,cAAc,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EACzE,cAAc,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAC9E,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,mBAA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AAC,aAAa,CAAC,CAAC;QAC7C,QAAQ,CAAC,aAAa,GAAG,aAAa,CAAC;QAEvC,MAAM,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAC;QAE/D,mEAAmE;QACnE,IAAI,QAAQ,CAAC,sBAAsB,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;YAC5D,MAAM,UAAU,GAAG,IAAI,cAAc,CACnC,YAAY,CAAC,kBAAkB,EAC/B,YAAY,CAAC,OAAO,EACpB,gBAAgB,IAAI,IAAI,EACxB,QAAQ,CAAC,aAAa,IAAI,IAAI,CAC/B,CAAC;YACF,UAAU,CAAC,cAAc,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;YAChD,QAAQ,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IAED,OAAO;QACL,eAAe;QACf,aAAa;QACb,eAAe;QACf,cAAc;QACd,WAAW;QACX,UAAU;QACV,gBAAgB;KACjB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SynapseManager } from '../synapses/synapse-manager.js';
|
|
2
|
+
import type { CrossBrainNotifier, CrossBrainSubscriptionManager, CrossBrainCorrelator, ResearchOrchestrator } from '@timmeck/brain-core';
|
|
3
|
+
import type { Services } from '../ipc/router.js';
|
|
4
|
+
export declare function setupEventListeners(services: Services, synapseManager: SynapseManager, notifier: CrossBrainNotifier | null, correlator: CrossBrainCorrelator | null, orchestrator: ResearchOrchestrator | null): void;
|
|
5
|
+
export declare function setupCrossBrainSubscriptions(subscriptionManager: CrossBrainSubscriptionManager | null, correlator: CrossBrainCorrelator | null, orchestrator: ResearchOrchestrator | null): void;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event listener setup — extracted from BrainCore.setupEventListeners + setupCrossBrainSubscriptions.
|
|
3
|
+
* Pure extraction, no logic changes.
|
|
4
|
+
*/
|
|
5
|
+
import { getLogger } from '../utils/logger.js';
|
|
6
|
+
import { getEventBus } from '../utils/events.js';
|
|
7
|
+
export function setupEventListeners(services, synapseManager, notifier, correlator, orchestrator) {
|
|
8
|
+
const bus = getEventBus();
|
|
9
|
+
const webhook = services.webhook;
|
|
10
|
+
const causal = services.causal;
|
|
11
|
+
const hypothesis = services.hypothesis;
|
|
12
|
+
const orch = orchestrator;
|
|
13
|
+
bus.on('error:reported', ({ errorId, projectId }) => {
|
|
14
|
+
synapseManager.strengthen({ type: 'error', id: errorId }, { type: 'project', id: projectId }, 'co_occurs');
|
|
15
|
+
notifier?.notify('error:reported', { errorId, projectId });
|
|
16
|
+
correlator?.recordEvent('brain', 'error:reported', { errorId, projectId });
|
|
17
|
+
webhook?.fire('error:reported', { errorId, projectId });
|
|
18
|
+
causal?.recordEvent('brain', 'error:reported', { errorId, projectId });
|
|
19
|
+
hypothesis?.observe({ source: 'brain', type: 'error:reported', value: 1, timestamp: Date.now() });
|
|
20
|
+
orch?.onEvent('error:reported', { errorId, projectId });
|
|
21
|
+
});
|
|
22
|
+
bus.on('solution:applied', ({ errorId, solutionId, success }) => {
|
|
23
|
+
if (success) {
|
|
24
|
+
synapseManager.strengthen({ type: 'solution', id: solutionId }, { type: 'error', id: errorId }, 'solves');
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const synapse = synapseManager.find({ type: 'solution', id: solutionId }, { type: 'error', id: errorId }, 'solves');
|
|
28
|
+
if (synapse)
|
|
29
|
+
synapseManager.weaken(synapse.id, 0.7);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
bus.on('module:registered', ({ moduleId, projectId }) => {
|
|
33
|
+
synapseManager.strengthen({ type: 'code_module', id: moduleId }, { type: 'project', id: projectId }, 'co_occurs');
|
|
34
|
+
});
|
|
35
|
+
bus.on('rule:learned', ({ ruleId, pattern }) => {
|
|
36
|
+
getLogger().info(`New rule #${ruleId} learned: ${pattern}`);
|
|
37
|
+
causal?.recordEvent('brain', 'rule:learned', { ruleId, pattern });
|
|
38
|
+
hypothesis?.observe({ source: 'brain', type: 'rule:learned', value: 1, timestamp: Date.now() });
|
|
39
|
+
orch?.onEvent('rule:learned', { ruleId });
|
|
40
|
+
});
|
|
41
|
+
bus.on('insight:created', ({ insightId, type }) => {
|
|
42
|
+
getLogger().info(`New insight #${insightId} (${type})`);
|
|
43
|
+
notifier?.notifyPeer('marketing-brain', 'insight:created', { insightId, type });
|
|
44
|
+
correlator?.recordEvent('brain', 'insight:created', { insightId, type });
|
|
45
|
+
webhook?.fire('insight:created', { insightId, type });
|
|
46
|
+
causal?.recordEvent('brain', 'insight:created', { insightId, type });
|
|
47
|
+
hypothesis?.observe({ source: 'brain', type: 'insight:created', value: 1, timestamp: Date.now() });
|
|
48
|
+
orch?.onEvent('insight:created', { insightId, type });
|
|
49
|
+
});
|
|
50
|
+
bus.on('solution:applied', ({ errorId, solutionId, success }) => {
|
|
51
|
+
orch?.onEvent('solution:applied', { errorId, solutionId, success: success ? 1 : 0 });
|
|
52
|
+
});
|
|
53
|
+
bus.on('memory:created', ({ memoryId, projectId }) => {
|
|
54
|
+
if (projectId) {
|
|
55
|
+
synapseManager.strengthen({ type: 'memory', id: memoryId }, { type: 'project', id: projectId }, 'co_occurs');
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
bus.on('session:ended', ({ sessionId }) => {
|
|
59
|
+
getLogger().info(`Session #${sessionId} ended`);
|
|
60
|
+
});
|
|
61
|
+
bus.on('decision:recorded', ({ decisionId, projectId }) => {
|
|
62
|
+
if (projectId) {
|
|
63
|
+
synapseManager.strengthen({ type: 'decision', id: decisionId }, { type: 'project', id: projectId }, 'co_occurs');
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
bus.on('task:created', ({ taskId }) => {
|
|
67
|
+
getLogger().info(`Task #${taskId} created`);
|
|
68
|
+
});
|
|
69
|
+
bus.on('task:completed', ({ taskId }) => {
|
|
70
|
+
getLogger().info(`Task #${taskId} completed`);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
export function setupCrossBrainSubscriptions(subscriptionManager, correlator, orchestrator) {
|
|
74
|
+
if (!subscriptionManager || !correlator)
|
|
75
|
+
return;
|
|
76
|
+
const logger = getLogger();
|
|
77
|
+
subscriptionManager.subscribe('trading-brain', ['trade:completed'], (event, data) => {
|
|
78
|
+
logger.info(`[cross-brain] Received ${event} from trading-brain`, { data });
|
|
79
|
+
correlator.recordEvent('trading-brain', event, data);
|
|
80
|
+
orchestrator?.onCrossBrainEvent('trading-brain', event, data);
|
|
81
|
+
});
|
|
82
|
+
subscriptionManager.subscribe('trading-brain', ['trade:outcome'], (event, data) => {
|
|
83
|
+
correlator.recordEvent('trading-brain', event, data);
|
|
84
|
+
orchestrator?.onCrossBrainEvent('trading-brain', event, data);
|
|
85
|
+
const d = data;
|
|
86
|
+
if (d && d.win === false) {
|
|
87
|
+
const lossCorrelations = correlator.getCorrelations(0.3)
|
|
88
|
+
.filter(c => c.type === 'error-trade-loss');
|
|
89
|
+
if (lossCorrelations.length > 0) {
|
|
90
|
+
logger.warn(`[cross-brain] Trade loss correlated with recent errors (strength: ${lossCorrelations[0].strength.toFixed(2)})`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
subscriptionManager.subscribe('marketing-brain', ['post:published'], (event, data) => {
|
|
95
|
+
logger.info(`[cross-brain] Received ${event} from marketing-brain`, { data });
|
|
96
|
+
correlator.recordEvent('marketing-brain', event, data);
|
|
97
|
+
orchestrator?.onCrossBrainEvent('marketing-brain', event, data);
|
|
98
|
+
});
|
|
99
|
+
subscriptionManager.subscribe('marketing-brain', ['campaign:created'], (event, data) => {
|
|
100
|
+
correlator.recordEvent('marketing-brain', event, data);
|
|
101
|
+
orchestrator?.onCrossBrainEvent('marketing-brain', event, data);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=events-init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events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CAAC,CAAC,IAAI,KAAK,kBAAkB,CAAC,CAAC;YAC9C,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAChC,MAAM,CAAC,IAAI,CAAC,qEAAqE,gBAAgB,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YAC/H,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,mBAAmB,CAAC,SAAS,CAAC,iBAAiB,EAAE,CAAC,gBAAgB,CAAC,EAAE,CAAC,KAAa,EAAE,IAAa,EAAE,EAAE;QACpG,MAAM,CAAC,IAAI,CAAC,0BAA0B,KAAK,uBAAuB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9E,UAAU,CAAC,WAAW,CAAC,iBAAiB,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACvD,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,EAAE,KAAK,EAAE,IAA+B,CAAC,CAAC;IAC7F,CAAC,CAAC,CAAC;IAEH,mBAAmB,CAAC,SAAS,CAAC,iBAAiB,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,KAAa,EAAE,IAAa,EAAE,EAAE;QACtG,UAAU,CAAC,WAAW,CAAC,iBAAiB,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACvD,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,EAAE,KAAK,EAAE,IAA+B,CAAC,CAAC;IAC7F,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
import type { BrainConfig } from '../types/config.types.js';
|
|
3
|
+
export declare function logCrash(config: BrainConfig | null, type: string, err: Error): void;
|
|
4
|
+
export declare function runRetentionCleanup(db: Database.Database, config: BrainConfig): void;
|
|
5
|
+
export interface CleanupRefs {
|
|
6
|
+
cleanupTimer: ReturnType<typeof setInterval> | null;
|
|
7
|
+
retentionTimer: ReturnType<typeof setInterval> | null;
|
|
8
|
+
borgSync: {
|
|
9
|
+
stop(): void;
|
|
10
|
+
} | null;
|
|
11
|
+
telegramBot: {
|
|
12
|
+
stop(): Promise<void>;
|
|
13
|
+
} | null;
|
|
14
|
+
discordBot: {
|
|
15
|
+
stop(): Promise<void>;
|
|
16
|
+
} | null;
|
|
17
|
+
peerNetwork: {
|
|
18
|
+
stopDiscovery(): void;
|
|
19
|
+
} | null;
|
|
20
|
+
pluginRegistry: {
|
|
21
|
+
size: number;
|
|
22
|
+
list(): Array<{
|
|
23
|
+
name: string;
|
|
24
|
+
}>;
|
|
25
|
+
unloadPlugin(name: string): Promise<boolean>;
|
|
26
|
+
} | null;
|
|
27
|
+
subscriptionManager: {
|
|
28
|
+
disconnectAll(): void;
|
|
29
|
+
} | null;
|
|
30
|
+
attentionEngine: {
|
|
31
|
+
stop(): void;
|
|
32
|
+
} | null;
|
|
33
|
+
commandCenter: {
|
|
34
|
+
stop(): void;
|
|
35
|
+
} | null;
|
|
36
|
+
orchestrator: {
|
|
37
|
+
stop(): void;
|
|
38
|
+
} | null;
|
|
39
|
+
researchScheduler: {
|
|
40
|
+
stop(): void;
|
|
41
|
+
} | null;
|
|
42
|
+
researchEngine: {
|
|
43
|
+
stop(): void;
|
|
44
|
+
} | null;
|
|
45
|
+
embeddingEngine: {
|
|
46
|
+
stop(): void;
|
|
47
|
+
} | null;
|
|
48
|
+
learningEngine: {
|
|
49
|
+
stop(): void;
|
|
50
|
+
} | null;
|
|
51
|
+
mcpHttpServer: {
|
|
52
|
+
stop(): void;
|
|
53
|
+
} | null;
|
|
54
|
+
apiServer: {
|
|
55
|
+
stop(): void;
|
|
56
|
+
} | null;
|
|
57
|
+
ipcServer: {
|
|
58
|
+
stop(): void;
|
|
59
|
+
} | null;
|
|
60
|
+
db: {
|
|
61
|
+
close(): void;
|
|
62
|
+
} | null;
|
|
63
|
+
}
|
|
64
|
+
export declare function cleanup(refs: CleanupRefs): void;
|
|
65
|
+
export declare function setupCrashRecovery(config: BrainConfig | null, onRestart: () => void): void;
|