Skip to content

feat: stamp the build's git commit into every version display - #2345

Merged
ranxianglei merged 5 commits into
masterfrom
2026-10-07_version-commit-hash
Oct 7, 2026
Merged

ranxianglei merged 5 commits into
masterfrom
2026-10-07_version-commit-hash

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Why

While trialing a locally-installed build (npm install -g <worktree>) the semver alone cannot distinguish it from the npm release carrying the same version number — bili --version shows 0.1.187 either way. Add the build's git commit wherever a human reads a version.

What

  • scripts/write-build-info.mjs stamps dist/build-info.json at build time (git rev-parse --short + -dirty suffix when the worktree is dirty; unknown outside a git repo; never fails the build).
  • BUILD_COMMIT in src/version.ts: bundled code reads dist/build-info.json; dev (tsx) asks git directly.
  • Rendered at:
    • bili --version → 0.1.187 (8f9faf9e)
    • /acp panel host line → host=billion-context 0.1.187 (8f9faf9e)
    • web UI header chip + overview row → v0.1.187 (8f9faf9e)
    • /__bili/health, /__bili/status, /__bili/overview → additive commit field

Compatibility audit (why this is safe)

  • Every in-repo consumer matches the version by regex / startsWith / substring, none compares equality: canary e2e (assert.match), index-entry guard, acp-status panel test. All keep passing unchanged.
  • --version first token stays the bare semver, so shell users and scripts that take the first word keep working.
  • Display-only: the updater (semver compare), advisory watcher, MCP serverInfo, plugin manifest, logger [v=…] tags all keep bare package.json semver — zero update-path impact.
  • commit field on health/status/overview is additive JSON.

Tests

tests/build-info.test.ts (5): BUILD_COMMIT format; versionWithCommit; real --version subprocess (regex-friendly, starts with semver); live proxy boot (pre-probed free port — --port 0 is rejected by loadOptions) asserting health + overview commit. Plus existing acp-status / acp-panel / update-notes / web-config-form suites (38/38) and typecheck.

