henergyqueai 0.4.0 → 0.4.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.
@@ -25,7 +25,9 @@ import {
25
25
  } from "../src/reglages.js";
26
26
  import { lastSession, saveSession } from "../src/sessions.js";
27
27
 
28
- const VERSION = "0.4.0";
28
+ const VERSION = "0.4.1";
29
+ const HEADER_HEIGHT = 9;
30
+ const BODY_ROW = HEADER_HEIGHT + 1;
29
31
  const CONFIG = path.join(homedir(), ".henergyqueai", "config.json");
30
32
  const DEFAULT_BASE = process.env.HENERGYQUEAI_URL || "https://henergyqueai.fr";
31
33
  const MODELS = { aelyr: "Aelyr", oryne: "Oryne", velys: "Velys" };
@@ -267,6 +269,36 @@ function header(session) {
267
269
  say("");
268
270
  }
269
271
 
272
+ // Keep the brand in a real fixed terminal region. Only rows below the header
273
+ // are allowed to scroll, so a long conversation cannot push the butterfly out
274
+ // of view.
275
+ function pinHeader(session) {
276
+ clearScreen();
277
+ header(session);
278
+ if (!process.stdout.isTTY) return () => {};
279
+
280
+ let active = true;
281
+ const reserve = () => {
282
+ if (!active) return;
283
+ const bottom = process.stdout.rows || 24;
284
+ if (bottom <= BODY_ROW + 2) return;
285
+ process.stdout.write(
286
+ `\u001b[s\u001b[${BODY_ROW};${bottom}r\u001b[u\u001b[${BODY_ROW};1H`,
287
+ );
288
+ };
289
+ const release = () => {
290
+ if (!active) return;
291
+ active = false;
292
+ process.stdout.off("resize", reserve);
293
+ process.stdout.write("\u001b[s\u001b[r\u001b[u");
294
+ };
295
+
296
+ reserve();
297
+ process.stdout.on("resize", reserve);
298
+ process.once("exit", release);
299
+ return release;
300
+ }
301
+
270
302
  const menuPaint = (option, active) => {
271
303
  const [label, detail = ""] = option.split("\t");
272
304
  const marker = active ? brand("◆") : style.dim("◇");
@@ -529,6 +561,7 @@ async function main() {
529
561
  );
530
562
  } else say(style.dim(" Aucune conversation à reprendre ici."));
531
563
  }
564
+ let releaseHeader = () => {};
532
565
  try {
533
566
  if (first) {
534
567
  messages.push({ role: "user", content: first });
@@ -537,8 +570,7 @@ async function main() {
537
570
  return;
538
571
  }
539
572
  if (!(await trusted(session.root))) return;
540
- clearScreen();
541
- header(session);
573
+ releaseHeader = pinHeader(session);
542
574
  session.headerActive = true;
543
575
  for (;;) {
544
576
  const line = await prompt(`${brand("Vous")} ${style.dim("›")} `);
@@ -559,7 +591,9 @@ async function main() {
559
591
  }
560
592
  } catch (error) {
561
593
  say(style.red(error.message));
562
- process.exit(1);
594
+ process.exitCode = 1;
595
+ } finally {
596
+ releaseHeader();
563
597
  }
564
598
  }
565
599
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "henergyqueai",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "L’assistant HenergyqueAI dans votre terminal : il lit votre projet, propose des modifications et lance des commandes, avec votre accord.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/butterfly.js CHANGED
@@ -107,6 +107,8 @@ export const still = () => paint(FRAMES[0]);
107
107
  export const brand = (text) =>
108
108
  plain ? text : `\u001b[${fg("#c46c4f")}m${text}\u001b[0m`;
109
109
 
110
+ let activeFlutter = null;
111
+
110
112
  // Flaps in the reserved header area while something is being waited for. The
111
113
  // cursor is saved and restored around every frame, so streamed answers keep
112
114
  // writing at the bottom instead of inheriting five animation lines.
@@ -115,25 +117,38 @@ export function flutter(label = "", { row = 1, column = 3 } = {}) {
115
117
  if (label) process.stdout.write(`${label}\n`);
116
118
  return () => {};
117
119
  }
120
+ // A second request must replace the previous animation instead of leaving
121
+ // another timer painting a second butterfly into the terminal.
122
+ activeFlutter?.();
118
123
  let at = 0;
124
+ let stopped = false;
119
125
  const show = () => {
126
+ if (stopped) return;
120
127
  const lines = paint(FRAMES[at % FRAMES.length]);
121
128
  const frame = lines
122
129
  .map(
123
130
  (line, index) =>
124
- `\u001b[${row + index};${column}H${line}${index === 2 && label ? ` \u001b[2m${label}\u001b[0m` : ""}`,
131
+ `\u001b[${row + index};${column}H\u001b[${WIDTH + label.length + 2}X${line}${index === 2 && label ? ` \u001b[2m${label}\u001b[0m` : ""}`,
125
132
  )
126
133
  .join("");
127
- process.stdout.write(`\u001b7${frame}\u001b8`);
134
+ process.stdout.write(`\u001b[s${frame}\u001b[u`);
128
135
  at += 1;
129
136
  };
130
137
  show();
131
138
  const timer = setInterval(show, 140);
132
- return () => {
139
+ const stop = () => {
140
+ if (stopped) return;
141
+ stopped = true;
133
142
  clearInterval(timer);
134
143
  const resting = still()
135
- .map((line, index) => `\u001b[${row + index};${column}H${line}`)
144
+ .map(
145
+ (line, index) =>
146
+ `\u001b[${row + index};${column}H\u001b[${WIDTH + label.length + 2}X${line}`,
147
+ )
136
148
  .join("");
137
- process.stdout.write(`\u001b7${resting}\u001b8`);
149
+ process.stdout.write(`\u001b[s${resting}\u001b[u`);
150
+ if (activeFlutter === stop) activeFlutter = null;
138
151
  };
152
+ activeFlutter = stop;
153
+ return stop;
139
154
  }