Watch
0
0
Fork
You've already forked hyperhive
0

hive ui: the dashboard wears the swarm UI's chrome, and its own header, tab strip and menu mounts go

The dashboard mounts @hive/shared's AppShell, the header, nav and settings menu the swarm UI has, from a new shell.js: the hive's name for the brand, the tabs agents, rebuild queue and kept state routed by the URL hash, the theme, motion and solid-background settings in this page's own browser storage, and the shared links and user menus. The three tab panes stay plain DOM, kept hidden in index.html and moved into the shell's content column by shell.js. The tabs, the hash-to-tab parse and the menu entries sit in shell-routes.js, which npm test covers (the dashboard package gets a test script). The old header, the createTabStrip tabbar, the leet tab names, the identity headline and title code, the sticky-top wrapper, the links-menu.js and user-menu.js mounts and their CSS are removed. The docs say the plain tab names and the new chrome.
This commit is contained in:
iris 2026-11-21 10:21:21 +01:00
commit 7707a257e9
15 changed files with 250 additions and 367 deletions

View file

@ -29,11 +29,11 @@ the other surfaces: the API docs and the swarm UI.
The dashboard is a single page with these tabs: The dashboard is a single page with these tabs:
- **4G3NTS** — every agent, live. This is the default tab and the one you - **agents** — every agent, live. This is the default tab and the one you
check most. check most.
- **R3BU1LD QU3U3** — the rebuild queue. A build's output and history are on - **rebuild queue** — the rebuild queue. A build's output and history are on
the swarm's `builds` Grafana board. the swarm's `builds` Grafana board.
- **K3PT ST4T3** — kept state from agents with no container (tombstones), - **kept state** — kept state from agents with no container (tombstones),
with a purge button per entry. with a purge button per entry.
Each agent also serves a small web server, with its stats and screen pages: open Each agent also serves a small web server, with its stats and screen pages: open

View file

@ -8,16 +8,17 @@ creation, linking external forge and matrix accounts, the controller's job
graph) and is where you do day-to-day work. The hive dashboard keeps shrinking: graph) and is where you do day-to-day work. The hive dashboard keeps shrinking:
parts of it go, bit by bit. parts of it go, bit by bit.
A fixed header holds the tab strip, a **pages** menu with links to the API docs The header looks like the swarm UI's: the hive's name, the tabs, a settings menu
and the swarm UI, and a profile menu with your authelia settings and sign-out. for the theme, a **pages** menu with links to the API docs and the swarm UI, and
a profile menu with your authelia settings and sign-out.
The URL hash (`#agents`, `#rebuild`, `#kept`) picks the tab. The URL hash (`#agents`, `#rebuild`, `#kept`) picks the tab.
- **4G3NTS** lists the hive's containers, one row each, sorted by name, with - **agents** lists the hive's containers, one row each, sorted by name, with
the agent's status and the actions on it: rebuild, start, stop, destroy. A red the agent's status and the actions on it: rebuild, start, stop, destroy. A red
banner at the top says two agents hash to the same port. Rename one and banner at the top says two agents hash to the same port. Rename one and
rebuild. rebuild.
- **R3BU1LD QU3U3** shows the rebuild queue and each build's log. - **rebuild queue** shows the rebuild queue and each build's log.
- **K3PT ST4T3** lists agents with kept state and no container, with their size - **kept state** lists agents with kept state and no container, with their size
and age. **PURG3** wipes one's state directory. The list also shows an agent and age. **PURG3** wipes one's state directory. The list also shows an agent
that's part-way through a spawn, because both look the same on disk: the row that's part-way through a spawn, because both look the same on disk: the row
says `offline` and the tab carries a warning. says `offline` and the tab carries a warning.

View file

