billion-context 0.1.74-pr.478.295 → 0.1.74

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/dist/index.js CHANGED
@@ -1141,14 +1141,14 @@ var require_util = __commonJS({
1141
1141
  }
1142
1142
  const port = url.port != null ? url.port : url.protocol === "https:" ? 443 : 80;
1143
1143
  let origin = url.origin != null ? url.origin : `${url.protocol || ""}//${url.hostname || ""}:${port}`;
1144
- let path18 = url.path != null ? url.path : `${url.pathname || ""}${url.search || ""}`;
1144
+ let path17 = url.path != null ? url.path : `${url.pathname || ""}${url.search || ""}`;
1145
1145
  if (origin[origin.length - 1] === "/") {
1146
1146
  origin = origin.slice(0, origin.length - 1);
1147
1147
  }
1148
- if (path18 && path18[0] !== "/") {
1149
- path18 = `/${path18}`;
1148
+ if (path17 && path17[0] !== "/") {
1149
+ path17 = `/${path17}`;
1150
1150
  }
1151
- return new URL(`${origin}${path18}`);
1151
+ return new URL(`${origin}${path17}`);
1152
1152
  }
1153
1153
  if (!isHttpOrHttpsPrefixed(url.origin || url.protocol)) {
1154
1154
  throw new InvalidArgumentError("Invalid URL protocol: the URL must start with `http:` or `https:`.");
@@ -1969,9 +1969,9 @@ var require_diagnostics = __commonJS({
1969
1969
  "undici:client:sendHeaders",
1970
1970
  (evt) => {
1971
1971
  const {
1972
- request: { method, path: path18, origin }
1972
+ request: { method, path: path17, origin }
1973
1973
  } = evt;
1974
- debugLog("sending request to %s %s%s", method, origin, path18);
1974
+ debugLog("sending request to %s %s%s", method, origin, path17);
1975
1975
  }
1976
1976
  );
1977
1977
  }
@@ -1989,14 +1989,14 @@ var require_diagnostics = __commonJS({
1989
1989
  "undici:request:headers",
1990
1990
  (evt) => {
1991
1991
  const {
1992
- request: { method, path: path18, origin },
1992
+ request: { method, path: path17, origin },
1993
1993
  response: { statusCode }
1994
1994
  } = evt;
1995
1995
  debugLog(
1996
1996
  "received response to %s %s%s - HTTP %d",
1997
1997
  method,
1998
1998
  origin,
1999
- path18,
1999
+ path17,
2000
2000
  statusCode
2001
2001
  );
2002
2002
  }
@@ -2005,23 +2005,23 @@ var require_diagnostics = __commonJS({
2005
2005
  "undici:request:trailers",
2006
2006
  (evt) => {
2007
2007
  const {
2008
- request: { method, path: path18, origin }
2008
+ request: { method, path: path17, origin }
2009
2009
  } = evt;
2010
- debugLog("trailers received from %s %s%s", method, origin, path18);
2010
+ debugLog("trailers received from %s %s%s", method, origin, path17);
2011
2011
  }
2012
2012
  );
2013
2013
  diagnosticsChannel.subscribe(
2014
2014
  "undici:request:error",
2015
2015
  (evt) => {
2016
2016
  const {
2017
- request: { method, path: path18, origin },
2017
+ request: { method, path: path17, origin },
2018
2018
  error
2019
2019
  } = evt;
2020
2020
  debugLog(
2021
2021
  "request to %s %s%s errored - %s",
2022
2022
  method,
2023
2023
  origin,
2024
- path18,
2024
+ path17,
2025
2025
  error.message
2026
2026
  );
2027
2027
  }
@@ -2136,7 +2136,7 @@ var require_request = __commonJS({
2136
2136
  var kHandler = /* @__PURE__ */ Symbol("handler");
2137
2137
  var Request = class {
2138
2138
  constructor(origin, {
2139
- path: path18,
2139
+ path: path17,
2140
2140
  method,
2141
2141
  body,
2142
2142
  headers,
@@ -2153,11 +2153,11 @@ var require_request = __commonJS({
2153
2153
  maxRedirections,
2154
2154
  typeOfService
2155
2155
  }, handler) {
2156
- if (typeof path18 !== "string") {
2156
+ if (typeof path17 !== "string") {
2157
2157
  throw new InvalidArgumentError("path must be a string");
2158
- } else if (path18[0] !== "/" && !(path18.startsWith("http://") || path18.startsWith("https://")) && method !== "CONNECT") {
2158
+ } else if (path17[0] !== "/" && !(path17.startsWith("http://") || path17.startsWith("https://")) && method !== "CONNECT") {
2159
2159
  throw new InvalidArgumentError("path must be an absolute URL or start with a slash");
2160
- } else if (invalidPathRegex.test(path18)) {
2160
+ } else if (invalidPathRegex.test(path17)) {
2161
2161
  throw new InvalidArgumentError("invalid request path");
2162
2162
  }
2163
2163
  if (typeof method !== "string") {
@@ -2232,7 +2232,7 @@ var require_request = __commonJS({
2232
2232
  this.completed = false;
2233
2233
  this.aborted = false;
2234
2234
  this.upgrade = upgrade || null;
2235
- this.path = query ? serializePathWithQuery(path18, query) : path18;
2235
+ this.path = query ? serializePathWithQuery(path17, query) : path17;
2236
2236
  this.origin = origin;
2237
2237
  this.protocol = getProtocolFromUrlString(origin);
2238
2238
  this.idempotent = idempotent == null ? method === "HEAD" || method === "GET" : idempotent;
@@ -7415,7 +7415,7 @@ var require_client_h1 = __commonJS({
7415
7415
  return method !== "GET" && method !== "HEAD" && method !== "OPTIONS" && method !== "TRACE" && method !== "CONNECT";
7416
7416
  }
7417
7417
  function writeH1(client, request) {
7418
- const { method, path: path18, host, upgrade, blocking, reset } = request;
7418
+ const { method, path: path17, host, upgrade, blocking, reset } = request;
7419
7419
  let { body, headers, contentLength } = request;
7420
7420
  const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH" || method === "QUERY" || method === "PROPFIND" || method === "PROPPATCH";
7421
7421
  if (util.isFormDataLike(body)) {
@@ -7493,7 +7493,7 @@ var require_client_h1 = __commonJS({
7493
7493
  if (socket.setTypeOfService) {
7494
7494
  socket.setTypeOfService(request.typeOfService);
7495
7495
  }
7496
- let header = `${method} ${path18} HTTP/1.1\r
7496
+ let header = `${method} ${path17} HTTP/1.1\r
7497
7497
  `;
7498
7498
  if (typeof host === "string") {
7499
7499
  header += `host: ${host}\r
@@ -8146,7 +8146,7 @@ var require_client_h2 = __commonJS({
8146
8146
  function writeH2(client, request) {
8147
8147
  const requestTimeout = request.bodyTimeout ?? client[kBodyTimeout];
8148
8148
  const session = client[kHTTP2Session];
8149
- const { method, path: path18, host, upgrade, expectContinue, signal, protocol, headers: reqHeaders } = request;
8149
+ const { method, path: path17, host, upgrade, expectContinue, signal, protocol, headers: reqHeaders } = request;
8150
8150
  let { body } = request;
8151
8151
  if (upgrade != null && upgrade !== "websocket") {
8152
8152
  util.errorRequest(client, request, new InvalidArgumentError(`Custom upgrade "${upgrade}" not supported over HTTP/2`));
@@ -8214,7 +8214,7 @@ var require_client_h2 = __commonJS({
8214
8214
  }
8215
8215
  headers[HTTP2_HEADER_METHOD] = "CONNECT";
8216
8216
  headers[HTTP2_HEADER_PROTOCOL] = "websocket";
8217
- headers[HTTP2_HEADER_PATH] = path18;
8217
+ headers[HTTP2_HEADER_PATH] = path17;
8218
8218
  if (protocol === "ws:" || protocol === "wss:") {
8219
8219
  headers[HTTP2_HEADER_SCHEME] = protocol === "ws:" ? "http" : "https";
8220
8220
  } else {
@@ -8255,7 +8255,7 @@ var require_client_h2 = __commonJS({
8255
8255
  stream2.setTimeout(requestTimeout);
8256
8256
  return true;
8257
8257
  }
8258
- headers[HTTP2_HEADER_PATH] = path18;
8258
+ headers[HTTP2_HEADER_PATH] = path17;
8259
8259
  headers[HTTP2_HEADER_SCHEME] = protocol === "http:" ? "http" : "https";
8260
8260
  const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH";
8261
8261
  if (body && typeof body.read === "function") {
@@ -10598,10 +10598,10 @@ var require_proxy_agent = __commonJS({
10598
10598
  };
10599
10599
  const {
10600
10600
  origin,
10601
- path: path18 = "/",
10601
+ path: path17 = "/",
10602
10602
  headers = {}
10603
10603
  } = opts;
10604
- opts.path = origin + path18;
10604
+ opts.path = origin + path17;
10605
10605
  if (!("host" in headers) && !("Host" in headers)) {
10606
10606
  const { host } = new URL(origin);
10607
10607
  headers.host = host;
@@ -12684,20 +12684,20 @@ var require_mock_utils = __commonJS({
12684
12684
  }
12685
12685
  return normalizedQp;
12686
12686
  }
12687
- function safeUrl(path18) {
12688
- if (typeof path18 !== "string") {
12689
- return path18;
12687
+ function safeUrl(path17) {
12688
+ if (typeof path17 !== "string") {
12689
+ return path17;
12690
12690
  }
12691
- const pathSegments = path18.split("?", 3);
12691
+ const pathSegments = path17.split("?", 3);
12692
12692
  if (pathSegments.length !== 2) {
12693
- return path18;
12693
+ return path17;
12694
12694
  }
12695
12695
  const qp = new URLSearchParams(pathSegments.pop());
12696
12696
  qp.sort();
12697
12697
  return [...pathSegments, qp.toString()].join("?");
12698
12698
  }
12699
- function matchKey(mockDispatch2, { path: path18, method, body, headers }) {
12700
- const pathMatch = matchValue(mockDispatch2.path, path18);
12699
+ function matchKey(mockDispatch2, { path: path17, method, body, headers }) {
12700
+ const pathMatch = matchValue(mockDispatch2.path, path17);
12701
12701
  const methodMatch = matchValue(mockDispatch2.method, method);
12702
12702
  const bodyMatch = typeof mockDispatch2.body !== "undefined" ? matchValue(mockDispatch2.body, body) : true;
12703
12703
  const headersMatch = matchHeaders(mockDispatch2, headers);
@@ -12722,8 +12722,8 @@ var require_mock_utils = __commonJS({
12722
12722
  const basePath = key.query ? serializePathWithQuery(key.path, key.query) : key.path;
12723
12723
  const resolvedPath = typeof basePath === "string" ? safeUrl(basePath) : basePath;
12724
12724
  const resolvedPathWithoutTrailingSlash = removeTrailingSlash(resolvedPath);
12725
- let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path18, ignoreTrailingSlash }) => {
12726
- return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(path18)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl(path18), resolvedPath);
12725
+ let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path17, ignoreTrailingSlash }) => {
12726
+ return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(path17)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl(path17), resolvedPath);
12727
12727
  });
12728
12728
  if (matchedMockDispatches.length === 0) {
12729
12729
  throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`);
@@ -12762,19 +12762,19 @@ var require_mock_utils = __commonJS({
12762
12762
  mockDispatches.splice(index, 1);
12763
12763
  }
12764
12764
  }
12765
- function removeTrailingSlash(path18) {
12766
- while (path18.endsWith("/")) {
12767
- path18 = path18.slice(0, -1);
12765
+ function removeTrailingSlash(path17) {
12766
+ while (path17.endsWith("/")) {
12767
+ path17 = path17.slice(0, -1);
12768
12768
  }
12769
- if (path18.length === 0) {
12770
- path18 = "/";
12769
+ if (path17.length === 0) {
12770
+ path17 = "/";
12771
12771
  }
12772
- return path18;
12772
+ return path17;
12773
12773
  }
12774
12774
  function buildKey(opts) {
12775
- const { path: path18, method, body, headers, query } = opts;
12775
+ const { path: path17, method, body, headers, query } = opts;
12776
12776
  return {
12777
- path: path18,
12777
+ path: path17,
12778
12778
  method,
12779
12779
  body,
12780
12780
  headers,
@@ -13464,10 +13464,10 @@ var require_pending_interceptors_formatter = __commonJS({
13464
13464
  }
13465
13465
  format(pendingInterceptors) {
13466
13466
  const withPrettyHeaders = pendingInterceptors.map(
13467
- ({ method, path: path18, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
13467
+ ({ method, path: path17, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
13468
13468
  Method: method,
13469
13469
  Origin: origin,
13470
- Path: path18,
13470
+ Path: path17,
13471
13471
  "Status code": statusCode,
13472
13472
  Persistent: persist ? PERSISTENT : NOT_PERSISTENT,
13473
13473
  Invocations: timesInvoked,
@@ -13549,9 +13549,9 @@ var require_mock_agent = __commonJS({
13549
13549
  const acceptNonStandardSearchParameters = this[kMockAgentAcceptsNonStandardSearchParameters];
13550
13550
  const dispatchOpts = { ...opts };
13551
13551
  if (acceptNonStandardSearchParameters && dispatchOpts.path) {
13552
- const [path18, searchParams] = dispatchOpts.path.split("?");
13552
+ const [path17, searchParams] = dispatchOpts.path.split("?");
13553
13553
  const normalizedSearchParams = normalizeSearchParams(searchParams, acceptNonStandardSearchParameters);
13554
- dispatchOpts.path = `${path18}?${normalizedSearchParams}`;
13554
+ dispatchOpts.path = `${path17}?${normalizedSearchParams}`;
13555
13555
  }
13556
13556
  return this[kAgent].dispatch(dispatchOpts, handler);
13557
13557
  }
@@ -13952,12 +13952,12 @@ var require_snapshot_recorder = __commonJS({
13952
13952
  * @return {Promise<void>} - Resolves when snapshots are loaded
13953
13953
  */
13954
13954
  async loadSnapshots(filePath) {
13955
- const path18 = filePath || this.#snapshotPath;
13956
- if (!path18) {
13955
+ const path17 = filePath || this.#snapshotPath;
13956
+ if (!path17) {
13957
13957
  throw new InvalidArgumentError("Snapshot path is required");
13958
13958
  }
13959
13959
  try {
13960
- const data = await readFile3(resolve(path18), "utf8");
13960
+ const data = await readFile3(resolve(path17), "utf8");
13961
13961
  const parsed = JSON.parse(data);
13962
13962
  if (Array.isArray(parsed)) {
13963
13963
  this.#snapshots.clear();
@@ -13971,7 +13971,7 @@ var require_snapshot_recorder = __commonJS({
13971
13971
  if (error.code === "ENOENT") {
13972
13972
  this.#snapshots.clear();
13973
13973
  } else {
13974
- throw new UndiciError(`Failed to load snapshots from ${path18}`, { cause: error });
13974
+ throw new UndiciError(`Failed to load snapshots from ${path17}`, { cause: error });
13975
13975
  }
13976
13976
  }
13977
13977
  }
@@ -13982,11 +13982,11 @@ var require_snapshot_recorder = __commonJS({
13982
13982
  * @returns {Promise<void>} - Resolves when snapshots are saved
13983
13983
  */
13984
13984
  async saveSnapshots(filePath) {
13985
- const path18 = filePath || this.#snapshotPath;
13986
- if (!path18) {
13985
+ const path17 = filePath || this.#snapshotPath;
13986
+ if (!path17) {
13987
13987
  throw new InvalidArgumentError("Snapshot path is required");
13988
13988
  }
13989
- const resolvedPath = resolve(path18);
13989
+ const resolvedPath = resolve(path17);
13990
13990
  await mkdir3(dirname5(resolvedPath), { recursive: true });
13991
13991
  const data = Array.from(this.#snapshots.entries()).map(([hash, snapshot]) => ({
13992
13992
  hash,
@@ -14618,15 +14618,15 @@ var require_redirect_handler = __commonJS({
14618
14618
  return;
14619
14619
  }
14620
14620
  const { origin, pathname, search } = util.parseURL(new URL(this.location, this.opts.origin && new URL(this.opts.path, this.opts.origin)));
14621
- const path18 = search ? `${pathname}${search}` : pathname;
14622
- const redirectUrlString = `${origin}${path18}`;
14621
+ const path17 = search ? `${pathname}${search}` : pathname;
14622
+ const redirectUrlString = `${origin}${path17}`;
14623
14623
  for (const historyUrl of this.history) {
14624
14624
  if (historyUrl.toString() === redirectUrlString) {
14625
14625
  throw new InvalidArgumentError(`Redirect loop detected. Cannot redirect to ${origin}. This typically happens when using a Client or Pool with cross-origin redirects. Use an Agent for cross-origin redirects.`);
14626
14626
  }
14627
14627
  }
14628
14628
  this.opts.headers = cleanRequestHeaders(this.opts.headers, statusCode === 303, this.opts.origin !== origin);
14629
- this.opts.path = path18;
14629
+ this.opts.path = path17;
14630
14630
  this.opts.origin = origin;
14631
14631
  this.opts.query = null;
14632
14632
  }
@@ -16395,10 +16395,10 @@ var require_cache_handler = __commonJS({
16395
16395
  }
16396
16396
  return locationUrl.pathname + locationUrl.search;
16397
16397
  }
16398
- function deleteCachedUri(store, cacheKey, path18) {
16398
+ function deleteCachedUri(store, cacheKey, path17) {
16399
16399
  deleteCachedValue(store, {
16400
16400
  ...cacheKey,
16401
- path: path18
16401
+ path: path17
16402
16402
  });
16403
16403
  for (let i = 0; i < util.safeHTTPMethods.length; i++) {
16404
16404
  const method = util.safeHTTPMethods[i];
@@ -16406,7 +16406,7 @@ var require_cache_handler = __commonJS({
16406
16406
  deleteCachedValue(store, {
16407
16407
  ...cacheKey,
16408
16408
  method,
16409
- path: path18
16409
+ path: path17
16410
16410
  });
16411
16411
  }
16412
16412
  }
@@ -16417,9 +16417,9 @@ var require_cache_handler = __commonJS({
16417
16417
  }
16418
16418
  const values = Array.isArray(headerValue3) ? headerValue3 : [headerValue3];
16419
16419
  for (let i = 0; i < values.length; i++) {
16420
- const path18 = getSameOriginPath(cacheKey, values[i]);
16421
- if (path18 !== void 0) {
16422
- deleteCachedUri(store, cacheKey, path18);
16420
+ const path17 = getSameOriginPath(cacheKey, values[i]);
16421
+ if (path17 !== void 0) {
16422
+ deleteCachedUri(store, cacheKey, path17);
16423
16423
  }
16424
16424
  }
16425
16425
  }
@@ -21297,11 +21297,11 @@ var require_fetch = __commonJS({
21297
21297
  function dispatch({ body }) {
21298
21298
  const url = requestCurrentURL(request);
21299
21299
  const agent = fetchParams.controller.dispatcher;
21300
- const path18 = url.pathname + url.search;
21300
+ const path17 = url.pathname + url.search;
21301
21301
  const hasTrailingQuestionMark = url.search.length === 0 && url.href[url.href.length - url.hash.length - 1] === "?";
21302
21302
  return new Promise((resolve, reject) => agent.dispatch(
21303
21303
  {
21304
- path: hasTrailingQuestionMark ? `${path18}?` : path18,
21304
+ path: hasTrailingQuestionMark ? `${path17}?` : path17,
21305
21305
  origin: url.origin,
21306
21306
  method: request.method,
21307
21307
  body: agent.isMockActive ? request.body && (request.body.source || request.body.stream) : body,
@@ -22248,9 +22248,9 @@ var require_util4 = __commonJS({
22248
22248
  }
22249
22249
  }
22250
22250
  }
22251
- function validateCookiePath(path18) {
22252
- for (let i = 0; i < path18.length; ++i) {
22253
- const code = path18.charCodeAt(i);
22251
+ function validateCookiePath(path17) {
22252
+ for (let i = 0; i < path17.length; ++i) {
22253
+ const code = path17.charCodeAt(i);
22254
22254
  if (code < 32 || // exclude CTLs (0-31)
22255
22255
  code > 126 || // exclude DEL and non-ascii
22256
22256
  code === 59) {
@@ -25487,11 +25487,11 @@ var require_undici = __commonJS({
25487
25487
  if (typeof opts.path !== "string") {
25488
25488
  throw new InvalidArgumentError("invalid opts.path");
25489
25489
  }
25490
- let path18 = opts.path;
25490
+ let path17 = opts.path;
25491
25491
  if (!opts.path.startsWith("/")) {
25492
- path18 = `/${path18}`;
25492
+ path17 = `/${path17}`;
25493
25493
  }
25494
- url = new URL(util.parseOrigin(url).origin + path18);
25494
+ url = new URL(util.parseOrigin(url).origin + path17);
25495
25495
  } else {
25496
25496
  if (!opts) {
25497
25497
  opts = typeof url === "object" ? url : {};
@@ -47619,13 +47619,13 @@ function getUpstreamConnectionStatus() {
47619
47619
  }
47620
47620
 
47621
47621
  // src/config.ts
47622
- function safeReadJson(path18) {
47622
+ function safeReadJson(path17) {
47623
47623
  try {
47624
- const raw = readFileSync(path18, "utf8").replace(/^\uFEFF/, "");
47624
+ const raw = readFileSync(path17, "utf8").replace(/^\uFEFF/, "");
47625
47625
  return JSON.parse(raw);
47626
47626
  } catch (e) {
47627
47627
  if (e.code !== "ENOENT") {
47628
- log("error", `[acp-config] failed to parse ${path18}: ${String(e)}`);
47628
+ log("error", `[acp-config] failed to parse ${path17}: ${String(e)}`);
47629
47629
  }
47630
47630
  return void 0;
47631
47631
  }
@@ -49748,17 +49748,14 @@ function relPathFor(id, protocol, upstreamOrigin) {
49748
49748
  }
49749
49749
  var SessionStore = class {
49750
49750
  enabled;
49751
- get dir() {
49752
- return this.root;
49753
- }
49754
- root;
49751
+ dir;
49755
49752
  store;
49756
49753
  constructor(opts) {
49757
49754
  const debounceMs = opts?.debounceMs ?? defaultDebounce();
49758
49755
  this.enabled = (opts?.enabled ?? true) && debounceMs >= 0;
49759
- this.root = opts?.dir ?? defaultDir();
49756
+ this.dir = opts?.dir ?? defaultDir();
49760
49757
  this.store = new StateStore({
49761
- dir: this.root,
49758
+ dir: this.dir,
49762
49759
  version: PERSIST_VERSION,
49763
49760
  debounceMs: Math.max(0, debounceMs),
49764
49761
  enabled: this.enabled,
@@ -49782,67 +49779,55 @@ var SessionStore = class {
49782
49779
  }
49783
49780
  return out;
49784
49781
  }
49785
- /** Startup load: ONE directory walk + parse (previously #286's
49786
- * migrateLegacyIds ran its own loadAll before initSessions' second
49787
- * loadAll — two full walks per boot, #407), with the legacy-id rekey
49788
- * applied in-memory on the same data. The #286 migration: sessions
49789
- * persisted under the old derived hash id are re-keyed to the
49790
- * client-provided conversation value stored in meta.label (which is now
49791
- * the session id itself). Collisions on the same label keep the most
49792
- * recently saved record; the losers, and any label already claimed by a
49793
- * new-format session, are deleted. Records without a label cannot be
49794
- * mapped and are left in place (they load under their old id but are
49795
- * never requested again — the new proxy 400s anonymous requests).
49796
- * Self-terminating: after one pass no loaded id differs from its label,
49797
- * so the log fires exactly once ever instead of on every boot. */
49798
- async loadAllMigrated() {
49799
- const out = /* @__PURE__ */ new Map();
49800
- if (!this.enabled) return out;
49782
+ /** One-time migration for the #286 identity change: sessions persisted
49783
+ * under the old derived hash id are re-keyed to the client-provided
49784
+ * conversation value stored in meta.label (which is now the session id
49785
+ * itself). Collisions on the same label keep the most recently saved
49786
+ * record; the losers, and any label already claimed by a new-format
49787
+ * session, are deleted. Records without a label cannot be mapped and are
49788
+ * left in place (they load under their old id but are never requested
49789
+ * again — the new proxy 400s anonymous requests). Self-terminating:
49790
+ * after one pass no loaded id differs from its label. */
49791
+ async migrateLegacyIds() {
49792
+ if (!this.enabled) return;
49801
49793
  const loaded = await this.store.loadAll();
49802
49794
  const claimed = /* @__PURE__ */ new Set();
49803
49795
  const byLabel = /* @__PURE__ */ new Map();
49804
- const dropped = /* @__PURE__ */ new Set();
49796
+ let unlabeled = 0;
49805
49797
  for (const [id, envelope] of loaded) {
49806
49798
  const session = buildSession(envelope.payload);
49807
- out.set(id, session);
49808
49799
  const label = session.meta.label;
49809
- if (!label) continue;
49800
+ if (!label) {
49801
+ unlabeled++;
49802
+ continue;
49803
+ }
49810
49804
  if (label === id) {
49811
49805
  claimed.add(id);
49812
49806
  continue;
49813
49807
  }
49814
49808
  const prev = byLabel.get(label);
49815
49809
  if (!prev || envelope.savedAt >= prev.savedAt) {
49816
- if (prev) {
49817
- await this.removeLegacyFile(prev.id, prev.session);
49818
- dropped.add(prev.id);
49819
- }
49810
+ if (prev) await this.removeLegacyFile(prev.id, prev.session);
49820
49811
  byLabel.set(label, { id, savedAt: envelope.savedAt, session });
49821
49812
  } else {
49822
49813
  await this.removeLegacyFile(id, session);
49823
- dropped.add(id);
49824
49814
  }
49825
49815
  }
49826
49816
  let rekeyed = 0;
49827
49817
  for (const [label, { id, session }] of byLabel) {
49828
49818
  if (claimed.has(label)) {
49829
49819
  await this.removeLegacyFile(id, session);
49830
- dropped.add(id);
49831
49820
  continue;
49832
49821
  }
49833
49822
  session.id = label;
49834
49823
  await this.store.writeNow(label, () => buildRecord(session));
49835
49824
  await this.removeLegacyFile(id, session);
49836
- out.delete(id);
49837
- out.set(label, session);
49838
49825
  claimed.add(label);
49839
49826
  rekeyed++;
49840
49827
  }
49841
- for (const id of dropped) out.delete(id);
49842
- if (rekeyed > 0) {
49843
- log("info", `[persist] migration (#286): rekeyed ${rekeyed} legacy session(s)`);
49828
+ if (rekeyed || unlabeled) {
49829
+ log("info", `[persist] one-time migration (#286): rekeyed ${rekeyed} legacy session(s), left ${unlabeled} unlabeled legacy file(s) in place`);
49844
49830
  }
49845
- return out;
49846
49831
  }
49847
49832
  /** Remove a legacy session file. The kernel store never deletes (cleanup
49848
49833
  * is downstream policy), so the path is recomputed here: the namespaced
@@ -49921,24 +49906,14 @@ function buildRecord(session) {
49921
49906
  messages: session.lastMessages,
49922
49907
  metadata: { ...session.metadata },
49923
49908
  state: session.state,
49924
- blockContents: serializeBlockContents(session.blockContents),
49909
+ blockContents: Object.fromEntries(session.blockContents),
49925
49910
  createdAt: session.createdAt
49926
49911
  };
49927
49912
  }
49928
- function serializeBlockContents(map) {
49929
- const out = {};
49930
- for (const [bid, c] of map) {
49931
- out[bid] = c.one.text === c.full.text && c.one.count === c.full.count ? { full: c.full } : c;
49932
- }
49933
- return out;
49934
- }
49935
49913
  function buildSession(parsed) {
49936
49914
  const blockContents = /* @__PURE__ */ new Map();
49937
49915
  for (const [bid, content] of Object.entries(parsed.blockContents ?? {})) {
49938
- if (!content || typeof content !== "object" || typeof content.full?.text !== "string") continue;
49939
- const full = { text: content.full.text, count: content.full.count ?? 0 };
49940
- const one = content.one && typeof content.one.text === "string" ? { text: content.one.text, count: content.one.count ?? 0 } : { ...full };
49941
- blockContents.set(bid, { one, full });
49916
+ if (content && typeof content === "object") blockContents.set(bid, content);
49942
49917
  }
49943
49918
  const meta = parsed.meta ?? {};
49944
49919
  const stats = parsed.stats ?? {};
@@ -50004,109 +49979,6 @@ function getStore() {
50004
49979
  return _store;
50005
49980
  }
50006
49981
 
50007
- // src/session-gc.ts
50008
- import { readdirSync, rmSync, statSync as statSync3 } from "fs";
50009
- import * as path6 from "path";
50010
- var DAY_MS = 864e5;
50011
- var DEFAULT_RETENTION_DAYS = 90;
50012
- var DEFAULT_MAX_BYTES = 1024 * 1024 * 1024;
50013
- function gcOptionsFromEnv() {
50014
- const days = intEnv("BILI_SESSION_RETENTION_DAYS", DEFAULT_RETENTION_DAYS);
50015
- const maxBytes = intEnv("BILI_SESSION_MAX_BYTES", DEFAULT_MAX_BYTES);
50016
- return { retentionMs: Math.max(0, days) * DAY_MS, maxBytes: Math.max(0, maxBytes) };
50017
- }
50018
- function intEnv(name, fallback) {
50019
- const v2 = process.env[name];
50020
- if (!v2) return fallback;
50021
- const n = Number.parseInt(v2, 10);
50022
- return Number.isFinite(n) ? n : fallback;
50023
- }
50024
- function collectUnits(dir) {
50025
- const units = /* @__PURE__ */ new Map();
50026
- const walk = (d) => {
50027
- let entries;
50028
- try {
50029
- entries = readdirSync(d, { withFileTypes: true });
50030
- } catch {
50031
- return;
50032
- }
50033
- for (const e of entries) {
50034
- if (!e.isFile()) {
50035
- if (e.isDirectory()) walk(path6.join(d, e.name));
50036
- continue;
50037
- }
50038
- if (!e.name.endsWith(".json") || e.name.startsWith(".tmp-")) continue;
50039
- const abs = path6.join(d, e.name);
50040
- let st2;
50041
- try {
50042
- st2 = statSync3(abs);
50043
- } catch {
50044
- continue;
50045
- }
50046
- const rel2 = path6.relative(dir, abs);
50047
- const key = e.name.endsWith(".fb.json") ? `${rel2.slice(0, -".fb.json".length)}.json` : rel2;
50048
- const u2 = units.get(key);
50049
- if (u2) {
50050
- u2.files.push(abs);
50051
- u2.size += st2.size;
50052
- u2.mtimeMs = Math.max(u2.mtimeMs, st2.mtimeMs);
50053
- } else {
50054
- units.set(key, { files: [abs], size: st2.size, mtimeMs: st2.mtimeMs });
50055
- }
50056
- }
50057
- };
50058
- walk(dir);
50059
- return [...units.values()];
50060
- }
50061
- function gcSessionFiles(dir, opts) {
50062
- let units;
50063
- try {
50064
- units = collectUnits(dir);
50065
- } catch {
50066
- return null;
50067
- }
50068
- if (units.length === 0) return null;
50069
- const result = { scannedFiles: 0, scannedBytes: 0, deletedUnits: 0, deletedFiles: 0, bytesFreed: 0, remainingBytes: 0 };
50070
- for (const u2 of units) {
50071
- result.scannedFiles += u2.files.length;
50072
- result.scannedBytes += u2.size;
50073
- }
50074
- const deleted = /* @__PURE__ */ new Set();
50075
- const deleteUnit = (u2) => {
50076
- for (const f2 of u2.files) rmSync(f2, { force: true });
50077
- deleted.add(u2);
50078
- result.deletedUnits++;
50079
- result.deletedFiles += u2.files.length;
50080
- result.bytesFreed += u2.size;
50081
- };
50082
- if (opts.retentionMs > 0) {
50083
- const cutoff = (opts.nowMs ?? Date.now()) - opts.retentionMs;
50084
- for (const u2 of units) if (u2.mtimeMs < cutoff) deleteUnit(u2);
50085
- }
50086
- if (opts.maxBytes > 0) {
50087
- let total = 0;
50088
- for (const u2 of units) if (!deleted.has(u2)) total += u2.size;
50089
- if (total > opts.maxBytes) {
50090
- const sorted = units.filter((u2) => !deleted.has(u2)).sort((a, b2) => a.mtimeMs - b2.mtimeMs);
50091
- for (const u2 of sorted) {
50092
- if (total <= opts.maxBytes) break;
50093
- deleteUnit(u2);
50094
- total -= u2.size;
50095
- }
50096
- }
50097
- }
50098
- result.remainingBytes = result.scannedBytes - result.bytesFreed;
50099
- if (result.deletedFiles > 0) {
50100
- log("info", `[gc] sessions dir: removed ${result.deletedUnits} old session record(s), freed ${fmtBytes(result.bytesFreed)}, ${fmtBytes(result.remainingBytes)} remaining`);
50101
- }
50102
- return result;
50103
- }
50104
- function fmtBytes(n) {
50105
- if (n >= 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)}MB`;
50106
- if (n >= 1024) return `${(n / 1024).toFixed(1)}KB`;
50107
- return `${n}B`;
50108
- }
50109
-
50110
49982
  // src/session.ts
50111
49983
  function lastCompressSuffix(info) {
50112
49984
  if (!info) return "";
@@ -50120,8 +49992,8 @@ async function initSessions() {
50120
49992
  initialized = true;
50121
49993
  const store = getStore();
50122
49994
  if (!store.enabled) return;
50123
- gcSessionFiles(store.dir, gcOptionsFromEnv());
50124
- const loaded = await store.loadAllMigrated();
49995
+ await store.migrateLegacyIds();
49996
+ const loaded = await store.loadAll();
50125
49997
  if (loaded.size > MAX_SESSIONS) {
50126
49998
  const entries = [...loaded.entries()].sort((a, b2) => (b2[1].createdAt ?? 0) - (a[1].createdAt ?? 0));
50127
49999
  for (const [id, s3] of entries) {
@@ -50203,12 +50075,7 @@ function markDirty(session) {
50203
50075
  getStore().scheduleSave(session);
50204
50076
  }
50205
50077
  function cacheBlockContent(session, blockId, content) {
50206
- if (content.one.text === content.full.text && content.one.count === content.full.count) {
50207
- const view = { text: content.full.text, count: content.full.count };
50208
- session.blockContents.set(blockId, { one: view, full: view });
50209
- } else {
50210
- session.blockContents.set(blockId, content);
50211
- }
50078
+ session.blockContents.set(blockId, content);
50212
50079
  }
50213
50080
  function resetSessionCompression(session) {
50214
50081
  session.state = createInitialState();
@@ -50278,7 +50145,7 @@ function withStagedCompressGuidance(text) {
50278
50145
 
50279
50146
  // src/decompress-shared.ts
50280
50147
  import { mkdirSync as mkdirSync3, unlinkSync, writeFileSync as writeFileSync2 } from "fs";
50281
- import { dirname as dirname2, join as join3 } from "path";
50148
+ import { dirname as dirname2, join as join2 } from "path";
50282
50149
  import { tmpdir } from "os";
50283
50150
  var trackedTempFiles = [];
50284
50151
  function getDecompressTmpCap() {
@@ -50330,7 +50197,7 @@ function resolveDecompress(args, ctx) {
50330
50197
  }
50331
50198
  const header = `[Block ${blockId} content \u2014 ${count} item(s)${full ? ", full" : ""}]`;
50332
50199
  const safeBlockId = blockId.replace(/[^a-zA-Z0-9_-]/g, "-");
50333
- const outPath = body.length > 1e4 ? join3(tmpdir(), `acp-decompress-${safeBlockId}-${Date.now()}.txt`) : null;
50200
+ const outPath = body.length > 1e4 ? join2(tmpdir(), `acp-decompress-${safeBlockId}-${Date.now()}.txt`) : null;
50334
50201
  if (outPath) {
50335
50202
  try {
50336
50203
  mkdirSync3(dirname2(outPath), { recursive: true });
@@ -50937,7 +50804,7 @@ async function preflightCompress(deps, messages) {
50937
50804
 
50938
50805
  // src/web/index.ts
50939
50806
  import { readFileSync as readFileSync3 } from "fs";
50940
- import { dirname as dirname4, join as join4 } from "path";
50807
+ import { dirname as dirname4, join as join3 } from "path";
50941
50808
  import { fileURLToPath } from "url";
50942
50809
 
50943
50810
  // src/web/page.ts
@@ -50946,7 +50813,7 @@ import { existsSync as existsSync3 } from "fs";
50946
50813
  // src/ca.ts
50947
50814
  var import_node_forge = __toESM(require_lib(), 1);
50948
50815
  import fs2 from "fs";
50949
- import path7 from "path";
50816
+ import path6 from "path";
50950
50817
  import tls2 from "tls";
50951
50818
  var ROOT_CERT_FILE = "root-ca.pem";
50952
50819
  var ROOT_KEY_FILE = "root-ca-key.pem";
@@ -50966,7 +50833,7 @@ var rootKey;
50966
50833
  var secureContextCache = /* @__PURE__ */ new Map();
50967
50834
  var SECURE_CONTEXT_CACHE_MAX = 64;
50968
50835
  function rootCaPath() {
50969
- return path7.join(caDir(), ROOT_CERT_FILE);
50836
+ return path6.join(caDir(), ROOT_CERT_FILE);
50970
50837
  }
50971
50838
  function collectSystemCaPems(env = process.env) {
50972
50839
  const pems = [];
@@ -50995,7 +50862,7 @@ function writeCombinedBundle() {
50995
50862
  for (const pem of tls2.rootCertificates) certs.add(pem.trim());
50996
50863
  certs.add(rootCertPem.trim());
50997
50864
  const body = [...certs].map((pem) => pem.endsWith("\n") ? pem : pem + "\n").join("");
50998
- fs2.writeFileSync(path7.join(caDir(), COMBINED_CA_FILE), body, { mode: 420 });
50865
+ fs2.writeFileSync(path6.join(caDir(), COMBINED_CA_FILE), body, { mode: 420 });
50999
50866
  }
51000
50867
  function generateRootCA() {
51001
50868
  const keys = import_node_forge.default.pki.rsa.generateKeyPair({ bits: 2048 });
@@ -51029,8 +50896,8 @@ function ensureRootCA() {
51029
50896
  }
51030
50897
  const dir = caDir();
51031
50898
  fs2.mkdirSync(dir, { recursive: true });
51032
- const certPath = path7.join(dir, ROOT_CERT_FILE);
51033
- const keyPath = path7.join(dir, ROOT_KEY_FILE);
50899
+ const certPath = path6.join(dir, ROOT_CERT_FILE);
50900
+ const keyPath = path6.join(dir, ROOT_KEY_FILE);
51034
50901
  if (fs2.existsSync(certPath) && fs2.existsSync(keyPath)) {
51035
50902
  rootCertPem = fs2.readFileSync(certPath, "utf8");
51036
50903
  rootKeyPem = fs2.readFileSync(keyPath, "utf8");
@@ -51318,7 +51185,7 @@ function readJsonBody(req) {
51318
51185
  function version() {
51319
51186
  try {
51320
51187
  const here = fileURLToPath(import.meta.url);
51321
- const packagePath = join4(dirname4(here), "..", "..", "package.json");
51188
+ const packagePath = join3(dirname4(here), "..", "..", "package.json");
51322
51189
  return JSON.parse(readFileSync3(packagePath, "utf8")).version ?? "dev";
51323
51190
  } catch {
51324
51191
  return "dev";
@@ -51357,7 +51224,7 @@ function reapOrphanBlocks(session, visible, deactivate) {
51357
51224
  // src/instance.ts
51358
51225
  import { randomUUID as randomUUID3 } from "crypto";
51359
51226
  import fs3 from "fs";
51360
- import path8 from "path";
51227
+ import path7 from "path";
51361
51228
  function isProxyInstanceFile(v2) {
51362
51229
  return v2 !== void 0 && "instanceId" in v2;
51363
51230
  }
@@ -51399,11 +51266,11 @@ function readProxyInstanceFile(file) {
51399
51266
  return void 0;
51400
51267
  }
51401
51268
  function instanceFilePath() {
51402
- return path8.join(stateDir(), "proxy-origin");
51269
+ return path7.join(stateDir(), "proxy-origin");
51403
51270
  }
51404
51271
  function atomicWriteInstanceFile(info, file) {
51405
51272
  const filePath = file ?? instanceFilePath();
51406
- fs3.mkdirSync(path8.dirname(filePath), { recursive: true });
51273
+ fs3.mkdirSync(path7.dirname(filePath), { recursive: true });
51407
51274
  const tempPath = `${filePath}.${process.pid}.${randomUUID3()}.tmp`;
51408
51275
  let descriptor;
51409
51276
  try {
@@ -51447,7 +51314,7 @@ function isPidAlive(pid) {
51447
51314
  }
51448
51315
  }
51449
51316
  function registryFilePath() {
51450
- return path8.join(stateDir(), "instances.json");
51317
+ return path7.join(stateDir(), "instances.json");
51451
51318
  }
51452
51319
  function registerInstanceAndWarn(entry, warn) {
51453
51320
  const file = registryFilePath();
@@ -51470,7 +51337,7 @@ function registerInstanceAndWarn(entry, warn) {
51470
51337
  }
51471
51338
  entries.push(entry);
51472
51339
  try {
51473
- fs3.mkdirSync(path8.dirname(file), { recursive: true });
51340
+ fs3.mkdirSync(path7.dirname(file), { recursive: true });
51474
51341
  fs3.writeFileSync(file, JSON.stringify({ instances: entries }) + "\n");
51475
51342
  } catch {
51476
51343
  }
@@ -54190,7 +54057,7 @@ function buildStatusPanel(input) {
54190
54057
  // src/plugin.ts
54191
54058
  import { fileURLToPath as fileURLToPath2 } from "url";
54192
54059
  import fs4 from "fs";
54193
- import path9 from "path";
54060
+ import path8 from "path";
54194
54061
 
54195
54062
  // src/sse-util.ts
54196
54063
  function normalizeSseLineEndings(buf) {
@@ -54202,7 +54069,7 @@ function normalizeSseLineEndings(buf) {
54202
54069
  var PROXY_VERSION = (() => {
54203
54070
  try {
54204
54071
  const here = fileURLToPath2(import.meta.url);
54205
- const pkg = path9.join(path9.dirname(here), "..", "package.json");
54072
+ const pkg = path8.join(path8.dirname(here), "..", "package.json");
54206
54073
  return JSON.parse(fs4.readFileSync(pkg, "utf8")).version ?? "dev";
54207
54074
  } catch {
54208
54075
  return "dev";
@@ -54215,7 +54082,7 @@ var PLUGIN_PROTOCOL_VERSION = 1;
54215
54082
  var VERSION = (() => {
54216
54083
  try {
54217
54084
  const here = fileURLToPath2(import.meta.url);
54218
- const pkg = path9.join(path9.dirname(here), "..", "package.json");
54085
+ const pkg = path8.join(path8.dirname(here), "..", "package.json");
54219
54086
  return JSON.parse(fs4.readFileSync(pkg, "utf8")).version ?? "dev";
54220
54087
  } catch {
54221
54088
  return "dev";
@@ -54245,7 +54112,7 @@ function pluginReportedContextWindow(headers) {
54245
54112
  var MAX_PLUGIN_CONVERSATIONS = 1024;
54246
54113
  var conversations = /* @__PURE__ */ new Map();
54247
54114
  var remembered = /* @__PURE__ */ new Map();
54248
- var conversationsFile = () => path9.join(stateDir(), "plugin-conversations.json");
54115
+ var conversationsFile = () => path8.join(stateDir(), "plugin-conversations.json");
54249
54116
  var conversationsSaveTimer;
54250
54117
  var conversationsDirty = false;
54251
54118
  function writeConversationsFile() {
@@ -54889,12 +54756,12 @@ import tls3 from "tls";
54889
54756
  // src/discover.ts
54890
54757
  import fs6 from "fs";
54891
54758
  import os2 from "os";
54892
- import path11 from "path";
54759
+ import path10 from "path";
54893
54760
 
54894
54761
  // src/client-config.ts
54895
54762
  import fs5 from "fs";
54896
54763
  import os from "os";
54897
- import path10 from "path";
54764
+ import path9 from "path";
54898
54765
  function toModelWindow(id, contextWindow) {
54899
54766
  return typeof id === "string" && id.length > 0 && typeof contextWindow === "number" && Number.isFinite(contextWindow) && contextWindow > 0 ? { id, contextWindow: Math.floor(contextWindow) } : null;
54900
54767
  }
@@ -54912,19 +54779,19 @@ function readJsonObject(filePath) {
54912
54779
  }
54913
54780
  function resolvePiHome(env) {
54914
54781
  const h = os.homedir();
54915
- return nonEmpty2(env.PI_CODING_AGENT_DIR) ? env.PI_CODING_AGENT_DIR : nonEmpty2(env.PI_HOME) ? env.PI_HOME : path10.join(h, ".pi", "agent");
54782
+ return nonEmpty2(env.PI_CODING_AGENT_DIR) ? env.PI_CODING_AGENT_DIR : nonEmpty2(env.PI_HOME) ? env.PI_HOME : path9.join(h, ".pi", "agent");
54916
54783
  }
54917
54784
  function resolveOmpHome(env) {
54918
54785
  const h = os.homedir();
54919
- return nonEmpty2(env.PI_CODING_AGENT_DIR) ? env.PI_CODING_AGENT_DIR : path10.join(h, ".omp", "agent");
54786
+ return nonEmpty2(env.PI_CODING_AGENT_DIR) ? env.PI_CODING_AGENT_DIR : path9.join(h, ".omp", "agent");
54920
54787
  }
54921
54788
  function resolveHermesHome(env) {
54922
54789
  const h = os.homedir();
54923
- return nonEmpty2(env.HERMES_HOME) ? env.HERMES_HOME : path10.join(h, ".hermes");
54790
+ return nonEmpty2(env.HERMES_HOME) ? env.HERMES_HOME : path9.join(h, ".hermes");
54924
54791
  }
54925
54792
  function resolveDshHome(env) {
54926
54793
  const h = os.homedir();
54927
- return nonEmpty2(env.DSH_HOME) ? env.DSH_HOME : path10.join(h, ".dsh");
54794
+ return nonEmpty2(env.DSH_HOME) ? env.DSH_HOME : path9.join(h, ".dsh");
54928
54795
  }
54929
54796
  function parseDshSettingsYaml(text) {
54930
54797
  const out = [];
@@ -54943,7 +54810,7 @@ function parseDshSettingsYaml(text) {
54943
54810
  function readDshConfig(dshHome) {
54944
54811
  let text;
54945
54812
  try {
54946
- text = fs5.readFileSync(path10.join(dshHome, "settings.yaml"), "utf8");
54813
+ text = fs5.readFileSync(path9.join(dshHome, "settings.yaml"), "utf8");
54947
54814
  } catch {
54948
54815
  return { baseUrls: [] };
54949
54816
  }
@@ -54951,8 +54818,8 @@ function readDshConfig(dshHome) {
54951
54818
  }
54952
54819
  function readClaudeSettings(homeDir, cwd, env = process.env) {
54953
54820
  const files = [
54954
- path10.join(homeDir, ".claude", "settings.json"),
54955
- path10.join(cwd, ".claude", "settings.json")
54821
+ path9.join(homeDir, ".claude", "settings.json"),
54822
+ path9.join(cwd, ".claude", "settings.json")
54956
54823
  ];
54957
54824
  let anthropicBaseUrl;
54958
54825
  let model;
@@ -55025,7 +54892,7 @@ function parseCodexToml(text) {
55025
54892
  return result;
55026
54893
  }
55027
54894
  function readCodexConfig(codexHome) {
55028
- const cfgPath = path10.join(codexHome, "config.toml");
54895
+ const cfgPath = path9.join(codexHome, "config.toml");
55029
54896
  let text;
55030
54897
  try {
55031
54898
  text = fs5.readFileSync(cfgPath, "utf8");
@@ -55035,7 +54902,7 @@ function readCodexConfig(codexHome) {
55035
54902
  return parseCodexToml(text);
55036
54903
  }
55037
54904
  function readPiConfig(piHome) {
55038
- const cfgPath = path10.join(piHome, "models.json");
54905
+ const cfgPath = path9.join(piHome, "models.json");
55039
54906
  const obj = readJsonObject(cfgPath);
55040
54907
  const providers = {};
55041
54908
  const rawProviders = obj?.providers;
@@ -55116,7 +54983,7 @@ function parseOmpYaml(text) {
55116
54983
  return result;
55117
54984
  }
55118
54985
  function readOmpConfig(ompHome) {
55119
- const cfgPath = path10.join(ompHome, "models.yml");
54986
+ const cfgPath = path9.join(ompHome, "models.yml");
55120
54987
  let text;
55121
54988
  try {
55122
54989
  text = fs5.readFileSync(cfgPath, "utf8");
@@ -55192,7 +55059,7 @@ function parseHermesYaml(text) {
55192
55059
  return result;
55193
55060
  }
55194
55061
  function readHermesConfig(hermesHome) {
55195
- const cfgPath = path10.join(hermesHome, "config.yaml");
55062
+ const cfgPath = path9.join(hermesHome, "config.yaml");
55196
55063
  let text;
55197
55064
  try {
55198
55065
  text = fs5.readFileSync(cfgPath, "utf8");
@@ -55203,8 +55070,8 @@ function readHermesConfig(hermesHome) {
55203
55070
  }
55204
55071
  function resolveOpencodeConfigFile(env) {
55205
55072
  if (nonEmpty2(env.OPENCODE_CONFIG)) return env.OPENCODE_CONFIG;
55206
- const xdg2 = nonEmpty2(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME : path10.join(os.homedir(), ".config");
55207
- return path10.join(xdg2, "opencode", "opencode.json");
55073
+ const xdg2 = nonEmpty2(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME : path9.join(os.homedir(), ".config");
55074
+ return path9.join(xdg2, "opencode", "opencode.json");
55208
55075
  }
55209
55076
  function readOpencodeConfig(file) {
55210
55077
  let text;
@@ -55266,7 +55133,7 @@ function parseZcodeConfig(obj) {
55266
55133
  return result;
55267
55134
  }
55268
55135
  function readZcodeConfig(zcodeHome) {
55269
- const cfgPath = path10.join(zcodeHome, "v2", "config.json");
55136
+ const cfgPath = path9.join(zcodeHome, "v2", "config.json");
55270
55137
  let txt;
55271
55138
  try {
55272
55139
  txt = fs5.readFileSync(cfgPath, "utf8");
@@ -55285,10 +55152,10 @@ function loadClientConfig(env, cwd) {
55285
55152
  const home = os.homedir();
55286
55153
  const config = {};
55287
55154
  config.claude = readClaudeSettings(home, cwd, env);
55288
- const codexHome = nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME : path10.join(home, ".codex");
55155
+ const codexHome = nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME : path9.join(home, ".codex");
55289
55156
  config.codex = readCodexConfig(codexHome);
55290
55157
  config.pi = readPiConfig(resolvePiHome(env));
55291
- const zcodeHome = nonEmpty2(env.ZCODE_DATA_BASE_DIR) ? env.ZCODE_DATA_BASE_DIR : path10.join(home, ".zcode");
55158
+ const zcodeHome = nonEmpty2(env.ZCODE_DATA_BASE_DIR) ? env.ZCODE_DATA_BASE_DIR : path9.join(home, ".zcode");
55292
55159
  config.zcode = readZcodeConfig(zcodeHome);
55293
55160
  config.omp = readOmpConfig(resolveOmpHome(env));
55294
55161
  config.opencode = readOpencodeConfig(resolveOpencodeConfigFile(env));
@@ -55348,14 +55215,14 @@ function extractHttpsHosts(config) {
55348
55215
  }
55349
55216
  function configFilePaths(env) {
55350
55217
  const home = os2.homedir();
55351
- const codexHome = nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME : path11.join(home, ".codex");
55352
- const zcodeHome = nonEmpty2(env.ZCODE_DATA_BASE_DIR) ? env.ZCODE_DATA_BASE_DIR : path11.join(home, ".zcode");
55218
+ const codexHome = nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME : path10.join(home, ".codex");
55219
+ const zcodeHome = nonEmpty2(env.ZCODE_DATA_BASE_DIR) ? env.ZCODE_DATA_BASE_DIR : path10.join(home, ".zcode");
55353
55220
  return [
55354
- path11.join(home, ".claude", "settings.json"),
55355
- path11.join(process.cwd(), ".claude", "settings.json"),
55356
- path11.join(codexHome, "config.toml"),
55357
- path11.join(resolvePiHome(env), "models.json"),
55358
- path11.join(zcodeHome, "v2", "config.json")
55221
+ path10.join(home, ".claude", "settings.json"),
55222
+ path10.join(process.cwd(), ".claude", "settings.json"),
55223
+ path10.join(codexHome, "config.toml"),
55224
+ path10.join(resolvePiHome(env), "models.json"),
55225
+ path10.join(zcodeHome, "v2", "config.json")
55359
55226
  ];
55360
55227
  }
55361
55228
  function readMtimes(paths) {
@@ -58112,10 +57979,10 @@ async function pipeThrough(stream2, res) {
58112
57979
  }
58113
57980
  async function dumpStreamToFile(stream2, dir, name) {
58114
57981
  const { mkdirSync: mkdirSync6, createWriteStream: createWriteStream2 } = await import("fs");
58115
- const { join: join5 } = await import("path");
57982
+ const { join: join4 } = await import("path");
58116
57983
  try {
58117
57984
  mkdirSync6(dir, { recursive: true });
58118
- const ws2 = createWriteStream2(join5(dir, name));
57985
+ const ws2 = createWriteStream2(join4(dir, name));
58119
57986
  ws2.on("error", (e) => {
58120
57987
  logDumpFailure("SSE stream dump", e);
58121
57988
  });
@@ -61191,12 +61058,12 @@ var To = (s3) => {
61191
61058
  };
61192
61059
 
61193
61060
  // src/update.ts
61194
- import path12 from "path";
61061
+ import path11 from "path";
61195
61062
  import { fileURLToPath as fileURLToPath3 } from "url";
61196
61063
  var REGISTRY_BASE = "https://registry.npmjs.org";
61197
61064
  var CHECK_INTERVAL_MS = 3 * 60 * 1e3;
61198
- var THROTTLE_FILE = path12.join(cacheDir(), ".update-check");
61199
- var LOCK_FILE = path12.join(cacheDir(), ".update-lock");
61065
+ var THROTTLE_FILE = path11.join(cacheDir(), ".update-check");
61066
+ var LOCK_FILE = path11.join(cacheDir(), ".update-lock");
61200
61067
  var LOCK_MAX_AGE_MS = 30 * 60 * 1e3;
61201
61068
  function shouldStealLock(holderAlive, ageMs) {
61202
61069
  return !holderAlive || ageMs >= LOCK_MAX_AGE_MS;
@@ -61231,27 +61098,27 @@ async function readLastCheck() {
61231
61098
  }
61232
61099
  async function writeLastCheck(ts2) {
61233
61100
  try {
61234
- await mkdir2(path12.dirname(THROTTLE_FILE), { recursive: true });
61101
+ await mkdir2(path11.dirname(THROTTLE_FILE), { recursive: true });
61235
61102
  await writeFile2(THROTTLE_FILE, String(ts2), "utf-8");
61236
61103
  } catch {
61237
61104
  }
61238
61105
  }
61239
61106
  async function findInstallDir(packageName) {
61240
- let dir = path12.dirname(fileURLToPath3(import.meta.url));
61107
+ let dir = path11.dirname(fileURLToPath3(import.meta.url));
61241
61108
  for (; ; ) {
61242
61109
  try {
61243
- const pkg = JSON.parse(await readFile2(path12.join(dir, "package.json"), "utf-8"));
61110
+ const pkg = JSON.parse(await readFile2(path11.join(dir, "package.json"), "utf-8"));
61244
61111
  if (pkg.name === packageName) return dir;
61245
61112
  } catch {
61246
61113
  }
61247
- const parent = path12.dirname(dir);
61114
+ const parent = path11.dirname(dir);
61248
61115
  if (parent === dir) return void 0;
61249
61116
  dir = parent;
61250
61117
  }
61251
61118
  }
61252
61119
  async function readDiskVersion(installDir) {
61253
61120
  try {
61254
- const pkg = JSON.parse(await readFile2(path12.join(installDir, "package.json"), "utf-8"));
61121
+ const pkg = JSON.parse(await readFile2(path11.join(installDir, "package.json"), "utf-8"));
61255
61122
  return pkg.version;
61256
61123
  } catch {
61257
61124
  return void 0;
@@ -61288,13 +61155,13 @@ async function syntaxCheckEntry(entryAbs) {
61288
61155
  } catch (e) {
61289
61156
  return `entry unreadable: ${String(e)}`;
61290
61157
  }
61291
- const tmpCheck = path12.join(cacheDir(), ".update-syntax-check.mjs");
61158
+ const tmpCheck = path11.join(cacheDir(), ".update-syntax-check.mjs");
61292
61159
  try {
61293
61160
  await mkdir2(cacheDir(), { recursive: true });
61294
61161
  await writeFile2(tmpCheck, source);
61295
61162
  const r = await runNodeCheck(tmpCheck);
61296
61163
  if (r.code !== 0) {
61297
- return `entry does not parse (${path12.basename(entryAbs)}): ${r.stderr.split("\n").filter(Boolean).slice(0, 3).join(" | ").slice(0, 300)}`;
61164
+ return `entry does not parse (${path11.basename(entryAbs)}): ${r.stderr.split("\n").filter(Boolean).slice(0, 3).join(" | ").slice(0, 300)}`;
61298
61165
  }
61299
61166
  return null;
61300
61167
  } finally {
@@ -61307,7 +61174,7 @@ async function syntaxCheckEntry(entryAbs) {
61307
61174
  async function verifyEntries(dir, label) {
61308
61175
  let pkg;
61309
61176
  try {
61310
- pkg = JSON.parse(await readFile2(path12.join(dir, "package.json"), "utf-8"));
61177
+ pkg = JSON.parse(await readFile2(path11.join(dir, "package.json"), "utf-8"));
61311
61178
  } catch (e) {
61312
61179
  return `${label}: package.json unreadable: ${String(e)}`;
61313
61180
  }
@@ -61317,11 +61184,11 @@ async function verifyEntries(dir, label) {
61317
61184
  }
61318
61185
  for (const rel2 of entries) {
61319
61186
  try {
61320
- await access(path12.join(dir, rel2));
61187
+ await access(path11.join(dir, rel2));
61321
61188
  } catch {
61322
61189
  return `${label}: entry missing: ${rel2}`;
61323
61190
  }
61324
- const reason = await syntaxCheckEntry(path12.join(dir, rel2));
61191
+ const reason = await syntaxCheckEntry(path11.join(dir, rel2));
61325
61192
  if (reason) return `${label}: ${reason}`;
61326
61193
  }
61327
61194
  return null;
@@ -61526,14 +61393,14 @@ async function installViaTarball(version2, tarballUrl, installDir, integrity, sh
61526
61393
  if (!v2.ok) {
61527
61394
  return { ok: false, error: `tarball integrity verification failed: ${v2.error}` };
61528
61395
  }
61529
- const tmpFile = path12.join(cacheDir(), `.update-${version2}.tgz`);
61396
+ const tmpFile = path11.join(cacheDir(), `.update-${version2}.tgz`);
61530
61397
  try {
61531
61398
  await mkdir2(cacheDir(), { recursive: true });
61532
61399
  await writeFile2(tmpFile, tgzBuffer);
61533
61400
  } catch (e) {
61534
61401
  return { ok: false, error: `failed to write temp file ${tmpFile}: ${String(e)}` };
61535
61402
  }
61536
- const stagingDir = path12.join(cacheDir(), `.update-staging-${version2}`);
61403
+ const stagingDir = path11.join(cacheDir(), `.update-staging-${version2}`);
61537
61404
  try {
61538
61405
  await rm2(stagingDir, { recursive: true, force: true });
61539
61406
  await mkdir2(stagingDir, { recursive: true });
@@ -61555,7 +61422,7 @@ async function installViaTarball(version2, tarballUrl, installDir, integrity, sh
61555
61422
  } finally {
61556
61423
  await rm2(tmpFile, { force: true });
61557
61424
  }
61558
- const backupDir = path12.join(cacheDir(), `.update-backup-${version2}`);
61425
+ const backupDir = path11.join(cacheDir(), `.update-backup-${version2}`);
61559
61426
  try {
61560
61427
  await rm2(backupDir, { recursive: true, force: true });
61561
61428
  await cp(installDir, backupDir, { recursive: true, force: true });
@@ -61612,12 +61479,12 @@ function startAutoUpdate(opts) {
61612
61479
 
61613
61480
  // src/mcp.ts
61614
61481
  import fs9 from "fs";
61615
- import path13 from "path";
61482
+ import path12 from "path";
61616
61483
  import { fileURLToPath as fileURLToPath4 } from "url";
61617
61484
  var VERSION2 = (() => {
61618
61485
  try {
61619
61486
  const here = fileURLToPath4(import.meta.url);
61620
- const pkg = path13.join(path13.dirname(here), "..", "package.json");
61487
+ const pkg = path12.join(path12.dirname(here), "..", "package.json");
61621
61488
  return JSON.parse(fs9.readFileSync(pkg, "utf8")).version ?? "dev";
61622
61489
  } catch {
61623
61490
  return "dev";
@@ -61788,7 +61655,7 @@ if (process.argv[1] && /(?:^|[\\/])mcp\.(?:ts|js)$/.test(process.argv[1])) {
61788
61655
 
61789
61656
  // src/plugin-install.ts
61790
61657
  import fs10 from "fs";
61791
- import path14 from "path";
61658
+ import path13 from "path";
61792
61659
  import os4 from "os";
61793
61660
  import { execFileSync as execFileSync2 } from "child_process";
61794
61661
  import { fileURLToPath as fileURLToPath5 } from "url";
@@ -61807,12 +61674,12 @@ function proxyOriginForInstall() {
61807
61674
  var PLUGIN_AGENTS = ["pi", "omp", "claude", "codex", "opencode"];
61808
61675
  function selfPackageRoot() {
61809
61676
  const here = fileURLToPath5(import.meta.url);
61810
- return path14.resolve(path14.dirname(here), "..");
61677
+ return path13.resolve(path13.dirname(here), "..");
61811
61678
  }
61812
61679
  function homeFile(rel2, envOverride) {
61813
61680
  const raw = (envOverride !== void 0 ? process.env[envOverride] : void 0)?.trim();
61814
61681
  const base = raw && raw.length > 0 ? raw : os4.homedir();
61815
- return path14.join(base, rel2);
61682
+ return path13.join(base, rel2);
61816
61683
  }
61817
61684
  function backupOnce(file) {
61818
61685
  if (fs10.existsSync(file) && !fs10.existsSync(`${file}.bili-bak`)) {
@@ -61831,7 +61698,7 @@ function readJson(file) {
61831
61698
  try {
61832
61699
  parsed = JSON.parse(text);
61833
61700
  } catch (err2) {
61834
- throw new Error(`${file}: not valid JSON (${err2 instanceof Error ? err2.message : String(err2)}) \u2014 fix it or restore ${path14.basename(file)}.bili-bak first; refusing to overwrite`);
61701
+ throw new Error(`${file}: not valid JSON (${err2 instanceof Error ? err2.message : String(err2)}) \u2014 fix it or restore ${path13.basename(file)}.bili-bak first; refusing to overwrite`);
61835
61702
  }
61836
61703
  if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
61837
61704
  throw new Error(`${file}: expected a JSON object at top level, refusing to overwrite`);
@@ -61839,7 +61706,7 @@ function readJson(file) {
61839
61706
  return parsed;
61840
61707
  }
61841
61708
  function writeJson(file, data) {
61842
- fs10.mkdirSync(path14.dirname(file), { recursive: true });
61709
+ fs10.mkdirSync(path13.dirname(file), { recursive: true });
61843
61710
  backupOnce(file);
61844
61711
  fs10.writeFileSync(file, JSON.stringify(data, null, 2) + "\n");
61845
61712
  }
@@ -61850,7 +61717,7 @@ function requireDistFile(file) {
61850
61717
  }
61851
61718
  }
61852
61719
  function piSettingsFile() {
61853
- return path14.join(resolvePiHome(process.env), "settings.json");
61720
+ return path13.join(resolvePiHome(process.env), "settings.json");
61854
61721
  }
61855
61722
  function isPiEntry(entry, root) {
61856
61723
  return entry === root || /^npm:billion-context(-pi)?(@|$)/.test(entry) || /(^|[/\\])node_modules[/\\]billion-context(-pi)?([\/\\]|$)/.test(entry) || /(^|[/\\])billion-context(-pi)?$/.test(entry);
@@ -61916,14 +61783,14 @@ function ompConfigFile() {
61916
61783
  `bili plugin: PI_CODING_AGENT_DIR points at the bili overlay ${raw} \u2014 operating on the real omp home ${realHome} instead
61917
61784
  `
61918
61785
  );
61919
- return path14.join(realHome, "config.yml");
61786
+ return path13.join(realHome, "config.yml");
61920
61787
  }
61921
- return path14.join(raw, "config.yml");
61788
+ return path13.join(raw, "config.yml");
61922
61789
  }
61923
- return path14.join(os4.homedir(), ".omp", "agent", "config.yml");
61790
+ return path13.join(os4.homedir(), ".omp", "agent", "config.yml");
61924
61791
  }
61925
61792
  function ompExtensionPath() {
61926
- return path14.join(selfPackageRoot(), "dist", "agent", "omp.js");
61793
+ return path13.join(selfPackageRoot(), "dist", "agent", "omp.js");
61927
61794
  }
61928
61795
  function ompEntryValue(line) {
61929
61796
  return line.replace(/#.*$/, "").trim().replace(/^-\s*/, "").replace(/^["']|["']$/g, "").trim();
@@ -61953,7 +61820,7 @@ function ompInstall() {
61953
61820
  const file = ompConfigFile();
61954
61821
  const entry = ompExtensionPath();
61955
61822
  requireDistFile(entry);
61956
- fs10.mkdirSync(path14.dirname(file), { recursive: true });
61823
+ fs10.mkdirSync(path13.dirname(file), { recursive: true });
61957
61824
  let text = fs10.existsSync(file) ? fs10.readFileSync(file, "utf8") : "";
61958
61825
  if (ompBlockLoaded(text)) return `omp: already installed (${file})`;
61959
61826
  {
@@ -62014,7 +61881,7 @@ function ompStatus() {
62014
61881
  }
62015
61882
  function ompPluginLoadedFrom(ompHome) {
62016
61883
  try {
62017
- return ompBlockLoaded(fs10.readFileSync(path14.join(ompHome, "config.yml"), "utf8"));
61884
+ return ompBlockLoaded(fs10.readFileSync(path13.join(ompHome, "config.yml"), "utf8"));
62018
61885
  } catch {
62019
61886
  return false;
62020
61887
  }
@@ -62025,7 +61892,7 @@ function claudeMcpJson() {
62025
61892
  }
62026
61893
  function claudeInstall() {
62027
61894
  const root = selfPackageRoot();
62028
- const mcpJs = path14.join(root, "dist", "mcp.js");
61895
+ const mcpJs = path13.join(root, "dist", "mcp.js");
62029
61896
  requireDistFile(mcpJs);
62030
61897
  const claude = process.env.CLAUDE?.trim() || "claude";
62031
61898
  try {
@@ -62052,14 +61919,14 @@ function claudeStatus() {
62052
61919
  }
62053
61920
  function codexToml() {
62054
61921
  const raw = process.env.CODEX_HOME?.trim();
62055
- if (raw && raw.length > 0) return path14.join(raw, "config.toml");
61922
+ if (raw && raw.length > 0) return path13.join(raw, "config.toml");
62056
61923
  return homeFile(".codex/config.toml");
62057
61924
  }
62058
61925
  function codexBlock() {
62059
61926
  return `
62060
61927
  [mcp_servers.bili]
62061
61928
  command = ${JSON.stringify(process.execPath)}
62062
- args = [${JSON.stringify(path14.join(selfPackageRoot(), "dist", "mcp.js"))}]
61929
+ args = [${JSON.stringify(path13.join(selfPackageRoot(), "dist", "mcp.js"))}]
62063
61930
  env = { BILI_MCP_PROXY = ${JSON.stringify(proxyOriginForInstall())} }
62064
61931
  `;
62065
61932
  }
@@ -62075,7 +61942,7 @@ function codexInstall() {
62075
61942
  fs10.writeFileSync(file, refreshed);
62076
61943
  return `codex: refreshed proxy origin -> ${file} [mcp_servers.bili]`;
62077
61944
  }
62078
- fs10.mkdirSync(path14.dirname(file), { recursive: true });
61945
+ fs10.mkdirSync(path13.dirname(file), { recursive: true });
62079
61946
  backupOnce(file);
62080
61947
  fs10.writeFileSync(file, text + (text.endsWith("\n") || text.length === 0 ? "" : "\n") + codexBlock());
62081
61948
  return `codex: installed -> ${file} [mcp_servers.bili]`;
@@ -62107,12 +61974,12 @@ function opencodeJson() {
62107
61974
  const raw = process.env.OPENCODE_CONFIG?.trim();
62108
61975
  if (raw && raw.length > 0) return raw;
62109
61976
  const xdg2 = process.env.XDG_CONFIG_HOME?.trim();
62110
- if (xdg2 && xdg2.length > 0) return path14.join(xdg2, "opencode/opencode.json");
62111
- return path14.join(os4.homedir(), ".config", "opencode", "opencode.json");
61977
+ if (xdg2 && xdg2.length > 0) return path13.join(xdg2, "opencode/opencode.json");
61978
+ return path13.join(os4.homedir(), ".config", "opencode", "opencode.json");
62112
61979
  }
62113
61980
  function opencodeInstall() {
62114
61981
  const file = opencodeJson();
62115
- const mcpJs = path14.join(selfPackageRoot(), "dist", "mcp.js");
61982
+ const mcpJs = path13.join(selfPackageRoot(), "dist", "mcp.js");
62116
61983
  requireDistFile(mcpJs);
62117
61984
  const data = readJson(file);
62118
61985
  const mcp = data.mcp ?? {};
@@ -62167,11 +62034,11 @@ import { randomUUID as randomUUID5 } from "crypto";
62167
62034
  import fs11 from "fs";
62168
62035
  import net2 from "net";
62169
62036
  import os5 from "os";
62170
- import path15 from "path";
62037
+ import path14 from "path";
62171
62038
  import { pathToFileURL } from "url";
62172
62039
  import { spawn } from "child_process";
62173
62040
  function selfDistFile(name) {
62174
- return path15.join(selfPackageRoot(), "dist", name);
62041
+ return path14.join(selfPackageRoot(), "dist", name);
62175
62042
  }
62176
62043
  var LAUNCHER_DEFAULT_HOST = "127.0.0.1";
62177
62044
  var LAUNCHER_DEFAULT_PORT = 8787;
@@ -62207,12 +62074,12 @@ function unwrapUpstream2(url) {
62207
62074
  return idx >= 0 ? url.slice(idx + "/bili/".length) : url;
62208
62075
  }
62209
62076
  function resolveCaCertPath(env) {
62210
- const base = env.XDG_DATA_HOME || path15.join(os5.homedir(), ".local/share");
62211
- return path15.join(base, "billion-context", "ca", "root-ca.pem");
62077
+ const base = env.XDG_DATA_HOME || path14.join(os5.homedir(), ".local/share");
62078
+ return path14.join(base, "billion-context", "ca", "root-ca.pem");
62212
62079
  }
62213
62080
  function resolveCombinedCaPath(env) {
62214
- const base = env.XDG_DATA_HOME || path15.join(os5.homedir(), ".local/share");
62215
- return path15.join(base, "billion-context", "ca", "combined-ca.pem");
62081
+ const base = env.XDG_DATA_HOME || path14.join(os5.homedir(), ".local/share");
62082
+ return path14.join(base, "billion-context", "ca", "combined-ca.pem");
62216
62083
  }
62217
62084
  function discoverRoutes(client, config) {
62218
62085
  const httpsDomains = [];
@@ -62445,7 +62312,7 @@ function buildCodexMcpArgs(origin, conversationId2) {
62445
62312
  ];
62446
62313
  }
62447
62314
  function overlayLockPath(overlay) {
62448
- return path15.join(overlay, ".bili-launch.pid");
62315
+ return path14.join(overlay, ".bili-launch.pid");
62449
62316
  }
62450
62317
  function livePidHoldsOverlay(overlay) {
62451
62318
  let raw;
@@ -62464,8 +62331,8 @@ function livePidHoldsOverlay(overlay) {
62464
62331
  return pid;
62465
62332
  }
62466
62333
  function linkOverlayEntry(realHome, overlay, entry) {
62467
- const target = path15.join(realHome, entry);
62468
- const link = path15.join(overlay, entry);
62334
+ const target = path14.join(realHome, entry);
62335
+ const link = path14.join(overlay, entry);
62469
62336
  try {
62470
62337
  fs11.symlinkSync(target, link);
62471
62338
  return true;
@@ -62514,7 +62381,7 @@ function sqliteSetMembers(base) {
62514
62381
  function mergeSqliteSet(overlay, realHome, base) {
62515
62382
  const members = sqliteSetMembers(base).filter((m2) => {
62516
62383
  try {
62517
- return fs11.lstatSync(path15.join(overlay, m2)).isFile();
62384
+ return fs11.lstatSync(path14.join(overlay, m2)).isFile();
62518
62385
  } catch {
62519
62386
  return false;
62520
62387
  }
@@ -62532,8 +62399,8 @@ function mergeSqliteSet(overlay, realHome, base) {
62532
62399
  };
62533
62400
  try {
62534
62401
  for (const m2 of members) {
62535
- const src = path15.join(overlay, m2);
62536
- const dst = path15.join(realHome, m2);
62402
+ const src = path14.join(overlay, m2);
62403
+ const dst = path14.join(realHome, m2);
62537
62404
  let dstStat;
62538
62405
  try {
62539
62406
  dstStat = fs11.lstatSync(dst);
@@ -62613,10 +62480,10 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
62613
62480
  if (!members.some((m2) => m2 !== entry && overlayEntries.includes(m2))) continue;
62614
62481
  let mainSt;
62615
62482
  try {
62616
- mainSt = fs11.lstatSync(path15.join(overlay, entry));
62483
+ mainSt = fs11.lstatSync(path14.join(overlay, entry));
62617
62484
  } catch {
62618
62485
  }
62619
- const keepSidecars = mainSt !== void 0 && isWriteThroughHardlink(path15.join(overlay, entry), path15.join(realHome, entry), mainSt);
62486
+ const keepSidecars = mainSt !== void 0 && isWriteThroughHardlink(path14.join(overlay, entry), path14.join(realHome, entry), mainSt);
62620
62487
  dbSets.push({ base: entry, keepSidecars });
62621
62488
  }
62622
62489
  const skipEntries = /* @__PURE__ */ new Set();
@@ -62627,7 +62494,7 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
62627
62494
  }
62628
62495
  for (const entry of overlayEntries) {
62629
62496
  if (entry === generatedFile) continue;
62630
- const overlayPath = path15.join(overlay, entry);
62497
+ const overlayPath = path14.join(overlay, entry);
62631
62498
  if (entry.startsWith(`.${generatedFile}.`) && entry.endsWith(".tmp")) {
62632
62499
  try {
62633
62500
  fs11.unlinkSync(overlayPath);
@@ -62648,7 +62515,7 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
62648
62515
  target = fs11.readlinkSync(overlayPath);
62649
62516
  } catch {
62650
62517
  }
62651
- const wanted = realEntries.has(entry) ? path15.join(realHome, entry) : void 0;
62518
+ const wanted = realEntries.has(entry) ? path14.join(realHome, entry) : void 0;
62652
62519
  if (!wanted || target !== wanted) {
62653
62520
  try {
62654
62521
  fs11.unlinkSync(overlayPath);
@@ -62656,7 +62523,7 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
62656
62523
  }
62657
62524
  }
62658
62525
  } else if (realEntries.has(entry)) {
62659
- const realPath = path15.join(realHome, entry);
62526
+ const realPath = path14.join(realHome, entry);
62660
62527
  if (isWriteThroughHardlink(overlayPath, realPath, st2)) {
62661
62528
  try {
62662
62529
  fs11.unlinkSync(overlayPath);
@@ -62686,7 +62553,7 @@ function refreshOverlayHome(realHome, overlay, generatedFile) {
62686
62553
  for (const entry of realEntries) {
62687
62554
  if (entry === generatedFile) continue;
62688
62555
  total += 1;
62689
- const overlayPath = path15.join(overlay, entry);
62556
+ const overlayPath = path14.join(overlay, entry);
62690
62557
  let present = false;
62691
62558
  try {
62692
62559
  fs11.lstatSync(overlayPath);
@@ -62753,7 +62620,7 @@ function mergeOverlayEntry(src, dst, excludedName) {
62753
62620
  let ok = true;
62754
62621
  for (const entry of entries) {
62755
62622
  if (excludedName !== void 0 && entry === excludedName) continue;
62756
- if (!mergeOverlayEntry(path15.join(src, entry), path15.join(dst, entry), excludedName)) ok = false;
62623
+ if (!mergeOverlayEntry(path14.join(src, entry), path14.join(dst, entry), excludedName)) ok = false;
62757
62624
  }
62758
62625
  return ok;
62759
62626
  }
@@ -62806,7 +62673,7 @@ function piPluginInstalled(piHome) {
62806
62673
  const root = selfPackageRoot();
62807
62674
  if (!root) return false;
62808
62675
  try {
62809
- const parsed = JSON.parse(fs11.readFileSync(path15.join(piHome, "settings.json"), "utf8"));
62676
+ const parsed = JSON.parse(fs11.readFileSync(path14.join(piHome, "settings.json"), "utf8"));
62810
62677
  const list = Array.isArray(parsed.packages) ? parsed.packages.map(String) : [];
62811
62678
  return list.some((p2) => isBiliPiEntry(p2, root));
62812
62679
  } catch {
@@ -62814,10 +62681,10 @@ function piPluginInstalled(piHome) {
62814
62681
  }
62815
62682
  }
62816
62683
  function writeOverlayFileAtomic(overlay, fileName, contents) {
62817
- const draft = path15.join(overlay, `.${fileName}.${process.pid}.tmp`);
62684
+ const draft = path14.join(overlay, `.${fileName}.${process.pid}.tmp`);
62818
62685
  try {
62819
62686
  fs11.writeFileSync(draft, contents);
62820
- fs11.renameSync(draft, path15.join(overlay, fileName));
62687
+ fs11.renameSync(draft, path14.join(overlay, fileName));
62821
62688
  } catch {
62822
62689
  try {
62823
62690
  fs11.rmSync(draft, { force: true });
@@ -62827,7 +62694,7 @@ function writeOverlayFileAtomic(overlay, fileName, contents) {
62827
62694
  }
62828
62695
  function preparePiHttpRewrite(piHome, origin, httpRewrites, httpsRewrites) {
62829
62696
  if (httpRewrites.length === 0 && httpsRewrites.length === 0) return void 0;
62830
- const modelsPath = path15.join(piHome, "models.json");
62697
+ const modelsPath = path14.join(piHome, "models.json");
62831
62698
  let txt;
62832
62699
  try {
62833
62700
  txt = fs11.readFileSync(modelsPath, "utf8");
@@ -62915,7 +62782,7 @@ function unpackDeadProxyUrlsInFile(filePath, livePorts) {
62915
62782
  return changed;
62916
62783
  }
62917
62784
  function prepareOmpHttpRewrite(ompHome, origin, httpRewrites, httpsRewrites) {
62918
- const modelsPath = path15.join(ompHome, "models.yml");
62785
+ const modelsPath = path14.join(ompHome, "models.yml");
62919
62786
  const unpacked = unpackDeadProxyUrlsInFile(modelsPath, liveProxyPorts());
62920
62787
  if (unpacked > 0) {
62921
62788
  console.error(`bili: unpacked ${unpacked} dead proxy URL(s) from the real ${modelsPath}`);
@@ -62967,7 +62834,7 @@ function prepareOmpHttpRewrite(ompHome, origin, httpRewrites, httpsRewrites) {
62967
62834
  }
62968
62835
  function prepareHermesHome(hermesHome, origin, rewrites) {
62969
62836
  if (rewrites.length === 0) return void 0;
62970
- const cfgPath = path15.join(hermesHome, "config.yaml");
62837
+ const cfgPath = path14.join(hermesHome, "config.yaml");
62971
62838
  let txt;
62972
62839
  try {
62973
62840
  txt = fs11.readFileSync(cfgPath, "utf8");
@@ -62997,21 +62864,21 @@ function prepareHermesHome(hermesHome, origin, rewrites) {
62997
62864
  }
62998
62865
  function writeHermesIdentityPlugin(hermesHome, overlay, rewrites) {
62999
62866
  try {
63000
- if (fs11.existsSync(path15.join(hermesHome, "plugins"))) return false;
62867
+ if (fs11.existsSync(path14.join(hermesHome, "plugins"))) return false;
63001
62868
  } catch {
63002
62869
  return false;
63003
62870
  }
63004
- const dir = path15.join("plugins", "model-providers", "bili-session-identity");
62871
+ const dir = path14.join("plugins", "model-providers", "bili-session-identity");
63005
62872
  try {
63006
- fs11.mkdirSync(path15.join(overlay, dir), { recursive: true });
62873
+ fs11.mkdirSync(path14.join(overlay, dir), { recursive: true });
63007
62874
  } catch {
63008
62875
  return false;
63009
62876
  }
63010
62877
  const keys = rewrites.map((r) => r.key);
63011
- const pluginDir = path15.join(overlay, dir);
62878
+ const pluginDir = path14.join(overlay, dir);
63012
62879
  try {
63013
- fs11.writeFileSync(path15.join(pluginDir, "__init__.py"), hermesIdentityPluginSource(keys));
63014
- fs11.writeFileSync(path15.join(pluginDir, "plugin.yaml"), [
62880
+ fs11.writeFileSync(path14.join(pluginDir, "__init__.py"), hermesIdentityPluginSource(keys));
62881
+ fs11.writeFileSync(path14.join(pluginDir, "plugin.yaml"), [
63015
62882
  "name: bili-session-identity",
63016
62883
  "kind: model-provider",
63017
62884
  "version: 1.0.0",
@@ -63023,7 +62890,7 @@ function writeHermesIdentityPlugin(hermesHome, overlay, rewrites) {
63023
62890
  return false;
63024
62891
  }
63025
62892
  try {
63026
- return fs11.existsSync(path15.join(overlay, dir, "__init__.py"));
62893
+ return fs11.existsSync(path14.join(overlay, dir, "__init__.py"));
63027
62894
  } catch {
63028
62895
  return false;
63029
62896
  }
@@ -63080,7 +62947,7 @@ function hermesIdentityPluginSource(providerKeys) {
63080
62947
  ].join("\n");
63081
62948
  }
63082
62949
  function prepareDshHome(dshHome, origin, rewrites) {
63083
- const cfgPath = path15.join(dshHome, "settings.yaml");
62950
+ const cfgPath = path14.join(dshHome, "settings.yaml");
63084
62951
  let txt;
63085
62952
  try {
63086
62953
  txt = fs11.readFileSync(cfgPath, "utf8");
@@ -63118,7 +62985,7 @@ function writeDshAcpPatch(dshHome) {
63118
62985
  writeOverlayFileAtomic(dir, ".bili-acp.patch.yml", `- insert:
63119
62986
  - name: ${pluginUrl}
63120
62987
  `);
63121
- const file = path15.join(dir, ".bili-acp.patch.yml");
62988
+ const file = path14.join(dir, ".bili-acp.patch.yml");
63122
62989
  try {
63123
62990
  return fs11.existsSync(file) ? file : void 0;
63124
62991
  } catch {
@@ -63163,8 +63030,8 @@ function prepareOpencodeHttpRewrite(configFile2, origin, httpRewrites, httpsRewr
63163
63030
  if (!plugins.includes(pluginPath)) plugins.push(pluginPath);
63164
63031
  root.plugin = plugins;
63165
63032
  }
63166
- const tmp = fs11.mkdtempSync(path15.join(os5.tmpdir(), "bili-opencode-"));
63167
- const tmpFile = path15.join(tmp, "opencode.json");
63033
+ const tmp = fs11.mkdtempSync(path14.join(os5.tmpdir(), "bili-opencode-"));
63034
+ const tmpFile = path14.join(tmp, "opencode.json");
63168
63035
  fs11.writeFileSync(tmpFile, JSON.stringify(root));
63169
63036
  return tmpFile;
63170
63037
  }
@@ -63255,7 +63122,7 @@ async function ensureProxyRunning(opts, deps = {}) {
63255
63122
  const port = opts.port;
63256
63123
  const script = process.argv[1];
63257
63124
  if (!script) throw new Error("bili: cannot resolve launcher script path");
63258
- const logPath2 = path15.join(os5.tmpdir(), `bili-proxy-${port}.log`);
63125
+ const logPath2 = path14.join(os5.tmpdir(), `bili-proxy-${port}.log`);
63259
63126
  const logFd = fs11.openSync(logPath2, "a");
63260
63127
  let child;
63261
63128
  try {
@@ -63335,10 +63202,10 @@ var PATH_EXTS = process.platform === "win32" ? [".cmd", ".bat", ".exe", ""] : ["
63335
63202
  function resolveOnPath(name, env) {
63336
63203
  const p2 = env.PATH;
63337
63204
  if (!p2) return void 0;
63338
- for (const dir of p2.split(path15.delimiter)) {
63205
+ for (const dir of p2.split(path14.delimiter)) {
63339
63206
  if (!dir) continue;
63340
63207
  for (const ext of PATH_EXTS) {
63341
- const f2 = path15.join(dir, name + ext);
63208
+ const f2 = path14.join(dir, name + ext);
63342
63209
  try {
63343
63210
  if (fs11.existsSync(f2) && fs11.statSync(f2).isFile()) return f2;
63344
63211
  } catch {
@@ -63358,7 +63225,7 @@ function resolveClientCommand(client, env) {
63358
63225
  if (piBin) return { command: piBin, prefixArgs: [] };
63359
63226
  const piResolved = resolveOnPath("pi", env);
63360
63227
  if (piResolved) return { command: piResolved, prefixArgs: [] };
63361
- const cli = path15.join(
63228
+ const cli = path14.join(
63362
63229
  os5.homedir(),
63363
63230
  ".pi/agent/npm/node_modules/@earendil-works/pi-coding-agent/dist/cli.js"
63364
63231
  );
@@ -63517,7 +63384,7 @@ async function runLaunch(params, deps = {}) {
63517
63384
  console.error(`bili: claude budget aligned \u2014 CLAUDE_CODE_AUTO_COMPACT_WINDOW=${claudeBudget.CLAUDE_CODE_AUTO_COMPACT_WINDOW}`);
63518
63385
  }
63519
63386
  if (injectMcp) {
63520
- const mcpFile = path15.join(os5.tmpdir(), `bili-mcp-${Date.now()}.json`);
63387
+ const mcpFile = path14.join(os5.tmpdir(), `bili-mcp-${Date.now()}.json`);
63521
63388
  fs11.writeFileSync(mcpFile, JSON.stringify(buildMcpConfig(origin)));
63522
63389
  tmpFiles.push(mcpFile);
63523
63390
  clientArgs = ["--mcp-config", mcpFile, ...clientArgs];
@@ -63537,7 +63404,7 @@ async function runLaunch(params, deps = {}) {
63537
63404
  stopProxy(handle2);
63538
63405
  if (opencodeTmpFile) {
63539
63406
  try {
63540
- fs11.rmSync(path15.dirname(opencodeTmpFile), { recursive: true, force: true });
63407
+ fs11.rmSync(path14.dirname(opencodeTmpFile), { recursive: true, force: true });
63541
63408
  } catch {
63542
63409
  }
63543
63410
  }
@@ -63569,7 +63436,7 @@ async function runTestPi(params, deps = {}) {
63569
63436
  }
63570
63437
  const ca = resolveCaCertPath(process.env);
63571
63438
  const env = buildPiEnv(handle2.origin, ca, process.env);
63572
- const sessionDir = path15.join(os5.tmpdir(), `bili-pi-test-${Date.now()}`);
63439
+ const sessionDir = path14.join(os5.tmpdir(), `bili-pi-test-${Date.now()}`);
63573
63440
  fs11.mkdirSync(sessionDir, { recursive: true });
63574
63441
  const args = [
63575
63442
  "-p",
@@ -63598,7 +63465,7 @@ async function runTestPi(params, deps = {}) {
63598
63465
 
63599
63466
  // src/export.ts
63600
63467
  import { mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "fs";
63601
- import path16 from "path";
63468
+ import path15 from "path";
63602
63469
  function fmtDate(ms2) {
63603
63470
  return ms2 ? new Date(ms2).toISOString().replace("T", " ").slice(0, 19) + " UTC" : "\u2014";
63604
63471
  }
@@ -63730,7 +63597,7 @@ async function exportSession(selector, opts = {}) {
63730
63597
  }
63731
63598
  const markdown = renderHandoff(matches[0], opts.full ?? false);
63732
63599
  if (opts.output) {
63733
- mkdirSync5(path16.dirname(path16.resolve(opts.output)), { recursive: true });
63600
+ mkdirSync5(path15.dirname(path15.resolve(opts.output)), { recursive: true });
63734
63601
  writeFileSync4(opts.output, markdown, "utf8");
63735
63602
  return `written to ${opts.output}`;
63736
63603
  }
@@ -63740,11 +63607,11 @@ async function exportSession(selector, opts = {}) {
63740
63607
  // src/cli.ts
63741
63608
  import { readFileSync as readFileSync4 } from "fs";
63742
63609
  import { fileURLToPath as fileURLToPath6 } from "url";
63743
- import path17 from "path";
63610
+ import path16 from "path";
63744
63611
  var VERSION3 = (() => {
63745
63612
  try {
63746
63613
  const here = fileURLToPath6(import.meta.url);
63747
- const pkg = path17.join(path17.dirname(here), "..", "package.json");
63614
+ const pkg = path16.join(path16.dirname(here), "..", "package.json");
63748
63615
  return JSON.parse(readFileSync4(pkg, "utf8")).version ?? "dev";
63749
63616
  } catch {
63750
63617
  return "dev";
@@ -63753,7 +63620,7 @@ var VERSION3 = (() => {
63753
63620
  var PACKAGE_NAME = (() => {
63754
63621
  try {
63755
63622
  const here = fileURLToPath6(import.meta.url);
63756
- const pkg = path17.join(path17.dirname(here), "..", "package.json");
63623
+ const pkg = path16.join(path16.dirname(here), "..", "package.json");
63757
63624
  return JSON.parse(readFileSync4(pkg, "utf8")).name ?? "billion-context";
63758
63625
  } catch {
63759
63626
  return "billion-context";