import { useState } from "react"; import { Link } from "react-router"; import { api, ApiError, type PackageRow, type Project } from "../api"; import { useFetch, fmtDate } from "../hooks"; import { Badge, Empty, ErrorBox, Loading, Td } from "../components/ui"; import { useMe } from "../App"; type Decision = { id: string; execution_id: string | null; project_id: string; mode: string; decision: string; reasons: string[]; checks: Record; created_at: string; project_slug: string; url: string | null; method: string | null; state: string | null }; type Egress = { id: number; ts: string; host: string; port: number; decision: string; execution_id: string | null; client: string | null; reason: string | null }; const MODES = ["discovery", "development", "research", "production"]; export default function Policy() { const { me } = useMe(); const projects = useFetch<{ projects: Project[] }>("projects"); const pkgs = useFetch<{ packages: PackageRow[] }>("akps"); const [filter, setFilter] = useState(""); const decisions = useFetch<{ decisions: Decision[]; summary: { mode: string; decision: string; n: number }[]; modes: Record }>(`policy/decisions?limit=100${filter ? `&decision=${filter}` : ""}`); const egress = useFetch<{ egress: Egress[] }>("egress?limit=100"); const [err, setErr] = useState(null); const canWrite = me?.role === "admin" || me?.role === "operator"; const patch = async (id: string, body: Record) => { setErr(null); try { await api(`projects/${id}`, { method: "PATCH", body }); projects.reload(); } catch (e) { setErr(e as ApiError); } }; const approvable = pkgs.data?.packages.filter((p) => ["tested", "registered", "monitored"].includes(p.lifecycle)) ?? []; return (

Policy Center

Policy modes

{decisions.data ?
{Object.entries(decisions.data.modes).map(([m, d]) =>
{d}
)}
: }

Projects

{projects.loading && } {projects.data && {projects.data.projects.map((p) => )}
ProjectModeApproved AKPs (production)Budget / dayExecutions 24 h
{p.name} {p.slug} {canWrite ? : } {canWrite ? : p.approved_akps.length} {approvable.length === 0 &&
no tested packages yet
}
{p.budget?.max_executions_per_day ?? "—"}{p.executions_24h ?? 0}
}

Decision log

{decisions.data &&
{decisions.data.summary.map((s) => {s.mode}/{s.decision}: {s.n})}
} {decisions.loading && } {decisions.data && decisions.data.decisions.length === 0 && No policy decisions recorded.} {decisions.data && decisions.data.decisions.length > 0 && {decisions.data.decisions.map((d) => )}
WhenProjectModeDecisionRequestReasons
{d.execution_id ? {fmtDate(d.created_at)} : fmtDate(d.created_at)}{d.project_slug}{d.mode}{d.method} {d.url}{d.reasons.join("; ")}
}

Egress proxy log (sandboxed workers)

{egress.loading && } {egress.data && egress.data.egress.length === 0 && No proxy traffic yet. Sandboxed runs reach the network only through the egress proxy.} {egress.data && egress.data.egress.length > 0 && {egress.data.egress.map((g) => )}
WhenHostDecisionReasonExecution
{fmtDate(g.ts)}{g.host}:{g.port}{g.reason}{g.execution_id ? {g.execution_id.slice(0, 8)} : "—"}
}
); }