Merge branch 'feature/hub-home-tile-open' into unify/skills-20261114

This commit is contained in:
Kevin Veen-Birkenbach committed 2026-11-14 21:57:47 +00:00
commit ad3685ef03
7 files changed
+606 -13

No files matched your search

+11 -2
View File
@@ -28,11 +28,20 @@ const Nav = (() => {
}
/**
* @param hash - the location hash.
* @param hash - the location hash, optionally ending in ?open=<kind>:<id>, a Home pin key the screen opens.
* @param pinned - how many pins Home holds; an empty hash opens Home once it holds one, else Stream.
* @returns {screen, view, redirect, spot}, plus open, the pin key, when the hash names one; a hash with open
* redirects to itself without it.
*/
function route(hash, pinned) {
const [head, sub] = decodeURIComponent(String(hash).replace(/^#/, "")).split("/");
const [path, query] = String(hash).replace(/^#/, "").split("?");
const found = place(path, pinned);
const open = new URLSearchParams(query || "").get("open");
return open ? {...found, open, redirect: found.redirect || `#${path}`} : found;
}
function place(path, pinned) {
const [head, sub] = decodeURIComponent(path).split("/");
if (!head && pinned > 0) {
return {screen: "home", view: null, redirect: "#home"};
}
+136 -3
View File
@@ -38,7 +38,11 @@
drawHome();
}
function homeMessage(key) {
/**
* @param key - a message pin's raw id, <ts>/<entry id>.
* @returns the stream entry, null when it no longer exists or the key is malformed, undefined while it loads.
*/
function homeEntry(key) {
const cut = key.indexOf("/");
const ts = Number(key.slice(0, cut));
const id = key.slice(cut + 1);
@@ -50,7 +54,11 @@
if (!shown && (!known || (!known.busy && Date.now() - known.at > HOME_MESSAGE))) {
homeLoadMessage(key, ts, id);
}
const entry = shown || (known ? known.entry : undefined);
return shown || (known ? known.entry : undefined);
}
function homeMessage(key) {
const entry = homeEntry(key);
if (entry === undefined) {
return homeWait("Loading …");
}
@@ -229,6 +237,119 @@
legend.replaceChildren(...drawn.series.map((line) => h("span", {class: `legend-chip ${line.tone}`, "data-series": line.id}, line.label)));
}
const HOME_RETRY = 150;
const HOME_TRIES = 60;
const HOME_LINKS = {"radio-log": "#stream/radio", "agents/order": "#agents/hierarchy?open=panel:agents/order"};
const HOME_SCREENS = {task: "#tasks/list", message: "#stream", artifact: "#artifacts/orbit", agent: "#agents/orbit", ancestry: "#artifacts/tree", metric: "#resources"};
const homeItemOf = (item) => [...document.querySelectorAll("#main [data-item]")].find((node) => node.dataset.item === item) || null;
/**
* @param pin - a Home pin.
* @returns the hash of the full view of its panel or item: the panel's own tab and view, or the item's tab and view
* with ?open=<pin key>; null for a kind without a full view.
*/
function homeLink(pin) {
if (pin.kind === Panels.PANEL) {
return Object.hasOwn(HOME_LINKS, pin.id) ? HOME_LINKS[pin.id] : `#${pin.id}`;
}
return Object.hasOwn(HOME_SCREENS, pin.kind) ? `${HOME_SCREENS[pin.kind]}?open=${Panels.keyOf(pin)}` : null;
}
function homeOpenPanel(id) {
const found = document.querySelector(`#main [data-panel="${id}"]`);
if (found) {
found.scrollIntoView({block: "start"});
const title = found.querySelector('[tabindex="-1"]');
if (title) {
title.focus({preventScroll: true});
}
}
return Boolean(found);
}
function homeOpenMessage(key) {
const entry = homeEntry(key);
if (entry) {
openPopup("Message", [popupHead(icon(Nav.ICONS.stream), "Message", h("span", {class: "muted"}, when(entry.ts))),
h("div", {class: "popup-body"}, h("ol", {class: "feed"}, eventRow(entry)))], () => homeItemOf(`message:${key}`));
}
return entry !== undefined;
}
function homeOpenArtifact(ref) {
const node = artifactNode(ref);
if (!node) {
return Boolean(tree.model);
}
if (node.repo && node.repo !== art.repo) {
art.repo = node.repo;
drawArtifacts();
}
artSelect(node.id);
return true;
}
function homeOpenAncestry(path) {
if (!tree.data || tree.busy || !tree.dom || tree.dom.view !== "tree") {
return false;
}
tree.open.add(path);
drawArtifacts();
const frame = homeItemOf(`ancestry:${path}`);
if (frame) {
frame.scrollIntoView({block: "center"});
}
return true;
}
function homeOpenMetric(id) {
const pin = homePins().find((entry) => entry.kind === "metric" && entry.id === id);
if (!pin || !homeMetricView(pin.view)) {
return true;
}
if (!resourceRestore(pin.view)) {
return false;
}
const panel = document.querySelector(`#main [data-panel="resources-${pin.view.chart}"]`);
if (panel) {
panel.scrollIntoView({block: "nearest"});
}
return true;
}
const HOME_OPENERS = {
panel: homeOpenPanel,
task: (id) => {
taskSheet(id);
return true;
},
message: homeOpenMessage,
artifact: homeOpenArtifact,
agent: (key) => {
openAgent(key, pickOf(key));
return true;
},
ancestry: homeOpenAncestry,
metric: (raw, id) => homeOpenMetric(id),
};
/**
* @param open - the pin key a hash names after ?open=, such as agent:s1 or panel:agents/order.
* @param screen - the screen the hash shows.
* @param tries - how many more times to wait HOME_RETRY ms for data the item needs, such as the tree or the samples.
*/
function homeOpen(open, screen, tries) {
const cut = open.indexOf(":");
const kind = open.slice(0, cut);
const id = open.slice(cut + 1);
if (cut < 1 || !Object.hasOwn(HOME_OPENERS, kind) || !Panels.ID.test(id) || ui.screen !== screen) {
return;
}
if (!HOME_OPENERS[kind](kind === Panels.PANEL ? id : Panels.raw(id), id) && tries > 0) {
window.setTimeout(() => homeOpen(open, screen, tries - 1), HOME_RETRY);
}
}
function homeRefused(why) {
homeView.pins = homeStore.read();
drawHome();
@@ -373,8 +494,9 @@
const body = h("div", {class: "home-body"});
const grip = iconBtn("bi-grip-vertical", "Move", "btn small ghost home-grip", null, "Move: drag to another tile, or focus the tile and press the arrow keys");
const handle = iconBtn("bi-arrow-down-right", "Resize", "btn small ghost home-resize", null, "Resize: drag, or the arrow keys, 1 to 12 columns wide and rows high");
const open = h("a", {class: "btn small ghost icon-only home-open", "aria-label": "Open", hidden: true}, icon("bi-arrows-angle-expand"));
const tile = h("article", {class: "home-tile", tabindex: 0, role: "listitem", "data-pin": key, on: {keydown: (event) => homeKeys(event, key)}},
h("header", {class: "home-head"}, grip, title, iconBtn("bi-x-lg", "Unpin", "btn small ghost home-unpin", () => homeUnpin(key), "Unpin: remove the tile from Home")), body, handle);
h("header", {class: "home-head"}, grip, title, open, iconBtn("bi-x-lg", "Unpin", "btn small ghost home-unpin", () => homeUnpin(key), "Unpin: remove the tile from Home")), body, handle);
grip.addEventListener("pointerdown", (event) => homeGrab(event, key, "move"));
handle.addEventListener("pointerdown", (event) => homeGrab(event, key, "size"));
handle.addEventListener("keydown", (event) => homeSizeKeys(event, key));
@@ -382,6 +504,16 @@
return tile;
}
function homeOpenLink(open, link, name) {
open.hidden = !link;
if (link) {
open.setAttribute("href", link);
open.setAttribute("title", `Open: show ${name} in full view`);
} else {
open.removeAttribute("href");
}
}
function homeContent(entry, pin) {
try {
return entry.render({w: pin.w, h: pin.h});
@@ -401,6 +533,7 @@
tile.setAttribute("aria-label", `${name}, ${pin.w} by ${pin.h}, tile ${index + 1} of ${count}`);
homeSpan(tile, pin);
tile.querySelector(".home-title").textContent = name;
homeOpenLink(tile.querySelector(".home-open"), content ? homeLink(pin) : null, name);
const body = tile.querySelector(".home-body");
const shown = content || homeGone(pin, key);
if (body.childNodes.length !== 1 || body.firstChild !== shown) {
+26 -5
View File
@@ -269,16 +269,37 @@
* plot is too small, and those series for a legend.
*/
function metricChart(view, size) {
const data = resourceView.data;
const span = {from: data.since, to: Math.max(data.until, data.since + 60)};
const parts = resourceParts(data, {tokens: view.tokens, hidden: [], combinedHidden: [], combined: view.chart === "combined"}, span);
const series = RESOURCE_SERIES[view.chart](parts);
const hidden = new Set(view.shown === null ? [] : series.map((line) => line.id).filter((id) => !view.shown.includes(id)));
const {span, parts, series, hidden} = metricParts(resourceView.data, view);
const [, , label] = RESOURCE_PANELS.find(([kind]) => kind === view.chart);
const drawn = RESOURCE_CHARTS[view.chart]({kind: view.chart, label}, {...parts, hidden, combinedHidden: hidden}, span, size);
return {svg: resourceSmall(size) ? null : drawn.svg, series: series.filter((line) => !hidden.has(line.id))};
}
function metricParts(data, view) {
const span = {from: data.since, to: Math.max(data.until, data.since + 60)};
const parts = resourceParts(data, {tokens: view.tokens, hidden: [], combinedHidden: [], combined: view.chart === "combined"}, span);
const series = RESOURCE_SERIES[view.chart](parts);
return {span, parts, series, hidden: new Set(view.shown === null ? [] : series.map((line) => line.id).filter((id) => !view.shown.includes(id)))};
}
/**
* @param view - a metric pin's view: {chart, tokens, shown}.
* @returns false while no samples are loaded; else true.
*/
function resourceRestore(view) {
if (resourceView.data === null) {
return false;
}
const {series, hidden} = metricParts(resourceView.data, view);
const ids = new Set(series.map((line) => line.id));
ViewStore.update(view.chart === "combined" ? "resources.combinedHidden" : "resources.hidden", (list) => [...list.filter((id) => !ids.has(id)), ...hidden]);
ViewStore.set("resources.combined", view.chart === "combined");
if (view.chart !== "hardware") {
ViewStore.set("resources.tokens", view.tokens);
}
return true;
}
function resourceParts(data, view, span) {
return {
hardware: hardwareSeries(data.samples),
+8 -2
View File
@@ -36,14 +36,20 @@
if (route.view) {
ui.views[route.screen] = route.view;
}
const show = () => {
render(true);
if (route.open) {
window.setTimeout(() => homeOpen(route.open, route.screen, HOME_TRIES), 0);
}
};
if (document.startViewTransition && drawn.screen && !calm.matches) {
document.startViewTransition(() => render(true)).ready.catch((error) => {
document.startViewTransition(show).ready.catch((error) => {
if (error.name !== "AbortError") {
throw error;
}
});
} else {
render(true);
show();
}
}
+3
View File
@@ -14,6 +14,9 @@
.home-body svg.chart { display: block; width: 100%; height: auto; max-height: 100%; }
.home-body .stage, .home-body .graph3d { height: 100%; min-height: 0; }
.home-grip { cursor: grab; touch-action: none; }
.home-open[hidden] { display: none; }
.home-tile[data-w="1"] .home-head { gap: 2px; padding-inline: 2px; }
.home-tile[data-w="1"] .home-head .icon-only { min-width: 24px; padding-inline: 4px; }
.home-resize { position: absolute; right: 2px; bottom: 2px; z-index: 3; cursor: nwse-resize; touch-action: none; }
.home-gone { display: grid; place-content: center; justify-items: center; gap: var(--sp-2); height: 100%; text-align: center; }
.home-gone-word { color: var(--bad); font-size: var(--fs-lg); text-transform: uppercase; letter-spacing: .06em; }