import { Alert, Button, Card, Checkbox, Group, PasswordInput, SegmentedControl, Select, Stack, Table, Text, TextInput, Title } from '@mantine/core'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { useState } from 'react'; import { api, unwrap } from '../../api/client'; import { useAutonomy, useConfig, useHealth, useKill, useUsers } from '../../api/hooks'; import { Can, ErrorAlert, fmtTs, pct, PageHeader } from '../../components/common'; import { DataTable } from '../../components/states'; import './admin.css'; export function KillSwitchPage() { const kill = useKill(); const health = useHealth(); const cfg = useConfig(); const qc = useQueryClient(); const [reason, setReason] = useState(''); const m = useMutation({ mutationFn: (engaged: boolean) => unwrap(api.POST('/api/kill-switch', { body: { engaged, reason } })), onSuccess: () => { qc.invalidateQueries({ queryKey: ['kill'] }); qc.invalidateQueries({ queryKey: ['runs'] }); }, }); const k = kill.data; const providers = (cfg.data?.providers ?? {}) as Record; return (
Emergency stop
{k?.engaged ? 'ENGAGED' : 'released'} {k?.engaged && {k.reason} - by {k.actor} since {fmtTs(k.since)}} Engaging stops the active run and its Playwright process tree, blocks all egress (pod, web, LLM, tickets) and refuses new runs. Also settable by creating var/KILL.
Admin only.}> setReason(e.currentTarget.value)} /> {k?.engaged ? : }
Providers and health Mock app: {health.data?.mock_up ? 'up' : 'DOWN'} - Ollama: {health.data?.ollama_up ? 'up' : 'off/down'} - frontier: {health.data?.frontier_configured ? 'configured' : 'not configured'} LLM routing: stub (always) - local: {String(providers.local ?? 'none')} - frontier: {String(providers.frontier ?? 'off')} - local model {String(cfg.data?.ollama_model ?? '')}
); } /** Settings > Health check: what a run needs, read-only. Every line says what is wrong and how to fix it. */ export function HealthCheckPanel() { const q = useQuery({ queryKey: ['health-readiness'], queryFn: () => unwrap(api.GET('/api/admin/readiness')), staleTime: 0 }); const items = q.data?.items ?? []; const bad = items.filter((i) => !i.ok).length; return (
Health check {q.isLoading ? 'Checking...' : q.data ? (bad ? `${bad} of ${items.length} checks need attention.` : 'All checks passed.') : 'Not checked.'} Read-only: nothing is sent to the pod or changed.
{items.map((i) => (
{i.label} {i.detail} {!i.ok && i.fix && Fix: {i.fix}} {i.ok ? 'OK' : 'Needs attention'}
))}
); } export function AutonomyPage() { const q = useAutonomy(); const qc = useQueryClient(); const m = useMutation({ mutationFn: ({ module, level }: { module: string; level: 'L0' | 'L1' | 'L2' }) => unwrap(api.PUT('/api/autonomy/{module}', { params: { path: { module } }, body: { level } })), onSettled: () => qc.invalidateQueries({ queryKey: ['autonomy'] }), }); return ( L0: humans approve every new/changed/generated case. L1: approved library cases and patch-touched cases auto-approve. L2: generated drafts too. Real-defect confirmation and tickets are never autonomous. Promotion is refused unless the metrics meet the thresholds; demotion is always allowed. {Object.entries(q.data ?? {}).map(([mod, a]) => ( {mod}{a.level} {a.metrics.n_approval_decisions} / {a.thresholds.min_labels} {pct(a.metrics.case_approval_rate)} (min {pct(a.thresholds.min_agreement)}) {pct(a.metrics.real_defect_recall)} (min {pct(a.thresholds.min_recall)}) L1 {a.can_promote.L1 ? 'yes' : 'no'} / L2 {a.can_promote.L2 ? 'yes' : 'no'} admin only}> m.mutate({ module: mod, level: v as 'L0' | 'L1' | 'L2' })} /> ))} ); } /** Scheduled runs (step 7): the same screen at /schedules, /admin/scheduler and Settings > Schedules. */ export { ScheduledRunsPage as SchedulerPage } from '../runs/ScheduledRunsPage'; export function UsersPage() { const q = useUsers(); const qc = useQueryClient(); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [role, setRole] = useState<'viewer' | 'consultant' | 'qa_approver' | 'admin'>('viewer'); const create = useMutation({ mutationFn: () => unwrap(api.POST('/api/users', { body: { username, password, role } })), onSuccess: () => { setUsername(''); setPassword(''); qc.invalidateQueries({ queryKey: ['users'] }); }, }); const update = useMutation({ mutationFn: ({ uid, body }: { uid: number; body: { role?: 'viewer' | 'consultant' | 'qa_approver' | 'admin'; disabled?: boolean } }) => unwrap(api.PATCH('/api/users/{uid}', { params: { path: { uid } }, body })), onSuccess: () => qc.invalidateQueries({ queryKey: ['users'] }), }); return ( People who sign themselves up start as viewers: they can read test runs and reports, but cannot start runs. Give them a role here. Roles: viewer (read), consultant (start test runs, approve scenarios, self-heal fixes, drafts), qa_approver (start test runs, decide on failures, waivers, owners, sign off reports), admin (everything, including the emergency stop, automatic approval, scheduled runs and users). {(q.data ?? []).map((u) => ( {u.username} setRole((v as typeof role) ?? 'viewer')} /> ); }