Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(notch): the panel ranks sessions, it does not race them

enescb4434b4b089
diff --git a/docs/notch-hud.md b/docs/notch-hud.md
index 9748fe4f0..22dd0beb8 100644
--- a/docs/notch-hud.md
+++ b/docs/notch-hud.md
@@ -46,9 +46,23 @@ the HUD window via a `getHudWindow()`/`sendToHud()` singleton (mirror `main-wind
Row shape sent to the HUD:
```ts
{ nodeId, agentId, title, model?, state: 'working'|'needsYou'|'done'|'idle',
- prompt?, activity?, contextPercent?,
+ prompt?, activity?, contextPercent?, unread,
subagents: [{ id, label?, state: 'working'|'done' }], updatedAt }
```
+- **row order = STATE PRIORITY, not recency** (`hudRowRank`): `needsYou` → unread `done` →
+ `working` → `idle`, the sessions sidebar's own section order (`STATUS_GROUP_ORDER`,
+ renderer/lib/sessionList.ts) — the owner asked the notch to follow the sidebar's model. Ties
+ inside a tier break on **first appearance** (the accum Map's insertion order), a fact no feed
+ event can change. The rows used to sort on `updatedAt` DESC, and `updatedAt` is bumped by every
+ event including the `onNodeNowChange` activity/context ticks, so a busy session climbed to the
+ top every few seconds and — because the panel draws only the first `HUD_ROW_CAP` rows — each
+ climb also evicted the last row and handed it back: the reported "keeps reshuffling, things
+ disappear and come back". `updatedAt` still drives the row's reltime tag and the staleness
+ watchdog; it is simply no longer doing double duty as the row's position.
+- **`unread`** is the done latch said out loud (`state === 'done' && !doneSeen`) — the same mark
+ the sidebar carries. It was previously readable only as "the row exists at all", which is
+ invisible beside five other rows and looks like a glitch when a phone-side read-ack retires the
+ row. The renderer draws it as an **Unread** badge on the title line.
- **`prompt` is clipped at the mirror's `PROMPT_MAX` (120)** — `firstPromptLine` imports that
constant rather than keeping its own number, because the phone's Live Activity line is fed by the
SAME `onNodeStateChange` seam and the two surfaces must not show one prompt at two lengths.
@@ -112,10 +126,18 @@ the transparent rest of the window stays click-through. Hidden entirely when idl
(driven by `max-height`, so content of unknown height animates) → the rows box, bottom corners
still rounded, top still fused — a spring-ish `--capsule-dur` (~220 ms) `--capsule-ease` expand
from the notch, NOT a separate floating panel. Rows fade in and start below the bar line
- (`padding-top: calc(var(--bar) + 4px)`). Up to ~6 session rows, newest-active first. Each row:
- animated mascot/green check + title + `model · reltime` tag (blue working / gray idle / green
+ (`padding-top: calc(var(--bar) + 4px)`). `HUD_ROW_CAP` (6) session rows in the pushed
+ (state-priority) order. Each row:
+ animated mascot/green check + title + an **Unread** badge when `row.unread` + `model · reltime`
+ tag (blue working / gray idle / green
done) + a `You: <prompt>` (or `activity`) second line + a `▸ N subagents` disclosure (child rows:
- label + state). A **Go** button (or row-tap) → IPC → main mirrors the notification-click handler:
+ label + state). Because the order is now meaningful, a cut row is a real omission, so the cap is
+ disclosed instead of silent: a `+N more · 1 needs you · 2 unread` footer counts what is hidden by
+ tier (the sidebar answers the same question with `projectSignalCounts`; the notch has no room for
+ a badge per section) and clicking it draws the full list — the cap and the counting are the pure
+ `splitPanelRows` / `overflowLabel` (`src/renderer/hud/panel-rows.ts`, unit-tested). Note main
+ pushes ALL rows: the collapsed indicator aggregates over the whole array, so capping in main
+ would silently drop a working agent's mascot. A **Go** button (or row-tap) → IPC → main mirrors the notification-click handler:
`getMainWindow().show()/focus()` + `sendToMain(app:focus-node, nodeId)` → `Canvas.focusNodeById`,
and clears that node's done latch.
- **Dismissing a row**: hovering a row reveals a `×` (right-click on the row does the same) →
diff --git a/src/main/notch-hud-model.test.ts b/src/main/notch-hud-model.test.ts
index 0896071ee..3441a599b 100644
--- a/src/main/notch-hud-model.test.ts
+++ b/src/main/notch-hud-model.test.ts
@@ -6,6 +6,7 @@ import {
createHudModel,
bucketState,
firstPromptLine,
+ hudRowRank,
HUD_STALE_DROP_MS,
type HudRow,
WORKING_STALE_MS
@@ -213,16 +214,93 @@ describe('6h drop', () => {
// The collapsed-indicator aggregation is NOT here: it is the renderer's pure `buildIndicator`
// (src/renderer/hud/indicator.ts + indicator.test.ts), the only side that draws it.
-describe('row ordering', () => {
- it('sorts newest-active first', () => {
+describe('row ordering — state priority, never recency', () => {
+ it('ranks needsYou → unread done → working → idle (the sidebar’s section order)', () => {
+ expect(hudRowRank({ state: 'needsYou', unread: false })).toBeLessThan(
+ hudRowRank({ state: 'done', unread: true })
+ )
+ expect(hudRowRank({ state: 'done', unread: true })).toBeLessThan(
+ hudRowRank({ state: 'working', unread: false })
+ )
+ expect(hudRowRank({ state: 'working', unread: false })).toBeLessThan(
+ hudRowRank({ state: 'idle', unread: false })
+ )
+ // A `done` that is no longer unread is not a "new for you" row — it ranks with idle, never
+ // above a session that is still running.
+ expect(hudRowRank({ state: 'done', unread: false })).toBe(hudRowRank({ state: 'idle', unread: false }))
+ })
+
+ it('orders the built rows by tier, regardless of how recently each moved', () => {
const m = createHudModel()
- m.applyStateChange(stateChange({ nodeId: 'a', state: 'working', agentId: 'claude', ts: T0 + 1 }))
- m.applyStateChange(stateChange({ nodeId: 'b', state: 'working', agentId: 'codex', ts: T0 + 2 }))
- m.applyStateChange(stateChange({ nodeId: 'c', state: 'working', agentId: 'claude', ts: T0 + 3 }))
- m.applyStateChange(stateChange({ nodeId: 'd', state: 'done', agentId: 'gemini', ts: T0 + 4 }))
+ // Deliberately created oldest-tier-first and with recency running the OTHER way: under the old
+ // `updatedAt` sort this came out exactly reversed.
+ m.applyStateChange(stateChange({ nodeId: 'w1', state: 'working', agentId: 'claude', ts: T0 + 1 }))
+ m.applyStateChange(stateChange({ nodeId: 'd1', state: 'done', agentId: 'gemini', ts: T0 + 2 }))
+ m.applyStateChange(stateChange({ nodeId: 'w2', state: 'working', agentId: 'codex', ts: T0 + 3 }))
+ m.applyStateChange(stateChange({ nodeId: 'n1', state: 'needsYou', agentId: 'claude', ts: T0 + 4 }))
const rows = m.buildRows(T0 + 10, titleOf)
- expect(rows.map((r) => r.nodeId)).toEqual(['d', 'c', 'b', 'a'])
- expect(rows.map((r) => r.state)).toEqual(['done', 'working', 'working', 'working'])
+ expect(rows.map((r) => r.nodeId)).toEqual(['n1', 'd1', 'w1', 'w2'])
+ expect(rows.map((r) => r.state)).toEqual(['needsYou', 'done', 'working', 'working'])
+ })
+
+ it('an activity tick does NOT move a row (the reshuffle regression)', () => {
+ const m = createHudModel()
+ for (const id of ['a', 'b', 'c']) {
+ m.applyStateChange(stateChange({ nodeId: id, state: 'working', agentId: 'claude', ts: T0 }))
+ }
+ const before = m.buildRows(T0, titleOf).map((r) => r.nodeId)
+ expect(before).toEqual(['a', 'b', 'c'])
+ // Every tool call pushes one of these. `updatedAt` moves (it still drives reltime + the
+ // watchdog) — the ROW must not.
+ m.applyNowChange(nowChange({ nodeId: 'c', ts: T0 + 5_000, activity: 'Editing a.ts' }))
+ m.applyNowChange(nowChange({ nodeId: 'b', ts: T0 + 9_000, contextPercent: 12 }))
+ expect(m.buildRows(T0 + 10_000, titleOf).map((r) => r.nodeId)).toEqual(['a', 'b', 'c'])
+ expect(rowFor(m.buildRows(T0 + 10_000, titleOf), 'c')?.updatedAt).toBe(T0 + 5_000)
+ })
+
+ it('breaks ties by first appearance, which no feed event can change', () => {
+ const m = createHudModel()
+ m.applyStateChange(stateChange({ nodeId: 'first', state: 'working', ts: T0 + 100 }))
+ m.applyStateChange(stateChange({ nodeId: 'second', state: 'working', ts: T0 + 50 }))
+ m.applyStateChange(stateChange({ nodeId: 'third', state: 'working', ts: T0 + 75 }))
+ // Timestamps are shuffled; appearance order is not.
+ expect(m.buildRows(T0 + 200, titleOf).map((r) => r.nodeId)).toEqual(['first', 'second', 'third'])
+ // A subagent burst + a new turn on the youngest row still doesn't hoist it.
+ m.applyAgentEvent({ nodeId: 'third', agentId: 'claude', kind: 'subagent-start', toolUseId: 't1' } as never)
+ m.applyAgentEvent({ nodeId: 'third', agentId: 'claude', kind: 'state', newTurn: true, task: 'go' } as never)
+ expect(m.buildRows(T0 + 300, titleOf).map((r) => r.nodeId)).toEqual(['first', 'second', 'third'])
+ // Only a real STATE move relocates a row — and then only to its new tier.
+ m.applyStateChange(stateChange({ nodeId: 'third', state: 'needsYou', ts: T0 + 400 }))
+ expect(m.buildRows(T0 + 400, titleOf).map((r) => r.nodeId)).toEqual(['third', 'first', 'second'])
+ })
+
+ it('keeps the panel’s first 6 rows STABLE across ticks (what the cap used to churn)', () => {
+ const m = createHudModel()
+ const ids = ['n1', 'n2', 'n3', 'n4', 'n5', 'n6', 'n7']
+ for (const id of ids) {
+ m.applyStateChange(stateChange({ nodeId: id, state: 'working', agentId: 'claude', ts: T0 }))
+ }
+ const window = (): string[] => m.buildRows(T0 + 60_000, titleOf).slice(0, 6).map((r) => r.nodeId)
+ const first = window()
+ expect(first).toEqual(['n1', 'n2', 'n3', 'n4', 'n5', 'n6'])
+ // The 7th session ticking away is exactly what used to evict the 6th row and then hand it back.
+ for (let i = 1; i <= 5; i++) {
+ m.applyNowChange(nowChange({ nodeId: 'n7', ts: T0 + i * 1_000, activity: `step ${i}` }))
+ expect(window()).toEqual(first)
+ }
+ })
+})
+
+describe('unread', () => {
+ it('marks a finished-and-unlooked-at row, and nothing else', () => {
+ const m = createHudModel()
+ m.applyStateChange(stateChange({ nodeId: 'done', state: 'done' }))
+ m.applyStateChange(stateChange({ nodeId: 'busy', state: 'working' }))
+ m.applyStateChange(stateChange({ nodeId: 'ask', state: 'needsYou' }))
+ const rows = m.buildRows(T0, titleOf)
+ expect(rowFor(rows, 'done')?.unread).toBe(true)
+ expect(rowFor(rows, 'busy')?.unread).toBe(false)
+ expect(rowFor(rows, 'ask')?.unread).toBe(false)
})
})
diff --git a/src/main/notch-hud-model.ts b/src/main/notch-hud-model.ts
index 0ec498115..ea029f0ea 100644
--- a/src/main/notch-hud-model.ts
+++ b/src/main/notch-hud-model.ts
@@ -44,10 +44,49 @@ export interface HudRow {
activity?: string
contextPercent?: number
subagents: HudSubagentRow[]
- /** Last-change time (ms) — drives ordering + the row's "reltime" tag. */
+ /**
+ * A finished turn the user has not looked at yet — the sessions sidebar's `unread` mark
+ * (renderer/lib/sessionList.ts), which is what the HUD's done latch has always meant.
+ *
+ * It used to be implicit: a seen `done` demotes to `idle` and idle rows are not emitted, so
+ * "unread" was readable ONLY as "the row exists at all". That is unreadable from the user's side
+ * — a row that vanishes when the phone acks it looks like a glitch rather than a read receipt —
+ * so the fact is now stated on the row, labelled by the renderer and ranked by `hudRowRank`.
+ */
+ unread: boolean
+ /** Last-change time (ms) — drives the row's "reltime" tag and the staleness watchdog. NOT the
+ * row order: see `hudRowRank` for why sorting by this is what made the panel reshuffle. */
updatedAt: number
}
+/**
+ * Row order tiers, and the ONE reason the HUD does not sort by recency.
+ *
+ * `needsYou` → unread `done` → `working` → `idle`: what must be acted on, then what is new for
+ * you, then what is merely live, then what has settled. This is the sessions sidebar's own section
+ * order (`STATUS_GROUP_ORDER` in renderer/lib/sessionList.ts) — the model the owner asked the notch
+ * to follow — so the two surfaces rank a session the same way and can share its vocabulary.
+ *
+ * The rows used to be sorted `updatedAt` descending, and `updatedAt` is bumped by EVERY feed event
+ * including `applyNowChange` — the activity/context ticks a working session emits per tool call. So
+ * a busy session climbed to the top every few seconds, and since the panel draws only the first
+ * `HUD_ROW_CAP` rows, each climb also changed MEMBERSHIP: the last row dropped off and came back.
+ * That was the reported bug ("keeps reshuffling — things disappear and come back"). A tick says
+ * nothing about a session's importance, so it must not move the row.
+ */
+const ROW_RANK: Record<HudRowState, number> = { needsYou: 0, done: 1, working: 2, idle: 3 }
+
+/**
+ * The tier a row sorts in (lower = higher up the panel). A `done` row that is no longer unread
+ * ranks with `idle`: the tier is "new for you", not "finished". (Today the latch demotes such a row
+ * to `idle` before it is ever built, so this only matters if that ever changes — the rank must not
+ * quietly promote a read session above a running one.)
+ */
+export function hudRowRank(row: Pick<HudRow, 'state' | 'unread'>): number {
+ if (row.state === 'done' && !row.unread) return ROW_RANK.idle
+ return ROW_RANK[row.state]
+}
+
// The collapsed-indicator aggregation used to be duplicated here (`buildIndicator`/`HudIndicator`)
// with no production caller — the HUD renderer, which is the only thing that draws it, cannot
// import src/main. It lived on as dead code and drifted (it never learned the `needsYou` dot the
@@ -118,7 +157,7 @@ export interface HudModel {
dismiss(nodeId: string): void
/** Drop nodes gone from the mirror + idle > 6h. Returns true if anything changed. */
prune(now: number): boolean
- /** Build the row array (active sessions, newest-active first), joining titles in. */
+ /** Build the row array (active sessions, in `hudRowRank` order), joining titles in. */
buildRows(now: number, getTitle: (nodeId: string) => string | undefined): HudRow[]
}
@@ -288,7 +327,13 @@ export function createHudModel(): HudModel {
}
function buildRows(now: number, getTitle: (nodeId: string) => string | undefined): HudRow[] {
- const rows: HudRow[] = []
+ // Collected in `nodes` iteration order — a Map iterates in INSERTION order, and an accum is
+ // inserted exactly once (`ensure` sets only when the key is absent; nothing re-sets a live
+ // key), so this index is "the order these sessions first appeared to the HUD". That is the
+ // tiebreak below: it is a fact no feed event can change, which is precisely what `updatedAt`
+ // was not. A pruned node that later returns re-enters at the end of its tier — the only way a
+ // row moves within a tier, and it is a genuinely new session as far as the HUD is concerned.
+ const rows: { row: HudRow; seen: number }[] = []
for (const [nodeId, a] of nodes) {
const state = displayState(a, now)
// The HUD shows active sessions only — nothing when a node is idle/seen.
@@ -299,20 +344,29 @@ export function createHudModel(): HudModel {
a.dismissedAt = undefined
const model = a.sessionId ? modelBySession.get(a.sessionId) : undefined
rows.push({
- nodeId,
- agentId: a.agentId,
- title: getTitle(nodeId) || 'Session',
- ...(model ? { model } : {}),
- state,
- ...(a.prompt ? { prompt: a.prompt } : {}),
- ...(a.activity ? { activity: a.activity } : {}),
- ...(typeof a.contextPercent === 'number' ? { contextPercent: a.contextPercent } : {}),
- subagents: [...a.subagents.values()],
- updatedAt: a.updatedAt
+ row: {
+ nodeId,
+ agentId: a.agentId,
+ title: getTitle(nodeId) || 'Session',
+ ...(model ? { model } : {}),
+ state,
+ ...(a.prompt ? { prompt: a.prompt } : {}),
+ ...(a.activity ? { activity: a.activity } : {}),
+ ...(typeof a.contextPercent === 'number' ? { contextPercent: a.contextPercent } : {}),
+ subagents: [...a.subagents.values()],
+ // The latch, said out loud: a finished turn nobody has looked at. `noteFocus` / a
+ // read-ack from the phone clears `doneSeen`, which retires the row entirely.
+ unread: state === 'done' && !a.doneSeen,
+ updatedAt: a.updatedAt
+ },
+ seen: rows.length
})
}
- rows.sort((x, y) => y.updatedAt - x.updatedAt)
- return rows
+ // Tier first, first-appearance second. Deliberately NOT `updatedAt` on either axis (see
+ // `hudRowRank`): a row moves only when the SESSION's state moves, so an activity tick can
+ // neither reorder the panel nor push the last row out of the cap and back in.
+ rows.sort((x, y) => hudRowRank(x.row) - hudRowRank(y.row) || x.seen - y.seen)
+ return rows.map((r) => r.row)
}
return {
diff --git a/src/preload/hud.ts b/src/preload/hud.ts
index 7624d68c2..b7599b8cb 100644
--- a/src/preload/hud.ts
+++ b/src/preload/hud.ts
@@ -20,6 +20,9 @@ export interface HudRow {
activity?: string
contextPercent?: number
subagents: HudSubagentRow[]
+ /** A finished turn the user has not looked at yet (the sessions sidebar's `unread` mark) — the
+ * row's sort tier and its "Unread" badge. */
+ unread: boolean
updatedAt: number
}
export interface HudPush {
diff --git a/src/renderer/hud/hud.css b/src/renderer/hud/hud.css
index b26170e6d..79efb91df 100644
--- a/src/renderer/hud/hud.css
+++ b/src/renderer/hud/hud.css
@@ -334,7 +334,17 @@ body {
justify-content: center;
width: 22px;
}
+/* Title cell = name + optional Unread badge. The cell is the flex line; the NAME carries the
+ ellipsis (a grid item defaults to min-width:auto, so min-width:0 is what lets it shrink instead
+ of pushing the tag column off the row). */
.hud-row__title {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ min-width: 0;
+ overflow: hidden;
+}
+.hud-row__name {
font-family: var(--hud-mono);
font-size: 12px;
font-weight: 600;
@@ -343,6 +353,21 @@ body {
overflow: hidden;
text-overflow: ellipsis;
}
+/* "Unread" — a finished turn you have not looked at. Green, the same ink as the done check and the
+ collapsed capsule's blob, so the three read as one signal. Never shrinks: the badge is the point
+ of the row, the title is what gives way. */
+.hud-row__badge {
+ flex-shrink: 0;
+ font-family: var(--hud-mono);
+ font-size: 9px;
+ font-weight: 700;
+ letter-spacing: 0.3px;
+ text-transform: uppercase;
+ color: #30d158;
+ background: rgba(48, 209, 88, 0.16);
+ border-radius: 5px;
+ padding: 1px 5px;
+}
.hud-row__tag {
grid-column: 3;
grid-row: 1;
@@ -381,6 +406,19 @@ body {
font-weight: 600;
}
+/* "+N more · 2 unread" — what the 6-row cap left out, since the list is now ranked and a cut row
+ is a real omission. Click toggles the full list (the panel already scrolls past --panel-max-h). */
+.hud-panel__more {
+ font-family: var(--hud-mono);
+ font-size: 10px;
+ color: #8e8e93;
+ padding: 7px 8px 2px;
+ cursor: pointer;
+}
+.hud-panel__more:hover {
+ color: #f2f2f7;
+}
+
/* Dithered pixel separator between rows (agent-notch's DitherSeparator: a sparse row of gray
pixels). Two offset dashed gradients read as scattered 2px cells rather than a solid rule. */
.hud-sep {
diff --git a/src/renderer/hud/main.ts b/src/renderer/hud/main.ts
index 562ca5a1a..7abfd87bc 100644
--- a/src/renderer/hud/main.ts
+++ b/src/renderer/hud/main.ts
@@ -9,6 +9,7 @@ import { HUD_BRAND_PULSE_CLASS, brandPulseBackground, brandPulsePlan } from '../
import { createGrokMarkSvg } from '../lib/grokMark'
import { createCopilotMarkSvg } from '../lib/copilotMark'
import { buildIndicator, orderIndicatorAgents } from './indicator'
+import { HUD_ROW_CAP, overflowLabel, splitPanelRows } from './panel-rows'
import { percentText } from '../lib/usageFormat'
import codexPet from '../assets/pet-codex.webp'
@@ -29,6 +30,8 @@ interface HudRow {
activity?: string
contextPercent?: number
subagents: HudSubagentRow[]
+ /** Finished and not yet looked at — the sidebar's `unread` mark, ranked + labelled here. */
+ unread: boolean
updatedAt: number
}
interface HudPush {
@@ -80,6 +83,10 @@ let hoverExpand = true
let percentMode: 'used' | 'remaining' = 'remaining'
// Which subagent disclosures the user has opened (by nodeId), preserved across re-renders.
const openSubs = new Set<string>()
+// The user clicked "+N more" — draw every pushed row instead of the first HUD_ROW_CAP. Reset when
+// the panel closes: the cap is the glance default, and an expansion is about the panel in front of
+// you, not a preference.
+let showAllRows = false
// ---- Interaction: click-through hotspot + expand/collapse ----------------------------------
@@ -111,6 +118,10 @@ indicator.addEventListener('click', () => {
function setExpanded(next: boolean): void {
if (expanded === next) return
expanded = next
+ if (!expanded && showAllRows) {
+ showAllRows = false
+ renderPanel(latestRows)
+ }
capsule.classList.toggle('expanded', expanded)
syncCapsuleOverhang() // expanded: drop the padding so the panel gets the full width
window.hud.setExpanded(expanded)
@@ -246,7 +257,9 @@ function renderIndicator(rows: HudRow[]): void {
function renderPanel(rows: HudRow[]): void {
panel.replaceChildren()
- const shown = rows.slice(0, 6)
+ // Rows arrive in state-priority order (main's `hudRowRank`), so the cap always cuts from the
+ // least urgent end — but it still cuts, and what it cut is counted below rather than dropped.
+ const { shown, hidden } = splitPanelRows(rows, showAllRows ? rows.length : HUD_ROW_CAP)
shown.forEach((row, i) => {
// Dithered pixel separator between rows (agent-notch's DitherSeparator).
if (i > 0) {
@@ -256,6 +269,22 @@ function renderPanel(rows: HudRow[]): void {
}
panel.append(buildRow(row))
})
+ const label = overflowLabel(hidden)
+ if (label || showAllRows) panel.append(buildMore(label))
+}
+
+/** The "+N more · 2 unread" footer — click to draw the rest (the panel scrolls), click again to
+ * return to the glance-sized list. */
+function buildMore(label: string | undefined): HTMLElement {
+ const el = document.createElement('div')
+ el.className = 'hud-panel__more'
+ el.textContent = showAllRows ? 'Show fewer' : (label ?? '')
+ el.addEventListener('click', (e) => {
+ e.stopPropagation()
+ showAllRows = !showAllRows
+ renderPanel(latestRows)
+ })
+ return el
}
function buildRow(row: HudRow): HTMLElement {
@@ -274,7 +303,19 @@ function buildRow(row: HudRow): HTMLElement {
const title = document.createElement('div')
title.className = 'hud-row__title'
- title.textContent = row.title
+ const name = document.createElement('span')
+ name.className = 'hud-row__name'
+ name.textContent = row.title
+ title.append(name)
+ // Say "unread" out loud. The row's mere existence used to be the only sign that a finished
+ // session was new for you — invisible next to five other rows, and indistinguishable from a
+ // glitch when it vanished on a read-ack from the phone. Same word the sessions sidebar uses.
+ if (row.unread) {
+ const badge = document.createElement('span')
+ badge.className = 'hud-row__badge'
+ badge.textContent = 'Unread'
+ title.append(badge)
+ }
const tag = document.createElement('div')
tag.className = `hud-row__tag hud-row__tag--${row.state}`
@@ -333,10 +374,13 @@ function buildRow(row: HudRow): HTMLElement {
return el
}
+// Sub-line fallback wording, borrowed from the sessions sidebar's labels (STATE_LABEL /
+// STATUS_GROUP_LABEL in renderer/lib/sessionList.ts) so one session does not have two names on two
+// surfaces. `done` reads "Done" — the "new for you" half of it is the Unread badge's job.
function stateLabel(state: HudRow['state']): string {
- if (state === 'working') return 'Working…'
+ if (state === 'working') return 'Running'
if (state === 'needsYou') return 'Needs you'
- if (state === 'done') return 'Finished'
+ if (state === 'done') return 'Done'
return 'Idle'
}
diff --git a/src/renderer/hud/panel-rows.test.ts b/src/renderer/hud/panel-rows.test.ts
new file mode 100644
index 000000000..bfbd1e2d8
--- /dev/null
+++ b/src/renderer/hud/panel-rows.test.ts
@@ -0,0 +1,53 @@
+import { describe, it, expect } from 'vitest'
+import { HUD_ROW_CAP, overflowLabel, splitPanelRows, type PanelRow } from './panel-rows'
+
+const row = (state: PanelRow['state'], unread = false): PanelRow => ({ state, unread })
+
+describe('splitPanelRows', () => {
+ it('draws the first HUD_ROW_CAP rows and hands the rest back as hidden', () => {
+ const rows = Array.from({ length: 9 }, (_, i) => ({ id: i }))
+ const { shown, hidden } = splitPanelRows(rows)
+ expect(shown).toHaveLength(HUD_ROW_CAP)
+ expect(hidden).toHaveLength(9 - HUD_ROW_CAP)
+ // Order is the caller's ranking, untouched on both sides — re-sorting here would be the very
+ // churn the ranking exists to stop.
+ expect([...shown, ...hidden]).toEqual(rows)
+ })
+
+ it('hides nothing when the list fits', () => {
+ const rows = [row('needsYou'), row('working')]
+ const { shown, hidden } = splitPanelRows(rows)
+ expect(shown).toEqual(rows)
+ expect(hidden).toEqual([])
+ expect(overflowLabel(hidden)).toBeUndefined()
+ })
+
+ it('honors an explicit cap (the "show all" expansion passes rows.length)', () => {
+ const rows = Array.from({ length: 9 }, (_, i) => ({ id: i }))
+ expect(splitPanelRows(rows, rows.length).hidden).toEqual([])
+ expect(splitPanelRows(rows, 2).shown).toEqual([{ id: 0 }, { id: 1 }])
+ })
+})
+
+describe('overflowLabel', () => {
+ it('counts what the cap left out, by tier, in tier order', () => {
+ const hidden = [
+ row('needsYou'),
+ row('done', true),
+ row('done', true),
+ row('working'),
+ row('working'),
+ row('working')
+ ]
+ expect(overflowLabel(hidden)).toBe('+6 more · 1 needs you · 2 unread · 3 running')
+ })
+
+ it('omits empty tiers rather than printing zeroes', () => {
+ expect(overflowLabel([row('working'), row('working')])).toBe('+2 more · 2 running')
+ expect(overflowLabel([row('done', true)])).toBe('+1 more · 1 unread')
+ })
+
+ it('counts a read `done` as idle, not as unread', () => {
+ expect(overflowLabel([row('done', false), row('idle')])).toBe('+2 more · 2 idle')
+ })
+})
diff --git a/src/renderer/hud/panel-rows.ts b/src/renderer/hud/panel-rows.ts
new file mode 100644
index 000000000..c08611aa5
--- /dev/null
+++ b/src/renderer/hud/panel-rows.ts
@@ -0,0 +1,67 @@
+// Pure cap + overflow rule for the expanded Notch HUD panel (docs/notch-hud.md).
+//
+// The panel is a GLANCE surface: it draws only the first few rows of the array main pushes. That
+// cap used to be an accident-limiter over a recency sort — the 6th row was whichever session had
+// ticked least recently, so it fell off and came back every few seconds and losing it cost
+// nothing. Now the array arrives in state-priority order (`hudRowRank`, src/main/notch-hud-model),
+// so the cap truncates a MEANINGFUL list: whatever it cuts is the least urgent, but it is still a
+// real omission, and a panel that silently shows 6 of 11 sessions is lying by omission about the
+// two that need you. Hence `overflowLabel` — the sessions sidebar answers the same question with a
+// counted badge (`projectSignalCounts`), and this is that badge for a surface with no room for one.
+//
+// Kept pure + DOM-free so the cap and the counting are unit-tested without a renderer (main.ts
+// draws the result and owns the "show all" toggle).
+
+/** The row shape the split reads — a structural subset of the HUD row contract (main.ts mirrors
+ * that contract locally on purpose, so this module needs no type from main/preload). */
+export interface PanelRow {
+ state: 'working' | 'needsYou' | 'done' | 'idle'
+ unread?: boolean
+}
+
+/** How many rows the expanded panel draws before it starts counting instead. */
+export const HUD_ROW_CAP = 6
+
+export interface PanelSplit<T> {
+ /** The rows actually drawn. */
+ shown: T[]
+ /** The rows the cap left out, in the same order — never dropped silently, always counted. */
+ hidden: T[]
+}
+
+/** Split the pushed rows at the cap. Order is preserved on both sides: the caller has already
+ * ranked them, and re-sorting here is exactly the churn the ranking exists to stop. */
+export function splitPanelRows<T>(rows: readonly T[], cap = HUD_ROW_CAP): PanelSplit<T> {
+ if (cap <= 0) return { shown: [], hidden: [...rows] }
+ return { shown: rows.slice(0, cap), hidden: rows.slice(cap) }
+}
+
+/**
+ * The "+N more" line, broken down by what is hidden — "+3 more · 1 needs you · 2 unread".
+ *
+ * The words are the sessions sidebar's (`STATUS_GROUP_LABEL`: Need attention / Unread / Running /
+ * Idle, lowercased to sit in a count phrase), and the clauses run in the same tier order the rows
+ * do, so the line reads as a continuation of the list rather than a separate vocabulary. A tier
+ * with nothing in it is omitted entirely — "0 unread" is noise on a strip this narrow.
+ *
+ * Returns undefined when nothing is hidden, so the caller draws no element at all.
+ */
+export function overflowLabel(hidden: readonly PanelRow[]): string | undefined {
+ if (hidden.length === 0) return undefined
+ let needsYou = 0
+ let unread = 0
+ let working = 0
+ let idle = 0
+ for (const r of hidden) {
+ if (r.state === 'needsYou') needsYou++
+ else if (r.state === 'done' && r.unread !== false) unread++
+ else if (r.state === 'working') working++
+ else idle++
+ }
+ const parts = [`+${hidden.length} more`]
+ if (needsYou) parts.push(`${needsYou} needs you`)
+ if (unread) parts.push(`${unread} unread`)
+ if (working) parts.push(`${working} running`)
+ if (idle) parts.push(`${idle} idle`)
+ return parts.join(' · ')
+}