docs(readme): present the app instead of the starter kit

Rewrite README.md around the shipped menu-bar app: features, requirements, install from source, usage (Esc, click-outside, Markdown, Replace), privacy, architecture, status and a compact development section. Remove the starter-kit framing, placeholder/stub claims and the kit verification section; update the ADR/module counts and document the transient outside-click monitor.
This commit is contained in:
schihei committed 2026-11-26 17:19:13 +01:00
1 parent 39ec191348
commit 7c9cece201
2 files changed
+170 -101

No files matched your search

+1 -1
View File
@@ -251,7 +251,7 @@ b0a7d3451d8830654fe79476b8d32d95709d956817a4436f58c0f73bbd8d3194 ./Packages/Spr
8c5c21634d749ad05da8b6a0fc1d8e132a494177a697ba0a1338a7a6b5dba50c ./Packages/SprachmittlerKit/Tests/SprachmittlerTextTests/PlaceholderTests.swift
67c0f9ba9e818267e99c1756b82643f7e59effa6783325675386aba0a1002cb3 ./Packages/SprachmittlerKit/Tests/SprachmittlerTextTests/ProtectedTokenScannerTests.swift
c3294d486cfe44a6f0a69a1ec05cff33a8eccf090fce04fadffa96b6b2563d6f ./Packages/SprachmittlerKit/Tests/SprachmittlerTextTests/TextNormalizationTests.swift
a212d7f39aadba95375bdc14786ee12ffc43b4555e4a591f60ce5da0dfd7c5b0 ./README.md
eeff058dee89a14f9c9207bc5a28d5f06a733c9f596af7bd4553a90c199780cf ./README.md
f1dbc2fb876d909b8486239e9b75b09ed68516c341d586e96d8626715c86a88c ./dist/Sprachmittler-0.1.0-local.dmg
3b7b1fe301c5f715c6f4f74cc553a907c1ae89e669d5625d414dc3dae51d0216 ./docs/ARCHITECTURE.md
018c5faf1a5d2e8d851ab209d45e64993cbd6b7976c4aa90c571359c83e83264 ./docs/CODING_STANDARDS.md
+169 -100
View File
@@ -1,134 +1,203 @@
# Sprachmittler: OpenCode 2.x starter kit
# Sprachmittler
Sprachmittler is a native macOS menu-bar app for Apple Silicon. Select text in any app, press **⌘C twice**, and a small floating panel shows a translation produced by Tencent's **Hy-MT3-7B** translation model running locally through **Ollama**. The panel has **Copy** and an explicit **Replace** button in the lower right corner; nothing is ever replaced automatically.
Sprachmittler is a native macOS menu-bar app for Apple Silicon. Select text in any app, press **⌘C twice**, and a floating panel shows a translation from Tencent's **Hy-MT3** model running locally through **Ollama**. Copy it, or click **Replace** to put it over the selection. Nothing is replaced automatically, and nothing leaves your Mac by default.
This repository is the development kit for building the app with **OpenCode 2.x**. It contains the architecture, specifications, a task plan, an evaluation design, OpenCode agents, commands and skills in native V2 format, and a compilable scaffold.
Sprachmittler is the companion to Schriftleser and Vorleser: Vorleser reads text aloud, Schriftleser reads documents into text, Sprachmittler translates the text you select.
It is the companion to **Schriftleser** and **Vorleser**: Vorleser reads text aloud, Schriftleser turns documents into text, and Sprachmittler translates the text you select.
A user-facing installation, permission and troubleshooting guide is in [docs/USER_GUIDE.md](docs/USER_GUIDE.md).
## How it works
## Features
1. Select text in Safari, Mail, Word, Notes, an editor or any other app.
2. Press **⌘C** twice quickly (the DeepL-style double copy).
3. A non-activating panel appears; the source app keeps the keyboard focus.
4. The translation streams in while the local Hy-MT3 model works.
5. **Copy** puts the translation on the clipboard. **Replace** replaces the selected text with the translation — only when you click it.
6. **Esc** closes the panel. **⌘Z** in the source app undoes a Replace in apps that support undo.
**Translate**
Nothing is sent anywhere except the configured Ollama endpoint, which is `http://127.0.0.1:11434` by default. There is no history, no telemetry and no account.
- Double-copy trigger in any app: select, **⌘C**, **⌘C**.
- Streaming translations from a local Hy-MT3 model; no cloud API.
- 102 supported languages with a language picker and recent targets.
- Markdown rendering for headings, bold, italic, lists, quotes, code and links.
- Configurable translation text size, source-preview toggle and an optional Fast model preset.
## Prerequisites
**The panel**
| Requirement | Version |
- Non-activating floating panel: the source app stays frontmost and keeps the menu bar.
- Draggable full-width header; the panel keeps its position while open and appears near the cursor when shown again.
- **Esc** closes it without clicking first; a click outside closes it too.
- Copy, Retry and explicit **Replace**, with validation warnings that disable Replace when the output is unsafe.
**System integration**
- Menu-bar actions: Translate Clipboard Text, target language, Copy Last Translation, Replace Last Translation, Settings, onboarding, diagnostics and Quit.
- macOS **Services** item: "Translate with Sprachmittler".
- First-run onboarding checks Ollama, the model and the optional Accessibility permission.
- Accessibility is used only for Replace and is never required for translation or Copy.
**Privacy**
- Local Ollama endpoint by default; a remote endpoint needs an explicit toggle and HTTPS.
- No history, telemetry or account. Source text and translations are never written to disk.
- No global key taps and no Input Monitoring.
## Requirements
| Requirement | Details |
|---|---|
| Apple Silicon Mac | macOS 14 Sonoma or later; 16 GB unified memory recommended for the 7B model |
| Xcode | 16 or later (Swift 6) |
| Ollama | current release; this kit was verified with 0.40.18 |
| Translation model | `hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M` (about 5.15 GB); optional fast model `hf.co/tencent/Hy-MT3-1.8B-GGUF:Q4_K_M` (about 1.35 GB) |
| Homebrew | for `xcodegen`, `swiftformat`, `swiftlint`, `xcbeautify`, `ripgrep`, `jq` |
| OpenCode | **2.x** (check with `opencode --version`) |
| Mac | Apple Silicon, macOS 14 Sonoma or later |
| Ollama | Current release; verified with 0.40.18 |
| Translation model | `hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M` (about 5.15 GB, 16 GB unified memory recommended) |
| Fast preset (optional) | `hf.co/tencent/Hy-MT3-1.8B-GGUF:Q4_K_M` (about 1.35 GB) |
| Accessibility | Optional; needed only for Replace |
| Build tools | Xcode 16 or later, Homebrew, XcodeGen, SwiftFormat and SwiftLint (`make bootstrap`) |
| OpenCode | Optional; **2.x** only when using the repository's agent workflow |
## Getting started
## Install from source
```bash
git init && git add -A && git commit -m "chore: Sprachmittler OpenCode kit"
make bootstrap # installs xcodegen, swiftformat, swiftlint, jq, ripgrep
ollama pull hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M # about 5.15 GB
make smoke # translates one fixed synthetic sentence
make doctor # checks OpenCode 2.x and the resolved V2 config
make verify # format, lint, privacy, tests, Debug + Release builds
make app # builds and launches the Debug app
make install # builds Release, installs in /Applications and launches
make dmg # local unnotarised DMG from the Release build
make icon # regenerate the app icon assets
opencode # start OpenCode in the repo root
git clone <repository-url>
cd Sprachmittler
make bootstrap
```
Then paste the prompt from `docs/KICKOFF.md` into OpenCode, or simply run:
Start Ollama and download the model once:
```text
/next
```bash
ollama serve
ollama pull hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M
```
The **Replace** button needs the macOS Accessibility permission. The app asks for it only when you use Replace; double-copy, translation and Copy work without any permission.
Then build, install and launch the Release app:
## What's inside
```bash
make install
```
| Path | Purpose |
`make install` builds the Release configuration, replaces `/Applications/Sprachmittler.app` and opens it. For a local disk image instead:
```bash
make dmg
```
The DMG is ad-hoc signed for local use, not notarised. The app runs from the menu bar and has no Dock icon; open it and follow the first-run onboarding.
For a Debug build during development:
```bash
make app
```
## Usage
1. Select text in Safari, Mail, Notes, an editor or any other app.
2. Press **⌘C** twice quickly. The double-copy window is 500 ms by default and configurable.
3. The panel appears near the cursor and the translation streams in.
4. **Copy** puts the translation on the clipboard. **Replace** overwrites the selection only when you click it.
5. **Esc** or a click outside closes the panel.
The panel takes keyboard focus while it is visible by default, so Esc and the shortcuts work immediately. The app itself is not activated: the source app stays frontmost, and clicking it returns keyboard focus. The **Close with Esc without clicking** setting turns the focus-taking behaviour off.
| Action | Shortcut |
|---|---|
| `AGENTS.md` | Project rules OpenCode loads automatically: commands, workflow, non-negotiables, doc map |
| `opencode.json` | Native OpenCode 2.x config: loads `docs/CODING_STANDARDS.md` and defines an ordered `permissions` list |
| `.opencode/agents/` | `architect` (plans, read-only), `swift-reviewer` (reviews, read-only), `test-engineer` (tests and fakes only), `translation-evaluator` (runs evaluations) |
| `.opencode/commands/` | `/next`, `/task T2.2`, `/plan …`, `/verify`, `/review`, `/adr …`, `/status`, `/manual-test …`, `/evaluate …` |
| `.opencode/skills/` | `translation-quality` (prompt fidelity, validation, judging output), `selection-capture` (double copy, pasteboard, insertion, permissions) |
| `docs/ARCHITECTURE.md` | Authoritative design: modules, capture/insertion flow, session state machine, budgets, risks |
| `docs/PRD.md` | User stories, requirements R001–R050, acceptance criteria |
| `docs/IMPLEMENTATION_PLAN.md` | 9 milestones (M0–M8), about 50 tasks, each with acceptance criteria and traceability |
| `docs/KICKOFF.md` | Ready-to-paste prompts for the first session and checkpoints |
| `docs/PROGRESS.md` | Checklist the agent updates after each task |
| `docs/HYMT3_MODEL.md` | Model tags, licence, all documented prompt templates, sampling, performance |
| `docs/OLLAMA_TRANSLATION_API.md` | HTTP contract for `/api/chat`, options mapping, error mapping, fixtures |
| `docs/SELECTION_AND_CLIPBOARD.md` | Double-copy algorithm, pasteboard restoration, Accessibility replacement, compatibility matrix |
| `docs/TRANSLATION_OUTPUT.md` | Prompt selection, chunking, protective token validation, output rules T1–T4 |
| `docs/LANGUAGES.md` | The 102 supported languages and their exact model names |
| `docs/SECURITY_PRIVACY.md` | Privacy invariants SP-1…SP-15, checked by `scripts/privacy-check.sh` |
| `docs/MODEL_EVALUATION.md` | Corpus, metrics, report format and the default-model gate |
| `docs/TESTING.md` | Test layers, required cases, manual release checklist |
| `docs/DECISIONS.md` | ADR-001…ADR-015 |
| `docs/CODING_STANDARDS.md` | Swift 6 concurrency, structure, logging, UI, style |
| `docs/OPENCODE_V2.md` | Why the OpenCode files look the way they do, and how to check them |
| `docs/PERFORMANCE.md` | Reference measurements and budgets |
| `evaluation/` | Corpus manifest schema and example; the corpus itself stays out of git |
| `project.yml` | XcodeGen spec for the app target |
| `Packages/SprachmittlerKit/` | SwiftPM package with module placeholders, test targets and synthetic fixtures |
| `App/` | Menu-bar app stubs, `Info.plist` (Services, ATS), non-sandboxed entitlements |
| `scripts/` | `bootstrap`, `verify`, `privacy-check`, `opencode-check`, `smoke-ollama`, `capture-fixtures`, `manifest` |
| Translate the selection | **⌘C** twice |
| Close the panel | **Esc**, or click outside |
| Copy the translation | **⌘C** |
| Retry | **⌘R** |
| Replace the selection | **⌘↩** |
| Settings | **⌘,** |
## The canonical prompt
### Markdown
All translation prompts live in `SprachmittlerEngines`. The default is Tencent's documented English template, byte for byte:
When the source looks like Markdown and **Settings ▸ General ▸ Translation ▸ Render Markdown formatting** is on (the default), the translation is rendered with headings, bold, italic, lists, quotes, fenced code and links. JSON, HTML and code sources are never Markdown-rendered. **Copy** and **Replace** always use the raw Markdown translation, not the rendered text. Only `http` and `https` links open, and only on an explicit click.
### Replace
Replace verifies the source app and, when available, the selected text before touching it. It prefers a direct Accessibility write and falls back to a clipboard snapshot plus synthetic paste. Blocking validation warnings — a likely preamble, truncation, a repetition loop or a lost protected token — disable Replace by default. The previous clipboard is restored after the fallback paste when it is still safe to do so.
### Settings
- **General** — target language, source preview, Markdown rendering, translation text size, Esc behaviour, double-copy window and startup.
- **Model** — model and Fast preset, Ollama endpoint, sampling and context settings.
- **Translation** — chunking and prompt policy.
- **Privacy** — local/remote endpoint policy and permissions.
- **Diagnostics** — server version, model digests, the last 50 timings and error kinds. No text or translations.
## Privacy
- The default endpoint is `http://127.0.0.1:11434`. A non-loopback endpoint requires an explicit setting and HTTPS.
- Source text, translations and pasteboard contents are never written to disk and are not kept as history.
- The clipboard snapshot for a Replace fallback lives in memory for that one replacement and is restored.
- Logs contain counts, timings, short hashes and error kinds, never the selected text or the translation.
- Markdown links are restricted to `http`/`https`; remote images are never fetched.
- The app does not install a key tap and never requests Input Monitoring. While the panel is visible, a transient mouse-down monitor dismisses it when a click goes to another app; the event is discarded and the monitor is removed when the panel closes.
The hard requirements are listed in [docs/SECURITY_PRIVACY.md](docs/SECURITY_PRIVACY.md).
## How it works
```text
Translate the following text into {target_lang}. Note that you should **only output the translated result without any additional explanation**:
{source_text}
select text → ⌘C twice → pasteboard capture → validate → chunk
→ documented Hy-MT3 prompt → Ollama /api/chat (streaming)
→ validate → floating panel
```
`{target_lang}` is the full English language name from the model card (for example `German`, `Chinese`, `Traditional Chinese`). The prefix is kept stable so Ollama can reuse its prompt cache; only the target language and the source text change. The model has no default system prompt, and the app sends none.
The app is a menu-bar agent (`LSUIElement`) with a non-activating `NSPanel`. Replace re-verifies the frontmost app and the selected text before inserting. The translation pipeline, capture/insertion seams and UI state models are separate modules so they can be tested without the UI.
## Recommended way to work with OpenCode
| Module | Responsibility |
|---|---|
| `App/` | Menu-bar app, panel, settings, onboarding, diagnostics and composition root |
| `Packages/SprachmittlerKit/` | Translation pipeline, prompt adapters, Ollama client, capture/insertion, text utilities and tests |
| `docs/` | Architecture, product requirements, model/API contracts, privacy, testing and decisions |
| `scripts/` | Build, verification, privacy, fixture, icon and release helpers |
| `evaluation/` | Corpus manifest schema, metrics and report format; the corpus itself stays out of git |
1. **One task per session.** `/task T2.2` keeps context small and focused.
2. **Headless first.** M1–M2 build the Ollama client, the Hy-MT3 adapter, the language catalogue, chunking and validation. `sprachmittler-cli translate` gives you a working translation engine before any UI exists.
3. **Capture real fixtures early (T1.1).** The exact `/api/show` output, streaming shapes and prompt-cache behaviour are recorded from your Ollama. Recorded fixtures stop the agent from guessing.
4. **Measure before choosing.** The 7B is the provisional default; T7.4 is the evaluation gate. The 1.8B may be the better everyday choice on smaller Macs.
5. **You are the test rig for macOS-only behaviour.** Double copy, panel focus, Accessibility replacement, clipboard restoration, Services and VoiceOver need a human. Use `/manual-test <feature>` and report results back.
6. **Review gate.** `/next` already calls `@swift-reviewer`. Run `/review` yourself before committing larger changes.
7. **Record decisions.** When you deviate from the architecture, run `/adr <title>` so the docs stay true.
See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for the full design.
## Placeholders to change
## Status
- Bundle ID prefix `de.schihei` in `project.yml`.
- App name "Sprachmittler" if you prefer another. Search the repo for `Sprachmittler`.
- The default model tag in `docs/HYMT3_MODEL.md` and `docs/PROGRESS.md` once T7.4 is decided.
- Model tags for the fast preset once the 1.8B conversion has been verified on your Ollama.
Sprachmittler is at **0.1.0**. M0–M8 are implemented, `make verify` is green, and local install and DMG builds are verified.
## Licensing note
The 7B model is the provisional default; the default model and prompt policy are decided by the evaluation gate in [docs/MODEL_EVALUATION.md](docs/MODEL_EVALUATION.md). Manual macOS-only checks remain for the double-copy and insertion matrices, VoiceOver, and the 10-app compatibility matrix. Current task state is in [docs/PROGRESS.md](docs/PROGRESS.md).
Local builds are ad-hoc signed. `make release` is the Developer ID and notarisation path and needs the corresponding credentials.
## Development
```bash
make bootstrap # install xcodegen, swiftformat, swiftlint, jq and ripgrep if missing
make doctor # check OpenCode 2.x and the resolved V2 configuration
make generate # regenerate Sprachmittler.xcodeproj from project.yml
make build # swift build plus the Debug app target
make test # package unit, contract and component tests
make app # build and launch the Debug app
make verify # format, lint, privacy, tests, Debug + Release builds
make install # build Release, install in /Applications and launch
make dmg # local unnotarised DMG from the Release build
make smoke # translate one fixed synthetic sentence
make live-test # tests against a real local Ollama
make fixtures # capture Ollama fixtures
make manifest # regenerate MANIFEST.sha256
make release # signed/notarised release dry-run; needs credentials
```
The package builds and tests without Xcode UI:
```bash
swift build --package-path Packages/SprachmittlerKit
swift test --package-path Packages/SprachmittlerKit
```
`swift run --package-path Packages/SprachmittlerKit sprachmittler-cli --help` exposes the language catalogue, model inspection, translation and evaluation commands.
### Working with OpenCode
The repository is set up for the **OpenCode 2.x** development workflow. `AGENTS.md` contains the rules the agent loads, `opencode.json` is the native V2 config, and `.opencode/` contains the agents, commands and skills. Use `/next` for the next open task, `/task T4.2` for a named task, and `/verify` before calling work done. [docs/OPENCODE_V2.md](docs/OPENCODE_V2.md) explains the configuration and how to check it.
OpenCode is a development tool. The app builds and runs without it.
### Forking
- Set your bundle identifier in `project.yml` (the default `de.schihei.sprachmittler` is a placeholder).
- Change model tags in `docs/HYMT3_MODEL.md` and the preset definitions in `SprachmittlerEngines`.
- Use your own Developer ID and notarisation credentials for `make release`.
- Do not commit `Sprachmittler.xcodeproj`, build products, `evaluation/corpus/` or evaluation results.
## Licensing
Sprachmittler bundles no models. Hy-MT3 is published by Tencent under **Apache-2.0**; the GGUF conversions used here are published by Tencent on Hugging Face. Settings shows the licence and the model digest. Re-check the model card before commercial distribution. The 30B-A3B model is not a preset: it needs far more memory than a 16 GB Mac has.
## Kit verification status (2026-11-26)
What was checked when the kit was assembled:
- `swift build` and `swift test --skip SprachmittlerLiveTests` pass for `Packages/SprachmittlerKit` with Swift 6.4.2 on macOS 27.2.1 (arm64).
- `xcodegen generate` and the Debug app build pass with Xcode 27.2.
- `scripts/privacy-check.sh` and `scripts/opencode-check.sh` (static part) pass; all scripts pass `bash -n`.
- `opencode.json`, the evaluation schema and the example parse as JSON; `plutil` accepts the Info.plist and entitlements.
- `make smoke` translated the fixed synthetic sentence into German with `hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M` on Ollama 0.40.18: 34 output tokens in 2.89 s, 45.81 tokens/s, cold load 2.05 s.
- The canonical prompt on the longer Hy-MT3 figure caption: 246 output tokens in 6.52 s, 44.6 tokens/s; 6.49 GB resident with `num_ctx` 8192.
- The owner's reference run with the same model: 255 output tokens, 43.07 tokens/s, 5.97 s warm, 177/178 prompt tokens cached.
Not yet checked: the double-copy gesture, panel focus, Accessibility replacement, clipboard restoration, Services, VoiceOver and real-world translation quality. Those are manual tasks in `docs/TESTING.md` and the compatibility matrices.