mirror of
https://github.com/BigMarc/grammargem.git
synced 2026-10-13 17:01:55 +02:00
Replace the MLXEngine stub with real Qwen2.5-3B-4bit inference via mlx-swift-examples (2.25.9): loads the local model snapshot on disk (no network), chat-templated generation per AIAction, and tone classification. Wired behind the existing AIEngine seam; AppState resolves the model dir through ModelManager. Build notes: - arm64-only now (MLX is Metal / Apple-Silicon only; matches the spec). - swift build (CLI) cannot compile mlx-swift's .metal kernels, so the metallib is generated once via scripts/build-metallib.sh (xcodebuild) and vendored at AppSupport/mlx.metallib; scripts/build.sh ships it as Contents/Resources/mlx-swift_Cmlx.bundle/Contents/Resources/default.metallib (the path mlx resolves, and it codesigns cleanly). - A hidden --mlx-selftest entrypoint runs one headless generation to verify the runtime end-to-end. Verified: the signed app's self-test produces a real rewrite; full test suite green (the MLX integration test is gated behind GRAMMAGEM_MLX_TEST). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
56 lines
2.2 KiB
Swift
56 lines
2.2 KiB
Swift
// swift-tools-version:5.10
|
|
import PackageDescription
|
|
import Foundation
|
|
|
|
// GrammaGem — native macOS menu-bar writing assistant.
|
|
//
|
|
// Layer-1 grammar is the real **Harper** core (Apache-2.0), embedded as a Rust
|
|
// C-FFI static library (see `harper-ffi/`). Build the lib first with
|
|
// `harper-ffi/build.sh`; `scripts/build.sh` does this automatically.
|
|
//
|
|
// Layer-2 AI (rewrite / tone / Ask) is the real on-device LLM via MLX
|
|
// (mlx-swift-examples). MLX is **Apple-Silicon / Metal only**, so the app is
|
|
// arm64-only (matches the product spec: Apple Silicon, macOS 14+). The Harper
|
|
// static lib stays universal; the linker just uses its arm64 slice.
|
|
|
|
// Absolute path to the prebuilt Harper static lib, independent of build cwd.
|
|
let packageRoot = URL(fileURLWithPath: #filePath).deletingLastPathComponent().path
|
|
let harperLibDir = packageRoot + "/harper-ffi/lib"
|
|
|
|
let package = Package(
|
|
name: "GrammaGem",
|
|
platforms: [
|
|
.macOS(.v14) // Apple Silicon, macOS 14+ (per the product spec)
|
|
],
|
|
products: [
|
|
.executable(name: "GrammaGem", targets: ["GrammaGem"])
|
|
],
|
|
dependencies: [
|
|
// On-device LLM runtime. Pinned to an exact tag (the LLM libraries still
|
|
// ship from this repo at 2.25.9; the package name is "mlx-libraries").
|
|
.package(url: "https://github.com/ml-explore/mlx-swift-examples.git", exact: "2.25.9"),
|
|
],
|
|
targets: [
|
|
// C shim exposing libharper_ffi's C ABI (harper-ffi/include/harper.h) to Swift.
|
|
.target(name: "CHarper", path: "Sources/CHarper"),
|
|
.executableTarget(
|
|
name: "GrammaGem",
|
|
dependencies: [
|
|
"CHarper",
|
|
.product(name: "MLXLLM", package: "mlx-swift-examples"),
|
|
.product(name: "MLXLMCommon", package: "mlx-swift-examples"),
|
|
],
|
|
path: "Sources/GrammaGem",
|
|
linkerSettings: [
|
|
// Link the prebuilt Harper static library (arm64 slice).
|
|
.unsafeFlags(["-L\(harperLibDir)", "-lharper_ffi"])
|
|
]
|
|
),
|
|
.testTarget(
|
|
name: "GrammaGemTests",
|
|
dependencies: ["GrammaGem"],
|
|
path: "Tests/GrammaGemTests"
|
|
),
|
|
]
|
|
)
|