peppa/apps/web/components/VoiceInput.tsx
Асель 6b75324971 PEP-10/27/53: runners with a story queue, a git worktree per runner, free runners
- Runner settings with inheritance system → project → story (settings rows):
  mode story (default, one runner per story) / queue, context fresh / continue,
  workspace shared / worktree, maxRunners. No rows = behaviour as before.
- runner_tasks: a runner's story history and queue; sessions.name, sessions.workspace_path
  (migration 0007_runners).
- moveTask → startTaskOnRunner; runnerTick in the watchdog moves free queue runners to
  their next story (fresh: same tmux, new generation without resume; continue: message),
  reassigns queues of dead runners, removes finished runners' worktrees (clean + pushed).
- Free runners («Новый терминал»), rename, «Оформить стори»; the Stop hook doesn't ping
  for free runners or stories that left work.
- Web: «Новый терминал» (runners page, project sessions tab) with voice input,
  project/story runner settings, runner stories in the details panel; CLI peppa runner …
- e2e: packages/testkit/test/runners.test.ts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 06:38:02 +05:00

63 lines
2.3 KiB
TypeScript

"use client";
// PEP-53: voice input for a prompt — the browser's own speech recognition (Web Speech API,
// Chrome/Safari); nothing is sent to Peppa but the recognized text. Hidden where unsupported.
import { useEffect, useRef, useState } from "react";
import { Mic, MicOff } from "lucide-react";
import { Button } from "@/components/ui/button";
type Recognition = {
lang: string;
interimResults: boolean;
continuous: boolean;
start(): void;
stop(): void;
onresult: ((e: { resultIndex: number; results: ArrayLike<{ isFinal: boolean; 0: { transcript: string } }> }) => void) | null;
onend: (() => void) | null;
onerror: (() => void) | null;
};
export function VoiceInput({ target }: { target: string }) {
const [supported, setSupported] = useState(false);
const [on, setOn] = useState(false);
const rec = useRef<Recognition | null>(null);
useEffect(() => {
const w = window as unknown as { SpeechRecognition?: new () => Recognition; webkitSpeechRecognition?: new () => Recognition };
setSupported(!!(w.SpeechRecognition ?? w.webkitSpeechRecognition));
return () => rec.current?.stop();
}, []);
if (!supported) return null;
const toggle = () => {
if (on) {
rec.current?.stop();
return;
}
const w = window as unknown as { SpeechRecognition?: new () => Recognition; webkitSpeechRecognition?: new () => Recognition };
const Ctor = (w.SpeechRecognition ?? w.webkitSpeechRecognition)!;
const r = new Ctor();
r.lang = "ru-RU";
r.interimResults = false;
r.continuous = true;
r.onresult = (e) => {
const el = document.getElementById(target) as HTMLTextAreaElement | HTMLInputElement | null;
if (!el) return;
for (let i = e.resultIndex; i < e.results.length; i++) {
const res = e.results[i]!;
if (res.isFinal) el.value = `${el.value}${el.value && !/\s$/.test(el.value) ? " " : ""}${res[0].transcript.trim()}`;
}
};
r.onend = () => setOn(false);
r.onerror = () => setOn(false);
rec.current = r;
r.start();
setOn(true);
};
return (
<Button type="button" size="sm" variant={on ? "default" : "outline"} onClick={toggle} aria-pressed={on} title={on ? "Остановить диктовку" : "Надиктовать промпт"}>
{on ? <MicOff /> : <Mic />}
{on ? "Стоп" : "Голосом"}
</Button>
);
}