Files
web-terminal/public/main.ts
Yaojia Wang e4c327e25e feat: voice command mapping — context-gated approve/reject over voice
While a tool-permission gate is held on the active tab, spoken confirm
phrases resolve it via the existing approve/reject WS channel — no server
change (byte-shuttle intact). Everything else stays ordinary dictation.

Safety: whole-utterance-exact matching + leading-negation guard + reject
precedence + confidence gate (approve only) + a cancellable 1.5s confirm
window whose commit re-validates gate identity/epoch/connectivity (TOCTOU
guard) + stale-gate epoch bound at PTT-start.

New pure modules public/voice-commands.ts and public/voice-confirm.ts at
100% coverage; wiring in voice/terminal-session/tabs/main. 1307 tests pass,
typecheck clean, build:web OK. Independent code + security reviews flagged a
confirm-window TOCTOU and an unwired cancel path — both fixed and covered.

Plan: docs/PLAN_VOICE_COMMANDS.md.
2026-07-01 10:38:32 +02:00

97 lines
3.4 KiB
TypeScript

/**
* public/main.ts — esbuild entry point for the browser frontend.
*
* Bootstraps the multi-tab app: a tab bar (#tabs) + a utility toolbar (#toolbar)
* over a stack of terminal panes (#term), each tab an independent TerminalSession.
* The mobile key bar routes input to the active tab.
*
* Per-session terminal/WS/reconnect logic lives in terminal-session.ts;
* tab management + persistence in tabs.ts.
*/
// CSS side-effect import (esbuild → public/build/main.css; typed via css.d.ts).
import '@xterm/xterm/css/xterm.css'
import { mountKeybar } from './keybar.js'
import { TabApp } from './tabs.js'
import { mountSearch } from './search.js'
import { mountQrConnect } from './qr.js'
import { mountSettings, loadSettings, type Settings } from './settings.js'
import { mountDashboard } from './dashboard.js'
import { mountHistory } from './history.js'
import { mountShortcuts } from './shortcuts.js'
import { mountShareSession } from './share.js'
const paneHost = document.getElementById('term')
const tabs = document.getElementById('tabs')
const toolbar = document.getElementById('toolbar')
if (!paneHost) throw new Error('#term element not found in DOM')
if (!tabs) throw new Error('#tabs element not found in DOM')
if (!toolbar) throw new Error('#toolbar element not found in DOM')
const app = new TabApp(paneHost, tabs)
// v0.4: a share link (?join=<id>) opens/focuses that shared session, then we
// strip the param so a refresh doesn't keep re-opening it.
const joinId = new URLSearchParams(location.search).get('join')
if (joinId) {
app.openSession(joinId)
history.replaceState(null, '', location.pathname)
}
// Apply saved theme/font (M3) to the restored tabs.
let settings: Settings = loadSettings()
app.applySettings(settings)
// Key bar (mobile + desktop) sends to whichever tab is active. onVoiceTrigger
// activates the full voice path (dictation + context-gated confirm/reject, VC)
// and un-dormants the 🎤 button (createVoiceInput / matchCommand are otherwise
// unreachable dead code without this wiring).
mountKeybar((data) => app.sendToActive(data), {
onVoiceTrigger: (action) => app.handleVoiceTrigger(action),
})
// Multi-device: when this device regains focus, re-assert the active tab's size
// so a shared session snaps to THIS screen (latest-writer-wins) — full-screen on
// whichever device you're currently using.
window.addEventListener('focus', () => app.refitActive())
document.addEventListener('visibilitychange', () => {
if (!document.hidden) app.refitActive()
})
// Toolbar utilities.
mountSearch(toolbar, {
find: (query, dir) => app.findInActive(query, dir),
clear: () => app.clearActiveSearch(),
})
mountSettings(
toolbar,
() => settings,
(s) => {
settings = s
app.applySettings(s)
},
)
mountDashboard(toolbar, {
snapshot: () => app.snapshot(),
focus: (idx) => app.focusTab(idx),
})
mountHistory(toolbar, {
resume: (cwd, id) => app.newTabForResume(cwd, id),
})
mountShortcuts(toolbar)
mountShareSession(toolbar, () => app.activeSessionId())
// Session management lives on the home Sessions chooser now (open / kill /
// new), so the standalone /manage.html page was removed.
mountQrConnect(toolbar)
// PWA: register the service worker (installable + offline shell, M4).
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
void navigator.serviceWorker.register('./sw.js').catch(() => {
// SW registration is best-effort; the app works without it.
})
})
}