Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
205 lines
7.7 KiB
Swift
205 lines
7.7 KiB
Swift
import Foundation
|
|
import os
|
|
import PeekabooAutomationKit
|
|
import PeekabooBridge
|
|
import PeekabooFoundation
|
|
import Security
|
|
|
|
@MainActor
|
|
final class PeekabooBridgeHostCoordinator {
|
|
static let shared = PeekabooBridgeHostCoordinator()
|
|
|
|
private let logger = Logger(subsystem: "ai.openclaw", category: "PeekabooBridge")
|
|
|
|
private var host: PeekabooBridgeHost?
|
|
private var services: OpenClawPeekabooBridgeServices?
|
|
|
|
private static let legacySocketDirectoryNames = ["clawdbot", "clawdis", "moltbot"]
|
|
|
|
private static var openclawSocketPath: String {
|
|
let fileManager = FileManager.default
|
|
let base = fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask).first
|
|
?? fileManager.homeDirectoryForCurrentUser.appendingPathComponent("Library/Application Support")
|
|
return Self.makeSocketPath(for: "OpenClaw", in: base)
|
|
}
|
|
|
|
private static func makeSocketPath(for directoryName: String, in baseDirectory: URL) -> String {
|
|
baseDirectory
|
|
.appendingPathComponent(directoryName, isDirectory: true)
|
|
.appendingPathComponent(PeekabooBridgeConstants.socketName, isDirectory: false)
|
|
.path
|
|
}
|
|
|
|
private static var legacySocketPaths: [String] {
|
|
let fileManager = FileManager.default
|
|
let base = fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask).first
|
|
?? fileManager.homeDirectoryForCurrentUser.appendingPathComponent("Library/Application Support")
|
|
return Self.legacySocketDirectoryNames.map { Self.makeSocketPath(for: $0, in: base) }
|
|
}
|
|
|
|
func setEnabled(_ enabled: Bool) async {
|
|
if enabled {
|
|
await self.startIfNeeded()
|
|
} else {
|
|
await self.stop()
|
|
}
|
|
}
|
|
|
|
func stop() async {
|
|
guard let host else { return }
|
|
await host.stop()
|
|
self.host = nil
|
|
self.services = nil
|
|
self.logger.info("PeekabooBridge host stopped")
|
|
}
|
|
|
|
private func startIfNeeded() async {
|
|
guard self.host == nil else { return }
|
|
|
|
var allowlistedTeamIDs: Set = ["Y5PE65HELJ"]
|
|
if let teamID = Self.currentTeamID() {
|
|
allowlistedTeamIDs.insert(teamID)
|
|
}
|
|
let allowlistedBundles: Set<String> = []
|
|
|
|
self.ensureLegacySocketSymlinks()
|
|
|
|
let services = OpenClawPeekabooBridgeServices()
|
|
let server = PeekabooBridgeServer(
|
|
services: services,
|
|
hostKind: .gui,
|
|
allowlistedTeams: allowlistedTeamIDs,
|
|
allowlistedBundles: allowlistedBundles)
|
|
|
|
let host = PeekabooBridgeHost(
|
|
socketPath: Self.openclawSocketPath,
|
|
server: server,
|
|
allowedTeamIDs: allowlistedTeamIDs,
|
|
requestTimeoutSec: 10)
|
|
|
|
self.services = services
|
|
self.host = host
|
|
|
|
await host.start()
|
|
self.logger
|
|
.info("PeekabooBridge host started at \(Self.openclawSocketPath, privacy: .public)")
|
|
}
|
|
|
|
private func ensureLegacySocketSymlinks() {
|
|
for legacyPath in Self.legacySocketPaths {
|
|
self.ensureLegacySocketSymlink(at: legacyPath)
|
|
}
|
|
}
|
|
|
|
private func ensureLegacySocketSymlink(at legacyPath: String) {
|
|
let fileManager = FileManager.default
|
|
let legacyDirectory = (legacyPath as NSString).deletingLastPathComponent
|
|
do {
|
|
let directoryAttributes: [FileAttributeKey: Any] = [
|
|
.posixPermissions: 0o700,
|
|
]
|
|
try fileManager.createDirectory(
|
|
atPath: legacyDirectory,
|
|
withIntermediateDirectories: true,
|
|
attributes: directoryAttributes)
|
|
let linkURL = URL(fileURLWithPath: legacyPath)
|
|
let linkValues = try? linkURL.resourceValues(forKeys: [.isSymbolicLinkKey])
|
|
if linkValues?.isSymbolicLink == true {
|
|
let destination = try FileManager.default.destinationOfSymbolicLink(atPath: legacyPath)
|
|
let destinationURL = URL(fileURLWithPath: destination, relativeTo: linkURL.deletingLastPathComponent())
|
|
.standardizedFileURL
|
|
if destinationURL.path == URL(fileURLWithPath: Self.openclawSocketPath).standardizedFileURL.path {
|
|
return
|
|
}
|
|
try fileManager.removeItem(atPath: legacyPath)
|
|
} else if fileManager.fileExists(atPath: legacyPath) {
|
|
try fileManager.removeItem(atPath: legacyPath)
|
|
}
|
|
try fileManager.createSymbolicLink(atPath: legacyPath, withDestinationPath: Self.openclawSocketPath)
|
|
} catch {
|
|
let message = "Failed to create legacy PeekabooBridge socket symlink: \(error.localizedDescription)"
|
|
self.logger
|
|
.debug("\(message, privacy: .public)")
|
|
}
|
|
}
|
|
|
|
private static func currentTeamID() -> String? {
|
|
var code: SecCode?
|
|
guard SecCodeCopySelf(SecCSFlags(), &code) == errSecSuccess,
|
|
let code
|
|
else {
|
|
return nil
|
|
}
|
|
|
|
var staticCode: SecStaticCode?
|
|
guard SecCodeCopyStaticCode(code, SecCSFlags(), &staticCode) == errSecSuccess,
|
|
let staticCode
|
|
else {
|
|
return nil
|
|
}
|
|
|
|
var infoCF: CFDictionary?
|
|
guard SecCodeCopySigningInformation(
|
|
staticCode,
|
|
SecCSFlags(rawValue: kSecCSSigningInformation),
|
|
&infoCF) == errSecSuccess,
|
|
let info = infoCF as? [String: Any]
|
|
else {
|
|
return nil
|
|
}
|
|
|
|
return info[kSecCodeInfoTeamIdentifier as String] as? String
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
private final class OpenClawPeekabooBridgeServices: PeekabooBridgeServiceProviding {
|
|
let permissions: PermissionsService
|
|
let screenCapture: any ScreenCaptureServiceProtocol
|
|
let automation: any UIAutomationServiceProtocol
|
|
let windows: any WindowManagementServiceProtocol
|
|
let applications: any ApplicationServiceProtocol
|
|
let menu: any MenuServiceProtocol
|
|
let dock: any DockServiceProtocol
|
|
let dialogs: any DialogServiceProtocol
|
|
let snapshots: any SnapshotManagerProtocol
|
|
let desktopObservation: any DesktopObservationServiceProtocol
|
|
|
|
init() {
|
|
let logging = LoggingService(subsystem: "ai.openclaw.peekaboo")
|
|
let feedbackClient: any AutomationFeedbackClient = NoopAutomationFeedbackClient()
|
|
|
|
let snapshots = InMemorySnapshotManager(options: .init(
|
|
snapshotValidityWindow: 600,
|
|
maxSnapshots: 50,
|
|
deleteArtifactsOnCleanup: false))
|
|
let applications = ApplicationService(feedbackClient: feedbackClient)
|
|
|
|
let screenCapture = ScreenCaptureService(loggingService: logging)
|
|
let automation = UIAutomationService(
|
|
snapshotManager: snapshots,
|
|
loggingService: logging,
|
|
searchPolicy: .balanced,
|
|
feedbackClient: feedbackClient)
|
|
let menu = MenuService(applicationService: applications, feedbackClient: feedbackClient)
|
|
let screens = ScreenService()
|
|
|
|
self.permissions = PermissionsService()
|
|
self.snapshots = snapshots
|
|
self.applications = applications
|
|
self.screenCapture = screenCapture
|
|
self.automation = automation
|
|
self.windows = WindowManagementService(applicationService: applications, feedbackClient: feedbackClient)
|
|
self.menu = menu
|
|
self.dock = DockService(feedbackClient: feedbackClient)
|
|
self.dialogs = DialogService(feedbackClient: feedbackClient)
|
|
self.desktopObservation = DesktopObservationService(
|
|
screenCapture: screenCapture,
|
|
automation: automation,
|
|
applications: applications,
|
|
menu: menu,
|
|
screens: screens,
|
|
snapshotManager: snapshots)
|
|
}
|
|
}
|