Files
museion/Museion/SessionTranscriptView.swift
T
AlexKucera b02d36bb5d
CI / ci (push) Canceled after 0s
feat(mentor): research & library-light (S8) (#29)
The mentor researches mid-pass and its findings arrive as candidate
source-notes with provenance inside their Session. A third museion-
tools tool, submit_research_notes, is the typed rail (ADR-0006
posture): decode-validate only, reply {"received": N}, write NOTHING
— the session is the holding area, and keeping is the writer's act.

Candidates ride the transcript as first-class rows (researchNote):
parsed from the tool call's rawInput by payload shape — the notes
array routes before the fix-card parse, titles are display text —
one row per note, all-or-nothing per batch, the wire's whitespace
rule mirrored so both boundaries agree. Resume re-materializes them
for free: replays re-run the same parse; dispositions reset honestly
(they were never persisted — engine-owned cargo, ADR-0007).

The writer curates in place (full cards in the shared transcript, no
palette — a handful curates where it lands): Keep opens the
ask-before sheet (G9; PromoteAskSheet posture — inline refusal,
buttons kept) and ONE confirm lands one plain markdown note with
provenance into the piece's research/ via writeResearchNote — the
one folder(of:) id lookup anchors it inside this Home, a symlinked
research/ refuses, collision -2; Reject vanishes, recording nothing.
The pass stub names the rail and forbids the engine writing
candidates itself; kept notes flip hasResearch, so every later pass
sees the research/ path (S8.3 at v1 depth).

Finish-audit (three reviewers) drove the whitespace-parity and
shape-routing fixes, the ResearchNoteContent dedup, and a poll-loop
fix for the debounce rig's sidecar half that the larger suite's load
had pushed past its fixed sleep — full suite green (373 tests).

Closes #29
2026-10-22 14:06:16 +02:00

249 lines
7.4 KiB
Swift

//
// SessionTranscriptView.swift
// Museion
//
// #28 (S2.3): the shared session transcript, extracted from MentorPaneView —
// one renderer for the ACTIVE session's rows + streaming buffers. The
// Mentor pane passes its debug toggle; the Sessions pane reads the writing
// voice.
//
import SwiftUI
/// The shared session transcript — the ACTIVE session's rows + streaming
/// buffers, extracted from MentorPaneView in #28 so the Sessions pane reads
/// the same surface. Writing voice: pass `showsDebugRows: false` (the debug
/// toggle stays the Mentor pane's).
struct SessionTranscriptView: View {
let model: MentorSessionModel
/// Raw session/tool rows, collapsed thinking, and live thinking render
/// only when on — the model keeps every row either way.
var showsDebugRows = false
/// #29 (S8.3): the Home a kept research note lands in — nil (previews)
/// hides the candidate card's Keep/Reject buttons.
var home: URL?
/// The ask-before keep (#29 G9): ONE blocking confirm per candidate,
/// presented over the transcript — never inside a lazy row.
@State private var pendingKeep: PendingKeep?
private struct PendingKeep: Identifiable {
let rowID: UUID
let candidate: ResearchCandidate
var id: UUID {
rowID
}
}
var body: some View {
ScrollView {
LazyVStack(alignment: .leading, spacing: 10) {
ForEach(model.rows.filter { showsDebugRows || Self.isWritingRow($0) }) { row in
rowView(row)
}
if showsDebugRows, !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)
.sheet(item: $pendingKeep) { pending in
if let home {
ResearchKeepSheet(model: model, rowID: pending.rowID, candidate: pending.candidate, home: home)
}
}
}
/// The writing-session filter: prose + card events stay; raw rows and
/// thinking are debug-only. Static, nonisolated — pure, testable from
/// any context.
nonisolated static func isWritingRow(_ row: SessionRow) -> Bool {
switch row.content {
case .text, .fixCard, .researchNote: true
case .thought, .raw: false
}
}
@ViewBuilder
private func rowView(_ row: SessionRow) -> some View {
switch row.content {
case let .text(text):
textRow(text)
case let .thought(text):
ThoughtRow(text: text)
case let .fixCard(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 .researchNote(candidate):
ResearchNoteRow(
candidate: candidate,
actions: home != nil,
keep: { pendingKeep = PendingKeep(rowID: row.id, candidate: candidate) },
reject: { model.setResearchDisposition(rowID: row.id, .rejected) },
)
case let .raw(kind, json):
RawUpdateRow(kind: kind, json: json)
}
}
private func textRow(_ text: String) -> some View {
Text(text)
.textSelection(.enabled)
.frame(maxWidth: .infinity, alignment: .leading)
}
/// 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)
}
}
/// #29 (S8.3): one candidate research-note card — serif title, mono
/// muted url, selectable note, muted-italic quote. Pending offers Keep
/// (ask-before) + Reject (no confirm — vanishes, nothing recorded);
/// kept/rejected dim 0.45 (closed-card voice) with their meta line.
private struct ResearchNoteRow: View {
let candidate: ResearchCandidate
let actions: Bool
let keep: () -> Void
let reject: () -> Void
var body: some View {
VStack(alignment: .leading, spacing: 6) {
ResearchNoteContent(candidate: candidate)
dispositionView
}
.frame(maxWidth: .infinity, alignment: .leading)
.opacity(dimmed)
}
@ViewBuilder
private var dispositionView: some View {
switch candidate.disposition {
case .pending:
if actions {
HStack(spacing: 8) {
Button("Keep", action: keep)
.buttonStyle(.bordered)
.controlSize(.small)
.font(.system(size: 11, design: DesignTokens.mono))
.help("Land this note in the piece's research/ folder")
Button("Reject", action: reject)
.buttonStyle(.bordered)
.controlSize(.small)
.font(.system(size: 11, design: DesignTokens.mono))
.help("Vanish the candidate — nothing is recorded")
}
}
case let .kept(fileName):
meta("kept · research/\(fileName)")
case .rejected:
meta("rejected")
}
}
private var dimmed: Double {
candidate.disposition == .pending ? 1 : 0.45
}
private func meta(_ text: String) -> some View {
Text(text)
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.muted)
}
}
/// #24 fix: the engine's thinking, collapsed — a pass's thought stream
/// runs to hundreds of lines and is not the critique.
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)
}
}
}
/// #29 audit: the candidate's content block — title/url/note/quote — shared
/// by the transcript row and the keep sheet's preview, so a restyle edits
/// one place. File scope: ResearchKeepSheet reuses it.
struct ResearchNoteContent: View {
let candidate: ResearchCandidate
var body: some View {
VStack(alignment: .leading, spacing: 6) {
Text(candidate.title)
.font(.system(size: 13, design: DesignTokens.serif))
Text(candidate.url)
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.muted)
.lineLimit(1)
.truncationMode(.middle)
if !candidate.note.isEmpty {
Text(candidate.note)
.textSelection(.enabled)
}
if !candidate.quote.isEmpty {
Text("“\(candidate.quote)”")
.italic()
.foregroundStyle(DesignTokens.muted)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
}
}
#Preview {
SessionsPaneView(model: MentorSessionModel(), posts: nil, binaryPath: nil)
}