MoonshotAI / MoonshotAI/kimi-code
[Bug] npm install from an old native install (≤0.28) silently keeps the old binary: ~/.kimi-code/bin/kimi shadows the new npm shim via PATH
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
环境
- macOS 15.6(darwin 25.6.0,arm64),node v25.9.0,npm 11.19.0
- 旧版本:0.28.1,旧的原生二进制安装方式,二进制位于
~/.kimi-code/bin/kimi(Mach-O,约 158MB,同目录还有旧安装器附带的fd、rg) - 新版本:
@moonshot-ai/kimi-code@0.43.0,npm 全局安装(shim 位于/opt/homebrew/bin/kimi)
现象
旧版安装器曾把 export PATH="$HOME/.kimi-code/bin:$PATH" 写入 ~/.zshrc。之后按官方文档升级:
npm install -g @moonshot-ai/kimi-code@latest
安装成功退出、没有任何警告,但 kimi --version 仍输出 0.28.1——实际生效的仍是旧原生二进制。新版 shim 在 /opt/homebrew/bin/kimi,被 PATH 中更靠前的 ~/.kimi-code/bin/kimi 完全遮蔽,属于静默升级失败,用户无从察觉(0.43.0 本身功能正常,直接调用 /opt/homebrew/bin/kimi --version 可以验证)。
原因
0.43.0 的 postinstall 接管逻辑只识别并迁移旧 Python CLI 的 shim——按 realpath 解析后的 shim 内容包含 kimi_cli 标记来判断(apps/kimi-code/scripts/postinstall/migrate.mjs 中 const PYTHON_MARKER = 'kimi_cli'),并明确"不碰无法识别为旧 Python CLI 的 kimi"。旧的原生二进制安装(~/.kimi-code/bin/kimi + .zshrc 中的 PATH 行)不在处理范围内,于是被原样保留并继续优先命中。
期望
postinstall/takeover 增加对旧原生安装的识别与处理:
- 检测
~/.kimi-code/bin/kimi存在且不是本包安装的 shim(例如按 Mach-O/ELF 魔数或版本探测)时,将其重命名为kimi-legacy(与现有 Python shim 的迁移命名保持一致);和/或 - 安装结束时打印醒目警告,指出 PATH 遮蔽问题并给出修复命令。
临时解决办法(已验证)
mv ~/.kimi-code/bin/kimi ~/.kimi-code/bin/kimi-legacy
之后 which kimi → /opt/homebrew/bin/kimi,kimi --version → 0.43.0,--help 输出正常。fd、rg 保留在原目录不受影响,~/.zshrc 里的 PATH 行也无需改动。
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in apps/kimi-code/scripts/postinstall/migrate.mjs and trace the postinstall/takeover entry point, including its existing Python CLI marker handling. Reproduce the PATH-shadowing case with ~/.kimi-code/bin/kimi, then verify that installation handles the legacy native binary or clearly warns about it and that the new npm shim is the command users reach.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100