👾 Open Computer Use – Open-Source Alternative to Codex Computer Use
Swift accessibilityai-agentai-agentsclaude-codecodexcodex-computer-usecomputer-usecomputer-use-agentcross-platformcuadesktop-automationgemini-cligui-automationmacosmcpmodel-context-protocolopen-computer-useopen-computer-use-mcpopenai-codexopencode
Stabilize permission identity across app installs
Leo054bc77c5580
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 510f0aa..a3f8b5d 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -35,6 +35,38 @@ jobs:with:node-version: "22"+ - name: Prepare Open Computer Use signing config+ env:+ OPEN_COMPUTER_USE_CODESIGN_P12_BASE64: ${{ secrets.OPEN_COMPUTER_USE_CODESIGN_P12_BASE64 }}+ OPEN_COMPUTER_USE_CODESIGN_P12_PASSWORD: ${{ secrets.OPEN_COMPUTER_USE_CODESIGN_P12_PASSWORD }}+ OPEN_COMPUTER_USE_CODESIGN_KEYCHAIN_PASSWORD: ${{ secrets.OPEN_COMPUTER_USE_CODESIGN_KEYCHAIN_PASSWORD }}+ OPEN_COMPUTER_USE_CODESIGN_IDENTITY: ${{ secrets.OPEN_COMPUTER_USE_CODESIGN_IDENTITY }}+ run: |+ echo "OPEN_COMPUTER_USE_CODESIGN_MODE=adhoc" >> "${GITHUB_ENV}"++ if [ -z "${OPEN_COMPUTER_USE_CODESIGN_P12_BASE64}" ] || [ -z "${OPEN_COMPUTER_USE_CODESIGN_P12_PASSWORD}" ] || [ -z "${OPEN_COMPUTER_USE_CODESIGN_IDENTITY}" ]; then+ echo "No Open Computer Use signing certificate configured; release artifacts will fall back to ad-hoc signing and may create install-specific macOS permission identities."+ exit 0+ fi++ keychain_password="${OPEN_COMPUTER_USE_CODESIGN_KEYCHAIN_PASSWORD:-${RUNNER_TEMP}-open-computer-use-keychain}"+ cert_path="${RUNNER_TEMP}/open-computer-use-signing.p12"+ keychain_path="${RUNNER_TEMP}/open-computer-use-signing.keychain-db"++ CERT_PATH="${cert_path}" python3 -c 'import base64, os, pathlib; pathlib.Path(os.environ["CERT_PATH"]).write_bytes(base64.b64decode(os.environ["OPEN_COMPUTER_USE_CODESIGN_P12_BASE64"]))'++ security create-keychain -p "${keychain_password}" "${keychain_path}"+ security set-keychain-settings -lut 21600 "${keychain_path}"+ security unlock-keychain -p "${keychain_password}" "${keychain_path}"+ security import "${cert_path}" -k "${keychain_path}" -P "${OPEN_COMPUTER_USE_CODESIGN_P12_PASSWORD}" -T /usr/bin/codesign -T /usr/bin/security+ security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "${keychain_password}" "${keychain_path}"++ {+ echo "OPEN_COMPUTER_USE_CODESIGN_MODE=identity"+ echo "OPEN_COMPUTER_USE_CODESIGN_IDENTITY=${OPEN_COMPUTER_USE_CODESIGN_IDENTITY}"+ echo "OPEN_COMPUTER_USE_CODESIGN_KEYCHAIN=${keychain_path}"+ } >> "${GITHUB_ENV}"+- name: Build npm release artifactsrun: npm run npm:packdiff --git a/README.md b/README.mdindex 8399e8b..0a27ab4 100644--- a/README.md+++ b/README.md@@ -18,7 +18,7 @@ Install it globally first:npm i -g open-computer-use```-Before first use, grant macOS `Accessibility` and `Screen Recording` permission to the `Open Computer Use.app` installed by `npm install -g open-computer-use`. That global npm install location should be treated as the long-term stable permission target. The development copy at `dist/Open Computer Use.app` should only be used as a local debugging fallback, not as the long-term app identity. If you are not sure about the current state, run:+Before first use, grant macOS `Accessibility` and `Screen Recording` permission to the `Open Computer Use.app` you actually plan to keep installed. Official npm / Homebrew / DMG builds should share the same bundle identifier and signing identity so macOS treats them as the same app; unsigned local debug builds can still appear as separate permission entries. If you are not sure about the current state, run:```bashopen-computer-usediff --git a/README.zh-CN.md b/README.zh-CN.mdindex 0180032..245f228 100644--- a/README.zh-CN.md+++ b/README.zh-CN.md@@ -18,7 +18,7 @@npm i -g open-computer-use```-第一次使用前,给 `Open Computer Use.app` 授予 macOS 的 `Accessibility` 和 `Screen Recording` 权限+第一次使用前,给你实际准备长期保留的那个 `Open Computer Use.app` 授予 macOS 的 `Accessibility` 和 `Screen Recording` 权限。正式发布的 npm / Homebrew / DMG 构建应共享同一个 bundle identifier 和签名身份,这样 macOS 才会把它们识别成同一个 app;未正式签名的本地调试构建仍可能单独占一个权限条目。```bashopen-computer-usediff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.mdindex 33ed49f..a214dca 100644--- a/docs/ARCHITECTURE.md+++ b/docs/ARCHITECTURE.md@@ -35,7 +35,7 @@- app bundle 以 `LSUIElement` agent-style 形态运行,默认不在 Dock 暴露常驻图标,但仍可按需显示权限窗口。- 主窗口负责渲染 `Accessibility` / `Screen & System Audio Recording` 两类权限卡片、`Allow` / `Done` 状态和 relaunch 后的状态收敛;当两项权限都已完成时会自动关闭,不再要求用户手动退出。- 辅助 drag panel 会跳转到对应的 `System Settings` 页面;点击 `Allow` 后,panel 会从主窗口里的按钮位置做一段 spring + curved frame 的入场,再落到 `System Settings` 内容区下沿。panel 默认保持在窗口右侧内容区下方居中并固定贴近窗口底边,不再依赖实时扫描权限页内部 `+ / -` 控件行;窗口层级上会显式排在当前 `System Settings` 窗口之上,避免被权限列表内容盖住,同时尽量减少对系统设置自身滚动区域的干扰。panel 内也补了显式返回按钮,允许用户中断当前 guidance、回到 onboarding 主窗口重新选择权限步骤。-- 权限状态优先基于 TCC 持久授权记录判断,避免 CLI 子进程与 GUI app 对授权状态看到不一致的结果;同时会兼容 bundle-id 和路径型授权记录,并在源码启动场景下优先认 npm 全局安装后的稳定 `.app` 路径,仓库内 `dist/` 产物只作为开发兜底。+- 权限状态优先基于 TCC 持久授权记录判断,避免 CLI 子进程与 GUI app 对授权状态看到不一致的结果;同时会兼容 bundle-id 和路径型授权记录,并按统一 bundle identity 去发现当前运行副本、`/Applications`、npm、Homebrew 等渠道的已安装 `.app`。源码态 `dist/` 产物只作为开发兜底;如果没有统一的正式 codesign identity,不同渠道或不同构建产物仍可能在 TCC 里分裂成多个授权条目。### 2. MCP 层diff --git a/docs/CICD.md b/docs/CICD.mdindex bae3915..a68e6e7 100644--- a/docs/CICD.md+++ b/docs/CICD.md@@ -4,9 +4,9 @@## 当前 release 入口-- `scripts/release-package.sh`:构建 universal `Open Computer Use.app`,stage 三个 npm 包目录,并产出 `dist/release/npm/*.tgz` 与 `dist/release/release-manifest.json`。+- `scripts/release-package.sh`:构建 universal `Open Computer Use.app`,stage 三个 npm 包目录,并产出 `dist/release/npm/*.tgz` 与 `dist/release/release-manifest.json`。如果提供统一的 Apple codesign identity,npm 包里的 `.app` 会按同一签名链封装;否则会回退到 ad-hoc signing。- `scripts/build-cursor-motion-dmg.sh`:本地构建 `Cursor Motion.app` 并封装 `dist/release/cursor-motion/CursorMotion-<version>.dmg`,支持 `native` / `arm64` / `x86_64` / `universal`。-- `.github/workflows/release.yml`:支持 push semver tag 自动发布,也支持手动触发;tag push 时会同时跑 npm release 打包逻辑与 `Cursor Motion` 的 DMG 打包,并把 `.dmg` 上传到对应的 GitHub Releases 页面。当前 `Cursor Motion` 这条链路只做 ad-hoc codesign,不包含 notarization。+- `.github/workflows/release.yml`:支持 push semver tag 自动发布,也支持手动触发;tag push 时会同时跑 npm release 打包逻辑与 `Cursor Motion` 的 DMG 打包,并把 `.dmg` 上传到对应的 GitHub Releases 页面。`Open Computer Use` 的 npm 产物会优先使用仓库 secrets 里提供的 codesign 证书导入临时 keychain 后统一签名;若未配置证书则仍回退到 ad-hoc signing。当前 `Cursor Motion` 这条链路仍只做 ad-hoc codesign,不包含 notarization。## 设计原则diff --git a/docs/histories/2026-04/20260420-1558-fix-permission-relaunch-misdetection.md b/docs/histories/2026-04/20260420-1558-fix-permission-relaunch-misdetection.mdnew file mode 100644index 0000000..0dc4608--- /dev/null+++ b/docs/histories/2026-04/20260420-1558-fix-permission-relaunch-misdetection.md@@ -0,0 +1,26 @@+## [2026-04-20 15:58] | Task: 修复权限授权后重开 app 仍误弹 onboarding++### 🤖 Execution Context+* **Agent ID**: `codex`+* **Base Model**: `gpt-5.4`+* **Runtime**: `Codex CLI on macOS`++### 📥 User Query+> allow 授权都完成后,重新打开 app 还会弹出两个都要 `Allow` 的授权窗口;但关掉窗口后再跑 `open-computer-use` 或 `open-computer-use doctor` 又显示两个权限都已经 granted。这个回归是后来引入的,需要修掉。++### 🛠 Changes Overview+**Scope:** `packages/OpenComputerUseKit`, `docs/histories`++**Key Actions:**+- **[Stable Permission Target]**: 把权限目标 bundle 的选择逻辑改成真正优先 npm 全局安装后的稳定 `.app`,不再让当前运行的临时/源码 app copy 抢在前面。+- **[Permission Client Ordering]**: 重新整理 TCC 查询候选,先认稳定 bundle identifier,再认稳定 app 路径,最后再兼容当前运行中的 app 路径,减少开发态路径误导授权状态。+- **[Grant Aggregation Fix]**: TCC 查询不再被第一条命中的 `false` 提前短路;现在会遍历所有候选,只要任一匹配记录已 `granted` 就视为已授权,避免旧路径记录把真实授权盖掉。+- **[Regression Tests]**: 新增单测覆盖“源码/临时 app 重开时仍应沿用稳定安装身份”和“多条候选里任一 granted 即视为 granted”这两个回归点。++### 🧠 Design Intent (Why)+这次回归的根因不是权限真的丢了,而是权限状态读取在 app 重开时又回到了“当前运行 copy 的路径优先 + 第一条命中即返回”的旧行为,导致某些临时路径或旧记录把真正稳定的授权身份遮住。修复目标是让 app mode、`open-computer-use` 和 `doctor` 对同一份稳定授权身份给出一致结论,不再出现“窗口说缺权限,CLI 说已授权”的分叉。++### 📁 Files Modified+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/Permissions.swift`+- `packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift`+- `docs/histories/2026-04/20260420-1558-fix-permission-relaunch-misdetection.md`diff --git a/docs/histories/2026-04/20260420-1608-unify-open-computer-use-app-identity.md b/docs/histories/2026-04/20260420-1608-unify-open-computer-use-app-identity.mdnew file mode 100644index 0000000..0b4e695--- /dev/null+++ b/docs/histories/2026-04/20260420-1608-unify-open-computer-use-app-identity.md@@ -0,0 +1,32 @@+## [2026-04-20 16:08] | Task: 收口 Open Computer Use 的跨渠道 app 身份++### 🤖 Execution Context+* **Agent ID**: `codex`+* **Base Model**: `gpt-5.4`+* **Runtime**: `Codex CLI on macOS`++### 📥 User Query+> `npm i -g open-computer-use && open-computer-use` 拉起的授权,以及仓库里 `./scripts/build-open-computer-use-app.sh debug` / `./dist/Open Computer Use.app/Contents/MacOS/OpenComputerUse` 拉起的授权,被系统识别成两个 app。希望不管从 npm / brew / dmg 等什么渠道安装,identify 都一样,不要再分裂成多个授权对象;另外需要进一步确认 npmjs 上通过 GitHub Actions 打出来的包是否也会影响这个问题。++### 🛠 Changes Overview+**Scope:** `packages/OpenComputerUseKit`, `scripts/`, `.github/workflows/`, `README`, `docs/`++**Key Actions:**+- **[Unified Codesign Path]**: 给 `scripts/build-open-computer-use-app.sh` 补上统一的 codesign 入口,支持显式 identity、自动发现本机 Apple signing identity、以及 ad-hoc/skip 降级,并在 ad-hoc 情况下直接提示 TCC 仍可能把不同构建识别成不同 app。+- **[Channel-Agnostic Bundle Discovery]**: 把权限目标发现从“优先 npm 全局路径”改成“统一发现当前运行副本、`/Applications`、npm、Homebrew 等渠道的同 bundle app,再优先使用稳定安装副本作为权限目标”,减少渠道偏置,同时避免临时运行副本抢在长期授权对象前面。+- **[CI Release Signing]**: 给 `release.yml` 增加可选的证书导入步骤;当配置 `OPEN_COMPUTER_USE_CODESIGN_*` secrets 时,GitHub Actions 打出来的 npm 包会用统一 codesign identity 封装,避免 npmjs 上的 `.app` 因 ad-hoc/unsigned 而继续分裂 TCC 身份。+- **[Docs Sync]**: README、架构和 CI/CD 文档统一改成“正式发布渠道靠同一 bundle id + 同一签名身份收口”,不再把 npm 路径写成唯一长期授权对象。++### 🧠 Design Intent (Why)+macOS 的 TCC 不只看 `CFBundleIdentifier`,还会把 code requirement 一起纳入身份判断。只统一 bundle id 但继续让各个渠道产出 ad-hoc 或未正式签名的 `.app`,权限条目仍会拆开。要真正把 npm / brew / dmg 收成同一个 app,必须让它们共享同一个 bundle identifier 和同一条正式签名链;源码调试态没有这条签名链时,则要明确告诉用户这是降级行为,而不是继续假装“已经是同一个 app”。++### 📁 Files Modified+- `.github/workflows/release.yml`+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/Permissions.swift`+- `packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift`+- `scripts/build-open-computer-use-app.sh`+- `README.md`+- `README.zh-CN.md`+- `docs/ARCHITECTURE.md`+- `docs/CICD.md`+- `docs/histories/2026-04/20260420-1608-unify-open-computer-use-app-identity.md`diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/Permissions.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/Permissions.swiftindex de23669..cde0971 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/Permissions.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/Permissions.swift@@ -100,6 +100,7 @@ public struct PermissionDiagnostics: Sendable {public enum PermissionSupport {public static let bundleDisplayName = "Open Computer Use"public static let bundleIdentifier = "com.ifuryst.opencomputeruse"+ private static let appBundleName = "\(bundleDisplayName).app"private static let npmPackageNames = ["open-computer-use","open-computer-use-mcp",@@ -107,58 +108,153 @@ public enum PermissionSupport {]public static func currentAppBundleURL() -> URL? {- if let bundleURL = resolvedMainAppBundleURL() {- return bundleURL- }-- return preferredInstalledAppBundleURL() ?? fallbackDevelopmentAppBundleURL()+ preferredPermissionAppBundleURL(+ preferredInstalledBundleURL: preferredInstalledAppBundleURL(),+ runningBundleURL: resolvedMainAppBundleURL(),+ fallbackDevelopmentBundleURL: fallbackDevelopmentAppBundleURL()+ )}public static func currentPermissionClients() -> [PermissionClientRecord] {- var records: [PermissionClientRecord] = []+ permissionClients(+ primaryBundleURL: currentAppBundleURL(),+ runningBundleURL: resolvedMainAppBundleURL(),+ mainBundleIdentifier: Bundle.main.bundleIdentifier+ )+ }++ public static func openSystemSettings(for permission: SystemPermissionKind) {+ NSWorkspace.shared.open(permission.settingsURL)+ }++ public static func requestAccessibilityPrompt() {+ let options: NSDictionary = ["AXTrustedCheckOptionPrompt": true]+ _ = AXIsProcessTrustedWithOptions(options)+ }- if let bundleURL = currentAppBundleURL()?.standardizedFileURL {- records.append(PermissionClientRecord(identifier: bundleURL.path, type: 1))+ static func preferredPermissionAppBundleURL(+ preferredInstalledBundleURL: URL?,+ runningBundleURL: URL?,+ fallbackDevelopmentBundleURL: URL?+ ) -> URL? {+ preferredInstalledBundleURL ?? runningBundleURL ?? fallbackDevelopmentBundleURL+ }- if let bundle = Bundle(url: bundleURL),- let resolvedBundleIdentifier = bundle.bundleIdentifier {- records.append(PermissionClientRecord(identifier: resolvedBundleIdentifier, type: 0))+ static func permissionClients(+ primaryBundleURL: URL?,+ runningBundleURL: URL?,+ mainBundleIdentifier: String?,+ canonicalBundleIdentifier: String = bundleIdentifier+ ) -> [PermissionClientRecord] {+ var records: [PermissionClientRecord] = []+ var seen = Set<PermissionClientRecord>()++ func append(_ record: PermissionClientRecord?) {+ guard let record, seen.insert(record).inserted else {+ return}- } else if let mainBundleIdentifier = Bundle.main.bundleIdentifier {- records.append(PermissionClientRecord(identifier: mainBundleIdentifier, type: 0))+ records.append(record)}- if !records.contains(where: { $0.identifier == bundleIdentifier && $0.type == 0 }) {- records.append(PermissionClientRecord(identifier: bundleIdentifier, type: 0))+ append(PermissionClientRecord(identifier: canonicalBundleIdentifier, type: 0))++ if let mainBundleIdentifier, mainBundleIdentifier != canonicalBundleIdentifier {+ append(PermissionClientRecord(identifier: mainBundleIdentifier, type: 0))+ }++ if let primaryBundleURL {+ append(PermissionClientRecord(identifier: primaryBundleURL.standardizedFileURL.path, type: 1))+ }++ if let runningBundleURL {+ append(PermissionClientRecord(identifier: runningBundleURL.standardizedFileURL.path, type: 1))}return records}- public static func openSystemSettings(for permission: SystemPermissionKind) {- NSWorkspace.shared.open(permission.settingsURL)- }+ static func preferredInstalledAppBundleURL(candidates: [URL]) -> URL? {+ var seenPaths = Set<String>()- public static func requestAccessibilityPrompt() {- let options: NSDictionary = ["AXTrustedCheckOptionPrompt": true]- _ = AXIsProcessTrustedWithOptions(options)+ for candidate in candidates {+ let standardizedURL = candidate.standardizedFileURL+ if seenPaths.insert(standardizedURL.path).inserted {+ return standardizedURL+ }+ }++ return nil}private static func preferredInstalledAppBundleURL() -> URL? {+ let fileManager = FileManager.default+ var candidates: [URL] = []+ var seenPaths = Set<String>()++ func appendCandidate(_ bundleURL: URL?) {+ guard let bundleURL else {+ return+ }++ let standardizedURL = bundleURL.standardizedFileURL+ guard seenPaths.insert(standardizedURL.path).inserted else {+ return+ }++ guard isValidAppBundle(standardizedURL) else {+ return+ }++ candidates.append(standardizedURL)+ }++ appendCandidate(NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleIdentifier))++ for directory in standardApplicationDirectories() {+ appendCandidate(directory.appendingPathComponent(appBundleName, isDirectory: true))+ }+for nodeModulesRoot in npmGlobalNodeModulesRoots() {for packageName in npmPackageNames {- let candidate = nodeModulesRoot+ appendCandidate(+ nodeModulesRoot.appendingPathComponent(packageName, isDirectory: true).appendingPathComponent("dist", isDirectory: true)- .appendingPathComponent("\(bundleDisplayName).app", isDirectory: true)+ .appendingPathComponent(appBundleName, isDirectory: true)+ )+ }+ }- if isValidAppBundle(candidate) {- return candidate+ for prefix in homebrewPrefixes() {+ appendCandidate(prefix+ .appendingPathComponent("Caskroom", isDirectory: true)+ .appendingPathComponent("open-computer-use", isDirectory: true)+ .appendingPathComponent(appBundleName, isDirectory: true)+ )++ let caskroomRoot = prefix+ .appendingPathComponent("Caskroom", isDirectory: true)+ .appendingPathComponent("open-computer-use", isDirectory: true)+ if let versionDirectories = try? fileManager.contentsOfDirectory(at: caskroomRoot, includingPropertiesForKeys: nil, options: [.skipsHiddenFiles]) {+ for versionDirectory in versionDirectories {+ appendCandidate(versionDirectory.appendingPathComponent(appBundleName, isDirectory: true))+ }+ }++ let cellarRoot = prefix+ .appendingPathComponent("Cellar", isDirectory: true)+ .appendingPathComponent("open-computer-use", isDirectory: true)+ if let versionDirectories = try? fileManager.contentsOfDirectory(at: cellarRoot, includingPropertiesForKeys: nil, options: [.skipsHiddenFiles]) {+ for versionDirectory in versionDirectories {+ appendCandidate(versionDirectory+ .appendingPathComponent("dist", isDirectory: true)+ .appendingPathComponent(appBundleName, isDirectory: true)+ )}}}- return nil+ return preferredInstalledAppBundleURL(candidates: candidates)}private static func fallbackDevelopmentAppBundleURL() -> URL? {@@ -171,7 +267,7 @@ public enum PermissionSupport {while directoryURL.path != "/" {let candidate = directoryURL.appendingPathComponent("dist", isDirectory: true)- .appendingPathComponent("\(bundleDisplayName).app", isDirectory: true)+ .appendingPathComponent(appBundleName, isDirectory: true)if isValidAppBundle(candidate) {return candidate@@ -188,11 +284,48 @@ public enum PermissionSupport {}private static func npmGlobalNodeModulesRoots() -> [URL] {+ let candidatePrefixes = packageManagerPrefixes()+ let roots = candidatePrefixes.map {+ $0.appendingPathComponent("lib", isDirectory: true)+ .appendingPathComponent("node_modules", isDirectory: true)+ .standardizedFileURL+ }++ return uniqueStandardizedURLs(roots)+ }++ private static func standardApplicationDirectories() -> [URL] {+ let fileManager = FileManager.default+ let directories = fileManager.urls(for: .applicationDirectory, in: .allDomainsMask).map {+ $0.standardizedFileURL+ }++ return uniqueStandardizedURLs(directories)+ }++ private static func homebrewPrefixes() -> [URL] {let env = ProcessInfo.processInfo.environment- let candidatePrefixes = [+ let prefixes = [+ env["HOMEBREW_PREFIX"],env["npm_config_prefix"],env["NPM_CONFIG_PREFIX"],env["PREFIX"],+ "/opt/homebrew",+ "/usr/local",+ ]+ .compactMap { $0 }+ .map { URL(fileURLWithPath: $0, isDirectory: true) }++ return uniqueStandardizedURLs(prefixes)+ }++ private static func packageManagerPrefixes() -> [URL] {+ let env = ProcessInfo.processInfo.environment+ let prefixes = [+ env["npm_config_prefix"],+ env["NPM_CONFIG_PREFIX"],+ env["PREFIX"],+ env["HOMEBREW_PREFIX"],NSHomeDirectory() + "/.npm-global","/opt/homebrew","/usr/local",@@ -200,20 +333,21 @@ public enum PermissionSupport {.compactMap { $0 }.map { URL(fileURLWithPath: $0, isDirectory: true) }- var roots: [URL] = []- var seenPaths = Set<String>()+ return uniqueStandardizedURLs(prefixes)+ }- for prefix in candidatePrefixes {- let root = prefix.appendingPathComponent("lib", isDirectory: true)- .appendingPathComponent("node_modules", isDirectory: true)- .standardizedFileURL+ private static func uniqueStandardizedURLs(_ urls: [URL]) -> [URL] {+ var uniqueURLs: [URL] = []+ var seenPaths = Set<String>()- if seenPaths.insert(root.path).inserted {- roots.append(root)+ for url in urls {+ let standardizedURL = url.standardizedFileURL+ if seenPaths.insert(standardizedURL.path).inserted {+ uniqueURLs.append(standardizedURL)}}- return roots+ return uniqueURLs}private static func resolvedMainAppBundleURL() -> URL? {@@ -242,11 +376,15 @@ public enum PermissionSupport {}}-public struct PermissionClientRecord: Sendable, Equatable {+public struct PermissionClientRecord: Sendable, Equatable, Hashable {public let identifier: Stringpublic let type: Int32}+func tccAuthorizationGranted(authValues: [Int32?]) -> Bool {+ authValues.contains(2)+}+private struct TCCAuthorizationStore {let accessibility: Bool?let screenRecording: Bool?@@ -296,6 +434,8 @@ private struct TCCDatabase {LIMIT 1;"""+ var authValues: [Int32?] = []+for client in clients {var statement: OpaquePointer?guard sqlite3_prepare_v2(database, query, -1, &statement, nil) == SQLITE_OK else {@@ -310,14 +450,14 @@ private struct TCCDatabase {sqlite3_bind_int(statement, 3, client.type)if sqlite3_step(statement) == SQLITE_ROW {- let authorized = sqlite3_column_int(statement, 0) == 2+ authValues.append(sqlite3_column_int(statement, 0))sqlite3_finalize(statement)- return authorized+ continue}sqlite3_finalize(statement)}- return false+ return tccAuthorizationGranted(authValues: authValues)}}diff --git a/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift b/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swiftindex ac45400..afaf91b 100644--- a/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift+++ b/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift@@ -75,6 +75,58 @@ final class OpenComputerUseKitTests: XCTestCase {XCTAssertTrue(diagnostics.missingPermissions.isEmpty)}+ func testPreferredPermissionAppBundleURLPrefersInstalledCopyOverTransientRunningCopy() {+ let installed = URL(fileURLWithPath: "/opt/homebrew/lib/node_modules/open-computer-use/dist/Open Computer Use.app")+ let running = URL(fileURLWithPath: "/Users/example/projects/open-codex-computer-use/dist/Open Computer Use.app")+ let fallback = URL(fileURLWithPath: "/Users/example/projects/open-codex-computer-use-debug/dist/Open Computer Use.app")++ let resolved = PermissionSupport.preferredPermissionAppBundleURL(+ preferredInstalledBundleURL: installed,+ runningBundleURL: running,+ fallbackDevelopmentBundleURL: fallback+ )++ XCTAssertEqual(resolved, installed)+ }++ func testPreferredInstalledAppBundleURLUsesFirstDiscoveredInstalledCopy() {+ let applications = URL(fileURLWithPath: "/Applications/Open Computer Use.app")+ let npm = URL(fileURLWithPath: "/opt/homebrew/lib/node_modules/open-computer-use/dist/Open Computer Use.app")+ let duplicateApplications = URL(fileURLWithPath: "/Applications/Open Computer Use.app")++ let resolved = PermissionSupport.preferredInstalledAppBundleURL(+ candidates: [applications, npm, duplicateApplications]+ )++ XCTAssertEqual(resolved, applications)+ }++ func testPermissionClientsKeepStableBundleIdentityAheadOfTransientAppPath() {+ let installed = URL(fileURLWithPath: "/opt/homebrew/lib/node_modules/open-computer-use/dist/Open Computer Use.app")+ let running = URL(fileURLWithPath: "/Users/example/projects/open-codex-computer-use/dist/Open Computer Use.app")++ let clients = PermissionSupport.permissionClients(+ primaryBundleURL: installed,+ runningBundleURL: running,+ mainBundleIdentifier: PermissionSupport.bundleIdentifier+ )++ XCTAssertEqual(+ clients,+ [+ PermissionClientRecord(identifier: PermissionSupport.bundleIdentifier, type: 0),+ PermissionClientRecord(identifier: installed.path, type: 1),+ PermissionClientRecord(identifier: running.path, type: 1),+ ]+ )+ }++ func testTCCAuthorizationGrantedTreatsAnyGrantedCandidateAsGranted() {+ XCTAssertTrue(tccAuthorizationGranted(authValues: [0, 2]))+ XCTAssertFalse(tccAuthorizationGranted(authValues: [0, nil]))+ XCTAssertFalse(tccAuthorizationGranted(authValues: []))+ }+func testKeyPressParserSupportsCommandStyleChord() throws {let parsed = try KeyPressParser.parse("super+c")XCTAssertEqual(parsed.displayValue, "c")diff --git a/scripts/build-open-computer-use-app.sh b/scripts/build-open-computer-use-app.shindex 20458ad..58c85a3 100755--- a/scripts/build-open-computer-use-app.sh+++ b/scripts/build-open-computer-use-app.sh@@ -5,6 +5,9 @@ set -euo pipefailrepo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"configuration="debug"arch_mode="native"+codesign_mode="${OPEN_COMPUTER_USE_CODESIGN_MODE:-auto}"+codesign_identity="${OPEN_COMPUTER_USE_CODESIGN_IDENTITY:-}"+codesign_keychain="${OPEN_COMPUTER_USE_CODESIGN_KEYCHAIN:-}"usage() {cat <<'EOF'@@ -13,6 +16,11 @@ Usage: ./scripts/build-open-computer-use-app.sh [debug|release] [--configurationExamples:./scripts/build-open-computer-use-app.sh debug./scripts/build-open-computer-use-app.sh --configuration release --arch universal++Environment:+ OPEN_COMPUTER_USE_CODESIGN_MODE=auto|identity|adhoc|none+ OPEN_COMPUTER_USE_CODESIGN_IDENTITY="Developer ID Application: Example, Inc. (TEAMID)"+ OPEN_COMPUTER_USE_CODESIGN_KEYCHAIN=/path/to/signing.keychain-dbEOF}@@ -60,6 +68,11 @@ if [[ "${arch_mode}" != "native" && "${arch_mode}" != "arm64" && "${arch_mode}"exit 1fi+if [[ "${codesign_mode}" != "auto" && "${codesign_mode}" != "identity" && "${codesign_mode}" != "adhoc" && "${codesign_mode}" != "none" ]]; then+ echo "Unsupported OPEN_COMPUTER_USE_CODESIGN_MODE: ${codesign_mode}" >&2+ exit 1+fi+read_package_version() {python3 - "${repo_root}/plugins/open-computer-use/.codex-plugin/plugin.json" <<'PY'import json@@ -91,6 +104,85 @@ build_binary() {printf '%s/OpenComputerUse\n' "${binary_dir}"}+find_codesign_identity() {+ local prefix="${1:-}"+ local -a args=(find-identity -v -p codesigning)++ if [[ -n "${codesign_keychain}" ]]; then+ args+=("${codesign_keychain}")+ fi++ security "${args[@]}" 2>/dev/null \+ | sed -n "s/.*\"\\(${prefix}: .*\\)\"/\1/p" \+ | head -n 1+}++resolve_codesign_identity() {+ case "${codesign_mode}" in+ none)+ return 1+ ;;+ adhoc)+ printf '%s\n' "-"+ return 0+ ;;+ identity)+ if [[ -z "${codesign_identity}" ]]; then+ echo "OPEN_COMPUTER_USE_CODESIGN_IDENTITY is required when OPEN_COMPUTER_USE_CODESIGN_MODE=identity" >&2+ exit 1+ fi+ printf '%s\n' "${codesign_identity}"+ return 0+ ;;+ auto)+ if [[ -n "${codesign_identity}" ]]; then+ printf '%s\n' "${codesign_identity}"+ return 0+ fi++ local discovered_identity+ discovered_identity="$(find_codesign_identity "Developer ID Application")"+ if [[ -n "${discovered_identity}" ]]; then+ printf '%s\n' "${discovered_identity}"+ return 0+ fi++ discovered_identity="$(find_codesign_identity "Apple Development")"+ if [[ -n "${discovered_identity}" ]]; then+ printf '%s\n' "${discovered_identity}"+ return 0+ fi++ printf '%s\n' "-"+ return 0+ ;;+ esac+}++codesign_app_bundle() {+ local app_path="${1:-}"+ local identity=""++ if ! identity="$(resolve_codesign_identity)"; then+ echo "Skipping codesign for ${app_path} (OPEN_COMPUTER_USE_CODESIGN_MODE=none)" >&2+ return+ fi++ local -a args=(--force --deep --sign "${identity}")++ if [[ -n "${codesign_keychain}" && "${identity}" != "-" ]]; then+ args+=(--keychain "${codesign_keychain}")+ fi++ codesign "${args[@]}" "${app_path}" >/dev/null++ if [[ "${identity}" == "-" ]]; then+ echo "Signed ${app_path} with ad-hoc identity; macOS TCC may still treat separately built copies as different app identities until a stable Apple signing identity is configured." >&2+ else+ echo "Signed ${app_path} with ${identity}" >&2+ fi+}+cd "${repo_root}"package_version="$(read_package_version)"@@ -176,5 +268,6 @@ cat > "${contents_dir}/Info.plist" <<PLISTPLISTplutil -lint "${contents_dir}/Info.plist" >/dev/null+codesign_app_bundle "${app_root}"echo "Built ${app_root} (${arch_mode}, ${configuration})"