Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions docs/adr/0086-favourite-stacks-list-first.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion docs/adr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
36 changes: 36 additions & 0 deletions ui/src/components/Sidebar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,40 @@ describe('the sidebar', () => {
expect((persist.get<Record<string, number>>('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<HTMLElement>('[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();
});
});
58 changes: 54 additions & 4 deletions ui/src/components/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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<StackOrder>(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,
Expand Down Expand Up @@ -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('/');
}
Expand All @@ -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);
}
</script>

<template>
Expand Down Expand Up @@ -428,6 +446,18 @@ async function copyPath(s: StackEntry) {
<span v-else-if="!s.running" class="faint small">offline</span>
<span v-else-if="stackIdle(s)" class="faint small" data-testid="sidebar-stack-idle">idle</span>
</button>
<button
type="button"
class="fav-btn"
:class="{ on: favourites.has(s.id) }"
:aria-pressed="favourites.has(s.id)"
:aria-label="favourites.has(s.id) ? `Remove ${s.name} from favourites` : `Add ${s.name} to favourites`"
:title="favourites.has(s.id) ? 'Remove from favourites' : 'Add to favourites: listed first (this browser only)'"
data-testid="sidebar-stack-fav"
@click.stop="favourites.toggle(s.id)"
>
<Icon name="star" :size="14" />
</button>
<button
type="button"
class="more-btn"
Expand Down Expand Up @@ -599,6 +629,9 @@ async function copyPath(s: StackEntry) {
</button>
<button v-else type="button" class="opt" role="menuitem" data-testid="sidebar-menu-stop" @click="stopStack(menu!.s)"><Icon name="power" :size="14" /> Stop…</button>
<button type="button" class="opt" role="menuitem" @click="copyPath(menu!.s)"><Icon name="copy" :size="14" /> Copy path</button>
<button type="button" class="opt" role="menuitem" data-testid="sidebar-menu-fav" @click="toggleFavourite(menu!.s)">
<Icon name="star" :size="14" /> {{ favourites.has(menu.s.id) ? 'Remove from favourites' : 'Add to favourites' }}
</button>
<div class="sep" role="separator" />
<button
type="button"
Expand Down Expand Up @@ -645,6 +678,7 @@ async function copyPath(s: StackEntry) {
flex: 1;
}
.head-btn,
.fav-btn,
.more-btn {
display: grid;
place-items: center;
Expand All @@ -659,21 +693,37 @@ async function copyPath(s: StackEntry) {
}
.head-btn:hover,
.head-btn.open,
.fav-btn:hover,
.more-btn:hover,
.more-btn.open {
background: var(--surface-hover);
color: var(--text);
}
/* The "…" shows on hover and focus; a right click opens the same menu. */
/* The "…" and the star show on hover and focus; a right click opens the
same menu. A favourite's star always shows, filled. */
.fav-btn,
.more-btn {
opacity: 0;
}
.fav-btn {
width: 20px;
}
.stack-row:hover .fav-btn,
.stack-row:hover .more-btn,
.fav-btn:focus-visible,
.fav-btn.on,
.more-btn:focus-visible,
.more-btn.open {
opacity: 1;
}
.fav-btn.on {
color: var(--warn);
}
.fav-btn.on :deep(svg) {
fill: currentColor;
}
@media (hover: none) {
.fav-btn,
.more-btn {
opacity: 1;
}
Expand Down
13 changes: 12 additions & 1 deletion ui/src/components/StackSwitcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useHub } from '@/stores/hub';
import { useStack } from '@/stores/stack';
import { laneLabel, lastTab, MAIN, orderLanes } from '@/lib/lanes';
import { laneView, stackPage } from '@/lib/stackRoutes';
import { useFavourites } from '@/lib/stackOrder';
import type { LaneView } from '@/api/types';
import Icon from './icons/Icon.vue';
import AddStackDialog from './AddStackDialog.vue';
Expand All @@ -29,7 +30,12 @@ function addStack() {
adding.value = true;
}

const stacks = computed(() => [...hub.stacks].sort((a, b) => Number(b.running) - Number(a.running) || a.name.localeCompare(b.name)));
// The favourites first, as in the sidebar (ADR-0086); then the running ones.
const favourites = useFavourites();
const fav = (id: string) => (favourites.has(id) ? 0 : 1);
const stacks = computed(() =>
[...hub.stacks].sort((a, b) => fav(a.id) - fav(b.id) || Number(b.running) - Number(a.running) || a.name.localeCompare(b.name)),
);
const current = computed(() => hub.entry(stack.id));
const currentName = computed(() => current.value?.name ?? stack.view?.name ?? 'Select a stack');

Expand Down Expand Up @@ -136,6 +142,7 @@ function onKey(e: KeyboardEvent) {
<span class="sdot" :class="!hub.reachable ? 'unknown' : s.running ? 'on' : 'off'" aria-hidden="true" />
<div class="grow">
<div class="row">
<Icon v-if="favourites.has(s.id)" name="star" :size="12" class="fav" label="Favourite" data-testid="stack-option-fav" />
<span class="opt-name">{{ s.name }}</span>
<span v-if="hub.reachable" class="pill sm" :class="s.running ? 'ok' : ''">{{ s.running ? 'running' : 'offline' }}</span>
</div>
Expand Down Expand Up @@ -285,6 +292,10 @@ ul {
.opt.current {
background: var(--accent-soft);
}
.fav {
color: var(--warn);
fill: currentColor;
}
.opt-name {
font-weight: 600;
}
Expand Down
1 change: 1 addition & 0 deletions ui/src/components/icons/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const icons = {
trash: '<path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/>',
history: '<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M12 7v5l4 2"/>',
gauge: '<path d="m12 14 4-4"/><path d="M3.34 19a10 10 0 1 1 17.32 0"/>',
star: '<path d="M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z"/>',
} as const;

export type IconName = keyof typeof icons;
20 changes: 19 additions & 1 deletion ui/src/lib/stackOrder.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beforeEach, describe, expect, it } from 'vitest';
import { forgetOpened, noteOpened, openedTimes, orderStacks, savedOrder, saveOrder } from './stackOrder';
import { forgetFavourite, forgetOpened, noteOpened, openedTimes, orderStacks, savedOrder, saveOrder, useFavourites } from './stackOrder';

const s = (id: string, name: string) => ({ id, name });
const all = [s('c', 'web'), s('a', 'api'), s('b', 'worker'), s('d', 'db')];
Expand All @@ -25,4 +25,22 @@ describe('the order of the stacks', () => {
forgetOpened('a');
expect(openedTimes()).toEqual({ b: 7 });
});

it('puts the favourites first, each part in the chosen order (ADR-0086)', () => {
expect(orderStacks(all, 'name', {}, ['c', 'b']).map((x) => x.name)).toEqual(['web', 'worker', 'api', 'db']);
expect(orderStacks(all, 'opened', { b: 20, c: 10, d: 5 }, ['c', 'b']).map((x) => x.name)).toEqual(['worker', 'web', 'db', 'api']);
});

it('keeps the favourites in this browser, and forgets a removed one', () => {
const favs = useFavourites();
favs.toggle('a');
favs.toggle('b');
expect(favs.list()).toEqual(['a', 'b']);
expect(JSON.parse(localStorage.getItem('devstack.sidebar.favourites') ?? '[]')).toEqual(['a', 'b']);
favs.toggle('a');
expect(favs.has('a')).toBe(false);
forgetFavourite('b');
expect(favs.list()).toEqual([]);
expect(JSON.parse(localStorage.getItem('devstack.sidebar.favourites') ?? 'null')).toEqual([]);
});
});
45 changes: 39 additions & 6 deletions ui/src/lib/stackOrder.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// The order of the stacks in the sidebar (#377): by name, or by when this
// browser last opened each. Both are kept in this browser, as the fold state
// is. "Last opened" is a snapshot taken when the page loads or the choice is
// made: opening a stack moves nothing while the page is open.
// made: opening a stack moves nothing while the page is open. Favourites
// (ADR-0086) list first, each part in that order; marking one is the user's
// own act on its row, so it moves at once.
import { ref } from 'vue';
import { persist } from './persist';

export type StackOrder = 'name' | 'opened';

const ORDER_KEY = 'sidebar.order';
const OPENED_KEY = 'sidebar.opened';
const FAVOURITES_KEY = 'sidebar.favourites';

export function savedOrder(): StackOrder {
return persist.get<StackOrder>(ORDER_KEY) === 'opened' ? 'opened' : 'name';
Expand All @@ -33,15 +37,44 @@ export function forgetOpened(id: string): void {
persist.set(OPENED_KEY, all);
}

// One list for the sidebar and the switcher, so a star shows in both at once;
// read from the browser on first use.
const favourites = ref<string[] | null>(null);
const favs = (): string[] => (favourites.value ??= persist.get<string[]>(FAVOURITES_KEY) ?? []);
function saveFavs(next: string[]) {
favourites.value = next;
persist.set(FAVOURITES_KEY, next);
}

/** The stacks this browser marked as favourites, by id. */
export function useFavourites() {
return {
list: (): readonly string[] => favs(),
has: (id: string) => favs().includes(id),
toggle: (id: string) => saveFavs(favs().includes(id) ? favs().filter((x) => x !== id) : [...favs(), id]),
};
}

export function forgetFavourite(id: string): void {
if (favs().includes(id)) saveFavs(favs().filter((x) => x !== id));
}

type Named = { id: string; name: string };

const byName = (a: Named, b: Named) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id);

/**
* The stacks in the chosen order. By last opened, the most recent first; a
* stack never opened here (or added since the snapshot) follows, by name.
* The stacks in the chosen order, the favourites first. By last opened, the
* most recent first; a stack never opened here (or added since the
* snapshot) follows, by name.
*/
export function orderStacks<T extends Named>(stacks: readonly T[], order: StackOrder, opened: Record<string, number>): T[] {
if (order === 'name') return [...stacks].sort(byName);
return [...stacks].sort((a, b) => (opened[b.id] ?? -1) - (opened[a.id] ?? -1) || byName(a, b));
export function orderStacks<T extends Named>(
stacks: readonly T[],
order: StackOrder,
opened: Record<string, number>,
favourites: readonly string[] = [],
): T[] {
const fav = (s: Named) => (favourites.includes(s.id) ? 0 : 1);
const within = order === 'name' ? byName : (a: Named, b: Named) => (opened[b.id] ?? -1) - (opened[a.id] ?? -1) || byName(a, b);
return [...stacks].sort((a, b) => fav(a) - fav(b) || within(a, b));
}