CI / ci (push) Canceled after 0s
#180: one PostFrontmatter module now owns the lenient read (parse/split/decoded) and every write posture — fresh stamp, merge-import, update-keys — behind one known-key table (type, pass_state, origin; one insertion order). The three near-twin walkers are deleted byte-identically: PostStore.stamped/splitFrontmatter/ mergedFrontmatter, LearningDecay.stampingFrontmatter, Post.frontmatter(of:) — 21 call sites swept across seven production files and eight test files. The Unaided First Draft eligibility is named once and consumed by both gates: isUnaidedFirstDraftPair (writer ∧ post — the scan's read-back gate) and isCaptureEligible (pair ∧ First Draft — the capture gate at pass invocation). The lenient ?? default stamp decode is extracted with it (the third copy's deferred extraction). One deliberate divergence from the absorbed writer, doc-commented and pinned: mergingImport now preserves hand-edit lines above the opening --- on import where the old split-first shape silently dropped them — lossless through every posture is the ticket's contract. Seven codec pins (PostFrontmatterTests) cover the posture round-trip (foreign keys verbatim through import → save → advance → micropub), the lenient unknown-type decode, and the predicates' truth table. Existing pieces are untouched on disk: every posture moved verbatim and the full suite pins the byte shapes (664/664 green; the one under-load flake in the #179 repoint pin is pre-existing on main, proven by a stashed-tree control run). Closes #180
7.5 KiB
7.5 KiB
#180 PostFrontmatter codec — one read/write engine, named eligibility predicates
Date: 2026-11-10 Type: issue Reference: #180
Goal
Consolidate the three near-twin post frontmatter writers (fresh stamp, import merge, in-place key update) into ONE codec module behind one known-key table and one insertion-order rule; name the Unaided First Draft eligibility pair once and consume it from both gates; keep every existing piece byte-identical on disk. Step 2 of 2 of the 2026-11-09 architecture review's content line.
What Was Done
- New
Museion/PostFrontmatter.swift— the codec: the lenient read (parsemoved fromPost.frontmatter(of:),splitfromPostStore.splitFrontmatter, plusdecoded— the ONE lenient?? defaultstamp decode, extracting the third copy the #31 ponytail note deferred) and the three named write postures:stamped(fresh),mergingImport(external keys verbatim, ours win),updating(the in-place line-walk moved verbatim fromLearningDecay.stampingFrontmatter). One known-key table:ownedKeys(type:passState:origin:). - Two named eligibility predicates, consumed by both gates:
isUnaidedFirstDraftPair(writer ∧ post —Post.scan's read-back gate inPostLibrary.parse) andisCaptureEligible(pair ∧ First Draft —PostStore.captureFirstDraftStats). - Deleted the twins:
PostStore.stamped,PostStore.splitFrontmatter,PostStore.mergedFrontmatter,LearningDecay.stampingFrontmatter,Post.frontmatter(of:)— 21 call sites swept across 7 production files (PostStore, PostLibrary, LearningDecay, FixCardStore ×2, LearningsPaneView, PostsModelOutline, Micropub) and 8 test files. - New
MuseionTests/PostFrontmatterTests.swift— 7 pins: fresh-stamp byte shape, merge-import (foreign keys verbatim, ours win in place, bare file, #180 prefix-preservation divergence), update-keys (in-place overwrite, insert-before-close, bare prepend, hand-edit lines above the block), the chained posture round-trip (import → save → advance → micropub, foreign key verbatim at every hop), lenient unknown-type decode, and the two predicates' truth table (pair true at Pass-1 Done, capture false — the AC's exact distinction). - DOX pass: root AGENTS.md trust-boundaries learning re-pointed to the new symbols;
Museion/AGENTS.mdmap entry + PostStore/PostLibrary bullets;MuseionTests/AGENTS.mdsuite map. - Reviews: implement-close Standards+Spec fanout (2 findings, both fixed), finish-audit fanout (ponytail/security/general — 0 critical, 1 shrink applied, 2 comment fixes applied, 1 security INFO deferred with a ceiling comment).
Net −133 lines, 18 files modified + 2 new.
Decisions & Rationale
| Decision | Rationale |
|---|---|
mergingImport = one line over updating with ownedKeys |
The import twin's line-walk was byte-for-byte the same walk; unifying killed the twin. Only reachable delta: hand-edit lines above --- now SURVIVE import where the old split-first shape dropped them — deliberate, lossless-direction divergence, doc-commented on mergingImport and pinned in the suite (both reviewers converged on flagging it unpinned; the pin + comment landed). |
overwrite's blocked path keeps the split(updating(...)).block + body dance |
Preserves the exact old composition (update walk → re-split → take block → swap body), so save output stays byte-identical including the prefix-drop the re-split incidentally performs. No fourth posture invented for one caller. |
decoded returns a Stamp struct, not a 3-tuple |
swiftlint large_tuple (default rules) warns on >2-element tuples; the struct reads better at call sites and carries Equatable for the bare-defaults pin. |
isCaptureEligible re-derives the pair instead of calling isUnaidedFirstDraftPair |
One decode instead of two; identical semantics (lenient triple + three equals). |
Learnings dismiss rides PostFrontmatter.updating |
Ticket keeps Learning/Fix Card DOCUMENTS out of scope, but deleting stampingFrontmatter (an AC) forces its one learning caller onto the codec's generic walk — mechanical reuse, document shape unchanged. |
Post.title(of:) NOT unified with split |
Title's unterminated-block branch returns untitled; split's returns the whole text as body. Different contracts; unifying would change bytes. Out of scope. |
Gotchas & Fixes
| Problem | Root Cause | Fix |
|---|---|---|
| My first prefix pin expected the inserted key ABOVE existing keys | The walk inserts before the CLOSING --- (after existing keys) — the code was right, the pin was wrong |
Corrected the expectation to the real shape; test green |
home repoint mid-pass refuses the advance failed in both full-suite runs |
Pre-existing #179 timing flake: the held prompt times out under full-suite machine load before endHeldPrompt — the test's own comment predicts it |
PROVEN pre-existing: full suite on stashed clean main failed the same test; the suite in isolation (5/5) and the final verify run (664/664) pass. Not this diff's seam. |
| One new line_length violation after the rename sweep | PostStore.stamped( → PostFrontmatter.stamped( grew PostsModelTests:407 to 146 chars |
Wrapped the call; swiftlint back to exactly the clean-main count (279) |
Mixed // + /// comment block on mergingImport |
The #143 orphaned-doc-comment trap | Folded into one /// block with a blank /// separator |
| Terminal cwd drifted into a reviewer child's scratch probe dir | Child probe dirs share the session shell | Re-ran with explicit workdir; no repo files touched |
Files Changed
| File | Change Summary |
|---|---|
Museion/PostFrontmatter.swift |
NEW — the codec: parse/split/decoded, three postures, ownedKeys, two predicates |
MuseionTests/PostFrontmatterTests.swift |
NEW — 7 pins incl. the posture round-trip and prefix divergence |
Museion/PostStore.swift |
Swept to the codec; mergedFrontmatter/stamped/splitFrontmatter deleted; capture gate → isCaptureEligible |
Museion/PostLibrary.swift |
parse → codec read; read-back gate → isUnaidedFirstDraftPair; Post.frontmatter deleted |
Museion/LearningDecay.swift |
dismiss → codec updating; stampingFrontmatter deleted |
Museion/FixCardStore.swift ×2 sites, Museion/LearningsPaneView.swift, Museion/PostsModelOutline.swift, Museion/Micropub.swift |
Mechanical read-site sweep |
MuseionTests/ (8 files) |
Mechanical rename sweep + comment fixes |
AGENTS.md, Museion/AGENTS.md, MuseionTests/AGENTS.md |
DOX pass |
Open Items & Next Steps
- Flat-key ceiling: an indented
key: valueinside a nested YAML block scalar is rewritten unindented by the walk (inherited verbatim from the deleted writers; security-review INFO-1, local-only, user's own import). Recorded as aponytail:comment at the walk; indentation-aware walk only if nested frontmatter ever matters. - The
home repoint mid-passflake remains open from #179 (fails under full-suite load ~2/3 runs this session, green in isolation and in the final run) — its timing assumptions, not this ticket.
Verification
build-for-testingexit 0;test-without-buildingexit 0 — 664 executed / 664 passed / 0 failed (xcresult count, not the banner).- swiftformat clean; swiftlint 279 violations = exact clean-main parity.
- GitNexus detect-changes (index-relative): affected flows all route through
overwrite/learnings— the diff's own seams.
Log written by write-log skill