feat(sessions): keep every session, record review details, name and stamp the PDF
Sessions are now the unit of the product instead of an implicit capture run. - Nothing is deleted by default: the fixed 10-session cap is gone. An age limit (Never / 7 / 14 / 30 / 90 / 180 / 365 days) is chosen in Settings > Sessions and applied on launch, after archiving, and by "Clean up now". Sent PDFs are never touched. - Each session carries review details: lane, deployed version, commit, reviewer (pre-filled with the Mac user) and a free note. They persist in session.json and are inherited by the next session, so a review run is typed once. - PDF file names are Redline-<yyyyMMdd-HHmm>-<LANE>-<SHORTID>.pdf, and every page carries a two-line reference footer (tool, build time, session / lane, deployed build, commit, reviewer, note). The PDF document info carries the same values in Author and Keywords. - Verification: 159 tests, a headless panel self-test, and a LaunchServices-driven end-to-end run that types and clicks the real panel.
This commit is contained in:
@@ -2,7 +2,7 @@ import Foundation
|
||||
|
||||
public enum SessionState: String, Codable, Sendable {
|
||||
case open // accepting captures
|
||||
case archived // closed and kept as a past session (sent or not); pruned by retention
|
||||
case archived // closed and kept as a past session (sent or not); pruned only by an age policy the user set
|
||||
}
|
||||
|
||||
/// The manifest persisted as session.json alongside the PNGs.
|
||||
@@ -12,28 +12,39 @@ public struct CaptureSession: Codable, Sendable, Identifiable, Equatable {
|
||||
public private(set) var state: SessionState
|
||||
public private(set) var captures: [Capture]
|
||||
/// Set when the PDF is built, so a re-send reuses the same file. nil on a
|
||||
/// session that was closed without ever sending — the Past submissions list
|
||||
/// session that was closed without ever sending — the Past sessions list
|
||||
/// shows that as "Not sent".
|
||||
public private(set) var pdfFileName: String?
|
||||
/// Lane / deployed build / commit / reviewer / note for this session. Absent from
|
||||
/// manifests written before v0.5.0 — those decode as `.empty`, never a guess.
|
||||
public private(set) var context: ReviewContext
|
||||
|
||||
public init(
|
||||
id: UUID,
|
||||
createdAt: Date,
|
||||
state: SessionState,
|
||||
captures: [Capture],
|
||||
pdfFileName: String?
|
||||
pdfFileName: String?,
|
||||
context: ReviewContext = .empty
|
||||
) {
|
||||
self.id = id
|
||||
self.createdAt = createdAt
|
||||
self.state = state
|
||||
self.captures = captures
|
||||
self.pdfFileName = pdfFileName
|
||||
self.context = context
|
||||
}
|
||||
|
||||
public var isEmpty: Bool {
|
||||
captures.isEmpty
|
||||
}
|
||||
|
||||
/// First 8 characters of the UUID, uppercase — the stable short handle used in
|
||||
/// file names, the session list and the PDF header.
|
||||
public var shortID: String {
|
||||
String(id.uuidString.replacingOccurrences(of: "-", with: "").prefix(8)).uppercased()
|
||||
}
|
||||
|
||||
/// max(sequence)+1, or 1 when empty.
|
||||
public var nextSequence: Int {
|
||||
(captures.map(\.sequence).max() ?? 0) + 1
|
||||
@@ -46,7 +57,8 @@ public struct CaptureSession: Codable, Sendable, Identifiable, Equatable {
|
||||
createdAt: createdAt,
|
||||
state: state,
|
||||
captures: captures + [capture],
|
||||
pdfFileName: pdfFileName
|
||||
pdfFileName: pdfFileName,
|
||||
context: context
|
||||
)
|
||||
}
|
||||
|
||||
@@ -58,7 +70,8 @@ public struct CaptureSession: Codable, Sendable, Identifiable, Equatable {
|
||||
createdAt: createdAt,
|
||||
state: state,
|
||||
captures: captures.filter { $0.id != captureID },
|
||||
pdfFileName: pdfFileName
|
||||
pdfFileName: pdfFileName,
|
||||
context: context
|
||||
)
|
||||
}
|
||||
|
||||
@@ -70,7 +83,50 @@ public struct CaptureSession: Codable, Sendable, Identifiable, Equatable {
|
||||
createdAt: createdAt,
|
||||
state: .archived,
|
||||
captures: captures,
|
||||
pdfFileName: pdfFileName
|
||||
pdfFileName: pdfFileName,
|
||||
context: context
|
||||
)
|
||||
}
|
||||
|
||||
/// Value-semantic: returns a new session; does not mutate `self`.
|
||||
public func withContext(_ newContext: ReviewContext) -> CaptureSession {
|
||||
CaptureSession(
|
||||
id: id,
|
||||
createdAt: createdAt,
|
||||
state: state,
|
||||
captures: captures,
|
||||
pdfFileName: pdfFileName,
|
||||
context: newContext
|
||||
)
|
||||
}
|
||||
|
||||
/// Value-semantic: returns a new session; does not mutate `self`.
|
||||
public func withPDFFileName(_ name: String?) -> CaptureSession {
|
||||
CaptureSession(
|
||||
id: id,
|
||||
createdAt: createdAt,
|
||||
state: state,
|
||||
captures: captures,
|
||||
pdfFileName: name,
|
||||
context: context
|
||||
)
|
||||
}
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case id, createdAt, state, captures, pdfFileName, context
|
||||
}
|
||||
|
||||
/// `context` is decoded leniently so every manifest written before v0.5.0 keeps
|
||||
/// loading; all other keys are required, exactly as before.
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.init(
|
||||
id: try container.decode(UUID.self, forKey: .id),
|
||||
createdAt: try container.decode(Date.self, forKey: .createdAt),
|
||||
state: try container.decode(SessionState.self, forKey: .state),
|
||||
captures: try container.decode([Capture].self, forKey: .captures),
|
||||
pdfFileName: try container.decodeIfPresent(String.self, forKey: .pdfFileName),
|
||||
context: try container.decodeIfPresent(ReviewContext.self, forKey: .context) ?? .empty
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user