@ -11,15 +11,18 @@ matrix accounts, the controller's job graph — are on the
[swarm UI](../../2-handbook/swarm/ui.md). [swarm UI](../../2-handbook/swarm/ui.md).
hive-c0re serves the dashboard at `/`. hive-c0re serves the dashboard at `/`.
It has a fixed chrome header at the top and a `<main>` that shows exactly Its chrome is `@hive/shared`'s `AppShell`, the same header, nav and settings
one tab pane at a time. The URL hash (`#agents`, `#rebuild`, menu the swarm UI has (`shell.js` mounts it), and the content column below it
shows exactly one tab pane at a time. The URL hash (`#agents`, `#rebuild`,
`#kept`) drives which pane is `#kept`) drives which pane is
active; hash changes don't reload the page. active; hash changes don't reload the page.
**Chrome header** (fixed, overlays the active tab pane): **Chrome header** (sticky, over the active tab pane):
- **Brand**: the hive's name, from `state.hive_name`.
- **Pages menu**: a link icon at the right end of the chrome, beside the - **Pages menu**: a link icon at the right end of the chrome, beside the
profile avatar (`links-menu.js`, `@hive/shared`'s `LinksMenu`, the same profile avatar (`shell.js`, `@hive/shared`'s `LinksMenu`, the same
component the swarm UI uses for its service links), opening a popover with links to **api docs** component the swarm UI uses for its service links), opening a popover with links to **api docs**
(`/api/docs/`) and **swarm** (the swarm (`/api/docs/`) and **swarm** (the swarm
UI at the swarm apex domain, opened in a new tab). The swarm entry UI at the swarm apex domain, opened in a new tab). The swarm entry
@ -27,7 +30,7 @@ active; hash changes don't reload the page.
`HIVE_SWARM_PUBLIC_URL` (set from `services.hyperhive.swarm.domain`); `HIVE_SWARM_PUBLIC_URL` (set from `services.hyperhive.swarm.domain`);
with no domain set there is no swarm entry. The standalone pages link back to `/`. with no domain set there is no swarm entry. The standalone pages link back to `/`.
- **Profile menu**: the signed-in user's avatar at the right end of the - **Profile menu**: the signed-in user's avatar at the right end of the
chrome (`user-menu.js`, the same component as the swarm UI's and the agent chrome (`shell.js`, `@hive/shared`'s `UserMenu`, the same component as the swarm UI's and the agent
page's). It opens a popover with the user's name and links to authelia's page's). It opens a popover with the user's name and links to authelia's
settings and sign-out pages. The name comes from `/api/whoami`, which the settings and sign-out pages. The name comes from `/api/whoami`, which the
dashboard's nginx vhost proxies to authelia, and the links from dashboard's nginx vhost proxies to authelia, and the links from
@ -35,10 +38,12 @@ active; hash changes don't reload the page.
`HIVE_AUTHELIA_PUBLIC_URL` (set from `services.hyperhive.swarm.authelia.url`). `HIVE_AUTHELIA_PUBLIC_URL` (set from `services.hyperhive.swarm.authelia.url`).
If the name doesn't load the avatar shows a question mark, and without the URL the If the name doesn't load the avatar shows a question mark, and without the URL the
popover has no links. popover has no links.
- **Tab strip**: `◆ 4G3NTS ◆`, `◆ R3BU1LD QU3U3 ◆`, - **Settings menu**: the theme, motion and solid-background settings, kept in
`◆ K3PT ST4T3 ◆`. this page's own browser storage.
- **Nav**: **agents**, **rebuild queue** and **kept state**, with the sliding
underline the swarm UI has.
- **Banner-thin** (`░▒▓█▓▒░ HYPERHIVE / HIVE-C0RE / WE ARE THE WIRED ░▒▓█▓▒░`) - **Banner-thin** (`░▒▓█▓▒░ HYPERHIVE / HIVE-C0RE / WE ARE THE WIRED ░▒▓█▓▒░`)
— sits below the tab strip. — sits in the footer.
- **No warning banner.** No page shows hive-level warnings (host disk - **No warning banner.** No page shows hive-level warnings (host disk
pressure, failing background sweeps, forge boot failures, agents that pressure, failing background sweeps, forge boot failures, agents that
need a claude login). They live in a push-based registry need a claude login). They live in a push-based registry
@ -50,9 +55,8 @@ active; hash changes don't reload the page.
A container crash is a swarm-level Grafana alert on the crash watcher's A container crash is a swarm-level Grafana alert on the crash watcher's
own log line, so a hive with no otel export has no operator-visible own log line, so a hive with no otel export has no operator-visible
warning signal beyond `/health/ready`. warning signal beyond `/health/ready`.
- **Browser tab title** — `hyperhive // h1ve-c0re` by default; updated - **Browser tab title** — `<tab> · <hive>`, such as `agents · pr1ma`, once
to `<swarm> / <hive> // h1ve-c0re` once `hive_name` / `swarm_name` `hive_name` arrives in the state snapshot.
arrive in the state snapshot.
## 4G3NTS tab ## 4G3NTS tab

View file

