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(speech): adopt a freshly downloaded model when the selection points at nothing
enesa1fc310b8ef7
diff --git a/src/renderer/components/settings/sections/SpeechSection.tsx b/src/renderer/components/settings/sections/SpeechSection.tsxindex a79d44d50..5b91e5ba8 100644--- a/src/renderer/components/settings/sections/SpeechSection.tsx+++ b/src/renderer/components/settings/sections/SpeechSection.tsx@@ -1,5 +1,6 @@import { useCallback, useEffect, useRef, useState } from 'react'import type { SpeechModelInfo } from '@shared/types'+import { modelAfterDelete, modelAfterDownload } from '@shared/speech'import { DEFAULT_SETTINGS } from '@shared/types'import {buildModifierChord,@@ -203,11 +204,16 @@ export function SpeechSection({const [busy, setBusy] = useState<Record<string, boolean>>({})const [rowError, setRowError] = useState<Record<string, string>>({})- const refreshModels = useCallback(async (): Promise<void> => {+ // Returns the fresh list as well as storing it: a caller that has just downloaded or deleted+ // needs to decide the selection from the POST-change state, and `models` is a render behind.+ const refreshModels = useCallback(async (): Promise<SpeechModelInfo[]> => {try {- setModels(await window.nodeTerminal.speech.models())+ const next = await window.nodeTerminal.speech.models()+ setModels(next)+ return next} catch {// leave the last-known list on a transient read error+ return []}}, [])@@ -263,7 +269,16 @@ export function SpeechSection({setProgress((p) => ({ ...p, [m.id]: 0 }))try {await window.nodeTerminal.speech.downloadModel(m.id)- await refreshModels()+ const fresh = await refreshModels()+ // Downloading is not selecting — but the setting defaults to `tiny`, so someone whose first+ // download is `base` is left pointed at a model that is not on disk, and dictation fails.+ // `modelAfterDownload` adopts the fresh one only when the current pick has nothing behind+ // it, so an already-working choice is never taken away by trying a second model.+ // Read the settings back from the store, not the render scope: a download takes minutes,+ // and this closure's `settings` is a snapshot from before it started.+ const live = useSettings.getState().settings.speech+ const adopt = modelAfterDownload(fresh, live.model, m.id)+ if (adopt) update({ speech: { ...live, model: adopt } })} catch (err) {setRowError((e) => ({...e,@@ -284,7 +299,11 @@ export function SpeechSection({setBusy((b) => ({ ...b, [m.id]: true }))try {await window.nodeTerminal.speech.deleteModel(m.id)- await refreshModels()+ const fresh = await refreshModels()+ // Deleting the selected model leaves the same dangling pointer a first download does.+ const live = useSettings.getState().settings.speech+ const adopt = modelAfterDelete(fresh, live.model)+ if (adopt) update({ speech: { ...live, model: adopt } })} catch (err) {setRowError((e) => ({ ...e, [m.id]: err instanceof Error ? err.message : 'Delete failed.' }))} finally {diff --git a/src/shared/speech.test.ts b/src/shared/speech.test.tsindex 71b566380..82dd309ad 100644--- a/src/shared/speech.test.ts+++ b/src/shared/speech.test.ts@@ -1,5 +1,12 @@import { describe, expect, it } from 'vitest'-import { WHISPER_MODELS, whisperModel, WHISPER_DOWNLOAD_BASE } from './speech'+import {+ WHISPER_MODELS,+ whisperModel,+ WHISPER_DOWNLOAD_BASE,+ modelAfterDownload,+ modelAfterDelete,+ type ModelDownloadState+} from './speech'import { DEFAULT_SETTINGS } from './types'describe('whisper model catalog', () => {@@ -30,3 +37,41 @@ describe('whisper model catalog', () => {})})})++const list = (...ids: Array<[string, boolean]>): ModelDownloadState[] =>+ ids.map(([id, downloaded]) => ({ id, downloaded }))++describe('modelAfterDownload', () => {+ it('adopts the first download — the default selection points at a model nobody fetched', () => {+ // `tiny` is selected out of the box (see the default above), so a user whose first download is+ // `base` was left pointed at a file that is not on disk, and dictation failed.+ expect(modelAfterDownload(list(['tiny', false], ['base', true]), 'tiny', 'base')).toBe('base')+ })++ it('leaves a working selection alone when a second model is tried out', () => {+ expect(modelAfterDownload(list(['tiny', true], ['small', true]), 'tiny', 'small')).toBeNull()+ })++ it('is a no-op when the selection is what was just downloaded', () => {+ expect(modelAfterDownload(list(['tiny', true]), 'tiny', 'tiny')).toBeNull()+ })++ it('adopts when the selected id is not in the catalogue at all', () => {+ // A removed/renamed model in an old settings file has nothing behind it either.+ expect(modelAfterDownload(list(['base', true]), 'ancient', 'base')).toBe('base')+ })+})++describe('modelAfterDelete', () => {+ it('falls back to another downloaded model when the selected one is deleted', () => {+ expect(modelAfterDelete(list(['tiny', false], ['small', true]), 'tiny')).toBe('small')+ })++ it('keeps the selection when it is still on disk', () => {+ expect(modelAfterDelete(list(['tiny', true], ['small', true]), 'tiny')).toBeNull()+ })++ it('answers null when nothing is downloaded — there is nothing truthful to select', () => {+ expect(modelAfterDelete(list(['tiny', false], ['small', false]), 'tiny')).toBeNull()+ })+})diff --git a/src/shared/speech.ts b/src/shared/speech.tsindex 58265ebb7..3f51b12b3 100644--- a/src/shared/speech.ts+++ b/src/shared/speech.ts@@ -19,3 +19,43 @@ export const WHISPER_DOWNLOAD_BASE = 'https://huggingface.co/ggerganov/whisper.cexport function whisperModel(id: string): WhisperModelInfo | undefined {return WHISPER_MODELS.find((m) => m.id === id)}++/** The download/selection state a surface needs to keep the two in step. Deliberately narrower+ * than `SpeechModelInfo` so the mobile-shaped lists fit it too. */+export interface ModelDownloadState {+ id: string+ downloaded: boolean+}++/**+ * The model to select after `justDownloaded` finished, or null to leave the choice alone.+ *+ * Downloading is not selecting — but a settings default (`tiny`) means there is ALWAYS a+ * selection, so a user who downloads `base` first ends up pointed at a model that is not on disk+ * and dictation fails with "model not downloaded". They downloaded a model and reasonably believe+ * they are done. So: adopt the fresh download whenever the current selection has nothing behind+ * it, and never when it does — a working setup is not hijacked by trying a second model out.+ */+export function modelAfterDownload(+ models: readonly ModelDownloadState[],+ current: string,+ justDownloaded: string+): string | null {+ if (current === justDownloaded) return null+ // An id that is not in the list at all (a renamed/removed model) has nothing behind it either.+ return models.find((m) => m.id === current)?.downloaded ? null : justDownloaded+}++/**+ * The model to select after a delete, or null to leave it alone. Deleting the selected model+ * leaves the same dangling pointer a first download does — so fall back to whatever else is on+ * disk. Null when nothing is: there is nothing truthful to select, and the row list already says+ * so louder than a silent switch would.+ */+export function modelAfterDelete(+ models: readonly ModelDownloadState[],+ current: string+): string | null {+ if (models.find((m) => m.id === current)?.downloaded) return null+ return models.find((m) => m.downloaded)?.id ?? null+}