// // 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 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) } /// 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: 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 .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) } } /// #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) } } } #Preview { SessionsPaneView(model: MentorSessionModel(), posts: nil, binaryPath: nil) }