feat(outline): convert to post — S4 (#114)
CI / ci (push) Canceled after 0s

In-place outline→post conversion on the piece: id, folder, Pass
State, origin kept, type frontmatter flips to post, body transforms
once. The ask picks the transform — Verbatim Bullets (default,
lossless) or Headings ladder (roots ##, stepping to the ###### floor,
deeper stays bullets), with a warning when the ladder would drop
paragraph lines between bullets.

The open session flushes first, then reopens routed to prose via
proseOverridePostID (lastDraftWasOutline's machinery reversed).
An outline that went lossy on disk behind an unwarned ask aborts
the convert; an unanswered #67 conflict aborts every flush-first
op (shared flushOrAbort seam); rescan no longer hands a same-id
reopened session its predecessor's stale disk text; a held #111
guard ask dies with the outline it pointed at.

Audit round (finish-audit, three reviewers) included: 13 new pins,
206 tests green, pin discrimination verified. Record:
docs/devlog/20261016-issue114-convert-to-post_log.md
This commit is contained in:
AlexKucera committed 2026-10-16 18:03:41 +02:00
1 parent 21e2f27450
commit c0513aae85
14 files changed
+547 -19

No files matched your search

+32 -5
View File
@@ -272,17 +272,32 @@ nonisolated enum PostStore {
/// vanished post throws — `writeNew` is the only creator; saving must
/// never resurrect a deleted post with reset metadata.
static func overwrite(id: String, body: String, home: URL) throws {
let piece = try existingStamp(id: id, home: home)
try stamped(body: body, passState: piece.passState, origin: piece.origin, type: piece.type)
.write(to: piece.dir.appendingPathComponent("post.md"), atomically: true, encoding: .utf8)
}
/// #114: the shared read behind `overwrite` and `convert` — resolve the
/// folder, read the file (vanished → throw: a write never resurrects,
/// #18), derive the preserved stamp values. The caller stamps its own
/// type and body.
// swiftlint:disable:next large_tuple
private static func existingStamp(id: String, home: URL) throws -> (
dir: URL, passState: Post.PassState, origin: Post.Origin, type: Post.ContentType, body: String,
) {
guard let dir = folder(of: id, home: home),
let existing = try? String(contentsOf: dir.appendingPathComponent("post.md"), encoding: .utf8)
else {
throw CocoaError(.fileReadNoSuchFile)
}
let matter = Post.frontmatter(of: existing)
let passState = Post.PassState(rawValue: matter["pass_state"] ?? "") ?? .firstDraft
let origin = Post.Origin(rawValue: matter["origin"] ?? "") ?? .writer
let type = Post.ContentType(rawValue: matter["type"] ?? "") ?? .post
try stamped(body: body, passState: passState, origin: origin, type: type)
.write(to: dir.appendingPathComponent("post.md"), atomically: true, encoding: .utf8)
return (
dir,
Post.PassState(rawValue: matter["pass_state"] ?? "") ?? .firstDraft,
Post.Origin(rawValue: matter["origin"] ?? "") ?? .writer,
Post.ContentType(rawValue: matter["type"] ?? "") ?? .post,
splitFrontmatter(existing).body,
)
}
/// Body text (frontmatter stripped) for editing; nil when unreadable.
@@ -294,6 +309,18 @@ nonisolated enum PostStore {
return splitFrontmatter(text).body
}
/// #114 (S4): Convert to Post — the one-time in-place transform. The
/// file's own `pass_state`/`origin` are kept (the stamp re-derives
/// them from the file, same as overwrite), id and folder never move,
/// `type` flips to `post`, the body transforms once. Ladder = the
/// headings mapping; verbatim = body unchanged. One-way in v1.
static func convert(id: String, headingsLadder: Bool, home: URL) throws {
let piece = try existingStamp(id: id, home: home)
let transformed = headingsLadder ? OutlineTree.headingsLadderBody(piece.body) : piece.body
try stamped(body: transformed, passState: piece.passState, origin: piece.origin, type: .post)
.write(to: piece.dir.appendingPathComponent("post.md"), atomically: true, encoding: .utf8)
}
// MARK: Cursor-state sidecar (#66)
/// Cursor state for one post: selection + scroll, `.museion-state.json`