feat(sessions): session lifecycle UI (S2.3) (#28)
CI / ci (push) Canceled after 0s

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
This commit is contained in:
AlexKucera committed 2026-10-22 12:21:12 +02:00
1 parent 78c8844184
commit 9895614b7e
15 files changed
+1523 -245

No files matched your search

+9 -120
View File
@@ -71,7 +71,9 @@ struct MentorPaneView: View {
.padding(.vertical, 6)
Divider()
}
transcript
// #28: the transcript rendering is shared — the Sessions pane
// reads the same surface in the writing voice.
SessionTranscriptView(model: model, showsDebugRows: debugRows)
Divider()
inputBar
case let .crashed(lastPrompt):
@@ -81,7 +83,10 @@ struct MentorPaneView: View {
// #17: the pane lives in the workspace's fixed 356pt mentor column —
// no root min frame (it was the full-window M0 surface).
.task {
model.binaryPath = binaryPath ?? model.binaryPath
// #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).
@@ -90,16 +95,6 @@ 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 {
@@ -120,7 +115,7 @@ struct MentorPaneView: View {
.help(note)
}
Spacer()
if case let .ready(sessionId) = model.phase {
if case .ready = model.phase, let sessionId = model.activeEntry?.sessionId {
Text("session \(sessionId.prefix(8))")
.font(.caption2)
.foregroundStyle(.tertiary)
@@ -160,112 +155,6 @@ struct MentorPaneView: View {
.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
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)
}
// 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)
@@ -322,7 +211,7 @@ private extension MentorPaneView {
// MARK: Crash → restart prompt (map decision: EOF/crash surfaces an
// in-pane Restart prompt, never data loss)
// in-pane Restart prompt; the transcript replays from the engine (ADR-0007)
private func crashCard(lastPrompt: String?) -> some View {
VStack(spacing: 14) {