Files
skills/orchestrator/templates/page-spawn.js
T
Kevin Veen-BirkenbachandClaude Opus 5.5 90c56cb786 feat(orchestrator): Agents and Artifacts views with spawn tree, orbit, 3D and signed branch deletes
Phase 4 of requirement 001. Agents and Artifacts each offer Orbit, Chord, Swimlane, Tree and 3D: the spawn tree (page-spawn.js) and the artifacts orbit (page-artifacts.js, kvb_orchestrator/artifacts.py) replace the "folgt" placeholders, 3D runs on the vendored 3d-force-graph and three.js (MIT, LICENSE files kept, served from the image under the unchanged CSP), and a Bootstrap Icons sprite (icons.py, MIT) replaces the emoji glyphs, also in the meditation page.

Signed branch deletes: the Tree view offers a delete only for merged-clean branches without a gc skip reason; the operator signs the exact item with the passkey, the hub writes a job without any command (kvb_orchestrator/cleanup.py), and the host path unit runs client/cleanup.py, which verifies the signature, dry-runs pkgmgr branch cleanup for that exact branch, refuses patterns, option names, changed tips, other worktrees and plans naming other branches, deletes, and rewrites the branch tree. pkgmgr runs with core.hooksPath=/dev/null, core.fsmonitor=false and the config hook events disabled through GIT_CONFIG_COUNT, because the cwd is a repository agents can write and pkgmgr releases before 4c8b137 delete without scan mode (test with a positive control that both hook kinds fire without it).

3D labels go into the tooltip as a text node: the vendored tooltip renders a string label as HTML.

Tests: 503 OK, Chromium (CDP) and Firefox (BiDi) walks over every screen at three widths.

MEDUSA acceptances (kvb-think-criticize skeptic 2026-11-07): WEB-FLASK-004 view.py:135 (file template, autoescape on, state via tojson), MEDUSA-MM-SCAN-058 server.py:69/:85 (substring pla in --templates and Places), RH005 client/cleanup.py:199 (raise SystemExit(main())), B704 icons.py:45 (sprite baked into the image, names checked against it), EXA002 page-artifacts.js:221 (openAgent only opens the drawer), STG002 page-constants.js:64 (U+2212 in a static label), PL002 page-graph3d.js:44 (CSS class space-tools; the real tooltip sink fixed), B603 client/cleanup.py:75 (argv without shell; hook hole closed).

🎯 Fix: 92 %
💥 Break: 5 %
💸 Cost: 100 %
⏱️ Time: –
🛡️ Security: 100 %
🏆 Score: 87
🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 %

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 15:03:14 +00:00

122 lines
5.1 KiB
JavaScript

