-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.js
More file actions
2758 lines (2650 loc) · 136 KB
/
Copy pathplugin.js
File metadata and controls
2758 lines (2650 loc) · 136 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
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Hermes Command Center — desktop plugin.
*
* Read-only health + activity dashboard for your Hermes instance. Six tabs:
* - Overview : processes, today's tokens, cron health, errors, memory fill
* - Cron : job definitions + recent executions
* - Plugins : installed backend + desktop plugins
* - Models : per-model token/cost breakdown + 15-day trend
* - Skills : skill usage stats
* - Memory : always-on memory + fact store health
*
* Backed by the command-center dashboard plugin API (mounted at
* /api/plugins/command-center/). Plain ESM loaded uncompiled: UI is jsx()
* calls, NOT JSX syntax; only @hermes/plugin-sdk, react, react/jsx-runtime
* resolve. Read-only — never writes state.
*/
import {
Badge,
Button,
cn,
Codicon,
EmptyState,
ErrorState,
haptic,
host,
relativeTime,
ROUTES_AREA,
SIDEBAR_NAV_AREA,
PALETTE_AREA,
Skeleton,
useQuery
} from '@hermes/plugin-sdk'
import { jsx, jsxs } from 'react/jsx-runtime'
import { useEffect, useState } from 'react'
const ID = 'command-center'
const TABS = ['overview', 'activity', 'usage', 'tools', 'cron', 'plugins', 'models', 'skills', 'memory', 'system']
// Fixed accent palette (deliberately NOT theme accent so each section stays
// distinguishable, same approach as the achievements sections).
const ACCENTS = {
green: { key: 'green', text: '#2f9e63', bg: 'rgba(47,158,99,0.12)' },
blue: { key: 'blue', text: '#2f7fd4', bg: 'rgba(47,127,212,0.12)' },
teal: { key: 'teal', text: '#0f9a9a', bg: 'rgba(15,154,154,0.12)' },
gold: { key: 'gold', text: '#b7791f', bg: 'rgba(183,121,31,0.12)' },
purple: { key: 'purple', text: '#7b5fd9', bg: 'rgba(123,95,217,0.12)' },
rose: { key: 'rose', text: '#d4578f', bg: 'rgba(212,87,143,0.12)' },
red: { key: 'red', text: '#d64545', bg: 'rgba(214,69,69,0.12)' },
idle: { key: 'idle', text: '#8a8f98', bg: 'rgba(138,143,152,0.12)' }
}
const TAB_META = {
overview: { icon: 'dashboard', accent: ACCENTS.blue },
activity: { icon: 'history', accent: ACCENTS.rose },
usage: { icon: 'graph-line', accent: ACCENTS.gold },
tools: { icon: 'tools', accent: ACCENTS.teal },
cron: { icon: 'clock', accent: ACCENTS.teal },
plugins: { icon: 'plug', accent: ACCENTS.purple },
models: { icon: 'graph', accent: ACCENTS.gold },
skills: { icon: 'book', accent: ACCENTS.green },
memory: { icon: 'database', accent: ACCENTS.rose },
system: { icon: 'server', accent: ACCENTS.blue }
}
// ── helpers ────────────────────────────────────────────────────────────────
function fmtNum(n) {
if (n == null) return '0'
if (n >= 1e9) return (n / 1e9).toFixed(2) + 'B'
if (n >= 1e6) return (n / 1e6).toFixed(2) + 'M'
if (n >= 1e3) return (n / 1e3).toFixed(1) + 'k'
return String(Math.round(n))
}
function fmtDate(ts) {
if (!ts) return '—'
const d = new Date(ts * 1000)
return d.toLocaleDateString(undefined, { month: 'short', day: 'numeric' })
}
function fmtTime(ms) {
if (!ms) return '—'
const d = new Date(ms > 1e11 ? ms : ms * 1000)
return d.toLocaleString(undefined, { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' })
}
// ── injected polish CSS (fade-up, shimmer, glow) ──────────────────────────
const POLISH_CSS = `
.hc-fade-up { animation: hcFadeUp .45s cubic-bezier(.22,.9,.35,1) both; }
@keyframes hcFadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.hc-shimmer { position: relative; overflow: hidden; }
.hc-shimmer::after { content: ''; position: absolute; inset: 0; transform: translateX(-100%);
background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent); animation: hcShimmer 1.6s infinite; }
@keyframes hcShimmer { 100% { transform: translateX(100%); } }
.hc-glow { transition: box-shadow .25s ease; }
.hc-glow:hover { box-shadow: 0 0 0 1px rgba(123,95,217,.15), 0 12px 40px -8px rgba(123,95,217,.25); }
.hc-ring-track { stroke: var(--hc-track, rgba(127,127,127,.14)); }
.hc-ring-value { transition: stroke-dashoffset 1s cubic-bezier(.22,.9,.35,1); }
.hc-bar-gradient { transition: height 1s cubic-bezier(.22,.9,.35,1); }
`
// Injected once per mount; idempotent.
function usePolishCss() {
useEffect(() => {
let el = document.getElementById('hermes-center-polish')
if (!el) {
el = document.createElement('style')
el.id = 'hermes-center-polish'
el.textContent = POLISH_CSS
document.head.appendChild(el)
}
return () => {
// Leave the style in place across tab switches; remove on unmount is
// fine to skip — the page component lives for the whole session.
}
}, [])
}
// ── health ring ────────────────────────────────────────────────────────────
// Circular ring with a gradient stroke and a centered value.
function RingGauge({ value, max, label, sub, from, to, size }) {
const s = size || 64
const stroke = 6
const r = (s - stroke) / 2
const c = 2 * Math.PI * r
const pct = Math.min(100, Math.round((value / max) * 100))
const off = c * (1 - pct / 100)
const gid = 'hc-ring-' + Math.abs(hashCode(label))
return jsxs('div', {
className: 'relative inline-flex items-center justify-center',
style: { width: s, height: s },
children: [
jsxs('svg', {
width: s,
height: s,
className: '-rotate-90',
children: [
jsx('defs', {
children: jsx('linearGradient', {
id: gid,
x1: '0%',
y1: '0%',
x2: '100%',
y2: '100%',
children: [
jsx('stop', { offset: '0%', stopColor: from }),
jsx('stop', { offset: '100%', stopColor: to })
]
})
}),
jsx('circle', { cx: s / 2, cy: s / 2, r, fill: 'none', strokeWidth: stroke, className: 'hc-ring-track' }),
jsx('circle', {
cx: s / 2,
cy: s / 2,
r,
fill: 'none',
strokeWidth: stroke,
strokeLinecap: 'round',
stroke: `url(#${gid})`,
strokeDasharray: c,
strokeDashoffset: off,
className: 'hc-ring-value'
})
]
}),
jsxs('div', {
className: 'absolute inset-0 flex flex-col items-center justify-center',
children: [
jsx('span', { className: 'text-sm font-bold tabular-nums text-(--ui-text-primary)', children: `${pct}%` }),
label ? jsx('span', { className: 'text-[0.625rem] font-medium uppercase tracking-wide text-(--ui-text-secondary)', children: label }) : null
]
})
]
})
}
function hashCode(str) {
let h = 0
for (let i = 0; i < str.length; i++) h = (h * 31 + str.charCodeAt(i)) | 0
return Math.abs(h)
}
// ── area chart (SVG) ───────────────────────────────────────────────────────
// Smooth gradient area chart for the daily token trend.
function AreaChart({ daily, height, from, to }) {
const h = height || 120
const w = 640
const pad = 4
const max = Math.max(...daily.map(d => d.tokens), 1)
const n = daily.length
const step = n > 1 ? (w - pad * 2) / (n - 1) : w / 2
const pts = daily.map((d, i) => ({
x: pad + i * step,
y: h - pad - (d.tokens / max) * (h - pad * 2)
}))
const line = pts.map((p, i) => `${i === 0 ? 'M' : 'L'}${p.x.toFixed(1)},${p.y.toFixed(1)}`).join(' ')
const area = `${line} L${pts[pts.length - 1].x.toFixed(1)},${h} L${pts[0].x.toFixed(1)},${h} Z`
const gid = 'hc-area-' + Math.abs(hashCode(String(daily.length) + from))
const last = pts[pts.length - 1]
return jsxs('svg', {
viewBox: `0 0 ${w} ${h}`,
className: 'w-full',
preserveAspectRatio: 'none',
style: { height },
children: [
jsx('defs', {
children: jsx('linearGradient', {
id: gid,
x1: '0%',
y1: '0%',
x2: '0%',
y2: '100%',
children: [
jsx('stop', { offset: '0%', stopColor: from, stopOpacity: 0.35 }),
jsx('stop', { offset: '100%', stopColor: to, stopOpacity: 0.02 })
]
})
}),
jsx('path', { d: area, fill: `url(#${gid})` }),
jsx('path', { d: line, fill: 'none', stroke: from, strokeWidth: 2, strokeLinecap: 'round' }),
last ? jsx('circle', { cx: last.x, cy: last.y, r: 4, fill: from, className: 'hc-glow' }) : null
]
})
}
// ── shared visual atoms ────────────────────────────────────────────────────
// Icon chip: rounded square with a gradient background + white icon.
// Gradient + white glyph reads clearly at small sizes (the tinted bg +
// colored glyph approach washed out the icon on some accents).
function IconChip({ codicon, accent, size }) {
const s = size || 'h-8 w-8'
const grad = {
green: 'linear-gradient(135deg, #2f9e63 0%, #3ecf8e 100%)',
blue: 'linear-gradient(135deg, #2f7fd4 0%, #5aa7f0 100%)',
teal: 'linear-gradient(135deg, #0f9a9a 0%, #2fc4c4 100%)',
gold: 'linear-gradient(135deg, #b7791f 0%, #e0a63d 100%)',
purple: 'linear-gradient(135deg, #7b5fd9 0%, #a48cf0 100%)',
rose: 'linear-gradient(135deg, #d4578f 0%, #f07ab0 100%)',
red: 'linear-gradient(135deg, #d64545 0%, #f07070 100%)',
idle: 'linear-gradient(135deg, #8a8f98 0%, #b0b5bd 100%)'
}
return jsx('div', {
className: cn('flex shrink-0 items-center justify-center rounded-lg text-white', s),
style: {
background: grad[accent.key] || 'linear-gradient(135deg, #7b5fd9 0%, #a48cf0 100%)',
boxShadow: '0 4px 10px rgba(0,0,0,0.18)'
},
children: jsx(Codicon, { name: codicon, className: 'text-base leading-none' })
})
}
// Status pill with a glowing dot.
function StatusPill({ tone, children }) {
const toneMeta = {
ok: { color: '#2f9e63', bg: 'rgba(47,158,99,0.12)' },
warn: { color: '#b7791f', bg: 'rgba(183,121,31,0.12)' },
err: { color: '#d64545', bg: 'rgba(214,69,69,0.12)' },
idle: { color: '#8a8f98', bg: 'rgba(138,143,152,0.12)' }
}[tone] || { color: '#8a8f98', bg: 'rgba(138,143,152,0.12)' }
return jsxs('span', {
className: 'inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[0.625rem] font-medium',
style: { backgroundColor: toneMeta.bg, color: toneMeta.color },
children: [
jsx('span', {
className: 'h-1.5 w-1.5 rounded-full',
style: {
backgroundColor: toneMeta.color,
boxShadow: `0 0 6px 1px ${toneMeta.color}55`
}
}),
children
]
})
}
// ── health hover card ──────────────────────────────────────────────────────
// Floating card that explains what the health score means. Appears on hover
// of the health ring; uses the opaque elevated surface so text stays readable
// over any background.
function HealthBreakdown({ health, factors }) {
const [open, setOpen] = useState(false)
const totalPenalty = factors.reduce((acc, f) => acc + (f.ok ? 0 : f.penalty), 0)
return jsxs('div', {
className: 'relative',
onMouseEnter: () => setOpen(true),
onMouseLeave: () => setOpen(false),
children: [
jsx('button', {
type: 'button',
className: 'flex items-center gap-1.5 rounded-lg px-2 py-1 text-[0.625rem] font-medium text-(--ui-text-secondary) transition-colors hover:bg-(--ui-bg-quaternary) hover:text-(--ui-text-secondary)',
children: [
jsx(Codicon, { name: 'info', className: 'text-xs' }),
'What is this?'
]
}),
open
? jsxs('div', {
className: 'absolute right-0 top-full z-30 mt-2 w-80 rounded-xl border border-(--ui-stroke-secondary) bg-(--ui-bg-elevated) p-4 shadow-xl',
children: [
jsxs('div', {
className: 'mb-3 flex items-baseline justify-between gap-2',
children: [
jsx('span', { className: 'text-sm font-bold text-(--ui-text-primary)', children: 'Health score' }),
jsx('span', { className: 'text-xs font-semibold tabular-nums text-(--ui-text-secondary)', children: `${health}%` })
]
}),
jsx('p', {
className: 'mb-3 text-[0.6875rem] leading-relaxed text-(--ui-text-secondary)',
children: 'A composite of your instance, starting at 100 and deducting points for issues. Anything above 80 means everything important is working.'
}),
jsxs('div', {
className: 'flex flex-col gap-1.5',
children: factors.map(f =>
jsxs('div', {
key: f.label,
className: 'flex items-start gap-2',
children: [
jsx('span', {
className: cn(
'mt-0.5 flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-full text-[0.5rem] font-bold text-white',
f.ok ? 'bg-(--ui-ok)' : 'bg-(--ui-error)'
),
children: f.ok ? '✓' : '−'
}),
jsxs('div', {
className: 'min-w-0 flex-1',
children: [
jsxs('div', {
className: 'flex items-center justify-between gap-2',
children: [
jsx('span', { className: 'text-[0.6875rem] font-medium text-(--ui-text-primary)', children: f.label }),
f.penalty > 0
? jsx('span', { className: 'text-[0.625rem] font-semibold tabular-nums text-(--ui-error)', children: `−${f.penalty}` })
: jsx('span', { className: 'text-[0.625rem] text-(--ui-text-tertiary)', children: 'ok' })
]
}),
jsx('span', { className: 'text-[0.625rem] leading-snug text-(--ui-text-tertiary)', children: f.desc })
]
})
]
})
)
}),
totalPenalty > 0
? jsx('div', {
className: 'mt-3 border-t border-(--ui-stroke-secondary) pt-2 text-[0.625rem] text-(--ui-text-secondary)',
children: `Total deductions: −${totalPenalty}`
})
: null
]
})
: null
]
})
}
// ── hero header ────────────────────────────────────────────────────────────
function HeroHeader({ processes, onRefresh, health, healthColor, factors }) {
const live = processes && processes.length > 0
return jsxs('div', {
className: 'relative rounded-2xl border border-(--ui-stroke-secondary) p-6',
style: {
background:
'linear-gradient(135deg, rgba(123,95,217,0.14) 0%, rgba(212,87,143,0.10) 45%, rgba(47,127,212,0.10) 100%)'
},
children: [
// soft decorative blobs — clipped by an inner rounded layer so the
// hero keeps its border radius WITHOUT overflow-hidden (which would
// clip the HealthBreakdown dropdown below).
jsx('div', {
className: 'pointer-events-none absolute inset-0 overflow-hidden rounded-2xl',
children: [
jsx('div', {
className: 'absolute -right-8 -top-10 h-40 w-40 rounded-full',
style: { background: 'radial-gradient(circle, rgba(212,87,143,0.18) 0%, transparent 70%)' }
}),
jsx('div', {
className: 'absolute -bottom-12 right-24 h-36 w-36 rounded-full',
style: { background: 'radial-gradient(circle, rgba(47,127,212,0.16) 0%, transparent 70%)' }
})
]
}),
jsxs('div', {
className: 'relative flex items-center gap-4',
children: [
jsx('div', {
className: 'flex h-12 w-12 shrink-0 items-center justify-center rounded-xl text-white',
style: { background: 'linear-gradient(135deg, #7b5fd9 0%, #d4578f 100%)', boxShadow: '0 8px 24px rgba(123,95,217,0.35)' },
children: jsx(Codicon, { name: 'dashboard', className: 'text-2xl' })
}),
jsxs('div', {
className: 'min-w-0 flex-1',
children: [
jsx('div', { className: 'text-lg font-bold tracking-tight text-(--ui-text-primary)', children: 'Hermes Command Center' }),
jsx('div', { className: 'truncate text-xs text-(--ui-text-tertiary)', children: 'Your Hermes instance at a glance, refreshed every 30 seconds.' })
]
}),
health != null && healthColor
? jsxs('div', {
className: 'flex shrink-0 items-center gap-2',
children: [
jsx(RingGauge, {
value: health,
max: 100,
label: 'health',
from: healthColor[0],
to: healthColor[1],
size: 56
}),
jsxs('div', {
className: 'flex flex-col gap-1',
children: [
live
? jsx(StatusPill, { tone: 'ok', children: 'Live' })
: jsx(StatusPill, { tone: 'idle', children: 'Offline' }),
jsx(HealthBreakdown, { health, factors: factors || [] })
]
})
]
})
: null
]
})
]
})
}
// ── stat card ──────────────────────────────────────────────────────────────
function StatCard({ label, value, sub, icon, accent, pulse, index }) {
return jsxs('div', {
className: cn(
'hc-glow group relative flex flex-col gap-2 overflow-hidden rounded-xl border border-(--ui-stroke-secondary) bg-(--ui-bg-chrome) p-4 transition-all hover:-translate-y-0.5 hover:shadow-lg',
'hc-fade-up'
),
style: index != null ? { animationDelay: `${index * 40}ms` } : null,
children: [
jsxs('div', {
className: 'flex items-start justify-between gap-2',
children: [
jsx('span', { className: 'text-[0.625rem] font-medium uppercase tracking-wider text-(--ui-text-secondary)', children: label }),
icon && accent ? jsx(IconChip, { codicon: icon, accent, size: 'h-7 w-7' }) : null
]
}),
jsx('span', {
className: cn('truncate text-xl font-bold tabular-nums', pulse && 'animate-pulse'),
style: { color: accent ? accent.text : undefined },
title: typeof value === 'string' && value.length > 20 ? value : undefined,
children: value
}),
sub ? jsx('span', { className: 'truncate text-[0.625rem] text-(--ui-text-secondary)', children: sub }) : null
]
})
}
// ── section wrapper ────────────────────────────────────────────────────────
function Section({ title, icon, accent, children, extra }) {
return jsxs('div', {
className: 'mb-4 overflow-hidden rounded-xl border border-(--ui-stroke-secondary) bg-(--ui-bg-chrome)',
children: [
jsxs('div', {
className: 'flex items-center gap-2.5 border-b border-(--ui-stroke-secondary) px-4 py-2.5',
children: [
icon && accent ? jsx(IconChip, { codicon: icon, accent, size: 'h-6 w-6' }) : null,
jsx('span', { className: 'text-xs font-semibold text-(--ui-text-primary)', children: title }),
extra ? jsx('span', { className: 'ml-auto text-[0.625rem] font-medium text-(--ui-text-secondary)', children: extra }) : null
]
}),
jsx('div', { className: 'p-4', children })
]
})
}
// ── gateway strip ──────────────────────────────────────────────────────────
// Compact gateway status bar under the hero: phase, pid, heartbeat age.
function GatewayStrip({ gateway }) {
const phase = gateway.phase || 'unknown'
const live = phase === 'running' || phase === 'starting'
const heartbeat = gateway.heartbeat_age != null ? gateway.heartbeat_age : null
const hbFresh = heartbeat != null && heartbeat < 120
const tone = live && hbFresh ? 'ok' : phase === 'starting' ? 'warn' : 'idle'
return jsxs('div', {
className: 'flex items-center gap-3 rounded-xl border border-(--ui-stroke-secondary) bg-(--ui-bg-chrome) px-4 py-2.5',
children: [
jsx(StatusPill, { tone, children: `gateway ${phase}` }),
gateway.pid ? jsx('span', { className: 'font-mono text-[0.625rem] text-(--ui-text-secondary)', children: `pid ${gateway.pid}` }) : null,
heartbeat != null
? jsx('span', { className: 'text-[0.625rem] text-(--ui-text-secondary)', children: heartbeat < 120 ? 'heartbeat: fresh' : `heartbeat: ${Math.round(heartbeat / 60)}m ago` })
: jsx('span', { className: 'text-[0.625rem] text-(--ui-text-secondary)', children: 'no heartbeat file' }),
jsx('span', { className: 'ml-auto text-[0.625rem] text-(--ui-text-secondary)', children: gateway.exited_at ? `last exit ${fmtRelTime(new Date(gateway.exited_at))}` : '' })
]
})
}
// ── error log viewer ───────────────────────────────────────────────────────
// Parse a log line into {ts, time, level, msg}. Log lines look like
// "2026-08-09 18:46:23,651 WARNING tools.registry: ...".
function parseLogLine(ln) {
const m = ln.match(/^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})[,\s](\d+)?\s+([A-Z]+)\s+(.*)$/)
if (m) {
return { ts: m[1], time: m[1].slice(11), level: m[2] ? m[3] : m[3], msg: (m[2] ? m[4] : m[3] + ' ' + m[4]) }
}
// Fallback: no timestamp prefix.
return { ts: '', time: '', level: '', msg: ln }
}
const LOG_LEVEL_STYLE = {
ERROR: { text: '#d64545', bg: 'rgba(214,69,69,0.12)' },
WARNING: { text: '#b7791f', bg: 'rgba(183,121,31,0.12)' },
INFO: { text: '#2f7fd4', bg: 'rgba(47,127,212,0.12)' },
DEBUG: { text: '#8a8f98', bg: 'rgba(138,143,152,0.12)' }
}
// Compact log viewer: each entry is a card in a responsive grid, with a
// level pill + time + truncated message + copy button. Cards fill the
// width in multiple columns like every other tab — no full-width rows.
function ErrorLogViewer({ lines }) {
const parsed = lines.map(parseLogLine)
const errorCount = parsed.filter(l => l.level === 'ERROR').length
const warnCount = parsed.filter(l => l.level === 'WARNING').length
const [copied, setCopied] = useState(null)
const copyLine = (i, full) => {
void navigator.clipboard.writeText(full).then(() => {
setCopied(i)
haptic('tap')
setTimeout(() => setCopied(null), 1500)
})
}
return jsx(Section, {
title: 'Recent errors',
icon: 'error',
accent: ACCENTS.red,
extra: errorCount ? `${errorCount} errors · ${warnCount} warnings` : `${warnCount} warnings`,
children: jsxs('div', {
className: 'grid gap-2',
style: { gridTemplateColumns: 'repeat(auto-fill, minmax(340px, 1fr))' },
children: parsed.map((l, i) => {
const style = LOG_LEVEL_STYLE[l.level] || LOG_LEVEL_STYLE.INFO
const full = `${l.ts} ${l.level} ${l.msg}`.trim()
return jsxs('div', {
key: i,
className: cn(
'hc-fade-up group relative flex items-start gap-2 rounded-xl border border-(--ui-stroke-secondary) bg-(--ui-bg-chrome) p-3 transition-all hover:-translate-y-0.5 hover:shadow-lg'
),
style: { animationDelay: `${i * 25}ms` },
children: [
l.level
? jsx('span', {
className: 'w-16 shrink-0 rounded px-1.5 py-0.5 text-center text-[0.5625rem] font-bold',
style: { backgroundColor: style.bg, color: style.text },
children: l.level
})
: null,
jsxs('div', {
className: 'min-w-0 flex-1',
children: [
jsxs('div', {
className: 'flex items-center justify-between gap-2',
children: [
l.time
? jsx('span', { className: 'font-mono text-[0.625rem] tabular-nums text-(--ui-text-secondary)', title: l.ts, children: l.time })
: null,
jsx('button', {
type: 'button',
className: cn(
'flex shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-[0.5625rem] transition-all',
copied === i
? 'text-(--ui-ok)'
: 'text-(--ui-text-secondary) hover:bg-(--ui-bg-quaternary) hover:text-(--ui-text-primary)'
),
style: copied === i ? { backgroundColor: 'rgba(47,158,99,0.12)' } : undefined,
onClick: () => copyLine(i, full),
title: 'Copy error',
children: copied === i
? 'copied'
: jsx(Codicon, { name: 'copy', className: 'text-[0.6875rem]' })
})
]
}),
jsx('span', {
className: 'mt-0.5 block font-mono text-[0.625rem] leading-snug text-(--ui-text-secondary)',
title: full,
children: l.msg
})
]
})
]
})
})
})
})
}
// ── Overview tab ───────────────────────────────────────────────────────────
function OverviewTab({ data, onRefresh }) {
const t = data.tokens_24h || {}
const c = data.cron_24h || {}
const e = data.errors_24h || {}
const m = data.memory || {}
const cachePct = t.input + t.output > 0 ? Math.round((t.cache_read / (t.input + t.output + t.cache_read)) * 100) : 0
const live = data.processes && data.processes.length > 0
// Composite health score: 100 minus penalties, with a structured breakdown
// for the hover card.
let health = 100
const factors = []
const addFactor = (label, penalty, ok, desc) => {
if (!ok) health -= penalty
factors.push({ label, penalty, ok, desc })
}
addFactor('Backends running', 35, !!live, live ? 'Hermes backends are up.' : 'No backend processes detected — nothing is serving requests.')
addFactor('Errors (24h)', Math.min(15, (e.count_24h || 0) * 5), !e.count_24h, e.count_24h ? `${e.count_24h} real errors in the last 24h (5 points each, capped at 15 — transient stream closes don't tank the score).` : 'No real errors in the last 24h.')
addFactor('Cron failures', 20, !c.failed, c.failed ? `${c.failed} cron job(s) failed recently.` : 'No recent cron failures.')
addFactor('Cache efficiency', cachePct < 50 ? 10 : 0, cachePct >= 50, cachePct < 50 ? `Only ${cachePct}% of token traffic came from cache (want ≥50%).` : `${cachePct}% of token traffic came from cache.`)
// Memory headroom is per-file (MEMORY.md vs 4000, USER.md vs 2500) —
// the combined sum vs a single limit overstates fill.
const memOver = (m.memory_md_limit && m.memory_md_chars / m.memory_md_limit > 0.9) ||
(m.user_md_limit && m.user_md_chars / m.user_md_limit > 0.9)
addFactor('Memory headroom', memOver ? 10 : 0, !memOver, memOver ? 'A memory file is over 90% full — needs consolidation.' : 'Memory files have headroom.')
health = Math.max(0, health)
const healthColor = health >= 80 ? ['#2f9e63', '#0f9a9a'] : health >= 50 ? ['#b7791f', '#d4578f'] : ['#d64545', '#d4578f']
return jsxs('div', {
className: 'flex flex-col gap-4 p-6',
children: [
jsx(HeroHeader, { processes: data.processes, onRefresh, health, healthColor, factors }),
jsx(GatewayStrip, { gateway: data.gateway || {} }),
jsxs('div', {
className: 'grid gap-3',
style: { gridTemplateColumns: 'repeat(auto-fit, minmax(180px, 1fr))' },
children: [
jsx(StatCard, {
label: 'Backends running',
value: data.processes ? data.processes.length : '0',
sub: live && data.processes[0] ? data.processes[0].cmd.slice(0, 40) : 'no active backends',
icon: 'pulse',
accent: live ? ACCENTS.green : ACCENTS.red,
pulse: live,
index: 0
}),
jsx(StatCard, {
label: 'Tokens (24h)',
value: fmtNum(t.input + t.output),
sub: `${fmtNum(t.cache_read)} cache · $${(t.cost || 0).toFixed(2)}`,
icon: 'zap',
accent: ACCENTS.blue,
index: 1
}),
jsx(StatCard, {
label: 'Cache efficiency',
value: `${cachePct}%`,
sub: 'served from cache',
icon: 'graph',
accent: ACCENTS.teal,
index: 2
}),
jsx(StatCard, {
label: 'Cron (24h)',
value: `${c.completed || 0} ok`,
sub: c.failed ? `${c.failed} failed` : 'no failures',
icon: 'clock',
accent: c.failed ? ACCENTS.red : ACCENTS.gold,
index: 3
}),
jsx(StatCard, {
label: 'Errors (24h)',
value: String(e.count_24h || 0),
sub: e.latest && e.latest.length ? e.latest[0].slice(0, 52) : 'clean',
icon: 'error',
accent: e.count_24h ? ACCENTS.red : ACCENTS.green,
index: 4
}),
jsx(StatCard, {
label: 'Facts in memory',
value: String(m.facts || 0),
sub: 'deep memory entries',
icon: 'database',
accent: ACCENTS.purple,
index: 5
}),
jsx(StatCard, {
label: 'Process groups',
value: String((data.processes || []).length),
sub: 'desktop + backends',
icon: 'plug',
accent: ACCENTS.rose,
index: 6
}),
jsx(StatCard, {
label: 'Last refresh',
value: data.generated_at ? relativeTime(data.generated_at * 1000) : '—',
sub: 'auto-refresh 30s',
icon: 'history',
accent: ACCENTS.gold,
index: 7
})
]
}),
// Recent error lines — only when there are errors to show
e.count_24h && e.latest && e.latest.length
? jsx(ErrorLogViewer, { lines: e.latest })
: null,
jsx(Section, {
title: 'Active processes',
icon: 'pulse',
accent: ACCENTS.green,
extra: `${(data.processes || []).length} running`,
children: jsxs('div', {
className: 'grid gap-2',
style: { gridTemplateColumns: 'repeat(auto-fill, minmax(320px, 1fr))' },
children: (data.processes || []).length
? data.processes.map((p, i) =>
jsxs('div', {
key: i,
className: cn(
'hc-fade-up flex items-center gap-2.5 rounded-xl border border-(--ui-stroke-secondary) bg-(--ui-bg-chrome) p-3 transition-all hover:-translate-y-0.5 hover:shadow-lg'
),
style: { animationDelay: `${i * 25}ms` },
children: [
jsx('span', {
className: 'shrink-0 rounded-md px-1.5 py-0.5 font-mono text-[0.625rem] font-semibold tabular-nums',
style: { backgroundColor: 'rgba(47,158,99,0.12)', color: '#2f9e63' },
children: p.pid
}),
jsx('span', { className: 'min-w-0 flex-1 truncate text-xs text-(--ui-text-secondary)', title: p.cmd, children: p.cmd })
]
})
)
: jsx(EmptyState, { title: 'No backends', description: 'No Hermes backend processes detected.' })
})
})
]
})
}
// ── Cron tab ───────────────────────────────────────────────────────────────
function fmtSchedule(s) {
if (!s) return '—'
if (typeof s === 'string') return s
return s.display || s.expr || '—'
}
function fmtDuration(ms) {
if (ms == null) return '—'
if (ms < 1000) return `${ms}ms`
if (ms < 60000) return `${(ms / 1000).toFixed(1)}s`
return `${Math.round(ms / 60000)}m`
}
function fmtNextRun(iso) {
if (!iso) return 'not scheduled'
const d = new Date(iso)
if (isNaN(d.getTime())) return '—'
const diff = d.getTime() - Date.now()
if (diff < 0) return 'due'
if (diff < 3600000) return `in ${Math.max(1, Math.round(diff / 60000))}m`
if (diff < 86400000) return `in ${Math.round(diff / 3600000)}h`
return `in ${Math.round(diff / 86400000)}d`
}
// Execution timestamps arrive as ISO strings (started_at). Parse defensively.
function execDate(ex) {
if (ex.at_iso) {
const d = new Date(ex.at_iso)
if (!isNaN(d.getTime())) return d
}
const ms = ex.at_ms
if (ms != null) {
const d = new Date(ms > 1e12 ? ms : ms * 1000)
if (!isNaN(d.getTime())) return d
}
return null
}
function fmtRelTime(date) {
if (!date) return '—'
const diff = Date.now() - date.getTime()
if (diff < 60000) return 'just now'
if (diff < 3600000) return `${Math.max(1, Math.round(diff / 60000))}m ago`
if (diff < 86400000) return `${Math.round(diff / 3600000)}h ago`
return `${Math.round(diff / 86400000)}d ago`
}
// Group executions into ordered day buckets with labels.
function groupByDay(executions) {
const groups = []
const seen = new Map()
for (const ex of executions) {
const d = execDate(ex)
const key = d ? d.toDateString() : 'unknown'
let label
if (d) {
const today = new Date()
const yest = new Date(today.getTime() - 86400000)
if (d.toDateString() === today.toDateString()) label = 'Today'
else if (d.toDateString() === yest.toDateString()) label = 'Yesterday'
else label = d.toLocaleDateString(undefined, { weekday: 'short', month: 'short', day: 'numeric' })
} else {
label = 'Unknown'
}
if (!seen.has(key)) {
seen.set(key, groups.length)
groups.push({ key, label, items: [] })
}
groups[seen.get(key)].items.push(ex)
}
return groups
}
function CronTab({ data }) {
const jobs = data.jobs || []
const executions = data.executions || []
const enabledCount = jobs.filter(j => j.enabled !== false && !j.paused).length
const failedCount = jobs.filter(j => j.last_status === 'failed').length
return jsxs('div', {
className: 'flex flex-col gap-4 p-6',
children: [
// Summary strip
jsxs('div', {
className: 'grid gap-3',
style: { gridTemplateColumns: 'repeat(auto-fit, minmax(180px, 1fr))' },
children: [
jsx(StatCard, { label: 'Total jobs', value: String(jobs.length), sub: 'scheduled', icon: 'clock', accent: ACCENTS.teal, index: 0 }),
jsx(StatCard, { label: 'Active', value: String(enabledCount), sub: 'enabled + not paused', icon: 'play', accent: ACCENTS.green, index: 1 }),
jsx(StatCard, { label: 'Last status', value: failedCount ? `${failedCount} failed` : 'all ok', sub: failedCount ? 'needs attention' : 'last runs clean', icon: 'check', accent: failedCount ? ACCENTS.red : ACCENTS.green, index: 2 }),
jsx(StatCard, { label: 'Recent runs', value: String(executions.length), sub: 'last 40 executions', icon: 'history', accent: ACCENTS.blue, index: 3 })
]
}),
// Job cards
jsx(Section, {
title: 'Scheduled jobs',
icon: 'clock',
accent: ACCENTS.teal,
extra: `${jobs.length} jobs · ${enabledCount} active`,
children: jobs.length
? jsxs('div', {
className: 'grid gap-2.5',
// Inline grid template — the host Tailwind build purges plugin
// grid-cols-* classes beyond 1/2/4/6, so auto-fill keeps the
// job cards 2-up on wide panes and 1-up on narrow ones.
style: { gridTemplateColumns: 'repeat(auto-fill, minmax(340px, 1fr))' },
children: jobs.map((job, i) => {
const paused = job.paused || job.state === 'paused'
const disabled = job.enabled === false
const inactive = paused || disabled
const statusTone = job.last_status === 'failed' ? 'err' : job.last_status === 'ok' ? 'ok' : 'idle'
const accent = inactive ? ACCENTS.idle : job.last_status === 'failed' ? ACCENTS.red : ACCENTS.green
return jsxs('div', {
key: job.id,
className: cn(
'hc-glow hc-fade-up flex flex-col gap-2 rounded-xl border border-(--ui-stroke-secondary) bg-(--ui-bg-chrome) p-3.5 transition-all hover:-translate-y-0.5 hover:shadow-lg',
inactive && 'opacity-70'
),
style: { animationDelay: `${i * 40}ms` },
children: [
jsxs('div', {
className: 'flex items-start gap-2.5',
children: [
jsx(IconChip, { codicon: inactive ? 'circle-slash' : 'clock', accent, size: 'h-8 w-8' }),
jsxs('div', {
className: 'min-w-0 flex-1',
children: [
jsxs('div', {
className: 'flex items-center gap-1.5',
children: [
jsx('span', { className: 'truncate text-xs font-semibold text-(--ui-text-primary)', children: job.name }),
job.no_agent ? jsx(Badge, { children: 'script' }) : null
]
}),
jsxs('div', {
className: 'mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[0.625rem] text-(--ui-text-secondary)',
children: [
jsx('span', { className: 'font-mono', children: fmtSchedule(job.schedule) }),
job.model ? jsx('span', { children: job.model }) : null,
job.deliver && job.deliver !== 'origin' ? jsx('span', { children: `→ ${job.deliver}` }) : null
]
})
]
}),
jsx('div', {
className: 'flex shrink-0 flex-col items-end gap-1',
children: jsx(StatusPill, { tone: statusTone, children: job.last_status || '—' })
})
]
}),
jsxs('div', {
className: 'flex items-center justify-between border-t border-(--ui-stroke-secondary) pt-2 text-[0.625rem]',
children: [
jsx('span', { className: 'text-(--ui-text-secondary)', children: job.next_run_at ? `Next: ${fmtNextRun(job.next_run_at)}` : (inactive ? 'Paused' : 'No next run') }),
job.last_error
? jsx('span', { className: 'max-w-[45%] truncate text-(--ui-error)', title: job.last_error, children: job.last_error })
: null
]
})
]
})
})
})
: jsx(EmptyState, { title: 'No cron jobs', description: 'Nothing scheduled yet.' })
}),
// Executions table — grouped by day, compact aligned rows
jsx(Section, {
title: 'Recent executions',
icon: 'history',
accent: ACCENTS.blue,
extra: `${executions.length} shown`,
children: executions.length
? jsxs('div', {
className: 'grid gap-1',
// Inline grid template: day groups flow side-by-side on wide
// panes instead of one full-width column of sparse rows.
style: { gridTemplateColumns: 'repeat(auto-fill, minmax(420px, 1fr))', alignItems: 'start' },
children: groupByDay(executions).map(group =>
jsxs('div', {
key: group.key,
className: 'mb-0',
children: [
jsxs('div', {
className: 'flex items-center gap-2 px-1 pb-1.5 pt-2 text-[0.625rem] font-semibold uppercase tracking-wider text-(--ui-text-secondary)',
children: [
jsx('span', { children: group.label }),
jsx('span', { className: 'rounded-full bg-(--ui-bg-quaternary) px-1.5 text-[0.5625rem] tabular-nums', children: String(group.items.length) })
]
}),
jsxs('div', {
className: 'flex flex-col overflow-hidden rounded-lg border border-(--ui-stroke-secondary)',
children: group.items.map((ex, i) => {
const tone = ex.status === 'completed' ? ACCENTS.green : ex.status === 'failed' ? ACCENTS.red : ACCENTS.gold
const d = execDate(ex)
return jsxs('div', {
key: i,
className: cn(
'flex items-center gap-2.5 px-2.5 py-1.5 text-xs transition-colors hover:bg-(--ui-bg-quaternary)',
i > 0 && 'border-t border-(--ui-stroke-secondary)'
),
children: [
jsx('span', {
className: 'w-[4.5rem] shrink-0 rounded-md px-1.5 py-0.5 text-center text-[0.625rem] font-semibold',
style: { backgroundColor: tone.bg, color: tone.text },
children: ex.status || 'unknown'
}),
jsx('span', { className: 'min-w-0 flex-1 truncate font-medium text-(--ui-text-primary)', children: ex.job_name }),
jsx('span', { className: 'w-14 shrink-0 text-right text-[0.625rem] tabular-nums text-(--ui-text-secondary)', children: ex.duration_ms != null ? fmtDuration(ex.duration_ms) : '' }),
ex.error
? jsx('span', { className: 'max-w-[12rem] truncate text-[0.625rem] text-(--ui-error)', title: ex.error, children: ex.error })
: null,
jsx('span', { className: 'w-16 shrink-0 text-right text-[0.625rem] tabular-nums text-(--ui-text-secondary)', title: d ? d.toLocaleString() : '', children: fmtRelTime(d) })
]
})
})
})
]
})
)
})
: jsx(EmptyState, { title: 'No executions', description: 'No recent cron runs recorded.' })
})
]
})
}
// ── Plugins tab ────────────────────────────────────────────────────────────
// Icon + accent per backend plugin, keyed by name; falls back to a neutral
// plug icon. NOTE: icons must exist in the host's bundled codicon set — the
// build subsets the font, so `trophy`/`paint-bucket` are stripped at build
// time and render as blank squares. Verified-present: sparkle, symbol-color,
// dashboard, pulse, plug, globe, extensions, milestone, star.
const PLUGIN_META = {
'command-center': { icon: 'dashboard', accent: ACCENTS.purple },
'hermes-achievements': { icon: 'sparkle', accent: ACCENTS.gold },
'status-cost': { icon: 'pulse', accent: ACCENTS.green },
'theme-switcher': { icon: 'symbol-color', accent: ACCENTS.rose }
}
// Some repo-mounted plugins have no description in their manifest; give them
// a short human line so cards never show a bare "No description."
const PLUGIN_FALLBACK_DESC = {
'hermes-achievements': 'Gamified achievement tracking: badges, XP, tiers, quests, and rewards for your Hermes usage.'
}
function fmtMtime(mt) {