feat(ui): design-council polish overhaul
CI / ci (push) Canceled after 0s
CI / ci (pull_request) Canceled after 0s

Eight arbitrated rounds over the workspace surface: piece-scoped Mentor
hosting, conversation-voice system messages, glyph-measured roster
truncation, bounded learnings/archive columns, symmetric trends grid,
top-aligned settings forms, serif editor titles, outline rail rhythm,
launch auto-focus root fix. New seams pinned by SessionScopeTests +
WordBoundaryTruncationTests; full suite green.
This commit is contained in:
AlexKucera committed 2026-11-07 20:41:34 +01:00
1 parent b2db859887
commit 3a7d495b4b
21 files changed
+2287 -516

No files matched your search

+206 -69
View File
@@ -11,6 +11,7 @@
// 2px accent edge bar on the selected row.
//
import AppKit
import SwiftUI
/// The Posts destination: the workspace's full four-column layout
@@ -201,6 +202,14 @@ struct PostsLibraryColumn: View {
/// non-archived pieces. nil = not searching (sections render).
@State private var query = ""
@State private var matches: [Post]?
/// r5 (argon#44, mercury#52, sol#37): focus state for the field's
/// accent ring. r8 (argon#6, mercury#12 — root cause found): the r6/r7
/// onAppear-unfocus could never work — the launch focus is AppKit
/// assigning the window's INITIAL first responder to its first text
/// input (this field), at window-become-key, AFTER onAppear. FocusState
/// merely mirrors that back as true. LaunchFocusReset (below) resigns
/// it at the first become-key; from then on only the user drives this.
@FocusState private var searchFocused: Bool
private var trimmedQuery: String {
query.trimmingCharacters(in: .whitespacesAndNewlines)
@@ -261,9 +270,18 @@ struct PostsLibraryColumn: View {
}
}
} label: {
HStack(alignment: .firstTextBaseline, spacing: 8) {
// r7 (mercury#18, argon#12 — TWO-AXIS ladder,
// the r6 four-step collapse undone): the
// head ROW leads at the column's PRIMARY
// inset (x14) — chevron glyph in a 14pt slot
// — and every nested CONTENT shares the one
// indent step (x28): head text, group
// labels, and the rows' inner text. No third
// or fourth x-axis exists in the column.
HStack(alignment: .firstTextBaseline, spacing: 0) {
Image(systemName: "chevron.down")
.font(.system(size: 9, weight: .semibold))
.font(.system(size: 10, weight: .semibold))
.frame(width: 14, alignment: .leading)
.rotationEffect(.degrees(collapsed.contains(project) ? -90 : 0))
.foregroundStyle(DesignTokens.muted)
Text(project)
@@ -294,6 +312,9 @@ struct PostsLibraryColumn: View {
}
}
.frame(width: DesignTokens.libraryWidth)
// r8 (argon#6, mercury#12): the focus-rider replaces the r6/r7
// onAppear-unfocus — see LaunchFocusReset below for the mechanism.
.background(LaunchFocusReset())
.sheet(item: $renamingPost) { post in
RenamePostSheet(post: post) { title in
model.rename(post, to: title, home: home)
@@ -320,7 +341,7 @@ struct PostsLibraryColumn: View {
}
try? await Task.sleep(for: .milliseconds(250))
guard !Task.isCancelled else { return }
let found = await Self.search(
let found = await librarySearch(
candidates: model.posts.filter { !$0.isArchived },
matching: trimmedQuery,
home: home,
@@ -330,28 +351,6 @@ struct PostsLibraryColumn: View {
}
}
/// #144: the title+body scan — a thin mount for the pure
/// `LibrarySearch` seam (title matches first, stable partition, both
/// halves keep the scan's Finder order; body via readBody — frontmatter
/// never searched), pinned by MuseionTests/LibrarySearchTests.swift.
/// The reader's per-piece cancellation check stops a superseded sweep's
/// body reads between files; the in-memory title walk itself completes
/// cheaply and the caller's guard discards its result.
///
/// ponytail: full-body re-read per sweep (folder(of:) re-walked per
/// piece — same unbounded-read ceiling as Post.scan, LearningsIndex
/// posture); a PostScanCache-style body memo if it ever measures hot.
private nonisolated static func search(
candidates: [Post],
matching trimmed: String,
home: URL,
) async -> [Post] {
LibrarySearch.results(for: trimmed, in: candidates) { post in
guard !Task.isCancelled else { return nil }
return PostStore.readBody(id: post.id, home: home)
}
}
/// One piece row + its context menu — sections and search results
/// render the same row (#144: results carry the full menu too).
private func postRow(_ post: Post) -> some View {
@@ -378,18 +377,29 @@ struct PostsLibraryColumn: View {
}
/// Pass-State groups inside one project (`.vB .group-label`: smaller,
/// softer, indented under the section head).
/// softer, indented under the section head). r2: the label binds to
/// its FIRST row (bottom 1 + stack 4) — it floated closer to the
/// preceding row than to its own children.
private func passStateGroups(_ pieces: [Post]) -> some View {
ForEach(Post.PassState.allCases, id: \.self) { state in
let grouped = pieces.filter { $0.passState == state }
if !grouped.isEmpty {
Text(state.rawValue.uppercased())
.font(.system(size: 10, design: DesignTokens.mono))
// mercury#53 (r5): display-only normalization — the stored
// rawValues keep their hyphen ("Pass-1 Done"); the rendered
// label uses the space form so it matches the Pass 1 / Pass 2
// vocabulary everywhere else.
Text(state.rawValue.uppercased().replacingOccurrences(of: "-", with: " "))
.font(.system(size: 11, weight: .medium, design: DesignTokens.mono))
.kerning(0.6)
.foregroundStyle(DesignTokens.muted.opacity(0.8))
.padding(.horizontal, 22)
.padding(.top, 8)
.padding(.bottom, 5)
// r6 (sol#6/21 — contrast final): group labels are
// informational meta — FULL muted ink, no wash.
.foregroundStyle(DesignTokens.muted)
// r6 ladder: full muted ink. r7 two-axis: x28 — the ONE
// indent step, shared with the head text and the row
// cards' inner content.
.padding(.leading, 28)
.padding(.top, 10)
.padding(.bottom, 1)
ForEach(grouped) { post in
postRow(post)
}
@@ -397,15 +407,34 @@ struct PostsLibraryColumn: View {
}
}
/// #144: the field row + bottom hairline (the pane-head voice).
/// #144 + mercury#54 (r4): a real field surface — surface fill + hairline
/// border on the column's chrome, taller than a text row; the placeholder
/// renders in the palette's muted ink via the under-Text trick (stronger
/// than the system's faint default — it reads as an input, not sidebar
/// text). r5 (argon#44, mercury#52, sol#37): the insertion caret tints
/// terracotta (.tint on the field), and the small magnifier glyph sits at
/// the field's leading edge (icon→text spacing rides the HStack's 6pt).
/// r8 (argon#6, mercury#12): focus draws a QUIET 1pt ring — accent at 0.6,
/// present but never the strongest saturation on screen.
private var searchField: some View {
HStack(spacing: 6) {
Image(systemName: "magnifyingglass")
Image(systemName: "magnifyinglass")
.font(.system(size: 11))
.foregroundStyle(DesignTokens.muted)
TextField("Search posts", text: $query)
.textFieldStyle(.plain)
.font(.system(size: 12))
ZStack(alignment: .leading) {
if query.isEmpty {
Text("Search posts")
.font(.system(size: 12))
.foregroundStyle(DesignTokens.muted)
.allowsHitTesting(false)
}
TextField("", text: $query)
.textFieldStyle(.plain)
.font(.system(size: 12))
.focused($searchFocused)
.tint(DesignTokens.accent)
.accessibilityLabel("Search posts")
}
if isSearching {
Button {
query = ""
@@ -417,11 +446,27 @@ struct PostsLibraryColumn: View {
.accessibilityLabel("Clear search")
}
}
.padding(.horizontal, 12)
.padding(.vertical, 7)
.overlay(alignment: .bottom) {
Rectangle().fill(DesignTokens.border).frame(height: 1)
}
.padding(.horizontal, 10)
.padding(.vertical, 8)
.background(
RoundedRectangle(cornerRadius: 8)
.fill(DesignTokens.surface)
.overlay(
// r8 (argon#6, mercury#12): quiet focus — accent at 0.6,
// one step down from full strength.
RoundedRectangle(cornerRadius: 8)
.strokeBorder(
searchFocused ? DesignTokens.accent.opacity(0.6) : DesignTokens.border,
lineWidth: 1,
),
),
)
// r7 (mercury#18, argon#12 — two-axis ladder): the box spans the
// FULL padded column width at the PRIMARY inset — leading 14
// (aligned with the 'Posts' header text) to trailing 14 — the
// same edges the row cards lead at.
.padding(.horizontal, 14)
.padding(.vertical, 8)
}
/// Flat results, title matches first (stable partition — both halves
@@ -430,12 +475,15 @@ struct PostsLibraryColumn: View {
ScrollView {
LazyVStack(alignment: .leading, spacing: 4) {
Text("\(found.count) \(found.count == 1 ? "match" : "matches")")
.font(.system(size: 10, design: DesignTokens.mono))
.font(.system(size: 11, design: DesignTokens.mono))
.kerning(0.6)
.foregroundStyle(DesignTokens.muted.opacity(0.8))
.padding(.horizontal, 14)
// r6: full muted ink; r7 two-axis: x28 — the indent
// step, heading the flat result list exactly where
// group labels head their sections.
.foregroundStyle(DesignTokens.muted)
.padding(.leading, 28)
.padding(.top, 12)
.padding(.bottom, 5)
.padding(.bottom, 1)
ForEach(found) { post in
postRow(post)
}
@@ -471,6 +519,80 @@ struct PostsLibraryColumn: View {
}
}
/// #144: the title+body scan — a thin mount for the pure
/// `LibrarySearch` seam (title matches first, stable partition, both
/// halves keep the scan's Finder order; body via readBody — frontmatter
/// never searched), pinned by MuseionTests/LibrarySearchTests.swift.
/// The reader's per-piece cancellation check stops a superseded sweep's
/// body reads between files; the in-memory title walk itself completes
/// cheaply and the caller's guard discards its result. File scope since
/// r6 (PostsLibraryColumn hit its type-body ceiling).
///
/// ponytail: full-body re-read per sweep (folder(of:) re-walked per
/// piece — same unbounded-read ceiling as Post.scan, LearningsIndex
/// posture); a PostScanCache-style body memo if it ever measures hot.
private nonisolated func librarySearch(
candidates: [Post],
matching trimmed: String,
home: URL,
) async -> [Post] {
LibrarySearch.results(for: trimmed, in: candidates) { post in
guard !Task.isCancelled else { return nil }
return PostStore.readBody(id: post.id, home: home)
}
}
/// r8 (argon#6, mercury#12 — the launch auto-focus ROOT CAUSE, killed at
/// the source): the search field is the window's first — and at launch,
/// only — text input, and AppKit assigns the window's initial first
/// responder to it when the window becomes key. That happens AFTER
/// onAppear, so the r6/r7 `searchFocused = false` writes were always
/// overridden (FocusState mirrors the assignment back as true: terracotta
/// ring + caret, the strongest element on screen). This invisible rider
/// rides the library column and, at the window's FIRST become-key,
/// resigns focus back to the window itself (`makeFirstResponder(nil)` —
/// the neutral state; nothing gains focus instead). ONCE per process: a
/// pane-switch remount must never steal a focus the user set on return.
/// The second, next-runloop resign covers an assignment that lands after
/// the notification (the PostEditorView layout-race precedent).
private struct LaunchFocusReset: NSViewRepresentable {
/// Process-wide once-flag — launch is a once-per-process event.
private static var hasRun = false
final class RiderView: NSView {
private var keyObserver: NSObjectProtocol?
override func viewDidMoveToWindow() {
if let keyObserver {
NotificationCenter.default.removeObserver(keyObserver)
}
keyObserver = nil
guard let window else { return }
keyObserver = NotificationCenter.default.addObserver(
forName: NSWindow.didBecomeKeyNotification,
object: window,
queue: .main,
) { _ in
MainActor.assumeIsolated {
// The observer is scoped to `window` (object:), so the
// notification carries nothing we don't already hold —
// reading `note` here would cross a Sendable boundary.
guard !LaunchFocusReset.hasRun else { return }
LaunchFocusReset.hasRun = true
window.makeFirstResponder(nil)
DispatchQueue.main.async { window.makeFirstResponder(nil) }
}
}
}
}
func makeNSView(context _: Context) -> RiderView {
RiderView()
}
func updateNSView(_: RiderView, context _: Context) {}
}
/// #108: Move to Project ask — radio list of the non-archived projects,
/// default = the piece's current project. Matches RenamePostSheet's shape.
struct MoveToProjectSheet: View {
@@ -559,7 +681,8 @@ struct RenamePostSheet: View {
}
}
/// One post row per the export: title, Pass State + Origin in mono 11.
/// One post row per the export: title + origin-only mono-11 meta (the Pass
/// State rides the uppercase group label above; it stays in the a11y label).
/// #108 (variant B): 2px accent edge bar on the leading side when selected
/// (`.vB .post-row[aria-current] { border-left-color: var(--accent) }`,
/// radius 0 8 8 0), and a muted ✳ suffix on outline pieces. Internal: the
@@ -573,17 +696,18 @@ struct LibraryPostRow: View {
var body: some View {
// `.vB .post-row { border-left: 2px solid transparent;
// border-radius: 0 8px 8px 0 }` — every row: leading corners square
// (the 2px strip below), trailing rounded 8. Only the strip's COLOR
// changes on selection.
// (the 2px strip below), trailing rounded 8. Only the strip's
// VISIBILITY changes on selection.
let shape = UnevenRoundedRectangle(cornerRadii: .init(bottomTrailing: 8, topTrailing: 8))
return Button(action: select) {
HStack(spacing: 0) {
// `.vB .post-row { border-left: 2px solid transparent }` —
// the leading strip is always 2px wide so hover/selection
// never shifts the title.
Rectangle()
.fill(selected ? DesignTokens.accent : .clear)
.frame(width: 2)
// The leading strip is always 2px wide so hover/selection
// never shifts the title. r6 (mercury#49/52, argon#13):
// the shared SelectedRowStrip capsule — accent, radius-1
// ends, vertically inset 6pt (was 3) so it sits INSIDE
// the card, never pasted on its square leading edge.
SelectedRowStrip()
.opacity(selected ? 1 : 0)
VStack(alignment: .leading, spacing: 5) {
HStack(alignment: .firstTextBaseline, spacing: 0) {
Text(post.title)
@@ -592,19 +716,24 @@ struct LibraryPostRow: View {
.foregroundStyle(DesignTokens.muted)
}
}
.font(.callout.weight(.semibold))
// ui-polish r8: serif-13 per the row contract — `.callout`
// was the system sans design (the r6/r7 councils pixel-
// verified sans glyphs on the Archive rows).
.font(.system(size: 13, weight: .semibold, design: DesignTokens.serif))
.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)
// Origin only — the Pass State already rides the uppercase
// group label above (it stays in the accessibility label).
// r7: the status micro-label sits INSIDE the row's content
// padding — same x as the title, never flush with the edge.
Text(post.origin.rawValue)
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.muted)
.frame(maxWidth: .infinity, alignment: .leading)
}
.padding(10)
.padding(.horizontal, 12)
.padding(.vertical, 10)
}
.clipShape(shape)
}
@@ -612,14 +741,22 @@ struct LibraryPostRow: View {
.foregroundStyle(DesignTokens.foreground)
.background {
if selected || hover {
// r8 (mercury#11): the selected row DROPS its gray outline —
// fill + accent capsule read as ONE shape; stacking fill +
// outline + capsule competed. Hover keeps its borderless
// 0.06 wash exactly as before.
shape
.fill(selected ? DesignTokens.surface : DesignTokens.foreground.opacity(0.06))
.overlay(
shape.strokeBorder(selected ? DesignTokens.border : .clear),
)
.fill(selected ? DesignTokens.foreground.opacity(0.08) : DesignTokens.foreground.opacity(0.06))
}
}
.padding(.horizontal, 8)
// r7 (mercury#18, argon#12 — two-axis ladder): the row CARD
// leads at the PRIMARY inset (x14, the 'Posts' header text's
// edge); its INNER content (title + status micro-label, strip
// 2 + padding 12) lands at x28 — the ONE indent step, shared
// with the head text and the group labels. No other x-axis
// exists in the column. Vertical padding stays the content
// VStack's constant 10 whether or not the row shows its strip.
.padding(.horizontal, 14)
.onHover { hover = $0 }
// help sits on the row — the ✳ span isn't individually hoverable in
// SwiftUI (prototype: `title="outline"` on the star).