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
58 lines
2.3 KiB
Swift
58 lines
2.3 KiB
Swift
//
|
|
// PostsModelMicropubSummary.swift
|
|
// Museion
|
|
//
|
|
// SummaryPrompt.swift's model half — #208: PostsModel.summarize drafts
|
|
// a first-person summary of the OPEN piece on a fresh one-shot
|
|
// chat-profile engine and hands the text to the caller. The write is
|
|
// NOT here — the send stamps the frontmatter `summary:` line
|
|
// (PostFrontmatter, slice 1).
|
|
//
|
|
|
|
import Foundation
|
|
|
|
@MainActor
|
|
extension PostsModel {
|
|
/// #208: draft a first-person summary of the OPEN piece on a fresh
|
|
/// one-shot chat-profile engine. Flush-first (the engine reads
|
|
/// disk); the guards are the shared open-piece rail's. Returns the
|
|
/// cleaned reply, or nil with `lastError` set naming the blocker
|
|
/// (nothing running / not ready / no open piece / the engine said
|
|
/// nothing). Writes NOTHING — the text is the caller's to place.
|
|
/// `summarizing` is live while the turn runs: the pass bar's Cancel
|
|
/// ends it (the Blind Read posture) and a Pass refuses meanwhile.
|
|
func summarize(mentor: MentorSessionModel) async -> String? {
|
|
guard let (id, _, home) = guardOpenPieceRun("a summary", mentor: mentor) else { return nil }
|
|
guard flushOrAbort(id) else { return nil }
|
|
// House posture (blindRead): the run is firing — a stale guard
|
|
// refusal no longer owns the error strip.
|
|
lastError = nil
|
|
// brief-28: the guard answered the session's OWN library; disk is
|
|
// the truth post-flush — ONE read feeds the prompt AND the title
|
|
// (the scan snapshot can lag a just-flushed heading).
|
|
guard let dir = PostStore.folder(of: id, home: home),
|
|
let raw = try? String(contentsOf: dir.appendingPathComponent("post.md"), encoding: .utf8)
|
|
else {
|
|
lastError = "Couldn't read the piece before summarizing."
|
|
return nil
|
|
}
|
|
let body = PostFrontmatter.split(raw).body
|
|
guard !body.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
|
|
lastError = "This piece has no text to summarize."
|
|
return nil
|
|
}
|
|
summarizing = true
|
|
defer { summarizing = false }
|
|
let pieceTitle = Post.title(of: raw)
|
|
let reply = await mentor.runSummary(
|
|
prompt: SummaryPrompt.prompt(title: pieceTitle, body: body),
|
|
pieceTitle: pieceTitle,
|
|
)
|
|
guard let summary = reply.map(SummaryPrompt.cleaned), !summary.isEmpty else {
|
|
lastError = "The engine didn't return a summary — try again."
|
|
return nil
|
|
}
|
|
return summary
|
|
}
|
|
}
|