Compare commits
2
Commits
a3e544fbe4
...
7c9cece201
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c9cece201 | ||
|
|
39ec191348 |
No files matched your search
@@ -8,6 +8,8 @@ import SwiftUI
|
||||
final class PanelController: NSObject, NSWindowDelegate {
|
||||
private let panel: TranslationPanel
|
||||
private let viewModel: PanelViewModel
|
||||
private var isClosing = false
|
||||
private var outsideClickMonitor: Any?
|
||||
|
||||
/// Creates the panel and its SwiftUI content.
|
||||
init(viewModel: PanelViewModel) {
|
||||
@@ -20,6 +22,12 @@ final class PanelController: NSObject, NSWindowDelegate {
|
||||
)
|
||||
super.init()
|
||||
panel.delegate = self
|
||||
NotificationCenter.default.addObserver(
|
||||
self,
|
||||
selector: #selector(panelDidResignKey(_:)),
|
||||
name: NSWindow.didResignKeyNotification,
|
||||
object: panel
|
||||
)
|
||||
panel.isFloatingPanel = true
|
||||
panel.isMovable = true
|
||||
panel.becomesKeyOnlyIfNeeded = false
|
||||
@@ -54,15 +62,57 @@ final class PanelController: NSObject, NSWindowDelegate {
|
||||
if viewModel.configuration.closeWithEscape {
|
||||
panel.makeKey()
|
||||
}
|
||||
installOutsideClickMonitor()
|
||||
}
|
||||
|
||||
/// Hides the panel and cancels/releases its content.
|
||||
func close() {
|
||||
guard !isClosing else { return }
|
||||
isClosing = true
|
||||
defer { isClosing = false }
|
||||
removeOutsideClickMonitor()
|
||||
panel.orderOut(nil)
|
||||
Task { await viewModel.close() }
|
||||
}
|
||||
|
||||
/// A click outside the panel makes another window key. Treat that as a dismissal, but not
|
||||
/// while the language popover (a child window) is open.
|
||||
@objc private func panelDidResignKey(_ notification: Notification) {
|
||||
guard panel.isVisible, !isClosing else { return }
|
||||
if panel.childWindows?.contains(where: \.isVisible) == true {
|
||||
return
|
||||
}
|
||||
close()
|
||||
}
|
||||
|
||||
/// While the panel is visible, a click sent to another app dismisses it. Global monitors do not
|
||||
/// receive events sent to this app, so clicks in the panel and its popover are ignored. The
|
||||
/// event itself is never read.
|
||||
private func installOutsideClickMonitor() {
|
||||
guard outsideClickMonitor == nil else { return }
|
||||
outsideClickMonitor = NSEvent.addGlobalMonitorForEvents(
|
||||
matching: [.leftMouseDown, .rightMouseDown, .otherMouseDown]
|
||||
) { [weak self] _ in
|
||||
Task { @MainActor [weak self] in
|
||||
guard let self, panel.isVisible else { return }
|
||||
close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func removeOutsideClickMonitor() {
|
||||
if let outsideClickMonitor {
|
||||
NSEvent.removeMonitor(outsideClickMonitor)
|
||||
self.outsideClickMonitor = nil
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
|
||||
func windowWillClose(_ notification: Notification) {
|
||||
removeOutsideClickMonitor()
|
||||
Task { await viewModel.close() }
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -29,7 +29,7 @@ c4a25b6c1207197109d12ea740dc15ad8aa75b6304d901110aa3e10570cd65a0 ./App/Onboardi
|
||||
ba9467153908c81fbb2497d5679642ae15c7b9fa23a10ca9b9ab678042aab222 ./App/Onboarding/README.md
|
||||
eaf54c09c3df9847f456cb81f198df3b82fa53f02f1fad4918af5549e92ddc7c ./App/Panel/LanguagePickerView.swift
|
||||
76dcf59e01ae8319d4f0aabc5e600c549adaf56b6db802794804c3215be9377c ./App/Panel/MarkdownTranslationView.swift
|
||||
267c008ba680bc49f2397bf01a667fa7594177cdb2333ea190cfff36a5fa3174 ./App/Panel/PanelController.swift
|
||||
0d8e9dd5c361987e717e5425cb3a4bef2849a3ba5f40d302a4074f4847abf45b ./App/Panel/PanelController.swift
|
||||
aa364e7cb6373cdeaea0c24f59c959ebcdca228be21a27c6fae431463a6d2c04 ./App/Panel/PanelView+Content.swift
|
||||
278b9bd96ffe8c322703dec7c660632351c8e9a1996b0ee5713299f3de4ae082 ./App/Panel/PanelView.swift
|
||||
bd37b327672595d55c263f109005b816406cce5928ac58c66286cee0f5d16531 ./App/Panel/README.md
|
||||
@@ -251,11 +251,11 @@ 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
|
||||
38541779aa6190cc99d81ad16f98693a6fa00f14e9fa166dd36339cfe23865fc ./docs/ARCHITECTURE.md
|
||||
3b7b1fe301c5f715c6f4f74cc553a907c1ae89e669d5625d414dc3dae51d0216 ./docs/ARCHITECTURE.md
|
||||
018c5faf1a5d2e8d851ab209d45e64993cbd6b7976c4aa90c571359c83e83264 ./docs/CODING_STANDARDS.md
|
||||
c39bba389cc023831dab2244f475eb7707320686f98633b6923ea04347b83aed ./docs/DECISIONS.md
|
||||
017ff14372220594a25a9d139145fa6cf05a3b50ddd2d1f54f8e98b6fe6463c9 ./docs/DECISIONS.md
|
||||
5b80ea8994519f2be34aa10abb345ac3029d3d3a29705dcfa0a1cb344f4b95d2 ./docs/HYMT3_MODEL.md
|
||||
d87fc9df926f6ba77ce67b2731b83f48f2b49848c637f12d0fdfb5f27f3c6775 ./docs/IMPLEMENTATION_PLAN.md
|
||||
c3a1838fb0a06acf6b7826f6ff278e15065af198dab22ffb1435dacdc064ad69 ./docs/KICKOFF.md
|
||||
@@ -265,12 +265,12 @@ a28161210fbabe27d1348f3552851fe7b30c9dccc658272f2cc79af5e085ec40 ./docs/MODEL_E
|
||||
e6dbccc3cb4c7a169a6daaa563066a6764a76b6b7649738b839dcbd9b2400ee5 ./docs/OPENCODE_V2.md
|
||||
e2b785807ecb56eb1e7c02aaa6a487ce7c1be421865685bed4be2e973269bdce ./docs/PERFORMANCE.md
|
||||
4a37cf1815071b3afdd10443ec9e05a5a78411d615c42f51117c5873922531c4 ./docs/PRD.md
|
||||
70b7be815282fa6d25beb4ce805f6ac47f45878b16621798ed6a4ac1e294011f ./docs/PROGRESS.md
|
||||
7e55a36c4785c77009797f32ef0837be68168d35feab9bf4803484b4df8cd203 ./docs/SECURITY_PRIVACY.md
|
||||
e6208158c5230a63ddcf5fca4f6a7f9559f34c7026a5310398891955c6277b89 ./docs/PROGRESS.md
|
||||
c72f39e7e5e1fb9c45c32f0741a379564debca4b408e702615d162f360d47ecf ./docs/SECURITY_PRIVACY.md
|
||||
2e6c7ba67d857db7cddf1e31b5a6516f70b8094e9115094b58156f9e6626452c ./docs/SELECTION_AND_CLIPBOARD.md
|
||||
8720e8bf79ba7ab051bb8bd09f55b7766f98941904f354cbe3ab7b88c941e860 ./docs/TESTING.md
|
||||
d86aa67b08549ecce44e14d1e4fde0050ea5e89f77643733efd312fa42ef4e25 ./docs/TRANSLATION_OUTPUT.md
|
||||
8a5dce4b34d9c4630dcf42006970c7cc624e16281af37b023e3563c946d1aa7a ./docs/USER_GUIDE.md
|
||||
d59e6bf414777e4a068b08c2e81fcc3dee220034f0916e3867f338c4b7e6f4a3 ./docs/USER_GUIDE.md
|
||||
373b20746a6ed145ee598786458a97cead5cacd97a339db14b3e2341645c6c8d ./evaluation/README.md
|
||||
a60f1917c64ac8c3df0d01dd55818652ae100a6d750c34be24675b33226cad45 ./evaluation/corpus.example.json
|
||||
a5c4b95257aa02eca20ae98acf68dee329acb870f16fb3ac549038627327da71 ./evaluation/corpus.schema.json
|
||||
|
||||
@@ -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.
|
||||
@@ -554,7 +554,7 @@ stateDiagram-v2
|
||||
| Onboarding | `NSWindow` (not a SwiftUI `Window` scene) | Ollama reachable + version, Hy-MT3 installed, target language, optional Accessibility for Replace; each with a fix button |
|
||||
| Diagnostics | Window from the menu | Server version, model digests, last 50 timings and error kinds; copy as text; no text or translations |
|
||||
|
||||
Panel keyboard: **Esc** close, **⌘C** copy translation, **⌘↩** Replace, **⌘R** retry, **⌘,** Settings. The panel is made key when shown (unless the setting is off) so Esc and the shortcuts work without a click; the app is still not activated, the source app remains frontmost and owns the menu bar, and clicking the source app takes keyboard focus back. While the panel is key it receives keystrokes, so a user who types immediately after triggering should disable the Esc-on-show setting. The whole header bar (full width, flush with the top edge) moves the panel; the drag view moves the window itself from the screen-space mouse delta because `performDrag` does nothing while the app is inactive; moving it keeps its position while it stays open, and a newly shown panel is placed near the cursor (DeepL-like transient position). The translation text size is a Settings value.
|
||||
Panel keyboard: **Esc** close, **⌘C** copy translation, **⌘↩** Replace, **⌘R** retry, **⌘,** Settings. The panel is made key when shown (unless the setting is off) so Esc and the shortcuts work without a click; the app is still not activated, the source app remains frontmost and owns the menu bar, and clicking the source app takes keyboard focus back. A click sent to another app dismisses the panel; while the panel is visible a transient mouse-down monitor observes only that the click went to another app, discards the event and is removed on close. While the panel is key it receives keystrokes, so a user who types immediately after triggering should disable the Esc-on-show setting. The whole header bar (full width, flush with the top edge) moves the panel; the drag view moves the window itself from the screen-space mouse delta because `performDrag` does nothing while the app is inactive; moving it keeps its position while it stays open, and a newly shown panel is placed near the cursor (DeepL-like transient position). The translation text size is a Settings value.
|
||||
|
||||
Accessibility: every control has an `accessibilityLabel`; the panel exposes source and translation as read-only text elements; full keyboard navigation; respects Reduce Motion and Increase Contrast.
|
||||
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ Status: Accepted (amended 2026-11-26: Esc without a click)
|
||||
|
||||
Context: The app must be available over any app and must not activate itself or take application focus from the selection. A regular Dock app with a window would interrupt the workflow. Users also expect Esc to dismiss a transient panel immediately, which requires the panel to be the key window.
|
||||
Decision: Use `LSUIElement = YES`, a `MenuBarExtra`, and a floating `NSPanel` with `.nonactivatingPanel` and `becomesKeyOnlyIfNeeded = false`. Never call `NSApp.activate` or `makeKeyAndOrderFront` for the translation panel. Onboarding and Settings are the only surfaces that activate the app. By default the panel calls `makeKey()` when shown, so Esc and the keyboard shortcuts work immediately; the setting `closeWithEscape` can restore click-first behaviour. The panel's SwiftUI exit command handles Esc and calls the same close path that cancels an in-flight request.
|
||||
Consequences: The app stays unactivated: `NSWorkspace.frontmostApplication` and the menu bar stay with the source app, and Replace still re-verifies that app. While the panel is visible it holds keyboard focus, so keystrokes and shortcuts go to the panel until the user clicks back into the source app; the setting turns this off. Every action still has a button.
|
||||
Consequences: The app stays unactivated: `NSWorkspace.frontmostApplication` and the menu bar stay with the source app, and Replace still re-verifies that app. While the panel is visible it holds keyboard focus, so keystrokes and shortcuts go to the panel until the user clicks back into the source app; the setting turns this off. A click outside the panel dismisses it: the panel observes `didResignKey` and, while visible, a transient global mouse-down monitor. Global monitors do not receive events sent to this app, so clicks in the panel and its popover are ignored; the event is discarded and the monitor is removed on close. The monitor is not a key tap and needs no Input Monitoring. Every action still has a button.
|
||||
|
||||
## ADR-010 — Native OpenCode 2.x configuration
|
||||
Status: Accepted
|
||||
|
||||
@@ -155,3 +155,4 @@ Legend: `[ ]` open · `[~]` in progress · `[x]` done · `[!]` blocked (explain)
|
||||
2026-11-26 · Panel · Fixed dragging: `performDrag` was a no-op while the non-activating panel's app is inactive, so `WindowDragArea` now moves the window from the screen-space mouse delta. The drag surface is a full-width 56 pt header bar flush with the panel top; buttons stay clickable above it. Verified with synthetic drags from the title, top edge, empty header and grip while Finder was frontmost.
|
||||
2026-11-26 · Panel · Esc now closes the panel without a click: `TranslationPanel` becomes key on show without activating the app (`frontmostApplication` and the menu bar stay with the source app), and `keyDown` handles keyCode 53. Added the `closeWithEscape` setting (default on) and amended ADR-009.
|
||||
2026-11-26 · Panel · Markdown translations render with headings, bold/italic, inline code, lists, quotes, fenced code, rules and http/https links. `MarkdownPresentation` rejects JSON/HTML/code and only renders with the `renderMarkdown` setting (default on); Copy/Replace stay raw. Added ADR-021 and tests.
|
||||
2026-11-26 · Panel · A click outside the panel now closes it. The panel observes `didResignKey` and installs a transient global mouse-down monitor while visible; global monitors ignore events sent to this app, so panel/popover clicks are unaffected, and the monitor is removed on close. Verified: inside click keeps it open, outside click closes it with and without `closeWithEscape`, and an outside click while the language popover is open closes both.
|
||||
@@ -40,6 +40,7 @@ These are hard requirements. The `swift-reviewer` agent checks every change agai
|
||||
| Screen Recording | Nothing | Never requested. No screenshots, no `CGWindowListCreateImage`, no `SCStream`. |
|
||||
| Camera / Microphone | Nothing | Never requested. No `AVCaptureDevice`. |
|
||||
| Apple Events | Nothing | Never requested. No `NSAppleScript` / `AEDeterminePermissionToAutomateTarget`. |
|
||||
| Global mouse-down monitor | Dismiss the translation panel when the click goes to another app | Installed only while the panel is visible and removed on close. The event is discarded; no key events, location, text or app identity are read. Not a key tap and needs no Input Monitoring. |
|
||||
|
||||
## Clipboard rules
|
||||
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ the Hy-MT3 model and the target language. You can reopen setup from the menu bar
|
||||
|
||||
1. Select text in any app.
|
||||
2. Press **⌘C** twice quickly (within 500 ms).
|
||||
3. The floating panel appears near the mouse. The source app stays frontmost; the panel takes keyboard focus while it is visible so Esc and the shortcuts work immediately. Clicking the source app takes focus back.
|
||||
3. The floating panel appears near the mouse. The source app stays frontmost; the panel takes keyboard focus while it is visible so Esc and the shortcuts work immediately. Clicking the source app takes focus back. Clicking anywhere outside the panel closes it; Esc also closes it.
|
||||
4. The translation streams in. Use the language picker to change the target.
|
||||
5. Click **Copy** to put the translation on the clipboard, or **Replace** to replace the selection.
|
||||
6. **Esc** closes the panel. **⌘C** copies, **⌘↩** replaces, **⌘R** retries and **⌘,** opens Settings.
|
||||
|
||||
Reference in new issue
Block a user