@robinpath/cli 1.91.0 → 1.93.0

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 +101 -91
  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 ? "1.91.0" : "1.91.0";
18601
+ var CLI_VERSION = true ? "1.93.0" : "1.93.0";
18602
18602
  var FLAG_QUIET = false;
18603
18603
  var FLAG_VERBOSE = false;
18604
18604
  var FLAG_AUTO_ACCEPT = false;
@@ -24477,10 +24477,11 @@ function ChatApp({ engine }) {
24477
24477
  if (response) setMessages((p) => [...p, { id: ++nextId, text: response }]);
24478
24478
  } catch (err) {
24479
24479
  setMessages((p) => [...p, { id: ++nextId, text: `Error: ${err.message}`, dim: true }]);
24480
+ } finally {
24481
+ setLoading(false);
24482
+ setStreaming("");
24483
+ engine.updateStatus();
24480
24484
  }
24481
- setLoading(false);
24482
- setStreaming("");
24483
- engine.updateStatus();
24484
24485
  }, [engine]);
24485
24486
  if (!trusted) {
24486
24487
  return /* @__PURE__ */ jsx2(
@@ -24736,103 +24737,112 @@ Type / to see available commands.`;
24736
24737
  // ── AI message ──
24737
24738
  async handleAIMessage(text) {
24738
24739
  const ui = this.ui;
24739
- const { expanded } = expandFileRefs(text);
24740
- this.conversationMessages.push({ role: "user", content: expanded });
24741
- await autoCompact(this.conversationMessages);
24742
- const activeModel = readAiConfig().model || this.model;
24743
- const activeKey = readAiConfig().apiKey || this.apiKey;
24744
- const activeProvider = this.resolveProvider(activeKey);
24745
24740
  let finalResponse = "";
24746
- for (let loop = 0; loop < 15; loop++) {
24747
- let fullText = "";
24748
- const result = await fetchBrainStream(
24749
- loop === 0 ? expanded : this.conversationMessages[this.conversationMessages.length - 1].content,
24750
- {
24751
- onToken: (delta) => {
24752
- if (delta === "\x1B[RETRY]") {
24753
- fullText = "";
24754
- ui?.setStreaming("");
24755
- return;
24756
- }
24757
- fullText += delta;
24758
- const clean = fullText.replace(/<memory>[\s\S]*?<\/memory>/g, "").replace(/<cmd>[\s\S]*?<\/cmd>/g, "").replace(/\n{3,}/g, "\n\n").trim();
24759
- ui?.setStreaming(clean);
24760
- },
24761
- conversationHistory: this.conversationMessages.slice(0, -1),
24762
- provider: activeProvider,
24763
- model: activeModel,
24764
- apiKey: activeKey,
24765
- cliContext: this.cliContext
24741
+ try {
24742
+ const { expanded } = expandFileRefs(text);
24743
+ this.conversationMessages.push({ role: "user", content: expanded });
24744
+ await autoCompact(this.conversationMessages);
24745
+ const activeModel = readAiConfig().model || this.model;
24746
+ const activeKey = readAiConfig().apiKey || this.apiKey;
24747
+ const activeProvider = this.resolveProvider(activeKey);
24748
+ for (let loop = 0; loop < 15; loop++) {
24749
+ let fullText = "";
24750
+ const result = await fetchBrainStream(
24751
+ loop === 0 ? expanded : this.conversationMessages[this.conversationMessages.length - 1].content,
24752
+ {
24753
+ onToken: (delta) => {
24754
+ if (delta === "\x1B[RETRY]") {
24755
+ fullText = "";
24756
+ ui?.setStreaming("");
24757
+ return;
24758
+ }
24759
+ fullText += delta;
24760
+ const clean = fullText.replace(/<memory>[\s\S]*?<\/memory>/g, "").replace(/<cmd>[\s\S]*?<\/cmd>/g, "").replace(/\n{3,}/g, "\n\n").trim();
24761
+ ui?.setStreaming(clean);
24762
+ },
24763
+ conversationHistory: this.conversationMessages.slice(0, -1),
24764
+ provider: activeProvider,
24765
+ model: activeModel,
24766
+ apiKey: activeKey,
24767
+ cliContext: this.cliContext
24768
+ }
24769
+ );
24770
+ if (!result) {
24771
+ finalResponse = "\u26A0 No internet connection. Check your network and try again.";
24772
+ break;
24766
24773
  }
24767
- );
24768
- if (!result) {
24769
- finalResponse = "No internet connection. Check your network and try again.";
24770
- break;
24771
- }
24772
- if (result.error) {
24773
- finalResponse = result.error;
24774
- break;
24775
- }
24776
- if (!result.code) {
24777
- finalResponse = fullText || "No response. Try again.";
24778
- break;
24779
- }
24780
- if (result.usage) {
24781
- const pt2 = result.usage.prompt_tokens || 0;
24782
- const ct2 = result.usage.completion_tokens || 0;
24783
- this.usage.promptTokens += pt2;
24784
- this.usage.completionTokens += ct2;
24785
- this.usage.totalTokens += pt2 + ct2;
24786
- this.usage.requests++;
24787
- this.usage.cost += estimateCost(activeModel, pt2, ct2);
24788
- }
24789
- const { cleaned } = extractMemoryTags(stripCommandTags(result.code));
24790
- const commands = extractCommands(result.code);
24791
- if (cleaned) this.conversationMessages.push({ role: "assistant", content: cleaned });
24792
- if (commands.length === 0) {
24793
- finalResponse = cleaned || fullText;
24794
- break;
24795
- }
24796
- if (cleaned) ui?.addMessage(cleaned);
24797
- const cmdResults = [];
24798
- for (const cmd of commands) {
24799
- const preview = cmd.split("\n")[0].slice(0, 80);
24800
- ui?.addMessage(`$ ${preview}${cmd.includes("\n") ? " ..." : ""}`, true);
24801
- const r = await executeShellCommand(cmd);
24802
- cmdResults.push({ command: cmd, stdout: r.stdout || "", stderr: r.stderr || "", exitCode: r.exitCode });
24803
- if (r.exitCode === 0 && r.stdout?.trim()) {
24804
- const lines = r.stdout.trim().split("\n");
24805
- if (lines.length <= 15) {
24806
- ui?.addMessage(lines.join("\n"), true);
24807
- } else {
24808
- ui?.addMessage(
24809
- `${lines.slice(0, 5).join("\n")}
24774
+ if (result.error) {
24775
+ finalResponse = `\u26A0 ${result.error}`;
24776
+ break;
24777
+ }
24778
+ if (!result.code) {
24779
+ const model = readAiConfig().model || this.model;
24780
+ const hint = model === "robinpath-default" ? "The free model may be temporarily unavailable. Try again or switch to a paid model with /model." : "The AI returned an empty response. Try rephrasing or check your API key with /usage.";
24781
+ finalResponse = fullText || `\u26A0 ${hint}`;
24782
+ break;
24783
+ }
24784
+ if (result.usage) {
24785
+ const pt2 = result.usage.prompt_tokens || 0;
24786
+ const ct2 = result.usage.completion_tokens || 0;
24787
+ this.usage.promptTokens += pt2;
24788
+ this.usage.completionTokens += ct2;
24789
+ this.usage.totalTokens += pt2 + ct2;
24790
+ this.usage.requests++;
24791
+ this.usage.cost += estimateCost(activeModel, pt2, ct2);
24792
+ }
24793
+ const { cleaned } = extractMemoryTags(stripCommandTags(result.code));
24794
+ const commands = extractCommands(result.code);
24795
+ if (cleaned) this.conversationMessages.push({ role: "assistant", content: cleaned });
24796
+ if (commands.length === 0) {
24797
+ finalResponse = cleaned || fullText;
24798
+ break;
24799
+ }
24800
+ if (cleaned) ui?.addMessage(cleaned);
24801
+ const cmdResults = [];
24802
+ for (const cmd of commands) {
24803
+ const preview = cmd.split("\n")[0].slice(0, 80);
24804
+ ui?.addMessage(`$ ${preview}${cmd.includes("\n") ? " ..." : ""}`, true);
24805
+ const r = await executeShellCommand(cmd);
24806
+ cmdResults.push({ command: cmd, stdout: r.stdout || "", stderr: r.stderr || "", exitCode: r.exitCode });
24807
+ if (r.exitCode === 0 && r.stdout?.trim()) {
24808
+ const lines = r.stdout.trim().split("\n");
24809
+ if (lines.length <= 15) {
24810
+ ui?.addMessage(lines.join("\n"), true);
24811
+ } else {
24812
+ ui?.addMessage(
24813
+ `${lines.slice(0, 5).join("\n")}
24810
24814
  ... (${lines.length - 10} lines hidden)
24811
24815
  ${lines.slice(-5).join("\n")}`,
24812
- true
24813
- );
24816
+ true
24817
+ );
24818
+ }
24819
+ } else if (r.exitCode !== 0) {
24820
+ ui?.addMessage(`exit ${r.exitCode}: ${(r.stderr || "").slice(0, 200)}`, true);
24821
+ } else {
24822
+ ui?.addMessage("done", true);
24814
24823
  }
24815
- } else if (r.exitCode !== 0) {
24816
- ui?.addMessage(`exit ${r.exitCode}: ${(r.stderr || "").slice(0, 200)}`, true);
24817
- } else {
24818
- ui?.addMessage("done", true);
24819
24824
  }
24820
- }
24821
- const summary = cmdResults.map((r) => {
24822
- let out = `$ ${r.command}
24825
+ const summary = cmdResults.map((r) => {
24826
+ let out = `$ ${r.command}
24823
24827
  `;
24824
- if (r.exitCode === 0) out += (r.stdout || "(no output)").slice(0, 5e3);
24825
- else {
24826
- out += `Exit: ${r.exitCode}
24828
+ if (r.exitCode === 0) out += (r.stdout || "(no output)").slice(0, 5e3);
24829
+ else {
24830
+ out += `Exit: ${r.exitCode}
24827
24831
  `;
24828
- if (r.stderr) out += r.stderr.slice(0, 2e3);
24829
- }
24830
- return out;
24831
- }).join("\n\n");
24832
- this.conversationMessages.push({ role: "user", content: `[Results]
24832
+ if (r.stderr) out += r.stderr.slice(0, 2e3);
24833
+ }
24834
+ return out;
24835
+ }).join("\n\n");
24836
+ this.conversationMessages.push({ role: "user", content: `[Results]
24833
24837
  ${summary}` });
24838
+ ui?.setStreaming("");
24839
+ finalResponse = "";
24840
+ }
24841
+ } catch (err) {
24842
+ finalResponse = `\u26A0 Error: ${err.message}`;
24843
+ } finally {
24834
24844
  ui?.setStreaming("");
24835
- finalResponse = "";
24845
+ ui?.setLoading(false);
24836
24846
  }
24837
24847
  saveSession(this.sessionId, this.sessionName, this.conversationMessages, this.usage);
24838
24848
  return finalResponse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robinpath/cli",
3
- "version": "1.91.0",
3
+ "version": "1.93.0",
4
4
  "description": "AI-powered scripting CLI — automate anything from your terminal",
5
5
  "type": "module",
6
6
  "license": "MIT",