@robinpath/cli 1.92.0 → 1.94.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 +109 -93
  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.92.0" : "1.92.0";
18601
+ var CLI_VERSION = true ? "1.94.0" : "1.94.0";
18602
18602
  var FLAG_QUIET = false;
18603
18603
  var FLAG_VERBOSE = false;
18604
18604
  var FLAG_AUTO_ACCEPT = false;
@@ -21947,6 +21947,14 @@ async function fetchBrainStream(prompt, { onToken, conversationHistory, provider
21947
21947
  doneData = parsed;
21948
21948
  } else if (eventType === "error") {
21949
21949
  logVerbose("Brain stream error:", parsed.message);
21950
+ return {
21951
+ code: fullText,
21952
+ sources: metadata?.sources || [],
21953
+ context: metadata?.context || {},
21954
+ validation: null,
21955
+ usage: doneData?.usage || null,
21956
+ error: parsed.message || "AI model error"
21957
+ };
21950
21958
  }
21951
21959
  } catch {
21952
21960
  }
@@ -24477,10 +24485,11 @@ function ChatApp({ engine }) {
24477
24485
  if (response) setMessages((p) => [...p, { id: ++nextId, text: response }]);
24478
24486
  } catch (err) {
24479
24487
  setMessages((p) => [...p, { id: ++nextId, text: `Error: ${err.message}`, dim: true }]);
24488
+ } finally {
24489
+ setLoading(false);
24490
+ setStreaming("");
24491
+ engine.updateStatus();
24480
24492
  }
24481
- setLoading(false);
24482
- setStreaming("");
24483
- engine.updateStatus();
24484
24493
  }, [engine]);
