feat: DevDesk v0.1.0, a persistent browser terminal for Claude Code
ttyd serves a single-file xterm.js UI styled with the LotusGuild TDS (web_template base.css). Sessions live in a dedicated tmux server unit (devdesk-tmux.service), so restarting or upgrading the web unit never stops Claude. Each named session maps to a project directory. A Claude SessionStart hook records the conversation ID, so after a reboot the session resumes that exact conversation. - bin/devdesk: attach / new / ls / end / pick, with an fzf picker - ttyd requires a credential that NPM injects; origin check enabled - debian/: dh 13 with --no-stop-on-upgrade for the tmux unit, bundled sha256-verified ttyd 1.7.7, lintian overrides, man page - CI: lint, test, build, smoke-test, artifact; v* tags publish to the Gitea apt registry and create a release Refs: tinker ticket 887531976 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
Client, FlowControl, decodeServer, encodeBinaryInput, encodeInit, encodeInput, encodeResize,
|
||||
parseListOutput, parseTitle, sessionFromSearch, tokenUrl, wsUrl,
|
||||
} from '../web/src/protocol.js';
|
||||
|
||||
const text = (bytes) => new TextDecoder().decode(bytes);
|
||||
|
||||
test('init message is bare JSON with the auth token and size', () => {
|
||||
assert.deepEqual(JSON.parse(text(encodeInit('dG9r', 120, 40))), { AuthToken: 'dG9r', columns: 120, rows: 40 });
|
||||
});
|
||||
|
||||
test('input frames are prefixed with "0" and UTF-8 encoded', () => {
|
||||
assert.equal(text(encodeInput('héllo\n')), '0héllo\n');
|
||||
assert.deepEqual([...encodeBinaryInput('\x1b\xff')], [0x30, 0x1b, 0xff]);
|
||||
});
|
||||
|
||||
test('resize frames are "1" + JSON', () => {
|
||||
assert.equal(text(encodeResize(80, 24)), '1{"columns":80,"rows":24}');
|
||||
});
|
||||
|
||||
test('server frames split into command and payload', () => {
|
||||
const frame = new TextEncoder().encode('0output').buffer;
|
||||
const { type, payload } = decodeServer(frame);
|
||||
assert.equal(type, '0');
|
||||
assert.equal(text(payload), 'output');
|
||||
});
|
||||
|
||||
test('URLs follow the page location, including a path prefix', () => {
|
||||
const loc = { protocol: 'https:', host: 'dev.lotusguild.org', pathname: '/' };
|
||||
assert.equal(wsUrl(loc, 'main'), 'wss://dev.lotusguild.org/ws?arg=main');
|
||||
assert.equal(wsUrl(loc, null), 'wss://dev.lotusguild.org/ws');
|
||||
assert.equal(tokenUrl(loc), 'https://dev.lotusguild.org/token');
|
||||
const sub = { protocol: 'http:', host: 'localhost:7681', pathname: '/desk/index.html' };
|
||||
assert.equal(wsUrl(sub, '--list'), 'ws://localhost:7681/desk/ws?arg=--list');
|
||||
});
|
||||
|
||||
test('only valid session names are taken from the URL', () => {
|
||||
assert.equal(sessionFromSearch('?arg=tinker_tickets'), 'tinker_tickets');
|
||||
assert.equal(sessionFromSearch('?arg=../etc'), null);
|
||||
assert.equal(sessionFromSearch('?arg=--list'), null);
|
||||
assert.equal(sessionFromSearch(''), null);
|
||||
});
|
||||
|
||||
test('tmux titles carry the session and the pane title', () => {
|
||||
assert.deepEqual(parseTitle('devdesk:main|✳ Refactor | parser'), { session: 'main', pane: '✳ Refactor | parser' });
|
||||
assert.deepEqual(parseTitle('devdesk:picker|Pick a session'), { session: 'picker', pane: 'Pick a session' });
|
||||
assert.equal(parseTitle('bash'), null);
|
||||
});
|
||||
|
||||
test('session list JSON survives pty line endings', () => {
|
||||
const out = '\r\n{"default":"main","sessions":[],\r\n"projects":[]}\r\n';
|
||||
assert.deepEqual(parseListOutput(out), { default: 'main', sessions: [], projects: [] });
|
||||
const colored = '\x1b[1;39m{\x1b[0m\x1b[34;1m"default"\x1b[0m:\x1b[0;32m"main"\x1b[0m}';
|
||||
assert.deepEqual(parseListOutput(colored), { default: 'main' });
|
||||
assert.throws(() => parseListOutput('devdesk: tmux server is not running'));
|
||||
});
|
||||
|
||||
test('flow control pauses after highWater pending writes and resumes below lowWater', () => {
|
||||
const flow = new FlowControl({ limit: 10, highWater: 2, lowWater: 1 });
|
||||
assert.deepEqual(flow.onData(5), { command: null, track: false });
|
||||
assert.deepEqual(flow.onData(10), { command: null, track: true }); // pending 1
|
||||
assert.deepEqual(flow.onData(11), { command: null, track: true }); // pending 2
|
||||
assert.deepEqual(flow.onData(11), { command: Client.PAUSE, track: true }); // pending 3
|
||||
assert.equal(flow.release(), null); // 2
|
||||
assert.equal(flow.release(), null); // 1
|
||||
assert.equal(flow.release(), Client.RESUME); // 0
|
||||
});
|
||||
Reference in New Issue
Block a user