From 804b5889f6c1b9bf9fe8abc0da0ff451d57011ef Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Thu, 1 Oct 2026 13:14:55 +0200 Subject: [PATCH 1/3] =?UTF-8?q?feat(workspace):=20add=20M1=20Home=20&=20Po?= =?UTF-8?q?sts=20list=20=E2=80=94=20nav=20rail,=20posts=20mirror,=20Home?= =?UTF-8?q?=20repoint=20(fixes=20#17)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The post-gate main surface is the workspace shell from the design contract: nav rail (Posts/Sessions/Learnings/Settings), Posts pane mirroring /posts/ on disk (Pass State groups, origin meta, empty state; lazy folders skipped), Settings pane with repoint-only Home picking (NSOpenPanel + UserDefaults, default ~/Documents/Museion per b3daac9), placeholder panes until #28/#26. Column collapse mirrors the export's media queries so narrow windows never clip. Mentor pane becomes the fourth column (#14 surface preserved). [Generated by AI] --- AGENTS.md | 1 + CHANGELOG.md | 2 + Museion/AGENTS.md | 10 ++ Museion/ContentView.swift | 8 +- Museion/DesignTokens.swift | 34 ++++ Museion/MentorPaneView.swift | 3 +- Museion/MuseionApp.swift | 20 +++ Museion/PostLibrary.swift | 114 ++++++++++++ Museion/PostsPaneView.swift | 168 ++++++++++++++++++ Museion/SettingsPaneView.swift | 53 ++++++ Museion/WorkspaceView.swift | 168 ++++++++++++++++++ MuseionTests/AGENTS.md | 1 + MuseionTests/PostLibraryTests.swift | 111 ++++++++++++ .../20261001-issue17-home-posts-list_log.md | 73 ++++++++ docs/devlog/INDEX.md | 1 + 15 files changed, 762 insertions(+), 5 deletions(-) create mode 100644 Museion/DesignTokens.swift create mode 100644 Museion/PostLibrary.swift create mode 100644 Museion/PostsPaneView.swift create mode 100644 Museion/SettingsPaneView.swift create mode 100644 Museion/WorkspaceView.swift create mode 100644 MuseionTests/PostLibraryTests.swift create mode 100644 docs/devlog/20261001-issue17-home-posts-list_log.md diff --git a/AGENTS.md b/AGENTS.md index a7263a3..7ce42ff 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -177,6 +177,7 @@ Session logs live in `docs/devlog/` (one per completed task/issue/milestone). Fu | Date | Log | |------|-----| +| 2026-10-01 | [20261001-issue17-home-posts-list_log.md](docs/devlog/20261001-issue17-home-posts-list_log.md) | | 2026-09-25 | [20260925-issue50-profile-backup-s2-6_log.md](docs/devlog/20260925-issue50-profile-backup-s2-6_log.md) | | 2026-09-16 | [20260916-issue14-acp-bridge-s2-2_log.md](docs/devlog/20260916-issue14-acp-bridge-s2-2_log.md) | | 2026-09-05 | [20260905-issue48-provisioning-failure-alert-retry-ux_log.md](docs/devlog/20260905-issue48-provisioning-failure-alert-retry-ux_log.md) | diff --git a/CHANGELOG.md b/CHANGELOG.md index f8dafb2..c2e5814 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file. The format ### Added +- **workspace:** M1 Home & Posts list (PRD S1.1) — the post-gate main surface is now the workspace shell from the design contract: nav rail (Posts, Sessions, Learnings, Settings), a Posts pane that mirrors the Museion Home's `posts/` folder on disk (Pass State groups, origin meta, empty state, lazy folders skipped), a Settings pane where the Home can be repointed (repoint-only — Museion never moves content; NSOpenPanel picker, UserDefaults persistence, default `~/Documents/Museion`), and placeholder panes for Sessions/Learnings until their milestones; the M0 mentor pane becomes the workspace's fourth column (issue #17) + - **backup:** S2.6 daily profile backup — on launch, once per 24 h and only while the engine is idle (gateway.pid liveness + `ps` scan), Museion snapshots `~/.hermes/profiles/museion/` into a timestamped folder under `~/Library/Application Support/Museion/Backups/` (credentials included, logs/caches/locks excluded, last 7 kept); restore is manual Finder copy-back — Help → Open Backup Folder, `RESTORE.md` beside the snapshots (issue #50) - **acp:** M0 ACP bridge (PRD S2.2) — the app spawns the Hermes engine (`hermes acp -p museion`) as a child process via a hand-rolled NDJSON JSON-RPC stdio client, opens a Session, streams mentor replies live in a debug pane, renders fix-card tool calls as structured cards, cancels turns via Stop, tears the child down on quit, and surfaces an in-pane restart prompt on engine crash — never data loss (issue #14) - **provisioning:** S2.1 profile provisioning — idempotent per-gate pass creates the `museion` Hermes profile (`hermes profile create --no-alias --no-skills`) and additively seeds the bundled writing skills via `seed-manifest.txt`; existing skills are never overwritten (issue #47) diff --git a/Museion/AGENTS.md b/Museion/AGENTS.md index d4032ea..8dd87d5 100644 --- a/Museion/AGENTS.md +++ b/Museion/AGENTS.md @@ -17,6 +17,16 @@ Owned by the root AGENTS.md contract. The `.xcodeproj` uses **filesystem-synchro - No persistence layer yet — the SwiftData template was stripped; vault-vs-database gets an ADR when the need is real. Exception: the engine gate's `state.json` (see below). - Tabs for indentation; SwiftFormat + SwiftLint must both stay clean. +## Workspace shell (M1, #17 / S1.1) + +- `DesignTokens.swift` — palette/geometry from the design contract (`ref/Web-Prototype/museion-workspace.html` `:root` + grid): background/surface/foreground/muted/border/accent colors, radius 10/14, column widths (rail 56, library 232, editor min 420, mentor 356), serif/mono font designs. Light-only — the export defines one palette. +- `WorkspaceView.swift` — post-gate main surface (replaces the M0 mentor pane as root): nav rail (Posts/Sessions/Learnings + Settings at bottom) + active pane. `RailButton` per the export (44×44, muted icon, hover wash, surface card + 2px edge bar when current). Sessions/Learnings are honest placeholders until #28/#26. Posts renders the full grid; **column collapse mirrors the export's media queries** (library hides < 1100 px, mentor hides < 920 px budget) as macOS pane collapse — never a fixed four-column minWidth that clips. `PaneHeader` = 52pt serif-15 title row + border. +- `PostsPaneView.swift` — Posts destination: library column (Pass State groups in mono-11 uppercase labels, post rows with title + passState/origin meta), empty state, editor placeholder until #19–#21, mentor column (`MentorPaneView`, fixed 356). Selecting a post sets `selectedPostID` (editor shows its title; no editing yet). +- `PostLibrary.swift` — `Post` (nonisolated: id/title/passState/origin) + `PostLibrary.scan(home:)`: reads `posts//post.md`, skips dirs without post.md (lazy folders), loose files, hidden dirs; Title = first non-empty line after frontmatter, `#` stripped, `untitled` when blank; `pass_state`/`origin` frontmatter keys read leniently (First Draft/writer defaults — corpus posts ship bare; key format pinned by #18). Read-only — lifecycle is #18. +- `SettingsPaneView.swift` — Home control (NSOpenPanel folder pick; files/canCreate on). Repoint-only semantics stated in-UI. +- `AppGateState.museionHome` — app-scoped Home (UserDefaults `museionHome`, default `~/Documents/Museion` = `defaultMuseionHome`). Explicit init: `Self` in a stored-property initializer breaks `@ObservationTracked` (covariant-Self error). +- `MentorPaneView` no longer carries a root min-frame — it lives in the 356pt mentor column. + ## Engine gate (launch gate, tickets #35–#41) - `EngineGate.swift` — `EngineProbe` (nonisolated): six-path probe order, `acp --check` health (stdin closed, 5 s timeout, exit-status branching), `acp --version` version, `state.json` writer/reader. `EngineGateModel` (@MainActor @Observable): phases for the UI, `onPass` seam (fires provisioning, #47), `currentBinaryPath` handed to provisioning. `execute(_:timeout:)`/`ProcessOutput` are internal — shared child-process machinery. diff --git a/Museion/ContentView.swift b/Museion/ContentView.swift index 96e8237..0329a11 100644 --- a/Museion/ContentView.swift +++ b/Museion/ContentView.swift @@ -35,11 +35,11 @@ struct ContentView: View { @Bindable var gate = gate Group { - // #14: post-gate main surface is the mentor debug pane (M0 demo - // surface, map decision: pane placement). Gate pass hands over the - // probe's winning binary — no re-probe. + // #17: post-gate main surface is the workspace shell (nav rail + + // Posts/Sessions/Learnings/Settings). Gate pass hands over the probe's + // winning binary — no re-probe. if gate.gateModel.currentBinaryPath != nil { - MentorPaneView(model: gate.mentor, binaryPath: gate.gateModel.currentBinaryPath) + WorkspaceView() } else { VStack(spacing: 8) { Image(systemName: "books.vertical") diff --git a/Museion/DesignTokens.swift b/Museion/DesignTokens.swift new file mode 100644 index 0000000..81bf2d8 --- /dev/null +++ b/Museion/DesignTokens.swift @@ -0,0 +1,34 @@ +// +// DesignTokens.swift +// Museion +// +// Visual tokens from the design contract (ref/Web-Prototype/museion-workspace.html, #17). +// + +import SwiftUI + +/// Colors, radii, and column geometry extracted from the export's `:root` +/// and workspace grid. Light-only on purpose — the export defines one palette. +enum DesignTokens { + static let background = Color(red: 0xFA / 255, green: 0xFA / 255, blue: 0xF7 / 255) + static let surface = Color(red: 1, green: 1, blue: 1) + static let foreground = Color(red: 0x1A / 255, green: 0x19 / 255, blue: 0x16 / 255) + static let muted = Color(red: 0x6B / 255, green: 0x69 / 255, blue: 0x64 / 255) + static let border = Color(red: 0xE8 / 255, green: 0xE5 / 255, blue: 0xDF / 255) + static let accent = Color(red: 0xC9 / 255, green: 0x64 / 255, blue: 0x42 / 255) + + static let radius: CGFloat = 10 + static let radiusLarge: CGFloat = 14 + + /// The workspace grid: rail | posts library | editor | mentor (grid-template-columns + /// `56px 232px minmax(420px, 1fr) 356px`). + static let railWidth: CGFloat = 56 + static let libraryWidth: CGFloat = 232 + static let editorMinWidth: CGFloat = 420 + static let mentorWidth: CGFloat = 356 + + /// The serif display face maps to the system serif design (export stack: + /// Iowan Old Style / Charter / Georgia); mono to the system monospaced. + static let serif: Font.Design = .serif + static let mono: Font.Design = .monospaced +} diff --git a/Museion/MentorPaneView.swift b/Museion/MentorPaneView.swift index 8e0e849..b435c28 100644 --- a/Museion/MentorPaneView.swift +++ b/Museion/MentorPaneView.swift @@ -37,7 +37,8 @@ struct MentorPaneView: View { crashCard(lastPrompt: lastPrompt) } } - .frame(minWidth: 560, minHeight: 420) + // #17: the pane lives in the workspace's fixed 356pt mentor column — + // no root min frame (it was the full-window M0 surface). .task { model.binaryPath = binaryPath ?? model.binaryPath // Hosted unit tests run this app as their runner — never spawn a diff --git a/Museion/MuseionApp.swift b/Museion/MuseionApp.swift index 60638c6..0120756 100644 --- a/Museion/MuseionApp.swift +++ b/Museion/MuseionApp.swift @@ -22,6 +22,26 @@ final class AppGateState { let backup = BackupModel() /// #14: the app-scoped mentor bridge — the pane renders it; quit tears it down. let mentor = MentorSessionModel() + /// #17: the Museion Home — repoint-only (ADR-0004). Defaults to + /// `~/Documents/Museion`; UserDefaults is the persistence floor: a Home is + /// a plain folder, nothing app-owned to put in a database. + var museionHome: URL { + didSet { UserDefaults.standard.set(museionHome.absoluteString, forKey: "museionHome") } + } + + init() { + // Explicit init: `Self` in a stored-property initializer trips + // @ObservationTracked's macro expansion (covariant Self). + museionHome = UserDefaults.standard.string(forKey: "museionHome").flatMap(URL.init(string:)) + ?? Self.defaultMuseionHome + } + + /// The default Home, absent a stored override — `~/Documents/Museion` + /// (b3daac9: Documents, not the account root; TCC note in ADR-0004). + nonisolated static let defaultMuseionHome = FileManager.default.homeDirectoryForCurrentUser + .appendingPathComponent("Documents/Museion", isDirectory: true) + + private static let homeKey = "museionHome" } @main diff --git a/Museion/PostLibrary.swift b/Museion/PostLibrary.swift new file mode 100644 index 0000000..4b58e7e --- /dev/null +++ b/Museion/PostLibrary.swift @@ -0,0 +1,114 @@ +// +// PostLibrary.swift +// Museion +// +// #17 (S1.1): the Posts list mirrors what is on disk under the Museion Home. +// + +import Foundation + +/// One Post on disk: `/posts//post.md` (ADR-0004 shape). +/// A Post directory with no post.md yet is skipped — folders are created lazily +/// on first write, so an empty folder is not a Post. +nonisolated struct Post: Identifiable, Equatable { + /// The post folder's name — the Post's durable identity (CONTEXT.md). + let id: String + /// The Post's Title: first non-empty line, heading markers stripped. + var title: String + /// Pass State from frontmatter; First Draft when absent (explicit, never inferred). + var passState: PassState + /// Origin from frontmatter; writer when absent. Immutable once set (CONTEXT.md). + var origin: Origin + + nonisolated enum PassState: String, Equatable, CaseIterable { + case firstDraft = "First Draft" + case pass1Done = "Pass-1 Done" + case pass2Done = "Pass-2 Done" + } + + nonisolated enum Origin: String, Equatable { + case writer + /// PRD S5.1 pins the frontmatter vocabulary: `origin: writer|ai`. + // swiftlint:disable:next identifier_name + case ai + } +} + +/// Scans `/posts/` and parses each Post's frontmatter leniently. +/// Read-only for #17 — create/rename/delete round-trips are #18. +/// Nonisolated: a pure synchronous disk scan, safe from any executor. +nonisolated struct PostLibrary: Equatable { + private(set) var posts: [Post] = [] + + /// Reads every `posts//post.md`. Frontmatter keys (`pass_state:`, `origin:`) + /// are read leniently — corpus posts ship bare, so absent or unknown values fall + /// back to First Draft / writer. Keys outside a frontmatter block are ignored; + /// a malformed folder can't crash the list. + static func scan(home: URL) -> PostLibrary { + let postsURL = home.appendingPathComponent("posts", isDirectory: true) + guard let entries = try? FileManager.default.contentsOfDirectory( + at: postsURL, + includingPropertiesForKeys: [.isDirectoryKey], + ) else { return PostLibrary() } + + var posts: [Post] = [] + for dir in entries where (try? dir.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true { + let fileURL = dir.appendingPathComponent("post.md") + guard let text = try? String(contentsOf: fileURL, encoding: .utf8) else { continue } + let frontmatter = Self.frontmatter(of: text) + posts.append( + Post( + id: dir.lastPathComponent, + title: Self.title(of: text), + passState: Post.PassState(rawValue: frontmatter["pass_state"] ?? "") ?? .firstDraft, + origin: Post.Origin(rawValue: frontmatter["origin"] ?? "") ?? .writer, + ), + ) + } + return PostLibrary(posts: posts.sorted { $0.title.localizedStandardCompare($1.title) == .orderedAscending }) + } + + /// The `---`-delimited frontmatter block if present; empty otherwise. + static func frontmatter(of text: String) -> [String: String] { + let lines = text.split(separator: "\n", omittingEmptySubsequences: false) + guard lines.first?.trimmed() == "---" else { return [:] } + var map: [String: String] = [:] + for line in lines.dropFirst() { + let trimmed = line.trimmed() + guard trimmed != "---" else { break } + guard let colon = trimmed.firstIndex(of: ":") else { continue } + let key = trimmed[.. String { + var lines = text.split(separator: "\n", omittingEmptySubsequences: false)[...] + if lines.first?.trimmed() == "---" { + if let close = lines.dropFirst().firstIndex(where: { $0.trimmed() == "---" }) { + lines = lines[(close + 1)...] + } else { + lines = lines.dropFirst() // unterminated block: no title inside it + } + } + for line in lines { + let trimmed = line.trimmed() + if trimmed.isEmpty { + continue + } + return trimmed.trimmingCharacters(in: CharacterSet(charactersIn: "#").union(.whitespaces)) + } + return "untitled" + } +} + +private nonisolated extension Substring { + func trimmed() -> String { + trimmingCharacters(in: .whitespacesAndNewlines) + } +} diff --git a/Museion/PostsPaneView.swift b/Museion/PostsPaneView.swift new file mode 100644 index 0000000..1087d72 --- /dev/null +++ b/Museion/PostsPaneView.swift @@ -0,0 +1,168 @@ +// +// PostsPaneView.swift +// Museion +// +// #17 (S1.1): the Posts pane — library column mirroring the Home's posts/ +// on disk, editor placeholder until #19–#21, mentor column (#14). +// + +import SwiftUI + +/// The Posts destination: the workspace's full four-column layout +/// library 232 | editor ≥420 | mentor 356 (design contract grid). +struct PostsPaneView: View { + let home: URL + /// #14: the app-scoped mentor model + the gate's winning binary (no re-probe). + var mentor: MentorSessionModel + var mentorBinaryPath: String? + /// Width budget after the rail — drives column collapse (export media queries: + /// library hides ≤1100, mentor hides ≤920). + var availableWidth: CGFloat = .infinity + @State private var library = PostLibrary() + @State private var selectedPostID: String? + + private var showsLibrary: Bool { + availableWidth >= 1100 - DesignTokens.railWidth + } + + private var showsMentor: Bool { + availableWidth >= 920 - DesignTokens.railWidth + } + + var body: some View { + HStack(spacing: 0) { + if showsLibrary { + libraryColumn + paneBorder + } + editorPlaceholder + if showsMentor { + paneBorder + mentorColumn + } + } + .task(id: home) { library = PostLibrary.scan(home: home) } + } + + private var paneBorder: some View { + Rectangle() + .fill(DesignTokens.border) + .frame(width: 1) + } + + // MARK: Library column + + private var libraryColumn: some View { + VStack(spacing: 0) { + PaneHeader(title: "Posts") { + // New Post arrives with #18 (Post lifecycle: lazy folder + slug). + EmptyView() + } + if library.posts.isEmpty { + emptyState + } else { + ScrollView { + LazyVStack(alignment: .leading, spacing: 4) { + ForEach(Post.PassState.allCases, id: \.self) { state in + let posts = library.posts.filter { $0.passState == state } + if !posts.isEmpty { + Text(state.rawValue.uppercased()) + .font(.system(size: 11, design: DesignTokens.mono)) + .kerning(0.6) + .foregroundStyle(DesignTokens.muted) + .padding(.horizontal, 14) + .padding(.top, 18) + .padding(.bottom, 7) + ForEach(posts) { post in + PostRow(post: post, selected: post.id == selectedPostID) { + selectedPostID = post.id + } + } + } + } + } + .padding(.bottom, 12) + } + } + } + .frame(width: DesignTokens.libraryWidth) + } + + private var emptyState: some View { + VStack(spacing: 8) { + Text("No posts yet") + .font(.system(size: 16, weight: .semibold, design: DesignTokens.serif)) + Text("Posts in this Home's posts/ folder appear here.") + .font(.callout) + .foregroundStyle(DesignTokens.muted) + .multilineTextAlignment(.center) + } + .padding(38) + .frame(maxWidth: .infinity, maxHeight: .infinity) + } + + // MARK: Editor + mentor columns + + private var editorPlaceholder: some View { + VStack(spacing: 10) { + if let post = library.posts.first(where: { $0.id == selectedPostID }) { + Text(post.title) + .font(.system(size: 16, weight: .semibold, design: DesignTokens.serif)) + } + Text("The editor arrives with S1.2 (#19–#21).") + .font(.callout) + .foregroundStyle(DesignTokens.muted) + } + .frame(maxWidth: .infinity, maxHeight: .infinity) + .background(DesignTokens.surface) + } + + private var mentorColumn: some View { + MentorPaneView(model: mentor, binaryPath: mentorBinaryPath) + .frame(width: DesignTokens.mentorWidth) + } +} + +/// One post row per the export: title, Pass State + Origin in mono 11. +private struct PostRow: View { + let post: Post + let selected: Bool + let select: () -> Void + @State private var hover = false + + var body: some View { + Button(action: select) { + VStack(alignment: .leading, spacing: 5) { + Text(post.title) + .font(.callout.weight(.semibold)) + .lineLimit(1) + .truncationMode(.tail) + .frame(maxWidth: .infinity, alignment: .leading) + HStack { + Text(post.passState.rawValue) + Text(post.origin.rawValue) + } + .font(.system(size: 11, design: DesignTokens.mono)) + .foregroundStyle(DesignTokens.muted) + .frame(maxWidth: .infinity, alignment: .leading) + } + .padding(10) + } + .buttonStyle(.plain) + .foregroundStyle(DesignTokens.foreground) + .background { + let fill: Color? = selected ? DesignTokens.surface : (hover ? DesignTokens.foreground.opacity(0.06) : nil) + if let fill { + RoundedRectangle(cornerRadius: DesignTokens.radius) + .fill(fill) + .overlay( + RoundedRectangle(cornerRadius: DesignTokens.radius) + .strokeBorder(selected ? DesignTokens.border : .clear), + ) + } + } + .padding(.horizontal, 8) + .onHover { hover = $0 } + .accessibilityLabel("\(post.title), \(post.passState.rawValue), origin \(post.origin.rawValue)") + } +} diff --git a/Museion/SettingsPaneView.swift b/Museion/SettingsPaneView.swift new file mode 100644 index 0000000..e89777d --- /dev/null +++ b/Museion/SettingsPaneView.swift @@ -0,0 +1,53 @@ +// +// SettingsPaneView.swift +// Museion +// +// #17 (S1.1): Settings — the Museion Home path, repoint-only (ADR-0004). +// + +import AppKit +import SwiftUI + +/// Settings pane. #17 scope: the Home control only — further settings arrive +/// with their tickets. Choosing a folder repoints Museion at that root; +/// content is never moved. +struct SettingsPaneView: View { + @Binding var home: URL + + var body: some View { + ScrollView { + VStack(alignment: .leading, spacing: 12) { + Text("Content") + .font(.system(size: 13, weight: .semibold)) + HStack(spacing: 8) { + Text(home.path(percentEncoded: false)) + .font(.system(size: 12, design: DesignTokens.mono)) + .lineLimit(1) + .truncationMode(.middle) + .textSelection(.enabled) + Spacer(minLength: 12) + Button("Choose…") { chooseHome() } + } + Text( + "Repoint-only: Museion never moves content. The Posts list reads this folder's posts/ directory.", + ) + .font(.callout) + .foregroundStyle(DesignTokens.muted) + } + .padding(24) + .frame(maxWidth: .infinity, alignment: .leading) + } + .background(DesignTokens.background) + } + + private func chooseHome() { + let panel = NSOpenPanel() + panel.canChooseDirectories = true + panel.canChooseFiles = false + panel.canCreateDirectories = true + panel.message = "Choose the folder holding your posts. Museion never moves content." + if panel.runModal() == .OK, let url = panel.url { + home = url + } + } +} diff --git a/Museion/WorkspaceView.swift b/Museion/WorkspaceView.swift new file mode 100644 index 0000000..a515132 --- /dev/null +++ b/Museion/WorkspaceView.swift @@ -0,0 +1,168 @@ +// +// WorkspaceView.swift +// Museion +// +// #17 (S1.1): the workspace shell — nav rail + panes, built from the design +// contract's grid geometry (ref/Web-Prototype/museion-workspace.html): +// rail 56 | library 232 | editor min 420 | mentor 356. +// + +import SwiftUI + +/// The post-gate main surface. Posts shows the full four-column workspace; +/// Sessions/Learnings/Settings fill the space after the rail until their +/// tickets land (#28/#26; Settings is real here). +struct WorkspaceView: View { + @Environment(AppGateState.self) private var gate + @State private var selection: Pane = .posts + + enum Pane: Hashable { + case posts + case sessions + case learnings + case settings + } + + var body: some View { + @Bindable var gate = gate + + return GeometryReader { geo in + HStack(spacing: 0) { + navRail + paneBorder + switch selection { + case .posts: + // #14: mentor column hands in the app-scoped model + gate's winner. + // Column collapse mirrors the export's media queries (library ≤1100, + // mentor ≤920) as macOS pane collapse per the PRD. + PostsPaneView( + home: gate.museionHome, + mentor: gate.mentor, + mentorBinaryPath: gate.gateModel.currentBinaryPath, + availableWidth: geo.size.width - DesignTokens.railWidth, + ) + case .sessions: + PlaceholderPane(title: "Sessions", detail: "Session lifecycle arrives with S2.3 (#28).") + case .learnings: + PlaceholderPane(title: "Learnings", detail: "Promote, consult, and decay arrive with S4 (#26, #27).") + case .settings: + SettingsPaneView(home: $gate.museionHome) + } + } + .background(DesignTokens.background) + } + // Collapsed floor: rail 56 + editor 420 (export ≤920 layout). + .frame(minWidth: 480, minHeight: 320) + } + + /// 1px contract border between rail and pane (`.rail { border-right }`). + private var paneBorder: some View { + Rectangle() + .fill(DesignTokens.border) + .frame(width: 1) + } + + // MARK: Nav rail + + private var navRail: some View { + VStack(spacing: 8) { + RailButton(pane: .posts, selection: $selection, label: "Posts", systemImage: "doc.text") + RailButton(pane: .sessions, selection: $selection, label: "Sessions", systemImage: "bubble.left") + RailButton(pane: .learnings, selection: $selection, label: "Learnings", systemImage: "cube") + Spacer() + RailButton(pane: .settings, selection: $selection, label: "Settings", systemImage: "gearshape") + } + .padding(.horizontal, 4) + .padding(.vertical, 8) + .frame(width: DesignTokens.railWidth) + .frame(maxHeight: .infinity) + } +} + +/// Rail button per the export: 44×44 muted icon, hover wash, and the current +/// pane raised as a surface card with a 2px selection bar on the rail's edge. +private struct RailButton: View { + let pane: WorkspaceView.Pane + @Binding var selection: WorkspaceView.Pane + let label: String + let systemImage: String + @State private var hover = false + + var body: some View { + let selected = selection == pane + Button { + selection = pane + } label: { + Image(systemName: systemImage) + .frame(width: 44, height: 44) + } + .buttonStyle(.plain) + .foregroundStyle(selected ? DesignTokens.foreground : DesignTokens.muted) + .background { + if selected || hover { + RoundedRectangle(cornerRadius: DesignTokens.radius) + .fill(selected ? DesignTokens.surface : DesignTokens.foreground.opacity(0.06)) + .overlay( + RoundedRectangle(cornerRadius: DesignTokens.radius) + .strokeBorder(selected ? DesignTokens.border : .clear), + ) + } + } + .overlay(alignment: .leading) { + // Selection bar (`.rail-btn[aria-current]::before`); offset to sit + // on the rail's leading edge like the export's negative inset. + if selected { + Rectangle() + .fill(DesignTokens.foreground) + .frame(width: 2, height: 22) + .offset(x: -6) + } + } + .onHover { hover = $0 } + .help(label) + .accessibilityLabel(label) + } +} + +/// Pane-head row per the export (52pt, serif 15 semibold title, bottom border). +struct PaneHeader: View { + let title: String + @ViewBuilder var trailing: () -> Trailing + + var body: some View { + VStack(spacing: 0) { + HStack { + Text(title) + .font(.system(size: 15, weight: .semibold, design: DesignTokens.serif)) + Spacer() + trailing() + } + .padding(.horizontal, 14) + .frame(minHeight: 52) + Rectangle() + .fill(DesignTokens.border) + .frame(height: 1) + } + } +} + +/// Navigation-target placeholder (#17 AC: panes exist as targets; real content +/// arrives with their tickets — honest copy, no fake controls). +struct PlaceholderPane: View { + let title: String + let detail: String + + var body: some View { + VStack(spacing: 10) { + Image(systemName: "hourglass") + .font(.largeTitle) + .foregroundStyle(DesignTokens.muted) + Text(title) + .font(.system(size: 16, weight: .semibold, design: DesignTokens.serif)) + Text(detail) + .font(.callout) + .foregroundStyle(DesignTokens.muted) + } + .frame(maxWidth: .infinity, maxHeight: .infinity) + } +} diff --git a/MuseionTests/AGENTS.md b/MuseionTests/AGENTS.md index fb1a6ca..7d127e7 100644 --- a/MuseionTests/AGENTS.md +++ b/MuseionTests/AGENTS.md @@ -20,6 +20,7 @@ Owned by the root AGENTS.md contract. - `EngineGateTests.swift` builds fake `hermes` shell scripts in temp dirs and runs them through the real `Process` path — copy that pattern for any future child-process testing. - `ACPClientTests.swift` extends it into a full fake ACP *server*: a zsh script speaking real NDJSON JSON-RPC over stdio (`makeFakeACP`), with a per-binary mode file (`crashAfterHandshake`, `hangOnPrompt`, default full) and a base64-encoded fix-card payload — shell quoting can never break the wire JSON. Only `acpTempDir` remains as a helper; crash assertions use Swift Testing's `confirmation` (hook the callback BEFORE triggering the crash). - `ProfileProvisionerTests.swift` extends it: the fake creates the profile at `/profiles/` (self-locating, race-free under parallel tests); payload dirs are built at runtime; the bundled-payload test asserts manifest ↔ payload correspondence. #48 failure-path tests live in `ProfileProvisionerFailureTests.swift` (own file — Not-Now defer + re-fail, config.yaml byte-identity + fresh-profile no-config (mcp_servers negative invariant), state.json engine-gate-only, copy-phase catch branch, path-traversal rejection, orphaned-temp sweep). Shared helpers (`makeFakeHermes`, `makePayload`, `defaultSkills`, `provTempDir`) are internal in `ProfileProvisionerTests.swift`. `ProfileBackupTests.swift` (own helpers `backupTempDir`/`makeProfileFixture`) injects profile/backups roots, a fixed clock, and a `psScan` stub — a dev machine may run the real engine, so the ps scan is never trusted in tests. +- `PostLibraryTests.swift` (#17) — throwaway Homes via `makeHome`/`writePost` in temp dirs: bare corpus posts (First Draft/writer defaults), lenient frontmatter (`pass_state`/`origin`), lazy folders + noise not surfacing, localizedStandardCompare title sort, blank-draft `untitled`, default Home = `~/Documents/Museion`. ## Verification diff --git a/MuseionTests/PostLibraryTests.swift b/MuseionTests/PostLibraryTests.swift new file mode 100644 index 0000000..6ad3f42 --- /dev/null +++ b/MuseionTests/PostLibraryTests.swift @@ -0,0 +1,111 @@ +// +// PostLibraryTests.swift +// MuseionTests +// +// #17: the Posts list mirrors /posts/ on disk. +// + +import Foundation +@testable import Museion +import Testing + +/// Builds throwaway Homes in a temp dir: posts written bare (corpus shape, +/// no frontmatter) or with frontmatter; noise entries that must not crash or +/// surface as Posts. +private func makeHome(_ write: (URL) throws -> Void) throws -> URL { + let home = FileManager.default.temporaryDirectory + .appendingPathComponent("postlib-\(UUID().uuidString)", isDirectory: true) + try FileManager.default.createDirectory(at: home, withIntermediateDirectories: true) + try write(home) + return home +} + +private func writePost(_ home: URL, _ id: String, _ body: String) throws { + let dir = home.appendingPathComponent("posts/\(id)", isDirectory: true) + try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true) + try body.write(to: dir.appendingPathComponent("post.md"), atomically: true, encoding: .utf8) +} + +@Test func `bare post is first draft writer with heading title`() throws { + let home = try makeHome { home in + try writePost(home, "the-new-reeder", "## The New Reeder\n\nBody text.") + } + let library = PostLibrary.scan(home: home) + #expect(library.posts.count == 1) + let post = try #require(library.posts.first) + #expect(post.id == "the-new-reeder") + #expect(post.title == "The New Reeder") + #expect(post.passState == .firstDraft) + #expect(post.origin == .writer) +} + +@Test func `frontmatter keys are read leniently`() throws { + let home = try makeHome { home in + try writePost( + home, + "a-short-defence-of-footnotes", + "---\npass_state: Pass-1 Done\norigin: ai\ntitle: ignored — body wins\n---\n\n# A Short Defence of Footnotes\n\nBody.", + ) + } + let post = try #require(PostLibrary.scan(home: home).posts.first) + #expect(post.passState == .pass1Done) + #expect(post.origin == .ai) + #expect(post.title == "A Short Defence of Footnotes") +} + +@Test func `empty home is empty and missing home is empty`() throws { + let empty = try makeHome { _ in } + #expect(PostLibrary.scan(home: empty).posts.isEmpty) + + let missing = FileManager.default.temporaryDirectory + .appendingPathComponent("postlib-missing-\(UUID().uuidString)") + #expect(PostLibrary.scan(home: missing).posts.isEmpty) +} + +@Test func `lazy folders and noise are not posts`() throws { + let home = try makeHome { home in + try writePost(home, "one", "One") + // Lazy folder: no post.md yet (created lazily on first write, #18). + try FileManager.default.createDirectory( + at: home.appendingPathComponent("posts/not-yet", isDirectory: true), + withIntermediateDirectories: true, + ) + // Noise: loose file at posts/ root, hidden dir. + try "loose".write( + to: home.appendingPathComponent("posts/loose.md"), + atomically: true, + encoding: .utf8, + ) + try FileManager.default.createDirectory( + at: home.appendingPathComponent("posts/.DS_Store-dir", isDirectory: true), + withIntermediateDirectories: true, + ) + } + #expect(PostLibrary.scan(home: home).posts.map(\.id) == ["one"]) +} + +@Test func `posts sort by title locally`() throws { + let home = try makeHome { home in + try writePost(home, "z-id", "## Alpha\n") + try writePost(home, "a-id", "## Beta 2\n") + try writePost(home, "m-id", "## beta 10\n") + } + // localizedStandardCompare: case-insensitive, numeric-aware (Finder order). + #expect(PostLibrary.scan(home: home).posts.map(\.title) == ["Alpha", "Beta 2", "beta 10"]) +} + +@Test func `blank draft title is untitled`() { + #expect(PostLibrary.title(of: "\n\n \n") == "untitled") + #expect(PostLibrary.title(of: "---\npass_state: Pass-2 Done\n---\n") == "untitled") + #expect(PostLibrary.title(of: "") == "untitled") + // Frontmatter-first title: first non-empty line after the block. + #expect(PostLibrary.title(of: "---\norigin: writer\n---\n\n## Named\n\nBody") == "Named") +} + +@Test func `home default is documents museion`() { + #expect( + AppGateState.defaultMuseionHome + == FileManager.default.homeDirectoryForCurrentUser + .appendingPathComponent("Documents/Museion", isDirectory: true), + ) +} diff --git a/docs/devlog/20261001-issue17-home-posts-list_log.md b/docs/devlog/20261001-issue17-home-posts-list_log.md new file mode 100644 index 0000000..5ca0075 --- /dev/null +++ b/docs/devlog/20261001-issue17-home-posts-list_log.md @@ -0,0 +1,73 @@ +# M1: Home & Posts list (#17) + +> **Date:** 2026-10-01 +> **Type:** issue +> **Reference:** https://git.babylondreams.de/AlexKucera/museion/issues/17 + +## Goal + +Ship #17 (S1.1): the workspace shell from the design contract — nav rail (Posts, Sessions, Learnings, Settings), Posts pane mirroring the Home's `posts/` on disk with empty state, Home editable in Settings with repoint-only semantics, placeholder panes for Sessions/Learnings. + +## What Was Done + +- `DesignTokens.swift` — palette + geometry extracted from `museion-workspace.html` (`:root` vars, grid columns 56/232/min-420/356, radii 10/14, serif/mono designs). +- `WorkspaceView.swift` — post-gate root surface: nav rail + pane switch; `RailButton` with the export's selected-card + edge-bar treatment; honest placeholders for Sessions (#28) / Learnings (#26, #27). +- `PostsPaneView.swift` — Posts destination with Pass State group labels, post rows (title + mono meta), empty state, editor placeholder (#19–#21), mentor column (`MentorPaneView` at 356). +- `PostLibrary.swift` — `PostLibrary.scan(home:)`: mirrors `posts/` (dirs with `post.md` only — lazy folders and noise skipped), lenient frontmatter (`pass_state`/`origin`, First Draft/writer defaults), Title = first non-empty line after frontmatter with `#` stripped, `untitled` fallback. +- `SettingsPaneView.swift` — Home row + NSOpenPanel repoint; repoint-only copy in-UI. +- `AppGateState.museionHome` — UserDefaults-backed, default `~/Documents/Museion` (main's b3daac9 default, not the old `~/Museion` from the issue text). +- `MentorPaneView` root min-frame dropped (it's a column now). +- Tests (+7): PostLibraryTests — bare post defaults, lenient frontmatter, empty/missing home, lazy-folder + noise exclusion, title sort, untitled edges, default Home. + +## Decisions & Rationale + +| Decision | Rationale | +|----------|-----------| +| Column collapse instead of a fat minWidth | First build forced rail+library+editor+mentor minWidth (1064); the restored 900pt window clipped the rail and mentor off-screen (user hit it live). The export collapses at media-query thresholds (≤1100 library, ≤920 mentor); PRD says map that to macOS pane collapse. `GeometryReader` budget drives `showsLibrary`/`showsMentor`. | +| Lenient frontmatter read (`pass_state`/`origin` keys, defaults) | Corpus posts ship bare; the write-side key format is #18's to pin. CONTEXT.md: Pass State explicit, never inferred — First Draft default is the honest read of a bare post. | +| UserDefaults for the Home | A Home is a plain folder the user points at — nothing app-owned worth a database. Same floor as state.json reasoning. | +| NSOpenPanel over fileImporter | fileImporter's folder mode still shows files on macOS; one proven AppKit call beats bridging workarounds. | +| Explicit `AppGateState.init()` | `Self` in a stored-property initializer trips `@ObservationTracked` (covariant-Self compile error). | +| Scan on `.task(id: home)` only | #17 is read-only; no FS events yet — #18 adds lifecycle (create/rename/delete round-trips) and re-scan triggers. | + +## Gotchas & Fixes + +| Problem | Root Cause | Fix | +|---------|------------|-----| +| Empty posts list despite defaults write | `defaults write` from the agent's shell lives in a different cfprefsd context than the `open`-launched app; plist on disk never got the key | Verified scan logic standalone (swift REPL finds both posts); user-path verification (Settings → Choose…) is the honest route — CLI defaults injection is unreliable for GUI apps | +| Rail icons "invisible" in early screenshots | 900pt restored window < 1064 minWidth → HStack laid out at min size, clipping both edges | Column collapse (above) | +| `localizedStandardCompare` order surprise | It's Finder-like (case-insensitive, numeric-aware): "Beta 2" < "beta 10" | Test expectation corrected — the code is right | +| SwiftFormat reformatting drive-by (944-line prototype diff) | Ran `swiftformat .` repo-wide | Reverted untouched files; formatted only changed files after | +| AppleScript `by` reserved word | `set {bx, by} to position` — `by` is an AppleScript term | Renamed to `btnPos`/`btnSize` | + +## Verification + +- Build: `xcodebuild … build` → **BUILD SUCCEEDED** +- Tests: full suite → **TEST SUCCEEDED**, 52/52 passed (45 pre-existing + 7 new) +- Lint: `swiftlint Museion/ MuseionTests/` → 0 violations; SwiftFormat clean on changed files +- Live: app launched, gate sheet passed and dismissed via AX, workspace rendered (rail/Posts/editor/mentor verified by screenshot); window-resize collapse fix built but final visual pass blocked by a fullscreen break timer — needs one manual look + +## Files Changed + +| File | Change Summary | +|------|---------------| +| `Museion/DesignTokens.swift` | New — design-contract tokens | +| `Museion/WorkspaceView.swift` | New — nav rail + pane shell, collapse logic | +| `Museion/PostsPaneView.swift` | New — library column, groups, empty state, editor placeholder | +| `Museion/PostLibrary.swift` | New — disk scan + lenient frontmatter | +| `Museion/SettingsPaneView.swift` | New — Home repoint via NSOpenPanel | +| `Museion/MuseionApp.swift` | `AppGateState.museionHome` + default | +| `Museion/ContentView.swift` | Post-gate root → `WorkspaceView` | +| `Museion/MentorPaneView.swift` | Root min-frame dropped | +| `MuseionTests/PostLibraryTests.swift` | New — 7 tests | +| `Museion/AGENTS.md`, `MuseionTests/AGENTS.md` | Contracts updated | + +## Open Items & Next Steps + +- [ ] Manual look at the collapse behavior at narrow widths (break timer blocked the final screenshot pass) +- [ ] #18 Post lifecycle — New Post button, lazy folder creation, slug naming, rename/delete round-trips; pins the frontmatter key format written on save +- [ ] Mentor engine crash on workspace entry — pre-existing #14 behavior (drift note also visible); not #17 scope but worth a #28 look when Sessions land + +--- + +*Log written by write-log skill* diff --git a/docs/devlog/INDEX.md b/docs/devlog/INDEX.md index 5705c27..854eb5e 100644 --- a/docs/devlog/INDEX.md +++ b/docs/devlog/INDEX.md @@ -5,6 +5,7 @@ Complete history of session logs in this directory, newest first. One-line summa | Date | Type | File | Summary | |------|------|------|---------| +| 2026-10-01 | issue | [20261001-issue17-home-posts-list_log.md](20261001-issue17-home-posts-list_log.md) | #17 shipped: workspace shell, Posts mirror, Home repoint — 52 tests green | | 2026-09-25 | issue | [20260925-issue50-profile-backup-s2-6_log.md](20260925-issue50-profile-backup-s2-6_log.md) | #50 S2.6 daily profile backup: liveness gate, curated copy, retention 7, RESTORE.md — 8 tests green | | 2026-09-16 | issue | [20260916-issue14-acp-bridge-s2-2_log.md](20260916-issue14-acp-bridge-s2-2_log.md) | #14 M0 ACP bridge: NDJSON JSON-RPC client, mentor pane, fix-card round-trip, crash restart — 37 tests green | | 2026-09-05 | issue | [20260905-issue48-provisioning-failure-alert-retry-ux_log.md](20260905-issue48-provisioning-failure-alert-retry-ux_log.md) | #48 shipped: failure card with retry/Not-Now, traversal guard, temp sweep — 30 tests green | From 765d32d4d49dc9292031fc998170536995883a1d Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Thu, 1 Oct 2026 13:43:25 +0200 Subject: [PATCH 2/3] =?UTF-8?q?refactor(workspace):=20finish-audit=20fixes?= =?UTF-8?q?=20=E2=80=94=20off-main=20scan,=20parser=20edges,=20dead=20code?= =?UTF-8?q?=20out?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewers' findings on 804b588: scan moved off MainActor (Task.detached), PostLibrary struct folded into Post.scan, hidden dirs and symlinked dirs now actually skipped (test de-vacuated), unterminated frontmatter no longer leaks as the Title, quoted YAML values unquoted, leading blank line before --- tolerated, #-only body reads untitled, persisted Home validated isFileURL. Dead code deleted: radiusLarge, editorMinWidth, homeKey, PaneHeader trailing slot, Settings ScrollView, PostRow fill dance. Tests 56/56, lint 0. [Generated by AI] --- Museion/AGENTS.md | 6 +- Museion/DesignTokens.swift | 5 +- Museion/MuseionApp.swift | 9 ++- Museion/PostLibrary.swift | 63 +++++++-------- Museion/PostsPaneView.swift | 30 ++++---- Museion/SettingsPaneView.swift | 38 +++++---- Museion/WorkspaceView.swift | 7 +- MuseionTests/AGENTS.md | 2 +- MuseionTests/PostLibraryTests.swift | 77 +++++++++++++++---- .../20261001-issue17-home-posts-list_log.md | 22 ++++++ 10 files changed, 158 insertions(+), 101 deletions(-) diff --git a/Museion/AGENTS.md b/Museion/AGENTS.md index 8dd87d5..d8a874c 100644 --- a/Museion/AGENTS.md +++ b/Museion/AGENTS.md @@ -19,12 +19,12 @@ Owned by the root AGENTS.md contract. The `.xcodeproj` uses **filesystem-synchro ## Workspace shell (M1, #17 / S1.1) -- `DesignTokens.swift` — palette/geometry from the design contract (`ref/Web-Prototype/museion-workspace.html` `:root` + grid): background/surface/foreground/muted/border/accent colors, radius 10/14, column widths (rail 56, library 232, editor min 420, mentor 356), serif/mono font designs. Light-only — the export defines one palette. +- `DesignTokens.swift` — palette/geometry from the design contract (`ref/Web-Prototype/museion-workspace.html` `:root` + grid): background/surface/foreground/muted/border/accent colors, radius 10, column widths (rail 56, library 232, mentor 356; the export's editor min 420 lands with #19's editor column), serif/mono font designs. Light-only — the export defines one palette. - `WorkspaceView.swift` — post-gate main surface (replaces the M0 mentor pane as root): nav rail (Posts/Sessions/Learnings + Settings at bottom) + active pane. `RailButton` per the export (44×44, muted icon, hover wash, surface card + 2px edge bar when current). Sessions/Learnings are honest placeholders until #28/#26. Posts renders the full grid; **column collapse mirrors the export's media queries** (library hides < 1100 px, mentor hides < 920 px budget) as macOS pane collapse — never a fixed four-column minWidth that clips. `PaneHeader` = 52pt serif-15 title row + border. - `PostsPaneView.swift` — Posts destination: library column (Pass State groups in mono-11 uppercase labels, post rows with title + passState/origin meta), empty state, editor placeholder until #19–#21, mentor column (`MentorPaneView`, fixed 356). Selecting a post sets `selectedPostID` (editor shows its title; no editing yet). -- `PostLibrary.swift` — `Post` (nonisolated: id/title/passState/origin) + `PostLibrary.scan(home:)`: reads `posts//post.md`, skips dirs without post.md (lazy folders), loose files, hidden dirs; Title = first non-empty line after frontmatter, `#` stripped, `untitled` when blank; `pass_state`/`origin` frontmatter keys read leniently (First Draft/writer defaults — corpus posts ship bare; key format pinned by #18). Read-only — lifecycle is #18. +- `PostLibrary.swift` — `Post` (nonisolated: id/title/passState/origin) + `Post.scan(home:) -> [Post]`: reads `posts//post.md`, skips dirs without post.md (lazy folders), loose files, hidden dirs (dot-prefix), and symlinked dirs; Title = first non-empty line after frontmatter (`untitled` on blank, marker-only, or unterminated-frontmatter bodies); `pass_state`/`origin` frontmatter keys read leniently (First Draft/writer defaults, quoted YAML values unquoted, leading blank line before `---` tolerated — corpus posts ship bare; write-side key format pinned by #18). Read-only — lifecycle is #18. Scan runs off-main via `Task.detached` in PostsPaneView (big Homes must not freeze the UI). - `SettingsPaneView.swift` — Home control (NSOpenPanel folder pick; files/canCreate on). Repoint-only semantics stated in-UI. -- `AppGateState.museionHome` — app-scoped Home (UserDefaults `museionHome`, default `~/Documents/Museion` = `defaultMuseionHome`). Explicit init: `Self` in a stored-property initializer breaks `@ObservationTracked` (covariant-Self error). +- `AppGateState.museionHome` — app-scoped Home (UserDefaults `museionHome`, default `~/Documents/Museion` = `defaultMuseionHome`; non-file URLs read back as nil — the Home is always a folder). Explicit init: `Self` in a stored-property initializer breaks `@ObservationTracked` (covariant-Self error). - `MentorPaneView` no longer carries a root min-frame — it lives in the 356pt mentor column. ## Engine gate (launch gate, tickets #35–#41) diff --git a/Museion/DesignTokens.swift b/Museion/DesignTokens.swift index 81bf2d8..4c9daaa 100644 --- a/Museion/DesignTokens.swift +++ b/Museion/DesignTokens.swift @@ -18,13 +18,12 @@ enum DesignTokens { static let accent = Color(red: 0xC9 / 255, green: 0x64 / 255, blue: 0x42 / 255) static let radius: CGFloat = 10 - static let radiusLarge: CGFloat = 14 /// The workspace grid: rail | posts library | editor | mentor (grid-template-columns - /// `56px 232px minmax(420px, 1fr) 356px`). + /// `56px 232px minmax(420px, 1fr) 356px`). Editor min (420) has no enforcement + /// yet — the editor column arrives with #19. static let railWidth: CGFloat = 56 static let libraryWidth: CGFloat = 232 - static let editorMinWidth: CGFloat = 420 static let mentorWidth: CGFloat = 356 /// The serif display face maps to the system serif design (export stack: diff --git a/Museion/MuseionApp.swift b/Museion/MuseionApp.swift index 0120756..1273768 100644 --- a/Museion/MuseionApp.swift +++ b/Museion/MuseionApp.swift @@ -24,7 +24,8 @@ final class AppGateState { let mentor = MentorSessionModel() /// #17: the Museion Home — repoint-only (ADR-0004). Defaults to /// `~/Documents/Museion`; UserDefaults is the persistence floor: a Home is - /// a plain folder, nothing app-owned to put in a database. + /// a plain folder, nothing app-owned to put in a database. Non-file URLs + /// read back as nil (the default wins) — the Home is always a folder. var museionHome: URL { didSet { UserDefaults.standard.set(museionHome.absoluteString, forKey: "museionHome") } } @@ -32,7 +33,9 @@ final class AppGateState { init() { // Explicit init: `Self` in a stored-property initializer trips // @ObservationTracked's macro expansion (covariant Self). - museionHome = UserDefaults.standard.string(forKey: "museionHome").flatMap(URL.init(string:)) + museionHome = UserDefaults.standard.string(forKey: "museionHome") + .flatMap(URL.init(string:)) + .flatMap { $0.isFileURL ? $0 : nil } ?? Self.defaultMuseionHome } @@ -40,8 +43,6 @@ final class AppGateState { /// (b3daac9: Documents, not the account root; TCC note in ADR-0004). nonisolated static let defaultMuseionHome = FileManager.default.homeDirectoryForCurrentUser .appendingPathComponent("Documents/Museion", isDirectory: true) - - private static let homeKey = "museionHome" } @main diff --git a/Museion/PostLibrary.swift b/Museion/PostLibrary.swift index 4b58e7e..acd2e9e 100644 --- a/Museion/PostLibrary.swift +++ b/Museion/PostLibrary.swift @@ -8,12 +8,10 @@ import Foundation /// One Post on disk: `/posts//post.md` (ADR-0004 shape). -/// A Post directory with no post.md yet is skipped — folders are created lazily -/// on first write, so an empty folder is not a Post. nonisolated struct Post: Identifiable, Equatable { /// The post folder's name — the Post's durable identity (CONTEXT.md). let id: String - /// The Post's Title: first non-empty line, heading markers stripped. + /// The Post's Title: first non-empty line after any frontmatter, heading markers stripped. var title: String /// Pass State from frontmatter; First Draft when absent (explicit, never inferred). var passState: PassState @@ -32,76 +30,73 @@ nonisolated struct Post: Identifiable, Equatable { // swiftlint:disable:next identifier_name case ai } -} -/// Scans `/posts/` and parses each Post's frontmatter leniently. -/// Read-only for #17 — create/rename/delete round-trips are #18. -/// Nonisolated: a pure synchronous disk scan, safe from any executor. -nonisolated struct PostLibrary: Equatable { - private(set) var posts: [Post] = [] - - /// Reads every `posts//post.md`. Frontmatter keys (`pass_state:`, `origin:`) - /// are read leniently — corpus posts ship bare, so absent or unknown values fall - /// back to First Draft / writer. Keys outside a frontmatter block are ignored; + /// Reads every `posts//post.md` into Posts (sorted by title, Finder order). + /// Read-only for #17 — create/rename/delete round-trips are #18. Symlinks and + /// hidden dirs are skipped; folders without `post.md` (lazy) aren't Posts; /// a malformed folder can't crash the list. - static func scan(home: URL) -> PostLibrary { + static func scan(home: URL) -> [Post] { let postsURL = home.appendingPathComponent("posts", isDirectory: true) guard let entries = try? FileManager.default.contentsOfDirectory( at: postsURL, - includingPropertiesForKeys: [.isDirectoryKey], - ) else { return PostLibrary() } + includingPropertiesForKeys: [.isDirectoryKey, .isSymbolicLinkKey], + ) else { return [] } var posts: [Post] = [] - for dir in entries where (try? dir.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true { + for dir in entries { + let values = try? dir.resourceValues(forKeys: [.isDirectoryKey, .isSymbolicLinkKey]) + guard values?.isDirectory ?? false, !(values?.isSymbolicLink ?? false), + !dir.lastPathComponent.hasPrefix(".") else { continue } let fileURL = dir.appendingPathComponent("post.md") guard let text = try? String(contentsOf: fileURL, encoding: .utf8) else { continue } - let frontmatter = Self.frontmatter(of: text) + let frontmatter = frontmatter(of: text) posts.append( Post( id: dir.lastPathComponent, - title: Self.title(of: text), - passState: Post.PassState(rawValue: frontmatter["pass_state"] ?? "") ?? .firstDraft, - origin: Post.Origin(rawValue: frontmatter["origin"] ?? "") ?? .writer, + title: title(of: text), + passState: PassState(rawValue: frontmatter["pass_state"] ?? "") ?? .firstDraft, + origin: Origin(rawValue: frontmatter["origin"] ?? "") ?? .writer, ), ) } - return PostLibrary(posts: posts.sorted { $0.title.localizedStandardCompare($1.title) == .orderedAscending }) + return posts.sorted { $0.title.localizedStandardCompare($1.title) == .orderedAscending } } /// The `---`-delimited frontmatter block if present; empty otherwise. + /// Quoted scalar values (`origin: "ai"`) are unquoted — lenient YAML. static func frontmatter(of text: String) -> [String: String] { let lines = text.split(separator: "\n", omittingEmptySubsequences: false) - guard lines.first?.trimmed() == "---" else { return [:] } + guard lines.first(where: { !$0.trimmed().isEmpty })?.trimmed() == "---" else { return [:] } var map: [String: String] = [:] - for line in lines.dropFirst() { + for line in lines.drop(while: { $0.trimmed() != "---" }).dropFirst() { let trimmed = line.trimmed() guard trimmed != "---" else { break } guard let colon = trimmed.firstIndex(of: ":") else { continue } let key = trimmed[.. String { var lines = text.split(separator: "\n", omittingEmptySubsequences: false)[...] - if lines.first?.trimmed() == "---" { - if let close = lines.dropFirst().firstIndex(where: { $0.trimmed() == "---" }) { + if let open = lines.firstIndex(where: { !$0.trimmed().isEmpty }), lines[open].trimmed() == "---" { + if let close = lines[(open + 1)...].firstIndex(where: { $0.trimmed() == "---" }) { lines = lines[(close + 1)...] } else { - lines = lines.dropFirst() // unterminated block: no title inside it + return "untitled" // unterminated block: nothing trustworthy follows } } for line in lines { let trimmed = line.trimmed() - if trimmed.isEmpty { - continue - } - return trimmed.trimmingCharacters(in: CharacterSet(charactersIn: "#").union(.whitespaces)) + guard !trimmed.isEmpty else { continue } + let stripped = trimmed.trimmingCharacters(in: CharacterSet(charactersIn: "#").union(.whitespaces)) + return stripped.isEmpty ? "untitled" : stripped } return "untitled" } diff --git a/Museion/PostsPaneView.swift b/Museion/PostsPaneView.swift index 1087d72..73fc5dd 100644 --- a/Museion/PostsPaneView.swift +++ b/Museion/PostsPaneView.swift @@ -17,8 +17,8 @@ struct PostsPaneView: View { var mentorBinaryPath: String? /// Width budget after the rail — drives column collapse (export media queries: /// library hides ≤1100, mentor hides ≤920). - var availableWidth: CGFloat = .infinity - @State private var library = PostLibrary() + var availableWidth: CGFloat + @State private var posts: [Post] = [] @State private var selectedPostID: String? private var showsLibrary: Bool { @@ -41,7 +41,10 @@ struct PostsPaneView: View { mentorColumn } } - .task(id: home) { library = PostLibrary.scan(home: home) } + .task(id: home) { + // Scan off-main: .task inherits MainActor; a big Home must not freeze the UI. + posts = await Task.detached(priority: .userInitiated) { Post.scan(home: home) }.value + } } private var paneBorder: some View { @@ -54,18 +57,16 @@ struct PostsPaneView: View { private var libraryColumn: some View { VStack(spacing: 0) { - PaneHeader(title: "Posts") { - // New Post arrives with #18 (Post lifecycle: lazy folder + slug). - EmptyView() - } - if library.posts.isEmpty { + // New Post arrives with #18 (Post lifecycle: lazy folder + slug). + PaneHeader(title: "Posts") + if posts.isEmpty { emptyState } else { ScrollView { LazyVStack(alignment: .leading, spacing: 4) { ForEach(Post.PassState.allCases, id: \.self) { state in - let posts = library.posts.filter { $0.passState == state } - if !posts.isEmpty { + let grouped = posts.filter { $0.passState == state } + if !grouped.isEmpty { Text(state.rawValue.uppercased()) .font(.system(size: 11, design: DesignTokens.mono)) .kerning(0.6) @@ -73,7 +74,7 @@ struct PostsPaneView: View { .padding(.horizontal, 14) .padding(.top, 18) .padding(.bottom, 7) - ForEach(posts) { post in + ForEach(grouped) { post in PostRow(post: post, selected: post.id == selectedPostID) { selectedPostID = post.id } @@ -105,7 +106,7 @@ struct PostsPaneView: View { private var editorPlaceholder: some View { VStack(spacing: 10) { - if let post = library.posts.first(where: { $0.id == selectedPostID }) { + if let post = posts.first(where: { $0.id == selectedPostID }) { Text(post.title) .font(.system(size: 16, weight: .semibold, design: DesignTokens.serif)) } @@ -151,10 +152,9 @@ private struct PostRow: View { .buttonStyle(.plain) .foregroundStyle(DesignTokens.foreground) .background { - let fill: Color? = selected ? DesignTokens.surface : (hover ? DesignTokens.foreground.opacity(0.06) : nil) - if let fill { + if selected || hover { RoundedRectangle(cornerRadius: DesignTokens.radius) - .fill(fill) + .fill(selected ? DesignTokens.surface : DesignTokens.foreground.opacity(0.06)) .overlay( RoundedRectangle(cornerRadius: DesignTokens.radius) .strokeBorder(selected ? DesignTokens.border : .clear), diff --git a/Museion/SettingsPaneView.swift b/Museion/SettingsPaneView.swift index e89777d..3b2743b 100644 --- a/Museion/SettingsPaneView.swift +++ b/Museion/SettingsPaneView.swift @@ -15,28 +15,26 @@ struct SettingsPaneView: View { @Binding var home: URL var body: some View { - ScrollView { - VStack(alignment: .leading, spacing: 12) { - Text("Content") - .font(.system(size: 13, weight: .semibold)) - HStack(spacing: 8) { - Text(home.path(percentEncoded: false)) - .font(.system(size: 12, design: DesignTokens.mono)) - .lineLimit(1) - .truncationMode(.middle) - .textSelection(.enabled) - Spacer(minLength: 12) - Button("Choose…") { chooseHome() } - } - Text( - "Repoint-only: Museion never moves content. The Posts list reads this folder's posts/ directory.", - ) - .font(.callout) - .foregroundStyle(DesignTokens.muted) + VStack(alignment: .leading, spacing: 12) { + Text("Content") + .font(.system(size: 13, weight: .semibold)) + HStack(spacing: 8) { + Text(home.path(percentEncoded: false)) + .font(.system(size: 12, design: DesignTokens.mono)) + .lineLimit(1) + .truncationMode(.middle) + .textSelection(.enabled) + Spacer(minLength: 12) + Button("Choose…") { chooseHome() } } - .padding(24) - .frame(maxWidth: .infinity, alignment: .leading) + Text( + "Repoint-only: Museion never moves content. The Posts list reads this folder's posts/ directory.", + ) + .font(.callout) + .foregroundStyle(DesignTokens.muted) } + .padding(24) + .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) .background(DesignTokens.background) } diff --git a/Museion/WorkspaceView.swift b/Museion/WorkspaceView.swift index a515132..8bd0b3b 100644 --- a/Museion/WorkspaceView.swift +++ b/Museion/WorkspaceView.swift @@ -51,7 +51,7 @@ struct WorkspaceView: View { } .background(DesignTokens.background) } - // Collapsed floor: rail 56 + editor 420 (export ≤920 layout). + // Collapsed floor: rail 56 + editor placeholder (export ≤920 layout). .frame(minWidth: 480, minHeight: 320) } @@ -125,9 +125,9 @@ private struct RailButton: View { } /// Pane-head row per the export (52pt, serif 15 semibold title, bottom border). -struct PaneHeader: View { +/// Trailing slot returns with #18's New Post button. +struct PaneHeader: View { let title: String - @ViewBuilder var trailing: () -> Trailing var body: some View { VStack(spacing: 0) { @@ -135,7 +135,6 @@ struct PaneHeader: View { Text(title) .font(.system(size: 15, weight: .semibold, design: DesignTokens.serif)) Spacer() - trailing() } .padding(.horizontal, 14) .frame(minHeight: 52) diff --git a/MuseionTests/AGENTS.md b/MuseionTests/AGENTS.md index 7d127e7..d7009f7 100644 --- a/MuseionTests/AGENTS.md +++ b/MuseionTests/AGENTS.md @@ -20,7 +20,7 @@ Owned by the root AGENTS.md contract. - `EngineGateTests.swift` builds fake `hermes` shell scripts in temp dirs and runs them through the real `Process` path — copy that pattern for any future child-process testing. - `ACPClientTests.swift` extends it into a full fake ACP *server*: a zsh script speaking real NDJSON JSON-RPC over stdio (`makeFakeACP`), with a per-binary mode file (`crashAfterHandshake`, `hangOnPrompt`, default full) and a base64-encoded fix-card payload — shell quoting can never break the wire JSON. Only `acpTempDir` remains as a helper; crash assertions use Swift Testing's `confirmation` (hook the callback BEFORE triggering the crash). - `ProfileProvisionerTests.swift` extends it: the fake creates the profile at `/profiles/` (self-locating, race-free under parallel tests); payload dirs are built at runtime; the bundled-payload test asserts manifest ↔ payload correspondence. #48 failure-path tests live in `ProfileProvisionerFailureTests.swift` (own file — Not-Now defer + re-fail, config.yaml byte-identity + fresh-profile no-config (mcp_servers negative invariant), state.json engine-gate-only, copy-phase catch branch, path-traversal rejection, orphaned-temp sweep). Shared helpers (`makeFakeHermes`, `makePayload`, `defaultSkills`, `provTempDir`) are internal in `ProfileProvisionerTests.swift`. `ProfileBackupTests.swift` (own helpers `backupTempDir`/`makeProfileFixture`) injects profile/backups roots, a fixed clock, and a `psScan` stub — a dev machine may run the real engine, so the ps scan is never trusted in tests. -- `PostLibraryTests.swift` (#17) — throwaway Homes via `makeHome`/`writePost` in temp dirs: bare corpus posts (First Draft/writer defaults), lenient frontmatter (`pass_state`/`origin`), lazy folders + noise not surfacing, localizedStandardCompare title sort, blank-draft `untitled`, default Home = `~/Documents/Museion`. +- `PostLibraryTests.swift` (#17) — throwaway Homes via `makeHome`/`writePost` in temp dirs: bare corpus posts (First Draft/writer defaults), lenient + quoted frontmatter (`pass_state`/`origin`), lazy folders / hidden dirs / symlinks / noise not surfacing, localizedStandardCompare title sort, `untitled` edges (blank, marker-only, unterminated frontmatter), leading-blank-line frontmatter, default Home = `~/Documents/Museion`. ## Verification diff --git a/MuseionTests/PostLibraryTests.swift b/MuseionTests/PostLibraryTests.swift index 6ad3f42..795a3e2 100644 --- a/MuseionTests/PostLibraryTests.swift +++ b/MuseionTests/PostLibraryTests.swift @@ -30,9 +30,9 @@ private func writePost(_ home: URL, _ id: String, _ body: String) throws { let home = try makeHome { home in try writePost(home, "the-new-reeder", "## The New Reeder\n\nBody text.") } - let library = PostLibrary.scan(home: home) - #expect(library.posts.count == 1) - let post = try #require(library.posts.first) + let posts = Post.scan(home: home) + #expect(posts.count == 1) + let post = try #require(posts.first) #expect(post.id == "the-new-reeder") #expect(post.title == "The New Reeder") #expect(post.passState == .firstDraft) @@ -47,22 +47,31 @@ private func writePost(_ home: URL, _ id: String, _ body: String) throws { "---\npass_state: Pass-1 Done\norigin: ai\ntitle: ignored — body wins\n---\n\n# A Short Defence of Footnotes\n\nBody.", ) } - let post = try #require(PostLibrary.scan(home: home).posts.first) + let post = try #require(Post.scan(home: home).first) #expect(post.passState == .pass1Done) #expect(post.origin == .ai) #expect(post.title == "A Short Defence of Footnotes") } +@Test func `quoted frontmatter values are unquoted`() throws { + let home = try makeHome { home in + try writePost(home, "quoted", "---\npass_state: \"Pass-2 Done\"\norigin: 'ai'\n---\n\n## Quoted\n") + } + let post = try #require(Post.scan(home: home).first) + #expect(post.passState == .pass2Done) + #expect(post.origin == .ai) +} + @Test func `empty home is empty and missing home is empty`() throws { let empty = try makeHome { _ in } - #expect(PostLibrary.scan(home: empty).posts.isEmpty) + #expect(Post.scan(home: empty).isEmpty) let missing = FileManager.default.temporaryDirectory .appendingPathComponent("postlib-missing-\(UUID().uuidString)") - #expect(PostLibrary.scan(home: missing).posts.isEmpty) + #expect(Post.scan(home: missing).isEmpty) } -@Test func `lazy folders and noise are not posts`() throws { +@Test func `lazy folders, hidden dirs and noise are not posts`() throws { let home = try makeHome { home in try writePost(home, "one", "One") // Lazy folder: no post.md yet (created lazily on first write, #18). @@ -70,18 +79,36 @@ private func writePost(_ home: URL, _ id: String, _ body: String) throws { at: home.appendingPathComponent("posts/not-yet", isDirectory: true), withIntermediateDirectories: true, ) - // Noise: loose file at posts/ root, hidden dir. + // Hidden dir WITH a post.md — must not surface. + try writePost(home, ".trash", "---\n---\n## Hidden\n") + // Noise: loose file at posts/ root. try "loose".write( to: home.appendingPathComponent("posts/loose.md"), atomically: true, encoding: .utf8, ) - try FileManager.default.createDirectory( - at: home.appendingPathComponent("posts/.DS_Store-dir", isDirectory: true), - withIntermediateDirectories: true, + } + #expect(Post.scan(home: home).map(\.id) == ["one"]) +} + +@Test func `symlinked post dir is not followed`() throws { + let home = try makeHome { home in + try writePost(home, "one", "One") + // A post.md outside the Home, linked into posts/ by symlink. + let outside = home.deletingLastPathComponent() + .appendingPathComponent("postlib-outside-\(UUID().uuidString)", isDirectory: true) + try FileManager.default.createDirectory(at: outside, withIntermediateDirectories: true) + try "## Stolen\n".write( + to: outside.appendingPathComponent("post.md"), + atomically: true, + encoding: .utf8, + ) + try FileManager.default.createSymbolicLink( + at: home.appendingPathComponent("posts/linked", isDirectory: true), + withDestinationURL: outside, ) } - #expect(PostLibrary.scan(home: home).posts.map(\.id) == ["one"]) + #expect(Post.scan(home: home).map(\.id) == ["one"]) } @Test func `posts sort by title locally`() throws { @@ -91,15 +118,31 @@ private func writePost(_ home: URL, _ id: String, _ body: String) throws { try writePost(home, "m-id", "## beta 10\n") } // localizedStandardCompare: case-insensitive, numeric-aware (Finder order). - #expect(PostLibrary.scan(home: home).posts.map(\.title) == ["Alpha", "Beta 2", "beta 10"]) + #expect(Post.scan(home: home).map(\.title) == ["Alpha", "Beta 2", "beta 10"]) } @Test func `blank draft title is untitled`() { - #expect(PostLibrary.title(of: "\n\n \n") == "untitled") - #expect(PostLibrary.title(of: "---\npass_state: Pass-2 Done\n---\n") == "untitled") - #expect(PostLibrary.title(of: "") == "untitled") + #expect(Post.title(of: "\n\n \n") == "untitled") + #expect(Post.title(of: "---\npass_state: Pass-2 Done\n---\n") == "untitled") + #expect(Post.title(of: "") == "untitled") + #expect(Post.title(of: "#\n") == "untitled") // heading marker only, no text // Frontmatter-first title: first non-empty line after the block. - #expect(PostLibrary.title(of: "---\norigin: writer\n---\n\n## Named\n\nBody") == "Named") + #expect(Post.title(of: "---\norigin: writer\n---\n\n## Named\n\nBody") == "Named") +} + +@Test func `unterminated frontmatter is untitled, never leaked`() { + // No closing ---: frontmatter lines must never leak as the Title. + #expect(Post.title(of: "---\npass_state: First Draft\norigin: writer\n") == "untitled") + #expect(Post.frontmatter(of: "---\npass_state: First Draft\n")["pass_state"] == "First Draft") +} + +@Test func `leading blank line still opens frontmatter`() throws { + // A leading newline before --- must not defeat frontmatter detection. + let text = "\n---\npass_state: Pass-1 Done\n---\n\n## After Blank\n" + let home = try makeHome { try writePost($0, "blank-open", text) } + let post = try #require(Post.scan(home: home).first) + #expect(post.passState == .pass1Done) + #expect(post.title == "After Blank") } @Test func `home default is documents museion`() { diff --git a/docs/devlog/20261001-issue17-home-posts-list_log.md b/docs/devlog/20261001-issue17-home-posts-list_log.md index 5ca0075..3229cb4 100644 --- a/docs/devlog/20261001-issue17-home-posts-list_log.md +++ b/docs/devlog/20261001-issue17-home-posts-list_log.md @@ -47,6 +47,28 @@ Ship #17 (S1.1): the workspace shell from the design contract — nav rail (Post - Lint: `swiftlint Museion/ MuseionTests/` → 0 violations; SwiftFormat clean on changed files - Live: app launched, gate sheet passed and dismissed via AX, workspace rendered (rail/Posts/editor/mentor verified by screenshot); window-resize collapse fix built but final visual pass blocked by a fullscreen break timer — needs one manual look + +## Finish Audit (same day) + +Three fresh-context reviewers (ponytail / security / general) over `804b588`. Accepted and fixed: + +| Fix | Source | +|-----|--------| +| Scan off-main: `Task.detached { Post.scan(home:) }` in `.task(id:)` — MainActor-inherited synchronous scan froze the UI on big Homes | security MEDIUM-1 + review | +| `PostLibrary` struct → `Post.scan(home:) -> [Post]` (wrapper with one field, unused Equatable) | ponytail | +| Hidden-dir skip now real (dot-prefix guard) — the AGENTS.md claim was code-less and the test vacuous; test now writes a `post.md` into `.trash/` | review MEDIUM + security INFO-5 | +| Unterminated frontmatter returns `untitled` (was leaking `pass_state: …` as Title) | review MEDIUM | +| Quoted YAML values unquoted (`origin: "ai"` → `.ai`) | review MEDIUM | +| Leading blank line before `---` no longer defeats frontmatter detection (both parser funcs) | review LOW | +| `#`-only body → `untitled` (was empty string) | review LOW | +| Symlinked post dirs skipped (one resourceValues guard, single fetch) | security LOW-3 | +| Persisted home validated `isFileURL` (fails closed to default; hygiene) | security LOW-2 | +| Dead code out: `radiusLarge`, `editorMinWidth`, `homeKey`; `PaneHeader` trailing slot; Settings ScrollView; PostRow optional-fill dance; `availableWidth` default | ponytail | + +Discarded as speculative: read-cap on file heads (detached hop fixes the hang; #18 owns growth), UserDefaults round-trip test (shared test host). + +Tests 56/56 (4 new: quoted values, symlink, unterminated frontmatter, leading blank). Lint 0. + ## Files Changed | File | Change Summary | From efc97d061cdd815c13d9646f2a98b01ce60ce504 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Thu, 1 Oct 2026 13:50:18 +0200 Subject: [PATCH 3/3] chore: refresh GitNexus index block, fix devlog index count GitNexus analyze updated its managed AGENTS.md block (1308 symbols, 2519 relationships, 39 flows) and index artifacts. Devlog INDEX row corrected to the post-audit 56-test count. [Generated by AI] --- AGENTS.md | 37 +++++++++++++++++++------------------ docs/devlog/INDEX.md | 2 +- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 7ce42ff..0dc64c4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -129,29 +129,30 @@ Single-context: `CONTEXT.md` + `docs/adr/` at the repo root. See `docs/agents/do # GitNexus — Code Intelligence -This project is indexed by GitNexus as **museion** (965 symbols, 1676 relationships, 31 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely. +This project is indexed by GitNexus as **museion** (1308 symbols, 2519 relationships, 39 execution flows). -> Index stale? Run `node .gitnexus/run.cjs analyze` from the project root — it auto-selects an available runner. No `.gitnexus/run.cjs` yet? `npx gitnexus analyze` (npm 11 crash → `npm i -g gitnexus`; #1939). +> Index stale? Run `node .gitnexus/run.cjs analyze --index-only` from the project root — it auto-selects an available runner. No `.gitnexus/run.cjs` yet? Bootstrap with `npx`, `bunx`, or `pnpm dlx` — e.g. `bunx gitnexus@latest analyze` (npm 11 npx crash; #1939). ## Always Do -- **MUST run impact analysis before editing any symbol.** Before modifying a function, class, or method, run `impact({target: "symbolName", direction: "upstream"})` and report the blast radius (direct callers, affected processes, risk level) to the user. -- **MUST run `detect_changes()` before committing** to verify your changes only affect expected symbols and execution flows. For regression review, compare against the default branch: `detect_changes({scope: "compare", base_ref: "main"})`. -- **MUST warn the user** if impact analysis returns HIGH or CRITICAL risk before proceeding with edits. -- When exploring unfamiliar code, use `query({query: "concept"})` to find execution flows instead of grepping. It returns process-grouped results ranked by relevance. -- When you need full context on a specific symbol — callers, callees, which execution flows it participates in — use `context({name: "symbolName"})`. +- **MUST run impact before editing.** Use `impact({target: "symbolName", direction: "upstream"})` or `node .gitnexus/run.cjs impact "symbolName" --direction upstream --repo .`; report callers, processes, and risk. Never substitute grep for graph analysis. +- **MUST analyze graph changes before committing.** Use `detect_changes({scope: "all"})` (MCP) or `node .gitnexus/run.cjs detect-changes --scope all --repo .` (CLI fallback). `partial: true` or `truncated: true` is not a clean check — a zero means unseen, not unaffected; re-run it. For regression review: `detect_changes({scope: "compare", base_ref: "main"})` or `node .gitnexus/run.cjs detect-changes --scope compare --base-ref "main" --repo .`. +- MUST warn on HIGH/CRITICAL `risk` pre-edit; never use `riskSharedAxes` to waive a HIGH/CRITICAL `risk` warning. Compare File/symbol: MCP File omits axes; Graph-RAG expands File. +- **MUST treat `risk: UNKNOWN` as unresolved, not as low.** An empty caller set is not evidence the symbol is unused — it can also mean the callers are not resolvable by the index (plain-object property access, dynamic dispatch, cross-language calls). `impact` pairs `UNKNOWN` with a `riskNote` saying so. Confirm with a text search before treating the symbol as safe to change or delete; do not proceed on the strength of a zero. +- **MUST use `query({search_query: "concept"})` for concepts/flows, `context({name: "symbolName"})` for a named symbol, or `impact` for blast radius, on read-only callers, dependencies, imports, or execution flow.** Graph first; text search only for empty/`UNKNOWN`/literals. +- For security review, `explain({target: "fileOrSymbol"})` lists taint findings (source→sink flows; needs `analyze --pdg`). ## Never Do -- NEVER edit a function, class, or method without first running `impact` on it. -- NEVER ignore HIGH or CRITICAL risk warnings from impact analysis. +- NEVER edit a function, class, or method before MCP/CLI impact analysis. +- NEVER ignore HIGH or CRITICAL risk warnings from impact analysis, and never read `UNKNOWN` as an all-clear — it means the walk could not answer, which is the one verdict that requires confirming by other means. - NEVER rename symbols with find-and-replace — use `rename` which understands the call graph. -- NEVER commit changes without running `detect_changes()` to check affected scope. +- NEVER commit before MCP/CLI graph change analysis. ## Resources | Resource | Use for | -|----------|---------| +| --- | --- | | `gitnexus://repo/museion/context` | Codebase overview, check index freshness | | `gitnexus://repo/museion/clusters` | All functional areas | | `gitnexus://repo/museion/processes` | All execution flows | @@ -160,13 +161,13 @@ This project is indexed by GitNexus as **museion** (965 symbols, 1676 relationsh ## CLI | Task | Read this skill file | -|------|---------------------| -| Understand architecture / "How does X work?" | `.claude/skills/gitnexus/gitnexus-exploring/SKILL.md` | -| Blast radius / "What breaks if I change X?" | `.claude/skills/gitnexus/gitnexus-impact-analysis/SKILL.md` | -| Trace bugs / "Why is X failing?" | `.claude/skills/gitnexus/gitnexus-debugging/SKILL.md` | -| Rename / extract / split / refactor | `.claude/skills/gitnexus/gitnexus-refactoring/SKILL.md` | -| Tools, resources, schema reference | `.claude/skills/gitnexus/gitnexus-guide/SKILL.md` | -| Index, status, clean, wiki CLI commands | `.claude/skills/gitnexus/gitnexus-cli/SKILL.md` | +| --- | --- | +| Understand architecture / "How does X work?" | `.claude/skills/gitnexus-exploring/SKILL.md` | +| Blast radius / "What breaks if I change X?" | `.claude/skills/gitnexus-impact-analysis/SKILL.md` | +| Trace bugs / "Why is X failing?" | `.claude/skills/gitnexus-debugging/SKILL.md` | +| Rename / extract / split / refactor | `.claude/skills/gitnexus-refactoring/SKILL.md` | +| Tools, resources, schema reference | `.claude/skills/gitnexus-guide/SKILL.md` | +| Index, status, clean, wiki CLI commands | `.claude/skills/gitnexus-cli/SKILL.md` | diff --git a/docs/devlog/INDEX.md b/docs/devlog/INDEX.md index 854eb5e..3da3811 100644 --- a/docs/devlog/INDEX.md +++ b/docs/devlog/INDEX.md @@ -5,7 +5,7 @@ Complete history of session logs in this directory, newest first. One-line summa | Date | Type | File | Summary | |------|------|------|---------| -| 2026-10-01 | issue | [20261001-issue17-home-posts-list_log.md](20261001-issue17-home-posts-list_log.md) | #17 shipped: workspace shell, Posts mirror, Home repoint — 52 tests green | +| 2026-10-01 | issue | [20261001-issue17-home-posts-list_log.md](20261001-issue17-home-posts-list_log.md) | #17 shipped + finish-audit: workspace shell, Posts mirror, Home repoint — 56 tests green | | 2026-09-25 | issue | [20260925-issue50-profile-backup-s2-6_log.md](20260925-issue50-profile-backup-s2-6_log.md) | #50 S2.6 daily profile backup: liveness gate, curated copy, retention 7, RESTORE.md — 8 tests green | | 2026-09-16 | issue | [20260916-issue14-acp-bridge-s2-2_log.md](20260916-issue14-acp-bridge-s2-2_log.md) | #14 M0 ACP bridge: NDJSON JSON-RPC client, mentor pane, fix-card round-trip, crash restart — 37 tests green | | 2026-09-05 | issue | [20260905-issue48-provisioning-failure-alert-retry-ux_log.md](20260905-issue48-provisioning-failure-alert-retry-ux_log.md) | #48 shipped: failure card with retry/Not-Now, traversal guard, temp sweep — 30 tests green |