import { useCallback, useEffect, useState, type FormEvent } from 'react'; import { api } from '../api'; import { fmtId } from '../util'; import type { GraphNodeProjection, MissionProjection, MissionSession, MissionsResponse } from '../types'; export function Missions({ refreshTick = 0 }: { refreshTick?: number }) { const [data, setData] = useState(null); const [err, setErr] = useState(''); const [selected, setSelected] = useState(null); const [profileFilter, setProfileFilter] = useState<'all' | 'graph' | 'ordinary'>('all'); const load = useCallback(() => { api('/api/missions') .then((d) => { setData(d); setErr(''); setSelected((current) => current ?? d.sessions[0]?.id ?? null); }) .catch((e) => setErr((e as Error).message)); }, []); useEffect(() => { load(); }, [load, refreshTick]); if (err) return

Could not load Missions: {err}

; if (!data) return

Loading...

; const totals = summarize(data.missions); const graphMissions = data.missions.filter((mission) => mission.graph); const visibleSessions = data.sessions.map((session) => ({ ...session, missions: session.missions.filter((mission) => profileFilter === 'all' || (profileFilter === 'graph' ? Boolean(mission.graph) : !mission.graph)), })).filter((session) => session.missions.length > 0 || profileFilter === 'all'); const active = visibleSessions.find((s) => s.id === selected) ?? visibleSessions[0] ?? null; return ( <>

Durable AIWG Mission Control state and Agentic Sandbox fleet work share one projection. Cockpit observes the parent mission and its independently managed child workloads; the conductor remains the owner of policy and durability.

{data.count} total {totals.active} active {totals.awaiting} awaiting approval {totals.terminal} terminal {graphMissions.length} graph-profile
Run profile {(['all', 'graph', 'ordinary'] as const).map((filter) => )}
{profileFilter !== 'ordinary' && graphMissions.length > 0 && } session.source === 'aiwg-mc')} onChanged={load} /> {!visibleSessions.length ?

No runs match this profile filter.

: (
{active && }
)} ); } function GraphRuns({ missions }: { missions: MissionProjection[] }) { return

Flow / graph runs

Read-only ledger projection. Visual editing is intentionally deferred; raw route evidence is not rendered.

{missions.map((mission) =>

{mission.graph!.graph_id} run {fmtId(mission.graph!.run_id)}

{mission.graph!.graph_version ? `v${mission.graph!.graph_version} · ` : ''}{mission.status}{mission.graph!.replay_of_run_id ? ` · replay of ${fmtId(mission.graph!.replay_of_run_id)}` : ''}{mission.graph!.checkpoint_id ? ` · checkpoint ${fmtId(mission.graph!.checkpoint_id)}` : ''}

{!mission.graph_nodes?.length ?

Graph identity is present; node ledger data is not available yet.

: {mission.graph_nodes.map((node) => )}
{mission.graph_nodes.length} graph node(s)
NodeStateRuntime / routeHITL / retryCost / evidenceReplay lineage
}
)}
; } function GraphNodeRow({ node }: { node: GraphNodeProjection }) { return {node.node_id}{node.node_run_id && {fmtId(node.node_run_id)}} {node.runtime_binding}{node.route_reason ?? 'No route reason recorded'} {node.hitl_status ?? '-'}retries {node.retry_count ?? 0} ${(node.cost_usd ?? 0).toFixed(4)} · {node.tokens ?? 0} tokens{node.evidence_summary ?? 'No redacted evidence summary'} {node.replay_of_node_run_id ? `replay of ${fmtId(node.replay_of_node_run_id)}` : node.checkpoint_id ? `checkpoint ${fmtId(node.checkpoint_id)}` : '-'} ; } function MissionComposer({ sessions, onChanged }: { sessions: MissionSession[]; onChanged: () => void }) { const [sessionId, setSessionId] = useState(sessions[0]?.id ?? ''); const [objective, setObjective] = useState(''); const [completion, setCompletion] = useState(''); const [runNow, setRunNow] = useState(false); const [acceptCost, setAcceptCost] = useState(false); const [error, setError] = useState(''); const [busy, setBusy] = useState(false); useEffect(() => { if (!sessions.some((session) => session.id === sessionId)) setSessionId(sessions[0]?.id ?? ''); }, [sessions, sessionId]); if (!sessions.length) return

Create a Mission Control session with aiwg mc start before dispatching from Cockpit.

; const selected = sessions.find((session) => session.id === sessionId) ?? sessions[0]!; const submit = async (event: FormEvent) => { event.preventDefault(); setBusy(true); setError(''); try { await api('/api/missions', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ session_id: selected.id, objective, completion, expected_updated_at: selected.updated_at, request_id: globalThis.crypto?.randomUUID?.() ?? `cockpit-${Date.now()}`, run: runNow, accept_cost: acceptCost, }), }); setObjective(''); setCompletion(''); onChanged(); } catch (caught) { setError(`Mission dispatch failed: ${(caught as Error).message}`); } finally { setBusy(false); } }; return
{runNow && } {error &&

{error}

}
; } function MissionSessionView({ session, onChanged }: { session: MissionSession; onChanged: () => void }) { const fleet = session.source === 'agentic-sandbox-fleet'; const controllable = session.source === 'aiwg-mc'; const [mutationError, setMutationError] = useState(''); const [mutating, setMutating] = useState(''); const mutate = async (action: 'pause' | 'resume' | 'cancel', missionId?: string) => { setMutating(`${action}:${missionId ?? session.id}`); setMutationError(''); const path = action === 'cancel' ? `/api/missions/${encodeURIComponent(session.id)}/${encodeURIComponent(missionId!)}/cancel` : `/api/missions/${encodeURIComponent(session.id)}/${action}`; try { await api(path, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ expected_updated_at: session.updated_at, request_id: globalThis.crypto?.randomUUID?.() ?? `cockpit-${Date.now()}`, }), }); onChanged(); } catch (error) { setMutationError(`Mission control failed: ${(error as Error).message}. Refresh and retry if the state changed elsewhere.`); } finally { setMutating(''); } }; return (

{session.name}

{fleet && session.parent_mission_id ? `Parent mission ${session.parent_mission_id} · ` : ''} {session.source} · {session.state} {session.inventory_revision !== undefined ? ` · inventory r${session.inventory_revision}` : ''} {session.updated_at ? ` · updated ${new Date(session.updated_at).toLocaleString()}` : ''}

{session.audit_count} audit events {controllable && session.state === 'active' && } {controllable && session.state === 'paused' && }
{mutationError &&

{mutationError}

} {!session.missions.length ?

This session has no missions.

: ( {fleet ? : } {session.missions.map((m) => ( {fleet ? <> : <> } ))}
{session.missions.length} mission projection(s)
Child workloadStatusTarget / runtimeBindingEvidence
MissionStatusSourceLoopBacking
{m.title} {fleet && {workloadSemantics(m)}} {m.completion && Done when: {m.completion}} {m.error && {m.error}} {controllable && !m.terminal && m.status !== 'aborted' && m.status !== 'failed' && m.status !== 'completed' && m.status !== 'done' && ( )} {m.health && health: {m.health}} {m.backpressure && backpressure: {m.backpressure.reason}{m.backpressure.retryable ? ' · retryable' : ' · operator action'}} {m.target_id ?? '-'}{m.executor_id ?? '-'} / {m.runtime_id ?? '-'} {fleetBinding(m)}revision {m.revision ?? 0}{m.last_seen ? ` · ${new Date(m.last_seen).toLocaleString()}` : ''} {fleetEvidence(m)}{m.source} {loopText(m)} {backingText(m)}
)} {session.audit_tail.length > 0 && (

Audit Tail

{session.audit_tail.map((event, i) => (

{event.ts ? new Date(event.ts).toLocaleTimeString() : 'event'} {' '}{String(event.event ?? 'mission_event')} {event.missionId || event.mission_id ? <> · {fmtId(String(event.missionId ?? event.mission_id))} : null}

))}
)}
); } function workloadSemantics(mission: MissionProjection) { if (mission.workload_kind === 'daemon') return `daemon health · desired ${mission.desired_state ?? 'unknown'}`; if (mission.workload_kind === 'persistent-agent') return `persistent retention · desired ${mission.desired_state ?? 'unknown'}`; if (mission.workload_kind === 'scheduled-collector') return `scheduled collection${mission.schedule ? ` · ${mission.schedule}` : ''}`; if (mission.workload_kind === 'one-shot-command') return `one-shot terminal result · desired ${mission.desired_state ?? 'unknown'}`; return mission.workload_kind ?? 'fleet workload'; } function fleetBinding(mission: MissionProjection) { const bindings = [ mission.runtime_session_id && `session ${fmtId(mission.runtime_session_id)}`, mission.task_id && `task ${fmtId(mission.task_id)}`, mission.command_id && `command ${fmtId(mission.command_id)}`, ].filter(Boolean); return bindings.length ? bindings.join(' · ') : 'binding pending'; } function fleetEvidence(mission: MissionProjection) { if (!mission.artifacts?.length) return No artifacts yet; return
    {mission.artifacts.map((artifact) => (
  • {safeArtifactHref(artifact.uri) ? {artifact.kind} : {artifact.kind}} {artifact.sha256.slice(0, 12)} · {artifact.uri}
  • ))}
; } function safeArtifactHref(uri: string) { try { return ['http:', 'https:'].includes(new URL(uri).protocol); } catch { return false; } } function summarize(missions: MissionProjection[]) { return missions.reduce((acc, mission) => { if (mission.status === 'awaiting-approval' || mission.status === 'input-required' || mission.backpressure?.reason === 'approval') acc.awaiting += 1; if (mission.terminal) acc.terminal += 1; else acc.active += 1; return acc; }, { active: 0, awaiting: 0, terminal: 0 }); } function statusClass(status: string) { return status.replace(/[^a-z0-9_-]/gi, '-'); } function loopText(mission: MissionProjection) { if (mission.loop === undefined && !mission.max_iterations) return '-'; return `${mission.loop ?? 0}/${mission.max_iterations ?? '?'}`; } function backingText(mission: MissionProjection) { if (mission.transport === 'uhp') return `UHP ${mission.endpoint_profile ?? 'profile unknown'} · ${mission.protocol_version ?? 'version unknown'}`; if (mission.transport === 'a2a') return `A2A${mission.task_id ? ` ${fmtId(mission.task_id)}` : ''}`; if (mission.ralph_loop_id) return `Ralph ${fmtId(mission.ralph_loop_id)}`; if (mission.task_id && mission.instance_id) return `${fmtId(mission.instance_id)} / ${fmtId(mission.task_id)}`; if (mission.target_agent) return fmtId(mission.target_agent); return '-'; }