CI / ci (push) Canceled after 0s
Only the writer's explicit confirmation promotes a Fix Card into a Learning — one confirm, one entry, never a repetition counter. The Learning is a plain markdown file under <home>/learnings/<type>s/ carrying the card's teaching fields (pattern, problem, diagnostic question, the demonstration example) plus promotion provenance; the instance-bound anchor and mechanical replacement stay on the card. Every pass consults these files via query_learnings; the Learnings pane replaces its placeholder. Promote consults the on-disk card as the truth and rejects symlinked learnings paths before any write (finish-audit round). Dismiss/decay follows in #27. Closes #26
119 lines
3.6 KiB
Swift
119 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
|
|
let home: URL
|
|
@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, home: home) {
|
|
case .promoted:
|
|
dismiss()
|
|
case let .refused(reason):
|
|
refusal = reason
|
|
}
|
|
}
|
|
}
|