@timmeck/brain 1.8.1 → 1.8.2

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 (162) hide show
  1. package/BRAIN_PLAN.md +3324 -3324
  2. package/LICENSE +21 -21
  3. package/dist/cli/commands/dashboard.js +595 -595
  4. package/dist/dashboard/server.js +25 -25
  5. package/dist/db/migrations/001_core_schema.js +115 -115
  6. package/dist/db/migrations/002_learning_schema.js +33 -33
  7. package/dist/db/migrations/003_code_schema.js +48 -48
  8. package/dist/db/migrations/004_synapses_schema.js +52 -52
  9. package/dist/db/migrations/005_fts_indexes.js +73 -73
  10. package/dist/db/migrations/007_feedback.js +8 -8
  11. package/dist/db/migrations/008_git_integration.js +33 -33
  12. package/dist/db/migrations/009_embeddings.js +3 -3
  13. package/dist/db/repositories/antipattern.repository.js +3 -3
  14. package/dist/db/repositories/code-module.repository.js +32 -32
  15. package/dist/db/repositories/notification.repository.js +3 -3
  16. package/dist/db/repositories/project.repository.js +21 -21
  17. package/dist/db/repositories/rule.repository.js +24 -24
  18. package/dist/db/repositories/solution.repository.js +50 -50
  19. package/dist/db/repositories/synapse.repository.js +18 -18
  20. package/dist/db/repositories/terminal.repository.js +24 -24
  21. package/dist/ipc/server.d.ts +8 -0
  22. package/dist/ipc/server.js +67 -1
  23. package/dist/ipc/server.js.map +1 -1
  24. package/dist/matching/error-matcher.js +5 -5
  25. package/dist/matching/fingerprint.js +6 -1
  26. package/dist/matching/fingerprint.js.map +1 -1
  27. package/dist/services/error.service.js +4 -3
  28. package/dist/services/error.service.js.map +1 -1
  29. package/dist/services/git.service.js +14 -14
  30. package/package.json +49 -49
  31. package/src/api/server.ts +395 -395
  32. package/src/brain.ts +266 -266
  33. package/src/cli/colors.ts +116 -116
  34. package/src/cli/commands/config.ts +169 -169
  35. package/src/cli/commands/dashboard.ts +755 -755
  36. package/src/cli/commands/doctor.ts +118 -118
  37. package/src/cli/commands/explain.ts +83 -83
  38. package/src/cli/commands/export.ts +31 -31
  39. package/src/cli/commands/import.ts +199 -199
  40. package/src/cli/commands/insights.ts +65 -65
  41. package/src/cli/commands/learn.ts +24 -24
  42. package/src/cli/commands/modules.ts +53 -53
  43. package/src/cli/commands/network.ts +67 -67
  44. package/src/cli/commands/projects.ts +42 -42
  45. package/src/cli/commands/query.ts +120 -120
  46. package/src/cli/commands/start.ts +62 -62
  47. package/src/cli/commands/status.ts +75 -75
  48. package/src/cli/commands/stop.ts +34 -34
  49. package/src/cli/ipc-helper.ts +22 -22
  50. package/src/cli/update-check.ts +63 -63
  51. package/src/code/fingerprint.ts +87 -87
  52. package/src/code/parsers/generic.ts +29 -29
  53. package/src/code/parsers/python.ts +54 -54
  54. package/src/code/parsers/typescript.ts +65 -65
  55. package/src/code/registry.ts +60 -60
  56. package/src/dashboard/server.ts +142 -142
  57. package/src/db/connection.ts +22 -22
  58. package/src/db/migrations/001_core_schema.ts +120 -120
  59. package/src/db/migrations/002_learning_schema.ts +38 -38
  60. package/src/db/migrations/003_code_schema.ts +53 -53
  61. package/src/db/migrations/004_synapses_schema.ts +57 -57
  62. package/src/db/migrations/005_fts_indexes.ts +78 -78
  63. package/src/db/migrations/006_synapses_phase3.ts +17 -17
  64. package/src/db/migrations/007_feedback.ts +13 -13
  65. package/src/db/migrations/008_git_integration.ts +38 -38
  66. package/src/db/migrations/009_embeddings.ts +8 -8
  67. package/src/db/repositories/antipattern.repository.ts +66 -66
  68. package/src/db/repositories/code-module.repository.ts +142 -142
  69. package/src/db/repositories/notification.repository.ts +66 -66
  70. package/src/db/repositories/project.repository.ts +93 -93
  71. package/src/db/repositories/rule.repository.ts +108 -108
  72. package/src/db/repositories/solution.repository.ts +154 -154
  73. package/src/db/repositories/synapse.repository.ts +153 -153
  74. package/src/db/repositories/terminal.repository.ts +101 -101
  75. package/src/embeddings/engine.ts +238 -238
  76. package/src/index.ts +63 -63
  77. package/src/ipc/client.ts +118 -118
  78. package/src/ipc/protocol.ts +35 -35
  79. package/src/ipc/router.ts +133 -133
  80. package/src/ipc/server.ts +176 -110
  81. package/src/learning/decay.ts +46 -46
  82. package/src/learning/pattern-extractor.ts +90 -90
  83. package/src/learning/rule-generator.ts +74 -74
  84. package/src/matching/error-matcher.ts +5 -5
  85. package/src/matching/fingerprint.ts +34 -29
  86. package/src/matching/similarity.ts +61 -61
  87. package/src/matching/tfidf.ts +74 -74
  88. package/src/matching/tokenizer.ts +41 -41
  89. package/src/mcp/auto-detect.ts +93 -93
  90. package/src/mcp/http-server.ts +140 -140
  91. package/src/mcp/server.ts +73 -73
  92. package/src/parsing/error-parser.ts +28 -28
  93. package/src/parsing/parsers/compiler.ts +93 -93
  94. package/src/parsing/parsers/generic.ts +28 -28
  95. package/src/parsing/parsers/go.ts +97 -97
  96. package/src/parsing/parsers/node.ts +69 -69
  97. package/src/parsing/parsers/python.ts +62 -62
  98. package/src/parsing/parsers/rust.ts +50 -50
  99. package/src/parsing/parsers/shell.ts +42 -42
  100. package/src/parsing/types.ts +47 -47
  101. package/src/research/gap-analyzer.ts +135 -135
  102. package/src/research/insight-generator.ts +123 -123
  103. package/src/research/research-engine.ts +116 -116
  104. package/src/research/synergy-detector.ts +126 -126
  105. package/src/research/template-extractor.ts +130 -130
  106. package/src/research/trend-analyzer.ts +127 -127
  107. package/src/services/code.service.ts +271 -271
  108. package/src/services/error.service.ts +4 -3
  109. package/src/services/git.service.ts +132 -132
  110. package/src/services/notification.service.ts +41 -41
  111. package/src/services/synapse.service.ts +59 -59
  112. package/src/services/terminal.service.ts +81 -81
  113. package/src/synapses/activation.ts +80 -80
  114. package/src/synapses/decay.ts +38 -38
  115. package/src/synapses/hebbian.ts +69 -69
  116. package/src/synapses/pathfinder.ts +81 -81
  117. package/src/synapses/synapse-manager.ts +109 -109
  118. package/src/types/code.types.ts +52 -52
  119. package/src/types/error.types.ts +67 -67
  120. package/src/types/ipc.types.ts +8 -8
  121. package/src/types/mcp.types.ts +53 -53
  122. package/src/types/research.types.ts +28 -28
  123. package/src/types/solution.types.ts +30 -30
  124. package/src/utils/events.ts +45 -45
  125. package/src/utils/hash.ts +5 -5
  126. package/src/utils/logger.ts +48 -48
  127. package/src/utils/paths.ts +19 -19
  128. package/tests/e2e/test_code_intelligence.py +1015 -0
  129. package/tests/e2e/test_error_memory.py +451 -0
  130. package/tests/e2e/test_full_integration.py +534 -0
  131. package/tests/fixtures/code-modules/modules.ts +83 -83
  132. package/tests/fixtures/errors/go.ts +9 -9
  133. package/tests/fixtures/errors/node.ts +24 -24
  134. package/tests/fixtures/errors/python.ts +21 -21
  135. package/tests/fixtures/errors/rust.ts +25 -25
  136. package/tests/fixtures/errors/shell.ts +15 -15
  137. package/tests/fixtures/solutions/solutions.ts +27 -27
  138. package/tests/helpers/setup-db.ts +52 -52
  139. package/tests/integration/code-flow.test.ts +86 -86
  140. package/tests/integration/error-flow.test.ts +83 -83
  141. package/tests/integration/ipc-flow.test.ts +166 -166
  142. package/tests/integration/learning-cycle.test.ts +82 -82
  143. package/tests/integration/synapse-flow.test.ts +117 -117
  144. package/tests/unit/code/analyzer.test.ts +58 -58
  145. package/tests/unit/code/fingerprint.test.ts +51 -51
  146. package/tests/unit/code/scorer.test.ts +55 -55
  147. package/tests/unit/learning/confidence-scorer.test.ts +60 -60
  148. package/tests/unit/learning/decay.test.ts +45 -45
  149. package/tests/unit/learning/pattern-extractor.test.ts +50 -50
  150. package/tests/unit/matching/error-matcher.test.ts +69 -69
  151. package/tests/unit/matching/fingerprint.test.ts +47 -47
  152. package/tests/unit/matching/similarity.test.ts +65 -65
  153. package/tests/unit/matching/tfidf.test.ts +71 -71
  154. package/tests/unit/matching/tokenizer.test.ts +83 -83
  155. package/tests/unit/parsing/parsers.test.ts +113 -113
  156. package/tests/unit/research/gap-analyzer.test.ts +45 -45
  157. package/tests/unit/research/trend-analyzer.test.ts +45 -45
  158. package/tests/unit/synapses/activation.test.ts +80 -80
  159. package/tests/unit/synapses/decay.test.ts +27 -27
  160. package/tests/unit/synapses/hebbian.test.ts +96 -96
  161. package/tests/unit/synapses/pathfinder.test.ts +72 -72
  162. package/tsconfig.json +18 -18
