# Sprachmittler: OpenCode 2.x starter kit 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. 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. ## How it works 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. 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. ## Prerequisites | Requirement | Version | |---|---| | 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`) | ## Getting started ```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 # the scaffold should already build and test make app # builds and launches Sprachmittler.app opencode # start OpenCode in the repo root ``` Then paste the prompt from `docs/KICKOFF.md` into OpenCode, or simply run: ```text /next ``` 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. ## What's inside | Path | Purpose | |---|---| | `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` | ## The canonical prompt All translation prompts live in `SprachmittlerEngines`. The default is Tencent's documented English template, byte for byte: ```text Translate the following text into {target_lang}. Note that you should **only output the translated result without any additional explanation**: {source_text} ``` `{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. ## Recommended way to work with OpenCode 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 ` 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 ` so the docs stay true. ## Placeholders to change - 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. ## Licensing note 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.