billion-context 0.1.95 → 0.1.96-pr.641.470

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`)
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,7 @@ 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
180
181
  bili pi --mitm-domain api.foo.com # add a domain to the MITM whitelist
181
182
  ```
182
183
 
package/dist/index.js CHANGED
@@ -51390,9 +51390,9 @@ ${body}`;
51390
51390
  var PAIRED = /\x3cacp\s[^<>]{0,256}>([^<>]{0,64})<\/acp>/;
51391
51391
  var LONE_OPEN = /\x3cacp(?:\s[^<>]{0,256})?>/;
51392
51392
  var LONE_CLOSE = /<\/acp(?=[\s>])[^<>]{0,32}>/;
51393
- var PARTIAL_TAIL = /(\x3cacp\s[^<>]*|\x3c\/acp(?:\s[^<>]*)?|<\/?a?c?p?)$/;
51393
+ var PARTIAL_TAIL = /(\x3cacp\s[^<>]*|\x3c\/acp(?:\s[^<>]{0,32})?|<\/?a?c?p?)$/;
51394
51394
  var TRUNC_OPEN = /\x3cacp\s[^<>]*$/;
51395
- var TRUNC_CLOSE = /\x3c\/acp(?:\s[^<>]*)?$/;
51395
+ var TRUNC_CLOSE = /\x3c\/acp(?:\s[^<>]{0,32})?$/;
51396
51396
  var CLOSE_TAG = "</acp";
51397
51397
  var HOLD_LIMIT = 128;
51398
51398
  var TAG_OPEN_CAP = 4096;
@@ -56835,6 +56835,98 @@ function resolveDshHome(env) {
56835
56835
  const h = os.homedir();
56836
56836
  return nonEmpty2(env.DSH_HOME) ? env.DSH_HOME : path10.join(h, ".dsh");
56837
56837
  }
56838
+ function resolveCodebuddyHome(env) {
56839
+ const h = os.homedir();
56840
+ return nonEmpty2(env.CODEBUDDY_CONFIG_DIR) ? env.CODEBUDDY_CONFIG_DIR : path10.join(h, ".codebuddy");
56841
+ }
56842
+ function parseCodebuddyModelsJson(obj) {
56843
+ const out = { models: [], urls: [] };
56844
+ const seenUrl = /* @__PURE__ */ new Set();
56845
+ const collect = (id, entry) => {
56846
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) return;
56847
+ const e = entry;
56848
+ const url = e.url;
56849
+ if (typeof url === "string" && url.length > 0 && !seenUrl.has(url)) {
56850
+ seenUrl.add(url);
56851
+ out.urls.push(url);
56852
+ }
56853
+ const win = toModelWindow(id, e.maxInputTokens);
56854
+ if (win) out.models.push(win);
56855
+ };
56856
+ if (!obj) return out;
56857
+ if (Array.isArray(obj)) {
56858
+ for (const item of obj) {
56859
+ if (!item || typeof item !== "object" || Array.isArray(item)) continue;
56860
+ const it2 = item;
56861
+ collect(it2.id ?? it2.name, it2);
56862
+ }
56863
+ return out;
56864
+ }
56865
+ if (typeof obj !== "object") return out;
56866
+ const root = obj;
56867
+ const modelsField = root.models;
56868
+ if (Array.isArray(modelsField)) {
56869
+ for (const item of modelsField) {
56870
+ if (!item || typeof item !== "object" || Array.isArray(item)) continue;
56871
+ const it2 = item;
56872
+ collect(it2.id ?? it2.name, it2);
56873
+ }
56874
+ return out;
56875
+ }
56876
+ if (modelsField && typeof modelsField === "object") {
56877
+ for (const [id, val] of Object.entries(modelsField)) collect(id, val);
56878
+ return out;
56879
+ }
56880
+ for (const [id, val] of Object.entries(root)) collect(id, val);
56881
+ return out;
56882
+ }
56883
+ function readJsonFile(filePath) {
56884
+ try {
56885
+ return JSON.parse(fs6.readFileSync(filePath, "utf8"));
56886
+ } catch {
56887
+ return null;
56888
+ }
56889
+ }
56890
+ function readCodebuddyConfig(codebuddyHome, cwd, env = process.env) {
56891
+ let codebuddyBaseUrl;
56892
+ let model;
56893
+ let autoCompactWindow;
56894
+ const settings = readJsonObject(path10.join(codebuddyHome, "settings.json"));
56895
+ const settingsEnv = settings?.env;
56896
+ if (settingsEnv && typeof settingsEnv === "object" && !Array.isArray(settingsEnv)) {
56897
+ const e = settingsEnv;
56898
+ const v2 = e.CODEBUDDY_BASE_URL;
56899
+ if (nonEmpty2(v2)) codebuddyBaseUrl = v2;
56900
+ }
56901
+ const tm = settings?.model;
56902
+ if (nonEmpty2(tm)) model = String(tm);
56903
+ const tacw = Number(settings?.autoCompactWindow);
56904
+ if (Number.isFinite(tacw) && tacw > 0) autoCompactWindow = tacw;
56905
+ if (!codebuddyBaseUrl && nonEmpty2(env.CODEBUDDY_BASE_URL)) codebuddyBaseUrl = env.CODEBUDDY_BASE_URL;
56906
+ const windowByModel = /* @__PURE__ */ new Map();
56907
+ const urls = [];
56908
+ const seenUrl = /* @__PURE__ */ new Set();
56909
+ for (const f2 of [
56910
+ path10.join(codebuddyHome, "models.json"),
56911
+ path10.join(cwd, ".codebuddy", "models.json")
56912
+ ]) {
56913
+ const parsed = parseCodebuddyModelsJson(readJsonFile(f2));
56914
+ for (const w2 of parsed.models) windowByModel.set(w2.id, w2.contextWindow);
56915
+ for (const u2 of parsed.urls) {
56916
+ if (!seenUrl.has(u2)) {
56917
+ seenUrl.add(u2);
56918
+ urls.push(u2);
56919
+ }
56920
+ }
56921
+ }
56922
+ return {
56923
+ ...codebuddyBaseUrl ? { codebuddyBaseUrl } : {},
56924
+ ...model ? { model } : {},
56925
+ ...autoCompactWindow ? { autoCompactWindow } : {},
56926
+ ...windowByModel.size > 0 ? { models: [...windowByModel.entries()].map(([id, contextWindow]) => ({ id, contextWindow })) } : {},
56927
+ ...urls.length > 0 ? { modelUrls: urls } : {}
56928
+ };
56929
+ }
56838
56930
  function parseDshSettingsYaml(text) {
56839
56931
  const out = [];
56840
56932
  const seen = /* @__PURE__ */ new Set();
@@ -57208,6 +57300,7 @@ function loadClientConfig(env, cwd) {
57208
57300
  config.opencode = readOpencodeConfig(resolveOpencodeConfigFile(env));
57209
57301
  config.hermes = readHermesConfig(resolveHermesHome(env));
57210
57302
  config.dsh = readDshConfig(resolveDshHome(env));
57303
+ config.codebuddy = readCodebuddyConfig(resolveCodebuddyHome(env), cwd, env);
57211
57304
  return config;
57212
57305
  }
57213
57306
  function collectModelWindows(config, scope) {
@@ -57222,12 +57315,14 @@ function collectModelWindows(config, scope) {
57222
57315
  else if (scope === "pi") for (const p2 of Object.values(config.pi?.providers ?? {})) add(p2.models);
57223
57316
  else if (scope === "omp") for (const p2 of Object.values(config.omp?.providers ?? {})) add(p2.models);
57224
57317
  else if (scope === "opencode") for (const p2 of Object.values(config.opencode?.providers ?? {})) add(p2.models);
57318
+ else if (scope === "codebuddy") add(config.codebuddy?.models);
57225
57319
  return out;
57226
57320
  }
57227
57321
  for (const p2 of Object.values(config.pi?.providers ?? {})) add(p2.models);
57228
57322
  for (const p2 of Object.values(config.omp?.providers ?? {})) add(p2.models);
57229
57323
  for (const p2 of Object.values(config.opencode?.providers ?? {})) add(p2.models);
57230
57324
  add(config.codex?.modelWindows);
57325
+ add(config.codebuddy?.models);
57231
57326
  return out;
57232
57327
  }
57233
57328
 
@@ -57265,18 +57360,26 @@ function extractHttpsHosts(config) {
57265
57360
  if (config.zcode) {
57266
57361
  for (const prov of Object.values(config.zcode.providers)) push(prov.baseURL);
57267
57362
  }
57363
+ if (config.codebuddy) {
57364
+ push(config.codebuddy.codebuddyBaseUrl);
57365
+ for (const u2 of config.codebuddy.modelUrls ?? []) push(u2);
57366
+ }
57268
57367
  return out;
57269
57368
  }
57270
57369
  function configFilePaths(env) {
57271
57370
  const home = os2.homedir();
57272
57371
  const codexHome = nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME : path11.join(home, ".codex");
57273
57372
  const zcodeHome = nonEmpty2(env.ZCODE_DATA_BASE_DIR) ? env.ZCODE_DATA_BASE_DIR : path11.join(home, ".zcode");
57373
+ const codebuddyHome = resolveCodebuddyHome(env);
57274
57374
  return [
57275
57375
  path11.join(home, ".claude", "settings.json"),
57276
57376
  path11.join(process.cwd(), ".claude", "settings.json"),
57277
57377
  path11.join(codexHome, "config.toml"),
57278
57378
  path11.join(resolvePiHome(env), "models.json"),
57279
- path11.join(zcodeHome, "v2", "config.json")
57379
+ path11.join(zcodeHome, "v2", "config.json"),
57380
+ path11.join(codebuddyHome, "settings.json"),
57381
+ path11.join(codebuddyHome, "models.json"),
57382
+ path11.join(process.cwd(), ".codebuddy", "models.json")
57280
57383
  ];
57281
57384
  }
57282
57385
  function readMtimes(paths) {
@@ -64802,7 +64905,7 @@ function selfDistFile(name) {
64802
64905
  return path15.join(selfPackageRoot(), "dist", name);
64803
64906
  }
64804
64907
  var LAUNCHER_DEFAULT_HOST = "127.0.0.1";
64805
- var LAUNCH_CLIENTS = ["pi", "codex", "claude", "omp", "opencode", "hermes", "dsh", "pi-test"];
64908
+ var LAUNCH_CLIENTS = ["pi", "codex", "claude", "omp", "opencode", "hermes", "dsh", "codebuddy", "pi-test"];
64806
64909
  var HEALTH_PATH = "/__bili/health";
64807
64910
  var HEALTH_POLL_INTERVAL_MS = 200;
64808
64911
  var SPAWN_WAIT_MS = 2e4;
@@ -64890,6 +64993,29 @@ function discoverRoutes(client, config) {
64890
64993
  }
64891
64994
  } catch {
64892
64995
  }
64996
+ } else if (client === "codebuddy") {
64997
+ const raw = nonEmpty2(config.codebuddy?.codebuddyBaseUrl) ? config.codebuddy.codebuddyBaseUrl : "https://tencent.sso.codebuddy.cn/v2";
64998
+ const real = unwrapUpstream2(raw);
64999
+ try {
65000
+ const url = new URL(real);
65001
+ if ((url.protocol === "https:" || url.protocol === "http:") && !rewriteKeys.has("CODEBUDDY_BASE_URL")) {
65002
+ rewriteKeys.add("CODEBUDDY_BASE_URL");
65003
+ httpRewrites.push({ key: "CODEBUDDY_BASE_URL", realUpstream: real });
65004
+ }
65005
+ } catch {
65006
+ }
65007
+ for (const rawModelUrl of config.codebuddy?.modelUrls ?? []) {
65008
+ try {
65009
+ const url = new URL(unwrapUpstream2(rawModelUrl));
65010
+ if (url.protocol !== "https:") continue;
65011
+ const host = url.hostname;
65012
+ if (host && !httpsSeen.has(host.toLowerCase())) {
65013
+ httpsSeen.add(host.toLowerCase());
65014
+ httpsDomains.push(host);
65015
+ }
65016
+ } catch {
65017
+ }
65018
+ }
64893
65019
  } else if (client === "pi") {
64894
65020
  for (const [name, prov] of Object.entries(config.pi?.providers ?? {})) {
64895
65021
  classify(prov.baseUrl, name);
@@ -65033,6 +65159,21 @@ function buildClaudeEnv(origin, caPath, httpRewrites, httpsRewrites, baseEnv) {
65033
65159
  if (hr2) env.ANTHROPIC_BASE_URL = hr2.realUpstream;
65034
65160
  return env;
65035
65161
  }
65162
+ async function resolveCodebuddyBudgetEnv(opts) {
65163
+ const { model, userAutoCompactWindow, shellAutoCompactWindow, routes, upstreamUrl } = opts;
65164
+ if (!model || userAutoCompactWindow !== void 0 || nonEmpty2(shellAutoCompactWindow)) return {};
65165
+ const window2 = await resolveLauncherWindow(model, routes, upstreamUrl);
65166
+ if (!window2) return {};
65167
+ return { CODEBUDDY_AUTO_COMPACT_WINDOW: String(window2) };
65168
+ }
65169
+ function buildCodebuddyEnv(origin, caPath, httpRewrites, httpsRewrites, baseEnv) {
65170
+ const env = { ...baseEnv, HTTPS_PROXY: origin, NODE_EXTRA_CA_CERTS: caPath, BILLION_CONTEXT_PROXY: origin };
65171
+ const r = httpRewrites.find((rw) => rw.key === "CODEBUDDY_BASE_URL");
65172
+ if (r) env.CODEBUDDY_BASE_URL = wrapUpstream(origin, r.realUpstream);
65173
+ const hr2 = httpsRewrites.find((rw) => rw.key === "CODEBUDDY_BASE_URL");
65174
+ if (hr2) env.CODEBUDDY_BASE_URL = hr2.realUpstream;
65175
+ return env;
65176
+ }
65036
65177
  function launcherDirectUrl(env) {
65037
65178
  return env.BILI_LAUNCHER_DIRECT === "1";
65038
65179
  }
@@ -65073,7 +65214,7 @@ function isPrivateIPv4(host) {
65073
65214
  return false;
65074
65215
  }
65075
65216
  function launcherInjectMcp(env, base, codexUpstream) {
65076
- if (base === "pi" || base === "omp" || base === "opencode" || base === "hermes" || base === "dsh") return false;
65217
+ if (base === "pi" || base === "omp" || base === "opencode" || base === "hermes" || base === "dsh" || base === "codebuddy") return false;
65077
65218
  if (env.BILI_LAUNCHER_PLUGIN === "0") return false;
65078
65219
  if (base === "codex" && env.BILI_LAUNCHER_PLUGIN === void 0 && codexUpstream !== void 0 && isPrivateUpstreamHost(codexUpstream)) {
65079
65220
  return false;
@@ -65828,6 +65969,10 @@ function resolveClientCommand(client, env) {
65828
65969
  );
65829
65970
  return { command: process.execPath, prefixArgs: [cli] };
65830
65971
  }
65972
+ if (client === "codebuddy") {
65973
+ const resolved2 = resolveOnPath("codebuddy", env) ?? resolveOnPath("cbc", env);
65974
+ return { command: resolved2 ?? "codebuddy", prefixArgs: [] };
65975
+ }
65831
65976
  const resolved = resolveOnPath(client, env);
65832
65977
  return { command: resolved ?? client, prefixArgs: [] };
65833
65978
  }
@@ -65984,6 +66129,19 @@ async function runLaunch(params, deps = {}) {
65984
66129
  }
65985
66130
  if (injectMcp && codexConversationId) clientArgs = [...buildCodexMcpArgs(origin, codexConversationId), ...clientArgs];
65986
66131
  }
66132
+ } else if (base === "codebuddy") {
66133
+ env = buildCodebuddyEnv(origin, ca, routes.httpRewrites, routes.httpsRewrites, process.env);
66134
+ const codebuddyBudget = await resolveCodebuddyBudgetEnv({
66135
+ model: config.codebuddy?.model,
66136
+ userAutoCompactWindow: config.codebuddy?.autoCompactWindow,
66137
+ shellAutoCompactWindow: process.env.CODEBUDDY_AUTO_COMPACT_WINDOW,
66138
+ routes: biliRoutes,
66139
+ upstreamUrl: config.codebuddy?.codebuddyBaseUrl ?? "https://tencent.sso.codebuddy.cn/v2"
66140
+ });
66141
+ Object.assign(env, codebuddyBudget);
66142
+ if (codebuddyBudget.CODEBUDDY_AUTO_COMPACT_WINDOW !== void 0) {
66143
+ console.error(`bili: codebuddy budget aligned \u2014 CODEBUDDY_AUTO_COMPACT_WINDOW=${codebuddyBudget.CODEBUDDY_AUTO_COMPACT_WINDOW}`);
66144
+ }
65987
66145
  } else {
65988
66146
  env = directUrl ? buildClaudePluginEnv(origin, true, process.env) : buildClaudeEnv(origin, ca, routes.httpRewrites, routes.httpsRewrites, process.env);
65989
66147
  if (directUrl) env.BILLION_CONTEXT_PROXY = origin;
@@ -66238,6 +66396,7 @@ Usage:
66238
66396
  bili opencode [opts --] [args] start a proxy + launch opencode against it (cert-MITM)
66239
66397
  bili hermes [opts --] [args] start a proxy + launch hermes-agent against it (/bili/ rewrite)
66240
66398
  bili dsh [opts --] [args] start a proxy + launch deepseek-harness against it (/bili/ rewrite)
66399
+ bili codebuddy [opts --] [args] start a proxy + launch codebuddy against it (/bili/ rewrite)
66241
66400
  bili test pi non-polluting pi smoke test through the proxy
66242
66401
  bili export [session] [--full] list sessions / export one as a Markdown handoff
66243
66402
  (--full includes original messages; --output FILE)
@@ -66252,7 +66411,7 @@ Usage:
66252
66411
  bili --version print version
66253
66412
  bili --help show this help
66254
66413
 
66255
- Launcher (bili pi / bili codex / bili claude / bili omp / bili opencode / bili hermes / bili dsh):
66414
+ Launcher (bili pi / bili codex / bili claude / bili omp / bili opencode / bili hermes / bili dsh / bili codebuddy):
66256
66415
  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
66257
66416
  MITM CA \u2014 no config-file edits. Discovered HTTPS upstream domains are
66258
66417
  auto-whitelisted for MITM so the proxy TLS-terminates exactly the hosts the
@@ -66268,6 +66427,7 @@ Launcher (bili pi / bili codex / bili claude / bili omp / bili opencode / bili h
66268
66427
  bili omp # launch omp through the proxy (pi-based; /bili/ rewrite)
66269
66428
  bili hermes # launch hermes-agent through the proxy (/bili/ rewrite of ~/.hermes/config.yaml)
66270
66429
  bili dsh --profile web "task" # launch deepseek-harness through the proxy (/bili/ rewrite of ~/.dsh/settings.yaml)
66430
+ bili codebuddy # launch codebuddy through the proxy (CODEBUDDY_BASE_URL /bili/ rewrite)
66271
66431
  bili test pi # quick end-to-end check of the pi path
66272
66432
  bili --mitm-domain api.foo.com pi # add a domain to the MITM whitelist (flags precede the client)
66273
66433
  bili -F http://127.0.0.1:7897 codex # route bili's upstream through a proxy (gost-style -F)