feat(mentor): editorial pane chrome (#156)
CI / ci (push) Canceled after 0s

Wayfinder map #153, build slice 2 of the #154 contract: the pane's
chrome joins the transcript's editorial voice (#155).

Header per .pane-head — serif-15/600 "Mentor", engine status, mono-10
session chip; ready is the semantic green dot (DesignTokens.readyGreen,
the palette's sole exception) + lowercase mono "ready", base version in
the tooltip, the drift note kept visible. The segmented Pass 1 | Pass 2
| Chat picker is dead (settled #4): PassBarView always carries and owns
the compact text-tab selector (2pt accent underline) over a PASS N ·
STATE status line, the cost line, and the actions as MonoButton —
accent solid / surface+border / accent outline, the danger voice.
Fix-cards row is the ruled plain mono link; crash, missing-engine, and
starting states render as the quiet state-cards.

Finish-audit fanout: security clean; orphaned MARK, stale doc comment,
and a phantom-border comment fixed; pass-selector remount reset and
solid-button contrast parked in the devlog (swift-wiki gotcha #28).

Suite 592/592 (xcresult count), swiftformat + swiftlint clean at the
error tier.

Closes #153
This commit is contained in:
AlexKucera committed 2026-11-04 10:37:13 +01:00
1 parent 2aa8bdabd8
commit d6c4712aaa
8 files changed
+317 -140

No files matched your search

+217 -120
View File
@@ -2,14 +2,19 @@
// MentorPaneView.swift
// Museion
//
// M0 ACP bridge (#14): the debug pane — the M0 demo surface. Post-gate main
// surface replacing the content placeholder (map decision: pane placement).
// The mentor pane (#14 map → #153/#156): the editorial chrome per the
// locked contract (ref/prototypes/wf154-mentor-pane-prototype.html) —
// serif pane head with the green ready dot and session chip, the compact
// Pass 1 / Pass 2 selector + status line in the pass bar (the segmented
// mode picker died, settled #4), a plain mono fix-cards row, and the
// crash / missing-engine / starting states in the same voice.
//
import SwiftUI
/// The mentor debug pane: transcript, freeform input, Stop while streaming,
/// restart prompt on crash. Post-gate main surface (map decision).
/// The mentor pane: the pass bar + shared transcript around it (the
/// conversation surface itself lives in SessionTranscriptView) and the
/// crash restart prompt.
struct MentorPaneView: View {
@State private var model: MentorSessionModel
/// #23 follow-up: opens the Fix Cards palette window (scene "fix-cards").
@@ -28,10 +33,6 @@ struct MentorPaneView: View {
/// #137 (S4): opens Settings — the missing-key line's way out (nil =
/// previews; PostsPaneView threads WorkspaceView's pane hop).
var onOpenSettings: (() -> Void)?
/// #24 (S3.1): the segmented surface — Pass 1 | Pass 2 | Chat. Pass
/// modes carry the pass bar; Chat is the freeform surface alone.
private enum Mode: Hashable { case pass1, pass2, chat }
@State private var mode: Mode = .pass1
/// Writing-session filter (#23 dogfood): session/tool/debug rows render
/// only when on — off by default, persisted. The model keeps every row
/// either way (debug history intact; the toggle flips instantly).
@@ -77,33 +78,40 @@ struct MentorPaneView: View {
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else {
ProgressView("Starting the mentor engine…")
.frame(maxWidth: .infinity, maxHeight: .infinity)
// #156: the interim in the editorial voice — mono, quiet.
VStack(spacing: 8) {
ProgressView().controlSize(.small)
Text("Starting the mentor engine…")
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.muted)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
case .ready:
modePicker
if let kind = passKind {
PassBarView(kind: kind, posts: posts, home: home, model: model, onOpenSettings: onOpenSettings)
Divider()
}
// #156 (settled #4): the pass bar always carries — its Pass 1 /
// Pass 2 selector replaced the mode picker; the transcript +
// composer below are the conversation surface, chat is not a
// mode.
PassBarView(posts: posts, home: home, model: model, onOpenSettings: onOpenSettings)
Divider()
if let posts, !posts.openPieceCards.isEmpty {
// #23 follow-up: the detail moved to the palette window —
// this row just names it and opens it.
// #23 follow-up + #156 ruling: a plain mono row — a link,
// not content (no card, no hairline of its own; the
// Divider above already separates it from the bar).
Button {
openWindow(id: "fix-cards")
} label: {
Label(
"Fix Cards · \(posts.openPieceCards.count)",
systemImage: "rectangle.and.pencil.and.ellipsis",
)
HStack(spacing: 6) {
Image(systemName: "rectangle.and.pencil.and.ellipsis")
Text("Fix Cards · \(posts.openPieceCards.count)")
}
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.muted)
}
.buttonStyle(.borderless)
.buttonStyle(.plain)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, 12)
.padding(.vertical, 6)
Divider()
.padding(.horizontal, 14)
.padding(.top, 10)
}
// #28: the transcript rendering is shared — the Sessions pane
// reads the same surface in the writing voice. #30: the
@@ -144,11 +152,11 @@ struct MentorPaneView: View {
// MARK: Header
private var header: some View {
HStack(spacing: 8) {
Image(systemName: "bubble.left.and.text.bubble.right")
.foregroundStyle(.secondary)
Text("Mentor Session")
.font(.headline)
HStack(spacing: 10) {
// #156 (contract `.pane-head`): serif 15/600 title + engine
// status + session chip — nothing else (settled #5).
Text("Mentor")
.font(.system(size: 15, weight: .semibold, design: DesignTokens.serif))
.fixedSize()
MentorEngineStatus(gate: gate, model: model)
Spacer()
@@ -159,39 +167,18 @@ struct MentorPaneView: View {
// layout priority.
if case .ready = model.phase, let sessionId = model.activeEntry?.sessionId, sessionId != MentorSessionModel.passTranscriptKey {
Text("session \(sessionId.prefix(8))")
.font(.caption2)
.foregroundStyle(.tertiary)
.font(.system(size: 10, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.muted)
.opacity(0.75)
.textSelection(.enabled)
}
}
.padding(.horizontal, 12)
.padding(.horizontal, 14)
// #90: pane heads align at the export's 52px — same height as the
// Posts header and the editor toolbar, so the three hairlines read
// as one line.
.frame(minHeight: 52)
}
// MARK: Pass surface (#24, S3.1)
private var passKind: PassKind? {
switch mode {
case .pass1: .pass1
case .pass2: .pass2
case .chat: nil
}
}
private var modePicker: some View {
Picker("Mentor surface", selection: $mode) {
Text("Pass 1").tag(Mode.pass1)
Text("Pass 2").tag(Mode.pass2)
Text("Chat").tag(Mode.chat)
}
.pickerStyle(.segmented)
.padding(.horizontal, 12)
.padding(.top, 10)
.padding(.bottom, 8)
}
}
// MARK: Crash card (file-scope extension — type_body_length posture; the
@@ -204,26 +191,28 @@ private extension MentorPaneView {
// in-pane Restart prompt; the transcript replays from the engine, ADR-0007)
private func crashCard(lastPrompt: String?) -> some View {
VStack(spacing: 14) {
// #156 (contract `.state-card`): accent tri (danger = terracotta —
// no second hue), serif 14/600 head, sans-12 muted body, Restart
// in the solid-accent button voice.
VStack(spacing: 10) {
Image(systemName: "exclamationmark.triangle.fill")
.font(.system(size: 30))
.foregroundStyle(.orange)
.font(.system(size: 24))
.foregroundStyle(DesignTokens.accent)
Text("The mentor engine stopped")
.font(.title3)
.font(.system(size: 14, weight: .semibold, design: DesignTokens.serif))
Text("Nothing is lost — the transcript stays, and the engine can be restarted.")
.font(.callout)
.foregroundStyle(.secondary)
.font(.system(size: 12))
.foregroundStyle(DesignTokens.muted)
.multilineTextAlignment(.center)
if let lastPrompt, !lastPrompt.isEmpty {
Text("Last prompt: \(lastPrompt)")
.font(.caption)
.foregroundStyle(.tertiary)
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.muted)
.lineLimit(2)
}
Button("Restart") {
MonoButton(title: "Restart") {
Task { await model.restart() }
}
.buttonStyle(.borderedProminent)
if !model.stderrTail.isEmpty {
DisclosureGroup("Technical details") {
Text(model.stderrTail.joined(separator: "\n"))
@@ -241,11 +230,70 @@ private extension MentorPaneView {
}
}
/// #24 (S3.1): the pass bar — what the pass critiques + the honest cost
/// estimate (PassContext), the open piece's Pass State, and the Run/Cancel
/// action. Additive chrome above the mentor pane's shared transcript.
/// #156 (contract `.btn`): the pane's action button — mono 11, 28pt,
/// radius 6 — in the contract's three looks: accent solid (primary),
/// surface + border (secondary), accent outline (the danger/Stop voice).
/// #155 sendButton precedent: a plain button with the fills drawn by hand
/// (borderedProminent carries the system tint, not the palette).
private struct MonoButton: View {
enum Style { case solid, secondary, outline }
let title: String
var style: Style = .solid
var disabled = false
let action: () -> Void
var body: some View {
Button(action: action) {
Text(title)
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(ink)
.padding(.horizontal, 13)
.frame(minHeight: 28)
.background(RoundedRectangle(cornerRadius: 6).fill(fill))
.overlay(
RoundedRectangle(cornerRadius: 6)
.strokeBorder(stroke, lineWidth: 1),
)
}
.buttonStyle(.plain)
.disabled(disabled)
.opacity(disabled ? 0.45 : 1)
}
private var ink: Color {
switch style {
case .solid: DesignTokens.surface
case .secondary: DesignTokens.foreground
case .outline: DesignTokens.accent
}
}
private var fill: Color {
switch style {
case .solid: DesignTokens.accent
case .secondary: DesignTokens.surface
case .outline: .clear
}
}
private var stroke: Color {
switch style {
case .solid: .clear
case .secondary: DesignTokens.border
case .outline: DesignTokens.accent
}
}
}
/// #24 (S3.1) → #156: the pass bar — the compact Pass 1 / Pass 2 selector
/// + `PASS N · STATE` status line (settled #4: the selector replaced the
/// segmented mode picker), what the pass critiques + the honest cost
/// estimate (PassContext), and the Run / Blind Read / Cancel actions.
/// Additive chrome above the mentor pane's shared transcript.
private struct PassBarView: View {
let kind: PassKind
/// The selected pass — the bar's own state (nothing outside reads it).
@State private var kind: PassKind = .pass1
let posts: PostsModel?
let home: URL?
let model: MentorSessionModel
@@ -253,35 +301,83 @@ private struct PassBarView: View {
let onOpenSettings: (() -> Void)?
var body: some View {
VStack(alignment: .leading, spacing: 8) {
VStack(alignment: .leading, spacing: 0) {
selector
.padding(.bottom, 9)
statusLine
.padding(.bottom, 5)
Text(description)
.font(.callout)
.font(.system(size: 11))
.foregroundStyle(DesignTokens.muted)
.frame(maxWidth: .infinity, alignment: .leading)
HStack {
Text(stateLabel)
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.muted)
Spacer()
actions
}
.fixedSize(horizontal: false, vertical: true)
.padding(.bottom, 10)
actions
// #137: the pass profile's provider has no key — name it and
// offer the way out. A readable-but-keyed profile shows nothing.
if let label = missingKeyLabel {
HStack(spacing: 4) {
Text("Missing \(label) key —")
Button("Open Settings") {
onOpenSettings?()
}
.buttonStyle(.borderless)
.foregroundStyle(DesignTokens.accent)
}
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.muted)
missingKeyLine(label: label)
.padding(.top, 8)
}
}
.padding(.horizontal, 12)
.padding(.bottom, 10)
.padding(.horizontal, 14)
.padding(.vertical, 12)
}
/// Contract `.selector`: text tabs — mono 10, uppercase, tracked; the
/// active tab carries fg ink + a 2pt accent underline.
private var selector: some View {
HStack(spacing: 14) {
passTab(.pass1)
passTab(.pass2)
}
}
private func passTab(_ pass: PassKind) -> some View {
Button {
kind = pass
} label: {
Text(pass.rawValue)
.font(.system(size: 10, design: DesignTokens.mono))
.tracking(0.8) // CSS .08em @ 10px
.textCase(.uppercase)
.foregroundStyle(kind == pass ? DesignTokens.foreground : DesignTokens.muted)
.padding(.top, 3)
.padding(.bottom, 5)
.overlay(alignment: .bottom) {
if kind == pass {
Rectangle()
.fill(DesignTokens.accent)
.frame(height: 2)
}
}
}
.buttonStyle(.plain)
.accessibilityLabel(pass.rawValue)
.accessibilityAddTraits(kind == pass ? [.isSelected] : [])
}
/// Contract `.status-line`: `PASS N · STATE` — the open piece's Pass
/// State in the library's post-meta voice.
private var statusLine: some View {
Text("\(kind.rawValue) · \(stateLabel)")
.font(.system(size: 10, design: DesignTokens.mono))
.tracking(0.8)
.textCase(.uppercase)
.foregroundStyle(DesignTokens.muted)
}
/// #137: the missing-key ask — mono 11, the Open Settings way out.
private func missingKeyLine(label: String) -> some View {
HStack(spacing: 4) {
Text("Missing \(label) key —")
Button("Open Settings") {
onOpenSettings?()
}
.buttonStyle(.borderless)
.foregroundStyle(DesignTokens.accent)
}
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.muted)
}
/// #137: nil unless the pass profile's provider is readable AND unkeyed
@@ -311,40 +407,50 @@ private struct PassBarView: View {
return posts.posts.first(where: { $0.id == posts.selectedPostID })?.passState.rawValue ?? "—"
}
/// Cancel while a pass or Blind Read runs; Run otherwise — disabled
/// with no open piece, while the engine can't take the turn, or (#137)
/// while the pass profile's provider has no key (the help names it).
/// Cancel while a pass or Blind Read runs (the accent-outline danger
/// voice); Run + Blind Read otherwise — Run disabled with no open
/// piece, while the engine can't take the turn, or (#137) while the
/// pass profile's provider has no key (the help names it).
/// #122: the Blind Read trigger sits beside Run — advisory-only.
@ViewBuilder
private var actions: some View {
if posts?.runningPass != nil || posts?.runningBlindRead == true {
Button("Cancel") {
posts?.cancelPass(mentor: model)
}
.buttonStyle(.bordered)
} else {
blindReadButton
if let label = missingKeyLabel {
runPassButton
.disabled(true)
.help("\(kind.rawValue) needs a \(label) API key — add it in Settings → Provider Keys.")
HStack(spacing: 7) {
if posts?.runningPass != nil || posts?.runningBlindRead == true {
MonoButton(title: "Cancel", style: .outline) {
posts?.cancelPass(mentor: model)
}
} else {
runPassButton
.disabled(posts?.session?.postID == nil || !model.phase.isReady || model.isStreaming)
blindReadButton
if let label = missingKeyLabel {
MonoButton(title: "Run \(kind.rawValue)", disabled: true, action: runPass)
.help("\(kind.rawValue) needs a \(label) API key — add it in Settings → Provider Keys.")
} else {
MonoButton(
title: "Run \(kind.rawValue)",
disabled: posts?.session?.postID == nil || !model.phase.isReady || model.isStreaming,
action: runPass,
)
}
}
}
}
private func runPass() {
guard let posts, let home else { return }
Task { await posts.runPass(kind, home: home, mentor: model) }
}
/// #122: the Blind Read — one purposeful click judges the current
/// document against the Pass-start snapshot, blind. Disabled with the
/// blocking reason in help (no snapshot yet is the fresh-piece norm).
private var blindReadButton: some View {
Button("Blind Read") {
MonoButton(
title: "Blind Read",
style: .secondary,
disabled: blindReadBlocked != nil,
) {
guard let posts, let home else { return }
Task { await posts.blindRead(home: home, mentor: model) }
}
.buttonStyle(.bordered)
.disabled(blindReadBlocked != nil)
.help(
blindReadBlocked
?? "Judge the current document against the Pass-start snapshot — advisory only, nothing is recorded.",
@@ -358,15 +464,6 @@ private struct PassBarView: View {
guard model.phase.isReady, !model.isStreaming else { return "The mentor engine can't take the turn right now." }
return nil
}
/// The Run button core — shared by the ready and missing-key branches.
private var runPassButton: some View {
Button("Run \(kind.rawValue)") {
guard let posts, let home else { return }
Task { await posts.runPass(kind, home: home, mentor: model) }
}
.buttonStyle(.borderedProminent)
}
}
#Preview {