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.
This commit is contained in:
schihei committed 2026-11-27 20:21:30 +01:00
1 parent 9f89000b0d
commit 2a601058f4
29 files changed
+607 -122

No files matched your search

@@ -16,6 +16,7 @@ struct AppSettingsTests {
#expect(settings.doubleCopyWindowMs == 500)
#expect(settings.maxCharactersLatin == 4000)
#expect(settings.maxCharactersCJK == 2000)
#expect(settings.maximumPartsPerSelection == 1)
#expect(settings.numCtx == 8192)
#expect(settings.translationFontSize == 17)
#expect(settings.languageRoutes.isEmpty)
@@ -25,6 +26,18 @@ struct AppSettingsTests {
#expect(!settings.hasCompletedOnboarding)
}
@Test func captureLimitsFollowPartsAndScript() {
var settings = AppSettings()
#expect(settings.captureLimits.chunkLimit(for: "a") == 4000)
#expect(settings.captureLimits.captureLimit(for: "a") == 4000)
#expect(settings.captureLimits.captureLimit(for: "你") == 2000)
settings.maximumPartsPerSelection = 4
#expect(settings.captureLimits.captureLimit(for: "a") == 16000)
#expect(settings.captureLimits.captureLimit(for: "你") == 8000)
#expect(settings.captureLimits.maximumParts == 4)
}
@Test func codableRoundTripPreservesValues() throws {
var settings = AppSettings()
settings.endpoint = try #require(URL(string: "https://example.com:11434"))
@@ -38,6 +51,7 @@ struct AppSettingsTests {
settings.closeWithEscape = false
settings.launchAtLogin = true
settings.hasCompletedOnboarding = true
settings.maximumPartsPerSelection = 4
let data = try JSONEncoder().encode(settings)
let decoded = try JSONDecoder().decode(AppSettings.self, from: data)
@@ -65,6 +79,7 @@ struct AppSettingsTests {
#expect(decoded.renderMarkdown)
#expect(decoded.closeWithEscape)
#expect(!decoded.autoCopy)
#expect(decoded.maximumPartsPerSelection == 1)
}
@Test func fastModelCanBeClearedExplicitly() throws {
@@ -102,7 +117,8 @@ struct AppSettingsTests {
let decoded = try JSONDecoder().decode(AppSettings.self, from: Data(json.utf8))
#expect(decoded.doubleCopyWindowMs == 300)
#expect(decoded.maxCharactersLatin == 500)
#expect(decoded.maxCharactersCJK == 5000)
#expect(decoded.maxCharactersCJK == 4000)
#expect(decoded.maximumPartsPerSelection == 1)
#expect(decoded.numCtx == 1024)
#expect(decoded.numPredict == 8192)
#expect(decoded.temperature == 2)
@@ -131,6 +147,8 @@ struct AppSettingsTests {
]
settings.autoCopy = true
settings.targetLanguage = "de"
settings.maxCharactersCJK = 9999
settings.maximumPartsPerSelection = 99
settings.sanitize()
#expect(settings.doubleCopyWindowMs == 300)
@@ -139,6 +157,8 @@ struct AppSettingsTests {
#expect(settings.topK == 1)
#expect(settings.keepModelLoaded == HyMT3ModelPreset.defaultKeepAlive)
#expect(settings.translationFontSize == 28)
#expect(settings.maxCharactersCJK == 4000)
#expect(settings.maximumPartsPerSelection == 8)
#expect(settings.languageRoutes == [
LanguageRoute(source: "de", target: "en"),
LanguageRoute(source: "zh", target: "en"),