Files
schihei 2a601058f4 feat(capture): translate long selections in parts
The capture gate and the chunk size were the same number, so a selection above one chunk was rejected before the pipeline could split it; the Settings sliders moved both thresholds together. Add maximumPartsPerSelection (1-8, default 1, so existing behaviour is unchanged). The capture limit is now part size x parts and travels on TranslationSessionRequest, so the watcher, CapturePolicy and TranslationSession agree for that capture. TranslationStreaming gained an optional per-part callback; the session emits chunkStarted and the panel shows 'Part 2 of 4' while streaming and '2 parts' when finished. textTooLong now points at Settings and offers an Open Settings button. Lower the dense-script part-size maximum to 4000 because 5000 dense characters plus a 4096-token output can overflow the 8192-token context. Tests cover capture limits, watcher limits, pipeline part callbacks, session events and limits, panel progress, settings clamping and migration. Docs updated: ADR-011, TRANSLATION_OUTPUT, SELECTION_AND_CLIPBOARD, ARCHITECTURE, LANGUAGES and README. Verified: make verify green; live 4355-character German text showed Part 1 of 2, Part 2 of 2 and '2 parts'; with one part the panel showed the too-long message and Open Settings.
2026-11-27 20:21:30 +01:00

163 lines
22 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Progress
The agent updates this file at the end of every task: check the box, add the ISO date, add one line of notes (deviations, follow-ups). Do not delete history.
Legend: `[ ]` open · `[~]` in progress · `[x]` done · `[!]` blocked (explain)
## M0 — Scaffold and tooling
- [x] T0.1 Package.swift, module placeholders, fixtures load — 2026-11-26
- [~] T0.2 App sources, Info.plist, menu-bar stub, entitlements — 2026-11-26 · signatures automated; visual menu-bar/Settings/Quit confirmation pending
- [x] T0.3 project.yml / XcodeGen — 2026-11-26
- [x] T0.4 verify script, format/lint, logging + signposts — 2026-11-26
- [~] T0.5 OpenCode 2.x doctor — 2026-11-26 · doctor green; `/status` needs an interactive TUI run
- [x] T0.6 Environment record and smoke run — 2026-11-26
## M1 — Ollama text client
- [x] T1.1 Capture fixtures, resolve VERIFY items — 2026-11-26 · 7B resolved; 1.8B deferred
- [x] T1.2 HTTP client, endpoint policy, redirects, error mapping — 2026-11-26
- [x] T1.3 Catalog (version, tags, show, ps) — 2026-11-26
- [x] T1.4 Streaming chat client (NDJSON, timeouts, cancellation) — 2026-11-26
- [x] T1.5 Warm-up, keep-alive, unload — 2026-11-26
- [x] T1.6 sprachmittler-cli models / show / translate — 2026-11-26
## M2 — Hy-MT3 adapter and text pipeline
- [x] T2.1 Adapter protocol, registry, sampling merge — 2026-11-26
- [x] T2.2 Hy-MT3 adapter and byte-exact prompt — 2026-11-26
- [x] T2.3 Language catalogue (102 languages) — 2026-11-26
- [x] T2.4 Language detection, content classifier, chunker — 2026-11-26
- [x] T2.5 Protected tokens, output validator, preamble detector — 2026-11-26
- [x] T2.6 Prompt policy and documented fallbacks — 2026-11-26
- [x] T2.7 Compatibility spike (gate) — 2026-11-26 · 7B passed; 1.8B not installed
## M3 — Double-copy capture
- [x] T3.1 DoubleCopyDetector state machine — 2026-11-26
- [x] T3.2 Pasteboard watcher and own-write suppression — 2026-11-26
- [x] T3.3 Clipboard snapshot and restore — 2026-11-26
- [x] T3.4 Services provider and menu item — 2026-11-26
- [~] T3.5 Manual double-copy matrix — 2026-11-26 · code complete; 10-app matrix needs a person
## M4 — Translation session and panel
- [x] T4.1 TranslationSession actor and epochs — 2026-11-26
- [~] T4.2 Panel controller and view model — 2026-11-26 · code/test complete; manual focus/position pending
- [~] T4.3 Panel view with Copy and Replace — 2026-11-26 · code complete; manual streaming/Copy/Replace pending
- [x] T4.4 Target language, persistence, same-language — 2026-11-26
- [x] T4.5 Error messages and recovery actions — 2026-11-26
- [~] T4.6 Panel keyboard and accessibility — 2026-11-26 · shortcuts/labels in code; VoiceOver manual pending
## M5 — Replace
- [x] T5.1 InsertionCoordinator and target capture — 2026-11-26
- [x] T5.2 Accessibility direct replacement — 2026-11-26
- [x] T5.3 Paste fallback and clipboard restore — 2026-11-26
- [x] T5.4 Safety checks and Copy fallback — 2026-11-26
- [~] T5.5 Manual insertion matrix and permission onboarding — 2026-11-26 · 10-app matrix needs a person
## M6 — Settings, onboarding, menu bar
- [x] T6.1 AppSettings and persistence — 2026-11-26
- [~] T6.2 Onboarding checks and window — 2026-11-26 · code complete; manual checks pending
- [~] T6.3 Settings UI — 2026-11-26 · code complete; manual endpoint/licence checks pending
- [~] T6.4 Status menu, launch at login, diagnostics — 2026-11-26 · code complete; manual login/diagnostics checks pending
- [~] T6.5 End-to-end integration checkpoint (gate) — 2026-11-26 · needs the user's manual 10-app pass
## M7 — Evaluation and the default-model gate
- [x] T7.1 Corpus manifest and eval CLI — 2026-11-26
- [x] T7.2 Metrics — 2026-11-26
- [x] T7.3 Reports — 2026-11-26
- [~] T7.4 Evaluation run — 2026-11-26 · synthetic harness validated; private corpus and 1.8B still needed
- [~] T7.5 Default-model ADR (gate) — 2026-11-26 · blocked on T7.4 and user decision
## M8 — Hardening and release
- [x] T8.1 Privacy audit and self-test — 2026-11-26
- [~] T8.2 Accessibility pass — 2026-11-26 · labels/keyboard in code; VoiceOver manual
- [~] T8.3 Performance pass — 2026-11-26 · app/7B measured; panel/Copy/Replace/1.8B unmeasured
- [x] T8.4 German localisation and end-user README — 2026-11-26 · user review pending
- [x] T8.5 Release script — 2026-11-26 · dry-run; credentials/notarisation manual
- [~] T8.6 Compatibility matrix completion — 2026-11-26 · 10-app matrix needs a person
## Environment record
| Item | Value | Date |
|---|---|---|
| OpenCode version | 2.4.1 | 2026-11-26 |
| Ollama version | 0.40.18 | 2026-11-26 |
| Translation model | `hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M` (7.5B, Q4_K_M) | 2026-11-26 |
| Model resident memory | 6.49 GB with `num_ctx` 8192 | 2026-11-26 |
| Mac (chip, memory) | Apple M5 Pro, 48 GB | 2026-11-26 |
| macOS | 27.2.1 (26B131) | 2026-11-26 |
| Xcode / Swift | Xcode 27.2 / Swift 6.4.2 | 2026-11-26 |
| Reference speed | 246 output tokens in 6.52 s, 44.6 tok/s | 2026-11-26 |
## Notes log
<!-- YYYY-MM-DD · T<m>.<n> · note -->
2026-11-26 · kit · Package scaffold, docs and OpenCode 2.x configuration created. Package build/test and app build verified.
2026-11-26 · kit · Canonical prompt validated against the real 7B model: 178 prompt tokens, 246 output tokens, 44.6 tok/s. URL, e-mail, `{{placeholder}}`, Markdown and JSON preservation checked with the default prompt.
2026-11-26 · kit · Owner reference run recorded: 255 output tokens, 43.07 tok/s, 5.97 s warm, 177/178 prompt tokens cached.
2026-11-26 · kit · `make smoke` passed with 7B Q4_K_M: 34 output tokens in 2.89 s, 45.81 tok/s, cold load 2.05 s.
2026-11-26 · kit · `make fixtures` captured version, tags, ps, show, en→de, de→en, Markdown, truncated and missing-model fixtures. Digest `262ac792aeb5`.
2026-11-26 · T0.1 · Verified `swift build` and `make test`; the text and Ollama fixture-loading tests pass through `Bundle.module`. Placeholder enums stay until their modules gain real types.
2026-11-26 · T0.2 · Debug + Release builds and signatures pass via `scripts/check-signature.sh`; an install-style re-sign preserves only `app-sandbox=false` plus Hardened Runtime. The app launches as a `UIElement` (no Dock icon); visual menu-bar/Settings/Quit confirmation is still pending.
2026-11-26 · T0.3 · `xcodegen generate` and Debug/Release `xcodebuild` pass; the generated project stays git-ignored. Bundle prefix remains the provisional `de.schihei`.
2026-11-26 · T0.4 · Added the 9 `os.Logger` categories, 8 `OSSignposter` intervals and a 12-hex `shortHash`; contract tests pass. `verify.sh` now lints Tests and checks Debug + Release signatures; `make install` preserves entitlements and Hardened Runtime. Leaf logging seam for M1/M2 is documented; `shortHash` must be logged with `privacy: .private`.
2026-11-26 · T0.5 · `make doctor` green; native V2 config resolves; agents/commands/skills and the `/status` command file are present. `/status` itself still needs one interactive TUI run.
2026-11-26 · T0.6 · `make smoke` with 7B Q4_K_M: 35 output tokens, 0.86 s warm, 46.96 tok/s, URL preserved. Environment table was already filled.
2026-11-26 · T1.1 · Re-ran `make fixtures` with the 7B (digest `262ac792aeb5`); every fixture < 200 KB and the new contract tests pass. `keep_alive:"0"` unloads immediately; `done_reason` observed `stop`/`length`; a client abort returns no final object. 1.8B VERIFY deferred to T2.7/T7.4.
2026-11-26 · T1.2 · Added `EndpointPolicy`, ephemeral/redirect-refusing `OllamaHTTPClient`, error-body parsing and the Core `SprachmittlerError` mapper. Endpoint, redirect, session and error tests pass; CLI unreachable exits 3.
2026-11-26 · T1.3 · Added `InstalledModel`/`ModelDetails`/`LoadedModel`, `OllamaVersion` and the actor `OllamaCatalogClient` with per-digest show caching and `refresh()`. Filter, `:latest`, parameter, cache and version tests pass.
2026-11-26 · T1.4 · Added the streaming `OllamaChatClient`: NDJSON lines, split-line handling, `done_reason`/metrics, mid-stream errors, first-token/idle/total timeouts with `ManualSleeper`, and cancellation that stops the URL task. All transport/chat tests pass.
2026-11-26 · T1.5 · Added the provisional Engines slice (`ModelLanguage`, 16 common names, byte-exact Default prompt, documented options, request factory) and the loopback-only warm-up policy. Warm-up uses fixed `Hello.` and `num_predict: 8`; unload uses `keep_alive:"0"`.
2026-11-26 · T1.6 · Implemented `sprachmittler-cli models`, `show` and `translate` (`--text/--file`, `--target`, `--model`, `--json`, `--include-source`). Live 7B checks: models/show, en→de text, JSON with null sourceLanguage/empty warnings, unreachable exit 3. The 102-language catalogue remains T2.3.
2026-11-26 · M1 · Review fixes: 180 s URLSession request/resource budget (no 60 s pre-emption), missing-`done` is an error, CLI diagnostics go to stderr and endpoint rejection exits 2, `CLIEnvironment` is the composition root, and cancellation/URL-task-stop tests are deterministic. Both reviewers approved.
2026-11-26 · T2.1 · Added `AdapterRequest`/`TranslationAdapter`/`AdapterRegistry`, `SamplingOptions` + overrides, and exact wire-option tests. Prompt literals remain only in Engines.
2026-11-26 · T2.2 · `HyMT3Adapter` builds one user message, publisher sampling, `num_ctx: 8192`, no system/think; byte-exact golden tests for Default, Delimiters and Structured Data 1.
2026-11-26 · T2.3 · `HyMT3Languages` now has all 102 entries with exact model names, BCP-47 variants (`zh-Hant`, `pt-BR`, `nb`/`nn`, `kk-Cyrl`, `mn-Cyrl`, `ku`/`ckb`), RTL and dense-script flags.
2026-11-26 · T2.4 · Added `TextNormalization` (N1–N3, T1), `NaturalLanguageDetector`, `ContentClassifier` and the script-aware `Chunker`; join round-trips exactly, grapheme clusters are never split.
2026-11-26 · T2.5 · Added `ProtectedTokenScanner` for all ten token kinds, `OutputValidator` for empty/preamble/truncation/repetition/token/number checks, and a streaming repetition detector. No output is rewritten.
2026-11-26 · T2.6 · Added `PromptPolicy`: Default first, one documented Delimiters/Structured Data 1 retry only after a lost protected token. `TranslationPipeline` (Core) enforces the one retry and joins chunks with the source separators.
2026-11-26 · T2.7 · 7B spike: en→de, de→en, Markdown, JSON, placeholders and a 4,315-char long text passed with no warnings; an 8,785-char repetitive source hit the repetition guard. Results and timings are in `HYMT3_MODEL.md` §7. The 1.8B spike still needs the model.
2026-11-26 · T3.1 · Added the pure `DoubleCopyDetector`: 500 ms default window, identical text after line-ending/outer-trim normalisation, duplicate changeCount ignored, reset rules.
2026-11-26 · T3.2 · Added `PasteboardWatcher` (120 ms injected ticker, read only after a change, 750 ms own-write suppression, 4000/2000 script limits, clear on stop) and `SystemPasteboard`.
2026-11-26 · T3.3 · Added `ClipboardSnapshot`/`ClipboardItemData`: all items and types, forced lazy data, restore only when `changeCount` still matches, own/transient/concealed markers on writes.
2026-11-26 · T3.4 · Added `ServicesProvider` and wired `NSApp.servicesProvider` + `NSUpdateDynamicServices`; the menu-bar “Translate Clipboard Text” item now delivers a `.menu` capture. The app has a log-only sink until the M4 panel.
2026-11-26 · M3 · The capture matrix (T3.5) is intentionally still unchecked; it needs a person in 10 real apps. No Accessibility is requested on the double-copy or Services path.
2026-11-26 · M2/M3 · Review fixes: `OllamaError` is mapped to `SprachmittlerError` at the Core boundary and the CLI maps domain errors to exit 2/3/4; the chunker preserves leading empty separators; `LanguageMatching` moved to Engines and `keepAlive` is supplied by the composition root; `CapturePolicy` enforces the 4000/2000 limit and own markers for menu/Services; golden prompt tests remove exactly one fixture terminator; docs aligned (TestSupport deps, warning enum, 15 common targets, Fixtures path).
2026-11-26 · T4.1 · Added `TranslationSession` actor with epochs, one in-flight task, delta forwarding, cancellation and stale-event dropping; tests cover streaming, replacement, cancel and factory failures.
2026-11-26 · T4.2 · Added `PanelViewModel` in Core and a non-activating `NSPanel` controller in the app; the panel positions near the mouse and never calls `NSApp.activate`.
2026-11-26 · T4.3 · Added the SwiftUI panel: source preview, streaming translation, warning/error banners, Copy, Retry, Replace, close; Replace is disabled while translating and for blocking warnings.
2026-11-26 · T4.4 · Added searchable language picker, recent targets, target persistence and retranslation on change; same-language advisory with “Translate anyway”.
2026-11-26 · T4.5 · Added `SprachmittlerError.userMessage`, `RecoveryAction` and an exhaustive test; raw server/model text is never shown.
2026-11-26 · T4.6 · Added Esc, ⌘C, ⌘↩, ⌘R, ⌘, paths and accessibility labels; VoiceOver verification remains manual.
2026-11-26 · T5.1 · Target provider captures the frontmost PID/bundle at trigger and reads only the focused selection when Accessibility is trusted; the coordinator verifies the target again at Replace.
2026-11-26 · T5.2 · Added `AXTextEditor` (focused element, selected text, secure-field check, direct set) behind a testable protocol; AX work runs on an actor, never the main actor.
2026-11-26 · T5.3 · Added `CGEventPoster` ⌘V to the target PID, full snapshot/write/restore and a 300 ms settle; own writes suppress the watcher.
2026-11-26 · T5.4 · Added `InsertionPolicy` frontmost/selection checks, secure-field refusal, self-insertion refusal, blocking-warning gate and Copy fallback.
2026-11-26 · T5.5 · The insertion matrix and real-app permission flow remain manual; unit/component tests cover the strategies and failure paths.
2026-11-26 · T6.1 · Added versioned `AppSettings` with v0 migration, clamping, unknown-key tolerance, recent targets, `SettingsStore` over a UserDefaults seam and reset.
2026-11-26 · T6.2 · Added onboarding for Ollama/version, Hy-MT3 install, target and optional Accessibility, with fix actions; first-run and menu reopen wired.
2026-11-26 · T6.3 · Added General/Model/Translation/Privacy/Diagnostics tabs, endpoint validation, model/digest/licence display and reset.
2026-11-26 · T6.4 · Added the status menu (translate, target, copy/replace last, setup, diagnostics, about, settings, quit), launch-at-login via `SMAppService`, and a text-free diagnostics window.
2026-11-26 · T6.5 · The end-to-end gate is ready to run but not marked complete: it needs the user's manual double-copy → panel → Copy/Replace pass.
2026-11-26 · M4/M5/M6 smoke · Launched the Debug app and sent two identical clipboard copies; the non-activating panel appeared on screen without a crash. Full focus, Copy/Replace, VoiceOver, onboarding and 10-app matrices remain manual.
2026-11-26 · M4/M5/M6 review · Cleared the previous translation when a new capture arrives (menu Replace cannot pair old text with a new selection); restored the clipboard on cancelled/failed paste; reset the panel before showing a new capture; mapped blocked Replace to the real warning; mapped endpoint/transport errors in onboarding and settings; surfaced launch-item errors; moved Fast-model detection to Engines; suppressed retry deltas and streamed chunk separators; made settings updates atomic and fastModel nullable; fixed refresh endpoint validation; localized warning strings; used the captured selection for an early safety check; the event observer now sees only current-epoch events and only a validated `.ready` result can become the status-menu last translation; insertion-target enrichment is generation-guarded. `make verify` green.
2026-11-26 · T7.1 · Added `sprachmittler-cli languages`, `detect` and `eval`; manifest decoding/validation, relative path loading, target filtering and precise errors.
2026-11-26 · T7.2 · Added chrF, BLEU, protected-token retention, numeric consistency and latency percentiles with hand-computed tests.
2026-11-26 · T7.3 · Added `report.md`/`report.json` with environment, per-category tables, observations and limitations; raw outputs stay under the ignored results path.
2026-11-26 · T7.4 · Ran the eval harness on a synthetic 4-segment manifest with the 7B: 0% failures, token retention 1.0, chrF 61–96, first token 57–102 ms. The private corpus and 1.8B comparison remain pending; this is not a default decision.
2026-11-26 · T7.5 · ADR-008 remains Proposed. The gate needs the private corpus report, 1.8B numbers and the user's decision; docs still label the 7B provisional.
2026-11-26 · T8.1 · Extended `privacy-check.sh` for the evaluation harness and added `privacy-self-test.sh`, which seeds and detects every major SP rule; wired into `make verify`.
2026-11-26 · T8.2 · Added accessibility labels to panel/settings/onboarding controls and keyboard paths; VoiceOver, Reduce Motion and Increase Contrast remain manual.
2026-11-26 · T8.3 · Measured idle CPU 0.1%, app RSS ≈84.9 MB, 7B first token 57–102 ms and 0.45–0.91 s warm on the synthetic eval. Panel/Copy/Replace signposts and 1.8B remain unmeasured.
2026-11-26 · T8.4 · Added English/German `Localizable.strings` for the app shell and `docs/USER_GUIDE.md` (install, permissions, privacy, troubleshooting).
2026-11-26 · T8.5 · Added `scripts/release.sh` (archive unsigned, Developer ID sign, notarise/staple, DMG, `--dry-run`) and `make release`.
2026-11-26 · T8.6 · The compatibility matrix remains a manual 10-app pass; no untested cell is claimed.
2026-11-26 · T8.5 · Added a sibling-family app icon (`make icon`), `CFBundleIconName`/asset catalog wiring, `make install` from the Release build, and `make dmg`/`scripts/make-dmg.sh` with a mounted-image signature check. Dry-run release and local DMG/install were verified.
2026-11-26 · M4 polish · Enlarged the drag surface to the whole left header block, with a visible grip backed by an AppKit `performDrag` area; the panel keeps a moved position while visible and only recenters near the cursor when shown again. Added a persisted `translationFontSize` setting (default 17 pt, 12–28) with a Settings stepper and applied it to the translation text.
2026-11-26 · Panel · The source section now stays available as a collapsed “Show source” disclosure row after the user collapses it, instead of disappearing.
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.
2026-11-26 · Panel · Added an optional reverse direction: with the saved target German and fallback English, confidently German text is translated to English automatically, and vice versa. The saved target and effective target are separate; a banner offers a one-capture override, and the language picker still changes the saved target. `autoSwitchTarget` defaults on and `fallbackTargetLanguage` defaults to English/the opposite language. Filtered near-zero detector hypotheses so the high-confidence same-language rule works. Added resolver, settings, view-model and detector tests. (Superseded by the routing entry below.)
2026-11-26 · Settings · Replaced the single reverse-direction pair with language routing: the saved target is the mother tongue and the default for every source; an empty `languageRoutes` table means everything goes to the mother tongue. Optional source→target rules (for example Chinese → English) apply only to confidently detected sources. The panel shows the effective direction, offers a one-capture override, and keeps the picker session-only; persistent rules live in Settings. Removed the old fallback settings.
2026-11-27 · Panel · Fixed the header language picker: an override now carries the chosen language instead of only disabling routing. `TranslationDirectionPolicy.resolve` takes `override: ModelLanguage?`, and `PanelViewModel` stores the override target, so picking a language other than the mother tongue retranslates into it; a new capture still returns to the rule/mother tongue. Added picker and rule-override tests.
2026-11-27 · T3.2/T4.1/Settings · Long selections can now be translated in parts. The capture gate and the chunk size were the same number, so text over one chunk was rejected before the pipeline could split it. Added `maximumPartsPerSelection` (1–8, default 1, so existing behaviour is unchanged); the capture limit is now part size × parts, carried on `TranslationSessionRequest` and applied by the watcher, `CapturePolicy` and the session. `TranslationStreaming` can report each part, the session emits `chunkStarted`, and the panel shows “Part 2 of 4” while streaming and “3 parts” when finished. `textTooLong` now points at Settings and offers the Settings button. Lowered the dense-script part size maximum to 4000 (5000 dense characters plus a 4096-token output can overflow the 8192 context). Tests: capture limits, watcher limits, pipeline part callbacks, session events, panel progress and settings clamping. Docs: ADR-011, TRANSLATION_OUTPUT, SELECTION_AND_CLIPBOARD, ARCHITECTURE, LANGUAGES, README.