Files
museion/Museion/PromoteAskSheet.swift
AlexKucera 5bf09552f6
CI / ci (push) Canceled after 0s
refactor(posts): route every library write through one rail
#179: every library-reflecting store write (draft save, session-born
post, rename, move to project, archive/restore, trash, convert,
project creation, import batch, pass advance) now rides one internal
seam — performWrite pairs the write with exactly one rescan and owns
the error strip (cleared BEFORE the write so importFiles' per-file
failure messages survive the success tail; a nil-Home refusal writes
nothing). The model owns the Home: watchedHome is private(set), set
only by bind (construction + the Settings repoint); no public method
takes a Home parameter — 14 view call sites and ~115 test call sites
swept, dead home plumbing cut. The editor's debounced flush, the card
closes, the pass substrate and the micropub publish stay off the rail
by design (own error semantics, no library regroup).

A converged review finding is closed with a guard: the pass advance
re-resolves watchedHome after the engine's minutes-long turn, so a
mid-pass Settings repoint now refuses the advance with an honest strip
message instead of silently stamping pass state into the repointed
library (wrong-piece write on a slug collision). createProject
failures now surface in the sheet AND the strip — the rail-owns-the-
strip posture supersedes the #108 sheet-only rule.

Five rail pins (PostsModelWriteRailTests, suite members): write → one
library refresh + strip cleared, failed write owns the strip, nil-Home
refusal, import batch keeps per-file messages, mid-pass repoint
refuses the advance — the last two flip-verified against their guards.
ScriptedEngine gains endHeldPrompt (release a held turn as ended).

Verification: suite 657/657 the evening this landed; the next-morning
re-run could not start — both test runners hung before establishing
connection (#134 testmanagerd wedge; an untouched control suite hangs
identically — machine state, not this diff; reboot pending). Rail pins
5/5 isolated after the last test-only edit; swiftlint at baseline
parity; swiftformat clean.

Closes #179

[Generated by AI]
2026-11-10 08:45:04 +01:00

118 lines
3.6 KiB
Swift

//
// PromoteAskSheet.swift
// Museion
//
// #26 (S4.1): the promotion ask, extracted from FixCardsWindow.swift
// (file was past its length ceiling; OutlineRowTextView precedent).
//
import SwiftUI
/// #26 (S4.1): the promotion ask — ONE explicit confirmation writes ONE
/// plain markdown Learning (never a repetition counter; the store refuses
/// the second). The design contract's #promoteDialog: title, the consulted-
/// on-future-Passes body, a learning preview, Cancel/Promote. Promote is
/// the sheet's only write path; Cancel writes nothing; a refusal shows its
/// reason with the buttons kept (ApplyAskSheet posture).
struct PromoteAskSheet: View {
let card: FixCardStore.StoredFixCard
let posts: PostsModel
@Environment(\.dismiss) private var dismiss
@State private var refusal: String?
var body: some View {
VStack(alignment: .leading, spacing: 12) {
ScrollView {
VStack(alignment: .leading, spacing: 12) {
Text("Promote to Learnings?")
.font(.headline)
Text(
"This pattern will be consulted on future Passes for \(typePlural). "
+ "Museion will write one plain markdown Learning.",
)
.font(.callout)
// The Learning preview: pattern, problem, provenance —
// the file the confirm writes.
VStack(alignment: .leading, spacing: 6) {
Text(card.pattern)
.font(.callout.weight(.semibold))
if !card.problem.isEmpty {
Text(card.problem).font(.callout)
}
// The preview shows what lands: the diagnostic
// and, on demonstration lanes, the example the
// Learning will carry.
if !card.diagnosticQuestion.isEmpty {
Text(card.diagnosticQuestion).font(.callout)
}
if card.lane == .demonstration, !card.fix.isEmpty {
Text("Example: \(card.fix)").font(.callout)
}
if !provenanceLine.isEmpty {
Text(provenanceLine)
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.muted)
}
}
.padding(8)
.frame(maxWidth: .infinity, alignment: .leading)
.background(.quaternary.opacity(0.3), in: RoundedRectangle(cornerRadius: 6))
if let refusal {
Text(refusal)
.font(.callout)
.foregroundStyle(.orange)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
}
HStack(spacing: 8) {
Button("Promote") { promote() }
.buttonStyle(.borderedProminent)
Button("Cancel") { dismiss() }
.buttonStyle(.bordered)
}
.frame(maxWidth: .infinity, alignment: .trailing)
}
.padding(16)
.frame(width: 320, alignment: .leading)
}
/// The open piece's content type, pluralized; "pieces" when unknown.
private var typePlural: String {
guard let id = posts.session?.postID,
let type = posts.posts.first(where: { $0.id == id })?.type
else { return "pieces" }
return type == .post ? "Posts" : "Outlines"
}
/// "<piece title> · Pass N · <engine> · <date>" — provenance.piece is
/// the piece id, resolved through the model's title lookup (fallback:
/// the id); missing parts drop out, date falls back to promotedAt.
private var provenanceLine: String {
var parts: [String] = []
if let pieceID = card.provenance?.piece {
parts.append(posts.title(of: pieceID))
}
if let pass = card.provenance?.pass {
parts.append("Pass \(pass)")
}
if let engine = card.provenance?.engine {
parts.append(engine)
}
if let date = card.provenance?.date {
parts.append(date)
}
return parts.joined(separator: " · ")
}
private func promote() {
switch posts.promoteCard(card) {
case .promoted:
dismiss()
case let .refused(reason):
refusal = reason
}
}
}