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.

feat(breadcrumbs): pure record/step logic + note generation

Mina Sameh002151f16fc9
diff --git a/src/renderer/lib/breadcrumbs.test.ts b/src/renderer/lib/breadcrumbs.test.ts
new file mode 100644
index 000000000..ba9745b64
--- /dev/null
+++ b/src/renderer/lib/breadcrumbs.test.ts
@@ -0,0 +1,180 @@
+import { describe, it, expect } from 'vitest'
+import {
+ BREADCRUMB_CAP, buildNote, recordBreadcrumb, stepBreadcrumb,
+ type BreadcrumbState, type BreadcrumbTarget
+} from './breadcrumbs'
+import type { AgentNodeStatus } from '../state/agentStatus'
+
+const target = (over: Partial<BreadcrumbTarget> = {}): BreadcrumbTarget => ({
+ id: 'n1', kind: 'terminal', title: 'My Terminal', ...over
+})
+
+describe('buildNote', () => {
+ it('non-agent node: "<kind> · <title>"', () => {
+ expect(buildNote(target({ kind: 'sticky', title: 'Deploy notes' }), undefined))
+ .toBe('sticky · Deploy notes')
+ })
+
+ it('agent node with no live status falls back to the agent label', () => {
+ expect(buildNote(target({ agentId: 'claude' }), undefined)).toBe('Claude Code · Unknown')
+ })
+
+ it('agent node with a live state uses the sessions-sidebar phrasing', () => {
+ const status: AgentNodeStatus = { state: 'waiting', unread: false }
+ expect(buildNote(target({ agentId: 'claude' }), status)).toBe('Claude Code · Waiting for your response')
+ })
+
+ it('agent node with a session name prefers it over the agent label', () => {
+ const status: AgentNodeStatus = { state: 'working', unread: false, session: 'fix-auth-bug' }
+ expect(buildNote(target({ agentId: 'claude' }), status)).toBe('fix-auth-bug · Running')
+ })
+
+ it('custom agent id with no builtin config falls back to the raw id', () => {
+ expect(buildNote(target({ agentId: 'my-custom-agent' }), undefined))
+ .toBe('my-custom-agent · Unknown')
+ })
+
+ it('an unknown node kind degrades to a generic label rather than inventing one', () => {
+ expect(buildNote(target({ kind: undefined, title: 'Untitled' }), undefined))
+ .toBe('terminal · Untitled')
+ })
+})
+
+describe('recordBreadcrumb', () => {
+ const empty: BreadcrumbState = { list: [], index: -1 }
+
+ it('appends the first stop', () => {
+ const next = recordBreadcrumb(empty, target(), undefined, 1000)
+ expect(next.list).toEqual([{ nodeId: 'n1', at: 1000, note: 'terminal · My Terminal' }])
+ expect(next.index).toBe(0)
+ })
+
+ it('dedupes the same node within the debounce window', () => {
+ const first = recordBreadcrumb(empty, target(), undefined, 1000)
+ const second = recordBreadcrumb(first, target(), undefined, 1500)
+ expect(second).toBe(first) // same object identity — a true no-op
+ })
+
+ it('records the same node again after the debounce window passes', () => {
+ const first = recordBreadcrumb(empty, target(), undefined, 1000)
+ const second = recordBreadcrumb(first, target(), undefined, 5000)
+ expect(second.list).toHaveLength(2)
+ expect(second.index).toBe(1)
+ })
+
+ it('records a DIFFERENT node inside the debounce window', () => {
+ const first = recordBreadcrumb(empty, target({ id: 'a' }), undefined, 1000)
+ const second = recordBreadcrumb(first, target({ id: 'b' }), undefined, 1100)
+ expect(second.list.map((x) => x.nodeId)).toEqual(['a', 'b'])
+ expect(second.index).toBe(1)
+ })
+
+ it('truncates the forward tail on a fresh navigation from a non-tip cursor', () => {
+ let s = recordBreadcrumb(empty, target({ id: 'a' }), undefined, 1000)
+ s = recordBreadcrumb(s, target({ id: 'b' }), undefined, 5000)
+ s = recordBreadcrumb(s, target({ id: 'c' }), undefined, 9000)
+ expect(s.list.map((x) => x.nodeId)).toEqual(['a', 'b', 'c'])
+ // Go back to 'a' (index 0), then land somewhere new — 'b' and 'c' must be dropped.
+ const backAtA: BreadcrumbState = { list: s.list, index: 0 }
+ const fresh = recordBreadcrumb(backAtA, target({ id: 'd' }), undefined, 13000)
+ expect(fresh.list.map((x) => x.nodeId)).toEqual(['a', 'd'])
+ expect(fresh.index).toBe(1)
+ })
+
+ it('caps at BREADCRUMB_CAP, dropping the oldest', () => {
+ let s = empty
+ for (let i = 0; i < BREADCRUMB_CAP + 5; i++) {
+ s = recordBreadcrumb(s, target({ id: `n${i}` }), undefined, 1000 + i * 5000)
+ }
+ expect(s.list).toHaveLength(BREADCRUMB_CAP)
+ expect(s.list[0].nodeId).toBe('n5') // the first 5 were evicted
+ expect(s.list[s.list.length - 1].nodeId).toBe(`n${BREADCRUMB_CAP + 4}`)
+ expect(s.index).toBe(BREADCRUMB_CAP - 1)
+ })
+
+ it('does not mutate the state it was handed', () => {
+ const first = recordBreadcrumb(empty, target({ id: 'a' }), undefined, 1000)
+ const before = [...first.list]
+ recordBreadcrumb(first, target({ id: 'b' }), undefined, 5000)
+ expect(first.list).toEqual(before)
+ expect(first.index).toBe(0)
+ })
+})
+
+describe('stepBreadcrumb', () => {
+ const exists = (ids: string[]) => (id: string) => ids.includes(id)
+
+ it('moves back one stop', () => {
+ const state: BreadcrumbState = {
+ list: [
+ { nodeId: 'a', at: 1, note: '' },
+ { nodeId: 'b', at: 2, note: '' }
+ ],
+ index: 1
+ }
+ expect(stepBreadcrumb(state, 'back', exists(['a', 'b']))).toEqual({ ...state, index: 0 })
+ })
+
+ it('moves forward one stop', () => {
+ const state: BreadcrumbState = {
+ list: [
+ { nodeId: 'a', at: 1, note: '' },
+ { nodeId: 'b', at: 2, note: '' }
+ ],
+ index: 0
+ }
+ expect(stepBreadcrumb(state, 'forward', exists(['a', 'b']))?.index).toBe(1)
+ })
+
+ it('returns null at the start of the list going back', () => {
+ const state: BreadcrumbState = { list: [{ nodeId: 'a', at: 1, note: '' }], index: 0 }
+ expect(stepBreadcrumb(state, 'back', exists(['a']))).toBeNull()
+ })
+
+ it('returns null at the end of the list going forward', () => {
+ const state: BreadcrumbState = { list: [{ nodeId: 'a', at: 1, note: '' }], index: 0 }
+ expect(stepBreadcrumb(state, 'forward', exists(['a']))).toBeNull()
+ })
+
+ it('returns null on an empty list', () => {
+ const state: BreadcrumbState = { list: [], index: -1 }
+ expect(stepBreadcrumb(state, 'back', exists([]))).toBeNull()
+ expect(stepBreadcrumb(state, 'forward', exists([]))).toBeNull()
+ })
+
+ it('skips a deleted node in the walked direction instead of landing on it', () => {
+ const state: BreadcrumbState = {
+ list: [
+ { nodeId: 'a', at: 1, note: '' },
+ { nodeId: 'deleted', at: 2, note: '' },
+ { nodeId: 'c', at: 3, note: '' }
+ ],
+ index: 2
+ }
+ // Going back from 'c': 'deleted' is skipped, lands on 'a'.
+ expect(stepBreadcrumb(state, 'back', exists(['a', 'c']))?.index).toBe(0)
+ })
+
+ it('returns null when every stop in the walked direction is deleted', () => {
+ const state: BreadcrumbState = {
+ list: [
+ { nodeId: 'gone1', at: 1, note: '' },
+ { nodeId: 'gone2', at: 2, note: '' },
+ { nodeId: 'c', at: 3, note: '' }
+ ],
+ index: 2
+ }
+ expect(stepBreadcrumb(state, 'back', exists(['c']))).toBeNull()
+ })
+
+ it('keeps the list identity when it moves — only the cursor changes', () => {
+ const state: BreadcrumbState = {
+ list: [
+ { nodeId: 'a', at: 1, note: '' },
+ { nodeId: 'b', at: 2, note: '' }
+ ],
+ index: 1
+ }
+ expect(stepBreadcrumb(state, 'back', exists(['a', 'b']))?.list).toBe(state.list)
+ })
+})
diff --git a/src/renderer/lib/breadcrumbs.ts b/src/renderer/lib/breadcrumbs.ts
new file mode 100644
index 000000000..5ea9aa428
--- /dev/null
+++ b/src/renderer/lib/breadcrumbs.ts
@@ -0,0 +1,110 @@
+import type { NavStop, NodeKind } from '@shared/types'
+import type { AgentId } from '@shared/agents/config'
+import { agentConfig } from '@shared/agents/config'
+import type { AgentNodeStatus } from '../state/agentStatus'
+import { sessionStatusKind, STATE_LABEL } from './sessionList'
+
+/** Camera navigation history is capped so it never grows unbounded on a long-lived project. */
+export const BREADCRUMB_CAP = 20
+
+/** Recording the same node twice inside this window is a no-op — a focus that immediately
+ * re-triggers (e.g. a sidebar click into an already-focused node) must not spam the trail. */
+export const BREADCRUMB_DEDUPE_MS = 3000
+
+const KIND_LABEL: Partial<Record<NodeKind, string>> = {
+ terminal: 'terminal',
+ sticky: 'sticky',
+ editor: 'editor',
+ diff: 'diff',
+ video: 'video',
+ web: 'web',
+ browser: 'browser',
+ dino: 'dino',
+ group: 'group'
+}
+
+/** The subset of a node `recordBreadcrumb`/`buildNote` need — loose on purpose so callers can
+ * pass a live React Flow node or a plain object without importing its full type. */
+export interface BreadcrumbTarget {
+ id: string
+ kind: NodeKind | undefined
+ title: string
+ agentId?: AgentId
+}
+
+/** One project's breadcrumb array plus a cursor into it. The cursor is NOT persisted — only
+ * `list` rides `IndexEntryV3.breadcrumbs`; a project reactivation resets the cursor to the tip. */
+export interface BreadcrumbState {
+ list: NavStop[]
+ index: number
+}
+
+/**
+ * The note is a SNAPSHOT of what was happening at record time, not a live pointer — a later
+ * state change must not retroactively rewrite history. For an agent node it mirrors the exact
+ * phrasing the sessions sidebar already uses (`sessionStatusKind` + `STATE_LABEL`), so the note
+ * is never an invented-fresh string; the session name (if set) is preferred over the bare agent
+ * label, same precedence the header chip follows.
+ */
+export function buildNote(target: BreadcrumbTarget, status: AgentNodeStatus | undefined): string {
+ if (target.agentId) {
+ // agentConfig, not a raw AGENT_CONFIG lookup: AgentId is `BuiltinAgentId | (string & {})` (a
+ // custom agent's id), and AGENT_CONFIG is only keyed by the builtin subset — indexing it
+ // directly with a custom id fails to typecheck. agentConfig(id) exists for exactly this.
+ const agentLabel = agentConfig(target.agentId)?.label ?? target.agentId
+ const name = status?.session || agentLabel
+ const stateLabel = STATE_LABEL[sessionStatusKind(status?.state)]
+ return `${name} · ${stateLabel}`
+ }
+ const kindLabel = KIND_LABEL[target.kind ?? 'terminal'] ?? 'node'
+ return `${kindLabel} · ${target.title}`
+}
+
+/**
+ * Records a deliberate node landing. Browser-style history: if the cursor is not at the tip (the
+ * user went back, then navigated somewhere new — not via stepBreadcrumb), the forward tail is
+ * dropped before the new stop is appended, exactly like a browser tab's history after navigating
+ * away from a back-visited page.
+ *
+ * Returns the SAME object (by reference) when the call is a no-op dedupe, so callers can skip a
+ * write (`next === state`) instead of comparing array contents.
+ */
+export function recordBreadcrumb(
+ state: BreadcrumbState,
+ target: BreadcrumbTarget,
+ status: AgentNodeStatus | undefined,
+ now: number
+): BreadcrumbState {
+ const current = state.list[state.index]
+ if (current && current.nodeId === target.id && now - current.at < BREADCRUMB_DEDUPE_MS) {
+ return state
+ }
+ const truncated = state.list.slice(0, state.index + 1)
+ const appended: NavStop[] = [
+ ...truncated,
+ { nodeId: target.id, at: now, note: buildNote(target, status) }
+ ]
+ const capped = appended.length > BREADCRUMB_CAP
+ ? appended.slice(appended.length - BREADCRUMB_CAP)
+ : appended
+ return { list: capped, index: capped.length - 1 }
+}
+
+/**
+ * Moves the cursor one stop back/forward, skipping any breadcrumb whose node no longer exists
+ * (never landing on a dead entry). Returns null when there is no reachable stop in that
+ * direction — callers no-op rather than move the camera.
+ */
+export function stepBreadcrumb(
+ state: BreadcrumbState,
+ direction: 'back' | 'forward',
+ nodeExists: (nodeId: string) => boolean
+): BreadcrumbState | null {
+ const delta = direction === 'back' ? -1 : 1
+ let i = state.index + delta
+ while (i >= 0 && i < state.list.length) {
+ if (nodeExists(state.list[i].nodeId)) return { list: state.list, index: i }
+ i += delta
+ }
+ return null
+}
diff --git a/src/renderer/lib/sessionList.ts b/src/renderer/lib/sessionList.ts
index 853f177cd..83617f3b4 100644
--- a/src/renderer/lib/sessionList.ts
+++ b/src/renderer/lib/sessionList.ts
@@ -34,7 +34,7 @@ export type StatusKind = 'working' | 'attention' | 'done' | 'unknown'
/** Sessions sidebar top-level grouping mode. */
export type SidebarGrouping = 'project' | 'status'
-const STATE_LABEL: Record<StatusKind, string> = {
+export const STATE_LABEL: Record<StatusKind, string> = {
working: 'Running',
attention: 'Waiting for your response',
done: 'Done',