Skip to content

Default install to a user-level npm prefix (~/.local) - #2292

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-07_user-level-install-prefix
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-07_user-level-install-prefix

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Summary

Closes #2217 (来源: dog/billion-context#16, internal tracker — owner-directed).

Make the documented default install a user-level npm prefix so Linux/macOS users never land on a root-owned global prefix — the cohort behind the #1603/#2192 update retry-storms (a sudo-created root-owned install fails self-update at the swap stage and re-downloads the tarball every 3-min cycle, up to ~480 downloads/day/machine).

What changes (旧 → 新)

where before after
README.md Install one plain npm install -g billion-context block Linux/macOS: npm config set prefix "$HOME/.local" + PATH line (with "add to ~/.bashrc / ~/.zshrc" note) + install; nvm/Homebrew-Node and Windows keep the plain install; EACCES troubleshooting → the two prefix lines + reinstall, "avoid sudo"
README.zh-CN.md 安装 same plain block zh mirror of the above (zh/en kept in sync)
website/blog/posts/2026-10-08_meet-bili.md / .zh.md bare install sentence adds the user-prefix parenthetical for non-nvm/Homebrew Linux/macOS (both are pre-launch drafts)
src/update.ts remediationHint (/not writable/ branch) "point npm at a user-writable prefix and reinstall (npm install -g …)" — generic platform-split: POSIX gets the concrete npm config set prefix "$HOME/.local" (+ put "$HOME/.local/bin" on PATH) then reinstall; win32 gets "the default npm prefix (%APPDATA%\npm) is user-writable — repair that dir's ownership/permissions and reinstall"

The remediation hint is emitted on the #1603 backoff escalation log line only. String-only change — no download/extract/install/version-check logic touched, and no test asserts the old string. Flagging for the human reviewer per §5: src/update.ts changes normally route through the no-op-release protocol; this is a user-guidance string, not updater logic — owner decides whether staging is still wanted.

Windows compatibility

Windows keeps the plain install: npm's default prefix there (%APPDATA%\npm) is already user-writable, and the $HOME bash-isms don't apply — so the prefix flow is deliberately NOT advertised for Windows anywhere. The update.ts hint branches on process.platform.

Why this is the root-cause fix

