feat(mentor): museion-tools MCP server (#23)
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
Headless --serve-mcp role in the app binary: NDJSON JSON-RPC on stdio exposing query_learnings and submit_fix_cards (ADR-0006 cards, anchor-validated; stale lands flagged, never rejected), registered into the museion profile at provisioning. Cards persist per piece under <piece>/cards/ and surface in a floating Fix Cards palette with pass-stamped provenance. Live dogfood drove the shape: session/prompt waits pass length (the 15 s request default abandoned working turns), a liveness row and a persisted Debug checkbox (off) split writing sessions from debug chatter, the verdict references findings by title only while the cards carry the detail (persona v1.3 — tools work in silence), and the #24 pass rails (pass bar, TurnOutcome seam, snapshots) ride in. Three-reviewer audit round: piece-path shape guard closes the JSON-drop and substring-oracle holes, nested submit rawInput parsing (the flat parser never matched the live rail), missing stopReason never advances a pass, 1 MB stdin cap, card scan off MainActor. 296 tests green; every behavioral fix flip-verified. Closes #23
This commit is contained in:
1 parent
c2e94fd825
commit
683ddf8426
29 files changed
+2626
-169
No files matched your search
+252
-87
@@ -13,12 +13,29 @@ import SwiftUI
|
||||
struct MentorPaneView: View {
|
||||
@State private var draft = ""
|
||||
@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?) {
|
||||
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 {
|
||||
@@ -30,6 +47,30 @@ struct MentorPaneView: View {
|
||||
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()
|
||||
}
|
||||
transcript
|
||||
Divider()
|
||||
inputBar
|
||||
@@ -49,6 +90,16 @@ struct MentorPaneView: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// The writing-session transcript: prose (verdicts, labels, notes) and
|
||||
/// card events stay; raw session/tool rows and collapsed thinking are
|
||||
/// debug-only. Static — pure, testable.
|
||||
static func isWritingRow(_ row: SessionRow) -> Bool {
|
||||
switch row.content {
|
||||
case .text, .fixCard: true
|
||||
case .thought, .raw: false
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Header
|
||||
|
||||
private var header: some View {
|
||||
@@ -75,6 +126,11 @@ struct MentorPaneView: View {
|
||||
.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
|
||||
@@ -83,35 +139,56 @@ struct MentorPaneView: View {
|
||||
.frame(minHeight: 52)
|
||||
}
|
||||
|
||||
// MARK: Transcript
|
||||
// MARK: Pass surface (#24, S3.1)
|
||||
|
||||
private var transcript: some View {
|
||||
ScrollViewReader { proxy in
|
||||
ScrollView {
|
||||
LazyVStack(alignment: .leading, spacing: 10) {
|
||||
ForEach(model.rows) { row in
|
||||
rowView(row)
|
||||
.id(row.id)
|
||||
}
|
||||
if !model.streamingText.isEmpty {
|
||||
textRow("Mentor: \(model.streamingText)")
|
||||
.id("streaming")
|
||||
}
|
||||
}
|
||||
.padding(12)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
.onChange(of: model.rows.count) { scrollToBottom(proxy) }
|
||||
.onChange(of: model.streamingText) { scrollToBottom(proxy) }
|
||||
private var passKind: PassKind? {
|
||||
switch mode {
|
||||
case .pass1: .pass1
|
||||
case .pass2: .pass2
|
||||
case .chat: nil
|
||||
}
|
||||
}
|
||||
|
||||
private func scrollToBottom(_ proxy: ScrollViewProxy) {
|
||||
if let last = model.rows.last?.id {
|
||||
proxy.scrollTo(last, anchor: .bottom)
|
||||
} else {
|
||||
proxy.scrollTo("streaming", anchor: .bottom)
|
||||
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: Transcript
|
||||
|
||||
private var transcript: some View {
|
||||
ScrollView {
|
||||
LazyVStack(alignment: .leading, spacing: 10) {
|
||||
ForEach(model.rows.filter { debugRows || Self.isWritingRow($0) }) { row in
|
||||
rowView(row)
|
||||
}
|
||||
if debugRows, !model.streamingThought.isEmpty {
|
||||
// Live thinking: quiet, capped — it's transient (the full
|
||||
// text lands in a collapsed row when the turn ends).
|
||||
Text(model.streamingThought)
|
||||
.font(.system(size: 11, design: DesignTokens.mono))
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
.lineLimit(3)
|
||||
.textSelection(.enabled)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
if !model.streamingText.isEmpty {
|
||||
textRow("Mentor: \(model.streamingText)")
|
||||
}
|
||||
}
|
||||
.padding(12)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
// #24 fix: programmatic scrollTo raced the growing lazy rows and
|
||||
// mislanded at the TOP; the native bottom anchor needs no scroll code.
|
||||
.defaultScrollAnchor(.bottom)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
@@ -119,8 +196,12 @@ struct MentorPaneView: View {
|
||||
switch row.content {
|
||||
case let .text(text):
|
||||
textRow(text)
|
||||
case let .thought(text):
|
||||
ThoughtRow(text: text)
|
||||
case let .fixCard(card):
|
||||
FixCardRow(card: card)
|
||||
// #23 follow-up: detail lives in the palette window — the
|
||||
// transcript keeps a one-line event, not the card.
|
||||
FixCardEventRow(pattern: card.pattern)
|
||||
case let .raw(kind, json):
|
||||
RawUpdateRow(kind: kind, json: json)
|
||||
}
|
||||
@@ -132,29 +213,101 @@ struct MentorPaneView: View {
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
// MARK: Rows
|
||||
|
||||
/// The tool-call EVENT, not the card: the pattern title alone. The
|
||||
/// card's full statement lives in the Fix Cards palette window.
|
||||
private struct FixCardEventRow: View {
|
||||
let pattern: String
|
||||
|
||||
var body: some View {
|
||||
Label(pattern, systemImage: "rectangle.and.pencil.and.ellipsis")
|
||||
.font(.system(size: 11, design: DesignTokens.mono))
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
|
||||
/// #24 fix: the engine's thinking, collapsed — a pass's thought stream runs
|
||||
/// to hundreds of lines and is not the critique (only `agent_message_chunk`
|
||||
/// is). Same shape as RawUpdateRow: quiet mono, expandable, never in the way.
|
||||
private struct ThoughtRow: View {
|
||||
let text: String
|
||||
|
||||
var body: some View {
|
||||
DisclosureGroup {
|
||||
Text(text)
|
||||
.font(.system(size: 10, design: .monospaced))
|
||||
.foregroundStyle(.secondary)
|
||||
.textSelection(.enabled)
|
||||
} label: {
|
||||
Text("thinking")
|
||||
.font(.system(size: 11, design: .monospaced))
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
|
||||
private struct RawUpdateRow: View {
|
||||
let kind: String
|
||||
let json: String
|
||||
|
||||
var body: some View {
|
||||
DisclosureGroup {
|
||||
Text(json)
|
||||
.font(.system(size: 10, design: .monospaced))
|
||||
.textSelection(.enabled)
|
||||
} label: {
|
||||
Text(kind)
|
||||
.font(.system(size: 11, design: .monospaced))
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Input + crash card (file-scope extension — type_body_length posture)
|
||||
|
||||
private extension MentorPaneView {
|
||||
// MARK: Input
|
||||
|
||||
private var inputBar: some View {
|
||||
HStack(spacing: 8) {
|
||||
TextField("Ask the mentor…", text: $draft, axis: .vertical)
|
||||
.textFieldStyle(.plain)
|
||||
.lineLimit(1 ... 4)
|
||||
.onSubmit { send() }
|
||||
Button {
|
||||
send()
|
||||
} label: {
|
||||
Image(systemName: "arrow.up.circle.fill")
|
||||
.font(.title2)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(draft.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty || model.isStreaming)
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
// Liveness: a pass legitimately runs minutes of silent tool work
|
||||
// (skill loads, learnings) — without this the pane reads as dead
|
||||
// (dogfood #23: "hard to tell if it is still thinking").
|
||||
if model.isStreaming {
|
||||
Button {
|
||||
model.stopStreaming()
|
||||
} label: {
|
||||
Text("Stop")
|
||||
HStack(spacing: 8) {
|
||||
ProgressView()
|
||||
.controlSize(.small)
|
||||
Text("Mentor is working — Stop to interrupt.")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
HStack(spacing: 8) {
|
||||
TextField("Ask the mentor…", text: $draft, axis: .vertical)
|
||||
.textFieldStyle(.plain)
|
||||
.lineLimit(1 ... 4)
|
||||
.onSubmit { send() }
|
||||
Button {
|
||||
send()
|
||||
} label: {
|
||||
Image(systemName: "arrow.up.circle.fill")
|
||||
.font(.title2)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(draft.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty || model.isStreaming)
|
||||
if model.isStreaming {
|
||||
Button {
|
||||
model.stopStreaming()
|
||||
} label: {
|
||||
Text("Stop")
|
||||
}
|
||||
.controlSize(.regular)
|
||||
}
|
||||
.controlSize(.regular)
|
||||
}
|
||||
}
|
||||
.padding(12)
|
||||
@@ -207,57 +360,69 @@ struct MentorPaneView: View {
|
||||
.padding(24)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Rows
|
||||
/// #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
|
||||
|
||||
private struct FixCardRow: View {
|
||||
let card: FixCard
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
Label(card.pattern, systemImage: "rectangle.and.pencil.and.ellipsis")
|
||||
.font(.callout.weight(.semibold))
|
||||
if !card.anchor.isEmpty {
|
||||
Text("“\(card.anchor)”")
|
||||
.font(.system(size: 11, design: .monospaced))
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
if !card.problem.isEmpty {
|
||||
Text(card.problem).font(.callout)
|
||||
}
|
||||
if !card.diagnosticQuestion.isEmpty {
|
||||
Text("Diagnostic: \(card.diagnosticQuestion)")
|
||||
.font(.callout)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
if !card.fix.isEmpty {
|
||||
Text("Fix: \(card.fix)").font(.callout)
|
||||
}
|
||||
Text(card.provenance + " · " + card.status)
|
||||
.font(.caption2)
|
||||
.foregroundStyle(.tertiary)
|
||||
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(10)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(.quaternary.opacity(0.3), in: RoundedRectangle(cornerRadius: 8))
|
||||
}
|
||||
.padding(.horizontal, 12)
|
||||
.padding(.bottom, 10)
|
||||
}
|
||||
|
||||
private struct RawUpdateRow: View {
|
||||
let kind: String
|
||||
let json: String
|
||||
/// 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"
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
DisclosureGroup {
|
||||
Text(json)
|
||||
.font(.system(size: 10, design: .monospaced))
|
||||
.textSelection(.enabled)
|
||||
} label: {
|
||||
Text(kind)
|
||||
.font(.system(size: 11, design: .monospaced))
|
||||
.foregroundStyle(.secondary)
|
||||
/// 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)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user