From 8f713e39374202741b58dcd7f055493ea0ce00e6 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Patel Date: Sun, 11 Oct 2026 12:46:31 +0530 Subject: [PATCH 01/12] feat(pilot): add PilotPriority, PilotAction and PilotState core types --- Sources/PerchModuleKit/PilotAction.swift | 88 ++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Sources/PerchModuleKit/PilotAction.swift diff --git a/Sources/PerchModuleKit/PilotAction.swift b/Sources/PerchModuleKit/PilotAction.swift new file mode 100644 index 0000000..162714b --- /dev/null +++ b/Sources/PerchModuleKit/PilotAction.swift @@ -0,0 +1,88 @@ +import Foundation +import PerchCore + +/// How urgent one `PilotAction` is — the single ranking axis every module shares, +/// so Pilot can merge actions from different signals and sort them consistently. +/// +/// The named levels are the ONLY way to make a priority: the memberwise init is +/// internal, so a module in `PerchModules` picks a documented level rather than +/// inventing a magic number. Higher `rank` = more urgent. +public struct PilotPriority: Comparable, Hashable, Sendable { + public let rank: Int + init(_ rank: Int) { self.rank = rank } + + public static func < (lhs: PilotPriority, rhs: PilotPriority) -> Bool { lhs.rank < rhs.rank } + + /// A deploy/health endpoint is down — a production incident, nothing outranks it. + public static let prodDown = PilotPriority(100) + /// CI failing on a *specific* branch you chose to watch (your main build is broken). + public static let mainBroken = PilotPriority(90) + /// Deploy degraded (reachable but non-2xx) — still an incident, so above your own work. + public static let degraded = PilotPriority(80) + /// Changes requested on YOUR PR with unresolved threads — the ball is in your court. + public static let yourMove = PilotPriority(70) + /// Your PR has merge conflicts — blocks landing it. + public static let conflicts = PilotPriority(68) + /// CI failing on your PR, or a watched build on any/unspecified branch. + public static let ciFailingPR = PilotPriority(65) + /// A review has been requested of you — unblocking someone else ranks above landing + /// your own already-green PR (a deliberate call; flip the two if you disagree). + public static let reviewAsked = PilotPriority(55) + /// Your PR is approved + green + mergeable — a win that's ready to land. + public static let readyToMerge = PilotPriority(50) +} + +/// One suggested next action Pilot surfaces: what to do, how urgent, and where a +/// tap goes. In v1 every action is *navigation* — opening the thing in the +/// browser — so `url` is the whole interaction; write-actions (merge, re-run) are +/// a v2 concern layered on later. +public struct PilotAction: Equatable, Sendable, Identifiable { + /// Stable, per-kind-prefixed dedup key, e.g. `"pr-merge:owner/repo#120"`. The + /// same action across polls keeps the same id, so ordering never flaps and the + /// shell can dedup. + public let id: String + public let title: String + public let subtitle: String? + public let symbolName: String? + public let tint: Tint + public let priority: PilotPriority + /// Where a tap opens (the PR, the failing run, the deploy). nil = no target. + public let url: String? + + public init(id: String, title: String, subtitle: String? = nil, + symbolName: String? = nil, tint: Tint = .neutral, + priority: PilotPriority, url: String? = nil) { + self.id = id + self.title = title + self.subtitle = subtitle + self.symbolName = symbolName + self.tint = tint + self.priority = priority + self.url = url + } +} + +/// Pilot's typed state: the ranked actions plus enough about the *sources* to stay +/// honest on the pill. `face`/`detail` only receive `State` (never freshness), so +/// readiness and source availability are carried here — that's what lets the pill +/// say "Checking…" or "N unavailable" instead of a confident, wrong "All clear". +public struct PilotState: Equatable, Sendable { + /// Already ranked (most urgent first). + public let actions: [PilotAction] + /// Human names of sources that are configured but whose signal isn't usable — + /// either a reported render that's stale/error/no-access, or a source you turned + /// on but haven't finished setting up (e.g. CI with no repo). Lets the pill + + /// panel admit the picture is partial instead of a false "All clear". + public let sourcesUnavailable: [String] + /// True once every live source has reported at least once — until then the pill + /// reads "Checking…" rather than a premature "All clear". + public let ready: Bool + + public init(actions: [PilotAction], sourcesUnavailable: [String], ready: Bool) { + self.actions = actions + self.sourcesUnavailable = sourcesUnavailable + self.ready = ready + } + + public static let empty = PilotState(actions: [], sourcesUnavailable: [], ready: false) +} From bd6754684d888874b83a6942bb374d7053d42e5d Mon Sep 17 00:00:00 2001 From: Nitin Kumar Patel Date: Sun, 11 Oct 2026 12:46:31 +0530 Subject: [PATCH 02/12] feat(pilot): add defaulted actions(for:context:) to NotchModule --- Sources/PerchModuleKit/NotchModule.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sources/PerchModuleKit/NotchModule.swift b/Sources/PerchModuleKit/NotchModule.swift index c7799ab..9863859 100644 --- a/Sources/PerchModuleKit/NotchModule.swift +++ b/Sources/PerchModuleKit/NotchModule.swift @@ -39,10 +39,19 @@ public protocol NotchModule: Sendable { /// …), shown under the panel row title. Receives the same context (settings) /// as `stream`, so it can name the configured repo/URL. Defaults to nil. func contextLabel(_ context: ModuleContext) -> String? + + /// Suggested next actions derived purely from this state (and the module's + /// settings), for the Pilot aggregator to rank and surface. Defaults to empty — + /// a module overrides it only when its state implies something to *do* (merge a + /// ready PR, look at a failing run, check a down deploy). Takes `context` so a + /// module can read its own settings (e.g. a URL that lives there, not in State), + /// mirroring `contextLabel`. + func actions(for value: State, context: ModuleContext) -> [PilotAction] } public extension NotchModule { func detail(for value: State) -> [DetailRow] { [] } func notification(for value: State, previous: State?) -> ModuleAlert? { nil } func contextLabel(_ context: ModuleContext) -> String? { nil } + func actions(for value: State, context: ModuleContext) -> [PilotAction] { [] } } From b3e9edd1e71cf9b7111bbe8d0124c3f241ac9023 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Patel Date: Sun, 11 Oct 2026 12:46:31 +0530 Subject: [PATCH 03/12] feat(pilot): carry suggested actions on ModuleRender --- Sources/PerchModuleKit/DetailRow.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/PerchModuleKit/DetailRow.swift b/Sources/PerchModuleKit/DetailRow.swift index 181b94e..b4a874b 100644 --- a/Sources/PerchModuleKit/DetailRow.swift +++ b/Sources/PerchModuleKit/DetailRow.swift @@ -100,11 +100,16 @@ public struct ModuleRender: Equatable, Sendable { /// scoped to, or the host it pings), shown under the panel row's title so /// the user always knows the source. public let contextLabel: String? + /// Suggested next actions this update implies, for the Pilot aggregator to + /// rank. Empty for modules that don't override `actions(for:context:)`. + public let actions: [PilotAction] - public init(pill: PillContent, detail: [DetailRow], alert: ModuleAlert? = nil, contextLabel: String? = nil) { + public init(pill: PillContent, detail: [DetailRow], alert: ModuleAlert? = nil, + contextLabel: String? = nil, actions: [PilotAction] = []) { self.pill = pill self.detail = detail self.alert = alert self.contextLabel = contextLabel + self.actions = actions } } From f830301ab3258b2300a997cdf10abc781f3d702c Mon Sep 17 00:00:00 2001 From: Nitin Kumar Patel Date: Sun, 11 Oct 2026 12:46:31 +0530 Subject: [PATCH 04/12] feat(pilot): thread module actions through the render pipeline --- Sources/PerchModuleKit/AnyNotchModule.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/PerchModuleKit/AnyNotchModule.swift b/Sources/PerchModuleKit/AnyNotchModule.swift index db06306..a351c97 100644 --- a/Sources/PerchModuleKit/AnyNotchModule.swift +++ b/Sources/PerchModuleKit/AnyNotchModule.swift @@ -28,6 +28,7 @@ public struct AnyNotchModule: Sendable { let face = module.face(for: snapshot.value, in: slot) let pill = PillContent(face: face, freshness: snapshot.freshness, asOf: snapshot.asOf) let detail = module.detail(for: snapshot.value) + let actions = module.actions(for: snapshot.value, context: context) var alert: ModuleAlert? if snapshot.freshness.isTrustworthy { // a real (live) observation if let previousLive { @@ -35,7 +36,8 @@ public struct AnyNotchModule: Sendable { } previousLive = snapshot.value } - continuation.yield(ModuleRender(pill: pill, detail: detail, alert: alert, contextLabel: contextLabel)) + continuation.yield(ModuleRender(pill: pill, detail: detail, alert: alert, + contextLabel: contextLabel, actions: actions)) } continuation.finish() } From aea42049cc9f4345bd01d7f8f8af382d7232776b Mon Sep 17 00:00:00 2001 From: Nitin Kumar Patel Date: Sun, 11 Oct 2026 12:46:31 +0530 Subject: [PATCH 05/12] feat(pilot): derive deploy actions from health state --- Sources/PerchModules/DeployModule.swift | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Sources/PerchModules/DeployModule.swift b/Sources/PerchModules/DeployModule.swift index 572a807..8d13b5d 100644 --- a/Sources/PerchModules/DeployModule.swift +++ b/Sources/PerchModules/DeployModule.swift @@ -91,4 +91,24 @@ public struct DeployModule: NotchModule { return PillFace(text: "…", symbolName: "questionmark.circle", tint: .neutral, tooltip: "Checking") } } + + /// Pilot actions: a down or degraded endpoint is something to go look at. The + /// URL lives in settings (not in `HealthState`), so this reads it from context. + public func actions(for value: HealthState, context: ModuleContext) -> [PilotAction] { + let urlString = context.settings["url"] ?? "" + guard !urlString.isEmpty else { return [] } + let host = URL(string: urlString)?.host ?? urlString + switch value { + case .down: + return [PilotAction(id: "deploy-down:\(urlString)", title: "Deploy down", + subtitle: "\(host) — unreachable", symbolName: "xmark.octagon.fill", + tint: .critical, priority: .prodDown, url: urlString)] + case .degraded: + return [PilotAction(id: "deploy-degraded:\(urlString)", title: "Deploy degraded", + subtitle: "\(host) — non-2xx", symbolName: "exclamationmark.triangle.fill", + tint: .warning, priority: .degraded, url: urlString)] + case .healthy, .unknown: + return [] + } + } } From c5169f7e6f9bff638473dbbc62f54bd33d30f445 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Patel Date: Sun, 11 Oct 2026 12:46:31 +0530 Subject: [PATCH 06/12] feat(pilot): derive CI-failing action from build state --- Sources/PerchModules/GitHubBuildsModule.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sources/PerchModules/GitHubBuildsModule.swift b/Sources/PerchModules/GitHubBuildsModule.swift index deacffa..5ecf528 100644 --- a/Sources/PerchModules/GitHubBuildsModule.swift +++ b/Sources/PerchModules/GitHubBuildsModule.swift @@ -273,6 +273,24 @@ public struct GitHubBuildsModule: NotchModule { url: value.url.isEmpty ? nil : value.url) } + /// Pilot action: a failing build is something to look at. Priority is higher + /// when a *specific* branch is watched (your main build is broken) than when + /// watching "any branch" (`*`/blank). `BuildInfo.branch` is the run's branch, so + /// the watched-branch decision uses the module's own configured `branch`. The id + /// uses owner/repo (BuildInfo has no repo field) so it's stable + distinct. + public func actions(for value: BuildInfo, context: ModuleContext) -> [PilotAction] { + guard value.state == .failing else { return [] } + let watchesSpecificBranch = !branch.isEmpty && branch != "*" + let priority: PilotPriority = watchesSpecificBranch ? .mainBroken : .ciFailingPR + let where_ = value.branch.isEmpty ? "" : " on \(value.branch)" + return [PilotAction( + id: "build-failing:\(owner)/\(repo):\(value.shortSHA.isEmpty ? value.url : value.shortSHA)", + title: "CI failing\(where_)", + subtitle: "\(owner)/\(repo) · \(value.workflowName.isEmpty ? "CI" : value.workflowName)", + symbolName: "xmark.octagon.fill", tint: .critical, priority: priority, + url: value.url.isEmpty ? nil : value.url)] + } + /// A 401 (revoked/expired token) won't fix itself by retrying — back off hard. static func isAuthError(_ error: Error) -> Bool { if case GitHubAuthError.http(let status) = error, status == 401 { return true } From c9b850a28844334659aa8824fc1794ad99366d77 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Patel Date: Sun, 11 Oct 2026 12:46:31 +0530 Subject: [PATCH 07/12] feat(pilot): queue-aware PR actions via a shared classify (status kept identical) --- Sources/PerchModules/GitHubPRsModule.swift | 117 +++++++++++++++++---- 1 file changed, 95 insertions(+), 22 deletions(-) diff --git a/Sources/PerchModules/GitHubPRsModule.swift b/Sources/PerchModules/GitHubPRsModule.swift index bda0238..283d198 100644 --- a/Sources/PerchModules/GitHubPRsModule.swift +++ b/Sources/PerchModules/GitHubPRsModule.swift @@ -341,31 +341,104 @@ public struct GitHubPRsModule: NotchModule { return pluralComment(pr.commentCount) } - /// Map a PR's review + merge status to a label, tint, and icon. - static func status(for pr: PRSummary) -> (label: String, tint: Tint, symbol: String) { - if pr.isDraft { return ("draft", .neutral, "pencil.circle") } - if pr.mergeable == "CONFLICTING" { return ("conflicts", .critical, "exclamationmark.triangle.fill") } - // The good end-state: approved, green, no conflicts — good to land. - if pr.isReadyToMerge { return ("ready to merge", .good, "checkmark.seal.fill") } + /// The ordered classification of a PR's review + merge status — the ONE + /// precedence both the panel label (`status(for:)`) and the Pilot action + /// (`authorAction(for:)`) read, so the two can never drift. + enum PRSignal: Equatable { + case draft, conflicts, readyToMerge, approved + case changesToResolve, awaitingReReview, reviewRequired + case commented, comments, open + } + + /// Classify a PR in the same order `status(for:)` always used: draft → + /// conflicts → ready → decision (approved / changes-requested{threads,none} / + /// review-required) → engagement (commented / N-comments / open). + static func classify(_ pr: PRSummary) -> PRSignal { + if pr.isDraft { return .draft } + if pr.mergeable == "CONFLICTING" { return .conflicts } + if pr.isReadyToMerge { return .readyToMerge } // approved, green, no conflicts — good to land switch pr.reviewDecision { - case "APPROVED": return ("approved", .good, "checkmark.circle.fill") + case "APPROVED": return .approved case "CHANGES_REQUESTED": - // GitHub holds this decision until a reviewer re-reviews, so make it - // actionable: unresolved threads ⇒ your move (resolve them); none - // left ⇒ you've addressed them and it's waiting on the reviewer. - if pr.unresolvedThreads > 0 { - return ("\(pr.unresolvedLabel) to resolve", .critical, "text.bubble.fill") - } - return ("awaiting re-review", .warning, "clock.arrow.circlepath") - case "REVIEW_REQUIRED": return ("review required", .warning, "clock.fill") + // Held by GitHub until re-review: unresolved threads ⇒ your move; none ⇒ awaiting reviewer. + return pr.unresolvedThreads > 0 ? .changesToResolve : .awaitingReReview + case "REVIEW_REQUIRED": return .reviewRequired default: - // No formal decision, but say whether people have engaged instead of a - // bare "open": a Comment review → "commented"; conversation → "N - // comments". (A plain "Comment" review never sets reviewDecision, so - // "open" alone hides that the PR has been looked at.) - if pr.reviewCount > 0 { return ("commented", .info, "text.bubble.fill") } - if pr.commentCount > 0 { return (pluralComment(pr.commentCount), .info, "bubble.left.fill") } - return ("open", .info, "arrow.triangle.pull") + if pr.reviewCount > 0 { return .commented } + if pr.commentCount > 0 { return .comments } + return .open + } + } + + /// Map a PR's review + merge status to a label, tint, and icon — derived from + /// `classify` so it stays the single source of PR precedence. + static func status(for pr: PRSummary) -> (label: String, tint: Tint, symbol: String) { + switch classify(pr) { + case .draft: return ("draft", .neutral, "pencil.circle") + case .conflicts: return ("conflicts", .critical, "exclamationmark.triangle.fill") + case .readyToMerge: return ("ready to merge", .good, "checkmark.seal.fill") + case .approved: return ("approved", .good, "checkmark.circle.fill") + case .changesToResolve: return ("\(pr.unresolvedLabel) to resolve", .critical, "text.bubble.fill") + case .awaitingReReview: return ("awaiting re-review", .warning, "clock.arrow.circlepath") + case .reviewRequired: return ("review required", .warning, "clock.fill") + // A plain Comment review never sets reviewDecision, so "open" alone would + // hide that the PR has been looked at — distinguish engagement. + case .commented: return ("commented", .info, "text.bubble.fill") + case .comments: return (pluralComment(pr.commentCount), .info, "bubble.left.fill") + case .open: return ("open", .info, "arrow.triangle.pull") + } + } + + /// Pilot actions for the PR queue. Author queues yield one *author* action per + /// PR (merge/resolve/your-move/CI); the review-requested queue yields "review" + /// actions. Other queues and no-access yield nothing (so we never suggest + /// "Merge" on a PR you don't own). + public func actions(for value: PRState, context: ModuleContext) -> [PilotAction] { + guard !value.noAccess else { return [] } + switch value.queue { + case .authored: + return value.items.compactMap { Self.authorAction(for: $0) } + case .reviewRequested: + return value.items.map { pr in + PilotAction(id: "pr-review:\(pr.repo)#\(pr.number)", + title: "Review #\(pr.number)", + subtitle: "\(pr.repo) · \(pr.title)", + symbolName: "eye", tint: .warning, priority: .reviewAsked, url: pr.url) + } + case .reviewing, .reviewedBy: + return [] + } + } + + /// At most ONE author action per PR, in the same precedence as `classify`, with + /// CI-failing layered on top (it is not a `status` branch, so `status` stays + /// untouched): conflicts → your-move → merge → CI-failing → nothing. + static func authorAction(for pr: PRSummary) -> PilotAction? { + switch classify(pr) { + case .draft: + return nil // don't nag about a draft + case .conflicts: + return PilotAction(id: "pr-conflicts:\(pr.repo)#\(pr.number)", title: "Resolve conflicts #\(pr.number)", + subtitle: "\(pr.repo) · \(pr.title)", symbolName: "exclamationmark.triangle.fill", + tint: .critical, priority: .conflicts, url: pr.url) + case .changesToResolve: + return PilotAction(id: "pr-threads:\(pr.repo)#\(pr.number)", title: "\(pr.unresolvedLabel) to resolve #\(pr.number)", + subtitle: "\(pr.repo) · \(pr.title)", symbolName: "text.bubble.fill", + tint: .critical, priority: .yourMove, url: pr.url) + case .readyToMerge: + return PilotAction(id: "pr-merge:\(pr.repo)#\(pr.number)", title: "Merge #\(pr.number)", + subtitle: "\(pr.repo) · approved · CI green", symbolName: "checkmark.seal.fill", + tint: .good, priority: .readyToMerge, url: pr.url) + case .approved, .awaitingReReview, .reviewRequired, .commented, .comments, .open: + // Nothing structural to do as the author — but a red pipeline is: offer + // "CI failing" here (it's not a `status` precedence branch, so layering it + // on doesn't change the panel label). Everything else is nil. + if pr.checksState == "FAILURE" || pr.checksState == "ERROR" { + return PilotAction(id: "pr-ci:\(pr.repo)#\(pr.number)", title: "CI failing #\(pr.number)", + subtitle: "\(pr.repo) · \(pr.title)", symbolName: "xmark.octagon.fill", + tint: .critical, priority: .ciFailingPR, url: pr.url) + } + return nil } } From 2ca4c03f3a69fec5c5d2d7d1852f16b84992158b Mon Sep 17 00:00:00 2001 From: Nitin Kumar Patel Date: Sun, 11 Oct 2026 12:46:31 +0530 Subject: [PATCH 08/12] feat(pilot): add PilotModule aggregator and ranker (deterministic, no AI) --- Sources/PerchModules/PilotModule.swift | 230 +++++++++++++++++++++++++ 1 file changed, 230 insertions(+) create mode 100644 Sources/PerchModules/PilotModule.swift diff --git a/Sources/PerchModules/PilotModule.swift b/Sources/PerchModules/PilotModule.swift new file mode 100644 index 0000000..f705ee8 --- /dev/null +++ b/Sources/PerchModules/PilotModule.swift @@ -0,0 +1,230 @@ +import Foundation +import PerchCore +import PerchModuleKit + +/// Pilot — "turn the glance into the next move". A deterministic aggregator (no +/// AI): it composes the actionable dev-signal modules (your PRs, review-requested +/// PRs, Builds, Deploy), collects the `PilotAction`s each one derives from its own +/// typed state, ranks them on one shared priority scale, and surfaces the single +/// highest-leverage next action on the pill plus the ranked list (each tappable) in +/// the panel. Purely additive: it runs existing modules, changing none of them. +public struct PilotModule: NotchModule { + public typealias State = PilotState + + public static let descriptor = ModuleDescriptor( + id: "pilot.actions", + name: "Pilot", + summary: "Your single highest-leverage next action, across PRs, CI and deploys.", + supportedSlots: [.leftPill, .rightPill, .panel], + requiresConnection: true, + detailFirst: true, + // Pilot is a to-do list, not a live incident siren — it colours the pill but + // never force-opens the panel (the member modules already alert on their own + // transitions; Pilot raises no notifications of its own). + opensPanelOnCritical: false + ) + + /// The signal sources Pilot can compose, with their include-toggle key, label + /// and default. Single source of truth for the settings list, the factory's + /// include-logic and `contextLabel` — so a default can't drift across the three. + public static func sources() -> [(key: String, label: String, on: Bool)] { + // PRs/reviews work with zero config (all accessible repos). Builds + deploy + // need a repo / URL, so they default OFF — a fresh Pilot is immediately + // useful and clean ("All clear"), not "1 unavailable" until you set a repo. + [("incMyPRs", "Include my PRs", true), + ("incReviews", "Include review requests", true), + ("incBuilds", "Include CI builds", false), + ("incDeploy", "Include deploy health", false)] + } + + /// One composed signal source: a built module plus the settings its stream + /// should read (passed as a per-member `ModuleContext`), plus a human name used + /// when that source is unavailable. + public struct Member: Sendable { + public let module: AnyNotchModule + public let settings: [String: String] + public let name: String + public init(module: AnyNotchModule, settings: [String: String], name: String) { + self.module = module + self.settings = settings + self.name = name + } + } + + private let members: [Member] + /// Names of sources the user turned on but didn't finish configuring (e.g. CI + /// with no repo). They can't produce actions, so they're reported as unavailable + /// — otherwise Pilot would say "All clear" while silently watching nothing. + private let unconfigured: [String] + + public init(members: [Member], unconfigured: [String] = []) { + self.members = members + self.unconfigured = unconfigured + } + + public func stream(_ context: ModuleContext) -> AsyncStream> { + let clock = context.clock + let members = self.members + let unconfigured = self.unconfigured + return AsyncStream { continuation in + // Seed so the panel isn't blank and the pill reads "Checking…" (not a + // premature "All clear") until every source has reported. + let seed = Self.reduce(members.map { SourceState(name: $0.name) }, unconfigured: unconfigured) + continuation.yield(Snapshot(value: seed, freshness: seed.ready ? .live : .unknown, asOf: clock.now())) + + let acc = PilotAccumulator(names: members.map(\.name), unconfigured: unconfigured, + continuation: continuation, clock: clock) + let task = Task { + await withTaskGroup(of: Void.self) { group in + for (i, member) in members.enumerated() { + group.addTask { + let ctx = ModuleContext(clock: clock, settings: member.settings) + for await render in member.module.renderStream(ctx, slot: .panel) { + await acc.update(index: i, render: render) + } + } + } + } + continuation.finish() + } + continuation.onTermination = { _ in task.cancel() } + } + } + + public func face(for value: PilotState, in slot: Slot) -> PillFace { + guard value.ready else { + return PillFace(text: "Checking…", symbolName: "hourglass", tint: .neutral, + tooltip: "Pilot is gathering signals") + } + let unavailable = value.sourcesUnavailable + if value.actions.isEmpty { + if unavailable.isEmpty { + return PillFace(text: "All clear", symbolName: "checkmark.seal", tint: .good, + tooltip: "Nothing needs you right now") + } + return PillFace(text: "\(unavailable.count) unavailable", symbolName: "wifi.exclamationmark", + tint: .neutral, tooltip: "No actions · unavailable: \(unavailable.joined(separator: ", "))") + } + let top = value.actions[0] + let more = value.actions.count - 1 + let text = more > 0 ? "\(top.title) +\(more)" : top.title + let note = unavailable.isEmpty ? "" : " · \(unavailable.count) source\(unavailable.count == 1 ? "" : "s") unavailable" + // Attention dot only when something actually wants attention (warning/critical), + // so a calm "ready to merge" top action doesn't paint an alarm. + let worst = CombinedModule.worstTint(value.actions.map(\.tint)) + let badge: Tint? = (worst == .warning || worst == .critical) ? worst : nil + return PillFace(text: text, symbolName: top.symbolName, tint: top.tint, + tooltip: "\(top.title)\(top.subtitle.map { " — \($0)" } ?? "")\(note)", + badge: badge) + } + + public func detail(for value: PilotState) -> [DetailRow] { + var rows = value.actions.map { a in + DetailRow(id: a.id, title: a.title, subtitle: a.subtitle, tint: a.tint, + symbolName: a.symbolName, url: a.url) + } + for name in value.sourcesUnavailable { + rows.append(DetailRow(id: "pilot-unavailable-\(name)", title: "\(name) unavailable", + subtitle: "signal not available", tint: .warning, + symbolName: "wifi.exclamationmark")) + } + if rows.isEmpty, value.ready { + rows = [DetailRow(id: "pilot-clear", title: "All clear", + subtitle: "Nothing needs you right now", tint: .good, symbolName: "checkmark.seal")] + } + return rows + } + + public func contextLabel(_ context: ModuleContext) -> String? { + let count = Self.sources().filter { context.bool($0.key, fallback: $0.on) }.count + let repo = (context.settings["repo"].flatMap { $0.isEmpty ? nil : $0 }) ?? "all repos" + return "\(count) source\(count == 1 ? "" : "s") · \(repo)" + } + + // MARK: - Pure reduction (testable) + + /// One source's accumulated view, as the reducer sees it. + struct SourceState: Sendable { + var name: String + var renders = 0 + var latest: Freshness = .unknown + var lastActions: [PilotAction] = [] + } + + /// Fold the per-source states (+ any configured-but-unbuilt sources) into one + /// `PilotState`. Pure and deterministic — the riskiest logic, kept out of the + /// actor so it can be table-tested. + static func reduce(_ sources: [SourceState], unconfigured: [String]) -> PilotState { + // reported = produced a real render beyond the initial `.unknown` seed: + // latest is no longer `.unknown`, OR it has emitted ≥2 renders (covers a + // source that stays `.unknown`, e.g. a no-access repo, so one bad source + // doesn't pin Pilot at "Checking…" forever). + func reported(_ s: SourceState) -> Bool { s.latest != .unknown || s.renders >= 2 } + let allReported = sources.allSatisfy(reported) + + // A reported source whose latest render isn't usable is "unavailable". + // `.computing` is neutral — keep its retained actions, don't count it. + var unavailable: [String] = sources.compactMap { s in + guard reported(s) else { return nil } + switch s.latest { + case .live, .computing: return nil + case .stale, .error, .unknown: return s.name + } + } + unavailable += unconfigured // turned on but not set up → always unavailable + + let ranked = PilotRanker.rank(sources.flatMap { $0.lastActions }) + return PilotState(actions: ranked, sourcesUnavailable: unavailable, ready: allReported) + } +} + +/// Pure, deterministic ranking of Pilot actions. No clock, no randomness. +public enum PilotRanker { + public static func rank(_ actions: [PilotAction]) -> [PilotAction] { + // Dedup by non-empty url (two sources pointing at the same place → keep the + // more urgent one). Url-less actions never collapse together. + var byURL: [String: PilotAction] = [:] + var urlless: [PilotAction] = [] + for a in actions { + guard let u = a.url, !u.isEmpty else { urlless.append(a); continue } + if let existing = byURL[u] { + if a.priority > existing.priority { byURL[u] = a } + } else { + byURL[u] = a + } + } + let merged = Array(byURL.values) + urlless + // Priority desc, then stable tie-break by id so order never flaps between polls. + return merged.sorted { lhs, rhs in + lhs.priority != rhs.priority ? lhs.priority > rhs.priority : lhs.id < rhs.id + } + } +} + +/// Collects the latest render from each member and OWNS the continuation so every +/// emission happens inside the actor — serialized and in arrival order, with no +/// `await` between the state mutation and the synchronous `yield`. That removes the +/// interleaving race a yield-outside-the-actor design would have. +private actor PilotAccumulator { + private var sources: [PilotModule.SourceState] + private let unconfigured: [String] + private let continuation: AsyncStream>.Continuation + private let clock: any Clock + + init(names: [String], unconfigured: [String], + continuation: AsyncStream>.Continuation, clock: any Clock) { + self.sources = names.map { PilotModule.SourceState(name: $0) } + self.unconfigured = unconfigured + self.continuation = continuation + self.clock = clock + } + + func update(index: Int, render: ModuleRender) { + guard sources.indices.contains(index) else { return } + sources[index].renders += 1 + sources[index].latest = render.pill.freshness + if render.pill.freshness.isTrustworthy { sources[index].lastActions = render.actions } + let state = PilotModule.reduce(sources, unconfigured: unconfigured) + continuation.yield(Snapshot(value: state, freshness: state.ready ? .live : .unknown, asOf: clock.now())) + } +} From e5bd3cc3380897a702874dc1b261fc4bcd369a59 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Patel Date: Sun, 11 Oct 2026 12:46:31 +0530 Subject: [PATCH 09/12] feat(pilot): register Pilot as one module entry --- Sources/PerchModules/ModuleSpecs.swift | 61 ++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/Sources/PerchModules/ModuleSpecs.swift b/Sources/PerchModules/ModuleSpecs.swift index b687863..726636d 100644 --- a/Sources/PerchModules/ModuleSpecs.swift +++ b/Sources/PerchModules/ModuleSpecs.swift @@ -147,6 +147,67 @@ public enum ModuleSpecs { return AnyNotchModule(CombinedModule(members: members)) }, + spec(PilotModule.self, category: .github, tag: "your next move", + settings: PilotModule.sources().map { src in + ModuleSetting(key: src.key, label: src.label, placeholder: "", + defaultValue: src.on ? "true" : "false", kind: .toggle) + } + [ + ModuleSetting(key: "repo", label: "Repository (owner/name)", placeholder: "owner/name — required for CI builds"), + ModuleSetting(key: "branch", label: "Branch", placeholder: "main — or * for any", defaultValue: "main"), + ModuleSetting(key: "url", label: "Deploy URL (optional)", placeholder: "https://…/health"), + ModuleSetting(key: "limit", label: "PRs per queue", placeholder: "8", defaultValue: "8"), + refreshSetting("90"), + ]) { binding, deps in + let ctx = ModuleContext(settings: binding.settings) // tolerant bool parse, shared with contextLabel + let s = binding.settings + let repoRaw = s["repo"] ?? "", branch = s["branch"] ?? "main" + let url = s["url"] ?? "", limit = s["limit"] ?? "", refresh = s["refreshSeconds"] ?? "" + // PRs accept a comma/space list; Builds needs a single owner/name — take + // the first VALID repo so a list can't corrupt the build API call. + let buildRepo = parseRepoList(repoRaw).first + func withRefresh(_ base: [String: String]) -> [String: String] { + var m = base + if !refresh.isEmpty { m["refreshSeconds"] = refresh } + return m + } + var members: [PilotModule.Member] = [] + var unconfigured: [String] = [] + func add(_ id: String, _ settings: [String: String], _ name: String) { + if let mod = ModuleSpecs.make(SlotBinding(module: id, settings: settings), deps) { + members.append(PilotModule.Member(module: mod, settings: settings, name: name)) + } + } + func toggle(_ key: String) -> Bool { + let def = PilotModule.sources().first { $0.key == key }?.on ?? false + return ctx.bool(key, fallback: def) + } + if toggle("incMyPRs") { + var ps = withRefresh(["queue": "author", "showChecks": "true"]) + if !repoRaw.isEmpty { ps["repo"] = repoRaw } + if !limit.isEmpty { ps["limit"] = limit } + add("github.prs", ps, "My PRs") + } + if toggle("incReviews") { + var ps = withRefresh(["queue": "review-requested"]) + if !repoRaw.isEmpty { ps["repo"] = repoRaw } + if !limit.isEmpty { ps["limit"] = limit } + add("github.prs", ps, "Reviews") + } + // Builds/Deploy need a repo / URL. When enabled but unset, surface them as + // *unconfigured* (so Pilot admits CI/deploy isn't watched) rather than + // silently dropping them and reporting a false "All clear". + if toggle("incBuilds") { + if let br = buildRepo { add("github.builds", withRefresh(["repo": br, "branch": branch]), "Build") } + else { unconfigured.append("Build") } + } + if toggle("incDeploy") { + if !url.isEmpty { add("deploy.health", withRefresh(["url": url]), "Deploy") } + else { unconfigured.append("Deploy") } + } + guard !members.isEmpty else { return nil } + return AnyNotchModule(PilotModule(members: members, unconfigured: unconfigured)) + }, + spec(AIUsageModule.self, category: .local, tag: "AI token usage", settings: [ ModuleSetting(key: "dir", label: "Data folder", placeholder: "~/.claude", defaultValue: "~/.claude"), From 443896efeab2f82fe35d85997ecdf20dc0c8cfde Mon Sep 17 00:00:00 2001 From: Nitin Kumar Patel Date: Sun, 11 Oct 2026 12:46:31 +0530 Subject: [PATCH 10/12] test(pilot): ranker, reducer, pill/panel, deploy actions and render threading --- Tests/PerchModulesTests/PilotTests.swift | 176 +++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 Tests/PerchModulesTests/PilotTests.swift diff --git a/Tests/PerchModulesTests/PilotTests.swift b/Tests/PerchModulesTests/PilotTests.swift new file mode 100644 index 0000000..ee1d273 --- /dev/null +++ b/Tests/PerchModulesTests/PilotTests.swift @@ -0,0 +1,176 @@ +import Testing +import Foundation +import PerchCore +import PerchModuleKit +@testable import PerchModules + +// Pilot is deterministic: the ranker, the reducer, and the pill/panel mappings are +// pure functions, so they're worth pinning exactly. + +private func action(_ id: String, _ priority: PilotPriority, url: String? = nil, tint: Tint = .neutral) -> PilotAction { + PilotAction(id: id, title: id, symbolName: nil, tint: tint, priority: priority, url: url) +} + +// MARK: - Ranker + +@Test func rankerOrdersByPriorityThenStableId() { + let ranked = PilotRanker.rank([ + action("b", .degraded, url: "u-b"), + action("a", .prodDown, url: "u-a"), + action("c", .readyToMerge, url: "u-c"), + ]) + #expect(ranked.map(\.id) == ["a", "b", "c"]) // prodDown > degraded > readyToMerge + let tie = PilotRanker.rank([action("z", .reviewAsked, url: "z"), action("a", .reviewAsked, url: "a")]) + #expect(tie.map(\.id) == ["a", "z"]) // same priority → stable by id, never flaps +} + +@Test func rankerDedupsByUrlKeepingHighestPriority() { + let ranked = PilotRanker.rank([ + action("low", .readyToMerge, url: "https://x/pr/1"), + action("high", .conflicts, url: "https://x/pr/1"), + ]) + #expect(ranked.count == 1) + #expect(ranked[0].id == "high") +} + +@Test func rankerDoesNotCollapseUrllessActions() { + let ranked = PilotRanker.rank([action("a", .conflicts), action("b", .conflicts, url: "")]) + #expect(ranked.count == 2) +} + +// MARK: - Reducer (the riskiest logic — reported / unavailable / retention) + +private func src(_ name: String, renders: Int = 0, latest: Freshness = .unknown, + actions: [PilotAction] = []) -> PilotModule.SourceState { + PilotModule.SourceState(name: name, renders: renders, latest: latest, lastActions: actions) +} + +@Test func reduceStaysUnreadyUntilEverySourceReports() { + // Seed only: one render each, still .unknown → not reported → Checking. + let s = PilotModule.reduce([src("A", renders: 1), src("B", renders: 1)], unconfigured: []) + #expect(s.ready == false) + #expect(s.actions.isEmpty) +} + +@Test func reduceTreatsPermanentUnknownAsReportedButUnavailable() { + // A no-access repo stays .unknown; after its 2nd render it counts as reported + // (so it can't pin Pilot at Checking) but is flagged unavailable. + let s = PilotModule.reduce([src("A", renders: 2, latest: .unknown)], unconfigured: []) + #expect(s.ready == true) + #expect(s.sourcesUnavailable == ["A"]) +} + +@Test func reduceRetainsLastActionsWhenASourceGoesStale() { + let kept = [action("keep", .conflicts, url: "u")] + let s = PilotModule.reduce([src("A", renders: 2, latest: .stale(since: Date()), actions: kept)], unconfigured: []) + #expect(s.actions.map(\.id) == ["keep"]) // retained across the blip + #expect(s.sourcesUnavailable == ["A"]) // but honestly flagged + #expect(s.ready == true) +} + +@Test func reduceErrorBeforeAnyLiveIsReportedUnavailableWithNoActions() { + let s = PilotModule.reduce([src("A", renders: 1, latest: .error("boom"))], unconfigured: []) + #expect(s.ready == true) + #expect(s.sourcesUnavailable == ["A"]) + #expect(s.actions.isEmpty) +} + +@Test func reduceComputingIsNeutralNotUnavailable() { + let a = [action("x", .readyToMerge, url: "u")] + let s = PilotModule.reduce([src("A", renders: 2, latest: .computing, actions: a)], unconfigured: []) + #expect(s.sourcesUnavailable.isEmpty) // .computing isn't "unavailable" + #expect(s.actions.map(\.id) == ["x"]) +} + +@Test func reduceFoldsUnconfiguredSourcesIntoUnavailable() { + // A source turned on but not set up (CI with no repo) is unavailable, so Pilot + // never says "All clear" while silently watching nothing. + let s = PilotModule.reduce([src("My PRs", renders: 2, latest: .live)], unconfigured: ["Build"]) + #expect(s.sourcesUnavailable == ["Build"]) + #expect(s.ready == true) +} + +// MARK: - Pill / panel + +@Test func pilotFaceIsHonestAboutReadinessAndSources() { + let m = PilotModule(members: []) + let checking = m.face(for: PilotState(actions: [], sourcesUnavailable: [], ready: false), in: .panel) + #expect(checking.text == "Checking…") + let clear = m.face(for: PilotState(actions: [], sourcesUnavailable: [], ready: true), in: .panel) + #expect(clear.text == "All clear") + #expect(clear.tint == .good) + let partial = m.face(for: PilotState(actions: [], sourcesUnavailable: ["Build"], ready: true), in: .panel) + #expect(partial.text.contains("unavailable")) + #expect(partial.tint != .good) +} + +@Test func pilotFaceShowsTopActionAndCalmBadge() { + let m = PilotModule(members: []) + let top = PilotAction(id: "pr-review:o/r#2", title: "Review #2", tint: .warning, priority: .reviewAsked, url: "u2") + let second = PilotAction(id: "pr-merge:o/r#1", title: "Merge #1", tint: .good, priority: .readyToMerge, url: "u1") + let face = m.face(for: PilotState(actions: [top, second], sourcesUnavailable: [], ready: true), in: .panel) + #expect(face.text == "Review #2 +1") + #expect(face.tint == .warning) + #expect(face.badge == .warning) // attention dot because a warning is present + // A calm, all-good top action paints NO alarm dot. + let calm = m.face(for: PilotState(actions: [second], sourcesUnavailable: [], ready: true), in: .panel) + #expect(calm.badge == nil) +} + +@Test func pilotDetailListsActionsThenUnavailableSources() { + let m = PilotModule(members: []) + let a = PilotAction(id: "pr-merge:o/r#1", title: "Merge #1", tint: .good, priority: .readyToMerge, url: "u1") + let rows = m.detail(for: PilotState(actions: [a], sourcesUnavailable: ["Deploy"], ready: true)) + #expect(rows.count == 2) + #expect(rows[0].url == "u1") + #expect(rows[1].title.contains("Deploy")) + let clear = m.detail(for: PilotState(actions: [], sourcesUnavailable: [], ready: true)) + #expect(clear.count == 1) + #expect(clear[0].title == "All clear") +} + +@Test func pilotContextLabelCountsEnabledSources() { + let m = PilotModule(members: []) + // Defaults: My PRs + Reviews on, Builds + Deploy off → 2 sources. + #expect(m.contextLabel(ModuleContext(settings: ["repo": "o/r"])) == "2 sources · o/r") + // Turning on Builds adds a source; blank repo reads as "all repos". + #expect(m.contextLabel(ModuleContext(settings: ["incBuilds": "true"])) == "3 sources · all repos") +} + +// MARK: - Deploy actions + +@Test func deployActionsMapHealthToPriority() { + let m = DeployModule() + let ctx = ModuleContext(settings: ["url": "https://api.example.com/health"]) + #expect(m.actions(for: .down, context: ctx).first?.priority == .prodDown) + #expect(m.actions(for: .degraded, context: ctx).first?.priority == .degraded) + #expect(m.actions(for: .healthy, context: ctx).isEmpty) + #expect(m.actions(for: .down, context: ModuleContext()).isEmpty) // no url → nothing + #expect(m.actions(for: .down, context: ctx).first?.url == "https://api.example.com/health") +} + +// MARK: - AnyNotchModule threads actions through to ModuleRender + +private struct FakeActionModule: NotchModule { + typealias State = Int + static let descriptor = ModuleDescriptor(id: "fake.act", name: "Fake", summary: "", + supportedSlots: [.panel], requiresConnection: false) + func stream(_ context: ModuleContext) -> AsyncStream> { + AsyncStream { cont in + cont.yield(Snapshot(value: 1, freshness: .live, asOf: context.clock.now())) + cont.finish() + } + } + func face(for value: Int, in slot: Slot) -> PillFace { PillFace(text: "\(value)") } + func actions(for value: Int, context: ModuleContext) -> [PilotAction] { + [PilotAction(id: "fa-\(value)", title: "do", priority: .readyToMerge, url: "u")] + } +} + +@Test func anyNotchModuleThreadsActionsOntoRender() async { + let any = AnyNotchModule(FakeActionModule()) + for await render in any.renderStream(ModuleContext(), slot: .panel) { + #expect(render.actions.map(\.id) == ["fa-1"]) + break + } +} From 9a9bf87c8781e9e33c1136679e04618ded91f490 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Patel Date: Sun, 11 Oct 2026 12:46:31 +0530 Subject: [PATCH 11/12] test(pilot): PR and build action mappings --- Tests/PerchModulesTests/FaceTests.swift | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/Tests/PerchModulesTests/FaceTests.swift b/Tests/PerchModulesTests/FaceTests.swift index eaf26f7..646531b 100644 --- a/Tests/PerchModulesTests/FaceTests.swift +++ b/Tests/PerchModulesTests/FaceTests.swift @@ -322,6 +322,61 @@ private func series(_ v: Int) -> VitalSeries { VitalSeries(current: v, history: #expect(m.face(for: .running, in: .leftPill).tint == .info) } +@Test func prActionsAreQueueAwareAndOnePerPR() { + let m = GitHubPRsModule(client: .init(auth: .init( + flow: .init(http: NoopHTTP(), clientID: "x"), store: NoopStore()))) + func pr(_ n: Int, review: String? = nil, mergeable: String? = "MERGEABLE", + draft: Bool = false, checks: String? = nil, unresolved: Int = 0) -> PRSummary { + PRSummary(number: n, title: "t\(n)", repo: "o/r", url: "https://x/pr/\(n)", + reviewDecision: review, mergeable: mergeable, isDraft: draft, + checksState: checks, unresolvedThreads: unresolved) + } + // Authored queue → at most ONE author action per PR, at the right priority. + let authored = PRState(count: 5, items: [ + pr(1, review: "APPROVED", checks: "SUCCESS"), // ready to merge + pr(2, mergeable: "CONFLICTING"), // conflicts + pr(3, review: "CHANGES_REQUESTED", unresolved: 2), // your move + pr(4, review: "APPROVED", checks: "FAILURE"), // approved but CI failing + pr(5, draft: true), // draft → nothing + ], queue: .authored) + let acts = m.actions(for: authored, context: ModuleContext()) + let prio = Dictionary(uniqueKeysWithValues: acts.map { ($0.id, $0.priority) }) + #expect(prio["pr-merge:o/r#1"] == .readyToMerge) + #expect(prio["pr-conflicts:o/r#2"] == .conflicts) + #expect(prio["pr-threads:o/r#3"] == .yourMove) + #expect(prio["pr-ci:o/r#4"] == .ciFailingPR) + #expect(acts.allSatisfy { !$0.id.contains("#5") }) // draft → no action + #expect(acts.count == 4) // one per actionable PR + #expect(acts.first { $0.id == "pr-merge:o/r#1" }?.url == "https://x/pr/1") + + // Review-requested queue → review actions, never a "merge". + let reviews = m.actions(for: PRState(count: 1, items: [pr(9)], queue: .reviewRequested), context: ModuleContext()) + #expect(reviews.first?.priority == .reviewAsked) + #expect(reviews.first?.id == "pr-review:o/r#9") + + // Other queues / no-access → nothing (never suggest acting on a PR you don't own). + #expect(m.actions(for: PRState(count: 1, items: [pr(9)], queue: .reviewing), context: ModuleContext()).isEmpty) + #expect(m.actions(for: PRState(count: 0, items: [], repoScope: "o/r", noAccess: true, queue: .authored), + context: ModuleContext()).isEmpty) +} + +@Test func buildActionsFireOnlyWhenFailing() { + func client() -> GitHubAPIClient { + .init(auth: .init(flow: .init(http: NoopHTTP(), clientID: "x"), store: NoopStore())) + } + func info(_ s: BuildState) -> BuildInfo { + BuildInfo(state: s, workflowName: "CI", branch: "main", shortSHA: "abc", + durationText: "1m", url: "https://x/run/1") + } + let watched = GitHubBuildsModule(client: client(), owner: "o", repo: "r", branch: "main") + let anyBranch = GitHubBuildsModule(client: client(), owner: "o", repo: "r", branch: "*") + // A specific watched branch failing ranks as "main broken"; "any branch" is lower. + #expect(watched.actions(for: info(.failing), context: ModuleContext()).first?.priority == .mainBroken) + #expect(anyBranch.actions(for: info(.failing), context: ModuleContext()).first?.priority == .ciFailingPR) + #expect(watched.actions(for: info(.passing), context: ModuleContext()).isEmpty) + #expect(watched.actions(for: info(.failing), context: ModuleContext()).first?.url == "https://x/run/1") +} + // Minimal doubles so the PR module can be constructed without a network. import PerchGitHub private struct NoopHTTP: HTTPClient { From 7dc7d6cb3b15dee7a49bbc114e99eb8b04a76e48 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Patel Date: Sun, 11 Oct 2026 12:46:31 +0530 Subject: [PATCH 12/12] test(pilot): factory resolution and end-to-end streaming --- Tests/PerchModulesTests/EndToEndTests.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Tests/PerchModulesTests/EndToEndTests.swift b/Tests/PerchModulesTests/EndToEndTests.swift index 8542b5a..14e10f3 100644 --- a/Tests/PerchModulesTests/EndToEndTests.swift +++ b/Tests/PerchModulesTests/EndToEndTests.swift @@ -468,6 +468,25 @@ private func firstRender(_ module: AnyNotchModule, #expect(offRender?.detail.first?.subtitle?.contains("@octocat") == false) } +@Test func e2e_pilotFactoryResolvesMembersFromToggles() async { + // Defaults build at least one member (PRs work with no repo) → resolves. + #expect(githubFactory().makeModule(for: SlotBinding(module: "pilot.actions")) != nil) + // Every source toggled off → no members → nil (matches Combined). + let allOff = SlotBinding(module: "pilot.actions", settings: [ + "incMyPRs": "false", "incReviews": "false", "incBuilds": "false", "incDeploy": "false"]) + #expect(githubFactory().makeModule(for: allOff) == nil) +} + +@Test func e2e_pilotStreamsAndReachesLive() async { + // Pilot composes its member(s), polls, and reaches a live aggregate render. + let m = githubFactory().makeModule(for: SlotBinding(module: "pilot.actions", + settings: ["incReviews": "false"]))! + let render = await firstRender(m) { $0.pill.freshness == .live } + #expect(render != nil) + // Live → the pill is no longer the "Checking…" seed. + #expect(render?.pill.face.text != "Checking…") +} + @Test func e2e_prModuleHonorsLimitConfig() async { let m = githubFactory().makeModule(for: SlotBinding(module: "github.prs"))! let render = await firstRender(m, settings: ["queue": "review-requested", "limit": "1"]) { r in !r.detail.isEmpty && r.pill.freshness == .live }