@@ -41,7 +41,12 @@ struct OpenClawApp: App {
4141 }
4242
4343 init ( ) {
44+ let launchPlan = AppLaunchRuntimePlan . current
4445 if let error = AppProfile . current . validationError {
46+ if launchPlan . isElevationHost {
47+ fputs ( " OpenClaw elevation host profile is invalid: \( error . localizedDescription ) \n " , stderr )
48+ Darwin . exit ( 2 )
49+ }
4550 let alert = NSAlert ( )
4651 alert . alertStyle = . critical
4752 alert . messageText = " OpenClaw profile is invalid "
@@ -59,7 +64,7 @@ struct OpenClawApp: App {
5964 }
6065 OpenClawLogging . bootstrapIfNeeded ( )
6166
62- Self . applyAttachOnlyOverrideIfNeeded ( )
67+ Self . applyAttachOnlyOverrideIfNeeded ( plan : launchPlan )
6368 _state = State ( initialValue : AppStateStore . shared )
6469 }
6570
@@ -113,7 +118,7 @@ struct OpenClawApp: App {
113118 }
114119 . onChange ( of : self . state . connectionMode ) { _ , mode in
115120 Task { await ConnectionModeCoordinator . shared . apply ( mode : mode , paused : self . state . isPaused ) }
116- if AppLaunchPresentationPolicy . current . allowsAutomaticPresentation {
121+ if AppLaunchRuntimePlan . current . allowsAutomaticPresentation {
117122 CLIInstallPrompter . shared . checkAndPromptIfNeeded ( reason : " connection-mode " )
118123 }
119124 BrowserProfileImportModel . shared . handleConnectionModeChange ( )
@@ -179,14 +184,13 @@ struct OpenClawApp: App {
179184 : " OpenClaw "
180185 }
181186
182- private static func applyAttachOnlyOverrideIfNeeded ( ) {
183- let args = CommandLine . arguments
184- guard args . contains ( " --attach-only " ) || args . contains ( " --no-launchd " ) else { return }
187+ private static func applyAttachOnlyOverrideIfNeeded ( plan : AppLaunchRuntimePlan ) {
188+ guard plan . attachOnly else { return }
185189 if let error = GatewayLaunchAgentManager . applyAttachOnlyRuntimeOverride ( ) {
186- Self . logger . error ( " attach-only flag failed: \( error , privacy : . public ) " )
190+ self . logger . error ( " attach-only flag failed: \( error , privacy : . public ) " )
187191 return
188192 }
189- Self . logger . info ( " attach-only flag enabled " )
193+ self . logger . info ( " attach-only flag enabled " )
190194 }
191195
192196 private var isGatewaySleeping : Bool {
@@ -454,6 +458,12 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
454458 : DisabledUpdaterController ( )
455459 super . init ( )
456460 if let instanceOwnershipFailure {
461+ if AppLaunchRuntimePlan . current . isElevationHost {
462+ fputs (
463+ " OpenClaw elevation host could not claim its instance lock: \( instanceOwnershipFailure ) \n " ,
464+ stderr )
465+ Darwin . exit ( 2 )
466+ }
457467 let alert = NSAlert ( )
458468 alert . alertStyle = . critical
459469 alert . messageText = " OpenClaw could not claim its instance lock "
@@ -527,6 +537,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
527537 }
528538
529539 func application ( _ : NSApplication , open urls : [ URL ] ) {
540+ guard ! AppLaunchRuntimePlan . current . isElevationHost else { return }
530541 Task { @MainActor in
531542 for url in urls {
532543 await DeepLinkHandler . shared . handle ( url : url )
@@ -535,6 +546,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
535546 }
536547
537548 func applicationShouldHandleReopen ( _ : NSApplication , hasVisibleWindows flag : Bool ) -> Bool {
549+ guard AppLaunchRuntimePlan . current . allowsAutomaticPresentation else { return false }
538550 if flag {
539551 return true
540552 }
@@ -551,13 +563,13 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
551563 return
552564 }
553565 #endif
554- let launchPolicy = AppLaunchPresentationPolicy . current
555- if ! AppProfile . current . isActive {
566+ let launchPlan = AppLaunchRuntimePlan . current
567+ if ! AppProfile . current . isActive , ! launchPlan . isElevationHost {
556568 switch ApplicationRelocator . handleLaunch ( ) {
557569 case . terminating :
558570 return
559571 case let . continueLaunch ( startUpdater ) :
560- if startUpdater {
572+ if startUpdater , launchPlan . allowsUpdater {
561573 if OpenClawConfigFile . gatewayUpdateChannel ( ) == nil {
562574 self . updaterController . startAfterResolvingGatewayUpdateChannel ( )
563575 } else {
@@ -575,10 +587,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
575587 MacNodeModeCoordinator . prepareNodeIdentityProfile (
576588 isExistingInstallation : state . onboardingSeen || state . connectionMode != . unconfigured )
577589 }
578- AppActivationPolicy . apply ( showDockIcon : state ? . showDockIcon ?? false )
590+ AppActivationPolicy . apply ( showDockIcon : launchPlan . allowsDockIcon && ( state ? . showDockIcon ?? false ) )
579591 if let state {
580592 let shouldWaitForConnection = state . connectionMode != . unconfigured
581- if ! shouldWaitForConnection , launchPolicy . allowsAutomaticPresentation {
593+ if ! shouldWaitForConnection , launchPlan . allowsAutomaticPresentation {
582594 Task { @MainActor in
583595 await self . scheduleFirstRunOnboardingIfNeeded ( gatewayConnected : false )
584596 }
@@ -592,34 +604,36 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
592604 await ConnectionModeCoordinator . shared . apply (
593605 mode : state . connectionMode ,
594606 paused : state . isPaused )
595- guard shouldWaitForConnection , launchPolicy . allowsAutomaticPresentation else { return }
607+ guard shouldWaitForConnection , launchPlan . allowsAutomaticPresentation else { return }
596608 await self . scheduleFirstRunOnboardingIfNeeded (
597609 gatewayConnected : ControlChannel . shared . state == . connected )
598610 }
599611 }
600612 TerminationSignalWatcher . shared . start ( )
601- NodePairingApprovalPrompter . shared . start ( )
602- DevicePairingApprovalPrompter . shared . start ( )
603- ExecApprovalsPromptServer . shared . start ( )
604- ExecApprovalsGatewayPrompter . shared . start ( )
605613 MacNodeModeCoordinator . shared . start ( )
606- if let state {
607- CookieSyncManager . shared . start ( state : state )
614+ if launchPlan . allowsInteractiveServices {
615+ NodePairingApprovalPrompter . shared . start ( )
616+ DevicePairingApprovalPrompter . shared . start ( )
617+ ExecApprovalsPromptServer . shared . start ( )
618+ ExecApprovalsGatewayPrompter . shared . start ( )
619+ if let state {
620+ CookieSyncManager . shared . start ( state : state )
621+ }
622+ VoiceWakeGlobalSettingsSync . shared . start ( )
623+ QuickChatController . shared . start ( )
608624 }
609- VoiceWakeGlobalSettingsSync . shared . start ( )
610- QuickChatController . shared . start ( )
611625 Task { PresenceReporter . shared . start ( ) }
612626 Task { await HealthStore . shared . refresh ( onDemand : true ) }
613627 Task { await PortGuardian . shared . sweep ( mode : AppStateStore . shared . connectionMode ) }
614628 AppStateStore . shared . applyPeekabooBridgeHostState ( )
615- if launchPolicy . allowsAutomaticPresentation {
629+ if launchPlan . allowsAutomaticPresentation {
616630 DispatchQueue . main . asyncAfter ( deadline : . now ( ) + 1.0 ) {
617631 if ! PostUpdateController . shared . startIfNeeded ( ) {
618632 CLIInstallPrompter . shared . checkAndPromptIfNeeded ( reason : " launch " )
619633 }
620634 }
621635 }
622- if launchPolicy . allowsAutomaticPresentation {
636+ if launchPlan . allowsAutomaticPresentation {
623637 Task {
624638 try? await Task . sleep ( for : . seconds ( 2 ) )
625639 DashboardManager . shared . preloadIfConfigured ( )
@@ -628,7 +642,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
628642
629643 #if DEBUG
630644 // Screenshot/demo helper: show the pairing panel with sample requests.
631- if launchPolicy . allowsAutomaticPresentation ,
645+ if launchPlan . allowsAutomaticPresentation ,
632646 ProcessInfo . processInfo . environment [ " OPENCLAW_DEBUG_PAIRING_DEMO " ] == " 1 "
633647 {
634648 DispatchQueue . main . asyncAfter ( deadline : . now ( ) + 1.0 ) {
@@ -637,14 +651,14 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
637651 }
638652 #endif
639653 // Developer/testing helper: auto-open chat when launched with --chat (or legacy --webchat).
640- if launchPolicy . shouldAutoOpenChat ( arguments : CommandLine . arguments ) {
654+ if launchPlan . shouldAutoOpenChat ( arguments : CommandLine . arguments ) {
641655 self . webChatAutoLogger . debug ( " Auto-opening chat via CLI flag " )
642656 Task { @MainActor in
643657 let sessionKey = await WebChatManager . shared . preferredSessionKey ( )
644658 WebChatManager . shared . show ( sessionKey : sessionKey )
645659 }
646660 }
647- if launchPolicy . shouldAutoOpenDashboard ( arguments : CommandLine . arguments ) {
661+ if launchPlan . shouldAutoOpenDashboard ( arguments : CommandLine . arguments ) {
648662 self . webChatAutoLogger . info ( " Auto-opening dashboard via CLI flag " )
649663 self . openDashboardAction ( )
650664 }
0 commit comments