Files
museion/Museion/EngineGateView.swift
T
AlexKuceraandCipher c0b2cb0b93
CI / ci (push) Canceled after 0s
feat(provisioning): add S2.1 pass with failure alert & retry (fixes #47, #48)
Idempotent per-gate pass: create the museion Hermes profile only when
missing (exit-1 "already exists" = success), then additively seed the
bundled writing skills from seed-manifest.txt — temp-copy+rename, present
skills never touched, orphaned temps swept, manifest entries validated
kebab-case at the trust boundary.

Failures surface a separate phase-named alert ("couldn't set up the
writing profile" / "couldn't copy the writing skills"), never re-raising
the gate: excerpt behind Technical details (stdout per #43, stderr
fallback), Retry re-runs the whole pass, Not Now defers to the next
launch's silent retry. The card presents only after the gate sheet's
dismissal completes and snapshots its failure so a successful Retry
doesn't blank it mid-animation.

Provisioning writes nothing to the profile config (no mcp_servers entry,
#44) and leaves state.json engine-gate-only. 30/30 tests green.

Co-Authored-By: Cipher <cipher@babylondreams.de>
2026-09-05 15:03:01 +02:00

239 lines
7.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// EngineGateView.swift
// Museion
//
// Ceiling note: a pathological all-hang machine holds the checking card up to
// ~N×5 s (per-candidate timeout, ticket #36) — not 5 s total.
//
import SwiftUI
/// The launch Engine gate: one blocking card, three states (tickets #38/#40/#41).
/// Shown once per app-launch over the first window; the sheet never closes itself.
struct EngineGateView: View {
/// Shared app-scoped model — one check per app-launch even if ⌘N opens more windows (#41).
let model: EngineGateModel
/// Fires the moment a check passes — provisioning (#13) starts here, in parallel (ticket #41).
var onEnginePass: (@MainActor @Sendable () -> Void)?
/// Unlock point: pass-card dismissal (ticket #41). The sheet's only exit.
var onDismiss: (@MainActor @Sendable () -> Void)?
var body: some View {
VStack(spacing: 14) {
switch model.phase {
case .idle, .checking:
checkingCard
case let .pass(engineVersion, binaryPath):
passCard(engineVersion: engineVersion, binaryPath: binaryPath)
case let .fail(firstProbePath, stderrExcerpt):
failCard(firstProbePath: firstProbePath, stderrExcerpt: stderrExcerpt)
}
}
.padding(24)
.frame(width: 460)
.onAppear {
model.onPass = onEnginePass
Task { await model.beginAutomaticCheck() }
}
.interactiveDismissDisabled()
}
// MARK: Checking (ticket #41) — spinner, no buttons; per-candidate timeout flips the card to fail
private var checkingCard: some View {
VStack(spacing: 14) {
ProgressView()
.controlSize(.regular)
.padding(.bottom, 2)
Text("Checking the Engine…")
.font(.title3)
Text("Running hermes acp --check")
.font(.callout)
.foregroundStyle(.secondary)
}
}
// MARK: Pass (ticket #40) — check icon, version, explicit dismiss; no re-check
private func passCard(engineVersion: String, binaryPath: String) -> some View {
VStack(spacing: 14) {
Image(systemName: "checkmark.circle.fill")
.font(.system(size: 30))
.foregroundStyle(.secondary)
Text("Engine ready")
.font(.title3)
Text("Hermes \(engineVersion) answered the health check. The mentor is available.")
.font(.callout)
.foregroundStyle(.secondary)
.multilineTextAlignment(.center)
Text(binaryPath)
.font(.system(size: 10, design: .monospaced))
.foregroundStyle(.tertiary)
.lineLimit(1)
.truncationMode(.middle)
Button("Start Writing") {
onDismiss?()
}
.keyboardShortcut(.defaultAction)
.buttonStyle(.borderedProminent)
}
}
// MARK: Fail (ticket #40) — two install steps, re-check, collapsed stderr
private func failCard(firstProbePath: String, stderrExcerpt: String) -> some View {
VStack(spacing: 14) {
Image(systemName: "exclamationmark.triangle.fill")
.font(.system(size: 30))
.foregroundStyle(.orange)
Text("Museion needs its engine")
.font(.title3)
Text("The Hermes engine wasn't found or didn't answer. Museion is paused until it's installed — Passes and Sessions need it.")
.font(.callout)
.foregroundStyle(.secondary)
.multilineTextAlignment(.center)
installSteps
Button("Re-check") {
Task { await model.runCheck() }
}
.buttonStyle(.borderedProminent)
if !stderrExcerpt.isEmpty {
DisclosureGroup("Technical details") {
VStack(alignment: .leading, spacing: 6) {
Text(stderrExcerpt)
.font(.system(size: 10, design: .monospaced))
.foregroundStyle(.secondary)
.textSelection(.enabled)
Text("Probed: \(firstProbePath)")
.font(.system(size: 10, design: .monospaced))
.foregroundStyle(.tertiary)
}
.frame(maxWidth: .infinity, alignment: .leading)
}
.font(.system(size: 11))
.frame(maxWidth: .infinity, alignment: .leading)
} else {
Text("Probed: \(firstProbePath)")
.font(.system(size: 10, design: .monospaced))
.foregroundStyle(.tertiary)
}
}
}
/// Ticket #40: exactly two steps + the docs link. Nothing else.
private var installSteps: some View {
VStack(alignment: .leading, spacing: 10) {
HStack(alignment: .top, spacing: 8) {
Text("1.").monospacedDigit().foregroundStyle(.secondary)
VStack(alignment: .leading, spacing: 4) {
Text(installCommand)
.font(.system(size: 11, design: .monospaced))
.textSelection(.enabled)
.fixedSize(horizontal: false, vertical: true)
Button {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(installCommand, forType: .string)
} label: {
Label("Copy", systemImage: "doc.on.doc")
}
.controlSize(.small)
.buttonStyle(.link)
.font(.system(size: 11))
}
}
HStack(alignment: .top, spacing: 8) {
Text("2.").monospacedDigit().foregroundStyle(.secondary)
Text("Come back here and click Re-check.")
}
Link("Installation guide", destination: URL(string: "https://hermes-agent.nousresearch.com/docs")!)
.font(.system(size: 11))
.frame(maxWidth: .infinity)
}
.padding(12)
.background(.quaternary.opacity(0.3), in: RoundedRectangle(cornerRadius: 8))
}
private let installCommand = "curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash"
}
/// #48: provisioning failure card — separate from the gate, which never re-raises.
/// Presented only after the gate sheet has been dismissed.
struct ProvisioningFailureCard: View {
let model: ProvisioningModel
/// Retry re-runs the whole idempotent pass with the gate's binary (#45).
let onRetry: () -> Void
/// Snapshot taken when the card appears; a successful Retry nils
/// `model.lastFailure` mid-presentation, and reading it live would blank
/// the card during its dismiss animation.
@State private var failure: ProfileProvisioner.Outcome?
var body: some View {
if let failure, case let .failed(phase, excerpt) = failure {
VStack(spacing: 14) {
Image(systemName: "exclamationmark.triangle.fill")
.font(.system(size: 30))
.foregroundStyle(.orange)
Text(phase.rawValue)
.font(.title3)
Text("Museion couldn't finish setting up the mentor's writing profile. Nothing is lost — the setup is safe to run again.")
.font(.callout)
.foregroundStyle(.secondary)
.multilineTextAlignment(.center)
if !excerpt.isEmpty {
DisclosureGroup("Technical details") {
Text(excerpt)
.font(.system(size: 10, design: .monospaced))
.foregroundStyle(.secondary)
.textSelection(.enabled)
.frame(maxWidth: .infinity, alignment: .leading)
}
.font(.system(size: 11))
.frame(maxWidth: .infinity, alignment: .leading)
}
HStack {
Button("Not Now") {
model.deferFailure()
}
.keyboardShortcut(.cancelAction)
Button("Retry") {
onRetry()
}
.keyboardShortcut(.defaultAction)
.buttonStyle(.borderedProminent)
}
}
.padding(24)
.frame(width: 460)
.onAppear(perform: refreshIfNewFailure)
.onChange(of: model.lastFailure) {
refreshIfNewFailure()
}
}
}
/// Refresh only on a new failure — never on clearing, so the card stays
/// rendered until the sheet dismisses it.
private func refreshIfNewFailure() {
if case .failed = model.lastFailure {
failure = model.lastFailure
}
}
}
#Preview {
EngineGateView(model: EngineGateModel())
}
#Preview("provisioning failure") {
ProvisioningFailureCard(
model: ProvisioningModel(),
onRetry: {},
)
}