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

+9 -5
View File
@@ -88,7 +88,8 @@ final class AppEnvironment {
pasteboard: pasteboard,
configuration: DoubleCopyDetector.Configuration(
window: Double(windowMs) / 1000
)
),
limits: store.current().captureLimits
)
let factoryStore = store
@@ -218,7 +219,8 @@ final class AppEnvironment {
renderMarkdown: settings.renderMarkdown,
closeWithEscape: settings.closeWithEscape,
languageRoutes: settings.languageRoutes,
recentTargets: settings.recentTargets
recentTargets: settings.recentTargets,
captureLimits: settings.captureLimits
)
}
@@ -227,6 +229,7 @@ final class AppEnvironment {
let previousTarget = panelViewModel.configuration.target.code
let previousRoutes = panelViewModel.configuration.languageRoutes
panelViewModel.updateConfiguration(configuration(for: settings))
watcher.limits = settings.captureLimits
if settings.doubleCopyWindowMs != watcherWindowMs {
watcherWindowMs = settings.doubleCopyWindowMs
restartWatcher()
@@ -250,7 +253,8 @@ final class AppEnvironment {
pasteboard: pasteboard,
configuration: DoubleCopyDetector.Configuration(
window: Double(watcherWindowMs) / 1000
)
),
limits: settingsStore.current().captureLimits
)
if let sink = watcherEventSink {
watcher.start(onEvent: sink)
@@ -279,7 +283,7 @@ final class AppEnvironment {
lastWarnings = []
onStateChange?()
switch CapturePolicy.validate(captured.text) {
switch CapturePolicy.validate(captured.text, limits: settingsStore.current().captureLimits) {
case .valid:
lastCaptureFailure = nil
case .empty:
@@ -404,7 +408,7 @@ extension AppEnvironment {
await diagnostics.record(kind: "error", detail: error.diagnosticCode)
}
onStateChange?()
case .started, .delta, .cancelled:
case .started, .chunkStarted, .delta, .cancelled:
break
}
}