feat(orchestrator): legend toggle per panel and Home tile (017)

Every view panel and Home tile that holds a legend gets an info button beside its star that hides or shows the legend. The pick is kept in the view store under legend.views per panel and legend.tiles per pin key; the store validates both maps and drops the state of a tile whose pin left Home. Unit tests for the store, E2E in Chromium and Firefox at 1920, 1366 and 390.

🎯 Fix: 94 %
💥 Break: 4 %
💸 Tokens: 100 %
⏱️ Velocity: 100 %
🛡️ Security: 100 %
🏆 Score: 90
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-17 14:13:29 +00:00
1 parent 0f841fd5cb
commit 94bf0b418a
7 files changed
+385 -3

No files matched your search

+34 -2
View File
@@ -4,6 +4,7 @@ import copy
import json
import re
import threading
from collections.abc import Callable
from pathlib import Path
from .errors import Conflict, ToolError
@@ -18,7 +19,13 @@ VIEW = {
"burn": {"overlays": []},
"home": {"pins": []},
"kanban": {"hidden": []},
"legend": {"views": {}, "tiles": {}},
}
LEGEND_PANELS = (
"agents/orbit", "agents/chord", "agents/swimlane", "artifacts/orbit", "artifacts/chord", "artifacts/swimlane",
"tasks/rasci", "tasks/gantt", "tasks/burn", "resources-hardware", "resources-tokens", "resources-combined",
)
PIN_KEY = re.compile(r"[A-Za-z0-9:_./-]{1,32}:[A-Za-z0-9:_./-]{1,200}")
VIEW_PATH = re.compile(r"[A-Za-z]{1,32}(?:\.[A-Za-z]{1,32})?")
SERIES_ID = re.compile(r"[A-Za-z0-9:_./-]{1,200}")
PIN_KIND = re.compile(r"[A-Za-z0-9:_./-]{1,32}")
@@ -136,21 +143,42 @@ def pins(value: object) -> list[dict]:
return found
def legend_flags(value: object, name: str, known: Callable[[str], object], what: str) -> dict[str, bool]:
"""Args:
value: a map of legend owners to whether their legend shows.
name: where the map sits, for the error message.
known: true for a key that may own a legend.
what: the keys known accepts, for the error message.
Returns:
The map; a key known refuses or a value other than true or false
raises ToolError.
"""
if not isinstance(value, dict) or not all(isinstance(key, str) and known(key) for key in value):
raise ToolError(f"{name} must map {what} to true or false")
return {key: flag(shown, f"{name}.{key}") for key, shown in value.items()}
def valid_view(raw: object) -> dict:
"""Args:
raw: the whole view document as the page sent it.
Returns:
The document with every key of VIEW and nothing else; any other
key, a missing one or a malformed value raises ToolError.
key, a missing one or a malformed value raises ToolError. The
legend state of a tile whose pin left Home is dropped.
"""
data = section(raw, "view", tuple(VIEW))
resources = section(data["resources"], "resources", tuple(VIEW["resources"]))
burn = section(data["burn"], "burn", tuple(VIEW["burn"]))
home = section(data["home"], "home", tuple(VIEW["home"]))
kanban = section(data["kanban"], "kanban", tuple(VIEW["kanban"]))
legend = section(data["legend"], "legend", tuple(VIEW["legend"]))
if not isinstance(resources["tokens"], str) or resources["tokens"] not in TOKEN_MODES:
raise ToolError(f"resources.tokens must be one of {', '.join(TOKEN_MODES)}")
pinned = pins(home["pins"])
keys = {f"{pin['kind']}:{pin['id']}" for pin in pinned}
tiles = legend_flags(legend["tiles"], "legend.tiles", PIN_KEY.fullmatch, "pin keys kind:id")
return {
"resources": {
"hidden": series_ids(resources["hidden"], "resources.hidden"),
@@ -159,8 +187,12 @@ def valid_view(raw: object) -> dict:
"combinedHidden": series_ids(resources["combinedHidden"], "resources.combinedHidden"),
},
"burn": {"overlays": members(burn["overlays"], "burn.overlays", "metrics", OVERLAYS)},
"home": {"pins": pins(home["pins"])},
"home": {"pins": pinned},
"kanban": {"hidden": members(kanban["hidden"], "kanban.hidden", "layers", KANBAN_LAYERS)},
"legend": {
"views": legend_flags(legend["views"], "legend.views", LEGEND_PANELS.__contains__, f"panels of {', '.join(LEGEND_PANELS)}"),
"tiles": {key: shown for key, shown in tiles.items() if key in keys},
},
}
+1
View File
@@ -643,6 +643,7 @@ pre.notes { margin: 0; padding: 8px 10px; background: var(--sunken); border-radi
{% include "page-home.js" %}
{% include "page-legend.js" %}
{% include "page-rules.js" %}
{% include "page-firewall.js" %}
+1
View File
@@ -53,6 +53,7 @@
announce();
measure();
homeBoot();
legendBoot();
apply();
drawTime();
motion.asOf = ui.asOf;
+85
View File
@@ -0,0 +1,85 @@
const LEGEND_PARTS = ".legend, .res-legend, .home-metric > .legend-chips";
const LEGEND_PATHS = {view: "legend.views", tile: "legend.tiles"};
const legendView = {buttons: new WeakMap()};
const legendShown = (path, key) => ViewStore.get(path)[key] !== false;
function legendToggle(path, key) {
const show = !legendShown(path, key);
ViewStore.update(path, (flags) => {
const next = {...flags};
delete next[key];
return show ? next : {...next, [key]: false};
});
}
function legendButton(path, key) {
const button = iconBtn("bi-info-circle", "Legend", "btn small ghost legend-toggle", (event) => {
event.stopPropagation();
legendToggle(path, key);
});
button.dataset.legendKey = key;
button.addEventListener("pointerdown", (event) => event.stopPropagation());
return button;
}
function paintLegend(owner, button, shown) {
const state = shown ? "shown" : "hidden";
if (owner.dataset.legend !== state) {
owner.dataset.legend = state;
}
if (button.getAttribute("aria-pressed") !== String(shown)) {
button.setAttribute("aria-pressed", String(shown));
button.title = `Legend: ${shown ? "shown, press to hide it" : "hidden, press to show it"}`;
}
}
/**
* @param owner - a panel of a view or a Home tile.
* @param path - the view-store key of its kind, legend.views or legend.tiles.
* @param key - its panel id or pin key there.
* @param place - (button) => void putting the button in its spot, or null when the owner holds no legend.
*/
function legendFor(owner, path, key, place) {
const made = legendView.buttons.get(owner);
if (!place) {
if (made) {
made.remove();
legendView.buttons.delete(owner);
}
if (owner.dataset.legend) {
delete owner.dataset.legend;
}
return;
}
const button = made && made.dataset.legendKey === key ? made : legendButton(path, key);
legendView.buttons.set(owner, button);
place(button);
paintLegend(owner, button, legendShown(path, key));
}
const ownOf = (host, selector) => [...host.querySelectorAll(selector)].find((node) => node.closest(Panels.HOSTS) === host) || null;
function markLegends() {
for (const host of document.querySelectorAll("#main [data-panel]")) {
if (host.closest(".home-tile")) {
continue;
}
const star = ownOf(host, ".star");
legendFor(host, LEGEND_PATHS.view, host.dataset.panel, star && ownOf(host, LEGEND_PARTS) ? (button) => star.nextElementSibling !== button && star.after(button) : null);
}
for (const tile of document.querySelectorAll(".home-tile[data-pin]")) {
const open = tile.querySelector(".home-open");
legendFor(tile, LEGEND_PATHS.tile, tile.dataset.pin, tile.querySelector(`.home-body :is(${LEGEND_PARTS})`) ? (button) => open.previousElementSibling !== button && open.before(button) : null);
}
}
function legendBoot() {
new MutationObserver(markLegends).observe(document.body, {childList: true, subtree: true});
ViewStore.on("legend", () => {
markLegends();
drawHome();
drawResources();
});
markLegends();
}
@@ -5,3 +5,4 @@
.legend-chip:hover { border-color: var(--line-strong); }
.legend-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.legend-chip[aria-pressed="false"] { color: var(--muted); text-decoration: line-through; opacity: 0.5; }
[data-legend="hidden"] :is(.res-legend, .home-metric > .legend-chips), [data-legend="hidden"] .legend:not(:has(> .star)), [data-legend="hidden"] .legend > :not(.star, .legend-toggle) { display: none; }