diff --git a/CHANGELOG.md b/CHANGELOG.md index 13d38e09..24aca2bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,14 @@ and listed with their assets on the ## [Unreleased] +### Added + +- **Favourite stacks** (#377, ADR-0086): a star in a stack's sidebar row, + or "Add to favourites" in its menu, marks it; favourites list first in + the sidebar and in the stack switcher, the others below, each part in + the chosen order. Marking moves the stack at once. Favourites live in + the browser's `localStorage`, as the order does. + ## [0.35.0] - 2026-11-03 A connection to a shared lane is to the lane, not to its lease: it diff --git a/docs/adr/0086-favourite-stacks-list-first.md b/docs/adr/0086-favourite-stacks-list-first.md new file mode 100644 index 00000000..b6c79814 --- /dev/null +++ b/docs/adr/0086-favourite-stacks-list-first.md @@ -0,0 +1,49 @@ +# ADR-0086: Favourite stacks list first, marked by a star kept in the browser + +- **Status:** Accepted (card in the pull request); built +- **Date:** 2026-11-03 +- **Deciders:** project owner +- **Related:** [ADR-0084](0084-the-sidebar-orders-stacks-by-name-or-last-opened.md) (the order; its point 1 beat favourites, amended here), [ADR-0081](0081-a-stack-has-a-page-every-lane-the-same-view.md) (the sidebar's stack rows), [ADR-0070](0070-a-review-card-comes-before-the-code-an-adr-records-what-was-built.md); issue #377 + +## Context + +ADR-0084 let the user order the stacks by name or by last opened and left +favourites and hiding (#377) open. With many stacks, the few a user works +on every day still move with the order: by name they sit wherever their +name puts them, by last opened they drop when another stack was looked at. +The owner asked for favourites that show first. + +## Decision + +The owner approved the points in the conversation on **2026-11-03**: + +| # | Category | Point | Beats | Reversing costs | +|---|---|---|---|---| +| 1 | term | A stack can be marked a favourite, by a star in its sidebar row or an entry in its menu; favourites list first, the others below, each part in the chosen order (name / last opened). | A third order "favourites first", a separate "Favourites" heading, dragging. | Low: the star and entry go, stored ids are ignored. | +| 2 | concept | Marking or unmarking moves the stack at once: it is the user's own act on that row; opening still moves nothing while the page is open (ADR-0084 point 2 stands). | Waiting for the next load. | Low: UI code only. | +| 3 | contract | Favourites live in the browser's `localStorage` (`devstack.sidebar.favourites`, a list of stack ids), as the order does; removing a stack from the dashboard drops it. | A setting in the hub, per machine. | Moving it to the hub later loses the per-browser values. | +| 4 | concept | The top-bar stack switcher also lists favourites first (then running, then by name, as before); the command palette stays as it is. | Sidebar only; the palette too. | Low. | +| 5 | concept | Hiding stacks (#377) stays open. | Building it now. | — | + +As built: + +1. **The star.** A star button sits in the stack's row before "…". Like + "…" it shows on hover and focus (always on a touch screen); on a + favourite it always shows, filled. The stack's menu has "Add to + favourites" / "Remove from favourites". +2. **The order.** `orderStacks` sorts the favourites before the others and + each part by the chosen order; a favourite never opened here follows + the opened favourites, by name, as ADR-0084 has it for all stacks. +3. **The switcher.** A favourite carries a small filled star before its + name and is listed first. +4. **Keys.** `devstack.sidebar.favourites` (stack ids). The sidebar and the + switcher share one list in the page, so a star shows in both at once. +5. **Code.** `ui/src/lib/stackOrder.ts`, `ui/src/components/Sidebar.vue`, + `ui/src/components/StackSwitcher.vue`. Tests: `stackOrder.test.ts`, + `Sidebar.test.ts`. + +## Consequences + +- Each browser has its own favourites, as it has its own order. +- ADR-0084 point 1 no longer beats favourites; its other points stand. +- Hiding stacks (#377) stays open. diff --git a/docs/adr/README.md b/docs/adr/README.md index 797a5d8e..f3fc2d7e 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -166,5 +166,6 @@ 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 | +| [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; point 1 amended by ADR-0086 (favourites) | | [0085](0085-a-connection-to-a-shared-lane-outlasts-its-restarts.md) | A connection to a shared lane is to the lane: it outlasts the lane's restarts and the hub's; a sharing with nothing to open is refused | Accepted (card in the pull request); built | +| [0086](0086-favourite-stacks-list-first.md) | Favourite stacks list first, marked by a star 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 771774df..2f6eb529 100644 --- a/ui/src/components/Sidebar.test.ts +++ b/ui/src/components/Sidebar.test.ts @@ -145,4 +145,40 @@ describe('the sidebar', () => { expect((persist.get>('sidebar.opened') ?? {}).ab12).toBeGreaterThan(10); app.unmount(); }); + + it('lists a favourite first at once, marked by its star or its menu (ADR-0086)', async () => { + const zoo: StackEntry = { ...entry, id: 'cd34', name: 'zoo', repo: '/src/zoo', running: false, daemon: null }; + fake.on('/hub/stacks/cd34/worktrees', ok([])); + 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()); + const star = (id: string) => q(el, `[data-stack="${id}"] [data-testid="sidebar-stack-fav"]`); + expect(names()).toEqual(['shop', 'zoo']); + + star('cd34').click(); + await settle(); + expect(names()).toEqual(['zoo', 'shop']); + expect(star('cd34').getAttribute('aria-pressed')).toBe('true'); + expect(persist.get('sidebar.favourites')).toEqual(['cd34']); + + // The menu says what the star does. + q(el, '[data-stack="cd34"] [data-testid="sidebar-stack-menu"]').click(); + await settle(); + const entryFav = document.querySelector('[data-testid="sidebar-menu-fav"]')!; + expect(entryFav.textContent?.trim()).toBe('Remove from favourites'); + entryFav.click(); + await settle(); + expect(names()).toEqual(['shop', 'zoo']); + expect(star('cd34').getAttribute('aria-pressed')).toBe('false'); + expect(persist.get('sidebar.favourites')).toEqual([]); + app.unmount(); + }); }); diff --git a/ui/src/components/Sidebar.vue b/ui/src/components/Sidebar.vue index c43cb962..bffc265f 100644 --- a/ui/src/components/Sidebar.vue +++ b/ui/src/components/Sidebar.vue @@ -12,7 +12,8 @@ // come live from its stream; the others' are read when the hub's list of // stacks changes or it says a stack's worktrees did (no polling, ADR-0021, // ADR-0078). A stack's menu (its -// "…" button, or a right click) starts, stops and removes it. +// "…" button, or a right click) starts, stops and removes it. A star marks a +// favourite: favourites list first (ADR-0086). import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue'; import { useRoute, useRouter } from 'vue-router'; import { api, paths, sharedId, v1 } from '@/api'; @@ -22,7 +23,17 @@ import { laneLabel, lastTab, MAIN, nodeLabel, runCounts, runsAnything, started } import { laneView, stackPage } from '@/lib/stackRoutes'; import { persist } from '@/lib/persist'; import { statusBucket } from '@/lib/status'; -import { forgetOpened, noteOpened, openedTimes, orderStacks, savedOrder, saveOrder, type StackOrder } from '@/lib/stackOrder'; +import { + forgetFavourite, + forgetOpened, + noteOpened, + openedTimes, + orderStacks, + savedOrder, + saveOrder, + useFavourites, + type StackOrder, +} from '@/lib/stackOrder'; import { useHub } from '@/stores/hub'; import { connectedTo, usePool } from '@/stores/pool'; import { useStack } from '@/stores/stack'; @@ -75,9 +86,11 @@ function toggle(id: string) { // By name or by last opened, never by state: a start or a stop moves nothing // in the list. Last opened is the snapshot taken when the page loaded or the // choice was made, so opening a stack does not move it under the pointer. +// Favourites come first, and a star moves its stack at once. const order = ref(savedOrder()); const openedSnapshot = ref(openedTimes()); -const stacks = computed(() => orderStacks(hub.stacks, order.value, openedSnapshot.value)); +const favourites = useFavourites(); +const stacks = computed(() => orderStacks(hub.stacks, order.value, openedSnapshot.value, favourites.list())); // A stack shown is opened; the hub's list may arrive after the route. watch( () => [route.params.stack, hub.stacks.length] as const, @@ -361,6 +374,7 @@ async function removeStack(s: StackEntry) { if (!res.ok) return; persist.forgetStack(s.id); forgetOpened(s.id); + forgetFavourite(s.id); delete known.value[s.id]; if (isCurrent(s)) void router.push('/'); } @@ -373,6 +387,10 @@ async function copyPath(s: StackEntry) { ui.toast('info', s.repo, 'Copying is not allowed here.'); } } +function toggleFavourite(s: StackEntry) { + closeMenu(); + favourites.toggle(s.id); +}