Skip to content

fix(terminal): run Ghostty launch commands through bash - #2313

Open
huyanxius wants to merge 2 commits into
jlcodes99:mainfrom
huyanxius:fix/ghostty-shell-command
Open

huyanxius wants to merge 2 commits into
jlcodes99:mainfrom
huyanxius:fix/ghostty-shell-command

Conversation

@huyanxius

@huyanxius huyanxius commented Sep 8, 2026 •

Copy link
Copy Markdown

我在 macOS 上使用 Cockpit Tools 时,遇到了从 Codex 实例弹窗选择 Ghostty 后无法启动的问题。排查后尝试加了一层 shell 包装,本地的定向测试和真实 Ghostty 启动验证都通过了,因此提交这个 PR,想请维护者帮忙看看修复方向和实现是否合适。

Why

排查时发现,原实现把 cd ... && CODEX_HOME=... <cli> 直接写入 Ghostty surface 的 command。Ghostty 的 macOS 启动链添加 exec -l 后,目录切换后的命令不会执行;省略目录切换时,环境变量赋值会被当作可执行文件。

Changes

  • 仅在 Codex 的 Ghostty 分支添加 /bin/bash -lc 包装,先引用完整命令,再进行 AppleScript 转义。
  • 保留原有命令预览。
  • 补充实际执行生成命令的回归测试,覆盖工作目录、环境变量、引号和特殊字符,以及目录切换失败。

Verification

  • 从当前源码提取启动计划结构、AppleScript 转义函数、macOS 启动函数及对应测试,以 rustc --edition=2021 --test 独立编译:4 项测试通过。修复前已确认其中两项失败(未执行目标命令、环境赋值被当作程序)。
  • 真实 Ghostty 1.3.1,通过生成的 AppleScript 创建临时窗口:修复前目标命令未执行;修复后执行成功,实际工作目录和 CODEX_HOME 均与输入一致。路径含空格、单引号、双引号及中文;使用无账号凭据的测试命令,测试窗口已关闭。
  • git diff --check:通过。
  • cargo test -p cockpit-tools --lib macos_ghostty --locked:上游未修改时即因 Cargo.lock 需要更新而退出,未进入编译。未修改锁文件;本机磁盘空间不足以构建完整 Tauri 应用,因此以上独立编译和真实终端验证不代表完整应用构建通过。

Review

这次只验证了本机的 Ghostty 1.3.1,还没有完成整个应用的构建。想请维护者重点看看:这里显式使用 /bin/bash -lc 是否符合项目的终端启动方式,以及是否有其他版本或配置需要兼容。如果项目有更合适的处理方式,也欢迎指出。

Related Issues

Closes #2312

Ghostty prefixes surface commands with exec, breaking directory changes and environment assignments.

Wrap the complete command in bash -lc and quote embedded apostrophes before AppleScript escaping.

Codex starts with the selected working directory and instance environment.
Direct exec handling can silently skip Codex launch or misread environment assignments.

Exercise the generated surface command with directory setup, quoted values, and a failed cd.

Regressions fail on missing execution while the command preview remains covered.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: macOS 从 Codex 实例启动 Ghostty 时命令执行失败

1 participant