diff --git a/.agents/notes/implemented/architecture/2026-10-25-cua-bundle-id-consent.i18n.yaml b/.agents/notes/implemented/architecture/2026-10-25-cua-bundle-id-consent.i18n.yaml index 47839dbec9..7a21fc65bd 100644 --- a/.agents/notes/implemented/architecture/2026-10-25-cua-bundle-id-consent.i18n.yaml +++ b/.agents/notes/implemented/architecture/2026-10-25-cua-bundle-id-consent.i18n.yaml @@ -9,8 +9,8 @@ en: bb387fc89c1c578c zh: 947456baea45cc95 /agent-note-macos-consent-shared-by-bundle-identifier/decision: - en: 36daa80b5b60098c - zh: 3bb53a14d04ed829 + en: 7b1bbab1f95b7610 + zh: 434e7a3fba81174b /agent-note-macos-consent-shared-by-bundle-identifier/alternatives-considered: en: 637b1fd2bafb1b28 zh: 06d882818ffaf800 diff --git a/.agents/notes/implemented/architecture/2026-10-25-cua-bundle-id-consent.md b/.agents/notes/implemented/architecture/2026-10-25-cua-bundle-id-consent.md index 65f88e2ac1..b5cfc122cd 100644 --- a/.agents/notes/implemented/architecture/2026-10-25-cua-bundle-id-consent.md +++ b/.agents/notes/implemented/architecture/2026-10-25-cua-bundle-id-consent.md @@ -12,7 +12,7 @@ Users who install multiple versions of one application want one permission decis macOS application consent uses the exact, case-sensitive native bundle identifier. The helper hashes `macos:bundle-id:` followed by that identifier into `CuaApplicationId`. When a bundle identifier exists, installation paths, versions and signatures do not distinguish grants. Otherwise, the helper hashes `macos:executable-path:` followed by the canonical executable path. Both identities support saved access; path identities survive restart and in-place updates, while a different path requires a new decision. Conversation decisions and saved grants retain the scopes and revocation behavior of [profile consent storage](2026-10-19-cua-profile-consent-storage.md). -This supersedes the executable/signature identity choice in [application consent](2026-09-26-cua-application-consent.md); that note still owns enforcement and human decisions. The running process path comes from the operating system. Missing catalog path metadata does not block consent when that process path is available. If the runtime bundle identifier is unavailable, a reported application bundle can supply it only when its main executable matches the process path; otherwise the executable path identifies the grant. Native process, executable-location and window checks continue to bind each handle to its selected target. Launch checks reread the bundle identifier and executable path from disk; they do not fingerprint executable content. Replacing bytes at the same path while retaining the identifier or path identity therefore retains consent, including during an approval wait. +This supersedes the executable/signature identity choice in [application consent](2026-09-26-cua-application-consent.md); that note still owns enforcement and human decisions. The running process path comes from the operating system. A valid runtime bundle identifier does not depend on path-query success. Missing paths omit optional grant metadata; they never substitute a cached catalog path. When both bundle identity and process path are unavailable, consent fails with the path query cause. Process identity must still be verified, and any available process path must match the selected target. Missing catalog path metadata does not block consent when the process path is available. If the runtime bundle identifier is unavailable, a reported application bundle can supply it only when its main executable matches the process path; otherwise the executable path identifies the grant. Native process, executable-location and window checks continue to bind each handle to its selected target. Launch checks reread the bundle identifier and executable path from disk; they do not fingerprint executable content. Replacing bytes at the same path while retaining the identifier or path identity therefore retains consent, including during an approval wait. The identity prefixes separate new grants from old path/signature, process-instance and executable-content digests. Old grants remain removable but do not grant access to new bundle identities; users decide again before permission covers other installations. diff --git a/.agents/notes/implemented/architecture/2026-10-25-cua-bundle-id-consent.zh.md b/.agents/notes/implemented/architecture/2026-10-25-cua-bundle-id-consent.zh.md index 6c51e65ea7..bfc0bc5020 100644 --- a/.agents/notes/implemented/architecture/2026-10-25-cua-bundle-id-consent.zh.md +++ b/.agents/notes/implemented/architecture/2026-10-25-cua-bundle-id-consent.zh.md @@ -12,7 +12,7 @@ Status: implemented macOS 应用授权使用原生应用提供的、区分大小写的完整 Bundle ID。helper 将 `macos:bundle-id:` 和该标识连接后计算摘要,生成 `CuaApplicationId`。有 Bundle ID 时,安装路径、版本和签名不区分授权。否则,helper 对 `macos:executable-path:` 与规范化可执行路径计算摘要。两种身份都支持长期许可;路径身份在重启和原地更新后保持不变,另一个路径需要新的决定。会话决定和长期许可保留[profile 授权存储](2026-10-19-cua-profile-consent-storage.zh.md)规定的范围和撤销行为。 -本决策取代[应用授权](2026-09-26-cua-application-consent.zh.md)中的可执行文件和签名身份选择,原记录仍负责执行检查与用户决定。运行进程的可执行路径由操作系统提供。只要能取得实际进程路径,应用目录信息中缺少路径不会阻止授权。运行时无法取得 Bundle ID 时,仅在其报告的应用 bundle 主可执行文件与进程路径一致时读取该标识,否则按可执行路径识别授权。原生进程、可执行文件位置和窗口检查继续把每个句柄绑定到所选目标。启动检查从磁盘重新读取 Bundle ID 和可执行路径,但不计算可执行内容指纹。因此,在相同路径下替换内容且保留相同标识或路径身份时,许可仍会沿用,包括等待用户批准期间的替换。 +本决策取代[应用授权](2026-09-26-cua-application-consent.zh.md)中的可执行文件和签名身份选择,原记录仍负责执行检查与用户决定。运行进程的可执行路径由操作系统提供。有效的运行时 Bundle ID 不依赖路径查询成功。无法取得路径时省略授权记录中的可选路径信息,不用缓存的应用目录路径代替。Bundle ID 和实际路径均不可用时,授权失败并报告路径查询原因。进程身份仍须验证,可取得的实际路径仍须与所选目标一致。只要能取得实际进程路径,应用目录信息中缺少路径不会阻止授权。运行时无法取得 Bundle ID 时,仅在其报告的应用 bundle 主可执行文件与进程路径一致时读取该标识,否则按可执行路径识别授权。原生进程、可执行文件位置和窗口检查继续把每个句柄绑定到所选目标。启动检查从磁盘重新读取 Bundle ID 和可执行路径,但不计算可执行内容指纹。因此,在相同路径下替换内容且保留相同标识或路径身份时,许可仍会沿用,包括等待用户批准期间的替换。 身份前缀将新授权与旧的路径和签名、进程实例、可执行内容摘要分开。旧授权仍可撤销,但不能授予新 Bundle ID 身份访问权限;许可覆盖其他安装副本前,需要用户重新决定。 diff --git a/docs/upgrade-guide/v0.2.1-rc.3/cua-bundle-id-consent/guide.i18n.yaml b/docs/upgrade-guide/v0.2.1-rc.3/cua-bundle-id-consent/guide.i18n.yaml index 0c2f0aa4b5..c86fcc5009 100644 --- a/docs/upgrade-guide/v0.2.1-rc.3/cua-bundle-id-consent/guide.i18n.yaml +++ b/docs/upgrade-guide/v0.2.1-rc.3/cua-bundle-id-consent/guide.i18n.yaml @@ -9,8 +9,8 @@ en: d24696e5f85e9144 zh: 184f7ebd8b8880df /macos-computer-use-application-identity/change: - en: 9ee94f2635015c1c - zh: 679e0f6a410b9728 + en: 7edc0de236633686 + zh: 08afc35393c95484 /macos-computer-use-application-identity/migration: en: 9c13aeec5e544d36 zh: da697d3ee5a4637f diff --git a/docs/upgrade-guide/v0.2.1-rc.3/cua-bundle-id-consent/guide.md b/docs/upgrade-guide/v0.2.1-rc.3/cua-bundle-id-consent/guide.md index c0163d7664..c1010bf678 100644 --- a/docs/upgrade-guide/v0.2.1-rc.3/cua-bundle-id-consent/guide.md +++ b/docs/upgrade-guide/v0.2.1-rc.3/cua-bundle-id-consent/guide.md @@ -9,7 +9,7 @@ English | [中文](guide.zh.md) ## Change -Application grants use the case-sensitive native bundle identifier. Versions and copies at different paths share permission and revocation, regardless of signing. Applications without a bundle identifier use their canonical executable path and can also receive always-allow grants. Restarting or replacing the executable at that path retains consent; moving it requires renewed consent. The profile storage and conversation scopes are unchanged. +Application grants use the case-sensitive native bundle identifier. Versions and copies at different paths share permission and revocation, regardless of signing. Applications without a bundle identifier use their canonical executable path and can also receive always-allow grants. Restarting or replacing the executable at that path retains consent; moving it requires renewed consent. A valid running bundle identifier does not require an executable path. Grant records can omit executablePath, and the permission page then shows the name without a path tooltip or icon. Existing records remain readable; older versions that require this field cannot read new pathless records. The profile storage location and conversation scopes are unchanged. This affects macOS users with saved path/signature grants, including grants imported from the legacy `allowedApps` configuration. Those grants do not match the new identities. They remain visible and removable but do not authorize other installations automatically. Old and new records can show the same name and path; the permission page does not distinguish them. Another program declaring an approved bundle identifier or replacing an executable at an approved fallback path inherits permission; this policy does not authenticate publishers. diff --git a/docs/upgrade-guide/v0.2.1-rc.3/cua-bundle-id-consent/guide.zh.md b/docs/upgrade-guide/v0.2.1-rc.3/cua-bundle-id-consent/guide.zh.md index f42405ca01..c3b9103501 100644 --- a/docs/upgrade-guide/v0.2.1-rc.3/cua-bundle-id-consent/guide.zh.md +++ b/docs/upgrade-guide/v0.2.1-rc.3/cua-bundle-id-consent/guide.zh.md @@ -9,7 +9,7 @@ description: macOS Computer Use 授权改用 Bundle ID,旧应用身份需要 ## 变更 -应用授权使用原生应用提供的、区分大小写的 Bundle ID。不同路径的版本和副本共用许可与撤销决定,不受签名状态影响。缺少 Bundle ID 的应用使用规范化可执行路径,也可以“始终允许”。在该路径重启或替换可执行文件会沿用许可,移动文件则需重新授权。profile 存储和对话范围保持不变。 +应用授权使用原生应用提供的、区分大小写的 Bundle ID。不同路径的版本和副本共用许可与撤销决定,不受签名状态影响。缺少 Bundle ID 的应用使用规范化可执行路径,也可以“始终允许”。在该路径重启或替换可执行文件会沿用许可,移动文件则需重新授权。运行中的有效 Bundle ID 不依赖可执行路径。授权记录可以省略 executablePath,权限页此时显示名称,不显示路径提示或图标。已有记录仍可读取,要求该字段的旧版本无法读取缺少路径的新记录。profile 存储位置和对话范围保持不变。 受影响的是保存过路径和签名授权的 macOS 用户,包括通过旧 `allowedApps` 配置导入授权的用户。这些授权不匹配新身份。旧记录仍可查看和撤销,但不会自动授权其他安装副本。新旧条目可能显示相同名称和路径,权限页没有区分它们。其他程序声明已批准的 Bundle ID,或替换路径授权对应的可执行文件时,也会继承许可,这项规则不验证发布者身份。 diff --git a/packages/experimental/cua-macos/README.i18n.yaml b/packages/experimental/cua-macos/README.i18n.yaml index 9ea9468a23..fc17156479 100644 --- a/packages/experimental/cua-macos/README.i18n.yaml +++ b/packages/experimental/cua-macos/README.i18n.yaml @@ -12,11 +12,11 @@ en: 4549f02fc53854a5 zh: 6f74f1130b6623a8 /deepseek-ai-dsh-experimental-cua-macos/table-of-contents: - en: ce05c98afbe694b4 - zh: d4e30ee79d4cb08f + en: 02455cf3360adcec + zh: 6c8cb57c12b1b68d /deepseek-ai-dsh-experimental-cua-macos/use-this-package: - en: f309b70a6f669ae0 - zh: 1fe4c4ba0a7c3045 + en: 50c7988dbf05a059 + zh: 570f8691d0c734c5 /deepseek-ai-dsh-experimental-cua-macos/use-this-package/connect-an-external-execution-environment: en: 786b8fd630b11e5f zh: 55143f15486afce8 @@ -45,8 +45,8 @@ en: a2c9acb5a4320dda zh: e8d1586af60215c4 /deepseek-ai-dsh-experimental-cua-macos/known-limitations-and-deferred-work: - en: 93de44ec35281188 - zh: 80405135f3e1669a + en: 6081dbea9d334488 + zh: 1145f2b0692f2425 /deepseek-ai-dsh-experimental-cua-macos/known-limitations-and-deferred-work/dev-note: en: b836f01bd0bceb4a zh: 8122fa08b2aa95fa diff --git a/packages/experimental/cua-macos/README.md b/packages/experimental/cua-macos/README.md index df6c1f785b..4195769515 100644 --- a/packages/experimental/cua-macos/README.md +++ b/packages/experimental/cua-macos/README.md @@ -20,7 +20,7 @@ Inspect macOS permissions, select running applications and windows, read accessi - [Known Limitations and Deferred Work](#known-limitations-and-deferred-work) - [Dev Note](#dev-note) -The helper supplies bounded 64-pixel PNG application icons for permission prompts and saved-application lists. Icon reads do not launch an application or inspect its windows; the native bundle identifier determines reusable consent. +The helper supplies bounded 64-pixel PNG application icons for permission prompts and saved-application lists. Icon reads do not launch an application or inspect its windows; icons do not determine reusable consent. The shared helper queries the process macOS considers responsible for it and captures that application’s name and icon before announcing readiness. A Desktop app launched from Terminal can therefore identify Terminal even when another GUI application sits between it and the helper. Permission queries retain this metadata after the responsible application exits and across connections sharing the helper. If the system query or application metadata is unavailable, the field is omitted and the UI uses the system prompt for guidance. @@ -67,7 +67,7 @@ Keypad names (`KP_0` through `KP_9`, `KP_Enter`, and keypad operators) retain th Agent disposal and plugin unload cancel and await the complete tool call, including image admission and attachment storage. An image write already in progress must settle before disposal returns; a canceled call cannot return a successful screenshot. -Application consent is enforced before AX reads, window-title reads, screenshots, activation, and input through the CUA tool. The first selection asks the human for session access, denial, or saved access when profile persistence is available. Session access is stored by conversation and application identity and survives DSH restart and Computer Use disablement. Other conversations require their own consent. Application identities use the case-sensitive bundle identifier, so versions and copies at different paths share consent and revocation regardless of signing. Without a bundle identifier, consent uses the canonical executable path. Restarting or updating at that path retains consent; moving or copying the executable to another path requires a new decision. This policy does not authenticate the publisher: another program declaring the same identifier, or replacing an approved executable at the same fallback path, inherits consent. Denial prevents repeated prompts in that session. Revocation reads and removes saved access in the same queue as grant creation, invalidates each affected Agent connection, and awaits its native cleanup without replaying input. Every app handle on those Agent connections becomes unusable; other applications need fresh selection, but their session and saved grants remain reusable. See the [application consent decision](../../../.agents/notes/implemented/architecture/2026-09-26-cua-application-consent.md). These checks govern CUA calls; persistent PTC and separately authorized shell tools are not an operating-system sandbox. +Application consent is enforced before AX reads, window-title reads, screenshots, activation, and input through the CUA tool. The first selection asks the human for session access, denial, or saved access when profile persistence is available. Session access is stored by conversation and application identity and survives DSH restart and Computer Use disablement. Other conversations require their own consent. Application identities use the case-sensitive bundle identifier, so versions and copies at different paths share consent and revocation regardless of signing. A valid running bundle identifier remains sufficient when the operating system cannot supply an executable path. Available paths are still checked against the selected target; process-instance and window ownership checks remain mandatory. Without a bundle identifier, consent requires the canonical executable path. Restarting or updating at that path retains consent; moving or copying the executable to another path requires a new decision. This policy does not authenticate the publisher: another program declaring the same identifier, or replacing an approved executable at the same fallback path, inherits consent. Denial prevents repeated prompts in that session. Revocation reads and removes saved access in the same queue as grant creation, invalidates each affected Agent connection, and awaits its native cleanup without replaying input. Every app handle on those Agent connections becomes unusable; other applications need fresh selection, but their session and saved grants remain reusable. See the [application consent decision](../../../.agents/notes/implemented/architecture/2026-09-26-cua-application-consent.md). These checks govern CUA calls; persistent PTC and separately authorized shell tools are not an operating-system sandbox. Raw `getState` exposes validated state fields and the complete text for the requested disclosure options. The native helper also returns structured element diagnostics for native checks; the tool projection omits that duplicate array from model text and structured tool values. @@ -220,7 +220,7 @@ The queue orders individual native requests. Holding an app object does not rese - Observed failures include dispatched Unicode text not appearing in Blender and background Command+A not selecting all text in AppKit. Inspect application state after input; a successful tool result confirms dispatch only. - Native binaries require a local build. Signing and Desktop distribution remain future work. The [permission page](../cua/README.md) offers macOS prompts and app revocation; packaged Desktop permission attribution remains deferred. - Saved permission rows show the name, path and icon of one approved copy, not an inventory of every installation sharing its identity. Removing that copy can leave its icon unavailable. Revocation still applies to every copy with the same identity. -- If macOS does not expose a running application’s bundle identifier, the helper checks its reported bundle only when its executable matches the observed process path, then falls back to that path. Failure to identify the actual process executable remains an error; missing bundle metadata alone does not prevent saved consent. +- If macOS does not expose a running application’s bundle identifier, the helper checks its reported bundle only when its executable matches the observed process path, then falls back to that path. Consent identity creation fails only when both the bundle identifier and actual executable path are unavailable; process-instance verification can still fail independently. - Persistent PTC is an external dependency assumption, not an implementation in this package. Real-model task success requires separate evaluation beyond native and protocol fixtures. ----- diff --git a/packages/experimental/cua-macos/README.zh.md b/packages/experimental/cua-macos/README.zh.md index e8be02e3bf..8a9ac85bdd 100644 --- a/packages/experimental/cua-macos/README.zh.md +++ b/packages/experimental/cua-macos/README.zh.md @@ -20,7 +20,7 @@ kind: "package-reference" - [已知限制与后续工作](#known-limitations-and-deferred-work) - [开发备注](#dev-note) -helper 为授权提示和已授权应用列表提供 64 像素 PNG 图标。读取图标不会启动应用或检查窗口,可复用授权由原生应用的 Bundle ID 决定。 +helper 为授权提示和已授权应用列表提供 64 像素 PNG 图标。读取图标不会启动应用或检查窗口,图标不决定可复用授权。 共享 helper 查询 macOS 为它记录的责任进程,在发布就绪状态前保存对应应用的名称和图标。因此,从 Terminal 启动 Desktop 时,即使中间还有另一个 GUI 应用,也能识别到 Terminal。责任应用退出后,权限查询仍保留这些信息,后续复用该 helper 的连接读取同一份记录。系统查询或应用信息不可用时省略该字段,由界面引导用户按系统弹窗选择授权对象。 @@ -67,7 +67,7 @@ pnpm dsh headless --patch packages/experimental/cua-macos/examples/macos.cordis. Agent 销毁和插件卸载会取消并等待完整工具调用,包括图像接入检查和附件存储。已经开始的图像写入必须结束后,销毁才会返回;已取消的调用不会返回成功截图。 -CUA 工具在读取 AX、窗口标题、截图、激活和输入前检查应用授权。首次选择应用时询问用户,可选择本会话允许、拒绝;profile 提供持久存储时还可保存长期授权。会话许可按对话和应用身份持久化,重启 DSH 或关闭 Computer Use 后仍可复用,其他对话需要单独授权。应用身份使用区分大小写的 Bundle ID,因此不同路径下的版本和副本共用许可与撤销决定,不受签名状态影响。没有 Bundle ID 时,授权使用规范化的可执行路径。在同一路径下重启或更新会沿用许可,移动或复制到另一个路径则需要重新决定。这项规则不验证发布者身份,其他程序声明相同标识,或替换路径授权所对应的可执行文件时,也会继承许可。拒绝后,同一会话不会反复询问。撤销与长期许可的保存共用队列,在队列内读取并移除许可,然后使相关 Agent 连接失效并等待原生清理完成,不自动重放输入。同一 Agent 连接中的其他应用也需要重新选择,其他应用的会话许可和长期许可仍可复用。设计理由见[应用授权决策](../../../.agents/notes/implemented/architecture/2026-09-26-cua-application-consent.zh.md)。这些检查的范围是 CUA 调用。persistent PTC 与已授权的 shell 仍按各自执行权限运行。 +CUA 工具在读取 AX、窗口标题、截图、激活和输入前检查应用授权。首次选择应用时询问用户,可选择本会话允许、拒绝;profile 提供持久存储时还可保存长期授权。会话许可按对话和应用身份持久化,重启 DSH 或关闭 Computer Use 后仍可复用,其他对话需要单独授权。应用身份使用区分大小写的 Bundle ID,因此不同路径下的版本和副本共用许可与撤销决定,不受签名状态影响。运行中应用具有有效 Bundle ID 时,即使操作系统无法提供可执行路径,也可以授权。路径可取得时仍核对所选目标,进程实例和窗口归属检查始终保留。缺少 Bundle ID 时,授权必须取得规范化可执行路径。在同一路径下重启或更新会沿用许可,移动或复制到另一个路径则需要重新决定。这项规则不验证发布者身份,其他程序声明相同标识,或替换路径授权所对应的可执行文件时,也会继承许可。拒绝后,同一会话不会反复询问。撤销与长期许可的保存共用队列,在队列内读取并移除许可,然后使相关 Agent 连接失效并等待原生清理完成,不自动重放输入。同一 Agent 连接中的其他应用也需要重新选择,其他应用的会话许可和长期许可仍可复用。设计理由见[应用授权决策](../../../.agents/notes/implemented/architecture/2026-09-26-cua-application-consent.zh.md)。这些检查的范围是 CUA 调用。persistent PTC 与已授权的 shell 仍按各自执行权限运行。 原始 `getState` 操作返回经过校验的状态字段,以及按本次披露选项生成的完整文本。原生 helper 还返回供原生检查使用的结构化元素诊断数组;工具投影会从模型文本和结构化工具值中移除这份重复数组。 @@ -220,7 +220,7 @@ Use selectText only on controls advertising selectionWritable. It selects a uniq - 实测 Blender Unicode 输入曾出现分派成功但界面未显示文本,后台 AppKit 的 Command+A 曾未选中全文。输入后必须检查应用状态;工具返回成功只表示已分派。 - 原生二进制需要本地构建,签名和桌面分发留待后续。[权限页面](../cua/README.zh.md)提供 macOS 申请入口和应用授权撤销;桌面安装包的权限归属留待后续处理。 - 已保存许可的条目显示一个已批准副本的名称、路径和图标,不枚举共享身份的所有安装副本。删除该副本后图标可能不可用,撤销仍作用于同一身份的所有副本。 -- macOS 无法提供运行中应用的 Bundle ID 时,helper 仅在其报告的 bundle 可执行路径与实际进程路径相同时读取该 bundle,仍无标识则使用路径。无法识别实际进程的可执行路径时仍会报错;仅缺少 bundle 元数据不会阻止保存许可。 +- macOS 无法提供运行中应用的 Bundle ID 时,helper 仅在其报告的 bundle 可执行路径与实际进程路径相同时读取该 bundle,仍无标识则使用路径。只有 Bundle ID 和实际可执行路径均不可用时才拒绝生成授权身份;进程实例验证仍可能独立失败。 - 持久 PTC 是对外部运行环境的假设,本包不实现它。真实模型任务成功率需要在原生测试和协议测试之外单独评估。 ----- diff --git a/packages/experimental/cua-macos/native/README.i18n.yaml b/packages/experimental/cua-macos/native/README.i18n.yaml index 6637bab31e..11839acf84 100644 --- a/packages/experimental/cua-macos/native/README.i18n.yaml +++ b/packages/experimental/cua-macos/native/README.i18n.yaml @@ -18,14 +18,14 @@ en: 02b25ac1126b6094 zh: 3995a1f46354531b /dsh-cua-native-helper/request-protocol: - en: c4c32b6447e39e00 - zh: e798843da1a83ada + en: 916702298d1c07be + zh: 026e587b1275ca70 /dsh-cua-native-helper/observation-and-input: en: c527eedc3a0ee968 zh: ce8cc12d5a62e8ae /dsh-cua-native-helper/verification: - en: b4be018ae95b449d - zh: e604f17c8c81047b + en: 2bde45bdd96c1d6d + zh: 6d4dd4d316f89e45 /dsh-cua-native-helper/further-exploration: en: 265e1927952ce6d7 zh: 7c35d9fd98b6e6c8 diff --git a/packages/experimental/cua-macos/native/README.md b/packages/experimental/cua-macos/native/README.md index 7c48bf3634..10061fb046 100644 --- a/packages/experimental/cua-macos/native/README.md +++ b/packages/experimental/cua-macos/native/README.md @@ -55,9 +55,9 @@ Successful `activate` and `performSecondaryAction` AXRaise results include `fore Every app-targeted operation requires `appHandle` from `getApp` in the same helper. The helper pins the PID and kernel process start time, and invalidates the handle and all of its snapshots after process exit or PID reuse. Calling `getApp` can acquire the replacement process without reactivating old handles. A random per-helper namespace prevents handles from a terminated helper matching those of its replacement. Repeated acquisition of the same live process shares its handle. -Stable error codes are `INVALID_REQUEST` (malformed envelope), `INVALID_ARGUMENT` (invalid parameters), `UNSUPPORTED` (unknown operation), `APP_UNAVAILABLE`, `AMBIGUOUS_APP`, `STALE_APP`, `STALE_SNAPSHOT`, `WINDOW_UNAVAILABLE`, `WINDOW_CHANGED`, `PERMISSION_DENIED`, `FOREGROUND_REQUIRED` (hover target is not the unobscured foreground window), `PANEL_NOT_READY` (system panel recipient unavailable before input), and `NATIVE_ERROR` (remaining operating-system failures). An error never promises that a partially dispatched input was rolled back. The host must not retry input automatically. +Stable error codes are `INVALID_REQUEST` (malformed envelope), `INVALID_ARGUMENT` (invalid parameters), `UNSUPPORTED` (unknown operation), `APP_UNAVAILABLE`, `APP_PATH_UNAVAILABLE`, `PROCESS_INSPECTION_FAILED`, `AMBIGUOUS_APP`, `STALE_APP`, `STALE_SNAPSHOT`, `WINDOW_UNAVAILABLE`, `WINDOW_CHANGED`, `PERMISSION_DENIED`, `FOREGROUND_REQUIRED` (hover target is not the unobscured foreground window), `PANEL_NOT_READY` (system panel recipient unavailable before input), and `NATIVE_ERROR` (remaining operating-system failures). An error never promises that a partially dispatched input was rolled back. The host must not retry input automatically. -Application selection returns an authorization record to the Host: a SHA-256 digest of the case-sensitive bundle identifier prefixed with `macos:bundle-id:`, display name, executable path, and persistable flag. All installations with that identifier share consent, including unsigned and ad-hoc-signed applications. Without a nonempty bundle identifier, both running and stopped applications use SHA-256 of `macos:executable-path:` followed by the symlink-resolved executable path and remain eligible for saved consent. Process IDs and start times validate live handles but do not enter the saved identity. The Host strips this record from model results and obtains human consent before launch, observation or input. This pipe protocol is trusted Host transport, not a sandbox against a separately authorized shell process. +Application selection returns an authorization record to the Host: a SHA-256 digest of the case-sensitive bundle identifier prefixed with `macos:bundle-id:`, display name, optional executable path, and persistable flag. All installations with that identifier share consent, including unsigned and ad-hoc-signed applications. Without a nonempty bundle identifier, both running and stopped applications use SHA-256 of `macos:executable-path:` followed by the symlink-resolved executable path and remain eligible for saved consent. A running bundle identifier remains usable when the process path query fails; the record omits executablePath. Available paths must still match the selection. Without either identity, APP_PATH_UNAVAILABLE reports the path query cause, including its errno, before any target operation. PROCESS_INSPECTION_FAILED means the process instance could not be verified; only ESRCH from process inspection is reported as a missing process. Neither failure triggers an automatic retry. Process IDs and start times validate live handles but do not enter the saved identity. The Host strips this record from model results and obtains human consent before launch, observation or input. This pipe protocol is trusted Host transport, not a sandbox against a separately authorized shell process. Protocol declarations are generated from [the shared protocol](../../cua/src/protocol.ts). Run `pnpm exec tsx packages/experimental/cua-macos/native/generate-protocol.ts` from the repository root; package tests verify generated JSON and Swift field/enum tables. Model-submittable parameters exclude Host resource bounds and the private launch continuation. @@ -105,7 +105,7 @@ Use `python3 packages/experimental/cua-macos/native/tests/test_swift.py` for off Run `python3 packages/experimental/cua-macos/native/tests/shared_helper_e2e.py --helper /absolute/helper` to verify concurrent startup, a shared service PID, independent handles, same-application handoff, request-local screenshot deadlines, connection cleanup and signal shutdown with an owned AppKit fixture. Existing Accessibility and Screen Recording grants are required. `--without-desktop` limits the check to protocol and process lifetime. -Run `python3 packages/experimental/cua-macos/native/tests/application_consent_e2e.py --helper /absolute/helper` in an unlocked macOS GUI session with the Apple Swift compiler available. It owns and cleans up its AppKit bundles and standalone GUI processes, checks metadata replacement, cold and direct launches, shared bundle IDs, and persistent path identity across standalone restarts. The default identity check requires no Accessibility or Screen Recording grants. Add `--desktop` to read each fixture’s controls, verify an AX button press in its state file, and capture its window; this requires existing grants for both permissions. +Run `python3 packages/experimental/cua-macos/native/tests/application_consent_e2e.py --helper /absolute/helper` in an unlocked macOS GUI session with the Apple Swift compiler available. It owns and cleans up its AppKit bundles and standalone GUI processes, checks metadata replacement, cold and direct launches, shared bundle IDs, persistent path identity across standalone restarts, and selection after a running executable is deleted. The default identity check requires no Accessibility or Screen Recording grants. Add `--desktop` to read each fixture’s controls, verify an AX button press in its state file, and capture its window; this requires existing grants for both permissions. Run `python3 packages/experimental/cua-macos/native/tests/launcher_identity_e2e.py --helper /absolute/helper` in a GUI login session to verify a Launch Services application that starts a nested GUI launcher and then the helper. The helper identifies the outer responsible application and retains its name and icon after the launchers exit. This check owns both applications and the helper, cleans up its Launch Services registrations, and does not request Accessibility or Screen Recording access. diff --git a/packages/experimental/cua-macos/native/README.zh.md b/packages/experimental/cua-macos/native/README.zh.md index 88864bf323..2adbcca2f2 100644 --- a/packages/experimental/cua-macos/native/README.zh.md +++ b/packages/experimental/cua-macos/native/README.zh.md @@ -55,9 +55,9 @@ AppKit 在主事件循环上运行。阻塞式 socket 接收与握手使用后 每个面向应用的操作都要求使用同一 helper 的 `getApp` 返回的 `appHandle`。helper 固定 PID 和内核进程启动时间,进程退出或 PID 被复用后使句柄及其全部快照失效。再次调用 `getApp` 可取得替代进程,不会重新激活旧句柄。随机的 helper 命名空间防止已终止 helper 的句柄与替代实例重合。重复获取同一存活进程会共享句柄。 -稳定错误码包括 `INVALID_REQUEST`(信封无效)、`INVALID_ARGUMENT`(参数无效)、`UNSUPPORTED`(操作未知)、`APP_UNAVAILABLE`、`AMBIGUOUS_APP`、`STALE_APP`、`STALE_SNAPSHOT`、`WINDOW_UNAVAILABLE`、`WINDOW_CHANGED`、`PERMISSION_DENIED`、`FOREGROUND_REQUIRED`(悬停目标不是未被遮挡的前台窗口)、`PANEL_NOT_READY`(输入前系统面板接收方尚不可用)及 `NATIVE_ERROR`(其余操作系统失败)。错误不保证已分派的部分输入被回滚,Host 不得自动重试输入。 +稳定错误码包括 `INVALID_REQUEST`(信封无效)、`INVALID_ARGUMENT`(参数无效)、`UNSUPPORTED`(操作未知)、`APP_UNAVAILABLE`、`APP_PATH_UNAVAILABLE`、`PROCESS_INSPECTION_FAILED`、`AMBIGUOUS_APP`、`STALE_APP`、`STALE_SNAPSHOT`、`WINDOW_UNAVAILABLE`、`WINDOW_CHANGED`、`PERMISSION_DENIED`、`FOREGROUND_REQUIRED`(悬停目标不是未被遮挡的前台窗口)、`PANEL_NOT_READY`(输入前系统面板接收方尚不可用)及 `NATIVE_ERROR`(其余操作系统失败)。错误不保证已分派的部分输入被回滚,Host 不得自动重试输入。 -应用选择向 Host 返回授权记录:区分大小写的 Bundle ID 加上 `macos:bundle-id:` 前缀后计算的 SHA-256 摘要、显示名称、可执行路径和可持久化标记。相同标识的所有安装副本共用授权,包括未签名和临时签名的应用。缺少非空 Bundle ID 时,运行中和未启动应用都对 `macos:executable-path:` 与解析符号链接后的可执行路径计算 SHA-256,仍可保存长期授权。进程号和启动时间只校验存活句柄,不进入已保存身份。Host 从模型结果中移除此记录,并在启动、观察和输入前取得用户许可。此管道协议用于可信 Host 传输,无法隔离另一个已获授权的 shell 进程。 +应用选择向 Host 返回授权记录:区分大小写的 Bundle ID 加上 `macos:bundle-id:` 前缀后计算的 SHA-256 摘要、显示名称、可选的可执行路径和可持久化标记。相同标识的所有安装副本共用授权,包括未签名和临时签名的应用。缺少非空 Bundle ID 时,运行中和未启动应用都对 `macos:executable-path:` 与解析符号链接后的可执行路径计算 SHA-256,仍可保存长期授权。进程路径查询失败时,运行中的有效 Bundle ID 仍可用于授权,记录省略 executablePath;路径可取得时仍须与所选目标一致。两种身份均不可用时,在执行目标操作前返回 APP_PATH_UNAVAILABLE,保留路径查询原因和 errno。PROCESS_INSPECTION_FAILED 表示无法验证进程实例,只有进程检查返回 ESRCH 时才报告进程不存在;两种失败都不触发自动重试。进程号和启动时间只校验存活句柄,不进入已保存身份。Host 从模型结果中移除此记录,并在启动、观察和输入前取得用户许可。此管道协议用于可信 Host 传输,无法隔离另一个已获授权的 shell 进程。 协议声明从[共享协议](../../cua/src/protocol.ts)生成。在仓库根目录运行 `pnpm exec tsx packages/experimental/cua-macos/native/generate-protocol.ts`,包测试检查生成的 JSON 和 Swift 字段/枚举表。模型参数不包含 Host 资源上限和私有启动续接操作。 @@ -105,7 +105,7 @@ AppKit 在主事件循环上运行。阻塞式 socket 接收与握手使用后 运行 `python3 packages/experimental/cua-macos/native/tests/shared_helper_e2e.py --helper /absolute/helper`,通过测试自建的 AppKit fixture 核实并发启动、共享服务 PID、独立句柄、同一应用交接、请求级截图期限、连接清理和信号退出。需要已有辅助功能和屏幕录制权限。`--without-desktop` 将检查限定为协议与进程生命期。 -在已解锁的 macOS GUI 会话中运行 `python3 packages/experimental/cua-macos/native/tests/application_consent_e2e.py --helper /absolute/helper`,需要可用的 Apple Swift 编译器。它创建并清理自己的 AppKit 应用和独立 GUI 进程,检查元数据替换、冷启动与直接启动、共用 Bundle ID,以及独立程序重启后的持久路径身份。默认身份检查不需要辅助功能或屏幕录制权限。添加 `--desktop` 可读取各测试窗口的控件,通过状态文件验证 AX 按钮点击,并截取该窗口;此模式要求已有两项系统权限。 +在已解锁的 macOS GUI 会话中运行 `python3 packages/experimental/cua-macos/native/tests/application_consent_e2e.py --helper /absolute/helper`,需要可用的 Apple Swift 编译器。它创建并清理自己的 AppKit 应用和独立 GUI 进程,检查元数据替换、冷启动与直接启动、共用 Bundle ID、独立程序重启后的持久路径身份,以及删除运行中可执行文件后的选择行为。默认身份检查不需要辅助功能或屏幕录制权限。添加 `--desktop` 可读取各测试窗口的控件,通过状态文件验证 AX 按钮点击,并截取该窗口;此模式要求已有两项系统权限。 在 GUI 登录会话中运行 `python3 packages/experimental/cua-macos/native/tests/launcher_identity_e2e.py --helper /absolute/helper`,验证由 Launch Services 启动的应用先启动另一个 GUI 启动器,再启动 helper。helper 识别外层责任应用,并在启动器退出后保留其名称和图标。检查只使用测试自建的两个应用和 helper,结束后清理对应的 Launch Services 注册,不申请辅助功能或屏幕录制权限。 diff --git a/packages/experimental/cua-macos/native/Sources/CuaNative/ApplicationAuthorization.swift b/packages/experimental/cua-macos/native/Sources/CuaNative/ApplicationAuthorization.swift index 92655251de..7412624397 100644 --- a/packages/experimental/cua-macos/native/Sources/CuaNative/ApplicationAuthorization.swift +++ b/packages/experimental/cua-macos/native/Sources/CuaNative/ApplicationAuthorization.swift @@ -5,23 +5,29 @@ import Foundation enum ApplicationAuthorization { // Versions and copies with the same bundle identifier share consent, regardless of signing. - static func describe(_ identity: ProcessIdentity, name: String, expectedExecutablePath: String?) throws -> JSONValue { + static func describe(_ identity: ProcessIdentity, name: String, expectedExecutablePath: String?, + readBundle: (Int32) -> (identifier: String?, url: URL?) = runningBundle, + readPath: (Int32) -> Result = NativePlatform.executablePathResult) throws -> JSONValue { try NativePlatform.verify(identity) - guard let executablePath = NativePlatform.executablePath(identity.pid) else { - throw NativeFailure(code: "APP_UNAVAILABLE", message: "Cannot identify the application executable") - } - let path = URL(fileURLWithPath: executablePath).resolvingSymlinksInPath().path - if let expectedExecutablePath, path != URL(fileURLWithPath: expectedExecutablePath).resolvingSymlinksInPath().path { + let bundle = readBundle(identity.pid) + var bundleID = bundle.identifier.flatMap { $0.isEmpty ? nil : $0 } + let pathResult = readPath(identity.pid) + let path = (try? pathResult.get()).map { URL(fileURLWithPath: $0).resolvingSymlinksInPath().path } + if let path, let expectedExecutablePath, path != URL(fileURLWithPath: expectedExecutablePath).resolvingSymlinksInPath().path { throw NativeFailure(code: "STALE_APP", message: "Application executable changed during selection; select the application again") } - let application = NSRunningApplication(processIdentifier: identity.pid) - var bundleID = application?.bundleIdentifier - if bundleID?.isEmpty != false, let url = application?.bundleURL, + if bundleID == nil, let path, let url = bundle.url, let installed = InstalledApplication.read(url), installed.executablePath == path { bundleID = installed.bundleID } try NativePlatform.verify(identity) - return record(bundleID: bundleID, name: name, executablePath: path) + if bundleID?.isEmpty != false, case .failure(let error) = pathResult { throw error } + return try record(bundleID: bundleID, name: name, executablePath: path) + } + + static func runningBundle(_ pid: Int32) -> (identifier: String?, url: URL?) { + let application = NSRunningApplication(processIdentifier: pid) + return (application?.bundleIdentifier, application?.bundleURL) } static func describeInstalled(_ app: InstalledApplication) throws -> JSONValue { @@ -29,16 +35,18 @@ enum ApplicationAuthorization { current.bundleID == app.bundleID, current.executablePath == app.executablePath else { throw NativeFailure(code: "STALE_APP", message: "Application changed after selection; select it again") } - return record(bundleID: current.bundleID, name: app.name, executablePath: current.executablePath) + return try record(bundleID: current.bundleID, name: app.name, executablePath: current.executablePath) } - private static func record(bundleID: String?, name: String, executablePath: String) -> JSONValue { - let path = URL(fileURLWithPath: executablePath).resolvingSymlinksInPath().path + private static func record(bundleID: String?, name: String, executablePath: String?) throws -> JSONValue { + let path = executablePath.map { URL(fileURLWithPath: $0).resolvingSymlinksInPath().path } let identity: String if let bundleID, !bundleID.isEmpty { identity = "macos:bundle-id:" + bundleID } - else { identity = "macos:executable-path:" + path } - return .object(["id": .string(digest(identity)), "name": .string(name), - "executablePath": .string(path), "persistable": .bool(true)]) + else if let path { identity = "macos:executable-path:" + path } + else { throw NativePlatform.executablePathFailure(0) } + var value: [String: JSONValue] = ["id": .string(digest(identity)), "name": .string(name), "persistable": .bool(true)] + if let path { value["executablePath"] = .string(path) } + return .object(value) } private static func digest(_ value: String) -> String { diff --git a/packages/experimental/cua-macos/native/Sources/CuaNative/NativePlatform.swift b/packages/experimental/cua-macos/native/Sources/CuaNative/NativePlatform.swift index 0f52efaba4..600b28f5c3 100644 --- a/packages/experimental/cua-macos/native/Sources/CuaNative/NativePlatform.swift +++ b/packages/experimental/cua-macos/native/Sources/CuaNative/NativePlatform.swift @@ -72,17 +72,42 @@ enum NativePlatform { return responsible > 0 ? responsible : nil } static func executablePath(_ pid: Int32) -> String? { - var buffer = [CChar](repeating: 0, count: 4 * Int(MAXPATHLEN)) - guard proc_pidpath(pid, &buffer, UInt32(buffer.count)) > 0 else { return nil } - return String(decoding: buffer.prefix { $0 != 0 }.map { UInt8(bitPattern: $0) }, as: UTF8.self) + try? executablePathResult(pid).get() + } + static func executablePathResult(_ pid: Int32) -> Result { + var buffer = [CChar](repeating: 0, count: Int(PROC_PIDPATHINFO_MAXSIZE)) + errno = 0 + guard proc_pidpath(pid, &buffer, UInt32(buffer.count)) > 0 else { return .failure(executablePathFailure(errno)) } + return .success(String(decoding: buffer.prefix { $0 != 0 }.map { UInt8(bitPattern: $0) }, as: UTF8.self)) + } + static func executablePathFailure(_ error: Int32) -> NativeFailure { + let reason: String + switch error { + case ENOENT, ENOTDIR, EIO, ESTALE, ENODEV, ENXIO: reason = "macOS could not resolve the executable's filesystem path" + case EACCES, EPERM: reason = "macOS denied the executable path query" + case ENAMETOOLONG, EOVERFLOW: reason = "the executable path exceeds the system query limit" + case ENOMEM, ENOBUFS, EAGAIN: reason = "macOS lacked resources for the executable path query" + default: reason = "macOS did not provide an executable path" + } + return NativeFailure(code: "APP_PATH_UNAVAILABLE", message: "Executable path unavailable: \(reason) (errno \(error)). Check the application's installation and system access before selecting it again") + } + static func processIdentityFailure(_ error: Int32) -> NativeFailure { + if error == ESRCH { + return NativeFailure(code: "APP_UNAVAILABLE", message: "Application process no longer exists; select the application again") + } + if error == 0 { + return NativeFailure(code: "PROCESS_INSPECTION_FAILED", message: "macOS returned incomplete application process information; check system access before selecting it again") + } + return NativeFailure(code: "PROCESS_INSPECTION_FAILED", message: "Cannot verify the application process identity (errno \(error): \(String(cString: strerror(error)))). Check system access and resources before selecting it again") } static func identity(_ pid: Int32) throws -> ProcessIdentity { var info = proc_bsdinfo() let size = MemoryLayout.stride + errno = 0 let copied = withUnsafeMutablePointer(to: &info) { pointer in proc_pidinfo(pid, PROC_PIDTBSDINFO, 0, pointer, Int32(size)) } - guard copied == Int32(size) else { throw NativeFailure(code: "APP_UNAVAILABLE", message: "Target application exited or cannot be inspected; select it again") } + guard copied == Int32(size) else { throw processIdentityFailure(copied == 0 ? errno : 0) } return ProcessIdentity(pid: pid, startedSeconds: info.pbi_start_tvsec, startedMicroseconds: info.pbi_start_tvusec) } static func verify(_ identity: ProcessIdentity) throws { diff --git a/packages/experimental/cua-macos/native/tests/application_consent_e2e.py b/packages/experimental/cua-macos/native/tests/application_consent_e2e.py index 4cab4cf516..0578f93cdc 100644 --- a/packages/experimental/cua-macos/native/tests/application_consent_e2e.py +++ b/packages/experimental/cua-macos/native/tests/application_consent_e2e.py @@ -1,6 +1,7 @@ """Verify bundle and executable-path consent, optionally with fixture-only GUI operations.""" import argparse import base64 +import ctypes from contextlib import ExitStack import hashlib import json @@ -33,7 +34,9 @@ def main(): if args.desktop: assert helper.call("getCapabilities", {})["permissions"] == {"accessibility": True, "screenRecording": True} + checked_windows = 0 def check_window(app, state_path): + nonlocal checked_windows if not args.desktop: return state = wait_for_state(state_path, lambda value: value["pid"] == app["pid"] and value["windowId"] > 0) @@ -44,6 +47,7 @@ def main(): wait_for_state(state_path, lambda value: value["axPresses"] == state["axPresses"] + 1) captured = helper.call("screenshot", owner) assert base64.b64decode(captured["data"], validate=True).startswith(b"\x89PNG\r\n\x1a\n") + checked_windows += 1 register = "/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister" def fixture(name, bundle_id): @@ -139,8 +143,34 @@ def main(): finally: stop(process) assert standalone_ids[0] == standalone_ids[1], standalone_ids + + libsystem = ctypes.CDLL(None, use_errno=True) + libsystem.proc_pidpath.argtypes = [ctypes.c_int, ctypes.c_void_p, ctypes.c_uint32] + libsystem.proc_pidpath.restype = ctypes.c_int + for name, bundle_id in [("Deleted bundle executable", identifier), ("Deleted path executable", None)]: + app, executable, state, _ = fixture(name, bundle_id) + pending = helper.call("getApp", {"selector": str(app)}) + launched = helper.call("launchApp", {"appHandle": pending["appHandle"]}) + pid = launched["pid"] + wait_for_state(state, lambda value: value["pid"] == pid and value["windowId"] > 0) + executable.unlink() + buffer = ctypes.create_string_buffer(4096) + ctypes.set_errno(0) + copied = libsystem.proc_pidpath(pid, buffer, len(buffer)) + path_error = ctypes.get_errno() + if bundle_id is None and copied == 0: + failure = helper.call("getApp", {"selector": str(pid)}, error_code="APP_PATH_UNAVAILABLE") + assert "exited" not in failure["message"], failure + else: + running = helper.call("getApp", {"selector": str(pid)}) + authorization = running["authorization"] + assert authorization["id"] == pending["authorization"]["id"] and authorization["persistable"] is True, authorization + if copied == 0: + assert "executablePath" not in authorization, authorization + check_window(running, state) + print(f"Deleted executable: bundle_id={bundle_id is not None}, proc_pidpath_bytes={copied}, errno={path_error}") print("PASS: changed bundles cannot launch; cold/running and direct-bundle identities agree; copies share consent; other IDs stay separate; missing IDs and standalone GUIs use persistent paths across restarts" - + ("; all seven GUI instances expose controls, receive an AX click and produce a PNG" if args.desktop else "")) + + (f"; {checked_windows} GUI instances expose controls, receive an AX click and produce a PNG" if args.desktop else "")) if __name__ == "__main__": diff --git a/packages/experimental/cua-macos/native/tests/swift/PermissionIdentityTests.swift b/packages/experimental/cua-macos/native/tests/swift/PermissionIdentityTests.swift index a5997f5aad..c1279f2115 100644 --- a/packages/experimental/cua-macos/native/tests/swift/PermissionIdentityTests.swift +++ b/packages/experimental/cua-macos/native/tests/swift/PermissionIdentityTests.swift @@ -23,6 +23,79 @@ import Testing #expect(try ApplicationAuthorization.describe(identity, name: "Fixture", expectedExecutablePath: path) == observed) } +@Test(arguments: [ENOENT, EIO, ENODEV, EPERM, EACCES, ENAMETOOLONG, EOVERFLOW, ENOMEM, ENOBUFS]) +func liveBundleIdentitySurvivesAnUnavailableExecutablePath(error: Int32) throws { + let identity = try NativePlatform.identity(getpid()) + let expectedPath = try #require(NativePlatform.executablePath(identity.pid)) + let bundle: (Int32) -> (identifier: String?, url: URL?) = { _ in ("test.dsh.bundle", nil) } + let before = try ApplicationAuthorization.describe(identity, name: "Fixture", expectedExecutablePath: expectedPath, readBundle: bundle) + var queries = 0 + let after = try ApplicationAuthorization.describe(identity, name: "Fixture", expectedExecutablePath: expectedPath, + readBundle: bundle, readPath: { _ in queries += 1; return .failure(NativePlatform.executablePathFailure(error)) }) + try NativePlatform.verify(identity) + #expect(after["id"] == before["id"]) + #expect(after["persistable"] == .bool(true)) + #expect(after.object?["executablePath"] == nil) + #expect(queries == 1) +} + +@Test(arguments: [ENOENT, EIO, ENODEV, EPERM, EACCES, ENAMETOOLONG, EOVERFLOW, ENOMEM, ENOBUFS]) +func missingBundleAndPathReportsThePathFailureWithoutRetry(error: Int32) throws { + let identity = try NativePlatform.identity(getpid()) + var queries = 0 + do { + _ = try ApplicationAuthorization.describe(identity, name: "Fixture", expectedExecutablePath: nil, + readBundle: { _ in (nil, nil) }, readPath: { _ in queries += 1; return .failure(NativePlatform.executablePathFailure(error)) }) + Issue.record("An application without either identity was accepted") + } catch let failure as NativeFailure { + #expect(failure.code == "APP_PATH_UNAVAILABLE") + #expect(failure.message.contains("errno \(error)")) + #expect(!failure.message.contains("exited")) + } + try NativePlatform.verify(identity) + #expect(queries == 1) +} + +@Test func availablePathsStillRejectADifferentTargetWithAValidBundleIdentifier() throws { + let identity = try NativePlatform.identity(getpid()) + do { + _ = try ApplicationAuthorization.describe(identity, name: "Fixture", expectedExecutablePath: "/another/executable", + readBundle: { _ in ("test.dsh.bundle", nil) }) + Issue.record("A mismatched target path was accepted") + } catch let failure as NativeFailure { #expect(failure.code == "STALE_APP") } +} + +@Test func bundleIdentityCannotAuthorizeAProcessThatExitsDuringInspection() throws { + let process = Process(), input = Pipe() + process.executableURL = URL(fileURLWithPath: "/bin/cat") + process.standardInput = input + process.standardOutput = FileHandle.nullDevice + try process.run() + defer { + input.fileHandleForWriting.closeFile() + if process.isRunning { process.terminate() } + process.waitUntilExit() + } + let identity = try NativePlatform.identity(process.processIdentifier) + do { + _ = try ApplicationAuthorization.describe(identity, name: "Fixture", expectedExecutablePath: nil, + readBundle: { _ in ("test.dsh.bundle", nil) }, readPath: { _ in + process.terminate() + process.waitUntilExit() + return .failure(NativePlatform.executablePathFailure(ENOENT)) + }) + Issue.record("An exited process was authorized by its bundle identifier") + } catch let failure as NativeFailure { #expect(failure.code == "APP_UNAVAILABLE") } +} + +@Test(arguments: [Int32(0), EIO, EPERM, EACCES, ENOMEM]) +func failedProcessInspectionDoesNotReportAnExit(error: Int32) { + let failure = NativePlatform.processIdentityFailure(error) + #expect(failure.code == "PROCESS_INSPECTION_FAILED") + #expect(!failure.message.contains("exited")) + #expect(!failure.message.contains("Success")) +} + @MainActor @Test func applicationIconsUseBoundedNativePNGs() throws { let encoded = try #require(ApplicationCatalog.icon(at: "/System/Library/CoreServices/Finder.app/Contents/MacOS/Finder")) #expect(encoded.hasPrefix("data:image/png;base64,")) diff --git a/packages/experimental/cua-macos/tests/provider-lifecycle.spec.ts b/packages/experimental/cua-macos/tests/provider-lifecycle.spec.ts index d36534413b..77195e0dd8 100644 --- a/packages/experimental/cua-macos/tests/provider-lifecycle.spec.ts +++ b/packages/experimental/cua-macos/tests/provider-lifecycle.spec.ts @@ -657,7 +657,7 @@ it('rejects an unsupported native host before starting preparation', async () => }) -async function permissionProfile(allowedApps: Array<{ id: string; name: string; executablePath: string }> = []) { +async function permissionProfile(allowedApps: Array<{ id: string; name: string; executablePath?: string }> = []) { const f = await setup() await f.provider.dispose() const home = await mkdtemp(join(tmpdir(), 'cua-grant-profile-')), dir = join(home, 'profile') @@ -709,12 +709,12 @@ it('stores revocation without entering the HMR configuration queue', async () => await blocked }) -it('stores persistable application consent separately from configuration', async () => { +it.each([true, false])('stores persistable application consent separately from configuration (path present: %s)', async (hasPath) => { const f = await permissionProfile(), { profile } = f expect(f.ctx.settings.describe().find(row => row.ns === 'cua')).toBeUndefined() await f.ctx.plugin(UserQuestions) f.ctx.on('user-questions/request', async () => ({ answers: [{ id: 'cua-app-access', selected: ['Always allow'] }] })) - const authorization = { id: 'a'.repeat(64), name: 'Fixture', executablePath: '/fixture/app', persistable: true } + const authorization = { id: 'a'.repeat(64), name: 'Fixture', ...(hasPath ? { executablePath: '/fixture/app' } : {}), persistable: true } native.request.mockResolvedValue({ appHandle: 'signed-app', pid: 17, name: 'Fixture', authorization }) expect((await f.execute('getApp', { selector: 'Fixture' })).isError).toBe(false) expect(await readFile(profile.patchPath, 'utf8')).not.toContain(authorization.id) @@ -740,10 +740,10 @@ it('rejects an application handle before any helper or consent has been acquired expect(native.request).not.toHaveBeenCalled() }) -it('uses configured application grants for a matching identity without requesting a human answer', async () => { +it.each([true, false])('uses configured grants without requesting a human answer (path present: %s)', async (hasPath) => { const f = await setup() await f.provider.dispose() - const grant = { id: 'a'.repeat(64), name: 'Fixture', executablePath: '/fixture/app' } + const grant = { id: 'a'.repeat(64), name: 'Fixture', ...(hasPath ? { executablePath: '/fixture/app' } : {}) } await f.ctx.plugin(NativeProvider, { ...config, allowedApps: [grant] }) native.request.mockResolvedValueOnce({ appHandle: 'saved-app', pid: 17, name: 'Fixture', authorization: { ...grant, persistable: true } }) expect((await f.execute('getApp', { selector: 'Fixture' })).isError).toBe(false) diff --git a/packages/experimental/cua/README.i18n.yaml b/packages/experimental/cua/README.i18n.yaml index 5165a47566..e2ce1454d0 100644 --- a/packages/experimental/cua/README.i18n.yaml +++ b/packages/experimental/cua/README.i18n.yaml @@ -21,8 +21,8 @@ en: 1e15a89ecb1614d7 zh: 1e81d085845e28ab /deepseek-ai-dsh-cua/understand-the-implementation: - en: be463bdd095cc2a9 - zh: 23248be7a2f0b1db + en: 60121c7dacc67c0b + zh: ea17f519f29aa948 /deepseek-ai-dsh-cua/further-exploration: en: 166e3c1f9a67f753 zh: 698c5136c5350052 diff --git a/packages/experimental/cua/README.md b/packages/experimental/cua/README.md index 6a2c39c33c..0dd7211c50 100644 --- a/packages/experimental/cua/README.md +++ b/packages/experimental/cua/README.md @@ -67,6 +67,8 @@ The [permission store](src/permission-store.ts) uses `storageDomain` with the co Legacy `allowedApps` are imported on first store access and never reapplied after migration. The old configuration can be removed after checking the permission page. Grants, denials and the option to ask again are durable; the page still omits conversation-only grants. Standalone compositions without a profile retain only process-local decisions; a profile without domain storage refuses authorization operations. +Grant executable paths are optional display metadata. Missing paths omit the tooltip and icon query while retaining the application name and revoke action. Existing stored records remain valid; new records without paths require a reader that supports the optional field. Storage failures still reject authorization and dispatch without substituting temporary permission. + The permission Remote also exposes `ptcConfiguration()` and `enablePersistentPtc()` for the detail-page runtime setting. Reads inspect the existing runtime and editable profile entry. Explicit writes use `configEditor.edit()` to preserve other fields and apply normal Loader reload; an already-persistent runtime is left intact. This setting is separate from system and application authorization. The provider calls [installCua](src/index.ts) with its prepared helper, connection factory, and guidance. [NativeClient](src/native-client.ts) owns request correlation, byte limits, cancellation acknowledgement, and failure settlement. The platform connector owns startup and connection cleanup. The shared executor retains one connection per Agent and joins in-flight image writes during disposal. diff --git a/packages/experimental/cua/README.zh.md b/packages/experimental/cua/README.zh.md index 183b456fa8..425a753d67 100644 --- a/packages/experimental/cua/README.zh.md +++ b/packages/experimental/cua/README.zh.md @@ -67,6 +67,8 @@ kind: "package-reference" 旧 `allowedApps` 只在首次访问存储时导入,迁移后不再应用。确认权限页显示正确后,可以删除旧配置。授权、拒绝和允许再次询问均持久化,页面仍不显示仅对某个会话生效的许可。没有 profile 的独立组合只保留进程内决定;有 profile 但缺少域存储的组合会拒绝授权操作。 +授权记录中的可执行路径是可选的展示信息。缺少路径时不显示路径提示,也不查询图标,应用名称和撤销操作仍然可用。已有存储记录保持有效,缺少路径的新记录需要支持可选字段的读取方。存储失败仍会拒绝授权和操作,不会改用临时许可。 + 权限 Remote 还通过 `ptcConfiguration()` 和 `enablePersistentPtc()` 支持详情页的执行方式设置。查询读取现有执行器和可编辑的 profile 条目。显式写入使用 `configEditor.edit()` 保留其他字段并按正常 Loader 规则重载;已是持久化模式的执行器保持不变。此设置独立于系统权限和应用授权。 提供方将准备好的 helper、连接工厂和指引传给 [installCua](src/index.ts)。[NativeClient](src/native-client.ts) 负责请求关联、字节上限、取消确认和失败处理。平台连接器负责启动和连接清理。共享执行器为每个 Agent 保留一个连接,并在销毁时等待进行中的图像写入。 diff --git a/packages/experimental/cua/src/access.ts b/packages/experimental/cua/src/access.ts index 1fc9dbb72c..cb4bc815de 100644 --- a/packages/experimental/cua/src/access.ts +++ b/packages/experimental/cua/src/access.ts @@ -81,12 +81,13 @@ export class CuaAccess extends TypertRemoteService { /** * Load presentation icons separately from application decisions. - * @returns Optional native PNG icons keyed by executable path for saved and blocked applications. + * @returns Optional native PNG icons keyed by executable path; applications without paths are skipped. */ @Remote async applicationIcons(): Promise> { const state = await this.policy.status() - const paths = [...new Set([...state.allowedApps, ...state.blockedApps].map(app => app.executablePath))] + const paths = [...new Set([...state.allowedApps, ...state.blockedApps] + .flatMap(app => app.executablePath === undefined ? [] : [app.executablePath]))] return paths.length === 0 ? {} : z.record(z.string(), ApplicationIcon).parse(await this.control('applicationIcons', { paths })) } diff --git a/packages/experimental/cua/src/application-access.ts b/packages/experimental/cua/src/application-access.ts index f07a76e486..02066411e1 100644 --- a/packages/experimental/cua/src/application-access.ts +++ b/packages/experimental/cua/src/application-access.ts @@ -13,7 +13,7 @@ import { CuaPermissionStore, type ApplicationPermission, type PermissionTransact /** Native identity admission occurs before any application observation or input. */ export const ApplicationAuthorizationResult = z.object({ id: z.string().regex(/^[a-f0-9]{64}$/).transform(value => value as CuaApplicationId), - name: z.string(), executablePath: z.string().min(1), persistable: z.boolean(), + name: z.string(), executablePath: z.string().min(1).optional(), persistable: z.boolean(), }) /** Application consent uses one profile store, including conversation-scoped decisions. */ export interface AccessOptions { store: CuaPermissionStore } diff --git a/packages/experimental/cua/src/application-types.ts b/packages/experimental/cua/src/application-types.ts index a82db79545..36595ba1a7 100644 --- a/packages/experimental/cua/src/application-types.ts +++ b/packages/experimental/cua/src/application-types.ts @@ -1,7 +1,7 @@ /** Application identities admitted from native selection or saved provider configuration. */ import type { Branded } from '@deepseek-ai/dsh-brand' -/** Helper-computed digest of platform application information, a process instance or a pending executable. */ +/** Native application consent digest, separate from process and window handles. */ export type CuaApplicationId = Branded<'CuaApplicationId'> /** Identity shown to the human before application access is granted. */ export interface CuaApplicationGrant { @@ -9,6 +9,6 @@ export interface CuaApplicationGrant { id: CuaApplicationId /** Application label presented when the decision was made. */ name: string - /** Canonical executable path presented with the application label. */ - executablePath: string + /** Canonical executable path for display and icons; absent when the operating system cannot provide it. */ + executablePath?: string } diff --git a/packages/experimental/cua/src/client/PermissionPanel.tsx b/packages/experimental/cua/src/client/PermissionPanel.tsx index 0742fc3790..0e391e90df 100644 --- a/packages/experimental/cua/src/client/PermissionPanel.tsx +++ b/packages/experimental/cua/src/client/PermissionPanel.tsx @@ -86,7 +86,7 @@ function Applications({ title, apps, icons, onAction, label, disabled }: {