24485
24494
  if (!trusted) {
24486
24495
  return /* @__PURE__ */ jsx2(
@@ -24736,105 +24745,112 @@ Type / to see available commands.`;
24736
24745
  // ── AI message ──
24737
24746
  async handleAIMessage(text) {
24738
24747
  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
24748
  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
24749
+ try {
24750
+ const { expanded } = expandFileRefs(text);
24751
+ this.conversationMessages.push({ role: "user", content: expanded });
24752
+ await autoCompact(this.conversationMessages);
24753
+ const activeModel = readAiConfig().model || this.model;
24754
+ const activeKey = readAiConfig().apiKey || this.apiKey;
24755
+ const activeProvider = this.resolveProvider(activeKey);
24756
+ for (let loop = 0; loop < 15; loop++) {
24757
+ let fullText = "";
24758
+ const result = await fetchBrainStream(
24759
+ loop === 0 ? expanded : this.conversationMessages[this.conversationMessages.length - 1].content,
24760
+ {
24761
+ onToken: (delta) => {
24762
+ if (delta === "\x1B[RETRY]") {
24763
+ fullText = "";
24764
+ ui?.setStreaming("");
24765
+ return;
24766
+ }
24767
+ fullText += delta;
24768
+ const clean = fullText.replace(/<memory>[\s\S]*?<\/memory>/g, "").replace(/<cmd>[\s\S]*?<\/cmd>/g, "").replace(/\n{3,}/g, "\n\n").trim();
24769
+ ui?.setStreaming(clean);
24770
+ },
24771
+ conversationHistory: this.conversationMessages.slice(0, -1),
24772
+ provider: activeProvider,
24773
+ model: activeModel,
24774
+ apiKey: activeKey,
24775
+ cliContext: this.cliContext
24776
+ }
24777
+ );
24778
+ if (!result) {
24779
+ finalResponse = "\u26A0 No internet connection. Check your network and try again.";
24780
+ break;
24766
24781
  }
24767
- );
24768
- if (!result) {
24769
- finalResponse = "\u26A0 No internet connection. Check your network and try again.";
24770
- break;
24771
- }
24772
- if (result.error) {
24773
- finalResponse = `\u26A0 ${result.error}`;
24774
- break;
24775
- }
24776
- if (!result.code) {
24777
- const model = readAiConfig().model || this.model;
24778
- 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.";
24779
- finalResponse = fullText || `\u26A0 ${hint}`;
24780
- break;
24781
- }
24782
- if (result.usage) {
24783
- const pt2 = result.usage.prompt_tokens || 0;
24784
- const ct2 = result.usage.completion_tokens || 0;
24785
- this.usage.promptTokens += pt2;
24786
- this.usage.completionTokens += ct2;
24787
- this.usage.totalTokens += pt2 + ct2;
24788
- this.usage.requests++;
24789
- this.usage.cost += estimateCost(activeModel, pt2, ct2);
24790
- }
24791
- const { cleaned } = extractMemoryTags(stripCommandTags(result.code));
24792
- const commands = extractCommands(result.code);
24793
- if (cleaned) this.conversationMessages.push({ role: "assistant", content: cleaned });
24794
- if (commands.length === 0) {
24795
- finalResponse = cleaned || fullText;
24796
- break;
24797
- }
24798
- if (cleaned) ui?.addMessage(cleaned);
24799
- const cmdResults = [];
24800
- for (const cmd of commands) {
24801
- const preview = cmd.split("\n")[0].slice(0, 80);
24802
- ui?.addMessage(`$ ${preview}${cmd.includes("\n") ? " ..." : ""}`, true);
24803
- const r = await executeShellCommand(cmd);
24804
- cmdResults.push({ command: cmd, stdout: r.stdout || "", stderr: r.stderr || "", exitCode: r.exitCode });
24805
- if (r.exitCode === 0 && r.stdout?.trim()) {
24806
- const lines = r.stdout.trim().split("\n");
24807
- if (lines.length <= 15) {
24808
- ui?.addMessage(lines.join("\n"), true);
24809
- } else {
24810
- ui?.addMessage(
24811
- `${lines.slice(0, 5).join("\n")}
24782
+ if (result.error) {
24783
+ finalResponse = `\u26A0 ${result.error}`;
24784
+ break;
24785
+ }
24786
+ if (!result.code) {
24787
+ const model = readAiConfig().model || this.model;
24788
+ 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.";
24789
+ finalResponse = fullText || `\u26A0 ${hint}`;
24790
+ break;
24791
+ }
24792
+ if (result.usage) {
24793
+ const pt2 = result.usage.prompt_tokens || 0;
24794
+ const ct2 = result.usage.completion_tokens || 0;
24795
+ this.usage.promptTokens += pt2;
24796
+ this.usage.completionTokens += ct2;
24797
+ this.usage.totalTokens += pt2 + ct2;
24798
+ this.usage.requests++;
24799
+ this.usage.cost += estimateCost(activeModel, pt2, ct2);
24800
+ }
24801
+ const { cleaned } = extractMemoryTags(stripCommandTags(result.code));
24802
+ const commands = extractCommands(result.code);
24803
+ if (cleaned) this.conversationMessages.push({ role: "assistant", content: cleaned });
24804
+ if (commands.length === 0) {
24805
+ finalResponse = cleaned || fullText;
24806
+ break;
24807
+ }
24808
+ if (cleaned) ui?.addMessage(cleaned);
24809
+ const cmdResults = [];
24810
+ for (const cmd of commands) {
24811
+ const preview = cmd.split("\n")[0].slice(0, 80);
24812
+ ui?.addMessage(`$ ${preview}${cmd.includes("\n") ? " ..." : ""}`, true);
24813
+ const r = await executeShellCommand(cmd);
24814
+ cmdResults.push({ command: cmd, stdout: r.stdout || "", stderr: r.stderr || "", exitCode: r.exitCode });
24815
+ if (r.exitCode === 0 && r.stdout?.trim()) {
24816
+ const lines = r.stdout.trim().split("\n");
24817
+ if (lines.length <= 15) {
24818
+ ui?.addMessage(lines.join("\n"), true);
24819
+ } else {
24820
+ ui?.addMessage(
24821
+ `${lines.slice(0, 5).join("\n")}
24812
24822
  ... (${lines.length - 10} lines hidden)
24813
24823
  ${lines.slice(-5).join("\n")}`,
24814
- true
24815
- );
24824
+ true
24825
+ );
24826
+ }
24827
+ } else if (r.exitCode !== 0) {
24828
+ ui?.addMessage(`exit ${r.exitCode}: ${(r.stderr || "").slice(0, 200)}`, true);
24829
+ } else {
24830
+ ui?.addMessage("done", true);
24816
24831
  }
24817
- } else if (r.exitCode !== 0) {
24818
- ui?.addMessage(`exit ${r.exitCode}: ${(r.stderr || "").slice(0, 200)}`, true);
24819
- } else {
24820
- ui?.addMessage("done", true);
24821
24832
  }
24822
- }
24823
- const summary = cmdResults.map((r) => {
24824
- let out = `$ ${r.command}
24833
+ const summary = cmdResults.map((r) => {
24834
+ let out = `$ ${r.command}
24825
24835
  `;
24826
- if (r.exitCode === 0) out += (r.stdout || "(no output)").slice(0, 5e3);
24827
- else {
24828
- out += `Exit: ${r.exitCode}
24836
+ if (r.exitCode === 0) out += (r.stdout || "(no output)").slice(0, 5e3);
24837
+ else {
24838
+ out += `Exit: ${r.exitCode}
24829
24839
  `;
24830
- if (r.stderr) out += r.stderr.slice(0, 2e3);
24831
- }
24832
- return out;
24833
- }).join("\n\n");
24834
- this.conversationMessages.push({ role: "user", content: `[Results]
24840
+ if (r.stderr) out += r.stderr.slice(0, 2e3);
24841
+ }
24842
+ return out;
24843
+ }).join("\n\n");
24844
+ this.conversationMessages.push({ role: "user", content: `[Results]
24835
24845
  ${summary}` });
24846
+ ui?.setStreaming("");
24847
+ finalResponse = "";
24848
+ }
24849
+ } catch (err) {
24850
+ finalResponse = `\u26A0 Error: ${err.message}`;
24851
+ } finally {
24836
24852
  ui?.setStreaming("");
24837
- finalResponse = "";
24853
+ ui?.setLoading(false);
24838
24854
  }
24839
24855
  saveSession(this.sessionId, this.sessionName, this.conversationMessages, this.usage);
24840
24856
  return finalResponse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robinpath/cli",
3
- "version": "1.92.0",
3
+ "version": "1.94.0",
4
4
  "description": "AI-powered scripting CLI — automate anything from your terminal",
5
5
  "type": "module",
6
6
  "license": "MIT",