--- title: Workstreams --- ```js const API = "http://127.0.0.1:8000"; const POLL = 15_000; ``` ```js // Fetch workstreams + topics + summary (for dep graph) in parallel const wsState = (async function*() { while (true) { let data = [], openWs = [], ok = false; try { const [rw, rt, rs] = await Promise.all([ fetch(`${API}/workstreams/`), fetch(`${API}/topics/`), fetch(`${API}/state/summary`), ]); ok = rw.ok && rt.ok && rs.ok; if (ok) { const [wsList, topicList, summary] = await Promise.all([rw.json(), rt.json(), rs.json()]); const topicMap = Object.fromEntries(topicList.map(t => [t.id, t])); data = wsList.map(w => ({ ...w, domain: topicMap[w.topic_id]?.domain ?? "unknown", topic_title: topicMap[w.topic_id]?.title ?? "—", })); // open_workstreams from summary carry depends_on / blocks lists openWs = summary.open_workstreams ?? []; } } catch {} yield {data, openWs, ok, ts: new Date()}; await new Promise(res => setTimeout(res, POLL)); } })(); ``` ```js const data = wsState.data ?? []; const openWs = wsState.openWs ?? []; const _ok = wsState.ok ?? false; const _ts = wsState.ts; ``` ```js // ── Workstream Health Index (WHI) ──────────────────────────────────────────── const _idToDomain = Object.fromEntries(data.map(w => [w.id, w.domain ?? "unknown"])); const _completedIds = new Set(data.filter(w => w.status === "completed" || w.status === "archived").map(w => w.id)); const _openCount = openWs.length; const _allEdges = openWs.flatMap(w => w.depends_on.map(d => ({from: w.id, to: d.workstream_id}))); const _totalEdges = _allEdges.length; // Dependency Density const _DD = _openCount > 0 ? _totalEdges / _openCount : 0; // Blocked Ratio const _BR = _openCount > 0 ? openWs.filter(w => w.status === "blocked").length / _openCount : 0; // Single-Point Risk — max inbound edges on one incomplete workstream const _inbound = {}; for (const e of _allEdges) { if (!_completedIds.has(e.to)) _inbound[e.to] = (_inbound[e.to] ?? 0) + 1; } const _SPR = _openCount > 0 ? (Object.keys(_inbound).length > 0 ? Math.max(...Object.values(_inbound)) : 0) / _openCount : 0; // Parallel Execution Potential — active workstreams with all deps completed const _PEP = _openCount > 0 ? openWs.filter(w => w.status === "active" && w.depends_on.every(d => _completedIds.has(d.workstream_id))).length / _openCount : 0; // Cross-Domain Dependency Ratio const _crossEdges = _allEdges.filter(e => (_idToDomain[e.from] ?? "?") !== (_idToDomain[e.to] ?? "?")).length; const _CDDR = _totalEdges > 0 ? _crossEdges / _totalEdges : 0; // Cycle Presence Indicator — DFS with visited/inStack colouring function _detectCycle(nodes, edges) { const adj = Object.fromEntries(nodes.map(n => [n.id, []])); for (const e of edges) { if (adj[e.from] !== undefined) adj[e.from].push(e.to); } const visited = new Set(), inStack = new Set(); function dfs(id) { if (inStack.has(id)) return true; if (visited.has(id)) return false; visited.add(id); inStack.add(id); for (const nx of (adj[id] ?? [])) { if (dfs(nx)) return true; } inStack.delete(id); return false; } for (const n of nodes) { if (!visited.has(n.id) && dfs(n.id)) return 1; } return 0; } const _CPI = _detectCycle(openWs, _allEdges); // WHI aggregation — DD normalised at DD_critical = 1.0, CPI halves the score const _DDnorm = Math.min(1, _DD / 1.0); let _WHI = 0.30*(1 - _DDnorm) + 0.25*(1 - _BR) + 0.15*(1 - _SPR) + 0.20*_PEP + 0.10*(1 - _CDDR); if (_CPI === 1) _WHI *= 0.5; _WHI = Math.max(0, Math.min(1, _WHI)); // Per-domain breakdown — intra-domain edges only (measures domain autonomy) const _domainBreakdown = [...new Set(openWs.map(w => _idToDomain[w.id] ?? "unknown"))].sort().map(domain => { const nodes = openWs.filter(w => (_idToDomain[w.id] ?? "unknown") === domain); const edges = nodes.flatMap(w => w.depends_on .filter(d => (_idToDomain[d.workstream_id] ?? "unknown") === domain) .map(d => ({from: w.id, to: d.workstream_id})) ); const oc = nodes.length; if (oc === 0) return null; const te = edges.length; const dd = oc > 0 ? te / oc : 0; const br = oc > 0 ? nodes.filter(w => w.status === "blocked").length / oc : 0; const pep = oc > 0 ? nodes.filter(w => { if (w.status !== "active") return false; const intraDeps = w.depends_on.filter(d => (_idToDomain[d.workstream_id] ?? "unknown") === domain); return intraDeps.every(d => _completedIds.has(d.workstream_id)); }).length / oc : 0; const inb = {}; for (const e of edges) inb[e.to] = (inb[e.to] ?? 0) + 1; const spr = oc > 0 ? (Object.keys(inb).length > 0 ? Math.max(...Object.values(inb)) : 0) / oc : 0; const cpi = _detectCycle(nodes, edges); const ddN = Math.min(1, dd / 1.0); let whi = 0.30*(1 - ddN) + 0.25*(1 - br) + 0.15*(1 - spr) + 0.20*pep + 0.10; // CDDR=0 within domain if (cpi === 1) whi *= 0.5; return {domain, whi: Math.max(0, Math.min(1, whi)), br, pep, cpi, openCount: oc}; }).filter(Boolean); ``` # Workstreams ```js import {injectTocTop} from "./components/toc-sidebar.js"; import {withDocHelp} from "./components/doc-overlay.js"; // ── Live indicator ──────────────────────────────────────────────────────────── const _liveEl = html`
make api`}
No dependency edges recorded for the current filter. Use create_dependency() via the MCP server to link workstreams.