billion-context 0.1.50-pr.232.72 → 0.1.50-pr.233.75
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 +2 -2
- package/dist/index.js +214 -68
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,9 +64,9 @@ and blind-tunnel everything else.
|
|
|
64
64
|
bili pi # launch pi through the proxy
|
|
65
65
|
bili codex # launch codex through the proxy
|
|
66
66
|
bili claude # launch claude through the proxy
|
|
67
|
-
bili omp # pi-style: MITM env +
|
|
67
|
+
bili omp # pi-style: MITM env + persistent overlay home (~/.omp/agent-bili, real config untouched)
|
|
68
68
|
bili opencode # MITM for HTTPS + temp opencode.json (/bili/ for HTTP) + thin /acp plugin
|
|
69
|
-
bili hermes # no MITM possible (certifi CA) —
|
|
69
|
+
bili hermes # no MITM possible (certifi CA) — persistent overlay home (~/.hermes-bili), all traffic /bili/
|
|
70
70
|
bili pi --mitm-domain api.foo.com # add a domain to the MITM whitelist
|
|
71
71
|
```
|
|
72
72
|
|
package/dist/index.js
CHANGED
|
@@ -58748,6 +58748,9 @@ function piSettingsFile() {
|
|
|
58748
58748
|
function isPiEntry(entry, root) {
|
|
58749
58749
|
return entry === root || /^npm:billion-context(-pi)?(@|$)/.test(entry) || /(^|[/\\])node_modules[/\\]billion-context(-pi)?([\/\\]|$)/.test(entry) || /(^|[/\\])billion-context(-pi)?$/.test(entry);
|
|
58750
58750
|
}
|
|
58751
|
+
function isBiliPiEntry(entry, root) {
|
|
58752
|
+
return entry === root || /^npm:billion-context(@|$)/.test(entry) || /(^|[/\\])node_modules[/\\]billion-context([\/\\]|$)/.test(entry) || /(^|[/\\])billion-context$/.test(entry);
|
|
58753
|
+
}
|
|
58751
58754
|
function piInstall() {
|
|
58752
58755
|
const root = selfPackageRoot();
|
|
58753
58756
|
const file = piSettingsFile();
|
|
@@ -59184,17 +59187,205 @@ function buildCodexMcpArgs(origin, conversationId2) {
|
|
|
59184
59187
|
`mcp_servers.bili.env.BILI_CONVERSATION_ID=${JSON.stringify(conversationId2)}`
|
|
59185
59188
|
];
|
|
59186
59189
|
}
|
|
59190
|
+
function overlayLockPath(overlay) {
|
|
59191
|
+
return path13.join(overlay, ".bili-launch.pid");
|
|
59192
|
+
}
|
|
59193
|
+
function livePidHoldsOverlay(overlay) {
|
|
59194
|
+
let raw;
|
|
59195
|
+
try {
|
|
59196
|
+
raw = fs10.readFileSync(overlayLockPath(overlay), "utf8");
|
|
59197
|
+
} catch {
|
|
59198
|
+
return void 0;
|
|
59199
|
+
}
|
|
59200
|
+
const pid = Number.parseInt(raw.trim(), 10);
|
|
59201
|
+
if (!Number.isInteger(pid) || pid <= 0 || pid === process.pid) return void 0;
|
|
59202
|
+
try {
|
|
59203
|
+
process.kill(pid, 0);
|
|
59204
|
+
} catch (err2) {
|
|
59205
|
+
if (err2.code === "ESRCH") return void 0;
|
|
59206
|
+
}
|
|
59207
|
+
return pid;
|
|
59208
|
+
}
|
|
59209
|
+
function refreshOverlayHome(realHome, overlay, generatedFile) {
|
|
59210
|
+
try {
|
|
59211
|
+
fs10.mkdirSync(overlay, { recursive: true });
|
|
59212
|
+
} catch {
|
|
59213
|
+
return false;
|
|
59214
|
+
}
|
|
59215
|
+
const holder = livePidHoldsOverlay(overlay);
|
|
59216
|
+
if (holder !== void 0) {
|
|
59217
|
+
console.error(
|
|
59218
|
+
`bili: another bili launch (pid ${holder}) is using ${overlay} \u2014 concurrent launches share this overlay and the last one's proxy port wins in the generated config.`
|
|
59219
|
+
);
|
|
59220
|
+
}
|
|
59221
|
+
try {
|
|
59222
|
+
fs10.writeFileSync(overlayLockPath(overlay), `${process.pid}
|
|
59223
|
+
`);
|
|
59224
|
+
} catch {
|
|
59225
|
+
}
|
|
59226
|
+
const realEntries = /* @__PURE__ */ new Set();
|
|
59227
|
+
try {
|
|
59228
|
+
for (const entry of fs10.readdirSync(realHome)) realEntries.add(entry);
|
|
59229
|
+
} catch {
|
|
59230
|
+
}
|
|
59231
|
+
try {
|
|
59232
|
+
for (const entry of fs10.readdirSync(overlay)) {
|
|
59233
|
+
if (entry === generatedFile) continue;
|
|
59234
|
+
const overlayPath = path13.join(overlay, entry);
|
|
59235
|
+
if (entry.startsWith(`.${generatedFile}.`) && entry.endsWith(".tmp")) {
|
|
59236
|
+
try {
|
|
59237
|
+
fs10.unlinkSync(overlayPath);
|
|
59238
|
+
} catch {
|
|
59239
|
+
}
|
|
59240
|
+
continue;
|
|
59241
|
+
}
|
|
59242
|
+
let st2;
|
|
59243
|
+
try {
|
|
59244
|
+
st2 = fs10.lstatSync(overlayPath);
|
|
59245
|
+
} catch {
|
|
59246
|
+
continue;
|
|
59247
|
+
}
|
|
59248
|
+
if (st2.isSymbolicLink()) {
|
|
59249
|
+
let target;
|
|
59250
|
+
try {
|
|
59251
|
+
target = fs10.readlinkSync(overlayPath);
|
|
59252
|
+
} catch {
|
|
59253
|
+
}
|
|
59254
|
+
const wanted = realEntries.has(entry) ? path13.join(realHome, entry) : void 0;
|
|
59255
|
+
if (!wanted || target !== wanted) {
|
|
59256
|
+
try {
|
|
59257
|
+
fs10.unlinkSync(overlayPath);
|
|
59258
|
+
} catch {
|
|
59259
|
+
}
|
|
59260
|
+
}
|
|
59261
|
+
} else if (realEntries.has(entry)) {
|
|
59262
|
+
if (mergeOverlayEntry(overlayPath, path13.join(realHome, entry))) {
|
|
59263
|
+
try {
|
|
59264
|
+
fs10.rmSync(overlayPath, { recursive: true, force: true });
|
|
59265
|
+
} catch {
|
|
59266
|
+
}
|
|
59267
|
+
} else {
|
|
59268
|
+
console.error(`bili: could not merge ${overlayPath} into ${realHome} \u2014 kept in place, resolve manually.`);
|
|
59269
|
+
}
|
|
59270
|
+
}
|
|
59271
|
+
}
|
|
59272
|
+
for (const entry of realEntries) {
|
|
59273
|
+
if (entry === generatedFile) continue;
|
|
59274
|
+
try {
|
|
59275
|
+
fs10.symlinkSync(path13.join(realHome, entry), path13.join(overlay, entry));
|
|
59276
|
+
} catch {
|
|
59277
|
+
}
|
|
59278
|
+
}
|
|
59279
|
+
} catch {
|
|
59280
|
+
}
|
|
59281
|
+
return true;
|
|
59282
|
+
}
|
|
59283
|
+
function mergeOverlayEntry(src, dst) {
|
|
59284
|
+
let st2;
|
|
59285
|
+
try {
|
|
59286
|
+
st2 = fs10.lstatSync(src);
|
|
59287
|
+
} catch {
|
|
59288
|
+
return true;
|
|
59289
|
+
}
|
|
59290
|
+
let dstStat;
|
|
59291
|
+
try {
|
|
59292
|
+
dstStat = fs10.lstatSync(dst);
|
|
59293
|
+
} catch {
|
|
59294
|
+
}
|
|
59295
|
+
if (st2.isDirectory()) {
|
|
59296
|
+
if (dstStat && !dstStat.isDirectory()) {
|
|
59297
|
+
try {
|
|
59298
|
+
fs10.renameSync(dst, `${dst}.bili-conflict`);
|
|
59299
|
+
dstStat = void 0;
|
|
59300
|
+
} catch {
|
|
59301
|
+
return false;
|
|
59302
|
+
}
|
|
59303
|
+
}
|
|
59304
|
+
try {
|
|
59305
|
+
fs10.mkdirSync(dst, { recursive: true });
|
|
59306
|
+
} catch {
|
|
59307
|
+
return false;
|
|
59308
|
+
}
|
|
59309
|
+
let entries;
|
|
59310
|
+
try {
|
|
59311
|
+
entries = fs10.readdirSync(src);
|
|
59312
|
+
} catch {
|
|
59313
|
+
return false;
|
|
59314
|
+
}
|
|
59315
|
+
let ok = true;
|
|
59316
|
+
for (const entry of entries) {
|
|
59317
|
+
if (!mergeOverlayEntry(path13.join(src, entry), path13.join(dst, entry))) ok = false;
|
|
59318
|
+
}
|
|
59319
|
+
return ok;
|
|
59320
|
+
}
|
|
59321
|
+
if (dstStat && dstStat.isDirectory()) {
|
|
59322
|
+
try {
|
|
59323
|
+
fs10.renameSync(src, `${dst}.bili-conflict`);
|
|
59324
|
+
return true;
|
|
59325
|
+
} catch {
|
|
59326
|
+
return false;
|
|
59327
|
+
}
|
|
59328
|
+
}
|
|
59329
|
+
if (st2.isSymbolicLink()) {
|
|
59330
|
+
if (dstStat) {
|
|
59331
|
+
try {
|
|
59332
|
+
fs10.unlinkSync(src);
|
|
59333
|
+
} catch {
|
|
59334
|
+
}
|
|
59335
|
+
return true;
|
|
59336
|
+
}
|
|
59337
|
+
try {
|
|
59338
|
+
fs10.renameSync(src, dst);
|
|
59339
|
+
} catch {
|
|
59340
|
+
return false;
|
|
59341
|
+
}
|
|
59342
|
+
return true;
|
|
59343
|
+
}
|
|
59344
|
+
if (dstStat && dstStat.mtimeMs >= st2.mtimeMs) {
|
|
59345
|
+
try {
|
|
59346
|
+
fs10.renameSync(src, `${dst}.bili-conflict`);
|
|
59347
|
+
return true;
|
|
59348
|
+
} catch {
|
|
59349
|
+
return false;
|
|
59350
|
+
}
|
|
59351
|
+
}
|
|
59352
|
+
if (dstStat) {
|
|
59353
|
+
try {
|
|
59354
|
+
fs10.renameSync(dst, `${dst}.bili-conflict`);
|
|
59355
|
+
} catch {
|
|
59356
|
+
return false;
|
|
59357
|
+
}
|
|
59358
|
+
}
|
|
59359
|
+
try {
|
|
59360
|
+
fs10.renameSync(src, dst);
|
|
59361
|
+
return true;
|
|
59362
|
+
} catch {
|
|
59363
|
+
return false;
|
|
59364
|
+
}
|
|
59365
|
+
}
|
|
59187
59366
|
function piPluginInstalled(piHome) {
|
|
59188
59367
|
const root = selfPackageRoot();
|
|
59189
59368
|
if (!root) return false;
|
|
59190
59369
|
try {
|
|
59191
59370
|
const parsed = JSON.parse(fs10.readFileSync(path13.join(piHome, "settings.json"), "utf8"));
|
|
59192
59371
|
const list = Array.isArray(parsed.packages) ? parsed.packages.map(String) : [];
|
|
59193
|
-
return list.some((p2) =>
|
|
59372
|
+
return list.some((p2) => isBiliPiEntry(p2, root));
|
|
59194
59373
|
} catch {
|
|
59195
59374
|
return false;
|
|
59196
59375
|
}
|
|
59197
59376
|
}
|
|
59377
|
+
function writeOverlayFileAtomic(overlay, fileName, contents) {
|
|
59378
|
+
const draft = path13.join(overlay, `.${fileName}.${process.pid}.tmp`);
|
|
59379
|
+
try {
|
|
59380
|
+
fs10.writeFileSync(draft, contents);
|
|
59381
|
+
fs10.renameSync(draft, path13.join(overlay, fileName));
|
|
59382
|
+
} catch {
|
|
59383
|
+
try {
|
|
59384
|
+
fs10.rmSync(draft, { force: true });
|
|
59385
|
+
} catch {
|
|
59386
|
+
}
|
|
59387
|
+
}
|
|
59388
|
+
}
|
|
59198
59389
|
function preparePiHttpRewrite(piHome, origin, httpRewrites, httpsRewrites) {
|
|
59199
59390
|
if (httpRewrites.length === 0 && httpsRewrites.length === 0) return void 0;
|
|
59200
59391
|
const modelsPath = path13.join(piHome, "models.json");
|
|
@@ -59231,19 +59422,10 @@ function preparePiHttpRewrite(piHome, origin, httpRewrites, httpsRewrites) {
|
|
|
59231
59422
|
}
|
|
59232
59423
|
}
|
|
59233
59424
|
}
|
|
59234
|
-
const
|
|
59235
|
-
|
|
59236
|
-
|
|
59237
|
-
|
|
59238
|
-
try {
|
|
59239
|
-
fs10.symlinkSync(path13.join(piHome, entry), path13.join(tmp, entry));
|
|
59240
|
-
} catch {
|
|
59241
|
-
}
|
|
59242
|
-
}
|
|
59243
|
-
} catch {
|
|
59244
|
-
}
|
|
59245
|
-
fs10.writeFileSync(path13.join(tmp, "models.json"), JSON.stringify(root));
|
|
59246
|
-
return tmp;
|
|
59425
|
+
const overlay = `${piHome}-bili`;
|
|
59426
|
+
if (!refreshOverlayHome(piHome, overlay, "models.json")) return void 0;
|
|
59427
|
+
writeOverlayFileAtomic(overlay, "models.json", JSON.stringify(root));
|
|
59428
|
+
return overlay;
|
|
59247
59429
|
}
|
|
59248
59430
|
function prepareOmpHttpRewrite(ompHome, origin, httpRewrites, httpsRewrites) {
|
|
59249
59431
|
if (httpRewrites.length === 0 && httpsRewrites.length === 0) return void 0;
|
|
@@ -59287,19 +59469,10 @@ function prepareOmpHttpRewrite(ompHome, origin, httpRewrites, httpsRewrites) {
|
|
|
59287
59469
|
}
|
|
59288
59470
|
}
|
|
59289
59471
|
}
|
|
59290
|
-
const
|
|
59291
|
-
|
|
59292
|
-
|
|
59293
|
-
|
|
59294
|
-
try {
|
|
59295
|
-
fs10.symlinkSync(path13.join(ompHome, entry), path13.join(tmp, entry));
|
|
59296
|
-
} catch {
|
|
59297
|
-
}
|
|
59298
|
-
}
|
|
59299
|
-
} catch {
|
|
59300
|
-
}
|
|
59301
|
-
fs10.writeFileSync(path13.join(tmp, "models.yml"), lines.join("\n"));
|
|
59302
|
-
return tmp;
|
|
59472
|
+
const overlay = `${ompHome}-bili`;
|
|
59473
|
+
if (!refreshOverlayHome(ompHome, overlay, "models.yml")) return void 0;
|
|
59474
|
+
writeOverlayFileAtomic(overlay, "models.yml", lines.join("\n"));
|
|
59475
|
+
return overlay;
|
|
59303
59476
|
}
|
|
59304
59477
|
function prepareHermesHome(hermesHome, origin, rewrites) {
|
|
59305
59478
|
if (rewrites.length === 0) return void 0;
|
|
@@ -59326,19 +59499,10 @@ function prepareHermesHome(hermesHome, origin, rewrites) {
|
|
|
59326
59499
|
changed = true;
|
|
59327
59500
|
}
|
|
59328
59501
|
if (!changed) return void 0;
|
|
59329
|
-
const
|
|
59330
|
-
|
|
59331
|
-
|
|
59332
|
-
|
|
59333
|
-
try {
|
|
59334
|
-
fs10.symlinkSync(path13.join(hermesHome, entry), path13.join(tmp, entry));
|
|
59335
|
-
} catch {
|
|
59336
|
-
}
|
|
59337
|
-
}
|
|
59338
|
-
} catch {
|
|
59339
|
-
}
|
|
59340
|
-
fs10.writeFileSync(path13.join(tmp, "config.yaml"), lines.join(eol));
|
|
59341
|
-
return tmp;
|
|
59502
|
+
const overlay = `${hermesHome}-bili`;
|
|
59503
|
+
if (!refreshOverlayHome(hermesHome, overlay, "config.yaml")) return void 0;
|
|
59504
|
+
writeOverlayFileAtomic(overlay, "config.yaml", lines.join(eol));
|
|
59505
|
+
return overlay;
|
|
59342
59506
|
}
|
|
59343
59507
|
function prepareOpencodeHttpRewrite(configFile2, origin, httpRewrites, httpsRewrites, pluginPath) {
|
|
59344
59508
|
if (httpRewrites.length === 0 && httpsRewrites.length === 0 && !pluginPath) return void 0;
|
|
@@ -59575,10 +59739,10 @@ async function runLaunch(params, deps = {}) {
|
|
|
59575
59739
|
const ca = resolveCaCertPath(process.env);
|
|
59576
59740
|
let env;
|
|
59577
59741
|
let clientArgs = params.clientArgs;
|
|
59578
|
-
let
|
|
59579
|
-
let
|
|
59742
|
+
let piOverlayHome;
|
|
59743
|
+
let ompOverlayHome;
|
|
59580
59744
|
let opencodeTmpFile;
|
|
59581
|
-
let
|
|
59745
|
+
let hermesOverlayHome;
|
|
59582
59746
|
const tmpFiles = [];
|
|
59583
59747
|
const directUrl = launcherDirectUrl(process.env);
|
|
59584
59748
|
if (directUrl) {
|
|
@@ -59599,16 +59763,16 @@ async function runLaunch(params, deps = {}) {
|
|
|
59599
59763
|
const origin = handle2.origin;
|
|
59600
59764
|
if (base === "pi") {
|
|
59601
59765
|
env = buildPiEnv(origin, ca, process.env);
|
|
59602
|
-
|
|
59603
|
-
if (
|
|
59766
|
+
piOverlayHome = preparePiHttpRewrite(resolvePiHome(process.env), origin, routes.httpRewrites, routes.httpsRewrites);
|
|
59767
|
+
if (piOverlayHome) env.PI_CODING_AGENT_DIR = piOverlayHome;
|
|
59604
59768
|
const piExt = selfDistFile("agent/pi.js");
|
|
59605
59769
|
if (piExt && fs10.existsSync(piExt) && !piPluginInstalled(resolvePiHome(process.env))) {
|
|
59606
59770
|
clientArgs = ["-e", piExt, ...clientArgs];
|
|
59607
59771
|
}
|
|
59608
59772
|
} else if (base === "omp") {
|
|
59609
59773
|
env = buildPiEnv(origin, ca, process.env);
|
|
59610
|
-
|
|
59611
|
-
if (
|
|
59774
|
+
ompOverlayHome = prepareOmpHttpRewrite(resolveOmpHome(process.env), origin, routes.httpRewrites, routes.httpsRewrites);
|
|
59775
|
+
if (ompOverlayHome) env.PI_CODING_AGENT_DIR = ompOverlayHome;
|
|
59612
59776
|
} else if (base === "opencode") {
|
|
59613
59777
|
env = { ...process.env, HTTPS_PROXY: origin, NODE_EXTRA_CA_CERTS: ca, BILLION_CONTEXT_PROXY: origin };
|
|
59614
59778
|
const opencodePlugin = selfDistFile("agent/opencode.js");
|
|
@@ -59617,9 +59781,9 @@ async function runLaunch(params, deps = {}) {
|
|
|
59617
59781
|
if (opencodeTmpFile) env.OPENCODE_CONFIG = opencodeTmpFile;
|
|
59618
59782
|
} else if (base === "hermes") {
|
|
59619
59783
|
env = { ...process.env };
|
|
59620
|
-
|
|
59621
|
-
if (
|
|
59622
|
-
env.HERMES_HOME =
|
|
59784
|
+
hermesOverlayHome = prepareHermesHome(resolveHermesHome(process.env), origin, routes.httpRewrites);
|
|
59785
|
+
if (hermesOverlayHome) {
|
|
59786
|
+
env.HERMES_HOME = hermesOverlayHome;
|
|
59623
59787
|
} else {
|
|
59624
59788
|
console.error(
|
|
59625
59789
|
routes.httpRewrites.length === 0 ? "bili: no hermes providers found in ~/.hermes/config.yaml \u2014 traffic will NOT go through the proxy (configure a provider first)." : "bili: hermes config.yaml could not be rewritten (unreadable or no matching provider endpoints) \u2014 traffic will NOT go through the proxy."
|
|
@@ -59657,24 +59821,6 @@ async function runLaunch(params, deps = {}) {
|
|
|
59657
59821
|
code = 1;
|
|
59658
59822
|
} finally {
|
|
59659
59823
|
stopProxy(handle2);
|
|
59660
|
-
if (piTmpHome) {
|
|
59661
|
-
try {
|
|
59662
|
-
fs10.rmSync(piTmpHome, { recursive: true, force: true });
|
|
59663
|
-
} catch {
|
|
59664
|
-
}
|
|
59665
|
-
}
|
|
59666
|
-
if (ompTmpHome) {
|
|
59667
|
-
try {
|
|
59668
|
-
fs10.rmSync(ompTmpHome, { recursive: true, force: true });
|
|
59669
|
-
} catch {
|
|
59670
|
-
}
|
|
59671
|
-
}
|
|
59672
|
-
if (hermesTmpHome) {
|
|
59673
|
-
try {
|
|
59674
|
-
fs10.rmSync(hermesTmpHome, { recursive: true, force: true });
|
|
59675
|
-
} catch {
|
|
59676
|
-
}
|
|
59677
|
-
}
|
|
59678
59824
|
if (opencodeTmpFile) {
|
|
59679
59825
|
try {
|
|
59680
59826
|
fs10.rmSync(path13.dirname(opencodeTmpFile), { recursive: true, force: true });
|