Files
Sprachmittler-Kit/docs/PRD.md
T

101 lines
9.5 KiB
Markdown

# Sprachmittler — Product requirements (v1)
## Problem
People read and write in more than one language all day. Switching to a browser translator breaks concentration, and cloud translators send the selected text to a third party. DeepL's macOS app solved the interaction problem with a double copy (⌘C twice), but it is a cloud service with accounts and limits. Running a strong local translation model through Ollama is possible, but it means a terminal, a prompt, manual copying and no reliable way to put the result back.
## Product statement
Select text in any app, press **⌘C twice**, and Sprachmittler shows a translation from a local Hy-MT3 model in a floating panel. Copy it, or click **Replace** to put it over the selection. The source app keeps the focus, nothing is sent to a third party, and nothing is replaced or copied behind your back.
## Persona
A technical professional on an Apple Silicon Mac who reads and writes English and German (and occasionally other languages), runs Ollama locally, cares about privacy, works with the keyboard and expects native macOS behaviour. They translate paragraphs in Mail, Safari, Word, Notes, Slack and an editor, and they do not want a document translator.
## User stories and acceptance criteria
| ID | Story | Acceptance criteria |
|---|---|---|
| US-1 | As a user, I select a paragraph in Safari and press ⌘C twice. | The panel appears within 250 ms; the source app stays active; the translation streams in. |
| US-2 | As a user, I click Copy and paste the translation somewhere. | The clipboard contains the translation; the panel stays open; the source app is unchanged. |
| US-3 | As a user, I click Replace. | The selected text in the source app is replaced; ⌘Z restores the original in apps that support undo; the panel closes. |
| US-4 | As a user, I do not want accidental replacements. | Nothing is inserted until Replace is clicked; Replace is disabled while translating or when validation blocks it. |
| US-5 | As a user, I switch the target language to German and back to English. | The translation is redone for the new target; the choice persists across launches. |
| US-6 | As a user, I translate a long selection. | It is chunked at paragraph boundaries and reassembled; no text is silently lost; a warning appears if a chunk fails. |
| US-7 | As a user, I translate text with a URL, an e-mail and `{{placeholders}}`. | All protected tokens survive; if one is lost, a warning appears and Replace is disabled. |
| US-8 | As a user, I translate Markdown or JSON. | Formatting and keys are preserved; user-facing values are translated. |
| US-9 | As a user, the model adds "Here is the translation:". | The panel shows a preamble warning; Replace is disabled by default; Copy still works. |
| US-10 | As a user, Ollama is not running or the model is missing. | The panel or onboarding names the problem and offers a fix; no raw error is shown. |
| US-11 | As a user, I use an app that does not accept Accessibility replacement. | Replace fails with a clear message and offers Copy; the app is not left in a broken state. |
| US-12 | As a user, I want to translate without granting Accessibility. | Double copy, translation, Copy and Services work; Replace explains the permission when clicked. |
| US-13 | As a user, I invoke Services ▸ Translate with Sprachmittler. | The selected text is translated in the same panel without clipboard polling or Accessibility. |
| US-14 | As a user, I translate from the terminal. | `sprachmittler-cli translate --text "…" --target de` prints the translation; `--json` emits structured output. |
| US-15 | As a user, I want certainty that my text stays local. | Default endpoint is loopback; remote requires an explicit toggle and HTTPS; logs contain no text; no history on disk. |
## Requirements
| ID | Area | Requirement | Verification |
|---|---|---|---|
| R001 | Capture | Two ⌘C copies within the configured window trigger a translation. | `DoubleCopyWatcherTests` |
| R002 | Capture | The two copies must contain identical, non-empty text. | `DoubleCopyWatcherTests` |
| R003 | Capture | The app ignores its own clipboard writes. | `OwnWriteSuppressionTests` |
| R004 | Capture | Whitespace-only selections are ignored with no panel. | `DoubleCopyWatcherTests` |
| R005 | Capture | Oversized text produces an actionable error before any request. | `TextLimitTests` |
| R006 | Capture | Services menu entry translates without clipboard polling. | Manual checklist |
| R007 | Capture | The menu bar can translate the current clipboard text on demand. | Manual checklist |
| R008 | Capture | No global key tap and no Input Monitoring permission. | Code review; privacy check |
| R009 | Translation | Ollama `/api/chat` with streaming NDJSON is the only backend. | `OllamaChatClientTests` |
| R010 | Translation | The Hy-MT3 default prompt is byte-exact. | `PromptGoldenTests` |
| R011 | Translation | The prompt prefix depends only on the target language and stays stable. | `PromptGoldenTests` |
| R012 | Translation | Target languages use the model card's exact English names. | `LanguageCatalogTests` |
| R013 | Translation | 7B Q4_K_M is the provisional default; 1.8B is offered as Fast. | `ModelCatalogTests` |
| R014 | Translation | Publisher sampling is mapped to Ollama option names. | `SamplingOptionsTests` |
| R015 | Translation | `num_ctx` is set to 8192 on every request. | `RequestEncodingTests` |
| R016 | Translation | Source language detection is for display only. | `LanguageDetectorTests` |
| R017 | Translation | Long text is chunked at paragraph boundaries and reassembled exactly. | `ChunkerTests` |
| R018 | Translation | Protected tokens are scanned and validated before Replace. | `ProtectedTokenTests` |
| R019 | Translation | Preamble, truncation and repetition produce warnings. | `OutputValidatorTests` |
| R020 | Translation | Same-language input produces a warning but can still be translated. | `SameLanguageTests` |
| R021 | Panel | The panel is non-activating and never steals focus. | Manual checklist |
| R022 | Panel | The translation streams into the panel. | Manual checklist |
| R023 | Panel | Copy writes the translation and keeps the panel open. | `PanelViewModelTests`, manual |
| R024 | Panel | Replace is an explicit button in the lower right; no auto-replace. | Manual checklist |
| R025 | Panel | Replace tries Accessibility first, then synthetic paste. | `InsertionCoordinatorTests` |
| R026 | Panel | Replace aborts if the source app or selection changed. | `InsertionTargetTests` |
| R027 | Panel | The previous clipboard is restored after a paste fallback. | `ClipboardSnapshotTests` |
| R028 | Panel | Replace is undoable in apps that support undo; this is documented. | Manual checklist |
| R029 | Panel | Esc closes; ⌘C copies; ⌘↩ replaces when safe. | Manual checklist |
| R030 | Panel | Blocking warnings disable Replace and are visible. | `PanelViewModelTests` |
| R031 | Permissions | Accessibility is optional and requested only for Replace. | Privacy check; manual |
| R032 | Privacy | No telemetry, analytics or accounts. | Privacy check |
| R033 | Privacy | Source text and translations are never logged in clear. | Privacy check |
| R034 | Privacy | No translation history; nothing text-related is persisted. | Code review; privacy check |
| R035 | Privacy | Loopback endpoint by default; remote needs HTTPS and an explicit toggle. | `EndpointPolicyTests` |
| R036 | Privacy | No Screen Recording, camera, microphone or Input Monitoring permission. | Info.plist/privacy check |
| R037 | Privacy | Clipboard snapshots live in memory for one replacement. | `ClipboardSnapshotTests` |
| R038 | Privacy | Selected and translated text is never executed or followed as instructions. | Code review |
| R039 | UX | Onboarding checks Ollama, model, target language and optional Accessibility. | Manual checklist |
| R040 | UX | Settings store no source text or translations. | `AppSettingsTests` |
| R041 | UX | Status menu exposes translate, language, copy, replace, settings, setup, quit. | Manual checklist |
| R042 | UX | Diagnostics shows versions, digests, timings and error kinds only. | Manual checklist |
| R043 | UX | The app UI is keyboard accessible and VoiceOver readable. | Manual checklist |
| R044 | UX | Launch at login is optional and reflects the system state. | Manual checklist |
| R045 | UX | English base and German localisation. | `LocalisationTests` |
| R046 | Tooling | CLI supports languages, models, show, detect, translate and eval. | CLI tests |
| R047 | Tooling | Evaluation corpus and metrics are documented and runnable. | Eval tests |
| R048 | Tooling | Unit, contract and component tests plus a manual compatibility matrix. | `make verify` |
| R049 | Release | Developer ID signing, notarisation and a DMG script. | Release checklist |
| R050 | Performance | Capture, panel, first token and insert budgets are met or re-recorded. | PERFORMANCE |
## Out of scope for v1
Document/file translation, image OCR, speech, dictation, writing improvement, translation memory, glossaries, cloud accounts, automatic replacement, automatic copy, background clipboard translation, Linux/Windows/iOS, Mac App Store.
## Success measures
- A selected paragraph is translated and shown in under 2 s from the second ⌘C on a warm M-series Mac (first token), and in under 8 s for 250 output tokens.
- Replace succeeds in at least 8 of 10 tested apps; the remaining apps get a clear Copy fallback.
- Zero lost URLs or placeholders in the evaluation corpus, or a visible warning.
- No source text, translation or app name appears in logs.
- The user prefers the panel flow over switching to a browser translator for at least 8 of 10 sampled translations.