feat(microblog): show Micro.blog publish status

The publish sheet flipped a draft live and remembered nothing, so
nothing on disk said a piece was out and the library could not show
it. A successful Publish now stamps `micropub_published` in the
piece's frontmatter; the row and the sheet read `published <date>`
or `draft on Micro.blog`, and a published piece's menu opens the
live post.

Sending a piece again no longer creates a second post: a piece that
remembers its post updates it in place (name and content only, so
categories set on Micro.blog survive). An image whose bytes are
unchanged rides its earlier upload through a per-piece memo. When
Micro.blog answers 404 the piece forgets both keys and the sheet
offers a fresh draft; a clear that cannot land says so instead of
claiming the link is gone.

Museion's micropub keys are dropped at the import boundary. An
imported `micropub_url` passes the format gate and would aim the
in-place update at one of the writer's own posts under their token,
so the keys are treated like `origin`: ours to set, never a foreign
file's to carry in. Publish is model-owned and trust-gates its URL
before anything is stamped.

Tests read recorded requests through an optional accessor: an
out-of-range subscript after a failed count expectation trapped the
hosted runner and reported every queued test as crashed.

+16 tests net (17 new pins in MicropubStatusTests, one retired whose
premise the in-place design voids); every new pin was watched fail
on its own guard. Rail 752/752; SwiftFormat and SwiftLint clean.
Reviews: standards + spec during the build, then a three-reviewer
finish audit. Docs: AGENTS.md bullets and learnings, GLOSSARY
terms, CHANGELOG [Unreleased], README, and the devlog.

Closes #206
This commit is contained in:
AlexKucera committed 2026-12-04 17:45:35 +01:00
1 parent 6938826101
commit 6aa31a419a
21 files changed
+1151 -225

No files matched your search

+24 -9
View File
@@ -166,7 +166,9 @@ nonisolated enum PostStore {
/// #22/#94/#95: import one external markdown file as a Post — copy, never
/// move (ADR-0004). Body byte-for-byte; external frontmatter keys kept
/// verbatim with `type: post`, `pass_state: First Draft` and
/// `origin: <chosen>` set / overwritten (our three keys win); id = Title
/// `origin: <chosen>` set / overwritten (our three keys win) and the
/// Micro.blog bookkeeping dropped (#206 — a foreign file carries no
/// post of this library); id = Title
/// slug at import; collisions `-2`/`-3`… (#60 machinery); a fresh copy,
/// no mtime preservation (#96).
static func importFile(at url: URL, origin: Post.Origin, project: String = Post.defaultProject, home: URL) throws -> Post {
@@ -663,7 +665,7 @@ nonisolated extension PostStore {
guard PostFrontmatter.isCaptureEligible(PostFrontmatter.parse(text)) else { return false }
let stats = DraftStats.compute(body: body)
let stamped = PostFrontmatter.updating(text: text, with: [
("stats_captured", FixCardStore.formatted(Date(), "yyyy-MM-dd'T'HH:mm:ss")), // lexically sortable
("stats_captured", FixCardStore.formatted(Date(), PostFrontmatter.stampFormat)), // lexically sortable
("stats_burstiness", String(format: "%.3f", stats.burstiness)),
("stats_type_token_ratio", String(format: "%.3f", stats.typeTokenRatio)),
("stats_sentence_variation", String(format: "%.3f", stats.sentenceVariation)),
@@ -675,22 +677,35 @@ nonisolated extension PostStore {
return true
}
// MARK: #33 (S6.1) — the remembered Micro.blog draft URL
// MARK: #33 (S6.1) / #206 — the remembered Micro.blog post
/// Stamp `micropub_url` in place on a successful draft send — the
/// publish step's target (a frontmatter-only change: the body and
/// Stamp micropub keys in place (`micropub_url`, the publish record
/// `micropub_published`) — a frontmatter-only change: the body and
/// every other key stay byte-identical, so the open session's
/// readBody-based echo check never fires). A vanished piece throws
/// (write-never-resurrects, `writeNew` is the only creator).
static func stampMicropubURL(id: String, url: String, home: URL) throws {
/// readBody-based echo check never fires, and every later editor
/// save re-reads the block (the stamps survive it). A vanished piece
/// throws (write-never-resurrects, `writeNew` is the only creator).
/// `dropping` removes those keys' lines outright (the forget).
static func stampMicropub(_ id: String, home: URL, _ pairs: [(key: String, value: String)], dropping: Set<String> = []) throws {
guard let dir = folder(of: id, home: home) else {
throw CocoaError(.fileReadNoSuchFile)
}
let file = dir.appendingPathComponent("post.md")
let raw = try String(contentsOf: file, encoding: .utf8)
try PostFrontmatter.updating(text: raw, with: [("micropub_url", url)])
try PostFrontmatter.updating(text: raw, with: pairs, dropping: dropping)
.write(to: file, atomically: true, encoding: .utf8)
}
/// #206: the piece forgets Micro.blog — both keys' lines removed
/// through the update posture's drop (no empty key left behind; an
/// absent key scans as no memory, and the next send inserts the line
/// fresh). Called when Micro.blog answers 404: the post is gone
/// there, so the piece is no longer on Micro.blog. Throws when the
/// write cannot land — the caller must not then claim the link is
/// gone.
static func forgetMicropub(id: String, home: URL) throws {
try stampMicropub(id, home: home, [], dropping: PostFrontmatter.micropubKeys)
}
}
// MARK: Cursor-state sidecar (#66)