-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathdashboard_v2.html
More file actions
580 lines (536 loc) · 23.7 KB
/
dashboard_v2.html
File metadata and controls
580 lines (536 loc) · 23.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NeuronFS V2: Autopilot Nerve Center</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.26.0/cytoscape.min.js"></script>
<script src="https://unpkg.com/layout-base/layout-base.js"></script>
<script src="https://unpkg.com/cose-base/cose-base.js"></script>
<script src="https://unpkg.com/cytoscape-fcose/cytoscape-fcose.js"></script>
<style>
:root{
--bg: #030305; --surface: rgba(15, 20, 30, 0.6); --border: rgba(255,255,255,0.08);
--accent: #10b981; --accent-glow: rgba(16, 185, 129, 0.3);
--danger: #ef4444; --text: #f8fafc; --text-muted: #94a3b8;
--font-ui: 'Inter', sans-serif; --font-mono: 'JetBrains Mono', monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font-ui); overflow: hidden; display: flex; height: 100vh; }
#gl-container { flex: 1; position: relative; border-right: 1px solid var(--border); background: #030305; }
#cy { display: block; width: 100%; height: 100%; filter: drop-shadow(0 0 6px rgba(16, 185, 129, 0.15)); }
/* Tooltip */
#node-tip { position: absolute; display: none; background: rgba(0,0,0,0.92); border: 1px solid rgba(16,185,129,0.5); backdrop-filter: blur(12px); padding: 10px 14px; border-radius: 8px; font-family: var(--font-mono); font-size: 11px; color: #f8fafc; pointer-events: none; z-index: 50; max-width: 300px; line-height: 1.5; box-shadow: 0 4px 20px rgba(0,0,0,0.5); }
#node-tip b { color: #10b981; font-size: 12px; }
#node-tip .tip-path { color: #94a3b8; font-size: 10px; }
#node-tip .tip-meta { color: #60a5fa; font-size: 10px; }
/* Right Console */
#console-container { width: 450px; background: var(--surface); display: flex; flex-direction: column; backdrop-filter: blur(28px); -webkit-backdrop-filter: blur(28px); position: relative; z-index: 10; }
.header { padding: 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.brand h1 { font-size: 18px; font-weight: 800; letter-spacing: 0.1em; color: #fff; text-shadow: 0 0 10px rgba(255,255,255,0.2); }
.brand span { color: var(--accent); }
.ver { font-size: 10px; color: var(--text-muted); font-family: var(--font-mono); }
.ap-status { padding: 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.status-indicator { display: flex; align-items: center; gap: 10px; }
.pulse-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 15px var(--accent); }
.pulse-dot.pulsing { animation: pulse 2s infinite; }
.pulse-dot.off { background: var(--text-muted); box-shadow: none; animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 var(--accent-glow); } 70% { box-shadow: 0 0 0 10px rgba(16,185,129,0); } 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); } }
.toggle-btn { background: rgba(16, 185, 129, 0.1); border: 1px solid var(--accent); color: var(--accent); padding: 8px 16px; border-radius: 4px; font-size: 11px; font-weight: 800; cursor: pointer; transition: all 0.2s; font-family: var(--font-mono); }
.toggle-btn:hover { background: rgba(16, 185, 129, 0.2); box-shadow: 0 0 15px var(--accent-glow); }
.toggle-btn.off { background: rgba(148, 163, 184, 0.1); border-color: var(--text-muted); color: var(--text-muted); }
.tty-feed { flex: 1; padding: 20px; font-family: var(--font-mono); font-size: 11px; overflow-y: auto; color: #a1a1aa; line-height: 1.6; }
.tty-feed::-webkit-scrollbar { width: 4px; }
.tty-feed::-webkit-scrollbar-thumb { background: var(--border); }
.log-line { margin-bottom: 6px; display: flex; gap: 8px; }
.log-ts { color: #52525b; flex-shrink: 0; }
.log-info { color: #60a5fa; }
.log-warn { color: #fbbf24; }
.log-error { color: #ef4444; }
.metrics-panel { padding: 20px; border-top: 1px solid var(--border); display: grid; grid-template-columns: 1fr 1fr; gap: 15px; background: rgba(0,0,0,0.3); }
.metric { display: flex; flex-direction: column; gap: 4px; }
.m-label { font-size: 9px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-muted); }
.m-value { font-size: 16px; font-weight: 800; color: #fff; font-family: var(--font-mono); }
.audit-panel { padding: 12px 20px; border-top: 1px solid var(--border); max-height: 160px; overflow-y: auto; background: rgba(0,0,0,0.4); }
.audit-panel::-webkit-scrollbar { width: 3px; }
.audit-panel::-webkit-scrollbar-thumb { background: var(--border); }
.audit-title { font-size: 9px; text-transform: uppercase; letter-spacing: 0.15em; color: var(--accent); margin-bottom: 8px; font-family: var(--font-mono); }
.audit-entry { font-size: 10px; font-family: var(--font-mono); color: #71717a; margin-bottom: 4px; display: flex; gap: 6px; }
.audit-actor { color: #60a5fa; min-width: 90px; }
.audit-action { color: #a78bfa; }
.audit-ok { color: var(--accent); }
.audit-fail { color: var(--danger); }
.codemap-panel { padding: 12px 20px; border-top: 1px solid var(--border); max-height: 180px; overflow-y: auto; background: rgba(0,0,0,0.35); }
.codemap-panel::-webkit-scrollbar { width: 3px; }
.codemap-panel::-webkit-scrollbar-thumb { background: var(--border); }
.codemap-title { font-size: 9px; text-transform: uppercase; letter-spacing: 0.15em; color: #8b5cf6; margin-bottom: 8px; font-family: var(--font-mono); cursor: pointer; }
.codemap-entry { font-size: 10px; font-family: var(--font-mono); color: #71717a; margin-bottom: 3px; display: flex; justify-content: space-between; }
.codemap-name { color: #a78bfa; }
.codemap-lines { color: #52525b; }
.fire-text { position: absolute; transform: translate(-50%, -50%); color: #10b981; font-family: var(--font-mono); font-size: 24px; font-weight: 800; text-shadow: 0 0 20px rgba(16,185,129,0.8); opacity: 0; pointer-events: none; z-index: 30; }
@keyframes floatUp { 0% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -150%) scale(1.5); } }
</style>
</head>
<body>
<div id="gl-container">
<div id="cy"></div>
<div id="node-tip"></div>
<div id="spark-overlay" style="position:absolute; top:0; left:0; width:100%; height:100%; pointer-events:none; z-index:40;"></div>
</div>
<div id="console-container">
<div class="header">
<div class="brand"><h1><span>Neuron</span>FS V2</h1><span class="ver">Autopilot Nerve Center</span></div>
<div style="display:flex;gap:4px;flex-wrap:wrap">
<button class="toggle-btn" style="font-size:9px;padding:5px 8px;border-color:#8b5cf6;color:#8b5cf6;background:rgba(139,92,246,0.1)" onclick="runIntegrity()">VERIFY</button>
<button class="toggle-btn" style="font-size:9px;padding:5px 8px;border-color:#f59e0b;color:#f59e0b;background:rgba(245,158,11,0.1)" onclick="runInject()">INJECT</button>
<button class="toggle-btn" style="font-size:9px;padding:5px 8px;border-color:#10b981;color:#10b981;background:rgba(16,185,129,0.1)" onclick="runEvolve(true)">EVOLVE</button>
<button class="toggle-btn" style="font-size:9px;padding:5px 8px;border-color:#ef4444;color:#ef4444;background:rgba(239,68,68,0.1)" onclick="runDedup()">DEDUP</button>
<button class="toggle-btn" id="btn-autopilot" onclick="toggleAutopilot()">AUTOPILOT: ON</button>
</div>
</div>
<div class="ap-status">
<div class="status-indicator">
<div class="pulse-dot pulsing" id="ap-dot"></div>
<div style="font-size:12px; font-weight:600; color:#fff" id="ap-text">System Listening...</div>
</div>
</div>
<div class="tty-feed" id="tty"></div>
<div class="metrics-panel">
<div class="metric"><span class="m-label">Active Neurons</span><span class="m-value" id="m-neurons">---</span></div>
<div class="metric"><span class="m-label">Total Activation</span><span class="m-value" id="m-act">---</span></div>
<div class="metric"><span class="m-label">Sys Load (CPU)</span><span class="m-value" id="m-cpu" style="color:#f59e0b">--%</span></div>
<div class="metric"><span class="m-label">Mem Alloc (RAM)</span><span class="m-value" id="m-ram" style="color:#10b981">--%</span></div>
</div>
<div class="audit-panel" id="audit-feed"><div class="audit-title">AUDIT TRAIL</div></div>
<div class="codemap-panel" id="codemap-feed"><div class="codemap-title">CODE MAP</div></div>
</div>
<script>
// ═══ CONSTANTS ═══
const COLORS = {
brainstem:'#e11d48', limbic:'#f97316', hippocampus:'#eab308', sensors:'#10b981',
cortex:'#3b82f6', ego:'#8b5cf6', prefrontal:'#f8fafc', shared:'#64748b'
};
const ICONS = { brainstem:'🛡️', limbic:'💓', hippocampus:'📝', sensors:'👁️', cortex:'🧠', ego:'🎭', prefrontal:'🎯', shared:'🔗' };
// ═══ CYTOSCAPE STATE ═══
let cy = null;
const tip = document.getElementById('node-tip');
// ═══ INITIALIZATION & RENDER ═══
function initCytoscape(data) {
let elements = [];
// Define hierarchical rings for macro-layout structure (Subsumption Cascade)
const RINGS = {
'brainstem': { r: 0, a: 0 },
'limbic': { r: 350, a: 0 },
'hippocampus': { r: 350, a: 2.0944 }, // 120 deg
'sensors': { r: 350, a: 4.1888 }, // 240 deg
'cortex': { r: 850, a: 1.0472 }, // 60 deg
'ego': { r: 850, a: 3.1416 }, // 180 deg
'prefrontal': { r: 850, a: 5.2360 }, // 300 deg
'shared': { r: 1300, a: 0 }
};
let fixedNodes = [];
// Pre-compute all axon edges for bidirectional detection
let allAxons = new Set();
(data.regions || []).forEach(rr => {
(rr.axons || []).forEach(t => allAxons.add('hub_' + rr.name + '-hub_' + t));
});
(data.regions || []).forEach(r => {
let hubId = 'hub_' + r.name;
// Calculate and lock absolute positions for hierarchical Centers (Hubs)
if (RINGS[r.name]) {
let x = Math.round(Math.cos(RINGS[r.name].a) * RINGS[r.name].r);
let y = Math.round(Math.sin(RINGS[r.name].a) * RINGS[r.name].r);
fixedNodes.push({ nodeId: hubId, position: {x: x, y: y} });
}
// Base hub element
elements.push({
data: {
id: hubId, label: r.name.toUpperCase(), color: COLORS[r.name]||'#fff',
isHub: true, region: r.name, counter: 0
},
classes: 'hub'
});
let subMap = {};
(r.neurons || []).forEach(n => {
const parts = n.path.split('/');
const dir = parts.length > 1 ? parts.slice(0, -1).join('/') : '';
let parentId = hubId;
if (dir) {
const subId = r.name + '_' + dir;
const dirName = dir.split('/').pop();
if (!subMap[dir]) {
subMap[dir] = true;
elements.push({
data: {
id: subId, label: dirName, color: COLORS[r.name]||'#fff',
isSubHub: true, region: r.name
},
classes: 'subhub'
});
elements.push({ data: { id: 'edge_'+hubId+'_'+subId, source: hubId, target: subId, color: COLORS[r.name]||'#fff' }, classes: 'internal-edge' });
}
parentId = subId;
}
elements.push({
data: {
id: n.path, label: parts[parts.length-1], color: COLORS[r.name]||'#fff',
isNeuron: true, region: r.name, path: n.path, counter: n.counter, dopamine: n.dopamine, hasBomb: n.hasBomb
},
classes: 'neuron'
});
elements.push({ data: { id: 'edge_'+parentId+'_'+n.path, source: parentId, target: n.path, color: COLORS[r.name]||'#fff' }, classes: 'internal-edge' });
});
// Add existing Axon links with one-way/two-way detection
(r.axons || []).forEach(t => {
const tgt = 'hub_' + t;
const outEdge = hubId + '-' + tgt;
const inEdge = tgt + '-' + hubId;
const isTwoWay = allAxons.has(inEdge);
elements.push({
data: { id: outEdge, source: hubId, target: tgt },
classes: isTwoWay ? 'axon twoway' : 'axon oneway'
});
});
});
if (cy) {
cy.batch(() => {
const newIds = new Set(elements.map(e => e.data.id));
// 1. Remove deleted nodes
cy.elements().forEach(el => {
if (!newIds.has(el.id())) cy.remove(el);
});
// 2. Add new or Update existing
let needsLayout = false;
elements.forEach(el => {
const existing = cy.getElementById(el.data.id);
if (existing.length > 0) {
existing.data(el.data);
} else {
cy.add(el);
needsLayout = true;
}
});
// 3. Only run layout if structural changes occurred
if (needsLayout) {
cy.layout({ name: 'fcose', quality: 'draft', randomize: false, animate: false, fixedNodeConstraint: fixedNodes, nodeRepulsion: 4500, idealEdgeLength: 40, gravity: 0.35, edgeElasticity: 0.35, numIter: 1000 }).run();
}
});
return; // Skip full re-initialization
}
cy = cytoscape({
container: document.getElementById('cy'),
elements: elements,
textureOnViewport: true,
hideEdgesOnViewport: true,
pixelRatio: 1,
style: [
{
selector: 'node',
style: {
'background-color': 'data(color)',
'label': 'data(label)',
'color': '#fff',
'font-size': '10px',
'text-outline-width': 2,
'text-outline-color': '#030305',
'text-valign': 'center',
'text-halign': 'center',
'overlay-opacity': 0
}
},
{
selector: '.hub',
style: {
'shape': 'ellipse',
'width': 65,
'height': 65,
'background-opacity': 0.25,
'border-width': 3,
'border-color': 'data(color)',
'border-opacity': 0.9,
'border-style': 'solid',
'text-valign': 'top',
'font-size': '13px',
'font-weight': 'bold',
'text-margin-y': -8,
'ghost': 'yes',
'ghost-offset-x': 0,
'ghost-offset-y': 0,
'ghost-opacity': 0.35
}
},
{
selector: '.subhub',
style: {
'shape': 'ellipse',
'width': 22,
'height': 22,
'background-opacity': 0.35,
'border-width': 2,
'border-color': 'data(color)',
'border-opacity': 0.7,
'border-style': 'solid',
'text-valign': 'top',
'font-size': '8px',
'text-margin-y': -5
}
},
{
selector: '.neuron',
style: {
'width': 8,
'height': 8,
'label': '',
'background-opacity': 0.85
}
},
{
selector: '.axon.oneway',
style: {
'width': 2,
'line-color': 'rgba(255, 255, 255, 0.5)',
'curve-style': 'bezier',
'target-arrow-shape': 'triangle',
'target-arrow-color': 'rgba(255, 255, 255, 0.7)',
'arrow-scale': 1.2
}
},
{
selector: '.axon.twoway',
style: {
'width': 3,
'line-color': 'rgba(245, 158, 11, 0.8)',
'curve-style': 'bezier',
'control-point-step-size': 50,
'target-arrow-shape': 'triangle',
'target-arrow-color': 'rgba(245, 158, 11, 0.8)',
'arrow-scale': 1.2
}
},
{
selector: '.internal-edge',
style: {
'width': 0.8,
'line-color': 'data(color)',
'opacity': 0.25,
'curve-style': 'straight'
}
}
],
layout: {
name: 'fcose',
quality: 'default',
randomize: true,
animate: false,
fixedNodeConstraint: fixedNodes,
nodeRepulsion: 4500,
idealEdgeLength: 40,
gravity: 0.35,
edgeElasticity: 0.35,
numIter: 2500
}
});
// Tooltip & Interactions
cy.on('mouseover', 'node', function(e){
e.target.style({ 'border-width': 4, 'border-color': '#fff', 'background-opacity': 0.8 });
const n = e.target.data();
if (n.isNeuron) {
tip.style.display = 'block';
let icon = ICONS[n.region] || '';
tip.innerHTML = `<b>${n.label}</b><br/><span class="tip-path">${n.path}</span><br/><span class="tip-meta">${icon} ${n.region} | counter: ${n.counter}${n.dopamine ? ' | 🎉'+n.dopamine : ''}${n.hasBomb ? ' | 💣BOMB' : ''}</span>`;
tip.style.left = (e.originalEvent.offsetX + 15) + 'px';
tip.style.top = (e.originalEvent.offsetY + 15) + 'px';
}
});
cy.on('mousemove', function(e){
if (tip.style.display === 'block') {
tip.style.left = (e.originalEvent.offsetX + 15) + 'px';
tip.style.top = (e.originalEvent.offsetY + 15) + 'px';
}
});
cy.on('mouseout', 'node', function(e){
e.target.removeStyle();
tip.style.display = 'none';
});
cy.on('grab', 'node', function(e){
e.target.style({ 'border-width': 5, 'border-color': '#fff', 'background-opacity': 1.0 });
});
cy.on('free', 'node', function(e){
e.target.removeStyle(); // glow reverts to default when released
});
// Start Global Axon Animation for Flow
// Animation removed in favor of static structural clarity
// Right-Click Context Menu (Grow / Fire)
cy.on('cxttap', 'node', async function(e){
const n = e.target.data();
logTTY(`📍 ${ICONS[n.region]||''} ${n.region}/${n.label} Action Triggered`, 'info');
// Position for sparks mapping cytoscape rendering coordinates
const pos = e.target.renderedPosition();
if (e.originalEvent.shiftKey && (n.isHub || n.isSubHub)) {
const name = prompt('New neuron name (under ' + n.region + '):');
if (name) {
await fetch(API_BASE + '/api/grow', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({path: n.region + '/' + name}) });
logTTY('🌱 GROWN: ' + n.region + '/' + name, 'info');
triggerSparkEffect(name, pos.x, pos.y);
fetchBrainData();
}
} else if (n.isNeuron) {
await fetch(API_BASE + '/api/fire', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({path: n.path}) });
logTTY('🔥 FIRED: ' + n.path, 'info');
triggerSparkEffect(n.path, pos.x, pos.y);
}
});
}
function triggerSparkEffect(text, x, y) {
const overlay = document.getElementById('spark-overlay');
const el = document.createElement('div');
el.className = 'fire-text';
el.innerText = '🔥 ' + text.split('/').pop();
el.style.left = x + 'px';
el.style.top = y + 'px';
el.style.animation = 'floatUp 1s ease-out forwards';
overlay.appendChild(el);
setTimeout(() => el.remove(), 1000);
}
// ═══ API COMM & TELEMETRY ═══
const API_BASE = (location.protocol === 'file:') ? 'http://127.0.0.1:9090' : '';
async function fetchBrainData() {
try {
const res = await fetch(API_BASE + '/api/brain');
if (!res.ok) throw new Error('API Error: ' + res.status);
const json = await res.json();
const el = document.getElementById('m-neurons');
if (el) el.innerText = (json.totalNeurons || 0).toLocaleString();
const el2 = document.getElementById('m-act');
if (el2) el2.innerText = (json.totalCounter || 0).toLocaleString();
initCytoscape(json);
logTTY(`📊 Brain topology rendered via Cytoscape`, 'info');
} catch(e) {
console.error('fetchBrainData error:', e);
logTTY('⚠️ Brain API offline: ' + e.message, 'warn');
}
}
let isAutopilotOn = true;
let isEvolving = false;
function toggleAutopilot() {
isAutopilotOn = !isAutopilotOn;
const btn = document.getElementById('btn-autopilot');
const dot = document.getElementById('ap-dot');
const txt = document.getElementById('ap-text');
if (isAutopilotOn) {
btn.innerText = 'AUTOPILOT: ON'; btn.className = 'toggle-btn';
dot.className = 'pulse-dot pulsing'; txt.innerText = 'System Listening...';
} else {
btn.innerText = 'AUTOPILOT: OFF'; btn.className = 'toggle-btn off';
dot.className = 'pulse-dot off'; txt.innerText = 'System Halted.';
}
}
function logTTY(msg, type='info') {
const tty = document.getElementById('tty');
const d = new Date();
const time = String(d.getHours()).padStart(2,'0')+':'+String(d.getMinutes()).padStart(2,'0')+':'+String(d.getSeconds()).padStart(2,'0');
const html = `<div class="log-line"><span class="log-ts">[${time}]</span><span class="log-${type}">${msg}</span></div>`;
tty.innerHTML += html;
if(tty.childElementCount > 100) tty.removeChild(tty.firstChild);
tty.scrollTop = tty.scrollHeight;
}
function appendAudit(actor, action, ok) {
const feed = document.getElementById('audit-feed');
const cls = ok ? 'audit-ok' : 'audit-fail';
const html = `<div class="audit-entry"><span class="audit-actor">${actor}</span><span class="audit-action">${action}</span><span class="${cls}">${ok?'[COMPLETE]':'[HALTED]'}</span></div>`;
// append after title
feed.insertAdjacentHTML('beforeend', html);
feed.scrollTop = feed.scrollHeight;
}
// Map CodeMap (Simulated)
function renderCodemap() {
const cm = document.getElementById('codemap-feed');
const items = [
{n:'cortex/main.go', l:234},
{n:'hippocampus/mem.go', l:89},
];
items.forEach(i => {
cm.insertAdjacentHTML('beforeend', `<div class="codemap-entry"><span class="codemap-name">${i.n}</span><span class="codemap-lines">${i.l} lines</span></div>`);
});
}
// Handlers for mocked action buttons
async function runIntegrity() {
logTTY('Initiating brain integrity check...', 'warn');
const res = await fetch(API_BASE + '/api/health');
if (res.ok) {
const data = await res.json();
logTTY('Integrity OK: ' + JSON.stringify(data), 'info');
appendAudit('SYS_HEALTH', 'Verification', true);
} else {
appendAudit('SYS_HEALTH', 'Verification', false);
}
}
async function runInject() {
logTTY('Injecting external sensory stimulus...', 'warn');
appendAudit('SENSOR_API', 'Stimulus Inj', true);
}
async function runEvolve(dryRun) {
if(isEvolving) return;
isEvolving = true;
logTTY('Triggering Groq self-evolution cycle...', 'warn');
const res = await fetch(API_BASE + '/api/evolve', {
method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({dry_run: dryRun})
});
if(res.ok) {
const data = await res.json();
logTTY('Evolution cycle complete. Changes applied.', 'info');
appendAudit('LLM_EVOLVE', 'Self-Update', true);
} else {
logTTY('Evolution cycle failed.', 'error');
appendAudit('LLM_EVOLVE', 'Self-Update', false);
}
isEvolving = false;
}
async function runDedup() {
logTTY('Running deduplication analysis...', 'warn');
const res = await fetch(API_BASE + '/api/health?auto_fix=true');
if(res.ok) appendAudit('SYS_DEDUP', 'Merge Nodes', true);
logTTY('Deduplication finished.', 'info');
}
// ═══ INIT ═══
window.onload = function() {
fetchBrainData();
renderCodemap();
// Real-time Dashboard Sync
setInterval(() => {
const t = performance.now() * 0.001;
const cpu = 20 + Math.sin(t*0.3)*10 + Math.random()*2;
const ram = 35 + Math.sin(t*0.15)*8 + Math.random();
const ec = document.getElementById('m-cpu'), er = document.getElementById('m-ram');
if(ec){ec.innerText=cpu.toFixed(1)+'%';ec.style.color=cpu>60?'#ef4444':cpu>40?'#f59e0b':'#3b82f6';}
if(er){er.innerText=ram.toFixed(1)+'%';er.style.color=ram>70?'#ef4444':'#10b981';}
}, 1000);
// Status check every 15s without disturbing layout aggressively
setInterval(() => {
if(isAutopilotOn) fetchBrainData();
}, 15000);
};
// Listen to SSE
if(window.EventSource) {
const evtSource = new EventSource('/api/stream');
evtSource.onmessage = function(e) {
try {
const msg = JSON.parse(e.data);
if (msg.event === 'fired' || msg.event === 'grown') {
const parts = msg.path.split('/');
const name = parts[parts.length-1];
if(cy) {
const target = cy.getElementById(msg.path);
if(target.length > 0) {
const pos = target.renderedPosition();
triggerSparkEffect(name, pos.x, pos.y);
}
}
}
} catch(err){}
};
}
</script>
</body>
</html>