CI / ci (push) Canceled after 0s
Wayfinder map #153, build slice 2 of the #154 contract: the pane's chrome joins the transcript's editorial voice (#155). Header per .pane-head — serif-15/600 "Mentor", engine status, mono-10 session chip; ready is the semantic green dot (DesignTokens.readyGreen, the palette's sole exception) + lowercase mono "ready", base version in the tooltip, the drift note kept visible. The segmented Pass 1 | Pass 2 | Chat picker is dead (settled #4): PassBarView always carries and owns the compact text-tab selector (2pt accent underline) over a PASS N · STATE status line, the cost line, and the actions as MonoButton — accent solid / surface+border / accent outline, the danger voice. Fix-cards row is the ruled plain mono link; crash, missing-engine, and starting states render as the quiet state-cards. Finish-audit fanout: security clean; orphaned MARK, stale doc comment, and a phantom-border comment fixed; pass-selector remount reset and solid-button contrast parked in the devlog (swift-wiki gotcha #28). Suite 592/592 (xcresult count), swiftformat + swiftlint clean at the error tier. Closes #153
398 lines
12 KiB
Swift
398 lines
12 KiB
Swift
//
|
||
// EngineStatusView.swift
|
||
// Museion
|
||
//
|
||
// #151 (map #148): the gateless engine-status surfaces — the rail pill
|
||
// and the anchored fail card (#149's variant-A verdict, prototype
|
||
// prototypes/GatelessStatusPrototype.swift). Quiet when healthy: once the
|
||
// engine answered and provisioning finished, nothing renders anywhere.
|
||
//
|
||
|
||
import SwiftUI
|
||
|
||
/// The pill/card state derivation — pure, test-pinned (#151). The gate's
|
||
/// phase machine is the source; a provisioning failure rides the same
|
||
/// failed surface under a passed gate.
|
||
enum EngineStatusSurface {
|
||
enum Visibility: Equatable {
|
||
case hidden
|
||
case pulsing
|
||
case failed
|
||
}
|
||
|
||
static func visibility(phase: EngineGateModel.Phase, provisioningFailed: Bool) -> Visibility {
|
||
switch phase {
|
||
case .idle: .hidden
|
||
case .checking: .pulsing
|
||
case .pass: provisioningFailed ? .failed : .hidden
|
||
case .fail: .failed
|
||
}
|
||
}
|
||
}
|
||
|
||
/// #149 variant A: the 44×44 rail slot above Archive — an 8pt pulsing
|
||
/// accent dot while checking (no text), the warning glyph on an accent-12%
|
||
/// wash when failed, nothing at all once healthy (the slot collapses and
|
||
/// the rail spacing closes). Slot click re-opens a collapsed fail card.
|
||
struct EngineStatusPill: View {
|
||
let visibility: EngineStatusSurface.Visibility
|
||
/// Opens the anchored card (only meaningful in the failed state).
|
||
var onOpen: () -> Void
|
||
|
||
var body: some View {
|
||
Button(action: onOpen) {
|
||
ZStack {
|
||
if visibility == .failed {
|
||
RoundedRectangle(cornerRadius: DesignTokens.radius)
|
||
.fill(DesignTokens.accent.opacity(0.12))
|
||
}
|
||
switch visibility {
|
||
case .pulsing:
|
||
Circle()
|
||
.fill(DesignTokens.accent)
|
||
.frame(width: 8, height: 8)
|
||
.pulsing()
|
||
case .failed:
|
||
Image(systemName: "exclamationmark.triangle.fill")
|
||
.font(.system(size: 15))
|
||
.foregroundStyle(DesignTokens.accent)
|
||
case .hidden:
|
||
EmptyView()
|
||
}
|
||
}
|
||
.frame(width: 44, height: 44)
|
||
}
|
||
.buttonStyle(.plain)
|
||
.help(helpText)
|
||
.accessibilityLabel(helpText)
|
||
}
|
||
|
||
private var helpText: String {
|
||
switch visibility {
|
||
case .pulsing: "Checking the engine"
|
||
case .failed: "Engine problem — click for details"
|
||
case .hidden: ""
|
||
}
|
||
}
|
||
}
|
||
|
||
/// The anchored fail card (#149): 340pt wide, bottom-leading at
|
||
/// railWidth + 12 / bottom 14 — surface bg, accent-0.5 border, radius 12,
|
||
/// shadow. Floats over content; never blocks, never pushes layout. Engine
|
||
/// failure and provisioning failure ride the same shell (#40 copy with the
|
||
/// gateless subtitle — nothing pauses).
|
||
struct EngineStatusCard: View {
|
||
let gate: AppGateState
|
||
let onCollapse: () -> Void
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 12) {
|
||
HStack(spacing: 8) {
|
||
Image(systemName: "exclamationmark.triangle.fill")
|
||
.foregroundStyle(DesignTokens.accent)
|
||
Text(title)
|
||
.font(.system(size: 15, weight: .semibold, design: DesignTokens.serif))
|
||
Spacer()
|
||
Button(action: onCollapse) {
|
||
Image(systemName: "chevron.down")
|
||
.font(.system(size: 10, weight: .semibold))
|
||
}
|
||
.buttonStyle(.plain)
|
||
.foregroundStyle(DesignTokens.muted)
|
||
.help("Collapse to the pill")
|
||
.accessibilityLabel("Collapse to the pill")
|
||
}
|
||
if case .fail = gate.gateModel.phase {
|
||
engineContent
|
||
} else {
|
||
setupContent
|
||
}
|
||
}
|
||
.padding(16)
|
||
.frame(width: 340, alignment: .leading)
|
||
.background(DesignTokens.surface, in: RoundedRectangle(cornerRadius: 12))
|
||
.overlay(RoundedRectangle(cornerRadius: 12).strokeBorder(DesignTokens.accent.opacity(0.5)))
|
||
.shadow(radius: 16, y: 4)
|
||
}
|
||
|
||
private var title: String {
|
||
if case .fail = gate.gateModel.phase {
|
||
return "Museion needs its engine"
|
||
}
|
||
return "Setup failed"
|
||
}
|
||
|
||
// MARK: Engine missing (#40 copy, gateless correction)
|
||
|
||
@ViewBuilder
|
||
private var engineContent: some View {
|
||
if case let .fail(firstProbePath, stderrExcerpt) = gate.gateModel.phase {
|
||
VStack(alignment: .leading, spacing: 12) {
|
||
Text(
|
||
"The Hermes engine wasn't found or didn't answer. Passes and Sessions need it — the editor keeps working.",
|
||
)
|
||
.font(.system(size: 12.5))
|
||
.foregroundStyle(DesignTokens.muted)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
|
||
installSteps
|
||
|
||
recheckRow
|
||
|
||
technicalDetails(stderrExcerpt: stderrExcerpt, firstProbePath: firstProbePath)
|
||
}
|
||
}
|
||
}
|
||
|
||
/// 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(DesignTokens.muted)
|
||
VStack(alignment: .leading, spacing: 4) {
|
||
Text(installCommand)
|
||
.font(.system(size: 11, design: DesignTokens.mono))
|
||
.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(DesignTokens.muted)
|
||
Text("Come back here and click Re-check.")
|
||
.font(.system(size: 12))
|
||
}
|
||
Link("Installation guide", destination: URL(string: "https://hermes-agent.nousresearch.com/docs")!)
|
||
.font(.system(size: 11))
|
||
}
|
||
.padding(12)
|
||
.background(DesignTokens.background, in: RoundedRectangle(cornerRadius: 8))
|
||
.overlay(RoundedRectangle(cornerRadius: 8).strokeBorder(DesignTokens.border))
|
||
}
|
||
|
||
private let installCommand = "curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash"
|
||
|
||
/// Re-check (#149): accent, disabled while checking, label "Checking…".
|
||
private var recheckRow: some View {
|
||
HStack {
|
||
Button {
|
||
Task { await gate.gateModel.runCheck() }
|
||
} label: {
|
||
HStack(spacing: 6) {
|
||
if gate.gateModel.phase == .checking {
|
||
ProgressView().controlSize(.small)
|
||
}
|
||
Text(gate.gateModel.phase == .checking ? "Checking…" : "Re-check")
|
||
}
|
||
.frame(minWidth: 120)
|
||
}
|
||
.buttonStyle(.borderedProminent)
|
||
.tint(DesignTokens.accent)
|
||
.disabled(gate.gateModel.phase == .checking)
|
||
Spacer()
|
||
}
|
||
}
|
||
|
||
/// stderr excerpt + the probed path. Empty stderr keeps the bare
|
||
/// Probed line (the not-found case answers nothing).
|
||
@ViewBuilder
|
||
private func technicalDetails(stderrExcerpt: String, firstProbePath: String) -> some View {
|
||
if !stderrExcerpt.isEmpty {
|
||
DisclosureGroup("Technical details") {
|
||
VStack(alignment: .leading, spacing: 6) {
|
||
Text(stderrExcerpt)
|
||
.font(.system(size: 10, design: DesignTokens.mono))
|
||
.foregroundStyle(DesignTokens.muted)
|
||
.textSelection(.enabled)
|
||
probedLine(firstProbePath)
|
||
}
|
||
.frame(maxWidth: .infinity, alignment: .leading)
|
||
}
|
||
.font(.system(size: 11))
|
||
} else {
|
||
probedLine(firstProbePath)
|
||
}
|
||
}
|
||
|
||
private func probedLine(_ firstProbePath: String) -> some View {
|
||
Text("Probed: \(firstProbePath)")
|
||
.font(.system(size: 10, design: DesignTokens.mono))
|
||
.foregroundStyle(DesignTokens.muted.opacity(0.7))
|
||
}
|
||
|
||
// MARK: Provisioning failure (#48 reborn, non-modal)
|
||
|
||
/// Live-reads the model: a successful Retry nils `lastFailure` and the
|
||
/// whole surface disappears — no dismiss-animation snapshot needed.
|
||
@ViewBuilder
|
||
private var setupContent: some View {
|
||
if case let .failed(profile, phase, excerpt) = gate.provisioning.lastFailure {
|
||
VStack(alignment: .leading, spacing: 12) {
|
||
Text(phase.rawValue)
|
||
.font(.system(size: 11, design: DesignTokens.mono))
|
||
.foregroundStyle(DesignTokens.muted)
|
||
if let profile {
|
||
// #134: the card names the failing profile — with three
|
||
// surface profiles, "which one?" is the first question.
|
||
Text(profile)
|
||
.font(.system(size: 10, design: DesignTokens.mono))
|
||
.foregroundStyle(DesignTokens.muted.opacity(0.7))
|
||
}
|
||
Text(
|
||
"Museion couldn't finish setting up the writing profiles. Nothing is lost — the setup is safe to run again.",
|
||
)
|
||
.font(.system(size: 12.5))
|
||
.foregroundStyle(DesignTokens.muted)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
|
||
HStack {
|
||
Button("Retry") {
|
||
Task {
|
||
await gate.provisioning.runPass(hermesBinary: gate.gateModel.currentBinaryPath)
|
||
}
|
||
}
|
||
.buttonStyle(.borderedProminent)
|
||
.tint(DesignTokens.accent)
|
||
Spacer()
|
||
}
|
||
|
||
if !excerpt.isEmpty {
|
||
DisclosureGroup("Technical details") {
|
||
Text(excerpt)
|
||
.font(.system(size: 10, design: DesignTokens.mono))
|
||
.foregroundStyle(DesignTokens.muted)
|
||
.textSelection(.enabled)
|
||
.frame(maxWidth: .infinity, alignment: .leading)
|
||
}
|
||
.font(.system(size: 11))
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// MARK: - Mentor header states (#151, #149's contract)
|
||
|
||
/// The mentor pane header's mono-10 engine states, one per gate verdict:
|
||
/// "checking the engine…" muted + mini spinner / "engine missing" accent
|
||
/// with help / "setup failed" accent / #156: the green ready-dot +
|
||
/// lowercase `ready` once ready (the base version rides the tooltip). The
|
||
/// gate's phase machine is the source; nil gate (previews) derives from
|
||
/// the mentor model alone.
|
||
struct MentorEngineStatus: View {
|
||
let gate: AppGateState?
|
||
let model: MentorSessionModel
|
||
|
||
/// #151: one state per gate verdict (internal — the pure mapping's
|
||
/// pins name the cases).
|
||
enum EngineState {
|
||
case checking
|
||
case engineMissing
|
||
case setupFailed
|
||
case ready
|
||
}
|
||
|
||
/// The gate-driven mapping, pure and test-pinned (#151) — engine
|
||
/// failure outranks a lingering provisioning failure (no engine →
|
||
/// Retry can't run anyway).
|
||
static func state(phase: EngineGateModel.Phase, provisioningFailed: Bool) -> EngineState {
|
||
switch phase {
|
||
case .idle, .checking: .checking
|
||
case .fail: .engineMissing
|
||
case .pass: provisioningFailed ? .setupFailed : .ready
|
||
}
|
||
}
|
||
|
||
/// No gate (previews): derive from the mentor model alone.
|
||
private var state: EngineState {
|
||
if let gate {
|
||
Self.state(phase: gate.gateModel.phase, provisioningFailed: gate.provisioning.hasFailure)
|
||
} else {
|
||
model.phase == .idle ? .checking : .ready
|
||
}
|
||
}
|
||
|
||
var body: some View {
|
||
switch state {
|
||
case .checking:
|
||
HStack(spacing: 5) {
|
||
ProgressView().controlSize(.mini)
|
||
Text("checking the engine…")
|
||
}
|
||
.font(.system(size: 10, design: DesignTokens.mono))
|
||
.foregroundStyle(DesignTokens.muted)
|
||
.layoutPriority(1)
|
||
case .engineMissing:
|
||
Text("engine missing")
|
||
.font(.system(size: 10, design: DesignTokens.mono))
|
||
.foregroundStyle(DesignTokens.accent)
|
||
.help("Passes and Sessions need the Hermes engine")
|
||
case .setupFailed:
|
||
Text("setup failed")
|
||
.font(.system(size: 10, design: DesignTokens.mono))
|
||
.foregroundStyle(DesignTokens.accent)
|
||
.help("Profile setup didn't finish — retry from the rail's status card")
|
||
case .ready:
|
||
// #156 (contract `.pane-head`): the ready signal is the semantic
|
||
// green dot + lowercase mono "ready" (#153 settle #6). The base
|
||
// version rides the tooltip; the advisory drift note stays visible
|
||
// (orange, pre-existing advisory) the rare time gate and handshake
|
||
// disagree.
|
||
HStack(spacing: 5) {
|
||
Circle()
|
||
.fill(DesignTokens.readyGreen)
|
||
.frame(width: 6, height: 6)
|
||
Text("ready")
|
||
if let note = model.versionNote {
|
||
Text(note)
|
||
.foregroundStyle(.orange)
|
||
.lineLimit(1)
|
||
.help(note)
|
||
}
|
||
}
|
||
.font(.system(size: 10, design: DesignTokens.mono))
|
||
.foregroundStyle(DesignTokens.muted)
|
||
.help(readyVersion.isEmpty ? "Engine ready" : "hermes \(readyVersion)")
|
||
.layoutPriority(1)
|
||
}
|
||
}
|
||
|
||
private var readyVersion: String {
|
||
if let engineVersion = model.engineVersion {
|
||
return engineVersion
|
||
}
|
||
if case let .pass(version, _)? = gate?.gateModel.phase {
|
||
return String(version.prefix(while: { $0 != "+" }))
|
||
}
|
||
return ""
|
||
}
|
||
}
|
||
|
||
/// The checking dot's pulse (#149: 8pt accent dot, pulsing). The
|
||
/// repeatForever animation rides the onAppear state flip — a constant
|
||
/// animation value never starts.
|
||
private struct PulsingModifier: ViewModifier {
|
||
@State private var dim = false
|
||
|
||
func body(content: Content) -> some View {
|
||
content
|
||
.opacity(dim ? 0.35 : 1)
|
||
.animation(.easeInOut(duration: 0.55).repeatForever(autoreverses: true), value: dim)
|
||
.onAppear { dim = true }
|
||
}
|
||
}
|
||
|
||
private extension View {
|
||
func pulsing() -> some View {
|
||
modifier(PulsingModifier())
|
||
}
|
||
}
|