billion-context-pi 0.0.2 → 0.0.4

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
@@ -8090,6 +8090,25 @@ function truncate2(s, n) {
8090
8090
  }
8091
8091
 
8092
8092
  // src/commands.ts
8093
+ import { readFileSync } from "fs";
8094
+ import { join as join5, dirname as dirname3 } from "path";
8095
+ import { fileURLToPath } from "url";
8096
+ function getDisplayName() {
8097
+ try {
8098
+ let dir = dirname3(fileURLToPath(import.meta.url));
8099
+ for (; ; ) {
8100
+ const pkg = JSON.parse(readFileSync(join5(dir, "package.json"), "utf-8"));
8101
+ if (pkg?.name === "pai-acp" || pkg?.name === "billion-context-pi") {
8102
+ return pkg.name;
8103
+ }
8104
+ const parent = dirname3(dir);
8105
+ if (parent === dir) break;
8106
+ dir = parent;
8107
+ }
8108
+ } catch {
8109
+ }
8110
+ return "pai-acp";
8111
+ }
8093
8112
  function makeCommands(runtime) {
8094
8113
  return [
8095
8114
  {
@@ -8184,7 +8203,7 @@ async function statusReport(runtime, ctx) {
8184
8203
  const activeBlocksList = state.blocks.filter((b) => b.active);
8185
8204
  const totalBlocksList = state.blocks;
8186
8205
  const lines = [];
8187
- const versionStr = "0.0.2" ? `pai-acp@${"0.0.2"}` : "";
8206
+ const versionStr = "0.0.4" ? `${getDisplayName()}@${"0.0.4"}` : "";
8188
8207
  lines.push("\u256D\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256E");
8189
8208
  lines.push("\u2502 ACP Context Analysis \u2502");
8190
8209
  lines.push("\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F");
@@ -8328,15 +8347,27 @@ When a background delegate finishes, an automated completion notification is inj
8328
8347
 
8329
8348
  // src/update.ts
8330
8349
  import { readFile, writeFile as writeFile3, mkdir as mkdir3 } from "fs/promises";
8331
- import { join as join5, dirname as dirname3 } from "path";
8332
- import { fileURLToPath } from "url";
8350
+ import { join as join6, dirname as dirname4 } from "path";
8351
+ import { fileURLToPath as fileURLToPath2 } from "url";
8333
8352
  import { execFile } from "child_process";
8334
- var PACKAGE_NAME = "pai-acp";
8335
- var REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
8353
+ var LEGACY_NAME = "pai-acp";
8354
+ var REGISTRY_BASE = "https://registry.npmjs.org";
8336
8355
  var SEMVER_RE = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z-.]+)?$/;
8337
8356
  var CHECK_INTERVAL_MS = 3 * 60 * 1e3;
8357
+ function throttleFilePath(name) {
8358
+ return `${process.env.HOME ?? ""}/.pi/agent/.${name}-update-check`;
8359
+ }
8338
8360
  var THROTTLE_FILE = `${process.env.HOME ?? ""}/.pi/agent/.pai-acp-update-check`;
8339
8361
  var updateInFlight = false;
8362
+ var cachedPackageName;
8363
+ async function getPackageName() {
8364
+ if (cachedPackageName !== void 0) return cachedPackageName;
8365
+ const dir = await findExtensionDir();
8366
+ if (!dir) return void 0;
8367
+ const pkg = await readPackageJson(join6(dir, "package.json"));
8368
+ cachedPackageName = pkg?.name;
8369
+ return cachedPackageName;
8370
+ }
8340
8371
  function parseVersion(v) {
8341
8372
  return v.replace(/^v/, "").split(".").map((n) => parseInt(n, 10) || 0);
8342
8373
  }
@@ -8349,18 +8380,18 @@ function isNewer(latest, current) {
8349
8380
  }
8350
8381
  return false;
8351
8382
  }
8352
- async function readLastCheck() {
8383
+ async function readLastCheck(name) {
8353
8384
  try {
8354
- const data = await readFile(THROTTLE_FILE, "utf-8");
8385
+ const data = await readFile(throttleFilePath(name), "utf-8");
8355
8386
  return parseInt(data.trim(), 10) || 0;
8356
8387
  } catch {
8357
8388
  return 0;
8358
8389
  }
8359
8390
  }
8360
- async function writeLastCheck(timestamp) {
8391
+ async function writeLastCheck(name, timestamp) {
8361
8392
  try {
8362
- await mkdir3(dirname3(THROTTLE_FILE), { recursive: true });
8363
- await writeFile3(THROTTLE_FILE, String(timestamp), "utf-8");
8393
+ await mkdir3(dirname4(throttleFilePath(name)), { recursive: true });
8394
+ await writeFile3(throttleFilePath(name), String(timestamp), "utf-8");
8364
8395
  } catch {
8365
8396
  }
8366
8397
  }
@@ -8373,19 +8404,19 @@ async function readPackageJson(path4) {
8373
8404
  }
8374
8405
  }
8375
8406
  function findNpmRoot(extDir) {
8376
- let dir = dirname3(extDir);
8407
+ let dir = dirname4(extDir);
8377
8408
  while (dir !== "/" && dir !== ".") {
8378
- if (dir.endsWith("node_modules")) return dirname3(dir);
8379
- dir = dirname3(dir);
8409
+ if (dir.endsWith("node_modules")) return dirname4(dir);
8410
+ dir = dirname4(dir);
8380
8411
  }
8381
8412
  return void 0;
8382
8413
  }
8383
8414
  async function findExtensionDir() {
8384
- let dir = dirname3(fileURLToPath(import.meta.url));
8415
+ let dir = dirname4(fileURLToPath2(import.meta.url));
8385
8416
  for (; ; ) {
8386
- const pkg = await readPackageJson(join5(dir, "package.json"));
8387
- if (pkg?.name === PACKAGE_NAME) return dir;
8388
- const parent = dirname3(dir);
8417
+ const pkg = await readPackageJson(join6(dir, "package.json"));
8418
+ if (pkg?.name === LEGACY_NAME || pkg?.name === "billion-context-pi") return dir;
8419
+ const parent = dirname4(dir);
8389
8420
  if (parent === dir) return void 0;
8390
8421
  dir = parent;
8391
8422
  }
@@ -8397,10 +8428,12 @@ async function autoInstallLatest(latest) {
8397
8428
  const npmDir = findNpmRoot(extDir);
8398
8429
  if (!npmDir) return false;
8399
8430
  try {
8431
+ const packageName = await getPackageName();
8432
+ if (!packageName) return false;
8400
8433
  const code = await new Promise((resolve2) => {
8401
8434
  execFile(
8402
8435
  "npm",
8403
- ["install", `${PACKAGE_NAME}@${latest}`, "--silent", "--no-audit", "--no-fund"],
8436
+ ["install", `${packageName}@${latest}`, "--silent", "--no-audit", "--no-fund"],
8404
8437
  { cwd: npmDir, timeout: 6e4, shell: process.platform === "win32" },
8405
8438
  (err) => resolve2(err ? 1 : 0)
8406
8439
  );
@@ -8418,12 +8451,14 @@ async function checkForUpdate(autoUpdate, notify) {
8418
8451
  if (updateInFlight) return;
8419
8452
  updateInFlight = true;
8420
8453
  try {
8454
+ const packageName = await getPackageName();
8455
+ if (!packageName) return;
8421
8456
  const now = Date.now();
8422
- const lastCheck = await readLastCheck();
8457
+ const lastCheck = await readLastCheck(packageName);
8423
8458
  if (now - lastCheck < CHECK_INTERVAL_MS) return;
8424
- await writeLastCheck(now);
8459
+ await writeLastCheck(packageName, now);
8425
8460
  const runtimeVersion = await getRuntimeVersion();
8426
- const res = await fetch(REGISTRY_URL, {
8461
+ const res = await fetch(`${REGISTRY_BASE}/${packageName}/latest`, {
8427
8462
  signal: AbortSignal.timeout(5e3),
8428
8463
  headers: { Accept: "application/json" }
8429
8464
  });
@@ -8431,7 +8466,7 @@ async function checkForUpdate(autoUpdate, notify) {
8431
8466
  const data = await res.json();
8432
8467
  const latest = data.version;
8433
8468
  if (!latest) return;
8434
- const current = runtimeVersion ?? "0.0.2";
8469
+ const current = runtimeVersion ?? "0.0.4";
8435
8470
  debug.event("update-check", {
8436
8471
  current,
8437
8472
  latest,
@@ -8445,7 +8480,7 @@ async function checkForUpdate(autoUpdate, notify) {
8445
8480
  );
8446
8481
  } else if (!installed && notify) {
8447
8482
  notify(
8448
- `${PACKAGE_NAME} ${latest} available (you have ${current}). Run: pi update --extension npm:${PACKAGE_NAME}`
8483
+ `${packageName} ${latest} available (you have ${current}). Run: pi update --extension npm:${packageName}`
8449
8484
  );
8450
8485
  }
8451
8486
  }
@@ -8457,37 +8492,37 @@ async function checkForUpdate(autoUpdate, notify) {
8457
8492
  async function getRuntimeVersion() {
8458
8493
  const extDir = await findExtensionDir();
8459
8494
  if (!extDir) return void 0;
8460
- const pkg = await readPackageJson(join5(extDir, "package.json"));
8495
+ const pkg = await readPackageJson(join6(extDir, "package.json"));
8461
8496
  return pkg?.version;
8462
8497
  }
8463
8498
 
8464
8499
  // src/rename-notice.ts
8465
- import { readFileSync, existsSync } from "fs";
8466
- import { join as join6, dirname as dirname4 } from "path";
8467
- import { fileURLToPath as fileURLToPath2 } from "url";
8500
+ import { readFileSync as readFileSync2, existsSync } from "fs";
8501
+ import { join as join7, dirname as dirname5 } from "path";
8502
+ import { fileURLToPath as fileURLToPath3 } from "url";
8468
8503
  import { execFile as execFile2 } from "child_process";
8469
- var LEGACY_NAME = "pai-acp";
8504
+ var LEGACY_NAME2 = "pai-acp";
8470
8505
  var NEW_NAME = "billion-context-pi";
8471
8506
  var NEW_REF = `npm:${NEW_NAME}`;
8472
- var REGISTRY_URL2 = `https://registry.npmjs.org/${NEW_NAME}/latest`;
8507
+ var REGISTRY_URL = `https://registry.npmjs.org/${NEW_NAME}/latest`;
8473
8508
  function findExtensionDirSync() {
8474
- let dir = dirname4(fileURLToPath2(import.meta.url));
8509
+ let dir = dirname5(fileURLToPath3(import.meta.url));
8475
8510
  for (; ; ) {
8476
8511
  try {
8477
- const data = JSON.parse(readFileSync(join6(dir, "package.json"), "utf-8"));
8478
- if (data?.name === LEGACY_NAME || data?.name === NEW_NAME) return dir;
8512
+ const data = JSON.parse(readFileSync2(join7(dir, "package.json"), "utf-8"));
8513
+ if (data?.name === LEGACY_NAME2 || data?.name === NEW_NAME) return dir;
8479
8514
  } catch {
8480
8515
  }
8481
- const parent = dirname4(dir);
8516
+ const parent = dirname5(dir);
8482
8517
  if (parent === dir) return void 0;
8483
8518
  dir = parent;
8484
8519
  }
8485
8520
  }
8486
8521
  function findNpmRootSync(extDir) {
8487
- let dir = dirname4(extDir);
8522
+ let dir = dirname5(extDir);
8488
8523
  for (; ; ) {
8489
- if (dir.endsWith("node_modules")) return dirname4(dir);
8490
- const parent = dirname4(dir);
8524
+ if (dir.endsWith("node_modules")) return dirname5(dir);
8525
+ const parent = dirname5(dir);
8491
8526
  if (parent === dir) return void 0;
8492
8527
  dir = parent;
8493
8528
  }
@@ -8496,8 +8531,8 @@ function isLegacyPackage() {
8496
8531
  const dir = findExtensionDirSync();
8497
8532
  if (!dir) return false;
8498
8533
  try {
8499
- const data = JSON.parse(readFileSync(join6(dir, "package.json"), "utf-8"));
8500
- return data?.name === LEGACY_NAME;
8534
+ const data = JSON.parse(readFileSync2(join7(dir, "package.json"), "utf-8"));
8535
+ return data?.name === LEGACY_NAME2;
8501
8536
  } catch {
8502
8537
  return false;
8503
8538
  }
@@ -8509,16 +8544,16 @@ function isNewPackageInstalled() {
8509
8544
  if (!npmDir) return false;
8510
8545
  try {
8511
8546
  const data = JSON.parse(
8512
- readFileSync(join6(npmDir, "node_modules", NEW_NAME, "package.json"), "utf-8")
8547
+ readFileSync2(join7(npmDir, "node_modules", NEW_NAME, "package.json"), "utf-8")
8513
8548
  );
8514
- return data?.name === NEW_NAME && existsSync(join6(npmDir, "node_modules", NEW_NAME, "dist", "index.js"));
8549
+ return data?.name === NEW_NAME && existsSync(join7(npmDir, "node_modules", NEW_NAME, "dist", "index.js"));
8515
8550
  } catch {
8516
8551
  return false;
8517
8552
  }
8518
8553
  }
8519
8554
  async function newPackageReady() {
8520
8555
  try {
8521
- const res = await fetch(REGISTRY_URL2, {
8556
+ const res = await fetch(REGISTRY_URL, {
8522
8557
  signal: AbortSignal.timeout(5e3),
8523
8558
  headers: { Accept: "application/json" }
8524
8559
  });
@@ -8548,12 +8583,10 @@ var CYAN = "\x1B[36m";
8548
8583
  var RESET = "\x1B[0m";
8549
8584
  function manualNotice() {
8550
8585
  const body = [
8551
- "\u2192 pai-acp is now billion-context-pi",
8586
+ "\u2192 pai-acp has been renamed to billion-context-pi",
8552
8587
  "Your context tools are unchanged \u2014 same package, new name.",
8553
- "To switch:",
8554
- " pi install billion-context-pi",
8555
- " pi uninstall pai-acp",
8556
- "(Your ~/.pi/acp.json config carries over.)"
8588
+ "Once billion-context-pi is published, it will install automatically.",
8589
+ "Your ~/.pi/acp.json config carries over."
8557
8590
  ].join("\n");
8558
8591
  return `${CYAN}${body}${RESET}`;
8559
8592
  }
@@ -8561,15 +8594,20 @@ function installingNotice() {
8561
8594
  return `${CYAN}Installing billion-context-pi\u2026${RESET}`;
8562
8595
  }
8563
8596
  function successNotice() {
8564
- return `${GREEN}\u2714 billion-context-pi installed \u2014 restart Pi to switch.${RESET}`;
8597
+ const body = [
8598
+ "\u2714 pai-acp \u2192 billion-context-pi (renamed, same tools).",
8599
+ "billion-context-pi has been installed. Restart Pi to switch over.",
8600
+ "Do NOT uninstall billion-context-pi \u2014 it is the replacement for pai-acp."
8601
+ ].join("\n");
8602
+ return `${GREEN}${body}${RESET}`;
8565
8603
  }
8566
8604
  function canUninstallNotice() {
8567
8605
  const body = [
8568
- `${GREEN}\u2714 billion-context-pi is active.${RESET}`,
8569
- `${CYAN}pai-acp is now inert. To clean up:${RESET}`,
8570
- ` ${CYAN}pi uninstall pai-acp${RESET}`
8606
+ "\u2714 You are now running billion-context-pi (formerly pai-acp).",
8607
+ "All your context tools (compress / decompress / search / delegate) are intact.",
8608
+ "pai-acp is now inert and safe to remove: pi uninstall pai-acp"
8571
8609
  ].join("\n");
8572
- return body;
8610
+ return `${GREEN}${body}${RESET}`;
8573
8611
  }
8574
8612
  async function installNewPackage() {
8575
8613
  return await runPi(["install", NEW_REF]) === 0;
@@ -8608,7 +8646,7 @@ async function checkRename(notify) {
8608
8646
  import { readFile as readFile2, writeFile as writeFile4, stat, copyFile, rename } from "fs/promises";
8609
8647
  import { existsSync as existsSync2 } from "fs";
8610
8648
  import { homedir } from "os";
8611
- import { join as join7 } from "path";
8649
+ import { join as join8 } from "path";
8612
8650
  var ACP_TOOLS = ["compress", "decompress", "search_context", "acp_status"];
8613
8651
  var BUILTIN_DEFAULT_TOOLS = {
8614
8652
  advisor: ["read", "grep", "find", "ls", "bash", "intercom"],
@@ -8624,8 +8662,8 @@ var BUILTIN_DEFAULT_TOOLS = {
8624
8662
  function resolveAgentDir() {
8625
8663
  const configured = process.env.PI_CODING_AGENT_DIR;
8626
8664
  if (configured === "~") return homedir();
8627
- if (configured?.startsWith("~/")) return join7(homedir(), configured.slice(2));
8628
- return configured || join7(homedir(), ".pi", "agent");
8665
+ if (configured?.startsWith("~/")) return join8(homedir(), configured.slice(2));
8666
+ return configured || join8(homedir(), ".pi", "agent");
8629
8667
  }
8630
8668
  function desiredTools(existing, name) {
8631
8669
  const base = Array.isArray(existing?.tools) && existing.tools.length > 0 ? [...existing.tools] : [...BUILTIN_DEFAULT_TOOLS[name] ?? []];
@@ -8635,7 +8673,7 @@ function desiredTools(existing, name) {
8635
8673
  return { tools: base, changed: true };
8636
8674
  }
8637
8675
  async function ensureSubagentAcpTools(settingsPath) {
8638
- const path4 = settingsPath ?? join7(resolveAgentDir(), "settings.json");
8676
+ const path4 = settingsPath ?? join8(resolveAgentDir(), "settings.json");
8639
8677
  let raw;
8640
8678
  let mtimeMs;
8641
8679
  try {
@@ -8736,8 +8774,8 @@ import { CONFIG_DIR_NAME } from "@earendil-works/pi-coding-agent";
8736
8774
  async function loadUserConfig(cwd) {
8737
8775
  const home = process.env.HOME ?? "";
8738
8776
  const merged = {};
8739
- for (const base of [join9(home, CONFIG_DIR_NAME), join9(cwd, CONFIG_DIR_NAME)]) {
8740
- const file = join9(base, "acp.json");
8777
+ for (const base of [join10(home, CONFIG_DIR_NAME), join10(cwd, CONFIG_DIR_NAME)]) {
8778
+ const file = join10(base, "acp.json");
8741
8779
  try {
8742
8780
  const raw = await fs3.readFile(file, "utf8");
8743
8781
  const parsed = JSON.parse(raw);
@@ -8750,7 +8788,7 @@ async function loadUserConfig(cwd) {
8750
8788
  }
8751
8789
  return merged;
8752
8790
  }
8753
- function join9(...parts) {
8791
+ function join10(...parts) {
8754
8792
  return path3.join(...parts);
8755
8793
  }
8756
8794
  var KNOWN = /* @__PURE__ */ new Set(["debug", "autoUpdate", "modelContextLimit", "delegate"]);