henergyqueai 0.4.0 → 0.4.2

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.2";
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" };
@@ -261,12 +263,40 @@ function header(session) {
261
263
  say(
262
264
  ` ${style.dim("──────────────────────────────────────────────────────────")}`,
263
265
  );
264
- say(
265
- ` ${style.dim("Écrivez votre demande. Le papillon reste dans l’en-tête pendant la réponse.")}`,
266
- );
266
+ say(` ${style.dim("Appuyez sur Entrée pour afficher le menu.")}`);
267
267
  say("");
268
268
  }
269
269
 
270
+ // Keep the brand in a real fixed terminal region. Only rows below the header
271
+ // are allowed to scroll, so a long conversation cannot push the butterfly out
272
+ // of view.
273
+ function pinHeader(session) {
274
+ clearScreen();
275
+ header(session);
276
+ if (!process.stdout.isTTY) return () => {};
277
+
278
+ let active = true;
279
+ const reserve = () => {
280
+ if (!active) return;
281
+ const bottom = process.stdout.rows || 24;
282
+ if (bottom <= BODY_ROW + 2) return;
283
+ process.stdout.write(
284
+ `\u001b[s\u001b[${BODY_ROW};${bottom}r\u001b[u\u001b[${BODY_ROW};1H`,
285
+ );
286
+ };
287
+ const release = () => {
288
+ if (!active) return;
289
+ active = false;
290
+ process.stdout.off("resize", reserve);
291
+ process.stdout.write("\u001b[s\u001b[r\u001b[u");
292
+ };
293
+
294
+ reserve();
295
+ process.stdout.on("resize", reserve);
296
+ process.once("exit", release);
297
+ return release;
298
+ }
299
+
270
300
  const menuPaint = (option, active) => {
271
301
  const [label, detail = ""] = option.split("\t");
272
302
  const marker = active ? brand("◆") : style.dim("◇");
@@ -529,6 +559,7 @@ async function main() {
529
559
  );
530
560
  } else say(style.dim(" Aucune conversation à reprendre ici."));
531
561
  }
562
+ let releaseHeader = () => {};
532
563
  try {
533
564
  if (first) {
534
565
  messages.push({ role: "user", content: first });
@@ -537,8 +568,7 @@ async function main() {
537
568
  return;
538
569
  }
539
570
  if (!(await trusted(session.root))) return;
540
- clearScreen();
541
- header(session);
571
+ releaseHeader = pinHeader(session);
542
572
  session.headerActive = true;
543
573
  for (;;) {
544
574
  const line = await prompt(`${brand("Vous")} ${style.dim("›")} `);
@@ -559,7 +589,9 @@ async function main() {
559
589
  }
560
590
  } catch (error) {
561
591
  say(style.red(error.message));
562
- process.exit(1);
592
+ process.exitCode = 1;
593
+ } finally {
594
+ releaseHeader();
563
595
  }
564
596
  }
565
597
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "henergyqueai",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
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
  }