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:
1 parent
64078e2f04
commit
a78572adc3
47 files changed
+4963
-79
No files matched your search
@@ -0,0 +1,139 @@
|
||||
import Foundation
|
||||
import SprachmittlerOllama
|
||||
|
||||
/// A user-facing recovery action. The UI never shows a raw `localizedDescription`.
|
||||
public enum RecoveryAction: Sendable, Equatable {
|
||||
/// Start Ollama.
|
||||
case startOllama
|
||||
/// Copy and run `ollama pull <model>`.
|
||||
case pullModel(String)
|
||||
/// Open the relevant System Settings page.
|
||||
case openSettings
|
||||
/// Copy the translation instead.
|
||||
case copyInstead
|
||||
/// Shorten the selection.
|
||||
case shortenText
|
||||
/// Retry the translation.
|
||||
case retry
|
||||
/// Nothing to do.
|
||||
case none
|
||||
}
|
||||
|
||||
public extension SprachmittlerError {
|
||||
/// A short, non-technical message for the panel and onboarding.
|
||||
var userMessage: String {
|
||||
switch self {
|
||||
case .noSelection:
|
||||
"No text was selected."
|
||||
case .emptyText:
|
||||
"No text was copied."
|
||||
case let .textTooLong(_, limit):
|
||||
"This selection is too long (limit \(limit) characters)."
|
||||
case .pasteboardUnavailable:
|
||||
"The clipboard is unavailable."
|
||||
case .ollamaUnreachable:
|
||||
"Ollama is not running."
|
||||
case let .ollamaTooOld(_, required):
|
||||
"Ollama is too old. Version \(required) or newer is required."
|
||||
case let .endpointRejected(reason):
|
||||
"The endpoint is not allowed: \(reason.userMessage)"
|
||||
case .modelNotInstalled:
|
||||
"The Hy-MT3 model is not installed."
|
||||
case .noAdapter:
|
||||
"This model is not supported."
|
||||
case .badRequest:
|
||||
"Ollama rejected the request."
|
||||
case .server:
|
||||
"Ollama returned an error."
|
||||
case .timeout:
|
||||
"Ollama took too long to answer."
|
||||
case .emptyOutput:
|
||||
"The model returned an empty translation."
|
||||
case .truncated:
|
||||
"The translation was cut off."
|
||||
case .repetitionLoop:
|
||||
"The translation started repeating."
|
||||
case .preambleDetected:
|
||||
"The model added an explanation."
|
||||
case .protectedTokenLost:
|
||||
"A URL, placeholder or code token was lost."
|
||||
case .accessibilityNotTrusted:
|
||||
"Replace needs the Accessibility permission."
|
||||
case .accessibilityUnsupported:
|
||||
"This app did not accept the replacement."
|
||||
case .insertionTargetChanged:
|
||||
"The selection changed before Replace."
|
||||
case .pasteboardRestoreFailed:
|
||||
"The previous clipboard could not be restored."
|
||||
case .cancelled:
|
||||
"Translation cancelled."
|
||||
}
|
||||
}
|
||||
|
||||
/// A stable non-text code for diagnostics.
|
||||
var diagnosticCode: String {
|
||||
switch self {
|
||||
case .noSelection: "noSelection"
|
||||
case .emptyText: "emptyText"
|
||||
case .textTooLong: "textTooLong"
|
||||
case .pasteboardUnavailable: "pasteboardUnavailable"
|
||||
case .ollamaUnreachable: "ollamaUnreachable"
|
||||
case .ollamaTooOld: "ollamaTooOld"
|
||||
case .endpointRejected: "endpointRejected"
|
||||
case .modelNotInstalled: "modelNotInstalled"
|
||||
case .noAdapter: "noAdapter"
|
||||
case .badRequest: "badRequest"
|
||||
case .server: "server"
|
||||
case .timeout: "timeout"
|
||||
case .emptyOutput: "emptyOutput"
|
||||
case .truncated: "truncated"
|
||||
case .repetitionLoop: "repetitionLoop"
|
||||
case .preambleDetected: "preambleDetected"
|
||||
case .protectedTokenLost: "protectedTokenLost"
|
||||
case .accessibilityNotTrusted: "accessibilityNotTrusted"
|
||||
case .accessibilityUnsupported: "accessibilityUnsupported"
|
||||
case .insertionTargetChanged: "insertionTargetChanged"
|
||||
case .pasteboardRestoreFailed: "pasteboardRestoreFailed"
|
||||
case .cancelled: "cancelled"
|
||||
}
|
||||
}
|
||||
|
||||
/// The primary recovery action, if any.
|
||||
var recoveryAction: RecoveryAction {
|
||||
switch self {
|
||||
case .ollamaUnreachable:
|
||||
.startOllama
|
||||
case let .modelNotInstalled(model):
|
||||
.pullModel(model)
|
||||
case .ollamaTooOld, .endpointRejected:
|
||||
.openSettings
|
||||
case .textTooLong:
|
||||
.shortenText
|
||||
case .accessibilityNotTrusted:
|
||||
.openSettings
|
||||
case .accessibilityUnsupported, .insertionTargetChanged, .pasteboardRestoreFailed:
|
||||
.copyInstead
|
||||
case .timeout, .server, .emptyOutput, .truncated, .repetitionLoop, .preambleDetected:
|
||||
.retry
|
||||
default:
|
||||
.none
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension EndpointRejection {
|
||||
var userMessage: String {
|
||||
switch self {
|
||||
case .scheme:
|
||||
"only http and https are supported"
|
||||
case .form:
|
||||
"it must not contain credentials, a query or a fragment"
|
||||
case .remoteNotAllowed:
|
||||
"remote endpoints are disabled"
|
||||
case .remoteRequiresHTTPS:
|
||||
"remote endpoints require HTTPS"
|
||||
case .redirect:
|
||||
"redirects are refused"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user