const spawn = {subs: new Map(), loading: false, dom: null};
const SPAWN_KINDS = {operator: "bi-person-circle", chair: "bi-award", session: "bi-robot", subagent: "bi-cpu", twig: "bi-cpu"};
function sessionRunning(node) {
const life = (spawn.subs.get(node.id) || {}).data;
if (life && life.died) {
return false;
}
return node.claims.some((claim) => claim.beat !== null && claim.beat >= state.now - ACTIVE_BEAT);
}
function twigs(session) {
const data = (spawn.subs.get(session) || {}).data;
const rows = data ? data.subagents : [];
const roots = [];
const open = [];
for (const row of rows) {
const twig = {id: `${session}/${row.id}`, kind: "twig", label: `${row.type}: ${row.description}`, running: !row.finished, row, session, children: []};
open.length = Math.min(open.length, Math.max(row.depth - 1, 0));
(open.length ? open[open.length - 1].children : roots).push(twig);
open.push(twig);
}
return roots;
}
function spawnTree() {
const nodes = state.graph.nodes;
const chair = nodes.find((node) => node.kind === "chair");
const entry = (node) => ({
id: node.id, kind: node.kind, label: node.label, node,
running: node.kind === "operator" ? null : node.kind === "subagent" ? node.tasks.some((task) => task.status === "running") : sessionRunning(node),
children: [],
});
const root = entry(nodes.find((node) => node.kind === "operator"));
const byId = new Map([[root.id, root]]);
if (chair) {
byId.set(chair.id, entry(chair));
root.children.push(byId.get(chair.id));
}
for (const node of nodes.filter((item) => item.kind === "session")) {
byId.set(node.id, entry(node));
(byId.get(chairKey()) || root).children.push(byId.get(node.id));
}
for (const node of nodes.filter((item) => item.kind === "subagent")) {
(byId.get(node.parent) || byId.get(chairKey()) || root).children.push(entry(node));
}
for (const [id, held] of byId) {
if (held.kind === "session" || held.kind === "chair") {
held.children.push(...twigs(id));
}
}
return root;
}
function spawnFlat(root) {
const found = [];
const walk = (entry, depth, parent) => {
found.push({entry, depth, parent});
entry.children.forEach((child) => walk(child, depth + 1, entry));
};
walk(root, 0, null);
return found;
}
async function loadSpawn() {
if (spawn.loading) {
return;
}
const due = state.graph.nodes.filter((node) => (node.kind === "session" || node.kind === "chair") && SESSION_ID.test(node.id))
.filter((node) => !spawn.subs.has(node.id) || Date.now() - spawn.subs.get(node.id).at > SUBS_TTL);
if (!due.length) {
return;
}
spawn.loading = true;
await Promise.all(due.map(async (node) => {
let data = null;
try {
const response = await fetch(`/api/subagents?session=${encodeURIComponent(node.id)}`, {cache: "no-store"});
data = response.ok ? await response.json() : null;
} catch {
data = null;
}
spawn.subs.set(node.id, {at: Date.now(), data});
}));
spawn.loading = false;
drawSpawn();
stage();
}
function spawnItem(entry) {
const running = entry.running === null ? null : entry.running ? chip("bi-play-circle", "läuft", "ok") : chip("bi-check-circle", "fertig", "neutral");
const open = entry.kind === "twig" ? () => focusSub(entry.session, entry.row.id) : entry.kind === "operator" ? null : () => select(entry.id);
const name = open ? h("button", {type: "button", class: "linkish", title: entry.kind === "twig" ? "Transkript im Stream zeigen" : `${entry.label} öffnen`, on: {click: open}}, entry.label) : h("strong", {}, entry.label);
const meta = entry.kind === "twig" ? h("span", {class: "muted"}, `Tiefe ${entry.row.depth} · `, when(entry.row.started)) : h("span", {class: "muted"}, NODE_KINDS[entry.kind]);
return h("li", {"data-kind": entry.kind, "data-running": entry.running === null ? null : String(entry.running)},
h("div", {class: "spawn-row"}, h("span", {class: "state", role: "img", ...named(NODE_KINDS[entry.kind] || "Subagent")}, icon(SPAWN_KINDS[entry.kind])), name, running, meta),
entry.children.length ? h("ul", {class: "spawn-tree"}, entry.children.map(spawnItem)) : null);
}
function spawnScreen() {
const list = h("div", {class: "card spawn"});
spawn.dom = {list};
window.setTimeout(() => {
drawSpawn();
loadSpawn();
}, 0);
return list;
}
function drawSpawn() {
if (!spawn.dom || !spawn.dom.list.isConnected) {
spawn.dom = null;
return;
}
const root = spawnTree();
const all = spawnFlat(root).map(({entry}) => entry).filter((entry) => entry.running !== null);
const running = all.filter((entry) => entry.running).length;
spawn.dom.list.replaceChildren(
h("div", {class: "inbox-head"}, h("h2", {class: "group-title"}, "Spawn-Baum", counter(all.length)), h("span", {class: "muted"}, `${running} laufen · ${all.length - running} fertig · Operator → Chair → Sessions → Subagenten`)),
h("ul", {class: "spawn-tree root"}, spawnItem(root)));
}