heyeric 1.4.0 → 1.5.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 +42 -5
  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(`
@@ -55,8 +55,17 @@ function getHistory() {
55
55
  return [];
56
56
  }
57
57
  }
58
+ var LAST_OUTPUT_FILE = join(tmpdir(), "eric-last-output");
59
+ function getLastOutput() {
60
+ try {
61
+ return readFileSync(LAST_OUTPUT_FILE, "utf-8").trim();
62
+ } catch {
63
+ return "";
64
+ }
65
+ }
58
66
  var lsOutput = getLs();
59
67
  var history = getHistory();
68
+ var lastOutput = getLastOutput();
60
69
  var systemPrompt = `You are a bash command generator.
61
70
  Convert the user's natural-language description into a single bash command.
62
71
  Prefer simple, well-known commands over complex one-liners when possible.
@@ -88,6 +97,12 @@ Recent command history:
88
97
  `;
89
98
  }
90
99
  }
100
+ if (lastOutput) {
101
+ systemPrompt += `
102
+ Output from last command run:
103
+ ${lastOutput}
104
+ `;
105
+ }
91
106
  systemPrompt += `
92
107
  Description to convert:`;
93
108
  function startSpinner() {
@@ -211,8 +226,30 @@ async function main() {
211
226
  if (!answer) {
212
227
  const updateMsg = await updatePromise;
213
228
  if (updateMsg) process.stderr.write(updateMsg);
214
- const child = spawn(command, { shell: true, stdio: "inherit" });
215
- child.on("close", (code) => process.exit(code ?? 0));
229
+ const child = spawn(command, {
230
+ shell: true,
231
+ stdio: ["inherit", "pipe", "pipe"]
232
+ });
233
+ let captured = "";
234
+ child.stdout.on("data", (data) => {
235
+ const text = data.toString();
236
+ process.stdout.write(text);
237
+ captured += text;
238
+ });
239
+ child.stderr.on("data", (data) => {
240
+ const text = data.toString();
241
+ process.stderr.write(text);
242
+ captured += text;
243
+ });
244
+ child.on("close", (code) => {
245
+ const lines = captured.trim().split("\n");
246
+ const tail = lines.slice(-200).join("\n");
247
+ try {
248
+ writeFileSync(LAST_OUTPUT_FILE, tail, "utf-8");
249
+ } catch {
250
+ }
251
+ process.exit(code ?? 0);
252
+ });
216
253
  return;
217
254
  }
218
255
  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.5.0",
4
4
  "description": "Natural language to bash commands via LLM",
5
5
  "type": "module",
6
6
  "bin": {