feat(orchestrator): draw agents and chairs as a matrix organigram
The agents hierarchy gains a matrix org chart: agents as columns, chairs as rows, so one agent with several chairs shows every one of them; a Home tile can pin it. Tests run once on unify/skills-20261114 after the merge (operator order 2026-11-14). 🎯 Fix: 82 % 💥 Break: 8 % 💸 Tokens: 90 % ⏱️ Velocity: 90 % 🛡️ Security: 100 % 🏆 Score: 93 🚦 Gate: ⛔ fix 82 % < 90, break 8 % > 5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
48f26b678a
commit
2b4c3baaa0
8 files changed
+641
-68
No files matched your search
@@ -1,6 +1,7 @@
|
||||
const hier = {chart: null, sig: "", closed: new Set(), ids: 0};
|
||||
const OFFICE_ICONS = {chair: "bi-award", line: "bi-person-badge", cluster: "bi-collection", work: "bi-briefcase", other: "bi-signpost-split"};
|
||||
const OFFICE_GROUPS = [["cluster", "Organizers", "Organizer"], ["work", "Presidents", "President"], ["other", "Other offices", "Office"]];
|
||||
const OFFICE_TITLES = {chair: "Chair", line: "Domain chair", work: "President", cluster: "Organizer", other: "Office"};
|
||||
const UNIT_ICONS = {dimension: "bi-diagram-2", work: "bi-briefcase"};
|
||||
|
||||
function hierarchyScreen() {
|
||||
hier.chart = h("section", {class: "card org-chart", "data-panel": "agents/hierarchy", "aria-labelledby": "org-title"});
|
||||
@@ -12,7 +13,7 @@
|
||||
|
||||
function hierarchySig() {
|
||||
const held = state.claims.map((claim) => [claim.office, claim.session, claim.agent, claim.work, claim.beat !== null && claim.beat >= state.now - ACTIVE_BEAT]);
|
||||
return JSON.stringify([held, state.agent_order, state.people, state.presence, [...look.hidden]]);
|
||||
return JSON.stringify([held, Organigram.dotted(state.claims, state.tasks), state.agent_order, state.people, state.presence, [...look.hidden]]);
|
||||
}
|
||||
|
||||
function drawHierarchy(force) {
|
||||
@@ -51,38 +52,14 @@
|
||||
return claim.agent || (claim.session === "-" ? "" : claim.session);
|
||||
}
|
||||
|
||||
function officeRow(claim, label, title) {
|
||||
const who = holderOf(claim);
|
||||
const active = claim.beat !== null && claim.beat >= state.now - ACTIVE_BEAT;
|
||||
return h("div", {class: "org-row", "data-office": claim.office},
|
||||
h("span", {class: "org-office", title: `${title} ${claim.office}`}, icon(OFFICE_ICONS[claim.kind]), h("strong", {}, label)),
|
||||
who ? h("button", {type: "button", class: "linkish org-holder", "data-focus": `agent:${claim.office}`, title: `Open ${who}`, on: {click: () => openAgent(who, near(`#main [data-focus="agent:${CSS.escape(claim.office)}"]`))}}, face(who, false), who) : h("span", {class: "muted"}, "–"),
|
||||
claim.session === "-" ? null : presenceMark(claim.session, false),
|
||||
active ? chip("bi-play-circle", "active", "ok") : chip("bi-pause-circle", "no heartbeat", "neutral"),
|
||||
claim.work && claim.work !== "-" ? h("span", {class: "muted org-work", title: claim.work}, short(claim.work)) : null,
|
||||
h("span", {class: "org-actions"},
|
||||
officeBtn("bi-arrow-left-right", "Hand over", `Hand over: ${claim.office} to another session, with a passkey signature`, () => officeSheet("takeover", claim), `takeover:${claim.office}`),
|
||||
officeBtn("bi-person-x", "Recall", `Recall: free ${claim.office}, with a passkey signature`, () => officeSheet("recall", claim), `recall:${claim.office}`)));
|
||||
}
|
||||
|
||||
function vacantRow(office, label) {
|
||||
return h("div", {class: "org-row vacant", "data-office": office},
|
||||
h("span", {class: "org-office"}, icon(OFFICE_ICONS.chair), h("strong", {}, label)),
|
||||
pill("vacant", "warn"),
|
||||
h("span", {class: "org-actions"}, officeBtn("bi-person-plus", "Appoint", `Appoint: give ${office} to a session, with a passkey signature`, () => officeSheet("appoint", {office, session: "", work: ""}), `appoint:${office}`)));
|
||||
}
|
||||
|
||||
function groupRow(glyph, label, count, note) {
|
||||
return h("div", {class: "org-row group"}, h("span", {class: "org-office"}, icon(glyph), h("strong", {}, label)), counter(count), h("span", {class: "muted"}, note));
|
||||
}
|
||||
|
||||
function orgNode(id, label, row, children) {
|
||||
if (!children.length) {
|
||||
return h("li", {}, h("div", {class: "org-line"}, h("span", {class: "org-gap", "aria-hidden": "true"}), row));
|
||||
}
|
||||
const open = !hier.closed.has(id);
|
||||
function nextOrgId() {
|
||||
hier.ids += 1;
|
||||
const list = h("ul", {class: "org-tree", id: `org-${hier.ids}`, hidden: !open}, children);
|
||||
return `org-${hier.ids}`;
|
||||
}
|
||||
|
||||
function folder(id, label, list) {
|
||||
const open = !hier.closed.has(id);
|
||||
list.hidden = !open;
|
||||
const toggle = h("button", {type: "button", class: "btn small ghost icon-only org-toggle", "aria-expanded": String(open), "aria-controls": list.id, "data-focus": `toggle:${id}`, ...named(`${open ? "Collapse" : "Expand"}: ${label}`)}, icon(open ? "bi-chevron-down" : "bi-chevron-right"));
|
||||
toggle.addEventListener("click", () => {
|
||||
const now = list.hidden;
|
||||
@@ -94,37 +71,144 @@
|
||||
} else {
|
||||
hier.closed.add(id);
|
||||
}
|
||||
drawLinks(list.closest(".organigram"));
|
||||
});
|
||||
return h("li", {"data-node": id}, h("div", {class: "org-line"}, toggle, row), list);
|
||||
return toggle;
|
||||
}
|
||||
|
||||
function chartTree() {
|
||||
const claims = state.claims;
|
||||
const dimensions = new Map();
|
||||
for (const claim of claims.filter((entry) => entry.kind === "line")) {
|
||||
dimensions.set(claim.dimension, [...(dimensions.get(claim.dimension) || []), claim]);
|
||||
function officeHead(claim, toggle) {
|
||||
const title = OFFICE_TITLES[claim.kind] || OFFICE_TITLES.other;
|
||||
return h("div", {class: "org-head"}, toggle,
|
||||
h("span", {class: "org-office", title: `${title} ${claim.office}`}, icon(OFFICE_ICONS[claim.kind] || OFFICE_ICONS.other),
|
||||
h("span", {class: "org-name"}, claim.kind === "chair" ? h("strong", {}, title) : [h("span", {class: "org-title"}, title), h("strong", {}, claim.office)])));
|
||||
}
|
||||
|
||||
function holderLine(claim) {
|
||||
const who = holderOf(claim);
|
||||
const active = claim.beat !== null && claim.beat >= state.now - ACTIVE_BEAT;
|
||||
return h("div", {class: "org-who"},
|
||||
who ? h("button", {type: "button", class: "linkish org-holder", "data-focus": `agent:${claim.office}`, title: `Open ${who}`, on: {click: () => openAgent(who, near(`#main [data-focus="agent:${CSS.escape(claim.office)}"]`))}}, face(who, false), who) : h("span", {class: "muted"}, "–"),
|
||||
claim.session === "-" ? null : presenceMark(claim.session, false),
|
||||
active ? chip("bi-play-circle", "active", "ok") : chip("bi-pause-circle", "no heartbeat", "neutral"));
|
||||
}
|
||||
|
||||
function dottedLines(claim, edges) {
|
||||
return edges.filter((edge) => edge.to === claim.office).map((edge) => h("div", {class: "org-dotted", "data-from": edge.from, title: `Additional superior from the register: ${edge.letters} on ${edge.tasks.join(", ")}`},
|
||||
icon("bi-bezier2"), `Also under ${edge.from} (${edge.letters})`));
|
||||
}
|
||||
|
||||
function officeBox(claim, edges, toggle) {
|
||||
return h("div", {class: `org-row org-box${claim.kind === "chair" ? " org-chair" : ""}`, "data-office": claim.office, "data-kind": claim.kind, "data-position": Organigram.position(claim)},
|
||||
officeHead(claim, toggle),
|
||||
holderLine(claim),
|
||||
claim.work && claim.work !== "-" ? h("span", {class: "muted org-work", title: claim.work}, short(claim.work)) : null,
|
||||
dottedLines(claim, edges),
|
||||
h("span", {class: "org-actions"},
|
||||
officeBtn("bi-arrow-left-right", "Hand over", `Hand over: ${claim.office} to another session, with a passkey signature`, () => officeSheet("takeover", claim), `takeover:${claim.office}`),
|
||||
officeBtn("bi-person-x", "Recall", `Recall: free ${claim.office}, with a passkey signature`, () => officeSheet("recall", claim), `recall:${claim.office}`)));
|
||||
}
|
||||
|
||||
function vacantBox(toggle) {
|
||||
return h("div", {class: "org-row org-box org-chair vacant", "data-office": "chair", "data-kind": "chair", "data-position": "chair"},
|
||||
h("div", {class: "org-head"}, toggle, h("span", {class: "org-office"}, icon(OFFICE_ICONS.chair), h("strong", {}, "Chair"))),
|
||||
pill("vacant", "warn"),
|
||||
h("span", {class: "org-actions"}, officeBtn("bi-person-plus", "Appoint", "Appoint: give chair to a session, with a passkey signature", () => officeSheet("appoint", {office: "chair", session: "", work: ""}), "appoint:chair")));
|
||||
}
|
||||
|
||||
function unitNode(unit, edges) {
|
||||
const list = h("ul", {class: "org-positions", id: nextOrgId()}, unit.positions.map((claim) => h("li", {}, officeBox(claim, edges, null))));
|
||||
const note = unit.kind === "work" ? "work/…" : unit.positions.length === 1 ? "line" : "lines";
|
||||
return h("li", {class: "org-unit", "data-node": unit.id},
|
||||
h("div", {class: "org-row group org-box org-unit-box", "data-unit": unit.id},
|
||||
h("div", {class: "org-head"}, folder(unit.id, unit.label, list), h("span", {class: "org-office"}, icon(UNIT_ICONS[unit.kind]), h("strong", {}, unit.label)), counter(unit.positions.length), h("span", {class: "muted"}, note))),
|
||||
list);
|
||||
}
|
||||
|
||||
function chairPart(chair, staff, units, edges) {
|
||||
const below = h("div", {class: "org-below", id: nextOrgId()},
|
||||
staff.length ? h("ul", {class: "org-staff", "aria-label": "Staff positions"}, staff.map((claim) => h("li", {}, officeBox(claim, edges, null)))) : null,
|
||||
units.length ? h("ul", {class: "org-units", "aria-label": "Line positions"}, units.map((unit) => unitNode(unit, edges))) : null);
|
||||
const toggle = staff.length || units.length ? folder("chair", "Chair", below) : null;
|
||||
return [h("div", {class: "org-level org-chair-level"}, chair ? officeBox(chair, edges, toggle) : vacantBox(toggle)), below];
|
||||
}
|
||||
|
||||
function organigram() {
|
||||
const edges = Organigram.dotted(state.claims, state.tasks);
|
||||
const {chair, staff, units} = Organigram.chart(state.claims);
|
||||
const under = h("div", {class: "org-below", id: nextOrgId()}, chairPart(chair, staff, units, edges));
|
||||
const root = h("div", {class: "org-row org-box org-root"},
|
||||
h("div", {class: "org-head"}, folder("operator", HUMAN, under), h("span", {class: "org-office"}, icon("bi-person-circle"), h("strong", {}, HUMAN))),
|
||||
h("span", {class: "muted"}, "assigns every office with a passkey signature"));
|
||||
const links = s("svg", {class: "org-links", "aria-hidden": "true", focusable: "false"});
|
||||
const canvas = h("div", {class: "organigram", "data-edges": String(edges.length)}, links, h("div", {class: "org-level"}, root), under);
|
||||
canvas.orgEdges = edges;
|
||||
const observer = new ResizeObserver(() => (canvas.isConnected ? drawLinks(canvas) : observer.disconnect()));
|
||||
observer.observe(canvas);
|
||||
return h("div", {class: "org-scroll", role: "region", tabindex: "0", "aria-label": "Organigram"}, canvas);
|
||||
}
|
||||
|
||||
function chartBox(base, node) {
|
||||
if (!node || !node.getClientRects().length) {
|
||||
return null;
|
||||
}
|
||||
const lines = [...dimensions].sort(([a], [b]) => a.localeCompare(b)).map(([dimension, held]) => orgNode(`dimension:${dimension}`, dimension,
|
||||
groupRow("bi-diagram-2", dimension, held.length, held.length === 1 ? "line" : "lines"),
|
||||
held.map((claim) => orgNode(claim.office, claim.office, officeRow(claim, claim.line, "Representative"), []))));
|
||||
const groups = OFFICE_GROUPS.map(([kind, label, title]) => [kind, label, title, claims.filter((entry) => entry.kind === kind)]).filter(([, , , held]) => held.length)
|
||||
.map(([kind, label, title, held]) => orgNode(`group:${kind}`, label, groupRow(OFFICE_ICONS[kind], label, held.length, kind === "other" ? "" : `${kind}/…`),
|
||||
held.map((claim) => orgNode(claim.office, claim.office, officeRow(claim, kind === "other" ? claim.office : claim.office.slice(kind.length + 1), title), []))));
|
||||
const chair = claims.find((entry) => entry.kind === "chair");
|
||||
const chairNode = orgNode("chair", "Chair", chair ? officeRow(chair, "Chair", "Office") : vacantRow("chair", "Chair"), [...lines, ...groups]);
|
||||
const root = h("div", {class: "org-row org-root"}, h("span", {class: "org-office"}, icon("bi-person-circle"), h("strong", {}, HUMAN)), h("span", {class: "muted"}, "assigns every office with a passkey signature"));
|
||||
return h("ul", {class: "org-tree root"}, orgNode("operator", HUMAN, root, [chairNode]));
|
||||
const found = node.getBoundingClientRect();
|
||||
return {left: found.left - base.left, top: found.top - base.top, right: found.right - base.left, bottom: found.bottom - base.top};
|
||||
}
|
||||
|
||||
function solidBoxes(canvas, boxOf) {
|
||||
const units = [...canvas.querySelectorAll(".org-units > .org-unit")].map((unit) => ({box: boxOf(unit.querySelector(".org-unit-box")), positions: [...unit.querySelectorAll(".org-positions > li > .org-box")].map(boxOf).filter(Boolean)}));
|
||||
return {root: boxOf(canvas.querySelector(".org-root")), chair: boxOf(canvas.querySelector(".org-chair")), staff: [...canvas.querySelectorAll(".org-staff > li > .org-box")].map(boxOf).filter(Boolean), units: units.filter((unit) => unit.box)};
|
||||
}
|
||||
|
||||
function drawLinks(canvas) {
|
||||
if (!canvas || !canvas.isConnected) {
|
||||
return;
|
||||
}
|
||||
const base = canvas.getBoundingClientRect();
|
||||
const boxOf = (node) => chartBox(base, node);
|
||||
const office = (name) => boxOf([...canvas.querySelectorAll(".org-box[data-office]")].find((node) => node.dataset.office === name));
|
||||
const dashed = (canvas.orgEdges || []).map((edge) => [edge, office(edge.from), office(edge.to)]).filter(([, from, to]) => from && to);
|
||||
const svg = canvas.querySelector(":scope > .org-links");
|
||||
svg.setAttribute("width", String(canvas.scrollWidth));
|
||||
svg.setAttribute("height", String(canvas.scrollHeight));
|
||||
svg.replaceChildren(...Organigram.solid(solidBoxes(canvas, boxOf)).map((d) => s("path", {class: "org-solid", d})),
|
||||
...dashed.map(([edge, from, to]) => s("path", {class: "org-dashed", d: Organigram.dashed(from, to), "data-from": edge.from, "data-to": edge.to}, s("title", {}, `${edge.from} to ${edge.to}: ${edge.letters} on ${edge.tasks.join(", ")}`))));
|
||||
}
|
||||
|
||||
function orgLegend() {
|
||||
const sample = (kind) => s("svg", {class: `org-sample ${kind}`, viewBox: "0 0 28 8", "aria-hidden": "true", focusable: "false"}, s("line", {x1: "1", y1: "4", x2: "27", y2: "4"}));
|
||||
return h("div", {class: "org-legend", role: "note"},
|
||||
h("span", {}, sample("solid"), "Line: domain chairs and presidents under the Chair"),
|
||||
h("span", {}, h("span", {class: "org-swatch", "aria-hidden": "true"}), "Staff: organizers and single offices beside the Chair"),
|
||||
h("span", {}, sample("dashed"), "Additional superior: A or C on a task in the register"));
|
||||
}
|
||||
|
||||
function drawChart() {
|
||||
const key = focusKey(hier.chart);
|
||||
hier.ids = 0;
|
||||
const old = hier.chart.querySelector(".org-scroll");
|
||||
const kept = old ? [old.scrollLeft, old.scrollTop] : null;
|
||||
const count = state.claims.length;
|
||||
const chart = organigram();
|
||||
hier.chart.replaceChildren(
|
||||
h("div", {class: "inbox-head", "data-star-slot": ""}, h("h2", {class: "group-title", id: "org-title"}, "Hierarchy", counter(count)),
|
||||
h("span", {class: "muted"}, "Formal offices from the council: Operator → Chair → dimensions → lines, plus organizers and presidents"),
|
||||
h("div", {class: "inbox-head", "data-star-slot": ""}, h("h2", {class: "group-title", id: "org-title"}, "Organigram", counter(count)),
|
||||
h("span", {class: "muted"}, "Formal offices from the council: Operator, Chair, line and staff positions"),
|
||||
h("span", {class: "spacer"}),
|
||||
h("button", {type: "button", class: "btn small soft", "data-focus": "appoint:new", ...named("New office", "New office: give a free office to a session, with a passkey signature"), on: {click: () => officeSheet("appoint", null)}}, icon("bi-person-plus"), "New office")),
|
||||
chartTree());
|
||||
orgLegend(),
|
||||
chart);
|
||||
if (kept) {
|
||||
[chart.scrollLeft, chart.scrollTop] = kept;
|
||||
} else {
|
||||
centerChair(chart);
|
||||
}
|
||||
refocus(hier.chart, key);
|
||||
}
|
||||
|
||||
function centerChair(chart) {
|
||||
const box = chart.querySelector(".org-chair");
|
||||
if (box) {
|
||||
const found = box.getBoundingClientRect();
|
||||
const frame = chart.getBoundingClientRect();
|
||||
chart.scrollLeft += found.left + found.width / 2 - (frame.left + frame.width / 2);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user