Fixes nothing on its own — observability for local trial builds (e.g. the #2337 lean trial).

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-07_version-commit-hash (b79a8ab)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2511-pr.2345.78f00a8

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-pr2345.tgz
npm install -g package

Install instructions are refreshed on each push.

ranxianglei added a commit that referenced this pull request Oct 7, 2026
--version now renders "<semver> (<commit>)"; the update-flip assertion keeps
its intent by matching the first token instead of the whole line.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到 #2345。正在定位对应的 PR 分支并核对代码与 CI 状态,稍后给出结论。

ranxianglei pushed a commit that referenced this pull request Oct 7, 2026
…dles

Bundle-relative path resolution assumed a flat dist layout: entries at dist/agent/*.js (and dist/kimi/*, dist/zcode/*) look one level up and miss both package.json (VERSION degraded to the 'dev' fallback in every subdirectory bundle, e.g. dsh-native log tags) and dist/build-info.json (BUILD_COMMIT fell back to a git spawn at import time, 'unknown' outside checkouts). Check two levels for both. Verified out-of-repo: dsh-native persistClientEvent now logs [v=0.1.187] instead of [v=dev]; top-level behavior byte-identical.
ranxianglei pushed a commit that referenced this pull request Oct 7, 2026
assert.match is search-semantics; the unanchored ^unknown alternative accepted any output merely starting with 'unknown'. Match the anchored ^$ form already used by the other assertions in this file.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 #2345 review 完成。方向正确、兼容面审过无回归;review 中发现同一根因的两个小问题已直接修在 PR 分支上(两个标注 commit,fast-forward,未动原三个提交):ffdfaa0c5(子目录 bundle 路径解析)+ e705677b8(测试正则收紧)。CI 已在全量矩阵上重跑(含 ubuntu/windows 的 hermetic registry e2e)。

结构化七问

  1. 是什么问题:本地 worktree 安装(npm install -g <worktree>)与携带相同 semver 的 npm 发布版无法区分——bili --version 两边都显示 0.1.187,trial build(fix: promptPack=lean actually reaches the proxy system prompt (kernel/packs) (#2335) #2337 lean trial 类)没有"跑的到底是哪份代码"的可观测性。
  2. 什么原因导致的:package.json 的 version 是唯一版本源,但 npm 发布与本地构建共享同一个版本号——不存在承载"这份代码由哪个 commit 构建"的信道。属可观测性缺口,不是既有代码缺陷。
  3. 怎么修复的:build 时把 git rev-parse --short HEAD(脏工作区加 -dirty,非 git 环境 unknown,永不 fail build)盖进 dist/build-info.json 随 tarball 发布;bundle 代码优先读它(识别的是 BUILD),dev(tsx)直接问 git(识别的是 CHECKOUT);只改展示层,更新路径零触碰。我的补充修复:bundle 相对路径解析原先假设平铺 dist 布局——子目录 bundle(dist/agent/*.js、dist/kimi/*、dist/zcode/*)向上一级同时找不到 package.json 和 dist/build-info.json,两处查找都改为检查两级(同一根因,一并修)。
  4. 是否有回归问题:逐项审过,无回归。既有行为清单及结论:①仓内所有版本消费方均为 regex/startsWith/substring 匹配、无一等值比较——canary e2e(assert.match 子串)、src/update.ts:1530 bootSmoke(只看 exit code、不解析 stdout)、acp-status 面板测试(startsWith)、plugin-list-version([Feature Request] bili plugin list 显示当前主机各 agent 已安装的 billion-context 版本 #2325,从 package.json/plugin.yaml 取值而非 --version)全部不受影响 ✓;②--version 首 token 保持裸 semver,取第一个词的脚本继续可用 ✓;③updater(semver 比较)/advisory/MCP serverInfo(直读 package.json)/logger [v=…] 标签全部保持裸 semver,更新路径零影响 ✓;④health/status/overview 为加性 JSON,deepEqual 类测试只锁子字段 ✓;⑤HELP banner 刻意保持裸 semver(稳定性)✓。高危模式(fail-fast 变吞错、阈值/时序漂移、输出格式破坏性变化)逐项排除。
  5. 是否破坏缓存:不涉及。无缓存/重试/增量游标/去重键变更;head system 字节稳定性与前缀缓存不受影响。
  6. 是否改了设计方向:不涉及。纯展示层增强,架构/边界/数据流无转向。
  7. 是否引入新配置:不涉及。无新 env/config 字段/CLI flag。

行为变更披露(旧→新+原因)

  • bili --version、/acp 面板 host 行、web UI header chip + overview 行:0.1.187 → 0.1.187 (<commit>) —— 本 PR 的预期功能本身。
  • /__bili/health:新增 version 和 commit 两字段(PR body 只提到加 commit,实际 diff 也加了 version——两者皆加性,旧客户端无感;body 略不全,不改你的文字,仅在此对齐)。status/overview 各加 commit。
  • 子目录 bundle 条目(ffdfaa0c5,review 顺手修):VERSION 由恒定的 "dev" 回退值 → 真实 package.json semver(仅影响 dsh-native 等日志标签 [v=…];已验证无任何逻辑对 "dev" 分支、无测试断言它);BUILD_COMMIT 由"import 时 spawn git、仓库外得 unknown"→ 读 stamp(消除每次 host plugin 启动一次无谓 git spawn)。顶层条目与 dev 模式行为字节级不变。仓库外 fake 安装实测:[v=dev] → [v=0.1.187]。

验证证据(本地定向,非全量):typecheck clean;build OK(stamp ed2496996-dirty);定向套件(master+PR 树)50/50 pass 0 skip,(推送树)46/46 pass 0 skip——差值是 PR base 之后 master 侧 #2325 给同目录测试文件新增的 4 个用例,与本 PR 无关;仓库外假全局安装探针:顶层 node dist/index.js --version → 0.1.187 (ed2496996-dirty) ✓。CI 覆盖说明:主 CI 先 npm test 后 build,故 2 个依赖 dist 的 e2e 用例按设计 skip(fcbe069 已处理);真实制品路径由每次 PR 触发的 ci-registry.yml(本地 verdaccio + 真 npm i -g + --version 探测)在合并前把关。

判定:可合并(等 CI 绿)。合并动作留给人工:#2345

ranxianglei and others added 5 commits October 7, 2026 22:52
…-build-identity)

The semver alone cannot distinguish a locally-installed test build from the
npm release with the same version number (exactly the situation while trialing
an unmerged fix). Add BUILD_COMMIT and render it wherever a human reads a
version:

- bili --version        → "0.1.187 (8f9faf9)" (first token stays bare semver;
                          all in-repo consumers match by regex, none compare equality)
- /acp panel host line  → billion-context 0.1.187 (8f9faf9)
- web UI header + overview row → v0.1.187 (8f9faf9) / "0.1.187 (8f9faf9)"
- /__bili/health and /__bili/overview → additive "commit" field

Resolution: bundled code reads dist/build-info.json stamped by
scripts/write-build-info.mjs at build time ("-dirty" suffix when the worktree
has uncommitted changes); dev (tsx) asks git directly; "unknown" otherwise.
The updater, advisory watcher and MCP serverInfo keep comparing/announcing
bare package.json semver — display-only, zero update-path impact.
--version now renders "<semver> (<commit>)"; the update-flip assertion keeps
its intent by matching the first token instead of the whole line.
…t PiSubagentChildSignal

- ci.yml runs npm test BEFORE npm run build; the two end-to-end build-info
  tests now skip when dist/index.js is absent (3 unit tests still run
  everywhere). Verified both modes locally (5/5 and 3 pass + 2 skipped).
- src/server/pi-subagent-channel.ts: drop the unused export flagged by
  unused-exports (pre-existing from #2268; same one-line fix the sibling
  branches carry).
…dles

Bundle-relative path resolution assumed a flat dist layout: entries at dist/agent/*.js (and dist/kimi/*, dist/zcode/*) look one level up and miss both package.json (VERSION degraded to the 'dev' fallback in every subdirectory bundle, e.g. dsh-native log tags) and dist/build-info.json (BUILD_COMMIT fell back to a git spawn at import time, 'unknown' outside checkouts). Check two levels for both. Verified out-of-repo: dsh-native persistClientEvent now logs [v=0.1.187] instead of [v=dev]; top-level behavior byte-identical.
assert.match is search-semantics; the unanchored ^unknown alternative accepted any output merely starting with 'unknown'. Match the anchored ^$ form already used by the other assertions in this file.
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