Open
Conversation
当用户同时安装了 nvm 管理的 openclaw 和 Homebrew 版本时, 面板显示的是 Homebrew 的旧版本而非实际激活版本。 根本原因有两处: 1. `resolve_openclaw_cli_path` 在非 Windows 平台优先检查硬编码的 Homebrew 路径(/opt/homebrew/bin),排在 enhanced_path 之前, 导致 nvm 激活版本被绕过。修复:将 enhanced_path 搜索提前, common_non_windows_cli_candidates 降为兜底,与 `which openclaw` 优先级保持一致。 2. `read_version_from_installation` 只查找 dir/node_modules/<pkg>/package.json, 对 npm 全局安装(nvm/Homebrew 均为此结构),CLI 本体位于包目录内, 应直接读取 dir/package.json。修复:在 node_modules 搜索前先尝试读取同目录的 package.json。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
问题现象:当系统存在两个 openclaw 实例时(如 nvm 新版本与 Homebrew 旧版本共存),面板无法获取实际运行实例的版本号,显示的是非活跃旧版本。 根本原因: 1. get_local_version 通过文件路径推断版本,无法反映正在运行的实例 2. resolve_openclaw_cli_path 优先检查硬编码的 Homebrew 路径, 排在 enhanced_path(含 nvm)之前,导致活跃版本被绕过 3. read_version_from_installation 不读取 dir/package.json, 无法从 npm 全局安装结构(nvm/Homebrew 均为此结构)中提取版本 修复方案: 1. get_local_version 优先执行 `openclaw status --json` 获取 runtimeVersion,即运行中实例自身汇报的版本,服务未运行时 再降级到原有文件读取逻辑 2. resolve_openclaw_cli_path 将 enhanced_path 搜索提前, 与 `which openclaw` 优先级一致,硬编码路径降为兜底 3. read_version_from_installation 增加读取 dir/package.json, 正确处理 CLI 本体位于包目录中的 npm 全局安装场景 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
问题描述
当系统存在两个 openclaw 实例时(如 nvm 管理的新版本与 Homebrew 遗留的旧版本共存),面板无法获取实际运行实例的版本号,显示的是非活跃的旧版本。
根因分析
1.
get_local_version通过文件路径推断版本,无法反映正在运行的实例(config.rs)函数通过读取磁盘上的
VERSION文件或package.json来获取版本号,本质上是"猜测"当前安装的版本,与正在运行的进程无关。当多个实例共存时,读到哪个文件取决于路径查找的优先级,而非实际运行的是哪个实例。2.
resolve_openclaw_cli_path路径优先级错误,硬编码 Homebrew 路径排在 PATH 之前(utils.rs)非 Windows 平台的查找顺序为:硬编码路径(含
/opt/homebrew/bin/openclaw)→enhanced_path()PATH 搜索。而enhanced_path()内部已将 nvm/volta 等版本管理器路径排在 Homebrew 之前。由于硬编码路径先执行,只要/opt/homebrew/bin/openclaw存在,就会被优先返回,完全绕过 nvm 激活的实例。3.
read_version_from_installation无法从 npm 全局安装结构中读取版本(config.rs)函数只查找
dir/node_modules/<pkg>/package.json,但 npm 全局安装(nvm/Homebrew 均为此结构)的 CLI 文件本身就位于包目录内,版本文件直接是dir/package.json,导致函数始终返回None,代码继续向下触发 Homebrew 兜底逻辑,读到旧版本号。修改方案
Fix 1:
get_local_version优先查询运行实例(config.rs)在函数最开头执行
openclaw status --json,从返回值的runtimeVersion字段直接取版本号。这是运行中的 openclaw 实例自身汇报的版本,与磁盘上有多少个安装无关。仅当 openclaw 未运行(命令失败或无该字段)时,才降级到原有的文件读取逻辑。Fix 2:
resolve_openclaw_cli_path调整路径查找优先级(utils.rs)将
enhanced_path()搜索提前,common_non_windows_cli_candidates()硬编码路径降为兜底。enhanced_path()已将 nvm 版本目录按版本号倒序排在 Homebrew 之前,调整后与which openclaw优先级一致。硬编码路径仅保留作为 GUI 环境 PATH 受限时的兜底。Fix 3:
read_version_from_installation增加读取dir/package.json(config.rs)在
VERSION文件检查之后、node_modules搜索之前,新增直接读取dir/package.json的逻辑,正确处理 CLI 本体位于包目录中的 npm 全局安装场景(nvm/Homebrew 均为此结构)。修复后完整降级链路:
验证结果
复现环境:macOS,nvm 管理 openclaw
2026.4.11(活跃),Homebrew 遗留 openclaw2026.3.23-2(非活跃,Node.js 已卸载)。package.jsonopenclaw status --json→runtimeVersion2026.3.23-2❌2026.4.11✅openclaw --version一致