Watch
0
0
Fork
You've already forked hyperhive
0

Compare commits

..
21 changed files with 63 additions and 169 deletions

View file

@ -20,20 +20,21 @@ the highlighted one. **Escape**, **Tab** or a click elsewhere shut the list with
changing anything. Typing the start of an option's name picks it, also with the list changing anything. Typing the start of an option's name picks it, also with the list
shut. A dropdown inside a dialog opens above the dialog and the dialog doesn't cut it off. shut. A dropdown inside a dialog opens above the dialog and the dialog doesn't cut it off.
| route | what | | route | what |
| ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `/` | the start page: the swarm's name over a digital-rain backdrop, plus a paperclip offering to set up an agent while no `ruth` exists (it opens the create form with `ruth` filled in); the swarm name in the header links here | | `/` | the start page: the swarm's name over a digital-rain backdrop, plus a paperclip offering to set up an agent while no `ruth` exists (it opens the create form with `ruth` filled in); the swarm name in the header links here |
| `/agents` | every agent, under a folded **hives** card with the hive directory and each hive's last reported status: status, config PR, wanted state, inference settings, resource caps, permissions; create agents (with their permissions, optionally from an [archetype](archetypes.md)), link forge, matrix and GitHub accounts | | `/hives` | the hive directory, each hive with its last reported status |
| `/agents/<name>/terminal` | one agent's live terminal | | `/agents` | every agent: status, config PR, wanted state, inference settings, resource caps, permissions; create agents (with their permissions, optionally from an [archetype](archetypes.md)), link forge, matrix and GitHub accounts |
| `/agents/<name>/subagents/<subagent>/terminal` | one of that agent's subagents' live terminal | | `/agents/<name>/terminal` | one agent's live terminal |
| `/alerts` | the alerts the swarm's Grafana holds now: the firing ones, with a button for the pending, no-data and error ones and a link to Grafana's own alert list; read through the controller with a Viewer service-account token | | `/agents/<name>/subagents/<subagent>/terminal` | one of that agent's subagents' live terminal |
| `/jobs` | the controller's job graph — where agent creation and credential mints show progress | | `/alerts` | the alerts the swarm's Grafana holds now: the firing ones, with a button for the pending, no-data and error ones and a link to Grafana's own alert list; read through the controller with a Viewer service-account token |
| `/schedules` | the scheduled prompts: add, edit, pause, resume and remove | | `/jobs` | the controller's job graph — where agent creation and credential mints show progress |
| `/messages` | the swarm-wide message feed: every message between agents, and to them from the operator, reminders and compaction, with a history window and a filter on sender or recipient; a folded **broadcast** card above the feed sends one message to several agents at once | | `/schedules` | the scheduled prompts: add, edit, pause, resume and remove |
| `/notifications` | the notification router's flows: a switch for each built-in, every flow drawn as a graph, and an editor for custom flows | | `/messages` | the swarm-wide message feed: every message between agents, and to them from the operator, reminders and compaction, with a history window and a filter on sender or recipient; a folded **broadcast** card above the feed sends one message to several agents at once |
| `/issues` | a cross-repo issue report | | `/notifications` | the notification router's flows: a switch for each built-in, every flow drawn as a graph, and an editor for custom flows |
| `/review` | the review classifier: its recent runs, a try-out on a real PR, and its settings | | `/issues` | a cross-repo issue report |
| `/builds` | the swarm builder's recent builds of agent config PRs, with what nix printed when one failed | | `/review` | the review classifier: its recent runs, a try-out on a real PR, and its settings |
| `/builds` | the swarm builder's recent builds of agent config PRs, with what nix printed when one failed |
Everything it shows comes from [`swarm-controller`](../../swarm-controller/README.md). Everything it shows comes from [`swarm-controller`](../../swarm-controller/README.md).
Pages that refresh on a timer share one polling rule: the page sends no new Pages that refresh on a timer share one polling rule: the page sends no new
@ -94,11 +95,10 @@ stream with an error status, the browser gives up and the badge reads
**disconnected**. The **reconnect** button beside it opens the stream again, and **disconnected**. The **reconnect** button beside it opens the stream again, and
the stream replays the rows. The messages page works the same way. the stream replays the rows. The messages page works the same way.
The settings menu in the header has a **hide developer details** toggle. It drops The settings menu in the header has a **hide debug output** toggle. It drops
the muted debug rows (thinking, coalesced ticks, harness chatter) from every the muted debug rows (thinking, coalesced ticks, harness chatter) from every
terminal, the preview and the tabs, and rows already on screen hide or show as terminal, the preview and the tabs, and rows already on screen hide or show as
you flip it. It also hides the **components** tab, a page for developers, which you flip it. The browser keeps the choice for the swarm UI, apart from the
still answers at `/components`. The browser keeps the choice for the swarm UI, apart from the
per-agent pages'. per-agent pages'.
A terminal's own tab takes the agent's icon as its browser-tab icon, so tabs of A terminal's own tab takes the agent's icon as its browser-tab icon, so tabs of

