CI / ci (push) Canceled after 0s
Variant B per the #104 prototype verdict: the library column groups pieces by project (serif lowercase heads, collapse toggle, Pass-State groups inside, 2px edge-bar selection shared with the new Archive pane via LibraryPostRow). Move to Project / Archive / Move Back / whole-project Unarchive are folder moves — post.md bytes untouched, never clobbering, ids globally unique. File ▸ New Post ⌘N and New Project… ⌥⌘N (CommandGroup, never CommandMenu per #84). Every folder move flushes pending edits first and aborts when the write failed — nothing moves without its text. Project membership and the archived-refusal derive from freshly resolved disk paths, never the scan snapshot. Slug and project-name comparisons fold through one canonical key (NFC + lowercase). Two reviewer fanouts this session; their findings are all fixed or visibly parked. 144/144 tests green (run twice), swiftformat/swiftlint clean. Closes #108
88 lines
8.9 KiB
Markdown
88 lines
8.9 KiB
Markdown
# Issue #108 — Library UI S2 (projects, archive, commands) + two audit rounds
|
||
|
||
> **Date:** 2026-10-13
|
||
> **Type:** issue
|
||
> **Reference:** Museion #108 (child of wayfinder map #97), prototype verdict #104 (variant B)
|
||
|
||
## Goal
|
||
|
||
Ship #108: the variant-B library UI — project-grouped library with section heads, the Archive rail pane, move/archive/restore/unarchive/createProject ops across PostStore + PostsModel, New Post/New Project commands — then harden it with reviewer fanouts and close every finding.
|
||
|
||
## What Was Done
|
||
|
||
**Core implementation (#108, variant B per #104):**
|
||
- `PostStore` (nonisolated): `move` / `archive` / `restore` / `unarchiveProject` / `createProject` over private `relocate` — pure folder moves, post.md bytes never rewritten; `validatedProject` (empty/slash/dot rejected, later +`:`/control-chars); never-clobber guards throughout.
|
||
- `PostsModel`: `pendingProject`/`targetProject`, `moveToProject`, `archivePost`, `restorePost`, `unarchiveProject`, `createProject`, `stageNewProject`/`cancelNewProject`/`askNewProject`, `newProjectPending`.
|
||
- UI: serif-15 semibold lowercase project heads + mono-11 `· N` counts, Pass-State groups inside, collapse toggle (chevron rotation, per-view state), 2px rust edge-bar selection on `LibraryPostRow` (extracted, shared with Archive), ✳ on outlines; `ArchivePaneView` (rail destination, Unarchive per project, Move Back per piece, row-click hops to Posts); File ▸ New Post ⌘N + New Project… ⌥⌘N via `CommandGroup(after: .newItem)` — never `CommandMenu("File")` (#84 trap).
|
||
|
||
**Audit round 1 (three-reviewer fanout, 10 fixes):**
|
||
- `EditorSession.flush()` → `@discardableResult Bool`; `flushOrAbort` in PostsModel — move/archive/restore abort when a write fails ("nothing was moved").
|
||
- Dotfile skip in `unarchiveProject` merge (.DS_Store wedged unarchive forever).
|
||
- Draft pane-hop `onChange(of: draft != nil)` in WorkspaceView.
|
||
- Session reopen after `restorePost`/`unarchiveProject` (stale `folderURL`).
|
||
- NFD/NFC duplicate guard in `createProject` → shared `folded(_:)` (NFC + lowercase).
|
||
- `openExternal` clears `pendingProject`; `localizedStandardCompare` project sort in both panes; deleted dead `clearPendingProject` + `moveTargets` property (later reborn as a function, see audit 2); new `PostsModelTests.swift` (5 tests).
|
||
|
||
**Fold follow-up:** `availableSlug` compares through `folded` (taken-set build, own-ID exclusion, suffix loop); rewrote the fold test to decomposed-jamo-vs-precomposed (`한국-2`); a Swift probe proved Swift `==`/Set hashing already fold canonical equivalence — the original "Set lookups don't fold" rationale was wrong and all doc text was corrected (the `folded` key stays as the explicit, tested contract; lowercase is the load-bearing half).
|
||
|
||
**Audit round 2 (three-reviewer fanout over the post-audit tree, 12 accepted findings):**
|
||
- **HIGH:** `unarchiveProject` skipped the flush gate (flagged by 2 reviewers) → gate added, disk-derived membership via `folder(of:)`, captured BEFORE the move (after it, archive membership is invisible).
|
||
- **MEDIUM:** `rename` ignored flush failure and `lastError = nil` erased the signal → `flushOrAbort` gate.
|
||
- **MEDIUM:** `unarchiveProject`'s `removeItem` permanently destroyed hidden children (`.git/`, `.research/`) → source removed only when the loop emptied it.
|
||
- **MEDIUM:** empty projects unreachable as move targets + Unicode-scalar sort in the picker → `moveTargets(home:)` — disk listing + default project, localized-sorted.
|
||
- Stale-snapshot trust in `move`/`archive`/`restore` (`post.project`, `isArchived` flag) → all derive from the freshly resolved disk path; the archived-refusal in `move` now derives from the resolved path too.
|
||
- Ops return Void (nobody consumed the `Post` returns); `createProject(named:) -> String?` with the failure reason inline in the sheet (no double-message into `lastError`); `flushOrAbort` appends "— nothing was moved." instead of replacing the flush-routed reason; `validatedProject` rejects `:`/control chars; stale `availableSlug` doc block deleted; `folder(of:)` comment corrected (piece-level check resolves symlinks); 4 new tests + fixed the `debounce flushes` suite flake (wall-clock sleep → bounded await).
|
||
|
||
**Verification:** full suite green at every stage — 134 → 139 → 140 → 141 → 144 (run twice consecutively at the end); swiftformat/swiftlint clean on all touched files; GitNexus re-indexed (2,654 nodes / 7,109 edges / 192 flows).
|
||
|
||
## Decisions & Rationale
|
||
|
||
| Decision | Rationale |
|
||
|----------|-----------|
|
||
| Variant B library layout | #104 prototype verdict — measured A/B/C, B won |
|
||
| Project heads render lowercase via `.textCase(.lowercase)` | Live user verdict; small caps tried and rejected — "don't work as UI element for projects" (folder keeps its case) |
|
||
| Archive head keeps two tap targets (chevron + name), no whole-head Button | Live verdict: the Unarchive button shares the row and must not be swallowed; only the missing a11y hint was added |
|
||
| Section collapse = per-view `@State`, not persisted | Prototype behavior; a fresh open shows everything |
|
||
| `folded` stays despite behavioral redundancy for NFC/NFD | Explicit tested contract; lowercase half is load-bearing (APFS case-insensitivity); deleting it saves 3 lines and loses the pin |
|
||
| Ops return Void | Only tests consumed the returns and they assert the same facts via `Post.scan`; rescan re-derives posts from disk |
|
||
| Disk-derived state over scan snapshots everywhere | A Finder-side move between scan and click must not misfile pieces or smuggle archived pieces back into projects/ |
|
||
| Flush gate before every folder move (incl. rename, unarchive) | The move succeeds exactly when a file write fails; text must land before the folder moves |
|
||
| `debounce flushes` test rewritten to bounded await | Flaked twice in one day under suite load — fixed 200 ms sleep starves when the main actor is busy |
|
||
|
||
## Gotchas & Fixes
|
||
|
||
| Problem | Root Cause | Fix |
|
||
|---------|------------|-----|
|
||
| Fold test failed: `#expect(decomposed != "한국")` | Swift `==` folds canonical equivalence — NFD/NFC compare equal | Premise pinned on byte inequality: `utf8.elementsEqual` |
|
||
| "Passes isolated" was a phantom | `-only-testing:` on a free `@Test` function (no suite class) ran ZERO tests and still said TEST SUCCEEDED | Read the pass count, not just the verdict; use xcresulttool for failure text |
|
||
| Unarchive-flush test failed in suite | Two bugs in my helper: one `deletingLastPathComponent()` too many (compared the home folder's name against "archive"), and membership re-evaluated after the move when it's already invisible | Correct depth (dir−1 = project dir, dir−2 = root); membership captured before the move |
|
||
| `move refuses an archived piece` failed after the Void cut | Refusal trusted the snapshot `isArchived` flag; test passed the original struct | Refusal derives from the resolved disk path |
|
||
| patch tool mangled these files repeatedly (eaten declaration lines, duplicated functions, mangled MARK) | Fuzzy matching on long structurally-similar regions | Always `read_file` to verify after patching; re-read before retrying |
|
||
| Reviewers re-litigated a settled live verdict (Archive head shape) | I under-briefed the exclusion list | Keep the adjudicated shape; add exclusion items as they're ruled |
|
||
| Security reviewer's doc note contradicted my fold rationale | My claim "Set lookups don't fold" was wrong — probe proved hashes are canonical-consistent | Corrected all rationale text in code comments, tests, AGENTS.md |
|
||
|
||
## Files Changed
|
||
|
||
| File | Change Summary |
|
||
|------|---------------|
|
||
| `Museion/PostStore.swift` | #108 ops + `relocate` + `validatedProject` + `folded` + disk-derived paths + Void returns + remove-only-when-empty |
|
||
| `Museion/PostsModel.swift` | project ops, `flushOrAbort` everywhere, `moveTargets`, `createProject -> String?`, disk-derived unarchive membership |
|
||
| `Museion/PostsPaneView.swift` | variant-B library column, `LibraryPostRow`, `MoveToProjectSheet`, `RenamePostSheet` |
|
||
| `Museion/WorkspaceView.swift` | Archive rail destination + `ArchivePaneView`, New Project ask, draft pane-hop |
|
||
| `Museion/MuseionApp.swift` | ⌘N / ⌥⌘N commands |
|
||
| `Museion/EditorSession.swift` | `flush() -> Bool` |
|
||
| `MuseionTests/PostStoreTests.swift` | #108 op tests, fold pin, hidden-folder survival, NFD twin, `:` rejection |
|
||
| `MuseionTests/PostsModelTests.swift` | new — model lifecycle tests incl. unarchive flush gate + moveTargets |
|
||
| `MuseionTests/EditorSessionTests.swift` | debounce test de-flaked |
|
||
| `Museion/AGENTS.md`, `MuseionTests/AGENTS.md`, `AGENTS.md` | DOX pass — contracts, tests, fold rationale corrected |
|
||
|
||
## Open Items & Next Steps
|
||
|
||
- [ ] Empty projects remain invisible in the library sections (they appear in the move picker now) — product-copy question, later slice
|
||
- [ ] Unarchive mid-loop rollback stays parked (adjudicated: throws honestly on genuine duplicate ids)
|
||
- [ ] ⌘N may be shadowed by the stock new-window item on some builds (menu item always fires) — known, watching
|
||
|
||
---
|
||
|
||
*Log written by write-log skill*
|