billion-context 0.1.102 → 0.1.103-pr.694.524

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -158,7 +158,7 @@ rewrite until dsh gains a settings-path env or an upstream loopback opt-out.
158
158
  Overlay dirs created by older versions are left in place and never merged back
159
159
  into the real home.
160
160
 
161
- ### Option 1 — Launcher (`bili pi` / `bili codex` / `bili claude` / `bili omp` / `bili opencode` / `bili hermes` / `bili dsh`)
161
+ ### Option 1 — Launcher (`bili pi` / `bili codex` / `bili claude` / `bili omp` / `bili opencode` / `bili hermes` / `bili dsh` / `bili codebuddy` / `bili qoder` / `bili trae`)
162
162
 
163
163
  The launcher wraps a client in one command: it starts a proxy on an
164
164
  independent port (a fresh instance is always spawned — a port is never
@@ -177,6 +177,9 @@ bili omp # pi-style, file-free (#535): env + extens
177
177
  bili opencode # MITM for HTTPS + temp opencode.json (/bili/ for HTTP) + thin /acp plugin
178
178
  bili hermes # file-free (#535): hermes proxy env (HTTPS_PROXY + HERMES_CA_BUNDLE) — https via CONNECT MITM, http via absolute-form forward proxy; real ~/.hermes untouched
179
179
  bili dsh # deepseek-harness: non-loopback upstreams ride proxy envs (https MITM, http absolute-form), loopback keeps the overlay DSH_HOME (~/.dsh-bili) rewrite (#535), built-in deepseek route via DEEPSEEK_BASE_URL, native /acp command injected via --patch
180
+ bili codebuddy # Tencent CodeBuddy Code CLI: CODEBUDDY_BASE_URL /bili/ rewrite (OpenAI chat completions wire), budget aligned via CODEBUDDY_AUTO_COMPACT_WINDOW; real ~/.codebuddy untouched
181
+ bili qoder # qoder: model endpoint is hardcoded https (no /bili/ rewrite possible) — cert-MITM via HTTPS_PROXY + NODE_EXTRA_CA_CERTS, default model hosts whitelisted (#653)
182
+ bili trae # Trae CLI (ByteDance, closed Go binary, no base-URL override) — cert-MITM via HTTPS_PROXY + SSL_CERT_FILE, model host from TRAE_CLI_API_HOST or the default enterprise gateway (#655)
180
183
  bili pi --mitm-domain api.foo.com # add a domain to the MITM whitelist
181
184
  ```
182
185
 
package/README.zh-CN.md CHANGED
@@ -84,7 +84,7 @@ npm install -g billion-context
84
84
 
85
85
  bili 永不拥有用户数据:每个被启动的客户端都跑在**真实 home** 上,运行期写入落在用户预期的位置。把客户端指向代理时,启动器按优先级选择——**优先 env 变量**(hermes/dsh/codex 的代理/CA env;pi/omp 的 `BILI_PROVIDER_REWRITES` URL 清单,由扩展加载时经 `registerProvider` 消费),其次 **CLI 参数或扩展 API**(codex `-c key=value`、opencode 插件),最后才是**生成文件**——目前仅剩 opencode 的临时 `opencode.json`(退出即删)和 dsh 的回环例外:dsh 的 fetch 栈对回环目标无条件绕过代理 env,所以本地上游保留持久 `~/.dsh-bili` overlay 改写,直到 dsh 提供 settings-path env 或上游支持回环 opt-out。旧版本创建的 overlay 目录原地保留,绝不合并回真实 home。
86
86
 
87
- ### 方式 1 —— 启动器(`bili pi` / `bili codex` / `bili claude` / `bili omp` / `bili opencode` / `bili hermes` / `bili dsh`)
87
+ ### 方式 1 —— 启动器(`bili pi` / `bili codex` / `bili claude` / `bili omp` / `bili opencode` / `bili hermes` / `bili dsh` / `bili codebuddy` / `bili qoder` / `bili trae`)
88
88
 
89
89
  启动器把客户端包进一条命令:在独立端口拉起一个代理(总是全新实例,绝不复用端口),再按客户端支持的机制把它指向代理 —— 能吃代理/CA 环境变量的走**证书 MITM**,不吃的走隔离的**`/bili/` 配置重写**。真实配置文件从不被修改;客户端自己的配置只被**读取**,用来发现它实际连接的 HTTPS 上游主机,把这些主机加入 MITM 白名单 —— 代理只 TLS 终结它们,其余流量盲透传。
90
90
 
@@ -96,6 +96,9 @@ bili omp # pi 同款,file-free(#535):环境变量 +
96
96
  bili opencode # HTTPS 走 MITM + 临时 opencode.json(HTTP 走 /bili/)+ 轻量 /acp 插件
97
97
  bili hermes # file-free(#535):hermes 代理环境变量(HTTPS_PROXY + HERMES_CA_BUNDLE)—— https 走 CONNECT MITM,http 走绝对形式转发;真实 ~/.hermes 不动
98
98
  bili dsh # deepseek-harness:非回环上游走代理 env(https MITM、http absolute-form),回环上游保留 overlay DSH_HOME(~/.dsh-bili)改写(#535),内置 deepseek 路由走 DEEPSEEK_BASE_URL,经 --patch 注入原生 /acp 命令
99
+ bili codebuddy # Tencent CodeBuddy Code CLI:CODEBUDDY_BASE_URL /bili/ 重写(OpenAI chat completions wire),预算对齐走 CODEBUDDY_AUTO_COMPACT_WINDOW;真实 ~/.codebuddy 不动
100
+ bili qoder # qoder:模型端点硬编码 https(无法 /bili/ 改写)—— 证书 MITM(HTTPS_PROXY + NODE_EXTRA_CA_CERTS),默认模型主机已加白名单(#653)
101
+ bili trae # Trae CLI(字节跳动,闭源 Go 二进制,无 base-URL 覆盖)—— 证书 MITM(HTTPS_PROXY + SSL_CERT_FILE),模型主机取 TRAE_CLI_API_HOST 或默认企业网关(#655)
99
102
  bili pi --mitm-domain api.foo.com # 向 MITM 白名单追加域名
100
103
  ```
101
104
 
package/dist/index.js CHANGED
@@ -57282,6 +57282,55 @@ import path10 from "path";
57282
57282
  function toModelWindow(id, contextWindow) {
57283
57283
  return typeof id === "string" && id.length > 0 && typeof contextWindow === "number" && Number.isFinite(contextWindow) && contextWindow > 0 ? { id, contextWindow: Math.floor(contextWindow) } : null;
57284
57284
  }
57285
+ var QODER_DEFAULT_MODEL_HOSTS = [
57286
+ "api2-v2.qoder.sh",
57287
+ "api1.qoder.sh",
57288
+ "api2.qoder.sh",
57289
+ "api3.qoder.sh",
57290
+ "gateway.qoder.com.cn"
57291
+ ];
57292
+ function qoderIsCnSite(env = process.env) {
57293
+ const site = env.QODERCLI_SITE?.trim().toLowerCase();
57294
+ if (site === "cn") return true;
57295
+ if (nonEmpty2(env.QODERCN_CONFIG_DIR) || nonEmpty2(env.QODERCN_CLI_HOME)) return true;
57296
+ const h = os.homedir();
57297
+ const cnDir = path10.join(h, ".qoder-cn");
57298
+ const intlDir = path10.join(h, ".qoder");
57299
+ try {
57300
+ if (fs6.existsSync(cnDir) && !fs6.existsSync(intlDir)) return true;
57301
+ } catch {
57302
+ }
57303
+ return false;
57304
+ }
57305
+ function resolveQoderHome(env = process.env) {
57306
+ const h = os.homedir();
57307
+ const cn2 = qoderIsCnSite(env);
57308
+ const configDir2 = cn2 ? env.QODERCN_CONFIG_DIR : env.QODER_CONFIG_DIR;
57309
+ if (nonEmpty2(configDir2)) return configDir2;
57310
+ const cliHomeEnv = cn2 ? env.QODERCN_CLI_HOME : env.QODER_CLI_HOME;
57311
+ const cliHome = nonEmpty2(cliHomeEnv) ? cliHomeEnv : h;
57312
+ const dirNameEnv = cn2 ? env.QODERCN_CONFIG_DIR_NAME : env.QODER_CONFIG_DIR_NAME;
57313
+ const dirName = nonEmpty2(dirNameEnv) ? dirNameEnv : cn2 ? ".qoder-cn" : ".qoder";
57314
+ return path10.join(cliHome, dirName);
57315
+ }
57316
+ function readQoderConfig(qoderHome, env = process.env) {
57317
+ const result = {};
57318
+ const obj = readJsonObject(path10.join(qoderHome, "settings.json"));
57319
+ const model = obj?.model;
57320
+ if (typeof model === "string" && model.trim().length > 0) {
57321
+ result.model = model.trim();
57322
+ } else if (model && typeof model === "object" && !Array.isArray(model)) {
57323
+ const name = model.name;
57324
+ if (nonEmpty2(name)) result.model = name.trim();
57325
+ }
57326
+ const cn2 = qoderIsCnSite(env);
57327
+ const host = nonEmpty2(cn2 ? env.QODERCN_MODEL_SERVER_HOST : env.QODER_MODEL_SERVER_HOST) ? cn2 ? env.QODERCN_MODEL_SERVER_HOST : env.QODER_MODEL_SERVER_HOST : void 0;
57328
+ if (host) {
57329
+ const bare = host.trim().replace(/^https?:\/\//i, "").replace(/\/+$/, "");
57330
+ if (bare.length > 0) result.modelServerHost = bare;
57331
+ }
57332
+ return result;
57333
+ }
57285
57334
  function nonEmpty2(s3) {
57286
57335
  return typeof s3 === "string" && s3.trim().length > 0;
57287
57336
  }
@@ -57314,6 +57363,98 @@ function resolveCodexHome(env) {
57314
57363
  const h = os.homedir();
57315
57364
  return nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME : path10.join(h, ".codex");
57316
57365
  }
57366
+ function resolveCodebuddyHome(env) {
57367
+ const h = os.homedir();
57368
+ return nonEmpty2(env.CODEBUDDY_CONFIG_DIR) ? env.CODEBUDDY_CONFIG_DIR : path10.join(h, ".codebuddy");
57369
+ }
57370
+ function parseCodebuddyModelsJson(obj) {
57371
+ const out = { models: [], urls: [] };
57372
+ const seenUrl = /* @__PURE__ */ new Set();
57373
+ const collect = (id, entry) => {
57374
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) return;
57375
+ const e = entry;
57376
+ const url = e.url;
57377
+ if (typeof url === "string" && url.length > 0 && !seenUrl.has(url)) {
57378
+ seenUrl.add(url);
57379
+ out.urls.push(url);
57380
+ }
57381
+ const win = toModelWindow(id, e.maxInputTokens);
57382
+ if (win) out.models.push(win);
57383
+ };
57384
+ if (!obj) return out;
57385
+ if (Array.isArray(obj)) {
57386
+ for (const item of obj) {
57387
+ if (!item || typeof item !== "object" || Array.isArray(item)) continue;
57388
+ const it2 = item;
57389
+ collect(it2.id ?? it2.name, it2);
57390
+ }
57391
+ return out;
57392
+ }
57393
+ if (typeof obj !== "object") return out;
57394
+ const root = obj;
57395
+ const modelsField = root.models;
57396
+ if (Array.isArray(modelsField)) {
57397
+ for (const item of modelsField) {
57398
+ if (!item || typeof item !== "object" || Array.isArray(item)) continue;
57399
+ const it2 = item;
57400
+ collect(it2.id ?? it2.name, it2);
57401
+ }
57402
+ return out;
57403
+ }
57404
+ if (modelsField && typeof modelsField === "object") {
57405
+ for (const [id, val] of Object.entries(modelsField)) collect(id, val);
57406
+ return out;
57407
+ }
57408
+ for (const [id, val] of Object.entries(root)) collect(id, val);
57409
+ return out;
57410
+ }
57411
+ function readJsonFile(filePath) {
57412
+ try {
57413
+ return JSON.parse(fs6.readFileSync(filePath, "utf8"));
57414
+ } catch {
57415
+ return null;
57416
+ }
57417
+ }
57418
+ function readCodebuddyConfig(codebuddyHome, cwd, env = process.env) {
57419
+ let codebuddyBaseUrl;
57420
+ let model;
57421
+ let autoCompactWindow;
57422
+ const settings = readJsonObject(path10.join(codebuddyHome, "settings.json"));
57423
+ const settingsEnv = settings?.env;
57424
+ if (settingsEnv && typeof settingsEnv === "object" && !Array.isArray(settingsEnv)) {
57425
+ const e = settingsEnv;
57426
+ const v2 = e.CODEBUDDY_BASE_URL;
57427
+ if (nonEmpty2(v2)) codebuddyBaseUrl = v2;
57428
+ }
57429
+ const tm = settings?.model;
57430
+ if (nonEmpty2(tm)) model = String(tm);
57431
+ const tacw = Number(settings?.autoCompactWindow);
57432
+ if (Number.isFinite(tacw) && tacw > 0) autoCompactWindow = tacw;
57433
+ if (!codebuddyBaseUrl && nonEmpty2(env.CODEBUDDY_BASE_URL)) codebuddyBaseUrl = env.CODEBUDDY_BASE_URL;
57434
+ const windowByModel = /* @__PURE__ */ new Map();
57435
+ const urls = [];
57436
+ const seenUrl = /* @__PURE__ */ new Set();
57437
+ for (const f2 of [
57438
+ path10.join(codebuddyHome, "models.json"),
57439
+ path10.join(cwd, ".codebuddy", "models.json")
57440
+ ]) {
57441
+ const parsed = parseCodebuddyModelsJson(readJsonFile(f2));
57442
+ for (const w2 of parsed.models) windowByModel.set(w2.id, w2.contextWindow);
57443
+ for (const u2 of parsed.urls) {
57444
+ if (!seenUrl.has(u2)) {
57445
+ seenUrl.add(u2);
57446
+ urls.push(u2);
57447
+ }
57448
+ }
57449
+ }
57450
+ return {
57451
+ ...codebuddyBaseUrl ? { codebuddyBaseUrl } : {},
57452
+ ...model ? { model } : {},
57453
+ ...autoCompactWindow ? { autoCompactWindow } : {},
57454
+ ...windowByModel.size > 0 ? { models: [...windowByModel.entries()].map(([id, contextWindow]) => ({ id, contextWindow })) } : {},
57455
+ ...urls.length > 0 ? { modelUrls: urls } : {}
57456
+ };
57457
+ }
57317
57458
  function parseDshSettingsYaml(text) {
57318
57459
  const out = [];
57319
57460
  const seen = /* @__PURE__ */ new Set();
@@ -57337,6 +57478,20 @@ function readDshConfig(dshHome) {
57337
57478
  }
57338
57479
  return { baseUrls: parseDshSettingsYaml(text) };
57339
57480
  }
57481
+ var TRAE_DEFAULT_MODEL_HOSTS = [
57482
+ "console.enterprise.trae.cn",
57483
+ "www.trae.cn"
57484
+ ];
57485
+ function resolveTraeHome(env) {
57486
+ const h = os.homedir();
57487
+ return nonEmpty2(env.TRAE_CONFIG_DIR) ? env.TRAE_CONFIG_DIR : path10.join(h, ".trae");
57488
+ }
57489
+ function readTraeConfig(env) {
57490
+ const result = {};
57491
+ const host = nonEmpty2(env.TRAE_CLI_API_HOST) ? env.TRAE_CLI_API_HOST.replace(/^https?:\/\//i, "").replace(/\/+$/, "") : void 0;
57492
+ if (host) result.modelApiHost = host;
57493
+ return result;
57494
+ }
57340
57495
  function readClaudeSettings(homeDir, cwd, env = process.env) {
57341
57496
  const files = [
57342
57497
  path10.join(homeDir, ".claude", "settings.json"),
@@ -57687,6 +57842,9 @@ function loadClientConfig(env, cwd) {
57687
57842
  config.opencode = readOpencodeConfig(resolveOpencodeConfigFile(env));
57688
57843
  config.hermes = readHermesConfig(resolveHermesHome(env));
57689
57844
  config.dsh = readDshConfig(resolveDshHome(env));
57845
+ config.codebuddy = readCodebuddyConfig(resolveCodebuddyHome(env), cwd, env);
57846
+ config.qoder = readQoderConfig(resolveQoderHome(env), env);
57847
+ config.trae = readTraeConfig(env);
57690
57848
  return config;
57691
57849
  }
57692
57850
  function collectModelWindows(config, scope) {
@@ -57701,12 +57859,14 @@ function collectModelWindows(config, scope) {
57701
57859
  else if (scope === "pi") for (const p2 of Object.values(config.pi?.providers ?? {})) add(p2.models);
57702
57860
  else if (scope === "omp") for (const p2 of Object.values(config.omp?.providers ?? {})) add(p2.models);
57703
57861
  else if (scope === "opencode") for (const p2 of Object.values(config.opencode?.providers ?? {})) add(p2.models);
57862
+ else if (scope === "codebuddy") add(config.codebuddy?.models);
57704
57863
  return out;
57705
57864
  }
57706
57865
  for (const p2 of Object.values(config.pi?.providers ?? {})) add(p2.models);
57707
57866
  for (const p2 of Object.values(config.omp?.providers ?? {})) add(p2.models);
57708
57867
  for (const p2 of Object.values(config.opencode?.providers ?? {})) add(p2.models);
57709
57868
  add(config.codex?.modelWindows);
57869
+ add(config.codebuddy?.models);
57710
57870
  return out;
57711
57871
  }
57712
57872
 
@@ -57744,18 +57904,36 @@ function extractHttpsHosts(config) {
57744
57904
  if (config.zcode) {
57745
57905
  for (const prov of Object.values(config.zcode.providers)) push(prov.baseURL);
57746
57906
  }
57907
+ if (config.codebuddy) {
57908
+ push(config.codebuddy.codebuddyBaseUrl);
57909
+ for (const u2 of config.codebuddy.modelUrls ?? []) push(u2);
57910
+ }
57911
+ if (config.qoder) {
57912
+ const hosts = nonEmpty2(config.qoder.modelServerHost) ? [config.qoder.modelServerHost] : QODER_DEFAULT_MODEL_HOSTS;
57913
+ for (const h of hosts) push(`https://${h}`);
57914
+ }
57915
+ if (config.trae) {
57916
+ const hosts = nonEmpty2(config.trae.modelApiHost) ? [config.trae.modelApiHost] : TRAE_DEFAULT_MODEL_HOSTS;
57917
+ for (const h of hosts) push(`https://${h}`);
57918
+ }
57747
57919
  return out;
57748
57920
  }
57749
57921
  function configFilePaths(env) {
57750
57922
  const home = os2.homedir();
57751
57923
  const codexHome = nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME : path11.join(home, ".codex");
57752
57924
  const zcodeHome = nonEmpty2(env.ZCODE_DATA_BASE_DIR) ? env.ZCODE_DATA_BASE_DIR : path11.join(home, ".zcode");
57925
+ const codebuddyHome = resolveCodebuddyHome(env);
57753
57926
  return [
57754
57927
  path11.join(home, ".claude", "settings.json"),
57755
57928
  path11.join(process.cwd(), ".claude", "settings.json"),
57756
57929
  path11.join(codexHome, "config.toml"),
57757
57930
  path11.join(resolvePiHome(env), "models.json"),
57758
- path11.join(zcodeHome, "v2", "config.json")
57931
+ path11.join(zcodeHome, "v2", "config.json"),
57932
+ path11.join(codebuddyHome, "settings.json"),
57933
+ path11.join(codebuddyHome, "models.json"),
57934
+ path11.join(process.cwd(), ".codebuddy", "models.json"),
57935
+ path11.join(resolveQoderHome(env), "settings.json"),
57936
+ path11.join(resolveTraeHome(env), "traecli.yaml")
57759
57937
  ];
57760
57938
  }
57761
57939
  function readMtimes(paths) {
@@ -58801,7 +58979,7 @@ function logUnrecognizedPath(log2, url) {
58801
58979
  const n = (unrecognizedPathCounts.get(key) ?? 0) + 1;
58802
58980
  unrecognizedPathCounts.set(key, n);
58803
58981
  if (n <= 3) {
58804
- log2("warn", `unrecognized path ${key} \u2014 not a known protocol (/chat/completions, /v1/messages, /responses, /responses/compact); forwarding unchanged`);
58982
+ log2("warn", `unrecognized path ${key} \u2014 not a known protocol (/chat/completions, /llm_raw_chat, /v1/messages, /responses, /responses/compact); forwarding unchanged`);
58805
58983
  } else if (n === 4) {
58806
58984
  log2("info", `unrecognized path ${key}: forwarding unchanged; further occurrences suppressed`);
58807
58985
  }
@@ -59354,7 +59532,7 @@ async function handle(req, res, opts, core, config, log2, instanceId, instanceSt
59354
59532
  }
59355
59533
  }
59356
59534
  upstreamOrigin = route ? route.upstream : /^https?:\/\//i.test(url) ? new URL(url).origin : opts.upstream;
59357
- protocol = route?.explicitProtocol ?? (req.method === "POST" && bodyBuffer.length > 0 ? urlPath.endsWith("/chat/completions") ? "openai" : urlPath.endsWith("/v1/messages") || urlPath.endsWith("/messages") ? "anthropic" : urlPath.endsWith("/responses") || responsesCompact ? "responses" : null : null);
59535
+ protocol = route?.explicitProtocol ?? (req.method === "POST" && bodyBuffer.length > 0 ? urlPath.endsWith("/chat/completions") || urlPath.endsWith("/llm_raw_chat") ? "openai" : urlPath.endsWith("/v1/messages") || urlPath.endsWith("/messages") ? "anthropic" : urlPath.endsWith("/responses") || responsesCompact ? "responses" : null : null);
59358
59536
  if (protocol !== null && bodyBuffer.length > 0) {
59359
59537
  try {
59360
59538
  const decoded = await decodeRequestBody(headerValue2(req, "content-encoding"), bodyBuffer, MAX_REQUEST_BYTES);
@@ -60436,7 +60614,7 @@ function logUpstreamProxyDecision(opts, upstreamUrl, decision) {
60436
60614
  }
60437
60615
  function inferWireProtocol(path18) {
60438
60616
  const p2 = path18.split("?", 2)[0];
60439
- if (p2.endsWith("/chat/completions")) return "openai";
60617
+ if (p2.endsWith("/chat/completions") || p2.endsWith("/llm_raw_chat")) return "openai";
60440
60618
  if (p2.endsWith("/responses") || p2.endsWith("/responses/compact")) return "responses";
60441
60619
  return null;
60442
60620
  }
@@ -65383,7 +65561,7 @@ function selfDistFile(name) {
65383
65561
  return path15.join(selfPackageRoot(), "dist", name);
65384
65562
  }
65385
65563
  var LAUNCHER_DEFAULT_HOST = "127.0.0.1";
65386
- var LAUNCH_CLIENTS = ["pi", "codex", "claude", "omp", "opencode", "hermes", "dsh", "pi-test"];
65564
+ var LAUNCH_CLIENTS = ["pi", "codex", "claude", "omp", "opencode", "hermes", "dsh", "codebuddy", "qoder", "trae", "pi-test"];
65387
65565
  var HEALTH_PATH = "/__bili/health";
65388
65566
  var HEALTH_POLL_INTERVAL_MS = 200;
65389
65567
  var SPAWN_WAIT_MS = 2e4;
@@ -65471,6 +65649,29 @@ function discoverRoutes(client, config) {
65471
65649
  }
65472
65650
  } catch {
65473
65651
  }
65652
+ } else if (client === "codebuddy") {
65653
+ const raw = nonEmpty2(config.codebuddy?.codebuddyBaseUrl) ? config.codebuddy.codebuddyBaseUrl : "https://tencent.sso.codebuddy.cn/v2";
65654
+ const real = unwrapUpstream2(raw);
65655
+ try {
65656
+ const url = new URL(real);
65657
+ if ((url.protocol === "https:" || url.protocol === "http:") && !rewriteKeys.has("CODEBUDDY_BASE_URL")) {
65658
+ rewriteKeys.add("CODEBUDDY_BASE_URL");
65659
+ httpRewrites.push({ key: "CODEBUDDY_BASE_URL", realUpstream: real });
65660
+ }
65661
+ } catch {
65662
+ }
65663
+ for (const rawModelUrl of config.codebuddy?.modelUrls ?? []) {
65664
+ try {
65665
+ const url = new URL(unwrapUpstream2(rawModelUrl));
65666
+ if (url.protocol !== "https:") continue;
65667
+ const host = url.hostname;
65668
+ if (host && !httpsSeen.has(host.toLowerCase())) {
65669
+ httpsSeen.add(host.toLowerCase());
65670
+ httpsDomains.push(host);
65671
+ }
65672
+ } catch {
65673
+ }
65674
+ }
65474
65675
  } else if (client === "pi") {
65475
65676
  for (const [name, prov] of Object.entries(config.pi?.providers ?? {})) {
65476
65677
  classify(prov.baseUrl, name);
@@ -65532,6 +65733,24 @@ function discoverRoutes(client, config) {
65532
65733
  } catch {
65533
65734
  }
65534
65735
  }
65736
+ } else if (client === "qoder") {
65737
+ const hosts = nonEmpty2(config.qoder?.modelServerHost) ? [config.qoder.modelServerHost] : QODER_DEFAULT_MODEL_HOSTS;
65738
+ for (const host of hosts) {
65739
+ const h = host.toLowerCase();
65740
+ if (h && !httpsSeen.has(h)) {
65741
+ httpsSeen.add(h);
65742
+ httpsDomains.push(h);
65743
+ }
65744
+ }
65745
+ } else if (client === "trae") {
65746
+ const hosts = nonEmpty2(config.trae?.modelApiHost) ? [config.trae.modelApiHost] : TRAE_DEFAULT_MODEL_HOSTS;
65747
+ for (const h of hosts) {
65748
+ const host = h.split(":", 2)[0].toLowerCase();
65749
+ if (host && !httpsSeen.has(host)) {
65750
+ httpsSeen.add(host);
65751
+ httpsDomains.push(host);
65752
+ }
65753
+ }
65535
65754
  } else {
65536
65755
  for (const [name, prov] of Object.entries(config.codex?.providers ?? {})) {
65537
65756
  classify(prov.baseUrl, `model_providers.${name}.base_url`);
@@ -65564,6 +65783,9 @@ function buildPiEnv(origin, caPath, baseEnv, httpRewrites = [], httpsRewrites =
65564
65783
  function buildCodexEnv(origin, caPath, baseEnv) {
65565
65784
  return { ...baseEnv, HTTPS_PROXY: origin, SSL_CERT_FILE: caPath, BILLION_CONTEXT_PROXY: origin };
65566
65785
  }
65786
+ function buildTraeEnv(origin, caPath, baseEnv) {
65787
+ return { ...baseEnv, HTTPS_PROXY: origin, SSL_CERT_FILE: caPath, BILLION_CONTEXT_PROXY: origin };
65788
+ }
65567
65789
  function buildCodexArgs(origin, httpRewrites, httpsRewrites, extra) {
65568
65790
  const args = [];
65569
65791
  for (const r of httpRewrites) {
@@ -65614,6 +65836,31 @@ function buildClaudeEnv(origin, caPath, httpRewrites, httpsRewrites, baseEnv) {
65614
65836
  if (hr2) env.ANTHROPIC_BASE_URL = hr2.realUpstream;
65615
65837
  return env;
65616
65838
  }
65839
+ async function resolveCodebuddyBudgetEnv(opts) {
65840
+ const { model, userAutoCompactWindow, shellAutoCompactWindow, routes, upstreamUrl } = opts;
65841
+ if (!model || userAutoCompactWindow !== void 0 || nonEmpty2(shellAutoCompactWindow)) return {};
65842
+ const window2 = await resolveLauncherWindow(model, routes, upstreamUrl);
65843
+ if (!window2) return {};
65844
+ return { CODEBUDDY_AUTO_COMPACT_WINDOW: String(window2) };
65845
+ }
65846
+ function buildCodebuddyEnv(origin, caPath, httpRewrites, httpsRewrites, baseEnv) {
65847
+ const env = { ...baseEnv, HTTPS_PROXY: origin, NODE_EXTRA_CA_CERTS: caPath, BILLION_CONTEXT_PROXY: origin };
65848
+ const r = httpRewrites.find((rw) => rw.key === "CODEBUDDY_BASE_URL");
65849
+ if (r) env.CODEBUDDY_BASE_URL = wrapUpstream(origin, r.realUpstream);
65850
+ const hr2 = httpsRewrites.find((rw) => rw.key === "CODEBUDDY_BASE_URL");
65851
+ if (hr2) env.CODEBUDDY_BASE_URL = hr2.realUpstream;
65852
+ return env;
65853
+ }
65854
+ function buildQoderEnv(origin, caPath, baseEnv) {
65855
+ return { ...baseEnv, HTTPS_PROXY: origin, NODE_EXTRA_CA_CERTS: caPath, BILLION_CONTEXT_PROXY: origin };
65856
+ }
65857
+ async function resolveQoderBudgetEnv(opts) {
65858
+ const { model, userAutoCompactWindow, windowKey, routes, upstreamUrl } = opts;
65859
+ if (!model || nonEmpty2(userAutoCompactWindow)) return {};
65860
+ const window2 = await resolveLauncherWindow(model, routes, upstreamUrl);
65861
+ if (!window2) return {};
65862
+ return { [windowKey]: String(window2) };
65863
+ }
65617
65864
  function launcherDirectUrl(env) {
65618
65865
  return env.BILI_LAUNCHER_DIRECT === "1";
65619
65866
  }
@@ -65654,7 +65901,7 @@ function isPrivateIPv4(host) {
65654
65901
  return false;
65655
65902
  }
65656
65903
  function launcherInjectMcp(env, base, codexUpstream) {
65657
- if (base === "pi" || base === "omp" || base === "opencode" || base === "hermes" || base === "dsh") return false;
65904
+ if (base === "pi" || base === "omp" || base === "opencode" || base === "hermes" || base === "dsh" || base === "codebuddy" || base === "qoder" || base === "trae") return false;
65658
65905
  if (env.BILI_LAUNCHER_PLUGIN === "0") return false;
65659
65906
  if (base === "codex" && env.BILI_LAUNCHER_PLUGIN === void 0 && codexUpstream !== void 0 && isPrivateUpstreamHost(codexUpstream)) {
65660
65907
  return false;
@@ -66477,6 +66724,18 @@ function resolveClientCommand(client, env) {
66477
66724
  );
66478
66725
  return { command: process.execPath, prefixArgs: [cli] };
66479
66726
  }
66727
+ if (client === "codebuddy") {
66728
+ const resolved2 = resolveOnPath("codebuddy", env) ?? resolveOnPath("cbc", env);
66729
+ return { command: resolved2 ?? "codebuddy", prefixArgs: [] };
66730
+ }
66731
+ if (client === "qoder") {
66732
+ const resolved2 = resolveOnPath("qoder", env) ?? resolveOnPath("qodercli", env);
66733
+ return { command: resolved2 ?? "qoder", prefixArgs: [] };
66734
+ }
66735
+ if (client === "trae") {
66736
+ const traeBin = resolveOnPath("traecli", env) ?? resolveOnPath("trae-cli", env) ?? resolveOnPath("trae", env);
66737
+ return { command: traeBin ?? "traecli", prefixArgs: [] };
66738
+ }
66480
66739
  const resolved = resolveOnPath(client, env);
66481
66740
  return { command: resolved ?? client, prefixArgs: [] };
66482
66741
  }
@@ -66543,6 +66802,10 @@ async function runLaunch(params, deps = {}) {
66543
66802
  console.error(
66544
66803
  "bili: direct-URL mode \u2014 claude's ANTHROPIC_BASE_URL is overridden to the proxy; a pre-configured relay is bypassed unless BILI_CLAUDE_UPSTREAM=<relay> is set. OAuth-subscription traffic requires the default MITM mode."
66545
66804
  );
66805
+ } else if (base === "qoder") {
66806
+ console.error(
66807
+ "bili: BILI_LAUNCHER_DIRECT has no effect for qoder \u2014 its model endpoint scheme is hardcoded https with no base-URL override env, so qoder always runs in cert-MITM mode."
66808
+ );
66546
66809
  }
66547
66810
  }
66548
66811
  const codexUpstream = base === "codex" ? codexUpstreamUrl(config.codex) : void 0;
@@ -66612,6 +66875,23 @@ async function runLaunch(params, deps = {}) {
66612
66875
  }
66613
66876
  const dshAcpPatch = writeDshAcpPatch(dshHomeDir);
66614
66877
  if (dshAcpPatch) clientArgs = dshArgsWithPatch(clientArgs, dshAcpPatch);
66878
+ } else if (base === "qoder") {
66879
+ env = buildQoderEnv(origin, ca, stripInheritedProxy(process.env));
66880
+ const qoderPrefix = qoderIsCnSite(process.env) ? "QODERCN" : "QODER";
66881
+ env[`${qoderPrefix}_MODEL_TRANSPORT`] = "http";
66882
+ const qoderBudget = await resolveQoderBudgetEnv({
66883
+ model: nonEmpty2(process.env[`${qoderPrefix}_MODEL`]) ? process.env[`${qoderPrefix}_MODEL`] : config.qoder?.model,
66884
+ userAutoCompactWindow: process.env[`${qoderPrefix}_AUTOCOMPACT_WINDOW`],
66885
+ windowKey: `${qoderPrefix}_AUTOCOMPACT_WINDOW`,
66886
+ routes: biliRoutes,
66887
+ upstreamUrl: `https://${config.qoder?.modelServerHost ?? QODER_DEFAULT_MODEL_HOSTS[0]}`
66888
+ });
66889
+ Object.assign(env, qoderBudget);
66890
+ if (qoderBudget[`${qoderPrefix}_AUTOCOMPACT_WINDOW`] !== void 0) {
66891
+ console.error(`bili: qoder budget aligned \u2014 ${qoderPrefix}_AUTOCOMPACT_WINDOW=${qoderBudget[`${qoderPrefix}_AUTOCOMPACT_WINDOW`]}`);
66892
+ }
66893
+ } else if (base === "trae") {
66894
+ env = buildTraeEnv(origin, resolveCombinedCaPath(process.env), stripInheritedProxy(process.env));
66615
66895
  } else if (base === "codex") {
66616
66896
  const codexConversationId = injectMcp ? randomUUID5() : void 0;
66617
66897
  if (directUrl) {
@@ -66642,6 +66922,19 @@ async function runLaunch(params, deps = {}) {
66642
66922
  Object.assign(env, inj.envPatch);
66643
66923
  if (inj.warning) console.error(`bili: ${inj.warning}`);
66644
66924
  }
66925
+ } else if (base === "codebuddy") {
66926
+ env = buildCodebuddyEnv(origin, ca, routes.httpRewrites, routes.httpsRewrites, process.env);
66927
+ const codebuddyBudget = await resolveCodebuddyBudgetEnv({
66928
+ model: config.codebuddy?.model,
66929
+ userAutoCompactWindow: config.codebuddy?.autoCompactWindow,
66930
+ shellAutoCompactWindow: process.env.CODEBUDDY_AUTO_COMPACT_WINDOW,
66931
+ routes: biliRoutes,
66932
+ upstreamUrl: config.codebuddy?.codebuddyBaseUrl ?? "https://tencent.sso.codebuddy.cn/v2"
66933
+ });
66934
+ Object.assign(env, codebuddyBudget);
66935
+ if (codebuddyBudget.CODEBUDDY_AUTO_COMPACT_WINDOW !== void 0) {
66936
+ console.error(`bili: codebuddy budget aligned \u2014 CODEBUDDY_AUTO_COMPACT_WINDOW=${codebuddyBudget.CODEBUDDY_AUTO_COMPACT_WINDOW}`);
66937
+ }
66645
66938
  } else {
66646
66939
  env = directUrl ? buildClaudePluginEnv(origin, true, process.env) : buildClaudeEnv(origin, ca, routes.httpRewrites, routes.httpsRewrites, process.env);
66647
66940
  if (directUrl) env.BILLION_CONTEXT_PROXY = origin;
@@ -66896,6 +67189,9 @@ Usage:
66896
67189
  bili opencode [opts --] [args] start a proxy + launch opencode against it (cert-MITM)
66897
67190
  bili hermes [opts --] [args] start a proxy + launch hermes-agent against it (/bili/ rewrite)
66898
67191
  bili dsh [opts --] [args] start a proxy + launch deepseek-harness against it (/bili/ rewrite)
67192
+ bili codebuddy [opts --] [args] start a proxy + launch codebuddy against it (/bili/ rewrite)
67193
+ bili qoder [opts --] [args] start a proxy + launch qoder against it (cert-MITM)
67194
+ bili trae [opts --] [args] start a proxy + launch Trae CLI against it (cert-MITM)
66899
67195
  bili test pi non-polluting pi smoke test through the proxy
66900
67196
  bili export [session] [--full] list sessions / export one as a Markdown handoff
66901
67197
  (--full includes original messages; --output FILE)
@@ -66910,12 +67206,12 @@ Usage:
66910
67206
  bili --version print version
66911
67207
  bili --help show this help
66912
67208
 
66913
- Launcher (bili pi / bili codex / bili claude / bili omp / bili opencode / bili hermes / bili dsh):
67209
+ Launcher (bili pi / bili codex / bili claude / bili omp / bili opencode / bili hermes / bili dsh / bili codebuddy / bili qoder / bili trae):
66914
67210
  Brings up a proxy on an independent port (a fresh instance every launch), then runs the client pointed at it via HTTPS_PROXY + the proxy's
66915
67211
  MITM CA \u2014 no config-file edits. Discovered HTTPS upstream domains are
66916
67212
  auto-whitelisted for MITM so the proxy TLS-terminates exactly the hosts the
66917
- client uses; HTTP / localhost providers go direct. pi/claude trust the CA
66918
- via NODE_EXTRA_CA_CERTS, codex via SSL_CERT_FILE. Proxy killed on client exit.
67213
+ client uses; HTTP / localhost providers go direct. pi/claude/qoder trust the CA
67214
+ via NODE_EXTRA_CA_CERTS, codex/trae via SSL_CERT_FILE. Proxy killed on client exit.
66919
67215
  bili flags (-F, --mitm-domain, --port, ...) must precede the client name;
66920
67216
  everything after the client name is passed through to the client.
66921
67217
  bili pi # launch pi through the proxy
@@ -66926,6 +67222,9 @@ Launcher (bili pi / bili codex / bili claude / bili omp / bili opencode / bili h
66926
67222
  bili omp # launch omp through the proxy (pi-based; /bili/ rewrite)
66927
67223
  bili hermes # launch hermes-agent through the proxy (/bili/ rewrite of ~/.hermes/config.yaml)
66928
67224
  bili dsh --profile web "task" # launch deepseek-harness through the proxy (/bili/ rewrite of ~/.dsh/settings.yaml)
67225
+ bili codebuddy # launch codebuddy through the proxy (CODEBUDDY_BASE_URL /bili/ rewrite)
67226
+ bili qoder # launch qoder through the proxy (cert-MITM; model endpoint is hardcoded https, so no /bili/ rewrite)
67227
+ bili trae # launch Trae CLI through the proxy (cert-MITM; model host via TRAE_CLI_API_HOST or --mitm-domain)
66929
67228
  bili test pi # quick end-to-end check of the pi path
66930
67229
  bili --mitm-domain api.foo.com pi # add a domain to the MITM whitelist (flags precede the client)
66931
67230
  bili -F http://127.0.0.1:7897 codex # route bili's upstream through a proxy (gost-style -F)