From 25965341e0be2a09906a8bb4d1f9810a8757b2c5 Mon Sep 17 00:00:00 2001 From: iris Date: Wed, 25 Nov 2026 21:43:23 +0100 Subject: [PATCH] frontend: one tone vocabulary for badges, hints, banners and toasts Part of the unification order in the UI sweep issue (step b). A badge named its tones positive/warning/negative, a hint muted/warn/error/ok, a banner info/warning/error and a toast info/ok/error. They now all take the shared Tone: neutral, info, ok, warn, error (a badge adds accent for a selected choice). Warn is amber everywhere (a hint used yellow), info is cyan everywhere (a toast used purple). A test pins the list against each component's CSS. --- docs/4-implementation/web-ui/css-vars.md | 9 ++++ docs/4-implementation/web-ui/swarm-ui.md | 2 +- frontend/packages/shared/package.json | 1 + frontend/packages/shared/src/badge/Badge.css | 9 ++-- frontend/packages/shared/src/badge/Badge.tsx | 12 ++--- frontend/packages/shared/src/tone.ts | 10 ++++ .../shared/src/warn-banner/WarnBanner.tsx | 8 +-- .../packages/swarm-ui/src/agent/AgentTypes.ts | 6 +-- .../swarm-ui/src/agent/detail/AgentApiKey.tsx | 2 +- .../src/agent/detail/AgentIdentity.tsx | 4 +- .../src/agent/detail/AgentPermissions.tsx | 4 +- .../swarm-ui/src/agent/detail/AgentSsh.tsx | 2 +- .../swarm-ui/src/agent/roster/AgentCard.tsx | 4 +- .../swarm-ui/src/agent/roster/WantedMenu.tsx | 6 +-- .../swarm-ui/src/agent/state/StateBadges.tsx | 4 +- .../src/agent/terminal/BashTasksMenu.tsx | 2 +- .../src/agent/terminal/CancelTurnBadge.tsx | 4 +- .../src/agent/terminal/SubagentsMenu.tsx | 2 +- .../swarm-ui/src/pages/AlertsPage.tsx | 8 +-- .../swarm-ui/src/pages/ComponentsPage.tsx | 15 ++---- .../swarm-ui/src/pages/IssueReportPage.tsx | 3 +- .../src/pages/LinkMatrixAccountForm.tsx | 2 +- .../swarm-ui/src/pages/PrReportPage.tsx | 10 ++-- .../swarm-ui/src/pages/builds/builds-types.ts | 6 +-- .../src/pages/messages/MessageCards.tsx | 6 +-- .../src/pages/review-common/TryOutResult.tsx | 2 +- .../src/pages/review-runs/RunsTypes.ts | 10 ++-- .../src/pages/schedules/ScheduleCard.tsx | 4 +- .../swarm-ui/src/pages/swarm/HivesCard.tsx | 8 +-- .../swarm-ui/src/pages/swarm/SwarmPage.tsx | 4 +- .../packages/swarm-ui/src/ui/hint/Hint.css | 7 ++- .../packages/swarm-ui/src/ui/hint/Hint.tsx | 7 +-- .../packages/swarm-ui/src/ui/toast/Toast.css | 5 +- .../packages/swarm-ui/src/ui/toast/toasts.ts | 4 +- .../swarm-ui/test/runs-types.test.mjs | 8 +-- frontend/packages/swarm-ui/test/tone.test.mjs | 50 +++++++++++++++++++ 36 files changed, 164 insertions(+), 86 deletions(-) create mode 100644 frontend/packages/shared/src/tone.ts create mode 100644 frontend/packages/swarm-ui/test/tone.test.mjs diff --git a/docs/4-implementation/web-ui/css-vars.md b/docs/4-implementation/web-ui/css-vars.md index 8ae2919b6..4d47859f0 100644 --- a/docs/4-implementation/web-ui/css-vars.md +++ b/docs/4-implementation/web-ui/css-vars.md @@ -117,6 +117,15 @@ stylesheet names a role and never a number: Stacking inside one component (1 or 2) stays a plain number. A new floating box uses `--z-popover` and `--shadow-pop`. +## Status tones + +A badge, a hint, a banner and a toast all take one of five tones, defined in +`shared/src/tone.ts`: `neutral` (no signal), `info` (cyan), `ok` (green), `warn` +(amber) and `error` (red). A badge adds `accent` for a selected or active choice. +A banner takes `info`, `warn` or `error`, and a toast takes the four that carry a +signal. A component that shows a status takes a `Tone` and doesn't invent a +fifth spelling. + ## Common mistakes The Catppuccin colour names **don't** map 1:1 to the variable names. diff --git a/docs/4-implementation/web-ui/swarm-ui.md b/docs/4-implementation/web-ui/swarm-ui.md index d75ab60b8..2937dcf5b 100644 --- a/docs/4-implementation/web-ui/swarm-ui.md +++ b/docs/4-implementation/web-ui/swarm-ui.md @@ -999,7 +999,7 @@ restricted, log or unrestricted. Selecting it lists the three modes; picking one `PUT` of the mode with the stored permissions beside it. The **repositories** row is how many repositories the agent's forge account may -create: a badge reading none or `up to N`, in the warning tone above 0. Selecting +create: a badge reading none or `up to N`, in the `warn` tone above 0. Selecting it opens a number box, 0 to 100, and **save** does a `PUT` of `max_repos` with the stored permissions beside it. A `PUT` that leaves `max_repos` out, and the `DELETE` of **use the default**, keep it. Nothing stored means 0, and the box warns that an diff --git a/frontend/packages/shared/package.json b/frontend/packages/shared/package.json index 2156b803e..c6c4e764a 100644 --- a/frontend/packages/shared/package.json +++ b/frontend/packages/shared/package.json @@ -42,6 +42,7 @@ "./warn-banner.css": "./src/warn-banner/WarnBanner.css", "./icon-button.js": "./src/icon-button/IconButton.tsx", "./icon-button.css": "./src/icon-button/IconButton.css", + "./tone.js": "./src/tone.ts", "./badge.js": "./src/badge/Badge.tsx", "./badge.css": "./src/badge/Badge.css", "./button.css": "./src/button/Button.css", diff --git a/frontend/packages/shared/src/badge/Badge.css b/frontend/packages/shared/src/badge/Badge.css index 1675cccd2..4e89528eb 100644 --- a/frontend/packages/shared/src/badge/Badge.css +++ b/frontend/packages/shared/src/badge/Badge.css @@ -89,15 +89,18 @@ conventions or css mix new colors" — this is that; stock mocha/latte keep their existing look, since both accents already sit close to `--fg` in contrast terms). */ -.ui-badge-positive .ui-badge-value { +.ui-badge-ok .ui-badge-value { color: color-mix(in srgb, var(--green) 60%, var(--fg)); } -.ui-badge-warning .ui-badge-value { +.ui-badge-warn .ui-badge-value { color: color-mix(in srgb, var(--amber) 60%, var(--fg)); } -.ui-badge-negative .ui-badge-value { +.ui-badge-error .ui-badge-value { color: color-mix(in srgb, var(--red) 60%, var(--fg)); } +.ui-badge-info .ui-badge-value { + color: color-mix(in srgb, var(--cyan) 60%, var(--fg)); +} .ui-badge-accent .ui-badge-value { color: color-mix(in srgb, var(--purple) 60%, var(--fg)); } diff --git a/frontend/packages/shared/src/badge/Badge.tsx b/frontend/packages/shared/src/badge/Badge.tsx index 1fe14cb90..f42d59efa 100644 --- a/frontend/packages/shared/src/badge/Badge.tsx +++ b/frontend/packages/shared/src/badge/Badge.tsx @@ -19,14 +19,14 @@ // `shared` is the one package both already depend on (see // `docs/5-project/web-ui/design-guide.md`'s component-first + junk-drawer rules). import type { ComponentChildren } from "preact"; +import type { Tone } from "../tone.js"; import "./Badge.css"; -export type BadgeTone = - | "neutral" - | "positive" - | "warning" - | "negative" - | "accent"; +/** + * The shared `Tone`, plus `accent` for "selected" or "active", which marks a + * choice rather than a status. + */ +export type BadgeTone = Tone | "accent"; /** * `'default'` — the filled pill every status/picker badge has always * been. `'quiet'` — no permanent fill, only a background on hover/ diff --git a/frontend/packages/shared/src/tone.ts b/frontend/packages/shared/src/tone.ts new file mode 100644 index 000000000..47e7d50fe --- /dev/null +++ b/frontend/packages/shared/src/tone.ts @@ -0,0 +1,10 @@ +// The one set of status tones: a badge, a hint, a banner and a toast all +// take a `Tone`, so "ok" or "warn" is spelled and coloured the same way +// everywhere. `neutral` is "no signal" (plain text, no colour); the other four +// map to the theme's green, amber, red and cyan (`--green`, `--amber`, +// `--red`, `--cyan`). A new component that shows a status takes a `Tone` and +// does not add a fifth spelling. + +export const TONES = ["neutral", "info", "ok", "warn", "error"] as const; + +export type Tone = (typeof TONES)[number]; diff --git a/frontend/packages/shared/src/warn-banner/WarnBanner.tsx b/frontend/packages/shared/src/warn-banner/WarnBanner.tsx index a8ce723f8..49b35e857 100644 --- a/frontend/packages/shared/src/warn-banner/WarnBanner.tsx +++ b/frontend/packages/shared/src/warn-banner/WarnBanner.tsx @@ -10,13 +10,15 @@ // is the first consumer — compose from this instead of duplicating the // banner's own border/colour/pulse rules locally. // -// `level` defaults to 'warning', matching `hive-warn.js`'s own default. +// `level` defaults to 'warn', matching `hive-warn.js`'s own default. // Only `error` pulses — an active incident, not a standing caveat, same // rule `hive-warn.css`'s own comment states. import type { ComponentChildren } from "preact"; +import type { Tone } from "../tone.js"; import "./WarnBanner.css"; -export type WarnLevel = "info" | "warning" | "error"; +/** A banner is never `neutral` or `ok`: it exists to flag something. */ +export type WarnLevel = Exclude; export interface WarnBannerProps { level?: WarnLevel; @@ -29,7 +31,7 @@ export interface WarnBannerProps { } export function WarnBanner({ - level = "warning", + level = "warn", class: extraClass, children, }: WarnBannerProps) { diff --git a/frontend/packages/swarm-ui/src/agent/AgentTypes.ts b/frontend/packages/swarm-ui/src/agent/AgentTypes.ts index 7122ab52d..11e4af4d9 100644 --- a/frontend/packages/swarm-ui/src/agent/AgentTypes.ts +++ b/frontend/packages/swarm-ui/src/agent/AgentTypes.ts @@ -89,13 +89,13 @@ export function isUpdating(row: Pick): boolean { // actionable meaning. export const FRESHNESS: Record = { - fresh: { tone: "positive", label: "fresh" }, - stale: { tone: "warning", label: "stale" }, + fresh: { tone: "ok", label: "fresh" }, + stale: { tone: "warn", label: "stale" }, never_reported: { tone: "neutral", label: "never reported" }, // `unknown` means the agent reported into the KV bucket but isn't in // the swarm-identity roster — a real, distinct case ("hive-reported, // not yet in swarm level"), not just a fallback default, so it gets a // label that says what to do about it rather than reusing the enum // name as the label. - unknown: { tone: "negative", label: "not in swarm identity" }, + unknown: { tone: "error", label: "not in swarm identity" }, }; diff --git a/frontend/packages/swarm-ui/src/agent/detail/AgentApiKey.tsx b/frontend/packages/swarm-ui/src/agent/detail/AgentApiKey.tsx index e9cd279eb..ec5e0eca6 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/AgentApiKey.tsx +++ b/frontend/packages/swarm-ui/src/agent/detail/AgentApiKey.tsx @@ -75,7 +75,7 @@ export function AgentApiKey({ hive, agent }: { hive: string; agent: string }) { {" "} )} diff --git a/frontend/packages/swarm-ui/src/agent/detail/AgentIdentity.tsx b/frontend/packages/swarm-ui/src/agent/detail/AgentIdentity.tsx index 5846b1599..298dad912 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/AgentIdentity.tsx +++ b/frontend/packages/swarm-ui/src/agent/detail/AgentIdentity.tsx @@ -94,7 +94,7 @@ export function AgentIdentity({ {showsLoginNeeded(row) ? ( @@ -117,7 +117,7 @@ export function AgentIdentity({ ) : null} {row.config_pr ? ( config PR{" "} diff --git a/frontend/packages/swarm-ui/src/agent/detail/AgentPermissions.tsx b/frontend/packages/swarm-ui/src/agent/detail/AgentPermissions.tsx index be9a2dd28..19bfdebbe 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/AgentPermissions.tsx +++ b/frontend/packages/swarm-ui/src/agent/detail/AgentPermissions.tsx @@ -295,7 +295,7 @@ export function AgentInternet({ agent, g }: { agent: string; g: GrantState }) { @@ -359,7 +359,7 @@ export function AgentRepos({ agent, g }: { agent: string; g: GrantState }) { diff --git a/frontend/packages/swarm-ui/src/agent/detail/AgentSsh.tsx b/frontend/packages/swarm-ui/src/agent/detail/AgentSsh.tsx index f53a4a394..0d9aa69f7 100644 --- a/frontend/packages/swarm-ui/src/agent/detail/AgentSsh.tsx +++ b/frontend/packages/swarm-ui/src/agent/detail/AgentSsh.tsx @@ -77,7 +77,7 @@ export function AgentSsh({ agent, g }: { agent: string; g: GrantState }) { diff --git a/frontend/packages/swarm-ui/src/agent/roster/AgentCard.tsx b/frontend/packages/swarm-ui/src/agent/roster/AgentCard.tsx index fbff2ed3d..5450dbba4 100644 --- a/frontend/packages/swarm-ui/src/agent/roster/AgentCard.tsx +++ b/frontend/packages/swarm-ui/src/agent/roster/AgentCard.tsx @@ -150,7 +150,7 @@ export function AgentCard({ ) : null} {hivePauseReason(row) !== null ? ( @@ -162,7 +162,7 @@ export function AgentCard({ {...inert} > diff --git a/frontend/packages/swarm-ui/src/agent/roster/WantedMenu.tsx b/frontend/packages/swarm-ui/src/agent/roster/WantedMenu.tsx index e2e6cfac6..7e0133cf7 100644 --- a/frontend/packages/swarm-ui/src/agent/roster/WantedMenu.tsx +++ b/frontend/packages/swarm-ui/src/agent/roster/WantedMenu.tsx @@ -38,11 +38,11 @@ export function WantedMenu({ const canDeclare = !!row.hive && !destroyed && !undeclared; const tone: BadgeTone = row.wanted === "up" - ? "positive" + ? "ok" : row.wanted === "paused" - ? "warning" + ? "warn" : destroyed - ? "negative" + ? "error" : "neutral"; const options: DropdownOption[] = [ { value: "up", label: "up" }, diff --git a/frontend/packages/swarm-ui/src/agent/state/StateBadges.tsx b/frontend/packages/swarm-ui/src/agent/state/StateBadges.tsx index 236b9dce0..c6bd3907e 100644 --- a/frontend/packages/swarm-ui/src/agent/state/StateBadges.tsx +++ b/frontend/packages/swarm-ui/src/agent/state/StateBadges.tsx @@ -14,7 +14,7 @@ import { const TURN_STATE_TONE: Record = { idle: "neutral", thinking: "accent", - compacting: "warning", + compacting: "warn", }; export function tokenTotal(u: TokenUsage | null): number | null { @@ -73,7 +73,7 @@ export function StateBadges({ own doc), never "offline"/"destroyed" — a stopped or destroyed agent publishes nothing at all. */} {header.agent_state !== "up" && ( - + )} {withModel && (agent === undefined ? ( diff --git a/frontend/packages/swarm-ui/src/agent/terminal/BashTasksMenu.tsx b/frontend/packages/swarm-ui/src/agent/terminal/BashTasksMenu.tsx index d5d27a43a..4d2258710 100644 --- a/frontend/packages/swarm-ui/src/agent/terminal/BashTasksMenu.tsx +++ b/frontend/packages/swarm-ui/src/agent/terminal/BashTasksMenu.tsx @@ -27,7 +27,7 @@ export function BashTasksMenu({ agentName }: { agentName: string }) { } value={running} - tone={running > 0 ? "positive" : "neutral"} + tone={running > 0 ? "ok" : "neutral"} ariaLabel={label} title={`${label}: ${open ? "close" : "open"} ${agentName}'s bash tasks`} expanded={open} diff --git a/frontend/packages/swarm-ui/src/agent/terminal/CancelTurnBadge.tsx b/frontend/packages/swarm-ui/src/agent/terminal/CancelTurnBadge.tsx index 036339b33..db127749c 100644 --- a/frontend/packages/swarm-ui/src/agent/terminal/CancelTurnBadge.tsx +++ b/frontend/packages/swarm-ui/src/agent/terminal/CancelTurnBadge.tsx @@ -62,7 +62,7 @@ export function CancelTurnBadge({ if (state.status === "error") { return ( } value={running.length} - tone={running.length > 0 ? "positive" : "neutral"} + tone={running.length > 0 ? "ok" : "neutral"} ariaLabel={runningLabel(running.length)} title={`${runningLabel(running.length)}: ${open ? "close" : "open"} ${agentName}'s subagents`} expanded={open} diff --git a/frontend/packages/swarm-ui/src/pages/AlertsPage.tsx b/frontend/packages/swarm-ui/src/pages/AlertsPage.tsx index 82fe2cf60..ff24f1af0 100644 --- a/frontend/packages/swarm-ui/src/pages/AlertsPage.tsx +++ b/frontend/packages/swarm-ui/src/pages/AlertsPage.tsx @@ -28,10 +28,10 @@ import { } from "./alerts.js"; const STATE_TONE: Record = { - Alerting: "negative", - Error: "negative", - NoData: "warning", - Pending: "warning", + Alerting: "error", + Error: "error", + NoData: "warn", + Pending: "warn", }; const COLUMNS: TableColumn[] = [ diff --git a/frontend/packages/swarm-ui/src/pages/ComponentsPage.tsx b/frontend/packages/swarm-ui/src/pages/ComponentsPage.tsx index 49076d170..191fafc98 100644 --- a/frontend/packages/swarm-ui/src/pages/ComponentsPage.tsx +++ b/frontend/packages/swarm-ui/src/pages/ComponentsPage.tsx @@ -55,9 +55,10 @@ import { Popover } from "../ui/popover/Popover.js"; import { Badge, type BadgeTone } from "@hive/shared/badge.js"; import { GearIcon } from "@hive/shared/icons.js"; import { Dropdown, type DropdownOption } from "@hive/shared/dropdown.js"; +import { TONES } from "@hive/shared/tone.js"; import "./ComponentsPage.css"; -const HINT_TONES: HintTone[] = ["muted", "warn", "error", "ok"]; +const HINT_TONES: HintTone[] = [...TONES]; const SUBMIT_SAMPLES: [string, SubmitState][] = [ ["done", { status: "done", value: undefined }], @@ -118,7 +119,7 @@ const TABLE_COLUMNS: TableColumn[] = [ { key: "status", header: "status", - render: () => , + render: () => , }, ]; @@ -133,13 +134,7 @@ const SELECT_OPTIONS: SelectOption[] = [ ]; const BUTTON_VARIANTS: ButtonVariant[] = ["primary", "default", "danger"]; -const BADGE_TONES: BadgeTone[] = [ - "neutral", - "positive", - "warning", - "negative", - "accent", -]; +const BADGE_TONES: BadgeTone[] = [...TONES, "accent"]; const MODEL_OPTIONS: DropdownOption[] = [ { value: "haiku", label: "haiku", description: "fast" }, @@ -250,7 +245,7 @@ function BadgeToggleSample() { return ( setPaused((p) => !p)} /> ); diff --git a/frontend/packages/swarm-ui/src/pages/IssueReportPage.tsx b/frontend/packages/swarm-ui/src/pages/IssueReportPage.tsx index af0280a71..df24375fe 100644 --- a/frontend/packages/swarm-ui/src/pages/IssueReportPage.tsx +++ b/frontend/packages/swarm-ui/src/pages/IssueReportPage.tsx @@ -329,8 +329,7 @@ function IssueReportBody() { /> ), ariaSort: ariaSortFor("blocked"), - render: (r) => - r.blocked ? : "—", + render: (r) => (r.blocked ? : "—"), // A distinct gap from the existing "hide blocked" toggle above: // that one only *hides* blocked issues, there was no way to see // *only* the blocked ones. Synthesized two-value set (not the raw diff --git a/frontend/packages/swarm-ui/src/pages/LinkMatrixAccountForm.tsx b/frontend/packages/swarm-ui/src/pages/LinkMatrixAccountForm.tsx index a2ba00743..48664eae8 100644 --- a/frontend/packages/swarm-ui/src/pages/LinkMatrixAccountForm.tsx +++ b/frontend/packages/swarm-ui/src/pages/LinkMatrixAccountForm.tsx @@ -181,7 +181,7 @@ export function LinkMatrixAccountForm({ setMode(v as Mode); }} /> - + {mode === "token" ? TOKEN_WARNING : PASSWORD_NOTE} {mode === "token" ? ( diff --git a/frontend/packages/swarm-ui/src/pages/PrReportPage.tsx b/frontend/packages/swarm-ui/src/pages/PrReportPage.tsx index 089c95f23..af84b661e 100644 --- a/frontend/packages/swarm-ui/src/pages/PrReportPage.tsx +++ b/frontend/packages/swarm-ui/src/pages/PrReportPage.tsx @@ -36,9 +36,9 @@ const REPO_FILTER_KEY = "swarm-ui:pr-report:repo-filter"; const TABLE_FILTERS_KEY = "swarm-ui:pr-report:table-filters"; const CI_TONE: Record, BadgeTone> = { - success: "positive", - pending: "warning", - failure: "negative", + success: "ok", + pending: "warn", + failure: "error", }; const COLUMNS: TableColumn[] = [ @@ -119,7 +119,7 @@ const COLUMNS: TableColumn[] = [ {r.changes_requested > 0 ? ( <> {" "} - + ) : null} @@ -132,7 +132,7 @@ const COLUMNS: TableColumn[] = [ key: "conflicts", header: "conflicts", render: (r) => - r.has_conflicts ? : "—", + r.has_conflicts ? : "—", sortBy: (r) => Number(r.has_conflicts), filterValues: (r) => [yesNo(r.has_conflicts)], filterMode: "multiselect", diff --git a/frontend/packages/swarm-ui/src/pages/builds/builds-types.ts b/frontend/packages/swarm-ui/src/pages/builds/builds-types.ts index b61f7b9ef..a58b0e713 100644 --- a/frontend/packages/swarm-ui/src/pages/builds/builds-types.ts +++ b/frontend/packages/swarm-ui/src/pages/builds/builds-types.ts @@ -35,9 +35,9 @@ export const OUTCOME_LABEL: Record = { }; export const OUTCOME_TONE: Record = { - built: "positive", - failed: "negative", - error: "warning", + built: "ok", + failed: "error", + error: "warn", }; /** diff --git a/frontend/packages/swarm-ui/src/pages/messages/MessageCards.tsx b/frontend/packages/swarm-ui/src/pages/messages/MessageCards.tsx index c4d41b239..aebabd073 100644 --- a/frontend/packages/swarm-ui/src/pages/messages/MessageCards.tsx +++ b/frontend/packages/swarm-ui/src/pages/messages/MessageCards.tsx @@ -43,9 +43,9 @@ const CONNECTION_LABEL: Record = { const CONNECTION_TONE: Record = { connecting: "neutral", - open: "positive", - reconnecting: "warning", - closed: "negative", + open: "ok", + reconnecting: "warn", + closed: "error", }; // One message's row. Memoised on the message, which keeps its identity while it diff --git a/frontend/packages/swarm-ui/src/pages/review-common/TryOutResult.tsx b/frontend/packages/swarm-ui/src/pages/review-common/TryOutResult.tsx index 0db67463c..c2221eb24 100644 --- a/frontend/packages/swarm-ui/src/pages/review-common/TryOutResult.tsx +++ b/frontend/packages/swarm-ui/src/pages/review-common/TryOutResult.tsx @@ -87,7 +87,7 @@ export function TryOutResult({

