alvin-bot 4.5.0 → 4.5.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.
- package/CHANGELOG.md +20 -0
- package/dist/tui/index.js +36 -30
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to Alvin Bot are documented here.
|
|
4
4
|
|
|
5
|
+
## [4.5.1] — 2026-04-09
|
|
6
|
+
|
|
7
|
+
### 🐛 TUI Header Rendering Hotfix
|
|
8
|
+
|
|
9
|
+
**The header was appearing inline in the middle of the conversation after scrolling** — a follow-up bug to the 4.5.0 TUI fix. Reported from a live 4.5.0 Test MacBook session where the header popped up right after a long bot response.
|
|
10
|
+
|
|
11
|
+
**Root cause**: `redrawHeader()` in 4.5.0 used `\x1b[H` (move to top-left) + `\x1b[s`/`\x1b[u` (save/restore cursor) to update the header in place when cost/model/target changed. But `\x1b[H` resolves to the **current viewport top**, not the document top — and once the terminal has scrolled past the original header, the "viewport top" is somewhere in the middle of the conversation. So the header got re-rendered inline in the middle of the bot's output.
|
|
12
|
+
|
|
13
|
+
**Fix**: removed all `redrawHeader()` calls from mid-session code paths:
|
|
14
|
+
- `ws.on("open")` (connect): no redraw, header was already drawn at startup
|
|
15
|
+
- `ws.on("close")` (disconnect): no redraw, just the error message
|
|
16
|
+
- `case "done"` (after each bot response): no redraw (this was the primary bug site — it fired after every message)
|
|
17
|
+
- `case "model"` (model switch): no redraw, just a success info line
|
|
18
|
+
- `case "target tui|telegram"` (target switch): no redraw, just an info line
|
|
19
|
+
- `process.stdout.on("resize")`: no redraw, just re-renders the prompt line
|
|
20
|
+
|
|
21
|
+
The only remaining `redrawHeader()` call is inside `/clear`, which calls `console.clear()` first to wipe the whole buffer — the only context where an in-place redraw is safe.
|
|
22
|
+
|
|
23
|
+
The trade-off: the header no longer reflects live cost/model/target updates mid-session. You'll see the up-to-date values after the next `/clear` or on the next TUI start. In exchange, the conversation flow stays clean. A future release could add a proper status-line region using terminal scrolling regions if this becomes annoying.
|
|
24
|
+
|
|
5
25
|
## [4.5.0] — 2026-04-09
|
|
6
26
|
|
|
7
27
|
### 🐛 TUI Bug Fixes (critical — the old TUI was effectively unusable)
|
package/dist/tui/index.js
CHANGED
|
@@ -105,27 +105,25 @@ function drawHeader() {
|
|
|
105
105
|
console.log(`${C.gray}${"─".repeat(w)}${C.reset}`);
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
|
-
* Redraw the header
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
108
|
+
* Redraw the header. The old "in-place" implementation used cursor save/
|
|
109
|
+
* restore escape sequences and jumped to \x1b[H — but once the terminal
|
|
110
|
+
* has scrolled past the original header, \x1b[H resolves to the current
|
|
111
|
+
* viewport top (not the document top), which means the header gets
|
|
112
|
+
* re-rendered inline in the middle of the content. That's what produced
|
|
113
|
+
* the "header appears in the middle of the bot response" bug in 4.5.0.
|
|
114
|
+
*
|
|
115
|
+
* The only safe way to redraw the header in a scrolling terminal is to
|
|
116
|
+
* clear the whole screen and redraw from scratch. Do that only in
|
|
117
|
+
* explicit reset contexts (/clear, SIGWINCH resize, initial connect).
|
|
118
|
+
* For mid-session cost/status updates, use inline info messages instead.
|
|
113
119
|
*/
|
|
114
|
-
function redrawHeader() {
|
|
120
|
+
function redrawHeader(opts = {}) {
|
|
115
121
|
if (isStreaming)
|
|
116
|
-
return;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
process.stdout.write("\x1b[H"); // Move to top-left
|
|
120
|
-
for (let i = 0; i < HEADER_LINES; i++) {
|
|
121
|
-
cursorTo(process.stdout, 0);
|
|
122
|
-
rlClearLine(process.stdout, 0);
|
|
123
|
-
if (i < HEADER_LINES - 1)
|
|
124
|
-
process.stdout.write("\x1b[1B");
|
|
122
|
+
return;
|
|
123
|
+
if (opts.clearScreen) {
|
|
124
|
+
console.clear();
|
|
125
125
|
}
|
|
126
|
-
process.stdout.write("\x1b[H");
|
|
127
126
|
drawHeader();
|
|
128
|
-
process.stdout.write("\x1b[u"); // Restore cursor
|
|
129
127
|
if (rl && !isStreaming)
|
|
130
128
|
rl.prompt(true);
|
|
131
129
|
}
|
|
@@ -222,7 +220,8 @@ function connectWebSocket() {
|
|
|
222
220
|
ws = new WebSocket(wsUrl);
|
|
223
221
|
ws.on("open", () => {
|
|
224
222
|
connected = true;
|
|
225
|
-
|
|
223
|
+
// No header redraw here — the header was already drawn at startTUI().
|
|
224
|
+
// Calling redrawHeader() in a scrolled terminal re-renders it inline.
|
|
226
225
|
printInfo(t("tui.connectedTo"));
|
|
227
226
|
showPrompt();
|
|
228
227
|
});
|
|
@@ -236,7 +235,7 @@ function connectWebSocket() {
|
|
|
236
235
|
ws.on("close", () => {
|
|
237
236
|
connected = false;
|
|
238
237
|
isStreaming = false;
|
|
239
|
-
|
|
238
|
+
// No header redraw — it would appear inline mid-chat.
|
|
240
239
|
printError(t("tui.connectionLost"));
|
|
241
240
|
setTimeout(connectWebSocket, 3000);
|
|
242
241
|
});
|
|
@@ -279,7 +278,10 @@ function handleMessage(msg) {
|
|
|
279
278
|
isStreaming = false;
|
|
280
279
|
currentResponse = "";
|
|
281
280
|
currentToolName = "";
|
|
282
|
-
|
|
281
|
+
// NOTE: do NOT call redrawHeader() here. On a scrolled terminal it
|
|
282
|
+
// renders the header inline at the viewport top, which looks like
|
|
283
|
+
// the header appeared in the middle of the conversation. The total
|
|
284
|
+
// cost is already shown inline at the end of each response.
|
|
283
285
|
showPrompt();
|
|
284
286
|
break;
|
|
285
287
|
case "error":
|
|
@@ -395,7 +397,8 @@ async function handleCommand(cmd) {
|
|
|
395
397
|
if (res.ok) {
|
|
396
398
|
currentModel = res.active || parts[1];
|
|
397
399
|
printSuccess(`${t("tui.switchedTo")}: ${currentModel}`);
|
|
398
|
-
|
|
400
|
+
// Header stays as-is (would appear inline otherwise) —
|
|
401
|
+
// next /clear redraws it with the new model.
|
|
399
402
|
}
|
|
400
403
|
else {
|
|
401
404
|
printError(res.error || t("tui.switchError"));
|
|
@@ -508,10 +511,15 @@ async function handleCommand(cmd) {
|
|
|
508
511
|
}
|
|
509
512
|
case "clear":
|
|
510
513
|
case "c":
|
|
511
|
-
|
|
512
|
-
|
|
514
|
+
// /clear is the ONLY command that safely redraws the header, because
|
|
515
|
+
// it wipes the entire screen first.
|
|
516
|
+
redrawHeader({ clearScreen: true });
|
|
513
517
|
if (ws?.readyState === WebSocket.OPEN) {
|
|
514
|
-
ws.send(JSON.stringify({
|
|
518
|
+
ws.send(JSON.stringify({
|
|
519
|
+
type: "reset",
|
|
520
|
+
target: activeTarget,
|
|
521
|
+
sessionKey: activeTarget === "tui" ? tuiSessionKey : undefined,
|
|
522
|
+
}));
|
|
515
523
|
}
|
|
516
524
|
break;
|
|
517
525
|
case "target":
|
|
@@ -520,12 +528,10 @@ async function handleCommand(cmd) {
|
|
|
520
528
|
if (val === "tui") {
|
|
521
529
|
activeTarget = "tui";
|
|
522
530
|
printSuccess("Target: TUI (your own isolated session)");
|
|
523
|
-
redrawHeader();
|
|
524
531
|
}
|
|
525
532
|
else if (val === "telegram" || val === "tel") {
|
|
526
533
|
activeTarget = "telegram";
|
|
527
534
|
printSuccess("Target: Telegram (your messages now go into the Telegram session — the bot replies in Telegram AND here)");
|
|
528
|
-
redrawHeader();
|
|
529
535
|
}
|
|
530
536
|
else {
|
|
531
537
|
printInfo(`Current target: ${activeTarget}. Use /target tui or /target telegram.`);
|
|
@@ -639,12 +645,12 @@ export async function startTUI() {
|
|
|
639
645
|
// mode on top of that causes every keystroke to be echoed TWICE (once by
|
|
640
646
|
// the terminal, once by readline's line editor) — producing the classic
|
|
641
647
|
// "hheelllloo" double-echo bug. Let readline manage the tty mode itself.
|
|
642
|
-
// Handle terminal resize —
|
|
648
|
+
// Handle terminal resize — we can't safely redraw the header in place
|
|
649
|
+
// on a scrolled buffer. Just re-render the prompt so readline picks up
|
|
650
|
+
// the new width for its line editor.
|
|
643
651
|
process.stdout.on("resize", () => {
|
|
644
|
-
if (!isStreaming)
|
|
645
|
-
redrawHeader();
|
|
652
|
+
if (!isStreaming)
|
|
646
653
|
showPrompt();
|
|
647
|
-
}
|
|
648
654
|
});
|
|
649
655
|
await fetchInitialModel();
|
|
650
656
|
connectWebSocket();
|