Skip to content

refactor(launcher): consolidate per-client binary-resolution copies into shared helpers (#1440 P3) - #2553

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-09_launcher-resolve-command
Oct 10, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-09_launcher-resolve-command

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Follow-up to #2453 in the same audit (#1440 P3 copy-paste matrix): the per-client binary-resolution copies inside resolveClientCommand (src/launcher.ts) collapse onto two module-private helpers. Pure move — zero behavior change, no new exports, one file touched.

What moved

  • firstOnPath(names, env) — ordered alias-chain PATH probe; used by the three true chains: codebuddy (codebuddy→cbc), qoder (qoder→qodercli), trae (traecli→trae-cli→trae). Short-circuits in the same left-to-right order as the old a ?? b chains.
  • probeInstalledBin(base, exts) — the install-dir extension probe (try/catch-swallowed existsSync loop) that mcode and antigravity each had inline; keeps each client's exact ext order (mcode win32 .cmd/.bat/.exe, antigravity win32 .exe) and returns first hit else bare base. The moved // Unreadable candidate… comment travels verbatim.
  • Left verbatim on purpose: BILI_CLIENT_BIN pre-pass, pi ladder, kimi (its fallback has no extension probing — routing it through the helper would add a pointless fs stat with zero behavioral delta), codex-win32 guard + its [Bug][Windows launcher] 经 codex.cmd 启动破坏 argv:嵌入引号拆分、%变量% 展开和 & 被解释 #2196 block, default tail.

Net: +28/−26 lines — the win is removing two duplicated probe bodies and three duplicated lookup patterns, not raw size.

Verification

  • Equivalence: canonical-JSON snapshot of resolveClientCommand over all 24 LAUNCH_CLIENTS × {linux, darwin, win32} (platform passed explicitly) × 6 env fixtures (PATH-hit / no-PATH home-fallback / PI_BIN / BILI_CLIENT_BIN / …), 432 rows, captured pre-edit on pristine tree and post-edit — diff empty.
  • Suites: launcher 292/292, launcher-gemini-family 28/28, fix-679-windows-launch 14/14 (2 platform-gated skips, pre-existing), route-passthrough 7/7. tsc --noEmit, npm run build, unused-export gate clean; lane-guard keyword precheck clean (no side-lane terms in diff).

…nto shared helpers (#1440 P3)

- Added two module-private helpers before resolveClientCommand: firstOnPath
  (left-to-right alias-chain PATH probe) and probeInstalledBin (ordered ext
  probing over an install-dir base path incl. the try/catch swallow).
- Rewrote the codebuddy, qoder, trae branches onto firstOnPath; the mcode and
  antigravity branches onto probeInstalledBin; comments moved verbatim.
- kimi left as-is: its fallback has no extension probing, so routing it through
  probeInstalledBin would add a pointless fs stat with zero behavioral value.
- pi ladder, BILI_CLIENT_BIN pre-pass, codex-win32 guard, and default tail are
  untouched.
- Equivalence proof: canonical-JSON snapshot matrix 24 clients x 3 platforms x
  6 fixtures = 432 rows via tsx harness; before/after diff empty.
- Suites: launcher.test.ts 292/292 pass; launcher-gemini-family 28/28;
  fix-679-windows-launch 14/14 (2 skipped, platform-gated);
  route-passthrough 7/7. tsc --noEmit clean, build OK, unused-export gate
  clean, lane-guard LANE-CLEAN.
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-09_launcher-resolve-command (a964319)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2733-pr.2553.54ba230

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-pr2553.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] 🏷 Review in progress — pulling branch 2026-10-09_launcher-resolve-command (a964319) for a full diff read + targeted verification. Will follow up with the structured conclusion.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成(PR 分支 2026-10-09_launcher-resolve-command @ a964319,单文件 src/launcher.ts +28/−26)。按八问作答:

  1. 是什么问题:audit: 全仓冗余审计与重构计划——server.ts 解体、客户端矩阵去重、死代码、AGENTS.md 模块图腐化 #1440 P3 copy-paste 审计(refactor(launcher): collapse per-client route-discovery copy into shared family helpers (#1440 P3) #2453 的后续切片)——resolveClientCommand 内五个客户端的二进制解析各抄了一份:codebuddy/qoder/trae 三条同构的有序别名链,mcode/antigravity 两份同构的 install-dir 扩展名探测循环。纯重复代码,无行为缺陷。
  2. 什么原因导致的:历史复制粘贴。同一「PATH 有序探测」和「existsSync 扩展名回退」模式被逐客户端内联,长期看有漂移风险(某处修一处漏另一处)。
  3. 影响范围与严重程度:重构本身零外部影响。风险面是五个客户端在 linux/darwin/win32 的启动解析——若等价性不成立会直接 launch 失败,已用独立等价性证明排除(见第 5 问)。
  4. 怎么修复的:两个模块私有 helper。firstOnPath(names, env) 左→右短路探测,替换三条 a ?? b ?? c 链,顺序逐条保持;probeInstalledBin(base, exts) 承接 try/catch-swallowed 的 existsSync 循环,保留 mcode(win32 .cmd/.bat/.exe)与 antigravity(win32 .exe)各自的精确扩展序,无命中回落裸 base,原注释随迁。kimi、BILI_CLIENT_BIN pre-pass、pi ladder、codex-win32 guard([Bug][Windows launcher] 经 codex.cmd 启动破坏 argv:嵌入引号拆分、%变量% 展开和 & 被解释 #2196)、default tail 有意留白——kimi 回退没有扩展名探测,套 helper 只会多一次无意义的 fs stat。无新导出。
  5. 是否回归问题:未发现。除作者自述的 432 行快照外,我做了独立验证:① 自建等价性 harness——24 个 LAUNCH_CLIENTS × {linux,darwin,win32} × 8 组 env fixture(PATH 命中/仅次级别名命中/mcode .cmd 优先/mcode 仅 .exe/agy LOCALAPPDATA/BILI_CLIENT_BIN/PI_BIN/全空回落)= 576 行,分别在 master 版与 PR 版 launcher.ts 上快照,diff 为空(字节级一致);② 本地复跑定向四套件(launcher / launcher-gemini-family / fix-679-windows-launch / route-passthrough):340 pass / 0 fail / 3 skip(平台门控,既有);③ tsc --noEmit 在 PR head 干净;④ CI 全绿(24/24 checks,含 windows-latest 双测试矩阵)。一个值得点名的语义细节:旧链用 ??(nullish),新 helper 用真值判断提前返回——已核实 resolveOnPath(src/launcher.ts:4308-4321)只可能返回 undefined 或非空绝对路径(dir/name 均有非空守卫),空串不可达,两者严格等价。既有测试也钉住了每条被移动的路径(launcher.test.ts:5103 codebuddy 链、:5354 qoder 回落、:5875 trae 链、mcode.cmd install-dir 探测命中),回归时抓得住。
  6. 是否破坏缓存:不涉及——未触碰任何缓存/重试/增量游标/去重键逻辑。
  7. 是否改了设计方向:不涉及——同文件同函数内部整理,私有 helper,无导出面/wire/持久化/配置面变化。
  8. 是否引入新配置:不涉及。

补充:diff 整洁度合格(单文件,每行都服务于去重目的,无无关改动/空白噪音);review 中未发现需要顺手修的小问题。master 在分支点后前进了 9 个提交(#2545/#2546/#2547/#2548/#2549/#2550/#2551 等),但逐一核对过文件清单,没有一个触碰 src/launcher.ts 或本 PR 的任何行,mergeable=true,「behind」不构成阻塞,rebase 是零内容操作,合并时由 GitHub 处理即可。

判定:可合。

@ranxianglei
ranxianglei merged commit 4fce5d3 into master Oct 10, 2026
24 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.198-master.4fce5d3 (rolling master tag).

npm install -g billion-context@0.0.198-master.4fce5d3  # 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.

1 participant