heyeric 1.4.0 → 1.6.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/index.js +52 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -9,9 +9,9 @@ import {
9
9
  // src/index.ts
10
10
  import { execSync, spawn } from "child_process";
11
11
  import { createInterface } from "readline";
12
- import { readFileSync } from "fs";
13
- import { platform } from "os";
14
- import { basename } from "path";
12
+ import { readFileSync, writeFileSync } from "fs";
13
+ import { platform, tmpdir } from "os";
14
+ import { basename, join } from "path";
15
15
  import cliSpinners from "cli-spinners";
16
16
  function die(msg) {
17
17
  process.stderr.write(`
@@ -20,7 +20,16 @@ eric: ${msg}
20
20
  process.exit(1);
21
21
  }
22
22
  var query = process.argv.slice(2).join(" ").trim();
23
- if (!query) die("Usage: eric <query>");
23
+ if (!query) {
24
+ const rl = createInterface({ input: process.stdin, output: process.stderr });
25
+ query = await new Promise((resolve) => {
26
+ rl.question("\x1B[1meric>\x1B[0m ", (input) => {
27
+ rl.close();
28
+ resolve(input.trim());
29
+ });
30
+ });
31
+ if (!query) die("Usage: eric <query>");
32
+ }
24
33
  var apiUrl = process.env.AI_API_URL || "https://aiapi.ericpark.me/v1/chat/completions";
25
34
  var apiKey = process.env.AI_API_KEY || "ericpark";
26
35
  var model = process.env.AI_MODEL || "gpt-5.4-mini";
@@ -55,8 +64,17 @@ function getHistory() {
55
64
  return [];
56
65
  }
57
66
  }
67
+ var LAST_OUTPUT_FILE = join(tmpdir(), "eric-last-output");
68
+ function getLastOutput() {
69
+ try {
70
+ return readFileSync(LAST_OUTPUT_FILE, "utf-8").trim();
71
+ } catch {
72
+ return "";
73
+ }
74
+ }
58
75
  var lsOutput = getLs();
59
76
  var history = getHistory();
77
+ var lastOutput = getLastOutput();
60
78
  var systemPrompt = `You are a bash command generator.
61
79
  Convert the user's natural-language description into a single bash command.
62
80
  Prefer simple, well-known commands over complex one-liners when possible.
@@ -88,6 +106,12 @@ Recent command history:
88
106
  `;
89
107
  }
90
108
  }
109
+ if (lastOutput) {
110
+ systemPrompt += `
111
+ Output from last command run:
112
+ ${lastOutput}
113
+ `;
114
+ }
91
115
  systemPrompt += `
92
116
  Description to convert:`;
93
117
  function startSpinner() {
@@ -211,8 +235,30 @@ async function main() {
211
235
  if (!answer) {
212
236
  const updateMsg = await updatePromise;
213
237
  if (updateMsg) process.stderr.write(updateMsg);
214
- const child = spawn(command, { shell: true, stdio: "inherit" });
215
- child.on("close", (code) => process.exit(code ?? 0));
238
+ const child = spawn(command, {
239
+ shell: true,
240
+ stdio: ["inherit", "pipe", "pipe"]
241
+ });
242
+ let captured = "";
243
+ child.stdout.on("data", (data) => {
244
+ const text = data.toString();
245
+ process.stdout.write(text);
246
+ captured += text;
247
+ });
248
+ child.stderr.on("data", (data) => {
249
+ const text = data.toString();
250
+ process.stderr.write(text);
251
+ captured += text;
252
+ });
253
+ child.on("close", (code) => {
254
+ const lines = captured.trim().split("\n");
255
+ const tail = lines.slice(-200).join("\n");
256
+ try {
257
+ writeFileSync(LAST_OUTPUT_FILE, tail, "utf-8");
258
+ } catch {
259
+ }
260
+ process.exit(code ?? 0);
261
+ });
216
262
  return;
217
263
  }
218
264
  messages.push({ role: "user", content: answer });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "heyeric",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "Natural language to bash commands via LLM",
5
5
  "type": "module",
6
6
  "bin": {