@arbidocs/cli 0.3.3 → 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
@@ -3429,7 +3457,7 @@ function getLatestVersion() {
3429
3457
  }
3430
3458
  }
3431
3459
  function getCurrentVersion() {
3432
- return "0.3.3";
3460
+ return "0.3.4";
3433
3461
  }
3434
3462
  async function fetchChangelog(fromVersion, toVersion) {
3435
3463
  try {
@@ -3473,19 +3501,19 @@ async function showChangelog(fromVersion, toVersion) {
3473
3501
  async function checkForUpdates(autoUpdate) {
3474
3502
  try {
3475
3503
  const latest = getLatestVersion();
3476
- if (!latest || latest === "0.3.3") return;
3504
+ if (!latest || latest === "0.3.4") return;
3477
3505
  if (autoUpdate) {
3478
3506
  console.log(
3479
3507
  `
3480
- Your arbi version is out of date (${"0.3.3"} \u2192 ${latest}). Updating...`
3508
+ Your arbi version is out of date (${"0.3.4"} \u2192 ${latest}). Updating...`
3481
3509
  );
3482
- await showChangelog("0.3.3", latest);
3510
+ await showChangelog("0.3.4", latest);
3483
3511
  child_process.execSync("npm install -g @arbidocs/cli@latest", { stdio: "inherit" });
3484
3512
  console.log(`Updated to ${latest}.`);
3485
3513
  } else {
3486
3514
  console.error(
3487
3515
  `
3488
- Your arbi version is out of date (${"0.3.3"} \u2192 ${latest}).
3516
+ Your arbi version is out of date (${"0.3.4"} \u2192 ${latest}).
3489
3517
  Run "arbi update" to upgrade, or "arbi update auto" to always stay up to date.`
3490
3518
  );
3491
3519
  }
@@ -3495,9 +3523,9 @@ Run "arbi update" to upgrade, or "arbi update auto" to always stay up to date.`
3495
3523
  function hintUpdateOnError() {
3496
3524
  try {
3497
3525
  const cached = readCache();
3498
- if (cached && cached.latest !== "0.3.3") {
3526
+ if (cached && cached.latest !== "0.3.4") {
3499
3527
  console.error(
3500
- `Your arbi version is out of date (${"0.3.3"} \u2192 ${cached.latest}). Run "arbi update".`
3528
+ `Your arbi version is out of date (${"0.3.4"} \u2192 ${cached.latest}). Run "arbi update".`
3501
3529
  );
3502
3530
  }
3503
3531
  } catch {
@@ -3539,6 +3567,7 @@ function registerLoginCommand(program2) {
3539
3567
  updateConfig({ selectedWorkspaceId: selected });
3540
3568
  const ws = wsList.find((w) => w.external_id === selected);
3541
3569
  console.log(`Workspace: ${ws.name} (${selected})`);
3570
+ console.log('\nTip: Run "arbi config alias" to use A as a shortcut for "arbi ask"');
3542
3571
  } catch (err) {
3543
3572
  console.error(`Login failed: ${core.getErrorMessage(err)}`);
3544
3573
  process.exit(1);
@@ -3564,7 +3593,7 @@ async function getVerificationCode(email, apiKey) {
3564
3593
  return Array.isArray(words) ? words.join(" ") : String(words);
3565
3594
  }
3566
3595
  function registerRegisterCommand(program2) {
3567
- 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").option("-w, --workspace <id>", "Workspace ID to select after login").action(async (opts) => {
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) => {
3568
3597
  const config = requireConfig();
3569
3598
  if (opts.nonInteractive) {
3570
3599
  await nonInteractiveRegister(config, opts);
@@ -3636,7 +3665,7 @@ Registered successfully as ${email}`);
3636
3665
  const allFlagsProvided = !!(opts.email || process.env.ARBI_EMAIL) && !!(opts.password || process.env.ARBI_PASSWORD) && !!opts.verificationCode;
3637
3666
  const doLogin = allFlagsProvided || await promptConfirm("Log in now?");
3638
3667
  if (doLogin) {
3639
- await loginAfterRegister(config, email, pw, opts.workspace);
3668
+ await loginAfterRegister(config, email, pw);
3640
3669
  }
3641
3670
  }
3642
3671
  async function nonInteractiveRegister(config, opts) {
@@ -3690,33 +3719,29 @@ async function nonInteractiveRegister(config, opts) {
3690
3719
  process.exit(1);
3691
3720
  }
3692
3721
  }
3693
- async function loginAfterRegister(config, email, password2, workspaceId) {
3722
+ async function loginAfterRegister(config, email, password2) {
3694
3723
  try {
3695
3724
  const { arbi } = await core.performPasswordLogin(config, email, password2, store);
3725
+ console.log(`Logged in as ${email}`);
3696
3726
  const { data: workspaces2 } = await arbi.fetch.GET("/api/user/workspaces");
3697
3727
  const wsList = workspaces2 || [];
3698
- console.log(`Logged in as ${email}`);
3699
- if (wsList.length === 0) return;
3700
- if (workspaceId) {
3701
- const ws = wsList.find((w) => w.external_id === workspaceId);
3702
- if (ws) {
3703
- updateConfig({ selectedWorkspaceId: ws.external_id });
3704
- console.log(`Workspace: ${ws.name} (${ws.external_id})`);
3705
- } else {
3706
- console.error(`Workspace ${workspaceId} not found.`);
3707
- }
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})`);
3708
3733
  return;
3709
3734
  }
3710
3735
  if (wsList.length === 1) {
3711
3736
  updateConfig({ selectedWorkspaceId: wsList[0].external_id });
3712
3737
  console.log(`Workspace: ${wsList[0].name} (${wsList[0].external_id})`);
3713
- } else if (wsList.length > 1) {
3714
- const choices = core.formatWorkspaceChoices(wsList);
3715
- const selected = await promptSelect("Select workspace", choices);
3716
- updateConfig({ selectedWorkspaceId: selected });
3717
- const ws = wsList.find((w) => w.external_id === selected);
3718
- console.log(`Workspace: ${ws.name} (${selected})`);
3738
+ return;
3719
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})`);
3720
3745
  } catch (err) {
3721
3746
  console.error(`Login failed: ${core.getErrorMessage(err)}`);
3722
3747
  console.error("You can log in later with: arbi login");
@@ -5161,7 +5186,7 @@ console.info = (...args) => {
5161
5186
  _origInfo(...args);
5162
5187
  };
5163
5188
  var program = new commander.Command();
5164
- program.name("arbi").description("ARBI CLI \u2014 interact with ARBI from the terminal").version("0.3.3");
5189
+ program.name("arbi").description("ARBI CLI \u2014 interact with ARBI from the terminal").version("0.3.4");
5165
5190
  registerConfigCommand(program);
5166
5191
  registerLoginCommand(program);
5167
5192
  registerRegisterCommand(program);