mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-09 00:49:41 +02:00
fix(tui): make an attach fit the terminal, show the way out, and resume history
Three things the first beta test surfaced. 1. Attaching from a terminal of a different shape showed the pane clipped to the browser's size, with tmux's dot padding filling the rest. Codeman pins every window it owns to `window-size manual` at whatever the web client reports (tmux-manager.ts), so no attaching client can resize it. The handoff now brackets the attach with `window-size latest` and restores the snapshot on detach. `latest`, rather than a one-off resize to our own size, is also what lets a terminal resized MID-attach follow along: tmux recomputes on every SIGWINCH while the TUI is blocked in spawnSync and cannot. 2. Nothing on screen said how to get back out, because Codeman keeps the status bar off on its panes (the web UI carries that information around the terminal instead). The tester exited the agent looking for the exit, leaving a dead pane. An attach now wears a `status-format[0]` bar reading "<prefix> D detach, back to the codeman dashboard", with the prefix READ from tmux rather than assumed, and the session's options are put back exactly as they were on detach. One option, not status-left/status-right, so tmux draws no window list beside it; `reverse` so it inherits the terminal's own theme. Restoring an array option unsets the BASE name, since dropping the `[0]` index leaves an empty array, which renders as a blank bar on a session that had one. The help overlay names the chord, and the dashboard confirms the detach. 3. Enter on a RECENT row said resuming was not wired up. It now creates a session carrying that conversation (`resumeSessionId` plus `/interactive`, the path the web UI's Resume Conversation list already uses), in the directory it ran in and under its old name, then attaches to it. The attach mechanics deliberately sit in a method the group dispatch cannot reach, plus a re-entrancy flag: routing resume back through the Enter handler re-dispatched on "this row is RECENT" and spawned one session per pass, 35 in about 40 seconds on the beta before it was killed. test/tui/tui-e2e.test.ts pins one press to one session with a pane that never appears, which is exactly the case that looped. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -45,6 +45,8 @@ const LIST_WIDTH = computeLayout(COLS, ROWS).list.width;
|
||||
const NOW = Date.now();
|
||||
|
||||
const ALPHA = 'aaaa1111-0000-0000-0000-000000000000';
|
||||
/** The id the fake server hands back for a resumed conversation. */
|
||||
const RESUMED = 'dddd4444-0000-0000-0000-000000000000';
|
||||
const BETA = 'bbbb2222-0000-0000-0000-000000000000';
|
||||
|
||||
/** Mutable so a test can add a session and announce it over SSE. */
|
||||
@@ -68,6 +70,10 @@ let liveState: Array<Record<string, unknown>> = [];
|
||||
let terminalReads = 0;
|
||||
/** Everything the TUI posted, so a test can assert on the exact body. */
|
||||
const answered: Array<{ id: string; body: Record<string, unknown> }> = [];
|
||||
/** `POST /api/sessions` bodies: resuming a RECENT row is the only thing that sends one. */
|
||||
const created: Array<Record<string, unknown>> = [];
|
||||
/** Sessions the TUI asked to start a pane for, in order. */
|
||||
const started: string[] = [];
|
||||
const inputs: Array<{ sessionId: string; body: Record<string, unknown> }> = [];
|
||||
|
||||
const PLAN_USAGE = {
|
||||
@@ -282,9 +288,22 @@ beforeAll(async () => {
|
||||
}
|
||||
if (url.startsWith('/api/sessions/unified')) return sendJson(res, { success: true, data: { sessions } });
|
||||
if (url === '/api/sessions' || url.startsWith('/api/sessions?')) {
|
||||
if (req.method === 'POST') {
|
||||
void readBody(req).then((body) => {
|
||||
created.push(body);
|
||||
sendJson(res, { success: true, data: { session: { id: RESUMED } } });
|
||||
});
|
||||
return;
|
||||
}
|
||||
return sendJson(res, { success: true, data: liveState });
|
||||
}
|
||||
|
||||
const startFor = sessionRoute(url, 'interactive');
|
||||
if (startFor) {
|
||||
started.push(startFor);
|
||||
return sendJson(res, { success: true, data: {} });
|
||||
}
|
||||
|
||||
const previewFor = sessionRoute(url, 'terminal');
|
||||
if (previewFor) {
|
||||
terminalReads++;
|
||||
@@ -662,6 +681,36 @@ describe('codeman tui (under a pty)', () => {
|
||||
await waitFor(() => !frameLines(output).join('\n').includes('no longer on screen'), 'escape to dismiss it');
|
||||
});
|
||||
|
||||
it('resumes a RECENT row exactly ONCE, however long its pane takes to appear', async () => {
|
||||
await waitFor(() => frameLines(output)[ROWS - 1].includes('attach'), 'the list to have focus');
|
||||
for (let i = 0; i < 8 && !rowFor(output, 'w3-gamma').startsWith('>'); i++) {
|
||||
term.write('\u001b[B');
|
||||
await new Promise((done) => setTimeout(done, 120));
|
||||
}
|
||||
await waitFor(() => rowFor(output, 'w3-gamma').startsWith('>'), 'the history row to be selected');
|
||||
|
||||
term.write('\r');
|
||||
await waitFor(() => created.length > 0, 'the resume POST');
|
||||
expect(created[0]).toMatchObject({
|
||||
// The conversation, in the directory it ran in, as a claude session.
|
||||
resumeSessionId: 'cccc3333-0000-0000-0000-000000000000',
|
||||
workingDir: '/tmp/gamma',
|
||||
mode: 'claude',
|
||||
name: 'w3-gamma',
|
||||
});
|
||||
await waitFor(() => started.includes(RESUMED), 'the resumed session to be started');
|
||||
|
||||
// The pane never appears here (the child runs on an empty tmux socket), which
|
||||
// is precisely the case that used to re-enter the resume: one session per
|
||||
// second until something killed it. One press must stay one session.
|
||||
await new Promise((done) => setTimeout(done, 2_500));
|
||||
expect(created).toHaveLength(1);
|
||||
expect(started).toEqual([RESUMED]);
|
||||
|
||||
term.write('\u001b');
|
||||
await waitFor(() => frameLines(output)[ROWS - 1].includes('attach'), 'the list to take focus back');
|
||||
});
|
||||
|
||||
it('quits on q and restores the screen it took over', async () => {
|
||||
term.write('q');
|
||||
await waitFor(() => exitCode !== null, 'the TUI to exit', 10_000);
|
||||
|
||||
Reference in New Issue
Block a user