feat(workspace): add M1 Home & Posts list — nav rail, posts mirror, Home repoint (fixes #17)

The post-gate main surface is the workspace shell from the design
contract: nav rail (Posts/Sessions/Learnings/Settings), Posts pane
mirroring <home>/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]
This commit is contained in:
AlexKucera committed 2026-10-01 13:14:55 +02:00
1 parent b3daac9486
commit 804b5889f6
15 files changed
+762 -5

No files matched your search

+10
View File
@@ -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/<id>/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.
+4 -4
View File
@@ -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")
+34
View File
@@ -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
}
+2 -1
View File
@@ -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
+20
View File
@@ -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
+114
View File
@@ -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: `<home>/posts/<id>/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 `<home>/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/<id>/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[..<colon].trimmingCharacters(in: .whitespaces)
let value = trimmed[trimmed.index(after: colon)...].trimmingCharacters(in: .whitespaces)
map[key] = value
}
return map
}
/// The Post's Title: first non-empty line after any frontmatter block,
/// `#` heading markers stripped. A body with no text at all reads as
/// `untitled` (the blank-draft id).
static func title(of text: String) -> 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)
}
}
+168
View File
@@ -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)")
}
}
+53
View File
@@ -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
}
}
}
+168
View File
@@ -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<Trailing: View>: 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)
}
}