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