--- title: Interventions --- ```js const API = "http://127.0.0.1:8000"; const POLL = 15_000; ``` ```js // Live poll: all tasks (filtered client-side) + workstreams + topics const interventionState = (async function*() { while (true) { let tasks = [], wsMap = {}, ok = false; try { const [rt, rw, rto, rr] = await Promise.all([ fetch(`${API}/tasks/?limit=500`), fetch(`${API}/workstreams/`), fetch(`${API}/topics/`), fetch(`${API}/repos/`), ]); ok = rt.ok && rw.ok && rto.ok && rr.ok; if (ok) { const [taskList, wsList, topicList, repoList] = await Promise.all([ rt.json(), rw.json(), rto.json(), rr.json(), ]); const topicMap = Object.fromEntries(topicList.map(t => [t.id, t])); const repoMap = Object.fromEntries(repoList.map(r => [r.id, r])); wsMap = Object.fromEntries(wsList.map(w => [w.id, { ...w, domain: repoMap[w.repo_id]?.domain_slug ?? topicMap[w.topic_id]?.domain_slug ?? "unknown", }])); tasks = taskList.map(t => ({ ...t, workstream_title: wsMap[t.workstream_id]?.title ?? "—", domain: wsMap[t.workstream_id]?.domain ?? "unknown", })); } } catch {} yield {tasks, ok, ts: new Date()}; await new Promise(res => setTimeout(res, POLL)); } })(); ``` ```js const tasks = interventionState.tasks ?? []; const _ok = interventionState.ok ?? false; const _ts = interventionState.ts; ``` ```js const OPEN_STATUSES = new Set(["todo", "in_progress", "blocked"]); // open = currently flagged for human action // closed = previously flagged (intervention_note records the resolution comment) const open = tasks.filter(t => t.needs_human === true); const closed = tasks.filter(t => t.intervention_note && !OPEN_STATUSES.has(t.status) && !t.needs_human); // Domain breakdown for top-3 const domainCounts = {}; for (const t of open) { domainCounts[t.domain] = (domainCounts[t.domain] ?? 0) + 1; } const top3Domains = Object.entries(domainCounts) .sort((a, b) => b[1] - a[1]) .slice(0, 3); const critHighCount = open.filter(t => t.priority === "critical" || t.priority === "high").length; ``` # Interventions ```js import {injectTocTop} from "./components/toc-sidebar.js"; import {withDocHelp} from "./components/doc-overlay.js"; // ── KPI sidebar card ────────────────────────────────────────────────────────── const _kpiBox = html`
Interventions
open
${open.length}
critical / high
${critHighCount}
${top3Domains.map(([domain, count]) => html`
${domain}
${count}
`)}
`; // ── Live indicator ──────────────────────────────────────────────────────────── const _liveEl = html`
${_ok ? `Live · updated ${_ts?.toLocaleTimeString()}` : html`Offline — run: make api`}
`; withDocHelp(_liveEl, "/docs/live-data"); injectTocTop("intervention-kpi-box", _kpiBox); injectTocTop("live-indicator", _liveEl); const _h1 = document.querySelector("#observablehq-main h1"); if (_h1) { _h1.style.position = "relative"; withDocHelp(_h1, "/docs/interventions"); } ``` Tasks flagged `needs_human=true` — actions only a human can take. --- ## Open ```js import {openActionConfirm} from "./components/action-confirm.js"; const PRIORITY_ORDER = {critical: 0, high: 1, medium: 2, low: 3}; const STATUS_ORDER = {blocked: 0, in_progress: 1, todo: 2}; function sortTasks(arr) { return [...arr].sort((a, b) => { const pd = (PRIORITY_ORDER[a.priority] ?? 9) - (PRIORITY_ORDER[b.priority] ?? 9); if (pd !== 0) return pd; return (STATUS_ORDER[a.status] ?? 9) - (STATUS_ORDER[b.status] ?? 9); }); } function renderCard(t) { const isOpen = OPEN_STATUSES.has(t.status); const borderColor = isOpen ? "#f59e0b" : "#22c55e"; function onMarkDone() { openActionConfirm({ title: "Mark Intervention as Done", entityTitle: t.title, label: "Resolution comment", placeholder: "What was done to resolve this?", confirmLabel: "Mark Done", onConfirm: async (comment) => { const res = await fetch(`${API}/tasks/${t.id}/`, { method: "PATCH", headers: {"Content-Type": "application/json"}, body: JSON.stringify({status: "done", needs_human: false, intervention_note: comment}), }); if (!res.ok) throw new Error(`API error ${res.status}`); }, }); } return html`
${t.priority} ${t.status.replace("_", " ")} ${t.domain} ${t.workstream_title} ${isOpen ? html`` : ""}
${t.intervention_note ?? "(no note)"}
${t.title !== t.intervention_note ? html`
Task: ${t.title}${t.description ?? ""}
` : ""}
`; } if (open.length === 0) { display(html`

No open interventions — you're clear! ✓

`); } else { display(html`
${sortTasks(open).map(renderCard)}
`); } ``` --- ## Completed / Cancelled ```js if (closed.length === 0) { display(html`

No completed interventions yet.

`); } else { display(html`
${[...closed].reverse().map(renderCard)}
`); } ```