From 12a7e2289ad1452c74e07faa1a632d0f525033fc Mon Sep 17 00:00:00 2001 From: Sebastian Gieseler Date: Mon, 2 Nov 2026 15:58:04 +0100 Subject: [PATCH] feat(ui): the sidebar orders the stacks by name or by last opened (#377, ADR-0084) A menu beside the "Stacks" heading's + chooses the order: by name (the default) or last opened first. Last opened is a snapshot taken when the page loads or the choice is made, so opening a stack moves nothing while the page is open; a start or a stop never does. The choice and the times live in this browser, as the fold state does. Co-Authored-By: Claude Opus 5.5 --- ...ar-orders-stacks-by-name-or-last-opened.md | 50 ++++++++ docs/adr/README.md | 1 + ui/src/components/Sidebar.test.ts | 33 +++++ ui/src/components/Sidebar.vue | 116 +++++++++++++++++- ui/src/lib/stackOrder.test.ts | 28 +++++ ui/src/lib/stackOrder.ts | 47 +++++++ 6 files changed, 270 insertions(+), 5 deletions(-) create mode 100644 docs/adr/0084-the-sidebar-orders-stacks-by-name-or-last-opened.md create mode 100644 ui/src/lib/stackOrder.test.ts create mode 100644 ui/src/lib/stackOrder.ts diff --git a/docs/adr/0084-the-sidebar-orders-stacks-by-name-or-last-opened.md b/docs/adr/0084-the-sidebar-orders-stacks-by-name-or-last-opened.md new file mode 100644 index 00000000..bf9cf422 --- /dev/null +++ b/docs/adr/0084-the-sidebar-orders-stacks-by-name-or-last-opened.md @@ -0,0 +1,50 @@ +# ADR-0084: The sidebar orders the stacks by name or by last opened, a choice kept in the browser + +- **Status:** Accepted (card in the pull request); built +- **Date:** 2026-11-02 +- **Deciders:** project owner +- **Related:** [ADR-0081](0081-a-stack-has-a-page-every-lane-the-same-view.md) (the sidebar's stack rows), [ADR-0078](0078-the-hub-follows-every-stacks-worktrees.md) (every stack's trees listed), [ADR-0070](0070-a-review-card-comes-before-the-code-an-adr-records-what-was-built.md); issue #377 + +## Context + +The sidebar listed every stack by name, and nothing moved when something +started or stopped (#374). With more than a handful of stacks, a user wants +the ones they work on near the top. Issue #377 asked for favourites, an +order of one's own (dragging, by name, last used) and hiding. Dragging was +not wanted; sorting the trees within a stack waits until this proves too +little. + +## Decision + +The owner approved the points in the conversation on **2026-11-02**: + +| # | Category | Point | Beats | Reversing costs | +|---|---|---|---|---| +| 1 | concept | The user chooses the order of the stacks in a menu beside `+`: by name (the default) or last opened first. | Dragging, favourites, an order by state. | Low: the menu goes, a stored choice is ignored. | +| 2 | concept | The order does not change while the page is open: last opened is taken when the page loads or the choice is made. | Re-sorting on every click, a row moving under the pointer. | Low: UI code only. | +| 3 | concept | There is no order by state: a start or a stop moves nothing (as since #374); the dot tells the state. | Running first. | One more entry in the menu. | +| 4 | contract | The choice and when each stack was last opened live in the browser's `localStorage`, as the fold state does. | A setting in the hub, per machine. | Moving it to the hub later loses the values per browser. | +| 5 | concept | The trees within a stack and "Shared with you" stay ordered by name. | An order per section. | Adding a choice per section. | + +As built: + +1. **The menu.** A button (↕) beside `+` in the "Stacks" heading opens a + menu with "By name" and "Last opened first"; the current choice has a + check mark. Choosing takes a new snapshot of the times. +2. **Opened.** A stack counts as opened whenever it is shown (its page or + a lane's views), however it was reached: the sidebar, the switcher, the + palette, a link. The time is noted at once, and used from the next load. +3. **Never opened.** A stack never opened in this browser, or added while + the page is open, follows the opened ones, by name. +4. **Keys.** `devstack.sidebar.order` (`name` or `opened`) and + `devstack.sidebar.opened` (stack id to milliseconds). Removing a stack + from the dashboard drops its time. +5. **Code.** `ui/src/lib/stackOrder.ts`, `ui/src/components/Sidebar.vue`. + Tests: `stackOrder.test.ts`, `Sidebar.test.ts`. + +## Consequences + +- Each browser has its own order; two browsers on one machine can differ. +- Last opened says what this browser showed, not what an agent or the CLI + used: a stack an agent works on through MCP does not rise. +- Favourites and hiding (#377) stay open. diff --git a/docs/adr/README.md b/docs/adr/README.md index 352c6631..71c95bbe 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -166,3 +166,4 @@ stay. | [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) | | [0082](0082-the-ports-of-a-machine.md) | The ports of a machine: every stack says what it holds, a stack can run shifted | Accepted (card in the pull request); built: points 1 (`/v1/ports`, `/hub/ports`, `doctor`) and 2 (the graph) in 0.33.0, points 3 to 7 (the shift, the claims, `up --shift`) after it | | [0083](0083-the-hub-takes-out-what-an-agent-switched-off-leaves.md) | The hub takes out what an agent switched off leaves: devstack's generated skills, and the folders a removed skill empties | Accepted (card in the pull request); built | +| [0084](0084-the-sidebar-orders-stacks-by-name-or-last-opened.md) | The sidebar orders the stacks by name or by last opened, a choice kept in the browser | Accepted (card in the pull request); built | diff --git a/ui/src/components/Sidebar.test.ts b/ui/src/components/Sidebar.test.ts index b51a22ca..771774df 100644 --- a/ui/src/components/Sidebar.test.ts +++ b/ui/src/components/Sidebar.test.ts @@ -112,4 +112,37 @@ describe('the sidebar', () => { expect(router.currentRoute.value.fullPath).toBe('/s/ab12/l/feat/events'); unmount(); }); + + it('orders the stacks by name, or by last opened as a snapshot that opening does not move (#377)', async () => { + const zoo: StackEntry = { ...entry, id: 'cd34', name: 'zoo', repo: '/src/zoo', running: false, daemon: null }; + fake.on('/hub/stacks/cd34/worktrees', ok([])); + persist.set('sidebar.opened', { cd34: 10 }); + await router.push('/pool'); + const hub = useHub(); + await hub.init(); + fake.stream('/hub/events').handlers.onMessage({ type: 'stacks', stacks: [zoo, entry] }); + const el = document.createElement('div'); + document.body.appendChild(el); + const app = createApp(Sidebar); + app.use(router); + app.mount(el); + await settle(); + const names = () => [...el.querySelectorAll('[data-testid="sidebar-stack"] .label')].map((x) => x.textContent?.trim()); + expect(names()).toEqual(['shop', 'zoo']); + + q(el, '[data-testid="sidebar-order"]').click(); + await settle(); + document.querySelector('[data-testid="sidebar-order-menu"] [data-order="opened"]')!.click(); + await settle(); + // zoo was opened here, shop never. + expect(names()).toEqual(['zoo', 'shop']); + expect(persist.get('sidebar.order')).toBe('opened'); + + // Opening shop notes it, and moves nothing until the page loads again. + await router.push('/s/ab12'); + await settle(); + expect(names()).toEqual(['zoo', 'shop']); + expect((persist.get>('sidebar.opened') ?? {}).ab12).toBeGreaterThan(10); + app.unmount(); + }); }); diff --git a/ui/src/components/Sidebar.vue b/ui/src/components/Sidebar.vue index 5c4b93ca..1ccb9355 100644 --- a/ui/src/components/Sidebar.vue +++ b/ui/src/components/Sidebar.vue @@ -1,6 +1,7 @@