Files
museion/Museion/MuseionApp.swift
T
AlexKuceraandClaude f21d3a6844
CI / ci (push) Canceled after 0s
feat(acp): add M0 ACP bridge — engine child + mentor pane (fixes #14)
Spawn hermes acp -p museion over NDJSON JSON-RPC stdio via a
hand-rolled thin client (no Swift SDK exists). The mentor debug
pane streams replies, renders fix-card tool calls as structured
cards (ADR-0006), cancels via session/cancel, tears down on quit
(willTerminate), and surfaces a restart prompt on engine crash —
never data loss. Version verify against state.json is advisory.

Fake ACP server test double (zsh speaking real NDJSON) covers
handshake, streaming + fix-card, drift, crash latch, cancel,
teardown. 36/36 tests green; finish-audit fixes included (wired
binaryPath, focus-loss teardown bug, double onCrash latch).

Co-Authored-By: Claude <noreply@anthropic.com>
2026-09-16 18:57:41 +02:00

109 lines
3.0 KiB
Swift

//
// MuseionApp.swift
// Museion
//
// Created by Alexander Kucera on 26.08.26.
//
import SwiftUI
/// App-scoped gate state — raised once per app-launch, first window only (ticket #41).
/// The model is shared so ⌘N during the gate can't start a second concurrent check.
@MainActor
@Observable
final class AppGateState {
var gateRaised = true
/// True once the gate sheet's onDismiss fired (dismissal completion, #48) —
/// the provisioning failure card presents only after this.
var gateDismissed = false
let gateModel = EngineGateModel()
let provisioning = ProvisioningModel()
/// #14: the app-scoped mentor bridge — the pane renders it; quit tears it down.
let mentor = MentorSessionModel()
}
@main
struct MuseionApp: App {
@State private var gate = AppGateState()
var body: some Scene {
WindowGroup {
ContentView()
.environment(gate)
// #14: app quit tears down the engine child cleanly (map
// decision: child lifecycle). willTerminate is the real quit
// signal on macOS — scenePhase .inactive also fires on plain
// focus loss, which would kill the engine on every app switch.
.onReceive(NotificationCenter.default.publisher(for: NSApplication.willTerminateNotification)) { _ in
gate.mentor.shutdown()
}
}
Window("About \(AppMetadata.name)", id: "about") {
AboutEngineView()
}
.windowResizability(.contentSize)
.commands {
// SwiftUI has no About scene on macOS; replace the stock panel with our window.
CommandGroup(replacing: .appInfo) {
OpenAboutButton()
}
}
}
}
private struct OpenAboutButton: View {
@Environment(\.openWindow) private var openWindow
var body: some View {
Button("About \(AppMetadata.name)") { openWindow(id: "about") }
}
}
/// Read-only mirror of the last completed check's state.json record (ticket #39).
/// Reads the file when opened; never triggers a check; no re-check button.
struct AboutEngineView: View {
@State private var record: EngineProbe.StateRecord?
var body: some View {
VStack(spacing: 12) {
Image(systemName: "books.vertical")
.font(.largeTitle)
Text(AppMetadata.name)
.font(.title)
.bold()
Text(AppMetadata.tagline)
.foregroundStyle(.secondary)
Divider()
if let record {
VStack(alignment: .leading, spacing: 6) {
aboutRow("Engine", record.status == "pass" ? "Ready" : "Unavailable")
aboutRow("Engine version", record.engineVersion ?? "—")
aboutRow("Last checked", record.checkedAt)
aboutRow("Binary path", record.binaryPath ?? "—")
}
} else {
Text("No engine check recorded yet.")
.foregroundStyle(.secondary)
}
}
.padding(20)
.frame(width: 380)
.onAppear { record = EngineProbe.readStateRecord() }
}
private func aboutRow(_ label: String, _ value: String) -> some View {
HStack(alignment: .firstTextBaseline) {
Text(label)
.foregroundStyle(.secondary)
Spacer(minLength: 12)
Text(value)
.textSelection(.enabled)
.lineLimit(1)
.truncationMode(.middle)
}
.font(.callout)
}
}