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
feat(speech): speech IPC surface wired in main + server (desktop-dictation Task 6)
enesf5c74ef8f15a
diff --git a/src/core/speech/register-ipc.test.ts b/src/core/speech/register-ipc.test.tsnew file mode 100644index 000000000..1439eec44--- /dev/null+++ b/src/core/speech/register-ipc.test.ts@@ -0,0 +1,49 @@+import { describe, expect, it, vi } from 'vitest'+import { mkdtempSync, writeFileSync } from 'node:fs'+import { tmpdir } from 'node:os'+import { join } from 'node:path'+import { registerSpeechIpc } from './register-ipc'+import { SpeechService, type WhisperEngineHandle } from './speech-service'+import { WhisperModelStore } from './whisper-models'+import { DEFAULT_SETTINGS } from '../../shared/types'++function setup(engine: 'whisper' | 'cloud' = 'whisper') {+ const handlers = new Map<string, (payload: any) => Promise<any>>()+ const dir = mkdtempSync(join(tmpdir(), 'ipc-'))+ const models = new WhisperModelStore({ dir })+ writeFileSync(models.modelPath('tiny'), 'x')+ const factory = async (): Promise<WhisperEngineHandle> => ({+ transcribe: async () => 'from whisper', free: async () => {},+ })+ const service = new SpeechService({ models, isPremium: () => false, engineFactory: factory })+ registerSpeechIpc({+ handle: (ch, fn) => handlers.set(ch, fn),+ service, models,+ settings: () => ({ ...DEFAULT_SETTINGS, speech: { engine, model: 'tiny', language: 'auto' } }),+ licenseToken: () => null,+ apiBase: 'https://api.example.dev',+ fetchFn: (async () => ({ ok: false, status: 404, json: async () => ({}) })) as any,+ })+ return { handlers }+}++describe('registerSpeechIpc', () => {+ it('routes transcribe to whisper and accepts an ArrayBuffer payload', async () => {+ const { handlers } = setup('whisper')+ const pcm = new Float32Array(16).buffer+ await expect(handlers.get('speech:transcribe')!({ pcm })).resolves.toEqual({ text: 'from whisper' })+ })++ it('routes transcribe to cloud when configured (and surfaces its 404 message)', async () => {+ const { handlers } = setup('cloud')+ await expect(handlers.get('speech:transcribe')!({ pcm: new Float32Array(16).buffer }))+ .rejects.toThrow("Cloud transcription isn't available yet.")+ })++ it('lists models merged with catalog metadata', async () => {+ const { handlers } = setup()+ const list = await handlers.get('speech:models')!({})+ expect(list.find((m: any) => m.id === 'tiny')).toMatchObject({ downloaded: true, pro: false, approxMB: 75 })+ expect(list.find((m: any) => m.id === 'base')).toMatchObject({ downloaded: false, pro: true })+ })+})diff --git a/src/core/speech/register-ipc.ts b/src/core/speech/register-ipc.tsnew file mode 100644index 000000000..79f11beb3--- /dev/null+++ b/src/core/speech/register-ipc.ts@@ -0,0 +1,48 @@+import { WHISPER_MODELS } from '../../shared/speech'+import type { Settings } from '../../shared/types'+import { cloudTranscribe } from './cloud-speech'+import { decodePcmPayload } from './pcm'+import type { SpeechService } from './speech-service'+import type { WhisperModelStore } from './whisper-models'++/** Registers the speech IPC surface. `handle` is the platform's+ * request/response seam — the same function works under Electron ipcMain and+ * the server's ws-rpc, which is what makes dictation a three-surface feature+ * for free. Mic consent is deliberately NOT here (Electron-only — the shells+ * register it themselves). */+export function registerSpeechIpc(deps: {+ handle: (channel: string, fn: (payload: any) => Promise<any>) => void+ service: SpeechService+ models: WhisperModelStore+ settings: () => Settings+ licenseToken: () => string | null+ apiBase: string+ fetchFn?: typeof fetch+}): void {+ deps.handle('speech:transcribe', async (payload: { pcm: ArrayBuffer | string; language?: string }) => {+ const speech = deps.settings().speech+ const pcm = decodePcmPayload(payload.pcm)+ const language = payload.language ?? speech.language+ const text = speech.engine === 'cloud'+ ? await cloudTranscribe(pcm, {+ apiBase: deps.apiBase,+ locale: language === 'auto' ? 'en' : language,+ token: deps.licenseToken(),+ fetchFn: deps.fetchFn,+ })+ : await deps.service.transcribe(pcm, { model: speech.model, language })+ return { text }+ })++ deps.handle('speech:models', async () => {+ const onDisk = await deps.models.list()+ return WHISPER_MODELS.map((m) => ({+ ...m,+ downloaded: onDisk.find((d) => d.id === m.id)?.downloaded ?? false,+ sizeMB: onDisk.find((d) => d.id === m.id)?.sizeMB,+ }))+ })++ deps.handle('speech:model-download', async ({ id }: { id: string }) => { await deps.models.download(id) })+ deps.handle('speech:model-delete', async ({ id }: { id: string }) => { await deps.models.delete(id) })+}diff --git a/src/main/index.ts b/src/main/index.tsindex a9f60b554..71e4b591d 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -2,7 +2,7 @@ import { join, resolve, posix } from 'path'import { readFile } from 'fs/promises'import { homedir } from 'os'import { randomUUID } from 'crypto'-import { app, BrowserWindow, dialog, ipcMain, Notification, shell } from 'electron'+import { app, BrowserWindow, dialog, ipcMain, Notification, shell, systemPreferences } from 'electron'import { IPC } from '../shared/ipc'import { registerFsHandlers } from '../core/fs-handlers'import { PtyManager } from '../core/pty-manager'@@ -55,6 +55,9 @@ import { initTranscriptIndex, searchTranscripts } from '../core/transcript-indeximport { initTelemetry } from './telemetry'import { initClaudeUsage } from './claude-usage'import { initLicense, isPremium, getStoredEntitlement } from '../core/license'+import { WhisperModelStore } from '../core/speech/whisper-models'+import { SpeechService } from '../core/speech/speech-service'+import { registerSpeechIpc } from '../core/speech/register-ipc'import { initRelayQuota, broadcastRelayQuota, relayQuotaAvailable } from '../core/relay-quota'import { initClaudeAccounts } from './claude-accounts'import { claudeCliCaps, registerClaudeCliIpc } from '../core/claude-cli'@@ -121,6 +124,14 @@ function isSafeExternalUrl(url: unknown): url is string {const settingsStore = new SettingsStore()const sshStore = new SshStore()const ptyManager = new PtyManager()+// Dictation: local whisper.cpp models live under userData, one dir per install (same convention+// as the tmux config / scrollback-store). onProgress pushes { id, pct } to the renderer the same+// way agent-status events do (sendToMain — resolves the live window at send time).+const whisperModels = new WhisperModelStore({+ dir: join(app.getPath('userData'), 'speech-models'),+ onProgress: (id, pct) => sendToMain(IPC.speechProgress, { id, pct })+})+const speechService = new SpeechService({ models: whisperModels, isPremium })// Relay PEER sinks (docs/remote-sessions.md 4b) — the desktop mirror of src/server/index.ts's// setFlowController / setResyncProvider / onClientGone. Wired at boot, BEFORE any peer can register@@ -389,6 +400,20 @@ app.whenReady().then(async () => {workspaceStore.registerIpc()gitService.registerIpc()presenceHub.registerIpc()+ registerSpeechIpc({+ handle: (channel, fn) => corePlatform.handle(channel, fn),+ service: speechService,+ models: whisperModels,+ settings: () => settingsStore.get(),+ licenseToken: () => getStoredEntitlement(),+ apiBase: RELAY_API_BASE+ })+ // Electron-only mic consent: not core-bound (systemPreferences is main-process-only), so it's+ // a raw ipcMain handler like the other Electron-only surfaces (dialogs, shell, media) rather+ // than going through registerSpeechIpc/corePlatform.+ ipcMain.handle(IPC.speechMicConsent, async () =>+ process.platform === 'darwin' ? systemPreferences.askForMediaAccess('microphone') : true+ )registerClaudeCliIpc()// Warm the `claude --version` probe now (it spawns a login shell + node, ~sub-second) so the// renderer's first `claude.cliCaps()` — awaited on the launch path of a cold-restored agentdiff --git a/src/server/index.ts b/src/server/index.tsindex 3d8b6a21b..fcdb4cf4e 100644--- a/src/server/index.ts+++ b/src/server/index.ts@@ -20,6 +20,14 @@ import { presenceHub } from '../core/presence/hub'import { initCanvasSync } from '../core/canvas-sync'import { wireAgentStatus } from './agent-status'import { IPC } from '@shared/ipc'+import { WhisperModelStore } from '../core/speech/whisper-models'+import { SpeechService } from '../core/speech/speech-service'+import { registerSpeechIpc } from '../core/speech/register-ipc'+import { isPremium, getStoredEntitlement } from '../core/license'++// Same env-override + default as src/core/check.ts / license.ts / src/main/telemetry.ts — each+// shell derives it locally rather than sharing an import (src/server must not import src/main).+const API_BASE = process.env.NODETERM_API_BASE || 'https://api.nodeterm.dev'/*** App version fed to ServerPlatform (surfaced to the renderer as the desktop app's@@ -75,6 +83,24 @@ export async function startServer(ptyManager.init(() => settingsStore.get())ptyManager.registerIpc()workspaceStore.registerIpc()+ // Dictation: same construction as src/main/index.ts, with the server's data dir. onProgress+ // broadcasts to every attached browser tab the same way wireAgentStatus pushes agent-status.+ const whisperModels = new WhisperModelStore({+ dir: path.join(config.dataDir, 'speech-models'),+ onProgress: (id, pct) => platform.broadcast(IPC.speechProgress, { id, pct })+ })+ const speechService = new SpeechService({ models: whisperModels, isPremium })+ registerSpeechIpc({+ handle: (channel, fn) => platform.handle(channel, fn),+ service: speechService,+ models: whisperModels,+ settings: () => settingsStore.get(),+ licenseToken: () => getStoredEntitlement(),+ apiBase: API_BASE+ })+ // Browser mic permission is the browser's own prompt (getUserMedia), not ours to gate —+ // unlike Electron's systemPreferences.askForMediaAccess, there is nothing server-side to ask.+ platform.handle(IPC.speechMicConsent, async () => true)// Canvas sync: reflect each browser tab's node mutations to the other attached tabs, so every// client converges on the same node set (and no tab writes back a node another tab deleted).initCanvasSync()diff --git a/src/shared/ipc.ts b/src/shared/ipc.tsindex 12b8e44ca..84daf0f12 100644--- a/src/shared/ipc.ts+++ b/src/shared/ipc.ts@@ -267,5 +267,16 @@ export const IPC = {pairingDone: 'pairing:done',pairingProbeSsh: 'pairing:probe-ssh',pairingListDevices: 'pairing:listDevices',- pairingRevokeDevice: 'pairing:revokeDevice'+ pairingRevokeDevice: 'pairing:revokeDevice',+ // Dictation (desktop/server). speechProgress is a main/server → renderer broadcast of+ // { id, pct } while a whisper model downloads (WhisperModelStore.onProgress).+ speechTranscribe: 'speech:transcribe',+ speechModels: 'speech:models',+ speechModelDownload: 'speech:model-download',+ speechModelDelete: 'speech:model-delete',+ speechProgress: 'speech:progress',+ // Electron-only: registered in src/main/index.ts (systemPreferences.askForMediaAccess) and+ // stubbed `async () => true` in src/server/index.ts (browser mic permission is the browser's+ // own prompt, not ours to gate).+ speechMicConsent: 'speech:mic-consent'} as const