Files
Triple-C/app/src/components/settings/SttSettings.tsx
T
shadow-testandClaude Opus 5 01a2f6aec8 Add Project Home, Auth Bridge, shared auth token, and Tier-1 polish
Project Home (DESIGN-REVIEW §B2): the project is promoted from a 280px
sidebar card to a first-class main-area view. ProjectCard.tsx (1,257
lines) is replaced by a select-only ProjectRow plus tabs for Overview,
Sessions, Automation, Config and Files. The PortMappings, FileManager
and ContainerProgress modals are absorbed rather than reimplemented.
Config gains a Saved/Saving/Failed indicator — save-on-blur failures
previously reached only console.error.

Tier-1 polish (DESIGN-REVIEW §A): new elevation, muted-accent, disabled
and focus-ring tokens; a global :focus-visible ring with every
focus:outline-none removed; filled buttons moved to --accent-emphasis
and white-on-success toggles retired, fixing three WCAG AA failures
(2.1:1, 2.5:1, 2.4:1); a shared Modal primitive with role="dialog",
focus trap and restore, adopted by all remaining modals; status
indicators that carry a glyph and word rather than colour alone.

Ctrl+Shift+W closes a tab, deliberately not Ctrl+W — that is readline's
kill-word, used constantly in the terminal this app is built around.

Auth Bridge: a general loopback-callback bridge so browser logins run
inside a container (aws sso login, Concourse fly login, claude login)
can complete against the host browser. Listeners are discovered from
/proc/net/tcp{,6} — ss/netstat/lsof are absent from the image — bound on
host 127.0.0.1 only, and tunnelled in over the Docker API via socat,
which keeps working on Docker Desktop where container IPs are not
routable. Falls back to [::1] because Node resolves localhost to IPv6
first, so claude login often binds ::1 alone. Opt-in per project.

This extracts create_attached_exec() and moves the existing terminal
session path onto it, so there is one attached-exec implementation
rather than two.

Shared auth token: `claude setup-token` is run in a container, the token
is stored in the OS keychain and injected as CLAUDE_CODE_OAUTH_TOKEN
into Anthropic-backend projects. Contrary to the initial design note,
setup-token uses an Anthropic-hosted redirect and blocks on a stdin
paste prompt rather than a loopback callback, so a stdin command is
required for the flow to complete.

The token is never logged, never returned to the frontend, and is
redacted from the streamed output with a stateful matcher that withholds
any tail that could still grow into a secret. Change detection uses a
random rotation id rather than a hash, since a hash in a docker-inspect
readable label would be an offline verification oracle.

Frontend 33 -> 51 tests; Rust 34 tests. Both builds clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-09 11:35:42 -07:00

246 lines
8.6 KiB
TypeScript

