-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDebugPage.tsx
More file actions
1061 lines (1000 loc) · 43 KB
/
DebugPage.tsx
File metadata and controls
1061 lines (1000 loc) · 43 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
import { useState, useEffect, useMemo } from 'react';
import { Link as RouterLink } from 'react-router-dom';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import Link from '@mui/material/Link';
import Tooltip from '@mui/material/Tooltip';
import { DEBUG_API_URL, LIBRARIES, LIB_ABBREV } from '../constants';
import { specPath } from '../utils/paths';
import { SectionHeader } from '../components/SectionHeader';
import { typography, colors, semanticColors, fontSize } from '../theme';
// ============================================================================
// Types
// ============================================================================
interface SpecStatus {
id: string;
title: string;
updated: string | null;
avg_score: number | null;
altair: number | null;
bokeh: number | null;
highcharts: number | null;
letsplot: number | null;
matplotlib: number | null;
plotly: number | null;
plotnine: number | null;
pygal: number | null;
seaborn: number | null;
}
interface LibraryStats {
id: string;
name: string;
impl_count: number;
avg_score: number | null;
min_score: number | null;
max_score: number | null;
}
interface ProblemSpec {
id: string;
title: string;
issue: string;
value: string | null;
}
interface SystemHealth {
database_connected: boolean;
api_response_time_ms: number;
timestamp: string;
total_specs_in_db: number;
total_impls_in_db: number;
}
interface DailyImplPoint {
date: string;
impls_updated: number;
}
interface RecentActivity {
spec_id: string;
spec_title: string;
library_id: string;
quality_score: number | null;
generated_by: string | null;
updated: string;
}
interface WeaknessCount {
text: string;
count: number;
}
interface DebugStatus {
total_specs: number;
total_implementations: number;
coverage_percent: number;
library_stats: LibraryStats[];
low_score_specs: ProblemSpec[];
oldest_specs: ProblemSpec[];
missing_preview_specs: ProblemSpec[];
missing_tags_specs: ProblemSpec[];
daily_impls: DailyImplPoint[];
recent_activity: RecentActivity[];
common_weaknesses: WeaknessCount[];
system: SystemHealth;
specs: SpecStatus[];
}
type SortKey = 'updated' | 'id' | 'title' | 'avg_score';
type SortDir = 'asc' | 'desc';
// ============================================================================
// Helpers
// ============================================================================
const LOW_SCORE_THRESHOLD = 90;
function scoreColor(score: number | null): string {
if (score === null) return 'var(--ink-muted)';
if (score >= 90) return colors.success;
if (score >= 75) return colors.warning;
return colors.error;
}
function formatNum(n: number): string {
if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;
if (n >= 1_000) return `${(n / 1_000).toFixed(1)}K`;
return n.toLocaleString();
}
function timeAgo(iso: string): string {
const then = new Date(iso).getTime();
if (Number.isNaN(then)) return '—';
const diffSec = Math.max(0, (Date.now() - then) / 1000);
if (diffSec < 60) return `${Math.floor(diffSec)}s ago`;
const diffMin = diffSec / 60;
if (diffMin < 60) return `${Math.floor(diffMin)}m ago`;
const diffHr = diffMin / 60;
if (diffHr < 24) return `${Math.floor(diffHr)}h ago`;
const diffDay = diffHr / 24;
if (diffDay < 30) return `${Math.floor(diffDay)}d ago`;
const diffMon = diffDay / 30;
if (diffMon < 12) return `${Math.floor(diffMon)}mo ago`;
return `${Math.floor(diffMon / 12)}y ago`;
}
function formatDateShort(iso: string): string {
const d = new Date(iso);
if (Number.isNaN(d.getTime())) return iso;
return d.toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
}
// Styled native input / select / button using CSS vars
const nativeControlSx = {
fontFamily: typography.fontFamily,
fontSize: fontSize.xs,
color: 'var(--ink)',
bgcolor: 'var(--bg-surface)',
border: '1px solid var(--rule)',
borderRadius: '4px',
px: 1,
py: 0.75,
outline: 'none',
'&:focus': { borderColor: colors.primary },
} as const;
// ============================================================================
// Component
// ============================================================================
const PING_INTERVAL_MS = 2000;
const PING_HISTORY = 30;
function pingColor(ms: number): string {
if (ms < 75) return colors.success;
if (ms < 200) return colors.warning;
return colors.error;
}
// Admin auth for /debug endpoints (require_admin in api/routers/debug.py).
// Two paths:
// - Cloudflare Access cookie set on .anyplot.ai → forwarded as Cf-Access-Jwt-Assertion
// to api.anyplot.ai. credentials: 'include' is required for the cookie to
// travel cross-origin to the API.
// - X-Admin-Token header as a fallback (CI, break-glass, local dev). Stored
// in sessionStorage so it survives reloads of the same tab without
// persisting across browser sessions.
const ADMIN_TOKEN_KEY = 'anyplot.adminToken';
// One-shot guard for the SPA-routed → CF Access page-gate bootstrap.
const RELOAD_GUARD_KEY = 'anyplot.debugAuthReloaded';
const readAdminToken = (): string => {
try { return sessionStorage.getItem(ADMIN_TOKEN_KEY) ?? ''; } catch { return ''; }
};
const writeAdminToken = (value: string): void => {
try { sessionStorage.setItem(ADMIN_TOKEN_KEY, value); } catch { /* sessionStorage may be unavailable */ }
};
const clearAdminToken = (): void => {
try { sessionStorage.removeItem(ADMIN_TOKEN_KEY); } catch { /* noop */ }
};
const adminFetch = (url: string, token: string): Promise<Response> =>
fetch(url, {
credentials: 'include',
headers: token ? { 'X-Admin-Token': token } : undefined,
});
export function DebugPage() {
const [data, setData] = useState<DebugStatus | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [authRequired, setAuthRequired] = useState(false);
const [adminToken, setAdminToken] = useState<string>(() => readAdminToken());
const [tokenInput, setTokenInput] = useState('');
const [reloadCounter, setReloadCounter] = useState(0);
const [sortKey, setSortKey] = useState<SortKey>('updated');
const [sortDir, setSortDir] = useState<SortDir>('desc');
const [searchText, setSearchText] = useState('');
const [showIncomplete, setShowIncomplete] = useState(false);
const [showLowScores, setShowLowScores] = useState(false);
const [missingLibrary, setMissingLibrary] = useState('');
const [pings, setPings] = useState<Array<{ ms: number; ok: boolean }>>([]);
const [prevFetchKey, setPrevFetchKey] = useState({ adminToken, reloadCounter });
// React 19 "adjust state on prop change": reset loading/error when fetch deps change.
if (prevFetchKey.adminToken !== adminToken || prevFetchKey.reloadCounter !== reloadCounter) {
setPrevFetchKey({ adminToken, reloadCounter });
setLoading(true);
setError(null);
}
useEffect(() => {
adminFetch(`${DEBUG_API_URL}/debug/status`, adminToken)
.then(async r => {
// Reaching here means the fetch promise resolved (the response may
// still be 401/403/503 — those are handled below). Clear the one-shot
// reload guard so a future cross-origin CF Access redirect can
// re-trigger the bootstrap.
try { sessionStorage.removeItem(RELOAD_GUARD_KEY); } catch { /* sessionStorage may be unavailable in private mode */ }
// 403 is the Cloudflare Access JWT path's denial: a signed-in Google
// account that isn't on the admin_allowed_emails allow-list. Surface
// it on the auth-required screen with the server's message so the
// user knows to sign in with a different account or ask for access.
if (r.status === 401 || r.status === 403 || r.status === 503) {
setAuthRequired(true);
if (r.status === 403) {
const body = await r.json().catch(() => ({}));
throw new Error(body?.message || 'this account is not authorized for /debug');
}
throw new Error(r.status === 503 ? 'admin auth not configured on server' : 'admin token required');
}
if (!r.ok) throw new Error(`${r.status}`);
setAuthRequired(false);
return r.json();
})
.then(setData)
.catch(e => {
// SPA-routed entry to /debug bypasses the Cloudflare Access page-
// level intercept. The first API fetch then 302s cross-origin to
// *.cloudflareaccess.com, which fetch can't follow without CORS,
// surfacing as TypeError("Failed to fetch"). Force one top-level
// navigation so CF Access can intercept the page request and bounce
// to Google login. sessionStorage guard keeps this from looping if
// the second load ALSO fails (e.g. wrong allow-list).
if (e instanceof TypeError) {
let alreadyTried = false;
try { alreadyTried = !!sessionStorage.getItem(RELOAD_GUARD_KEY); } catch { /* sessionStorage may be unavailable in private mode */ }
if (!alreadyTried) {
try { sessionStorage.setItem(RELOAD_GUARD_KEY, '1'); } catch { /* sessionStorage may be unavailable in private mode */ }
// replace() not assign() — assign would push the broken pre-auth
// /debug onto the back-stack, so the user could navigate back
// into the same loop after logging in.
window.location.replace(window.location.href);
return;
}
}
setError(e.message || 'failed to load');
})
.finally(() => setLoading(false));
}, [adminToken, reloadCounter]);
useEffect(() => {
if (authRequired) return;
let cancelled = false;
const tick = async () => {
const started = performance.now();
try {
const r = await adminFetch(`${DEBUG_API_URL}/debug/ping`, adminToken);
const totalMs = performance.now() - started;
if (!r.ok) throw new Error(`${r.status}`);
const json: { database_connected: boolean } = await r.json();
if (cancelled) return;
setPings(prev => [...prev.slice(-(PING_HISTORY - 1)), { ms: totalMs, ok: json.database_connected }]);
} catch {
if (cancelled) return;
const totalMs = performance.now() - started;
setPings(prev => [...prev.slice(-(PING_HISTORY - 1)), { ms: totalMs, ok: false }]);
}
};
tick();
const id = setInterval(tick, PING_INTERVAL_MS);
return () => { cancelled = true; clearInterval(id); };
}, [adminToken, authRequired]);
const handleTokenSubmit = (e: React.FormEvent) => {
e.preventDefault();
const trimmed = tokenInput.trim();
if (!trimmed) return;
writeAdminToken(trimmed);
setAdminToken(trimmed);
setTokenInput('');
};
const handleTokenClear = () => {
clearAdminToken();
setAdminToken('');
setReloadCounter(c => c + 1);
};
const countImpls = (spec: SpecStatus): number =>
LIBRARIES.filter(lib => spec[lib as keyof SpecStatus] !== null).length;
const hasLowScore = (spec: SpecStatus): boolean =>
LIBRARIES.some(lib => {
const s = spec[lib as keyof SpecStatus] as number | null;
return s !== null && s < LOW_SCORE_THRESHOLD;
});
const filteredSpecs = useMemo(() => {
if (!data) return [];
let filtered = [...data.specs];
if (searchText) {
const q = searchText.toLowerCase();
filtered = filtered.filter(s => s.id.toLowerCase().includes(q) || s.title.toLowerCase().includes(q));
}
if (showIncomplete) filtered = filtered.filter(s => countImpls(s) < 9);
if (showLowScores) filtered = filtered.filter(hasLowScore);
if (missingLibrary) filtered = filtered.filter(s => s[missingLibrary as keyof SpecStatus] === null);
filtered.sort((a, b) => {
let cmp = 0;
switch (sortKey) {
case 'updated': cmp = (a.updated || '').localeCompare(b.updated || ''); break;
case 'id': cmp = a.id.localeCompare(b.id); break;
case 'title': cmp = a.title.localeCompare(b.title); break;
case 'avg_score': cmp = (a.avg_score ?? 0) - (b.avg_score ?? 0); break;
}
return sortDir === 'desc' ? -cmp : cmp;
});
return filtered;
}, [data, searchText, showIncomplete, showLowScores, missingLibrary, sortKey, sortDir]);
const handleSort = (key: SortKey) => {
if (sortKey === key) {
setSortDir(sortDir === 'asc' ? 'desc' : 'asc');
} else {
setSortKey(key);
setSortDir(key === 'updated' || key === 'avg_score' ? 'desc' : 'asc');
}
};
if (authRequired) {
return (
<Box sx={{ py: 4, maxWidth: 420, mx: 'auto' }}>
<SectionHeader prompt="❯" title={<em>debug · admin auth</em>} />
<Typography sx={{ fontFamily: typography.fontFamily, fontSize: fontSize.xs, color: semanticColors.mutedText, mb: 2 }}>
{error || 'sign in via your browser session, or paste an admin token as a fallback.'}
</Typography>
<Box component="form" onSubmit={handleTokenSubmit} sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
<Box
component="input"
type="password"
autoFocus
placeholder="Admin token (fallback)"
value={tokenInput}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setTokenInput(e.target.value)}
sx={nativeControlSx}
/>
<Box sx={{ display: 'flex', gap: 1 }}>
<Box
component="button"
type="submit"
sx={{
...nativeControlSx,
cursor: 'pointer',
bgcolor: colors.primary,
color: 'var(--bg-page)',
borderColor: colors.primary,
fontWeight: 600,
}}
>
unlock
</Box>
{adminToken && (
<Box
component="button"
type="button"
onClick={handleTokenClear}
sx={{ ...nativeControlSx, cursor: 'pointer' }}
>
clear stored token
</Box>
)}
</Box>
<Typography sx={{ fontFamily: typography.fontFamily, fontSize: fontSize.xxs, color: semanticColors.mutedText, mt: 1 }}>
stored in sessionStorage — clears when this tab closes.
</Typography>
</Box>
</Box>
);
}
if (loading) {
return (
<Box sx={{ py: 4, textAlign: 'center' }}>
<Typography sx={{ fontFamily: typography.fontFamily, color: semanticColors.mutedText }}>
loading debug data...
</Typography>
</Box>
);
}
if (error || !data) {
return (
<Box sx={{ py: 4, textAlign: 'center' }}>
<Typography sx={{ fontFamily: typography.fontFamily, color: colors.error }}>
failed to load{error ? `: ${error}` : ''}
</Typography>
</Box>
);
}
// Derived KPIs
const totalImplsWithScore = data.library_stats.reduce(
(acc, l) => acc + (l.avg_score !== null ? l.impl_count : 0), 0
);
const weightedScoreSum = data.library_stats.reduce(
(acc, l) => acc + (l.avg_score !== null ? l.avg_score * l.impl_count : 0), 0
);
const avgQuality = totalImplsWithScore > 0 ? weightedScoreSum / totalImplsWithScore : null;
const maxDaily = Math.max(...data.daily_impls.map(p => p.impls_updated), 1);
const maxLibCount = Math.max(...data.library_stats.map(l => l.impl_count), 1);
const maxWeakness = Math.max(...data.common_weaknesses.map(w => w.count), 1);
const kpis: Array<{ label: string; value: number | null; suffix?: string }> = [
{ label: 'specs', value: data.total_specs },
{ label: 'impls', value: data.total_implementations },
{ label: 'coverage', value: data.coverage_percent, suffix: '%' },
{ label: 'avg quality', value: avgQuality !== null ? Math.round(avgQuality * 10) / 10 : null },
{ label: 'low score', value: data.low_score_specs.length },
{ label: 'stale specs', value: data.oldest_specs.length },
];
const firstDate = data.daily_impls[0]?.date ?? '';
const lastDate = data.daily_impls[data.daily_impls.length - 1]?.date ?? '';
return (
<Box sx={{ pt: { xs: 2, md: 3 }, pb: 4 }}>
{/* Header */}
<SectionHeader prompt="❯" title={<em>debug</em>} />
{/* System health row */}
{(() => {
const latest = pings[pings.length - 1];
const okPings = pings.filter(p => p.ok);
const currentOk = latest ? latest.ok : data.system.database_connected;
const currentMs = latest ? latest.ms : data.system.api_response_time_ms;
const avgMs = okPings.length > 0 ? okPings.reduce((a, p) => a + p.ms, 0) / okPings.length : null;
const maxMs = Math.max(...pings.map(p => p.ms), 1);
return (
<Box sx={{ display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: { xs: 1.5, md: 3 }, mt: -2, mb: 3, fontSize: fontSize.xs, fontFamily: typography.fontFamily }}>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.75 }}>
<Box sx={{ width: 8, height: 8, borderRadius: '50%', bgcolor: currentOk ? colors.success : colors.error }} />
<Typography component="span" sx={{ fontFamily: typography.fontFamily, fontSize: fontSize.xs, color: 'var(--ink-soft)' }}>
database {currentOk ? 'connected' : 'down'}
</Typography>
</Box>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
<Tooltip
title={avgMs !== null ? `avg ${avgMs.toFixed(0)}ms · max ${maxMs.toFixed(0)}ms · ${pings.length} samples` : 'measuring...'}
arrow
>
<Box sx={{
display: 'flex', alignItems: 'flex-end', gap: '1px',
height: 18, width: PING_HISTORY * 4,
borderBottom: '1px solid var(--rule)', px: 0.25,
}}>
{Array.from({ length: PING_HISTORY }).map((_, i) => {
const idx = pings.length - PING_HISTORY + i;
const p = idx >= 0 ? pings[idx] : null;
if (!p) return <Box key={i} sx={{ flex: 1 }} />;
return (
<Box
key={i}
sx={{
flex: 1,
height: p.ok ? `${Math.max((p.ms / maxMs) * 100, 8)}%` : '100%',
bgcolor: p.ok ? pingColor(p.ms) : colors.error,
opacity: 0.7,
}}
/>
);
})}
</Box>
</Tooltip>
<Typography component="span" sx={{
fontFamily: typography.fontFamily, fontSize: fontSize.xs,
color: currentOk ? pingColor(currentMs) : colors.error,
fontWeight: 600, minWidth: 52,
}}>
{currentMs.toFixed(0)}ms
</Typography>
{avgMs !== null && (
<Typography component="span" sx={{ fontFamily: typography.fontFamily, fontSize: fontSize.xxs, color: semanticColors.mutedText }}>
avg {avgMs.toFixed(0)}
</Typography>
)}
</Box>
<Typography component="span" sx={{ fontFamily: typography.fontFamily, fontSize: fontSize.xs, color: semanticColors.mutedText }}>
updated {new Date(data.system.timestamp).toLocaleTimeString()}
</Typography>
</Box>
);
})()}
{/* KPI Grid */}
<Box sx={{ display: 'grid', gridTemplateColumns: { xs: 'repeat(2, 1fr)', sm: 'repeat(3, 1fr)', md: 'repeat(6, 1fr)' }, gap: 2, mb: 4 }}>
{kpis.map(item => (
<Box key={item.label} sx={{ textAlign: 'center', p: 2, border: '1px solid var(--rule)', borderRadius: 1 }}>
<Typography sx={{ fontFamily: typography.serif, fontSize: '2rem', fontWeight: 300, color: 'var(--ink)', lineHeight: 1.2 }}>
{typeof item.value === 'number' ? `${formatNum(item.value)}${item.suffix ?? ''}` : '—'}
</Typography>
<Typography sx={{ fontFamily: typography.fontFamily, fontSize: fontSize.xs, color: semanticColors.mutedText, mt: 0.5 }}>
{item.label}
</Typography>
</Box>
))}
</Box>
{/* Daily Activity Bar Chart */}
<SectionHeader prompt="❯" title={<em>daily activity</em>} />
<Typography sx={{ fontFamily: typography.fontFamily, fontSize: fontSize.xs, color: semanticColors.mutedText, mb: 1 }}>
implementation updates · last 30 days
</Typography>
<Box sx={{ display: 'flex', alignItems: 'flex-end', gap: 0.25, height: 70, overflow: 'hidden' }}>
{data.daily_impls.map(point => (
<Tooltip key={point.date} title={`${point.date}: ${point.impls_updated} impls`} arrow>
<Box sx={{
flex: 1,
height: `${Math.max((point.impls_updated / maxDaily) * 100, point.impls_updated > 0 ? 3 : 0)}%`,
bgcolor: colors.primaryDark,
opacity: 0.5,
borderRadius: '2px 2px 0 0',
minHeight: point.impls_updated > 0 ? 2 : 0,
'&:hover': { opacity: 0.8 },
transition: 'opacity 0.15s ease',
}} />
</Tooltip>
))}
</Box>
<Box sx={{ display: 'flex', justifyContent: 'space-between', mt: 0.25 }}>
<Typography sx={{ fontFamily: typography.fontFamily, fontSize: fontSize.micro, color: semanticColors.mutedText }}>
{firstDate}
</Typography>
<Typography sx={{ fontFamily: typography.fontFamily, fontSize: fontSize.micro, color: semanticColors.mutedText }}>
{lastDate}
</Typography>
</Box>
{/* Library Coverage */}
<Box sx={{ mt: 4 }}>
<SectionHeader prompt="❯" title={<em>libraries</em>} />
</Box>
<Typography sx={{ fontFamily: typography.fontFamily, fontSize: fontSize.xs, color: semanticColors.mutedText, mb: 1 }}>
impl count · avg · min–max
</Typography>
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
{[...data.library_stats].sort((a, b) => b.impl_count - a.impl_count).map(lib => (
<Box
key={lib.id}
sx={{
display: 'grid',
gridTemplateColumns: '80px 1fr 40px 40px 70px',
gap: 1.5,
alignItems: 'center',
fontFamily: typography.fontFamily,
fontSize: fontSize.xxs,
}}
>
<Typography sx={{ fontFamily: typography.fontFamily, fontSize: fontSize.xs, color: semanticColors.mutedText, textAlign: 'right' }}>
{lib.name}
</Typography>
<Box sx={{ height: 10, bgcolor: 'var(--bg-elevated)', borderRadius: '2px', overflow: 'hidden' }}>
<Box sx={{
width: `${(lib.impl_count / maxLibCount) * 100}%`,
height: '100%',
bgcolor: colors.primaryDark,
opacity: 0.5,
}} />
</Box>
<Typography sx={{ fontFamily: typography.fontFamily, fontSize: fontSize.xxs, color: 'var(--ink-soft)', fontWeight: 600, textAlign: 'right' }}>
{lib.impl_count}
</Typography>
<Typography sx={{ fontFamily: typography.fontFamily, fontSize: fontSize.xxs, color: scoreColor(lib.avg_score), fontWeight: 600, textAlign: 'right' }}>
{lib.avg_score ?? '—'}
</Typography>
<Typography sx={{ fontFamily: typography.fontFamily, fontSize: fontSize.xxs, color: semanticColors.mutedText, textAlign: 'right' }}>
{lib.min_score?.toFixed(0) ?? '—'}–{lib.max_score?.toFixed(0) ?? '—'}
</Typography>
</Box>
))}
</Box>
<Box sx={{
display: 'grid',
gridTemplateColumns: '80px 1fr 40px 40px 70px',
gap: 1.5,
mt: 0.5,
fontFamily: typography.fontFamily,
fontSize: fontSize.micro,
color: semanticColors.mutedText,
}}>
<span />
<span />
<Box component="span" sx={{ textAlign: 'right' }}>count</Box>
<Box component="span" sx={{ textAlign: 'right' }}>avg</Box>
<Box component="span" sx={{ textAlign: 'right' }}>min–max</Box>
</Box>
{/* Recent Activity */}
{data.recent_activity.length > 0 && (
<>
<Box sx={{ mt: 4 }}>
<SectionHeader prompt="❯" title={<em>recent activity</em>} />
</Box>
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 0.5 }}>
{data.recent_activity.map((act, idx) => (
<Link
key={`${act.spec_id}-${act.library_id}-${idx}`}
component={RouterLink}
to={specPath(act.spec_id, 'python', act.library_id)}
sx={{
display: 'grid',
gridTemplateColumns: { xs: '55px 1fr 30px', sm: '65px 90px minmax(0, 1fr) 30px 130px' },
gap: { xs: 1, sm: 1.5 },
alignItems: 'center',
textDecoration: 'none',
color: 'inherit',
py: 0.5,
borderBottom: '1px solid var(--rule)',
'&:hover': { bgcolor: 'var(--bg-surface)' },
}}
>
<Typography sx={{ fontFamily: typography.fontFamily, fontSize: fontSize.xs, color: semanticColors.mutedText }}>
{timeAgo(act.updated)}
</Typography>
<Typography sx={{
fontFamily: typography.fontFamily, fontSize: fontSize.xs, color: 'var(--ink-soft)',
display: { xs: 'none', sm: 'block' },
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
}}>
{act.library_id}
</Typography>
<Typography sx={{
fontFamily: typography.fontFamily, fontSize: fontSize.xs, color: 'var(--ink)',
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', minWidth: 0,
}}>
<Box component="span" sx={{ display: { xs: 'inline', sm: 'none' }, color: semanticColors.mutedText, mr: 0.5 }}>
{act.library_id} ·
</Box>
{act.spec_title}
</Typography>
<Typography sx={{ fontFamily: typography.fontFamily, fontSize: fontSize.xs, color: scoreColor(act.quality_score), fontWeight: 600, textAlign: 'right' }}>
{act.quality_score !== null ? Math.round(act.quality_score) : '—'}
</Typography>
<Typography sx={{
fontFamily: typography.fontFamily, fontSize: fontSize.xxs, color: semanticColors.mutedText,
display: { xs: 'none', sm: 'block' },
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
textAlign: 'right',
}}>
{act.generated_by ?? '—'}
</Typography>
</Link>
))}
</Box>
</>
)}
{/* Common Weaknesses */}
{data.common_weaknesses.length > 0 && (
<>
<Box sx={{ mt: 4 }}>
<SectionHeader prompt="❯" title={<em>common weaknesses</em>} />
</Box>
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 0.75, alignItems: 'baseline' }}>
{data.common_weaknesses.map(w => {
const ratio = w.count / maxWeakness;
const size = ratio >= 0.8 ? fontSize.md : ratio >= 0.5 ? fontSize.sm : ratio >= 0.25 ? fontSize.xs : fontSize.xxs;
const weight = ratio >= 0.5 ? 600 : 400;
const opacity = ratio >= 0.8 ? 1 : ratio >= 0.5 ? 0.85 : ratio >= 0.25 ? 0.7 : 0.55;
return (
<Box key={w.text} sx={{
fontFamily: typography.fontFamily, fontSize: size, fontWeight: weight,
color: 'var(--ink-soft)', opacity, px: 0.75, py: 0.25, borderRadius: 0.5,
bgcolor: 'var(--bg-surface)', border: '1px solid var(--rule)',
}}>
{w.text}
<Box component="span" sx={{ fontSize: fontSize.micro, color: semanticColors.mutedText, ml: 0.5 }}>
{w.count}
</Box>
</Box>
);
})}
</Box>
</>
)}
{/* Problem Areas */}
<Box sx={{ mt: 4 }}>
<SectionHeader prompt="❯" title={<em>problem areas</em>} />
</Box>
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
{[
{ title: `low scores (avg < ${LOW_SCORE_THRESHOLD})`, items: data.low_score_specs },
{ title: 'missing previews', items: data.missing_preview_specs },
{ title: 'missing tags', items: data.missing_tags_specs },
{ title: 'oldest specs', items: data.oldest_specs },
].map(section => (
<Box
key={section.title}
component="details"
sx={{
border: '1px solid var(--rule)', borderRadius: 1, p: 0,
'& > summary': { cursor: 'pointer', listStyle: 'none' },
'& > summary::-webkit-details-marker': { display: 'none' },
}}
>
<Box
component="summary"
sx={{
display: 'flex', alignItems: 'center', gap: 1, px: 1.5, py: 1,
fontFamily: typography.fontFamily, fontSize: fontSize.xs, color: 'var(--ink-soft)',
}}
>
<Box component="span" sx={{ color: semanticColors.mutedText }}>▸</Box>
<Box component="span" sx={{ fontWeight: 600 }}>{section.title}</Box>
<Box component="span" sx={{ color: semanticColors.mutedText }}>
{section.items.length}
</Box>
</Box>
{section.items.length > 0 && (
<Box sx={{ display: 'flex', flexDirection: 'column', borderTop: '1px solid var(--rule)' }}>
{section.items.map((item, idx) => (
<Link
key={`${item.id}-${idx}`}
component={RouterLink}
to={specPath(item.id)}
sx={{
display: 'grid',
gridTemplateColumns: { xs: '1fr auto', sm: 'minmax(140px, 200px) 1fr auto' },
gap: 1, px: 1.5, py: 0.75, alignItems: 'center',
textDecoration: 'none', color: 'inherit',
fontFamily: typography.fontFamily, fontSize: fontSize.xs,
borderTop: idx > 0 ? '1px solid var(--rule)' : 'none',
'&:hover': { bgcolor: 'var(--bg-surface)' },
}}
>
<Box component="span" sx={{ color: colors.primary, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{item.id}
</Box>
<Box component="span" sx={{ color: semanticColors.mutedText, display: { xs: 'none', sm: 'inline' }, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{item.issue}
</Box>
{item.value && (
<Box component="span" sx={{ color: colors.error, whiteSpace: 'nowrap', textAlign: 'right' }}>
{item.value}
</Box>
)}
</Link>
))}
</Box>
)}
</Box>
))}
</Box>
{/* Spec Matrix */}
<Box sx={{ mt: 4 }}>
<SectionHeader prompt="❯" title={<em>specs</em>} />
</Box>
{/* Filter Bar */}
<Box sx={{
display: 'flex', gap: 1, mb: 2, flexWrap: { xs: 'nowrap', sm: 'wrap' },
overflowX: { xs: 'auto', sm: 'visible' }, pb: { xs: 0.5, sm: 0 },
}}>
<Box
component="input"
type="search"
placeholder="search spec id or title..."
value={searchText}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setSearchText(e.target.value)}
sx={{ ...nativeControlSx, flex: { xs: '0 0 180px', sm: '1 1 220px' } }}
/>
<Box
component="button"
type="button"
onClick={() => setShowIncomplete(v => !v)}
sx={{
...nativeControlSx,
cursor: 'pointer',
flexShrink: 0,
bgcolor: showIncomplete ? colors.highlight.bg : 'var(--bg-surface)',
color: showIncomplete ? colors.highlight.text : 'var(--ink-soft)',
borderColor: showIncomplete ? colors.primary : 'var(--rule)',
}}
>
incomplete {'<'}9
</Box>
<Box
component="button"
type="button"
onClick={() => setShowLowScores(v => !v)}
sx={{
...nativeControlSx,
cursor: 'pointer',
flexShrink: 0,
bgcolor: showLowScores ? colors.highlight.bg : 'var(--bg-surface)',
color: showLowScores ? colors.highlight.text : 'var(--ink-soft)',
borderColor: showLowScores ? colors.primary : 'var(--rule)',
}}
>
low scores {'<'}90
</Box>
<Box
component="select"
value={missingLibrary}
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => setMissingLibrary(e.target.value)}
sx={{ ...nativeControlSx, cursor: 'pointer', flexShrink: 0 }}
>
<option value="">missing library: any</option>
{LIBRARIES.map(lib => (
<option key={lib} value={lib}>missing: {lib}</option>
))}
</Box>
<Typography sx={{
fontFamily: typography.fontFamily, fontSize: fontSize.xs,
color: semanticColors.mutedText, alignSelf: 'center', flexShrink: 0, ml: { xs: 0, sm: 'auto' },
}}>
{filteredSpecs.length} / {data.total_specs}
</Typography>
</Box>
{/* Desktop: grid matrix */}
<Box sx={{ display: { xs: 'none', md: 'block' }, overflowX: 'auto' }}>
<Box sx={{ minWidth: 780 }}>
{/* Header row */}
<Box sx={{
display: 'grid',
gridTemplateColumns: '180px minmax(180px, 1fr) 50px 50px repeat(9, 40px) 80px',
gap: 0, alignItems: 'center',
position: 'sticky', top: 0, zIndex: 1,
bgcolor: 'var(--bg-page)',
borderBottom: '1px solid var(--rule)',
py: 1,
}}>
<SortableHeader label="spec id" active={sortKey === 'id'} dir={sortDir} onClick={() => handleSort('id')} />
<SortableHeader label="title" active={sortKey === 'title'} dir={sortDir} onClick={() => handleSort('title')} />
<HeaderCell>#</HeaderCell>
<SortableHeader label="avg" active={sortKey === 'avg_score'} dir={sortDir} onClick={() => handleSort('avg_score')} center />
{LIBRARIES.map(lib => (
<HeaderCell key={lib} center>{LIB_ABBREV[lib] ?? lib.slice(0, 3)}</HeaderCell>
))}
<SortableHeader label="updated" active={sortKey === 'updated'} dir={sortDir} onClick={() => handleSort('updated')} />
</Box>
{/* Body rows */}
{filteredSpecs.map(spec => {
const implCount = countImpls(spec);
return (
<Box
key={spec.id}
sx={{
display: 'grid',
gridTemplateColumns: '180px minmax(180px, 1fr) 50px 50px repeat(9, 40px) 80px',
gap: 0, alignItems: 'center', py: 0.5,
borderBottom: '1px solid var(--rule)',
'&:hover': { bgcolor: 'var(--bg-surface)' },
}}
>
<Link
component={RouterLink}
to={specPath(spec.id)}
sx={{
fontFamily: typography.fontFamily, fontSize: fontSize.xs,
color: colors.primary, textDecoration: 'none',
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
'&:hover': { textDecoration: 'underline' },
}}
>
{spec.id}
</Link>
<Typography sx={{
fontFamily: typography.fontFamily, fontSize: fontSize.xs,
color: semanticColors.labelText,
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', pr: 1,
}}>
{spec.title}
</Typography>
<Typography sx={{
fontFamily: typography.fontFamily, fontSize: fontSize.xs, fontWeight: 600,
color: implCount === 9 ? colors.success : implCount > 0 ? semanticColors.mutedText : 'var(--ink-muted)',
textAlign: 'center',
}}>
{implCount}/9
</Typography>
<Typography sx={{
fontFamily: typography.fontFamily, fontSize: fontSize.xs, fontWeight: 600,
color: scoreColor(spec.avg_score), textAlign: 'center',
}}>
{spec.avg_score !== null ? spec.avg_score.toFixed(1) : '—'}
</Typography>
{LIBRARIES.map(lib => {
const score = spec[lib as keyof SpecStatus] as number | null;
if (score === null) {
return (
<Box key={lib} sx={{ textAlign: 'center', fontFamily: typography.fontFamily, fontSize: fontSize.xs, color: 'var(--ink-muted)' }}>
—
</Box>
);
}
return (
<Link
key={lib}
component={RouterLink}
to={specPath(spec.id, 'python', lib)}
sx={{
textAlign: 'center', textDecoration: 'none',
fontFamily: typography.fontFamily, fontSize: fontSize.xs, fontWeight: 600,
color: scoreColor(score),
'&:hover': { opacity: 0.7 },
}}
>
{Math.round(score)}
</Link>
);
})}
<Typography sx={{ fontFamily: typography.fontFamily, fontSize: fontSize.xxs, color: semanticColors.mutedText }}>
{spec.updated ? formatDateShort(spec.updated) : '—'}
</Typography>
</Box>
);
})}
</Box>
</Box>
{/* Mobile: card list */}
<Box sx={{ display: { xs: 'flex', md: 'none' }, flexDirection: 'column', gap: 1.5 }}>
{filteredSpecs.map(spec => (
<Box
key={spec.id}
sx={{
border: '1px solid var(--rule)', borderRadius: 1, p: 1.5,
display: 'flex', flexDirection: 'column', gap: 1,
}}
>
<Box sx={{ display: 'flex', alignItems: 'baseline', gap: 1 }}>
<Link
component={RouterLink}
to={specPath(spec.id)}
sx={{
flex: 1, fontFamily: typography.fontFamily, fontSize: fontSize.sm,
color: 'var(--ink)', textDecoration: 'none', fontWeight: 500,
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
'&:hover': { color: colors.primary },
}}
>
{spec.title}
</Link>
<Typography sx={{
fontFamily: typography.fontFamily, fontSize: fontSize.xs,
color: scoreColor(spec.avg_score), fontWeight: 600, flexShrink: 0,
}}>
avg {spec.avg_score !== null ? spec.avg_score.toFixed(0) : '—'}
</Typography>
</Box>
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 0.5 }}>
{LIBRARIES.map(lib => {
const score = spec[lib as keyof SpecStatus] as number | null;
const missing = score === null;
const abbrev = LIB_ABBREV[lib] ?? lib.slice(0, 3);
const commonSx = {
display: 'inline-flex', alignItems: 'center', gap: 0.5,
px: 0.75, py: 0.25, borderRadius: 0.5,
fontFamily: typography.fontFamily, fontSize: fontSize.xxs, fontWeight: 600,
textDecoration: 'none',
bgcolor: missing ? 'var(--bg-elevated)' : `${scoreColor(score)}22`,
color: missing ? 'var(--ink-muted)' : scoreColor(score),
};
if (missing) {
return (
<Box key={lib} sx={commonSx}>
<Box component="span">{abbrev}</Box>
<Box component="span">—</Box>
</Box>
);
}
return (
<Link
key={lib}
component={RouterLink}
to={specPath(spec.id, 'python', lib)}
sx={{ ...commonSx, '&:hover': { opacity: 0.75 } }}