{title}

    {apps.map(app =>
  • - {icons?.[app.executablePath] !== undefined ? + {app.executablePath !== undefined && icons?.[app.executablePath] !== undefined ? : } {app.name}
    diff --git a/packages/experimental/cua/src/index.ts b/packages/experimental/cua/src/index.ts index 839cefbaf8..4729d58e5d 100644 --- a/packages/experimental/cua/src/index.ts +++ b/packages/experimental/cua/src/index.ts @@ -82,7 +82,7 @@ export const CuaConfig = Schema.object({ agentPreset: Schema.union([Schema.string().min(1), Schema.const(false)]).default('ptc'), allowedApps: Schema.array(Schema.object({ id: Schema.string().pattern(/^[a-f0-9]{64}$/).required(), - name: Schema.string().required(), executablePath: Schema.string().min(1).required(), + name: Schema.string().required(), executablePath: Schema.string().min(1), })).default([]), helperPath: Schema.string(), buildTimeoutMs: Schema.number().step(1).min(1).max(2 ** 31 - 1).default(300_000), diff --git a/packages/experimental/cua/src/permission-store.ts b/packages/experimental/cua/src/permission-store.ts index d4d3bc752a..b9de827dea 100644 --- a/packages/experimental/cua/src/permission-store.ts +++ b/packages/experimental/cua/src/permission-store.ts @@ -11,7 +11,7 @@ import type { CuaApplicationGrant, CuaApplicationId } from './application-types. const identity = z.object({ id: z.string().regex(/^[a-f0-9]{64}$/).transform(value => value as CuaApplicationId), - name: z.string(), executablePath: z.string().min(1), + name: z.string(), executablePath: z.string().min(1).optional(), }) const sessionDecision = z.object({ identity, decision: z.enum(['allow', 'deny', 'ask']), revision: z.number().int().nonnegative(), diff --git a/packages/experimental/cua/tests/access.spec.ts b/packages/experimental/cua/tests/access.spec.ts index 6dc01b4e8a..f089b071f7 100644 --- a/packages/experimental/cua/tests/access.spec.ts +++ b/packages/experimental/cua/tests/access.spec.ts @@ -33,7 +33,8 @@ const unusedConnector = () => { throw new Error('Mocked native client does not c const nativeConfig = { helperPath: '/fixture', cwd: '/', timeoutMs: 1000, connectTimeoutMs: 5000, screenshotTimeoutMs: 5000, axTimeoutMs: 100, maxRequestBytes: 4096, maxResponseBytes: 4096, graceMs: 100, textEventIntervalMs: 1, maxClickHoldMs: 5000 } -const identity = ApplicationAuthorizationResult.parse({ id: 'a'.repeat(64), name: 'Test application', executablePath: '/Applications/Fixture.app/Contents/MacOS/Fixture', persistable: true }) +const executablePath = '/Applications/Fixture.app/Contents/MacOS/Fixture' +const identity = ApplicationAuthorizationResult.parse({ id: 'a'.repeat(64), name: 'Test application', executablePath, persistable: true }) const handle = 'fixture-app' as CuaAppHandle const signal = new AbortController().signal @@ -356,8 +357,8 @@ it('reads application decisions without native work and retrieves icons separate control.request.mockReturnValueOnce(pending.promise) const icons = f.ctx.cuaAccess.applicationIcons() expect((await f.ctx.cuaAccess.applications()).allowedApps).toEqual(f.grants()) - pending.resolve({ [identity.executablePath]: 'data:image/png;base64,aWNvbg==' }) - expect(await icons).toEqual({ [identity.executablePath]: 'data:image/png;base64,aWNvbg==' }) + pending.resolve({ [executablePath]: 'data:image/png;base64,aWNvbg==' }) + expect(await icons).toEqual({ [executablePath]: 'data:image/png;base64,aWNvbg==' }) expect(f.grants()[0]).not.toHaveProperty('icon') }) @@ -376,6 +377,17 @@ it('skips native icon work for an empty application list and propagates icon fai expect((await f.ctx.cuaAccess.systemStatus()).accessibility).toBe(false) }) +it('keeps pathless grants manageable without requesting their icons', async () => { + const grant = { id: identity.id, name: identity.name } + const f = await setup('Always allow', { initial: [grant] }) + expect((await f.ctx.cuaAccess.applications()).allowedApps).toEqual([grant]) + expect(await f.ctx.cuaAccess.applicationIcons()).toEqual({}) + expect(native.instances).toHaveLength(1) + expect(native.instances[0]!.request).not.toHaveBeenCalled() + await f.ctx.cuaAccess.revoke(identity.id) + expect((await f.ctx.cuaAccess.applications()).allowedApps).toEqual([]) +}) + it('preserves captured launch metadata separately from the current helper parent', async () => { const f = await setup() await f.ctx.cuaAccess.systemStatus() diff --git a/packages/experimental/cua/tests/application-access.spec.ts b/packages/experimental/cua/tests/application-access.spec.ts index 1b72e4e510..84b56ce55f 100644 --- a/packages/experimental/cua/tests/application-access.spec.ts +++ b/packages/experimental/cua/tests/application-access.spec.ts @@ -66,6 +66,20 @@ it('refuses raw handle dispatch until getApp obtains consent', async () => { expect(dispatch).not.toHaveBeenCalled() }) +it('saves, reuses, and revokes a native identity without executable path metadata', async () => { + const f = await setup('Always allow') + const withoutPath = ApplicationAuthorizationResult.parse({ id: identity.id, name: identity.name, persistable: true }) + await f.access.select(f.agent, f.client, handle, withoutPath, signal) + expect(f.answer.mock.calls[0]![0].questions[0]!.options).toContainEqual({ label: 'Always allow' }) + expect(f.grants()).toEqual([{ id: identity.id, name: identity.name }]) + const second = 'another-handle' as CuaAppHandle + await f.access.select(f.agent, f.client, second, withoutPath, signal) + expect(f.answer).toHaveBeenCalledOnce() + await expect(f.access.run(f.client, second, signal, async () => 'observed')).resolves.toBe('observed') + await f.access.revoke(identity.id) + await expect(f.access.run(f.client, second, signal, async () => 'unexpected')).rejects.toThrow() +}) + it.each([ { persistable: true, writable: true, withIcon: true, offeredAlways: true }, { persistable: false, writable: true, withIcon: false, offeredAlways: false }, diff --git a/packages/experimental/cua/tests/panel.client.spec.tsx b/packages/experimental/cua/tests/panel.client.spec.tsx index df1430a48c..b0c2d08f69 100644 --- a/packages/experimental/cua/tests/panel.client.spec.tsx +++ b/packages/experimental/cua/tests/panel.client.spec.tsx @@ -329,6 +329,20 @@ it('fills application names, system permissions, and icons as their observations expect(screen.getByRole('region', { name: en.title })).toBe(requirements) }) +it('shows and revokes an application whose executable path is unavailable', () => { + const f = fixture() + const app = { id: 'a'.repeat(64) as CuaApplicationId, name: 'Path unavailable fixture' } + f.publish({ ...observe({ ...value, allowedApps: [app] }) }) + render() + const access = screen.getByRole('region', { name: en.applicationsTitle }) + const row = within(access).getByText(app.name).closest('li')! + expect(row.querySelector('[title]')).toBeNull() + expect(row.querySelector('img')).toBeNull() + expect(row.querySelector('[aria-hidden]')).not.toBeNull() + fireEvent.click(within(row).getByRole('button', { name: en.revoke })) + expect(f.props.revoke).toHaveBeenCalledWith(app.id) +}) + it.each(['applications', 'icons'] as const)('contains a failed %s query in the application section', (key) => { const f = fixture() f.publish({ ...observe(value), [key]: { value: null, busy: false, error: 'offline' } }) diff --git a/packages/experimental/cua/tests/permission-store.spec.ts b/packages/experimental/cua/tests/permission-store.spec.ts index 40c6fbe07a..f9cca9758d 100644 --- a/packages/experimental/cua/tests/permission-store.spec.ts +++ b/packages/experimental/cua/tests/permission-store.spec.ts @@ -64,6 +64,19 @@ it('isolates different profiles that use the same storage root', async () => { expect(await readdir(f.storageRoot)).toHaveLength(2) }) +it('reloads saved grants and conversation decisions with omitted executable paths', async () => { + const f = await setup(), first = await f.open() + const identity = { id: grant.id, name: grant.name } + await first.store.withState(signal, transaction => transaction.save({ migrated: true, applications: { + [grant.id]: { revoked: 0, always: identity, sessions: { conversation: { identity, decision: 'allow', revision: 1 } } }, + } })) + await first.ctx.fiber.dispose() + const resumed = await f.open() + const stored = await resumed.store.withState(signal, transaction => transaction.state.applications[grant.id]) + expect(stored?.always).toEqual(identity) + expect(stored?.sessions.conversation?.identity).toEqual(identity) +}) + it.skipIf(process.platform === 'win32')('uses the same profile identity through a directory symlink', async () => { const f = await setup(), a = await f.open(f.directory, [grant]) await a.store.withState(signal, transaction => transaction.state) @@ -137,6 +150,15 @@ it('uses temporary decisions only without a profile and fails when profile stora await expect(a.store.withState(signal, transaction => transaction.state)).rejects.toThrow('require storageDomain') }) +it('does not enter authorization or dispatch when the profile directory cannot be resolved', async () => { + const f = await setup(), a = await f.open() + await rm(f.directory, { recursive: true }) + let entered = 0 + await expect(a.store.withState(signal, () => { entered += 1 })).rejects.toMatchObject({ code: 'ENOENT' }) + await expect(a.store.withApplication(grant.id, signal, async () => { entered += 1 })).rejects.toMatchObject({ code: 'ENOENT' }) + expect(entered).toBe(0) +}) + it('keeps storage reads and other applications available while one native operation holds its lease', async () => { const f = await setup(), a = await f.open(), b = await f.open() const entered = Promise.withResolvers(), release = Promise.withResolvers()