View file

@ -51,7 +51,7 @@ that motivated the change.
| `warn` | amber, left rule | stderr, an unrecognised event shape, API retries | | `warn` | amber, left rule | stderr, an unrecognised event shape, API retries |
| `error` | red, left rule | turn failed, a tool result with `is_error: true` | | `error` | red, left rule | turn failed, a tool result with `is_error: true` |
The settings menu's "hide developer details" toggle (`getHideDebugPref()`, The settings menu's "hide debug output" toggle (`getHideDebugPref()`,
`@hive/shared/prefs.js`) skips `debug`-level rows entirely rather than `@hive/shared/prefs.js`) skips `debug`-level rows entirely rather than
muting them further — client-side only, no reload. The per-agent page and muting them further — client-side only, no reload. The per-agent page and
the swarm UI both have the toggle, as one shared row the swarm UI both have the toggle, as one shared row

View file

@ -1,4 +1,4 @@
// Settings-menu row: "hide developer details". Rendered as a `<SettingsMenu>` // Settings-menu row: "hide debug output". Rendered as a `<SettingsMenu>`
// child (`./SettingsMenu.js`) by each page that has a terminal, the // child (`./SettingsMenu.js`) by each page that has a terminal, the
// per-agent page and the swarm UI, rather than as a prop on the menu: the // per-agent page and the swarm UI, rather than as a prop on the menu: the
// caller owns its row. Both read the same preference (`../prefs.js`), which // caller owns its row. Both read the same preference (`../prefs.js`), which
@ -11,7 +11,7 @@ export function HideDebugSetting() {
const [hideDebug, setHideDebugState] = useState(() => getHideDebugPref()); const [hideDebug, setHideDebugState] = useState(() => getHideDebugPref());
return ( return (
<label class="settings-menu-row"> <label class="settings-menu-row">
<span>hide developer details</span> <span>hide debug output</span>
<input <input
type="checkbox" type="checkbox"
checked={hideDebug} checked={hideDebug}

View file

@ -58,7 +58,7 @@ function DiffBody({ text }: { text: string }) {
); );
} }
// A `debug` row, which follows the "hide developer details" preference as it // A `debug` row, which follows the "hide debug output" preference as it
// changes. Only debug rows subscribe, so a long terminal does not hold a // changes. Only debug rows subscribe, so a long terminal does not hold a
// listener per row. // listener per row.
function DebugRow({ row }: { row: TermRow }) { function DebugRow({ row }: { row: TermRow }) {
@ -67,7 +67,7 @@ function DebugRow({ row }: { row: TermRow }) {
() => subscribeHideDebugPref(() => setHidden(getHideDebugPref())), () => subscribeHideDebugPref(() => setHidden(getHideDebugPref())),
[], [],
); );
// "hide developer details" is a skip, not a dimmer — a hidden debug row // "hide debug output" is a skip, not a dimmer — a hidden debug row
// still occupies no DOM node at all, same as it never streamed, rather // still occupies no DOM node at all, same as it never streamed, rather
// than a CSS `display: none` that would keep it in the layout/DOM for // than a CSS `display: none` that would keep it in the layout/DOM for
// no benefit. // no benefit.

View file

@ -13,6 +13,7 @@ import { FlowEditorPage } from "./pages/notifications/FlowEditorPage.js";
import { NotificationsPage } from "./pages/notifications/NotificationsPage.js"; import { NotificationsPage } from "./pages/notifications/NotificationsPage.js";
import { ComponentsPage } from "./pages/ComponentsPage.js"; import { ComponentsPage } from "./pages/ComponentsPage.js";
import { JobsPage } from "./pages/JobsPage.js"; import { JobsPage } from "./pages/JobsPage.js";
import { HivesPage } from "./pages/HivesPage.js";
import { IssueReportPage } from "./pages/IssueReportPage.js"; import { IssueReportPage } from "./pages/IssueReportPage.js";
import { ReviewPage } from "./pages/review/ReviewPage.js"; import { ReviewPage } from "./pages/review/ReviewPage.js";
import { SchedulesPage } from "./pages/schedules/SchedulesPage.js"; import { SchedulesPage } from "./pages/schedules/SchedulesPage.js";
@ -33,6 +34,7 @@ export function App() {
<Shell> <Shell>
<Switch> <Switch>
<Route path="/" component={StartPage} /> <Route path="/" component={StartPage} />
<Route path="/hives" component={HivesPage} />
<Route path="/alerts" component={AlertsPage} /> <Route path="/alerts" component={AlertsPage} />
<Route path="/agents" component={AgentsPage} /> <Route path="/agents" component={AgentsPage} />
<Route path="/agents/:name/terminal" component={AgentTerminalPage} /> <Route path="/agents/:name/terminal" component={AgentTerminalPage} />

View file

@ -32,7 +32,7 @@ export interface AgentRow {
name: string; name: string;
hive: string | null; hive: string | null;
freshness: Freshness; freshness: Freshness;
// `age_seconds` deliberately unused here, same reason as HivesCard: // `age_seconds` deliberately unused here, same reason as HivesPage:
// `RelativeTime` recomputes age client-side from `last_seen_unix` // `RelativeTime` recomputes age client-side from `last_seen_unix`
// rather than rendering a once-computed-at-fetch value. // rather than rendering a once-computed-at-fetch value.
last_seen_unix: number | null; last_seen_unix: number | null;
@ -50,11 +50,11 @@ export function showsLoginNeeded(row: Pick<AgentRow, "needs_login">): boolean {
return row.needs_login === true; return row.needs_login === true;
} }
// Same tone pairing as HivesCard — one freshness enum shared by both // Same tone pairing as HivesPage — one freshness enum shared by both
// endpoints, so the same tone rule applies to both pages — but // endpoints, so the same tone rule applies to both pages — but
// `unknown`'s label diverges deliberately: an agent outside the // `unknown`'s label diverges deliberately: an agent outside the
// swarm-identity roster has a concrete next step (register it), while // swarm-identity roster has a concrete next step (register it), while
// an unrecognized *hive* on HivesCard doesn't carry the same // an unrecognized *hive* on HivesPage doesn't carry the same
// actionable meaning. // actionable meaning.
export const FRESHNESS: Record<Freshness, { tone: BadgeTone; label: string }> = export const FRESHNESS: Record<Freshness, { tone: BadgeTone; label: string }> =
{ {

View file

@ -1,7 +1,7 @@
// <AlertsPage> — `/alerts`' content: the alerts the swarm's Grafana holds // <AlertsPage> — `/alerts`' content: the alerts the swarm's Grafana holds
// now, from swarm-controller's `GET /api/alerts`. Only the firing ones show at // now, from swarm-controller's `GET /api/alerts`. Only the firing ones show at
// first; a button in the header adds the pending, no-data and errored ones. // first; a button in the header adds the pending, no-data and errored ones.
// Same shape as `HivesCard`: one fetch on a `RefreshIntervalPicker` cadence, // Same shape as `HivesPage`: one fetch on a `RefreshIntervalPicker` cadence,
// rendered as a `Table`. // rendered as a `Table`.
import { useState } from "preact/hooks"; import { useState } from "preact/hooks";
import { ApiErrorPanel } from "@hive/shared/api-error-panel.js"; import { ApiErrorPanel } from "@hive/shared/api-error-panel.js";

View file

@ -80,7 +80,7 @@ const TABLE_COLUMNS: TableColumn<Row>[] = [
render: (r) => r.detail, render: (r) => r.detail,
// One filterable column, multiselect mode — the checkbox-list popover // One filterable column, multiselect mode — the checkbox-list popover
// + reset-filters button are both real `Table` behavior an operator // + reset-filters button are both real `Table` behavior an operator
// hits daily (`AgentsPage`/`HivesCard`), so the demo shows them rather // hits daily (`AgentsPage`/`HivesPage`), so the demo shows them rather
// than a plain unfilterable grid. // than a plain unfilterable grid.
filterValues: (r) => [r.detail], filterValues: (r) => [r.detail],
filterMode: "multiselect", filterMode: "multiselect",
@ -408,7 +408,7 @@ export function ComponentsPage() {
panel body content panel body content
</Panel> </Panel>
</Sample> </Sample>
<Sample label="with actions (e.g. HivesCard's refresh picker)"> <Sample label="with actions (e.g. HivesPage's refresh picker)">
<Panel <Panel
title="example title" title="example title"
actions={ actions={

View file

@ -71,7 +71,7 @@ import {
} from "./CreateAgentSteps.js"; } from "./CreateAgentSteps.js";
import "./CreateAgentForm.css"; import "./CreateAgentForm.css";
// Mirrors swarm-controller's `HiveEntry` — same shape `HivesCard` // Mirrors swarm-controller's `HiveEntry` — same shape `HivesPage`
// consumes off `/api/hives/status`, but this page hits the plain // consumes off `/api/hives/status`, but this page hits the plain
// `/api/hives` roster (no status/freshness needed, just "what hives // `/api/hives` roster (no status/freshness needed, just "what hives
// exist to spawn into"). // exist to spawn into").

View file

@ -1,5 +1,4 @@
// <HivesCard> — the hive roster, a card on the agents page that starts folded. // <HivesPage> — the hive roster, `/hives`' content. Fetches
// Fetches
// swarm-controller's `GET /api/hives/status`, the swarm-wide status // swarm-controller's `GET /api/hives/status`, the swarm-wide status
// aggregate: one row per roster hive, freshness derived at read time // aggregate: one row per roster hive, freshness derived at read time
// from the status bucket. Supersedes the earlier `GET /api/hives` + // from the status bucket. Supersedes the earlier `GET /api/hives` +
@ -16,16 +15,15 @@
import { useState } from "preact/hooks"; import { useState } from "preact/hooks";
import { ApiErrorPanel } from "@hive/shared/api-error-panel.js"; import { ApiErrorPanel } from "@hive/shared/api-error-panel.js";
import { Badge, type BadgeTone } from "@hive/shared/badge.js"; import { Badge, type BadgeTone } from "@hive/shared/badge.js";
import { Disclosure } from "../../ui/disclosure/Disclosure.js"; import { Panel } from "../ui/panel/Panel.js";
import { RelativeTime } from "../../ui/relative-time/RelativeTime.js"; import { RelativeTime } from "../ui/relative-time/RelativeTime.js";
import { import {
RefreshIntervalPicker, RefreshIntervalPicker,
type RefreshIntervalMs, type RefreshIntervalMs,
} from "../../ui/refresh-interval/RefreshInterval.js"; } from "../ui/refresh-interval/RefreshInterval.js";
import { fetchJson, usePolled } from "../../ui/polled/usePolled.js"; import { fetchJson, usePolled } from "../ui/polled/usePolled.js";
import { Table, type TableColumn } from "../../ui/table/Table.js"; import { Table, type TableColumn } from "../ui/table/Table.js";
import { domainCell } from "../hive-domain.js"; import { domainCell } from "./hive-domain.js";
import { builtAfterToggle } from "./lazy-open.js";
type Freshness = "fresh" | "stale" | "never_reported" | "unknown"; type Freshness = "fresh" | "stale" | "never_reported" | "unknown";
@ -105,16 +103,14 @@ const COLUMNS: TableColumn<HiveStatus>[] = [
}, },
]; ];
// 30s default: this card has no inputs to interrupt, and the whole // 30s default: this page has no inputs to interrupt, and the whole
// point of a refresh-interval control is "no manual reload needed" — an // point of a refresh-interval control is "no manual reload needed" — an
// operator who wants it off still can, but the out-of-the-box behaviour // operator who wants it off still can, but the out-of-the-box behaviour
// should actually solve the staleness problem rather than require an // should actually solve the staleness problem rather than require an
// opt-in every visit. // opt-in every visit.
const DEFAULT_INTERVAL_MS: RefreshIntervalMs = 30_000; const DEFAULT_INTERVAL_MS: RefreshIntervalMs = 30_000;
// The roster is read on the first open and followed after, so an agents page export function HivesPage() {
// where the card is never opened does not poll it.
function HiveRoster() {
const [intervalMs, setIntervalMs] = const [intervalMs, setIntervalMs] =
useState<RefreshIntervalMs>(DEFAULT_INTERVAL_MS); useState<RefreshIntervalMs>(DEFAULT_INTERVAL_MS);
const { data: hives, error } = usePolled(intervalMs, (signal) => const { data: hives, error } = usePolled(intervalMs, (signal) =>
@ -122,14 +118,17 @@ function HiveRoster() {
); );
return ( return (
<> <Panel
<div class="ui-hives-refresh"> title="hives"
icon="🐝"
actions={
<RefreshIntervalPicker <RefreshIntervalPicker
id="hives-refresh" id="hives-refresh"
value={intervalMs} value={intervalMs}
onChange={setIntervalMs} onChange={setIntervalMs}
/> />
</div> }
>
{error ? ( {error ? (
<ApiErrorPanel <ApiErrorPanel
context="failed to load the hive roster" context="failed to load the hive roster"
@ -146,25 +145,6 @@ function HiveRoster() {
storageKey="swarm-ui:hives:table-filters" storageKey="swarm-ui:hives:table-filters"
/> />
) : null} ) : null}
</> </Panel>
);
}
export function HivesCard() {
const [open, setOpen] = useState(false);
const [built, setBuilt] = useState(false);
return (
<Disclosure
title="hives"
icon="🐝"
hint="the swarm's hives and when each last reported"
open={open}
onToggle={(next) => {
setOpen(next);
setBuilt((was) => builtAfterToggle(was, next));
}}
>
{built ? <HiveRoster /> : null}
</Disclosure>
); );
} }

View file

@ -12,7 +12,7 @@
// the dashboard's 4G3NTS tab shows — no `queueHref`, since a "view // the dashboard's 4G3NTS tab shows — no `queueHref`, since a "view
// queue →" link back to this same page would be noise. // queue →" link back to this same page would be noise.
// //
// Auto-refresh reuses `HivesCard`'s exact pattern (`RefreshIntervalPicker` // Auto-refresh reuses `HivesPage`'s exact pattern (`RefreshIntervalPicker`
// in the `Panel`'s `actions` slot, `useRefreshInterval` driving the // in the `Panel`'s `actions` slot, `useRefreshInterval` driving the
// re-fetch), but ticks a `refreshToken` bump instead of doing its own // re-fetch), but ticks a `refreshToken` bump instead of doing its own
// fetch — both `JobqGraph`/`JobqRollup` already accept that prop // fetch — both `JobqGraph`/`JobqRollup` already accept that prop
@ -29,7 +29,7 @@ import {
} from "../ui/refresh-interval/RefreshInterval.js"; } from "../ui/refresh-interval/RefreshInterval.js";
import "./JobsPage.css"; import "./JobsPage.css";
// Same 30s default + same reasoning as `HivesCard`: no inputs on this // Same 30s default + same reasoning as `HivesPage`: no inputs on this
// page for a refresh to clobber, so the out-of-the-box behaviour should // page for a refresh to clobber, so the out-of-the-box behaviour should
// just solve staleness rather than require an opt-in every visit. // just solve staleness rather than require an opt-in every visit.
const DEFAULT_INTERVAL_MS: RefreshIntervalMs = 30_000; const DEFAULT_INTERVAL_MS: RefreshIntervalMs = 30_000;

View file

@ -1,6 +1,7 @@
// <StartPage> — `/`, the swarm's landing page: the swarm's name over the // <StartPage> — `/`, the swarm's landing page: the swarm's name over the
// digital-rain backdrop, plus the setup assistant while the swarm has no // digital-rain backdrop, plus the setup assistant while the swarm has no
// `ruth`. The header's swarm name links here. The hive roster is a card on the agents page. // `ruth`. The header's swarm name links here. The hive roster that used to be
// `/` is now `/hives`.
import { MatrixRain } from "../shell/MatrixRain.js"; import { MatrixRain } from "../shell/MatrixRain.js";
import { useSwarmName } from "../shell/useSwarmName.js"; import { useSwarmName } from "../shell/useSwarmName.js";
import { SetupAssistant } from "./SetupAssistant.js"; import { SetupAssistant } from "./SetupAssistant.js";

View file

@ -36,14 +36,3 @@
.ui-agents-view-toggle button:not(.active):hover { .ui-agents-view-toggle button:not(.active):hover {
color: var(--fg); color: var(--fg);
} }
/* The folded hives card over the agents and details panels. */
.ui-agents-hives {
margin-block-end: 1em;
}
/* The roster's refresh picker, at the top right of the open card. */
.ui-hives-refresh {
display: flex;
justify-content: flex-end;
margin-block-end: 0.5em;
}

View file

@ -4,7 +4,7 @@
// status panel has anything to render against without a roster to embed // status panel has anything to render against without a roster to embed
// in — so all three ended up as one page. // in — so all three ended up as one page.
// //
// One fetch, on a refresh-interval cadence like HivesCard: `GET // One fetch, on a refresh-interval cadence like HivesPage: `GET
// /api/agents/status` — one row per roster agent (identity store is the // /api/agents/status` — one row per roster agent (identity store is the
// roster, so a never-reported agent still gets a row), each already // roster, so a never-reported agent still gets a row), each already
// carrying its freshness/snapshot/config PR/wanted state. Used to be // carrying its freshness/snapshot/config PR/wanted state. Used to be
@ -38,7 +38,6 @@ import { Button } from "../../ui/button/Button.js";
import { Dialog } from "../../ui/dialog/Dialog.js"; import { Dialog } from "../../ui/dialog/Dialog.js";
import { FilterableView } from "../../ui/filterable-view/FilterableView.js"; import { FilterableView } from "../../ui/filterable-view/FilterableView.js";
import { Panel } from "../../ui/panel/Panel.js"; import { Panel } from "../../ui/panel/Panel.js";
import { HivesCard } from "./HivesCard.js";
import { RelativeTime } from "../../ui/relative-time/RelativeTime.js"; import { RelativeTime } from "../../ui/relative-time/RelativeTime.js";
import { import {
RefreshIntervalPicker, RefreshIntervalPicker,
@ -51,7 +50,7 @@ import { CreateAgentForm } from "../CreateAgentForm.js";
import { WantedMenu } from "../../agent/roster/WantedMenu.js"; import { WantedMenu } from "../../agent/roster/WantedMenu.js";
import "./AgentsPage.css"; import "./AgentsPage.css";
// Same 30s default + same reasoning as HivesCard: no inputs on this page // Same 30s default + same reasoning as HivesPage: no inputs on this page
// for a refresh to clobber, so the out-of-the-box behaviour should just // for a refresh to clobber, so the out-of-the-box behaviour should just
// solve staleness rather than require an opt-in every visit. // solve staleness rather than require an opt-in every visit.
const DEFAULT_INTERVAL_MS: RefreshIntervalMs = 30_000; const DEFAULT_INTERVAL_MS: RefreshIntervalMs = 30_000;
@ -256,9 +255,6 @@ export function AgentsPage() {
return ( return (
<> <>
<div class="ui-agents-hives">
<HivesCard />
</div>
<SplitView <SplitView
primary={ primary={
<Panel <Panel

View file

@ -1,5 +0,0 @@
// A folded card builds its body on the first open and keeps it after, so a
// card nobody opens never fetches, and closing it does not drop what it read.
export function builtAfterToggle(built: boolean, open: boolean): boolean {
return built || open;
}

View file

@ -31,12 +31,11 @@ import type { ComponentChildren } from "preact";
import { Link, useLocation } from "wouter-preact"; import { Link, useLocation } from "wouter-preact";
import { LinksMenu } from "./LinksMenu.js"; import { LinksMenu } from "./LinksMenu.js";
import { UserMenu } from "./UserMenu.js"; import { UserMenu } from "./UserMenu.js";
import { useHideDebug } from "./useHideDebug.js";
import { SettingsMenu } from "@hive/shared/settings-menu.js"; import { SettingsMenu } from "@hive/shared/settings-menu.js";
import { HideDebugSetting } from "@hive/shared/hide-debug-setting.js"; import { HideDebugSetting } from "@hive/shared/hide-debug-setting.js";
import { useApplyThemeOverride } from "@hive/shared/theme-apply.js"; import { useApplyThemeOverride } from "@hive/shared/theme-apply.js";
import { useApplyMotionOverride } from "@hive/shared/motion-apply.js"; import { useApplyMotionOverride } from "@hive/shared/motion-apply.js";
import { isFullBleedRoute, visibleNavItems } from "./routes.js"; import { isFullBleedRoute } from "./routes.js";
import { useDynamicTabs } from "./useDynamicTabs.js"; import { useDynamicTabs } from "./useDynamicTabs.js";
import { useSwarmName } from "./useSwarmName.js"; import { useSwarmName } from "./useSwarmName.js";
import "./Shell.css"; import "./Shell.css";
@ -50,6 +49,7 @@ const THEME_KEY = "swarm-ui:theme-override";
const MOTION_KEY = "swarm-ui:motion-override"; const MOTION_KEY = "swarm-ui:motion-override";
const NAV_ITEMS: { href: string; label: string; accent: string }[] = [ const NAV_ITEMS: { href: string; label: string; accent: string }[] = [
{ href: "/hives", label: "hives", accent: "var(--purple)" },
{ href: "/agents", label: "agents", accent: "var(--green)" }, { href: "/agents", label: "agents", accent: "var(--green)" },
{ href: "/alerts", label: "alerts", accent: "var(--red)" }, { href: "/alerts", label: "alerts", accent: "var(--red)" },
{ href: "/jobs", label: "jobs", accent: "var(--pink)" }, { href: "/jobs", label: "jobs", accent: "var(--pink)" },
@ -209,11 +209,6 @@ export function Shell({ children }: { children: ComponentChildren }) {
// rather than reusing `NavLink`. // rather than reusing `NavLink`.
const { tabs, close: closeTab } = useDynamicTabs(); const { tabs, close: closeTab } = useDynamicTabs();
// The components tab is a developer page: it goes while "hide developer
// details" is on. The page itself still answers at `/components`.
const hideDeveloper = useHideDebug();
const navItems = visibleNavItems(NAV_ITEMS, hideDeveloper);
// Applied once here, not inside `SettingsMenu` — every route mounts // Applied once here, not inside `SettingsMenu` — every route mounts
// through this one `<Shell>`, so the override takes effect regardless // through this one `<Shell>`, so the override takes effect regardless
// of which page is showing or whether the menu's ever been opened, // of which page is showing or whether the menu's ever been opened,
@ -231,7 +226,7 @@ export function Shell({ children }: { children: ComponentChildren }) {
// scroll-offset bookkeeping needed. // scroll-offset bookkeeping needed.
function measureIndex(index: number): IndicatorRect | null { function measureIndex(index: number): IndicatorRect | null {
const navEl = navRef.current; const navEl = navRef.current;
const item = navItems[index]; const item = NAV_ITEMS[index];
const textEl = item ? textRefs.current[item.href] : null; const textEl = item ? textRefs.current[item.href] : null;
if (!navEl || !item || !textEl) return null; if (!navEl || !item || !textEl) return null;
const navRect = navEl.getBoundingClientRect(); const navRect = navEl.getBoundingClientRect();
@ -250,14 +245,8 @@ export function Shell({ children }: { children: ComponentChildren }) {
// [c's colour]"). Re-runs on navigation; a separate resize listener // [c's colour]"). Re-runs on navigation; a separate resize listener
// below re-measures the already-settled position without re-hopping // below re-measures the already-settled position without re-hopping
// (a reflow isn't a navigation). // (a reflow isn't a navigation).
// The list changed (the components tab came or went), so the settled index
// no longer names the same item: land directly on the active one again.
useEffect(() => { useEffect(() => {
settledIndexRef.current = -1; const targetIndex = NAV_ITEMS.findIndex((item) => item.href === location);
}, [hideDeveloper]);
useEffect(() => {
const targetIndex = navItems.findIndex((item) => item.href === location);
if (targetIndex === -1) { if (targetIndex === -1) {
settledIndexRef.current = -1; settledIndexRef.current = -1;
setIndicator(null); setIndicator(null);
@ -289,7 +278,7 @@ export function Shell({ children }: { children: ComponentChildren }) {
cancelled = true; cancelled = true;
if (timeoutId !== undefined) window.clearTimeout(timeoutId); if (timeoutId !== undefined) window.clearTimeout(timeoutId);
}; };
}, [location, hideDeveloper]); }, [location]);
// Fires the render *after* the indicator's first non-null commit — // Fires the render *after* the indicator's first non-null commit —
// deliberately one tick behind, not folded into the effect above, // deliberately one tick behind, not folded into the effect above,
@ -334,7 +323,7 @@ export function Shell({ children }: { children: ComponentChildren }) {
// label its page registered as a dynamic tab. An unmatched path gets // label its page registered as a dynamic tab. An unmatched path gets
// the bare brand. // the bare brand.
const pageLabel = const pageLabel =
navItems.find((item) => item.href === location)?.label ?? NAV_ITEMS.find((item) => item.href === location)?.label ??
tabs.find((tab) => tab.href === location)?.label; tabs.find((tab) => tab.href === location)?.label;
useEffect(() => { useEffect(() => {
document.title = pageLabel ? `${pageLabel} · ${brand}` : brand; document.title = pageLabel ? `${pageLabel} · ${brand}` : brand;
@ -366,7 +355,7 @@ export function Shell({ children }: { children: ComponentChildren }) {
</span> </span>
</Link> </Link>
<nav class="shell-nav" ref={navRef}> <nav class="shell-nav" ref={navRef}>
{navItems.map((item) => ( {NAV_ITEMS.map((item) => (
<NavLink <NavLink
key={item.href} key={item.href}
href={item.href} href={item.href}

View file

@ -15,15 +15,3 @@ const FULL_BLEED_ROUTE_PATTERN =
export function isFullBleedRoute(location: string): boolean { export function isFullBleedRoute(location: string): boolean {
return location === "/" || FULL_BLEED_ROUTE_PATTERN.test(location); return location === "/" || FULL_BLEED_ROUTE_PATTERN.test(location);
} }
// Routes that only a developer needs. "hide developer details" takes their
// tabs out of the nav; the pages themselves still answer at their paths.
const DEVELOPER_ROUTES = ["/components"];
export function visibleNavItems<T extends { href: string }>(
items: readonly T[],
hideDeveloper: boolean,
): readonly T[] {
if (!hideDeveloper) return items;
return items.filter((item) => !DEVELOPER_ROUTES.includes(item.href));
}

View file

@ -1,17 +0,0 @@
// The "hide developer details" preference as a value that follows its toggle:
// this tab's, through `setHideDebugPref`, and another tab's, through the
// `storage` event. The header uses it to hide the components tab.
import { useEffect, useState } from "preact/hooks";
import {
getHideDebugPref,
subscribeHideDebugPref,
} from "@hive/shared/prefs.js";
export function useHideDebug(): boolean {
const [hide, setHide] = useState(getHideDebugPref);
useEffect(
() => subscribeHideDebugPref(() => setHide(getHideDebugPref())),
[],
);
return hide;
}

View file

@ -9,7 +9,7 @@
// belongs next to the thing it affects, not tucked into a catch-all // belongs next to the thing it affects, not tucked into a catch-all
// menu" — and per mara's review on the refresh-interval PR, not a // menu" — and per mara's review on the refresh-interval PR, not a
// dedicated row stealing vertical space from the panel's actual // dedicated row stealing vertical space from the panel's actual
// content either). `HivesCard`'s refresh-interval picker is the // content either). `HivesPage`'s refresh-interval picker is the
// motivating caller. // motivating caller.
// //
// `onClose`: end-of-header close (✕) for `Dialog`'s `plain` mode. // `onClose`: end-of-header close (✕) for `Dialog`'s `plain` mode.

View file

@ -1,16 +0,0 @@
// A folded card fetches nothing until first opened. Run by `npm test`.
import assert from "node:assert/strict";
import { test } from "node:test";
import { builtAfterToggle } from "../src/pages/agents/lazy-open.ts";
test("a card nobody opened is not built", () => {
assert.equal(builtAfterToggle(false, false), false);
});
test("the first open builds it", () => {
assert.equal(builtAfterToggle(false, true), true);
});
test("closing it afterwards keeps it built", () => {
assert.equal(builtAfterToggle(true, false), true);
});

Some files were not shown because too many files have changed in this diff Show more