mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-12-02 00:59:32 +01:00
fix(tiles): send a tile's click report ephemeral, review follow-up
The tile's hand-encoded click report went through _handleDesktopTerminalClick and _sendSyntheticSgrTap to _sendInputAsync, so it took a seq, was persisted and would be redelivered after a reload. The documented TerminalTile rule (CLAUDE.md, Split-pane sessions) is that only typed input enters that queue and focus/mouse reports go out ephemeral, and the tile's own _onTerminalData says the same. Before #555 an opencode tile's click went through xterm's encoder and that ephemeral path. A click still unacknowledged when the page reloads, or sent during a server restart, could be replayed onto a later screen, where a press+release can pick a dialog option. _sendSyntheticSgrTap now takes an opt-in `ephemeral` field on its target and sends through _sendInputEphemeral when it is set; _handleDesktopTerminalClick passes the target through unchanged, and TerminalTile._installClickListener sets it. Without the flag nothing changes, so the primary pane's own click and touch tap reports stay on _sendInputAsync exactly as before (whether the primary pane should also go ephemeral is a separate question, out of scope here). Tests: the tile case now requires a frame with no seq and nothing pending in the reliable queue, and the targeted-click case in terminal-touch-tap spies on both send paths: a target with the flag goes ephemeral, an untargeted click and an untargeted tap stay durable. Dropping `ephemeral: true` from the tile, or the branch in _sendSyntheticSgrTap, turns the matching test red. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
24a73ecd81
commit
a96a94fb7e
5 files changed
+50
-15
No files matched your search
@@ -801,7 +801,7 @@ Further detail: with many sessions the horizontal strip stops being scannable, w
|
||||
|
||||
### Split-pane sessions
|
||||
|
||||
**Split-pane sessions** (`showSplitButton`, header button, default OFF, per-device like `showFileViewerButton` — not in `SettingsUpdateSchema`, `displayKeys` in settings-ui.js): shows two live sessions side-by-side in one Codeman window. Pane A is the untouched, existing singleton terminal (`this.terminal`/`this._ws` in terminal-ui.js); Pane B is an independent `TerminalTile` (terminal-tile.js, constructed by the orchestration in terminal-split.js) with its own xterm instance and its own `/ws/sessions/:id/terminal` WebSocket, whose `cid` is the tab's identity with a `:tile` suffix, so it can never supersede the primary pane's socket (the registry supersedes by cid per session). ⚠️ **Pane B is deliberately plainer than Pane A** — no local-echo overlay, no CJK IME, no touch/mobile handlers, no keyboard accessory bar (it does carry the primary pane's hollow-buffer wheel paging and desktop click report, through terminal-ui.js's own gates aimed at the tile, and its own keyCode-229 soft-keyboard controller from terminal-keycode229-recovery.js, the #441 next-keydown drain and #541's edit-based diff for Android autocorrect, since the 1180px width gate is reachable by a wide Android tablet; see terminal-tile.js's fileoverview) — since this is a desktop-only feature (a split view needs a wide viewport) and those features exist for mobile/touch input; `.btn-split` is hard-hidden below 1180px regardless of the setting by the `@media (max-width: 1179px)` rule in styles.css (mobile.css only carries a comment pointing at it: that file loads up to 1023px, so it cannot cover the 1024-1179px tablet range the feature also needs to stay off), and the per-device setting means turning it on at a desk can never sync it onto a phone in the first place. No persistence: closing the browser tab or reloading always returns to the normal single-pane view; there is no localStorage key for split state. ⚠️ Splitting a session against itself is disallowed (the picker excludes the active session), **as is splitting against a popped-out (detached) session** — `buildSplitPickerSessions()` excludes `detachedSessions` because a detached session's own window is already claiming its PTY size, and `MAX_WS_PER_SESSION` needs no change since Pane A/B are always two different sessions. ⚠️ Either pane's session ending (deleted locally or from another client) auto-collapses the split — Pane A's session ending promotes Pane B to the new single pane via `selectSession(id, { auto: true })` (an app-driven selection, so it must not spend the session's idle alert — see the Approvals Inbox note above), never by trying to hot-swap the lightweight `TerminalTile` object into the primary singleton state. ⚠️ Pane B refits on every window/sidebar/tab-rail resize via the SAME trailing-edge `ResizeObserver` callback that resizes Pane A (`throttledResize` in terminal-ui.js) — it only ever measured Pane A's own container, so without the explicit `this._forEachTile?.((tile) => tile.fit(), { grid: false })` call there (grid tiles are left out: the grid's own observer refits them on the same resize) Pane B silently kept its stale PTY size through every resize that did not happen to be a divider drag. ⚠️ A dropped WebSocket writes a `[disconnected, reconnecting…]` marker into Pane B and reconnects on the primary pane's backoff ladder (`CodemanWsReconnect` plus jitter; the attempt count resets only on a successful open), then refreshes the buffer to close the output gap. ⚠️ The open handler clears `_wsClosed`/`_markerOwed` BEFORE that refresh, or the refresh re-owes the marker and stamps it under a healthy pane. ⚠️ 4003/4004/4009/4010 stop the pane for good, report once through `onExit(code)` and write a marker saying why (`CodemanWsReconnect` alone would retry 4003). ⚠️ A replacement socket detaches the old one first and every handler ignores a socket that is no longer `this.ws`, so a late 4010 from a superseded socket cannot stop its successor; `destroy()` cancels a pending reconnect. Related but distinct: `detachSession()` already opens one session in a separate OS-level browser window (`isSoloWindow`) — that is prior art for "two sessions visible at once" but not for one window with a draggable in-page divider, which is what this feature adds. ⚠️ Pane B installs its own `attachCustomKeyEventHandler` gating the same app-level chords Pane A's own handler gates (command palette, Alt+1-9/[/] tab nav, Alt+B sidebar toggle, Ctrl+Z suspend, Shift/Ctrl+Enter newline, smart-copy Ctrl+C) — without it the document capture-phase handler's `preventDefault()` (which never stops xterm) let each chord ALSO write its raw byte/escape sequence into Pane B's live PTY on top of whatever the app action did to Pane A (COD-153). Ctrl+Z is swallowed unless Pane B's own session is `mode === 'shell'`, mirroring terminal-ui.js's reasoning: in a plain shell it is the user's own job-control tool, everywhere else it silently suspends an unattenLine truncated
|
||||
**Split-pane sessions** (`showSplitButton`, header button, default OFF, per-device like `showFileViewerButton` — not in `SettingsUpdateSchema`, `displayKeys` in settings-ui.js): shows two live sessions side-by-side in one Codeman window. Pane A is the untouched, existing singleton terminal (`this.terminal`/`this._ws` in terminal-ui.js); Pane B is an independent `TerminalTile` (terminal-tile.js, constructed by the orchestration in terminal-split.js) with its own xterm instance and its own `/ws/sessions/:id/terminal` WebSocket, whose `cid` is the tab's identity with a `:tile` suffix, so it can never supersede the primary pane's socket (the registry supersedes by cid per session). ⚠️ **Pane B is deliberately plainer than Pane A** — no local-echo overlay, no CJK IME, no touch/mobile handlers, no keyboard accessory bar (it does carry the primary pane's hollow-buffer wheel paging and desktop click report, through terminal-ui.js's own gates aimed at the tile, and its own keyCode-229 soft-keyboard controller from terminal-keycode229-recovery.js, the #441 next-keydown drain and #541's edit-based diff for Android autocorrect, since the 1180px width gate is reachable by a wide Android tablet; see terminal-tile.js's fileoverview) — since this is a desktop-only feature (a split view needs a wide viewport) and those features exist for mobile/touch input; `.btn-split` is hard-hidden below 1180px regardless of the setting by the `@media (max-width: 1179px)` rule in styles.css (mobile.css only carries a comment pointing at it: that file loads up to 1023px, so it cannot cover the 1024-1179px tablet range the feature also needs to stay off), and the per-device setting means turning it on at a desk can never sync it onto a phone in the first place. No persistence: closing the browser tab or reloading always returns to the normal single-pane view; there is no localStorage key for split state. ⚠️ Splitting a session against itself is disallowed (the picker excludes the active session), **as is splitting against a popped-out (detached) session** — `buildSplitPickerSessions()` excludes `detachedSessions` because a detached session's own window is already claiming its PTY size, and `MAX_WS_PER_SESSION` needs no change since Pane A/B are always two different sessions. ⚠️ Either pane's session ending (deleted locally or from another client) auto-collapses the split — Pane A's session ending promotes Pane B to the new single pane via `selectSession(id, { auto: true })` (an app-driven selection, so it must not spend the session's idle alert — see the Approvals Inbox note above), never by trying to hot-swap the lightweight `TerminalTile` object into the primary singleton state. ⚠️ Pane B refits on every window/sidebar/tab-rail resize via the SAME trailing-edge `ResizeObserver` callback that resizes Pane A (`throttledResize` in terminal-ui.js) — it only ever measured Pane A's own container, so without the explicit `this._forEachTile?.((tile) => tile.fit(), { grid: false })` call there (grid tiles are left out: the grid's own observer refits them on the same resize) Pane B silently kept its stale PTY size through every resize that did not happen to be a divider drag. ⚠️ A dropped WebSocket writes a `[disconnected, reconnecting…]` marker into Pane B and reconnects on the primary pane's backoff ladder (`CodemanWsReconnect` plus jitter; the attempt count resets only on a successful open), then refreshes the buffer to close the output gap. ⚠️ The open handler clears `_wsClosed`/`_markerOwed` BEFORE that refresh, or the refresh re-owes the marker and stamps it under a healthy pane. ⚠️ 4003/4004/4009/4010 stop the pane for good, report once through `onExit(code)` and write a marker saying why (`CodemanWsReconnect` alone would retry 4003). ⚠️ A replacement socket detaches the old one first and every handler ignores a socket that is no longer `this.ws`, so a late 4010 from a superseded socket cannot stop its successor; `destroy()` cancels a pending reconnect. Related but distinct: `detachSession()` already opens one session in a separate OS-level browser window (`isSoloWindow`) — that is prior art for "two sessions visible at once" but not for one window with a draggable in-page divider, which is what this feature adds. ⚠️ Pane B installs its own `attachCustomKeyEventHandler` gating the same app-level chords Pane A's own handler gates (command palette, Alt+1-9/[/] tab nav, Alt+B sidebar toggle, Ctrl+Z suspend, Shift/Ctrl+Enter newline, smart-copy Ctrl+C) — without it the document capture-phase handler's `preventDefault()` (which never stops xterm) let each chord ALSO write its raw byte/escape sequence into Pane B's live PTY on top of whatever the app action did to Pane A (COD-153). Ctrl+Z is swallowed unless Pane B's own session is `mode === 'shell'`, mirroring terminal-ui.js's reasoning: in a plain shell it is the user's own job-control tool, everywhere else it silently suspends an unattenLine truncated
|
||||
|
||||
### Tile grid
|
||||
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
* wheel-down from those overflow rows is xterm's, and brings it home).
|
||||
* - The desktop click report: a plain left-click hand-encoded as SGR while
|
||||
* the session's CLI has mouse tracking on (cliMouseTracking), for the modes
|
||||
* whose mouse DECSETs the server strips (_installClickListener).
|
||||
* whose mouse DECSETs the server strips (_installClickListener), sent
|
||||
* ephemeral, like every mouse report from this pane (_onTerminalData).
|
||||
* - The soft-keyboard controller (terminal-keycode229-recovery.js), one per
|
||||
* pane, on this pane's own textarea and composition helper and sending to
|
||||
* this pane's session (_createKeyCode229Recovery): it forwards an
|
||||
@@ -860,6 +861,9 @@
|
||||
terminal: this.terminal,
|
||||
sessionId: this.sessionId,
|
||||
linkHovered: this._linkHovered,
|
||||
// Like every mouse report from this pane (_onTerminalData): once,
|
||||
// never persisted, so a reload cannot replay it onto a later screen.
|
||||
ephemeral: true,
|
||||
});
|
||||
};
|
||||
this.mountEl.addEventListener('click', this._onClick);
|
||||
|
||||
@@ -5465,8 +5465,13 @@ Object.assign(CodemanApp.prototype, {
|
||||
|
||||
// Encode a tap as an SGR mouse report (press + release at button 0) and send it
|
||||
// to the PTY directly, bypassing xterm's mouse encoder. `target` ({ terminal,
|
||||
// sessionId }) aims it at a TerminalTile instead of the primary pane; either
|
||||
// field left out means the primary pane's.
|
||||
// sessionId, ephemeral }) aims it at a TerminalTile instead of the primary
|
||||
// pane; either of the first two left out means the primary pane's.
|
||||
// `ephemeral: true` sends it through _sendInputEphemeral instead of the
|
||||
// persisted exactly-once queue: a TerminalTile's mouse reports never enter
|
||||
// that queue (CLAUDE.md, Split-pane sessions), or a reload would replay one
|
||||
// onto a later screen. Left out, the report stays on _sendInputAsync, as the
|
||||
// primary pane always sent it.
|
||||
_sendSyntheticSgrTap(clientX, clientY, target = {}) {
|
||||
const sessionId = target.sessionId || this.activeSessionId;
|
||||
const terminal = target.terminal || this.terminal;
|
||||
@@ -5474,7 +5479,9 @@ Object.assign(CodemanApp.prototype, {
|
||||
if (!this._terminalViewportAtBottom(terminal)) return; // scrollback click → misfire, do nothing
|
||||
const pos = this._clientPointToCell(clientX, clientY, terminal);
|
||||
if (!pos) return;
|
||||
this._sendInputAsync(sessionId, `\x1b[<0;${pos.col};${pos.row}M\x1b[<0;${pos.col};${pos.row}m`);
|
||||
const report = `\x1b[<0;${pos.col};${pos.row}M\x1b[<0;${pos.col};${pos.row}m`;
|
||||
if (target.ephemeral) this._sendInputEphemeral(sessionId, report);
|
||||
else this._sendInputAsync(sessionId, report);
|
||||
},
|
||||
|
||||
// True when a parsed CLI version string ('2.1.187' — banner-parsed on the
|
||||
@@ -5758,10 +5765,12 @@ Object.assign(CodemanApp.prototype, {
|
||||
// clicks outside the cell grid, and sessions where xterm's own encoder is
|
||||
// live (it reported the click itself — a second report would double-move).
|
||||
//
|
||||
// `target` ({ terminal, sessionId, linkHovered }) runs the same skips for a
|
||||
// TerminalTile's click: its own terminal, its own session's tracking flag and
|
||||
// its own link hover (the primary pane's _linkHovered belongs to its terminal
|
||||
// alone). Every field left out means the primary pane's.
|
||||
// `target` ({ terminal, sessionId, linkHovered, ephemeral }) runs the same
|
||||
// skips for a TerminalTile's click: its own terminal, its own session's
|
||||
// tracking flag and its own link hover (the primary pane's _linkHovered
|
||||
// belongs to its terminal alone). `ephemeral` reaches _sendSyntheticSgrTap,
|
||||
// so a TerminalTile's mouse report never enters the persisted input queue.
|
||||
// Every field left out means the primary pane's.
|
||||
_handleDesktopTerminalClick(ev, target = {}) {
|
||||
const terminal = target.terminal || this.terminal;
|
||||
if (!terminal || !ev?.isTrusted) return;
|
||||
|
||||
@@ -514,13 +514,16 @@ describe('a tile reports a plain click to a CLI with mouse tracking on', () => {
|
||||
});
|
||||
const TAP = '\x1b[<0;21;6M\x1b[<0;21;6m';
|
||||
|
||||
it("sends one seq-tagged SGR press+release on the tile's socket, from the tile's own geometry", async () => {
|
||||
it("sends one ephemeral SGR press+release on the tile's socket, from the tile's own geometry", async () => {
|
||||
const app = makeApp({ other: { mode: 'shell' }, 's-tile': { mode: 'opencode', cliMouseTracking: true } });
|
||||
const { ws, mount } = await connectTile(app);
|
||||
|
||||
mount.fire('click', click());
|
||||
|
||||
expect(ws.inputFrames().map((f) => [f.d, typeof f.seq])).toEqual([[TAP, 'number']]);
|
||||
// No seq: like every mouse report from a tile, it never enters the
|
||||
// persisted exactly-once queue, so a reload cannot replay it.
|
||||
expect(ws.inputFrames().map((f) => [f.d, typeof f.seq])).toEqual([[TAP, 'undefined']]);
|
||||
expect((app._pendingDeliveries as Map<string, unknown[]>).get('s-tile')?.length ?? 0).toBe(0);
|
||||
});
|
||||
|
||||
it('sends nothing without the flag, over a selection, over its own hovered link, or scrolled up', async () => {
|
||||
|
||||
@@ -583,12 +583,16 @@ describe('terminal touch tap mouse guard', () => {
|
||||
// primary pane's terminal and active session are not consulted.
|
||||
const { app } = loadTerminalUiHarness();
|
||||
const sent: Array<{ id: string; data: string }> = [];
|
||||
// A tile's report must stay out of the persisted queue: it asks for the
|
||||
// ephemeral path, and only a target that says so gets it.
|
||||
const durable: Array<{ id: string; data: string }> = [];
|
||||
app.activeSessionId = 'sess-1';
|
||||
app.sessions = new Map([
|
||||
['sess-1', { mode: 'claude', cliMouseTracking: false }],
|
||||
['s2', { mode: 'opencode', cliMouseTracking: true }],
|
||||
]);
|
||||
app._sendInputAsync = (id: string, data: string) => sent.push({ id, data });
|
||||
app._sendInputEphemeral = (id: string, data: string) => sent.push({ id, data });
|
||||
app._sendInputAsync = (id: string, data: string) => durable.push({ id, data });
|
||||
app._linkHovered = true; // the PRIMARY pane's hover: must not block the tile
|
||||
app.terminal = {
|
||||
cols: 80,
|
||||
@@ -618,14 +622,16 @@ describe('terminal touch tap mouse guard', () => {
|
||||
target: { closest: (sel: string) => (sel === '.xterm-screen' ? {} : null) },
|
||||
};
|
||||
|
||||
app._handleDesktopTerminalClick(click, { terminal: other, sessionId: 's2', linkHovered: false });
|
||||
const tile = { terminal: other, sessionId: 's2', linkHovered: false, ephemeral: true };
|
||||
app._handleDesktopTerminalClick(click, tile);
|
||||
expect(sent).toEqual([{ id: 's2', data: '\x1b[<0;21;6M\x1b[<0;21;6m' }]);
|
||||
expect(durable).toEqual([]);
|
||||
|
||||
// The tile's own selection and its own link hover do block it.
|
||||
otherSelected = true;
|
||||
app._handleDesktopTerminalClick(click, { terminal: other, sessionId: 's2', linkHovered: false });
|
||||
app._handleDesktopTerminalClick(click, tile);
|
||||
otherSelected = false;
|
||||
app._handleDesktopTerminalClick(click, { terminal: other, sessionId: 's2', linkHovered: true });
|
||||
app._handleDesktopTerminalClick(click, { ...tile, linkHovered: true });
|
||||
expect(sent).toHaveLength(1);
|
||||
|
||||
// With no target the primary pane answers for itself, exactly as before.
|
||||
@@ -633,6 +639,19 @@ describe('terminal touch tap mouse guard', () => {
|
||||
expect(app._shouldReportMouseToCli('s2')).toBe(true);
|
||||
app._handleDesktopTerminalClick(click);
|
||||
expect(sent).toHaveLength(1);
|
||||
|
||||
// And the primary pane's own reports stay on the durable queue: an
|
||||
// untargeted click and an untargeted touch tap.
|
||||
app.sessions.set('sess-1', { mode: 'claude', cliMouseTracking: true });
|
||||
app.terminal = { ...app.terminal, hasSelection: () => false, buffer: { active: { viewportY: 50, baseY: 50 } } };
|
||||
app._linkHovered = false;
|
||||
app._handleDesktopTerminalClick(click);
|
||||
app._sendSyntheticSgrTap(50, 50);
|
||||
expect(durable).toEqual([
|
||||
{ id: 'sess-1', data: '\x1b[<0;22;7M\x1b[<0;22;7m' }, // the primary's own origin (0, 0)
|
||||
{ id: 'sess-1', data: '\x1b[<0;7;4M\x1b[<0;7;4m' },
|
||||
]);
|
||||
expect(sent).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("tap: a target uses that pane's geometry and scroll position", () => {
|
||||
|
||||
Reference in new issue
Block a user