// // 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" } #Preview { EngineGateView(model: EngineGateModel()) }