Files
museion/docs/devlog/20261012-issue22-import-external_log.md
T
AlexKucera 0f1c4ef4fe
CI / ci (push) Canceled after 0s
feat(posts): import & external markdown — S1.1 (#22)
External .md/.markdown opens and edits as-is in a single guest slot
(File > Open... Cmd+O, drag-onto-window): SessionTarget extends
EditorSession to write in place verbatim, no cursor sidecar, the #67
conflict alert reused for foreign files. Import... (Shift+Cmd+O)
copies multi-select files in as Posts behind ONE Origin ask
(writer default, immutable); external frontmatter keys ride verbatim
with pass_state/origin set; slug/collision machinery shared with
writeNew.

Audit fixes folded in: BOM stripped + CRLF normalized at the trust
boundary (a CRLF pair is one Swift grapheme — \n splits saw one
line); unreadable files refuse to open (loadFailed — a failed read
never becomes a write); dropped web links and severed symlinks
guarded; ~24 lines of reviewer-flagged dead weight removed.

7 new tests; full unit + UI suite green; swiftlint clean.

Map #22 stays open pending the live calibration pass (#88 posture).
2026-10-12 17:00:03 +02:00

5.7 KiB
Raw Blame History

Session Log — #22 Build: M1 Import & external markdown (S1.1)

Date: 2026-10-12 Branch: main @ 683d697 (working tree; commit awaits authorization) Ticket: #22 — wayfinder map that doubles as the build ticket

What happened

Build session on map #22. All six decision tickets (#91–#96) were resolved live at charting; the map's Notes carry execution into the map itself — so this session claimed #22 and built the slice, verifying against the PRD S1.1 acceptance criteria.

The shape

  • SessionTarget (.post(id, home) | .externalFile(url)) in EditorSession — one session machinery, two write targets. The convenience init(postID:home:) keeps every #19 call site unchanged; postID became computed-optional (callers use ?? "post" / ?.lastPathComponent guards).
  • PostStore: importFile(at:origin:home:) — read, split, mergedFrontmatter (external YAML keys verbatim; pass_state/origin set/overwritten in place; absent keys inserted before the closing ---; empty block → fresh #59 shape), then the shared private materialize (the lazy-folder/TOCTOU path extracted from writeNew). openableTypes + isMarkdown give every entry point the same .md/.markdown list.
  • PostsModel: externalSession guest slot (one at a time, transient per launch; openExternal flushes-and-replaces; select/newPost dismiss it flush-first); a second PostsWatcher on the external file's folder feeding the same diskDidChange conflict check; import staging (stageImport/cancelImport/importFiles — ONE Origin ask, per-file failures continue into lastError, last success opens).
  • UI: File ▸ Open… ⌘O + Import… ⇧⌘O in CommandGroup(after: .newItem) (never CommandMenu("File") — #84 trap); window-level dropDestination for drag-onto-window; OriginAskSheet ("Who wrote this?", writer default / ai, immutability line); editor column renders the guest ahead of the post session; crumb shows the file name; the #67 alert names the actual file.

Verification

  • xcodebuild build — SUCCEEDED
  • xcodebuild test (unit + UI) — SUCCEEDED; new ImportExternalTests (5 tests: #95 merge round-trip + original untouched, bare-file fresh block + -2 collision, empty → untitled, save-in-place verbatim + NO sidecar, #67 foreign-write conflict + Yes-reload)
  • swiftlint on changed files — 0 new violations (6 pre-existing tv warnings, verified identical at HEAD)
  • GitNexus impact analysis run before edits (EditorSession/PostsModel = CRITICAL blast radius, expected for central types; all changes additive — new enum case members, new properties, no call-site behavior change). detect-changes after: affected flows are exactly select/saveDraft/flush/writeNew/PostsPaneView, all covered green.

Traps dodged

  • Blanket swiftformat . reformatted 14 unrelated files (version drift, same class as #88's log) — reverted, lint scoped to changed files.
  • Two mid-generation slips (mangled placeholder text in PostStore/EditorSession patches) caught by re-read + build before anything shipped.

Finish-audit round (same session)

Three fresh-context reviewers (ponytail / security / general) over the uncommitted diff. Accepted and fixed:

  1. CRLF + BOM imports mangled (two reviewers, empirically confirmed): in Swift a CRLF pair is ONE grapheme, so every \n-split in the corpus machinery saw a CRLF file as a single line — id date-20261011-crlf-note-body instead of crlf-note. Root fix: normalize \r\n→\n + strip BOM at the import boundary (importFile) and on external reads (readDocument) — body lands LF, byte-for-byte now means per-decision content fidelity, not line-ending fidelity. Lone-CR (pre-OSX) files still degrade to untitled — ceiling named in a ponytail comment.
  2. Unreadable foreign file → silent empty editor → first keystroke destroys the original: loadFailed in EditorSession (a session that never loaded never writes — flush no-ops), openExternal refuses the open into lastError.
  3. Dragged web link = sync network fetch: isMarkdown now requires url.isFileURL.
  4. Atomic write severs symlinked external files: openExternal resolves symlinks first.
  5. Ponytail trims (~24 lines): shared markdownExtensions list, dead flushFirst param on dismissExternal, redundant Task re-hop in the external watcher, unused Equatable on SessionTarget, one pickMarkdown helper for both menu panels.

Discarded: clearing lastError on batch success (matches the established saveDraft/rename/trash pattern), off-main import batch (documented single-file-I/O posture holds), drop-bypasses-Origin-ask (drop opens, never imports — by design). Tests: +2 (CRLF import, unreadable-file guard) — 7 in the suite; full unit+UI green; lint clean (pre-existing warnings only).

Lessons

  • The SessionTarget enum is the whole design: #92's "the shape is the build's call" resolved to "postID becomes optional, target drives I/O" — 30 lines instead of a parallel ExternalSession class. When two documents differ only in disk I/O, parametrize the I/O, not the session.
  • Frontmatter merge is line-rewrite, not parse-and-restamp: keeping the external block verbatim except our two keys preserves comments, ordering, and unknown YAML shapes (#95) — a restamp would have normalized away the user's file.
  • Swift grapheme clusters: "\r\n" == one Character. Any split(separator: "\n") over user text silently sees CRLF files as a single line. Normalize at the trust boundary, not per-call-site.

Next

  • Map #22 close-out (resolution comment + acceptance criteria checkboxes) happens after Alexander's live pass — same posture as #88's calibration gate.