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(worktree): live branch/dirty/ahead-behind on the group chip; bound frames look bound

eneseac564589463
diff --git a/src/renderer/nodes/GroupNode.tsx b/src/renderer/nodes/GroupNode.tsx
index 1f67efde1..db9e988fb 100644
--- a/src/renderer/nodes/GroupNode.tsx
+++ b/src/renderer/nodes/GroupNode.tsx
@@ -1,6 +1,7 @@
-import { useState } from 'react'
+import { useEffect, useState } from 'react'
import { NodeResizer, useReactFlow, type NodeProps } from '@xyflow/react'
import { NODE_COLORS, ungroupNodes, type CanvasNode } from '../state/workspace'
+import { useWorktrees, WORKTREE_STATUS_THROTTLE_MS } from '../state/worktrees'
export type WorktreeAction = 'merge' | 'remove' | 'unbind'
@@ -27,14 +28,48 @@ export function GroupNode({ id, data, selected }: NodeProps<CanvasNode>) {
const { updateNodeData, setNodes } = useReactFlow()
const [showColors, setShowColors] = useState(false)
+ const wt = data.worktree
+ // The store is the ONLY caller of the worktree/status git IPC; it throttles
+ // (WORKTREE_STATUS_THROTTLE_MS) and is epoch-guarded, so asking often is free.
+ const status = useWorktrees((s) => (wt ? s.statusByPath[wt.path] : undefined))
+ const stale = useWorktrees((s) => (wt ? s.staleGroupIds.includes(id) : false))
+
+ const wtPath = wt?.path
+ // Asking once per render is NOT enough to make the chip live: nothing re-renders a group frame
+ // while the user works inside its terminals, so the dirty count would freeze at whatever it was
+ // when the node last happened to render (verified — it sat at "0 changed" until the canvas was
+ // clicked). Hence a tick. It owns no cache and no `git status` of its own: it just pokes the
+ // store, whose throttle still decides whether a real read happens (so N frames don't mean N
+ // reads, and a mid-window render still coalesces). A stale worktree has no directory left to
+ // stat, so it isn't polled.
+ useEffect(() => {
+ if (!wtPath || stale) return
+ const poke = () => void useWorktrees.getState().refreshStatus(wtPath)
+ poke()
+ const t = setInterval(poke, WORKTREE_STATUS_THROTTLE_MS)
+ return () => clearInterval(t)
+ }, [wtPath, stale])
+
const ungroup = () => setNodes((ns) => ungroupNodes(ns as CanvasNode[], id))
+ // A bound frame must read as a checkout at a glance: solid border + a stronger tint of the
+ // group's OWN color (no new palette). Stale drops the hue entirely and goes muted/warning.
+ const bound = !!wt
+ const frameClass = [
+ 'group-node',
+ selected ? 'selected' : '',
+ bound ? 'group-node--worktree' : '',
+ bound && stale ? 'group-node--worktree-stale' : ''
+ ]
+ .filter(Boolean)
+ .join(' ')
+
return (
<div
- className={`group-node${selected ? ' selected' : ''}`}
+ className={frameClass}
style={{
- borderColor: data.color,
- background: `${data.color}0f`,
+ borderColor: bound && stale ? undefined : data.color,
+ background: bound && stale ? undefined : `${data.color}${bound ? '1c' : '0f'}`,
// Rounded selection ring (box-shadow follows border-radius, unlike the resizer line).
boxShadow: selected ? `0 0 0 1.5px ${data.color}` : undefined
}}
@@ -74,18 +109,51 @@ export function GroupNode({ id, data, selected }: NodeProps<CanvasNode>) {
spellCheck={false}
onChange={(e) => updateNodeData(id, { title: e.target.value })}
/>
- {data.worktree && (
+ {wt && (
<div className="group-node__wt nodrag">
- <span className="group-node__branch" title={data.worktree.path}>
- ⎇ {data.worktree.branch}
- </span>
- <button
- className="group-node__wt-btn"
- title="Merge to main"
- onClick={() => worktreeActionHandler?.(id, 'merge')}
- >
- ⤴
- </button>
+ {stale ? (
+ // The directory is gone from disk (deleted outside the app). Merge and Remove would
+ // act on a path that no longer exists, so only Unbind is offered.
+ <span
+ className="group-node__branch group-node__branch--stale"
+ title={`Worktree directory is gone: ${wt.path}\nUnbind to detach this group from it.`}
+ >
+ ⎇ {wt.branch} · missing
+ </span>
+ ) : (
+ <span className="group-node__branch" title={wt.path}>
+ {/* The branch git reports NOW wins: the user may have switched branches inside
+ the worktree from a terminal, and the persisted name would then be a lie. */}
+ ⎇ {status?.branch || wt.branch}
+ {!!status && status.dirty > 0 && (
+ <em className="group-node__wt-dirty" title={`${status.dirty} changed file(s)`}>
+ {' '}
+ · {status.dirty} changed
+ </em>
+ )}
+ {!!status && status.ahead > 0 && (
+ <em className="group-node__wt-ahead" title={`${status.ahead} commit(s) ahead`}>
+ {' '}
+ · {status.ahead}↑
+ </em>
+ )}
+ {!!status && status.behind > 0 && (
+ <em className="group-node__wt-behind" title={`${status.behind} commit(s) behind`}>
+ {' '}
+ · {status.behind}↓
+ </em>
+ )}
+ </span>
+ )}
+ {!stale && (
+ <button
+ className="group-node__wt-btn"
+ title="Merge to main"
+ onClick={() => worktreeActionHandler?.(id, 'merge')}
+ >
+ ⤴
+ </button>
+ )}
<button
className="group-node__wt-btn"
title="Unbind worktree (keeps the worktree on disk)"
@@ -93,13 +161,15 @@ export function GroupNode({ id, data, selected }: NodeProps<CanvasNode>) {
>
Unbind
</button>
- <button
- className="group-node__wt-btn"
- title="Remove worktree"
- onClick={() => worktreeActionHandler?.(id, 'remove')}
- >
- ✕
- </button>
+ {!stale && (
+ <button
+ className="group-node__wt-btn"
+ title="Remove worktree"
+ onClick={() => worktreeActionHandler?.(id, 'remove')}
+ >
+ ✕
+ </button>
+ )}
</div>
)}
</div>
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index 353dbf063..babc26632 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -3679,6 +3679,22 @@ body,
cursor: grab;
}
+/* Bound to a git worktree: a checkout, not a loose grouping. Solid, thicker border (the tint is
+ bumped inline from the group's own data.color — no separate palette) so it reads as bound from
+ across the canvas, where the label pill is too small to parse. */
+.group-node--worktree {
+ border-style: solid;
+ border-width: 2px;
+}
+
+/* The worktree directory is gone from disk: drop the hue (GroupNode emits no inline border/background
+ for this case), go muted/warning. */
+.group-node--worktree-stale {
+ border-style: dashed;
+ border-color: rgba(255, 159, 10, 0.5);
+ background: rgba(255, 159, 10, 0.05);
+}
+
/* Floating label pill, sitting on the top border (opaque so it "cuts" the dashes).
--group-label-boost (set per viewport frame in Canvas.onMove) counter-scales the pill
when the canvas is zoomed out, so group names stay readable/clickable from afar. */
@@ -3729,7 +3745,7 @@ body,
}
.group-node__branch {
- max-width: 160px;
+ max-width: 260px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
@@ -3738,6 +3754,25 @@ body,
color: var(--accent);
}
+/* The worktree is gone from disk — muted/warning, not colorful. */
+.group-node__branch--stale {
+ color: #ff9f0a;
+ cursor: help;
+}
+
+/* Live status suffixes: dirty / ahead / behind, quieter than the branch name itself. */
+.group-node__wt-dirty,
+.group-node__wt-ahead,
+.group-node__wt-behind {
+ font-style: normal;
+ font-weight: 500;
+ color: var(--muted);
+}
+
+.group-node__wt-dirty {
+ color: #ff9f0a;
+}
+
.group-node__wt-btn {
background: #141416;
border: 1px solid var(--border);
diff --git a/src/shared/worktree-reconcile.test.ts b/src/shared/worktree-reconcile.test.ts
index 03956433f..556dd4d76 100644
--- a/src/shared/worktree-reconcile.test.ts
+++ b/src/shared/worktree-reconcile.test.ts
@@ -50,6 +50,22 @@ describe('reconcileWorktrees', () => {
expect(r.orphans).toEqual([])
})
+ // The realistic "deleted outside the app" case: `rm -rf` the directory and git STILL lists the
+ // worktree, tagged `prunable`. Before this, the entry counted as on-disk, the group was reported
+ // live, and a dead binding rendered as a healthy one (and was offered for adoption as an orphan).
+ it('treats a prunable entry (directory deleted behind git´s back) as gone, not live', () => {
+ const gone: WorktreeEntry = { ...wt('/wt/feat', 'feat'), prunable: true }
+ const r = reconcileWorktrees([bound('g1', '/wt/feat', 'feat')], [wt('/repo', 'main'), gone])
+ expect(r.stale).toEqual(['g1'])
+ expect(r.live).toEqual([])
+ })
+
+ it('never offers a prunable worktree as an adoptable orphan', () => {
+ const gone: WorktreeEntry = { ...wt('/wt/loose', 'loose'), prunable: true }
+ const r = reconcileWorktrees([], [wt('/repo', 'main'), gone, wt('/wt/real', 'real')])
+ expect(r.orphans.map((o) => o.path)).toEqual(['/wt/real'])
+ })
+
it('classifies a mixed workspace in one pass', () => {
const r = reconcileWorktrees(
[bound('g1', '/wt/a', 'a'), bound('g2', '/wt/gone', 'gone')],
diff --git a/src/shared/worktree-reconcile.ts b/src/shared/worktree-reconcile.ts
index eabb7a25b..094e5d519 100644
--- a/src/shared/worktree-reconcile.ts
+++ b/src/shared/worktree-reconcile.ts
@@ -34,7 +34,12 @@ const norm = normWorktreePath
export function reconcileWorktrees(bound: BoundGroup[], entries: WorktreeEntry[]): Reconciliation {
const usable = entries.filter((e) => !e.isBare)
const mainCheckout = usable[0]?.path
- const onDisk = new Set(usable.map((e) => norm(e.path)))
+ // `prunable` = git still lists it, but its directory is gone (deleted behind git's back, and
+ // nobody has run `git worktree prune` yet). Listed is NOT the same as present: counting these
+ // as on-disk would report a dead binding as live, and would offer a directory that no longer
+ // exists as an adoptable orphan.
+ const present = usable.filter((e) => !e.prunable)
+ const onDisk = new Set(present.map((e) => norm(e.path)))
const boundPaths = new Set(bound.map((b) => norm(b.worktree.path)))
const live: string[] = []
@@ -43,7 +48,7 @@ export function reconcileWorktrees(bound: BoundGroup[], entries: WorktreeEntry[]
;(onDisk.has(norm(b.worktree.path)) ? live : stale).push(b.groupId)
}
- const orphans = usable.filter(
+ const orphans = present.filter(
(e) => norm(e.path) !== norm(mainCheckout ?? '') && !boundPaths.has(norm(e.path))
)
diff --git a/src/shared/worktree.test.ts b/src/shared/worktree.test.ts
index c6f96fb19..4ed2fe674 100644
--- a/src/shared/worktree.test.ts
+++ b/src/shared/worktree.test.ts
@@ -127,11 +127,31 @@ describe('parseWorktreePorcelain', () => {
].join('\n')
const entries = parseWorktreePorcelain(out)
expect(entries).toEqual([
- { path: '/repo', head: 'abc123', branch: 'main', isBare: false },
- { path: '/wt/x', head: 'def456', branch: 'feature/x', isBare: false },
- { path: '/bare', head: null, branch: null, isBare: true }
+ { path: '/repo', head: 'abc123', branch: 'main', isBare: false, prunable: false },
+ { path: '/wt/x', head: 'def456', branch: 'feature/x', isBare: false, prunable: false },
+ { path: '/bare', head: null, branch: null, isBare: true, prunable: false }
])
})
+
+ // git keeps LISTING a worktree whose directory was deleted behind its back, tagging it
+ // `prunable`. Dropping that tag is what would let a dead worktree render as a healthy one.
+ it('flags a worktree whose directory is gone as prunable', () => {
+ const out = [
+ 'worktree /repo', 'HEAD abc123', 'branch refs/heads/main', '',
+ 'worktree /wt/gone', 'HEAD def456', 'branch refs/heads/feat',
+ 'prunable gitdir file points to non-existent location', ''
+ ].join('\n')
+ const entries = parseWorktreePorcelain(out)
+ expect(entries[0].prunable).toBe(false)
+ expect(entries[1]).toEqual({
+ path: '/wt/gone', head: 'def456', branch: 'feat', isBare: false, prunable: true
+ })
+ })
+
+ it('flags a bare `prunable` line with no reason', () => {
+ const entries = parseWorktreePorcelain(['worktree /wt/gone', 'prunable', ''].join('\n'))
+ expect(entries[0].prunable).toBe(true)
+ })
})
describe('isDangerousWorktreeRemovalPath', () => {
diff --git a/src/shared/worktree.ts b/src/shared/worktree.ts
index 4b25b877c..415d3ddbb 100644
--- a/src/shared/worktree.ts
+++ b/src/shared/worktree.ts
@@ -16,6 +16,12 @@ export interface WorktreeEntry {
branch: string | null
head: string | null
isBare: boolean
+ /**
+ * git still LISTS a worktree whose directory was deleted behind its back — it just tags it
+ * `prunable` (until someone runs `git worktree prune`). Treating such an entry as alive is what
+ * makes a dead binding look healthy, so the flag has to survive the parse.
+ */
+ prunable?: boolean
}
/**
@@ -114,10 +120,19 @@ export function worktreeFromEntry(
export function parseWorktreePorcelain(out: string): WorktreeEntry[] {
const entries: WorktreeEntry[] = []
let cur: Partial<WorktreeEntry> | null = null
+ const flush = (c: Partial<WorktreeEntry>): void => {
+ entries.push({
+ path: c.path!,
+ branch: c.branch ?? null,
+ head: c.head ?? null,
+ isBare: c.isBare ?? false,
+ prunable: c.prunable ?? false
+ })
+ }
for (const raw of out.split('\n')) {
const line = raw.trimEnd()
if (line.startsWith('worktree ')) {
- if (cur) entries.push({ path: cur.path!, branch: cur.branch ?? null, head: cur.head ?? null, isBare: cur.isBare ?? false })
+ if (cur) flush(cur)
cur = { path: line.slice('worktree '.length), isBare: false }
} else if (!cur) {
continue
@@ -127,9 +142,12 @@ export function parseWorktreePorcelain(out: string): WorktreeEntry[] {
cur.branch = line.slice('branch '.length).replace(/^refs\/heads\//, '')
} else if (line === 'bare') {
cur.isBare = true
+ } else if (line === 'prunable' || line.startsWith('prunable ')) {
+ // e.g. "prunable gitdir file points to non-existent location" — the directory is gone.
+ cur.prunable = true
}
}
- if (cur) entries.push({ path: cur.path!, branch: cur.branch ?? null, head: cur.head ?? null, isBare: cur.isBare ?? false })
+ if (cur) flush(cur)
return entries
}