mirror of
https://github.com/BigMarc/grammargem.git
synced 2026-10-13 17:01:55 +02:00
Native SwiftUI menu-bar app: global hotkey → capture selected text (AX API / clipboard fallback) → grammar (Harper) / local AI (MLX) → replace in place. Free/paid entitlement gate + Lemon Squeezy device-cap licensing, $0 marginal cost per user. Heavyweight engines behind protocol stubs so it builds out of the box. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
33 lines
1.2 KiB
Swift
33 lines
1.2 KiB
Swift
import Foundation
|
|
|
|
/// Layer 2 — local-LLM-powered rewriting / tone / "Ask" / translate.
|
|
///
|
|
/// Backed in production by **MLX** (mlx-swift) running a small instruct model
|
|
/// downloaded once from Hugging Face. The protocol isolates the rest of the app
|
|
/// from the runtime so the UI, gating, and tests don't depend on MLX being present.
|
|
protocol AIEngine: AnyObject {
|
|
/// Whether a model is loaded and ready to run locally.
|
|
var isReady: Bool { get }
|
|
|
|
/// Run an action against `text` and return the rewritten result.
|
|
/// Throws on model-not-ready or generation failure. Never performs network I/O.
|
|
func run(_ action: AIAction, on text: String) async throws -> String
|
|
|
|
/// Best-effort local tone classification (used by tone-detection UI).
|
|
func detectTone(_ text: String) async -> Tone
|
|
}
|
|
|
|
enum AIEngineError: LocalizedError {
|
|
case modelNotReady
|
|
case generationFailed(String)
|
|
|
|
var errorDescription: String? {
|
|
switch self {
|
|
case .modelNotReady:
|
|
return "The on-device model isn't ready yet. Finish the first-run download in Settings."
|
|
case .generationFailed(let why):
|
|
return "On-device rewrite failed: \(why)"
|
|
}
|
|
}
|
|
}
|