CI / ci (push) Canceled after 0s
A freeform Session births a Post. "New Post" in the Sessions pane opens an ask-before sheet prefilled with the session's last mentor reply (editable, G9); ONE confirm materializes the piece under projects/posts/ stamped origin: ai - immutable frontmatter, never stats-eligible - and opens it in Posts; a failed write keeps the sheet up with the reason inline and the draft intact. writeNew gains an origin parameter (additive default .writer, every existing caller compiles). "New Brainstorm" is a session started with an opener prompt - no new machinery (beginBrainstormSession over the normal new+prompt rails). The freeform composer (input, liveness, Stop) moved from MentorPaneView into the shared SessionTranscriptView: one conversation surface, two panes - the Sessions pane stops being a read-only transcript. Drill offers (S2.8) wire as one pass-persona section (v1.4): the seeded micro-drill doctrine owns the motivation moment, the two-minute bound, the single shelf, and the vanish - session flavor, no machinery beyond S2.3. Resume now speaks the real adapter wire. Live-probed against the engine: 0.21.5 answers session/load with the id at _meta.hermes.sessionProvenance.acpSessionId and NO top-level sessionId - resumeSession accepts both shapes; every prior real-engine resume misread as "engine does not know this session". The fake ACP server answers load in the real shape (a loadReplayLegacy knob pins the older contract), so the whole resume suite guards the live wire. New pins: draft-candidate extraction (last mentor row wins; thought/ card/research/raw lanes and refusal/connection rows never prefill), ai-stamp write + immutability through overwrite, brainstorm roster + labeled opener, legacy-shape resume. Finish-audit (three reviewers, parallel) converged on the confirm() dismissal that destroyed the edited draft on a failed write - fixed with sheet-local error state (stale-refusal re-show dies with the presentation) - and surfaced the missing brainstorm and legacy-shape pins; the resume fix was flip-verified (removing the provenance fallback fails the provenance pins). Full suite green (379 tests). Closes #30
310 lines
9.0 KiB
Swift
310 lines
9.0 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 surface — the ACTIVE session's rows + streaming
|
|
/// buffers + the freeform input rail (#28, extracted from MentorPaneView so
|
|
/// the Sessions pane reads the same surface; **#30: the composer moved here
|
|
/// too — a session is a conversation, and every session surface offers
|
|
/// one**). 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?
|
|
/// The freeform draft (#30: shared input rail).
|
|
@State private var draft = ""
|
|
|
|
private struct PendingKeep: Identifiable {
|
|
let rowID: UUID
|
|
let candidate: ResearchCandidate
|
|
var id: UUID {
|
|
rowID
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
transcript
|
|
Divider()
|
|
inputBar
|
|
}
|
|
.sheet(item: $pendingKeep) { pending in
|
|
if let home {
|
|
ResearchKeepSheet(model: model, rowID: pending.rowID, candidate: pending.candidate, home: home)
|
|
}
|
|
}
|
|
}
|
|
|
|
private var transcript: 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 freeform composer + liveness — the Mentor pane's #23 rail,
|
|
/// shared with the Sessions pane (#30).
|
|
private var inputBar: some View {
|
|
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 {
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
.padding(12)
|
|
.disabled(model.phase.isReady == false)
|
|
}
|
|
|
|
private func send() {
|
|
let text = draft
|
|
draft = ""
|
|
Task { await model.sendPrompt(text) }
|
|
}
|
|
|
|
/// 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)
|
|
}
|