// A session's conversation on paper — the transcript the project page draws// its conversation's last exchanges with.//// Moved unchanged from the old `/code` screens' `SessionPaper.swift` when// `/code` became the session table's list: the project page is the one// screen still drawing it. A session's own page is the session table's// conversation page (`session.json`, `ConversationPage`), which draws the// same notes from the definition.//// The conversation is the approved chat: the session's words on cream notes at// the left, mine on pale blue at the right, a long turn a page-wide letter, the// started and ended lines handwritten in pencil down the middle.importCottonKitimportSwiftUI// MARK: - the conversation/// A line handwritten in pencil down the middle of the conversation — when the/// session started, and when it ended.structSessionSystemLine: View {let text: Stringvar body: someView {Text(text) .paperHand(15) .multilineTextAlignment(.center) .frame(maxWidth: .infinity, alignment: .center) .padding(.vertical, 12) }}/// One turn or one message, on the paper the approved chat puts it on: the/// session's on cream at the left, mine on pale blue at the right. A long one is/// a letter — page wide, a wider margin. Attachments sit above the words as/// prints; the time (and, on mine, where the work stands) is handwritten under/// the paper on its outer side.structSessionNote<Answer: View>: View {let key: Stringlet words: Stringlet mine: Boollet footer: String?let media: [SessionFacts.Attachment] @ViewBuilder let answer: () -> Answerprivatestaticvar noteInset: CGFloat { 14 }privatestaticvar letterInset: CGFloat { 22 }privatestaticvar printWidth: CGFloat { 132 }privatestaticvar sideLane: CGFloat { 44 }privatevar isLetter: Bool { ChatPaper.isLetter(words) }privatevar dye: PaperDye { mine ? .blue : .cream }var body: someView { HStack(alignment: .top, spacing: 0) {if mine && !isLetter { Spacer(minLength: Self.sideLane) } VStack(alignment: mine ? .trailing : .leading, spacing: 6) {if !media.isEmpty { prints } noteiflet footer {Text(footer) .paperHand(14) .padding(.horizontal, 4) } }if !mine && !isLetter { Spacer(minLength: Self.sideLane) } } .padding(.top, 8) .accessibilityElement(children: .contain) .accessibilityIdentifier("session-note-\(key)") } @ViewBuilder privatevar note: someView {let inset = isLetter ? Self.letterInset : Self.noteInsetlet paper = Paper(dye: dye, edge: .cut, seed: key, inset: inset) { wordsBlock(inset: inset) }if isLetter { paper } else {HuggingWidth(inset: inset) { wordsBlock(inset: inset).hidden().accessibilityHidden(true) paper } } }privatefunc wordsBlock(inset: CGFloat) -> someView { VStack(alignment: .leading, spacing: 10) {Text(words) .paperBody(15) .lineSpacing(isLetter ? 6 : 3) .fixedSize(horizontal: false, vertical: true) .textSelection(.enabled) answer() } }privatevar prints: someView { HStack(spacing: 8) {ForEach(media) { entry inInstantPrint(seed: "\(key)-\(entry.key)", size: .grid) {CapturedImage( key: entry.key, title: entry.name ?? ShellLines.line("projects", "attachment"), width: Self.printWidth, height: Self.printWidth ) } .frame(width: Self.printWidth) } } }}// MARK: - the transcript/// A session's conversation, as the lines it is made of.////// **ONE TRANSCRIPT, TWO PAGES.** `/sessions/[id]` draws it whole and a/// project page draws its conversation's last exchanges inline, and two copies/// of these five cases is two places a new kind of line has to be added. It/// is read only: Cotton sends nothing to a session (Nov 2026), so an old/// message is history and offers no answer.structSessionTranscript: View {let session: JSONValuelet messages: [JSONValue]let turns: [JSONValue]/// The session and session-message definitions, whose conversation says/// the words under each note. @Environment(\.tableDefinitions) privatevar definitions/// How many lines a surface that does not OWN this transcript draws — the/// last `limit` of them (`SessionFacts.recent`). `nil` on the session's/// own page, which is where the whole of it lives.var limit: Int?var body: someView { VStack(alignment: .leading, spacing: 0) {ForEach(lines) { item in line(item) } } }privatevar lines: [SessionFacts.ChatItem] {let all = SessionFacts.chat(session, messages: messages, turns: turns)guardlet limit else { return all }returnSessionFacts.recent(all, limit: limit) } @ViewBuilder privatefunc line(_ item: SessionFacts.ChatItem) -> someView {switch item {case .started(let line), .ended(let line):iflet line { SessionSystemLine(text: line) }case .turn(let key, let turn, let mine):// A TURN has no state — it happened — so its footer is the time// alone. It still HAS one: a run is otherwise a wall of notes with// nothing between "9:04 am" and "6:12 pm".SessionNote( key: key, words: turn.text("text") ?? "", mine: mine, footer: turn.day("ts")?.clock, media: [] ) { EmptyView() }case .message(let key, let message, let mine):SessionNote( key: key, words: message.text("body") ?? "", mine: mine,// The time, in the definitions' words. footer: SessionFacts.messageFooter(message, mine: mine, definitions: definitions), media: SessionFacts.media(message) ) { EmptyView() } } }}