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
fix(settings): declare repository before the dispatch check reads it (#1090)
reviewcc3ce5f1130b
diff --git a/CLAUDE.md b/CLAUDE.mdindex 41a2ea385..5953d7c00 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -7725,7 +7725,16 @@ the Settings section and ShortcutsPanel start disagreeing about what a chord meashell, grid + snap, **default node size** (`defaultNodeWidth`/`defaultNodeHeight` — newterminal/agent nodes only, clamped in `terminalNodeSize()` in `state/workspace.ts`),pan-hover delay, double-click focus, accent, tmux on/scrollback, commit agent,- `seenShortcuts`.+ `seenShortcuts`. **Every section is MOUNTED whenever Settings is open** — an inactive one+ returns null from `SettingsSection`, but its hooks and the whole render body above that return+ still run. So a throw in a section the user never navigated to blanks the entire page: #1090+ (0.4.0) was `GitHubIssuesSection` calling `dispatchBindingFor` during render, a closure over a+ `const repository` declared ~140 lines lower (below the early returns) — a TDZ ReferenceError on+ every Settings open once dispatch was switched on for the active project. **tsc does not flag a+ closure that reads a later `const`**, only a direct read, so declare anything a render-time+ helper closes over ABOVE the helper. Each section is now wrapped in `SettingsSectionBoundary`,+ which contains a throw to that section (fallback shown only while it is the viewed one) — keep+ new sections inside one.- **Shortcuts** (`ShortcutsPanel.tsx`, ? / ⌘/): shown once on first launch (`seenShortcuts`).**Derived from the registry, never hand-listed** — see the Keybindings invariant below.- **Welcome** (`WelcomeScreen.tsx`): shown when no projects exist.diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 2aff2f74f..92bf3d360 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -1158,6 +1158,13 @@ Electron/Xvfb on Linux; macOS traffic lights and actual window movement still ne`npm test` must pass, and `npm run typecheck` is the fastest gate.+**The typecheck does not catch a closure reading a later `const`.** If a helper defined in a+component body reads a `const` declared further down and the helper is CALLED during render, it+throws a TDZ `ReferenceError` at runtime while `tsc` stays green (#1090 blanked all of Settings+this way). Declare what a render-time helper closes over above the helper, and give a new+Settings section a render test with its real-world state populated — every section renders on+each Settings open, visible or not, and each is wrapped in `SettingsSectionBoundary`.+Beyond that, one habit is worth more than any other here:**Mutation-test your guards.** Delete or invert the check you just added and confirm a test *fails*.diff --git a/src/renderer/components/settings/SettingsPage.tsx b/src/renderer/components/settings/SettingsPage.tsxindex 733a0d39d..fc6b7cf08 100644--- a/src/renderer/components/settings/SettingsPage.tsx+++ b/src/renderer/components/settings/SettingsPage.tsx@@ -7,6 +7,7 @@ import { SettingsSidebar } from './SettingsSidebar'import { projectsSettingsGroup, type SettingsSectionId } from './nav'import { projectSectionId } from './project-settings-targets'import { useSettingsTarget } from './useSettingsTarget'+import { SettingsSectionBoundary } from './SettingsSectionBoundary'import { ProjectSettingsSection } from './sections/ProjectSettingsSection'import { TerminalSection } from './sections/TerminalSection'import { ShellSection } from './sections/ShellSection'@@ -100,44 +101,100 @@ export function SettingsPage({<SettingsSearchContext.Provider value={query}><main className="min-w-0 flex-1 overflow-y-auto px-12 py-10"><div className="mx-auto max-w-[860px] space-y-10">- <TerminalSection isActive={active === 'terminal'} />- <ShellSection isActive={active === 'shell'} />- <BehaviorSection isActive={active === 'behavior'} />- <AppearanceSection isActive={active === 'appearance'} />- {isMac && <NotchSection isActive={active === 'notch'} />}- <PhoneSection isActive={active === 'phone'} />- <SpeechSection isActive={active === 'speech'} onNavigate={setActive} />- <ShortcutsSection isActive={active === 'shortcuts'} />- <AgentsSection isActive={active === 'agents'} />- <UsageSection isActive={active === 'usage'} />- <AccountsSection isActive={active === 'accounts'} />- <CustomAgentsSection isActive={active === 'custom-agents'} />- <ModelGatewaySection isActive={active === 'model-gateway'} />- <NotificationsSection isActive={active === 'notifications'} />- <CommitSection isActive={active === 'commit'} />- <TmuxSection isActive={active === 'tmux'} />- <GitHubIssuesSection isActive={active === 'github-issues'} />- <LicenseSection- isActive={active === 'license'}- onNavigate={(id) => {- setQuery('')- setActive(id)- }}- />- <PresenceIdentitySection isActive={active === 'presence'} />- <RemoteSection isActive={active === 'remote'} onClose={onClose} />- <TeamAccessSection isActive={active === 'team-access'} onClose={onClose} />- <LiveLinksSection isActive={active === 'live-links'} />- <SshSection isActive={active === 'ssh'} />- <UpdatesSection isActive={active === 'updates'} />- <PrivacySection isActive={active === 'privacy'} />- <DebugSection isActive={active === 'debug'} />+ <SettingsSectionBoundary title="Terminal" visible={active === 'terminal'}>+ <TerminalSection isActive={active === 'terminal'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Shell" visible={active === 'shell'}>+ <ShellSection isActive={active === 'shell'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Behavior" visible={active === 'behavior'}>+ <BehaviorSection isActive={active === 'behavior'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Appearance" visible={active === 'appearance'}>+ <AppearanceSection isActive={active === 'appearance'} />+ </SettingsSectionBoundary>+ {isMac && (+ <SettingsSectionBoundary title="Notch" visible={active === 'notch'}>+ <NotchSection isActive={active === 'notch'} />+ </SettingsSectionBoundary>+ )}+ <SettingsSectionBoundary title="Phone" visible={active === 'phone'}>+ <PhoneSection isActive={active === 'phone'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Speech" visible={active === 'speech'}>+ <SpeechSection isActive={active === 'speech'} onNavigate={setActive} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Keyboard Shortcuts" visible={active === 'shortcuts'}>+ <ShortcutsSection isActive={active === 'shortcuts'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Agents" visible={active === 'agents'}>+ <AgentsSection isActive={active === 'agents'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Usage" visible={active === 'usage'}>+ <UsageSection isActive={active === 'usage'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Accounts" visible={active === 'accounts'}>+ <AccountsSection isActive={active === 'accounts'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Custom agents" visible={active === 'custom-agents'}>+ <CustomAgentsSection isActive={active === 'custom-agents'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Model gateway" visible={active === 'model-gateway'}>+ <ModelGatewaySection isActive={active === 'model-gateway'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Notifications" visible={active === 'notifications'}>+ <NotificationsSection isActive={active === 'notifications'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Commit messages" visible={active === 'commit'}>+ <CommitSection isActive={active === 'commit'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Session protection" visible={active === 'tmux'}>+ <TmuxSection isActive={active === 'tmux'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="GitHub Issues" visible={active === 'github-issues'}>+ <GitHubIssuesSection isActive={active === 'github-issues'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="License" visible={active === 'license'}>+ <LicenseSection+ isActive={active === 'license'}+ onNavigate={(id) => {+ setQuery('')+ setActive(id)+ }}+ />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Your name" visible={active === 'presence'}>+ <PresenceIdentitySection isActive={active === 'presence'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Remote access" visible={active === 'remote'}>+ <RemoteSection isActive={active === 'remote'} onClose={onClose} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Team seats" visible={active === 'team-access'}>+ <TeamAccessSection isActive={active === 'team-access'} onClose={onClose} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Live links" visible={active === 'live-links'}>+ <LiveLinksSection isActive={active === 'live-links'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Remote (SSH)" visible={active === 'ssh'}>+ <SshSection isActive={active === 'ssh'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Updates" visible={active === 'updates'}>+ <UpdatesSection isActive={active === 'updates'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Privacy" visible={active === 'privacy'}>+ <PrivacySection isActive={active === 'privacy'} />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Debug" visible={active === 'debug'}>+ <DebugSection isActive={active === 'debug'} />+ </SettingsSectionBoundary>{openProjects.map((p) => (- <ProjectSettingsSection+ <SettingsSectionBoundarykey={p.id}- projectId={p.id}- isActive={active === projectSectionId(p.id)}- />+ title={p.name}+ visible={active === projectSectionId(p.id)}+ >+ <ProjectSettingsSection projectId={p.id} isActive={active === projectSectionId(p.id)} />+ </SettingsSectionBoundary>))}</div></main>diff --git a/src/renderer/components/settings/SettingsSectionBoundary.test.tsx b/src/renderer/components/settings/SettingsSectionBoundary.test.tsxnew file mode 100644index 000000000..b208a7ca6--- /dev/null+++ b/src/renderer/components/settings/SettingsSectionBoundary.test.tsx@@ -0,0 +1,50 @@+// @vitest-environment jsdom+import { act } from 'react'+import { createRoot } from 'react-dom/client'+import { afterEach, describe, expect, it, vi } from 'vitest'+import { SettingsSectionBoundary } from './SettingsSectionBoundary'++;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true++function Broken(): React.JSX.Element {+ throw new ReferenceError("Cannot access 'repository' before initialization")+}++describe('SettingsSectionBoundary (#1090)', () => {+ afterEach(() => vi.restoreAllMocks())++ const render = (visible: boolean): { host: HTMLElement; unmount: () => void } => {+ vi.spyOn(console, 'error').mockImplementation(() => {})+ const host = document.createElement('div')+ const root = createRoot(host)+ act(() => {+ root.render(+ <>+ <SettingsSectionBoundary title="GitHub Issues" visible={visible}>+ <Broken />+ </SettingsSectionBoundary>+ <SettingsSectionBoundary title="Terminal" visible={!visible}>+ <p>terminal settings</p>+ </SettingsSectionBoundary>+ </>+ )+ })+ return { host, unmount: () => act(() => root.unmount()) }+ }++ it('keeps the other sections rendered when one section throws', () => {+ const { host, unmount } = render(false)+ expect(host.textContent).toContain('terminal settings')+ // Not the section being viewed: its failure shows nowhere.+ expect(host.textContent).not.toContain('could not be displayed')+ unmount()+ })++ it('says the viewed section failed instead of rendering nothing', () => {+ const { host, unmount } = render(true)+ expect(host.textContent).toContain('GitHub Issues')+ expect(host.textContent).toContain('This section could not be displayed')+ expect(host.textContent).toContain("Cannot access 'repository' before initialization")+ unmount()+ })+})diff --git a/src/renderer/components/settings/SettingsSectionBoundary.tsx b/src/renderer/components/settings/SettingsSectionBoundary.tsxnew file mode 100644index 000000000..568866db3--- /dev/null+++ b/src/renderer/components/settings/SettingsSectionBoundary.tsx@@ -0,0 +1,43 @@+import { Component, type ReactNode } from 'react'++interface State {+ error: Error | null+}++/**+ * Error boundary for ONE settings section. Every section is mounted whenever Settings is open (an+ * inactive one renders null, but its hooks and render body still run), so a throw in any of them —+ * even one the user never navigated to — used to unmount the whole page and leave a blank window+ * (#1090: a TDZ ReferenceError in GitHubIssuesSection). The boundary contains it to that section:+ * the fallback shows only while the section is the one being viewed, so the rest of Settings stays+ * usable and the broken section says so instead of rendering nothing.+ */+export class SettingsSectionBoundary extends Component<+ { title: string; visible: boolean; children: ReactNode },+ State+> {+ state: State = { error: null }++ static getDerivedStateFromError(error: Error): State {+ return { error }+ }++ componentDidCatch(error: Error): void {+ console.error(`[settings] section "${this.props.title}" failed to render`, error)+ }++ render(): ReactNode {+ if (!this.state.error) return this.props.children+ if (!this.props.visible) return null+ return (+ <section className="space-y-3" role="alert">+ <h2 className="text-[28px] font-bold leading-tight tracking-tight text-text">{this.props.title}</h2>+ <p className="text-sm text-warn">+ This section could not be displayed. The rest of Settings still works; reopening Settings+ tries again.+ </p>+ <p className="text-[13px] text-muted">{this.state.error.message}</p>+ </section>+ )+ }+}diff --git a/src/renderer/components/settings/sections/GitHubIssuesSection.test.tsx b/src/renderer/components/settings/sections/GitHubIssuesSection.test.tsxindex a5991be56..1a9681e3e 100644--- a/src/renderer/components/settings/sections/GitHubIssuesSection.test.tsx+++ b/src/renderer/components/settings/sections/GitHubIssuesSection.test.tsx@@ -4,6 +4,9 @@ import { createRoot, type Root } from 'react-dom/client'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import type { GitHubAuthStatus, GitHubControlView } from '@shared/github-issues'import { useProjects } from '../../../state/projects'+import { useSettings } from '../../../state/settings'+import { DEFAULT_SETTINGS } from '@shared/types'+import { dispatchBinding } from '@shared/board-dispatch'import { registerWorkspaceDirty } from '../../../state/workspaceDirty'import { SettingsSearchContext } from '../context'import { GitHubIssuesSection, STATUS_AFTER_EDIT_MS } from './GitHubIssuesSection'@@ -113,11 +116,51 @@ describe('GitHubIssuesSection', () => {})afterEach(() => {+ useSettings.setState({ settings: { ...DEFAULT_SETTINGS } })act(() => root.unmount())host.remove()unregisterDirty()})+ // #1090: `dispatchStale` is computed during render and reads `repository` through+ // `dispatchBindingFor`. While that `const` was declared below the early returns, any render with a+ // dispatch entry for the active project threw a TDZ ReferenceError and blanked all of Settings.+ const withDispatch = (binding: string): void => {+ useSettings.setState({+ settings: {+ ...DEFAULT_SETTINGS,+ boardDispatch: {+ paused: false,+ projects: { p1: { columnId: 'todo', agentId: 'claude', maxConcurrent: 1, binding } }+ }+ }+ })+ }++ it('renders with dispatch switched on for the active project (#1090)', async () => {+ withDispatch(dispatchBinding('owner/repo', 'Todo', 'status:todo')!)+ stub(viewWith({}, true))+ await mount()+ expect(host.textContent).toContain('Dispatch agents')+ expect(host.textContent).not.toContain('Nothing dispatches until you confirm it again')+ })++ it('still flags a dispatch binding that no longer matches the column (#1090)', async () => {+ withDispatch(dispatchBinding('owner/repo', 'Renamed', 'status:todo')!)+ stub(viewWith({}, true))+ await mount()+ expect(host.textContent).toContain('Nothing dispatches until you confirm it again')+ })++ it('does not call a dispatch binding stale before the repository is known (#1090)', async () => {+ withDispatch(dispatchBinding('owner/repo', 'Todo', 'status:todo')!)+ status = vi.fn(() => new Promise<GitHubControlView>(() => {}))+ ;(window as unknown as { nodeTerminal: any }).nodeTerminal.githubControl.status = status+ await mount()+ expect(host.textContent).toContain('Dispatch agents')+ expect(host.textContent).not.toContain('Nothing dispatches until you confirm it again')+ })+it('says until when sync is held, and how much of the GitHub budget is left', async () => {stub({...viewWith({}, true),diff --git a/src/renderer/components/settings/sections/GitHubIssuesSection.tsx b/src/renderer/components/settings/sections/GitHubIssuesSection.tsxindex ee25ff655..06e678dbc 100644--- a/src/renderer/components/settings/sections/GitHubIssuesSection.tsx+++ b/src/renderer/components/settings/sections/GitHubIssuesSection.tsx@@ -180,6 +180,12 @@ export function GitHubIssuesSection({ isActive }: { isActive: boolean }): React.* for anyone. `patch: null` switches the project off, `undefined` leaves it as it is (the kill* switch alone). Every write prunes vanished projects. */const [dispatchNotice, setDispatchNotice] = useState('')+ // Declared HERE, above every reader, on purpose (#1090): `dispatchBindingFor` closes over it and+ // `dispatchStale` below calls that during render. A `const` declared further down (it used to sit+ // after the early returns) is in its temporal dead zone at that call, so the moment dispatch was+ // switched on for the active project every Settings open threw a ReferenceError and blanked the+ // whole page. TypeScript does not flag a closure that reads a later `const`.+ const repository = githubConfig?.repository ?? view?.project?.detectedRepository/** What the person consents to when they pick a column: the repository and the column's title* and GitHub label as they are NOW (@shared/board-dispatch `binding`). */const dispatchBindingFor = (columnId: string): string | undefined =>@@ -228,7 +234,10 @@ export function GitHubIssuesSection({ isActive }: { isActive: boolean }): React.: dispatchConfig?.agentId === 'codex'? codexAccounts.filter((a) => !a.host && !a.pending).map((a) => ({ id: a.id, label: a.label })): []- const dispatchStale = !!dispatchConfig && dispatchBindingFor(dispatchConfig.columnId) !== dispatchConfig.binding+ // Before the first status read the detected repository is simply not known yet; "it changed since+ // you switched this on" would be a confident wrong answer on every open, so wait for the read.+ const dispatchStale = !!dispatchConfig && (repository !== undefined || view !== null) &&+ dispatchBindingFor(dispatchConfig.columnId) !== dispatchConfig.binding/** `GitHubHostController.status(projectId)` MASKS the auth block for a project that is not* approved on this machine (`ghAuthenticated: false, activeProvider: null, tokenPresent: false`)@@ -363,7 +372,6 @@ export function GitHubIssuesSection({ isActive }: { isActive: boolean }): React.}const enabled = !!githubConfig- const repository = githubConfig?.repository ?? view?.project?.detectedRepositoryconst approved = enabled && !!view?.project?.approved// The repository approval lets the board READ; writes also need this machine to have approved the// column mapping now in the (git-shared) project file. Only an explicit false withholds it.