Overall:

diff --git a/frontend/packages/swarm-ui/src/pages/review-runs/RunsTypes.ts b/frontend/packages/swarm-ui/src/pages/review-runs/RunsTypes.ts index a48601156..dbbbfccd8 100644 --- a/frontend/packages/swarm-ui/src/pages/review-runs/RunsTypes.ts +++ b/frontend/packages/swarm-ui/src/pages/review-runs/RunsTypes.ts @@ -46,13 +46,13 @@ export const OUTCOME_LABEL: Record = { }; export const OUTCOME_TONE: Record = { - approved: "positive", + approved: "ok", "changes-requested": "accent", "no-verdict": "neutral", - "queue-full": "warning", - "post-failed": "negative", - done: "positive", - failed: "negative", + "queue-full": "warn", + "post-failed": "error", + done: "ok", + failed: "error", }; export const TRIGGER_LABEL: Record = { diff --git a/frontend/packages/swarm-ui/src/pages/schedules/ScheduleCard.tsx b/frontend/packages/swarm-ui/src/pages/schedules/ScheduleCard.tsx index 2e03a6694..999035fab 100644 --- a/frontend/packages/swarm-ui/src/pages/schedules/ScheduleCard.tsx +++ b/frontend/packages/swarm-ui/src/pages/schedules/ScheduleCard.tsx @@ -18,8 +18,8 @@ import { import "./ScheduleCard.css"; const STATE_TONE: Record = { - active: "positive", - paused: "warning", + active: "ok", + paused: "warn", past: "neutral", }; diff --git a/frontend/packages/swarm-ui/src/pages/swarm/HivesCard.tsx b/frontend/packages/swarm-ui/src/pages/swarm/HivesCard.tsx index 628e48a4d..a9a96b15e 100644 --- a/frontend/packages/swarm-ui/src/pages/swarm/HivesCard.tsx +++ b/frontend/packages/swarm-ui/src/pages/swarm/HivesCard.tsx @@ -45,13 +45,13 @@ interface HiveStatus { } // One tone + label per freshness value. `unknown` (reporting but absent -// from the roster) reads `negative` — it's the one case this endpoint +// from the roster) reads `error` — it's the one case this endpoint // cannot vouch for at all, per `status.rs`'s doc comment. const FRESHNESS: Record = { - fresh: { tone: "positive", label: "fresh" }, - stale: { tone: "warning", label: "stale" }, + fresh: { tone: "ok", label: "fresh" }, + stale: { tone: "warn", label: "stale" }, never_reported: { tone: "neutral", label: "never reported" }, - unknown: { tone: "negative", label: "unknown" }, + unknown: { tone: "error", label: "unknown" }, }; const COLUMNS: TableColumn[] = [ diff --git a/frontend/packages/swarm-ui/src/pages/swarm/SwarmPage.tsx b/frontend/packages/swarm-ui/src/pages/swarm/SwarmPage.tsx index adc210c55..88cbc8200 100644 --- a/frontend/packages/swarm-ui/src/pages/swarm/SwarmPage.tsx +++ b/frontend/packages/swarm-ui/src/pages/swarm/SwarmPage.tsx @@ -23,8 +23,8 @@ export function SwarmPage() { icon="🔔" hint={ <> - forge events routed to agents, - as flows + forge events routed to agents, as + flows } > diff --git a/frontend/packages/swarm-ui/src/ui/hint/Hint.css b/frontend/packages/swarm-ui/src/ui/hint/Hint.css index 19da0b860..a467dd047 100644 --- a/frontend/packages/swarm-ui/src/ui/hint/Hint.css +++ b/frontend/packages/swarm-ui/src/ui/hint/Hint.css @@ -3,11 +3,14 @@ .ui-hint { margin: 0; } -.ui-hint-muted { +.ui-hint-neutral { color: var(--muted); } +.ui-hint-info { + color: var(--cyan); +} .ui-hint-warn { - color: var(--yellow); + color: var(--amber); } .ui-hint-error { color: var(--red); diff --git a/frontend/packages/swarm-ui/src/ui/hint/Hint.tsx b/frontend/packages/swarm-ui/src/ui/hint/Hint.tsx index 53430ce58..bd3282a66 100644 --- a/frontend/packages/swarm-ui/src/ui/hint/Hint.tsx +++ b/frontend/packages/swarm-ui/src/ui/hint/Hint.tsx @@ -1,19 +1,20 @@ // — a line of small supporting text: helper text under a field, a // count, a status line, an inline problem or a success note. One component // for what each form and card used to restyle under its own class name, so -// "muted", "warning", "error" and "ok" mean the same colour everywhere. +// "neutral", "info", "ok", "warn" and "error" mean the same colour everywhere. // // `error` is read out when it appears (`role="alert"`); the other tones are // plain text unless the caller passes a `role`, such as `status` for a line // that changes after a save. `class` is for a page's // layout around the hint (a margin, a width), not for its colour. import type { ComponentChildren } from "preact"; +import type { Tone } from "@hive/shared/tone.js"; import "./Hint.css"; -export type HintTone = "muted" | "warn" | "error" | "ok"; +export type HintTone = Tone; export function Hint({ - tone = "muted", + tone = "neutral", as: Tag = "p", role, id, diff --git a/frontend/packages/swarm-ui/src/ui/toast/Toast.css b/frontend/packages/swarm-ui/src/ui/toast/Toast.css index 08717e35a..ad9592e62 100644 --- a/frontend/packages/swarm-ui/src/ui/toast/Toast.css +++ b/frontend/packages/swarm-ui/src/ui/toast/Toast.css @@ -27,7 +27,10 @@ white-space: pre-wrap; } .ui-toast-info { - border-left-color: var(--purple-dim); + border-left-color: var(--cyan); +} +.ui-toast-warn { + border-left-color: var(--amber); } .ui-toast-ok { border-left-color: var(--green); diff --git a/frontend/packages/swarm-ui/src/ui/toast/toasts.ts b/frontend/packages/swarm-ui/src/ui/toast/toasts.ts index a71fe339e..db64a1b27 100644 --- a/frontend/packages/swarm-ui/src/ui/toast/toasts.ts +++ b/frontend/packages/swarm-ui/src/ui/toast/toasts.ts @@ -3,7 +3,9 @@ // by itself, and a click dismisses it sooner. Anything that shows one calls // `showToast`; `` renders the list. -export type ToastTone = "info" | "ok" | "error"; +import type { Tone } from "@hive/shared/tone.js"; + +export type ToastTone = Exclude; export interface Toast { id: number; diff --git a/frontend/packages/swarm-ui/test/runs-types.test.mjs b/frontend/packages/swarm-ui/test/runs-types.test.mjs index 82589ab4f..2833bdb7e 100644 --- a/frontend/packages/swarm-ui/test/runs-types.test.mjs +++ b/frontend/packages/swarm-ui/test/runs-types.test.mjs @@ -27,10 +27,10 @@ test("every outcome has a label and a tone", () => { assert.deepEqual(Object.keys(OUTCOME_LABEL).sort(), [...OUTCOMES].sort()); }); -test("a run that failed or could not post reads as negative", () => { - assert.equal(OUTCOME_TONE.failed, "negative"); - assert.equal(OUTCOME_TONE["post-failed"], "negative"); - assert.equal(OUTCOME_TONE.approved, "positive"); +test("a run that failed or could not post reads as an error", () => { + assert.equal(OUTCOME_TONE.failed, "error"); + assert.equal(OUTCOME_TONE["post-failed"], "error"); + assert.equal(OUTCOME_TONE.approved, "ok"); }); test("the triggers are named for the operator", () => { diff --git a/frontend/packages/swarm-ui/test/tone.test.mjs b/frontend/packages/swarm-ui/test/tone.test.mjs new file mode 100644 index 000000000..9f0db8e22 --- /dev/null +++ b/frontend/packages/swarm-ui/test/tone.test.mjs @@ -0,0 +1,50 @@ +// The shared tone list. Run by `npm test`. Each component that takes a `Tone` +// must style every value it accepts, so a tone added to the list without a +// matching CSS rule (or an old spelling left in a stylesheet) fails here. +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { test } from "node:test"; +import { TONES } from "../../shared/src/tone.ts"; + +const css = (rel) => readFileSync(new URL(rel, import.meta.url), "utf8"); + +test("the list is the five agreed spellings", () => { + assert.deepEqual([...TONES], ["neutral", "info", "ok", "warn", "error"]); +}); + +// `neutral` is the default look, so a component may leave it unstyled. +const COMPONENTS = [ + ["badge", "../../shared/src/badge/Badge.css", "ui-badge-", ["neutral"]], + ["hint", "../src/ui/hint/Hint.css", "ui-hint-", []], + ["toast", "../src/ui/toast/Toast.css", "ui-toast-", ["neutral"]], +]; + +for (const [name, file, prefix, unstyled] of COMPONENTS) { + test(`${name} styles every tone it takes`, () => { + const text = css(file); + for (const tone of TONES) { + if (unstyled.includes(tone)) continue; + assert.ok( + text.includes(`.${prefix}${tone}`), + `${name}: no .${prefix}${tone}`, + ); + } + }); + + test(`${name} keeps no old tone spelling`, () => { + const text = css(file); + for (const old of ["positive", "negative", "warning", "muted"]) { + assert.ok( + !text.includes(`.${prefix}${old}`), + `${name}: .${prefix}${old}`, + ); + } + }); +} + +test("the banner styles info and error, and warn is its base look", () => { + const text = css("../../shared/src/warn-banner/WarnBanner.css"); + assert.ok(text.includes(".warn-banner-info")); + assert.ok(text.includes(".warn-banner-error")); + assert.ok(!text.includes(".warn-banner-warning")); +});