bitfab-cli 0.2.9 → 0.2.10

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.
Files changed (2) hide show
  1. package/dist/index.js +66 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6839,6 +6839,7 @@ var GLOBAL_CONFIG_DIR = path3.join(os3.homedir(), ".config", "bitfab");
6839
6839
  var GLOBAL_CONFIG_FILE = path3.join(GLOBAL_CONFIG_DIR, "config.json");
6840
6840
  var GLOBAL_CREDENTIALS_FILE = path3.join(GLOBAL_CONFIG_DIR, "credentials.json");
6841
6841
  var PROJECT_CONFIG_RELATIVE = path3.join(".bitfab", "config.local.json");
6842
+ var PROJECT_CREDENTIALS_RELATIVE = path3.join(".bitfab", "credentials.local.json");
6842
6843
  function readJsonFile(filePath) {
6843
6844
  try {
6844
6845
  const content = fs3.readFileSync(filePath, "utf-8");
@@ -6847,10 +6848,10 @@ function readJsonFile(filePath) {
6847
6848
  return null;
6848
6849
  }
6849
6850
  }
6850
- function findProjectConfigPath(startDir = process.cwd()) {
6851
+ function findProjectFile(relativePath, startDir = process.cwd()) {
6851
6852
  let dir = startDir;
6852
6853
  while (true) {
6853
- const candidate = path3.join(dir, PROJECT_CONFIG_RELATIVE);
6854
+ const candidate = path3.join(dir, relativePath);
6854
6855
  if (fs3.existsSync(candidate)) {
6855
6856
  return candidate;
6856
6857
  }
@@ -6862,12 +6863,19 @@ function findProjectConfigPath(startDir = process.cwd()) {
6862
6863
  }
6863
6864
  }
6864
6865
  function getProjectConfigData() {
6865
- const filePath = findProjectConfigPath();
6866
+ const filePath = findProjectFile(PROJECT_CONFIG_RELATIVE);
6866
6867
  if (!filePath) {
6867
6868
  return null;
6868
6869
  }
6869
6870
  return readJsonFile(filePath);
6870
6871
  }
6872
+ function getProjectCredentialsData() {
6873
+ const filePath = findProjectFile(PROJECT_CREDENTIALS_RELATIVE);
6874
+ if (!filePath) {
6875
+ return null;
6876
+ }
6877
+ return readJsonFile(filePath) ?? {};
6878
+ }
6871
6879
  function getConfigData() {
6872
6880
  return readJsonFile(GLOBAL_CONFIG_FILE) ?? {};
6873
6881
  }
@@ -6889,6 +6897,10 @@ function getApiKey() {
6889
6897
  if (process.env.BITFAB_API_KEY) {
6890
6898
  return process.env.BITFAB_API_KEY;
6891
6899
  }
6900
+ const projectCreds = getProjectCredentialsData();
6901
+ if (projectCreds !== null) {
6902
+ return typeof projectCreds.apiKey === "string" ? projectCreds.apiKey : null;
6903
+ }
6892
6904
  const creds = getCredentialsData();
6893
6905
  return typeof creds.apiKey === "string" ? creds.apiKey : null;
6894
6906
  }
@@ -27312,6 +27324,47 @@ function runLogoutCommand() {
27312
27324
  runLogout();
27313
27325
  }
27314
27326
 
27327
+ // src/updateCheck.ts
27328
+ var NPM_REGISTRY_URL = "https://registry.npmjs.org/bitfab-cli/latest";
27329
+ var TIMEOUT_MS = 3e3;
27330
+ function isNewer(latest, current) {
27331
+ const parse3 = (v) => v.split(".").map(Number);
27332
+ const [lMaj = 0, lMin = 0, lPat = 0] = parse3(latest);
27333
+ const [cMaj = 0, cMin = 0, cPat = 0] = parse3(current);
27334
+ if (lMaj !== cMaj) {
27335
+ return lMaj > cMaj;
27336
+ }
27337
+ if (lMin !== cMin) {
27338
+ return lMin > cMin;
27339
+ }
27340
+ return lPat > cPat;
27341
+ }
27342
+ function startUpdateCheck() {
27343
+ const controller = new AbortController();
27344
+ const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
27345
+ const current = getVersion();
27346
+ const done = fetch(NPM_REGISTRY_URL, { signal: controller.signal }).then(
27347
+ (res) => res.ok ? res.json() : null
27348
+ ).then((data) => {
27349
+ const latest = data?.version;
27350
+ if (latest && isNewer(latest, current)) {
27351
+ process.stderr.write(
27352
+ `
27353
+ Update available: ${current} -> ${latest}
27354
+ Run \`npx bitfab-cli@latest\` to get the newest version.
27355
+
27356
+ `
27357
+ );
27358
+ }
27359
+ }).catch(() => {
27360
+ }).finally(() => clearTimeout(timer));
27361
+ return () => {
27362
+ controller.abort();
27363
+ done.catch(() => {
27364
+ });
27365
+ };
27366
+ }
27367
+
27315
27368
  // src/index.ts
27316
27369
  var HELP_TEXT = `Usage: bitfab <command> [options]
27317
27370
 
@@ -27367,41 +27420,51 @@ async function main() {
27367
27420
  const { command, editor, skipPermissions, rest } = parseArgs(
27368
27421
  process.argv.slice(2)
27369
27422
  );
27423
+ const abortUpdateCheck = startUpdateCheck();
27370
27424
  if (!command || command === "help" || command === "--help" || command === "-h") {
27371
27425
  process.stdout.write(HELP_TEXT);
27426
+ abortUpdateCheck();
27372
27427
  return;
27373
27428
  }
27374
27429
  if (command === "init") {
27375
27430
  await runInit({ editor, skipPermissions });
27431
+ abortUpdateCheck();
27376
27432
  return;
27377
27433
  }
27378
27434
  if (command === "plugin-install") {
27379
27435
  await runInstall({ editor, skipPermissions });
27436
+ abortUpdateCheck();
27380
27437
  return;
27381
27438
  }
27382
27439
  if (command === "login") {
27383
27440
  await runLoginCommand();
27441
+ abortUpdateCheck();
27384
27442
  return;
27385
27443
  }
27386
27444
  if (command === "logout") {
27387
27445
  runLogoutCommand();
27446
+ abortUpdateCheck();
27388
27447
  return;
27389
27448
  }
27390
27449
  if (command === "setup") {
27391
27450
  await runSetup({ editor, skipPermissions });
27451
+ abortUpdateCheck();
27392
27452
  return;
27393
27453
  }
27394
27454
  if (command === "assistant") {
27395
27455
  await runAssistant({ editor, skipPermissions }, rest);
27456
+ abortUpdateCheck();
27396
27457
  return;
27397
27458
  }
27398
27459
  if (command === "update") {
27399
27460
  await runUpdate2({ editor, skipPermissions }, rest);
27461
+ abortUpdateCheck();
27400
27462
  return;
27401
27463
  }
27402
27464
  process.stderr.write(`Unknown command: ${command}
27403
27465
 
27404
27466
  ${HELP_TEXT}`);
27467
+ abortUpdateCheck();
27405
27468
  process.exit(1);
27406
27469
  }
27407
27470
  main().catch((err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bitfab-cli",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "description": "Install and configure the Bitfab plugin in Claude Code, Codex, or Cursor.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",