import { PREPARE_NODES } from './RunGuide'; import { useWaitsOnMe, waitingForWords } from '../../domain/waiting'; import { Anchor, Button, Group, Stack, Text, Textarea } from '@mantine/core'; import { IconExternalLink, IconFileTypePdf, IconHandStop, IconMessage, IconRobot, IconSend } from '@/components/icons'; import { useMutation, useQueryClient } from '@tanstack/react-query'; import { useMemo, useState } from 'react'; import { Link } from 'react-router-dom'; import { AGENT_BY_NODE, stepName } from '../../domain/agents'; import { shortWhenSec } from '../../domain/runName'; import { api, unwrap } from '../../api/client'; import { useGraphSpec, useReport, useRun, useRunReadiness, useTemporal } from '../../api/hooks'; import { decisionWords, plainReason } from '../../domain/glossary'; import { ModuleCard, PatchChanges } from '../home/ReadinessPage'; import { Can, ErrorAlert, fmtTs, Pill } from '../../components/common'; import { GraphView } from '../../components/GraphView'; import { nodeStates, useRunStream, type RunEvent } from '../../hooks/useRunStream'; export const TERMINAL = ['completed', 'failed', 'killed', 'cancelled']; const HIDDEN_KEYS = new Set(['node', 'traceback', 'audit_seq', 'keys', 'module', 'message']); // an agent's message is shown in full const fmtKey = (k: string) => k.replace(/^n_/, '').replace(/_/g, ' '); const fmtVal = (k: string, v: unknown) => (k === 'ms' && typeof v === 'number' ? `${(v / 1000).toFixed(1)} s` : v); // The detail views of a test run (the former tabs). The run workspace (RunWorkspace.tsx) shows them in its center. /** Compact, human-readable rendering of a node's event summary (scalars as pills, lists as counts or short joins). */ function SummaryPills({ summary }: { summary: Record }) { const entries = Object.entries(summary ?? {}).filter(([k, v]) => !HIDDEN_KEYS.has(k) && v !== null && v !== undefined && v !== '') .map(([k, v]) => [k === 'ms' ? 'took' : fmtKey(k), fmtVal(k, v)] as [string, unknown]) .sort(([a], [b]) => (a === 'took' ? 1 : b === 'took' ? -1 : 0)); if (!entries.length) return null; return ( {entries.slice(0, 12).map(([k, v]) => { let text: string; if (Array.isArray(v)) text = v.length <= 4 && v.every((x) => typeof x !== 'object') ? v.join(', ') || 'none' : `${v.length}`; else if (typeof v === 'object') text = Object.entries(v as Record).slice(0, 4).map(([a, b]) => `${a} ${typeof b === 'object' ? '…' : String(b)}`).join(' · '); else text = String(v); return {k} {text.length > 60 ? `${text.slice(0, 60)}…` : text}; })} ); } export function FeedCard({ e }: { e: RunEvent }) { const a = e.node ? AGENT_BY_NODE[e.node] : undefined; const tone = e.kind === 'error' || e.kind === 'killed' ? 'red' : e.kind === 'interrupted' ? 'amber' : a?.tone ?? 'neutral'; if (e.kind === 'note') { return (
{String(e.summary.by ?? 'someone')}· note · {shortWhenSec(e.ts)}
{String(e.summary.text ?? '')}
); } if (!e.node) { return (
Coordinator · {e.kind}{typeof e.summary?.status === 'string' ? `: ${String(e.summary.status).replace('_', ' ')}` : ''}{typeof e.summary?.message === 'string' ? ` · ${e.summary.message}` : ''} · {shortWhenSec(e.ts)}
); } const verb = e.kind === 'finished' ? 'finished' : e.kind === 'interrupted' ? 'paused for a human' : e.kind === 'error' ? 'failed' : e.kind === 'message' || e.kind === 'ai_scenarios' ? 'says' : e.kind; return (
{stepName(e.node)}{typeof e.summary?.module === 'string' ? ` · ${e.summary.module}` : ''} run by Coordinator · {verb} · {shortWhenSec(e.ts)}
{typeof e.summary?.message === 'string' && {e.summary.message}}
); } function GateCard({ id, gate }: { id: string; gate: string }) { if (gate === 'sign_in') { return (
Sign-in needed· a person signs in to the pod before the tests run
); } const tab = gate === 'approve_cases' ? 'scenarios' : 'failures'; return (
Waiting for your review · {gate === 'approve_cases' ? 'approve the scenarios for this patch' : 'judge the failures (real defect, not a defect, expected change)'}
); } export function NoteBox({ id }: { id: string }) { const [text, setText] = useState(''); const qc = useQueryClient(); const send = useMutation({ mutationFn: () => unwrap(api.POST('/api/runs/{run_id}/notes', { params: { path: { run_id: id } }, body: { text } })), onSuccess: () => { setText(''); qc.invalidateQueries({ queryKey: ['run', id] }); }, }); return (