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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
refactor(worktree): drop two fields nothing reads
enesee5a09a7f139
diff --git a/src/shared/scm-scope.test.ts b/src/shared/scm-scope.test.tsindex 3119b4834..771dbce98 100644--- a/src/shared/scm-scope.test.ts+++ b/src/shared/scm-scope.test.ts@@ -32,12 +32,12 @@ describe('boundGroups', () => {describe('scmScopes', () => {it('always puts the main checkout first', () => {const scopes = scmScopes(project, [bound('g1', 'feat', '/wt/feat')])- expect(scopes[0]).toEqual({ id: 'main', label: 'nodeterm (main checkout)', cwd: '/repo', kind: 'main' })+ expect(scopes[0]).toEqual({ id: 'main', label: 'nodeterm (main checkout)', cwd: '/repo' })})it('adds one scope per bound worktree, keyed by group id', () => {const scopes = scmScopes(project, [bound('g1', 'feat', '/wt/feat')])- expect(scopes[1]).toEqual({ id: 'g1', label: 'feat (worktree)', cwd: '/wt/feat', kind: 'worktree' })+ expect(scopes[1]).toEqual({ id: 'g1', label: 'feat (worktree)', cwd: '/wt/feat' })})it('returns nothing when the project has no cwd', () => {diff --git a/src/shared/scm-scope.ts b/src/shared/scm-scope.tsindex a7b32d4ab..f43cdc40e 100644--- a/src/shared/scm-scope.ts+++ b/src/shared/scm-scope.ts@@ -1,13 +1,18 @@import type { GroupWorktree } from './worktree'import type { BoundGroup } from './worktree-reconcile'-/** One checkout the Source Control panel can operate on. */+/**+ * One checkout the Source Control panel can operate on.+ *+ * There is deliberately no `kind: 'main' | 'worktree'` field: `id === 'main'` already IS that+ * distinction (it is the one id no group node can have), and the label already says "(worktree)".+ * A third encoding of the same fact is one more thing that can drift out of step with the other two.+ */export interface ScmScope {/** 'main' for the project's own checkout, else the bound group's node id. */id: stringlabel: stringcwd: string- kind: 'main' | 'worktree'}/**@@ -35,12 +40,11 @@ export function boundGroups(nodes: ScmScopeNode[]): BoundGroup[] {export function scmScopes(project: { cwd?: string; name: string }, bound: BoundGroup[]): ScmScope[] {if (!project.cwd) return []return [- { id: 'main', label: `${project.name} (main checkout)`, cwd: project.cwd, kind: 'main' },+ { id: 'main', label: `${project.name} (main checkout)`, cwd: project.cwd },...bound.map((b) => ({id: b.groupId,label: `${b.worktree.branch} (worktree)`,- cwd: b.worktree.path,- kind: 'worktree' as const+ cwd: b.worktree.path}))]}diff --git a/src/shared/worktree-reconcile.test.ts b/src/shared/worktree-reconcile.test.tsindex 556dd4d76..f496e5264 100644--- a/src/shared/worktree-reconcile.test.ts+++ b/src/shared/worktree-reconcile.test.ts@@ -15,21 +15,21 @@ const bound = (groupId: string, path: string, branch: string): BoundGroup => ({})describe('reconcileWorktrees', () => {- it('reports a binding whose worktree still exists as live', () => {+ it('does not report a binding whose worktree still exists as stale', () => {const r = reconcileWorktrees([bound('g1', '/wt/feat', 'feat')], [wt('/repo', 'main'), wt('/wt/feat', 'feat')])- expect(r.live).toEqual(['g1'])expect(r.stale).toEqual([])})it('reports a binding whose worktree is gone from disk as stale', () => {const r = reconcileWorktrees([bound('g1', '/wt/feat', 'feat')], [wt('/repo', 'main')])expect(r.stale).toEqual(['g1'])- expect(r.live).toEqual([])})it('ignores a trailing slash when matching paths', () => {+ // The persisted path has a trailing slash, git's does not: if that difference were not+ // normalised away, the binding would be reported stale even though its worktree is right there.const r = reconcileWorktrees([bound('g1', '/wt/feat/', 'feat')], [wt('/repo', 'main'), wt('/wt/feat', 'feat')])- expect(r.live).toEqual(['g1'])+ expect(r.stale).toEqual([])})it('reports a worktree on disk that no group is bound to as an orphan', () => {@@ -57,7 +57,6 @@ describe('reconcileWorktrees', () => {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', () => {@@ -71,7 +70,6 @@ describe('reconcileWorktrees', () => {[bound('g1', '/wt/a', 'a'), bound('g2', '/wt/gone', 'gone')],[wt('/repo', 'main'), wt('/wt/a', 'a'), wt('/wt/loose', 'loose')])- expect(r.live).toEqual(['g1'])expect(r.stale).toEqual(['g2'])expect(r.orphans.map((o) => o.path)).toEqual(['/wt/loose'])})diff --git a/src/shared/worktree-reconcile.ts b/src/shared/worktree-reconcile.tsindex 094e5d519..8815b8c73 100644--- a/src/shared/worktree-reconcile.ts+++ b/src/shared/worktree-reconcile.ts@@ -7,12 +7,15 @@ export interface BoundGroup {}/**- * live — group ids whose bound worktree is still registered with git.* stale — group ids whose worktree is gone from disk (deleted outside the app).* orphans — worktrees on disk that no group is bound to (every Unbind makes one).+ *+ * There is deliberately no `live` list: it is the exact complement of `stale` over the bindings the+ * caller passed in, and nothing ever read it. A second, derived source of the same truth is a+ * standing invitation for the two to disagree — the UI asks "is this group stale?", so `stale` is+ * the only answer that needs to exist.*/export interface Reconciliation {- live: string[]stale: string[]orphans: WorktreeEntry[]}@@ -42,15 +45,11 @@ export function reconcileWorktrees(bound: BoundGroup[], entries: WorktreeEntry[]const onDisk = new Set(present.map((e) => norm(e.path)))const boundPaths = new Set(bound.map((b) => norm(b.worktree.path)))- const live: string[] = []- const stale: string[] = []- for (const b of bound) {- ;(onDisk.has(norm(b.worktree.path)) ? live : stale).push(b.groupId)- }+ const stale = bound.filter((b) => !onDisk.has(norm(b.worktree.path))).map((b) => b.groupId)const orphans = present.filter((e) => norm(e.path) !== norm(mainCheckout ?? '') && !boundPaths.has(norm(e.path)))- return { live, stale, orphans }+ return { stale, orphans }}