import { useState, useEffect } from "react";
import { useSettings } from "../../hooks/useSettings";
import { getSttStatus, startStt, stopStt, pullSttImage, buildSttImage } from "../../lib/tauri-commands";
import { listen } from "@tauri-apps/api/event";
import type { SttStatus } from "../../lib/types";
import Tooltip from "../ui/Tooltip";
import Toggle from "../ui/Toggle";
export default function SttSettings() {
const { appSettings, saveSettings } = useSettings();
const [status, setStatus] = useState<SttStatus | null>(null);
const [loading, setLoading] = useState(false);
const [pulling, setPulling] = useState(false);
const [building, setBuilding] = useState(false);
const [buildLog, setBuildLog] = useState<string | null>(null);
const [model, setModel] = useState(appSettings?.stt?.model ?? "tiny");
const [port, setPort] = useState(String(appSettings?.stt?.port ?? 9876));
const [language, setLanguage] = useState(appSettings?.stt?.language ?? "");
useEffect(() => {
setModel(appSettings?.stt?.model ?? "tiny");
setPort(String(appSettings?.stt?.port ?? 9876));
setLanguage(appSettings?.stt?.language ?? "");
}, [appSettings?.stt?.model, appSettings?.stt?.port, appSettings?.stt?.language]);
useEffect(() => {
refreshStatus();
}, []);
const refreshStatus = () => {
getSttStatus().then(setStatus).catch(console.error);
};
const handleToggleEnabled = async () => {
if (!appSettings) return;
const newEnabled = !appSettings.stt.enabled;
await saveSettings({
...appSettings,
stt: { ...appSettings.stt, enabled: newEnabled },
});
};
const handleSaveModel = async () => {
if (!appSettings) return;
await saveSettings({
...appSettings,
stt: { ...appSettings.stt, model },
});
};
const handleSavePort = async () => {
if (!appSettings) return;
const portNum = parseInt(port, 10);
if (isNaN(portNum) || portNum < 1 || portNum > 65535) return;
await saveSettings({
...appSettings,
stt: { ...appSettings.stt, port: portNum },
});
};
const handleSaveLanguage = async () => {
if (!appSettings) return;
await saveSettings({
...appSettings,
stt: { ...appSettings.stt, language: language || null },
});
};
const handleStartStop = async () => {
setLoading(true);
try {
if (status?.running) {
await stopStt();
} else {
await startStt();
}
refreshStatus();
} catch (e) {
console.error("STT toggle failed:", e);
} finally {
setLoading(false);
}
};
const handlePull = async () => {
setPulling(true);
setBuildLog(null);
const unlisten = await listen<string>("stt-pull-progress", (event) => {
setBuildLog(event.payload);
});
try {
await pullSttImage();
refreshStatus();
} catch (e) {
console.error("STT image pull failed:", e);
setBuildLog(`Error: ${e}`);
} finally {
setPulling(false);
unlisten();
}
};
const handleBuild = async () => {
setBuilding(true);
setBuildLog(null);
const unlisten = await listen<string>("stt-build-progress", (event) => {
setBuildLog(event.payload);
});
try {
await buildSttImage();
refreshStatus();
} catch (e) {
console.error("STT image build failed:", e);
setBuildLog(`Error: ${e}`);
} finally {
setBuilding(false);
unlisten();
}
};
return (
<div>
<label className="block text-sm font-medium mb-1">
Speech to Text
<Tooltip text="Transcribe speech to text using Faster Whisper in a Docker container. Adds a mic button to the terminal." />
</label>
<p className="text-xs text-[var(--text-secondary)] mb-2">
Click the mic button in the terminal to dictate text via speech recognition.
</p>
<div className="space-y-2">
{/* Enable toggle */}
<div className="flex items-center gap-2">
<Toggle
label="Speech to text"
checked={!!appSettings?.stt?.enabled}
onChange={handleToggleEnabled}
/>
<span className="text-xs text-[var(--text-secondary)]">
{appSettings?.stt?.enabled ? "Enabled" : "Disabled"}
</span>
</div>
{appSettings?.stt?.enabled && (
<>
{/* Model selector */}
<div>
<label className="block text-xs text-[var(--text-secondary)] mb-1">Model</label>
<select
value={model}
onChange={(e) => setModel(e.target.value)}
onBlur={handleSaveModel}
className="w-full px-2 py-1 text-sm bg-[var(--bg-primary)] border border-[var(--border-color)] rounded focus:border-[var(--accent)]"
>
<option value="tiny">Tiny (fastest, ~75MB)</option>
<option value="small">Small (balanced, ~500MB)</option>
<option value="medium">Medium (most accurate, ~1.5GB)</option>
</select>
</div>
{/* Port */}
<div>
<label className="block text-xs text-[var(--text-secondary)] mb-1">Port</label>
<input
type="number"
value={port}
onChange={(e) => setPort(e.target.value)}
onBlur={handleSavePort}
min={1}
max={65535}
className="w-full px-2 py-1 text-sm bg-[var(--bg-primary)] border border-[var(--border-color)] rounded focus:border-[var(--accent)]"
/>
</div>
{/* Language */}
<div>
<label className="block text-xs text-[var(--text-secondary)] mb-1">Language (optional)</label>
<input
type="text"
value={language}
onChange={(e) => setLanguage(e.target.value)}
onBlur={handleSaveLanguage}
placeholder="Auto-detect"
className="w-full px-2 py-1 text-sm bg-[var(--bg-primary)] border border-[var(--border-color)] rounded focus:border-[var(--accent)]"
/>
</div>
{/* Container status + controls */}
<div className="pt-1">
<label className="block text-xs text-[var(--text-secondary)] mb-1">STT Container</label>
<div className="flex items-center gap-2 flex-wrap">
<span className="text-xs text-[var(--text-secondary)]">
{status?.image_exists
? status.running
? `Running (port ${status.port}, model: ${status.model})`
: status.container_exists
? "Stopped"
: "Image ready"
: "No image"}
</span>
{status?.image_exists && (
<button
onClick={handleStartStop}
disabled={loading}
className={`px-2 py-0.5 text-xs rounded transition-colors ${
status?.running
? "text-[var(--error)] hover:bg-[var(--bg-primary)]"
: "text-[var(--success)] hover:bg-[var(--bg-primary)]"
}`}
>
{loading ? "..." : status?.running ? "Stop" : "Start"}
</button>
)}
</div>
{/* Image actions */}
<div className="flex items-center gap-2 mt-2">
<button
onClick={handlePull}
disabled={pulling || building}
className="px-3 py-1 text-xs bg-[var(--bg-primary)] border border-[var(--border-color)] rounded hover:bg-[var(--border-color)] disabled:text-[var(--text-disabled)] transition-colors"
>
{pulling ? "Pulling..." : "Pull Image"}
</button>
<button
onClick={handleBuild}
disabled={pulling || building}
className="px-3 py-1 text-xs bg-[var(--bg-primary)] border border-[var(--border-color)] rounded hover:bg-[var(--border-color)] disabled:text-[var(--text-disabled)] transition-colors"
>
{building ? "Building..." : "Build Locally"}
</button>
</div>
{buildLog && (
<pre className="mt-2 text-[10px] text-[var(--text-secondary)] bg-[var(--bg-primary)] border border-[var(--border-color)] rounded px-2 py-1 max-h-20 overflow-y-auto whitespace-pre-wrap">
{buildLog}
</pre>
)}
</div>
</>
)}
</div>
</div>
);
}