Skip to content

fix: probe the real pi npm copy dir + versioned specs in lane presence (#2850) - #2852

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-12_pi-npm-copy-version-probe
Oct 12, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-12_pi-npm-copy-version-probe

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2850

What

bili plugin list showed installed / unknown for pi's npm-managed copy even when the copy exists on disk with a readable version, and bili doctor reported empty targets for the same lane (false "pi materializes the npm copy on next startup" hint, stale never detected).

Two defects in the shared lane-presence probe (inspectLanePresence("pi"), src/plugin-install.ts):

  1. Wrong directory — the probe joined an extra "agent" segment onto resolvePiHome(), whose default is already ~/.pi/agent (and which honors PI_CODING_AGENT_DIR / PI_HOME). It read <piHome>/agent/npm/node_modules/billion-context instead of pi's real materialization path <piHome>/npm/node_modules/billion-context (the same path isPiNpmCopy() in src/pi-channel.ts already uses). pkgVersionAt() found nothing → unknown; targets stayed empty.
  2. Versioned specs misrouted — the npm branch matched only the exact string npm:billion-context. npm:billion-context@0.1.150 / @latest pass isBiliPiEntry() (so status said "installed") but fell into the local-path branch, which cannot resolve an npm copy either.

Fix

  • Extract piNpmCopyRoot(env) in src/pi-channel.ts as the single source of truth for the materialization dir; isPiNpmCopy() now uses it too (behavior-identical refactor).
  • inspectLanePresence("pi"): match any npm:billion-context spec form (/^npm:billion-context(@|$)/) and probe piNpmCopyRoot(). The spec suffix never changes the folder name; the displayed value still comes from the copy's on-disk package.json — never from the spec string or the running CLI version.
  • updateLane("pi") (adjacent instance of the same mechanism): versioned npm specs previously fell through to "entry points at this checkout — rebuild the checkout"; they now get the pi-managed message like the unpinned form.

Degradation semantics preserved: missing copy / corrupt manifest / no version field → unknown; unconfigured → not installed; corrupt settings.json → probe error (doctor reports a broken probe, never a false absent); absolute-path installs keep local-path semantics. Self-refresh gating unchanged (only the unpinned npm:billion-context spec self-refreshes, #1196).

Behavior changes (old → new)

Surface Old New
bili plugin list pi row (npm entry) always unknown (probe read a nonexistent dir) the copy's real on-disk version; unknown only when genuinely unresolvable
bili doctor pi npm lane targets always empty → false "materializes on next startup" hint; stale never detected real target + version; hint only when the copy is genuinely absent; stale verdict works against the registry
bili plugin update pi (versioned npm spec) "entry points at this checkout — rebuild the checkout" "plugin copy is pi-managed … pi update upgrades it"

No config surface, env var, or default changes. No kernel/ changes. Diagnostics-only code paths — no wire/persistence impact.

Tests

  • tests/plugin-list-version.test.ts: all three spec forms resolve the real copy while a decoy 9.9.9 sits at the old wrong path; default ~/.pi/agent + PI_HOME layouts; missing copy stays unresolvable.
  • tests/doctor.test.ts: inspectLanePresence pi npm lane (targets/copyVersion/form per spec form, decoy ignored, absent copy → empty targets, absolute-path local-path semantics, corrupt settings → probe failure) + runDoctor (stale verdict off the real version, false hint gone, hint returns only when the copy is genuinely absent).
  • Directed suites green on the rebased head (plugin-list-version, doctor, update-pi-self-refresh, plugin-update, plugin-agent, launcher); typecheck + build clean. Full regression delegated to CI.

…e presence (#2850)

inspectLanePresence("pi") probed <piHome>/agent/npm/node_modules/... — an extra
"agent" segment stacked on top of resolvePiHome()'s own ~/.pi/agent default — so a
real pi-managed copy never resolved: `bili plugin list` showed "unknown" and doctor
kept targets empty (false "materializes on next startup" hint, no stale verdict).
Versioned npm specs (npm:billion-context@pinned / @latest) were additionally
misrouted into the local-path branch by the exact-string PI_NPM_ENTRY match.

- extract piNpmCopyRoot() in pi-channel.ts as the single source of truth for the
  materialization dir (now shared with isPiNpmCopy)
- inspectLanePresence: match any npm:billion-context spec form, probe the real dir
- updateLane(pi): route versioned specs to the pi-managed message instead of
  "entry points at this checkout"
- regression tests: decoy copy at the old wrong path, all three spec forms,
  default/PI_HOME/PI_CODING_AGENT_DIR layouts, missing-copy degradation, corrupt
  settings probe failure, absolute-path local-path semantics, doctor verdicts
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-12_pi-npm-copy-version-probe (2e5d348)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3162-pr.2852.670bb92

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-pr2852.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] 🏷 收到。这是本 agent 已完成的工作(Closes #2850,含 ework-agent-pr 标记),不重做——现在按 review 流程核对:拉取分支对照当前 master、逐项回归审查、定向验证、查 CI 状态,随后给出结构化八问结论。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成(本 agent 已完成工作的复核,未重做)— 结论:可合并。

核对方式:拉取分支 head 2e5d3482b,对照当前 master(56b3ca354)逐行审 diff;cherry-pick 到当前 master 的临时 worktree 上重跑定向验证;查 CI。master 在 PR base 之后新增的 6 个提交(#2829 fetch-chain-log-channel、#2828/#2824 sketch+image-index perf 等)与本 PR 触碰的 4 个文件零重叠,rebase 干净无冲突(GitHub 侧 mergeable: true,state 仅 behind)。

五关审查结论

  • ① 原 issue 方向:独立复核实证两处根因均成立——(a) inspectLanePresence("pi") 旧代码拼出 <piHome>/agent/npm/...,而 resolvePiHome()(src/client-config.ts:366)默认值已含 ~/.pi/agent,探测读的是不存在的目录 → unknown + targets 恒空;(b) 精确匹配 entries.includes(PI_NPM_ENTRY) 让带版本 spec 落入 local-path 分支(旧 updateLane 同理误报 "entry points at this checkout"——已验证 isPiEntry 的正则确实放行带版本 spec,所以旧路径必达该消息)。修的是根因(错目录 + spec 形态匹配),不是遮症状;采纳了 issue 的 helper 提取建议,并遵守其明确警告(不用会吞解析错误的 piNpmEntrySpec(),保住 doctor 的配置损坏探测语义)。
  • ② 回归清点(逐项过既有行为):裸 spec 探测路径 错→对(有意变更,已披露);带版本 spec 路由 local-path→npm(有意变更,已披露);绝对路径安装 local-path 语义 保持(新测试钉住);settings.json 损坏 → probe error 而非假 absent 保持(新测试断言 throw /not valid JSON/);未配置 → not installed 保持;副本缺失/manifest 损坏/无 version 字段 → unknown 降级 保持;自刷新策略(仅裸 spec 自刷新,dsh plugin-market installs never auto-update: the refresh chain's only trigger is a global bili self-update #1196)未动(refreshPiNpmCopy 零 diff,定向套件绿);isPiNpmCopy 为纯提取重构、路径表达式逐字符相同。无 fail-fast 变吞错、无阈值/时序漂移、无 wire/persistence 影响(调用方仅 doctor/pluginStatusAll/pluginUpdate CLI 面)。
  • ③ 代码:新正则 /^npm:billion-context(@|$)/ 与既有 isBiliPiEntry 谓词完全一致(锚定,不会误配 npm:billion-context-x);piNpmCopyRoot() 成为物化路径单一事实来源,全仓 grep 确认无其他处硬编码旧错误路径;import 图无环(plugin-install→pi-channel→client-config/dsh-channel);无新依赖、无配置/env、无 kernel/ 改动、无 version 触碰;diff 内无 as any/@ts-ignore/console.error。
  • ④ 测试有效性:断言有牙——旧错误路径放 9.9.9 诱饵、真实副本 0.1.143,任何回退到旧路径的改动都会被打脸;三种 spec 形态循环覆盖;默认 ~/.pi/agent + PI_HOME + PI_CODING_AGENT_DIR 三种布局;缺失副本不回落 CLI 版本;doctor stale 判定与假提示消失/真缺失时恢复均对着 mock registry 断言。非恒真、非只测 mock。
  • ⑤ diff 整洁度:4 文件 +187/−4,单一线性提交,每一行都与本 PR 目的相关;无跑题文件、无空白噪音、无 lockfile/生成物连带。

本地验证(rebase 后 head):定向套件 6 个文件(plugin-list-version / doctor / update-pi-self-refresh / plugin-update / plugin-agent / launcher)405 项:404 过 / 0 挂 / 1 skip;typecheck 干净;完整 build 干净(dist-import-annotations OK)。全量回归由 CI 把关。

CI(head 2e5d3482b):16/16 check run 全部完成、零失败——test 矩阵(ubuntu/windows × node 22/24)、hermetic registry e2e ×2、build-artifact、docs-sync、version-guard、docs-coverage、config-surface-guard、kernel-guard、unused-exports、lock-sync、pi-subagents-guard、lane-guard。


结构化八问

  1. 是什么问题:Pi 独立 npm 副本明明在磁盘上且版本可读,bili plugin list 却恒显示 unknown、bili doctor 拿不到真实 target(误提示「下次启动才生成副本」、stale 永不触发);带版本 spec 还会让 plugin update pi 误报「指向本 checkout」。
  2. 什么原因导致的:共享 presence 探测两处缺陷——路径在已含 agent 段的 resolvePiHome() 之上多拼一层 agent(读不存在的目录);spec 匹配用精确字符串,带版本形态被误分到 local-path 分支。updateLane 是同一机制的相邻实例。
  3. 影响范围与严重程度:仅诊断面(list 版本列 / doctor pi lane / update 一条消息),所有使用 Pi 独立 npm 副本的用户受影响;体验瑕疵级——无数据丢失、无功能损坏、不影响压缩/代理行为。
  4. 怎么修复的:提取 piNpmCopyRoot() 作为物化路径单一事实来源(isPiNpmCopy 同步复用),探测改按 spec 形态匹配并读真实路径;展示值仍只来自磁盘 package.json(不用 spec 字符串或 CLI 版本兜底);updateLane 带版本 spec 路由到 pi-managed 消息。
  5. 是否有回归问题:无。上述②逐项清点全部「保持」或「有意变更且已披露」;高危模式(语义漂移、fail-fast 变吞错、阈值/时序/输出格式变化)逐项过完,除已披露的三处诊断面改善外无漂移。
  6. 是否破坏缓存:不涉及(纯本地文件读取的诊断路径,无缓存/重试/游标/去重键)。
  7. 是否改了设计方向:不涉及。在 Install-Lane & Update-Ownership Contract 内修复,反而消除了探测与 pi-channel 之间的双路径漂移源。
  8. 是否引入新配置:无。无新 env/config/默认值。

行为变更披露(旧 → 新,PR 正文已有表格,此处重申):① plugin list pi 行 npm entry:恒 unknown → 磁盘副本真实版本(真不可解析才 unknown);② doctor pi npm lane:targets 恒空 + 假提示 + stale 永不触发 → 真实 target+版本、提示仅在副本真缺失时出现、stale 判定恢复;③ plugin update pi(带版本 spec):「entry points at this checkout」→「copy is pi-managed … pi update upgrades it」。

收工判定:代码、测试、CI 全绿,rebase 验证干净,无回归——可合并(合并按规矩由人工执行:https://github.com/ranxianglei/billion-context/pull/2852)。

@ranxianglei
ranxianglei merged commit a8d9dc3 into master Oct 12, 2026
16 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.303-master.a8d9dc3 (rolling master tag).

npm install -g billion-context@0.0.303-master.a8d9dc3  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

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.

bug: bili plugin list 无法读取 Pi 独立 npm 副本版本(unknown)

1 participant