The retry storm is produced at install time (docs teaching npm i -g onto a root-owned prefix → sudo → root-owned files). Preventing the root-owned prefix removes the producer; the concrete remediation string unblocks machines already stuck (#1603's "124× over 12 days" class). Downstream compatibility is already in place: client discovery searches ~/.local/lib/node_modules (src/agent/opencode-legacy.ts:113) and ~/.local/bin (src/pi-channel.ts:74, src/dsh-channel.ts:230, src/launcher.ts:3720).

Not changed (deliberately)

  • Hero one-liners (README.md:16, README.zh-CN.md:16, website/index.html chip) — correct for Windows/macOS/nvm; the Install section carries the prefix setup.
  • TECHNICAL-NOTES.md/.zh-CN.md install-lane tables — descriptive, not setup instructions.
  • CI workflow PR-comment snippets and reference/*.md internal recipes — dev/CI contexts with healthy prefixes.
  • Upgrade-banner hints (update-notes.ts, acp-status.ts, advisory.ts, web/client.ts) — nudges for already-running installs; the broken-prefix cohort hits the update.ts escalation hint instead.

Config surface

None — docs plus one log string; no config/env/flag additions.

Pre-flight (on this branch, master @ 9f82bbe + diff)

Review note

NOT auto-merge eligible (touches src/update.ts, §7.4 must-stay-human). Human review requested.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-07_user-level-install-prefix (4aa1233)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2419-pr.2292.0f416b0

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr2292.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR #2292 review — 可合(待 CI 全绿;合并由人执行)

先说结论:代码层面我找不到阻塞项。这是一个「文档 + 一条日志字符串」的窄改动,方向打在根因上,diff 干净,无回归。按七问给结论:

1. 是什么问题
文档默认安装方式把 bili 教到 root 属主的 npm global prefix(Linux/macOS 上 npm i -g 常落 root 目录 → 用户被迫 sudo → root-owned 文件)。这是 #1603/#2192 自更新重试风暴的源头。本 PR 把文档默认改成用户级 prefix(~/.local),并给已经卡住的机器一条具体修复提示。

2. 什么原因导致的
重试风暴在安装时产生:root-owned prefix 让自更新在 swap 阶段失败,旧行为下每个 3 分钟周期重下 tarball(~480 次/天/机)。根因是安装目标属主错误,不是更新逻辑本身。#1603 已加退避止血,但没消除「root-owned prefix」这个生产者——本 PR 补的就是这一环。

3. 怎么修复的
疏而非堵,在源头(安装文档)阻止 root-owned prefix:README 英/中默认改为 npm config set prefix "$HOME/.local" + PATH 行(nvm/Homebrew/Windows 保持 plain install);对已卡住的机器,把 src/update.ts 升级日志那条通用提示按平台拆具体命令(POSIX 给 set-prefix 两步,win32 给 %APPDATA%\npm 修复说明)。只动引导文案 + 一条日志字符串,不碰下载/解包/安装/版本检查逻辑。

4. 是否有回归问题 — 无。逐项过触碰路径的既有行为:

  • remediationHint 的 /not writable/ 分支(src/update.ts:399-404):控制流不变(同一正则门、同样单 return),仅返回文案按平台分流;两条分支都保留了原有的 autoUpdate:false / ACP_AUTO_UPDATE=0 兜底尾巴。
  • 触发时机未变:该提示只在 auto-update installs but never activates on long-lived plugin hosts; unwritable install dir retries every 3-min cycle for 11+ days #1603 退避升级行发出(src/update.ts:454,经 installBackoffRemediatedKeys 保证每 key 每进程一次);owner lanes 仍传自己的 hint 覆盖全局措辞。退避阈值(BACKOFF_THRESHOLD/BASE_MS/CAP_MS)全部未动。
  • 下载/解包/安装/版本检查逻辑:读了 src/update.ts:398-458 确认未触及。
  • 高危模式排查:无 fail-fast→吞错、无阈值/时序漂移、无 proxy 输出格式变化、无缓存/重试策略变化。
  • 文档改动纯增量,未删既有正确信息;hero 一行式(README.md:16/.zh-CN.md:16)刻意保留(对 Windows/macOS/nvm 本就正确)。
  • 唯一有意变更 = 那条 warn 级日志文案(旧→新见 PR 表格),作者已在 PR 体披露。

5. 是否破坏缓存 — 不涉及。不触碰任何缓存/重试游标/去重键;install-backoff 状态文件读写路径未改。

6. 是否改了设计方向 — 不涉及。架构/边界/数据流无转向;只是把「推荐安装位置」从 root global prefix 移到用户级 prefix,与现有下游发现路径一致——已逐处核实:src/agent/opencode-legacy.ts:113 搜 ~/.local/lib/node_modules,src/pi-channel.ts:74、src/dsh-channel.ts:230、src/launcher.ts:3720 均搜 ~/.local/bin。用户级 prefix 装完即可被这些通道发现。

7. 是否引入了新的配置 — 不涉及。无新 env/config/flag;仅文档 + 一条日志字符串。


几点补充判断:

  • 平台检测一致性:src/update.ts:400 用 process.platform === "win32",与 pi-channel.ts/dsh-channel.ts/launcher.ts 里 platform === "win32" 的既有约定同构,无引入新风格。em-dash 用 \u2014、反斜杠 %APPDATA%\\npm 转义均与本文件既有写法(line 454 的 \u2014/\u00d7)一致。
  • 测试有效性:无测试改动,且确认没有测试断言旧字符串(grep 全 tests/ 无命中,golden/wire-contract 不含日志串)。这是纯引导文案,仓库对其余分支(git working tree / managed by / default)也无断言,保持一致,不需要新增恒真文案测试。
  • §5 no-op 验证发布:PR 体把这个决定留给 owner。我的判断——无需 no-op staging。no-op 协议保护的是「updater 自身逻辑坏了会砖掉所有后续升级」,而本改动零 updater 逻辑面(纯用户引导日志串,不碰安装/解包/版本检查),不存在破坏升级链路的途径。建议跳过,请 owner 确认。
  • CI 状态(review 时刻):build-artifact、lane-guard、version-guard、kernel-guard、docs-sync、docs-coverage 已绿;ubuntu/windows 全量 test 与 hermetic-registry e2e 仍在跑。改动为文档+单条日志串,风险低;PR 体报告本地 npm test 4562 pass / 0 fail。

判定:可合(代码层面无阻塞项,待全量 CI 转绿)。非 auto-merge 资格——§7.4 触碰 src/update.ts,须人工合并。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant