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:
1 parent
9f89000b0d
commit
2a601058f4
29 files changed
+607
-122
No files matched your search
@@ -39,6 +39,8 @@ public struct AppSettings: Codable, Sendable, Equatable {
|
||||
public var maxCharactersLatin: Int
|
||||
/// The dense-script chunk limit.
|
||||
public var maxCharactersCJK: Int
|
||||
/// How many chunks one capture may contain (1–8). `1` rejects text longer than one chunk.
|
||||
public var maximumPartsPerSelection: Int
|
||||
/// `num_ctx`.
|
||||
public var numCtx: Int
|
||||
/// `num_predict`.
|
||||
@@ -89,6 +91,7 @@ public struct AppSettings: Codable, Sendable, Equatable {
|
||||
doubleCopyWindowMs = 500
|
||||
maxCharactersLatin = 4000
|
||||
maxCharactersCJK = 2000
|
||||
maximumPartsPerSelection = 1
|
||||
numCtx = 8192
|
||||
numPredict = 4096
|
||||
temperature = 0.7
|
||||
@@ -138,7 +141,8 @@ public struct AppSettings: Codable, Sendable, Equatable {
|
||||
languageRoutes = Self.normalizedRoutes(languageRoutes)
|
||||
doubleCopyWindowMs = Self.clamp(doubleCopyWindowMs, to: 300 ... 1000)
|
||||
maxCharactersLatin = Self.clamp(maxCharactersLatin, to: 500 ... 10000)
|
||||
maxCharactersCJK = Self.clamp(maxCharactersCJK, to: 500 ... 5000)
|
||||
maxCharactersCJK = Self.clamp(maxCharactersCJK, to: 500 ... 4000)
|
||||
maximumPartsPerSelection = Self.clamp(maximumPartsPerSelection, to: 1 ... 8)
|
||||
numCtx = Self.clamp(numCtx, to: 1024 ... 32768)
|
||||
numPredict = Self.clamp(numPredict, to: 1 ... 8192)
|
||||
temperature = min(max(temperature, 0), 2)
|
||||
@@ -169,10 +173,16 @@ public struct AppSettings: Codable, Sendable, Equatable {
|
||||
Chunker(latinLimit: maxCharactersLatin, denseLimit: maxCharactersCJK)
|
||||
}
|
||||
|
||||
/// The chunk and capture limits derived from the settings.
|
||||
public var captureLimits: CaptureLimits {
|
||||
CaptureLimits(chunker: chunker, maximumParts: maximumPartsPerSelection)
|
||||
}
|
||||
|
||||
struct DecodedLimits {
|
||||
let window: Int
|
||||
let latin: Int
|
||||
let cjk: Int
|
||||
let parts: Int
|
||||
let numCtx: Int
|
||||
let numPredict: Int
|
||||
let fontSize: Int
|
||||
@@ -203,7 +213,12 @@ public struct AppSettings: Codable, Sendable, Equatable {
|
||||
cjk: clamp(
|
||||
container.decodeIfPresent(Int.self, forKey: .maxCharactersCJK)
|
||||
?? defaults.maxCharactersCJK,
|
||||
to: 500 ... 5000
|
||||
to: 500 ... 4000
|
||||
),
|
||||
parts: clamp(
|
||||
container.decodeIfPresent(Int.self, forKey: .maximumPartsPerSelection)
|
||||
?? defaults.maximumPartsPerSelection,
|
||||
to: 1 ... 8
|
||||
),
|
||||
numCtx: clamp(
|
||||
container.decodeIfPresent(Int.self, forKey: .numCtx) ?? defaults.numCtx,
|
||||
@@ -244,7 +259,8 @@ public struct AppSettings: Codable, Sendable, Equatable {
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case endpoint, allowRemoteEndpoint, model, fastModel, targetLanguage, languageRoutes
|
||||
case recentTargetLanguages
|
||||
case doubleCopyWindowMs, maxCharactersLatin, maxCharactersCJK, numCtx, numPredict
|
||||
case doubleCopyWindowMs, maxCharactersLatin, maxCharactersCJK, maximumPartsPerSelection
|
||||
case numCtx, numPredict
|
||||
case temperature, topP, topK, repeatPenalty, keepModelLoaded, warmUpOnLaunch
|
||||
case promptVariantPolicy, autoCopy, showSourcePreview, translationFontSize, renderMarkdown
|
||||
case closeWithEscape, launchAtLogin, keepRecentTranslationInMemory, hasCompletedOnboarding
|
||||
|
||||
Reference in new issue
Block a user