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

+81 -14
View File
@@ -10,7 +10,11 @@
// it when non-empty (naming a category Micro.blog doesn't know
// creates it there), a re-send carries it in `replace` only when the
// piece has the line (`[]` clears; no line leaves the blog's). The
// blog's own list for the sheet's suggestions: MicropubCategories.swift.
// The blog's own list for the sheet's suggestions: MicropubCategories.swift.
// #208: the piece's `summary:` line TRAVELS the same way — a create
// carries it when non-empty, a re-send carries it in `replace` only
// when the piece has the line ("" clears). The AI half that drafts it
// rides a one-shot engine (SummaryPrompt.swift / PostsModelMicropubSummary.swift).
// #34 (S6.2): uploaded illustrations rewrite their asset refs IN
// PLACE with the uploaded URLs (position is the writer's) — the
// media surface (parse/upload/config/rewrite) lives in
@@ -82,16 +86,15 @@ nonisolated enum Micropub {
return request
}
static func makeDraftRequest(title: String, body: String, token: String, categories: [String] = []) -> URLRequest {
static func makeDraftRequest(title: String, body: String, token: String, categories: [String] = [], summary: String = "") -> URLRequest {
// h=entry with markdown content and name for the title; the
// Title publishes as the entry's name, the body ships verbatim
// (GLOSSARY: never stripped) — the one carve-out is #34's asset
// illustration refs, which REWRITE to their uploaded URLs on
// the WIRE (position and alt are the writer's; the piece on
// disk never changes). No photo property: it would render
// (GLOSSARY: any carve-out rewrites on the WIRE only — the piece
// on disk never changes). No photo property: it would render
// wherever the theme decides, not where placed (2026-11-01).
// #207: the categories travel — naming one Micro.blog doesn't
// know creates it there; no list, no key.
// #208: the summary travels when non-empty.
var properties: [String: Any] = [
"name": [title],
"content": [body],
@@ -100,6 +103,9 @@ nonisolated enum Micropub {
if !categories.isEmpty {
properties["category"] = categories
}
if !summary.isEmpty {
properties["summary"] = [summary]
}
return jsonPost(["type": ["h-entry"], "properties": properties], token: token)
}
@@ -118,7 +124,17 @@ nonisolated enum Micropub {
/// #207: `categories` opts the post's categories into `replace` —
/// a list (even empty: it clears them) is sent as written; nil
/// leaves whatever the post has.
static func makeUpdateRequest(url: String, title: String, body: String, token: String, categories: [String]? = nil) -> URLRequest {
/// #208: `summary` opts the summary into `replace` the same way —
/// a string (even empty: it clears it) is sent as written; nil
/// leaves whatever the post has.
static func makeUpdateRequest(
url: String,
title: String,
body: String,
token: String,
categories: [String]? = nil,
summary: String? = nil,
) -> URLRequest {
var replace: [String: Any] = [
"name": [title],
"content": [body],
@@ -126,6 +142,9 @@ nonisolated enum Micropub {
if let categories {
replace["category"] = categories
}
if let summary {
replace["summary"] = [summary]
}
return jsonPost([
"action": "update",
"url": url,
@@ -144,9 +163,10 @@ nonisolated enum Micropub {
body: String,
token: String,
categories: [String] = [],
summary: String = "",
transport: Transport = urlSessionTransport,
) async -> Outcome {
let request = makeDraftRequest(title: title, body: body, token: token, categories: categories)
let request = makeDraftRequest(title: title, body: body, token: token, categories: categories, summary: summary)
return await run(request, transport: transport, decodeDraftURL: true)
}
@@ -164,16 +184,18 @@ nonisolated enum Micropub {
/// #206: step 1 again, in place — the piece's current title and
/// body replace the remembered post's (a draft refreshed for
/// review; a live post edited). Needs the remembered URL. #207:
/// `categories` non-nil also replaces the post's categories.
/// `categories` non-nil also replaces the post's categories. #208:
/// `summary` non-nil also replaces the post's summary.
static func update(
url: String,
title: String,
body: String,
token: String,
categories: [String]? = nil,
summary: String? = nil,
transport: Transport = urlSessionTransport,
) async -> Outcome {
let request = makeUpdateRequest(url: url, title: title, body: body, token: token, categories: categories)
let request = makeUpdateRequest(url: url, title: title, body: body, token: token, categories: categories, summary: summary)
let outcome = await run(request, transport: transport, decodeDraftURL: false)
// `run` has one success word for the URL-less steps; the update's
// carries the URL it touched.
@@ -356,6 +378,19 @@ extension PostsModel {
return PostFrontmatter.categories(in: PostFrontmatter.parse(raw))
}
/// #208: the open piece's summary as it is on DISK — what the
/// publish sheet's field syncs to (the Categories discipline,
/// never the scan snapshot). The raw line read: the lenient parse
/// would trim a teaser's closing quote. No open saved piece or no
/// line → "".
func openPieceSummary() -> String {
guard let piece = openMicropubPiece,
let file = PostStore.folder(of: piece.id, home: piece.home)?.appendingPathComponent("post.md"),
let raw = try? String(contentsOf: file, encoding: .utf8)
else { return "" }
return PostFrontmatter.summary(inText: raw)
}
/// Step 1 of the two-step publish: send the OPEN piece to Micro.blog
/// (name = Title, markdown content). runPass's guard set minus
/// the engine gates (no engine involved); flush-first so the wire
@@ -376,11 +411,17 @@ extension PostsModel {
/// flush and before the ONE disk read that feeds the wire, so disk
/// and blog never disagree. A category write that cannot land
/// REFUSES the send — nothing goes out.
/// #208: `summary` rides the same posture — nil = no edit, the
/// piece's line is used as written; non-nil = that text is written
/// to the piece FIRST (sanitized to one line), after the flush and
/// before the one disk read. A write that cannot land REFUSES the
/// send — nothing goes out.
/// #179: outside the write rail by design — publish is not a library
/// verb, and a stamp failure must never un-send the draft.
func micropubSend(
token: String,
categories: [String]? = nil,
summary: String? = nil,
transport: Micropub.Transport = Micropub.urlSessionTransport,
) async -> Micropub.Outcome {
guard let piece = openMicropubPiece else {
@@ -392,12 +433,14 @@ extension PostsModel {
if let refused = stampCategories(categories, piece: piece) {
return refused
}
if let refused = stampSummary(summary, piece: piece) {
return refused
}
// Disk is the truth post-flush — ONE read serves the wire fields:
// Title (heading markers stripped — it publishes as the entry's
// name), the frontmatter-stripped body (the stamp is
// bookkeeping, never prose; the body itself is never stripped,
// GLOSSARY), the remembered URL, and the categories. No scan
// dependency: the list can lag the open piece.
// GLOSSARY), the remembered URL, the categories, and the summary.
guard let dir = PostStore.folder(of: piece.id, home: piece.home),
let raw = try? String(contentsOf: dir.appendingPathComponent("post.md"), encoding: .utf8)
else {
@@ -442,6 +485,20 @@ extension PostsModel {
return nil
}
/// #208: the sheet's summary edit lands on the piece HERE — the
/// Categories posture (after the flush, before the one read that
/// feeds the wire). nil is no edit. The refusal when the line
/// cannot land: the send stops here and nothing goes out.
private func stampSummary(_ summary: String?, piece: (id: String, home: URL)) -> Micropub.Outcome? {
guard let summary else { return nil }
do {
try PostStore.stampMicropub(piece.id, home: piece.home, [("summary", PostFrontmatter.summaryValue(summary))])
} catch {
return .refused("Couldn't save this piece's summary — nothing was sent. (\(error.localizedDescription))")
}
return nil
}
/// The wire step over the disk's text (`raw` — the Title and the
/// frontmatter come from it) and the wire body. #206: a piece that
/// remembers its post UPDATES it in place (the remembered URL never
@@ -456,6 +513,11 @@ extension PostsModel {
/// #207: a create carries the categories when non-empty (never
/// `[]`); an update carries `category` only when the piece HAS the
/// line — opt-in by key, `[]` clears, no line leaves the blog's.
/// #208: the summary rides the same rule — a create carries it
/// when non-empty; an update carries `summary` only when the piece
/// HAS the line (opt-in by key, `""` clears, no line leaves the
/// blog's). Read off the raw line (`summary(inText:)`): the lenient
/// parse trims a closing quote the teaser may own.
private func updateRememberedOrCreate(
raw: String,
wireBody: String,
@@ -465,6 +527,7 @@ extension PostsModel {
) async -> Micropub.Outcome {
let matter = PostFrontmatter.parse(raw)
let title = Post.title(of: raw)
let summaryLine = matter["summary"] != nil
if let remembered = Micropub.rememberedURL(matter) {
let outcome = await Micropub.update(
url: remembered,
@@ -472,6 +535,7 @@ extension PostsModel {
body: wireBody,
token: token,
categories: matter["category"] != nil ? PostFrontmatter.categories(in: matter) : nil,
summary: summaryLine ? PostFrontmatter.summary(inText: raw) : nil,
transport: transport,
)
if case .requestFailed(404, _) = outcome {
@@ -484,6 +548,7 @@ extension PostsModel {
body: wireBody,
token: token,
categories: PostFrontmatter.categories(in: matter),
summary: PostFrontmatter.summary(inText: raw),
transport: transport,
)
if case let .drafted(url, _) = outcome {
@@ -508,10 +573,12 @@ extension PostsModel {
/// draft a create returned — never the caller's URL, which the
/// sheet may hold stale against the disk. A failed send returns its
/// outcome with NO publish — disk and blog never silently disagree.
/// #208: `summary` rides the same applies-first posture.
func micropubPublish(
url: String,
token: String,
categories: [String]? = nil,
summary: String? = nil,
transport: Micropub.Transport = Micropub.urlSessionTransport,
) async -> Micropub.Outcome {
guard let piece = openMicropubPiece else {
@@ -521,8 +588,8 @@ extension PostsModel {
return .refused("That post address isn't a clean https URL — nothing was sent or remembered.")
}
var target = url
if let categories {
switch await micropubSend(token: token, categories: categories, transport: transport) {
if categories != nil || summary != nil {
switch await micropubSend(token: token, categories: categories, summary: summary, transport: transport) {
case let .updated(touched):
target = touched
case let .drafted(fresh, _):