5.9 KiB
5.9 KiB
Phase 2 - Add an isolated local stack and browser voice session
Copy this prompt into a fresh implementation session in the repository.
Implement Phase 2 of the active FOUR-phase local S2S plan only: Add an isolated local stack and browser voice session.
Do not execute the archived eight-stage prompts.
Prerequisite:
Phase 1 accepted. Isolated engine and candidate API use disposable DB/storage, not the operational database.
Required visible outcome:
The existing browser talks in Persian through local_s2s using OpenRouter STT/LLM/TTS, displays transcripts and closes normally in a disposable environment.
Execution rules:
- Read docs/plans/local-s2s-adapter-plan.md and docs/plans/local-s2s-adapter-progress.md first. Read applicable AGENTS.md, repository skills and governing API/database/workflow sections. Inspect current code; historical defaults are not current evidence.
- Implement only this phase. Check actual prerequisite artifacts, not just the existence of code. State observed, simulated, unverified and blocked outcomes separately.
- Preserve OpenAI/Gemini behavior, original operational/rollback containers/images, frozen old profiles and unrelated working-tree changes. No database reset, compose down, pruning or implicit provider switch.
- Keep existing browser PCM24k/application events, backend-derived identity, one canonical search implementation, document/chunk references and authorization/revision checks.
- Make the smallest scoped change. No plugin framework, full runtime rewrite, new broker or unrelated refactor. Update intentional contracts and affected consumers coherently; never edit applied migrations.
- Ordinary tests are provider-free. DB acceptance requires a verified disposable TEST_DATABASE_URL and --require-postgres; never production. Do not run a parallel application API against the operational database.
- Reuse explicit authorization already present. Paid requests, downloads and operational switching need the applicable bounded authorization. Without it, finish independent offline preparation, identify the exact missing prerequisite and keep dependent live acceptance open.
- Do not print keys/full environments/raw provider payloads or real user speech. Consent-controlled fixture artifacts are separate from default logs.
- Never fake provider events, terminal success or history acknowledgements. Unsupported capabilities fail safely. Do not introduce automatic cross-provider fallback.
- Before finishing: inspect diff, run meaningful checks, record exact commands/results and demo steps, update the progress ledger and list all not-run checks. Do not accept a phase with required live/human checks unrun. Do not begin the next phase.
Required work:
- Build a separate engine from the pinned SHA with local VAD and independently configured OpenRouter HTTP STT, tool-capable Chat Completions LLM and TTS. Avoid unnecessary local-model/GPU downloads.
- Discover/pin actual model IDs, voices, Persian hints, supported fields and PCM rates. Verify multipart/JSON STT, TTS streaming/format compatibility and explicit server-side credential forwarding.
- Begin with final-utterance STT. Bound requests/concurrency/bytes/retries/cleanup and meter startup probes. Provide stub mode plus an explicitly opt-in bounded live smoke and playable test audio.
- Add local_s2s settings/factory/readiness alongside openai/gemini. Preserve the browser PCM16LE mono24k and existing JSON events; use bounded stateful resampling if required.
- Freeze engine/patch/contract revision, component identities, voice/input policy and effective instruction/config digest. Compare to authoritative engine state, not request echoes or socket reachability.
- Map actual input acceptance, manual response creation/intent, tool framing, terminal/error and transcript/audio semantics without invented native commit events.
- Preserve owner/Origin/cookie/CSRF/replay/epoch checks and old snapshots. Audit provider DTO/DB constraints; use a forward migration only if actually needed and compatible with rollback.
- Use a separate test hostname/browser identity and disposable DB/storage. Until Phase 3, interruptions must fail safely and be labelled development-only; do not enable unsafe continuation.
Acceptance criteria:
- A normal browser greeting/answer/transcript/close works against the isolated candidate, and independent stage probes produce valid audio.
- Model/voice/rate/credential/effective-config mismatches fail setup accurately; keys and secret-derived hashes never enter profiles or logs.
- Existing OpenAI remains usable; new configuration does not rewrite old reservations or change the operational provider.
- Actual provider checks are distinguished from stubs. Missing credentials or real speech evidence leaves live acceptance pending.
Relevant areas; verify actual paths first:
Pinned engine service/build config, isolated Compose profile, local adapter, validated settings/profile/factory/readiness, .env.example, smoke harness and tests.
Validation:
HTTP boundary fixtures, pinned-engine relevant tests, local adapter contract tests, isolated PostgreSQL profile/admission/replay/revocation cases and bounded actual browser/provider smoke.
Visible demo:
Show a recorded Persian utterance becoming a WAV response, then perform a normal greeting in the existing browser against the isolated candidate.
Stop/narrow condition:
A different port is not DB isolation. Do not claim safe barge-in or production parity before Phase 3; do not promote this provider.
Deliver scoped implementation/configuration/tests/contracts as necessary,
docs/evaluation/local-s2s/phase-02.md with exact commands and actual/simulated/
unverified outcomes, and an updated docs/plans/local-s2s-adapter-progress.md.
Provide demo steps, acceptance verdict, risks, not-run checks and rollback relevance.
Do not declare completion while mandatory real-provider/human checks are missing.
Do not implement the next phase or switch the operational provider implicitly.