feat(m2-m3): adapter, text pipeline, double-copy capture and Services (T2.1-T2.7, T3.1-T3.4)

M2: TranslationAdapter/AdapterRegistry with documented Hy-MT3 prompts and publisher sampling; all 102 languages with BCP-47 variants, RTL and dense-script flags; normalisation, NLLanguage detection, content classification and exact-join script-aware chunking; protected-token scanning and output validation; prompt policy with one documented fallback; shared TranslationPipeline with Core error mapping. The CLI now reports sourceLanguage and warning codes.

M3: pure DoubleCopyDetector, 120 ms PasteboardWatcher with 750 ms own-write suppression, SystemPasteboard snapshot/restore and markers, CapturePolicy for the 4000/2000 limits, ServicesProvider and the menu-bar action. T3.5 (10-app manual matrix) remains intentionally open.

Docs: ARCHITECTURE, TRANSLATION_OUTPUT, HYMT3_MODEL (§7 spike), SELECTION_AND_CLIPBOARD, PROGRESS; ADR-016 superseded by ADR-017/018.

Verified: make verify green (format, strict lint, scripts, privacy, Debug+Release signatures, package tests); live 7B CLI en→de/de→en/Markdown/JSON/placeholders; empty input exits 2 and unreachable exits 3.
This commit is contained in:
schihei committed 2026-11-26 13:30:32 +01:00
1 parent 26b493e7e5
commit 64078e2f04
80 files changed
+4090 -325

No files matched your search

