feat(microblog): post summary for Micro.blog

A piece's `summary:` frontmatter line now travels to Micro.blog
beside `category:`. A first send carries the summary when it is not
empty; a re-send replaces the post's summary only when the piece has
the line (opt-in by key; an empty value clears it; no line leaves the
blog's). The same rule as categories, so a piece that never gained
the line cannot blank a summary set on Micro.blog itself.

The publish sheet gains a Summary field and an AI summary button. The
button drafts a first-person teaser from the open piece on a fresh
one-shot engine on the chat profile (the Blind Read's rail — the
resident session is never touched); the reply fills the field for the
writer to edit, and nothing is written until the send stamps the
line. The sheet is modal, so while its own turn runs the button is
the Stop; a Pass or Blind Read that owns the rail disables the button
with the reason on hover and refuses from behind it.

The summary is read off the RAW frontmatter line, never through the
lenient decode — which trims every edge quote — and the read walks
the block the way the lenient reader does. A `split`-based read finds
no block in a mixed-ending file while the lenient reader still sees
the key, and the empty value it answers would have been sent over a
live post's summary.

Reviewed twice (two-axis during the build, three-reviewer
finish-audit after): the mixed-ending read, an unfenced body line
claiming the key, the uncancellable modal turn, and the wrapper rule
eating a teaser's edge quotes were found and fixed before this
commit. Every guard was watched fail on its own pin. Rail 814/814;
SwiftFormat and SwiftLint clean.

Docs: AGENTS.md bullets and learnings, the GLOSSARY term, CHANGELOG
[Unreleased], PRD S6.1, and the devlog.

Closes #208
This commit is contained in:
AlexKucera committed 2026-12-05 12:32:38 +01:00
1 parent 6db4cf8cf1
commit 36393a9e8e
22 files changed
+1096 -36

No files matched your search

+135 -4
View File
@@ -28,6 +28,12 @@
// canonical text after a successful send, and after a failed step
// only its baseline re-syncs (the send writes the line before the
// wire — a later clear must still count as an edit).
// #208: a Summary field — the piece's `summary:` scalar, typed or
// drafted by the `AI summary` button (a one-shot chat-profile
// engine; the reply fills the field, the writer edits). Same
// discipline as Categories: the edit lands AT THE SEND, the field
// syncs on open/forget and settles from disk after a send. While the
// turn runs the button is the sheet's own Stop (the sheet is modal).
//
import SwiftUI
@@ -108,9 +114,25 @@ nonisolated enum MicropubCategoryField {
}
}
/// #208: the publish sheet's Summary field — its pure rules. The
/// edit-for-send test is a STRING compare (not a list), so a
/// trailing-space difference is not an edit and equal empties stay
/// nil (a piece without a line never gains an empty key).
nonisolated enum MicropubSummaryField {
/// The sheet's edit for the model: nil when the field IS the
/// settled one (both trimmed — whitespace alone is not an edit);
/// else the field's text ("" = cleared — the model writes
/// `summary:` empty and the re-send clears the post's).
static func pendingSummary(field: String, settled: String) -> String? {
let f = field.trimmingCharacters(in: .whitespacesAndNewlines)
return f == settled.trimmingCharacters(in: .whitespacesAndNewlines) ? nil : f
}
}
/// #33 (S6.1): the two-step Micro.blog ask over the open piece.
struct MicropubPublishSheet: View {
let posts: PostsModel
let mentor: MentorSessionModel
@Environment(\.dismiss) private var dismiss
private enum Phase: Equatable {
@@ -147,6 +169,11 @@ struct MicropubPublishSheet: View {
/// Whether the blog's categories were ever fetched in this sheet
/// (a blog with none is not re-asked after every send).
@State private var suggestionsLoaded = false
/// #208: the Summary field as typed, and the text it rests on (the
/// disk read on open, or a successful send's canonical form — the
/// pending-edit baseline).
@State private var summaryField = ""
@State private var settledSummaryField = ""
/// Token entry shows when none is saved — or again after an auth
/// failure (the entered-once token can be replaced, never a dead end).
@@ -163,6 +190,11 @@ struct MicropubPublishSheet: View {
MicropubCategoryField.pendingCategories(field: categoryField, settled: settledCategoryField)
}
/// #208: the Summary field's edit for the send — nil when nothing changed.
private var pendingSummary: String? {
MicropubSummaryField.pendingSummary(field: summaryField, settled: settledSummaryField)
}
var body: some View {
VStack(alignment: .leading, spacing: 12) {
Text(publishedAt == nil ? "Publish to Micro.blog?" : "On Micro.blog")
@@ -196,6 +228,43 @@ struct MicropubPublishSheet: View {
.foregroundStyle(DesignTokens.muted)
}
// #208: the Summary field, in every phase — a send is possible in all of them.
VStack(alignment: .leading, spacing: 4) {
HStack(spacing: 6) {
Text("Summary")
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.muted)
Spacer()
Button {
draftSummary()
} label: {
if summarizing {
ProgressView().controlSize(.small)
} else {
Text("AI summary")
}
}
.buttonStyle(.bordered)
.controlSize(.small)
// Disabled-with-reason (the pass bar's idiom) while ANOTHER
// rider owns the rail or a send runs — but never while this
// sheet's own summary turn runs: the spinner is the Stop.
.disabled(busy || (!summarizing && posts.oneShotRailBusy))
.help(summarizing ? "Stop the summary turn." : summaryButtonHelp)
.accessibilityLabel(summarizing ? "Stop summary" : "AI summary")
}
TextEditor(text: $summaryField)
.font(.system(size: 11, design: DesignTokens.mono))
.frame(height: 72)
.scrollContentBackground(.hidden)
.background(RoundedRectangle(cornerRadius: 6).stroke(DesignTokens.muted.opacity(0.35)))
.disabled(busy || posts.summarizing)
.accessibilityLabel("Summary")
Text("Shown by Micro.blog in feeds and cross-posts. One or two sentences, first person — line breaks become spaces.")
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.muted)
}
if showsTokenField {
SecureField("App token", text: $tokenField)
.textFieldStyle(.roundedBorder)
@@ -265,7 +334,7 @@ struct MicropubPublishSheet: View {
.frame(maxWidth: .infinity, alignment: .trailing)
}
.padding(16)
.frame(width: 340, alignment: .leading)
.frame(width: 420, alignment: .leading)
.onAppear {
// A piece sent in an earlier session still has its record:
// the remembered URL, and (#206) its publish stamp.
@@ -276,6 +345,7 @@ struct MicropubPublishSheet: View {
publishedAt = post.micropubPublished
phase = settledPhase
syncFieldFromDisk()
syncSummaryFromDisk()
loadSuggestions()
}
}
@@ -356,6 +426,7 @@ struct MicropubPublishSheet: View {
refusal = message
phase = settledPhase
syncSettledFromDisk()
syncSettledSummaryFromDisk()
}
/// Step 1 — the model decides create-vs-update by the piece's
@@ -369,7 +440,7 @@ struct MicropubPublishSheet: View {
refusal = nil
phase = postURL == nil ? .drafting : .updating
Task {
switch await posts.micropubSend(token: token, categories: pendingCategories) {
switch await posts.micropubSend(token: token, categories: pendingCategories, summary: pendingSummary) {
case let .drafted(url, preview):
postURL = url
previewURL = preview
@@ -401,11 +472,12 @@ struct MicropubPublishSheet: View {
refusal = nil
phase = .publishing
Task {
switch await posts.micropubPublish(url: url, token: token, categories: pendingCategories) {
switch await posts.micropubPublish(url: url, token: token, categories: pendingCategories, summary: pendingSummary) {
case .published:
publishedAt = Date()
phase = .published
settle()
syncSummaryFromDisk()
case let .authFailed(detail):
fail("Micro.blog rejected the token: \(detail)", tokenRejected: true)
case let .refused(reason), let .unreachable(reason):
@@ -433,6 +505,7 @@ struct MicropubPublishSheet: View {
// line the failed send already wrote stays on the piece, so the
// field re-syncs to it (no false pending state).
syncFieldFromDisk()
syncSummaryFromDisk()
}
// MARK: Categories (#207)
@@ -479,13 +552,71 @@ struct MicropubPublishSheet: View {
settledCategoryField = categoryField
}
/// A successful send: the field settles, and a token first entered
/// A successful send: the fields settle, and a token first entered
/// in this sheet gets its suggestions now — once. A blog WITH no
/// categories is not asked again after every send.
private func sendLanded() {
settle()
syncSummaryFromDisk()
if !suggestionsLoaded {
loadSuggestions()
}
}
// MARK: Summary (#208)
/// The piece's `summary:` line as it is on DISK (the model's read).
private var diskSummaryText: String {
posts.openPieceSummary()
}
/// The field AND its baseline take the disk's line (on open, after a forget).
private func syncSummaryFromDisk() {
summaryField = diskSummaryText
settledSummaryField = summaryField
}
/// Only the BASELINE follows the disk (a failed step — the send
/// writes the line before the wire; the Categories discipline).
private func syncSettledSummaryFromDisk() {
settledSummaryField = diskSummaryText
}
/// #208: the AI button's hover reason — the disabled state says why
/// (the pass bar's idiom).
private var summaryButtonHelp: String {
posts.oneShotRailBusy
? "A Pass, Blind Read, or summary is running — the engine is busy."
: "Drafts a first-person teaser from the piece — edit it before sending."
}
/// #208: the AI draft — a fresh one-shot chat-profile engine reads
/// the piece and the reply fills the field for the writer to edit.
/// A refusal shows inline (the field keeps its text). While the turn
/// runs the button is the sheet's OWN Stop (the sheet is modal — the
/// pass bar's Cancel sits behind it): `cancelPass` ends the turn on
/// the shared rail, and `summarizing` follows the model's flag so a
/// stop from anywhere clears the spinner.
private var summarizing: Bool {
posts.summarizing
}
private func draftSummary() {
guard !summarizing else {
// The spinner IS the stop: a hung engine must not hold the
// sheet.
posts.cancelPass(mentor: mentor)
return
}
refusal = nil
Task {
// The model owns the flag; the reply fills the field, a
// refusal lands inline.
if let text = await posts.summarize(mentor: mentor) {
summaryField = text
} else {
refusal = posts.lastError ?? "The engine didn't return a summary — try again."
}
}
}
}