@timmeck/brain-core 2.34.0 → 2.35.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/README.md +15 -14
- package/dist/codegen/context-builder.js +16 -16
- package/dist/codegen/context-builder.js.map +1 -1
- package/dist/concept-abstraction/concept-abstraction.d.ts +139 -0
- package/dist/concept-abstraction/concept-abstraction.js +532 -0
- package/dist/concept-abstraction/concept-abstraction.js.map +1 -0
- package/dist/concept-abstraction/index.d.ts +2 -0
- package/dist/concept-abstraction/index.js +2 -0
- package/dist/concept-abstraction/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/memory-palace/memory-palace.d.ts +2 -2
- package/dist/memory-palace/memory-palace.js.map +1 -1
- package/dist/research/auto-responder.js +10 -10
- package/dist/research/auto-responder.js.map +1 -1
- package/dist/research/research-orchestrator.d.ts +4 -0
- package/dist/research/research-orchestrator.js +151 -75
- package/dist/research/research-orchestrator.js.map +1 -1
- package/dist/self-modification/self-modification-engine.js +15 -13
- package/dist/self-modification/self-modification-engine.js.map +1 -1
- package/dist/unified/unified-server.d.ts +1 -0
- package/dist/unified/unified-server.js +7 -0
- package/dist/unified/unified-server.js.map +1 -1
- package/package.json +1 -1
- package/unified-dashboard.html +390 -259
package/README.md
CHANGED
|
@@ -112,7 +112,8 @@ Brain Core is the nervous system that powers all three Brain MCP servers ([Brain
|
|
|
112
112
|
| **DreamEngine** | Offline memory consolidation — replay, prune, compress, decay |
|
|
113
113
|
| **DreamConsolidator** | 4 phases: Memory Replay, Synapse Pruning, Compression, Importance Decay |
|
|
114
114
|
| **ThoughtStream** | Circular buffer capturing every engine's thoughts in real-time |
|
|
115
|
-
| **ConsciousnessServer** | HTTP + SSE server with live
|
|
115
|
+
| **ConsciousnessServer** | HTTP + SSE server with live Consciousness Entity visualization (legacy — now part of Mission Control) |
|
|
116
|
+
| **Consciousness Entity** | Animated Canvas 2D visualization: mood-colored pulsing orb, organic tentacles, 8-dimension ring, ambient particles, floating thoughts, inner eye tracking attention. 6 moods (flow/excited/anxious/reflective/bored/determined). Data from EmotionalModel via `/api/emotional` |
|
|
116
117
|
|
|
117
118
|
### Code Generation & Mining
|
|
118
119
|
|
|
@@ -122,17 +123,16 @@ Brain Core is the nervous system that powers all three Brain MCP servers ([Brain
|
|
|
122
123
|
| **ContextBuilder** | Builds system prompts from principles, anti-patterns, strategies, patterns |
|
|
123
124
|
| **CodeMiner** | Mines GitHub repos: README, package.json, directory structures |
|
|
124
125
|
| **PatternExtractor** | Extracts dependency, tech stack, structure, and README patterns |
|
|
125
|
-
| **CodegenServer** | HTTP + SSE dashboard for code review
|
|
126
|
+
| **CodegenServer** | HTTP + SSE dashboard for code review (legacy — now part of Mission Control) |
|
|
126
127
|
| **SignalScanner** | GitHub trending repos, Hacker News, crypto signal tracking |
|
|
127
128
|
|
|
128
129
|
### Dashboards
|
|
129
130
|
|
|
130
131
|
| Dashboard | Port | Description |
|
|
131
132
|
|-----------|------|-------------|
|
|
132
|
-
| **
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
| **Unified** | 7788 | Single UI for all brains with deep links |
|
|
133
|
+
| **Mission Control** | 7788 | Unified 7-tab dashboard: Overview, Consciousness (Entity visualization), Thoughts, CodeGen, Self-Mod, Engines, Intelligence |
|
|
134
|
+
|
|
135
|
+
<p align="center"><img src="../../docs/assets/mission-control.png" alt="Mission Control Dashboard" width="700"></p>
|
|
136
136
|
|
|
137
137
|
### Cross-Brain & Services
|
|
138
138
|
|
|
@@ -172,7 +172,7 @@ npm install @timmeck/brain-core
|
|
|
172
172
|
import {
|
|
173
173
|
createConnection, IpcServer, startMcpServer,
|
|
174
174
|
ResearchOrchestrator, DreamEngine, ThoughtStream,
|
|
175
|
-
|
|
175
|
+
UnifiedDashboardServer, PredictionEngine,
|
|
176
176
|
} from '@timmeck/brain-core';
|
|
177
177
|
|
|
178
178
|
// 1. Database
|
|
@@ -190,8 +190,9 @@ dreamEngine.start();
|
|
|
190
190
|
// 4. Consciousness
|
|
191
191
|
const thoughtStream = new ThoughtStream();
|
|
192
192
|
orchestrator.setThoughtStream(thoughtStream);
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
// Unified Mission Control dashboard (includes Consciousness Entity, Thoughts, CodeGen, Self-Mod, Engines)
|
|
194
|
+
const dashboard = new UnifiedDashboardServer({ port: 7790, thoughtStream, ... });
|
|
195
|
+
dashboard.start();
|
|
195
196
|
|
|
196
197
|
// 5. Predictions
|
|
197
198
|
const prediction = new PredictionEngine(db, { brainName: 'my-brain' });
|
|
@@ -227,7 +228,7 @@ prediction.start();
|
|
|
227
228
|
├── Scanner ────── SignalScanner, GitHubCollector, HnCollector, CryptoCollector
|
|
228
229
|
├── Causal ─────── CausalGraph (Granger causality), HypothesisEngine
|
|
229
230
|
├── Cross-Brain ── Client, Notifier, Correlator, Subscriptions
|
|
230
|
-
├── Dashboard ────
|
|
231
|
+
├── Dashboard ──── Mission Control (Unified), Consciousness*, CodeGen*, Hub*, Research*
|
|
231
232
|
├── Services ───── Webhook, Export, Backup, Ecosystem
|
|
232
233
|
├── Memory ─────── BaseMemoryEngine, types
|
|
233
234
|
├── DB ─────────── SQLite connection (WAL mode)
|
|
@@ -238,10 +239,10 @@ prediction.start();
|
|
|
238
239
|
|
|
239
240
|
| Brain | Version | Purpose | Ports |
|
|
240
241
|
|-------|---------|---------|-------|
|
|
241
|
-
| [Brain](../brain) | v3.
|
|
242
|
-
| [Trading Brain](../trading-brain) | v2.
|
|
243
|
-
| [Marketing Brain](../marketing-brain) | v1.
|
|
244
|
-
| **Brain Core** | v2.
|
|
242
|
+
| [Brain](../brain) | v3.34.0 | Error memory, code intelligence, full autonomy & self-modification | 7777/7778/7788 |
|
|
243
|
+
| [Trading Brain](../trading-brain) | v2.29.0 | Adaptive trading intelligence with signal learning & backtesting | 7779/7780 |
|
|
244
|
+
| [Marketing Brain](../marketing-brain) | v1.30.0 | Content strategy, engagement & cross-platform optimization | 7781/7782/7783 |
|
|
245
|
+
| **Brain Core** | v2.34.0 | Shared infrastructure — 30+ engines (this package) | — |
|
|
245
246
|
|
|
246
247
|
## Support
|
|
247
248
|
|
|
@@ -29,14 +29,14 @@ export class ContextBuilder {
|
|
|
29
29
|
let antiPatternsUsed = 0;
|
|
30
30
|
let patternsUsed = 0;
|
|
31
31
|
// Header
|
|
32
|
-
sections.push('
|
|
33
|
-
sections.push('
|
|
32
|
+
sections.push('You are a code generator in the Brain Ecosystem.');
|
|
33
|
+
sections.push('You have access to the Brain\'s accumulated knowledge:\n');
|
|
34
34
|
// 1. Principles from KnowledgeDistiller
|
|
35
35
|
if (this.knowledgeDistiller) {
|
|
36
36
|
const domain = request.knowledge_domains?.[0];
|
|
37
37
|
const principles = this.knowledgeDistiller.getPrinciples(domain, this.config.maxPrinciples);
|
|
38
38
|
if (principles.length > 0) {
|
|
39
|
-
sections.push('##
|
|
39
|
+
sections.push('## Proven Principles');
|
|
40
40
|
for (const p of principles) {
|
|
41
41
|
sections.push(`- ${p.statement} (confidence: ${p.confidence.toFixed(2)}, success: ${(p.success_rate * 100).toFixed(0)}%)`);
|
|
42
42
|
principlesUsed++;
|
|
@@ -46,9 +46,9 @@ export class ContextBuilder {
|
|
|
46
46
|
// 2. Anti-Patterns
|
|
47
47
|
const antiPatterns = this.knowledgeDistiller.getAntiPatterns(domain, this.config.maxAntiPatterns);
|
|
48
48
|
if (antiPatterns.length > 0) {
|
|
49
|
-
sections.push('## Anti-Patterns (
|
|
49
|
+
sections.push('## Anti-Patterns (avoid!)');
|
|
50
50
|
for (const ap of antiPatterns) {
|
|
51
|
-
const alt = ap.alternative ? ` →
|
|
51
|
+
const alt = ap.alternative ? ` → Instead: ${ap.alternative}` : '';
|
|
52
52
|
sections.push(`- ${ap.statement} (failure: ${(ap.failure_rate * 100).toFixed(0)}%)${alt}`);
|
|
53
53
|
antiPatternsUsed++;
|
|
54
54
|
}
|
|
@@ -57,7 +57,7 @@ export class ContextBuilder {
|
|
|
57
57
|
// 3. Strategies
|
|
58
58
|
const pkg = this.knowledgeDistiller.getPackage(domain ?? 'general');
|
|
59
59
|
if (pkg.strategies && pkg.strategies.length > 0) {
|
|
60
|
-
sections.push('##
|
|
60
|
+
sections.push('## Proven Strategies');
|
|
61
61
|
for (const s of pkg.strategies.slice(0, this.config.maxStrategies)) {
|
|
62
62
|
sections.push(`- ${s.description} (effectiveness: ${(s.effectiveness * 100).toFixed(0)}%)`);
|
|
63
63
|
}
|
|
@@ -69,7 +69,7 @@ export class ContextBuilder {
|
|
|
69
69
|
const deps = this.patternExtractor.getPatterns('dependency', this.config.maxPatterns);
|
|
70
70
|
const stacks = this.patternExtractor.getPatterns('tech_stack', 5);
|
|
71
71
|
if (deps.length > 0 || stacks.length > 0) {
|
|
72
|
-
sections.push('##
|
|
72
|
+
sections.push('## Popular Tech Patterns (from scanned repos)');
|
|
73
73
|
if (deps.length > 0) {
|
|
74
74
|
const depList = deps.map(d => {
|
|
75
75
|
const data = JSON.parse(d.pattern_data);
|
|
@@ -83,7 +83,7 @@ export class ContextBuilder {
|
|
|
83
83
|
const data = JSON.parse(s.pattern_data);
|
|
84
84
|
return `${data.stack} (${data.count}x)`;
|
|
85
85
|
}).join(', ');
|
|
86
|
-
sections.push(`-
|
|
86
|
+
sections.push(`- Most common stacks: ${stackList}`);
|
|
87
87
|
patternsUsed += stacks.length;
|
|
88
88
|
}
|
|
89
89
|
sections.push('');
|
|
@@ -93,7 +93,7 @@ export class ContextBuilder {
|
|
|
93
93
|
if (this.journal) {
|
|
94
94
|
const discoveries = this.journal.getEntries('discovery', this.config.maxJournalInsights);
|
|
95
95
|
if (discoveries.length > 0) {
|
|
96
|
-
sections.push('##
|
|
96
|
+
sections.push('## Recent Discoveries');
|
|
97
97
|
for (const d of discoveries) {
|
|
98
98
|
sections.push(`- ${d.title}: ${d.content.substring(0, 150)}`);
|
|
99
99
|
}
|
|
@@ -118,7 +118,7 @@ export class ContextBuilder {
|
|
|
118
118
|
if (this.selfScanner) {
|
|
119
119
|
const archSummary = this.selfScanner.getArchitectureSummary();
|
|
120
120
|
if (archSummary && archSummary !== 'No source files scanned yet.') {
|
|
121
|
-
sections.push('##
|
|
121
|
+
sections.push('## Own Codebase (Architecture Overview)');
|
|
122
122
|
sections.push(archSummary);
|
|
123
123
|
sections.push('');
|
|
124
124
|
}
|
|
@@ -127,7 +127,7 @@ export class ContextBuilder {
|
|
|
127
127
|
const content = this.selfScanner.getFileContent(request.target_file);
|
|
128
128
|
if (content) {
|
|
129
129
|
const truncated = content.length > 8000 ? content.substring(0, 8000) + '\n// ... (truncated)' : content;
|
|
130
|
-
sections.push('##
|
|
130
|
+
sections.push('## Current Source Code of Target File');
|
|
131
131
|
sections.push('```typescript');
|
|
132
132
|
sections.push(truncated);
|
|
133
133
|
sections.push('```');
|
|
@@ -136,18 +136,18 @@ export class ContextBuilder {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
// 8. Task section
|
|
139
|
-
sections.push('##
|
|
139
|
+
sections.push('## Task');
|
|
140
140
|
sections.push(request.task);
|
|
141
141
|
if (request.context) {
|
|
142
|
-
sections.push(`\
|
|
142
|
+
sections.push(`\nAdditional context: ${request.context}`);
|
|
143
143
|
}
|
|
144
144
|
if (request.target_file) {
|
|
145
|
-
sections.push(`\
|
|
145
|
+
sections.push(`\nTarget file: ${request.target_file}`);
|
|
146
146
|
}
|
|
147
147
|
// 9. Output instructions
|
|
148
148
|
const lang = request.language ?? 'typescript';
|
|
149
|
-
sections.push(`\
|
|
150
|
-
sections.push('
|
|
149
|
+
sections.push(`\nGenerate the code as ${lang === 'typescript' ? 'TypeScript ESM, use .js extensions in imports' : lang}.`);
|
|
150
|
+
sections.push('Respond with the code in a ```code``` block, followed by a brief explanation.');
|
|
151
151
|
const systemPrompt = sections.join('\n');
|
|
152
152
|
return {
|
|
153
153
|
systemPrompt,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-builder.js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QAED,yBAAyB;QACzB,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,IAAI,YAAY,CAAC;QAC9C,QAAQ,CAAC,IAAI,CAAC,0BAA0B,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,+CAA+C,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;QAC3H,QAAQ,CAAC,IAAI,CAAC,+EAA+E,CAAC,CAAC;QAE/F,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEzC,OAAO;YACL,YAAY;YACZ,cAAc;YACd,gBAAgB;YAChB,YAAY;YACZ,mBAAmB,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;SACxD,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
import type { ThoughtStream } from '../consciousness/thought-stream.js';
|
|
3
|
+
import type { MemoryPalace } from '../memory-palace/memory-palace.js';
|
|
4
|
+
export interface ConceptAbstractionConfig {
|
|
5
|
+
brainName: string;
|
|
6
|
+
/** Minimum Dice similarity to form a cluster. Default: 0.35 */
|
|
7
|
+
clusterThreshold?: number;
|
|
8
|
+
/** Minimum cluster size to keep. Default: 3 */
|
|
9
|
+
minClusterSize?: number;
|
|
10
|
+
/** Level-1 re-cluster threshold. Default: 0.25 */
|
|
11
|
+
level1Threshold?: number;
|
|
12
|
+
/** Level-2 re-cluster threshold. Default: 0.20 */
|
|
13
|
+
level2Threshold?: number;
|
|
14
|
+
/** Minimum word occurrence ratio for keyword extraction. Default: 0.6 */
|
|
15
|
+
keywordMinRatio?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface ConceptDataSources {
|
|
18
|
+
getPrinciples: (domain?: string, limit?: number) => Array<{
|
|
19
|
+
id?: string | number;
|
|
20
|
+
statement: string;
|
|
21
|
+
confidence: number;
|
|
22
|
+
domain?: string;
|
|
23
|
+
}>;
|
|
24
|
+
getAntiPatterns: (domain?: string, limit?: number) => Array<{
|
|
25
|
+
id?: string | number;
|
|
26
|
+
statement: string;
|
|
27
|
+
confidence?: number;
|
|
28
|
+
domain?: string;
|
|
29
|
+
}>;
|
|
30
|
+
getHypotheses?: (status?: string, limit?: number) => Array<{
|
|
31
|
+
id?: string | number;
|
|
32
|
+
statement: string;
|
|
33
|
+
confidence?: number;
|
|
34
|
+
domain?: string;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
export interface AbstractConcept {
|
|
38
|
+
id?: number;
|
|
39
|
+
title: string;
|
|
40
|
+
description: string;
|
|
41
|
+
level: number;
|
|
42
|
+
parentId: number | null;
|
|
43
|
+
domain: string;
|
|
44
|
+
memberCount: number;
|
|
45
|
+
avgConfidence: number;
|
|
46
|
+
avgSimilarity: number;
|
|
47
|
+
keywords: string[];
|
|
48
|
+
transferability: number;
|
|
49
|
+
createdAt: string;
|
|
50
|
+
updatedAt: string;
|
|
51
|
+
}
|
|
52
|
+
export interface ConceptMember {
|
|
53
|
+
conceptId: number;
|
|
54
|
+
memberType: MemberType;
|
|
55
|
+
memberId: number;
|
|
56
|
+
similarityToCentroid: number;
|
|
57
|
+
}
|
|
58
|
+
export type MemberType = 'principle' | 'anti_pattern' | 'strategy' | 'hypothesis' | 'concept';
|
|
59
|
+
export interface ConceptHistoryEntry {
|
|
60
|
+
cycle: number;
|
|
61
|
+
totalConcepts: number;
|
|
62
|
+
conceptsByLevel: Record<number, number>;
|
|
63
|
+
newCount: number;
|
|
64
|
+
mergedCount: number;
|
|
65
|
+
avgTransferability: number;
|
|
66
|
+
}
|
|
67
|
+
export interface ConceptHierarchy {
|
|
68
|
+
concept: AbstractConcept;
|
|
69
|
+
children: ConceptHierarchy[];
|
|
70
|
+
members: ConceptMember[];
|
|
71
|
+
}
|
|
72
|
+
export interface ConceptStatus {
|
|
73
|
+
totalConcepts: number;
|
|
74
|
+
conceptsByLevel: Record<number, number>;
|
|
75
|
+
avgTransferability: number;
|
|
76
|
+
topConcepts: AbstractConcept[];
|
|
77
|
+
recentHistory: ConceptHistoryEntry[];
|
|
78
|
+
cycleCount: number;
|
|
79
|
+
}
|
|
80
|
+
export declare function runConceptAbstractionMigration(db: Database.Database): void;
|
|
81
|
+
export declare class ConceptAbstraction {
|
|
82
|
+
private readonly db;
|
|
83
|
+
private readonly config;
|
|
84
|
+
private readonly log;
|
|
85
|
+
private ts;
|
|
86
|
+
private sources;
|
|
87
|
+
private cycleCount;
|
|
88
|
+
private readonly insertConcept;
|
|
89
|
+
private readonly insertMember;
|
|
90
|
+
private readonly insertHistory;
|
|
91
|
+
private readonly getConceptById;
|
|
92
|
+
private readonly getMembersByConcept;
|
|
93
|
+
private readonly getConceptsByLevelStmt;
|
|
94
|
+
private readonly getChildConcepts;
|
|
95
|
+
private readonly getTopConceptsStmt;
|
|
96
|
+
private readonly getTransferableStmt;
|
|
97
|
+
private readonly getHistoryStmt;
|
|
98
|
+
private readonly countConceptsStmt;
|
|
99
|
+
private readonly countByLevelStmt;
|
|
100
|
+
private readonly avgTransferabilityStmt;
|
|
101
|
+
private readonly clearConceptsStmt;
|
|
102
|
+
private readonly clearMembersStmt;
|
|
103
|
+
constructor(db: Database.Database, config: ConceptAbstractionConfig);
|
|
104
|
+
setThoughtStream(stream: ThoughtStream): void;
|
|
105
|
+
setDataSources(sources: ConceptDataSources): void;
|
|
106
|
+
/** Run concept formation: gather → cluster → hierarchy → persist */
|
|
107
|
+
formConcepts(): {
|
|
108
|
+
newConcepts: number;
|
|
109
|
+
totalConcepts: number;
|
|
110
|
+
levels: Record<number, number>;
|
|
111
|
+
};
|
|
112
|
+
getConceptsByLevel(level: number): AbstractConcept[];
|
|
113
|
+
getHierarchy(conceptId: number): ConceptHierarchy | null;
|
|
114
|
+
getMembers(conceptId: number): ConceptMember[];
|
|
115
|
+
getTransferableConcepts(minTransferability?: number): AbstractConcept[];
|
|
116
|
+
/** Register all concepts as nodes in MemoryPalace and link members. */
|
|
117
|
+
registerInPalace(palace: MemoryPalace): number;
|
|
118
|
+
getStatus(): ConceptStatus;
|
|
119
|
+
private gatherItems;
|
|
120
|
+
/** Greedy agglomerative clustering via bigram Dice similarity. */
|
|
121
|
+
private clusterItems;
|
|
122
|
+
/** Persist clusters as AbstractConcepts with members. Returns array of concept IDs. */
|
|
123
|
+
private persistClusters;
|
|
124
|
+
/** Convert persisted concepts to KnowledgeItems for re-clustering. */
|
|
125
|
+
private conceptsToItems;
|
|
126
|
+
private findConceptByTitle;
|
|
127
|
+
/** Bigram Dice coefficient — same algorithm as MemoryPalace and DreamConsolidator. */
|
|
128
|
+
private textOverlap;
|
|
129
|
+
private bigrams;
|
|
130
|
+
private generateTitle;
|
|
131
|
+
private generateDescription;
|
|
132
|
+
private extractKeywords;
|
|
133
|
+
private avgClusterSimilarity;
|
|
134
|
+
private computeTransferability;
|
|
135
|
+
private computeDomain;
|
|
136
|
+
private mostCommon;
|
|
137
|
+
private getTotalCount;
|
|
138
|
+
private getLevelCounts;
|
|
139
|
+
}
|