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(project-settings): guard loading-window commits + updater-based local saves
enesf696863b9613
diff --git a/src/renderer/components/settings/ProjectSettingsFamilies.tsx b/src/renderer/components/settings/ProjectSettingsFamilies.tsxindex 61f52770b..eda9bf6f5 100644--- a/src/renderer/components/settings/ProjectSettingsFamilies.tsx+++ b/src/renderer/components/settings/ProjectSettingsFamilies.tsx@@ -316,7 +316,7 @@ function FamilySection({ignoreShared,resolvedFamily,conflict,- fullLocal,+ ready,saveShared,saveLocal}: {@@ -327,20 +327,36 @@ function FamilySection({ignoreShared: booleanresolvedFamily: Record<string, { source: 'local' | 'shared' } | undefined>conflict: boolean- fullLocal: ProjectLocalSettings | undefined+ /** False until `snapshot` is an actual object (not `'loading'`, not `null`). Gates EVERY editor+ * in this family, shared and local alike: before the first read answers (or after a failed+ * one), there is no reliable doc to merge an edit into, and for an SSH project that window is a+ * network round-trip, not a render tick — a blur landing in it would write a doc built from+ * `{}`/`undefined`, silently deleting every other family already on disk. */+ ready: booleansaveShared: (doc: ProjectSettingsDoc) => Promise<boolean>- saveLocal: (local: ProjectLocalSettings | undefined) => Promise<boolean>+ saveLocal: (+ update: ProjectLocalSettings | undefined | ((current: ProjectLocalSettings | undefined) => ProjectLocalSettings | undefined)+ ) => Promise<boolean>}): React.JSX.Element {const config = FAMILY_CONFIG[family]+ const sharedDisabled = conflict || !ready+ const localDisabled = !ready+ // 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+ // directly, and the merge-base hazard this guards against is a data-corruption risk, not a UX+ // nicety — it must hold even if the DOM attribute is bypassed.const commitShared = (key: string, value: unknown): void => {+ if (sharedDisabled) returnvoid saveShared({ [family]: { [key]: value } } as ProjectSettingsDoc)}const commitLocal = (key: string, value: unknown): void => {- void saveLocal(nextLocalField(fullLocal, family, key, value))+ if (localDisabled) return+ void saveLocal((current) => nextLocalField(current, family, key, value))}const commitIgnoreShared = (on: boolean): void => {- void saveLocal(nextLocalIgnoreShared(fullLocal, family, on))+ if (localDisabled) return+ void saveLocal((current) => nextLocalIgnoreShared(current, family, on))}const renderShared = (f: FieldConfig): React.JSX.Element => {@@ -356,7 +372,7 @@ function FamilySection({note={overrideNote}ariaLabel={f.label}checked={sharedFamily?.[f.key] === true}- disabled={conflict}+ disabled={sharedDisabled}onCommit={(on) => commitShared(f.key, on ? true : undefined)}/>)@@ -368,7 +384,7 @@ function FamilySection({id={id}label={f.label}description={f.description}- disabled={conflict}+ disabled={sharedDisabled}text={formatEnvLines(sharedFamily?.[f.key] as Record<string, string> | undefined)}overrideNote={overrideNote}onCommitValue={(v) => commitShared(f.key, v)}@@ -383,7 +399,7 @@ function FamilySection({description={f.description}multiline={f.kind === 'textarea' || f.kind === 'list'}note={overrideNote}- disabled={conflict}+ disabled={sharedDisabled}text={textOf(f.kind, sharedFamily?.[f.key])}onCommit={(text) => commitShared(f.key, valueOf(f.kind, text))}/>@@ -403,6 +419,7 @@ function FamilySection({note={activeNote}ariaLabel={`${f.label} (this machine)`}checked={localFamily?.[f.key] === true}+ disabled={localDisabled}onCommit={(on) => commitLocal(f.key, on ? true : undefined)}/>)@@ -414,6 +431,7 @@ function FamilySection({id={id}label={f.label}description={f.description}+ disabled={localDisabled}text={formatEnvLines(localFamily?.[f.key] as Record<string, string> | undefined)}overrideNote={activeNote}onCommitValue={(v) => commitLocal(f.key, v)}@@ -428,6 +446,7 @@ function FamilySection({description={f.description}multiline={f.kind === 'textarea' || f.kind === 'list'}note={activeNote}+ disabled={localDisabled}text={textOf(f.kind, localFamily?.[f.key])}onCommit={(text) => commitLocal(f.key, valueOf(f.kind, text))}/>@@ -450,6 +469,7 @@ function FamilySection({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>@@ -471,8 +491,13 @@ export function ProjectFamilyEditors({resolved: ResolvedProjectSettingsconflict: booleansaveShared: (doc: ProjectSettingsDoc) => Promise<boolean>- saveLocal: (local: ProjectLocalSettings | undefined) => Promise<boolean>+ saveLocal: (+ update: ProjectLocalSettings | undefined | ((current: ProjectLocalSettings | undefined) => ProjectLocalSettings | undefined)+ ) => Promise<boolean>}): React.JSX.Element {+ // Loading and failed-read (`null`) both mean "no doc it is safe to merge an edit into" — see+ // `FamilySection`'s `ready` doc comment.+ const ready = snapshot !== 'loading' && snapshot !== nullconst shared: ProjectSettingsDoc = snapshot && snapshot !== 'loading' && snapshot.shared ? snapshot.shared : {}const local: ProjectLocalSettings | undefined = snapshot && snapshot !== 'loading' ? snapshot.local : undefinedreturn (@@ -487,7 +512,7 @@ export function ProjectFamilyEditors({ignoreShared={local?.ignoreShared?.[family] === true}resolvedFamily={resolved[family] as Record<string, { source: 'local' | 'shared' } | undefined>}conflict={conflict}- fullLocal={local}+ ready={ready}saveShared={saveShared}saveLocal={saveLocal}/>diff --git a/src/renderer/components/settings/sections/ProjectSettingsSection.test.tsx b/src/renderer/components/settings/sections/ProjectSettingsSection.test.tsxindex 9f165babb..d72ebf718 100644--- a/src/renderer/components/settings/sections/ProjectSettingsSection.test.tsx+++ b/src/renderer/components/settings/sections/ProjectSettingsSection.test.tsx@@ -257,6 +257,69 @@ describe('ProjectSettingsSection', () => {expect(localShell.disabled).toBe(false)expect(toggle.disabled).toBe(false)})++ it('disables every family editor (shared, local, and ignoreShared) while the read is in flight, and a blur landing in that window produces no write', async () => {+ let release: (v: ProjectSettingsSnapshot) => void = () => {}+ read = vi.fn(() => new Promise<ProjectSettingsSnapshot>((r) => (release = r)))+ ;(window as unknown as { nodeTerminal: any }).nodeTerminal.projectSettings.read = read+ await mountSection()+ const sharedShell = host.querySelector<HTMLInputElement>('#project-terminal-shell-p1')!+ const localShell = host.querySelector<HTMLInputElement>('#project-terminal-shell-local-p1')!+ const toggle = host.querySelector<HTMLButtonElement>(+ '[aria-label="Ignore shared setup settings on this machine"]'+ )!+ expect(sharedShell.disabled).toBe(true)+ expect(localShell.disabled).toBe(true)+ expect(toggle.disabled).toBe(true)+ // Bypass the DOM `disabled` attribute the way a stray/synthetic event could — the guard that+ // matters is the one inside the commit handler, not just the attribute.+ await typeInto(localShell, '/bin/zsh')+ await blur(localShell)+ expect(updateLocal).not.toHaveBeenCalled()+ await act(async () => {+ release(EMPTY_SNAPSHOT)+ })+ expect(sharedShell.disabled).toBe(false)+ expect(localShell.disabled).toBe(false)+ expect(toggle.disabled).toBe(false)+ })++ it('preserves an existing local family when a different local field is committed', async () => {+ read = vi.fn(async () => ({ shared: null, local: { agents: { launchCmd: 'x' } } }) as ProjectSettingsSnapshot)+ ;(window as unknown as { nodeTerminal: any }).nodeTerminal.projectSettings.read = read+ await mountSection()+ const local = host.querySelector<HTMLInputElement>('#project-terminal-shell-local-p1')!+ await typeInto(local, '/bin/zsh')+ await blur(local)+ expect(updateLocal).toHaveBeenCalledWith('p1', {+ agents: { launchCmd: 'x' },+ terminal: { shell: '/bin/zsh' }+ })+ })++ it('merges a shared textarea blur into the whole shared doc, preserving other families', async () => {+ read = vi.fn(async () => ({+ shared: { version: 1, rev: 1, savedAt: 't', agents: { launchCmd: 'y' } },+ local: undefined+ }) as ProjectSettingsSnapshot)+ ;(window as unknown as { nodeTerminal: any }).nodeTerminal.projectSettings.read = read+ await mountSection()+ const setupScript = host.querySelector<HTMLTextAreaElement>('#project-setup-setupScript-p1')!+ await typeIntoTextarea(setupScript, 'echo hi')+ await blur(setupScript)+ expect(writeShared).toHaveBeenCalledWith('p1', {+ agents: { launchCmd: 'y' },+ setup: { setupScript: 'echo hi' }+ })+ })++ it('commits parsed KEY=VALUE pairs from the shared env textarea on blur', async () => {+ await mountSection()+ const env = host.querySelector<HTMLTextAreaElement>('#project-agents-env-p1')!+ await typeIntoTextarea(env, 'A=1\nB=2')+ await blur(env)+ expect(writeShared).toHaveBeenCalledWith('p1', { agents: { env: { A: '1', B: '2' } } })+ })})describe('useProjectSettings', () => {@@ -400,6 +463,36 @@ describe('useProjectSettings', () => {expect(read).toHaveBeenCalledTimes(2)})+ it('keeps a local save that is still being re-read as the merge base for the next local save', async () => {+ // Same hazard as the shared-doc race above, on the local overlay: local edit A (terminal)+ // saves; local edit B (worktree) arrives before A's re-read lands. Merging B into the pre-A+ // local doc would make B's whole-document write silently drop A's edit.+ const first: ProjectSettingsSnapshot = {+ shared: { version: 1, rev: 1, savedAt: 't', terminal: { shell: '/bin/bash' } },+ local: { agents: { launchCmd: 'x' } }+ }+ let gate: (v: ProjectSettingsSnapshot) => void = () => {}+ read.mockResolvedValueOnce(first).mockReturnValue(+ new Promise<ProjectSettingsSnapshot>((r) => (gate = r))+ )+ await mount()+ await act(async () => {+ await hook.saveLocal((current) => ({ ...current, terminal: { shell: '/bin/zsh' } }))+ })+ expect(hook.snapshot).toBe('loading') // the re-read is gated open+ await act(async () => {+ await hook.saveLocal((current) => ({ ...current, worktree: { basePath: '/tmp/wt' } }))+ })+ expect(updateLocal).toHaveBeenLastCalledWith('p1', {+ agents: { launchCmd: 'x' },+ terminal: { shell: '/bin/zsh' },+ worktree: { basePath: '/tmp/wt' }+ })+ await act(async () => {+ gate(first)+ })+ })+it('degrades a failed read to "nothing readable" instead of throwing', async () => {read.mockRejectedValue(new Error('boom'))await mount()diff --git a/src/renderer/components/settings/useProjectSettings.ts b/src/renderer/components/settings/useProjectSettings.tsindex 956a175c0..d897e0077 100644--- a/src/renderer/components/settings/useProjectSettings.ts+++ b/src/renderer/components/settings/useProjectSettings.ts@@ -32,8 +32,21 @@ export interface ProjectSettingsHook {* may have sanitized what it wrote, so what the panel shows afterwards is the FILE, not our hope.*/saveShared(doc: ProjectSettingsDoc): Promise<boolean>- /** This machine's overlay, written whole (`undefined` clears it). Re-reads on success. */- saveLocal(local: ProjectLocalSettings | undefined): Promise<boolean>+ /**+ * Commits an edit to THIS MACHINE's local overlay — a whole-document write, exactly like+ * `saveShared`. Takes either the next whole document directly, or an updater over the CURRENT+ * one (preferring a still-in-flight write's result over the last-read snapshot, via the same+ * `pendingLocalRef` guard `saveShared` uses for the shared doc) — so two local edits inside one+ * IPC round-trip do not drop the first. Prefer the updater form for anything that merges into+ * the existing doc; the plain-value form stays for a caller that already holds the whole next+ * document (e.g. clearing the overlay with `undefined`). Re-reads on success.+ */+ saveLocal(+ update:+ | ProjectLocalSettings+ | undefined+ | ((current: ProjectLocalSettings | undefined) => ProjectLocalSettings | undefined)+ ): Promise<boolean>reload(): void}@@ -92,6 +105,11 @@ export function useProjectSettings(projectId: string): ProjectSettingsHook {// re-read is asynchronous; the user's next blur is not going to wait for it. Tagged with the// project id so a pane switch can never merge one project's edit into another's file.const pendingRef = useRef<{ projectId: string; doc: ProjectSettingsDoc } | null>(null)+ // Same hazard, same fix, for the LOCAL overlay: `saveLocal` is also a whole-document write, so+ // two local edits in one round-trip need their own pending base independent of the shared one.+ const pendingLocalRef = useRef<{ projectId: string; local: ProjectLocalSettings | undefined } | null>(+ null+ )useEffect(() => {let alive = true@@ -104,7 +122,10 @@ export function useProjectSettings(projectId: string): ProjectSettingsHook {const seqAtStart = writeSeqRef.currentconst settle = (next: ProjectSettingsSnapshot | null): void => {if (!alive) return- if (writeSeqRef.current === seqAtStart) pendingRef.current = null+ if (writeSeqRef.current === seqAtStart) {+ pendingRef.current = null+ pendingLocalRef.current = null+ }setSnapshot(next)}void window.nodeTerminal.projectSettings.read(projectId).then(settle, () => settle(null))@@ -138,10 +159,24 @@ export function useProjectSettings(projectId: string): ProjectSettingsHook {)const saveLocal = useCallback(- async (local: ProjectLocalSettings | undefined): Promise<boolean> => {- const ok = await window.nodeTerminal.projectSettings.updateLocal(projectId, local)- if (ok) reload()- return ok+ async (+ update:+ | ProjectLocalSettings+ | undefined+ | ((current: ProjectLocalSettings | undefined) => ProjectLocalSettings | undefined)+ ): Promise<boolean> => {+ const pending = pendingLocalRef.current+ const snap = snapshotRef.current+ const current =+ pending?.projectId === projectId ? pending.local : snap && snap !== 'loading' ? snap.local : undefined+ const next = typeof update === 'function' ? update(current) : update+ const ok = await window.nodeTerminal.projectSettings.updateLocal(projectId, next)+ if (!ok) return false+ // Advance the merge base NOW, not when the re-read lands: the next blur may arrive first.+ writeSeqRef.current += 1+ pendingLocalRef.current = { projectId, local: next }+ reload()+ return true},[projectId, reload])