@@ -1,755 +1,755 @@
1
- import { Command } from 'commander';
2
- import { withIpc } from '../ipc-helper.js';
3
- import { writeFileSync } from 'fs';
4
- import { resolve } from 'path';
5
- import { c, icons } from '../colors.js';
6
-
7
- export function dashboardCommand(): Command {
8
- return new Command('dashboard')
9
- .description('Generate and open the Brain dashboard with live data')
10
- .option('-o, --output <path>', 'Output HTML file path')
11
- .option('--no-open', 'Generate without opening in browser')
12
- .option('-l, --live', 'Start live dashboard server with SSE updates')
13
- .option('-p, --port <number>', 'Port for live dashboard', '7420')
14
- .action(async (opts) => {
15
- await withIpc(async (client) => {
16
- console.log(`${icons.chart} ${c.info('Fetching data from Brain...')}`);
17
-
18
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- const summary: any = await client.request('analytics.summary', {});
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- const network: any = await client.request('synapse.stats', {});
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
- const networkOverview: any = await client.request('analytics.network', { limit: 50 });
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
- const insights: any = await client.request('research.insights', {
26
- activeOnly: true,
27
- limit: 500,
28
- });
29
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
- const modules: any = await client.request('code.modules', {});
31
-
32
- // Collect language stats
33
- const langStats: Record<string, number> = {};
34
- const projectSet = new Set<string>();
35
- if (Array.isArray(modules)) {
36
- for (const m of modules) {
37
- langStats[m.language] = (langStats[m.language] || 0) + 1;
38
- if (m.projectId) projectSet.add(String(m.projectId));
39
- }
40
- }
41
-
42
- // Categorize insights
43
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
- const insightList = Array.isArray(insights) ? insights : [];
45
- const templates = insightList.filter((i: InsightItem) => i.type === 'template_candidate' || i.title?.includes('Template'));
46
- const suggestions = insightList.filter((i: InsightItem) => i.type === 'suggestion' || i.type === 'project_suggestion');
47
- const trends = insightList.filter((i: InsightItem) => i.type === 'trend' || i.type === 'pattern');
48
- const gaps = insightList.filter((i: InsightItem) => i.type === 'gap');
49
- const warnings = insightList.filter((i: InsightItem) => i.type === 'warning');
50
- const synergies = insightList.filter((i: InsightItem) => i.type === 'synergy' || i.type === 'optimization');
51
-
52
- // Build synapse graph data
53
- const synapseEdges = Array.isArray(networkOverview?.strongestSynapses) ? networkOverview.strongestSynapses : [];
54
-
55
- const data = {
56
- stats: {
57
- modules: summary.modules?.total ?? 0,
58
- synapses: network.totalSynapses ?? 0,
59
- errors: summary.errors?.total ?? 0,
60
- solutions: summary.solutions?.total ?? 0,
61
- rules: summary.rules?.active ?? 0,
62
- insights: insightList.length,
63
- },
64
- langStats,
65
- insights: { templates, suggestions, trends, gaps, warnings, synergies },
66
- synapseEdges,
67
- };
68
-
69
- const html = generateHtml(data);
70
- const outPath = opts.output
71
- ? resolve(opts.output)
72
- : resolve(import.meta.dirname, '../../../dashboard.html');
73
-
74
- // Inject live SSE connection for --live mode
75
- let finalHtml = html;
76
- if (opts.live) {
77
- const apiPort = opts.port || '7777';
78
- const sseScript = `
79
- <script>
80
- (function(){
81
- const evtSource = new EventSource('http://localhost:${apiPort}/api/v1/events');
82
- evtSource.onmessage = function(e) {
83
- try {
84
- const data = JSON.parse(e.data);
85
- if (data.type === 'stats_update') {
86
- document.querySelectorAll('.stat-card').forEach(card => {
87
- const label = card.querySelector('.stat-label')?.textContent?.toLowerCase();
88
- const num = card.querySelector('.stat-number');
89
- if (label && num && data.stats[label] !== undefined) {
90
- num.textContent = Number(data.stats[label]).toLocaleString();
91
- }
92
- });
93
- }
94
- if (data.type === 'event') {
95
- const dot = document.querySelector('.activity-dot');
96
- if (dot) { dot.style.background = '#ff5577'; setTimeout(() => dot.style.background = '', 500); }
97
- }
98
- } catch {}
99
- };
100
- evtSource.onerror = function() { setTimeout(() => location.reload(), 5000); };
101
- })();
102
- </script>`;
103
- finalHtml = html.replace('</body>', sseScript + '</body>');
104
- }
105
-
106
- writeFileSync(outPath, finalHtml, 'utf-8');
107
- console.log(`${icons.ok} ${c.success('Dashboard written to')} ${c.dim(outPath)}`);
108
- if (opts.live) {
109
- console.log(` ${c.info('Live mode:')} Connected to Brain daemon SSE on port ${opts.port || 7777}`);
110
- }
111
- console.log(` ${c.label('Modules:')} ${c.value(data.stats.modules)} ${c.label('Synapses:')} ${c.value(data.stats.synapses)} ${c.label('Insights:')} ${c.value(data.stats.insights)}`);
112
-
113
- if (opts.open !== false) {
114
- const { exec } = await import('child_process');
115
- exec(`start "" "${outPath}"`);
116
- }
117
- });
118
- });
119
- }
120
-
121
- interface InsightItem {
122
- type: string;
123
- title: string;
124
- description?: string;
125
- priority?: string;
126
- }
127
-
128
- interface SynapseEdge {
129
- source: string;
130
- target: string;
131
- type: string;
132
- weight: number;
133
- }
134
-
135
- interface DashboardData {
136
- stats: {
137
- modules: number;
138
- synapses: number;
139
- errors: number;
140
- solutions: number;
141
- rules: number;
142
- insights: number;
143
- };
144
- langStats: Record<string, number>;
145
- insights: {
146
- templates: InsightItem[];
147
- suggestions: InsightItem[];
148
- trends: InsightItem[];
149
- gaps: InsightItem[];
150
- warnings: InsightItem[];
151
- synergies: InsightItem[];
152
- };
153
- synapseEdges: SynapseEdge[];
154
- }
155
-
156
- function esc(s: string): string {
157
- return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
158
- }
159
-
160
- function generateHtml(data: DashboardData): string {
161
- const { stats, langStats, insights, synapseEdges } = data;
162
-
163
- // Build language chart bars
164
- const sortedLangs = Object.entries(langStats).sort((a, b) => b[1] - a[1]);
165
- const maxLang = sortedLangs[0]?.[1] || 1;
166
- const langBars = sortedLangs.slice(0, 12).map(([lang, count]) => {
167
- const pct = Math.round((count / maxLang) * 100);
168
- return `<div class="lang-row"><span class="lang-name">${esc(lang)}</span><div class="lang-bar-bg"><div class="lang-bar" data-width="${pct}"></div></div><span class="lang-count">${count}</span></div>`;
169
- }).join('\n');
170
-
171
- // Build insight cards
172
- function insightCards(items: InsightItem[], color: string): string {
173
- if (!items.length) return '<p class="empty">Keine Insights in dieser Kategorie.</p>';
174
- return items.slice(0, 30).map(i => {
175
- const prio = i.priority ? `<span class="prio prio-${String(i.priority).toLowerCase()}">${esc(String(i.priority))}</span>` : '';
176
- return `<div class="insight-card ${color}"><div class="insight-header">${prio}<strong>${esc(i.title)}</strong></div><p>${esc((i.description || '').slice(0, 200))}</p></div>`;
177
- }).join('\n');
178
- }
179
-
180
- const totalKnowledge = stats.modules + stats.synapses + stats.errors + stats.solutions;
181
- const activityLevel = Math.min(100, Math.round((stats.insights / Math.max(1, totalKnowledge)) * 1000));
182
-
183
- return `<!DOCTYPE html>
184
- <html lang="de">
185
- <head>
186
- <meta charset="UTF-8">
187
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
188
- <title>Brain — Dashboard</title>
189
- <style>
190
- @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');
191
- *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
192
- :root{
193
- --bg:#04060e;--bg2:rgba(10,12,24,.7);--bg3:rgba(20,24,50,.6);--bg4:rgba(30,35,70,.5);
194
- --glass:rgba(15,18,40,.55);--glass-border:rgba(100,120,255,.12);--glass-hover:rgba(100,120,255,.2);
195
- --text:#e8eaf6;--text2:#8b8fb0;--text3:#4a4d6e;
196
- --blue:#5b9cff;--red:#ff5577;--green:#3dffa0;
197
- --purple:#b47aff;--orange:#ffb347;--cyan:#47e5ff;
198
- --accent:linear-gradient(135deg,#b47aff,#5b9cff,#47e5ff);
199
- --radius:16px;--radius-sm:10px;
200
- }
201
- html{scroll-behavior:smooth}
202
- body{font-family:'Inter',system-ui,sans-serif;background:var(--bg);color:var(--text);line-height:1.6;min-height:100vh;overflow-x:hidden}
203
-
204
- /* Neural canvas background */
205
- #neural-bg{position:fixed;top:0;left:0;width:100%;height:100%;z-index:0;pointer-events:none}
206
-
207
- /* Ambient glow orbs */
208
- .orb{position:fixed;border-radius:50%;filter:blur(120px);opacity:.12;pointer-events:none;z-index:0}
209
- .orb-1{width:600px;height:600px;background:var(--purple);top:-200px;left:-100px;animation:orb-float 20s ease-in-out infinite}
210
- .orb-2{width:500px;height:500px;background:var(--blue);bottom:-150px;right:-100px;animation:orb-float 25s ease-in-out infinite reverse}
211
- .orb-3{width:400px;height:400px;background:var(--cyan);top:40%;left:50%;animation:orb-float 18s ease-in-out infinite 5s}
212
- @keyframes orb-float{0%,100%{transform:translate(0,0) scale(1)}33%{transform:translate(60px,-40px) scale(1.1)}66%{transform:translate(-40px,60px) scale(.9)}}
213
-
214
- .container{max-width:1400px;margin:0 auto;padding:0 28px;position:relative;z-index:1}
215
-
216
- /* Reveal animations */
217
- .reveal{opacity:0;transform:translateY(30px);transition:opacity .6s ease,transform .6s ease}
218
- .reveal.visible{opacity:1;transform:translateY(0)}
219
- .reveal-delay-1{transition-delay:.1s}.reveal-delay-2{transition-delay:.2s}
220
- .reveal-delay-3{transition-delay:.3s}.reveal-delay-4{transition-delay:.4s}
221
- .reveal-delay-5{transition-delay:.5s}
222
-
223
- section{margin-bottom:56px}
224
-
225
- /* Header */
226
- header{padding:60px 0 24px;text-align:center;position:relative}
227
- .logo{display:flex;align-items:center;justify-content:center;gap:20px;margin-bottom:12px}
228
- .logo-icon{
229
- width:68px;height:68px;border-radius:18px;
230
- background:linear-gradient(135deg,var(--purple),var(--blue),var(--cyan));
231
- display:flex;align-items:center;justify-content:center;font-size:32px;
232
- box-shadow:0 0 60px rgba(170,102,255,.35),0 0 120px rgba(90,150,255,.15);
233
- animation:icon-breathe 4s ease-in-out infinite;
234
- position:relative;
235
- }
236
- .logo-icon::after{
237
- content:'';position:absolute;inset:-3px;border-radius:20px;
238
- background:linear-gradient(135deg,var(--purple),var(--cyan));
239
- opacity:.4;filter:blur(8px);z-index:-1;animation:icon-breathe 4s ease-in-out infinite reverse;
240
- }
241
- @keyframes icon-breathe{0%,100%{box-shadow:0 0 60px rgba(170,102,255,.35),0 0 120px rgba(90,150,255,.15)}50%{box-shadow:0 0 80px rgba(170,102,255,.5),0 0 160px rgba(90,150,255,.25)}}
242
- .logo h1{font-size:2.8rem;font-weight:900;letter-spacing:-1px;background:linear-gradient(135deg,#fff 0%,var(--blue) 50%,var(--purple) 100%);-webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text}
243
- .tagline{color:var(--text2);font-size:1.05rem;font-weight:300;letter-spacing:.5px}
244
-
245
- /* Activity indicator */
246
- .activity{display:inline-flex;align-items:center;gap:10px;margin-top:16px;padding:8px 20px;border-radius:30px;background:var(--glass);border:1px solid var(--glass-border);backdrop-filter:blur(20px)}
247
- .activity-dot{width:8px;height:8px;border-radius:50%;background:var(--green);box-shadow:0 0 12px var(--green);animation:pulse-dot 2s ease-in-out infinite}
248
- @keyframes pulse-dot{0%,100%{opacity:1;box-shadow:0 0 12px var(--green)}50%{opacity:.5;box-shadow:0 0 20px var(--green)}}
249
- .activity-text{font-size:.8rem;color:var(--text2);font-weight:500}
250
- .activity-bar{width:80px;height:4px;border-radius:2px;background:var(--bg4);overflow:hidden}
251
- .activity-fill{height:100%;border-radius:2px;background:linear-gradient(90deg,var(--green),var(--cyan));transition:width 1.5s ease}
252
-
253
- /* Nav */
254
- nav{display:flex;justify-content:center;gap:8px;flex-wrap:wrap;padding:20px 0;margin-bottom:40px}
255
- nav a{
256
- color:var(--text2);text-decoration:none;padding:8px 18px;border-radius:24px;font-size:.85rem;font-weight:500;
257
- transition:all .3s ease;border:1px solid transparent;backdrop-filter:blur(10px);
258
- }
259
- nav a:hover{color:var(--text);background:var(--glass);border-color:var(--glass-border);transform:translateY(-1px)}
260
- nav a.research{
261
- background:var(--glass);color:var(--cyan);border-color:rgba(71,229,255,.25);font-weight:600;
262
- box-shadow:0 0 20px rgba(71,229,255,.1);animation:nav-glow 3s ease-in-out infinite alternate;
263
- }
264
- @keyframes nav-glow{0%{box-shadow:0 0 20px rgba(71,229,255,.1)}100%{box-shadow:0 0 35px rgba(71,229,255,.2)}}
265
-
266
- /* Stats */
267
- .stats-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(190px,1fr));gap:18px}
268
- .stat-card{
269
- background:var(--glass);border:1px solid var(--glass-border);border-radius:var(--radius);
270
- padding:28px 22px;text-align:center;position:relative;overflow:hidden;
271
- transition:all .35s ease;backdrop-filter:blur(20px);
272
- }
273
- .stat-card:hover{transform:translateY(-4px);border-color:var(--glass-hover);box-shadow:0 20px 60px rgba(0,0,0,.3)}
274
- .stat-card::before{content:'';position:absolute;top:0;left:0;right:0;height:2px}
275
- .stat-card::after{content:'';position:absolute;top:0;left:0;right:0;bottom:0;background:radial-gradient(ellipse at 50% 0%,rgba(255,255,255,.03),transparent 70%);pointer-events:none}
276
- .stat-card.blue::before{background:linear-gradient(90deg,transparent,var(--blue),transparent)}
277
- .stat-card.purple::before{background:linear-gradient(90deg,transparent,var(--purple),transparent)}
278
- .stat-card.red::before{background:linear-gradient(90deg,transparent,var(--red),transparent)}
279
- .stat-card.green::before{background:linear-gradient(90deg,transparent,var(--green),transparent)}
280
- .stat-card.orange::before{background:linear-gradient(90deg,transparent,var(--orange),transparent)}
281
- .stat-card.cyan::before{background:linear-gradient(90deg,transparent,var(--cyan),transparent)}
282
- .stat-number{font-size:2.6rem;font-weight:900;letter-spacing:-2px}
283
- .stat-card.blue .stat-number{color:var(--blue)}.stat-card.purple .stat-number{color:var(--purple)}
284
- .stat-card.red .stat-number{color:var(--red)}.stat-card.green .stat-number{color:var(--green)}
285
- .stat-card.orange .stat-number{color:var(--orange)}.stat-card.cyan .stat-number{color:var(--cyan)}
286
- .stat-label{color:var(--text2);font-size:.82rem;margin-top:6px;font-weight:500;letter-spacing:.3px;text-transform:uppercase}
287
-
288
- /* Section titles */
289
- .section-title{font-size:1.5rem;font-weight:700;margin-bottom:24px;display:flex;align-items:center;gap:12px}
290
- .section-title .icon{font-size:1.2rem;width:38px;height:38px;border-radius:var(--radius-sm);display:flex;align-items:center;justify-content:center;backdrop-filter:blur(10px)}
291
-
292
- /* Language chart */
293
- .lang-chart{max-width:650px}
294
- .lang-row{display:flex;align-items:center;gap:14px;margin-bottom:10px}
295
- .lang-name{width:100px;text-align:right;font-size:.85rem;color:var(--text2);font-weight:500}
296
- .lang-bar-bg{flex:1;height:28px;background:var(--bg3);border-radius:6px;overflow:hidden;border:1px solid var(--glass-border)}
297
- .lang-bar{height:100%;background:var(--accent);border-radius:6px;width:0;transition:width 1.2s cubic-bezier(.22,1,.36,1)}
298
- .lang-count{width:50px;font-size:.85rem;color:var(--text2);font-weight:600}
299
-
300
- /* Insight tabs */
301
- .tab-bar{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:24px}
302
- .tab-btn{
303
- padding:10px 20px;border-radius:24px;border:1px solid var(--glass-border);
304
- background:var(--glass);color:var(--text2);cursor:pointer;font-size:.85rem;font-weight:500;
305
- transition:all .3s ease;backdrop-filter:blur(10px);font-family:inherit;
306
- }
307
- .tab-btn:hover{border-color:var(--glass-hover);color:var(--text);transform:translateY(-1px)}
308
- .tab-btn.active{border-color:rgba(71,229,255,.35);color:var(--cyan);background:rgba(71,229,255,.08);box-shadow:0 0 20px rgba(71,229,255,.1)}
309
- .tab-btn .count{background:var(--bg4);padding:2px 8px;border-radius:12px;font-size:.72rem;margin-left:6px;font-weight:600}
310
- .tab-panel{display:none}.tab-panel.active{display:block}
311
- .insight-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(380px,1fr));gap:14px}
312
- .insight-card{
313
- background:var(--glass);border:1px solid var(--glass-border);border-radius:var(--radius-sm);
314
- padding:18px;border-left:3px solid var(--text3);transition:all .25s ease;backdrop-filter:blur(20px);
315
- }
316
- .insight-card:hover{transform:translateX(6px);border-color:var(--glass-hover);box-shadow:0 8px 30px rgba(0,0,0,.2)}
317
- .insight-card.cyan{border-left-color:var(--cyan)}.insight-card.orange{border-left-color:var(--orange)}
318
- .insight-card.green{border-left-color:var(--green)}.insight-card.red{border-left-color:var(--red)}
319
- .insight-card.purple{border-left-color:var(--purple)}.insight-card.blue{border-left-color:var(--blue)}
320
- .insight-header{display:flex;align-items:center;gap:8px;margin-bottom:8px;flex-wrap:wrap}
321
- .insight-card p{color:var(--text2);font-size:.85rem;line-height:1.5}
322
- .prio{font-size:.68rem;padding:3px 10px;border-radius:12px;text-transform:uppercase;font-weight:700;letter-spacing:.5px}
323
- .prio-critical{background:rgba(255,85,119,.15);color:var(--red);border:1px solid rgba(255,85,119,.25)}
324
- .prio-high{background:rgba(255,179,71,.15);color:var(--orange);border:1px solid rgba(255,179,71,.25)}
325
- .prio-medium{background:rgba(91,156,255,.15);color:var(--blue);border:1px solid rgba(91,156,255,.25)}
326
- .prio-low{background:rgba(139,143,176,.1);color:var(--text2);border:1px solid rgba(139,143,176,.2)}
327
- .empty{color:var(--text3);font-style:italic;padding:24px}
328
-
329
- /* Graph */
330
- .graph-container{position:relative;background:var(--glass);border:1px solid var(--glass-border);border-radius:var(--radius);overflow:hidden;backdrop-filter:blur(20px)}
331
- #synapse-graph{width:100%;height:500px;display:block;cursor:grab}
332
- #synapse-graph:active{cursor:grabbing}
333
- .graph-legend{display:flex;gap:16px;flex-wrap:wrap;padding:12px 20px;border-top:1px solid var(--glass-border);font-size:.8rem;color:var(--text2)}
334
- .legend-dot{display:inline-block;width:10px;height:10px;border-radius:50%;margin-right:6px;vertical-align:middle}
335
- .graph-tooltip{position:absolute;display:none;background:var(--bg2);border:1px solid var(--glass-border);border-radius:8px;padding:8px 14px;font-size:.8rem;color:var(--text);pointer-events:none;z-index:10;backdrop-filter:blur(20px);box-shadow:0 8px 30px rgba(0,0,0,.3)}
336
-
337
- /* Footer */
338
- footer{text-align:center;padding:40px 0;border-top:1px solid var(--glass-border)}
339
- footer p{color:var(--text3);font-size:.8rem}
340
- footer code{background:var(--glass);padding:3px 10px;border-radius:6px;font-size:.78rem;border:1px solid var(--glass-border)}
341
-
342
- /* Responsive */
343
- @media(max-width:600px){.stats-grid{grid-template-columns:1fr 1fr}.insight-grid{grid-template-columns:1fr}.logo h1{font-size:2rem}}
344
- </style>
345
- </head>
346
- <body>
347
-
348
- <canvas id="neural-bg"></canvas>
349
- <div class="orb orb-1"></div>
350
- <div class="orb orb-2"></div>
351
- <div class="orb orb-3"></div>
352
-
353
- <div class="container">
354
- <header class="reveal">
355
- <div class="logo">
356
- <div class="logo-icon">&#129504;</div>
357
- <h1>Brain</h1>
358
- </div>
359
- <p class="tagline">Adaptive Code Intelligence</p>
360
- <div class="activity">
361
- <span class="activity-dot"></span>
362
- <span class="activity-text">Neural Activity</span>
363
- <div class="activity-bar"><div class="activity-fill" style="width:0%" data-target="${activityLevel}"></div></div>
364
- <span class="activity-text" style="color:var(--cyan);font-weight:700">${activityLevel}%</span>
365
- </div>
366
- </header>
367
-
368
- <nav class="reveal reveal-delay-1">
369
- <a href="#stats">Stats</a>
370
- <a href="#languages">Languages</a>
371
- <a href="#network">&#128300; Network</a>
372
- <a href="#research" class="research">&#128161; Research</a>
373
- </nav>
374
-
375
- <section id="stats" class="reveal reveal-delay-2">
376
- <div class="section-title"><div class="icon" style="background:rgba(91,156,255,.1)">&#128202;</div> Neural Status</div>
377
- <div class="stats-grid">
378
- <div class="stat-card blue"><div class="stat-number">${stats.modules.toLocaleString()}</div><div class="stat-label">Modules</div></div>
379
- <div class="stat-card purple"><div class="stat-number">${stats.synapses.toLocaleString()}</div><div class="stat-label">Synapses</div></div>
380
- <div class="stat-card cyan"><div class="stat-number">${stats.insights}</div><div class="stat-label">Insights</div></div>
381
- <div class="stat-card red"><div class="stat-number">${stats.errors}</div><div class="stat-label">Errors</div></div>
382
- <div class="stat-card green"><div class="stat-number">${stats.solutions}</div><div class="stat-label">Solutions</div></div>
383
- <div class="stat-card orange"><div class="stat-number">${stats.rules}</div><div class="stat-label">Rules</div></div>
384
- </div>
385
- </section>
386
-
387
- <section id="languages" class="reveal reveal-delay-3">
388
- <div class="section-title"><div class="icon" style="background:rgba(180,122,255,.1)">&#128187;</div> Languages</div>
389
- <div class="lang-chart">${langBars}</div>
390
- </section>
391
-
392
- <section id="network" class="reveal reveal-delay-4">
393
- <div class="section-title"><div class="icon" style="background:rgba(71,229,255,.1)">&#128300;</div> Synapse Network</div>
394
- <div class="graph-container">
395
- <canvas id="synapse-graph"></canvas>
396
- <div class="graph-legend">
397
- <span><span class="legend-dot" style="background:var(--blue)"></span> error</span>
398
- <span><span class="legend-dot" style="background:var(--green)"></span> solution</span>
399
- <span><span class="legend-dot" style="background:var(--purple)"></span> code_module</span>
400
- <span><span class="legend-dot" style="background:var(--orange)"></span> project</span>
401
- <span><span class="legend-dot" style="background:var(--cyan)"></span> other</span>
402
- </div>
403
- <div id="graph-tooltip" class="graph-tooltip"></div>
404
- </div>
405
- </section>
406
-
407
- <section id="research" class="reveal reveal-delay-5">
408
- <div class="section-title"><div class="icon" style="background:rgba(71,229,255,.1)">&#128300;</div> Research Insights</div>
409
- <div class="tab-bar">
410
- <button class="tab-btn active" data-tab="templates">&#127912; Templates <span class="count">${insights.templates.length}</span></button>
411
- <button class="tab-btn" data-tab="suggestions">&#128161; Suggestions <span class="count">${insights.suggestions.length}</span></button>
412
- <button class="tab-btn" data-tab="trends">&#128200; Trends <span class="count">${insights.trends.length}</span></button>
413
- <button class="tab-btn" data-tab="gaps">&#9888;&#65039; Gaps <span class="count">${insights.gaps.length}</span></button>
414
- <button class="tab-btn" data-tab="synergies">&#9889; Synergies <span class="count">${insights.synergies.length}</span></button>
415
- <button class="tab-btn" data-tab="warnings">&#128680; Warnings <span class="count">${insights.warnings.length}</span></button>
416
- </div>
417
- <div class="tab-panel active" id="tab-templates"><div class="insight-grid">${insightCards(insights.templates, 'cyan')}</div></div>
418
- <div class="tab-panel" id="tab-suggestions"><div class="insight-grid">${insightCards(insights.suggestions, 'orange')}</div></div>
419
- <div class="tab-panel" id="tab-trends"><div class="insight-grid">${insightCards(insights.trends, 'green')}</div></div>
420
- <div class="tab-panel" id="tab-gaps"><div class="insight-grid">${insightCards(insights.gaps, 'red')}</div></div>
421
- <div class="tab-panel" id="tab-synergies"><div class="insight-grid">${insightCards(insights.synergies, 'purple')}</div></div>
422
- <div class="tab-panel" id="tab-warnings"><div class="insight-grid">${insightCards(insights.warnings, 'red')}</div></div>
423
- </section>
424
-
425
- <footer class="reveal reveal-delay-5">
426
- <p>Brain v1.0 &mdash; <code>brain dashboard</code></p>
427
- </footer>
428
- </div>
429
-
430
- <script>
431
- // --- Neural Network Canvas ---
432
- (function(){
433
- const canvas = document.getElementById('neural-bg');
434
- const ctx = canvas.getContext('2d');
435
- let W, H, nodes = [], mouse = {x:-1000,y:-1000};
436
-
437
- function resize(){
438
- W = canvas.width = window.innerWidth;
439
- H = canvas.height = window.innerHeight;
440
- }
441
- resize();
442
- window.addEventListener('resize', resize);
443
- document.addEventListener('mousemove', e => { mouse.x = e.clientX; mouse.y = e.clientY; });
444
-
445
- const NODE_COUNT = Math.min(80, Math.floor(window.innerWidth / 18));
446
- const CONNECT_DIST = 180;
447
- const MOUSE_DIST = 200;
448
-
449
- for(let i = 0; i < NODE_COUNT; i++){
450
- nodes.push({
451
- x: Math.random() * W,
452
- y: Math.random() * H,
453
- vx: (Math.random() - 0.5) * 0.4,
454
- vy: (Math.random() - 0.5) * 0.4,
455
- r: Math.random() * 2 + 1,
456
- pulse: Math.random() * Math.PI * 2,
457
- });
458
- }
459
-
460
- function draw(){
461
- ctx.clearRect(0, 0, W, H);
462
-
463
- // Draw connections
464
- for(let i = 0; i < nodes.length; i++){
465
- for(let j = i + 1; j < nodes.length; j++){
466
- const dx = nodes[i].x - nodes[j].x;
467
- const dy = nodes[i].y - nodes[j].y;
468
- const dist = Math.sqrt(dx*dx + dy*dy);
469
- if(dist < CONNECT_DIST){
470
- const alpha = (1 - dist / CONNECT_DIST) * 0.15;
471
- ctx.strokeStyle = 'rgba(91,156,255,' + alpha + ')';
472
- ctx.lineWidth = 0.5;
473
- ctx.beginPath();
474
- ctx.moveTo(nodes[i].x, nodes[i].y);
475
- ctx.lineTo(nodes[j].x, nodes[j].y);
476
- ctx.stroke();
477
- }
478
- }
479
-
480
- // Mouse interaction
481
- const mdx = nodes[i].x - mouse.x;
482
- const mdy = nodes[i].y - mouse.y;
483
- const mDist = Math.sqrt(mdx*mdx + mdy*mdy);
484
- if(mDist < MOUSE_DIST){
485
- const alpha = (1 - mDist / MOUSE_DIST) * 0.4;
486
- ctx.strokeStyle = 'rgba(180,122,255,' + alpha + ')';
487
- ctx.lineWidth = 1;
488
- ctx.beginPath();
489
- ctx.moveTo(nodes[i].x, nodes[i].y);
490
- ctx.lineTo(mouse.x, mouse.y);
491
- ctx.stroke();
492
- }
493
- }
494
-
495
- // Draw nodes
496
- const time = Date.now() * 0.001;
497
- for(const n of nodes){
498
- const glow = 0.4 + Math.sin(time * 1.5 + n.pulse) * 0.3;
499
- ctx.fillStyle = 'rgba(91,156,255,' + glow + ')';
500
- ctx.beginPath();
501
- ctx.arc(n.x, n.y, n.r, 0, Math.PI * 2);
502
- ctx.fill();
503
-
504
- n.x += n.vx;
505
- n.y += n.vy;
506
- if(n.x < 0 || n.x > W) n.vx *= -1;
507
- if(n.y < 0 || n.y > H) n.vy *= -1;
508
- }
509
-
510
- requestAnimationFrame(draw);
511
- }
512
- draw();
513
- })();
514
-
515
- // --- Reveal on scroll ---
516
- const observer = new IntersectionObserver(entries => {
517
- entries.forEach(e => { if(e.isIntersecting) e.target.classList.add('visible'); });
518
- }, {threshold: 0.1});
519
- document.querySelectorAll('.reveal').forEach(el => observer.observe(el));
520
-
521
- // --- Tab switching ---
522
- document.querySelectorAll('.tab-btn').forEach(btn => {
523
- btn.addEventListener('click', () => {
524
- document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
525
- document.querySelectorAll('.tab-panel').forEach(p => p.classList.remove('active'));
526
- btn.classList.add('active');
527
- document.getElementById('tab-' + btn.dataset.tab).classList.add('active');
528
- });
529
- });
530
-
531
- // --- Animate stat numbers ---
532
- const numObserver = new IntersectionObserver(entries => {
533
- entries.forEach(e => {
534
- if(!e.isIntersecting) return;
535
- const el = e.target;
536
- if(el.dataset.animated) return;
537
- el.dataset.animated = '1';
538
- const target = parseInt(el.textContent.replace(/\\D/g,''), 10);
539
- if(isNaN(target) || target === 0) return;
540
- const duration = 1200;
541
- const start = performance.now();
542
- function tick(now){
543
- const t = Math.min((now - start) / duration, 1);
544
- const ease = 1 - Math.pow(1 - t, 3);
545
- el.textContent = Math.round(target * ease).toLocaleString();
546
- if(t < 1) requestAnimationFrame(tick);
547
- }
548
- requestAnimationFrame(tick);
549
- });
550
- }, {threshold: 0.5});
551
- document.querySelectorAll('.stat-number').forEach(el => numObserver.observe(el));
552
-
553
- // --- Animate language bars ---
554
- setTimeout(() => {
555
- document.querySelectorAll('.lang-bar').forEach(bar => {
556
- bar.style.width = bar.dataset.width + '%';
557
- });
558
- }, 300);
559
-
560
- // --- Activity bar ---
561
- setTimeout(() => {
562
- document.querySelectorAll('.activity-fill').forEach(el => {
563
- el.style.width = el.dataset.target + '%';
564
- });
565
- }, 500);
566
-
567
- // --- Synapse Force-Directed Graph ---
568
- (function(){
569
- const edges = ${JSON.stringify(synapseEdges.map((e: SynapseEdge) => ({ s: e.source, t: e.target, type: e.type, w: e.weight })))};
570
- const canvas = document.getElementById('synapse-graph');
571
- if (!canvas || !edges.length) return;
572
- const ctx = canvas.getContext('2d');
573
- const container = canvas.parentElement;
574
- let W, H, dpr;
575
-
576
- const NODE_COLORS = {
577
- error: '#ff5577', solution: '#3dffa0', code_module: '#b47aff',
578
- project: '#ffb347', rule: '#5b9cff', antipattern: '#ff5577'
579
- };
580
- const DEFAULT_COLOR = '#47e5ff';
581
-
582
- // Build graph nodes & edges
583
- const nodeMap = new Map();
584
- const graphEdges = [];
585
- for (const e of edges) {
586
- if (!nodeMap.has(e.s)) nodeMap.set(e.s, { id: e.s, type: e.s.split(':')[0], x: 0, y: 0, vx: 0, vy: 0, connections: 0 });
587
- if (!nodeMap.has(e.t)) nodeMap.set(e.t, { id: e.t, type: e.t.split(':')[0], x: 0, y: 0, vx: 0, vy: 0, connections: 0 });
588
- nodeMap.get(e.s).connections++;
589
- nodeMap.get(e.t).connections++;
590
- graphEdges.push({ source: nodeMap.get(e.s), target: nodeMap.get(e.t), type: e.type, weight: e.w });
591
- }
592
- const nodes = [...nodeMap.values()];
593
-
594
- function resize() {
595
- dpr = window.devicePixelRatio || 1;
596
- W = container.clientWidth;
597
- H = 500;
598
- canvas.width = W * dpr;
599
- canvas.height = H * dpr;
600
- canvas.style.width = W + 'px';
601
- canvas.style.height = H + 'px';
602
- ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
603
- }
604
- resize();
605
- window.addEventListener('resize', resize);
606
-
607
- // Random initial positions
608
- for (const n of nodes) {
609
- n.x = W * 0.2 + Math.random() * W * 0.6;
610
- n.y = H * 0.2 + Math.random() * H * 0.6;
611
- }
612
-
613
- // Force simulation
614
- const REPULSION = 3000;
615
- const ATTRACTION = 0.008;
616
- const DAMPING = 0.85;
617
- const CENTER_GRAVITY = 0.002;
618
- let hovered = null;
619
- let dragging = null;
620
- let dragOff = {x:0,y:0};
621
-
622
- function simulate() {
623
- // Repulsion
624
- for (let i = 0; i < nodes.length; i++) {
625
- for (let j = i + 1; j < nodes.length; j++) {
626
- let dx = nodes[i].x - nodes[j].x;
627
- let dy = nodes[i].y - nodes[j].y;
628
- let dist = Math.sqrt(dx*dx + dy*dy) || 1;
629
- let force = REPULSION / (dist * dist);
630
- let fx = (dx / dist) * force;
631
- let fy = (dy / dist) * force;
632
- nodes[i].vx += fx; nodes[i].vy += fy;
633
- nodes[j].vx -= fx; nodes[j].vy -= fy;
634
- }
635
- }
636
- // Attraction along edges
637
- for (const e of graphEdges) {
638
- let dx = e.target.x - e.source.x;
639
- let dy = e.target.y - e.source.y;
640
- let dist = Math.sqrt(dx*dx + dy*dy) || 1;
641
- let force = (dist - 100) * ATTRACTION * e.weight;
642
- let fx = (dx / dist) * force;
643
- let fy = (dy / dist) * force;
644
- e.source.vx += fx; e.source.vy += fy;
645
- e.target.vx -= fx; e.target.vy -= fy;
646
- }
647
- // Center gravity
648
- for (const n of nodes) {
649
- n.vx += (W/2 - n.x) * CENTER_GRAVITY;
650
- n.vy += (H/2 - n.y) * CENTER_GRAVITY;
651
- }
652
- // Apply & damp
653
- for (const n of nodes) {
654
- if (n === dragging) continue;
655
- n.vx *= DAMPING; n.vy *= DAMPING;
656
- n.x += n.vx; n.y += n.vy;
657
- n.x = Math.max(20, Math.min(W - 20, n.x));
658
- n.y = Math.max(20, Math.min(H - 20, n.y));
659
- }
660
- }
661
-
662
- function getNodeRadius(n) { return Math.min(16, 5 + n.connections * 1.5); }
663
-
664
- function draw() {
665
- ctx.clearRect(0, 0, W, H);
666
- // Edges
667
- for (const e of graphEdges) {
668
- const alpha = 0.15 + e.weight * 0.5;
669
- ctx.strokeStyle = 'rgba(91,156,255,' + Math.min(0.8, alpha) + ')';
670
- ctx.lineWidth = 0.5 + e.weight * 2;
671
- ctx.beginPath();
672
- ctx.moveTo(e.source.x, e.source.y);
673
- ctx.lineTo(e.target.x, e.target.y);
674
- ctx.stroke();
675
- }
676
- // Nodes
677
- for (const n of nodes) {
678
- const r = getNodeRadius(n);
679
- const color = NODE_COLORS[n.type] || DEFAULT_COLOR;
680
- const isHover = n === hovered || n === dragging;
681
- // Glow
682
- if (isHover) {
683
- ctx.shadowColor = color;
684
- ctx.shadowBlur = 20;
685
- }
686
- ctx.fillStyle = color;
687
- ctx.globalAlpha = isHover ? 1 : 0.8;
688
- ctx.beginPath();
689
- ctx.arc(n.x, n.y, r, 0, Math.PI * 2);
690
- ctx.fill();
691
- ctx.globalAlpha = 1;
692
- ctx.shadowBlur = 0;
693
- // Label for hovered or large nodes
694
- if (isHover || n.connections >= 4) {
695
- ctx.fillStyle = '#e8eaf6';
696
- ctx.font = (isHover ? 'bold ' : '') + '11px Inter, system-ui, sans-serif';
697
- ctx.textAlign = 'center';
698
- ctx.fillText(n.id, n.x, n.y - r - 6);
699
- }
700
- }
701
- simulate();
702
- requestAnimationFrame(draw);
703
- }
704
- draw();
705
-
706
- // Interaction
707
- const tooltip = document.getElementById('graph-tooltip');
708
- function getNodeAt(mx, my) {
709
- for (let i = nodes.length - 1; i >= 0; i--) {
710
- const n = nodes[i], r = getNodeRadius(n);
711
- if (Math.hypot(mx - n.x, my - n.y) <= r + 4) return n;
712
- }
713
- return null;
714
- }
715
- function getPos(e) {
716
- const rect = canvas.getBoundingClientRect();
717
- return { x: e.clientX - rect.left, y: e.clientY - rect.top };
718
- }
719
- canvas.addEventListener('mousemove', function(e) {
720
- const p = getPos(e);
721
- if (dragging) {
722
- dragging.x = p.x + dragOff.x;
723
- dragging.y = p.y + dragOff.y;
724
- dragging.vx = 0; dragging.vy = 0;
725
- return;
726
- }
727
- const n = getNodeAt(p.x, p.y);
728
- hovered = n;
729
- canvas.style.cursor = n ? 'pointer' : 'grab';
730
- if (n) {
731
- const conns = graphEdges.filter(e => e.source === n || e.target === n);
732
- tooltip.innerHTML = '<strong>' + n.id + '</strong><br>' + conns.length + ' connections';
733
- tooltip.style.display = 'block';
734
- tooltip.style.left = (p.x + 15) + 'px';
735
- tooltip.style.top = (p.y - 10) + 'px';
736
- } else {
737
- tooltip.style.display = 'none';
738
- }
739
- });
740
- canvas.addEventListener('mousedown', function(e) {
741
- const p = getPos(e);
742
- const n = getNodeAt(p.x, p.y);
743
- if (n) {
744
- dragging = n;
745
- dragOff = { x: n.x - p.x, y: n.y - p.y };
746
- canvas.style.cursor = 'grabbing';
747
- }
748
- });
749
- canvas.addEventListener('mouseup', function() { dragging = null; });
750
- canvas.addEventListener('mouseleave', function() { dragging = null; hovered = null; tooltip.style.display = 'none'; });
751
- })();
752
- </script>
753
- </body>
754
- </html>`;
755
- }
1
+ import { Command } from 'commander';
2
+ import { withIpc } from '../ipc-helper.js';
3
+ import { writeFileSync } from 'fs';
4
+ import { resolve } from 'path';
5
+ import { c, icons } from '../colors.js';
6
+
7
+ export function dashboardCommand(): Command {
8
+ return new Command('dashboard')
9
+ .description('Generate and open the Brain dashboard with live data')
10
+ .option('-o, --output <path>', 'Output HTML file path')
11
+ .option('--no-open', 'Generate without opening in browser')
12
+ .option('-l, --live', 'Start live dashboard server with SSE updates')
13
+ .option('-p, --port <number>', 'Port for live dashboard', '7420')
14
+ .action(async (opts) => {
15
+ await withIpc(async (client) => {
16
+ console.log(`${icons.chart} ${c.info('Fetching data from Brain...')}`);
17
+
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ const summary: any = await client.request('analytics.summary', {});
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ const network: any = await client.request('synapse.stats', {});
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ const networkOverview: any = await client.request('analytics.network', { limit: 50 });
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ const insights: any = await client.request('research.insights', {
26
+ activeOnly: true,
27
+ limit: 500,
28
+ });
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ const modules: any = await client.request('code.modules', {});
31
+
32
+ // Collect language stats
33
+ const langStats: Record<string, number> = {};
34
+ const projectSet = new Set<string>();
35
+ if (Array.isArray(modules)) {
36
+ for (const m of modules) {
37
+ langStats[m.language] = (langStats[m.language] || 0) + 1;
38
+ if (m.projectId) projectSet.add(String(m.projectId));
39
+ }
40
+ }
41
+
42
+ // Categorize insights
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
+ const insightList = Array.isArray(insights) ? insights : [];
45
+ const templates = insightList.filter((i: InsightItem) => i.type === 'template_candidate' || i.title?.includes('Template'));
46
+ const suggestions = insightList.filter((i: InsightItem) => i.type === 'suggestion' || i.type === 'project_suggestion');
47
+ const trends = insightList.filter((i: InsightItem) => i.type === 'trend' || i.type === 'pattern');
48
+ const gaps = insightList.filter((i: InsightItem) => i.type === 'gap');
49
+ const warnings = insightList.filter((i: InsightItem) => i.type === 'warning');
50
+ const synergies = insightList.filter((i: InsightItem) => i.type === 'synergy' || i.type === 'optimization');
51
+
52
+ // Build synapse graph data
53
+ const synapseEdges = Array.isArray(networkOverview?.strongestSynapses) ? networkOverview.strongestSynapses : [];
54
+
55
+ const data = {
56
+ stats: {
57
+ modules: summary.modules?.total ?? 0,
58
+ synapses: network.totalSynapses ?? 0,
59
+ errors: summary.errors?.total ?? 0,
60
+ solutions: summary.solutions?.total ?? 0,
61
+ rules: summary.rules?.active ?? 0,
62
+ insights: insightList.length,
63
+ },
64
+ langStats,
65
+ insights: { templates, suggestions, trends, gaps, warnings, synergies },
66
+ synapseEdges,
67
+ };
68
+
69
+ const html = generateHtml(data);
70
+ const outPath = opts.output
71
+ ? resolve(opts.output)
72
+ : resolve(import.meta.dirname, '../../../dashboard.html');
73
+
74
+ // Inject live SSE connection for --live mode
75
+ let finalHtml = html;
76
+ if (opts.live) {
77
+ const apiPort = opts.port || '7777';
78
+ const sseScript = `
79
+ <script>
80
+ (function(){
81
+ const evtSource = new EventSource('http://localhost:${apiPort}/api/v1/events');
82
+ evtSource.onmessage = function(e) {
83
+ try {
84
+ const data = JSON.parse(e.data);
85
+ if (data.type === 'stats_update') {
86
+ document.querySelectorAll('.stat-card').forEach(card => {
87
+ const label = card.querySelector('.stat-label')?.textContent?.toLowerCase();
88
+ const num = card.querySelector('.stat-number');
89
+ if (label && num && data.stats[label] !== undefined) {
90
+ num.textContent = Number(data.stats[label]).toLocaleString();
91
+ }
92
+ });
93
+ }
94
+ if (data.type === 'event') {
95
+ const dot = document.querySelector('.activity-dot');
96
+ if (dot) { dot.style.background = '#ff5577'; setTimeout(() => dot.style.background = '', 500); }
97
+ }
98
+ } catch {}
99
+ };
100
+ evtSource.onerror = function() { setTimeout(() => location.reload(), 5000); };
101
+ })();
102
+ </script>`;
103
+ finalHtml = html.replace('</body>', sseScript + '</body>');
104
+ }
105
+
106
+ writeFileSync(outPath, finalHtml, 'utf-8');
107
+ console.log(`${icons.ok} ${c.success('Dashboard written to')} ${c.dim(outPath)}`);
108
+ if (opts.live) {
109
+ console.log(` ${c.info('Live mode:')} Connected to Brain daemon SSE on port ${opts.port || 7777}`);
110
+ }
111
+ console.log(` ${c.label('Modules:')} ${c.value(data.stats.modules)} ${c.label('Synapses:')} ${c.value(data.stats.synapses)} ${c.label('Insights:')} ${c.value(data.stats.insights)}`);
112
+
113
+ if (opts.open !== false) {
114
+ const { exec } = await import('child_process');
115
+ exec(`start "" "${outPath}"`);
116
+ }
117
+ });
118
+ });
119
+ }
120
+
121
+ interface InsightItem {
122
+ type: string;
123
+ title: string;
124
+ description?: string;
125
+ priority?: string;
126
+ }
127
+
128
+ interface SynapseEdge {
129
+ source: string;
130
+ target: string;
131
+ type: string;
132
+ weight: number;
133
+ }
134
+
135
+ interface DashboardData {
136
+ stats: {
137
+ modules: number;
138
+ synapses: number;
139
+ errors: number;
140
+ solutions: number;
141
+ rules: number;
142
+ insights: number;
143
+ };
144
+ langStats: Record<string, number>;
145
+ insights: {
146
+ templates: InsightItem[];
147
+ suggestions: InsightItem[];
148
+ trends: InsightItem[];
149
+ gaps: InsightItem[];
150
+ warnings: InsightItem[];
151
+ synergies: InsightItem[];
152
+ };
153
+ synapseEdges: SynapseEdge[];
154
+ }
155
+
156
+ function esc(s: string): string {
157
+ return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
158
+ }
159
+
160
+ function generateHtml(data: DashboardData): string {
161
+ const { stats, langStats, insights, synapseEdges } = data;
162
+
163
+ // Build language chart bars
164
+ const sortedLangs = Object.entries(langStats).sort((a, b) => b[1] - a[1]);
165
+ const maxLang = sortedLangs[0]?.[1] || 1;
166
+ const langBars = sortedLangs.slice(0, 12).map(([lang, count]) => {
167
+ const pct = Math.round((count / maxLang) * 100);
168
+ return `<div class="lang-row"><span class="lang-name">${esc(lang)}</span><div class="lang-bar-bg"><div class="lang-bar" data-width="${pct}"></div></div><span class="lang-count">${count}</span></div>`;
169
+ }).join('\n');
170
+
171
+ // Build insight cards
172
+ function insightCards(items: InsightItem[], color: string): string {
173
+ if (!items.length) return '<p class="empty">Keine Insights in dieser Kategorie.</p>';
174
+ return items.slice(0, 30).map(i => {
175
+ const prio = i.priority ? `<span class="prio prio-${String(i.priority).toLowerCase()}">${esc(String(i.priority))}</span>` : '';
176
+ return `<div class="insight-card ${color}"><div class="insight-header">${prio}<strong>${esc(i.title)}</strong></div><p>${esc((i.description || '').slice(0, 200))}</p></div>`;
177
+ }).join('\n');
178
+ }
179
+
180
+ const totalKnowledge = stats.modules + stats.synapses + stats.errors + stats.solutions;
181
+ const activityLevel = Math.min(100, Math.round((stats.insights / Math.max(1, totalKnowledge)) * 1000));
182
+
183
+ return `<!DOCTYPE html>
184
+ <html lang="de">
185
+ <head>
186
+ <meta charset="UTF-8">
187
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
188
+ <title>Brain — Dashboard</title>
189
+ <style>
190
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');
191
+ *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
192
+ :root{
193
+ --bg:#04060e;--bg2:rgba(10,12,24,.7);--bg3:rgba(20,24,50,.6);--bg4:rgba(30,35,70,.5);
194
+ --glass:rgba(15,18,40,.55);--glass-border:rgba(100,120,255,.12);--glass-hover:rgba(100,120,255,.2);
195
+ --text:#e8eaf6;--text2:#8b8fb0;--text3:#4a4d6e;
196
+ --blue:#5b9cff;--red:#ff5577;--green:#3dffa0;
197
+ --purple:#b47aff;--orange:#ffb347;--cyan:#47e5ff;
198
+ --accent:linear-gradient(135deg,#b47aff,#5b9cff,#47e5ff);
199
+ --radius:16px;--radius-sm:10px;
200
+ }
201
+ html{scroll-behavior:smooth}
202
+ body{font-family:'Inter',system-ui,sans-serif;background:var(--bg);color:var(--text);line-height:1.6;min-height:100vh;overflow-x:hidden}
203
+
204
+ /* Neural canvas background */
205
+ #neural-bg{position:fixed;top:0;left:0;width:100%;height:100%;z-index:0;pointer-events:none}
206
+
207
+ /* Ambient glow orbs */
208
+ .orb{position:fixed;border-radius:50%;filter:blur(120px);opacity:.12;pointer-events:none;z-index:0}
209
+ .orb-1{width:600px;height:600px;background:var(--purple);top:-200px;left:-100px;animation:orb-float 20s ease-in-out infinite}
210
+ .orb-2{width:500px;height:500px;background:var(--blue);bottom:-150px;right:-100px;animation:orb-float 25s ease-in-out infinite reverse}
211
+ .orb-3{width:400px;height:400px;background:var(--cyan);top:40%;left:50%;animation:orb-float 18s ease-in-out infinite 5s}
212
+ @keyframes orb-float{0%,100%{transform:translate(0,0) scale(1)}33%{transform:translate(60px,-40px) scale(1.1)}66%{transform:translate(-40px,60px) scale(.9)}}
213
+
214
+ .container{max-width:1400px;margin:0 auto;padding:0 28px;position:relative;z-index:1}
215
+
216
+ /* Reveal animations */
217
+ .reveal{opacity:0;transform:translateY(30px);transition:opacity .6s ease,transform .6s ease}
218
+ .reveal.visible{opacity:1;transform:translateY(0)}
219
+ .reveal-delay-1{transition-delay:.1s}.reveal-delay-2{transition-delay:.2s}
220
+ .reveal-delay-3{transition-delay:.3s}.reveal-delay-4{transition-delay:.4s}
221
+ .reveal-delay-5{transition-delay:.5s}
222
+
223
+ section{margin-bottom:56px}
224
+
225
+ /* Header */
226
+ header{padding:60px 0 24px;text-align:center;position:relative}
227
+ .logo{display:flex;align-items:center;justify-content:center;gap:20px;margin-bottom:12px}
228
+ .logo-icon{
229
+ width:68px;height:68px;border-radius:18px;
230
+ background:linear-gradient(135deg,var(--purple),var(--blue),var(--cyan));
231
+ display:flex;align-items:center;justify-content:center;font-size:32px;
232
+ box-shadow:0 0 60px rgba(170,102,255,.35),0 0 120px rgba(90,150,255,.15);
233
+ animation:icon-breathe 4s ease-in-out infinite;
234
+ position:relative;
235
+ }
236
+ .logo-icon::after{
237
+ content:'';position:absolute;inset:-3px;border-radius:20px;
238
+ background:linear-gradient(135deg,var(--purple),var(--cyan));
239
+ opacity:.4;filter:blur(8px);z-index:-1;animation:icon-breathe 4s ease-in-out infinite reverse;
240
+ }
241
+ @keyframes icon-breathe{0%,100%{box-shadow:0 0 60px rgba(170,102,255,.35),0 0 120px rgba(90,150,255,.15)}50%{box-shadow:0 0 80px rgba(170,102,255,.5),0 0 160px rgba(90,150,255,.25)}}
242
+ .logo h1{font-size:2.8rem;font-weight:900;letter-spacing:-1px;background:linear-gradient(135deg,#fff 0%,var(--blue) 50%,var(--purple) 100%);-webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text}
243
+ .tagline{color:var(--text2);font-size:1.05rem;font-weight:300;letter-spacing:.5px}
244
+
245
+ /* Activity indicator */
246
+ .activity{display:inline-flex;align-items:center;gap:10px;margin-top:16px;padding:8px 20px;border-radius:30px;background:var(--glass);border:1px solid var(--glass-border);backdrop-filter:blur(20px)}
247
+ .activity-dot{width:8px;height:8px;border-radius:50%;background:var(--green);box-shadow:0 0 12px var(--green);animation:pulse-dot 2s ease-in-out infinite}
248
+ @keyframes pulse-dot{0%,100%{opacity:1;box-shadow:0 0 12px var(--green)}50%{opacity:.5;box-shadow:0 0 20px var(--green)}}
249
+ .activity-text{font-size:.8rem;color:var(--text2);font-weight:500}
250
+ .activity-bar{width:80px;height:4px;border-radius:2px;background:var(--bg4);overflow:hidden}
251
+ .activity-fill{height:100%;border-radius:2px;background:linear-gradient(90deg,var(--green),var(--cyan));transition:width 1.5s ease}
252
+
253
+ /* Nav */
254
+ nav{display:flex;justify-content:center;gap:8px;flex-wrap:wrap;padding:20px 0;margin-bottom:40px}
255
+ nav a{
256
+ color:var(--text2);text-decoration:none;padding:8px 18px;border-radius:24px;font-size:.85rem;font-weight:500;
257
+ transition:all .3s ease;border:1px solid transparent;backdrop-filter:blur(10px);
258
+ }
259
+ nav a:hover{color:var(--text);background:var(--glass);border-color:var(--glass-border);transform:translateY(-1px)}
260
+ nav a.research{
261
+ background:var(--glass);color:var(--cyan);border-color:rgba(71,229,255,.25);font-weight:600;
262
+ box-shadow:0 0 20px rgba(71,229,255,.1);animation:nav-glow 3s ease-in-out infinite alternate;
263
+ }
264
+ @keyframes nav-glow{0%{box-shadow:0 0 20px rgba(71,229,255,.1)}100%{box-shadow:0 0 35px rgba(71,229,255,.2)}}
265
+
266
+ /* Stats */
267
+ .stats-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(190px,1fr));gap:18px}
268
+ .stat-card{
269
+ background:var(--glass);border:1px solid var(--glass-border);border-radius:var(--radius);
270
+ padding:28px 22px;text-align:center;position:relative;overflow:hidden;
271
+ transition:all .35s ease;backdrop-filter:blur(20px);
272
+ }
273
+ .stat-card:hover{transform:translateY(-4px);border-color:var(--glass-hover);box-shadow:0 20px 60px rgba(0,0,0,.3)}
274
+ .stat-card::before{content:'';position:absolute;top:0;left:0;right:0;height:2px}
275
+ .stat-card::after{content:'';position:absolute;top:0;left:0;right:0;bottom:0;background:radial-gradient(ellipse at 50% 0%,rgba(255,255,255,.03),transparent 70%);pointer-events:none}
276
+ .stat-card.blue::before{background:linear-gradient(90deg,transparent,var(--blue),transparent)}
277
+ .stat-card.purple::before{background:linear-gradient(90deg,transparent,var(--purple),transparent)}
278
+ .stat-card.red::before{background:linear-gradient(90deg,transparent,var(--red),transparent)}
279
+ .stat-card.green::before{background:linear-gradient(90deg,transparent,var(--green),transparent)}
280
+ .stat-card.orange::before{background:linear-gradient(90deg,transparent,var(--orange),transparent)}
281
+ .stat-card.cyan::before{background:linear-gradient(90deg,transparent,var(--cyan),transparent)}
282
+ .stat-number{font-size:2.6rem;font-weight:900;letter-spacing:-2px}
283
+ .stat-card.blue .stat-number{color:var(--blue)}.stat-card.purple .stat-number{color:var(--purple)}
284
+ .stat-card.red .stat-number{color:var(--red)}.stat-card.green .stat-number{color:var(--green)}
285
+ .stat-card.orange .stat-number{color:var(--orange)}.stat-card.cyan .stat-number{color:var(--cyan)}
286
+ .stat-label{color:var(--text2);font-size:.82rem;margin-top:6px;font-weight:500;letter-spacing:.3px;text-transform:uppercase}
287
+
288
+ /* Section titles */
289
+ .section-title{font-size:1.5rem;font-weight:700;margin-bottom:24px;display:flex;align-items:center;gap:12px}
290
+ .section-title .icon{font-size:1.2rem;width:38px;height:38px;border-radius:var(--radius-sm);display:flex;align-items:center;justify-content:center;backdrop-filter:blur(10px)}
291
+
292
+ /* Language chart */
293
+ .lang-chart{max-width:650px}
294
+ .lang-row{display:flex;align-items:center;gap:14px;margin-bottom:10px}
295
+ .lang-name{width:100px;text-align:right;font-size:.85rem;color:var(--text2);font-weight:500}
296
+ .lang-bar-bg{flex:1;height:28px;background:var(--bg3);border-radius:6px;overflow:hidden;border:1px solid var(--glass-border)}
297
+ .lang-bar{height:100%;background:var(--accent);border-radius:6px;width:0;transition:width 1.2s cubic-bezier(.22,1,.36,1)}
298
+ .lang-count{width:50px;font-size:.85rem;color:var(--text2);font-weight:600}
299
+
300
+ /* Insight tabs */
301
+ .tab-bar{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:24px}
302
+ .tab-btn{
303
+ padding:10px 20px;border-radius:24px;border:1px solid var(--glass-border);
304
+ background:var(--glass);color:var(--text2);cursor:pointer;font-size:.85rem;font-weight:500;
305
+ transition:all .3s ease;backdrop-filter:blur(10px);font-family:inherit;
306
+ }
307
+ .tab-btn:hover{border-color:var(--glass-hover);color:var(--text);transform:translateY(-1px)}
308
+ .tab-btn.active{border-color:rgba(71,229,255,.35);color:var(--cyan);background:rgba(71,229,255,.08);box-shadow:0 0 20px rgba(71,229,255,.1)}
309
+ .tab-btn .count{background:var(--bg4);padding:2px 8px;border-radius:12px;font-size:.72rem;margin-left:6px;font-weight:600}
310
+ .tab-panel{display:none}.tab-panel.active{display:block}
311
+ .insight-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(380px,1fr));gap:14px}
312
+ .insight-card{
313
+ background:var(--glass);border:1px solid var(--glass-border);border-radius:var(--radius-sm);
314
+ padding:18px;border-left:3px solid var(--text3);transition:all .25s ease;backdrop-filter:blur(20px);
315
+ }
316
+ .insight-card:hover{transform:translateX(6px);border-color:var(--glass-hover);box-shadow:0 8px 30px rgba(0,0,0,.2)}
317
+ .insight-card.cyan{border-left-color:var(--cyan)}.insight-card.orange{border-left-color:var(--orange)}
318
+ .insight-card.green{border-left-color:var(--green)}.insight-card.red{border-left-color:var(--red)}
319
+ .insight-card.purple{border-left-color:var(--purple)}.insight-card.blue{border-left-color:var(--blue)}
320
+ .insight-header{display:flex;align-items:center;gap:8px;margin-bottom:8px;flex-wrap:wrap}
321
+ .insight-card p{color:var(--text2);font-size:.85rem;line-height:1.5}
322
+ .prio{font-size:.68rem;padding:3px 10px;border-radius:12px;text-transform:uppercase;font-weight:700;letter-spacing:.5px}
323
+ .prio-critical{background:rgba(255,85,119,.15);color:var(--red);border:1px solid rgba(255,85,119,.25)}
324
+ .prio-high{background:rgba(255,179,71,.15);color:var(--orange);border:1px solid rgba(255,179,71,.25)}
325
+ .prio-medium{background:rgba(91,156,255,.15);color:var(--blue);border:1px solid rgba(91,156,255,.25)}
326
+ .prio-low{background:rgba(139,143,176,.1);color:var(--text2);border:1px solid rgba(139,143,176,.2)}
327
+ .empty{color:var(--text3);font-style:italic;padding:24px}
328
+
329
+ /* Graph */
330
+ .graph-container{position:relative;background:var(--glass);border:1px solid var(--glass-border);border-radius:var(--radius);overflow:hidden;backdrop-filter:blur(20px)}
331
+ #synapse-graph{width:100%;height:500px;display:block;cursor:grab}
332
+ #synapse-graph:active{cursor:grabbing}
333
+ .graph-legend{display:flex;gap:16px;flex-wrap:wrap;padding:12px 20px;border-top:1px solid var(--glass-border);font-size:.8rem;color:var(--text2)}
334
+ .legend-dot{display:inline-block;width:10px;height:10px;border-radius:50%;margin-right:6px;vertical-align:middle}
335
+ .graph-tooltip{position:absolute;display:none;background:var(--bg2);border:1px solid var(--glass-border);border-radius:8px;padding:8px 14px;font-size:.8rem;color:var(--text);pointer-events:none;z-index:10;backdrop-filter:blur(20px);box-shadow:0 8px 30px rgba(0,0,0,.3)}
336
+
337
+ /* Footer */
338
+ footer{text-align:center;padding:40px 0;border-top:1px solid var(--glass-border)}
339
+ footer p{color:var(--text3);font-size:.8rem}
340
+ footer code{background:var(--glass);padding:3px 10px;border-radius:6px;font-size:.78rem;border:1px solid var(--glass-border)}
341
+
342
+ /* Responsive */
343
+ @media(max-width:600px){.stats-grid{grid-template-columns:1fr 1fr}.insight-grid{grid-template-columns:1fr}.logo h1{font-size:2rem}}
344
+ </style>
345
+ </head>
346
+ <body>
347
+
348
+ <canvas id="neural-bg"></canvas>
349
+ <div class="orb orb-1"></div>
350
+ <div class="orb orb-2"></div>
351
+ <div class="orb orb-3"></div>
352
+
353
+ <div class="container">
354
+ <header class="reveal">
355
+ <div class="logo">
356
+ <div class="logo-icon">&#129504;</div>
357
+ <h1>Brain</h1>
358
+ </div>
359
+ <p class="tagline">Adaptive Code Intelligence</p>
360
+ <div class="activity">
361
+ <span class="activity-dot"></span>
362
+ <span class="activity-text">Neural Activity</span>
363
+ <div class="activity-bar"><div class="activity-fill" style="width:0%" data-target="${activityLevel}"></div></div>
364
+ <span class="activity-text" style="color:var(--cyan);font-weight:700">${activityLevel}%</span>
365
+ </div>
366
+ </header>
367
+
368
+ <nav class="reveal reveal-delay-1">
369
+ <a href="#stats">Stats</a>
370
+ <a href="#languages">Languages</a>
371
+ <a href="#network">&#128300; Network</a>
372
+ <a href="#research" class="research">&#128161; Research</a>
373
+ </nav>
374
+
375
+ <section id="stats" class="reveal reveal-delay-2">
376
+ <div class="section-title"><div class="icon" style="background:rgba(91,156,255,.1)">&#128202;</div> Neural Status</div>
377
+ <div class="stats-grid">
378
+ <div class="stat-card blue"><div class="stat-number">${stats.modules.toLocaleString()}</div><div class="stat-label">Modules</div></div>
379
+ <div class="stat-card purple"><div class="stat-number">${stats.synapses.toLocaleString()}</div><div class="stat-label">Synapses</div></div>
380
+ <div class="stat-card cyan"><div class="stat-number">${stats.insights}</div><div class="stat-label">Insights</div></div>
381
+ <div class="stat-card red"><div class="stat-number">${stats.errors}</div><div class="stat-label">Errors</div></div>
382
+ <div class="stat-card green"><div class="stat-number">${stats.solutions}</div><div class="stat-label">Solutions</div></div>
383
+ <div class="stat-card orange"><div class="stat-number">${stats.rules}</div><div class="stat-label">Rules</div></div>
384
+ </div>
385
+ </section>
386
+
387
+ <section id="languages" class="reveal reveal-delay-3">
388
+ <div class="section-title"><div class="icon" style="background:rgba(180,122,255,.1)">&#128187;</div> Languages</div>
389
+ <div class="lang-chart">${langBars}</div>
390
+ </section>
391
+
392
+ <section id="network" class="reveal reveal-delay-4">
393
+ <div class="section-title"><div class="icon" style="background:rgba(71,229,255,.1)">&#128300;</div> Synapse Network</div>
394
+ <div class="graph-container">
395
+ <canvas id="synapse-graph"></canvas>
396
+ <div class="graph-legend">
397
+ <span><span class="legend-dot" style="background:var(--blue)"></span> error</span>
398
+ <span><span class="legend-dot" style="background:var(--green)"></span> solution</span>
399
+ <span><span class="legend-dot" style="background:var(--purple)"></span> code_module</span>
400
+ <span><span class="legend-dot" style="background:var(--orange)"></span> project</span>
401
+ <span><span class="legend-dot" style="background:var(--cyan)"></span> other</span>
402
+ </div>
403
+ <div id="graph-tooltip" class="graph-tooltip"></div>
404
+ </div>
405
+ </section>
406
+
407
+ <section id="research" class="reveal reveal-delay-5">
408
+ <div class="section-title"><div class="icon" style="background:rgba(71,229,255,.1)">&#128300;</div> Research Insights</div>
409
+ <div class="tab-bar">
410
+ <button class="tab-btn active" data-tab="templates">&#127912; Templates <span class="count">${insights.templates.length}</span></button>
411
+ <button class="tab-btn" data-tab="suggestions">&#128161; Suggestions <span class="count">${insights.suggestions.length}</span></button>
412
+ <button class="tab-btn" data-tab="trends">&#128200; Trends <span class="count">${insights.trends.length}</span></button>
413
+ <button class="tab-btn" data-tab="gaps">&#9888;&#65039; Gaps <span class="count">${insights.gaps.length}</span></button>
414
+ <button class="tab-btn" data-tab="synergies">&#9889; Synergies <span class="count">${insights.synergies.length}</span></button>
415
+ <button class="tab-btn" data-tab="warnings">&#128680; Warnings <span class="count">${insights.warnings.length}</span></button>
416
+ </div>
417
+ <div class="tab-panel active" id="tab-templates"><div class="insight-grid">${insightCards(insights.templates, 'cyan')}</div></div>
418
+ <div class="tab-panel" id="tab-suggestions"><div class="insight-grid">${insightCards(insights.suggestions, 'orange')}</div></div>
419
+ <div class="tab-panel" id="tab-trends"><div class="insight-grid">${insightCards(insights.trends, 'green')}</div></div>
420
+ <div class="tab-panel" id="tab-gaps"><div class="insight-grid">${insightCards(insights.gaps, 'red')}</div></div>
421
+ <div class="tab-panel" id="tab-synergies"><div class="insight-grid">${insightCards(insights.synergies, 'purple')}</div></div>
422
+ <div class="tab-panel" id="tab-warnings"><div class="insight-grid">${insightCards(insights.warnings, 'red')}</div></div>
423
+ </section>
424
+
425
+ <footer class="reveal reveal-delay-5">
426
+ <p>Brain v1.0 &mdash; <code>brain dashboard</code></p>
427
+ </footer>
428
+ </div>
429
+
430
+ <script>
431
+ // --- Neural Network Canvas ---
432
+ (function(){
433
+ const canvas = document.getElementById('neural-bg');
434
+ const ctx = canvas.getContext('2d');
435
+ let W, H, nodes = [], mouse = {x:-1000,y:-1000};
436
+
437
+ function resize(){
438
+ W = canvas.width = window.innerWidth;
439
+ H = canvas.height = window.innerHeight;
440
+ }
441
+ resize();
442
+ window.addEventListener('resize', resize);
443
+ document.addEventListener('mousemove', e => { mouse.x = e.clientX; mouse.y = e.clientY; });
444
+
445
+ const NODE_COUNT = Math.min(80, Math.floor(window.innerWidth / 18));
446
+ const CONNECT_DIST = 180;
447
+ const MOUSE_DIST = 200;
448
+
449
+ for(let i = 0; i < NODE_COUNT; i++){
450
+ nodes.push({
451
+ x: Math.random() * W,
452
+ y: Math.random() * H,
453
+ vx: (Math.random() - 0.5) * 0.4,
454
+ vy: (Math.random() - 0.5) * 0.4,
455
+ r: Math.random() * 2 + 1,
456
+ pulse: Math.random() * Math.PI * 2,
457
+ });
458
+ }
459
+
460
+ function draw(){
461
+ ctx.clearRect(0, 0, W, H);
462
+
463
+ // Draw connections
464
+ for(let i = 0; i < nodes.length; i++){
465
+ for(let j = i + 1; j < nodes.length; j++){
466
+ const dx = nodes[i].x - nodes[j].x;
467
+ const dy = nodes[i].y - nodes[j].y;
468
+ const dist = Math.sqrt(dx*dx + dy*dy);
469
+ if(dist < CONNECT_DIST){
470
+ const alpha = (1 - dist / CONNECT_DIST) * 0.15;
471
+ ctx.strokeStyle = 'rgba(91,156,255,' + alpha + ')';
472
+ ctx.lineWidth = 0.5;
473
+ ctx.beginPath();
474
+ ctx.moveTo(nodes[i].x, nodes[i].y);
475
+ ctx.lineTo(nodes[j].x, nodes[j].y);
476
+ ctx.stroke();
477
+ }
478
+ }
479
+
480
+ // Mouse interaction
481
+ const mdx = nodes[i].x - mouse.x;
482
+ const mdy = nodes[i].y - mouse.y;
483
+ const mDist = Math.sqrt(mdx*mdx + mdy*mdy);
484
+ if(mDist < MOUSE_DIST){
485
+ const alpha = (1 - mDist / MOUSE_DIST) * 0.4;
486
+ ctx.strokeStyle = 'rgba(180,122,255,' + alpha + ')';
487
+ ctx.lineWidth = 1;
488
+ ctx.beginPath();
489
+ ctx.moveTo(nodes[i].x, nodes[i].y);
490
+ ctx.lineTo(mouse.x, mouse.y);
491
+ ctx.stroke();
492
+ }
493
+ }
494
+
495
+ // Draw nodes
496
+ const time = Date.now() * 0.001;
497
+ for(const n of nodes){
498
+ const glow = 0.4 + Math.sin(time * 1.5 + n.pulse) * 0.3;
499
+ ctx.fillStyle = 'rgba(91,156,255,' + glow + ')';
500
+ ctx.beginPath();
501
+ ctx.arc(n.x, n.y, n.r, 0, Math.PI * 2);
502
+ ctx.fill();
503
+
504
+ n.x += n.vx;
505
+ n.y += n.vy;
506
+ if(n.x < 0 || n.x > W) n.vx *= -1;
507
+ if(n.y < 0 || n.y > H) n.vy *= -1;
508
+ }
509
+
510
+ requestAnimationFrame(draw);
511
+ }
512
+ draw();
513
+ })();
514
+
515
+ // --- Reveal on scroll ---
516
+ const observer = new IntersectionObserver(entries => {
517
+ entries.forEach(e => { if(e.isIntersecting) e.target.classList.add('visible'); });
518
+ }, {threshold: 0.1});
519
+ document.querySelectorAll('.reveal').forEach(el => observer.observe(el));
520
+
521
+ // --- Tab switching ---
522
+ document.querySelectorAll('.tab-btn').forEach(btn => {
523
+ btn.addEventListener('click', () => {
524
+ document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
525
+ document.querySelectorAll('.tab-panel').forEach(p => p.classList.remove('active'));
526
+ btn.classList.add('active');
527
+ document.getElementById('tab-' + btn.dataset.tab).classList.add('active');
528
+ });
529
+ });
530
+
531
+ // --- Animate stat numbers ---
532
+ const numObserver = new IntersectionObserver(entries => {
533
+ entries.forEach(e => {
534
+ if(!e.isIntersecting) return;
535
+ const el = e.target;
536
+ if(el.dataset.animated) return;
537
+ el.dataset.animated = '1';
538
+ const target = parseInt(el.textContent.replace(/\\D/g,''), 10);
539
+ if(isNaN(target) || target === 0) return;
540
+ const duration = 1200;
541
+ const start = performance.now();
542
+ function tick(now){
543
+ const t = Math.min((now - start) / duration, 1);
544
+ const ease = 1 - Math.pow(1 - t, 3);
545
+ el.textContent = Math.round(target * ease).toLocaleString();
546
+ if(t < 1) requestAnimationFrame(tick);
547
+ }
548
+ requestAnimationFrame(tick);
549
+ });
550
+ }, {threshold: 0.5});
551
+ document.querySelectorAll('.stat-number').forEach(el => numObserver.observe(el));
552
+
553
+ // --- Animate language bars ---
554
+ setTimeout(() => {
555
+ document.querySelectorAll('.lang-bar').forEach(bar => {
556
+ bar.style.width = bar.dataset.width + '%';
557
+ });
558
+ }, 300);
559
+
560
+ // --- Activity bar ---
561
+ setTimeout(() => {
562
+ document.querySelectorAll('.activity-fill').forEach(el => {
563
+ el.style.width = el.dataset.target + '%';
564
+ });
565
+ }, 500);
566
+
567
+ // --- Synapse Force-Directed Graph ---
568
+ (function(){
569
+ const edges = ${JSON.stringify(synapseEdges.map((e: SynapseEdge) => ({ s: e.source, t: e.target, type: e.type, w: e.weight })))};
570
+ const canvas = document.getElementById('synapse-graph');
571
+ if (!canvas || !edges.length) return;
572
+ const ctx = canvas.getContext('2d');
573
+ const container = canvas.parentElement;
574
+ let W, H, dpr;
575
+
576
+ const NODE_COLORS = {
577
+ error: '#ff5577', solution: '#3dffa0', code_module: '#b47aff',
578
+ project: '#ffb347', rule: '#5b9cff', antipattern: '#ff5577'
579
+ };
580
+ const DEFAULT_COLOR = '#47e5ff';
581
+
582
+ // Build graph nodes & edges
583
+ const nodeMap = new Map();
584
+ const graphEdges = [];
585
+ for (const e of edges) {
586
+ if (!nodeMap.has(e.s)) nodeMap.set(e.s, { id: e.s, type: e.s.split(':')[0], x: 0, y: 0, vx: 0, vy: 0, connections: 0 });
587
+ if (!nodeMap.has(e.t)) nodeMap.set(e.t, { id: e.t, type: e.t.split(':')[0], x: 0, y: 0, vx: 0, vy: 0, connections: 0 });
588
+ nodeMap.get(e.s).connections++;
589
+ nodeMap.get(e.t).connections++;
590
+ graphEdges.push({ source: nodeMap.get(e.s), target: nodeMap.get(e.t), type: e.type, weight: e.w });
591
+ }
592
+ const nodes = [...nodeMap.values()];
593
+
594
+ function resize() {
595
+ dpr = window.devicePixelRatio || 1;
596
+ W = container.clientWidth;
597
+ H = 500;
598
+ canvas.width = W * dpr;
599
+ canvas.height = H * dpr;
600
+ canvas.style.width = W + 'px';
601
+ canvas.style.height = H + 'px';
602
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
603
+ }
604
+ resize();
605
+ window.addEventListener('resize', resize);
606
+
607
+ // Random initial positions
608
+ for (const n of nodes) {
609
+ n.x = W * 0.2 + Math.random() * W * 0.6;
610
+ n.y = H * 0.2 + Math.random() * H * 0.6;
611
+ }
612
+
613
+ // Force simulation
614
+ const REPULSION = 3000;
615
+ const ATTRACTION = 0.008;
616
+ const DAMPING = 0.85;
617
+ const CENTER_GRAVITY = 0.002;
618
+ let hovered = null;
619
+ let dragging = null;
620
+ let dragOff = {x:0,y:0};
621
+
622
+ function simulate() {
623
+ // Repulsion
624
+ for (let i = 0; i < nodes.length; i++) {
625
+ for (let j = i + 1; j < nodes.length; j++) {
626
+ let dx = nodes[i].x - nodes[j].x;
627
+ let dy = nodes[i].y - nodes[j].y;
628
+ let dist = Math.sqrt(dx*dx + dy*dy) || 1;
629
+ let force = REPULSION / (dist * dist);
630
+ let fx = (dx / dist) * force;
631
+ let fy = (dy / dist) * force;
632
+ nodes[i].vx += fx; nodes[i].vy += fy;
633
+ nodes[j].vx -= fx; nodes[j].vy -= fy;
634
+ }
635
+ }
636
+ // Attraction along edges
637
+ for (const e of graphEdges) {
638
+ let dx = e.target.x - e.source.x;
639
+ let dy = e.target.y - e.source.y;
640
+ let dist = Math.sqrt(dx*dx + dy*dy) || 1;
641
+ let force = (dist - 100) * ATTRACTION * e.weight;
642
+ let fx = (dx / dist) * force;
643
+ let fy = (dy / dist) * force;
644
+ e.source.vx += fx; e.source.vy += fy;
645
+ e.target.vx -= fx; e.target.vy -= fy;
646
+ }
647
+ // Center gravity
648
+ for (const n of nodes) {
649
+ n.vx += (W/2 - n.x) * CENTER_GRAVITY;
650
+ n.vy += (H/2 - n.y) * CENTER_GRAVITY;
651
+ }
652
+ // Apply & damp
653
+ for (const n of nodes) {
654
+ if (n === dragging) continue;
655
+ n.vx *= DAMPING; n.vy *= DAMPING;
656
+ n.x += n.vx; n.y += n.vy;
657
+ n.x = Math.max(20, Math.min(W - 20, n.x));
658
+ n.y = Math.max(20, Math.min(H - 20, n.y));
659
+ }
660
+ }
661
+
662
+ function getNodeRadius(n) { return Math.min(16, 5 + n.connections * 1.5); }
663
+
664
+ function draw() {
665
+ ctx.clearRect(0, 0, W, H);
666
+ // Edges
667
+ for (const e of graphEdges) {
668
+ const alpha = 0.15 + e.weight * 0.5;
669
+ ctx.strokeStyle = 'rgba(91,156,255,' + Math.min(0.8, alpha) + ')';
670
+ ctx.lineWidth = 0.5 + e.weight * 2;
671
+ ctx.beginPath();
672
+ ctx.moveTo(e.source.x, e.source.y);
673
+ ctx.lineTo(e.target.x, e.target.y);
674
+ ctx.stroke();
675
+ }
676
+ // Nodes
677
+ for (const n of nodes) {
678
+ const r = getNodeRadius(n);
679
+ const color = NODE_COLORS[n.type] || DEFAULT_COLOR;
680
+ const isHover = n === hovered || n === dragging;
681
+ // Glow
682
+ if (isHover) {
683
+ ctx.shadowColor = color;
684
+ ctx.shadowBlur = 20;
685
+ }
686
+ ctx.fillStyle = color;
687
+ ctx.globalAlpha = isHover ? 1 : 0.8;
688
+ ctx.beginPath();
689
+ ctx.arc(n.x, n.y, r, 0, Math.PI * 2);
690
+ ctx.fill();
691
+ ctx.globalAlpha = 1;
692
+ ctx.shadowBlur = 0;
693
+ // Label for hovered or large nodes
694
+ if (isHover || n.connections >= 4) {
695
+ ctx.fillStyle = '#e8eaf6';
696
+ ctx.font = (isHover ? 'bold ' : '') + '11px Inter, system-ui, sans-serif';
697
+ ctx.textAlign = 'center';
698
+ ctx.fillText(n.id, n.x, n.y - r - 6);
699
+ }
700
+ }
701
+ simulate();
702
+ requestAnimationFrame(draw);
703
+ }
704
+ draw();
705
+
706
+ // Interaction
707
+ const tooltip = document.getElementById('graph-tooltip');
708
+ function getNodeAt(mx, my) {
709
+ for (let i = nodes.length - 1; i >= 0; i--) {
710
+ const n = nodes[i], r = getNodeRadius(n);
711
+ if (Math.hypot(mx - n.x, my - n.y) <= r + 4) return n;
712
+ }
713
+ return null;
714
+ }
715
+ function getPos(e) {
716
+ const rect = canvas.getBoundingClientRect();
717
+ return { x: e.clientX - rect.left, y: e.clientY - rect.top };
718
+ }
719
+ canvas.addEventListener('mousemove', function(e) {
720
+ const p = getPos(e);
721
+ if (dragging) {
722
+ dragging.x = p.x + dragOff.x;
723
+ dragging.y = p.y + dragOff.y;
724
+ dragging.vx = 0; dragging.vy = 0;
725
+ return;
726
+ }
727
+ const n = getNodeAt(p.x, p.y);
728
+ hovered = n;
729
+ canvas.style.cursor = n ? 'pointer' : 'grab';
730
+ if (n) {
731
+ const conns = graphEdges.filter(e => e.source === n || e.target === n);
732
+ tooltip.innerHTML = '<strong>' + n.id + '</strong><br>' + conns.length + ' connections';
733
+ tooltip.style.display = 'block';
734
+ tooltip.style.left = (p.x + 15) + 'px';
735
+ tooltip.style.top = (p.y - 10) + 'px';
736
+ } else {
737
+ tooltip.style.display = 'none';
738
+ }
739
+ });
740
+ canvas.addEventListener('mousedown', function(e) {
741
+ const p = getPos(e);
742
+ const n = getNodeAt(p.x, p.y);
743
+ if (n) {
744
+ dragging = n;
745
+ dragOff = { x: n.x - p.x, y: n.y - p.y };
746
+ canvas.style.cursor = 'grabbing';
747
+ }
748
+ });
749
+ canvas.addEventListener('mouseup', function() { dragging = null; });
750
+ canvas.addEventListener('mouseleave', function() { dragging = null; hovered = null; tooltip.style.display = 'none'; });
751
+ })();
752
+ </script>
753
+ </body>
754
+ </html>`;
755
+ }