-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtask-overview-panel.tsx
More file actions
814 lines (782 loc) · 28.2 KB
/
Copy pathtask-overview-panel.tsx
File metadata and controls
814 lines (782 loc) · 28.2 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
"use client";
import { useMemo } from "react";
import { useRouter } from "next/navigation";
import useSWR from "swr";
import { ArrowUpRight, Loader2, SearchCode } from "lucide-react";
import { cn } from "@/lib/utils";
import { fetcher } from "@/lib/api";
import { Skeleton } from "@/components/ui/skeleton";
import { AnalysisProse } from "@/components/analysis-prose";
import { SeverityGroups } from "@/components/qa-report/action-items";
import { CopyJsonButton } from "@/components/qa-report/copy-json-button";
import { FALLBACK_TOKEN, VERDICT_TOKENS } from "@/components/qa-report/tokens";
import { TaskVerdictBadge } from "@/components/task-verdict-badge";
import { isActivePipelineStatus } from "@/lib/job-status";
import { formatCostUsd, hasDisplayableCostUsd } from "@/lib/format";
import type {
AnalysisClassification,
PreTrialFinding,
Task,
Trial,
} from "@/lib/types";
export type StaticCheckState =
| "unaudited"
| "running"
| "failed"
| "clean"
| "findings";
/**
* What to say for a task's source audit. Empty findings mean three
* different things depending on status: only `success` with no items is
* genuinely "we looked and found nothing".
*/
export function staticCheckState(
status: string | null | undefined,
findingCount: number,
): StaticCheckState {
if (!status) return "unaudited";
const normalized = status.toLowerCase();
if (normalized === "running" || normalized === "queued") return "running";
if (normalized === "success") return findingCount > 0 ? "findings" : "clean";
return "failed";
}
/** Problems first: a cheated success or broken task outranks a clean run. */
const CLASSIFICATION_ORDER: AnalysisClassification[] = [
"BAD_SUCCESS",
"BAD_FAILURE",
"HARNESS_ERROR",
"GOOD_FAILURE",
"GOOD_SUCCESS",
];
const CLASSIFICATION_LABELS: Record<AnalysisClassification, string> = {
BAD_SUCCESS: "Bad success",
BAD_FAILURE: "Bad failure",
HARNESS_ERROR: "Harness error",
GOOD_FAILURE: "Good failure",
GOOD_SUCCESS: "Good success",
};
/** A finding plus where it came from: the source audit, trial QA, or both. */
interface SourcedFinding extends PreTrialFinding {
fromAudit: boolean;
trials: Trial[];
}
function findingKey(item: PreTrialFinding): string {
// Server ids are content hashes that include the analyzer source, so they
// dedupe within one source only — the cross-source join is `links_to`.
// Items without an id fall back to a content key.
return (
item.id ?? `${item.tier ?? ""}|${item.title ?? ""}|${item.file ?? ""}`
);
}
function classificationRank(trial: Trial): number {
const classification = trial.analysis?.classification;
if (!classification) return CLASSIFICATION_ORDER.length;
const rank = CLASSIFICATION_ORDER.indexOf(classification);
return rank >= 0 ? rank : CLASSIFICATION_ORDER.length;
}
function trialLabel(trial: Trial): string {
const model = trial.model?.split("/").pop();
return model ? `${trial.agent} · ${model}` : trial.agent;
}
/**
* The task overview: the task's own QA (verdict + the source-audit findings)
* merged with the trial-level QA aggregated across the shown version's
* trials, each finding and classification linking back to the trial that
* surfaced it.
*/
export function TaskOverviewPanel({
taskId,
apiBaseUrl = "/api",
version,
scopeTrials,
scopeLoading,
verdictTask,
checksFindings,
checksStatus,
checksError,
checksCostUsd,
onRerunChecks,
checksRerunning,
checksQueueError,
checksLoading,
checksLoadError,
qaActive,
onOpenTrial,
className,
}: {
taskId: string | null;
apiBaseUrl?: string;
/** Version the pane is scoped to: a number pins, null deliberately
* aggregates every trial, and undefined means still resolving — the
* trial aggregation waits instead of briefly spanning all versions. */
version?: number | null;
/** The trials that belong to the host's context (an experiment drawer
* passes its own; the task page passes the version's). Trials outside
* this set still render, marked as from elsewhere. Null = no context. */
scopeTrials?: Trial[] | null;
/** The host is still streaming its trial rows — an empty scope renders
* as loading, not as "no trials". */
scopeLoading?: boolean;
/** Render the QA verdict inline — for panes whose host shows no verdict
* card of its own (the side-by-side "Task definition" pane). */
verdictTask?: Task | null;
checksFindings?: PreTrialFinding[] | null;
checksStatus?: string | null;
checksError?: string | null;
checksCostUsd?: number | null;
onRerunChecks: () => void;
checksRerunning: boolean;
checksQueueError?: string | null;
/** The checks state is still being fetched: an absent status must not
* read as "unaudited" — a Run click on that misread wipes real findings. */
checksLoading?: boolean;
checksLoadError?: string | null;
/** Task-level QA in flight — keeps the trial list polling until it lands. */
qaActive?: boolean;
/**
* Open a trial in the caller's own context (drawer / panel). Returns
* false when the trial isn't addressable there; the panel then falls
* back to the task page deep link.
*/
onOpenTrial?: (trial: Trial) => boolean;
className?: string;
}) {
const router = useRouter();
const versionKnown = version !== undefined;
// Probes are excluded at the query: they are internal instruction-overlay
// runs, not attempts, and their `analysis` is a different shape entirely.
// The fetch waits for the version so it can scope server-side — a task
// carries trials across many versions and experiments, and every full row
// ships its whole analysis payload.
const trialsKey =
taskId && versionKnown
? `${apiBaseUrl}/tasks/${taskId}/trials?probe=false${
version !== null ? `&version=${version}` : ""
}`
: null;
const { data: trials, error: trialsError } = useSWR<Trial[]>(trialsKey, fetcher, {
revalidateOnFocus: false,
refreshInterval: (data) => {
const anyAnalysisLive = (data ?? []).some((trial) =>
isActivePipelineStatus(trial.analysis_status),
);
return anyAnalysisLive || qaActive ? 15000 : 0;
},
});
// Host rows can include probes and superseded trials; filter them here too.
const scoped = useMemo(() => {
if (scopeTrials == null) return null;
return scopeTrials.filter(
(trial) => !trial.is_probe && !trial.superseded_by_trial_id,
);
}, [scopeTrials]);
const fetchedById = useMemo(
() => new Map((trials ?? []).map((trial) => [trial.id, trial])),
[trials],
);
// Show every trial of the version. The verdict is computed over all of
// them, so a shorter list can hide the evidence behind it.
const displayTrials = useMemo(() => {
if (scoped == null) return trials ?? null;
const inScope = new Set(scoped.map((trial) => trial.id));
// Until the host's rows have loaded, rows from elsewhere would render
// without their mark -- hold them back.
const elsewhere = scopeLoading
? []
: (trials ?? []).filter(
(trial) => !inScope.has(trial.id) && !trial.superseded_by_trial_id,
);
return [
...scoped.map((trial) => fetchedById.get(trial.id) ?? trial),
...elsewhere,
];
}, [scoped, scopeLoading, fetchedById, trials]);
// Null until the host's rows have loaded, so nothing is marked too early.
const foreignIds = useMemo(() => {
if (scoped == null || scopeLoading) return null;
const inScope = new Set(scoped.map((trial) => trial.id));
return new Set(
(trials ?? [])
.filter(
(trial) => !inScope.has(trial.id) && !trial.superseded_by_trial_id,
)
.map((trial) => trial.id),
);
}, [scoped, scopeLoading, trials]);
const versionTrials = useMemo(() => {
if (version === undefined) return [];
const all = displayTrials ?? [];
if (version === null) return all;
return all.filter((trial) => trial.task_version === version);
}, [displayTrials, version]);
const {
classificationCounts,
unanalyzedCount,
analyzedCount,
mergedFindings,
qaTrials,
} = useMemo(() => {
const byKey = new Map<string, SourcedFinding>();
const addTrial = (row: SourcedFinding, trial: Trial) => {
if (!row.trials.some((t) => t.id === trial.id)) row.trials.push(trial);
};
for (const item of checksFindings ?? []) {
const key = findingKey(item);
byKey.set(key, { ...item, id: key, fromAudit: true, trials: [] });
}
const counts = new Map<AnalysisClassification, number>();
const withQa: Trial[] = [];
let unanalyzed = 0;
for (const trial of versionTrials) {
if (!trial.analysis && !trial.analysis_status) {
unanalyzed += 1;
continue;
}
withQa.push(trial);
const analysis = trial.analysis;
if (!analysis) continue;
counts.set(
analysis.classification,
(counts.get(analysis.classification) ?? 0) + 1,
);
// Exploitation assessments are the trial→audit-finding join: an
// exploiting trial belongs on the audit row's "seen in" list. A
// not-exploited assessment only says the classifier looked — skip it.
for (const assessment of analysis.exploitation ?? []) {
if (!assessment.exploited || !assessment.links_to) continue;
const audited = byKey.get(assessment.links_to);
if (!audited) continue;
audited.exploited = true;
addTrial(audited, trial);
}
for (const item of analysis.action_items ?? []) {
// A post-trial item that links to an audit finding is the same
// defect seen from the trial side — fold it into that row. Ids
// can't make this join: the server hash includes the source.
const linked = item.links_to ? byKey.get(item.links_to) : undefined;
const existing = linked ?? byKey.get(findingKey(item));
if (existing) {
addTrial(existing, trial);
// One exploiting trial marks the finding exploited.
if (item.exploited) existing.exploited = true;
} else {
const key = findingKey(item);
byKey.set(key, {
...item,
id: key,
fromAudit: false,
trials: [trial],
});
}
}
}
withQa.sort(
(a, b) =>
classificationRank(a) - classificationRank(b) ||
Number(foreignIds?.has(a.id) ?? false) -
Number(foreignIds?.has(b.id) ?? false) ||
a.created_at.localeCompare(b.created_at),
);
return {
classificationCounts: counts,
unanalyzedCount: unanalyzed,
analyzedCount: withQa.filter((trial) => trial.analysis).length,
mergedFindings: Array.from(byKey.values()),
qaTrials: withQa,
};
}, [versionTrials, checksFindings, foreignIds]);
// The rows handed to SeverityGroups carry only copy-safe fields — its
// per-item copy button serializes the row as-is, so the trial objects
// stay behind in the lookup map and the copy gets ids.
const findingItems = useMemo(
() =>
mergedFindings.map(({ fromAudit, trials: sources, ...item }) => ({
...item,
from_audit: fromAudit,
trial_ids: sources.map((t) => t.id),
})),
[mergedFindings],
);
const findingSourcesById = useMemo(
() => new Map(mergedFindings.map((f) => [f.id ?? "", f])),
[mergedFindings],
);
const foreignShownCount = useMemo(
() =>
foreignIds
? versionTrials.filter((trial) => foreignIds.has(trial.id)).length
: 0,
[foreignIds, versionTrials],
);
const taskTrialHref = (trial: Trial): string | null => {
if (!taskId) return null;
const params = new URLSearchParams();
if (trial.task_version_id) params.set("version", trial.task_version_id);
params.set("trial", trial.id);
return `/tasks/${taskId}?${params.toString()}`;
};
const openTrial = (trial: Trial) => {
// Trials from elsewhere open in a new tab; the drawer keeps its context.
if (foreignIds?.has(trial.id)) {
const href = taskTrialHref(trial);
if (href) window.open(href, "_blank", "noopener,noreferrer");
return;
}
if (onOpenTrial?.(trial)) return;
const href = taskTrialHref(trial);
if (href) router.push(href);
};
const renderFindingSources = (item: PreTrialFinding) => {
const sourced = findingSourcesById.get(item.id ?? "");
if (!sourced) return null;
if (!sourced.fromAudit && !(sourced.trials?.length > 0)) return null;
return (
<div className="mt-1 flex flex-wrap items-center gap-1.5">
<span className="text-muted-foreground shrink-0 font-mono text-[10px] tracking-widest">
SEEN IN
</span>
{sourced.fromAudit ? (
<span
className="border-border text-muted-foreground inline-flex items-center gap-1 rounded border px-1.5 py-0.5 font-mono text-[10px]"
title="Found by the pre-trial audit of the task's source"
>
<SearchCode className="h-3 w-3 shrink-0" aria-hidden="true" />
Source audit
</span>
) : null}
{(sourced.trials ?? []).map((trial) => {
const foreign = foreignIds?.has(trial.id) ?? false;
return (
<button
key={trial.id}
type="button"
onClick={() => openTrial(trial)}
className={cn(
"border-border text-muted-foreground hover:text-foreground hover:border-foreground/40 inline-flex min-w-0 max-w-full items-center gap-1 rounded border px-1.5 py-0.5 font-mono text-[10px] transition-colors",
foreign && "border-dashed",
)}
title={
foreign
? `Open trial ${trial.name} in a new tab — ran outside this experiment`
: `Open trial ${trial.name}`
}
>
<span className="min-w-0 truncate">{trialLabel(trial)}</span>
<ArrowUpRight className="h-3 w-3 shrink-0" aria-hidden="true" />
</button>
);
})}
</div>
);
};
const checkState = staticCheckState(checksStatus, checksFindings?.length ?? 0);
const checksStateUnknown = Boolean(checksLoading || checksLoadError);
// Only a live run blocks the button. A stale "queued" row must stay
// re-queueable: re-queue is the backend's recovery path for queued jobs
// that never got picked up.
const auditRunning = (checksStatus ?? "").toLowerCase() === "running";
const findingsSummary = checksLoading
? "Loading…"
: checksLoadError
? "Unavailable"
: checkState === "running"
? "Audit running…"
: mergedFindings.length > 0
? `${mergedFindings.length} finding${mergedFindings.length === 1 ? "" : "s"}${
checkState === "unaudited" ? " · audit not run" : ""
}`
: checkState === "failed"
? "Audit failed"
: checkState === "unaudited"
? "Audit not run"
: "Clean";
const findingsBody = () => {
if (checksLoading) {
return (
<div className="flex flex-col gap-2">
<Skeleton className="h-8 w-full rounded-lg" />
<Skeleton className="h-8 w-full rounded-lg" />
<Skeleton className="h-3 w-2/5" />
</div>
);
}
// The default tier copy narrates trial classification; these findings
// speak to the task itself.
const findingsList =
findingItems.length > 0 ? (
<SeverityGroups
items={findingItems}
tierEffects={{
must_fix:
"The defect can decide trials — QA marks the task bad until it is fixed.",
should_fix: "Does not change the verdict.",
optional: "Does not change the verdict.",
}}
renderItemFooter={renderFindingSources}
/>
) : null;
if (checksLoadError) {
// The audit state is unknown, but trial-side findings come from the
// trials endpoint — show what survives under the error.
return (
<>
<p className="font-mono text-[11px] break-all text-red-500">
{checksLoadError}
</p>
{findingsList}
</>
);
}
return (
<>
{checkState === "failed" ? (
<p className="font-mono text-[11px] break-all text-red-500">
{checksError || "The source audit failed."}
</p>
) : checkState === "running" && findingItems.length === 0 ? (
<div className="flex flex-col gap-2">
<Skeleton className="h-8 w-full rounded-lg" />
<Skeleton className="h-8 w-full rounded-lg" />
<Skeleton className="h-3 w-2/5" />
</div>
) : null}
{findingsList ? (
findingsList
) : checkState === "clean" ? (
<p className="text-muted-foreground text-sm leading-relaxed">
{analyzedCount > 0
? "The source audit and trial QA found no defects in this task."
: "The source audit found no defects in this task's source."}
</p>
) : checkState === "unaudited" ? (
<p className="text-muted-foreground text-sm leading-relaxed">
The source audit has not run on this version yet.
</p>
) : null}
</>
);
};
const trialQaBody = () => {
if (!versionKnown) {
// The scoping version hasn't resolved; aggregating now would span
// every version. On a dead /detail it never will — say so.
return checksLoadError ? (
<p className="font-mono text-[11px] break-all text-red-500">
Unable to resolve the task version to scope the trials.
</p>
) : (
<div className="flex flex-col gap-2">
<Skeleton className="h-8 w-full rounded-lg" />
<Skeleton className="h-8 w-full rounded-lg" />
<Skeleton className="h-3 w-2/5" />
</div>
);
}
// Without a host scope, the fetch defines the set — wait for it.
// Scoped rows render immediately (or fail into the honest states below).
if (displayTrials == null) {
return trialsError ? (
<p className="font-mono text-[11px] break-all text-red-500">
Unable to load the task's trials.
</p>
) : (
<div className="flex flex-col gap-2">
<Skeleton className="h-8 w-full rounded-lg" />
<Skeleton className="h-8 w-full rounded-lg" />
<Skeleton className="h-3 w-2/5" />
</div>
);
}
if (versionTrials.length === 0) {
// An empty scope while the host is still streaming its trial rows
// is not an answer yet.
if (scopeLoading) {
return (
<div className="flex flex-col gap-2">
<Skeleton className="h-8 w-full rounded-lg" />
<Skeleton className="h-8 w-full rounded-lg" />
<Skeleton className="h-3 w-2/5" />
</div>
);
}
return (
<p className="text-muted-foreground text-sm leading-relaxed">
{version != null
? `No trials for v${version} yet.`
: "No trials for this task yet."}
</p>
);
}
if (qaTrials.length === 0) {
return (
<p className="text-muted-foreground text-sm leading-relaxed">
Trial QA has not run yet. Run QA to classify this task's
trials and synthesize a verdict.
</p>
);
}
return (
<>
<div className="flex flex-wrap items-center gap-1.5">
{CLASSIFICATION_ORDER.map((classification) => {
const count = classificationCounts.get(classification);
if (!count) return null;
const token = VERDICT_TOKENS[classification] ?? FALLBACK_TOKEN;
const Icon = token.icon;
return (
<span
key={classification}
className={cn(
"inline-flex items-center gap-1 rounded border px-1.5 py-0.5 font-mono text-[10px]",
token.chip,
token.accent,
)}
>
<Icon className="h-3 w-3" aria-hidden="true" />
{count} {CLASSIFICATION_LABELS[classification].toLowerCase()}
</span>
);
})}
{unanalyzedCount > 0 ? (
<span className="text-muted-foreground font-mono text-[10px]">
{unanalyzedCount} not analyzed
</span>
) : null}
</div>
<div className="flex flex-col gap-1.5">
{qaTrials.map((trial) => (
<TrialQaRow
key={trial.id}
trial={trial}
foreign={foreignIds?.has(trial.id) ?? false}
onOpen={() => openTrial(trial)}
/>
))}
</div>
</>
);
};
return (
<div className={cn("flex flex-col", className)}>
{verdictTask ? (
<div className="border-border border-b p-4">
<TaskVerdictBadge task={verdictTask} variant="inline" />
</div>
) : null}
<div className="border-border flex flex-col gap-3 border-b p-4">
<div className="flex flex-wrap items-center gap-2">
<h2 className="text-muted-foreground font-mono text-[11px] font-semibold tracking-wider uppercase">
Findings
</h2>
<span className="text-muted-foreground font-mono text-[11px]">
{findingsSummary}
{!checksStateUnknown && hasDisplayableCostUsd(checksCostUsd)
? ` · ${formatCostUsd(checksCostUsd)}`
: ""}
</span>
<div className="ml-auto flex items-center gap-2">
{findingItems.length > 0 ? (
<CopyJsonButton
value={findingItems}
label="the task's findings"
/>
) : null}
<button
type="button"
disabled={checksRerunning || auditRunning || checksStateUnknown}
onClick={onRerunChecks}
className="text-muted-foreground hover:text-foreground border-border rounded border px-2 py-0.5 font-mono text-[10px] font-medium disabled:cursor-not-allowed disabled:opacity-50"
title="Runs the source audit on the task's current version"
>
{checksRerunning
? "Queuing…"
: checkState === "unaudited"
? "Run audit"
: "Re-run audit"}
</button>
</div>
</div>
{checksQueueError ? (
<p className="text-[11px] text-red-500">{checksQueueError}</p>
) : null}
{findingsBody()}
</div>
<div className="flex flex-col gap-3 p-4">
<div className="flex flex-wrap items-center gap-2">
<h2 className="text-muted-foreground font-mono text-[11px] font-semibold tracking-wider uppercase">
Trial QA
</h2>
<span className="text-muted-foreground font-mono text-[11px]">
{!versionKnown
? checksLoadError
? "Unavailable"
: "Loading…"
: displayTrials == null
? trialsError
? "Unavailable"
: "Loading…"
: versionTrials.length === 0 && scopeLoading
? "Loading…"
: `${analyzedCount}/${versionTrials.length} trial${
versionTrials.length === 1 ? "" : "s"
} analyzed${version != null ? ` · v${version}` : ""}${
foreignShownCount > 0
? ` · ${foreignShownCount} from outside this experiment`
: ""
}`}
</span>
</div>
{trialQaBody()}
</div>
</div>
);
}
function TrialQaRow({
trial,
foreign,
onOpen,
}: {
trial: Trial;
/** From outside the host's context. */
foreign?: boolean;
onOpen: () => void;
}) {
const analysis = trial.analysis;
const running = isActivePipelineStatus(trial.analysis_status);
const failed = !analysis && trial.analysis_status === "failed";
const token = analysis
? (VERDICT_TOKENS[analysis.classification] ?? FALLBACK_TOKEN)
: FALLBACK_TOKEN;
const Icon = token.icon;
const hasBody = Boolean(
analysis?.evidence || analysis?.root_cause || analysis?.recommendation,
);
const header = (
<>
{running ? (
<Loader2
className="h-3.5 w-3.5 shrink-0 animate-spin text-blue-500"
aria-hidden="true"
/>
) : (
<Icon
className={cn(
"h-3.5 w-3.5 shrink-0",
failed ? "text-red-500" : token.accent,
)}
aria-hidden="true"
/>
)}
<span
className={cn(
"shrink-0 font-mono text-[10px] font-semibold tracking-wider",
running ? "text-blue-500" : failed ? "text-red-500" : token.accent,
)}
>
{running
? "ANALYZING"
: failed
? "QA FAILED"
: analysis
? CLASSIFICATION_LABELS[analysis.classification].toUpperCase()
: "PENDING"}
</span>
{analysis?.subtype ? (
<span
className="text-muted-foreground min-w-0 truncate font-mono text-[10px]"
title={analysis.subtype}
>
{analysis.subtype}
</span>
) : null}
<span className="text-muted-foreground min-w-0 flex-1 truncate text-[11px]">
{trialLabel(trial)}
</span>
{foreign ? (
<span
className="border-border text-muted-foreground shrink-0 rounded border border-dashed px-1.5 py-0.5 font-mono text-[9.5px]"
title="This trial ran outside this experiment"
>
elsewhere
</span>
) : null}
<button
type="button"
onClick={(event) => {
event.preventDefault();
event.stopPropagation();
onOpen();
}}
className="border-border text-muted-foreground hover:text-foreground hover:border-foreground/40 inline-flex shrink-0 items-center gap-1 rounded border px-1.5 py-0.5 font-mono text-[10px] transition-colors"
title={
foreign
? `Open trial ${trial.name} in a new tab`
: `Open trial ${trial.name}`
}
>
View trial
<ArrowUpRight className="h-3 w-3" aria-hidden="true" />
</button>
</>
);
if (!hasBody) {
return (
<div className="border-border bg-background/40 flex items-center gap-2.5 rounded-lg border px-3 py-2">
{header}
{failed && trial.analysis_error ? (
<span className="text-muted-foreground truncate font-mono text-[10px]">
{trial.analysis_error}
</span>
) : null}
</div>
);
}
return (
<details className="group border-border bg-background/40 rounded-lg border">
<summary className="hover:bg-foreground/5 flex cursor-pointer list-none items-center gap-2.5 px-3 py-2 transition-colors select-none">
<span
aria-hidden="true"
className="text-muted-foreground text-[9px] transition-transform group-open:rotate-90"
>
▶
</span>
{header}
</summary>
<div className="border-border flex flex-col gap-2 border-t px-3 py-3">
{analysis?.root_cause ? (
<div className="flex items-baseline gap-2">
<span className="text-muted-foreground shrink-0 font-mono text-[10px] tracking-widest">
CAUSE
</span>
<AnalysisProse
text={analysis.root_cause}
className="text-foreground/90 min-w-0"
/>
</div>
) : null}
{analysis?.evidence ? (
<div className="flex items-baseline gap-2">
<span className="text-muted-foreground shrink-0 font-mono text-[10px] tracking-widest">
EVIDENCE
</span>
<AnalysisProse
text={analysis.evidence}
className="text-foreground/90 min-w-0"
/>
</div>
) : null}
{analysis?.recommendation ? (
<div className="flex items-baseline gap-2">
<span className="text-muted-foreground shrink-0 font-mono text-[10px] tracking-widest">
FIX
</span>
<AnalysisProse
text={analysis.recommendation}
className="text-foreground/90 min-w-0"
/>
</div>
) : null}
</div>
</details>
);
}