fix(posts): finish-audit closeout for #179
CI / ci (push) Canceled after 0s
CI / ci (pull_request) Canceled after 0s

Reviewer fanout (ponytail/security/general) fixes: bind hoisted to the
WorkspaceView root task (stale boundHome after a Home repoint while
another pane was showing), railWriteReturningReason emits .writeFailed
(pinned, flip-verified), dead home: params deleted from the three ask
sheets, saveDraft locals inlined; AGENTS.md docs delta applied; devlog
closeout. Suite 655/655, lint parity with base.
This commit is contained in:
AlexKucera committed 2026-11-10 16:48:35 +01:00
1 parent 3bef1d12b1
commit 23b2090054
12 files changed
+58 -24

No files matched your search

+1 -1
View File
@@ -35,7 +35,7 @@ The map and the contracts, one bullet per file. Pin-level detail lives in the te
- `Pass.swift` — `PassKind` (pass1/pass2 — the app's own names) + `PassContext.stub` (the pinned minimal engine prompt: verdict in the reply, findings as fix-card tool calls, research as candidate tool calls — the engine never writes to the piece folder) + `estimateTokens` (chars/4).
- `BlindRead.swift` — neutral "Version A/B" prompt (both bodies inline, origin-free words never appear — the judge must not know which is the rewrite; caller randomizes order), ask = pick + one line why; `reveal` mapping appended by the model ONLY after the turn ends.
- Micropub (`Micropub.swift`, `MicropubMedia.swift`, `MicropubPublishSheet.swift`) — the Micro.blog publish path. Client over the injectable Transport: draft = h=entry (name, markdown content verbatim, post-status draft, sorted keys; `category:` frontmatter NEVER travels; NO `photo` property — uploaded illustrations ride INLINE in content, refs rewritten to uploaded URLs on the WIRE only, the piece on disk never changes). Every URL through `trustworthyURL` (https + host + no line/control characters — the URL is trust-boundary data landing in frontmatter); 401/403 → authFailed with `error_description`; `preview` is display-only, never the publish target. `MicropubTokenStore` = the app's own login-keychain credential (ADR-0014's no-Keychain rule covers only provider keys). Media: `illustrations(in:)` parses only `![alt](assets/…)` refs (remote refs ride as prose; multi-line alts don't parse at all — by design); parse + rewrite share ONE regex; markdown-active URLs ride the angle form. The model rail (`uploadIllustrations`) is the publish FLOOR: whitespace-empty alt refuses BEFORE any wire traffic, payload reads are contained (`../` or a symlinked asset refuses), uploads are all-or-nothing, style judgment stays with the author. The sheet owns Send as Draft → Publish, each an explicit click; refusals inline with buttons kept.
- `PostsModel.swift` — @MainActor @Observable, app-scoped. Domain extensions live in their own files (guard+Convert `PostsModelOutline.swift`, passes+Blind Read `PostsModelPasses.swift`, fix cards `PostsModelCards.swift`; watcher+rescan in a file-scope extension). `PostDraft` in-memory until first save; `mountID` keys the editor `.id` so every staging REMOUNTS (the outliner re-seeds its tree). FSEvents stream (file-level, 0.5 s latency) on BOTH `projects/` and `archive/`; rescan off-main through the app-scoped scan cache, skipping the `posts` assignment on equality (@Observable invalidates on assignment — panes would regroup on autosave echoes); the rescan hands the session the open post's disk text (the #67 external-change check, watcher echo suppressed by equality). Mixed-outline guard: a lossy outline select HOLDS the ask over an empty editor (nothing can normalize on ⌘S before the choice); reselect of the held piece is a no-op. External guest: one at a time, symlink-resolved (an atomic write renames over a symlink), its own watcher, dismissed flush-first by any post/draft open. Imports: ONE origin ask per batch, per-file failures continue into `lastError`. Structural ops are flush-first via `flushOrAbort` (a failed write or an unanswered #67 conflict aborts with nothing changed — the alert stays up). Convert: consent rechecked at answer time (Headings aborts when the body went lossy behind the ask); converting the open piece tears down and reopens routed prose. `runPass` chain: guards (one rail, mentor not mid-turn, engine ready, open saved piece) → flush → snapshot (unconditional, even for a later cancel) → capture stats → lint emit → `runningPass` live → own-engine run → advance ONLY on `.ended` with stopReason ≠ "refusal". `blindRead` mirrors the guards; nothing advances or records. `refreshCards` rides the rescan + open tails; `applyCard` = flush-first, stale anchor flags the card with no text change, the edit lands through `EditorSession.adoptText`; `promoteCard` writes a Learning and touches no text. `micropubSendDraft` = flush-first, ONE disk read serves both wire fields, success stamps `micropub_url`. `canArmWritingLock`/`editorBodyText` mirror the editor's outline routing (prose only).
- `PostsModel.swift` — @MainActor @Observable, app-scoped. #179: every library verb's store write rides the write rail (`PostsModelRail.swift`) — `railWrite`/`railWriteReturningReason`/`railWriteKeepingStrip`, deliberately NOT overloads (a shared base name let unlabeled trailing closures resolve into the wrong entry); the ONE pairing point (`pairRailRescan`) gives any railed write exactly one rescan, pinned by `PostsModelWriteRailTests`. The model owns the Home: `boundHome` is set by `bind(home:)` ALONE, driven by WorkspaceView's root `.task(id: museionHome)` (first frame + every repoint, whichever pane is showing); no public verb takes a Home parameter. Outside the rail by design: the editor flush (editor-owned), the pass substrate's snapshot/stats writes, and the publish stamp. Domain extensions live in their own files (guard+Convert `PostsModelOutline.swift`, passes+Blind Read `PostsModelPasses.swift`, fix cards `PostsModelCards.swift`; watcher+rescan in a file-scope extension). `PostDraft` in-memory until first save; `mountID` keys the editor `.id` so every staging REMOUNTS (the outliner re-seeds its tree). FSEvents stream (file-level, 0.5 s latency) on BOTH `projects/` and `archive/`; rescan off-main through the app-scoped scan cache, skipping the `posts` assignment on equality (@Observable invalidates on assignment — panes would regroup on autosave echoes); the rescan hands the session the open post's disk text (the #67 external-change check, watcher echo suppressed by equality). Mixed-outline guard: a lossy outline select HOLDS the ask over an empty editor (nothing can normalize on ⌘S before the choice); reselect of the held piece is a no-op. External guest: one at a time, symlink-resolved (an atomic write renames over a symlink), its own watcher, dismissed flush-first by any post/draft open. Imports: ONE origin ask per batch, per-file failures continue into `lastError`. Structural ops are flush-first via `flushOrAbort` (a failed write or an unanswered #67 conflict aborts with nothing changed — the alert stays up). Convert: consent rechecked at answer time (Headings aborts when the body went lossy behind the ask); converting the open piece tears down and reopens routed prose. `runPass` chain: guards (one rail, mentor not mid-turn, engine ready, open saved piece) → flush → snapshot (unconditional, even for a later cancel) → capture stats → lint emit → `runningPass` live → own-engine run → advance ONLY on `.ended` with stopReason ≠ "refusal". `blindRead` mirrors the guards; nothing advances or records. `refreshCards` rides the rescan + open tails; `applyCard` = flush-first, stale anchor flags the card with no text change, the edit lands through `EditorSession.adoptText`; `promoteCard` writes a Learning and touches no text. `micropubSendDraft` = flush-first, ONE disk read serves both wire fields, success stamps `micropub_url`. `canArmWritingLock`/`editorBodyText` mirror the editor's outline routing (prose only).
- `OutlineTree.swift` — the one-file plain nested-bullet tree model (ADR-0013): lenient parse, canonical serialize, normalize on save (preamble verbatim, stray prose after the first item drops); `parsesWithLoss` shares `parseItem` so detector and parser never disagree; structural ops are path-addressed, id-preserving, boundary-nil; single-node moves CROSS parents at sibling boundaries (LogSeq-style); `enter` = split/outdent/new-sibling; `extract`/`insertRun` are the drag primitives; `headingsLadderBody` = the Convert transform. Folds live in the view, keyed by node UUID.
- `OutlineEditorView.swift` — `OutlinePresenter` (pure projection: visible rows, fold skipping, zoom re-basing at a node's children, block selection, `applyBatch` sibling-only moves) + the SwiftUI surface: chrome bullets by depth, per-depth rails, ONE promoted `OutlineRowTextView` on the focused row, drag grip + drop chrome, zoom breadcrumbs, Esc stack (drag-cancel → selection-collapse → zoom-out). **Esc needs a local NSEvent keyDown monitor** — SwiftUI's hosting layer swallows Esc before keyDown AND before `.onExitCommand` (probe-pinned in EscEventProbeTests). Every keystroke serializes the whole tree through the existing session machinery; zoom/drag state is view-only, reset on load.
- `OutlineDrag.swift` — drag plumbing: NSEvent monitors (global outside the app, so an Esc-cancel never resolves as a drop); the gesture holds STRONG arm-time captures (a mid-drag scroll can drop the origin row's catcher — mouse-up must still clear state); live geometry from `CatcherView.rowFrames` reading CURRENT window-space frames (SwiftUI 27 removed the `.window` coordinate space; cached frames go stale on scroll); the pure drop math (`DropTarget`, `draggedIDs`, `isValidDrop`, `applyDrop`, `hitTestDrop`) rides a nonisolated presenter extension — resolved by id AFTER extraction.
+2 -3
View File
@@ -174,11 +174,11 @@ private struct CardRow: View {
// Apply = ask-before, a BLOCKING ask: the sheet is the only path
// from the Apply button to a write.
.sheet(isPresented: $asking) {
ApplyAskSheet(card: card, posts: gate.posts, home: gate.museionHome)
ApplyAskSheet(card: card, posts: gate.posts)
}
// #26: Promote is its own blocking ask — one confirm, one Learning.
.sheet(isPresented: $promoting) {
PromoteAskSheet(card: card, posts: gate.posts, home: gate.museionHome)
PromoteAskSheet(card: card, posts: gate.posts)
}
}
@@ -232,7 +232,6 @@ private struct SkipButton: View {
private struct ApplyAskSheet: View {
let card: FixCardStore.StoredFixCard
let posts: PostsModel
let home: URL
@Environment(\.dismiss) private var dismiss
@State private var wentStale = false
-1
View File
@@ -17,7 +17,6 @@ import SwiftUI
/// #33 (S6.1): the two-step Micro.blog ask over the open piece.
struct MicropubPublishSheet: View {
let posts: PostsModel
let home: URL
@Environment(\.dismiss) private var dismiss
private enum Phase: Equatable {
+9 -11
View File
@@ -177,10 +177,10 @@ final class PostsModel {
/// each. Nil in production (no observer, no cost).
@ObservationIgnored
var onRailEvent: (@MainActor (PostsModelRailEvent) -> Void)?
/// #179: the Home the model owns — set by `bind` ALONE (app
/// construction and the Settings repoint are the only two places it is
/// set); every verb reads it, none takes it. Watcher root + rescan
/// target.
/// #179: the Home the model owns — set by `bind` ALONE (WorkspaceView's
/// root `.task(id: museionHome)`: first frame and every repoint,
/// whichever pane is showing); every verb reads it, none takes it.
/// Watcher root + rescan target.
private(set) var boundHome: URL?
private var watcher = PostsWatcher()
/// #143 (OPT-F3): scan parse memo — a rescan re-parses only changed
@@ -192,8 +192,9 @@ final class PostsModel {
/// Bind a Home: ensure both container roots exist (FSEvents on a missing
/// path is unreliable; archive/ is a watcher root now, #107), initial
/// scan + start (or restart) the watcher. Called from
/// `.task(id: home)` — re-fires on Home repoint.
/// scan + start (or restart) the watcher. Called from WorkspaceView's
/// root `.task(id: museionHome)` — first frame and every Home repoint,
/// pane-independent.
func bind(home: URL) {
startWatching(home: home)
Task { await rescan() }
@@ -274,12 +275,9 @@ final class PostsModel {
/// its window).
func saveDraft() {
guard let staged = draft, let home = boundHome else { return }
let text = staged.text
let project = staged.project
let type = staged.type
railWrite {
let post = try PostStore.writeNew(body: text, project: project, type: type, home: home)
lastDraftWasOutline = type == .outline // #109: covers the lagging rescan
let post = try PostStore.writeNew(body: staged.text, project: staged.project, type: staged.type, home: home)
lastDraftWasOutline = staged.type == .outline // #109: covers the lagging rescan
draft = nil
pendingProject = nil // #108: the explicit target landed with the draft
selectedPostID = post.id
+5 -2
View File
@@ -17,7 +17,8 @@ import Foundation
/// #179: rail observability — what the write-rail suite reads off the
/// seam. `.write` = a verb's body rode the rail; `.pairedRescan` = the
/// rail scheduled the verb's ONE rescan; `.writeFailed` = the verb's
/// write threw (the strip owns the reason; nothing paired).
/// write threw (the reason's ROUTING stays with the entry — strip or
/// sheet; nothing paired).
enum PostsModelRailEvent: Equatable {
case write
case pairedRescan
@@ -55,7 +56,8 @@ extension PostsModel {
/// #179: the reason-returning entry (project creation) — the sheet
/// owns its inline reason and the strip behind the sheet must not
/// double-message one error. Same ONE rescan on success.
/// double-message one error. Same ONE rescan on success; a throw
/// still reports `.writeFailed` on the seam (the strip never hears it).
func railWriteReturningReason(_ operation: () throws -> Void) -> String? {
onRailEvent?(.write)
do {
@@ -63,6 +65,7 @@ extension PostsModel {
pairRailRescan()
return nil
} catch {
onRailEvent?(.writeFailed) // the seam reports it; the sheet owns the reason
return error.localizedDescription
}
}
+1 -5
View File
@@ -85,14 +85,10 @@ struct PostsPaneView: View {
}
}
}
.task(id: home) {
// Bind: initial off-main scan + (re)start the FSEvents watcher (#61).
model.bind(home: home)
}
// #33 (S6.1): the publish ask rides the pane (not the library
// column) — it targets the open piece.
.sheet(isPresented: $showingPublish) {
MicropubPublishSheet(posts: model, home: home)
MicropubPublishSheet(posts: model)
}
}
-1
View File
@@ -17,7 +17,6 @@ import SwiftUI
struct PromoteAskSheet: View {
let card: FixCardStore.StoredFixCard
let posts: PostsModel
let home: URL
@Environment(\.dismiss) private var dismiss
@State private var refusal: String?
+7
View File
@@ -151,6 +151,13 @@ struct WorkspaceView: View {
}
}
}
// #179 audit: the model bind rides the ROOT task — the Archive
// pane and every root sheet (import / new project / convert) call
// library verbs from any pane; a pane-local bind left `boundHome`
// stale after a Home repoint until Posts remounted.
.task(id: gate.museionHome) {
gate.posts.bind(home: gate.museionHome)
}
// Collapsed floor: rail 56 + editor placeholder (export ≤920 layout).
.frame(minWidth: 480, minHeight: 320)
// #151: every failure arrival auto-expands the card — a fresh