feat(v0.4): session manager grid with live preview thumbnails

The flat session list didn't tell you what each session was doing. Rebuild
/manage.html as a full-page grid where each card renders a LIVE preview
thumbnail — a read-only xterm showing the session's actual current screen,
scaled down like a screenshot — so you can recognize each at a glance.

- RingBuffer.tail(maxBytes): newest scrollback on chunk boundaries (no ANSI/UTF-8
  split); GET /live-sessions/:id/preview returns {cols,rows,data} (no attach, so
  it doesn't inflate watcher counts or keep sessions alive)
- manage.ts: card grid; per card a scaled read-only Terminal renders CLEAR+tail,
  auto-refresh every 4s, click thumbnail/Open to join, Kill / bulk kill
- bundles xterm into manage.js (+manage.css linked in manage.html)
- ring-buffer tail tests

Verified: 3 sessions rendered as recognizable thumbnails (top / git log / ls),
colored, with status/age; click opens. 228 tests green, tsc clean.
This commit is contained in:
Yaojia Wang
2026-06-19 11:37:32 +02:00
parent 199e29d15b
commit 787f806e02
7 changed files with 278 additions and 87 deletions

View File

@@ -35,6 +35,31 @@ describe('createRingBuffer', () => {
});
});
describe('tail()', () => {
it('returns empty for an empty buffer or non-positive maxBytes', () => {
const rb = createRingBuffer(1024);
expect(rb.tail(100)).toBe('');
rb.append('hello');
expect(rb.tail(0)).toBe('');
});
it('returns the most recent chunks up to ~maxBytes, on chunk boundaries', () => {
const rb = createRingBuffer(1024);
rb.append('aaaa'); // 4 bytes
rb.append('bbbb'); // 4 bytes
rb.append('cccc'); // 4 bytes
// maxBytes=5 → newest 'cccc' (4) then 'bbbb' (8 ≥ 5) → stop; never splits.
expect(rb.tail(5)).toBe('bbbbcccc');
});
it('returns the whole buffer when maxBytes exceeds its size (no soft-reset)', () => {
const rb = createRingBuffer(1024);
rb.append('one');
rb.append('two');
expect(rb.tail(1000)).toBe('onetwo');
});
});
describe('within capacity', () => {
it('replays everything appended, in order', () => {
const rb = createRingBuffer(1024);