Files
hapi/ios/Packages/HapiKit/Sources/HapiProtocol/Models/ExternalRef.swift
T
563e52b9a0 feat(ios): add outline, plan quotas, and pull-request awareness
Three H5 parity pieces for the chat surface:

- Conversation outline: a sheet lists the user prompts loaded in the
  transcript, filters them by text, and scrolls/flashes the chosen prompt
  through the same tokenized transcript target as pending requests.
- Plan quotas: a compact 5h/7d used-percent readout in the composer strip,
  fed by the runner's agent-quotas RPC through a new machine endpoint
  client. Hidden unless the machine advertises the capability and the
  active agent reports an OK account; refreshes every two minutes.
- PR awareness: session metadata now decodes external refs (tolerantly for
  unknown kinds), the list row shows the primary GitHub PR number with a
  forge-state tint, and the row context menu opens the PR in Safari.

Adds pure tests for outline filtering/truncation, quota selection and
countdown formatting, and PR badge precedence plus wire decoding.

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <noreply@hapi.run>
Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-12-01 07:05:40 +08:00

69 lines
2.2 KiB
Swift

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)
}
}