feat(sessions): past submissions list + start-new-session with 10-session retention

MMDB-2925. Two new menu functions in the Redline app:

- "Start new session" keeps the current screenshots as a past session
  (moved into the single archive/ folder — never deleted on close) and
  opens a fresh empty session. Sessions closed without ever sending keep
  pdfFileName nil and show as "Not sent" in the list.
- "Past submissions…" opens a window listing every retained session
  (timestamp, page count, what was sent) with actions to reveal the sent
  PDF and the session's screenshot folder.

Retention (Ben's rule 2026-10-11: "retain the past 10 sessions"): both
archive paths (send and close) keep the newest 10 archived session
folders in archive/ and remove the rest. Any PDF a pruned session
produced is untouched — it lives in the outbox/OneDrive folder.

archivedSessions() ordering now tie-breaks same-second sessions by the
session folder's creation date, so listing and pruning are deterministic
(manifest timestamps are whole-second ISO8601 — format pinned in
AtomicFileTests).

Tests: 6 core tests in SessionRetentionTests (close/keep/reconcile,
sent-vs-unsent, retention of 10, explicit prune, send-path retention) and
3 app-target tests in SessionWorkflowTests driving the real AppModel menu
actions through AppDelegate.makeLaunchModel(). PanelSnapshot renders the
new window as panel-06b-past-submissions.png.
This commit is contained in:
Claude Fable 5
2026-10-11 13:35:38 +04:00
parent eb1af5bf18
commit 6ab398c3f2
8 changed files with 790 additions and 18 deletions
+96
View File
@@ -14,6 +14,11 @@ public protocol SettingsWindowPresenting: AnyObject {
func presentSettingsWindow()
}
@MainActor
public protocol SubmissionsWindowPresenting: AnyObject {
func presentSubmissionsWindow()
}
@MainActor
public protocol ReturnsSectionProviding: AnyObject {
@ViewBuilder func returnsSection() -> AnyView
@@ -27,6 +32,8 @@ public final class AppModel {
public private(set) var screenRecordingGranted: Bool
public private(set) var allReturns: [ReturnedDocument] = []
public private(set) var commentedReturns: [ReturnedDocument] = []
/// Retained past sessions (newest first) — what the Past submissions window lists.
public private(set) var pastSessions: [CaptureSession] = []
public private(set) var statusLine: String?
public private(set) var isCapturing: Bool = false
public private(set) var isSending: Bool = false
@@ -134,6 +141,7 @@ public final class AppModel {
allReturns = all
commentedReturns = commented
}
func setPastSessions(_ value: [CaptureSession]) { pastSessions = value }
func setFolderDisplayNames(outbox: String, watch: String) {
outboxDisplayName = outbox
watchFolderDisplayName = watch
@@ -227,6 +235,12 @@ public final class AppModel {
// Empty ledger on first run is not an error.
}
do {
setPastSessions(try await spool.archivedSessions())
} catch {
setStatus((error as? ShotdeckError)?.errorDescription ?? "Could not load past sessions.")
}
// OneDrive mode: outbox == watch folder, so a freshly written, unmarked PDF must
// never show up as a return; only a document that already carries a mark does.
// Also make sure the resolved OneDrive folder actually exists before the
@@ -389,6 +403,88 @@ public final class AppModel {
}
}
/// True when "Start new session" applies: there is something to keep and no send
/// in flight that would archive the session on its own.
public var canStartNewSession: Bool { !session.isEmpty && !isSending }
/// Menu "Start new session": keeps the current screenshots as a past session
/// (moved into the single archive folder — never deleted) and opens a fresh empty
/// session. Session retention (newest 10 kept) is applied inside the store, on
/// this path and on the send path alike.
public func startNewSession() async {
var message: String
do {
if let archived = try await spool.closeCurrentSession() {
let count = archived.captures.count
message = "New session — \(count) capture\(count == 1 ? "" : "s") kept as a past session."
} else {
message = "New session started."
}
} catch {
message = (error as? ShotdeckError)?.errorDescription ?? "Could not start a new session."
}
if let refreshProblem = await reloadFromSpool() {
message += " \(refreshProblem)"
}
setStatus(message)
}
/// Re-reads the open session and the past-session list from the store. Returns a
/// problem description when either read failed (the caller decides how to surface
/// it), nil when everything was refreshed — never silently substitutes stale state.
func reloadFromSpool() async -> String? {
var problems: [String] = []
do {
replaceSession(try await spool.currentSession())
} catch {
problems.append(
"Could not reload the current session: \((error as? ShotdeckError)?.errorDescription ?? error.localizedDescription)")
}
do {
setPastSessions(try await spool.archivedSessions())
} catch {
problems.append(
"Could not load past sessions: \((error as? ShotdeckError)?.errorDescription ?? error.localizedDescription)")
}
return problems.isEmpty ? nil : problems.joined(separator: " ")
}
/// Where a past session's sent PDF lives now (the outbox in AirDrop mode, the
/// OneDrive folder in OneDrive mode), or nil when it was never sent / is gone.
public func sentPDFURL(for session: CaptureSession) -> URL? {
guard let name = session.pdfFileName else { return nil }
let url = outboxURL.appendingPathComponent(name)
return FileManager.default.fileExists(atPath: url.path) ? url : nil
}
/// "PDF" action on a past-submission row: reveals the exact PDF that was sent.
public func revealSentPDF(_ session: CaptureSession) {
guard session.pdfFileName != nil else {
setStatus("That session was never sent.")
return
}
guard let url = sentPDFURL(for: session) else {
setStatus("The PDF is no longer in \(outboxDisplayName).")
return
}
NSWorkspace.shared.activateFileViewerSelecting([url])
}
/// "Captures" action on a past-submission row: reveals that session's folder.
public func revealSessionCaptures(_ session: CaptureSession) {
let dir = paths.archiveDirectory(session.id)
guard FileManager.default.fileExists(atPath: dir.path) else {
setStatus("That past session is no longer on disk.")
return
}
NSWorkspace.shared.activateFileViewerSelecting([dir])
}
/// The single folder every retained session lives in.
public func openSessionsFolder() {
NSWorkspace.shared.open(paths.archive)
}
public func copyCommentedLinks() async {
do {
let text = try await ledger.clipboardText()
+20
View File
@@ -119,6 +119,26 @@ struct MenuBarView: View {
}
.disabled(!model.canRevealLastPDF)
Button {
Task { await model.startNewSession() }
} label: {
actionLabel("Start new session")
}
.disabled(!model.canStartNewSession)
Button {
if let presenter = model as? SubmissionsWindowPresenting {
presenter.presentSubmissionsWindow()
} else {
model.setStatus("Past submissions are not available in this build.")
}
} label: {
actionLabel(
"Past submissions…",
trailing: model.pastSessions.isEmpty ? nil : "\(model.pastSessions.count)"
)
}
Button {
Task { await model.captureNow() }
} label: {
+38 -3
View File
@@ -46,6 +46,11 @@ enum PanelSnapshot {
let region = sampleRegion()
// Two real past sessions through the REAL store paths (one sent with a PDF in
// the outbox, one closed without ever sending) so panel-06b has the exact two
// states the Past submissions window must distinguish.
try await seedPastSessions(to: model)
// 01 — Screen Recording missing (no public mutator; snapshot-only seam).
model.snapshotSetScreenRecordingGranted(false)
model.replaceRegion(nil)
@@ -74,6 +79,15 @@ enum PanelSnapshot {
to: directory.appendingPathComponent("panel-06-settings.png")
)
// 06b — Past submissions window against the same isolated model: the two
// seeded past sessions plus the live session's three captures from panel 04.
model.setPastSessions(try await model.spool.archivedSessions())
try render(
PastSubmissionsView().environment(model),
to: directory.appendingPathComponent("panel-06b-past-submissions.png"),
width: 440
)
// 07/08/09 — OneDrive-mode Settings + menu bar, on a SEPARATE isolated model so
// this transport switch never bleeds into the AirDrop-mode panels above.
try await captureOneDrivePanels(to: directory)
@@ -157,6 +171,27 @@ enum PanelSnapshot {
try renderMenuBar(model: model, to: directory, name: "09-captures-present-onedrive")
}
@MainActor
private static func seedPastSessions(to model: AppModel) async throws {
_ = try await model.spool.append(
pngData: try makePNGData(width: 192, height: 108, red: 0.55, green: 0.35, blue: 0.85),
pixelWidth: 192, pixelHeight: 108, scale: 2.0, capturedAt: Date())
_ = try await model.spool.append(
pngData: try makePNGData(width: 192, height: 108, red: 0.25, green: 0.7, blue: 0.6),
pixelWidth: 192, pixelHeight: 108, scale: 2.0, capturedAt: Date())
let sentName = "Redline-\(DubaiTime.fileStamp(Date())).pdf"
_ = try await model.spool.archiveCurrent(pdfFileName: sentName)
// The real send writes the PDF to the outbox; the fixture does the same so the
// row's PDF action is genuinely live in the snapshot.
try Data("%PDF-1.4\n% snapshot fixture\n".utf8).write(
to: model.paths.outbox.appendingPathComponent(sentName))
_ = try await model.spool.append(
pngData: try makePNGData(width: 160, height: 90, red: 0.9, green: 0.55, blue: 0.2),
pixelWidth: 160, pixelHeight: 90, scale: 2.0, capturedAt: Date())
_ = try await model.spool.closeCurrentSession()
}
@MainActor
private static func renderMenuBar(model: AppModel, to directory: URL, name: String) throws {
try render(
@@ -166,9 +201,9 @@ enum PanelSnapshot {
}
@MainActor
private static func render(_ view: some View, to url: URL) throws {
private static func render(_ view: some View, to url: URL, width: CGFloat = panelWidth) throws {
let wrapped = view
.frame(width: panelWidth, alignment: .topLeading)
.frame(width: width, alignment: .topLeading)
.fixedSize(horizontal: false, vertical: true)
.background(Color(nsColor: .windowBackgroundColor))
@@ -196,7 +231,7 @@ enum PanelSnapshot {
size.height = hosting.intrinsicContentSize.height
}
if size.height < 1 { size.height = 240 }
size.width = panelWidth
size.width = width
size.height = ceil(size.height)
hosting.setFrameSize(size)
+138
View File
@@ -0,0 +1,138 @@
import AppKit
import SwiftUI
import ShotdeckCore
/// "Past submissions…" window: every retained session and what was sent for it.
/// Read-and-reveal only — keeping/starting sessions is driven from the menu rows
/// (and the button on the current-session row below).
struct PastSubmissionsView: View {
@Environment(AppModel.self) private var model
var body: some View {
VStack(alignment: .leading, spacing: 8) {
currentSessionRow
Divider()
if model.pastSessions.isEmpty {
Text("No past sessions yet. Use “Start new session” to keep the current captures.")
.font(.caption)
.foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
} else {
ScrollView {
VStack(alignment: .leading, spacing: 6) {
ForEach(model.pastSessions) { session in
PastSessionRow(session: session)
}
}
}
.frame(maxHeight: 320)
}
Divider()
footer
}
.padding(10)
.frame(width: 420, alignment: .leading)
.controlSize(.small)
.task {
if let problem = await model.reloadFromSpool() {
model.setStatus(problem)
}
}
}
private var currentSessionRow: some View {
HStack(alignment: .center, spacing: 8) {
VStack(alignment: .leading, spacing: 2) {
Text("Current session")
.font(.caption)
.foregroundStyle(.secondary)
Text(currentSessionSummary)
.fixedSize(horizontal: false, vertical: true)
}
Spacer(minLength: 8)
Button("Start new session") {
Task { await model.startNewSession() }
}
.disabled(!model.canStartNewSession)
.help("Keeps these captures as a past session and starts a fresh one.")
}
}
private var currentSessionSummary: String {
let count = model.session.captures.count
if count == 0 {
return "Nothing captured yet."
}
return "\(count) capture\(count == 1 ? "" : "s") · started \(DubaiTime.stamp(model.session.createdAt))"
}
private var footer: some View {
HStack(spacing: 8) {
Text("Sessions are kept in one folder — the newest \(SpoolStore.defaultRetainedSessionCount).")
.font(.caption)
.foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
Spacer(minLength: 8)
Button("Open sessions folder") {
model.openSessionsFolder()
}
}
}
}
private struct PastSessionRow: View {
@Environment(AppModel.self) private var model
let session: CaptureSession
var body: some View {
HStack(alignment: .center, spacing: 8) {
VStack(alignment: .leading, spacing: 2) {
Text(DubaiTime.stamp(session.createdAt))
Text(submissionLabel)
.font(.caption)
.foregroundStyle(session.pdfFileName == nil ? .secondary : .primary)
.lineLimit(1)
}
Spacer(minLength: 8)
Button("PDF") {
model.revealSentPDF(session)
}
.disabled(model.sentPDFURL(for: session) == nil)
.help(session.pdfFileName.map { "Reveal \($0)" } ?? "This session was never sent.")
Button("Captures") {
model.revealSessionCaptures(session)
}
.help("Reveal this session's screenshots")
}
}
private var submissionLabel: String {
let pages = "\(session.captures.count) page\(session.captures.count == 1 ? "" : "s")"
guard let name = session.pdfFileName else {
return "\(pages) · not sent"
}
return "\(pages) · sent as \(name)"
}
}
extension AppModel: SubmissionsWindowPresenting {
private static var submissionsWindowController: NSWindowController?
public func presentSubmissionsWindow() {
if let existing = Self.submissionsWindowController {
existing.window?.makeKeyAndOrderFront(nil)
NSApp.activate()
return
}
let hosting = NSHostingController(rootView: PastSubmissionsView().environment(self))
let window = NSWindow(contentViewController: hosting)
window.title = "Redline — Past submissions"
window.styleMask = [.titled, .closable]
window.isReleasedWhenClosed = false
window.center()
let controller = NSWindowController(window: window)
Self.submissionsWindowController = controller
controller.showWindow(nil)
NSApp.activate()
}
}