Skip to content

refactor(launcher): replace the fifteen buildXxxEnv copies with one preset-table builder (#1440 P3) - #2306

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-07_launcher-env-table
Oct 7, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-07_launcher-env-table

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Issue #1440 P3 — collapse the fifteen copy-pasted buildXxxEnv functions in src/launcher.ts into one preset table + one private builder. Behavior-preserving: every exported signature stays byte-identical and returned env objects are value-equal (plus key-order-equal) for every client under every parameter combination.

Design

One module-private table + builder inserted between buildPiEnv and buildCodexEnv:

Net: src/launcher.ts 121+/93−, no new exports (table/builder stay module-private → the unused-exports gate from #1443 unaffected), no new deps, call sites untouched.

Equivalence proof

  • Snapshot script imported all 15 builders from source and emitted sorted-key canonical JSON for 43 client × param-combo lines (aider routeHttp both ways incl. stale-preseeded HTTP_PROXY; claude/codebuddy/gemini/iflow/antigravity × {none, http-only, https-only, both-schemes https-wins, no-match}; pi manifest edge cases; claude-plugin direct=false identity + direct=true fallback chain). BEFORE (pre-refactor tree) vs AFTER: diff exit 0, empty output, 43/43 equal. Script was throwaway, not committed.
  • Declaration-header audit: all 15 export function …(params): NodeJS.ProcessEnv { blocks byte-identical old vs new.
  • Comment audit: occurrence counts of all issue-tag comments unchanged.

Verification

  • Focused suites: tests/launcher.test.ts 282 ✓ · launcher-gemini-family 28 ✓ · launcher-plugin-mode 9 ✓ · codex-overlay-env 15 ✓ (0 fail)
  • npx tsc --noEmit clean · tsup build OK

Follow-up per #1440 P3 after this lands: nothing further in the env family (pi/claude-plugin are the honest bespoke remainder); remaining P3 items are the runLaunch per-client copies and the plugin-install XInstall/XRemove registry — larger, separate PRs.


Rebase note (master moved past v0.1.187)

Rebased onto 95ad8d25 — clean, zero conflicts (master's launcher changes since our base are all outside the builder region). Second commit is a one-line gate fix: master's own unused-exports job has been red since #2268 (PiSubagentChildSignal internal-only) — same mechanical demote this repo already used for codexRewriteInsertionIndex at release time (371b15b5); separate commit so it can be cherry-picked/dropped independently. Re-verified post-rebase: gate exit 0 · tsc clean · tsup OK · launcher suites 334/334 (launcher / gemini-family / plugin-mode / codex-overlay-env).

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-07_launcher-env-table (9435ccf)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2479-pr.2306.343744e

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-pr2306.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

🔍 Review of PR #2306 (refactor(launcher): preset-table builder · #1440 P3)

⚠️ 首要发现 —— 与 #1450 重复,合并前必须二选一
#2306 与仍处 open 的 #1450(converge buildXxxEnv family into data-driven client-env presets (#1440),分支 2026-09-27_client-env-dedup)是同一父 issue #1440、同一文件 src/launcher.ts、同一 buildXxxEnv 家族的两个并行实现(#1450:1 commit / 45+ 33−;#2306:1 commit / 121+ 93−)。两者改的是同一片行,无法同时落地。#2306 基于当前 master、覆盖全部 13 个表驱动客户端(含 gemini/iflow/qwen/antigravity 的 base-URL 族)、并把承重注释逐条搬进表项;#1450 更旧更小。建议:保留 #2306,关闭 #1450(superseded) —— 请你拍板(我不擅自关他人 PR)。

结构化七问

  1. 是什么问题:audit: 全仓冗余审计与重构计划——server.ts 解体、客户端矩阵去重、死代码、AGENTS.md 模块图腐化 #1440 全仓冗余审计的 P3 子项 —— src/launcher.ts 里 15 个 buildXxxEnv 是复制粘贴,其中 13 个函数体近乎逐字相同(仅差 CA 变量名、proxy 开关、NO_PROXY 附加、base-URL key)。属可维护性隐患(每接一个客户端抄 60–100 行、副本间易漂移),不是行为 bug。
  2. 什么原因导致:DRY 违规 —— 所有客户端共享同一骨架 {...baseEnv, HTTPS_PROXY=<origin>, <CA>=<caPath>, BILLION_CONTEXT_PROXY=<origin>},差异只在少数字段,却被写成 13 份独立字面量。
  3. 怎么修复:正是 audit: 全仓冗余审计与重构计划——server.ts 解体、客户端矩阵去重、死代码、AGENTS.md 模块图腐化 #1440 P3 规定的「数据表 + 一个 buildClientEnv(preset,…)」:模块私有 ENV_CLIENTS 表(caKeys/proxy/httpProxyOnRouteHttp/extras/baseUrlKeys)+ 单一 buildClientEnv(),按键序复刻每个原字面量的插入顺序;13 个 wrapper 变一行委托;三重复制的 loopback 字面量去重为 LAUNCHER_LOOPBACK_NO_PROXY;承重注释(能否新增对traecli的支持 #655/feat: 新增 qoder 客户端支持(bili qoder) #653/新增 bili gemini 启动器(Gemini CLI,可扩展覆盖同系 Qwen Code / iFlow) #1047/新增 bili aider 启动器 #1048/新增 bili copilot / bili amp / bili goose 启动器(第三梯队) #1049×2/feat: support Antigravity (CLI / extension) — first-class integration #2115/gateway-mode)逐条移到对应表项。buildPiEnv(JSON manifest)+ buildClaudePluginEnv(direct-URL 形态)刻意保留 bespoke。
  4. 回归风险:行为保持。我逐客户端核对了值相等 + 键序相等,覆盖 aider routeHttp 双向(含 stale-preseeded HTTP_PROXY)、claude/codebuddy/gemini/iflow/antigravity × {none / http-only / https-only / both-https-wins / no-match};两个 bespoke 未触碰。签名零变化、调用点未动、无新增导出(表与 builder 均模块私有 → refactor: drop dead declarations + demote internal-only exports + unused-export gate (#1440) #1443 unused-export 门禁不受影响)。高危模式逐项过:无 fail-fast 变吞错、无阈值/时序/输出格式漂移(纯 env 对象构造)。既有 tests/launcher.test.ts 用 assert.deepEqual 钉住各 builder 输出(含 rewrite 有/无两态),是真实回归护栏。CI 尚 pending(会跑全量门禁含 4 组聚焦套件)。
  5. 是否破坏缓存:不涉及 —— 只碰启动期子进程 env 构造,不触及代理缓存 / 重试游标 / 去重键 / 持久化。
  6. 设计方向:未变。模块内 DRY 重构,导出 API 逐字节不变,表 + builder 有意保持私有(不新增公共面)。
  7. 新配置:无。无新 env / config / CLI flag / 默认值。

非阻塞小观察(不影响合并):buildClientEnv 里 for (k of baseUrlKeys) env[k] = wrapUpstream(…) 对 iflow(2 个 key)会把纯函数 wrapUpstream 多算一次,结果确定等价,仅微效率差异;可留可修。

判定:#2306 本身可合 —— 干净单文件 121+/93−,行为保持,测试护栏在位,基于最新 master 无需 rebase(mergeable_state=blocked 只因 CI/review 未完成,非冲突)。唯一前置:先解决与 #1450 的重叠(建议关 #1450),并等 CI 转绿。

@ranxianglei
ranxianglei force-pushed the 2026-10-07_launcher-env-table branch 2 times, most recently from a835786 to 9435ccf Compare October 7, 2026 12:56
@ranxianglei
ranxianglei merged commit ed24969 into master Oct 7, 2026
25 checks passed
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.111-master.ed24969 (rolling master tag).

npm install -g billion-context@0.0.111-master.ed24969  # 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