refactor(workspace): finish-audit fixes — off-main scan, parser edges, dead code out
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]
This commit is contained in:
1 parent
804b5889f6
commit
765d32d4d4
10 files changed
+158
-101
No files matched your search
+3
-3
@@ -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/<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.
|
||||
- `PostLibrary.swift` — `Post` (nonisolated: id/title/passState/origin) + `Post.scan(home:) -> [Post]`: reads `posts/<id>/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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
+29
-34
@@ -8,12 +8,10 @@
|
||||
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.
|
||||
/// 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 `<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;
|
||||
/// Reads every `posts/<id>/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[..<colon].trimmingCharacters(in: .whitespaces)
|
||||
let value = trimmed[trimmed.index(after: colon)...].trimmingCharacters(in: .whitespaces)
|
||||
let value = trimmed[trimmed.index(after: colon)...]
|
||||
.trimmingCharacters(in: .whitespaces)
|
||||
.trimmingCharacters(in: CharacterSet(charactersIn: "\"'"))
|
||||
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).
|
||||
/// `#` heading markers stripped; `untitled` when nothing readable remains.
|
||||
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() == "---" }) {
|
||||
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"
|
||||
}
|
||||
|
||||
+15
-15
@@ -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),
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Trailing: View>: 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<Trailing: View>: View {
|
||||
Text(title)
|
||||
.font(.system(size: 15, weight: .semibold, design: DesignTokens.serif))
|
||||
Spacer()
|
||||
trailing()
|
||||
}
|
||||
.padding(.horizontal, 14)
|
||||
.frame(minHeight: 52)
|
||||
|
||||
Reference in new issue
Block a user