fix: 修复本机安装的代码助手因缺少 PATH 无法启动的问题 - #127
Merged
Merged
Conversation
macOS 上由 Finder / Dock 启动的 GUI 进程只继承最小 PATH (/usr/bin:/bin:/usr/sbin:/sbin)。代码助手 CLI 普遍以 #!/usr/bin/env node 这类 shebang 启动,此前只解决了“找到可执行文件”: find_dsh 会遍历扩展候选目录,但 spawn 时仍原样继承最小 PATH, 导致解释器不可见,进程以 127 退出并报 env: node: No such file or directory。 新增 platform/process_env.rs,统一构造并注入增强 PATH: 登录 shell PATH(zsh -lic,OnceLock 缓存)→ 当前进程 PATH → 可执行文件所在目录 → 各模块兜底目录,去重后写入子进程环境。 带上可执行文件所在目录是为了覆盖 nvm、pnpm 等工具链安装形态, 这类环境下 CLI 与解释器通常同处一个 bin 目录。 接入范围: - dsh_process::launch_command 的 Auto / Bundled / External 三个分支 - dsh_runtime_validate_external 的版本探测 - pi_web_process::launch_web、opencode_process::launch_web 与 validate_secure_version - codex_process::launch_app_server 验证:最小 PATH 下执行 dsh web,修复前 exit=127 并输出 env: node: No such file or directory,修复后正常输出回环监听地址。 cargo check --lib 通过,新增 5 个测试全部通过。
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.
改动说明
macOS 上由 Finder / Dock 启动的 GUI 进程只继承最小 PATH(
/usr/bin:/bin:/usr/sbin:/sbin)。代码助手 CLI 普遍以#!/usr/bin/env node这类 shebang 启动,而现有实现只解决了「找到可执行文件」这一半:find_dsh()会遍历扩展候选目录并正确命中/opt/homebrew/bin/dsh,但spawn时仍原样继承最小 PATH。结果解释器不可见,进程立即退出,界面只显示
DSH 进程已退出(exit status: 127),stderr 为env: node: No such file or directory。用户通过 Homebrew 安装本机 dsh 后即无法启动,且报错信息无法指向真实原因。实现范围
platform/process_env.rs:login_shell_path()(zsh -lic 'printf %s "$PATH"',OnceLock缓存)、augmented_path()、apply_augmented_path()。PATH 顺序为 登录 shell → 当前进程 → 可执行文件所在目录 → 各模块兜底目录,去重后写入子进程环境。bin目录,只把可执行文件绝对路径找出来并不够。dsh_process::launch_command的 Auto / Bundled / External 三个分支;extra_bin_dirs提升为pub(crate)供dsh.rs复用。dsh_runtime_validate_external版本探测、pi_web_process::launch_web、opencode_process::launch_web与validate_secure_version、codex_process::launch_app_server。验证
cargo check --lib通过,仅存量 warningcargo test,未配置 clippy/fmtcargo test396 passed / 0 failed / 4 ignored验证命令与结果:
新增测试覆盖:扩展目录保留、可执行文件所在目录注入、目录去重、PATH 确实写入子进程(
platform::process_env4 例),以及dsh_process中直指本缺陷的回归用例。风险与兼容性
command.env("PATH", ...)为覆盖写入,但增强结果包含原有 PATH,不会丢失既有可见性;顺序上登录 shell 优先,与用户在终端中执行 CLI 的解析结果一致。login_shell_path()首次调用会拉起一次登录 shell 并缓存,仅在首次启动某类助手时产生一次性开销;该 shell 调用失败时静默降级为当前 PATH 加兜底目录。login_shell_path()返回None,仍按原逻辑合并当前 PATH、APPDATA/npm与兜底目录。自检
CONTRIBUTING.md和docs/development-principles.md