diff --git a/apps/server/src/terminal/ghosttyStyle.ts b/apps/server/src/terminal/ghosttyStyle.ts index dc20fe9c30..ed20287410 100644 --- a/apps/server/src/terminal/ghosttyStyle.ts +++ b/apps/server/src/terminal/ghosttyStyle.ts @@ -187,7 +187,12 @@ export const loadGhosttyTerminalStyle: Effect.Effect< const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const home = NodeOS.homedir(); - const xdgConfigHome = process.env["XDG_CONFIG_HOME"] ?? path.join(home, ".config"); + // Per the XDG spec an empty XDG_CONFIG_HOME must be treated as unset. + const xdgConfigHomeEnv = process.env["XDG_CONFIG_HOME"]; + const xdgConfigHome = + xdgConfigHomeEnv !== undefined && xdgConfigHomeEnv.length > 0 + ? xdgConfigHomeEnv + : path.join(home, ".config"); const readFirstExisting = (candidates: ReadonlyArray) => Effect.gen(function* () { diff --git a/apps/web/src/components/ThreadTerminalDrawer.tsx b/apps/web/src/components/ThreadTerminalDrawer.tsx index 6cc8a6ffe8..9ef033ffa6 100644 --- a/apps/web/src/components/ThreadTerminalDrawer.tsx +++ b/apps/web/src/components/ThreadTerminalDrawer.tsx @@ -500,6 +500,8 @@ export function TerminalViewport({ let teardown: (() => void) | undefined; const setUpTerminal = (mount: HTMLDivElement): (() => void) => { + // Clear any failure message left by an earlier init attempt. + mount.textContent = ""; const localApi = readLocalApi(); const style = readTerminalStyle(); @@ -887,10 +889,18 @@ export function TerminalViewport({ }; }; - void ensureGhosttyReady().then(() => { - if (effectDisposed || containerRef.current !== mountElement) return; - teardown = setUpTerminal(mountElement); - }); + void ensureGhosttyReady().then( + () => { + if (effectDisposed || containerRef.current !== mountElement) return; + teardown = setUpTerminal(mountElement); + }, + (error: unknown) => { + if (effectDisposed || containerRef.current !== mountElement) return; + console.error("ghostty-web terminal failed to initialize", error); + mountElement.textContent = + "Terminal failed to initialize. Close and reopen the terminal to retry."; + }, + ); return () => { effectDisposed = true;