From 49613c0c3a3e956152a4099c093042c2b0a85745 Mon Sep 17 00:00:00 2001 From: Sebastian Gieseler Date: Fri, 6 Nov 2026 15:12:49 +0100 Subject: [PATCH] feat: the dashboard's mark says what needs attention, and flips to the nut (ADR-0097) The hub sends an `attention` event on its stream (the items of /hub/summary, each with a level: error or warn; failed lane starts are now among them). The dashboard puts a red or yellow dot on the mark in its top bar and on the favicon; the mark turns over to the nut of the nuts family on hover, and the favicon with it. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 9 ++ crates/devstack-hub/src/lib.rs | 18 ++++ crates/devstack-hub/src/notify/mod.rs | 4 +- crates/devstack-hub/src/notify/rules.rs | 86 +++++++++++++-- crates/devstack-hub/src/summary.rs | 100 +++++++++++++++++- ...shboards-mark-says-what-needs-attention.md | 79 ++++++++++++++ docs/adr/README.md | 1 + docs/dashboard-api.md | 4 +- ui/index.html | 2 +- ui/src/App.vue | 10 +- ui/src/api/mock/index.ts | 32 +++++- ui/src/api/types.ts | 18 ++++ ui/src/components/BrandMark.vue | 93 ++++++++++++++++ ui/src/components/Sidebar.vue | 6 +- ui/src/components/TopBar.vue | 11 +- ui/src/lib/brand.test.ts | 32 ++++++ ui/src/lib/brand.ts | 72 +++++++++++++ ui/src/stores/hub.ts | 14 ++- 18 files changed, 557 insertions(+), 34 deletions(-) create mode 100644 docs/adr/0097-the-dashboards-mark-says-what-needs-attention.md create mode 100644 ui/src/components/BrandMark.vue create mode 100644 ui/src/lib/brand.test.ts create mode 100644 ui/src/lib/brand.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index c47c58ff..d163dcff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,15 @@ and listed with their assets on the entry under the pool's with the command that removes it, `devstack doctor` warns, and a hook bound to the upstream applies for the agent that has it set up itself. +- **The dashboard's mark says when something needs attention.** A dot on + the mark in the top bar and on the browser tab's icon turns red when + something failed in any stack (a service, a build, a start, a lane's + start on a node) or the hub cannot be reached, and yellow when something + waits for you (a build held for promote, a pool request, a skill set to + answer). The hub sends it on its event stream as an `attention` event; + `/hub/summary` gives each item a `level` and now lists failed lane + starts too. On hover the mark turns over to the nut of the nuts family + ([ADR-0097](docs/adr/0097-the-dashboards-mark-says-what-needs-attention.md)). - **`devstack init` sets `PYTHONUTF8 = "1"` for Python apps.** On Windows a native Python process opens text files in the ANSI code page (cp1252) unless the code passes `encoding=`, while the same code in a container diff --git a/crates/devstack-hub/src/lib.rs b/crates/devstack-hub/src/lib.rs index 0b61bf96..962dad97 100644 --- a/crates/devstack-hub/src/lib.rs +++ b/crates/devstack-hub/src/lib.rs @@ -1576,6 +1576,23 @@ fn hub_events(s: &AppState) -> impl tokio_stream::Stream> = None; + tokio_stream::wrappers::WatchStream::new(s.board.subscribe()) + .map(|_| ()) + .merge(tokio_stream::wrappers::WatchStream::new(s.stacks.clone()).map(|_| ())) + .filter_map(move |()| { + let now = summary::attention(&s); + (last.as_ref() != Some(&now)).then(|| { + last = Some(now.clone()); + serde_json::json!({ "type": "attention", "items": now }) + }) + }) + }; // A dashboard that fell behind misses a toast, nothing it shows. let notices = tokio_stream::wrappers::BroadcastStream::new(notice::subscribe()).filter_map(|n| n.ok()); @@ -1587,6 +1604,7 @@ fn hub_events(s: &AppState) -> impl tokio_stream::Stream scope.apply(&ev), }; - s.board.set(&id, None, scope.glance()); + let mut glance = scope.glance(); + glance.attention.extend(lanes.attention()); + s.board.set(&id, None, glance); for n in notices { s.notify.deliver(&id, &name, None, n); } diff --git a/crates/devstack-hub/src/notify/rules.rs b/crates/devstack-hub/src/notify/rules.rs index 524ead81..2a2a9027 100644 --- a/crates/devstack-hub/src/notify/rules.rs +++ b/crates/devstack-hub/src/notify/rules.rs @@ -10,6 +10,8 @@ use serde_json::Value; use std::collections::HashMap; +use crate::summary::Level; + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum Kind { BuildFailed, @@ -179,7 +181,8 @@ impl Scope { if !svc.reason.starts_with(STOPPED_PREFIX) && !svc.reason.starts_with(CASCADE_PREFIX) => { - g.attention.push(attention(name, "failed", &svc.reason)); + g.attention + .push(attention(name, "failed", &svc.reason, Level::Error)); } _ => {} } @@ -188,11 +191,14 @@ impl Scope { name, "build held for promote", &svc.candidate_reason, + Level::Warn, + )), + Some("failed") => g.attention.push(attention( + name, + "build failed", + &svc.candidate_reason, + Level::Error, )), - Some("failed") => { - g.attention - .push(attention(name, "build failed", &svc.candidate_reason)); - } _ => {} } } @@ -201,12 +207,13 @@ impl Scope { } /// `: `, and the first line of why. -fn attention(service: &str, what: &str, reason: &str) -> crate::summary::Item { +fn attention(service: &str, what: &str, reason: &str, level: Level) -> crate::summary::Item { crate::summary::Item { lane: None, service: Some(service.to_string()), text: format!("{service}: {what}"), detail: first_lines(reason, 1), + level, } } @@ -325,6 +332,8 @@ pub struct Lanes { struct LaneSeen { owns_main: bool, failed_at: Option, + /// ` on failed`, and why, while it is so. + failure: Option<(String, String)>, } impl Lanes { @@ -350,13 +359,11 @@ impl Lanes { && was.failed_at != Some(at) { let m = &l["moving"]; - let what = if m["kind"] == "move" { "move" } else { "start" }; - let to = m["to"].as_str().unwrap_or("a node"); out.push(Notice { kind: Kind::LaneFailed, service: None, lane: Some(name.to_string()), - title: format!("Lane {name}: {what} on {to} failed"), + title: format!("Lane {name}: {}", failed_what(m)), body: first_lines(m["error"].as_str().unwrap_or(""), 3), }); } @@ -377,6 +384,28 @@ impl Lanes { out } + /// The lanes whose start or move on a node failed and that are still + /// so, for the hub's summary (ADR-0097). + pub fn attention(&self) -> Vec { + let mut out: Vec<_> = self + .known + .iter() + .flatten() + .filter_map(|(name, l)| { + let (what, why) = l.failure.clone()?; + Some(crate::summary::Item { + lane: Some(name.clone()), + service: None, + text: format!("lane {name}: {what}"), + detail: why, + level: Level::Error, + }) + }) + .collect(); + out.sort_by(|a, b| a.lane.cmp(&b.lane)); + out + } + /// The lanes that have an API of their own now: started, on this /// machine or on a node. pub fn started(lanes: &Value) -> Vec { @@ -401,12 +430,27 @@ fn seen(lanes: &Value) -> HashMap { LaneSeen { owns_main: l["owns_main"].as_bool().unwrap_or(false), failed_at: l["moving"]["failed_at"].as_u64(), + failure: failure(&l["moving"]), }, )) }) .collect() } +/// A lane's failed start or move: ` on failed`, and the +/// first line of why; `None` while it has not failed. +fn failure(m: &Value) -> Option<(String, String)> { + let error = m["error"].as_str()?; + Some((failed_what(m), first_lines(error, 1))) +} + +/// ` on failed`. +fn failed_what(m: &Value) -> String { + let what = if m["kind"] == "move" { "move" } else { "start" }; + let to = m["to"].as_str().unwrap_or("a node"); + format!("{what} on {to} failed") +} + /// At most `n` non-empty lines, each at most 200 characters. fn first_lines(text: &str, n: usize) -> String { text.lines() @@ -465,6 +509,7 @@ mod tests { assert_eq!(g.attention.len(), 1); assert_eq!(g.attention[0].text, "api: build held for promote"); assert_eq!(g.attention[0].detail, "schema"); + assert_eq!(g.attention[0].level, Level::Warn); s.apply(&service( "worker", json!({ "state": "failed", "reason": "port taken" }), @@ -473,6 +518,7 @@ mod tests { assert!(!g.starting); assert_eq!(g.attention[1].text, "worker: failed"); assert_eq!(g.attention[1].service.as_deref(), Some("worker")); + assert_eq!(g.attention[1].level, Level::Error); } #[test] @@ -634,6 +680,28 @@ mod tests { ); } + #[test] + fn a_failed_lane_needs_attention_while_it_is_so() { + let mut l = Lanes::default(); + let lane = |error: Option<&str>| { + json!([{ "name": "feat-x", "active": false, + "moving": error.map(|e| json!({ "kind": "move", "to": "big-box", "error": e, "failed_at": 1 })) }]) + }; + l.baseline(&lane(Some( + "no lease: node full +more", + ))); + // Unlike a notification, what had failed before counts: it still is. + let a = l.attention(); + assert_eq!(a.len(), 1); + assert_eq!(a[0].text, "lane feat-x: move on big-box failed"); + assert_eq!(a[0].detail, "no lease: node full"); + assert_eq!(a[0].lane.as_deref(), Some("feat-x")); + assert_eq!(a[0].level, Level::Error); + l.apply(&lane(None)); + assert!(l.attention().is_empty()); + } + #[test] fn lanes_failing_and_taking_the_main_ports() { let mut l = Lanes::default(); diff --git a/crates/devstack-hub/src/summary.rs b/crates/devstack-hub/src/summary.rs index 45856608..b00ff177 100644 --- a/crates/devstack-hub/src/summary.rs +++ b/crates/devstack-hub/src/summary.rs @@ -2,7 +2,9 @@ //! and one state over all of them, for the tray. What needs attention is //! what notifies (ADR-0045), read from the streams the hub follows for that //! (`notify`): each stream leaves its [`Glance`] on the [`Board`] after every -//! event, and takes it away when it ends. +//! event, and takes it away when it ends. The same items go to the +//! dashboard on `/hub/events` as an `attention` event, on every change +//! (ADR-0097). use axum::Json; use axum::extract::State; @@ -10,9 +12,20 @@ use axum::response::{IntoResponse, Response}; use serde::Serialize; use std::collections::{BTreeMap, HashMap}; use std::sync::{Arc, Mutex}; +use tokio::sync::watch; use crate::{AppState, Phase, StackEntry}; +/// How bad an [`Item`] is (ADR-0097): something failed, or something +/// waits for the user. +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize)] +#[serde(rename_all = "lowercase")] +pub(crate) enum Level { + #[default] + Error, + Warn, +} + /// Something that needs attention. #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize)] pub(crate) struct Item { @@ -24,6 +37,7 @@ pub(crate) struct Item { pub text: String, /// The first line of why, or empty. pub detail: String, + pub level: Level, } /// What one stream (a stack's main tree, or one of its lanes) shows now. @@ -38,19 +52,33 @@ pub(crate) struct Glance { } /// Each followed stream's last [`Glance`], by stack id and lane. -#[derive(Default)] pub(crate) struct Board { streams: Mutex, Glance>>>, + /// Moves when a glance changed: the dashboard's `attention` event. + changed: watch::Sender, +} + +impl Default for Board { + fn default() -> Self { + Self { + streams: Mutex::default(), + changed: watch::Sender::new(0), + } + } } impl Board { pub fn set(&self, stack: &str, lane: Option<&str>, g: Glance) { - self.streams + let before = self + .streams .lock() .unwrap() .entry(stack.to_string()) .or_default() - .insert(lane.map(str::to_string), g); + .insert(lane.map(str::to_string), g.clone()); + if before.as_ref() != Some(&g) { + self.changed.send_modify(|n| *n += 1); + } } fn remove(&self, stack: &str, lane: Option<&str>) { @@ -61,6 +89,13 @@ impl Board { streams.remove(stack); } } + drop(streams); + self.changed.send_modify(|n| *n += 1); + } + + /// Moves on every change of a glance. + pub fn subscribe(&self) -> watch::Receiver { + self.changed.subscribe() } /// Takes the stream's glance off the board when dropped: when its @@ -141,6 +176,7 @@ fn stack( .unwrap_or("") .trim() .to_string(), + level: Level::Error, }); } let mut starting = false; @@ -206,6 +242,28 @@ pub(crate) async fn get(State(s): State) -> Response { Json(summary(&s)).into_response() } +/// One item of the dashboard's `attention` event: an [`Item`] and its stack. +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] +pub(crate) struct Attention { + pub stack: String, + #[serde(flatten)] + pub item: Item, +} + +/// What needs attention in every stack, for `/hub/events` (ADR-0097). +pub(crate) fn attention(s: &AppState) -> Vec { + summary(s) + .stacks + .into_iter() + .flat_map(|st| { + st.attention.into_iter().map(move |item| Attention { + stack: st.id.clone(), + item, + }) + }) + .collect() +} + #[cfg(test)] mod tests { use super::*; @@ -231,6 +289,7 @@ mod tests { service: Some(service.into()), text: format!("{service}: build held for promote"), detail: String::new(), + level: Level::Warn, } } @@ -311,4 +370,37 @@ mod tests { } assert_eq!(board.of("ab12").len(), 1); } + + #[test] + fn the_board_says_when_a_glance_changed_and_only_then() { + let board = Board::default(); + let mut rx = board.subscribe(); + rx.mark_unchanged(); + board.set("ab12", None, Glance::default()); + assert!(rx.has_changed().unwrap()); + rx.mark_unchanged(); + board.set("ab12", None, Glance::default()); + assert!(!rx.has_changed().unwrap()); + board.set( + "ab12", + None, + Glance { + attention: vec![held("api")], + ..Default::default() + }, + ); + assert!(rx.has_changed().unwrap()); + } + + #[test] + fn an_item_says_its_level() { + let v = serde_json::to_value(Attention { + stack: "ab12".into(), + item: held("api"), + }) + .unwrap(); + assert_eq!(v["stack"], "ab12"); + assert_eq!(v["level"], "warn"); + assert_eq!(v["text"], "api: build held for promote"); + } } diff --git a/docs/adr/0097-the-dashboards-mark-says-what-needs-attention.md b/docs/adr/0097-the-dashboards-mark-says-what-needs-attention.md new file mode 100644 index 00000000..e2802321 --- /dev/null +++ b/docs/adr/0097-the-dashboards-mark-says-what-needs-attention.md @@ -0,0 +1,79 @@ +# ADR-0097: The dashboard's mark says what needs attention, in red or yellow + +- **Status:** Accepted (card in the pull request); built +- **Date:** 2026-11-06 +- **Deciders:** project owner +- **Related:** [ADR-0060](0060-the-tray-is-a-client-of-the-hub.md) (point 3: `/hub/summary`, what needs attention), [ADR-0045](0045-the-hub-notifies-the-desktop.md) (what notifies), [ADR-0021](0021-a-hub-serves-the-dashboard.md) and [ADR-0073](0073-a-pool-tells-its-members-what-changed-over-one-stream.md) (streams, no polling), [ADR-0032](0032-the-pool-is-administered-in-the-dashboard.md) (requests waiting for an admin), [ADR-0074](0074-a-pool-hands-out-skill-sets-the-hub-installs-them-for-the-agents.md) (skill sets waiting for an answer), [ADR-0070](0070-a-review-card-comes-before-the-code-an-adr-records-what-was-built.md) + +## Context + +The tray shows in its icon's colour whether something needs attention +(ADR-0060 point 4): the hub's summary, made from the streams it follows to +notify (ADR-0045). The dashboard had no such sign of its own. A failed +service or a candidate held for `promote` in another stack, or in a lane +not shown, was seen only on that stack's page, and a browser tab gave no +sign at all. The dashboard cannot work it out itself: it follows the +stream of the stack it shows, not every stack's, and polling +`/hub/summary` is what ADR-0021 and ADR-0073 rule out. + +The other apps of the nuts family turn their mark over to the family's nut +when the pointer is on it, and their favicon carries a red dot while +something runs, like an unread badge. + +## Decision + +The owner approved the points in the conversation on **2026-11-06**, all +four: + +| # | Category | Point | Beats | Reversing costs | +|---|---|---|---|---| +| 1 | contract | The hub's event stream sends an `attention` event when a dashboard connects and on every change: `{type, items: [{stack, lane, service, text, detail, level}]}`. These are the items `/hub/summary` lists, read from the same board. | Polling `/hub/summary`, or working it out in the browser, which sees only the stack on screen | Low: the event is only added; an older dashboard ignores it | +| 2 | contract | An attention item carries a `level`: `error` (a service, a build, a stack's start or a lane's start failed) or `warn` (a candidate held for `promote`). `/hub/summary` has it too; its `state` stays as it is. | A severity guessed from the text | Low: one more field | +| 3 | concept | The dashboard shows a dot on the favicon and on the mark in its top bar: red for an `error` item or a hub that cannot be reached, otherwise yellow for a `warn` item, a pool request waiting for an admin, or a skill set waiting for an answer. With nothing to show there is no dot. | A count in the tab title, or one colour as in the tray | Low: only how it looks | +| 4 | concept | The mark flips to the nut of the nuts family on hover, and the favicon flips with it, as in the family's other apps. There is no motion when the user asks for reduced motion. | No easter egg | None | + +Decided by the agent alone (not asked): + +- The nut is Lucide's `nut` (ISC), the same as in the family's other apps, + drawn in the mark's green on its dark tile. +- The favicon is made at run time as SVG text (a `data:` URL, which the + page's CSP allows for images): the front or the nut, with or without a + dot, not four files. +- A newer devstack is not a reason for the dot: the top bar's update button + says it already. +- A lane whose start or move on a node failed is in the summary while it + is so. It used to notify only (`lane_failed`, ADR-0045) and was missing + from `/hub/summary`; point 2 names it, so it is added there too. +- The dot's colours are the dark theme's `--danger` and `--warn` on the + favicon (its tile is dark in either theme), and the shown theme's in the + top bar. + +## Built + +- `crates/devstack-hub/src/summary.rs`: `Level`; `Item.level`; the board + says when a glance changed (`Board::subscribe`); `attention(&AppState)` + lists every stack's items with the stack's id. +- `crates/devstack-hub/src/notify/rules.rs`: the glance gives `held` the + level `warn`, failures `error`; `Lanes::attention` lists the lanes whose + start or move failed and still is so; `notify/mod.rs` puts them into the + main tree's glance. +- `crates/devstack-hub/src/lib.rs` (`hub_events`): the `attention` event, + made again when a glance or the stack list changed and sent only when the + items did. +- `ui/src/lib/brand.ts`: `attentionTone`, the favicon's SVG, the shared + `markFlipped`; `ui/src/components/BrandMark.vue`: the mark with its back + and the dot, in `TopBar.vue`; `ui/src/App.vue` keeps the favicon in step. + `hub.attention` and `hub.skillsWaiting` in `ui/src/stores/hub.ts` (the + sidebar's skill badge uses the latter now). The mock hub sends the event + as well. + +## Consequences + +- Every dashboard tab shows, in its favicon, whether something in any + stack failed or waits for the user, without the tray and without opening + that stack. +- A hub older than the dashboard sends no `attention` event: the dot then + shows only what the dashboard knows itself (the hub out of reach, pool + requests, skill sets). +- Containers are not in it, as they are not in the summary (ADR-0060 + point 3). diff --git a/docs/adr/README.md b/docs/adr/README.md index e51b6933..379e117a 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -179,3 +179,4 @@ stay. | [0094](0094-a-skill-carries-hooks-that-give-text-to-the-agents.md) | A skill carries hooks that give text to the agents; the hub writes one entry per agent and event, `devstack hook` picks the texts | Accepted (card in the pull request); built; addenda 2026-11-06 (end-of-session events `lane-stop`, `session-end`; an upstream the agent has set up itself counts) | | [0095](0095-the-daemon-ends-with-the-last-tree.md) | The daemon ends with the last tree; a stack has no start of its own, a stop always takes a tree's containers | Accepted (card in the pull request); built | | [0096](0096-a-port-held-now-refuses-the-start-one-up-of-a-tree-at-a-time.md) | A port held now refuses the start, whoever holds it (a stopped stack's containers too); one `up` of a tree at a time | Accepted (card in the pull request); built | +| [0097](0097-the-dashboards-mark-says-what-needs-attention.md) | The dashboard's mark and favicon carry a red or yellow dot for what needs attention, from an `attention` event of the hub; the mark flips to the nut | Accepted (card in the pull request); built | diff --git a/docs/dashboard-api.md b/docs/dashboard-api.md index 6dfc5413..5919921f 100644 --- a/docs/dashboard-api.md +++ b/docs/dashboard-api.md @@ -56,10 +56,10 @@ and `Referrer-Policy: no-referrer`. The dashboard has no inline script. | `POST /hub/notify/test` | cookie + Origin | one notification whatever the settings say: `204`, or `503` with why nothing shows. A click opens the dashboard | | `GET /hub/session` | cookie | `200 {"version": "", "link_unavailable": string\|null}`, or `401` (not paired: show "run `devstack ui`"). `link_unavailable` says why this platform has no `devstack://` link (macOS: "not on macOS yet", ADR-0054): the page keeps it and offers `devstack hub start` instead of its "Start hub" link while the hub is down. Older hubs leave it out | | `GET /hub/stacks` | cookie | `[StackEntry]` | -| `GET /hub/summary` | cookie or token | every registered stack at a glance, for the tray ([ADR-0060](adr/0060-the-tray-is-a-client-of-the-hub.md)): `{"state", "version", "stacks": [{id, name, repo, running, state, ready, total, lanes, attention: [{lane, service, text, detail}]}]}`. A stack's `state`: `stopped`, `starting`, `stopping` (a start or stop the hub runs), `ok` or `attention`; the whole `state` is the worst: `attention`, `starting`, `ok` (a stack runs) or `idle`. `ready` of `total`: the main tree's services running, healthy or done. `lanes`: started lanes. `attention`: what notifies (ADR-0045) and is still so, in the main tree and every started lane (`lane` names it): a failed service (not one the user stopped, not one held back by another's failure), a candidate `held` or whose build `failed`; and a failed start from the dashboard (`service` `null`). Containers are not in it. `version`: the hub's devstack | +| `GET /hub/summary` | cookie or token | every registered stack at a glance, for the tray ([ADR-0060](adr/0060-the-tray-is-a-client-of-the-hub.md)): `{"state", "version", "stacks": [{id, name, repo, running, state, ready, total, lanes, attention: [{lane, service, text, detail}]}]}`. A stack's `state`: `stopped`, `starting`, `stopping` (a start or stop the hub runs), `ok` or `attention`; the whole `state` is the worst: `attention`, `starting`, `ok` (a stack runs) or `idle`. `ready` of `total`: the main tree's services running, healthy or done. `lanes`: started lanes. `attention`: what notifies (ADR-0045) and is still so, in the main tree and every started lane (`lane` names it): a failed service (not one the user stopped, not one held back by another's failure), a candidate `held` or whose build `failed`, a lane whose start or move on a node failed (`service` `null`); and a failed start from the dashboard (`service` `null`). Each item's `level` ([ADR-0097](adr/0097-the-dashboards-mark-says-what-needs-attention.md)): `warn` for a candidate held, `error` for the rest; older hubs leave it out. Containers are not in it. `version`: the hub's devstack | | `GET /hub/ports` | cookie or token | the ports of every registered stack on this machine and where two stacks meet ([ADR-0082](adr/0082-the-ports-of-a-machine.md)): `{"stacks": [{id, name, running, containers?, ports: [PortEntry]}], "overlaps": [{port, proto, stacks: [{id, name, lane, holder?, kind}]}]}`. A running stack's `ports` are its daemon's `GET /v1/ports` (see [Ports](#ports)); a stack whose daemon does not run, or does not answer it (an older devstack), has what its stack file declares for the main working tree, each `kind: "declared"`, `lane: "main"`, moved by its shift on this machine: its services' `port`, its Compose groups' `announced_ports` and the ports on this machine their `urls` name (other published ports of the Compose files are not read). What a stopped stack's containers publish that run all the same (Docker started them again by their restart policy, or a stop kept them) is asked of Docker: those ports are `kind: "published"`, `listening: true`, in place of a declared entry of the same port, and the stack has `containers: true` ([ADR-0096](adr/0096-a-port-held-now-refuses-the-start-one-up-of-a-tree-at-a-time.md)). A stopped stack whose stack file is gone is left out; one whose file does not load has no ports. An overlap is one `port` and `proto` in more than one stack, each use listed once; an `instance` port does not count (the OS hands it out). Computed on request, nothing is polled | | `GET /hub/ws?path=` | cookie + Origin | WebSocket that carries the server-sent event stream at `` (`/hub/events`, `/hub/stacks/{id}/api/v1/...`, or `/hub/pool/shared/{lease}/api/v1/...[?pool=]` for a lane shared with this machine), one text message per event's `data`; how the dashboard reads every stream (a browser allows six HTTP/1.1 connections per host across all its tabs, WebSockets do not count; ADR-0021). The upstream is opened before the upgrade: `503` for a stack not running, `400` for another path. When the stream ends the socket closes | -| `GET /hub/events` | cookie | SSE: `{"type":"stacks","stacks":[StackEntry]}` and `{"type":"docker","docker":DockerEngine}` and `{"type":"release","current","newer":string|null,"error":string|null}` (a newer devstack; checked at start, every 12 h by the clock and when a dashboard connects and the last answer is over an hour old, unless `DEVSTACK_NO_UPDATE_CHECK`; `error` why the last check failed, no network or GitHub's rate limit, tried again after an hour and `null` once one succeeds, while a `newer` found before stays; older hubs leave it out) and `{"type":"update","update":{"running":bool,"error":string|null,"installed":string|null,"finished":ms|null}}` (the dashboard's update; `finished` is when the last one ended, `installed` the version it installed, told by the hub it started) and `{"type":"guests","guests":[Guest]}` (lanes of other members on this machine, every pool: `{pool, lease, member, owner, repo, lane, state: "offered"\|"running", since: unix s, cpus, memory}`, the leases whose node is this machine; read when the pool's stream says its leases or nodes changed) and `{"type":"worktrees","worktrees":{"":""}}` (a version of each registered stack's worktrees, running or not, ADR-0078: the hub looks at their folder once a second; a stack's lanes are read again when its version changes; older hubs never send it. Since ADR-0088 the version also moves when a checked-out branch or its upstream moves: their loose ref files, `packed-refs` and `FETCH_HEAD`, looked at without running git; the dashboard reads `branches` again then) and `{"type":"pools","pools":{"":{"live":"connecting"\|"live"\|"lost"\|"old","error"?,"versions":{"members","nodes","leases","upstreams","telemetry"}}}}` (the pools this machine follows over their coordinators' streams, ADR-0073: `old` for a coordinator without one, whose parts are read when the pool area opens; `versions` of each part, read again when one is not the one read last; older hubs never send it), each first and on every change | +| `GET /hub/events` | cookie | SSE: `{"type":"stacks","stacks":[StackEntry]}` and `{"type":"docker","docker":DockerEngine}` and `{"type":"release","current","newer":string|null,"error":string|null}` (a newer devstack; checked at start, every 12 h by the clock and when a dashboard connects and the last answer is over an hour old, unless `DEVSTACK_NO_UPDATE_CHECK`; `error` why the last check failed, no network or GitHub's rate limit, tried again after an hour and `null` once one succeeds, while a `newer` found before stays; older hubs leave it out) and `{"type":"update","update":{"running":bool,"error":string|null,"installed":string|null,"finished":ms|null}}` (the dashboard's update; `finished` is when the last one ended, `installed` the version it installed, told by the hub it started) and `{"type":"guests","guests":[Guest]}` (lanes of other members on this machine, every pool: `{pool, lease, member, owner, repo, lane, state: "offered"\|"running", since: unix s, cpus, memory}`, the leases whose node is this machine; read when the pool's stream says its leases or nodes changed) and `{"type":"worktrees","worktrees":{"":""}}` (a version of each registered stack's worktrees, running or not, ADR-0078: the hub looks at their folder once a second; a stack's lanes are read again when its version changes; older hubs never send it. Since ADR-0088 the version also moves when a checked-out branch or its upstream moves: their loose ref files, `packed-refs` and `FETCH_HEAD`, looked at without running git; the dashboard reads `branches` again then) and `{"type":"attention","items":[{stack, lane, service, text, detail, level}]}` (what needs attention in every stack, the items of `/hub/summary` with their stack's id, [ADR-0097](adr/0097-the-dashboards-mark-says-what-needs-attention.md): sent again when one changed; the dashboard's dot on its mark and favicon; older hubs never send it) and `{"type":"pools","pools":{"":{"live":"connecting"\|"live"\|"lost"\|"old","error"?,"versions":{"members","nodes","leases","upstreams","telemetry"}}}}` (the pools this machine follows over their coordinators' streams, ADR-0073: `old` for a coordinator without one, whose parts are read when the pool area opens; `versions` of each part, read again when one is not the one read last; older hubs never send it), each first and on every change | | `POST /hub/update` | cookie + Origin | `202`: `devstack update` in the background (output in `hub/update.log`); on success it restarts the hub on the new version, so the dashboard reconnects to it, and the new hub's `update` event names the installed version (the old hub leaves `hub/update.json` for it; a hub that starts on the old version while the updater runs waits for it and reports a failure); on failure the `update` event carries the end of its output. `409` while one runs (checked and claimed in one step). Running stacks switch at their next restart | | `POST /hub/update/check` | cookie + Origin | look for a newer release now: `{"current", "newer": string\|null}`, the same as the next `release` event; asked again within 30 s, the last answer (GitHub allows 60 unauthenticated requests an hour). `409` with `DEVSTACK_NO_UPDATE_CHECK`, `502` when GitHub cannot be asked, `504` after 30 s | | `POST /hub/stacks/scan` | cookie + Origin | `{"path", "add"?, "depth"?, "git_only"?, "configured_only"?}`: the folders below a folder (default one level, `depth` is clamped to 1 to 6; a repository only at its root, linked worktrees skipped) that are git repositories (`git_only`, default `true`) and have a `devstack.toml` (`configured_only`, default `true`); both `false` is a 400 (ADR-0089). `[{repo, id, name, error, configured, registered, added}]`: `configured` false is a folder without a stack file, named after the folder; with `add` the valid new ones are registered | diff --git a/ui/index.html b/ui/index.html index 445118c7..84767130 100644 --- a/ui/index.html +++ b/ui/index.html @@ -7,7 +7,7 @@ - + devstack diff --git a/ui/src/App.vue b/ui/src/App.vue index e4f8cdc7..1a22522a 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -1,8 +1,9 @@ + + + + diff --git a/ui/src/components/Sidebar.vue b/ui/src/components/Sidebar.vue index c68606b0..92bbe325 100644 --- a/ui/src/components/Sidebar.vue +++ b/ui/src/components/Sidebar.vue @@ -52,10 +52,6 @@ const route = useRoute(); // admin as a badge. const pool = usePool(); onBeforeUnmount(pool.watch()); -/** Skill sets offered and not answered, and updates that wait for the user (ADR-0074). */ -const skillsWaiting = computed( - () => (hub.skills?.sets ?? []).filter((x) => x.state === 'offered' || x.state === 'changed' || x.skills.some((k) => k.pending)).length, -); const poolHint = computed(() => { const o = pool.overview; if (!o) return ''; @@ -643,7 +639,7 @@ function toggleFavourite(s: StackEntry) { > Skills - {{ skillsWaiting }} + {{ hub.skillsWaiting }} diff --git a/ui/src/components/TopBar.vue b/ui/src/components/TopBar.vue index 36b867df..76e9a918 100644 --- a/ui/src/components/TopBar.vue +++ b/ui/src/components/TopBar.vue @@ -10,6 +10,7 @@ import { useWhatsNew } from '@/stores/whatsNew'; import StackSwitcher from './StackSwitcher.vue'; import PendingIndicator from './PendingIndicator.vue'; import NotifyMenu from './NotifyMenu.vue'; +import BrandMark from './BrandMark.vue'; import Icon from './icons/Icon.vue'; const hub = useHub(); @@ -77,15 +78,7 @@ const mismatch = computed(() => { - + devstack diff --git a/ui/src/lib/brand.test.ts b/ui/src/lib/brand.test.ts new file mode 100644 index 00000000..e2960fbd --- /dev/null +++ b/ui/src/lib/brand.test.ts @@ -0,0 +1,32 @@ +import { describe, expect, it } from 'vitest'; +import { attentionTone, faviconHref, faviconSvg } from './brand'; + +const none = { unreachable: false, items: [], poolWaiting: 0, skillsWaiting: 0 }; + +describe('attentionTone', () => { + it('is none when nothing needs attention', () => { + expect(attentionTone(none)).toBeNull(); + }); + it('is yellow for what waits for the user', () => { + expect(attentionTone({ ...none, items: [{ level: 'warn' }] })).toBe('warn'); + expect(attentionTone({ ...none, poolWaiting: 2 })).toBe('warn'); + expect(attentionTone({ ...none, skillsWaiting: 1 })).toBe('warn'); + }); + it('is red for a failure or a hub out of reach, whatever else waits', () => { + expect(attentionTone({ ...none, items: [{ level: 'warn' }, { level: 'error' }], poolWaiting: 1 })).toBe('error'); + expect(attentionTone({ ...none, unreachable: true })).toBe('error'); + }); +}); + +describe('favicon', () => { + it('shows the mark or the nut, with the dot only when there is one', () => { + expect(faviconSvg('mark', null)).toContain('M136 176h240'); + expect(faviconSvg('mark', null)).not.toContain('cx="400"'); + expect(faviconSvg('nut', null)).toContain('M4.93 4.93'); + expect(faviconSvg('mark', 'error')).toContain('fill="#f2667a"'); + expect(faviconSvg('nut', 'warn')).toContain('fill="#f0b043"'); + }); + it('is a data URL', () => { + expect(faviconHref('mark', null).startsWith('data:image/svg+xml,%3Csvg')).toBe(true); + }); +}); diff --git a/ui/src/lib/brand.ts b/ui/src/lib/brand.ts new file mode 100644 index 00000000..3b1f5abb --- /dev/null +++ b/ui/src/lib/brand.ts @@ -0,0 +1,72 @@ +// The mark, its back (the nut of the nuts family, as in their other apps) +// and the dot that says something needs attention (ADR-0097): for the top +// bar and, as SVG text, for the favicon. +import { computed, ref } from 'vue'; +import type { AttentionItem } from '@/api/types'; +import { useHub } from '@/stores/hub'; +import { usePool } from '@/stores/pool'; + +/** Something failed (red), or something waits for the user (yellow). */ +export type AttentionTone = 'error' | 'warn'; + +/** Whether the mark shows its back now (the pointer is on it): the favicon turns with it. */ +export const markFlipped = ref(false); + +/** + * The dot's colour, from the worst there is: the hub out of reach or an + * `error` item is red; a `warn` item, a request waiting for a pool admin or + * a skill set waiting for an answer is yellow; else none. + */ +export function attentionTone(a: { + unreachable: boolean; + items: readonly Pick[]; + poolWaiting: number; + skillsWaiting: number; +}): AttentionTone | null { + if (a.unreachable || a.items.some((i) => i.level !== 'warn')) return 'error'; + if (a.items.length || a.poolWaiting || a.skillsWaiting) return 'warn'; + return null; +} + +/** The dot's colours: those of the dark theme, which the tile has. */ +export const DOT: Record = { error: '#f2667a', warn: '#f0b043' }; + +/** The front's three lines and the point, on a 512 tile (as `favicon.svg`). */ +const MARK_PATHS = + ''; + +/** The nut (Lucide's `nut`, ISC), on a 512 tile; `BrandMark` draws it too. */ +const NUT_PATHS = + ''; + +/** The favicon: the front or the nut, with the dot top right when there is one. */ +export function faviconSvg(face: 'mark' | 'nut', tone: AttentionTone | null): string { + const dot = tone ? `` : ''; + return `${face === 'nut' ? NUT_PATHS : MARK_PATHS}${dot}`; +} + +/** `faviconSvg` as a URL for `` (the page's CSP allows `data:` images). */ +export function faviconHref(face: 'mark' | 'nut', tone: AttentionTone | null): string { + return `data:image/svg+xml,${encodeURIComponent(faviconSvg(face, tone))}`; +} + +/** The dot's colour for this hub: `attentionTone` of what the stores know. */ +export function useAttentionTone() { + const hub = useHub(); + const pool = usePool(); + return computed(() => + attentionTone({ + unreachable: hub.status === 'unreachable' || (hub.status === 'ok' && hub.stream === 'error'), + items: hub.attention, + poolWaiting: pool.dueAll, + skillsWaiting: hub.skillsWaiting, + }), + ); +} + +/** What the dot says, in words: its tooltip and the screen reader's. */ +export function attentionLabel(tone: AttentionTone | null): string { + if (tone === 'error') return 'Something failed or the hub is not reachable'; + if (tone === 'warn') return 'Something waits for you'; + return ''; +} diff --git a/ui/src/stores/hub.ts b/ui/src/stores/hub.ts index de62c108..42184af3 100644 --- a/ui/src/stores/hub.ts +++ b/ui/src/stores/hub.ts @@ -1,7 +1,7 @@ import { defineStore } from 'pinia'; import { computed, ref } from 'vue'; import { api, paths, Unreachable, type StreamState, type Subscription } from '@/api'; -import type { DockerEngine, Guest, HubEvent, HubSession, Opener, PoolSkillsState, StackEntry, UpdateState } from '@/api/types'; +import type { AttentionItem, DockerEngine, Guest, HubEvent, HubSession, Opener, PoolSkillsState, StackEntry, UpdateState } from '@/api/types'; import { act } from '@/lib/actions'; import { checkForAppUpdate } from '@/lib/app-update'; import { persist } from '@/lib/persist'; @@ -51,6 +51,12 @@ export const useHub = defineStore('hub', () => { const guests = ref([]); /** The pools' skill sets on this machine (ADR-0074); `null` until the hub tells (older hubs never do). */ const skills = ref(null); + /** Skill sets offered and not answered, and updates that wait for the user (ADR-0074). */ + const skillsWaiting = computed( + () => (skills.value?.sets ?? []).filter((x) => x.state === 'offered' || x.state === 'changed' || x.skills.some((k) => k.pending)).length, + ); + /** What needs attention in every stack (ADR-0097); empty from an older hub. */ + const attention = ref([]); /** A version of each stack's worktrees (ADR-0078); empty from an older hub. */ const worktrees = ref>({}); /** What this machine opens a stack's folder with (ADR-0046); null until asked. */ @@ -141,6 +147,10 @@ export const useHub = defineStore('hub', () => { skills.value = ev.skills; return; } + if (ev.type === 'attention') { + attention.value = ev.items; + return; + } if (ev.type === 'pools') { usePool().onFeed(ev.pools); return; @@ -267,6 +277,8 @@ export const useHub = defineStore('hub', () => { releaseError, guests, skills, + skillsWaiting, + attention, worktrees, updating, lastCheck,