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
View File
@@ -205,6 +205,7 @@ Session logs live in `docs/devlog/` (one per completed task/issue/milestone). Fu
<!-- write-log: window-start -->
| Date | Log |
|------|-----|
| 2026-11-10 | [20261110-issue179-postsmodel-write-rail_log.md](docs/devlog/20261110-issue179-postsmodel-write-rail_log.md) |
| 2026-11-09 | [20261109-issue178-extract-engine-host-transport-seam_log.md](docs/devlog/20261109-issue178-extract-engine-host-transport-seam_log.md) |
| 2026-11-09 | [20261109-issue177-type-transcript-rail-shared-tool-payload-decoder_log.md](docs/devlog/20261109-issue177-type-transcript-rail-shared-tool-payload-decoder_log.md) |
| 2026-11-09 | [20261109-issue183-shrink-agentsmd_log.md](docs/devlog/20261109-issue183-shrink-agentsmd_log.md) |
+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
+1
View File
@@ -39,6 +39,7 @@ Conventions every suite follows. Per-suite pin inventories are NOT kept here —
- `MicropubTests`, `MicropubModelTests`, `MicropubMediaTests` — publish wire contract, model flow, media/illustration surface.
- `MCPToolsTests`, `MCPServerWireTests`, `MCPToolsPromoteTests`, `ToolPayloadsTests`, `LearningsPaneTests`, `LearningDecayTests` — museion-tools store, wire, promote, tool-payload decoder shapes (strict + lenient, #177), learnings pane, decay.
- `FixCardApplyTests` — fix-card apply/skip/done lifecycle.
- `PostsModelWriteRailTests` — the #179 write rail's seam observability: every store-write verb rides the rail with exactly one paired rescan; a failed write (either failure-reporting entry) pairs none.
- `PostsModelTests`, `PassRunTests`, `BlindReadTests`, `EngineLifecycleTests`, `SessionLifecycleTests`, `SessionScopeTests`, `TranscriptRailTests` — model orchestration over the scripted in-process engine (#178): passes, blind read, per-surface engines, session lifecycle, scoped hosting, the typed transcript rail (#177 — speaker/notice type facts through the scripted engine, prefix-free invariant, append-seam classifiers).
- `DeslopLintTests` (with the `DeslopLintWiringTests` member) — native lint findings, config story, emit loop.
- `EditorSessionTests`, `ReadingPresenterTests`, `ProsePresenterTests`, `FocusModeTests`, `ImportExternalTests`, `ImageIngestTests` — editor session, reading pipeline, editing-surface parity, focus math, import + image ingest.
@@ -128,4 +128,20 @@ struct PostsModelWriteRailTests {
#expect(events == [.write, .writeFailed])
#expect(model.lastError != nil)
}
/// #179 audit: the reason-returning entry reports failure on the seam
/// too — `.writeFailed` fires, nothing pairs, and the strip stays
/// untouched (the sheet owns the reason).
@Test func `a failed reason-returning write reports writeFailed and leaves the strip alone`() throws {
let (model, _) = try makeModelHome()
var events: [PostsModelRailEvent] = []
model.onRailEvent = { events.append($0) }
#expect(model.createProject(named: "essays") == nil)
events.removeAll()
// case-folded duplicate → PostStore.createProject throws
#expect(model.createProject(named: "Essays") != nil)
#expect(events == [.write, .writeFailed])
#expect(model.lastError == nil)
}
}
@@ -38,3 +38,18 @@ Route every library verb's store write through ONE internal seam that pairs the
## Machine-state notes (this slot)
The hosted-test runner was wedged on arrival: six testmanagerd xctestsession transactions stuck for 2+ hours (an `_XCT_enableAutomationModeWithReply` open since ~00:11, before this slot). `killall` (SIGTERM) logged an exit handler but left pid 48552 alive; `kill -9` + launchd respawn cleared it — hosted tests ran normally after. Suite-member `-only-testing` filters containing backticks/spaces matched zero tests and "passed" vacuously (exit 0, empty counts) — the whole-suite filter is the reliable spelling.
## Finish-audit closeout (2026-11-10)
Three-reviewer fanout (ponytail / security / general) on the branch diff plus the pending AGENTS.md docs delta; findings triaged and fixed in the same tree.
**Accepted + fixed:**
- **Bind hoisted to the WorkspaceView root** (`.task(id: gate.museionHome)`): the pane-local `.task(id: home)` unmounted with the Posts pane, leaving `boundHome` stale after a Home repoint while the Archive pane and every root sheet (import / new project / convert) kept writing through it — a regression window main didn't have (its verbs read `gate.museionHome` fresh). The overclaiming comments ("app construction and the Settings repoint are the only two places it is set") corrected to name the root task. Unpinned delta: view wiring, no render harness — verified by build + suite; the bind seam itself is model-level.
- **`railWriteReturningReason` now emits `.writeFailed` on a throw** — the reason-returning entry's failure was unobservable on the seam (bare `[.write]` trail). Pinned: `a failed reason-returning write reports writeFailed and leaves the strip alone` (duplicate project name → `[.write, .writeFailed]`, `lastError` stays nil — pins the routing separation too). Flip-verified: guard removed → only this pin fails; restored → green.
- **Dead `home` parameters deleted** — `MicropubPublishSheet`, `PromoteAskSheet`, `ApplyAskSheet` no longer take or thread a Home (the sweep had stopped one layer short).
- **saveDraft's three hoisted locals deleted** — `staged` is an immutable local, captured directly.
**Rejected/deferred:** security INFO findings (pre-bind no-op guards unreachable via real UI and non-destructive; `onRailEvent` a standard internal test seam) — no remediation.
**Post-fix verification:** full unit suite `test-without-building -only-testing:MuseionTests` → executed 655 / passed 655 / failed 0 / skipped 0 (the 654 + the new pin); swiftformat 0/135 dirty; swiftlint 279 violations / 60 serious — byte-identical to base. `Task { await rescan() }` still exactly two sites (bind + `pairRailRescan`). GitNexus impact on `saveDraft`/`bind` = HIGH (144–145 upstream) — the acknowledged app-scoped-model closure; all edits body-only or call-site moves with grep-enumerated callers. The index itself predates the branch (no rail symbols).