mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-12-05 17:29:32 +01:00
A local or Docker Claude session can show its conversation as rendered text, the way the Response Viewer draws it, in place of the terminal. The terminal stays attached and sized underneath, so switching views never resizes the pane, and the user still types in the terminal. Discussion #858 has the background. - A Chat / Terminal switch and Alt+Shift+C change the view, and each session remembers its choice on this device until the session is gone. Two per-device settings pick the default view and hide the switch. Phones, remote and adopted sessions keep the terminal. - The server broadcasts `transcript:update`, at most one per 750 ms per session, and the view re-reads the conversation on it, so an answer fills in mid-turn. - The server keeps each transcript's parse and the byte offset it reached, so a read parses only the bytes appended since the last one, in chunks with an await between them. Overlapping reads of one file share one pass. The Response Viewer and the Discord bridge read through it too. - A full conversation read starts a transcript watcher for a session that has none, such as one picked up after a server restart. - A Docker session's hook reports the container's transcript path, and the server watches the host's copy of that file. - After `/clear`, Claude Code runs the statusline command with the new conversation's id and transcript path. The statusline exporter posts them, and the server follows the new conversation the way it follows a hook's report. - Keep-warm turns are hidden, long prompts fold, a "Working" line shows the turn's running time, and a pending dialog shows a notice that opens the terminal. The design note, docs/chat-view-plan.md, covers this and the four steps that follow it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
95 lines
2.7 KiB
TypeScript
95 lines
2.7 KiB
TypeScript
/**
|
|
* @fileoverview KeyedThrottle (src/utils/keyed-throttle.ts), the per-key throttle behind the
|
|
* server's `transcript:update` broadcast.
|
|
*
|
|
* Pinned: the first call sends at once, a burst inside the interval collapses into one trailing
|
|
* send at the interval's end, the trailing send runs the newest send it was given, a call after
|
|
* the interval sends at once, keys are independent, and cancelKey()/dispose() drop a pending
|
|
* trailing send.
|
|
*
|
|
* Port: N/A
|
|
*/
|
|
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { KeyedThrottle } from '../src/utils/index.js';
|
|
|
|
describe('KeyedThrottle', () => {
|
|
let throttle: KeyedThrottle;
|
|
let sends: Array<{ key: string; at: number }>;
|
|
const fire = (key: string) => throttle.fire(key, () => sends.push({ key, at: Date.now() }));
|
|
|
|
beforeEach(() => {
|
|
vi.useFakeTimers();
|
|
vi.setSystemTime(10_000);
|
|
throttle = new KeyedThrottle(750);
|
|
sends = [];
|
|
});
|
|
|
|
afterEach(() => {
|
|
throttle.dispose();
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
it('sends the first call at once', () => {
|
|
fire('a');
|
|
expect(sends).toEqual([{ key: 'a', at: 10_000 }]);
|
|
});
|
|
|
|
it('collapses a burst into one trailing send at the end of the interval', () => {
|
|
fire('a');
|
|
vi.advanceTimersByTime(100);
|
|
fire('a');
|
|
fire('a');
|
|
vi.advanceTimersByTime(300);
|
|
fire('a');
|
|
expect(sends).toHaveLength(1);
|
|
vi.advanceTimersByTime(349);
|
|
expect(sends).toHaveLength(1);
|
|
vi.advanceTimersByTime(1);
|
|
expect(sends).toEqual([
|
|
{ key: 'a', at: 10_000 },
|
|
{ key: 'a', at: 10_750 },
|
|
]);
|
|
vi.advanceTimersByTime(5000);
|
|
expect(sends).toHaveLength(2);
|
|
});
|
|
|
|
it('runs the newest send it was given when the trailing send fires', () => {
|
|
const labels: string[] = [];
|
|
throttle.fire('a', () => labels.push('first'));
|
|
throttle.fire('a', () => labels.push('second'));
|
|
throttle.fire('a', () => labels.push('third'));
|
|
vi.advanceTimersByTime(750);
|
|
expect(labels).toEqual(['first', 'third']);
|
|
});
|
|
|
|
it('sends at once again once the interval has passed', () => {
|
|
fire('a');
|
|
vi.advanceTimersByTime(800);
|
|
fire('a');
|
|
expect(sends.map((s) => s.at)).toEqual([10_000, 10_800]);
|
|
});
|
|
|
|
it('throttles each key on its own', () => {
|
|
fire('a');
|
|
fire('b');
|
|
expect(sends.map((s) => s.key)).toEqual(['a', 'b']);
|
|
});
|
|
|
|
it('drops a pending trailing send on cancelKey() and dispose()', () => {
|
|
fire('a');
|
|
fire('a');
|
|
fire('b');
|
|
fire('b');
|
|
throttle.cancelKey('a');
|
|
vi.advanceTimersByTime(1000);
|
|
expect(sends.map((s) => s.key)).toEqual(['a', 'b', 'b']);
|
|
|
|
fire('c');
|
|
fire('c');
|
|
throttle.dispose();
|
|
vi.advanceTimersByTime(1000);
|
|
expect(sends.map((s) => s.key)).toEqual(['a', 'b', 'b', 'c']);
|
|
});
|
|
});
|