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(worktrees): add picker search

Darren Kattane2cb4263f639
diff --git a/src/renderer/components/WorktreeDialog.test.tsx b/src/renderer/components/WorktreeDialog.test.tsx
new file mode 100644
index 000000000..78ea85090
--- /dev/null
+++ b/src/renderer/components/WorktreeDialog.test.tsx
@@ -0,0 +1,64 @@
+// @vitest-environment jsdom
+import { act } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { resetDialogStack } from './dialog-stack'
+import { WorktreeDialog } from './WorktreeDialog'
+import type { WorktreeEntry } from '@shared/worktree'
+
+;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
+
+const existing: WorktreeEntry[] = [
+ { path: '/repo.wt/feature-login', branch: 'feature/login', head: 'a', isBare: false },
+ { path: '/repo.wt/fix-api', branch: 'fix/api', head: 'b', isBare: false }
+]
+
+describe('WorktreeDialog existing-worktree search', () => {
+ let root: Root | undefined
+ let host: HTMLElement
+
+ beforeEach(() => {
+ host = document.createElement('div')
+ document.body.appendChild(host)
+ })
+
+ afterEach(() => {
+ act(() => root?.unmount())
+ root = undefined
+ host.remove()
+ resetDialogStack()
+ })
+
+ it('filters the scrollable picker by branch or path', () => {
+ root = createRoot(host)
+ act(() => {
+ root!.render(
+ <WorktreeDialog
+ intent="create"
+ repoPath="/repo"
+ existing={existing}
+ defaultBaseRef="main"
+ branches={[]}
+ defaultPath={() => '/repo.wt/feature'}
+ busy={false}
+ error={null}
+ onCreate={vi.fn()}
+ onBindExisting={vi.fn()}
+ onCancel={vi.fn()}
+ />
+ )
+ })
+
+ const search = document.querySelector<HTMLInputElement>(
+ '[aria-label="Search existing worktrees"]'
+ )!
+ expect(document.querySelectorAll('.bind-existing__row')).toHaveLength(2)
+ act(() => {
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(search, 'LOGIN')
+ search.dispatchEvent(new Event('input', { bubbles: true }))
+ })
+ const rows = [...document.querySelectorAll('.bind-existing__row')]
+ expect(rows).toHaveLength(1)
+ expect(rows[0].textContent).toContain('feature/login')
+ })
+})
diff --git a/src/renderer/components/WorktreeDialog.tsx b/src/renderer/components/WorktreeDialog.tsx
index 879927b13..f660b8a7e 100644
--- a/src/renderer/components/WorktreeDialog.tsx
+++ b/src/renderer/components/WorktreeDialog.tsx
@@ -2,7 +2,12 @@ import { useEffect, useState } from 'react'
import { createPortal } from 'react-dom'
import { useDialogStack } from './dialog-stack'
import { BranchSelect } from './BranchSelect'
-import { isValidGitRef, type WorktreeCreateValue, type WorktreeEntry } from '@shared/worktree'
+import {
+ filterWorktrees,
+ isValidGitRef,
+ type WorktreeCreateValue,
+ type WorktreeEntry
+} from '@shared/worktree'
interface Props {
/** 'create' = the pane/palette entry point (a new group frame); 'bind' = an existing group's
@@ -52,6 +57,7 @@ export function WorktreeDialog({
const [baseRef, setBaseRef] = useState(defaultBaseRef)
const [path, setPath] = useState(() => defaultPath(repoPath, 'feature/'))
const [pathEdited, setPathEdited] = useState(false)
+ const [existingQuery, setExistingQuery] = useState('')
// Keep the path in sync with the branch until the user edits it by hand.
useEffect(() => {
@@ -66,6 +72,7 @@ export function WorktreeDialog({
}, [defaultBaseRef, baseEdited])
const hasBranches = branches.length > 0
+ const filteredExisting = filterWorktrees(existing, existingQuery)
// Only the topmost modal answers a key (./dialog-stack): this dialog and a ConfirmDialog can be
// open at the same time, and one Escape must not close both.
@@ -108,8 +115,16 @@ export function WorktreeDialog({
{existing.length > 0 && (
<div className="bind-existing">
<div className="bind-existing__title">Existing worktrees</div>
+ <input
+ className="bind-existing__search"
+ type="search"
+ aria-label="Search existing worktrees"
+ placeholder="Search branch or path…"
+ value={existingQuery}
+ onChange={(e) => setExistingQuery(e.target.value)}
+ />
<div className="bind-existing__list">
- {existing.map((e) => (
+ {filteredExisting.map((e) => (
// A detached-HEAD worktree cannot be bound (there is no branch to merge or name the
// group after), so the row is DISABLED and says why — clicking it used to be a
// silent no-op.
@@ -130,6 +145,9 @@ export function WorktreeDialog({
<span className="bind-existing__path">{e.path}</span>
</button>
))}
+ {filteredExisting.length === 0 && (
+ <div className="bind-existing__empty">No matching worktrees</div>
+ )}
</div>
</div>
)}
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index 0f2eebaf6..52f5b0405 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -4407,6 +4407,30 @@ body,
color: var(--muted);
}
+.bind-existing__search {
+ width: 100%;
+ height: 30px;
+ margin: 0 0 6px;
+ padding: 0 9px;
+ border: 1px solid var(--border);
+ border-radius: 6px;
+ outline: none;
+ background: var(--bg);
+ color: var(--text);
+ font-size: 12px;
+}
+
+.bind-existing__search:focus {
+ border-color: var(--accent);
+}
+
+.bind-existing__empty {
+ padding: 10px 8px;
+ color: var(--muted);
+ font-size: 12px;
+ text-align: center;
+}
+
.bind-existing__row {
display: flex;
align-items: baseline;
diff --git a/src/renderer/styles.worktree.test.ts b/src/renderer/styles.worktree.test.ts
index e3efc083b..6b0fa96d7 100644
--- a/src/renderer/styles.worktree.test.ts
+++ b/src/renderer/styles.worktree.test.ts
@@ -12,4 +12,11 @@ describe('New Worktree existing-worktree list', () => {
expect(rule).toContain('max-height: min(260px, 32vh)')
expect(rule).toContain('overflow-y: auto')
})
+
+ it('offers a branch/path search before the scrolling list', () => {
+ expect(DIALOG).toContain('aria-label="Search existing worktrees"')
+ expect(DIALOG.indexOf('bind-existing__search')).toBeLessThan(
+ DIALOG.indexOf('bind-existing__list')
+ )
+ })
})
diff --git a/src/shared/worktree.test.ts b/src/shared/worktree.test.ts
index 00f61b045..48427e234 100644
--- a/src/shared/worktree.test.ts
+++ b/src/shared/worktree.test.ts
@@ -18,6 +18,7 @@ import {
DEFAULT_BASE_REF,
type WorktreeEntry
} from './worktree'
+import { filterWorktrees } from './worktree'
const entry = (path: string, branch: string | null): WorktreeEntry => ({
path,
@@ -401,3 +402,21 @@ describe('worktreeRemoveMessage', () => {
)
})
})
+
+describe('filterWorktrees', () => {
+ const entries = [
+ entry('/repo.worktrees/feature-login', 'feature/login'),
+ entry('/repo.worktrees/fix-api', 'fix/API'),
+ entry('/repo.worktrees/detached', null)
+ ]
+
+ it('matches branch or path without case sensitivity', () => {
+ expect(filterWorktrees(entries, 'LOGIN')).toEqual([entries[0]])
+ expect(filterWorktrees(entries, 'fix api')).toEqual([entries[1]])
+ })
+
+ it('returns every entry for a blank query and none for a miss', () => {
+ expect(filterWorktrees(entries, ' ')).toBe(entries)
+ expect(filterWorktrees(entries, 'not-here')).toEqual([])
+ })
+})
diff --git a/src/shared/worktree.ts b/src/shared/worktree.ts
index d8a9fe250..22e72404d 100644
--- a/src/shared/worktree.ts
+++ b/src/shared/worktree.ts
@@ -366,3 +366,13 @@ export function worktreeRemoveMessage(p: WorktreeRemovePrompt): string {
const warn = p.warning ? `\n\n⚠ ${p.warning}` : ''
return `${who}${what}${body}${optIn}${warn}`
}
+
+/** Case-insensitive branch/path search for the existing-worktree picker. Every term must match. */
+export function filterWorktrees(entries: WorktreeEntry[], query: string): WorktreeEntry[] {
+ const terms = query.trim().toLowerCase().split(/\s+/).filter(Boolean)
+ if (!terms.length) return entries
+ return entries.filter((entry) => {
+ const haystack = `${entry.branch ?? ''}\n${entry.path}`.toLowerCase()
+ return terms.every((term) => haystack.includes(term))
+ })
+}