Files
museion/Museion/SessionTranscriptView.swift
T
AlexKucera 9895614b7e
CI / ci (push) Canceled after 0s
feat(sessions): session lifecycle UI (S2.3) (#28)
Each Session is a conversation Museion UIs, never owns. The mentor
bridge hosts multiple engine-owned sessions: per-session transcripts
keyed by wire sessionId behind same-named proxies (every existing
caller compiles unchanged), a names-only roster at Application
Support/sessions.json (0600; id/name/pieceTitle/date — the words
stay engine-owned per ADR-0007), and the standard affordances over
the wire: session/new, session/load, session/fork, compact as the
/compress slash prompt, session/cancel as the Stop rail.

The Sessions pane replaces its placeholder: roster list (piece-
associated by name when Posts has an open piece), row-click resume
with the engine's full-history replay (user turns included), Fork ·
Compact, live streaming with Stop; every pass auto-creates its
rostered session and streams into it; the transcript renderer is
shared with the mentor pane. Notification hops ride the main queue
(FIFO with the continuation resume) so the adapter's replay-before-
response contract is guaranteed, not probabilistic.

Resume refusals are honest and entry-attributed (an engine-unknown
session never fabricates history); concurrent replays refuse instead
of interleaving; restart replays from the engine rather than trusting
a diverging local copy. Finish-audit (three reviewers) surfaced the
concurrent-resume race, the dead restart branch, the runPass guard
window, the 15 s session/load default, and the missing createSession
backstop — all fixed and pinned (12 lifecycle pins; 359 tests green).

Closes #28
2026-10-22 12:21:12 +02:00

138 lines
4.1 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
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)
}