How KeyPath installs system services without asking for your password every time.
SMAppService registers the helper. User approves once in System Settings.
XPC for privileged operations. Signature-validated, type-safe.
Helper deploys daemon plist and kanata binary to system paths.
NSXPCConnection to the privileged helper. Manages connection lifecycle, version checks, and routes all XPC calls through HelperProtocol. Wraps SMAppService.daemon() for helper registration via a testable SMAppServiceProtocol seam.public actor HelperManager { var connection: NSXPCConnection? static let helperMachServiceName = "com.keypath.helper" // Every XPC method maps to HelperProtocol func installRequiredRuntimeServices() async throws func recoverRequiredRuntimeServices() async throws func getHelperVersion() async throws -> String }
sudo (debug). In release mode, tries the helper first and falls back to sudo if the helper is unavailable. Pure routing, no domain logic.@MainActor public final class PrivilegedOperationsRouter { enum OperationMode { case privilegedHelper, directSudo } // Release = helper-first, Debug = sudo static var operationMode: OperationMode { #if DEBUG .directSudo #else .privilegedHelper #endif } }
SMAppService registration for the Kanata LaunchDaemon (com.keypath.kanata). Handles status checking, registration, unregistration, and migration from legacy launchctl-based installs.@MainActor public class KanataDaemonManager { nonisolated static let kanataServiceID = "com.keypath.kanata" nonisolated static let kanataPlistName = "com.keypath.kanata.plist" func registerDaemon() throws func unregisterDaemon() async throws func getDaemonStatus() -> SMAppService.Status }
PrivilegedOperationsRouter. The wizard and UI code call this, never the router or helper directly.SMAppService. Both HelperManager and KanataDaemonManager use an injectable smServiceFactory so tests can simulate .notFound, .requiresApproval, and other states without hitting real ServiceManagement IPC.protocol SMAppServiceProtocol: Sendable { var status: SMAppService.Status { get } func register() throws func unregister() async throws }
SMAppService.register() → helper binary copied to /Library/PrivilegedHelperTools/com.keypath.helperHelperManager creates NSXPCConnection(machServiceName:) with HelperProtocol interfacecom.keypath.kanata.plist to /Library/LaunchDaemons/ and loads itgetVersion() over XPC — if mismatch, prompt user to reinstall helper (ADR-014)SMAppService → new binary replaces old → app restart for clean stateHelperProtocolSyncTests enforces this in CI. (ADR-018)InstallerEngine. It owns the orchestration of privileged operations, system inspection, and postcondition enforcement.InstallerEngine (which uses PrivilegedOperationsRouter). Manual launchctl calls bypass signature validation, error handling, and postcondition checks.ServiceHealthChecker to determine if the daemon is actually running and responding.