+36 -20
View File
@@ -145,7 +145,7 @@ flowchart TD
- `SprachmittlerCapture` is the only module that imports `ApplicationServices`/`Accessibility` and touches `NSPasteboard`. It depends on `SprachmittlerCore` for domain types and protocols.
- `SprachmittlerEval` is linked into the CLI only, never into the app.
- `sprachmittler-cli` links `SprachmittlerOllama` and `SprachmittlerEngines` directly for the M1 commands; it is never linked into the app.
- `SprachmittlerTestSupport` is test-only and depends on `SprachmittlerCore` and `SprachmittlerOllama`; it is never linked into the app.
- `SprachmittlerTestSupport` is test-only and depends on `SprachmittlerCore`, `SprachmittlerCapture` and `SprachmittlerOllama`; it is never linked into the app.
- The `App` target holds no business logic. Anything with a branch worth testing belongs in a package module.
### Third-party dependencies
@@ -163,16 +163,18 @@ All other functionality uses Apple frameworks. No keyboard-shortcut library is n
```swift
// SprachmittlerCore
public struct LanguageCode: RawRepresentable, Hashable, Codable, Sendable {
public let rawValue: String // "de", "en", "zh-Hant", "pt-BR", "kk-Cyrl"
}
// Defined in SprachmittlerEngines; re-exported by SprachmittlerCore.
public typealias LanguageCode = String // "de", "en", "zh-Hant", "pt-BR", "kk-Cyrl"
public struct TargetLanguage: Hashable, Codable, Sendable, Identifiable {
public struct ModelLanguage: Hashable, Codable, Sendable, Identifiable {
public let code: LanguageCode
public let modelName: String // exact English name from the model card, e.g. "German"
public let displayName: String // localised UI name
public var id: String { code.rawValue }
public let displayName: String // English fallback; localizedDisplayName for UI
public let isRTL: Bool
public let usesDenseScript: Bool
public var id: String { code }
}
public typealias TargetLanguage = ModelLanguage
public struct CapturedText: Sendable, Equatable {
public let text: String
@@ -210,14 +212,14 @@ public struct TranslationResult: Sendable, Equatable {
}
public enum TranslationWarning: Sendable, Equatable {
case preambleDetected(line: String)
case preambleDetected(firstLine: String)
case truncated
case repetitionLoop
case missingProtectedToken(String)
case emptyOutput
case sameLanguage(source: LanguageCode, target: LanguageCode)
case chunkFailed(index: Int)
case sameLanguage(source: String, target: String)
case numericMismatch
case chunkFailed(index: Int)
}
public struct TranslationTiming: Sendable, Equatable {
@@ -228,7 +230,7 @@ public struct TranslationTiming: Sendable, Equatable {
}
public enum InsertionOutcome: Sendable, Equatable {
case replaced(by: InsertionMethod) // .accessibility, .paste
case replaced(using: InsertionMethod) // .accessibility, .paste
case copiedOnly
case failed(SprachmittlerError)
}
@@ -238,6 +240,8 @@ public enum InsertionMethod: String, Sendable {
}
```
Language and warning value types live in `SprachmittlerEngines`, because they carry model-card names and validation results: `ModelLanguage` (re-exported as `TargetLanguage`) and `TranslationWarning`. `SprachmittlerCore` re-exports both for the session and UI. `TranslationPipeline` in Core owns chunk orchestration, the one documented retry and timing.
### Error taxonomy
```swift
@@ -332,18 +336,28 @@ Full detail: `docs/SELECTION_AND_CLIPBOARD.md`.
### 7.1 Double-copy watcher (`SprachmittlerCapture`)
```swift
public protocol PasteboardWatching: Sendable {
func events() -> AsyncStream<PasteboardEvent>
@MainActor public protocol PasteboardAccessing: AnyObject {
var changeCount: Int { get }
func string() -> String?
func containsOwnWriteMarkers() -> Bool
func snapshot() -> ClipboardSnapshot?
func restore(_ snapshot: ClipboardSnapshot, onlyIfChangeCountMatches: Int) -> Bool
@discardableResult func write(_ text: String) -> Int
}
public enum PasteboardEvent: Sendable, Equatable {
case changed(changeCount: Int)
case textAvailable(String)
case ignoredOwnWrite
public struct DoubleCopyDetector { /* pure state machine */ }
@MainActor public final class PasteboardWatcher {
init(pasteboard: any PasteboardAccessing,
ticker: any PasteboardTicking = TimerPasteboardTicker())
func start(onEvent: @escaping @MainActor (PasteboardWatcherEvent) -> Void)
func stop()
func clear()
func noteOwnWrite(at: Date)
}
```
- Poll `NSPasteboard.general.changeCount` on a `@MainActor` timer every **120 ms**.
- Poll `NSPasteboard.general.changeCount` every **120 ms** on the main actor through `PasteboardTicking`.
- A candidate trigger is two changes within **500 ms** (range 300–1000 ms, setting) whose `.string` values are identical and non-empty after trimming.
- Require at least one non-whitespace character and at most `maxCharacters` (4000 Latin / 2000 CJK by default).
- Ignore changes whose pasteboard contains the app's own marker (`com.schihei.sprachmittler.own`) or `org.nspasteboard.TransientType`, and ignore all changes for 750 ms after our own write.
@@ -461,6 +475,8 @@ Thresholds are constants in one file and covered by tests. Quality failures are
Full detail: `docs/TRANSLATION_OUTPUT.md`.
`TranslationPipeline` in `SprachmittlerCore` is the shared implementation used by the CLI and the M4 session: it normalises input, detects the language, classifies content, scans protected tokens, chunks, calls the adapter, joins chunk results with the original separators, validates once, and enforces the single documented retry.
### 9.1 Input analysis (`SprachmittlerText`)
1. Normalise line endings to `\n`; strip NUL and other C0 controls except `\t` and `\n`; NFC.
@@ -474,8 +490,8 @@ Full detail: `docs/TRANSLATION_OUTPUT.md`.
| Content | Prompt |
|---|---|
| Plain prose | Documented **Default Translation** |
| Markdown / JSON / HTML | Documented **Structured Data 1** with `format_type` |
| Placeholder- or delimiter-heavy | Documented **Delimiters** |
| Markdown / JSON / HTML | Documented **Default Translation** first; **Structured Data 1** is the single fallback after a lost token |
| Placeholder- or delimiter-heavy | Documented **Default Translation** first; **Delimiters** is the single fallback after a lost token |
| User glossary (future) | Documented **Terminology** |
| User style (future) | Documented **Style** |
+17 -3
View File
@@ -110,8 +110,22 @@ Decision: `TranslationSession` is an actor with one active request. A new trigge
Consequences: Fast, predictable updates and no orphaned requests. The previous translation is lost when the user triggers a new one; that is intentional and avoids history.
## ADR-016 — Provisional M1 Engines slice for the CLI
Status: Accepted (provisional; replaced in M2)
Status: Superseded by ADR-017
Context: T1.6 needs the documented Default prompt and the exact model language name before T2.2/T2.3 exist. Putting either in the CLI target would violate documented-prompts-only and the lint rule that prompt and language literals live in `SprachmittlerEngines`.
Decision: Add a provisional `ModelLanguage` with the 16 common targets from `LANGUAGES.md` §5, the byte-exact Default Translation prompt, the documented sampling values and `HyMT3RequestFactory` in `SprachmittlerEngines`. T2.3 replaces the table with all 102 languages; T2.1/T2.2 replace the factory with `TranslationAdapter`/`HyMT3Adapter`.
Consequences: The M1 CLI translates en→de and the other common targets without a free-form prompt. Unknown codes fail before the network. Only 16 targets resolve until T2.3, and no prompt literal or model tag appears outside Engines.
Decision: Add a provisional `ModelLanguage` with the 15 common targets from `LANGUAGES.md` §5, the byte-exact Default Translation prompt, the documented sampling values and `HyMT3RequestFactory` in `SprachmittlerEngines`. T2.3 replaces the table with all 102 languages; T2.1/T2.2 replace the factory with `TranslationAdapter`/`HyMT3Adapter`.
Consequences: The M1 CLI translates en→de and the other common targets without a free-form prompt. Unknown codes fail before the network. Only 15 targets resolve until T2.3, and no prompt literal or model tag appears outside Engines.
## ADR-017 — Adapter registry in Engines; one pipeline in Core
Status: Accepted
Context: M1 needed a prompt and a request factory for the CLI before the model-family adapter existed. T2.1/T2.2 replace that factory, and both the CLI and the future panel must use the same chunking, validation and retry rules. Prompt strings must stay in `SprachmittlerEngines`; validation results must be visible to Core and the UI.
Decision: `TranslationAdapter` and `AdapterRegistry` live in `SprachmittlerEngines`. An `AdapterRequest` carries text, target, model, keep-alive, prompt variant and sampling. `HyMT3Adapter` is the only family adapter in v1; it sets the publisher sampling, `num_ctx: 8192`, exactly one user message and no system/think field. `TranslationWarning` and `ModelLanguage` (re-exported as `TargetLanguage`) also live in Engines, and `LanguageMatching` owns the canonical-code comparison. `TranslationPipeline` in `SprachmittlerCore` does normalisation, detection, classification, chunking, one documented retry after a lost protected token, validation and timing; the keep-alive value is supplied by the composition root. Core re-exports the warning and language types.
Consequences: The CLI and M4 session share one implementation. Prompt bytes and language names have one home. Adapter selection is explicit and unknown families fail with `noAdapter`. The M1 `HyMT3RequestFactory` and its 15-language table are removed. A second model family adds an adapter, not a branch in Core.
## ADR-018 — Capture behind a pasteboard protocol; Services is a first-class trigger
Status: Accepted
Context: Double copy, clipboard snapshot/restore and Services all touch `NSPasteboard`, but the state machine and watcher need deterministic tests without real time or the user's clipboard. The Services path must work with no Accessibility permission.
Decision: `SprachmittlerCapture` defines `PasteboardAccessing` and `PasteboardTicking`. `SystemPasteboard` is the only production `NSPasteboard` user; `FakePasteboard` and `ManualPasteboardTicker` live in `SprachmittlerTestSupport`. `DoubleCopyDetector` is a pure state machine over change events and an injected date. `PasteboardWatcher` polls every 120 ms, reads the string only after `changeCount` changes, suppresses own/transient changes for 750 ms, and enforces the 4000/2000 limit. `ServicesProvider` receives the system pasteboard and needs no polling or Accessibility. `AppDelegate` installs it and calls `NSUpdateDynamicServices`.
Consequences: Capture logic is unit-testable and no global key tap is needed. The Services and double-copy paths both produce `CapturedText`. The 10-app compatibility matrix remains a manual task.
+10 -7
View File
@@ -162,13 +162,16 @@ Fill in from the spike. One row per tag and direction.
| Tag | Digest (first 12) | Ollama | Direction | Works | Notes (quality, preamble, tokens, speed) |
|---|---|---|---|---|---|
| hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M | | 0.40.18 | en→de | ☐ | |
| hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M | | 0.40.18 | de→en | ☐ | |
| hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M | | 0.40.18 | markdown | ☐ | |
| hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M | | 0.40.18 | json | ☐ | |
| hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M | | 0.40.18 | placeholders | ☐ | |
| hf.co/tencent/Hy-MT3-1.8B-GGUF:Q4_K_M | | | en→de | ☐ | |
| hf.co/tencent/Hy-MT3-1.8B-GGUF:Q4_K_M | | | de→en | ☐ | |
| hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M | 262ac792aeb5 | 0.40.18 | en→de | ✅ | 33 output tokens, 0.94 s, no warnings. "Meeting" stayed as a loanword; no preamble. |
| hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M | 262ac792aeb5 | 0.40.18 | de→en | ✅ | 26 output tokens, 0.66 s, no warnings; 9:30 and Room 4B preserved. |
| hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M | 262ac792aeb5 | 0.40.18 | markdown | ✅ | 50 output tokens, 1.18 s, no warnings; heading, bold, code span and link URL preserved. "num_ctx setting" became "num_ctx-Einstieg" (literal-compound limitation, not edited). |
| hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M | 262ac792aeb5 | 0.40.18 | json | ✅ | 21 output tokens, 0.57 s, no warnings; keys and structure preserved, feature values translated. |
| hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M | 262ac792aeb5 | 0.40.18 | placeholders | ✅ | 28 output tokens, 0.72 s, no warnings; URL, e-mail, `{{name}}` and `${deadline}` preserved. |
| hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M | 262ac792aeb5 | 0.40.18 | long paragraph | ⚠️ | 4,315 varied chars → 2 chunks, 1,240 output tokens, 29.1 s, no warnings. An 8,785-char synthetic text whose source repeated identical blocks emitted a repeated window; the guard stopped it with `repetitionLoop` and missing-token warnings. Source repetition is indistinguishable from model repetition to the output-only guard. |
| hf.co/tencent/Hy-MT3-1.8B-GGUF:Q4_K_M | | | en→de | ☐ | Not installed; VERIFY deferred to T2.7/T7.4. |
| hf.co/tencent/Hy-MT3-1.8B-GGUF:Q4_K_M | | | de→en | ☐ | Not installed; VERIFY deferred to T2.7/T7.4. |
Prompt-prefix note: the prefix stayed identical across the en→de runs; Ollama reported 43–773 prompt tokens depending on chunk count. The `/api/chat` final object exposes prompt/eval counts but not the cached-token count, so cache reuse is inferred from the unchanged prefix and the owner's earlier 177/178 measurement, not from a new counter.
## 8. Adding a model
+25 -12
View File
@@ -21,20 +21,20 @@ Legend: `[ ]` open · `[~]` in progress · `[x]` done · `[!]` blocked (explain)
- [x] T1.6 sprachmittler-cli models / show / translate — 2026-11-26
## M2 — Hy-MT3 adapter and text pipeline
- [ ] T2.1 Adapter protocol, registry, sampling merge
- [ ] T2.2 Hy-MT3 adapter and byte-exact prompt
- [ ] T2.3 Language catalogue (102 languages)
- [ ] T2.4 Language detection, content classifier, chunker
- [ ] T2.5 Protected tokens, output validator, preamble detector
- [ ] T2.6 Prompt policy and documented fallbacks
- [ ] T2.7 Compatibility spike (gate)
- [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
- [ ] T3.1 DoubleCopyDetector state machine
- [ ] T3.2 Pasteboard watcher and own-write suppression
- [ ] T3.3 Clipboard snapshot and restore
- [ ] T3.4 Services provider and menu item
- [ ] T3.5 Manual double-copy matrix
- [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
- [ ] T4.1 TranslationSession actor and epochs
@@ -107,3 +107,16 @@ Legend: `[ ]` open · `[~]` in progress · `[x]` done · `[!]` blocked (explain)
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).
+2
View File
@@ -160,6 +160,8 @@ Info.plist:
**This table is filled in by a person, on a real Mac.** Double copy, Accessibility replacement and clipboard restoration differ in every app and cannot be tested headlessly. Until a row is tested its cells stay ☐; an untested cell is not a claim.
Implementation status (2026-11-26): T3.1–T3.4 are implemented and covered by component tests (`DoubleCopyDetector`, `PasteboardWatcher`, `ClipboardSnapshot`, `ServicesProvider`). The 4000/2000 limit and own-marker check apply to double copy, the menu item and Services (`CapturePolicy`). The matrix below is still untested; it is the T3.5 manual task.
For each app test:
1. A plain paragraph.
+1 -1
View File
@@ -21,7 +21,7 @@ Framework: **Swift Testing** (`import Testing`, `@Test`, `#expect`) for all pack
- HTTP contract tests use a serialized `URLProtocol` stub; timeout tests use `ManualSleeper` and never real time.
- Fakes live in `SprachmittlerTestSupport`: `FakePasteboard`, `FakeClock`, `FakeOllamaHTTPTransport`, `FakeOllamaCatalog`, `FakeOllamaChat`, `ManualSleeper`, `FakeTextInserter`, `FakeAccessibility`, `FakeSettingsStore`, `TemporaryDirectory`.
- Fixtures live inside their test target (SwiftPM resources must sit within the target) and are loaded with `Bundle.module`. All fixtures are **synthetic**; never add private text.
- Golden files for prompts, Markdown and JSON output live next to the tests (`Fixtures/golden/`); update them only with an explanation in the commit message.
- Golden files for prompts, Markdown and JSON output live next to the tests (`Fixtures/`); update them only with an explanation in the commit message.
## Required test cases (minimum)
+2 -3
View File
@@ -5,8 +5,7 @@ Modules: `SprachmittlerText` (analysis, chunking), `SprachmittlerEngines` (promp
## 1. Prompt policy
- **Default Translation** is the canonical prompt for v1. It is byte-exact in `docs/HYMT3_MODEL.md` §3.
- **Structured Data 1** is used for JSON, HTML and Markdown tables when the content class says so, or as a fallback if a protected token is lost in a structured source.
- **Delimiters** is the single documented retry when a protected token is lost in plain/delimited text.
- v1 starts with **Default Translation** for every content class. **Structured Data 1** (JSON/HTML/Markdown) and **Delimiters** are the only fallbacks, used once after a protected token was lost. They are selected by the deterministic `PromptPolicy`, never by a user instruction.
- **Terminology**, **Style** and **Structured Data 2** are reserved for future glossary/style/context features; not v1.
- No other prompt text is allowed. The user cannot type a prompt in v1.
@@ -109,7 +108,7 @@ Do not require exact string equality: locales legitimately change decimal and th
No source text is included unless `--include-source` is passed explicitly for debugging. Never write this JSON to disk automatically.
Until T2.4, `sourceLanguage` is `null`; until T2.5, `warnings` is empty.
Until T2.4, `sourceLanguage` is `null`; until T2.5, `warnings` is empty. As of M2 both are populated: `sourceLanguage` is the advisory `NLLanguageRecognizer` code (still nullable) and `warnings` contains the stable warning codes from `TranslationWarning.code`. `timing.promptTokens` and `timing.outputTokens` are summed over chunks and retry attempts.
## 11. Tests