// // FixCardsWindow.swift // Museion // // #23 follow-up (dogfood): the Fix Cards palette — the durable card // store's own surface, a floating window (scene id "fix-cards") opened // from the mentor pass bar. The transcript renders card tool calls as // one-line events; the card DETAIL lives here while the verdict gets // worked through. Show-only, never acts (Apply is #25). // import SwiftUI /// Palette body: the open piece's stored fix cards (`/cards/`, any /// MCP client's submissions — PostsModel re-derives on open/rescan, so this /// stays current via @Observable). Re-contextualizes as the piece changes. struct FixCardsPalette: View { @Environment(AppGateState.self) private var gate var body: some View { let posts = gate.posts VStack(alignment: .leading, spacing: 0) { if let title = openPieceTitle { Text(title) .font(.headline) .padding(.horizontal, 12) .padding(.top, 12) .padding(.bottom, 4) } if posts.openPieceCards.isEmpty { emptyState(hasPiece: posts.session?.postID != nil) } else { cardList(posts.openPieceCards) } } .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) // The window reads as app chrome, not a document — the same warm // cream the workspace root/rail paints (DesignTokens.background). .background(DesignTokens.background) } /// The pass label's title source — PostsModel's shared lookup. private var openPieceTitle: String? { guard let id = gate.posts.session?.postID else { return nil } return gate.posts.title(of: id) } private func emptyState(hasPiece: Bool) -> some View { VStack(alignment: .leading, spacing: 6) { Text(hasPiece ? "No fix cards yet." : "No piece open.") .font(.headline) Text(hasPiece ? "Run a pass — cards land here as the mentor files them." : "Open a post — its fix cards collect here.") .font(.callout) .foregroundStyle(.secondary) } .padding(12) .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) } /// The open piece's STORED fix cards (moved from MentorPaneView #23 S2.4 /// — uncapped here, the window owns its scroll). private func cardList(_ cards: [FixCardStore.StoredFixCard]) -> some View { ScrollView { VStack(alignment: .leading, spacing: 8) { Text("FIX CARDS · \(cards.count)") .font(.system(size: 11, design: DesignTokens.mono)) .foregroundStyle(DesignTokens.muted) ForEach(cards, id: \.id) { card in row(card) } } .padding(12) .frame(maxWidth: .infinity, alignment: .leading) } } /// One card: pattern title, problem + fix body, lane · emitter mono meta /// (ADR-0006). A stale anchor reads distinct — orange + caption — and is /// never appliable: v1 shows, never acts. private func row(_ card: FixCardStore.StoredFixCard) -> some View { let stale = card.anchorStatus == .stale var meta = "\(card.lane.rawValue) · \(card.emitter.rawValue)" if let pass = card.provenance?.pass { meta = "pass \(pass) · " + meta } if stale { meta += " · stale anchor" } return VStack(alignment: .leading, spacing: 6) { Label(card.pattern, systemImage: "rectangle.and.pencil.and.ellipsis") .font(.callout.weight(.semibold)) .foregroundStyle(stale ? .orange : DesignTokens.foreground) if !card.problem.isEmpty { Text(card.problem).font(.callout) } if !card.fix.isEmpty { Text("Fix: \(card.fix)").font(.callout) } Text(meta) .font(.system(size: 11, design: DesignTokens.mono)) .foregroundStyle(stale ? .orange : DesignTokens.muted) } .padding(10) .frame(maxWidth: .infinity, alignment: .leading) .background(.quaternary.opacity(0.3), in: RoundedRectangle(cornerRadius: 8)) } }