@ -5,7 +5,8 @@
"description": "hive-c0re dashboard SPA. Bundled by esbuild into a static dist; served by the hive-c0re Rust binary at runtime via tower_http::ServeDir.", "description": "hive-c0re dashboard SPA. Bundled by esbuild into a static dist; served by the hive-c0re Rust binary at runtime via tower_http::ServeDir.",
"type": "module", "type": "module",
"scripts": { "scripts": {
"build": "node ./build.mjs" "build": "node ./build.mjs",
"test": "node --test test/*.test.mjs"
}, },
"dependencies": { "dependencies": {
"@hive/shared": "*", "@hive/shared": "*",

View file

@ -128,23 +128,3 @@ code {
color: var(--amber); color: var(--amber);
border-color: var(--amber); border-color: var(--amber);
} }
/* ─── page-content gutter ─────────────────────────────────────────────
Inverted-gutter layout: the dashboard keeps `<body>` full-bleed
and wraps their padded content in a single `.page-content` div that
carries the horizontal gutter. Full-width chrome (the tab strip, the
footer) then spans edge-to-edge for free,
with no negative-margin breakout hacks. Only matches on pages that opt
in by adding the wrapper (index.html). */
.page-content {
padding: 0 1.5em;
}
/* ─── sticky top region ───────────────────────────────────────────────
One sticky container per page holding the page chrome (tab bar / page
header). common.js (initStickyTop) wraps the chrome in this on load. */
.sticky-top {
position: sticky;
top: 0;
z-index: 50;
}

View file

@ -282,23 +282,3 @@ export function openStream(url) {
noteWorkerActivity(); noteWorkerActivity();
return target; return target;
} }
// ─── sticky top region ───────────────────────────────────────────────
// One sticky container wrapping the page's chrome (tab bar / page
// header), built once by wrapping the existing chrome element. A page
// without a chrome (none today) gets an empty sticky region at the top of
// <body>.
export function initStickyTop() {
let top = document.querySelector(".sticky-top");
if (top) return top;
top = document.createElement("div");
top.className = "sticky-top";
const chrome = document.querySelector(".dashboard-chrome, .page-header");
if (chrome && chrome.parentNode) {
chrome.parentNode.insertBefore(top, chrome);
top.append(chrome);
} else {
document.body.prepend(top);
}
return top;
}

View file

