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(tui): a settings.json that exists but does not parse is never replaced
enes588c5c5c4984
diff --git a/src/core/agents/hooks/claude-tui.test.ts b/src/core/agents/hooks/claude-tui.test.tsindex deaa47d3e..5edc15a1d 100644--- a/src/core/agents/hooks/claude-tui.test.ts+++ b/src/core/agents/hooks/claude-tui.test.ts@@ -58,11 +58,14 @@ describe('ensureFullscreenTuiInFile (fail-open file wrapper)', () => {})})- it('tolerates a corrupt file (parses to {} then writes the key, like install-helper)', () => {+ it('NEVER touches a file that exists but does not parse (data loss beats a rendering default)', () => {+ // Unlike install-helper, which normalizes a corrupt file: if the hook merge bailed early,+ // this pass would be the FIRST writer here, and replacing the user's settings with {tui:...}+ // would silently destroy every real key they had.const p = path.join(dir, 'corrupt.json')writeFileSync(p, '{ not json', 'utf8')- expect(ensureFullscreenTuiInFile(p)).toBe(true)- expect(JSON.parse(readFileSync(p, 'utf8'))).toEqual({ tui: TUI_FULLSCREEN })+ expect(ensureFullscreenTuiInFile(p)).toBe(false)+ expect(readFileSync(p, 'utf8')).toBe('{ not json')})it('an empty file is treated as {} and gets the key', () => {diff --git a/src/core/agents/hooks/claude-tui.ts b/src/core/agents/hooks/claude-tui.tsindex 3eb988272..9424a0020 100644--- a/src/core/agents/hooks/claude-tui.ts+++ b/src/core/agents/hooks/claude-tui.ts@@ -32,16 +32,29 @@ export function ensureFullscreenTui(config: TuiSettings): { config: TuiSettings;/*** Fail-open file wrapper for the local surfaces (system `~/.claude` + managed account dirs). Reads- * `configPath` (a missing/empty/corrupt file → `{}`, matching install-helper), applies- * `ensureFullscreenTui`, and writes back ONLY if the key was added. Returns whether it wrote.- * A read or write error is swallowed + warned, never thrown.+ * `configPath`, applies `ensureFullscreenTui`, and writes back ONLY if the key was added. Returns+ * whether it wrote. A read or write error is swallowed + warned, never thrown.+ *+ * A file that EXISTS but does not parse is left completely alone — unlike install-helper, which+ * normalizes it. The hook merge usually runs first and normalizes a corrupt file, but when it bails+ * early (its managed-script write failed) this pass would be the FIRST writer, and "replace the+ * user's settings with {tui:...}" is data loss a cosmetic rendering default can never justify.+ * Only a genuinely missing/empty file is treated as `{}`.*/export function ensureFullscreenTuiInFile(configPath: string): boolean {let config: TuiSettings = {}+ let raw: string | null = nulltry {- config = JSON.parse(readFileSync(configPath, 'utf8')) as TuiSettings+ raw = readFileSync(configPath, 'utf8')} catch {- config = {}+ raw = null // missing/unreadable → create from {}+ }+ if (raw !== null && raw.trim() !== '') {+ try {+ config = JSON.parse(raw) as TuiSettings+ } catch {+ return false // exists but unparseable: never replace the user's file+ }}const { config: next, changed } = ensureFullscreenTui(config)if (!changed) return falsediff --git a/src/main/remote-ssh/remote-hooks.ts b/src/main/remote-ssh/remote-hooks.tsindex 278b08139..097513c3e 100644--- a/src/main/remote-ssh/remote-hooks.ts+++ b/src/main/remote-ssh/remote-hooks.ts@@ -166,10 +166,14 @@ export class RemoteHooks {childArgs(conn, controlPath, `cat ${posixQuote(config)} 2>/dev/null || echo '{}'`))let cfg: TuiSettings = {}- try {- cfg = JSON.parse(raw || '{}') as TuiSettings- } catch {- cfg = {}+ if (raw.trim() && raw.trim() !== '{}') {+ try {+ cfg = JSON.parse(raw) as TuiSettings+ } catch {+ // The file EXISTS but does not parse (`|| echo '{}'` only fires when it is missing):+ // never replace the user's settings with {tui:...} — same guard as the local wrapper.+ return+ }}const { config: next, changed } = ensureFullscreenTui(cfg)if (!changed) return // key already present (any value) → never overwrite the user's `/tui`