feat(m4-m6): session, panel, Replace, settings and onboarding

M4: TranslationSession actor with epochs/one-in-flight streaming, PanelViewModel, non-activating NSPanel, streaming panel UI, searchable/recent target languages, warnings/errors and Copy/Retry/Replace actions.

M5: InsertionCoordinator with target capture, AX direct replacement, secure-field/own-PID refusal, frontmost and selected-text verification, snapshot/⌘V/restore fallback, cancellation-safe restore and blocking-warning gate.

M6: versioned AppSettings/SettingsStore, onboarding for Ollama/model/target/Accessibility, General/Model/Translation/Privacy/Diagnostics settings, launch-at-login via SMAppService, status menu (target, copy/replace last, setup, diagnostics, about), text-free diagnostics and first-run setup.

Docs: PROGRESS M4–M6, ARCHITECTURE §10–§12, ADR-019/020, SELECTION_AND_CLIPBOARD and TESTING. Manual 10-app matrices, real AX/paste delivery, VoiceOver and focus checks remain open.

Verified: make verify green (format, strict lint, scripts, privacy, Debug+Release signatures, 217 package tests); app launches and a two-copy clipboard smoke test opens the panel.
This commit is contained in:
schihei committed 2026-11-26 14:03:16 +01:00
1 parent 64078e2f04
commit a78572adc3
47 files changed
+4963 -79

No files matched your search

@@ -92,7 +92,9 @@ public struct TranslationPipeline: Sendable {
text: String,
target: ModelLanguage,
model: String,
keepAlive: String
keepAlive: String,
sampling: SamplingOptions = .publisherDefault,
onDelta: (@Sendable (String) async -> Void)? = nil
) async throws -> PipelineResult {
let normalized = TextNormalization.normalizeInput(text)
guard !normalized.isEmpty else {
@@ -112,7 +114,9 @@ public struct TranslationPipeline: Sendable {
target: target,
model: model,
keepAlive: keepAlive,
tokens: tokens
sampling: sampling,
tokens: tokens,
onDelta: onDelta
)
let accumulator = try await translateAll(chunks, context: context)
@@ -150,7 +154,9 @@ public struct TranslationPipeline: Sendable {
let target: ModelLanguage
let model: String
let keepAlive: String
let sampling: SamplingOptions
let tokens: [ProtectedToken]
let onDelta: (@Sendable (String) async -> Void)?
}
private struct Accumulator {
@@ -180,6 +186,9 @@ public struct TranslationPipeline: Sendable {
accumulator.sawLength = true
}
accumulator.joined += result.text + chunk.separatorAfter
if !chunk.separatorAfter.isEmpty {
await context.onDelta?(chunk.separatorAfter)
}
}
} catch is CancellationError {
throw SprachmittlerError.cancelled
@@ -214,16 +223,10 @@ public struct TranslationPipeline: Sendable {
var outputTokens: Int?
while true {
let request = try registry.makeRequest(
AdapterRequest(
text: chunk.text,
target: context.target,
model: context.model,
keepAlive: context.keepAlive,
prompt: prompt
)
)
let attempt = try await stream(request)
let request = try makeRequest(chunk: chunk, prompt: prompt, context: context)
// A retry replaces the first attempt; do not stream both into the panel.
let deltaHandler = retried ? nil : context.onDelta
let attempt = try await stream(request, onDelta: deltaHandler)
response = attempt
promptTokens = sum(promptTokens, attempt.metrics.promptEvalCount)
outputTokens = sum(outputTokens, attempt.metrics.evalCount)
@@ -255,6 +258,23 @@ public struct TranslationPipeline: Sendable {
)
}
private func makeRequest(
chunk: TextChunk,
prompt: PromptVariant,
context: TranslationContext
) throws -> ChatRequest {
try registry.makeRequest(
AdapterRequest(
text: chunk.text,
target: context.target,
model: context.model,
keepAlive: context.keepAlive,
prompt: prompt,
sampling: context.sampling
)
)
}
private struct StreamResult {
let text: String
let doneReason: String?
@@ -263,7 +283,10 @@ public struct TranslationPipeline: Sendable {
let looped: Bool
}
private func stream(_ request: ChatRequest) async throws -> StreamResult {
private func stream(
_ request: ChatRequest,
onDelta: (@Sendable (String) async -> Void)?
) async throws -> StreamResult {
var text = ""
var doneReason: String?
var metrics = ChatMetrics.empty
@@ -280,6 +303,7 @@ public struct TranslationPipeline: Sendable {
firstTokenAt = clock()
}
text += delta
await onDelta?(delta)
if repetition.append(delta) {
looped = true
}