diff --git a/CHANGELOG.md b/CHANGELOG.md index 508ac3c7..178f17e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,17 @@ and listed with their assets on the runs once per machine, in the main working tree only. `lanes = false` still works and means the same; `devstack check` reports it as deprecated. +- **Every lane has the same view, `main` included** (ADR-0081): the main + working tree is the lane `main`, with the same header, actions and start + card as any lane; what has no meaning for it (Cold, Discard data, Remove + worktree, Move, Share, a start in the pool, another profile) is shown + disabled, with the reason. *Serve main ports* is the same button in + every lane that does not hold them. *Stop stack* now stops every lane and + the daemon; `main`'s own Stop stops the main working tree only. +- **The lane is in the URL**: `#/s//l//...` (`main` for the + main working tree), in the links of `devstack status`, `up`, `ui + --link`, notifications and the tray too. Links of the form + `#/s//services/api?lane=feat` still open that lane. ### Deprecated @@ -30,6 +41,15 @@ and listed with their assets on the - **`/v1/lanes/main/v1/...`** answers as the main working tree's `/v1/...` (ADR-0080), so a client addresses every tree as a lane. +- **A stack has a page of its own** (ADR-0081), above its lanes, at + `#/s/` (the sidebar's stack row): its daemon (pid, port, uptime) + and the restart banner, Start, Stop and Restart stack, who serves the + main ports and the control to give them to another lane or back to + main, its lanes with branch, place, state, port offset and what each + uses, and the services that run once per machine. A stopped stack's page + shows its start and its worktrees. +- **`ServiceView.singleton`** (ADR-0080, ADR-0081): whether a service runs + once per machine, in the main working tree only. ## [0.32.0] - 2026-10-30 diff --git a/crates/devstack-daemon/src/state.rs b/crates/devstack-daemon/src/state.rs index d1f166d1..b2267942 100644 --- a/crates/devstack-daemon/src/state.rs +++ b/crates/devstack-daemon/src/state.rs @@ -95,6 +95,10 @@ pub struct ServiceView { pub hot_reload: bool, /// The stack file gives it a hot-reload mode. pub hot_reload_available: bool, + /// It runs once per machine, in the main working tree only (`singleton + /// = true`, or the deprecated `lanes = false`, ADR-0080): the stack + /// page lists it as the stack's, not a lane's. Older daemons omit it. + pub singleton: bool, /// Where its last `prepare` outputs came from (ADR-0062): the store or /// a run. Since this daemon started; none before its first `prepare`. #[serde(skip_serializing_if = "Option::is_none")] diff --git a/crates/devstack-daemon/src/supervisor/mod.rs b/crates/devstack-daemon/src/supervisor/mod.rs index 294c6167..40c8660f 100644 --- a/crates/devstack-daemon/src/supervisor/mod.rs +++ b/crates/devstack-daemon/src/supervisor/mod.rs @@ -413,6 +413,7 @@ impl Supervisor { rebuild: None, hot_reload: false, hot_reload_available: svc.hot_reload.is_some(), + singleton: svc.singleton(), prepare: None, last_action: None, }, diff --git a/crates/devstack-desktop/src/notify.rs b/crates/devstack-desktop/src/notify.rs index 598c6b0a..47495048 100644 --- a/crates/devstack-desktop/src/notify.rs +++ b/crates/devstack-desktop/src/notify.rs @@ -12,7 +12,7 @@ pub struct Note { /// Whose: the stack, and the lane. pub context: String, pub body: String, - /// The dashboard's route a click shows (`/#/s/?lane=`). + /// The dashboard's route a click shows (`/#/s//l/`). pub route: String, /// The `devstack://open` link that shows it (`devstack open-url`). pub link: String, diff --git a/crates/devstack-hub/src/lib.rs b/crates/devstack-hub/src/lib.rs index 0d4570ef..6f860f16 100644 --- a/crates/devstack-hub/src/lib.rs +++ b/crates/devstack-hub/src/lib.rs @@ -817,7 +817,7 @@ fn from_own_page(h: &HeaderMap, method: &Method, path: &str, own: &[String]) -> #[derive(Deserialize)] struct CodeQuery { code: String, - /// Where to go once paired: a dashboard route (`/#/s/?lane=`), the + /// Where to go once paired: a dashboard route (`/#/s//l/`), the /// stack a notification is about (ADR-0045). Anything else goes home. next: Option, } diff --git a/crates/devstack-hub/src/notify/mod.rs b/crates/devstack-hub/src/notify/mod.rs index f1408911..87223b98 100644 --- a/crates/devstack-hub/src/notify/mod.rs +++ b/crates/devstack-hub/src/notify/mod.rs @@ -55,8 +55,8 @@ pub(crate) struct Target { } impl Target { - /// The dashboard's route for it (hash history). `lane=` (empty) shows - /// the main working tree, whichever lane was shown last. + /// The dashboard's route for it (hash history): the lane view + /// (ADR-0081), `main` for the main working tree. pub fn path(&self) -> String { if self.pool { return "/#/pool".into(); @@ -64,14 +64,11 @@ impl Target { let Some(stack) = &self.stack else { return "/#/".into(); }; - let mut p = format!("/#/s/{}", enc(stack)); + let lane = self.lane.as_deref().filter(|l| !l.is_empty()); + let mut p = format!("/#/s/{}/l/{}", enc(stack), enc(lane.unwrap_or("main"))); if let Some(s) = &self.service { p.push_str(&format!("/services/{}", enc(s))); } - p.push_str(&format!( - "?lane={}", - enc(self.lane.as_deref().unwrap_or("")) - )); p } @@ -609,7 +606,7 @@ mod tests { let shown = shown.lock().unwrap(); assert_eq!(shown.len(), 4); assert_eq!(shown[3].context, "shop · lane feat-x"); - assert_eq!(shown[3].route, "/#/s/ab12/services/api?lane=feat-x"); + assert_eq!(shown[3].route, "/#/s/ab12/l/feat-x/services/api"); assert_eq!( shown[3].link, "devstack://open?stack=ab12&lane=feat-x&service=api" @@ -723,7 +720,7 @@ mod tests { service: Some("api".into()), pool: false, }; - assert_eq!(t.path(), "/#/s/ab12/services/api?lane=feat%20x"); + assert_eq!(t.path(), "/#/s/ab12/l/feat%20x/services/api"); assert_eq!( t.link(), "devstack://open?stack=ab12&lane=feat%20x&service=api" @@ -732,7 +729,7 @@ mod tests { stack: Some("ab12".into()), ..Target::default() }; - assert_eq!(main.path(), "/#/s/ab12?lane="); + assert_eq!(main.path(), "/#/s/ab12/l/main"); assert_eq!(main.link(), "devstack://open?stack=ab12"); assert_eq!(Target::default().path(), "/#/"); assert_eq!(Target::default().link(), "devstack://open"); diff --git a/crates/devstack/src/hubcmd.rs b/crates/devstack/src/hubcmd.rs index 4615fb2d..1575dffc 100644 --- a/crates/devstack/src/hubcmd.rs +++ b/crates/devstack/src/hubcmd.rs @@ -325,7 +325,8 @@ pub fn pairing_url() -> Result { /// Where the dashboard shows a stack, on a lane or its main working tree. pub struct DashboardLinks { - /// The hash route: `/#/s/?lane=`. + /// The hash route: `/#/s//l/`, `main` for the main working + /// tree (ADR-0081). pub route: String, /// The page, for a browser paired before. pub page: String, @@ -341,7 +342,10 @@ pub fn dashboard_links(main_file: &Path, lane: Option<&str>) -> DashboardLinks { let abs = std::path::absolute(main_file).unwrap_or_else(|_| main_file.to_path_buf()); let id = devstack_daemon::registry::id_for(&devstack_proc::long_path(&abs)); let lane = crate::client::enc(lane.unwrap_or("")); - let route = format!("/#/s/{id}?lane={lane}"); + let route = format!( + "/#/s/{id}/l/{}", + if lane.is_empty() { "main" } else { &lane } + ); DashboardLinks { page: format!("http://127.0.0.1:{}{route}", devstack_hub::port()), link: if lane.is_empty() { @@ -358,7 +362,7 @@ pub fn dashboard_line(main_file: &Path, lane: Option<&str>) -> String { format!("dashboard: {}", dashboard_links(main_file, lane).page) } -/// Open the dashboard at `route` (a hash route, `/#/s/?lane=`), paired +/// Open the dashboard at `route` (a hash route, `/#/s//l/`), paired /// like `devstack ui`: a click on a notification (`devstack://open`). pub fn open_dashboard(route: &str) -> Result<()> { let url = format!( @@ -557,13 +561,16 @@ mod tests { let id = devstack_daemon::registry::id_for(&devstack_proc::long_path(&file)); let port = devstack_hub::port(); let main = super::dashboard_links(&file, None); - assert_eq!(main.route, format!("/#/s/{id}?lane=")); - assert_eq!(main.page, format!("http://127.0.0.1:{port}/#/s/{id}?lane=")); + assert_eq!(main.route, format!("/#/s/{id}/l/main")); + assert_eq!( + main.page, + format!("http://127.0.0.1:{port}/#/s/{id}/l/main") + ); assert_eq!(main.link, format!("devstack://open?stack={id}")); let lane = super::dashboard_links(&file, Some("feat-x")); assert_eq!( lane.page, - format!("http://127.0.0.1:{port}/#/s/{id}?lane=feat-x") + format!("http://127.0.0.1:{port}/#/s/{id}/l/feat-x") ); assert_eq!(lane.link, format!("devstack://open?stack={id}&lane=feat-x")); } diff --git a/crates/devstack/src/integration.rs b/crates/devstack/src/integration.rs index be19a7ca..253ae107 100644 --- a/crates/devstack/src/integration.rs +++ b/crates/devstack/src/integration.rs @@ -168,11 +168,12 @@ fn dashboard_route(query: &str) -> Result { if !stack.chars().all(|c| c.is_ascii_hexdigit()) { return Err(anyhow!("`{stack}` is no stack id")); } - let mut route = format!("/#/s/{stack}"); + // The lane view (ADR-0081): no lane named is the main working tree, the + // lane `main`; no lane is ever named so (ADR-0080). + let mut route = format!("/#/s/{stack}/l/{}", lane.as_deref().unwrap_or("main")); if let Some(s) = service { route.push_str(&format!("/services/{s}")); } - route.push_str(&format!("?lane={}", lane.unwrap_or_default())); Ok(route) } @@ -222,9 +223,9 @@ mod tests { fn an_open_link_names_a_dashboard_route_and_nothing_else() { assert_eq!( dashboard_route("stack=ab12&lane=feat-x&service=api").unwrap(), - "/#/s/ab12/services/api?lane=feat-x" + "/#/s/ab12/l/feat-x/services/api" ); - assert_eq!(dashboard_route("stack=ab12").unwrap(), "/#/s/ab12?lane="); + assert_eq!(dashboard_route("stack=ab12").unwrap(), "/#/s/ab12/l/main"); assert_eq!(dashboard_route("").unwrap(), "/#/"); assert_eq!(dashboard_route("page=pool").unwrap(), "/#/pool"); assert!(dashboard_route("page=settings").is_err()); diff --git a/crates/devstack/src/tray.rs b/crates/devstack/src/tray.rs index a16f3103..89e64ea8 100644 --- a/crates/devstack/src/tray.rs +++ b/crates/devstack/src/tray.rs @@ -115,14 +115,15 @@ fn plural(n: u64, one: &str) -> String { } } -/// `/#/s/?lane=`, and with a service its page. +/// `/#/s//l/` (`main`: the main working tree, ADR-0081), and +/// with a service its page. fn route(stack: &str, lane: Option<&str>, service: Option<&str>) -> String { let enc = crate::client::enc; - let mut r = format!("/#/s/{}", enc(stack)); + let lane = lane.filter(|l| !l.is_empty()).unwrap_or("main"); + let mut r = format!("/#/s/{}/l/{}", enc(stack), enc(lane)); if let Some(s) = service { r.push_str(&format!("/services/{}", enc(s))); } - r.push_str(&format!("?lane={}", enc(lane.unwrap_or("")))); r } @@ -463,7 +464,7 @@ mod tests { assert!(find(&m.entries, "stop:ab12").is_some()); assert!(find(&m.entries, "start:ab12").is_none()); assert!(find(&m.entries, "start:cd34").is_some()); - assert!(find(&m.entries, "open:/#/s/ab12/services/api?lane=feat%20x").is_some()); + assert!(find(&m.entries, "open:/#/s/ab12/l/feat%20x/services/api").is_some()); assert!(find(&m.entries, "hub-start").is_none()); assert!(find(&m.entries, QUIT).is_some()); } diff --git a/docs/adr/0081-a-stack-has-a-page-every-lane-the-same-view.md b/docs/adr/0081-a-stack-has-a-page-every-lane-the-same-view.md new file mode 100644 index 00000000..9591b463 --- /dev/null +++ b/docs/adr/0081-a-stack-has-a-page-every-lane-the-same-view.md @@ -0,0 +1,105 @@ +# ADR-0081: A stack has a page of its own; every lane, `main` included, has the same view + +- **Status:** Accepted (card in the pull request) +- **Date:** 2026-10-30 +- **Deciders:** project owner +- **Related:** [ADR-0024](0024-a-lane-is-a-supervisor-in-the-main-trees-daemon.md) (a worktree is a lane), [ADR-0047](0047-the-dashboard-makes-a-lane-from-a-branch.md) (the branch picker), [ADR-0067](0067-a-change-at-runtime-says-who-made-it.md) (who serves the main ports, set how), [ADR-0070](0070-a-review-card-comes-before-the-code-an-adr-records-what-was-built.md), [ADR-0076](0076-a-pool-machine-has-one-page-the-pool-area-has-tabs.md) (the URL style of the pool area), [ADR-0078](0078-the-hub-follows-every-stacks-worktrees.md) (a stopped stack's worktrees), [ADR-0080](0080-the-main-tree-answers-as-a-lane-shared-is-deprecated.md) (the main tree answers as the lane `main`; `singleton`), [#387](https://github.com/nuetzliches/devstack/issues/387) (several stacks on one machine) + +## Context + +The dashboard showed a stack as its main working tree with its lanes +beside it. The main tree's view differed from a lane's in many places: its +header had Start and Stop stack and the daemon's pid, port and uptime, a +lane's had its own actions, Serve main ports, Move and Share; the start +card, the branch picker and the command palette each told the two apart. +What belongs to the stack (its daemon, the main ports, the services that +run once per machine) had no place of its own and sat in the main tree's +view. The lane shown was store state, not in the URL (`?lane=` was read +once and dropped). + +ADR-0080 made the main tree answer as the lane `main`, so a client can +address every tree the same way. The daemon is unchanged: the main tree is +still its own tree. + +## Decision + +The owner approved the points in the conversation on **2026-10-30**: + +| Category | Point | Beats | Reversing costs | +|---|---|---|---| +| concept | Every lane, `main` (the main working tree) included, has the same view and the same switches. The UI distinguishes only whether a lane holds the main slot (the fixed ports), not where it comes from. | A main tree's view of its own, and texts that address the main tree and a lane separately. | UI only. | +| concept | A stack has a page of its own above its lanes: its lanes, the main slot, its singleton services, need and usage (later: a port graph and a port shift, #387). | The stack's things in the main tree's view, and no place for what spans its lanes. | UI only; a route less. | +| contract | Stack-level actions (start, stop and restart the stack, give the main slot to lane X) live on that page; a lane's actions live in the lane view only. | Stack and lane actions mixed in one header. | UI only. | + +What was built: + +1. **Routes.** `#/s/` is the stack's page; `#/s//l//...` + a lane's views, with the tabs as before (overview, a service, a + container, infrastructure, commands, usage, activity), `main` for the + main working tree. The store's lane follows the route, and the route the + store when it shows another lane by itself (a lane made from a branch, + `main` after a lane's worktree went). Older links still work: + `#/s/?lane=x` and `#/s//services/...`, `/infra...`, + `/commands`, `/usage`, `/events` go to the same tab of the lane named, + else of the lane shown last, else of `main`. The CLI's links + (`devstack status`, `up`, `ui --link`), the notifications', the + `devstack://open` route and the tray's use the new form. +2. **One lane view.** The main tree is a lane entry in the dashboard: + name `main`, at the repository, its branch, offset 0, holding the main + ports unless a lane does, started unless nothing of it runs. The header, + the start card, the branch picker and the command palette treat it as + any lane. Its actions map to what its daemon offers: Start is its + `POST /v1/up`, Stop its `POST /v1/down?infra=true` (its services and + containers; the daemon and the other lanes keep running), Restart and + Rebuild restart (rebuild) each of its running services at the same time, + as a lane's warm restart does, since the daemon has no restart of the + whole main tree. Shown disabled, each with a one-line reason: Cold, + Discard data, Remove worktree, Move, Share, a start in the pool and a + profile other than the daemon's. *Serve main ports* is the same button + in every lane that does not hold them; in `main` it takes them back. A + `main` with nothing running shows the start card, as a lane not started + does. +3. **The stack's page.** Its name, repository, the daemon's state (pid, + port, uptime; idle; offline) and version, the restart banner (another + devstack installed, a changed stack file); Start stack, Stop stack + (every lane and the daemon, `POST /hub/stacks/{id}/down?all=true`, the + confirmation listing the lanes that stop) and Restart stack; who serves + the main ports, since when and set how, with a control to give them to + another started lane or back to `main`; the lanes (`main` first, then by + name: branch, here or the node, state, port offset, the main-ports mark, + CPU and memory from each lane's own `/v1/usage`, read every 10 seconds), + a row opening the lane's views; and the services that run once per + machine. A stopped stack's page shows Start stack and its worktrees as + the hub lists them. It follows the main tree's stream without making + `main` the lane an older link opens. +4. **`ServiceView.singleton`**: the daemon says whether a service runs + once per machine (`Service::singleton()`, `singleton = true` or the + deprecated `lanes = false`); an older daemon omits it, and the page says + it does not know. +5. **Sidebar, switcher, palette.** The sidebar's stack row opens the + stack's page; the trees under it, `main` first and always listed, open + their lane views on the tab shown last; the highlight follows the route. + The stack switcher opens a stack's page and a lane's view. The command + palette offers the stack's actions and its lanes on the stack's page, + the lane's actions, views, services and commands in a lane view. The + sidebar's per-stack menu keeps Start and Stop (every lane). + +Decided by the agent alone (not asked): main's Restart and Rebuild as +per-service restarts of what runs; the main tree's Stop without a +confirmation, as a lane's; the stack page's "need" left at usage (no API +gives a stack's need without a pool); the main tree shown with the start +card when nothing of it runs; Move and Share shown disabled for `main` only +where the pool offers nodes, as they are shown for a lane only then; the +sidebar listing `main` under every stack, also one without worktrees. + +## Consequences + +- One view to change for every lane; the main tree's exceptions are a + list of disabled items with their reasons, in one place + (`ui/src/lib/laneActions.ts`). +- A link names the lane it shows; a bookmark and a notification open the + same lane again, whichever was shown last. +- Stop stack means the whole stack now; stopping only the main tree is + `main`'s Stop. +- The stack's page is where a port graph and a port shift for several + stacks on one machine (#387) go. diff --git a/docs/adr/README.md b/docs/adr/README.md index bf8fc67e..0926810e 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -163,3 +163,4 @@ stay. | [0078](0078-the-hub-follows-every-stacks-worktrees.md) | The hub follows every stack's worktrees; a stopped stack's lane can be started from the dashboard | Accepted (card in the pull request) | | [0079](0079-skills-local-to-a-working-tree.md) | Skills local to a working tree: a pool's project skills bound to their repository, devstack's own untracked | Accepted (card in the pull request) | | [0080](0080-the-main-tree-answers-as-a-lane-shared-is-deprecated.md) | The main working tree answers as the lane `main`; `singleton` replaces `lanes = false`; `shared` is deprecated | Accepted (card in the pull request) | +| [0081](0081-a-stack-has-a-page-every-lane-the-same-view.md) | A stack has a page of its own; every lane, `main` included, has the same view | Accepted (card in the pull request) | diff --git a/docs/dashboard-api.md b/docs/dashboard-api.md index f7842e7b..21e7253f 100644 --- a/docs/dashboard-api.md +++ b/docs/dashboard-api.md @@ -44,7 +44,7 @@ and `Referrer-Policy: no-referrer`. The dashboard has no inline script. | Method and path | Auth | Answer | |---|---|---| | `GET /`, `/assets/*`, `/theme.js`, `/manifest.webmanifest`, `/sw.js`, the icons | none | the app shell (works offline once cached) | -| `GET /auth?code=[&next=]` | none | sets the session cookie (one year, survives a hub restart), redirects to `/`, or to `next` when it is a dashboard route (`/#/…`, characters of a path and query only; a notification's, [ADR-0045](adr/0045-the-hub-notifies-the-desktop.md)). A browser that sends a valid session already keeps it: no second cookie | +| `GET /auth?code=[&next=]` | none | sets the session cookie (one year, survives a hub restart), redirects to `/`, or to `next` when it is a dashboard route (`/#/…`, characters of a path and query only; a notification's, [ADR-0045](adr/0045-the-hub-notifies-the-desktop.md): a lane's views `/#/s//l/[/services/]`, `main` for the main working tree, or a stack's page `/#/s/`, [ADR-0081](adr/0081-a-stack-has-a-page-every-lane-the-same-view.md); the form before 0.33.0, `/#/s/[/services/]?lane=`, still lands on that lane). A browser that sends a valid session already keeps it: no second cookie | | `GET /hub/ping` | none | `{"devstack":true,"version":""}`; CORS for the landing page only (ADR-0021; `OPTIONS /hub/ping` answers its preflight). With `?nonce=<16 to 128 characters>` also `"proof"`: hex of blake3 `keyed_hash(derive_key("devstack hub ping proof v1", token), nonce)`. The CLI asks with a fresh nonce and sends the token only to a hub whose proof matches | | `GET /hub/notify` | cookie | desktop notifications ([ADR-0045](adr/0045-the-hub-notifies-the-desktop.md)): `{"available": bool, "unavailable": string\|null, "trouble": string\|null, "kinds": [{"kind", "label", "on", "default"}], "muted": [scope]}`; `unavailable` says why nothing shows (no desktop session, switched off in the system's settings, `DEVSTACK_NO_NOTIFY`, "not on macOS yet"); `trouble` what does not work as it should while notifications show: on Windows devstack's name not registered at hub start (they may show without it, or not at all), on Linux the last click that could not open the dashboard (`xdg-open` did not start; gone with a click that does). Older hubs leave `trouble` out. Kinds: `build_failed`, `held`, `service_failed`, `lane_failed` (on by default), `main_ports`, `live` (off). A scope is a stack id or `/` | | `PUT /hub/notify` | cookie + Origin | `{"kinds"?: {kind: bool}, "muted"?: [scope]}` (`muted` replaces the list): the new settings, as `GET`; `400` for an unknown kind or scope. Kept per machine in the hub's state (`notify.json`) | @@ -246,6 +246,7 @@ type ServiceView = { rebuild?: Rebuild; // a dev server's last rebuild, from its output (ADR-0042): {state: rebuilding|ok|failed, since, ms?, tool, errors?}; an ok one for a minute, a failed one until the next hot_reload: boolean; // the toolchain's watcher runs it now hot_reload_available: boolean; // the stack file has `hot_reload` for it + singleton?: boolean; // it runs once per machine, in the main working tree only (`singleton = true`, or the deprecated `lanes = false`, ADR-0080); the dashboard's stack page lists it (ADR-0081). Since 0.33.0; older daemons omit it prepare?: PrepareView; // where its last `prepare` outputs came from (ADR-0062), since the daemon started; absent before its first `prepare` (and from older daemons) last_action?: { via: Client; at: number; action: string }; // the last `/v1/services//` that succeeded, and its client (ADR-0067), from the journal }; diff --git a/skills/devstack/SKILL.md b/skills/devstack/SKILL.md index ac36deb6..b48bba6a 100644 --- a/skills/devstack/SKILL.md +++ b/skills/devstack/SKILL.md @@ -129,8 +129,9 @@ port tell within a second, and they are the evidence to quote. Whenever you started the stack or a lane, or created a worktree, give the user its dashboard page: one link to its services, logs, builds and events. `devstack status`, `devstack up` and `devstack lane start` end with it -(`dashboard: http://127.0.0.1:/#/s/?lane=`, an empty -`lane=` is the main working tree); for a worktree not started yet, +(`dashboard: http://127.0.0.1:/#/s//l/`, the lane +`main` is the main working tree; `/#/s/` alone is the stack's page, +its lanes and who serves the main ports); for a worktree not started yet, `devstack ui --link` in it (or `--lane ` from the main tree) prints it. Quote it as printed, never build it yourself. The page opens in a browser that was paired before; `devstack ui --link` also prints a diff --git a/ui/src/api/mock/data.ts b/ui/src/api/mock/data.ts index 832b8bcb..77942701 100644 --- a/ui/src/api/mock/data.ts +++ b/ui/src/api/mock/data.ts @@ -24,6 +24,7 @@ function service(p: Partial & Pick, r candidate: null, port, url: port ? `${p.kind === 'devserver' ? 'https' : 'http'}://localhost:${port}` : null, + singleton: false, ...p, build_id: build, instance_port: proxied ? instance : null, @@ -80,6 +81,8 @@ export function shopSeed(now: number): MockStackSeed { kind: 'tool', groups: [], port: 8025, + // One mail catcher per machine, in the lane main (ADR-0080). + singleton: true, autostart: false, status: { state: 'stopped' }, pid: null, diff --git a/ui/src/api/mock/index.ts b/ui/src/api/mock/index.ts index 7191b3d6..45c17507 100644 --- a/ui/src/api/mock/index.ts +++ b/ui/src/api/mock/index.ts @@ -194,6 +194,7 @@ class MockHub { constructor() { const now = Date.now(); const shop = new MockStack(shopSeed(now)); + shop.serveMain('agent-login-fix', 'mcp', now - 12 * 60_000); const crm = new MockStack(crmSeed(now)); const docs = new MockStack(docsSeed(now)); this.stacks = [shop, crm, docs]; @@ -929,7 +930,7 @@ export class MockTransport implements Transport { return Date.now() - laneRemoval.at < 8000 ? { ...l, active: false, owns_main: false, running: 0, services: 5, removing: true } : null; } const active = l.name === 'agent-login-fix' || s.startedLanes.has(l.name); - const owns = l.name === 'agent-login-fix' && s.laneOwnsMain; + const owns = s.laneOwnsMain && s.view.main_served?.lane === l.name; // review-cart runs on a node of the pool once started (ADR-0025); // a lane moved goes where it was moved. const placed = laneNodes.get(l.name) ?? (l.name === 'review-cart' ? 'build-server' : 'local'); @@ -970,7 +971,8 @@ export class MockTransport implements Transport { const lm = /^\/v1\/lanes\/([^/]+)\/main$/.exec(p); if (lm && method === 'POST') { await sleep(1200); - s.laneOwnsMain = lm[1] !== 'main'; + s.serveMain(decodeURIComponent(lm[1])); + s.emit({ type: 'snapshot', stack: s.view }); return json(200, []); } const mv = /^\/v1\/lanes\/([^/]+)\/move$/.exec(p); @@ -994,11 +996,19 @@ export class MockTransport implements Transport { await sleep(body?.mode === 'cold' ? 2500 : 1500); return json(200, lanes()); } - const fw = /^\/v1\/lanes\/[^/]+(\/v1\/.*)$/.exec(p); - if (fw) p = fw[1]; + const fw = /^\/v1\/lanes\/([^/]+)(\/v1\/.*)$/.exec(p); + const inLaneName = fw && fw[1] !== 'main' ? decodeURIComponent(fw[1]) : null; + if (fw) p = fw[2]; const view = () => json(200, s.view); if (p === '/v1/stack' && method === 'GET') return view(); - if (p === '/v1/usage' && method === 'GET') return json(200, s.usageWithHistory()); + if (p === '/v1/usage' && method === 'GET') { + const r = s.usageWithHistory(); + if (inLaneName) { + const f = inLaneName === 'agent-login-fix' ? 0.7 : 1.3; + r.lanes = r.lanes.map((l) => ({ ...l, name: inLaneName, cpu: l.cpu * f, memory: Math.round(l.memory * f) })); + } + return json(200, r); + } // The store of what `prepare` makes (ADR-0062). if (p === '/v1/store' && method === 'GET') { const entries = s.storeEntries(); @@ -1006,8 +1016,16 @@ export class MockTransport implements Transport { } const se = /^\/v1\/store\/([^/]+)\/([^/]+)$/.exec(p); if (se && method === 'DELETE') return s.removeStoreEntry(decodeURIComponent(se[1]), decodeURIComponent(se[2])) ? empty(204) : json(404, { error: 'no such entry in the store' }); - if (p === '/v1/up' && method === 'POST') return empty(202); - if (p === '/v1/down' && method === 'POST') return empty(204); + if (p === '/v1/up' && method === 'POST') { + if (!fw) + for (const svc of s.view.services) + if (svc.autostart && ['stopped', 'exited', 'failed'].includes(svc.status.state)) s.startInstance(svc, svc.build_id ?? '0000000000000000'); + return empty(202); + } + if (p === '/v1/down' && method === 'POST') { + if (!fw) for (const svc of s.view.services) if (!['stopped', 'completed'].includes(svc.status.state)) s.setStatus(svc.name, { state: 'stopped' }); + return empty(204); + } if (/^\/v1\/infra\/[^/]+\/[^/]+\/logs$/.test(p)) { const t = new Date().toISOString(); diff --git a/ui/src/api/mock/stack.ts b/ui/src/api/mock/stack.ts index b188cc21..bfb7f39c 100644 --- a/ui/src/api/mock/stack.ts +++ b/ui/src/api/mock/stack.ts @@ -33,8 +33,13 @@ export class MockStack { entry: StackEntry; view: StackView; previous: Record; - /** Mock lane `agent-login-fix` serves the main ports. */ + /** Mock lane `agent-login-fix` serves the main ports (the shop's from the start, set by an agent). */ laneOwnsMain = false; + /** Serve the main ports by lane `name`, or give them back (`main`): the view says who and how (ADR-0067). */ + serveMain(name: string, via: 'dashboard' | 'mcp' = 'dashboard', at = Date.now()): void { + this.laneOwnsMain = name !== 'main'; + this.view.main_served = this.laneOwnsMain ? { lane: name, via, at } : undefined; + } /** Mock lane `review-cart` was started from the dashboard. */ /** Mock lanes started from the dashboard (`agent-login-fix` runs from the start). */ startedLanes = new Set(); diff --git a/ui/src/api/transport.ts b/ui/src/api/transport.ts index 1b7848f7..8977fad1 100644 --- a/ui/src/api/transport.ts +++ b/ui/src/api/transport.ts @@ -63,8 +63,9 @@ export const paths = { agent: '/hub/agent', scanStacks: '/hub/stacks/scan', up: (stack: string) => `/hub/stacks/${enc(stack)}/up`, - /** `restart`: the daemon leaves its lanes to the next one (ADR-0052). */ - down: (stack: string, infra = true, restart = false) => `/hub/stacks/${enc(stack)}/down?infra=${infra}${restart ? '&restart=true' : ''}`, + /** `restart`: the daemon leaves its lanes to the next one (ADR-0052); `all`: the lanes stop too, and the daemon exits. */ + down: (stack: string, infra = true, restart = false, all = false) => + `/hub/stacks/${enc(stack)}/down?infra=${infra}${restart ? '&restart=true' : ''}${all ? '&all=true' : ''}`, forget: (stack: string) => `/hub/stacks/${enc(stack)}`, branches: (stack: string) => `/hub/stacks/${enc(stack)}/branches`, worktrees: (stack: string) => `/hub/stacks/${enc(stack)}/worktrees`, @@ -163,6 +164,10 @@ export const v1 = { storeEntry: (service: string, key: string) => `/v1/store/${enc(service)}/${enc(key)}`, up: '/v1/up', down: '/v1/down', + /** The tree's own stop: its services and containers; the daemon and the other lanes stay. */ + downTree: '/v1/down?infra=true', + /** Without history: what a tree uses now. */ + usageNow: '/v1/usage', logStream: (service: string, tail = 500, build?: string) => `/v1/services/${enc(service)}/logs/stream?tail=${tail}${build ? `&build=${enc(build)}` : ''}`, buildLog: (service: string) => `/v1/services/${enc(service)}/build-log`, diff --git a/ui/src/api/types.ts b/ui/src/api/types.ts index 4dfb7e59..8b4a2478 100644 --- a/ui/src/api/types.ts +++ b/ui/src/api/types.ts @@ -322,6 +322,8 @@ export type ServiceView = { prepare?: PrepareView; /** The last action a client took on it, and which (ADR-0067). Older daemons omit it. */ last_action?: Change; + /** It runs once per machine, in the main working tree only (`singleton = true`, ADR-0080): the stack's, not a lane's. Older daemons omit it. */ + singleton?: boolean; }; /** Who changed something at runtime, and when (ADR-0067). */ diff --git a/ui/src/components/AddStackDialog.vue b/ui/src/components/AddStackDialog.vue index 18a3d169..10d21538 100644 --- a/ui/src/components/AddStackDialog.vue +++ b/ui/src/components/AddStackDialog.vue @@ -14,6 +14,7 @@ import AgentPrompt from './AgentPrompt.vue'; import Modal from './Modal.vue'; import Icon from './icons/Icon.vue'; import ScanStacks from './ScanStacks.vue'; +import { stackPage } from '@/lib/stackRoutes'; const props = defineProps<{ open: boolean }>(); const emit = defineEmits<{ close: [] }>(); @@ -97,7 +98,7 @@ const state = computed(() => { function openStack(id: string) { emit('close'); - void router.push({ name: 'overview', params: { stack: id } }); + void router.push(stackPage(id)); } async function add() { diff --git a/ui/src/components/BranchPicker.vue b/ui/src/components/BranchPicker.vue index 0c7b77c0..f435f28b 100644 --- a/ui/src/components/BranchPicker.vue +++ b/ui/src/components/BranchPicker.vue @@ -6,10 +6,12 @@ // working tree's checkout is never changed. Switching between lanes is the // sidebar's too. import { computed, nextTick, ref } from 'vue'; +import { useRoute, useRouter } from 'vue-router'; import type { BranchView, LaneView } from '@/api/types'; import { ago, useNow } from '@/lib/format'; import { laneActions, type LaneAction } from '@/lib/laneActions'; -import { laneLabel, samePath } from '@/lib/lanes'; +import { laneLabel, laneTab, MAIN, samePath } from '@/lib/lanes'; +import { laneView } from '@/lib/stackRoutes'; import { usePopover } from '@/lib/popover'; import { useHub } from '@/stores/hub'; import { useStack } from '@/stores/stack'; @@ -18,11 +20,13 @@ import Icon from './icons/Icon.vue'; const hub = useHub(); const stack = useStack(); const now = useNow(); +const route = useRoute(); +const router = useRouter(); const current = computed(() => stack.shownLane); -const branch = computed(() => (current.value ? current.value.branch : stack.view?.branch) ?? null); -/** A lane is named by its branch (shown already): only what kind of tree it is. */ -const tree = computed(() => (current.value ? 'lane' : 'main working tree')); +const branch = computed(() => current.value?.branch ?? stack.view?.branch ?? null); +/** A lane is named by its branch (shown already): only what kind of tree it is; `main` is the main working tree. */ +const tree = computed(() => (current.value?.name === MAIN ? 'main working tree' : 'lane')); /** Someone else's lane, or no hub: the branch is shown, nothing more. */ const canPick = computed(() => !stack.foreign && hub.reachable && !!stack.id); const busy = computed(() => stack.busy.branches); @@ -53,7 +57,7 @@ const rows = computed(() => { return (stack.branches?.branches ?? []) .filter((b) => !q || b.name.toLowerCase().includes(q)) // A stack that does not run has its worktrees from the hub (ADR-0078). - .map((b) => ({ b, lane: b.worktree && !b.main ? ([...stack.lanes, ...stack.offlineLanes].find((l) => samePath(l.path, b.worktree!)) ?? null) : null })) + .map((b) => ({ b, lane: b.main ? stack.mainLane : b.worktree ? ([...stack.lanes, ...stack.offlineLanes].find((l) => samePath(l.path, b.worktree!)) ?? null) : null })) .sort((x, y) => Number(y.b.main) - Number(x.b.main) || x.b.name.localeCompare(y.b.name)); }); /** The branches with a worktree (the main tree's first), then the other local ones, then the remote ones; each by name. */ @@ -74,7 +78,7 @@ function isShown(r: Row): boolean { /** What a click on the row does, said on it. */ function hint(r: Row): string { - if (r.b.main) return 'main tree'; + if (r.b.main) return 'lane main'; if (r.lane?.removing) return 'lane · removing'; if (r.lane) return r.lane.owns_main ? 'main ports' : r.lane.active === false ? 'lane · not started' : 'lane · running'; if (r.b.worktree) return 'worktree'; @@ -83,12 +87,9 @@ function hint(r: Row): string { function pick(r: Row) { if (busy.value) return; - if (r.b.main) { + if (r.b.main || r.lane) { close(); - stack.selectLane(null); - } else if (r.lane) { - close(); - stack.selectLane(r.lane.name); + if (stack.id) void router.push(laneView(stack.id, r.b.main ? null : r.lane!.name, laneTab(route.name))); } else if (!r.b.worktree) { close(); void stack.newLane(r.b.name); diff --git a/ui/src/components/CommandPalette.vue b/ui/src/components/CommandPalette.vue index 308c957a..20886116 100644 --- a/ui/src/components/CommandPalette.vue +++ b/ui/src/components/CommandPalette.vue @@ -2,14 +2,16 @@ // Ctrl+K / Cmd+K: go anywhere and run anything of the current stack by typing // (plan §6): views, stacks, services, groups, containers, the stack file's // commands. Actions that change something go through the same calls as the -// buttons, a command with a confirmation text still asks. +// buttons, a command with a confirmation text still asks. On a stack's page +// the stack's actions and its lanes; in a lane's views that lane's (ADR-0081). import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'; -import { useRouter } from 'vue-router'; +import { useRoute, useRouter } from 'vue-router'; import { useHub } from '@/stores/hub'; import { useStack } from '@/stores/stack'; import { useUi } from '@/stores/ui'; import { laneActions } from '@/lib/laneActions'; -import { laneLabel } from '@/lib/lanes'; +import { laneLabel, lastTab } from '@/lib/lanes'; +import { laneView, stackPage } from '@/lib/stackRoutes'; import Icon from './icons/Icon.vue'; import type { IconName } from './icons/icons'; @@ -17,6 +19,7 @@ const hub = useHub(); const stack = useStack(); const ui = useUi(); const router = useRouter(); +const route = useRoute(); const open = ref(false); const query = ref(''); @@ -28,14 +31,20 @@ type Item = { id: string; label: string; hint: string; icon: IconName; run: () = function go(name: string, params: Record = {}) { if (!stack.id) return; - void router.push({ name, params: { stack: stack.id, ...params } }); + void router.push(laneView(stack.id, stack.lane, name, params)); } const items = computed(() => { const out: Item[] = []; - const v = stack.view; const sid = stack.id; - if (sid) { + // The stack's page: its actions and its lanes, nothing of one lane. + const onPage = route.name === 'stack'; + const v = onPage ? null : stack.view; + if (sid && onPage) { + for (const l of [stack.mainLane, ...stack.lanes].filter((x) => !!x)) + out.push({ id: `lane-open:${l!.name}`, label: laneLabel(l!), hint: 'lane', icon: 'gitBranch', run: () => router.push(laneView(sid, l!.name, lastTab(route.name))) }); + } else if (sid && !stack.foreign) out.push({ id: 'view:stack', label: `Stack ${stack.entry?.name ?? ''}`.trim(), hint: 'stack page', icon: 'layers', run: () => router.push(stackPage(sid)) }); + if (sid && !onPage) { for (const [name, label, icon] of [ ['overview', 'Overview', 'grid'], ['infra', 'Infrastructure', 'box'], @@ -47,18 +56,18 @@ const items = computed(() => { } out.push({ id: 'ui:sidebar', label: `${ui.sidebarShown ? 'Hide' : 'Show'} sidebar`, hint: 'layout · Ctrl+B', icon: 'panelLeft', run: () => ui.toggleSidebar() }); for (const s of hub.stacks) - if (s.id !== sid) out.push({ id: `stack:${s.id}`, label: s.name, hint: `stack${s.running ? '' : ', stopped'}`, icon: 'layers', run: () => router.push({ name: 'overview', params: { stack: s.id } }) }); + if (s.id !== sid) out.push({ id: `stack:${s.id}`, label: s.name, hint: `stack${s.running ? '' : ', stopped'}`, icon: 'layers', run: () => router.push(stackPage(s.id)) }); // Someone else's lane (ADR-0040) is viewed: nothing that would change it is offered. const changes = !stack.readOnly; - if (sid && stack.entry && changes) { + if (sid && stack.entry && changes && onPage) { if (stack.running) { out.push({ id: 'stack:restart', label: `Restart stack ${stack.entry.name}`, hint: 'stack', icon: 'restart', run: () => stack.restartStack() }); out.push({ id: 'stack:stop', label: `Stop stack ${stack.entry.name}`, hint: 'stack', icon: 'stop', run: () => stack.stopStack() }); } else out.push({ id: 'stack:start', label: `Start stack ${stack.entry.name}`, hint: 'stack', icon: 'play', run: () => stack.startStack() }); } // The shown lane's actions, as its menu in the header has them. - const lane = stack.shownLane; - if (lane && changes) { + const lane = onPage ? null : stack.shownLane; + if (lane && changes && stack.running) { const { main, items: more } = laneActions(lane); for (const a of [main, ...more].filter((a) => !a.disabled)) out.push({ id: `lane:${a.key}`, label: `${a.label.replace(/…$/, '')} lane ${laneLabel(lane)}`, hint: a.hint ? `lane, ${a.hint}` : 'lane', icon: a.icon ?? 'gitBranch', run: () => stack.laneAction(lane, a.key) }); diff --git a/ui/src/components/LaneStart.vue b/ui/src/components/LaneStart.vue index 0aad2a21..b73235f2 100644 --- a/ui/src/components/LaneStart.vue +++ b/ui/src/components/LaneStart.vue @@ -3,16 +3,18 @@ // machine, on a node of the pool the developer picks, or in the pool with // the coordinator choosing (ADR-0031 point 4). A start on a node shows its // steps as the daemon reports them, so it survives navigating away and back. -// The same page for every tree (ADR-0078): a lane of a running stack (its -// daemon starts it), a lane of a stack that does not run (the hub starts it, -// the daemon comes up), and the main working tree of a stack that does not -// run (`lane` null: it runs on this machine only, on the main ports). +// The same page for every lane (ADR-0078, ADR-0081): a lane of a running +// stack (its daemon starts it), a lane of a stack that does not run (the hub +// starts it, the daemon comes up), and the lane `main`, the main working +// tree: it runs on this machine only, on its own ports, with the daemon's +// profile; what does not apply to it is shown disabled, with the reason. import { computed, onBeforeUnmount, ref, watch } from 'vue'; import { api, paths } from '@/api'; import type { LaneView, Placement } from '@/api/types'; import type { LaneTarget } from '@/stores/pool'; import { bytes, duration, useNow } from '@/lib/format'; -import { laneLabel } from '@/lib/lanes'; +import { NOT_FOR_MAIN } from '@/lib/laneActions'; +import { laneLabel, MAIN } from '@/lib/lanes'; import { throttle } from '@/lib/throttle'; import { usePool } from '@/stores/pool'; import { useHub } from '@/stores/hub'; @@ -30,21 +32,20 @@ onBeforeUnmount(pool.watch()); /** The nodes that can take a lane now, of every pool (ADR-0034). */ const nodes = computed(() => pool.targets); -/** The main working tree (of a stack that does not run), not a lane. */ -const isMain = computed(() => !props.lane); -const title = computed(() => (props.lane ? laneLabel(props.lane) : (stack.view?.branch ?? 'main'))); +/** The lane `main`: the main working tree (ADR-0080). */ +const isMain = computed(() => !props.lane || props.lane.name === MAIN); +const title = computed(() => (props.lane ? laneLabel(props.lane) : MAIN)); +const branch = computed(() => (isMain.value ? (props.lane?.branch ?? stack.view?.branch ?? null) : null)); const path = computed(() => props.lane?.path ?? stack.entry?.repo ?? ''); -const busy = computed(() => (props.lane ? stack.busy['lane-start'] === props.lane.name : !!(stack.id && hub.starting[stack.id]))); +const busy = computed(() => stack.busy['lane-start'] === (props.lane?.name ?? MAIN) || (!stack.running && !!(stack.id && hub.starting[stack.id]))); const m = computed(() => props.lane?.moving ?? null); const running = computed(() => !!m.value && !m.value.error && m.value.kind === 'start'); /** Why it does not start in the pool: it is the main working tree (ADR-0078 * point 4), or its stack file names no lane image (ADR-0028). Said before a * start, not after a lease and a sync. */ -const MAIN_HERE = "the main working tree runs on this machine, on the stack's main ports; a worktree's lane runs in the pool"; -const notInPool = computed(() => (isMain.value ? MAIN_HERE : (props.lane?.not_in_pool ?? null))); -/** A pool button's or a node's title when it cannot start there: short for - * the main working tree, whose why stands under the buttons. */ -const notInPoolTitle = computed(() => (isMain.value ? "Only a worktree's lane starts in the pool" : `No node can run it: ${notInPool.value}`)); +const notInPool = computed(() => (isMain.value ? NOT_FOR_MAIN.pool : (props.lane?.not_in_pool ?? null))); +/** A pool button's or a node's title when it cannot start there. */ +const notInPoolTitle = computed(() => (isMain.value ? NOT_FOR_MAIN.pool : `No node can run it: ${notInPool.value}`)); const failed = computed(() => (m.value?.error && m.value.kind === 'start' ? m.value : null)); const placeName = (to: string) => (to === 'pool' ? 'the pool' : pool.pools.some((p) => p.name === to) ? `the pool ${to}` : to); const now = useNow(); @@ -60,6 +61,14 @@ const lanesOn = (poolName: string, node: string) => (pool.overviews[poolName]?.l /** The stack file's profiles (ADR-0041): how the lane runs for a purpose. */ const profiles = computed(() => stack.view?.profiles ?? []); const profile = ref(''); +// The main working tree's is its daemon's: shown, not chosen. +watch( + () => (isMain.value ? (stack.mainView?.profile ?? '') : null), + (p) => { + if (p !== null) profile.value = p; + }, + { immediate: true }, +); const chosen = computed(() => profiles.value.find((p) => p.name === profile.value) ?? null); /** Where each pool's coordinator would start this lane, best first, with why * (ADR-0026 point 3): its own order, not one guessed here; by what the @@ -67,7 +76,7 @@ const chosen = computed(() => profiles.value.find((p) => p.name === profile.valu const placement = ref>({}); async function loadPlacement() { const repo = stack.view?.name; - if (!repo || !props.lane) return; + if (!repo || !props.lane || isMain.value) return; const out: Record = {}; for (const p of pool.placeable) { try { @@ -142,7 +151,7 @@ function lit(n: LaneTarget | null) { } function start(on?: string) { - if (!props.lane) void stack.startStack(); + if (!props.lane || isMain.value) void stack.startStack(); else if (!stack.running) void stack.startOfflineLane(props.lane, on ?? null, profile.value || undefined); else void stack.startLane(props.lane.name, on, profile.value || undefined); } @@ -153,10 +162,9 @@ function start(on?: string) {
- {{ isMain ? `${stack.entry?.name ?? 'The stack'} is not running` : `${title} is not running` }} - Nothing of it runs on this machine. Its main working tree starts here, on the stack's main ports. - {{ stack.entry?.name }} does not run either: its daemon comes up with this lane, its main working tree stays stopped. - {{ stack.entry?.name }} runs; this worktree's lane does not yet. Start it below, here or on a machine of the pool. + {{ title }} is not running + {{ stack.entry?.name }} does not run either: its daemon comes up with this lane. + {{ stack.entry?.name }} runs; this lane does not. Start it below.
not started
@@ -164,21 +172,13 @@ function start(on?: string) {

{{ title }}

- {{ isMain ? 'main working tree' : 'worktree' }} + {{ isMain ? `main working tree${branch ? ` · ${branch}` : ''}` : 'worktree' }} not started
-

- {{ stack.entry?.name }} does not run. Its main working tree runs on this machine, on the stack's main ports; on another machine of the pool, - a worktree's lane runs. -

-

- {{ stack.entry?.name }} does not run. Starting this lane brings the stack's daemon up, the main working tree's services stay stopped; it runs - here, or on another machine of the pool: everything of the lane runs there, its ports are forwarded here. -

-

- This worktree's lane runs nothing yet. Start it here, or on another machine of the pool: everything of the lane runs there (build, - services, its own infrastructure), its ports are forwarded here. +

+ This lane runs nothing now. Start it here.

{{ path }}

It has no stack file of its own: it runs with the main working tree's.

@@ -211,9 +211,9 @@ function start(on?: string) {

The lane's pages open once its daemon runs on the node; its containers and services show their own start there.

-

- It does not start in the pool: {{ MAIN_HERE }}. Pick or make one in the branch menu above, or in the sidebar. + {{ NOT_FOR_MAIN.pool }}. Pick or make one in the branch menu above, or in the sidebar.

@@ -299,7 +299,7 @@ function start(on?: string) { this machine - diff --git a/ui/src/components/Sidebar.test.ts b/ui/src/components/Sidebar.test.ts new file mode 100644 index 00000000..b51a22ca --- /dev/null +++ b/ui/src/components/Sidebar.test.ts @@ -0,0 +1,115 @@ +// The routes of a stack and its lanes (ADR-0081), and the sidebar on them: +// the stack's row opens its page, each tree its lane's views, the highlight +// follows the route; older links land on a lane's view. +import { beforeEach, describe, expect, it, vi } from 'vitest'; +import { createApp, nextTick } from 'vue'; +import { createPinia, setActivePinia } from 'pinia'; +import type { StackEntry } from '@/api/types'; +import { FakeTransport, ok } from '@/test/fake'; + +const t = vi.hoisted(() => ({ current: null as FakeTransport | null })); + +vi.mock('@/api', async (importOriginal) => { + const real = await importOriginal(); + return { + ...real, + api: () => { + if (!t.current) throw new Error('no fake transport'); + return t.current; + }, + }; +}); + +const { router } = await import('@/router'); +const { useHub } = await import('@/stores/hub'); +const { persist } = await import('@/lib/persist'); +const Sidebar = (await import('./Sidebar.vue')).default; + +const entry: StackEntry = { id: 'ab12', name: 'shop', file: '/src/shop/devstack.toml', repo: '/src/shop', running: true, daemon: { pid: 1, port: 7000, started: 0, version: '0.9.8' }, last_seen: null }; +const feat = { name: 'feat', path: '/src/feat', branch: 'feat', number: 1, active: true, port_offset: 100, owns_main: false, running: 1, services: 1 }; + +let fake: FakeTransport; + +beforeEach(() => { + localStorage.clear(); + setActivePinia(createPinia()); + fake = new FakeTransport(); + t.current = fake; + fake.on('/hub/session', ok({ version: '0.9.8' })); + fake.on('/hub/stacks/ab12/api/v1/lanes', ok([feat])); +}); + +async function settle() { + for (let i = 0; i < 5; i++) { + await new Promise((r) => setTimeout(r, 0)); + await nextTick(); + } +} + +describe('routes of a stack and its lanes', () => { + it('a stack is a page; a lane, main too, has the views', () => { + expect(router.resolve('/s/ab12').name).toBe('stack'); + expect(router.resolve('/s/ab12/l/main').name).toBe('overview'); + expect(router.resolve('/s/ab12/l/feat/services/api')).toMatchObject({ name: 'service', params: { stack: 'ab12', lane: 'feat', name: 'api' } }); + expect(router.resolve('/s/ab12/l/feat/usage').name).toBe('usage'); + }); + + it('an older link lands on the lane it named, or the one shown last', async () => { + await router.push('/s/ab12/services/api?lane=feat'); + expect(router.currentRoute.value.fullPath).toBe('/s/ab12/l/feat/services/api'); + await router.push('/s/ab12?lane='); + expect(router.currentRoute.value.fullPath).toBe('/s/ab12/l/main'); + persist.set('lane.ab12', 'feat'); + await router.push('/s/ab12/usage'); + expect(router.currentRoute.value.fullPath).toBe('/s/ab12/l/feat/usage'); + await router.push('/s/ab12'); + expect(router.currentRoute.value.name).toBe('stack'); + }); +}); + +describe('the sidebar', () => { + async function mounted() { + const hub = useHub(); + await hub.init(); + fake.stream('/hub/events').handlers.onMessage({ type: 'stacks', stacks: [entry] }); + const el = document.createElement('div'); + document.body.appendChild(el); + const app = createApp(Sidebar); + app.use(router); + app.mount(el); + await settle(); + return { el, unmount: () => app.unmount() }; + } + const q = (el: HTMLElement, sel: string) => el.querySelector(sel)!; + + it('lists main first, then the lanes, and highlights what the route shows', async () => { + await router.push('/s/ab12'); + const { el, unmount } = await mounted(); + const rows = [...el.querySelectorAll('[data-testid="sidebar-lane-main"], [data-testid="sidebar-lane"]')]; + expect(rows.map((r) => r.querySelector('.label')?.textContent?.trim())).toEqual(['main', 'feat']); + expect(q(el, '[data-testid="sidebar-stack"]').classList.contains('active')).toBe(true); + expect(rows.some((r) => r.classList.contains('active'))).toBe(false); + + await router.push('/s/ab12/l/feat/usage'); + await settle(); + expect(q(el, '[data-testid="sidebar-stack"]').classList.contains('active')).toBe(false); + expect(q(el, '[data-testid="sidebar-lane"][data-lane="feat"]').classList.contains('active')).toBe(true); + expect(q(el, '[data-testid="sidebar-lane-main"]').classList.contains('active')).toBe(false); + unmount(); + }); + + it('opens the stack page from the stack, a lane view from a tree, on the tab shown', async () => { + await router.push('/s/ab12/l/feat/events'); + const { el, unmount } = await mounted(); + q(el, '[data-testid="sidebar-lane-main"]').click(); + await settle(); + expect(router.currentRoute.value.fullPath).toBe('/s/ab12/l/main/events'); + q(el, '[data-testid="sidebar-stack"]').click(); + await settle(); + expect(router.currentRoute.value.fullPath).toBe('/s/ab12'); + q(el, '[data-testid="sidebar-lane"][data-lane="feat"]').click(); + await settle(); + expect(router.currentRoute.value.fullPath).toBe('/s/ab12/l/feat/events'); + unmount(); + }); +}); diff --git a/ui/src/components/Sidebar.vue b/ui/src/components/Sidebar.vue index 23a7fbed..5c4b93ca 100644 --- a/ui/src/components/Sidebar.vue +++ b/ui/src/components/Sidebar.vue @@ -1,9 +1,11 @@ diff --git a/ui/src/views/StackLayout.vue b/ui/src/views/StackLayout.vue index e67d68ab..0521648e 100644 --- a/ui/src/views/StackLayout.vue +++ b/ui/src/views/StackLayout.vue @@ -2,7 +2,8 @@ import { computed, watch } from 'vue'; import { useRoute, useRouter } from 'vue-router'; import { ago, useNow } from '@/lib/format'; -import { restartLanesText } from '@/lib/lanes'; +import { laneTab } from '@/lib/lanes'; +import { laneOfParam, laneParam, laneView, stackPage } from '@/lib/stackRoutes'; import { useHub } from '@/stores/hub'; import { useStack } from '@/stores/stack'; import Icon from '@/components/icons/Icon.vue'; @@ -22,32 +23,41 @@ const hub = useHub(); const stack = useStack(); const now = useNow(); +// The lane shown is the route's (ADR-0081): `#/s//l//...`, +// `main` for the main working tree; the store follows it. watch( - () => route.params.stack as string | undefined, - (id) => { - if (id) stack.select(id); + () => [route.params.stack, route.params.lane] as const, + ([id, lane]) => { + if (typeof id !== 'string' || !id) return; + stack.select(id, { lane: laneOfParam(lane) }); }, { immediate: true }, ); - -// A link names the lane to show (`?lane=`, empty: the main working tree), as -// a notification's does (ADR-0045); shown, the query goes again. +// And the route the store, when it shows another lane by itself (one made +// from a branch, the main tree after a lane's worktree went): that lane's +// list of the same tab, as a switch in the sidebar does. watch( - () => route.query.lane, + () => stack.lane, (lane) => { - if (typeof lane !== 'string' || !route.params.stack) return; - stack.selectLane(lane || null); - const { lane: _, ...rest } = route.query; - void router.replace({ query: rest }); + const id = route.params.stack; + if (typeof id !== 'string' || id !== stack.id || typeof route.params.lane !== 'string' || route.params.lane === laneParam(lane)) return; + void router.replace(laneView(id, lane, laneTab(route.name))); }, - { immediate: true }, ); -/** The shown lane, when it is not started: its start options instead of its views. */ +const hubDown = computed(() => hub.status === 'unreachable' || hub.stream === 'error'); +/** + * The shown lane, `main` too, when it is not started: its start options + * instead of its views and tabs, the same for every lane and whether the + * stack's daemon runs or not (ADR-0078, ADR-0081). + */ const idleLane = computed(() => { - const l = stack.lanes.find((x) => x.name === stack.lane); - return l && l.active === false && !l.removing ? l : null; + const l = stack.shownLane; + if (!l || l.active !== false || l.removing) return null; + if (!stack.running && (hubDown.value || stack.readOnly || !stack.entry)) return null; + return l; }); +const offlineStart = computed(() => !stack.running && !!idleLane.value); /** The shown lane's worktree is gone: made again on its branch, if the branch is still there. */ const restorable = computed(() => { const l = stack.ending; @@ -59,26 +69,7 @@ watch( if (gone) void stack.loadBranches(); }, ); -const hubDown = computed(() => hub.status === 'unreachable' || hub.stream === 'error'); -/** The main tree of a stack that does not run, shown: its start card, as a lane's (ADR-0078). */ -/** A tree of a stack that does not run, shown: its start card instead of its views and tabs, the same for the main tree and a lane (ADR-0078). */ -const showMainStart = computed(() => !hubDown.value && !!stack.entry && !stack.running && !stack.lane && !stack.readOnly); -const offlineStart = computed(() => showMainStart.value || !!stack.offlineLane); -const starting = computed(() => !!(stack.id && hub.starting[stack.id])); const unknown = computed(() => hub.fresh && !stack.entry && !stack.view); -/** The daemon runs another devstack than the hub: a restart of the stack - * starts it with the hub's (the installed) one. */ -const daemonOutdated = computed(() => { - const d = stack.entry?.daemon?.version; - const h = hub.version; - return d && h && d !== h ? { daemon: d, hub: h } : null; -}); -const restartReason = computed(() => { - if (!stack.running) return null; - if (daemonOutdated.value) return 'version'; - if (stack.view?.config_changed && !stack.ending) return 'config'; - return null; -}); /** What no request reports (ADR-0050): this tree's own, and what the main * tree knows of the lane shown (its worktree missing). */ const notices = computed(() => { @@ -125,12 +116,12 @@ function isActive(name: string) {
-