@arbidocs/cli 0.3.2 → 0.3.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.cjs CHANGED
@@ -2,11 +2,11 @@
2
2
  'use strict';
3
3
 
4
4
  var commander = require('commander');
5
- var core = require('@arbidocs/core');
6
- var prompts = require('@inquirer/prompts');
7
5
  var fs = require('fs');
8
- var path = require('path');
9
6
  var os = require('os');
7
+ var path = require('path');
8
+ var core = require('@arbidocs/core');
9
+ var prompts = require('@inquirer/prompts');
10
10
  var child_process = require('child_process');
11
11
  var sdk = require('@arbidocs/sdk');
12
12
  var module$1 = require('module');
@@ -15,8 +15,8 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentS
15
15
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
16
16
 
17
17
  var fs__default = /*#__PURE__*/_interopDefault(fs);
18
- var path__default = /*#__PURE__*/_interopDefault(path);
19
18
  var os__default = /*#__PURE__*/_interopDefault(os);
19
+ var path__default = /*#__PURE__*/_interopDefault(path);
20
20
 
21
21
  var store = new core.FileConfigStore();
22
22
  function getConfig() {
@@ -53,6 +53,18 @@ function clearChatSession() {
53
53
  }
54
54
 
55
55
  // src/commands/config-cmd.ts
56
+ var ALIAS_LINE = 'alias A="arbi ask"';
57
+ var ALIAS_MARKER = "# arbi-cli alias";
58
+ function getShellRcPath() {
59
+ const shell = process.env.SHELL || "";
60
+ if (shell.includes("zsh")) return path.join(os.homedir(), ".zshrc");
61
+ return path.join(os.homedir(), ".bashrc");
62
+ }
63
+ function isAliasInstalled(rcPath) {
64
+ if (!fs.existsSync(rcPath)) return false;
65
+ const content = fs.readFileSync(rcPath, "utf-8");
66
+ return content.includes(ALIAS_LINE) || content.includes(ALIAS_MARKER);
67
+ }
56
68
  function registerConfigCommand(program2) {
57
69
  const config = program2.command("config").description("Manage CLI configuration");
58
70
  config.command("set-url <url>").description("Set the ARBI server URL").action((url) => {
@@ -80,6 +92,22 @@ function registerConfigCommand(program2) {
80
92
  console.log(`Workspace: ${cfg.selectedWorkspaceId}`);
81
93
  }
82
94
  });
95
+ config.command("alias").description('Set up shell alias A for "arbi ask"').action(() => {
96
+ const rcPath = getShellRcPath();
97
+ if (isAliasInstalled(rcPath)) {
98
+ console.log(`Alias already set up in ${rcPath}`);
99
+ console.log("Usage: A what is the meaning of life");
100
+ return;
101
+ }
102
+ fs.appendFileSync(rcPath, `
103
+ ${ALIAS_MARKER}
104
+ ${ALIAS_LINE}
105
+ `);
106
+ console.log(`Added alias A="arbi ask" to ${rcPath}`);
107
+ console.log("");
108
+ console.log(`Run: source ${rcPath}`);
109
+ console.log("Then: A what is the meaning of life");
110
+ });
83
111
  }
84
112
 
85
113
  // ../../node_modules/fake-indexeddb/build/esm/lib/errors.js
@@ -3395,6 +3423,7 @@ async function promptConfirm(message, defaultValue = true) {
3395
3423
  }
3396
3424
  var CACHE_FILE = path__default.default.join(os__default.default.homedir(), ".arbi", "version-cache.json");
3397
3425
  var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
3426
+ var CHANGELOG_URL = "https://raw.githubusercontent.com/arbitrationcity/ARBI-frontend/refs/tags/{tag}/CHANGELOG.md";
3398
3427
  function readCache() {
3399
3428
  try {
3400
3429
  const data = JSON.parse(fs__default.default.readFileSync(CACHE_FILE, "utf8"));
@@ -3427,21 +3456,64 @@ function getLatestVersion() {
3427
3456
  return null;
3428
3457
  }
3429
3458
  }
3430
- function checkForUpdates(autoUpdate) {
3459
+ function getCurrentVersion() {
3460
+ return "0.3.4";
3461
+ }
3462
+ async function fetchChangelog(fromVersion, toVersion) {
3463
+ try {
3464
+ const url = CHANGELOG_URL.replace("{tag}", `v${toVersion}`);
3465
+ const res = await fetch(url, { signal: AbortSignal.timeout(5e3) });
3466
+ if (!res.ok) return null;
3467
+ const text = await res.text();
3468
+ return extractSections(text, fromVersion, toVersion);
3469
+ } catch {
3470
+ return null;
3471
+ }
3472
+ }
3473
+ function extractSections(changelog, fromVersion, toVersion) {
3474
+ const lines = changelog.split("\n");
3475
+ const sections = [];
3476
+ let capturing = false;
3477
+ for (const line of lines) {
3478
+ const match = line.match(/^## v(.+)/);
3479
+ if (match) {
3480
+ const version = match[1].trim();
3481
+ if (version === fromVersion) {
3482
+ break;
3483
+ }
3484
+ if (version === toVersion || capturing) {
3485
+ capturing = true;
3486
+ }
3487
+ }
3488
+ if (capturing) {
3489
+ sections.push(line);
3490
+ }
3491
+ }
3492
+ const result = sections.join("\n").trim();
3493
+ return result || null;
3494
+ }
3495
+ async function showChangelog(fromVersion, toVersion) {
3496
+ const changelog = await fetchChangelog(fromVersion, toVersion);
3497
+ if (changelog) {
3498
+ console.log("\n" + changelog);
3499
+ }
3500
+ }
3501
+ async function checkForUpdates(autoUpdate) {
3431
3502
  try {
3432
3503
  const latest = getLatestVersion();
3433
- if (!latest || latest === "0.3.2") return;
3504
+ if (!latest || latest === "0.3.4") return;
3434
3505
  if (autoUpdate) {
3435
3506
  console.log(
3436
3507
  `
3437
- Your arbi version is out of date (${"0.3.2"} \u2192 ${latest}). Updating...`
3508
+ Your arbi version is out of date (${"0.3.4"} \u2192 ${latest}). Updating...`
3438
3509
  );
3510
+ await showChangelog("0.3.4", latest);
3439
3511
  child_process.execSync("npm install -g @arbidocs/cli@latest", { stdio: "inherit" });
3440
3512
  console.log(`Updated to ${latest}.`);
3441
3513
  } else {
3442
3514
  console.error(
3443
3515
  `
3444
- Your arbi version is out of date (${"0.3.2"} \u2192 ${latest}).
3516
+ Your arbi version is out of date (${"0.3.4"} \u2192 ${latest}).
3445
3517
  Run "arbi update" to upgrade, or "arbi update auto" to always stay up to date.`
3446
3518
  );
3447
3519
  }
@@ -3451,9 +3523,9 @@ Run "arbi update" to upgrade, or "arbi update auto" to always stay up to date.`
3451
3523
  function hintUpdateOnError() {
3452
3524
  try {
3453
3525
  const cached = readCache();
3454
- if (cached && cached.latest !== "0.3.2") {
3526
+ if (cached && cached.latest !== "0.3.4") {
3455
3527
  console.error(
3456
- `Your arbi version is out of date (${"0.3.2"} \u2192 ${cached.latest}). Run "arbi update".`
3528
+ `Your arbi version is out of date (${"0.3.4"} \u2192 ${cached.latest}). Run "arbi update".`
3457
3529
  );
3458
3530
  }
3459
3531
  } catch {
@@ -3495,11 +3567,12 @@ function registerLoginCommand(program2) {
3495
3567
  updateConfig({ selectedWorkspaceId: selected });
3496
3568
  const ws = wsList.find((w) => w.external_id === selected);
3497
3569
  console.log(`Workspace: ${ws.name} (${selected})`);
3570
+ console.log('\nTip: Run "arbi config alias" to use A as a shortcut for "arbi ask"');
3498
3571
  } catch (err) {
3499
3572
  console.error(`Login failed: ${core.getErrorMessage(err)}`);
3500
3573
  process.exit(1);
3501
3574
  } finally {
3502
- checkForUpdates(getConfig()?.autoUpdate);
3575
+ await checkForUpdates(getConfig()?.autoUpdate);
3503
3576
  }
3504
3577
  });
3505
3578
  }
@@ -3520,56 +3593,65 @@ async function getVerificationCode(email, apiKey) {
3520
3593
  return Array.isArray(words) ? words.join(" ") : String(words);
3521
3594
  }
3522
3595
  function registerRegisterCommand(program2) {
3523
- program2.command("register").description("Register a new ARBI account").option("--non-interactive", "CI/automation mode (requires SUPPORT_API_KEY env var)").option("-e, --email <email>", "Email address (or ARBI_EMAIL env var)").option("-p, --password <password>", "Password (or ARBI_PASSWORD env var)").option("--first-name <name>", "First name").option("--last-name <name>", "Last name").action(
3524
- async (opts) => {
3525
- const config = requireConfig();
3526
- if (opts.nonInteractive) {
3527
- await nonInteractiveRegister(config, opts);
3528
- } else {
3529
- await interactiveRegister(config, opts);
3530
- }
3596
+ program2.command("register").description("Register a new ARBI account").option("--non-interactive", "CI/automation mode (requires SUPPORT_API_KEY env var)").option("-e, --email <email>", "Email address (or ARBI_EMAIL env var)").option("-p, --password <password>", "Password (or ARBI_PASSWORD env var)").option("-c, --verification-code <code>", "Verification code (skip prompt)").option("--first-name <name>", "First name").option("--last-name <name>", "Last name").action(async (opts) => {
3597
+ const config = requireConfig();
3598
+ if (opts.nonInteractive) {
3599
+ await nonInteractiveRegister(config, opts);
3600
+ } else {
3601
+ await smartRegister(config, opts);
3531
3602
  }
3532
- );
3603
+ });
3533
3604
  }
3534
- async function interactiveRegister(config, opts) {
3535
- const email = opts.email || await promptInput("Email");
3605
+ async function smartRegister(config, opts) {
3606
+ const email = opts.email || process.env.ARBI_EMAIL || await promptInput("Email");
3536
3607
  const arbi = sdk.createArbiClient({
3537
3608
  baseUrl: config.baseUrl,
3538
3609
  deploymentDomain: config.deploymentDomain,
3539
3610
  credentials: "omit"
3540
3611
  });
3541
3612
  await arbi.crypto.initSodium();
3542
- const codeMethod = await promptSelect("Verification method", [
3543
- { name: "I have an invitation code", value: "code" },
3544
- { name: "Send me a verification email", value: "email" }
3545
- ]);
3546
3613
  let verificationCode;
3547
- if (codeMethod === "code") {
3548
- verificationCode = await promptInput("Invitation code");
3614
+ if (opts.verificationCode) {
3615
+ verificationCode = opts.verificationCode;
3549
3616
  } else {
3550
- console.log("Sending verification email...");
3551
- const verifyResponse = await arbi.fetch.POST("/api/user/verify-email", {
3552
- body: { email }
3553
- });
3554
- if (verifyResponse.error) {
3555
- console.error(`Failed to send verification email: ${JSON.stringify(verifyResponse.error)}`);
3556
- process.exit(1);
3617
+ const codeMethod = await promptSelect("Verification method", [
3618
+ { name: "I have an invitation code", value: "code" },
3619
+ { name: "Send me a verification email", value: "email" }
3620
+ ]);
3621
+ if (codeMethod === "code") {
3622
+ verificationCode = await promptInput("Invitation code");
3623
+ } else {
3624
+ console.log("Sending verification email...");
3625
+ const verifyResponse = await arbi.fetch.POST("/api/user/verify-email", {
3626
+ body: { email }
3627
+ });
3628
+ if (verifyResponse.error) {
3629
+ console.error(`Failed to send verification email: ${JSON.stringify(verifyResponse.error)}`);
3630
+ process.exit(1);
3631
+ }
3632
+ console.log("Verification email sent. Check your inbox.");
3633
+ verificationCode = await promptInput("Verification code");
3557
3634
  }
3558
- console.log("Verification email sent. Check your inbox.");
3559
- verificationCode = await promptInput("Verification code");
3560
3635
  }
3561
- const password2 = opts.password || await promptPassword("Password");
3562
- const confirmPw = await promptPassword("Confirm password");
3563
- if (password2 !== confirmPw) {
3564
- console.error("Passwords do not match.");
3565
- process.exit(1);
3636
+ let pw;
3637
+ const flagOrEnvPassword = opts.password || process.env.ARBI_PASSWORD;
3638
+ if (flagOrEnvPassword) {
3639
+ pw = flagOrEnvPassword;
3640
+ } else {
3641
+ pw = await promptPassword("Password");
3642
+ const confirmPw = await promptPassword("Confirm password");
3643
+ if (pw !== confirmPw) {
3644
+ console.error("Passwords do not match.");
3645
+ process.exit(1);
3646
+ }
3566
3647
  }
3567
- const firstName = opts.firstName || await promptInput("First name", false) || "User";
3568
- const lastName = opts.lastName || await promptInput("Last name", false) || "";
3648
+ const hasAllCoreFlags = !!(opts.email || process.env.ARBI_EMAIL) && !!(opts.password || process.env.ARBI_PASSWORD) && !!opts.verificationCode;
3649
+ const firstName = opts.firstName || (hasAllCoreFlags ? "User" : await promptInput("First name", false) || "User");
3650
+ const lastName = opts.lastName || (hasAllCoreFlags ? "" : await promptInput("Last name", false) || "");
3569
3651
  try {
3570
3652
  await arbi.auth.register({
3571
3653
  email,
3572
- password: password2,
3654
+ password: pw,
3573
3655
  verificationCode,
3574
3656
  firstName,
3575
3657
  lastName
@@ -3580,27 +3662,10 @@ Registered successfully as ${email}`);
3580
3662
  console.error(`Registration failed: ${core.getErrorMessage(err)}`);
3581
3663
  process.exit(1);
3582
3664
  }
3583
- const doLogin = await promptConfirm("Log in now?");
3665
+ const allFlagsProvided = !!(opts.email || process.env.ARBI_EMAIL) && !!(opts.password || process.env.ARBI_PASSWORD) && !!opts.verificationCode;
3666
+ const doLogin = allFlagsProvided || await promptConfirm("Log in now?");
3584
3667
  if (doLogin) {
3585
- try {
3586
- const { arbi: loggedInArbi } = await core.performPasswordLogin(config, email, password2, store);
3587
- const { data: workspaces2 } = await loggedInArbi.fetch.GET("/api/user/workspaces");
3588
- const wsList = workspaces2 || [];
3589
- console.log(`Logged in as ${email}`);
3590
- if (wsList.length === 1) {
3591
- updateConfig({ selectedWorkspaceId: wsList[0].external_id });
3592
- console.log(`Workspace: ${wsList[0].name} (${wsList[0].external_id})`);
3593
- } else if (wsList.length > 1) {
3594
- const choices = core.formatWorkspaceChoices(wsList);
3595
- const selected = await promptSelect("Select workspace", choices);
3596
- updateConfig({ selectedWorkspaceId: selected });
3597
- const ws = wsList.find((w) => w.external_id === selected);
3598
- console.log(`Workspace: ${ws.name} (${selected})`);
3599
- }
3600
- } catch (err) {
3601
- console.error(`Login failed: ${core.getErrorMessage(err)}`);
3602
- console.error("You can log in later with: arbi login");
3603
- }
3668
+ await loginAfterRegister(config, email, pw);
3604
3669
  }
3605
3670
  }
3606
3671
  async function nonInteractiveRegister(config, opts) {
@@ -3615,24 +3680,31 @@ async function nonInteractiveRegister(config, opts) {
3615
3680
  console.error("Password required. Use --password <password> or set ARBI_PASSWORD");
3616
3681
  process.exit(1);
3617
3682
  }
3618
- if (!supportApiKey) {
3619
- console.error("SUPPORT_API_KEY env var is required for --non-interactive registration");
3620
- process.exit(1);
3621
- }
3622
3683
  const arbi = sdk.createArbiClient({
3623
3684
  baseUrl: config.baseUrl,
3624
3685
  deploymentDomain: config.deploymentDomain,
3625
3686
  credentials: "omit"
3626
3687
  });
3627
3688
  await arbi.crypto.initSodium();
3628
- const verifyResponse = await arbi.fetch.POST("/api/user/verify-email", {
3629
- body: { email }
3630
- });
3631
- if (verifyResponse.error) {
3632
- console.error(`verify-email failed: ${JSON.stringify(verifyResponse.error)}`);
3633
- process.exit(1);
3689
+ let verificationCode;
3690
+ if (opts.verificationCode) {
3691
+ verificationCode = opts.verificationCode;
3692
+ } else {
3693
+ if (!supportApiKey) {
3694
+ console.error(
3695
+ "Verification code required. Use --verification-code <code> or set SUPPORT_API_KEY for CI mode"
3696
+ );
3697
+ process.exit(1);
3698
+ }
3699
+ const verifyResponse = await arbi.fetch.POST("/api/user/verify-email", {
3700
+ body: { email }
3701
+ });
3702
+ if (verifyResponse.error) {
3703
+ console.error(`verify-email failed: ${JSON.stringify(verifyResponse.error)}`);
3704
+ process.exit(1);
3705
+ }
3706
+ verificationCode = await getVerificationCode(email, supportApiKey);
3634
3707
  }
3635
- const verificationCode = await getVerificationCode(email, supportApiKey);
3636
3708
  try {
3637
3709
  await arbi.auth.register({
3638
3710
  email,
@@ -3647,6 +3719,34 @@ async function nonInteractiveRegister(config, opts) {
3647
3719
  process.exit(1);
3648
3720
  }
3649
3721
  }
3722
+ async function loginAfterRegister(config, email, password2) {
3723
+ try {
3724
+ const { arbi } = await core.performPasswordLogin(config, email, password2, store);
3725
+ console.log(`Logged in as ${email}`);
3726
+ const { data: workspaces2 } = await arbi.fetch.GET("/api/user/workspaces");
3727
+ const wsList = workspaces2 || [];
3728
+ if (wsList.length === 0) {
3729
+ console.log("Creating your first workspace...");
3730
+ const ws2 = await core.workspaces.createWorkspace(arbi, "My First Workspace");
3731
+ updateConfig({ selectedWorkspaceId: ws2.external_id });
3732
+ console.log(`Workspace: ${ws2.name} (${ws2.external_id})`);
3733
+ return;
3734
+ }
3735
+ if (wsList.length === 1) {
3736
+ updateConfig({ selectedWorkspaceId: wsList[0].external_id });
3737
+ console.log(`Workspace: ${wsList[0].name} (${wsList[0].external_id})`);
3738
+ return;
3739
+ }
3740
+ const choices = core.formatWorkspaceChoices(wsList);
3741
+ const selected = await promptSelect("Select workspace", choices);
3742
+ updateConfig({ selectedWorkspaceId: selected });
3743
+ const ws = wsList.find((w) => w.external_id === selected);
3744
+ console.log(`Workspace: ${ws.name} (${selected})`);
3745
+ } catch (err) {
3746
+ console.error(`Login failed: ${core.getErrorMessage(err)}`);
3747
+ console.error("You can log in later with: arbi login");
3748
+ }
3749
+ }
3650
3750
 
3651
3751
  // src/commands/logout.ts
3652
3752
  function registerLogoutCommand(program2) {
@@ -5047,17 +5147,19 @@ function registerTuiCommand(program2) {
5047
5147
  });
5048
5148
  }
5049
5149
  function registerUpdateCommand(program2) {
5050
- const update = program2.command("update").description("Update ARBI CLI to the latest version").action(() => {
5051
- console.log(`Current version: ${"0.3.2"}`);
5150
+ const update = program2.command("update").description("Update ARBI CLI to the latest version").action(async () => {
5151
+ const current = getCurrentVersion();
5152
+ console.log(`Current version: ${current}`);
5052
5153
  console.log("Checking for updates...\n");
5053
5154
  try {
5054
- const latest = child_process.execSync("npm view @arbidocs/cli version", { encoding: "utf8" }).trim();
5055
- if (latest === "0.3.2") {
5155
+ const latest = getLatestVersion() || child_process.execSync("npm view @arbidocs/cli version", { encoding: "utf8" }).trim();
5156
+ if (latest === current) {
5056
5157
  console.log("Already up to date.");
5057
5158
  return;
5058
5159
  }
5059
5160
  console.log(`New version available: ${latest}`);
5060
- console.log("Updating...\n");
5161
+ await showChangelog(current, latest);
5162
+ console.log("\nUpdating...\n");
5061
5163
  child_process.execSync("npm install -g @arbidocs/cli@latest", { stdio: "inherit" });
5062
5164
  console.log(`
5063
5165
  Updated to ${latest}.`);
@@ -5084,7 +5186,7 @@ console.info = (...args) => {
5084
5186
  _origInfo(...args);
5085
5187
  };
5086
5188
  var program = new commander.Command();
5087
- program.name("arbi").description("ARBI CLI \u2014 interact with ARBI from the terminal").version("0.3.2");
5189
+ program.name("arbi").description("ARBI CLI \u2014 interact with ARBI from the terminal").version("0.3.4");
5088
5190
  registerConfigCommand(program);
5089
5191
  registerLoginCommand(program);
5090
5192
  registerRegisterCommand(program);