mirror of
https://github.com/wu736139669/hapi.git
synced 2026-12-05 07:07:04 +00:00
Settings gains a Machines screen: health, CLI version, capability and binary skew, rename, and the supervised runner restart the web banner exposes. Skew derivation lives in HapiProtocol so it is testable without a hub. The icon badge counts unread sessions on the active hub, with a notification-settings toggle that clears it immediately. The Japanese app-language option is dropped (no shipped catalog). via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run>
41 lines
1.6 KiB
Swift
41 lines
1.6 KiB
Swift
import Foundation
|
|
|
|
/// Ports `shared/src/runnerCapabilities.ts` for the native machine screen.
|
|
/// The hub hard-depends on these machine RPCs, so a runner missing one is
|
|
/// stale even when it still answers the heartbeat.
|
|
public enum RunnerSkew {
|
|
/// `REQUIRED_MACHINE_CAPABILITIES` values.
|
|
public static let requiredMachineCapabilities: [String] = [
|
|
"agent-availability",
|
|
"cursor-chat-store-status",
|
|
]
|
|
|
|
public static func missingRequiredCapabilities(_ advertised: [String]?) -> [String] {
|
|
let set = Set(advertised ?? [])
|
|
return requiredMachineCapabilities.filter { !set.contains($0) }
|
|
}
|
|
|
|
public static func isCapabilitySkewed(_ advertised: [String]?) -> Bool {
|
|
!missingRequiredCapabilities(advertised).isEmpty
|
|
}
|
|
|
|
/// True when the running process started from a different CLI binary or
|
|
/// mtime than the one currently installed on disk
|
|
/// (`cliBinaryUpdatedOnDisk` in the shared package).
|
|
public static func cliBinaryUpdatedOnDisk(_ metadata: MachineMetadata?) -> Bool {
|
|
guard let started = metadata?.startedCliMtimeMs,
|
|
let installed = metadata?.installedCliMtimeMs,
|
|
started.isFinite,
|
|
installed.isFinite else { return false }
|
|
return started != installed
|
|
}
|
|
|
|
/// Web banner restart gate: a newer binary is already on disk and the
|
|
/// runner is under a supervisor that can bring it back.
|
|
public static func canRestartRunner(_ machine: Machine) -> Bool {
|
|
machine.active
|
|
&& machine.metadata?.supervisedRestart == true
|
|
&& cliBinaryUpdatedOnDisk(machine.metadata)
|
|
}
|
|
}
|