fix(local-cli): AppleScript 被拒时降级到 Launch Services 打开 iTerm#486
Open
47seek wants to merge 2 commits into
Open
Conversation
daemon 通过 PM2/launchd 后台运行时,osascript 发送 Apple事件的负责进程是
node/PM2 而非 iTerm,macOS TCC 永不弹 Automation 授权弹窗,导致 -1743
错误且自动化设置里找不到 iTerm/Terminal。
新增 openViaCommandFile 降级路径:AppleScript 全部失败后,将命令写入临时
.command 文件并通过 `open -a iTerm` 打开。Launch Services 无需 Automation
权限,覆盖后台 daemon 场景。
影响面:
- 仅影响 macOS 本机 CLI 打开流程(openLocalCliInIterm)
- AppleScript 成功时行为不变,仅在全部失败后触发降级
- Linux 路径不受影响(darwin 平台检查在前)
- 新增 runOpenCommand 依赖注入点,默认走 spawnSync('open', ['-a', 'iTerm', path])
测试:新增 2 个单测覆盖降级成功与降级失败场景,原有 5 个 osascript
调用断言保持不变。vitest run --project unit test/local-cli-opener.test.ts
(25 passed) + test/card-handler-open-local-cli.test.ts (19 passed)。
Owner
Review 总结感谢 @47seek 贡献这个修复!方案方向正确——daemon 在 PM2/launchd 后台运行时 TCC 永不弹 Automation 授权弹窗,用 Launch Services 降级是合理思路。代码结构清晰,依赖注入设计好,测试覆盖到位。 我们做了两轮独立 review,发现以下问题,建议修复后再合入: 🔴 阻塞:成功路径永久泄漏临时目录
注意:不能简单短延迟 timer 清理——Launch Services 打开是异步的,且 iTerm 对外部脚本默认先弹"OK to run …?"确认框,用户可能很久后才确认或取消。建议让 🟡 建议同 PR 补齐
🟢 额外建议
验证结果
另外,botmux 项目在飞书有开发者协作群,方便日常沟通、方案讨论和快速 review。如果你愿意加入协作,可以私信我(@deepcoldy)获取入群方式。期待你的更新!🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改了什么
daemon 通过 PM2/launchd 后台运行时,
osascript发送 Apple事件的负责进程是 node/PM2 而非 iTerm,macOS TCC 永不弹 Automation 授权弹窗,导致-1743错误且自动化设置里找不到 iTerm/Terminal。新增
openViaCommandFile降级路径:AppleScript 全部失败后,将命令写入临时.command文件并通过open -a iTerm打开。Launch Services 无需 Automation 权限,覆盖后台 daemon 场景。为什么
用户从 iTerm 直接启动 daemon 时,iTerm 是负责进程,Automation 权限正常。改用 PM2 后台运行后,负责进程变为 PM2/node,TCC 无法授权,AppleScript 永久失败。
影响面
openLocalCliInIterm)runOpenCommand依赖注入点,默认走spawnSync(open, [-a, iTerm, path])测试验证
新增 2 个单测覆盖降级成功与降级失败场景,原有 5 个 osascript 调用断言保持不变。
已从 upstream/master 同步后提交,基于
a09ebcf9。