111 lines
9.6 KiB
Markdown
111 lines
9.6 KiB
Markdown
# Implementation plan
|
||
|
||
Work milestone by milestone, task by task. Each task is sized for one OpenCode session, about 100–400 lines of change. A task is done only when its acceptance criteria pass **and** `make verify` is green. Track status in `docs/PROGRESS.md`.
|
||
|
||
Conventions: `T<milestone>.<n>`. "AC" = acceptance criteria. "Verify" = commands that must succeed.
|
||
|
||
---
|
||
|
||
## M0 — Scaffold and tooling
|
||
|
||
Goal: an empty but correctly configured project that builds, tests, and launches as a menu-bar agent.
|
||
|
||
| Task | Description | AC |
|
||
|---|---|---|
|
||
| T0.1 | The kit ships `Packages/VorleserKit/Package.swift` with placeholder sources and tests. Verify it resolves and builds, fix any toolchain issues, and replace placeholder enums as modules gain real types. | `swift build --package-path Packages/VorleserKit` and `make test` succeed. |
|
||
| T0.2 | Complete the `App/` sources (stubs shipped): `VorleserApp` with a `MenuBarExtra` showing "Vorleser" + Quit; `AppDelegate` stub; `Info.plist` (LSUIElement, NSServices placeholder, ATS local networking); entitlements (no sandbox). | `make app` builds and the menu-bar icon appears, with no Dock icon. |
|
||
| T0.3 | Validate the shipped `project.yml` (XcodeGen) and `make generate`; set your own bundle ID prefix. | `xcodegen generate` produces a project that builds in Xcode and via `xcodebuild`. |
|
||
| T0.4 | Run the shipped `scripts/verify.sh`, `.swiftformat`, `.swiftlint.yml`; fix issues so the gate is green on the scaffold. | `make verify` runs end-to-end. |
|
||
| T0.5 | Add `os.Logger` categories helper in `VorleserCore` (`Log.capture`, `Log.ollama`, …) and an `OSSignposter` wrapper. | Unit test compiles and uses it. |
|
||
|
||
## M1 — Ollama client
|
||
|
||
Goal: synthesise speech and discover models/voices headlessly.
|
||
|
||
| Task | Description | AC |
|
||
|---|---|---|
|
||
| T1.1 | Run `scripts/capture-fixtures.sh` against a local Ollama; commit `Packages/VorleserKit/Tests/VorleserOllamaTests/Fixtures/*`. Update `docs/OLLAMA_SPEECH_API.md` VERIFY items with observed shapes. | Fixtures exist. Doc updated. |
|
||
| T1.2 | `OllamaHTTPClient`: base URL, JSON encode/decode, error body parsing, `EndpointPolicy` (SECURITY_PRIVACY SP-5). | `EndpointPolicyTests`, `ErrorMappingTests` green against fixtures. |
|
||
| T1.3 | `OllamaCatalog: SpeechModelCatalog`: `/api/version`, `/api/tags`, `/api/show` (defensive voice decoding, `capabilities` contains `speech`), per-model cache. | Tests for both voice shapes, missing `voices` → `["default"]`, version comparison. |
|
||
| T1.4 | `OllamaSpeechClient: SpeechSynthesizing` streaming PCM via `URLSession.bytes`, odd-byte carry, 100 ms chunking, idle timeout, cancellation propagation. | `URLProtocol` stub tests: chunk boundaries, odd bytes, cancel mid-stream cancels the task, 400 unknown voice mapping. |
|
||
| T1.5 | `vorleser-cli`: `voices [--model]`, `models`, `speak --model --voice --text|--file --out file.pcm|--play`. `--play` uses `afplay` on a temp WAV that the CLI writes itself. | Manual: `swift run vorleser-cli speak --text "Hallo" --model phonon:40m-de --play` is audible. |
|
||
|
||
## M2 — Text pipeline
|
||
|
||
| Task | Description | AC |
|
||
|---|---|---|
|
||
| T2.1 | `TextNormaliser` implementing N1–N5 (ARCHITECTURE §6.1). | Table-driven tests including PDF hyphenation (DE + EN), soft hyphens, page-number paragraphs, single-newline joins. |
|
||
| T2.2 | `Segmenter`: paragraphs → `NLTokenizer` sentences, 25-char merge, 1,500-char cap with the split order, `sourceRange`. | Tests: abbreviations ("z. B.", "e.g.", "Fig. 3"), decimals ("3.5 GHz"), very long sentence split, no word split, ranges map back to text. |
|
||
| T2.3 | `LanguageDetector` + `ModelRouter` (routing table, fallback, `latest` normalisation). | Tests: EN, DE, mixed, short text → nil → fallback. |
|
||
| T2.4 | `DocumentBuilder` composing T2.1–T2.3 into `ReadingDocument`. Add `vorleser-cli segment --file` to print segments. | Snapshot-style test on a sample article in `Packages/VorleserKit/Tests/VorleserTextTests/Fixtures/`. |
|
||
|
||
## M3 — Audio
|
||
|
||
| Task | Description | AC |
|
||
|---|---|---|
|
||
| T3.1 | `PCMConverter` (Int16LE → Float32), scalar + Accelerate path. | Tests: known sample values, endianness, empty input. |
|
||
| T3.2 | `EngineAudioPlayer: AudioPlaying` (graph, scheduling, epochs, events, elapsed time, rate). | `vorleser-cli speak --play-engine` plays through the engine. Unit tests for the epoch-filter logic, factored into a pure `ScheduleLedger`. |
|
||
| T3.3 | Engine lifecycle: lazy start, 30 s idle stop, configuration-change rebuild. | Manual test: unplug headphones mid-sentence → resumes. |
|
||
| T3.4 | `FakeAudioPlayer` in a test-support target (`VorleserTestSupport`). | Used by M4 tests. |
|
||
|
||
## M4 — Synthesis queue and session
|
||
|
||
| Task | Description | AC |
|
||
|---|---|---|
|
||
| T4.1 | `PCMCache` (LRU by bytes, 64 MB cap, key `(segmentID, VoiceSelection)`). | Eviction tests. |
|
||
| T4.2 | `SynthesisQueue` actor: serial, prefetch window, epoch cancellation, priority for the playhead segment. | Tests with a fake synthesiser with controllable latency: seek cancels in-flight work outside the window; no duplicate requests; cache hit → no request. |
|
||
| T4.3 | `ReadingSession` actor implementing the state machine and commands (ARCHITECTURE §8.2) including the 1.5 s rule. | State-transition tests for every edge in the diagram, using fakes. |
|
||
| T4.4 | `SessionViewModel` (`@MainActor @Observable`) mirroring state, progress, current sentence text. | Tests on the main actor. |
|
||
| T4.5 | `vorleser-cli read --file` with interactive keys (space, ←/→, q) in raw TTY mode. | Manual: full navigation works headlessly. **This is the main integration checkpoint before UI work.** |
|
||
|
||
## M5 — App shell, settings, discovery
|
||
|
||
| Task | Description | AC |
|
||
|---|---|---|
|
||
| T5.1 | `AppSettings` model + `SettingsStore` (UserDefaults, versioned, migration hook). | Round-trip and default tests. |
|
||
| T5.2 | Composition root `AppEnvironment` wiring client, catalog, queue, player, session. | App launches. `Read clipboard text` debug menu item reads the clipboard via the session. |
|
||
| T5.3 | Settings scene: General / Speech / Capture / Privacy tabs. Speech tab lists installed speech models with licence badges and voices from discovery, plus a "Test voice" button. | Manual. Voice list matches `ollama show`. |
|
||
| T5.4 | Model warm-up (`keepModelWarm`) and "Refresh models". | Signpost shows a lower TTFA on the first session after warm-up. |
|
||
| T5.5 | Launch at login via `SMAppService.mainApp`. | Toggle reflects the real status. |
|
||
|
||
## M6 — Selection capture
|
||
|
||
| Task | Description | AC |
|
||
|---|---|---|
|
||
| T6.1 | `AccessibilityPermission` helper (trusted check, prompt, deep link). | Onboarding can show the status. |
|
||
| T6.2 | `AXSelectionCapturer` per SELECTION_CAPTURE.md (focus, selected text, range fallback, parent walk, Electron flags, timeout, background queue). | Works in TextEdit, Safari, Preview (manual). Unit-test the pure parts behind an `AXClient` protocol. |
|
||
| T6.3 | Global hotkeys with `KeyboardShortcuts` (Read selection ⌥⎋, Stop ⌥⇧⎋) + recorder in Settings. | Hotkey triggers capture → session. |
|
||
| T6.4 | Services provider (`readSelection`) + Info.plist `NSServices`. | Right-click ▸ Services ▸ "Read with Vorleser" works in TextEdit and Safari. |
|
||
| T6.5 | `ClipboardSelectionCapturer` (opt-in) with full pasteboard restore and transient type. `CaptureChain`. | Tests with an injected `PasteboardProtocol`. Manual test in VS Code. |
|
||
| T6.6 | Menu-bar "Read selection" uses the previously frontmost app. | Works from the menu while Safari has the selection. |
|
||
|
||
## M7 — Controller panel
|
||
|
||
| Task | Description | AC |
|
||
|---|---|---|
|
||
| T7.1 | Non-activating floating `NSPanel` host (`ControllerPanel`), positioned near the top-right of the active screen, draggable, position remembered. | Source app keeps key focus while the panel is visible. |
|
||
| T7.2 | SwiftUI `ControllerView`: transport buttons, speed slider, voice menu, progress, state/error line, current sentence (toggleable). | All controls work. VoiceOver labels present. |
|
||
| T7.3 | Panel keyboard shortcuts (Space, ←/→, ⌥←/⌥→, −/=, Esc) when the panel is key. Clicking the panel makes it key without activating the app (`becomesKeyOnlyIfNeeded`). | Manual. |
|
||
| T7.4 | HUD for transient messages. | `noSelection` shows a HUD and no panel. |
|
||
| T7.5 | Menu-bar menu mirrors the session (Pause/Resume, Stop, current voice). | Manual. |
|
||
|
||
## M8 — Onboarding, errors, privacy
|
||
|
||
| Task | Description | AC |
|
||
|---|---|---|
|
||
| T8.1 | Onboarding window with three checks + fix actions (open Ollama download page, copy `ollama pull phonon`, open Accessibility settings, re-check). | Shown on first launch and from the menu. |
|
||
| T8.2 | `VorleserError.userMessage` / `recoveryAction` for every case. Panel and HUD use them. | Exhaustive switch test. |
|
||
| T8.3 | Optional disk cache (SP-7) with size cap and "Clear cache". | `DiskAudioCacheTests`. |
|
||
| T8.4 | Remote endpoint toggle + HTTPS enforcement in the UI. | UI blocks invalid configurations. |
|
||
| T8.5 | Privacy audit: grep checks for SP-1…SP-10 added to `scripts/verify.sh`. | `make verify` fails on violations. |
|
||
|
||
## M9 — Hardening and release
|
||
|
||
| Task | Description | AC |
|
||
|---|---|---|
|
||
| T9.1 | Fill the compatibility matrix in SELECTION_CAPTURE.md. Fix the top three failures. | Matrix complete. |
|
||
| T9.2 | Performance pass against ARCHITECTURE §15 budgets using signposts. Record results in `docs/PERFORMANCE.md`. | Budgets met or ADR explaining the deviation. |
|
||
| T9.3 | Diagnostics section (⌥-click in Settings). | Shows the listed fields, no text. |
|
||
| T9.4 | `scripts/release.sh`: archive, Developer ID sign, notarise (`notarytool`), staple, DMG. | Notarised build launches on a clean Mac. |
|
||
| T9.5 | README for end users: install, permissions, Services shortcut, troubleshooting (incl. `pbs -update`). | Reviewed. |
|