fix(cli-agent): use interactive login-shell PATH for install detection#254
Open
zerx-lab wants to merge 2 commits into
Open
fix(cli-agent): use interactive login-shell PATH for install detection#254zerx-lab wants to merge 2 commits into
zerx-lab wants to merge 2 commits into
Conversation
Fixes #253) Root cause: cli_agent.rs:657 — `is_on_path` read `std::env::var("PATH")`, which on macOS GUI launch only contains the minimal system PATH (/usr/bin:/bin:/usr/sbin:/sbin), missing Homebrew, nvm, cargo, etc. Fix: in CLIAgentInstallModel::new, obtain a BoxFuture from LocalShellState::get_interactive_path_env_var (interactive -i -l shell PATH) before spawning the scan, then await it and pass the result to cli_agent_is_on_path / is_on_path. Falls back to std::env::var("PATH") when the future yields None (non-local_tty builds). Identical pattern already used by agent_input_footer.rs and diff_state.rs for the same macOS PATH problem. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014oDbXMhdYGC1RErbFLwcuZ
zerx-lab
commented
Jun 18, 2026
Owner
Author
Review 总结整体倾向:Comment(可直接合并,但有一处建议改进) 阻塞问题无。 建议Windows 当 看起来不错的地方
— 由 Claude Routine 自动生成;如需复评请 @ 维护者人工触发。 Generated by Claude Code |
unwrap_or_default() on a missing PATH degrades to an empty string,
causing split_paths("") to yield one empty component and is_file()
to probe the CWD — not the intended early-return false.
Align with the Unix implementation using an explicit match/return false.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014oDbXMhdYGC1RErbFLwcuZ
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.
关联 Issue
Fixes #253
问题点(确定性描述)
根因:
app/src/terminal/cli_agent.rs:657,is_on_path函数调用std::env::var("PATH")读取进程环境 PATH。macOS 通过 Dock / Finder 启动 GUI 应用时,进程仅继承最小化系统 PATH(
/usr/bin:/bin:/usr/sbin:/sbin),不含用户级工具安装目录(Homebrew/opt/homebrew/bin、npm global~/.npm-global/bin、cargo~/.cargo/bin等),导致CLIAgentInstallModel的后台扫描对所有这些目录中的 CLI 工具返回false。调用链:
CLIAgentInstallModel::new(cli_agent.rs:592) →ctx.spawn(async)cli_agent_is_on_path(a)(cli_agent.rs:596 before fix)is_on_path(other.command_prefix())(cli_agent.rs:650)std::env::var("PATH")→ 返回最小化 PATH →is_file()检测失败复现证据
agent_input_footer/mod.rs:1021-1025中已有注释明确记录了同一问题并为 plugin 自动安装路径提供了修复,但CLIAgentInstallModel扫描未同步:修复方案
在
CLIAgentInstallModel::new中,于ctx.spawn之前通过LocalShellState::get_interactive_path_env_var获取交互式 login-shell PATH 的 future,在异步扫描任务内 await 该 future,将真实 PATH 传递给检测函数。local_tty特性未启用时回退到None(最终仍读std::env::var("PATH"))。此模式与以下两处已有实现完全一致:
agent_input_footer/mod.rs:1021-1025diff_state.rs:2891-2899规模声明
app/src/terminal/cli_agent.rs)cli_agent_is_on_path仅 1 处调用;is_on_path仅 3 处调用,均在同一文件内,无跨文件影响修改文件清单
app/src/terminal/cli_agent.rsLocalShellStateimport;CLIAgentInstallModel::new获取交互式 PATH future;cli_agent_is_on_path/is_on_path(unix & windows)增加path_env: Option<&str>参数验证
现有测试
cli_agent_tests.rs覆盖CLIAgent::detect,不覆盖is_on_path(私有函数),无需修改。影响面
CLIAgentInstallModel::is_cli_agent_installed的返回值会在 macOS GUI 启动场景下从false变为正确值settings_view/ai_page.rs:6351-6353中依赖此值渲染的"已安装 agent 列表"将正常显示is_cli_agent_installed仅被 UI 渲染代码读取)Generated by Claude Code