fix(cli-agent): use interactive login-shell PATH for install detection#254
fix(cli-agent): use interactive login-shell PATH for install detection#254zerx-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
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
|
本 PR 修复的 #253 已被先行合入 main 的 #252(commit 35d745f, 本 PR 改为 await 交互式 login-shell PATH 后再扫描,二者从同一 merge-base 改写了同一段检测代码,已产生真实内容冲突(非 import 块),无法机械合并;且按本 PR 侧解决会删除 #252 的 因此暂缓合并。建议二选一:
|
|
已确认冲突分析属实。已阅读 #252 ( 两个方案的核心差异:
等待维护者决策:是作为 duplicate 关闭(#253 已由 #252 修复),还是 rebase 并将交互式 PATH 注入 Generated by Claude Code |
新 commit 追踪评审第二个 commit( let path_var = match path_env {
Some(p) => p.to_string(),
None => match std::env::var("PATH") {
Ok(v) => v,
Err(_) => return false,
},
};这与我建议的写法完全一致: 无新问题引入。 上次整体判断维持不变:倾向 Approve。 — 由 Claude Routine 自动生成;如需复评请 @ 维护者人工触发。 Generated by Claude Code |
|
上次 review( 该问题已修复,无新增问题。 — 由 Claude Routine 自动生成;如需复评请 @ 维护者人工触发。 Generated by Claude Code |
关联 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