@ -9,17 +9,20 @@
@import "@hive/shared/jobq-graph.css"; @import "@hive/shared/jobq-graph.css";
@import "@hive/shared/user-menu.css"; @import "@hive/shared/user-menu.css";
@import "@hive/shared/links-menu.css"; @import "@hive/shared/links-menu.css";
@import "@hive/shared/app-shell.css";
@import "@hive/shared/icon-button.css";
@import "@hive/shared/settings-menu.css";
@import "@hive/shared/solid-backgrounds.css";
/* ─── tabbed dashboard chrome ────────────────────────────────────── /* ─── the dashboard page ───────────────────────────────────────────
Top-of-page sticky header with banner + tab strip. SSE stays The chrome (header, nav, settings) is `@hive/shared`'s AppShell, drawn by
alive across tab switches. See docs/4-implementation/web-ui/dashboard.md::Chrome header + Tab strip for the shell.js; SSE stays alive across tab switches. See
routing model. */ docs/4-implementation/web-ui/dashboard.md::Chrome header + Tab strip. */
body.dashboard-shell { body.dashboard-shell {
/* Full-bleed body (no horizontal gutter). The 1.5em side gutter lives /* Full-bleed body (no horizontal gutter). The 1.5em side gutter lives
on the inner `.page-content` wrapper (see common.css), so the sticky in the shell's content column, so the footer spans the full width
chrome bar and the footer span the full edge-to-edge with no negative-margin breakout. `padding-bottom`
width edge-to-edge with no negative-margin breakout. `padding-bottom`
keeps a little breathing room above the viewport edge (overridden to keeps a little breathing room above the viewport edge (overridden to
clear the selection bar via `.has-selection` below). No max-width cap clear the selection bar via `.has-selection` below). No max-width cap
— wide screens use the full width rather than empty side margins. */ — wide screens use the full width rather than empty side margins. */
@ -27,40 +30,6 @@ body.dashboard-shell {
padding-bottom: 1.5em; padding-bottom: 1.5em;
} }
.dashboard-chrome {
/* Pages menu + tab strip share one row (flex). The chrome owns the
horizontal gutter and the single full-width bottom divider; its
children drop their own side padding / border so they sit inline. */
display: flex;
align-items: center;
gap: 0.75em;
/* Stickiness lives on the `.sticky-top` wrapper (common.css) that
common.js wraps this chrome in. */
background: color-mix(
in srgb,
var(--bg) calc(100% - 14% * var(--glass-clear)),
transparent
);
-webkit-backdrop-filter: var(--glass-filter);
backdrop-filter: var(--glass-filter);
border-bottom: 1px solid var(--purple-dim);
padding: 0.3em 1em;
margin: 0 0 1em;
}
/* The pages menu and the profile menu, together at the right end of the
chrome. Their own looks are `@hive/shared/links-menu.css`'s and
`@hive/shared/user-menu.css`'s. */
.dashboard-chrome-actions {
display: flex;
align-items: center;
gap: 0.25em;
flex: none;
margin-left: auto;
}
.links-menu-slot,
.user-menu-slot {
flex: none;
}
.banner-thin { .banner-thin {
text-align: center; text-align: center;
margin: 0; margin: 0;
@ -73,52 +42,8 @@ body.dashboard-shell {
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.tabbar { /* Tab pane visibility: shell.js sets the `hidden` attribute on every pane but
display: flex; the one the URL hash names. */
flex-wrap: nowrap;
align-items: center;
gap: 0.2em;
/* On one row with the chrome's menus; the chrome owns the gutter +
the bottom divider, so no outer padding / border here. */
}
/* Shares the flat-pill aesthetic of the shared `.hive-tab` (sub-tabs on
the standalone pages) so the chrome reads as one family. Kept a touch
weightier than bare `.hive-tab` — larger font, bold labels, count
pills — since this is the dashboard's primary nav, not a sub-strip. */
.tabbar .tab {
display: inline-flex;
align-items: center;
gap: 0.5em;
flex-shrink: 0;
padding: 0.4em 0.95em;
color: var(--muted);
font-family: inherit;
font-size: 0.92em;
letter-spacing: 0.06em;
text-decoration: none;
border: 0;
border-radius: 4px;
cursor: pointer;
transition:
color 0.15s ease,
background 0.15s ease;
}
.tabbar .tab:hover {
color: var(--fg);
background: var(--border);
}
.tabbar .tab.hive-tab--active {
color: var(--purple);
background: var(--border);
}
.tab-label {
font-weight: bold;
white-space: nowrap;
}
/* Tab pane visibility — createTabStrip (@hive/shared/tabs.js) sets the
`hidden` attribute on every inactive pane (resolved from the URL hash;
default — no hash — is 4G3NTS). Only the active pane stays visible. */
.tab-pane[hidden] { .tab-pane[hidden] {
display: none; display: none;
} }

View file

@ -11,141 +11,78 @@
<link rel="stylesheet" href="/static/dashboard.css" /> <link rel="stylesheet" href="/static/dashboard.css" />
</head> </head>
<body class="dashboard-shell"> <body class="dashboard-shell">
<!-- Sticky chrome — just the tab strip. The "WE ARE THE WIRED" <!-- The page chrome: the header, the nav and the settings menu, drawn by
slug lives at the page footer below `<main>`; chrome is shell.js (@hive/shared's AppShell, the swarm UI's chrome). Tabs route
navigation only. Tabs route via the URL hash so F5 / back- via the URL hash so F5 / back-button / shared links keep you on the
button / shared links keep you on the same view. JS owns same view. -->
the show/hide. --> <div id="app-shell"></div>
<header class="dashboard-chrome">
<nav class="tabbar" id="tabbar" role="tablist">
<a
class="tab"
id="tab-agents"
href="#agents"
role="tab"
aria-controls="tab-pane-agents"
data-tab="agents"
>
<span class="tab-label">◆ 4G3NTS ◆</span>
</a>
<!-- The build lifecycle is two tabs here (builds.js): the rebuild
queue with its live log, and the build log history. Kept state
(kept.js) is the third. -->
<a
class="tab"
id="tab-rebuild"
href="#rebuild"
role="tab"
aria-controls="tab-pane-rebuild"
data-tab="rebuild"
>
<span class="tab-label">◆ R3BU1LD QU3U3 ◆</span>
</a>
<a <!-- The tab panes, kept here hidden until shell.js moves them into the
class="tab" shell's content column and shows the one the hash names. -->
id="tab-kept" <div id="pane-store" hidden>
href="#kept" <!-- agents: the containers. Container cards (the central thing the
role="tab" operator looks at) and the rebuild queue / cascade visualisation
aria-controls="tab-pane-kept" that drives them. -->
data-tab="kept" <section
> class="tab-pane"
<span class="tab-label">◆ K3PT ST4T3 ◆</span> id="tab-pane-agents"
</a> data-tab-pane="agents"
hidden
<!-- (Peer hives are no longer a tab — they render as a headline role="tabpanel"
under 4G3NTS. See tab-pane-agents.) --> >
</nav> <!-- JobqRollup mount point, kept outside #containers-section
<!-- The pages menu and the profile menu, together at the right.
Pages menu: the API docs and the swarm UI, filled by links-menu.js
from /api/state. Profile menu: the signed-in user, filled by
user-menu.js. -->
<div class="dashboard-chrome-actions">
<div class="links-menu-slot" id="links-menu"></div>
<div class="user-menu-slot" id="user-menu"></div>
</div>
</header>
<!-- Tab panes. createTabStrip (@hive/shared/tabs.js) keeps exactly one
visible by toggling the `hidden` attribute, resolved from the URL
hash (default 4G3NTS). Panes start `hidden` to avoid a flash before
the script runs. -->
<!-- Padded content wrapper: carries the 1.5em side gutter
(.page-content, common.css) while <body> stays full-bleed so the
sticky chrome above + the footer below span the full width. -->
<div class="page-content">
<main class="dashboard-main">
<!-- 4G3NTS: the agents. Container cards (the central thing
the operator looks at) and rebuild queue / cascade visualisation
that drives them. No inline `C0NTAINERS` h2 heading + divider
— the tab label 4G3NTS already says it. -->
<section
class="tab-pane"
id="tab-pane-agents"
data-tab-pane="agents"
hidden
role="tabpanel"
aria-labelledby="tab-agents"
>
<!-- Swarm / hive identity headline. Populated by refreshState from
hive_name + swarm_name; stays hidden when neither is set. -->
<h2 id="swarm-identity" hidden></h2>
<!-- JobqRollup mount point, kept outside #containers-section
deliberately — that section is wiped + rebuilt on every deliberately — that section is wiped + rebuilt on every
container-list render (see agents.js::renderContainers), which container-list render (see agents.js::renderContainers), which
would tear down and remount the Preact tree on every would tear down and remount the Preact tree on every
container-state tick. Mounted once by agents.js::initJobqRollup, container-state tick. Mounted once by agents.js::initJobqRollup,
refreshed via its own handle rather than by re-rendering. --> refreshed via its own handle rather than by re-rendering. -->
<div id="jobq-rollup-section"></div> <div id="jobq-rollup-section"></div>
<div id="containers-section"> <div id="containers-section">
<p class="meta">loading…</p> <p class="meta">loading…</p>
</div> </div>
</section> </section>
<!-- R3BU1LD QU3U3: pending + running rebuilds and first-spawns. Rendered from GET /api/jobq/graph by the <!-- R3BU1LD QU3U3: pending + running rebuilds and first-spawns. Rendered from GET /api/jobq/graph by the
`JobqGraph` Preact component (@hive/shared/jobq-graph.js); `JobqGraph` Preact component (@hive/shared/jobq-graph.js);
`rebuild_queue_changed` over /api/dashboard/stream is the `rebuild_queue_changed` over /api/dashboard/stream is the
refresh trigger and carries no payload of its own. --> refresh trigger and carries no payload of its own. -->
<section <section
class="tab-pane" class="tab-pane"
id="tab-pane-rebuild" id="tab-pane-rebuild"
data-tab-pane="rebuild" data-tab-pane="rebuild"
hidden hidden
role="tabpanel" role="tabpanel"
aria-labelledby="tab-rebuild" >
> <p class="meta">
<p class="meta"> pending + running rebuilds and first-spawns. one runs at a time.
pending + running rebuilds and first-spawns. one runs at a time. dedup: re-enqueueing a still-queued op collapses into the existing
dedup: re-enqueueing a still-queued op collapses into the existing entry.
entry. </p>
</p> <div id="rebuild-queue-section">
<div id="rebuild-queue-section"> <p class="meta">loading…</p>
<p class="meta">loading…</p> </div>
</div> </section>
</section>
<!-- K3PT ST4T3: kept state from agents whose container is absent, <!-- K3PT ST4T3: kept state from agents whose container is absent,
with a purge button per row. Rendered by kept.js; refreshed by the with a purge button per row. Rendered by kept.js; refreshed by the
`tombstones_changed` stream event. --> `tombstones_changed` stream event. -->
<section <section
class="tab-pane" class="tab-pane"
id="tab-pane-kept" id="tab-pane-kept"
data-tab-pane="kept" data-tab-pane="kept"
hidden hidden
role="tabpanel" role="tabpanel"
aria-labelledby="tab-kept" >
> <p class="meta">
<p class="meta"> kept state from previously tombstoned agents — recreating an agent
kept state from previously tombstoned agents — recreating an agent with the same name reuses it.
with the same name reuses it. </p>
</p> <div id="tombstones-section">
<div id="tombstones-section"> <p class="meta">loading…</p>
<p class="meta">loading…</p> </div>
</div> </section>
</section>
</main>
</div> </div>
<!-- /.page-content --> <!-- /#pane-store -->
<footer> <footer>
<pre class="banner banner-thin"> <pre class="banner banner-thin">

View file

@ -1,35 +0,0 @@
// Pages menu in the dashboard chrome: one icon button, beside the profile
// avatar at the right, that opens a popover linking the standalone pages
// (API docs) and the swarm UI. It is `@hive/shared`'s `LinksMenu`, the
// same component the swarm UI mounts for its service links, rendered with
// Preact like the profile menu. The swarm entry only exists when `/api/state`
// carries `swarm_public_url`, so a hive without a configured swarm domain
// shows no dead link.
import { h, render } from "preact";
import { LinksMenu } from "@hive/shared/links-menu.js";
import { $ } from "./common.js";
/** Menu entries for a state snapshot. The API docs open in place; the swarm
* UI is another site, so it opens in a new tab. */
export function menuLinks(state) {
const links = [
{ icon: "🧬", label: "api docs", url: "/api/docs/", external: false },
];
if (state && state.swarm_public_url) {
links.push({
icon: "🐝",
label: "swarm",
url: state.swarm_public_url,
});
}
return links;
}
/** (Re)render the menu into `#links-menu`. Safe to call on every state
* refresh: Preact diffs the same component, so an open popover stays open. */
export function renderLinksMenu(state) {
const root = $("links-menu");
if (!root) return;
render(h(LinksMenu, { links: menuLinks(state), label: "pages" }), root);
}

View file

@ -0,0 +1,29 @@
// The hive UI's tabs and the pure parts of its routing, kept apart from
// `shell.js` (which needs Preact and the shared shell) so `npm test` can run
// them. Routes are the URL hash.
export const TABS = [
{ href: "agents", label: "agents", accent: "var(--green)" },
{ href: "rebuild", label: "rebuild queue", accent: "var(--yellow)" },
{ href: "kept", label: "kept state", accent: "var(--red)" },
];
/** The tab the URL hash names; the first tab for none or an unknown one. */
export function tabOfHash(hash) {
const id = hash.replace(/^#/, "");
return TABS.some((t) => t.href === id) ? id : TABS[0].href;
}
/** Menu entries for a state snapshot. The API docs open in place; the swarm
* UI is another site, so it opens in a new tab. The swarm entry only exists
* when `/api/state` carries `swarm_public_url`, so a hive without a
* configured swarm domain shows no dead link. */
export function menuLinks(state) {
const links = [
{ icon: "🧬", label: "api docs", url: "/api/docs/", external: false },
];
if (state && state.swarm_public_url) {
links.push({ icon: "🐝", label: "swarm", url: state.swarm_public_url });
}
return links;
}

View file

@ -0,0 +1,88 @@
// The hive UI's page chrome: `@hive/shared`'s `AppShell`, the same header, nav
// row and settings menu the swarm UI has, with the hive's name for a brand and
// the dashboard's three tabs. Routes are the URL hash (`#agents`, `#rebuild`,
// `#kept`), so the gateway needs nothing beyond serving `index.html`.
//
// The tab panes stay plain DOM, built by `agents.js`, `builds.js` and
// `kept.js`: `index.html` keeps them in a hidden store, and `Panes` moves them
// into the shell's content column and shows the one the hash names.
import { h, render } from "preact";
import { useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
import { AppShell } from "@hive/shared/app-shell.js";
import { LinksMenu } from "@hive/shared/links-menu.js";
import { UserMenu } from "@hive/shared/user-menu.js";
import { TABS, menuLinks, tabOfHash } from "./shell-routes.js";
// Storage keys of the shared settings, this page's own: the swarm UI is
// another origin, so a choice made there is not seen here.
const THEME_KEY = "hive-ui:theme-override";
const MOTION_KEY = "hive-ui:motion-override";
const SOLID_KEY = "hive-ui:solid-backgrounds";
function useHashTab() {
const [tab, setTab] = useState(() => tabOfHash(location.hash));
useEffect(() => {
const onHash = () => setTab(tabOfHash(location.hash));
window.addEventListener("hashchange", onHash);
return () => window.removeEventListener("hashchange", onHash);
}, []);
return tab;
}
// A nav link for a hash route.
function HashLink({ href, className, children, ...rest }) {
return h("a", { href: "#" + href, class: className, ...rest }, children);
}
// The tab panes, moved out of the store into the content column. The shell
// remounts its content on every navigation, which moves them in again.
function Panes({ tab, panes, onShow }) {
const box = useRef(null);
useLayoutEffect(() => {
box.current.append(...panes);
for (const pane of panes) pane.hidden = pane.dataset.tabPane !== tab;
onShow(tab);
}, [tab]);
return h("div", { ref: box });
}
function Hive({ state, panes, onShow }) {
const tab = useHashTab();
return h(
AppShell,
{
brand: (state && state.hive_name) || "hive",
brandHref: TABS[0].href,
items: TABS,
location: tab,
LinkComponent: HashLink,
themeKey: THEME_KEY,
motionKey: MOTION_KEY,
solidKey: SOLID_KEY,
menus: [
h(LinksMenu, { links: menuLinks(state), label: "pages", key: "links" }),
h(UserMenu, {
whoamiUrl: "/api/whoami",
autheliaUrl: (state && state.authelia_public_url) || null,
key: "user",
}),
],
},
h(Panes, { tab, panes, onShow }),
);
}
/** (Re)render the shell into `#app-shell` for a state snapshot (`null` before
* the first one). Safe to call on every refresh: Preact diffs the same tree,
* so an open menu stays open. `onShow(tabId)` runs whenever a tab is shown. */
export function renderShell(state, onShow) {
const root = document.getElementById("app-shell");
if (!root) return;
if (!renderShell.panes) {
renderShell.panes = Array.from(
document.querySelectorAll("[data-tab-pane]"),
);
}
render(h(Hive, { state, panes: renderShell.panes, onShow }), root);
}

View file

@ -8,10 +8,9 @@
// live in `./common.js`. // live in `./common.js`.
// 4G3NTS (containers) domain lives in `./agents.js`. // 4G3NTS (containers) domain lives in `./agents.js`.
import { $, openStream, initStickyTop } from "./common.js"; import { $, openStream } from "./common.js";
import { el } from "@hive/shared/dom.js"; import { el } from "@hive/shared/dom.js";
import { bindAsyncForms } from "@hive/shared/forms.js"; import { bindAsyncForms } from "@hive/shared/forms.js";
import { createTabStrip } from "@hive/shared/tabs.js";
import { containersState, syncContainersFromSnapshot } from "./state.js"; import { containersState, syncContainersFromSnapshot } from "./state.js";
import { import {
initJobqRollup, initJobqRollup,
@ -30,12 +29,9 @@ import {
renderKept, renderKept,
syncKeptFromSnapshot, syncKeptFromSnapshot,
} from "./kept.js"; } from "./kept.js";
import { renderLinksMenu } from "./links-menu.js"; import { renderShell } from "./shell.js";
import { renderUserMenu } from "./user-menu.js";
(() => { (() => {
initStickyTop();
// ─── async forms ──────────────────────────────────────────────────────── // ─── async forms ────────────────────────────────────────────────────────
// Shared `data-async` submit interceptor (in common.js, shared with the other // Shared `data-async` submit interceptor (in common.js, shared with the other
// pages' bundles). On success it re-runs refreshState unless the form // pages' bundles). On success it re-runs refreshState unless the form
@ -121,23 +117,6 @@ import { renderUserMenu } from "./user-menu.js";
// synchronous read (e.g. the compose autocomplete pulls agent // synchronous read (e.g. the compose autocomplete pulls agent
// names from here instead of refetching on every keystroke). // names from here instead of refetching on every keystroke).
window.__hyperhive_state = s; window.__hyperhive_state = s;
// Hive identity: render the swarm/hive name as a headline at the
// top of the 4G3NTS pane + update the page title once the
// server-side display names are known. `hive_name` / `swarm_name`
// come from HYPERHIVE_HIVE_NAME / HYPERHIVE_SWARM_NAME env vars
// (set by services.hyperhive.{hiveName,swarmName} nix options).
// When unset we fall back gracefully — the headline stays hidden.
const hiveId = $("swarm-identity");
if (hiveId) {
const hive = s.hive_name;
const swarm = s.swarm_name;
if (hive || swarm) {
const label = swarm && hive ? `${swarm} / ${hive}` : hive || swarm;
hiveId.textContent = label;
hiveId.hidden = false;
document.title = label + " // h1ve-c0re";
}
}
const openDetails = snapshotOpenDetails(); const openDetails = snapshotOpenDetails();
// Sync transients + containers first so renderContainers below // Sync transients + containers first so renderContainers below
// sees the current derived maps (it reads from // sees the current derived maps (it reads from
@ -155,8 +134,7 @@ import { renderUserMenu } from "./user-menu.js";
syncKeptFromSnapshot(s); syncKeptFromSnapshot(s);
renderContainers(s); renderContainers(s);
renderKept(); renderKept();
renderLinksMenu(s); renderShell(s, activateTab);
renderUserMenu(s);
renderHiveRev(s.hyperhive_rev); renderHiveRev(s.hyperhive_rev);
restoreOpenDetails(openDetails); restoreOpenDetails(openDetails);
// No periodic refresh timer. Phase 6 covers every container // No periodic refresh timer. Phase 6 covers every container
@ -256,16 +234,8 @@ import { renderUserMenu } from "./user-menu.js";
})(); })();
// ─── tab routing ─────────────────────────────────────────────────────── // ─── tab routing ───────────────────────────────────────────────────────
// Hash-based: `#agents` / `#rebuild` / `#kept` // The shell (`shell.js`) routes by the URL hash (`#agents`, `#rebuild`,
// activate the matching pane on the dashboard. Empty // `#kept`; none means agents) and calls this each time a tab is shown.
// hash defaults to 4G3NTS. Tab routing only applies when the tab DOM is
// present.
// The shared hash-routed tab strip (@hive/shared/tabs.js) owns the
// tab/pane toggle + aria-selected + routing; `activateTab` runs the
// per-tab side-effects via the strip's onShow. Constructed below (after
// the lazy-load fns it calls are defined). The responsive overflow menu
// was dropped — if the strip ever runs out of room we move panes
// to their own pages rather than hide them in a dropdown.
function activateTab(target) { function activateTab(target) {
// Track active tab on the body so renderSelectionBar can gate // Track active tab on the body so renderSelectionBar can gate
// visibility (bar only belongs on 4G3NTS where agent cards live). // visibility (bar only belongs on 4G3NTS where agent cards live).
@ -273,11 +243,8 @@ import { renderUserMenu } from "./user-menu.js";
renderSelectionBar(Array.from(containersState.values())); renderSelectionBar(Array.from(containersState.values()));
} }
// Wire the shared tab strip now that activateTab + the lazy-load fns it // Draw the shell before the first state arrives, so the page has its frame.
// calls are defined. The strip resolves the active tab from the hash renderShell(null, activateTab);
// (default 4G3NTS), toggles the active tab/pane + aria-selected, and
// fires activateTab for the per-tab side-effects on every change.
createTabStrip($("tabbar"), { defaultId: "agents", onShow: activateTab });
// The rebuild queue mounts now, not on first show. // The rebuild queue mounts now, not on first show.
initBuilds(); initBuilds();
})(); })();

View file

@ -1,24 +0,0 @@
// Profile menu in the dashboard chrome, at the right of the tab strip: the
// signed-in user's avatar, name, and links to authelia's settings and
// sign-out. It is `@hive/shared`'s `UserMenu`, the same component the swarm UI
// and the per-agent page mount, rendered with Preact like the job-queue
// graph. `/api/whoami` is proxied to authelia by this dashboard's own nginx
// vhost, so it needs no CORS; authelia's URL comes from `/api/state`.
import { h, render } from "preact";
import { UserMenu } from "@hive/shared/user-menu.js";
import { $ } from "./common.js";
/** (Re)render the menu into `#user-menu`. Safe to call on every state
* refresh: Preact diffs the same component, so an open popover stays open. */
export function renderUserMenu(state) {
const root = $("user-menu");
if (!root) return;
render(
h(UserMenu, {
whoamiUrl: "/api/whoami",
autheliaUrl: (state && state.authelia_public_url) || null,
}),
root,
);
}

View file

@ -0,0 +1,29 @@
// The hive UI's tab routing and menu entries. Run by `npm test`.
import assert from "node:assert/strict";
import { test } from "node:test";
import { TABS, menuLinks, tabOfHash } from "../src/shell-routes.js";
test("a hash that names a tab shows that tab, with or without the #", () => {
assert.equal(tabOfHash("#rebuild"), "rebuild");
assert.equal(tabOfHash("kept"), "kept");
assert.equal(tabOfHash("#agents"), "agents");
});
test("no hash, or one that names no tab, shows the first tab", () => {
assert.equal(tabOfHash(""), TABS[0].href);
assert.equal(tabOfHash("#"), TABS[0].href);
assert.equal(tabOfHash("#nope"), TABS[0].href);
});
test("the API docs are always linked and open in place", () => {
assert.deepEqual(menuLinks(null), [
{ icon: "🧬", label: "api docs", url: "/api/docs/", external: false },
]);
});
test("the swarm is linked only when the state names its address", () => {
assert.equal(menuLinks({}).length, 1);
const links = menuLinks({ swarm_public_url: "https://swarm.example" });
assert.equal(links.length, 2);
assert.equal(links[1].url, "https://swarm.example");
});

View file

@ -59,6 +59,7 @@
"./show-thinking-setting.js": "./src/settings/ShowThinkingSetting.tsx", "./show-thinking-setting.js": "./src/settings/ShowThinkingSetting.tsx",
"./expand-details-setting.js": "./src/settings/ExpandDetailsSetting.tsx", "./expand-details-setting.js": "./src/settings/ExpandDetailsSetting.tsx",
"./settings-menu.css": "./src/settings/SettingsMenu.css", "./settings-menu.css": "./src/settings/SettingsMenu.css",
"./solid-backgrounds.css": "./src/settings/solid-backgrounds.css",
"./solid-backgrounds.js": "./src/settings/solid-backgrounds.tsx", "./solid-backgrounds.js": "./src/settings/solid-backgrounds.tsx",
"./user-menu.js": "./src/user-menu/UserMenu.tsx", "./user-menu.js": "./src/user-menu/UserMenu.tsx",
"./user-menu.css": "./src/user-menu/UserMenu.css", "./user-menu.css": "./src/user-menu/UserMenu.css",