native macOS codings agent orchestrator prowl.onev.cat
Something went wrong. Try again.
2.3 kB · 75 lines
Swift
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576import Foundationimport ProwlCLIShared
struct ProfilesRuntimeSnapshot { let profiles: [AgentProfile] let probeResults: [AgentProfileRuntime: AgentRuntimeAvailabilityProbeResult]}
final class ProfilesCommandHandler: CommandHandler { typealias SnapshotProvider = @MainActor () throws -> ProfilesRuntimeSnapshot
private let snapshotProvider: SnapshotProvider
init(snapshotProvider: @escaping SnapshotProvider) { self.snapshotProvider = snapshotProvider }
// swiftlint:disable:next async_without_await func handle(envelope: CommandEnvelope) async -> CommandResponse { do { let snapshot = try snapshotProvider() let payload = ProfilesCommandPayload( count: snapshot.profiles.count, profiles: snapshot.profiles.map { profile in ProfilesCommandProfile( id: profile.id.uuidString, name: profile.name, enabled: profile.isEnabled, runtime: profile.runtime.rawValue, availability: availability( for: profile.runtime, probeResult: snapshot.probeResults[profile.runtime] ) ) } ) return try CommandResponse( ok: true, command: "profiles", schemaVersion: "prowl.cli.profiles.v1", data: RawJSON(encoding: payload) ) } catch { return CommandResponse( ok: false, command: "profiles", schemaVersion: "prowl.cli.profiles.v1", error: CommandError( code: CLIErrorCode.profilesFailed, message: "Failed to list Agent Profiles." ) ) } }
private func availability( for runtime: AgentProfileRuntime, probeResult: AgentRuntimeAvailabilityProbeResult? ) -> ProfilesCommandAvailability { guard let probeResult else { return ProfilesCommandAvailability( status: .unknown, reason: "Availability check has not completed" ) } if probeResult.isAvailable { return ProfilesCommandAvailability(status: .available) } let name = AgentRuntimeAdapterRegistry.displayName(for: runtime) return ProfilesCommandAvailability( status: .unavailable, reason: "\(name) is not on your shell's PATH" ) }}