# Post Summary for Micro.blog (#208) > **Date:** 2026-12-05 > **Type:** issue > **Reference:** https://git.babylondreams.de/alex/Museion/issues/208 ## Goal Give the publish dialog a post-summary field plus an "AI summary" button. The summary is first-person, entices the reader to read the full piece, and travels to Micro.blog with the send. ## What Was Done - **Wire** (`Micropub.swift`): `makeDraftRequest`/`makeUpdateRequest`/`update`/`sendDraft` carry a `summary:` parameter. A create adds `properties.summary` only when non-empty; an update carries `summary` in `replace` only when the piece has the line (opt-in by key — `nil` leaves the post's summary alone, `""` clears it). One read (`updateRememberedOrCreate`) serves the wire fields, the categories, the summary, and the remembered URL. - **Codec** (`PostFrontmatter.swift`): `summaryValue(_:)` renders one line (whitespace runs — newlines included — collapse to one space, control characters drop; a value holding a quote or backslash renders QUOTED with the category codec's own escapes — one grammar for both keys). `summary(inText:)` reads it back off the RAW line: a parse-style block walk (past the opening fence to the next `---`) with a fused `\r\n---` tail strip, never through the lenient `parse` (which trims every edge quote) and never via `split` (whose closing-fence check a mixed-ending file defeats). `summary(in:)` — the lossy decoded read — was deleted (zero production consumers). - **Model** (`PostsModelMicropubSummary.swift`, `PostsModel.swift`, `PostsModelPasses.swift`): `summarize(mentor:)` = the shared open-piece guard rail → flush → ONE disk read feeds the prompt → `mentor.runSummary` on a fresh one-shot chat-profile engine → `SummaryPrompt.cleaned`. Writes nothing. `PostsModel.summarizing` is the one-shot rail's third rider; `oneShotRailBusy` is the ONE predicate the sheet, the pass bar's Cancel, `cancelPass`, and `guardOpenPieceRun` all consult. `micropubSend(categories:summary:)` stamps a pending summary edit at the send (write-before-wire — a failed stamp refuses with nothing on the wire); `micropubPublish` applies a pending edit first. - **Engine** (`MentorSessionModel.swift`): `runSummary(prompt:pieceTitle:)` rides `runOneShot` (label `Summary · `, reply read through `draftCandidateText`); exclusivity unchanged — a summary refuses while a Pass or Blind Read runs, and vice versa. - **Prompt** (`SummaryPrompt.swift`): `prompt(title:body:)` asks for a first-person teaser that entices the reader, reply = summary text only. `cleaned(_:)` trims, drops ONE leading `Summary:` label (colon required), strips ONE pair of surrounding quotes only when the inner text holds no other `"` (a wrapper, not a teaser that opens on a quoted word), then round-trips through the codec so the field shows exactly the text the wire will carry. - **Sheet** (`MicropubPublishSheet.swift`, `PostsPaneView.swift`): a Summary `TextEditor` (mono-11, 72pt) with the `AI summary` button in the label row; the reply fills the field for the writer to edit. The sheet holds `let mentor: MentorSessionModel` (PostsPaneView passes its own — the one construction site). Sync points mirror the Categories field: disk on open and after a forget, canonical one-line text after a successful send/publish, baseline only after a failed step. `MicropubSummaryField.pendingSummary` is a trimmed-STRING compare (whitespace alone is not an edit; equal empties stay nil — a piece without the line never gains an empty key). - **Cancel** (`MentorPaneView.swift`, `PostsModelPasses.swift`): the sheet is modal, so while its own summary turn runs the AI button IS the Stop (click → `cancelPass`); the pass bar's Cancel shows on `oneShotRailBusy`. - **Tests**: `MicropubSummaryTests.swift` (16 pins) + `SummaryGenerationTests.swift` (7 pins), plus `ScriptedEngine` mode `summaryOnPrompt` (a two-chunk summary-shaped reply, normal end, no fix-card call). 814 total (791 before). - **Docs**: `Museion/AGENTS.md` (SummaryPrompt, PostsModelMicropubSummary, the Micropub bullet, PostFrontmatter, PostStore, MentorSessionModel), `MuseionTests/AGENTS.md`, `GLOSSARY.md` Summary term, `PRD.md` S6.1, `CHANGELOG.md` [Unreleased]. ## Decisions & Rationale | Decision | Rationale | |----------|-----------| | The summary lives in a frontmatter `summary:` line, stamped at the send like `category:` (owner ruling) | Survives reopen, rides every re-send, visible in the file — the same discipline the category line established in #207. A sheet-only value would be lost on every reopen and could never be re-sent. | | The AI summary runs on the one-shot engine on the chat profile, never the resident session (owner ruling) | The resident session is the writer's conversation; a drafting side-quest would pollute its transcript. The one-shot rail (ADR-0014) spawns, drafts, and tears down — the Blind Read's proven shape. | | Create carries `summary` only when non-empty; update carries it in `replace` only when the line exists (opt-in by key); `""` clears | Mirrors #207 exactly. Without the opt-in, every re-send of a piece without a line would wipe a summary set on Micro.blog itself. | | The reader walks the RAW line, never `parse` | The lenient decode trims every edge quote — a teaser ending in `"why"` would lose its quotes through that door. Raw-line read + codec unescape keeps the writer's text exact. | | `summary(in:)` deleted rather than kept beside `summary(inText:)` | Zero production consumers and lossy by design. Two readers for one key invite the wrong one at a new call site. | | `oneShotRailBusy` as ONE computed predicate over three riders | The sheet, both Cancels, the guard, and `cancelPass` all need the same answer. One predicate: a fourth rider joins here and every site follows. | | `lastError` for refusals (not a `Result` return) | House posture — `blindRead` and `runPass` report through `lastError`; the sheet already renders the strip. A typed result would be the only one of its kind. | | Refusals keep the field's text | The writer may have typed a summary by hand before clicking AI; a refusal must not eat it. | | The AI button is the Stop during its own turn | The sheet is modal — the pass bar's Cancel is unreachable behind it. Without this, a hung turn would wedge the sheet with no way out. | | `cleaned` strips edge quotes only when no `"` remains inside | A reply opening and closing on quoted words is a teaser; its edge quotes are the writer's. Only a true wrapper (nothing quoted inside) strips. | ## Gotchas & Fixes | Problem | Root Cause | Fix | |---|---|---| | A mixed-ending `post.md` (a stray `\r` on the last block line) fused the closing fence; the lenient reader still saw the key → re-send path, a `split`-based reader found no block → `""` → `replace summary [""]` would wipe a LIVE post's summary | Two readers of one file disagreed on where the block ends | `summary(inText:)` walks the block the way `parse` does and strips a fused `\r\n---` tail; the mixed-ending wire pin went red on exactly this guard (FLIP-A) | | An unfenced body line named `summary:` was read as the summary | The reader did not require a fence | The parse-style walk requires an opening fence; body prose never claims the key | | A hung summary turn could not be cancelled from the modal sheet | The AI button had no Stop behavior and the pass bar's Cancel was behind the sheet | Model `summarizing` flag + `oneShotRailBusy`; the AI button doubles as Stop; `cancelPass` and `guardOpenPieceRun` consult the predicate. Flip: disabling `cancelPass`'s guard hangs the cancel pin (the timeout is the red). | | The first cancel pin's observable was wrong — asserting `runningPass == nil` held through the host's own one-shot lock, so the flip reddened nothing | A third belt masked the guard under test | The pin asserts `lastError == "A summary is already running."` instead; the flip then reddened exactly that pin | | `cleaned`'s wrapper rule stripped the edge quotes of prose bracketed by quoted words | The rule matched any string starting and ending with `"` | Strip only when the inner text holds no further `"`; pinned, flip-verified (FLIP-B) | | The audit round's own edits left 3 lint regressions (a missing blank line after a computed property; a lone `{` under a wrapped condition; a 144-char test line) | Hand edits after the last lint run | Fixed; the lone-brace was the house trap (#142/#179) — hoisted an `isQuotedWrapper` predicate | ## Files Changed | File | Change Summary | |------|---------------| | `Museion/Micropub.swift` | `summary:` on the draft/update builders; create carries when non-empty, update in `replace` by key; one read serves wire fields + categories + summary + URL | | `Museion/PostFrontmatter.swift` | `summaryValue` (one-line render, quote-aware) + `summary(inText:)` (raw-line read, parse-style walk, fused-fence strip); `summary(in:)` deleted | | `Museion/PostsModelMicropubSummary.swift` | new — `summarize(mentor:)`: guard rail → flush → one disk read → `runSummary` → `cleaned`; nil + `lastError` on refusal | | `Museion/SummaryPrompt.swift` | new — the prompt + `cleaned` (label drop, wrapper-only quote strip, codec round-trip) | | `Museion/PostsModel.swift` | `summarizing` flag; `oneShotRailBusy` predicate; `micropubSend(categories:summary:)`; `micropubPublish` applies a pending edit first | | `Museion/PostsModelPasses.swift` + `Museion/MentorPaneView.swift` | `cancelPass` + `guardOpenPieceRun` honor `oneShotRailBusy`; the pass bar's Cancel shows on it | | `Museion/MicropubPublishSheet.swift` | Summary field + AI summary button (doubles as Stop); sync mirrors the Categories field | | `Museion/PostsPaneView.swift` | the sheet takes the pane's own `mentor` | | `Museion/MentorSessionModel.swift` | `runSummary` over `runOneShot` | | `Museion/PostStore.swift` | `stampMicropub` carries the `summary:` line | | `MuseionTests/ScriptedEngine.swift` | `summaryOnPrompt` mode | | `MuseionTests/MicropubSummaryTests.swift` | new — 16 pins | | `MuseionTests/SummaryGenerationTests.swift` | new — 7 pins | | `GLOSSARY.md`, `PRD.md`, `CHANGELOG.md`, `Museion/AGENTS.md`, `MuseionTests/AGENTS.md` | Summary term, S6.1 clause, [Unreleased] entry, DOX rows | ## Verification - Finish-audit gates (final tree): `swiftformat --lint .` 0/161 · `swiftlint --strict .` 0 violations · `full-test.sh` **814/814** (run `20261205T095042Z-Museion`; 791 → 814, +23). The three files edited during the audit compiled in that run (SwiftCompile lines present). - Flips: fused-fence strip → exactly the 2 mixed-ending pins red; `cleaned` wrapper rule → exactly the bracketed-prose pin; `guardOpenPieceRun` summarizing refusal → exactly the reverse-exclusivity pin; `cancelPass` guard → the cancel pin hangs. All restored byte-exact (`cmp` + sha256). - Baseline before the audit: 809/809 on the pre-audit tree. ## Open Items & Next Steps - [ ] Owner to try the live sheet: the AI button's Stop behavior and the one-shot rail refusal are SwiftUI wiring, not host-testable. - [ ] Ticket candidate: Convert to Post rebuilds frontmatter and drops a piece's `summary:` line (#114 posture — same as `category:`). - [ ] Ticket candidate: a malformed frontmatter block lets a stamp land in the wrong place — pre-existing for every stamp, not #208's seam. --- *Log written by write-log skill*