CI / ci (push) Canceled after 0s
A freeform Session births a Post. "New Post" in the Sessions pane opens an ask-before sheet prefilled with the session's last mentor reply (editable, G9); ONE confirm materializes the piece under projects/posts/ stamped origin: ai - immutable frontmatter, never stats-eligible - and opens it in Posts; a failed write keeps the sheet up with the reason inline and the draft intact. writeNew gains an origin parameter (additive default .writer, every existing caller compiles). "New Brainstorm" is a session started with an opener prompt - no new machinery (beginBrainstormSession over the normal new+prompt rails). The freeform composer (input, liveness, Stop) moved from MentorPaneView into the shared SessionTranscriptView: one conversation surface, two panes - the Sessions pane stops being a read-only transcript. Drill offers (S2.8) wire as one pass-persona section (v1.4): the seeded micro-drill doctrine owns the motivation moment, the two-minute bound, the single shelf, and the vanish - session flavor, no machinery beyond S2.3. Resume now speaks the real adapter wire. Live-probed against the engine: 0.21.5 answers session/load with the id at _meta.hermes.sessionProvenance.acpSessionId and NO top-level sessionId - resumeSession accepts both shapes; every prior real-engine resume misread as "engine does not know this session". The fake ACP server answers load in the real shape (a loadReplayLegacy knob pins the older contract), so the whole resume suite guards the live wire. New pins: draft-candidate extraction (last mentor row wins; thought/ card/research/raw lanes and refusal/connection rows never prefill), ai-stamp write + immutability through overwrite, brainstorm roster + labeled opener, legacy-shape resume. Finish-audit (three reviewers, parallel) converged on the confirm() dismissal that destroyed the edited draft on a failed write - fixed with sheet-local error state (stale-refusal re-show dies with the presentation) - and surfaced the missing brainstorm and legacy-shape pins; the resume fix was flip-verified (removing the provenance fallback fails the provenance pins). Full suite green (379 tests). Closes #30
273 lines
8.5 KiB
Swift
273 lines
8.5 KiB
Swift
//
|
|
// 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).
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
/// The mentor debug pane: transcript, freeform input, Stop while streaming,
|
|
/// restart prompt on crash. Post-gate main surface (map decision).
|
|
struct MentorPaneView: View {
|
|
@State private var model: MentorSessionModel
|
|
/// #23 follow-up: opens the Fix Cards palette window (scene "fix-cards").
|
|
@Environment(\.openWindow) private var openWindow
|
|
/// Set post-gate by ContentView: the probe's winning binary (no re-probe).
|
|
var binaryPath: String?
|
|
/// #24 (S3.1): app-scoped Posts state for the pass bar (nil = no pass
|
|
/// surface, previews).
|
|
var posts: PostsModel?
|
|
/// #24 (S3.1): the Home passes run against.
|
|
var home: URL?
|
|
/// #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).
|
|
@AppStorage("mentorDebugRows") private var debugRows = false
|
|
|
|
init(model: MentorSessionModel, binaryPath: String?, posts: PostsModel? = nil, home: URL? = nil) {
|
|
_model = State(initialValue: model)
|
|
self.binaryPath = binaryPath
|
|
self.posts = posts
|
|
self.home = home
|
|
}
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
header
|
|
Divider()
|
|
switch model.phase {
|
|
case .idle, .starting:
|
|
ProgressView("Starting the mentor engine…")
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
case .ready:
|
|
modePicker
|
|
if let kind = passKind {
|
|
PassBarView(kind: kind, posts: posts, home: home, model: model)
|
|
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.
|
|
Button {
|
|
openWindow(id: "fix-cards")
|
|
} label: {
|
|
Label(
|
|
"Fix Cards · \(posts.openPieceCards.count)",
|
|
systemImage: "rectangle.and.pencil.and.ellipsis",
|
|
)
|
|
.font(.system(size: 11, design: DesignTokens.mono))
|
|
.foregroundStyle(DesignTokens.muted)
|
|
}
|
|
.buttonStyle(.borderless)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.padding(.horizontal, 12)
|
|
.padding(.vertical, 6)
|
|
Divider()
|
|
}
|
|
// #28: the transcript rendering is shared — the Sessions pane
|
|
// reads the same surface in the writing voice. #30: the
|
|
// freeform input + liveness ride the shared surface too.
|
|
SessionTranscriptView(model: model, showsDebugRows: debugRows, home: home)
|
|
case let .crashed(lastPrompt):
|
|
crashCard(lastPrompt: lastPrompt)
|
|
}
|
|
}
|
|
// #17: the pane lives in the workspace's fixed 356pt mentor column —
|
|
// no root min frame (it was the full-window M0 surface).
|
|
.task {
|
|
// #28 review: an honest if-let — the ?? self-assignment was a no-op.
|
|
if let binaryPath {
|
|
model.binaryPath = binaryPath
|
|
}
|
|
// Hosted unit tests run this app as their runner — never spawn a
|
|
// real engine child there (it outlives the test session and kills
|
|
// the runner).
|
|
guard ProcessInfo.processInfo.environment["XCTestConfigurationFilePath"] == nil else { return }
|
|
await model.openSession()
|
|
}
|
|
}
|
|
|
|
// 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)
|
|
if let version = model.engineVersion {
|
|
Text(version)
|
|
.font(.caption)
|
|
.foregroundStyle(.tertiary)
|
|
}
|
|
if let note = model.versionNote {
|
|
Text(note)
|
|
.font(.caption)
|
|
.foregroundStyle(.orange)
|
|
.help(note)
|
|
}
|
|
Spacer()
|
|
if case .ready = model.phase, let sessionId = model.activeEntry?.sessionId {
|
|
Text("session \(sessionId.prefix(8))")
|
|
.font(.caption2)
|
|
.foregroundStyle(.tertiary)
|
|
.textSelection(.enabled)
|
|
}
|
|
Toggle("Debug", isOn: $debugRows)
|
|
.toggleStyle(.checkbox)
|
|
.controlSize(.mini)
|
|
.foregroundStyle(.tertiary)
|
|
.help("Show session updates, tool calls, and engine thinking.")
|
|
}
|
|
.padding(.horizontal, 12)
|
|
// #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
|
|
|
|
// freeform composer moved to the shared SessionTranscriptView in #30)
|
|
|
|
private extension MentorPaneView {
|
|
// MARK: Crash → restart prompt (map decision: EOF/crash surfaces an
|
|
|
|
// in-pane Restart prompt; the transcript replays from the engine, ADR-0007)
|
|
|
|
private func crashCard(lastPrompt: String?) -> some View {
|
|
VStack(spacing: 14) {
|
|
Image(systemName: "exclamationmark.triangle.fill")
|
|
.font(.system(size: 30))
|
|
.foregroundStyle(.orange)
|
|
Text("The mentor engine stopped")
|
|
.font(.title3)
|
|
Text("Nothing is lost — the transcript stays, and the engine can be restarted.")
|
|
.font(.callout)
|
|
.foregroundStyle(.secondary)
|
|
.multilineTextAlignment(.center)
|
|
if let lastPrompt, !lastPrompt.isEmpty {
|
|
Text("Last prompt: \(lastPrompt)")
|
|
.font(.caption)
|
|
.foregroundStyle(.tertiary)
|
|
.lineLimit(2)
|
|
}
|
|
Button("Restart") {
|
|
Task { await model.restart() }
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
if !model.stderrTail.isEmpty {
|
|
DisclosureGroup("Technical details") {
|
|
Text(model.stderrTail.joined(separator: "\n"))
|
|
.font(.system(size: 10, design: .monospaced))
|
|
.foregroundStyle(.secondary)
|
|
.textSelection(.enabled)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
}
|
|
.font(.system(size: 11))
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
}
|
|
}
|
|
.padding(24)
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
}
|
|
}
|
|
|
|
/// #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.
|
|
private struct PassBarView: View {
|
|
let kind: PassKind
|
|
let posts: PostsModel?
|
|
let home: URL?
|
|
let model: MentorSessionModel
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
Text(description)
|
|
.font(.callout)
|
|
.foregroundStyle(DesignTokens.muted)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
HStack {
|
|
Text(stateLabel)
|
|
.font(.system(size: 11, design: DesignTokens.mono))
|
|
.foregroundStyle(DesignTokens.muted)
|
|
Spacer()
|
|
actions
|
|
}
|
|
}
|
|
.padding(.horizontal, 12)
|
|
.padding(.bottom, 10)
|
|
}
|
|
|
|
/// What the pass does + the predictable cost — or the honest ask when
|
|
/// no piece is open.
|
|
private var description: String {
|
|
guard let posts, let session = posts.session, session.postID != nil else {
|
|
return "Open a post to run a pass."
|
|
}
|
|
let tokens = PassContext.estimateTokens(
|
|
kind: kind, body: session.text, pieceURL: session.passPieceURL, hasResearch: session.hasResearch,
|
|
)
|
|
return "Critiques \(kind.level) · ~\(tokens.formatted()) tokens"
|
|
}
|
|
|
|
/// The open piece's current Pass State (the library's post-meta voice).
|
|
private var stateLabel: String {
|
|
guard let posts else { return "—" }
|
|
return posts.posts.first(where: { $0.id == posts.selectedPostID })?.passState.rawValue ?? "—"
|
|
}
|
|
|
|
/// Cancel while a pass runs; Run otherwise — disabled with no open
|
|
/// piece or while the engine can't take the turn.
|
|
@ViewBuilder
|
|
private var actions: some View {
|
|
if posts?.runningPass != nil {
|
|
Button("Cancel") {
|
|
posts?.cancelPass(mentor: model)
|
|
}
|
|
.buttonStyle(.bordered)
|
|
} else {
|
|
Button("Run \(kind.rawValue)") {
|
|
guard let posts, let home else { return }
|
|
Task { await posts.runPass(kind, home: home, mentor: model) }
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
.disabled(posts?.session?.postID == nil || !model.phase.isReady || model.isStreaming)
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
MentorPaneView(model: MentorSessionModel(), binaryPath: nil)
|
|
}
|