import Foundation /// A structured contribution link attached to session metadata /// (`ExternalRefSchema`, `shared/src/schemas.ts`). /// /// The wire union currently has one member (`github_pr`). Declared tolerantly /// with optional detail fields so an unknown future kind cannot fail the whole /// session summary decode. public struct ExternalRef: Codable, Equatable, Sendable { public var kind: String public var repo: String? public var number: Int? public var url: String? /// `primary` or `secondary` (list rows show the primary only). public var role: String? /// `agent`, `user`, or `inferred`. public var source: String? public var linkedAt: Int? /// `open`, `merged`, `closed`, or `draft`. public var openState: String? /// `pass`, `pending`, or `fail`. public var checks: String? /// `clean`, `conflicting`, `blocked`, `unstable`, or `behind`. public var merge: String? /// Epoch ms of the cached forge snapshot; absent on unsnapshotted links. public var statusCheckedAt: Int? /// Opaque estate classifier code; unknown values pass through. public var estateCode: String? public init( kind: String, repo: String? = nil, number: Int? = nil, url: String? = nil, role: String? = nil, source: String? = nil, linkedAt: Int? = nil, openState: String? = nil, checks: String? = nil, merge: String? = nil, statusCheckedAt: Int? = nil, estateCode: String? = nil ) { self.kind = kind self.repo = repo self.number = number self.url = url self.role = role self.source = source self.linkedAt = linkedAt self.openState = openState self.checks = checks self.merge = merge self.statusCheckedAt = statusCheckedAt self.estateCode = estateCode } public var isPrimaryGithubPullRequest: Bool { kind == "github_pr" && role == "primary" && number != nil && url != nil } } extension SessionSummaryMetadata { /// The row's primary GitHub PR link, when the hub carried one. public var primaryGithubPullRequest: ExternalRef? { externalRefs?.first(where: \.isPrimaryGithubPullRequest) } }