Mona commited on
Commit Β·
f7d6d0f
1
Parent(s): abec589
fix(tui): log panel cut off the two newest entries + auto-follow
Browse filesThe Activity panel draws a header row and bottom border, so only
(panel height - 2) entries fit β but the render window was sized for
the full panel height. The two newest log lines were silently dropped
on every render. The log window now matches the visible rows.
Also: new activity auto-follows β scrolling up to read history no
longer leaves the view stuck; the next event snaps back to the latest
entry. Added 'g' / End to jump to the end manually.
- tui.js: logViewH sizing, auto-follow in #log, g/End keys, injectable
stdin for tests
- test/tui-scroll.test.mjs: auto-follow + jump-to-end coverage
- package.json +1 -1
- src/tui.js +21 -7
- test/tui-scroll.test.mjs +73 -0
package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
| 10 |
"start": "node bin/mona-agent.js start",
|
| 11 |
"gui": "node bin/mona-agent.js gui",
|
| 12 |
"login": "node bin/mona-agent.js login",
|
| 13 |
-
"test": "node --test test/agent.test.mjs test/control.test.mjs test/docker-control.test.mjs"
|
| 14 |
},
|
| 15 |
"engines": {
|
| 16 |
"node": ">=20"
|
|
|
|
| 10 |
"start": "node bin/mona-agent.js start",
|
| 11 |
"gui": "node bin/mona-agent.js gui",
|
| 12 |
"login": "node bin/mona-agent.js login",
|
| 13 |
+
"test": "node --test test/agent.test.mjs test/control.test.mjs test/docker-control.test.mjs test/tui-scroll.test.mjs"
|
| 14 |
},
|
| 15 |
"engines": {
|
| 16 |
"node": ">=20"
|
src/tui.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
| 16 |
// c Clear activity log
|
| 17 |
// d Toggle debug info
|
| 18 |
// β / β Scroll log
|
|
|
|
| 19 |
// h / ? Show help + connect instructions
|
| 20 |
|
| 21 |
import os from 'node:os';
|
|
@@ -191,9 +192,11 @@ export class Dashboard {
|
|
| 191 |
};
|
| 192 |
#renderTimer = null;
|
| 193 |
#agent = null;
|
|
|
|
| 194 |
|
| 195 |
-
constructor(agent, { out = process.stdout, setup = false } = {}) {
|
| 196 |
this.#out = out;
|
|
|
|
| 197 |
this.#agent = agent || null;
|
| 198 |
const creds = loadCreds();
|
| 199 |
this.#state.agentId = agent?.creds?.agentId || creds?.agentId || null;
|
|
@@ -207,12 +210,12 @@ export class Dashboard {
|
|
| 207 |
}
|
| 208 |
|
| 209 |
this.#out.write(ansi.hide);
|
| 210 |
-
if (
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
}
|
| 215 |
-
|
| 216 |
this.#out.on?.('resize', () => this.#render());
|
| 217 |
|
| 218 |
if (this.#agent) this.#wireAgent(this.#agent);
|
|
@@ -305,6 +308,9 @@ export class Dashboard {
|
|
| 305 |
#log(type, msg) {
|
| 306 |
this.#logs.push({ time: timeStr(), type, msg });
|
| 307 |
if (this.#logs.length > this.#maxLogs) this.#logs.shift();
|
|
|
|
|
|
|
|
|
|
| 308 |
}
|
| 309 |
|
| 310 |
// ββ Input handling ββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -364,6 +370,10 @@ export class Dashboard {
|
|
| 364 |
case '\x1b[B': // Down
|
| 365 |
this.#scrollOffset = Math.max(0, this.#scrollOffset - 1);
|
| 366 |
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
}
|
| 368 |
}
|
| 369 |
|
|
@@ -443,7 +453,11 @@ export class Dashboard {
|
|
| 443 |
|
| 444 |
const sysLines = this.#renderSystem(wide ? Math.floor(W * 0.38) - 2 : W - 2, panelH);
|
| 445 |
const taskLines = this.#renderTask(wide ? Math.floor(W * 0.38) - 2 : W - 2, panelH);
|
| 446 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 447 |
|
| 448 |
if (wide) {
|
| 449 |
const leftW = Math.floor(W * 0.38);
|
|
|
|
| 16 |
// c Clear activity log
|
| 17 |
// d Toggle debug info
|
| 18 |
// β / β Scroll log
|
| 19 |
+
// g / End Jump to end of log (auto-follow on)
|
| 20 |
// h / ? Show help + connect instructions
|
| 21 |
|
| 22 |
import os from 'node:os';
|
|
|
|
| 192 |
};
|
| 193 |
#renderTimer = null;
|
| 194 |
#agent = null;
|
| 195 |
+
#stdin = null;
|
| 196 |
|
| 197 |
+
constructor(agent, { out = process.stdout, setup = false, stdin = process.stdin } = {}) {
|
| 198 |
this.#out = out;
|
| 199 |
+
this.#stdin = stdin;
|
| 200 |
this.#agent = agent || null;
|
| 201 |
const creds = loadCreds();
|
| 202 |
this.#state.agentId = agent?.creds?.agentId || creds?.agentId || null;
|
|
|
|
| 210 |
}
|
| 211 |
|
| 212 |
this.#out.write(ansi.hide);
|
| 213 |
+
if (this.#stdin.isTTY) {
|
| 214 |
+
this.#stdin.setRawMode?.(true);
|
| 215 |
+
this.#stdin.resume();
|
| 216 |
+
this.#stdin.setEncoding('utf8');
|
| 217 |
}
|
| 218 |
+
this.#stdin.on('data', (key) => this.#onKey(key));
|
| 219 |
this.#out.on?.('resize', () => this.#render());
|
| 220 |
|
| 221 |
if (this.#agent) this.#wireAgent(this.#agent);
|
|
|
|
| 308 |
#log(type, msg) {
|
| 309 |
this.#logs.push({ time: timeStr(), type, msg });
|
| 310 |
if (this.#logs.length > this.#maxLogs) this.#logs.shift();
|
| 311 |
+
// Auto-follow: new activity snaps the view back to the latest entry.
|
| 312 |
+
// (Scrolling up to read history is fine β the next event brings you back.)
|
| 313 |
+
this.#scrollOffset = 0;
|
| 314 |
}
|
| 315 |
|
| 316 |
// ββ Input handling ββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 370 |
case '\x1b[B': // Down
|
| 371 |
this.#scrollOffset = Math.max(0, this.#scrollOffset - 1);
|
| 372 |
break;
|
| 373 |
+
case 'g':
|
| 374 |
+
case '\x1b[F': // End
|
| 375 |
+
this.#scrollOffset = 0;
|
| 376 |
+
break;
|
| 377 |
}
|
| 378 |
}
|
| 379 |
|
|
|
|
| 453 |
|
| 454 |
const sysLines = this.#renderSystem(wide ? Math.floor(W * 0.38) - 2 : W - 2, panelH);
|
| 455 |
const taskLines = this.#renderTask(wide ? Math.floor(W * 0.38) - 2 : W - 2, panelH);
|
| 456 |
+
// The log panel draws a header row and a bottom border, so only
|
| 457 |
+
// (panel height β 2) entries are actually visible. Size the window
|
| 458 |
+
// accordingly or the two newest entries get cut off every render.
|
| 459 |
+
const logViewH = wide ? bodyH - 2 : Math.max(1, bodyH - panelH - 2);
|
| 460 |
+
const logLines = this.#renderLog(wide ? W - Math.floor(W * 0.38) - 3 : W - 2, logViewH);
|
| 461 |
|
| 462 |
if (wide) {
|
| 463 |
const leftW = Math.floor(W * 0.38);
|
test/tui-scroll.test.mjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// TUI scroll behavior: auto-follow to the latest entry, manual jump keys.
|
| 2 |
+
// Run: node --test test/tui-scroll.test.mjs
|
| 3 |
+
|
| 4 |
+
import { describe, it, after } from 'node:test';
|
| 5 |
+
import assert from 'node:assert/strict';
|
| 6 |
+
import { EventEmitter } from 'node:events';
|
| 7 |
+
import { PassThrough } from 'node:stream';
|
| 8 |
+
import { Dashboard } from '../src/tui.js';
|
| 9 |
+
|
| 10 |
+
class FakeTTY extends PassThrough {
|
| 11 |
+
constructor(cols, rows) { super(); this.isTTY = true; this.columns = cols; this.rows = rows; }
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
const strip = (raw) => raw
|
| 15 |
+
.replace(/\x1b\[[0-9;]*[A-Za-z]/g, '')
|
| 16 |
+
.replace(/\x1b\[[0-9;]*m/g, '');
|
| 17 |
+
|
| 18 |
+
const render = (out) => new Promise((resolve) => {
|
| 19 |
+
setTimeout(() => resolve(strip(out.read()?.toString() || '')), 250);
|
| 20 |
+
});
|
| 21 |
+
|
| 22 |
+
describe('dashboard scroll', () => {
|
| 23 |
+
after(() => {});
|
| 24 |
+
|
| 25 |
+
it('auto-follows to the newest entry even after scrolling up', async () => {
|
| 26 |
+
const out = new FakeTTY(100, 16);
|
| 27 |
+
const stdin = new FakeTTY(100, 16);
|
| 28 |
+
const agent = new EventEmitter();
|
| 29 |
+
agent.creds = { agentId: 'agent-1' };
|
| 30 |
+
const dash = new Dashboard(agent, { out, stdin });
|
| 31 |
+
dash.start();
|
| 32 |
+
agent.emit('connected');
|
| 33 |
+
|
| 34 |
+
// Fill the log so entries overflow the viewport (rows=16).
|
| 35 |
+
for (let i = 0; i < 30; i++) agent.emit('tool:done', `fill${i}`, {});
|
| 36 |
+
let text = await render(out);
|
| 37 |
+
assert.ok(text.includes('fill29 done'), 'newest entry visible at the bottom');
|
| 38 |
+
|
| 39 |
+
// Scroll up into history β the newest entry leaves the viewport.
|
| 40 |
+
for (let i = 0; i < 8; i++) stdin.write('\x1b[A');
|
| 41 |
+
text = await render(out);
|
| 42 |
+
assert.ok(!text.includes('fill29 done'), 'scrolled away from the newest entry');
|
| 43 |
+
|
| 44 |
+
// New activity arrives β the view must snap back to the bottom.
|
| 45 |
+
agent.emit('tool:done', 'fresh', {});
|
| 46 |
+
text = await render(out);
|
| 47 |
+
assert.ok(text.includes('fresh done'), 'auto-follow pulled the view back to the newest entry');
|
| 48 |
+
|
| 49 |
+
dash.stop();
|
| 50 |
+
});
|
| 51 |
+
|
| 52 |
+
it('g jumps to the end of the log', async () => {
|
| 53 |
+
const out = new FakeTTY(100, 16);
|
| 54 |
+
const stdin = new FakeTTY(100, 16);
|
| 55 |
+
const agent = new EventEmitter();
|
| 56 |
+
agent.creds = { agentId: 'agent-1' };
|
| 57 |
+
const dash = new Dashboard(agent, { out, stdin });
|
| 58 |
+
dash.start();
|
| 59 |
+
agent.emit('connected');
|
| 60 |
+
for (let i = 0; i < 30; i++) agent.emit('tool:done', `gfill${i}`, {});
|
| 61 |
+
let text = await render(out);
|
| 62 |
+
|
| 63 |
+
for (let i = 0; i < 8; i++) stdin.write('\x1b[A');
|
| 64 |
+
text = await render(out);
|
| 65 |
+
assert.ok(!text.includes('gfill29 done'));
|
| 66 |
+
|
| 67 |
+
stdin.write('g');
|
| 68 |
+
text = await render(out);
|
| 69 |
+
assert.ok(text.includes('gfill29 done'));
|
| 70 |
+
|
| 71 |
+
dash.stop();
|
| 72 |
+
});
|
| 73 |
+
});
|