@robinpath/cli 3.4.1 → 3.5.1

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/cli.mjs +148 -158
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -18598,7 +18598,7 @@ function getNativeModules() {
18598
18598
  import { join as join3, basename as basename2 } from "node:path";
18599
18599
  import { homedir as homedir2, platform as platform2 } from "node:os";
18600
18600
  import { existsSync as existsSync2 } from "node:fs";
18601
- var CLI_VERSION = true ? "3.4.1" : "3.4.1";
18601
+ var CLI_VERSION = true ? "3.5.1" : "3.5.1";
18602
18602
  var FLAG_QUIET = false;
18603
18603
  var FLAG_VERBOSE = false;
18604
18604
  var FLAG_AUTO_ACCEPT = false;
@@ -28495,6 +28495,64 @@ async function handleSaveRun(content, prompt, { save, run, outFile }) {
28495
28495
  console.log(content);
28496
28496
  }
28497
28497
  }
28498
+ function arrowSelect(options) {
28499
+ return new Promise((resolve13) => {
28500
+ if (!process.stdin.isTTY) {
28501
+ resolve13(0);
28502
+ return;
28503
+ }
28504
+ let selected = 0;
28505
+ function render2() {
28506
+ process.stdout.write("\x1B[2K\r");
28507
+ for (let i = 0; i < options.length; i++) {
28508
+ if (i > 0) process.stdout.write("\n\x1B[2K");
28509
+ const marker = i === selected ? color.cyan(" \u276F ") : " ";
28510
+ const text = i === selected ? color.bold(options[i]) : options[i];
28511
+ process.stdout.write(`${marker}${text}`);
28512
+ }
28513
+ if (options.length > 1) process.stdout.write(`\x1B[${options.length - 1}A\r`);
28514
+ }
28515
+ render2();
28516
+ process.stdin.setRawMode(true);
28517
+ process.stdin.resume();
28518
+ const onKey = (buf) => {
28519
+ const key = buf.toString();
28520
+ if (key === "\x1B[A") {
28521
+ selected = Math.max(0, selected - 1);
28522
+ render2();
28523
+ return;
28524
+ }
28525
+ if (key === "\x1B[B") {
28526
+ selected = Math.min(options.length - 1, selected + 1);
28527
+ render2();
28528
+ return;
28529
+ }
28530
+ if (key === "\r" || key === "\n") {
28531
+ process.stdin.removeListener("data", onKey);
28532
+ try {
28533
+ process.stdin.setRawMode(false);
28534
+ } catch {
28535
+ }
28536
+ process.stdin.pause();
28537
+ process.stdout.write("\n".repeat(options.length));
28538
+ resolve13(selected);
28539
+ return;
28540
+ }
28541
+ if (key === "\x1B" || key === "") {
28542
+ process.stdin.removeListener("data", onKey);
28543
+ try {
28544
+ process.stdin.setRawMode(false);
28545
+ } catch {
28546
+ }
28547
+ process.stdin.pause();
28548
+ process.stdout.write("\n".repeat(options.length));
28549
+ resolve13(options.length - 1);
28550
+ return;
28551
+ }
28552
+ };
28553
+ process.stdin.on("data", onKey);
28554
+ });
28555
+ }
28498
28556
  async function main() {
28499
28557
  const args = process.argv.slice(2);
28500
28558
  setFlags({
@@ -28721,171 +28779,103 @@ async function main() {
28721
28779
  return;
28722
28780
  }
28723
28781
  checkForUpdates();
28724
- const auth = readAuth();
28725
- if (!auth && process.stdin.isTTY) {
28726
- console.log("");
28727
- console.log(color.bold(" Welcome to RobinPath!"));
28728
- console.log("");
28729
- console.log(" To unlock AI assistant, deploy, snippets, and sync \u2014");
28730
- console.log(" please login to your RobinPath account.");
28731
- console.log("");
28732
- console.log(" Without login you can still:");
28733
- console.log(` ${color.dim("\u2022")} Run scripts: ${color.cyan("robinpath script.rp")}`);
28734
- console.log(` ${color.dim("\u2022")} Format code: ${color.cyan("robinpath fmt file.rp")}`);
28735
- console.log(` ${color.dim("\u2022")} Run tests: ${color.cyan("robinpath test")}`);
28736
- console.log(` ${color.dim("\u2022")} Install modules: ${color.cyan("robinpath add @robinpath/csv")}`);
28737
- console.log("");
28738
- const choice = await new Promise((resolve13) => {
28739
- if (!process.stdin.isTTY) {
28740
- resolve13("skip");
28782
+ if (process.stdin.isTTY) {
28783
+ const auth = readAuth();
28784
+ if (!auth) {
28785
+ console.log("");
28786
+ console.log(color.bold(" Welcome to RobinPath!"));
28787
+ console.log("");
28788
+ console.log(" Login to unlock AI assistant, deploy, snippets, and sync.");
28789
+ console.log(color.dim(" Without login: run scripts, fmt, test, and install modules."));
28790
+ console.log("");
28791
+ const choice = await arrowSelect(["Login", "Skip for now"]);
28792
+ if (choice === 0) {
28793
+ await handleLogin();
28794
+ } else {
28795
+ console.log(color.dim(" Run ") + color.cyan("robinpath login") + color.dim(" anytime."));
28796
+ console.log("");
28741
28797
  return;
28742
28798
  }
28743
- let selected = 0;
28744
- const options = ["Login", "Skip for now"];
28745
- function render2() {
28746
- process.stdout.write("\x1B[2K\r");
28747
- for (let i = 0; i < options.length; i++) {
28748
- if (i > 0) process.stdout.write("\n\x1B[2K");
28749
- const marker = i === selected ? color.cyan(" \u276F ") : " ";
28750
- const text = i === selected ? color.bold(options[i]) : options[i];
28751
- process.stdout.write(`${marker}${text}`);
28752
- }
28753
- if (options.length > 1) process.stdout.write(`\x1B[${options.length - 1}A`);
28754
- process.stdout.write("\r");
28755
- }
28756
- render2();
28757
- process.stdin.setRawMode(true);
28758
- process.stdin.resume();
28759
- const onKey = (buf) => {
28760
- const key = buf.toString();
28761
- if (key === "\x1B[A") {
28762
- selected = 0;
28763
- render2();
28764
- return;
28765
- }
28766
- if (key === "\x1B[B") {
28767
- selected = 1;
28768
- render2();
28769
- return;
28770
- }
28771
- if (key === "\r" || key === "\n") {
28772
- process.stdin.removeListener("data", onKey);
28773
- try {
28774
- process.stdin.setRawMode(false);
28775
- } catch {
28799
+ }
28800
+ const config = readAiConfig();
28801
+ if (!config.apiKey) {
28802
+ console.log("");
28803
+ console.log(color.green(" \u2713") + " Logged in!");
28804
+ console.log("");
28805
+ console.log(" Connect your OpenRouter API key to use the AI:");
28806
+ console.log("");
28807
+ console.log(color.bold(" 1.") + " Go to " + color.cyan("https://openrouter.ai/keys"));
28808
+ console.log(color.bold(" 2.") + " Create a key and copy it");
28809
+ console.log(color.bold(" 3.") + " Paste it below:");
28810
+ console.log("");
28811
+ const apiKey = await new Promise((resolve13) => {
28812
+ process.stdout.write(color.cyan(" API key: "));
28813
+ process.stdin.setRawMode(true);
28814
+ process.stdin.resume();
28815
+ let input = "";
28816
+ function redraw() {
28817
+ process.stdout.write("\r\x1B[2K");
28818
+ if (input.length === 0) {
28819
+ process.stdout.write(color.cyan(" API key: "));
28820
+ } else if (input.length <= 8) {
28821
+ process.stdout.write(color.cyan(" API key: ") + color.dim(input));
28822
+ } else {
28823
+ const prefix = input.slice(0, 8);
28824
+ const masked = "\u2022".repeat(Math.min(input.length - 8, 20));
28825
+ const suffix = input.length > 10 ? input.slice(-3) : "";
28826
+ process.stdout.write(color.cyan(" API key: ") + color.dim(prefix + masked + suffix));
28776
28827
  }
28777
- process.stdin.pause();
28778
- process.stdout.write("\n".repeat(options.length));
28779
- resolve13(selected === 0 ? "login" : "skip");
28780
- return;
28781
28828
  }
28782
- if (key === "\x1B" || key === "") {
28783
- process.stdin.removeListener("data", onKey);
28784
- try {
28785
- process.stdin.setRawMode(false);
28786
- } catch {
28829
+ const onData = (ch) => {
28830
+ const c = ch.toString();
28831
+ if (c === "\r" || c === "\n") {
28832
+ process.stdin.removeListener("data", onData);
28833
+ try {
28834
+ process.stdin.setRawMode(false);
28835
+ } catch {
28836
+ }
28837
+ process.stdin.pause();
28838
+ process.stdout.write("\n");
28839
+ resolve13(input);
28840
+ } else if (c === "" || c === "\x1B") {
28841
+ process.stdin.removeListener("data", onData);
28842
+ try {
28843
+ process.stdin.setRawMode(false);
28844
+ } catch {
28845
+ }
28846
+ process.stdin.pause();
28847
+ process.stdout.write("\n");
28848
+ resolve13("");
28849
+ } else if (c === "\x7F" || c === "\b") {
28850
+ if (input.length > 0) {
28851
+ input = input.slice(0, -1);
28852
+ redraw();
28853
+ }
28854
+ } else {
28855
+ for (const char of c) {
28856
+ if (char.charCodeAt(0) >= 32) input += char;
28857
+ }
28858
+ redraw();
28787
28859
  }
28788
- process.stdin.pause();
28789
- process.stdout.write("\n".repeat(options.length));
28790
- resolve13("skip");
28791
- return;
28792
- }
28793
- };
28794
- process.stdin.on("data", onKey);
28795
- });
28796
- if (choice === "login") {
28797
- await handleLogin();
28798
- } else {
28799
- console.log(color.dim(" Skipped. Run ") + color.cyan("robinpath login") + color.dim(" anytime to unlock AI features."));
28800
- console.log("");
28801
- return;
28802
- }
28803
- }
28804
- const existingConfig = readAiConfig();
28805
- if (!existingConfig.apiKey && process.stdin.isTTY) {
28806
- console.log("");
28807
- console.log(color.green(" \u2713 Logged in successfully!"));
28808
- console.log("");
28809
- console.log(" To explore the AI assistant and agent coding,");
28810
- console.log(" connect your OpenRouter API key:");
28811
- console.log("");
28812
- console.log(color.bold(" Step 1:") + " Go to " + color.cyan("https://openrouter.ai/keys"));
28813
- console.log(color.bold(" Step 2:") + ' Click "Create Key" and copy it');
28814
- console.log(color.bold(" Step 3:") + " Run this command:");
28815
- console.log("");
28816
- console.log(" " + color.cyan(color.bold("robinpath ai config set-key ...")));
28817
- console.log("");
28818
- const ready = await new Promise((resolve13) => {
28819
- if (!process.stdin.isTTY) {
28820
- resolve13("later");
28860
+ };
28861
+ process.stdin.on("data", onData);
28862
+ });
28863
+ if (apiKey && apiKey.trim()) {
28864
+ const k2 = apiKey.trim();
28865
+ const newConfig = { apiKey: k2, model: "anthropic/claude-sonnet-4.6" };
28866
+ if (k2.startsWith("sk-or-")) newConfig.provider = "openrouter";
28867
+ else if (k2.startsWith("sk-ant-")) newConfig.provider = "anthropic";
28868
+ else if (k2.startsWith("sk-")) newConfig.provider = "openai";
28869
+ else newConfig.provider = "openrouter";
28870
+ writeAiConfig(newConfig);
28871
+ console.log(color.green(" \u2713") + " API key saved! Provider: " + color.cyan(newConfig.provider));
28872
+ console.log("");
28873
+ } else {
28874
+ console.log(color.dim(" Skipped. Set it later: ") + color.cyan("robinpath ai config set-key ..."));
28875
+ console.log("");
28821
28876
  return;
28822
28877
  }
28823
- let selected = 0;
28824
- const options = ["Yes, I'm ready", "Maybe later"];
28825
- function render2() {
28826
- process.stdout.write("\x1B[2K\r");
28827
- for (let i = 0; i < options.length; i++) {
28828
- if (i > 0) process.stdout.write("\n\x1B[2K");
28829
- const marker = i === selected ? color.cyan(" \u276F ") : " ";
28830
- const text = i === selected ? color.bold(options[i]) : options[i];
28831
- process.stdout.write(`${marker}${text}`);
28832
- }
28833
- if (options.length > 1) process.stdout.write(`\x1B[${options.length - 1}A`);
28834
- process.stdout.write("\r");
28835
- }
28836
- render2();
28837
- process.stdin.setRawMode(true);
28838
- process.stdin.resume();
28839
- const onKey = (buf) => {
28840
- const key = buf.toString();
28841
- if (key === "\x1B[A") {
28842
- selected = 0;
28843
- render2();
28844
- return;
28845
- }
28846
- if (key === "\x1B[B") {
28847
- selected = 1;
28848
- render2();
28849
- return;
28850
- }
28851
- if (key === "\r" || key === "\n") {
28852
- process.stdin.removeListener("data", onKey);
28853
- try {
28854
- process.stdin.setRawMode(false);
28855
- } catch {
28856
- }
28857
- process.stdin.pause();
28858
- process.stdout.write("\n".repeat(options.length));
28859
- resolve13(selected === 0 ? "ready" : "later");
28860
- return;
28861
- }
28862
- if (key === "\x1B" || key === "") {
28863
- process.stdin.removeListener("data", onKey);
28864
- try {
28865
- process.stdin.setRawMode(false);
28866
- } catch {
28867
- }
28868
- process.stdin.pause();
28869
- process.stdout.write("\n".repeat(options.length));
28870
- resolve13("later");
28871
- return;
28872
- }
28873
- };
28874
- process.stdin.on("data", onKey);
28875
- });
28876
- console.log("");
28877
- if (ready === "ready") {
28878
- console.log(" Copy and paste this command in your terminal:");
28879
- console.log("");
28880
- console.log(" " + color.cyan(color.bold("robinpath ai config set-key")) + color.dim(" <paste-your-key-here>"));
28881
- console.log("");
28882
- console.log(color.dim(" After setting the key, run ") + color.cyan("robinpath") + color.dim(" to start the AI assistant."));
28883
- } else {
28884
- console.log(color.dim(" No problem! When you're ready, run:"));
28885
- console.log(" " + color.cyan("robinpath ai config set-key") + color.dim(" <your-openrouter-key>"));
28886
28878
  }
28887
- console.log("");
28888
- return;
28889
28879
  }
28890
28880
  await startInkOrFallback(null, null, { autoAccept: FLAG_AUTO_ACCEPT, devMode: FLAG_DEV_MODE });
28891
28881
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robinpath/cli",
3
- "version": "3.4.1",
3
+ "version": "3.5.1",
4
4
  "description": "AI-powered scripting CLI — automate anything from your terminal",
5
5
  "type": "module",
6
6
  "license": "MIT",