Files
museion/docs/devlog/20261015-issue111-outline-guard_log.md
T
AlexKucera 0b172f73ef
CI / ci (push) Canceled after 0s
feat(outline): mixed-content open guard — S7 (#111)
Opening a type: outline piece whose body parses with dropped prose
(paragraph lines between bullets) now asks before the outliner mounts:
Open in Prose (default, nothing drops), Open as Outline (explicit
consent to save normalization), or Cancel. The detector shares the
parser's item definition, the ask presents over an empty editor so
nothing can normalize on save before the choice, and the prose answer
rides a routing override that dies with the next open.

Audit round pinned the lifecycle: reselect of the open piece is a
no-op (an armed debounce must never flush mid-ask), and a draft or
guest staged during the ask displaces it without being destroyed.

Closes #111

[Generated by AI]
2026-10-15 18:31:26 +02:00

7.6 KiB

Issue #111 — Build S7: mixed-content outline guard — no silent prose loss

Date: 2026-10-15 Type: issue Reference: AlexKucera/Museion#111 (map #110)

Goal

A type: outline piece whose body has paragraph lines between bullets loses those lines on the next in-app save — the outliner's parse drops non-item lines after the first item and serialize never writes them back. S7 puts a guard at open: warn, offer prose mode (nothing drops; outlines render acceptably in prose via the apex pipeline), and only drop after an explicit choice to open as outline.

What Was Done

  • OutlineTree.parsesWithLoss(_:) (OutlineTree.swift) — the detector: true when any non-blank line after the first item line isn't an item. Reuses parseItem so the detector and the parser can never disagree. Blank lines are formatting, not prose — quiet. Preamble is verbatim by design — never a loss.
  • PostsModel.select guard branch — on open of a type: outline piece that parses with loss: ends the old session (flush-first; prose-mode flush can't drop), sets outlineGuardPieceID, nils the session, holds the open. The ask presents over an EMPTY editor — nothing can edit, so nothing can normalize on ⌘S, before the choice.
  • postType(_:) — the piece's type from the scan when the list knows it, from frontmatter during the rescan lag (the same window lastDraftWasOutline covers for routing).
  • Guard answers — openGuardedOutlineInProse(home:) sets proseOverridePostID (routing override, lastDraftWasOutline's exact lifecycle: dies in newPost/newOutline/select/openExternal) and opens; openGuardedOutlineAsOutline(home:) opens with outline routing standing (consented drop); cancelOutlineGuard() backs out, no session, piece stays guarded on next open.
  • Routing (PostsPaneView) — session routing adds session.postID != model.proseOverridePostID; a held-guard branch renders an inert notice (no editor) while the ask is up.
  • OutlineGuardSheet (WorkspaceView) — third house ask (OriginAsk/NewProject pattern): Open in Prose (default) · Open as Outline · Cancel (binding set(false) → cancelOutlineGuard; Esc included).
  • Tests — parsesWithLoss pin (6 cases: the hazard, deep prose, clean, preamble, blanks, empty) + 8 model tests (3 audit pins): guard fires + holds + file untouched, prose answer + edit/flush cycle never drops, outline answer = consented drop on save, cancel re-guards on next open, clean pieces open untouched.

Decisions & Rationale

Decision Rationale
Guard in select, not EditorSession/PostStore select is the ONE open path (library, archive pane, restore, import) — one choke point; the ruling places the choice at load/route time where the type decision lives
Detector = non-blank non-item line after first item, via parseItem Shares the parser's exact item definition — no drift between "would drop" and "drops"; blank lines normalize quietly everywhere already
Ask over an EMPTY editor (session nil'd) The ticket's flush discipline: a piece being edited can't silently normalize on ⌘S — there is no session to ⌘S into while the ask is up
proseOverridePostID routing override with lastDraftWasOutline's lifecycle The piece's frontmatter still says type: outline; without the override the rescan-lagged routing would mount the outliner over the prose answer. Same clear-sites as the #109 afterglow
No write-path change (overwrite unchanged) Loss is exclusively parse→serialize in the outliner surface; prose flushes write text verbatim — touching overwrite would guard nothing and touch every save
No openExternal guard Imported externals are force-stamped type: post (#95 merge) — they route prose; an outline-drafted piece is authored in the surface
Guard machinery in a file-scope extension PostsModel Kept the class body under swiftlint's type_body_length error threshold; same file, same actor

Gotchas & Fixes

Problem Root Cause Fix
SwiftFormat/SwiftLint failures after hand-edits Multi-line if guard-condition brace placement; long sheet copy; class body pushed past 350 lines Extracted isGuardedOutline helper, split sheet text into two Texts, moved guard members into a file-scope extension
Extension accidentally nested inside the class (build error: declaration only valid at file scope) A scripted block-move spliced it mid-class Programmatic repair: cut the orphaned block, appended the extension after the class's closing brace
-only-testing:MuseionTests/PostsModelTests matched zero tests PostsModelTests is free functions, not a named suite Verified via xcresult enumeration on the full MuseionTests run: 176/176 passed, all 6 new tests present
xcresult get test-results tests returned an empty node tree Summary-only shape for Swift Testing in this Xcode Enumerated via get test-results summary counts + grep of test names

Files Changed

File Change Summary
Museion/OutlineTree.swift + parsesWithLoss(_:) static detector
Museion/PostsModel.swift + outlineGuardPieceID/proseOverridePostID state, guard branch in select, guard extension (postType, answers, openUnguarded), override lifecycle clears
Museion/PostsPaneView.swift Routing: prose override check + held-guard inert branch
Museion/WorkspaceView.swift + outlineGuardBinding + OutlineGuardSheet (house ask pattern)
MuseionTests/OutlineTreeTests.swift + parsesWithLoss pin
MuseionTests/PostsModelTests.swift + 8 guard lifecycle tests (5 + 3 audit pins)

Audit Round (finish-audit, same day)

Three parallel fresh-context reviewers (ponytail-review, security-review, review). Accepted findings, all fixed with pinning tests:

Finding Fix
HIGH: same-id reselect re-fired the guard over an already-open piece; session nil'd without teardown — armed debounce could flush prose-dropped text mid-ask (the exact loss the guard exists to prevent) select returns early when the open piece is reselected (reselect was already a no-op pre-guard; the guard must not break that)
MEDIUM: menu commands during the ask (⌘N, drag-drop) left the hold live; answering destroyed the just-created draft/guest outlineGuardPieceID = nil in newPost/newOutline/openExternal; openUnguarded clears it too (select's tail now routes through it — one open body)
LOW: Cancel left the row selected over an empty editor cancelOutlineGuard clears selectedPostID when no session is up
ponytail: openUnguarded duplicated select's tail; postType+readBody read the file twice; test helper reinvented writeNew; placeholder branch had an always-true condition select's tail calls openUnguarded; isGuardedOutline does ONE disk read deriving type + body (splitFrontmatter); helper is one writeNew call; condition is != nil

Deferred: remembered per-piece prose preference (per-open consent is the ruled safe direction); main-actor guard reads (existing house posture, ponytail-marked).

Both lifecycle pins verified to bite: reverting the two fixes fails exactly reselecting the open guarded piece is a no-op and new draft during the ask displaces it and survives; restored → 179/179 green.

Open Items & Next Steps

  • S7 landed; map #110's next frontier tickets: P1 (#113) → S6 (#112), S4 (#114), S5 (#115)
  • Convert to Post (#114) will give guarded pieces a structural way out; the ask's copy already points at it
  • None — no known tech debt introduced

Log written by write-log skill