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
feat(project-settings): search integration + name-match forceVisible + deep links
enes8143636ecbbd
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 1c477e0f5..ff685bdb9 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -112,6 +112,7 @@ import {IconUnlock} from '../components/icons'import type { SettingsSectionId } from '../components/settings/nav'+import { projectSectionId } from '../components/settings/project-settings-targets'// Overlay surfaces (settings, source control, explorer, kanban, onboarding, dictation, …) are// code-split: they render behind a flag and must not sit in the startup chunk. See lazyPanels.import {@@ -836,6 +837,15 @@ export function Canvas() {const [welcomeOpen, setWelcomeOpen] = useState(false)// Optional deep-link target when opening settings (e.g. RemotePicker → the SSH section).const [settingsSection, setSettingsSection] = useState<SettingsSectionId | undefined>(undefined)+ // Bumped ONLY by a deep link, so SettingsPage re-targets (and clears its search box) even when+ // the requested section is the one it is already showing. Plain opens leave it alone.+ const [settingsNonce, setSettingsNonce] = useState(0)+ // Tab caret menu / sidebar right-click → this project's own pane in Settings.+ const openProjectSettings = useCallback((id: string) => {+ setSettingsSection(projectSectionId(id))+ setSettingsNonce((n) => n + 1)+ setSettingsOpen(true)+ }, [])const [scOpen, setScOpen] = useState(false)const [shortcutsOpen, setShortcutsOpen] = useState(false)// Debug log panel (issue #78). Settings' "Open" button fires the event (the dialog can't@@ -8779,6 +8789,11 @@ export function Canvas() {}},{ label: 'Set folder…', icon: <IconProject />, onClick: () => setProjectFolder(projectId) },+ {+ label: 'Project settings…',+ icon: <IconGear />,+ onClick: () => openProjectSettings(projectId)+ },{ type: 'separator' },{ type: 'colors', onPick: (color) => setProjectColor(projectId, color) },{ type: 'separator' },@@ -8791,7 +8806,15 @@ export function Canvas() {]})},- [activeProjectId, switchProject, renameProject, setProjectFolder, setProjectColor, closeProject]+ [+ activeProjectId,+ switchProject,+ renameProject,+ setProjectFolder,+ setProjectColor,+ closeProject,+ openProjectSettings+ ])// Reopen a previously closed project and make it active — the active-project effect reloads its@@ -9174,6 +9197,7 @@ export function Canvas() {onRemoteAccess={() => setRemoteDialogOpen(true)}onSetDefaultAccount={setProjectDefaultAccount}onSetDefaultPermissionMode={setProjectDefaultPermissionMode}+ onOpenProjectSettings={openProjectSettings}/><div className="top-banners">@@ -9673,7 +9697,11 @@ export function Canvas() {)}{settingsOpen && (- <SettingsPage onClose={() => setSettingsOpen(false)} initialSection={settingsSection} />+ <SettingsPage+ onClose={() => setSettingsOpen(false)}+ initialSection={settingsSection}+ retargetNonce={settingsNonce}+ />)}{scOpen && (diff --git a/src/renderer/components/TabBar.test.tsx b/src/renderer/components/TabBar.test.tsxnew file mode 100644index 000000000..4da6dcb0e--- /dev/null+++ b/src/renderer/components/TabBar.test.tsx@@ -0,0 +1,89 @@+// @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 type { Project } from '@shared/types'+import { useProjects } from '../state/projects'+import { TabBar } from './TabBar'++;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true++class NoopResizeObserver {+ observe(): void {}+ unobserve(): void {}+ disconnect(): void {}+}++function project(over: Partial<Project> = {}): Project {+ return {+ id: 'p1',+ name: 'Alpha',+ color: '#0a84ff',+ cwd: '/repo/alpha',+ viewport: { x: 0, y: 0, zoom: 1 },+ nodes: [],+ ...over+ }+}++describe('TabBar caret menu', () => {+ let root: Root+ let host: HTMLElement+ let onOpenProjectSettings: ReturnType<typeof vi.fn<(id: string) => void>>++ const click = async (el: HTMLElement): Promise<void> => {+ await act(async () => {+ el.dispatchEvent(new MouseEvent('click', { bubbles: true }))+ })+ }++ const menuButton = (label: string): HTMLButtonElement | undefined =>+ Array.from(document.querySelectorAll<HTMLButtonElement>('.tab-menu button')).find(+ (b) => b.textContent?.trim() === label+ )++ beforeEach(async () => {+ // jsdom implements neither; TabBar uses both purely for presentation.+ ;(globalThis as { ResizeObserver?: unknown }).ResizeObserver = NoopResizeObserver+ Element.prototype.scrollIntoView = (): void => {}+ ;(window as unknown as { nodeTerminal: any }).nodeTerminal = {}+ host = document.createElement('div')+ document.body.appendChild(host)+ useProjects.setState({ projects: [project()], activeProjectId: 'p1' })+ onOpenProjectSettings = vi.fn<(id: string) => void>()+ root = createRoot(host)+ await act(async () => {+ root.render(+ <TabBar+ onSwitch={vi.fn()}+ onReconnect={vi.fn()}+ onReorder={vi.fn()}+ onOpenWelcome={vi.fn()}+ onRename={vi.fn()}+ onSetFolder={vi.fn()}+ onCloseProject={vi.fn()}+ onRemoteAccess={vi.fn()}+ onSetDefaultAccount={vi.fn()}+ onSetDefaultPermissionMode={vi.fn()}+ onOpenProjectSettings={onOpenProjectSettings}+ />+ )+ })+ await click(host.querySelector<HTMLButtonElement>('.tab__caret')!)+ })++ afterEach(() => {+ act(() => root.unmount())+ host.remove()+ useProjects.setState({ projects: [], activeProjectId: '' })+ })++ it('offers "Project settings…" and deep-links the project it was opened on', async () => {+ const item = menuButton('Project settings…')+ expect(item).toBeDefined()+ await click(item!)+ expect(onOpenProjectSettings).toHaveBeenCalledWith('p1')+ // …and the menu closes behind it, like every other action in this menu.+ expect(document.querySelector('.tab-menu')).toBeNull()+ })+})diff --git a/src/renderer/components/TabBar.tsx b/src/renderer/components/TabBar.tsxindex 8205e41e9..02209ce00 100644--- a/src/renderer/components/TabBar.tsx+++ b/src/renderer/components/TabBar.tsx@@ -39,6 +39,9 @@ interface TabBarProps {onSetDefaultAccount: (id: string, accountId: string | undefined) => void/** Set (or clear, with undefined = use the global setting) the project's default permission mode. */onSetDefaultPermissionMode: (id: string, mode: AgentPermissionMode | undefined) => void+ /** Deep-link to this project's own pane in Settings — everything this menu can change plus the+ * shared/machine-local settings families, which have no other entry point. */+ onOpenProjectSettings: (id: string) => void}/**@@ -73,7 +76,8 @@ export function TabBar({onCloseProject,onRemoteAccess,onSetDefaultAccount,- onSetDefaultPermissionMode+ onSetDefaultPermissionMode,+ onOpenProjectSettings}: TabBarProps) {// Select the raw array and filter in a memo, a `.filter()` inside the selector returns a// fresh array every store snapshot, which re-rendered the TabBar on EVERY projects change.@@ -504,6 +508,14 @@ export function TabBar({))}</div>)}+ <button+ onClick={() => {+ onOpenProjectSettings(menuProject.id)+ closeMenu()+ }}+ >+ Project settings…+ </button><buttononClick={() => {onCloseProject(menuProject.id)diff --git a/src/renderer/components/settings/ProjectSettingsFamilies.tsx b/src/renderer/components/settings/ProjectSettingsFamilies.tsxindex eda9bf6f5..6ed9cb24b 100644--- a/src/renderer/components/settings/ProjectSettingsFamilies.tsx+++ b/src/renderer/components/settings/ProjectSettingsFamilies.tsx@@ -8,8 +8,10 @@ import type {} from '@shared/project-settings'import { Input } from '@renderer/ui/Input'import { Switch } from '@renderer/ui/Switch'+import { useSettingsSearch } from './context'import { FieldRow } from './FieldRow'import { formatEnvLines, formatListLines, parseEnvLines, parseListLines } from './project-settings-env'+import { matchesQuery, type SettingsSearchEntry } from './search'/*** The four per-family editors (setup / agents / worktree / terminal) that hang off@@ -112,6 +114,36 @@ const FAMILY_CONFIG: Record<ProjectSettingsFamily, FamilyConfig> = {const FAMILIES = Object.keys(FAMILY_CONFIG) as ProjectSettingsFamily[]+/**+ * Search metadata, derived from the config above so a field can never exist without one. Static+ * (no project name in the keywords): a query naming the PROJECT is handled one level up, by the+ * pane's `forceVisible` — see ProjectSettingsSection.+ *+ * Each family field yields ONE entry covering both of its rows (shared + "this machine"): the two+ * are the same setting, and hiding the local override while its shared twin shows would read as+ * the override having been lost.+ */+function fieldEntry(family: ProjectSettingsFamily, f: FieldConfig): SettingsSearchEntry {+ return {+ title: f.label,+ description: f.description,+ keywords: [family, FAMILY_CONFIG[family].title, f.key, 'project', 'this machine', 'override']+ }+}++function ignoreSharedEntry(family: ProjectSettingsFamily): SettingsSearchEntry {+ return {+ title: `Ignore shared ${FAMILY_CONFIG[family].title.toLowerCase()} settings`,+ keywords: [family, 'ignore', 'shared', 'override', 'this machine']+ }+}++/** Every family row's search entry, for the pane's `searchEntries`. */+export const FAMILY_SEARCH_ENTRIES: SettingsSearchEntry[] = FAMILIES.flatMap((family) => [+ ...FAMILY_CONFIG[family].fields.map((f) => fieldEntry(family, f)),+ ignoreSharedEntry(family)+])+/** Text a non-env, non-list field shows in its box: the raw string, or '' when unset. */function textOf(kind: FieldKind, raw: unknown): string {if (kind === 'list') return formatListLines(raw as string[] | undefined)@@ -337,10 +369,18 @@ function FamilySection({saveLocal: (update: ProjectLocalSettings | undefined | ((current: ProjectLocalSettings | undefined) => ProjectLocalSettings | undefined)) => Promise<boolean>-}): React.JSX.Element {+}): React.JSX.Element | null {const config = FAMILY_CONFIG[family]const sharedDisabled = conflict || !readyconst localDisabled = !ready+ // Row-level search filtering. Done here rather than with `SearchableRow` wrappers because every+ // field renders TWICE (shared + "this machine") from the same list — filtering the list keeps+ // the two copies in step by construction. An entirely unmatched family drops out, heading and+ // "This machine" disclosure included, so the search never leaves an empty shell behind.+ const query = useSettingsSearch()+ const fields = config.fields.filter((f) => matchesQuery(query, fieldEntry(family, f)))+ const showIgnoreShared = matchesQuery(query, ignoreSharedEntry(family))+ if (fields.length === 0 && !showIgnoreShared) return null// Guarded here too, not just via the `disabled` attribute below: a disabled control blocks real// user interaction, but nothing stops a caller (or a test) from dispatching events on it@@ -456,22 +496,24 @@ function FamilySection({return (<div className="space-y-3 border-t border-border pt-4"><h3 className="text-[13px] font-semibold text-text">{config.title}</h3>- <div className="space-y-2.5">{config.fields.map(renderShared)}</div>+ <div className="space-y-2.5">{fields.map(renderShared)}</div><details><summary className="cursor-pointer text-[13px] text-muted">This machine</summary><div className="mt-3 space-y-2.5"><p className="text-[12px] leading-relaxed text-muted">Overrides that apply only on this machine. Never written to the shared file.</p>- {config.fields.map(renderLocal)}- <SwitchField- label={`Ignore shared ${config.title.toLowerCase()} settings`}- description="Never use the git-shared values for this family on this machine, even where this machine sets none of its own."- ariaLabel={`Ignore shared ${family} settings on this machine`}- checked={ignoreShared}- disabled={localDisabled}- onCommit={commitIgnoreShared}- />+ {fields.map(renderLocal)}+ {showIgnoreShared && (+ <SwitchField+ label={`Ignore shared ${config.title.toLowerCase()} settings`}+ description="Never use the git-shared values for this family on this machine, even where this machine sets none of its own."+ ariaLabel={`Ignore shared ${family} settings on this machine`}+ checked={ignoreShared}+ disabled={localDisabled}+ onCommit={commitIgnoreShared}+ />+ )}</div></details></div>diff --git a/src/renderer/components/settings/SettingsPage.tsx b/src/renderer/components/settings/SettingsPage.tsxindex 6ad216208..aef8ea6df 100644--- a/src/renderer/components/settings/SettingsPage.tsx+++ b/src/renderer/components/settings/SettingsPage.tsx@@ -1,11 +1,12 @@-import { useEffect, useMemo, useState } from 'react'+import { useEffect, useMemo } from 'react'import { createPortal } from 'react-dom'import { useEntitlement } from '../../state/entitlement'import { useProjects } from '../../state/projects'import { SettingsSearchContext } from './context'import { SettingsSidebar } from './SettingsSidebar'-import { FIRST_SECTION_ID, projectsSettingsGroup, type SettingsSectionId } from './nav'+import { projectsSettingsGroup, type SettingsSectionId } from './nav'import { projectSectionId } from './project-settings-targets'+import { useSettingsTarget } from './useSettingsTarget'import { ProjectSettingsSection } from './sections/ProjectSettingsSection'import { TerminalSection } from './sections/TerminalSection'import { ShellSection } from './sections/ShellSection'@@ -36,15 +37,20 @@ const isMac = /Mac/i.test(navigator.platform || navigator.userAgent)export function SettingsPage({onClose,- initialSection+ initialSection,+ retargetNonce}: {onClose: () => void/** Section to open on; lets callers deep-link (e.g. "Add SSH server…" → the SSH section). */initialSection?: SettingsSectionId+ /** Bumped by a caller that deep-links to a section, so a repeat of the SAME `initialSection`+ * still re-targets (and clears the search box). Plain opens — the gear, ⌘, , the native menu —+ * leave it alone: they must not throw away a query or a section the user chose in the dialog. */+ retargetNonce?: number}): React.JSX.Element {const hydrate = useEntitlement((s) => s.hydrate)- const [active, setActive] = useState<SettingsSectionId>(initialSection ?? FIRST_SECTION_ID)- const [query, setQuery] = useState('')+ // Which section is shown and what is typed in the search box, plus the deep-link retarget rule.+ const { active, setActive, query, setQuery } = useSettingsTarget(initialSection, retargetNonce)// ONE list feeds both the nav rows and the panes below, so a "Projects" row can never point at a// section that is not rendered (or vice versa). Memoized: `projects.filter(...)` inside a zustand@@ -62,11 +68,6 @@ export function SettingsPage({void hydrate()}, [hydrate])- // Re-target when a caller opens settings to a specific section.- useEffect(() => {- if (initialSection) setActive(initialSection)- }, [initialSection])-useEffect(() => {const onKey = (e: KeyboardEvent) => {if (e.key === 'Escape') onClose()diff --git a/src/renderer/components/settings/SettingsSection.test.tsx b/src/renderer/components/settings/SettingsSection.test.tsxnew file mode 100644index 000000000..5297cd176--- /dev/null+++ b/src/renderer/components/settings/SettingsSection.test.tsx@@ -0,0 +1,92 @@+// @vitest-environment jsdom+import { act } from 'react'+import { createRoot, type Root } from 'react-dom/client'+import { afterEach, beforeEach, describe, expect, it } from 'vitest'+import { SettingsSearchContext } from './context'+import { SearchableRow } from './SearchableRow'+import { SettingsSection, sectionVisible } from './SettingsSection'+import type { SettingsSearchEntry } from './search'++;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true++const ENTRIES: SettingsSearchEntry[] = [{ title: 'Default shell', keywords: ['bash'] }]++describe('sectionVisible', () => {+ it('shows an active section and hides an inactive one when there is no query', () => {+ expect(sectionVisible('', true, ENTRIES)).toBe(true)+ expect(sectionVisible(' ', true, ENTRIES)).toBe(true)+ expect(sectionVisible('', false, ENTRIES)).toBe(false)+ })++ it('ignores forceVisible when there is no query', () => {+ // `matchesQuery` answers true for an EMPTY query, so every caller computing forceVisible from+ // it hands us `true` while the search box is empty. If that forced the pane open, opening+ // settings would render every project's pane at once (and, for SSH projects, read every one).+ expect(sectionVisible('', false, ENTRIES, true)).toBe(false)+ })++ it('shows a section whose entries match the query and hides one whose entries do not', () => {+ expect(sectionVisible('bash', false, ENTRIES)).toBe(true)+ expect(sectionVisible('zzz', true, ENTRIES)).toBe(false)+ })++ it('shows a section with no search entries at all for any query (legacy sections)', () => {+ expect(sectionVisible('zzz', false, undefined)).toBe(true)+ })++ it('shows an otherwise non-matching section when forceVisible is set under a query', () => {+ expect(sectionVisible('zzz', false, ENTRIES, true)).toBe(true)+ })+})++describe('SettingsSection', () => {+ let root: Root+ let host: HTMLElement++ const mount = async (node: React.JSX.Element, query: string): Promise<void> => {+ root = createRoot(host)+ await act(async () => {+ root.render(<SettingsSearchContext.Provider value={query}>{node}</SettingsSearchContext.Provider>)+ })+ }++ const section = (forceVisible?: boolean): React.JSX.Element => (+ <SettingsSection id="demo" title="Demo" isActive={false} searchEntries={ENTRIES} forceVisible={forceVisible}>+ <SearchableRow title="Default shell" keywords={['bash']}>+ <p>shell row</p>+ </SearchableRow>+ <SearchableRow title="Something else" keywords={['other']}>+ <p>other row</p>+ </SearchableRow>+ </SettingsSection>+ )++ beforeEach(() => {+ host = document.createElement('div')+ document.body.appendChild(host)+ })++ afterEach(() => {+ act(() => root.unmount())+ host.remove()+ })++ it('filters rows to the matching one on an ordinary query', async () => {+ await mount(section(), 'bash')+ expect(host.textContent).toContain('shell row')+ expect(host.textContent).not.toContain('other row')+ })++ it('renders the WHOLE section (rows unfiltered) when forceVisible is set', async () => {+ // forceVisible means "this query named the section itself" — navigation, not filtering, so+ // its rows must not be individually filtered by a query that matches none of them.+ await mount(section(true), 'zzz')+ expect(host.textContent).toContain('shell row')+ expect(host.textContent).toContain('other row')+ })++ it('renders nothing when neither active, matched, nor forced', async () => {+ await mount(section(false), 'zzz')+ expect(host.textContent).toBe('')+ })+})diff --git a/src/renderer/components/settings/SettingsSection.tsx b/src/renderer/components/settings/SettingsSection.tsxindex 355c077cf..24c411d68 100644--- a/src/renderer/components/settings/SettingsSection.tsx+++ b/src/renderer/components/settings/SettingsSection.tsx@@ -1,7 +1,29 @@import type React from 'react'-import { useSettingsSearch } from './context'+import { SettingsSearchContext, useSettingsSearch } from './context'import { matchesQuery, type SettingsSearchEntry } from './search'+/**+ * THE section-visibility predicate. Every gate in the settings dialog calls this one function:+ * `SettingsSection` itself, and `ProjectSettingsSection`'s outer gate (which must decide the same+ * thing one level earlier, so an invisible pane never mounts its settings-reading hook — an SSH+ * read is a network round-trip). Two hand-written copies of this rule drifting apart shows up as a+ * nav row pointing at a blank pane, so they share the implementation instead.+ *+ * `forceVisible` is honored ONLY under a non-empty query: callers compute it with `matchesQuery`,+ * which answers `true` for an empty query, so treating it as authoritative while the search box is+ * empty would render (and read) every project's pane the moment settings opens.+ */+export function sectionVisible(+ query: string,+ isActive: boolean,+ searchEntries: SettingsSearchEntry[] | undefined,+ forceVisible?: boolean+): boolean {+ if (query.trim() === '') return isActive+ if (forceVisible) return true+ return !searchEntries || searchEntries.some((e) => matchesQuery(query, e))+}+/** Section shell: header + card body. Renders only when it is the active section* (no query) or when at least one of its searchEntries matches (query present). */export function SettingsSection({@@ -10,6 +32,7 @@ export function SettingsSection({description,isActive,searchEntries,+ forceVisible,children}: {id: string@@ -17,18 +40,18 @@ export function SettingsSection({description?: stringisActive: booleansearchEntries?: SettingsSearchEntry[]+ /** "This query named the SECTION, not a field in it" — set by a project pane when the query+ * matches the project's own name. The section then renders whole: its rows are shown+ * unfiltered (see the cleared search context below), because naming a section is navigation,+ * not filtering, and a name query matches none of the individual rows. */+ forceVisible?: booleanchildren: React.ReactNode}): React.JSX.Element | null {const query = useSettingsSearch()- const hasQuery = query.trim() !== ''- if (hasQuery) {- const anyMatch = !searchEntries || searchEntries.some((e) => matchesQuery(query, e))- if (!anyMatch) {- return null- }- } else if (!isActive) {- return null- }+ if (!sectionVisible(query, isActive, searchEntries, forceVisible)) return null+ // Children see an EMPTY query when this section was forced open, so every `SearchableRow` (and+ // every other query-reading descendant) renders. Identical to `query` otherwise.+ const childQuery = forceVisible ? '' : queryreturn (<section id={id} data-settings-section={id} className="space-y-6"><div className="border-b border-border pb-5">@@ -38,7 +61,7 @@ export function SettingsSection({) : null}</div><div className="divide-y divide-border/60 rounded-2xl border border-border bg-white/[0.02] px-6 shadow-sm [&>*]:py-5">- {children}+ <SettingsSearchContext.Provider value={childQuery}>{children}</SettingsSearchContext.Provider></div></section>)diff --git a/src/renderer/components/settings/sections/ProjectSettingsSection.test.tsx b/src/renderer/components/settings/sections/ProjectSettingsSection.test.tsxindex d72ebf718..53be4518a 100644--- a/src/renderer/components/settings/sections/ProjectSettingsSection.test.tsx+++ b/src/renderer/components/settings/sections/ProjectSettingsSection.test.tsx@@ -320,6 +320,67 @@ describe('ProjectSettingsSection', () => {await blur(env)expect(writeShared).toHaveBeenCalledWith('p1', { agents: { env: { A: '1', B: '2' } } })})++ // --- Task 5: search integration ------------------------------------------------------------++ const pane = (): HTMLElement | null => host.querySelector('[data-settings-section="project-p1"]')++ it('renders the WHOLE pane, rows and families included, when the query is the project name', async () => {+ // Searching a project by NAME is navigation: it names the pane, not a field inside it, so+ // every row renders instead of the pane collapsing to the (zero) rows that match "Alpha".+ await mountSection(project(), { isActive: false, query: 'Alpha' })+ expect(pane()).not.toBeNull()+ expect(nameInput()).not.toBeNull()+ expect(host.querySelector('#project-permission-mode-p1')).not.toBeNull()+ expect(host.querySelector('#project-terminal-shell-p1')).not.toBeNull()+ expect(host.querySelector('#project-setup-setupScript-p1')).not.toBeNull()+ expect(host.querySelector('#project-worktree-basePath-local-p1')).not.toBeNull()+ })++ it('filters to the matching identity row on a field-term query', async () => {+ await mountSection(project(), { isActive: false, query: 'approval' })+ expect(pane()).not.toBeNull()+ expect(host.querySelector('#project-permission-mode-p1')).not.toBeNull()+ expect(host.querySelector('#project-name-p1')).toBeNull()+ expect(host.querySelector('#project-terminal-shell-p1')).toBeNull()+ })++ it('filters to the matching family on a family-term query', async () => {+ await mountSection(project(), { isActive: false, query: 'worktree' })+ expect(pane()).not.toBeNull()+ expect(host.querySelector('#project-worktree-basePath-p1')).not.toBeNull()+ expect(host.querySelector('#project-terminal-shell-p1')).toBeNull()+ expect(host.querySelector('#project-name-p1')).toBeNull()+ })++ it('renders nothing (and reads nothing) for a query matching neither the name nor any row', async () => {+ await mountSection(project(), { isActive: false, query: 'zzzznomatch' })+ expect(host.textContent).toBe('')+ expect(read).not.toHaveBeenCalled()+ })++ it('keeps the two visibility gates in agreement: no pane is ever mounted without being shown', async () => {+ // The outer gate in ProjectSettingsSection duplicates SettingsSection's predicate (so an+ // invisible SSH pane never mounts the reading hook). If the two ever disagree, one of these+ // two symptoms appears: a read fired for a pane that renders nothing (outer open, inner shut),+ // or a nav row pointing at a pane that renders nothing.+ for (const [query, isActive] of [+ ['', true],+ ['', false],+ ['Alpha', false],+ ['approval', false],+ ['worktree', false],+ ['zzzznomatch', true]+ ] as [string, boolean][]) {+ read.mockClear()+ await mountSection(project(), { isActive, query })+ const shown = pane() !== null+ expect({ query, mounted: read.mock.calls.length > 0 }).toEqual({ query, mounted: shown })+ act(() => root.unmount())+ }+ // afterEach unmounts once more; give it a live root.+ await mountSection()+ })})describe('useProjectSettings', () => {diff --git a/src/renderer/components/settings/sections/ProjectSettingsSection.tsx b/src/renderer/components/settings/sections/ProjectSettingsSection.tsxindex 9380652bd..50a140ab1 100644--- a/src/renderer/components/settings/sections/ProjectSettingsSection.tsx+++ b/src/renderer/components/settings/sections/ProjectSettingsSection.tsx@@ -19,9 +19,9 @@ import {systemAccountDisplay} from '../../../state/workspace'import { FieldRow } from '../FieldRow'-import { ProjectFamilyEditors } from '../ProjectSettingsFamilies'+import { FAMILY_SEARCH_ENTRIES, ProjectFamilyEditors } from '../ProjectSettingsFamilies'import { SearchableRow } from '../SearchableRow'-import { SettingsSection } from '../SettingsSection'+import { SettingsSection, sectionVisible } from '../SettingsSection'import { useSettingsSearch } from '../context'import { projectSectionId } from '../project-settings-targets'import { matchesQuery, type SettingsSearchEntry } from '../search'@@ -41,23 +41,26 @@ function persistIdentityEdit(): void {markWorkspaceDirty()}-function rowsFor(name: string): Record<string, SettingsSearchEntry> {- // The project's own name rides every row's keywords: searching a project by name has to surface- // its controls, not just the section header.- return {- name: { title: 'Project name', keywords: ['rename', 'project', 'title', name] },- folder: { title: 'Folder', keywords: ['cwd', 'path', 'directory', 'ssh', 'server', name] },- color: { title: 'Color', keywords: ['accent', 'swatch', 'tab', 'monogram', name] },- permission: {- title: 'Default permission mode',- keywords: ['claude', 'plan', 'accept edits', 'bypass', 'approval', name]- },- account: {- title: 'Default Claude account',- keywords: ['account', 'login', 'claude', 'system', name]- }+/**+ * Static search metadata for the identity/defaults rows (the ShellSection pattern). Deliberately+ * WITHOUT the project's name: a name query is handled by `forceVisible` below, which opens the+ * whole pane rather than filtering it down to whichever rows happened to mention the name.+ */+const ROWS = {+ name: { title: 'Project name', keywords: ['rename', 'project', 'title'] },+ folder: { title: 'Folder', keywords: ['cwd', 'path', 'directory', 'ssh', 'server'] },+ color: { title: 'Color', keywords: ['accent', 'swatch', 'tab', 'monogram'] },+ permission: {+ title: 'Default permission mode',+ keywords: ['claude', 'plan', 'accept edits', 'bypass', 'approval']+ },+ account: {+ title: 'Default Claude account',+ keywords: ['account', 'login', 'claude', 'system']}-}+} satisfies Record<string, SettingsSearchEntry>++const IDENTITY_ENTRIES: SettingsSearchEntry[] = Object.values(ROWS)/** Where this project's terminals run: a local folder, or `user@host:/remote/path` for SSH. */function projectTarget(project: Project): string {@@ -82,31 +85,51 @@ export function ProjectSettingsSection({}): React.JSX.Element | null {const project = useProjects((s) => s.projects.find((p) => p.id === projectId))const query = useSettingsSearch()- const rows = useMemo(() => rowsFor(project?.name ?? ''), [project?.name])- const entries = useMemo(() => Object.values(rows), [rows])+ const name = project?.name ?? ''+ // The pane's own name is a search entry in its own right (so a name query reaches the gate at+ // all) AND the trigger for `forceVisible` (so the pane then renders whole).+ const entries = useMemo(+ () => [...IDENTITY_ENTRIES, ...FAMILY_SEARCH_ENTRIES, { title: name, keywords: [name] }],+ [name]+ )+ const forceVisible = matchesQuery(query, { title: name })if (!project) return null- const visible = query.trim() !== '' ? entries.some((e) => matchesQuery(query, e)) : isActive- if (!visible) return null+ // Same predicate `SettingsSection` uses, evaluated one level earlier — see `sectionVisible`.+ if (!sectionVisible(query, isActive, entries, forceVisible)) return null// A relay tab is a live connection to ANOTHER machine's project, and an unavailable project's// files cannot be read at all. Both get an explanation and zero editors: `projectSettings.*`// here would read and write THIS machine's store, so an editor would silently edit the wrong// project (or nothing).if (project.remote || project.unavailable) {- return <ExplanatoryProjectSection project={project} isActive={isActive} entries={entries} />+ return (+ <ExplanatoryProjectSection+ project={project}+ isActive={isActive}+ entries={entries}+ forceVisible={forceVisible}+ />+ )}return (- <EditableProjectSection project={project} isActive={isActive} entries={entries} rows={rows} />+ <EditableProjectSection+ project={project}+ isActive={isActive}+ entries={entries}+ forceVisible={forceVisible}+ />)}function ExplanatoryProjectSection({project,isActive,- entries+ entries,+ forceVisible}: {project: ProjectisActive: booleanentries: SettingsSearchEntry[]+ forceVisible: boolean}): React.JSX.Element {return (<SettingsSection@@ -114,6 +137,7 @@ function ExplanatoryProjectSection({title={project.name}isActive={isActive}searchEntries={entries}+ forceVisible={forceVisible}><p className="text-[13px] leading-relaxed text-muted">{project.remote@@ -128,12 +152,12 @@ function EditableProjectSection({project,isActive,entries,- rows+ forceVisible}: {project: ProjectisActive: booleanentries: SettingsSearchEntry[]- rows: Record<string, SettingsSearchEntry>+ forceVisible: boolean}): React.JSX.Element {const settings = useProjectSettings(project.id)const claudeAccounts = useSettings((s) => s.settings.claudeAccounts)@@ -171,6 +195,7 @@ function EditableProjectSection({description={`Settings for this project only. Name, color and defaults live in ${project.ssh ? 'the project file on the server' : '.nodeterm/project.json'}, which is shared with anyone who has the repo.`}isActive={isActive}searchEntries={entries}+ forceVisible={forceVisible}>{conflict ? (<div@@ -184,7 +209,7 @@ function EditableProjectSection({file it is about is being ignored, even before Task 4's editors exist. */}</div>) : null}- <SearchableRow {...rows.name}>+ <SearchableRow {...ROWS.name}><FieldRowlabel="Project name"description="Shown on the tab and in the project switcher."@@ -205,7 +230,7 @@ function EditableProjectSection({}/></SearchableRow>- <SearchableRow {...rows.folder}>+ <SearchableRow {...ROWS.folder}><FieldRowlabel={project.ssh ? 'Server folder' : 'Folder'}description="Where this project's terminals start. Change it from the project tab's menu."@@ -216,7 +241,7 @@ function EditableProjectSection({}/></SearchableRow>- <SearchableRow {...rows.color}>+ <SearchableRow {...ROWS.color}><FieldRowlabel="Color"description="Accent for this project's tab and monogram."@@ -244,7 +269,7 @@ function EditableProjectSection({}/></SearchableRow>- <SearchableRow {...rows.permission}>+ <SearchableRow {...ROWS.permission}><FieldRowlabel="Default permission mode"description="Start-up permission mode for new Claude terminal sessions in this project. Saved in the shared project file, so it travels to everyone who clones the repo."@@ -275,7 +300,7 @@ function EditableProjectSection({}/></SearchableRow>- <SearchableRow {...rows.account}>+ <SearchableRow {...ROWS.account}><FieldRowlabel="Default Claude account"description="Account new Claude and chat nodes in this project use."diff --git a/src/renderer/components/settings/useSettingsTarget.test.tsx b/src/renderer/components/settings/useSettingsTarget.test.tsxnew file mode 100644index 000000000..32de39259--- /dev/null+++ b/src/renderer/components/settings/useSettingsTarget.test.tsx@@ -0,0 +1,91 @@+// @vitest-environment jsdom+import { act } from 'react'+import { createRoot, type Root } from 'react-dom/client'+import { afterEach, beforeEach, describe, expect, it } from 'vitest'+import { FIRST_SECTION_ID, type SettingsSectionId } from './nav'+import { useSettingsTarget, type SettingsTarget } from './useSettingsTarget'++;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true++describe('useSettingsTarget', () => {+ let root: Root+ let host: HTMLElement+ let target: SettingsTarget++ function Probe({+ initialSection,+ retargetNonce+ }: {+ initialSection?: SettingsSectionId+ retargetNonce?: number+ }): React.JSX.Element {+ target = useSettingsTarget(initialSection, retargetNonce)+ return <div>{target.active}</div>+ }++ const render = async (props: {+ initialSection?: SettingsSectionId+ retargetNonce?: number+ }): Promise<void> => {+ await act(async () => {+ root.render(<Probe {...props} />)+ })+ }++ beforeEach(() => {+ host = document.createElement('div')+ document.body.appendChild(host)+ root = createRoot(host)+ })++ afterEach(() => {+ act(() => root.unmount())+ host.remove()+ })++ it('opens on the first section when no caller asked for one', async () => {+ await render({})+ expect(target.active).toBe(FIRST_SECTION_ID)+ expect(target.query).toBe('')+ })++ it('opens on the section a deep link asked for', async () => {+ await render({ initialSection: 'project-p1' as SettingsSectionId, retargetNonce: 1 })+ expect(target.active).toBe('project-p1')+ })++ it('re-targets AND clears a stale query when the nonce is bumped for the SAME section', async () => {+ await render({ initialSection: 'project-p1' as SettingsSectionId, retargetNonce: 1 })+ await act(async () => {+ target.setActive('ssh')+ target.setQuery('zzzznomatch')+ })+ expect(target.active).toBe('ssh')+ // Deep-linked to the same project again: only the nonce changes.+ await render({ initialSection: 'project-p1' as SettingsSectionId, retargetNonce: 2 })+ expect(target.active).toBe('project-p1')+ // A filter left in the box would hide the pane the link just navigated to.+ expect(target.query).toBe('')+ })++ it('leaves the user\'s in-dialog section and query alone when nothing re-targets', async () => {+ await render({ initialSection: 'project-p1' as SettingsSectionId, retargetNonce: 1 })+ await act(async () => {+ target.setActive('ssh')+ target.setQuery('shell')+ })+ // A plain re-render (parent state changed elsewhere): same section, same nonce.+ await render({ initialSection: 'project-p1' as SettingsSectionId, retargetNonce: 1 })+ expect(target.active).toBe('ssh')+ expect(target.query).toBe('shell')+ })++ it('never clears the query for a plain open, which passes no section at all', async () => {+ await render({})+ await act(async () => {+ target.setQuery('shell')+ })+ await render({ retargetNonce: undefined })+ expect(target.query).toBe('shell')+ })+})diff --git a/src/renderer/components/settings/useSettingsTarget.ts b/src/renderer/components/settings/useSettingsTarget.tsnew file mode 100644index 000000000..552a2ee42--- /dev/null+++ b/src/renderer/components/settings/useSettingsTarget.ts@@ -0,0 +1,44 @@+import { useEffect, useState } from 'react'+import { FIRST_SECTION_ID, type SettingsSectionId } from './nav'++export interface SettingsTarget {+ /** Section whose pane is shown when the search box is empty. */+ active: SettingsSectionId+ setActive: (id: SettingsSectionId) => void+ /** Current search query. Empty = no filtering. */+ query: string+ setQuery: (q: string) => void+}++/**+ * What the settings dialog is currently pointed at, and how a caller re-points it.+ *+ * Its own hook (rather than two `useState`s inline in SettingsPage) because the retarget rule is+ * the load-bearing half of the deep-link feature and SettingsPage itself is untestable in+ * isolation — rendering it mounts ~25 section modules, every one of which reaches for the preload+ * API on mount.+ *+ * The rule:+ * - A deep link (`initialSection` + a BUMPED `retargetNonce`) selects that section AND clears the+ * query. Without the clear, a filter still sitting in the search box would hide the very pane+ * the link just navigated to — the nav row would highlight over an empty page.+ * - The nonce is what makes a REPEAT of the same section re-target: `initialSection` alone would+ * not change, so the effect would not re-run.+ * - Plain opens (the gear, ⌘, , the native menu) pass no section and never bump the nonce, so a+ * query or a section the user chose inside the dialog survives.+ */+export function useSettingsTarget(+ initialSection: SettingsSectionId | undefined,+ retargetNonce: number | undefined+): SettingsTarget {+ const [active, setActive] = useState<SettingsSectionId>(initialSection ?? FIRST_SECTION_ID)+ const [query, setQuery] = useState('')++ useEffect(() => {+ if (!initialSection) return+ setActive(initialSection)+ setQuery('')+ }, [initialSection, retargetNonce])++ return { active, setActive, query, setQuery }+}