Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex): guard wheel paging

[._.]/ Adam Eivyc78a8c7e73ea
diff --git a/client/src/lib/README.md b/client/src/lib/README.md
index 522f94d37d..31c26ab37c 100644
--- a/client/src/lib/README.md
+++ b/client/src/lib/README.md
@@ -192,7 +192,7 @@ grep -i "what you want to do" client/src/lib/README.md
| `tabNotation.js` | Guitar-tab / chord-sheet / ChordPro text parser for SongBook (`/songbook`). `parseTabSheet(text)` → `{ lines, meta, errors }` classifying each line (`section`/`chords`/`lyric`/`tabstaff`/`chordlyric`/`blank`/`text`) with chord names + column offsets, plus ChordPro meta (`{title:}`/`{artist:}`/`{key:}`/`{capo:}`); `detectFormat(text)` → `'chordpro' \| 'tab' \| 'plain'`; `normalizePastedTab(text)` cleans HTML remnants/entities, CRLF, tabs→spaces, blank-line runs; `transposeChordName(name, n)` / `transposeText(text, n)` transpose chord symbols (slash chords, sensible sharp/flat spelling, column-preserving on chord lines); `TAB_ARTICULATIONS` documents tab-staff technique characters for the viewer legend; `CHORD_TOKEN_RE` exported for reuse, plus `NOTE_TO_PC` / `spellPitchClass` exported minimally so `chordShapes.js` derives voicings from the same pitch-class tables. Forgiving — never throws, unknown lines classify as `text`. NOT the lead-sheet parser (`scoreNotation.js`). |
| `tailnetPeer.js` | `isTailnetPeer(peer)` — is this registered peer reachable ONLY over the tailnet? A faithful port of `server/lib/tailnetPeer.js` (MagicDNS `.ts.net`, the 100.64.0.0/10 CGNAT range with every octet range-checked, and the `fd7a:115c:a1e0::/48` ULA; an explicit non-tailnet `host` overrides a tailnet-looking `address`). FAIL-CLOSED — anything not positively recognized is not tailnet. Used to keep the unattended-render-routing picker from OFFERING a peer the server would refuse under ADR [federated visual prompts](../../../docs/decisions/2026-08-20-federated-visual-prompts.md) rule 5; the server stays authoritative and refuses such a route both on save and on every enqueue. Keep the table in `tailnetPeer.test.js` identical to the server suite’s. |
| `terminalDictation.js` | Voice-dictation/IME bridge for the Shell's xterm.js terminal. Apple dictation streams progressively refined guesses and *replaces* what it already typed; xterm forwards each insertion and drops the matching deletions, so the PTY accumulates a garble (`determin` + `determine` + `determines`…). `attachDictationBridge(terminal, sendData)` binds capture-phase listeners on `terminal.element` — ahead of xterm's own textarea listeners, which it stops — and forwards a diff instead: `TERMINAL_DEL` (`0x7f`) per dropped character, then the added text. `sendData` returns `false` to report a dropped send, which leaves the mirror where the PTY actually is. Paths that reach the PTY some other way (a keystroke xterm handles itself, paste, blur, composition end, screen-reader mode) resync the mirror without emitting. `planFieldEdit(mirror, next, floor)` → `{ data, committed }` is the pure core: `floor` is the prefix we did not write and must never rewind through, and `committed` (what the PTY holds afterward, which is *not* the field's value when the floor blocked a rewind) is what the caller must track. The prefix scan never splits a surrogate pair — cutting between the halves of an astral character would send a lone surrogate that serializes to `U+FFFD`. Wired in `useShellSession`; the test suite pins the seam against a real `Terminal`. |
-| `terminalScroll.js` | Scrolling the Shell terminal by touch, wheel, and page controls. xterm 6 binds **no touch handlers at all**, and a TUI’s ALTERNATE screen buffer has no terminal scrollback, so `scrollLines()` clamps to a no-op there. Normal shell scrollback uses `scrollLines()`; alternate-screen wheel gestures are captured before xterm’s mouse listener and translated to standard PageUp/PageDown input, which OpenCode supports for its message viewport. `attachTerminalTouchScroll(terminal)` (→ detach fn) makes a one-finger drag scroll in either buffer, `attachTerminalWheelScroll(terminal)` handles native wheel input, and `scrollTerminalPage(terminal, direction)` powers the `SCROLL_KEYS` buttons. `measureTerminalGeometry(terminal)` takes one layout read per gesture; `planTouchScrollSteps(accumPx, rowHeightPx)` is the pure sub-row-remainder core. Wired in `useShellSession`. |
+| `terminalScroll.js` | Scrolling the Shell terminal by touch, wheel, and page controls. xterm 6 binds **no touch handlers at all**, and a TUI’s ALTERNATE screen buffer has no terminal scrollback, so `scrollLines()` clamps to a no-op there. Normal shell scrollback uses `scrollLines()`; alternate-screen wheel gestures are captured before xterm’s mouse listener and translated to standard PageUp/PageDown input, which OpenCode supports for its message viewport, while apps that explicitly enable terminal mouse tracking keep xterm’s native wheel path. `attachTerminalTouchScroll(terminal)` (→ detach fn) makes a one-finger drag scroll in either buffer, `attachTerminalWheelScroll(terminal)` handles native wheel input, and `scrollTerminalPage(terminal, direction)` powers the `SCROLL_KEYS` buttons. `measureTerminalGeometry(terminal)` takes one layout read per gesture; `planTouchScrollSteps(accumPx, rowHeightPx)` is the pure sub-row-remainder core. Wired in `useShellSession`. |
| `terminalTheme.js` | Pure xterm.js palette builder for the Shell terminal. `buildTerminalTheme({ bg, fg, accent, card, error, success, warning }, mode)` assembles the xterm `theme` object — base ANSI colors from the active theme's CSS vars, the rest from mode-tuned literals (`ANSI_NIGHT` bright/pastel for dark backgrounds, `ANSI_DAY` darkened/saturated so colored CLI output stays legible on daytime themes). `parseCssColorToHex(raw, fallback)` normalizes both the `15 15 15` triple form and the `rgb(7 7 7 / 0.86)` function form (used by `--port-terminal-*` tokens) to `#rrggbb`, dropping alpha. No DOM reads — `Shell.jsx` resolves CSS vars and re-applies on theme switch. |
| `threejsAnimation.js` | Pure pose evaluator for the declarative clip contract in `server/lib/threejsModel.js`, used by the Three.js Models preview transport. `evaluateThreejsClipPose(clip, timeSeconds)` → `{ timeSeconds, pose, activeSequenceIds, activePartIds }` where `pose` is a null-prototype partId → `{ position?, rotationDegrees?, scale?, opacity?, visible? }` map: each part+channel resolves from the one sequence that owns the instant (the window containing it, else the most recent behind it, else the next ahead), `visible` steps at the window's end rather than interpolating, and a part no sequence drives is absent so the spec renders as authored. `collectThreejsCues(clip, from, to)` returns the data-only sound cues a play loop crossed in the half-open `[from, to)` interval — a scrub calls it never, which is what makes scrubbing silent. `listThreejsClips` / `listThreejsCues` / `resolveThreejsClip` / `getThreejsClipDuration` read a spec that may have no `animation` key at all. |
| `threejsEnvironment.js` | Image-based lighting for the procedural sculpt spec, used by the Three.js Models preview. `spec.lights` are punctual — they light a surface but give it nothing to REFLECT, so `metalness`, `transmission`, `clearcoat` and `iridescence` read off an environment or read off nothing, and a plausible conductor renders near-black without one. `createSculptEnvironmentTarget(renderer, preset)` builds a preset locally from three's own primitives and prefilters it through `PMREMGenerator` — `neutral` is three's bundled `RoomEnvironment`, `studio` a dark shell with three emissive softbox panels plus a floor bounce — returning null for `none`; the caller owns the render TARGET and disposes it (disposing only `.texture` leaks the framebuffer behind it). `THREEJS_RENDER_PROFILE` mirrors the server's colour-space/tone-map/exposure contract so the preview renders at what the export stamps on the model. Deliberately NOT drei's `<Environment preset=…>`, which fetches an HDR from a CDN: rendering a local model makes no outbound request. `resolveSculptEnvironment(spec)` is the client mirror of `resolveThreejsEnvironment` in `server/lib/threejsModel.js`, reading a spec with no `environment` key as the `none` it was actually authored against. |
diff --git a/client/src/lib/terminalScroll.js b/client/src/lib/terminalScroll.js
index 920c7ecd07..0c982086b5 100644
--- a/client/src/lib/terminalScroll.js
+++ b/client/src/lib/terminalScroll.js
@@ -31,6 +31,13 @@
// sequence of page keys when a gesture has a very large delta.
const MAX_SCROLL_STEPS = 64;
+// A short trackpad gesture can produce many pixel-mode wheel events. Four logical
+// lines is enough movement to make one page key useful without making each tiny
+// event jump the TUI by a full viewport.
+const WHEEL_PAGE_LINES = 4;
+const WHEEL_DELTA_MODE_LINE = 1;
+const WHEEL_DELTA_MODE_PAGE = 2;
+
// Used when the terminal hasn't been laid out yet, so a swipe on a freshly-attached
// session still scrolls instead of silently accumulating pixels forever.
const FALLBACK_ROW_HEIGHT_PX = 18;
@@ -74,6 +81,12 @@ export const measureTerminalGeometry = (terminal) => {
// same convention a normal terminal's Page Up/Down control uses.
const terminalPageLines = (terminal) => Math.max(1, (terminal?.rows ?? 1) - 1);
+const wheelDeltaLines = (event, rowHeightPx) => {
+ if (event.deltaMode === WHEEL_DELTA_MODE_LINE) return event.deltaY;
+ if (event.deltaMode === WHEEL_DELTA_MODE_PAGE) return event.deltaY * WHEEL_PAGE_LINES;
+ return event.deltaY / rowHeightPx;
+};
+
/**
* Scroll the normal terminal buffer by `lines` (negative = toward older output).
* Alternate-screen apps have no terminal scrollback, so each requested logical
@@ -114,13 +127,30 @@ export const attachTerminalWheelScroll = (terminal) => {
const el = terminal?.element;
if (!el?.addEventListener) return () => {};
+ let remainderLines = 0;
+ const rowHeightPx = measureTerminalGeometry(terminal).rowHeightPx;
+
const onWheel = (event) => {
- if (!isAltBuffer(terminal) || !event.deltaY || event.shiftKey) return;
- if (!sendTerminalPageKey(terminal, event.deltaY < 0 ? -1 : 1)) return;
+ if (!isAltBuffer(terminal) || !event.deltaY || event.shiftKey) {
+ remainderLines = 0;
+ return;
+ }
+ // An app that enabled terminal mouse tracking owns this wheel event. In
+ // particular, do not turn Vim/htop/tmux mouse input into an extra page key.
+ if (terminal.modes?.mouseTrackingMode !== 'none') {
+ remainderLines = 0;
+ return;
+ }
+
+ const totalLines = remainderLines + wheelDeltaLines(event, rowHeightPx);
+ const pages = Math.trunc(totalLines / WHEEL_PAGE_LINES);
+ remainderLines = totalLines - pages * WHEEL_PAGE_LINES;
+ // xterm's alternate-buffer fallback sends cursor keys for this event. Swallow
+ // it even before a page threshold is reached so a small trackpad delta cannot
+ // leak an unsupported sequence into the TUI.
if (event.cancelable) event.preventDefault();
- // xterm's mouse listener is on the same terminal element. Stop it before it
- // turns this wheel into an unsupported mouse report for the TUI.
event.stopImmediatePropagation();
+ if (pages) scrollTerminalLines(terminal, pages);
};
el.addEventListener('wheel', onWheel, { capture: true, passive: false });
diff --git a/client/src/lib/terminalScroll.test.js b/client/src/lib/terminalScroll.test.js
index d9269074f9..742d899b45 100644
--- a/client/src/lib/terminalScroll.test.js
+++ b/client/src/lib/terminalScroll.test.js
@@ -12,7 +12,7 @@ import {
// A stand-in for the xterm instance carrying only what this module reads. The real
// Terminal is not needed here: these tests pin the event ownership and key sequence
// that the Shell's xterm instance exposes to the PTY.
-const makeTerminal = ({ alt = true, rows = 24, height = 480 } = {}) => {
+const makeTerminal = ({ alt = true, rows = 24, height = 480, mouseTrackingMode = 'none' } = {}) => {
const el = document.createElement('div');
const screen = document.createElement('div');
screen.className = 'xterm-screen';
@@ -23,6 +23,7 @@ const makeTerminal = ({ alt = true, rows = 24, height = 480 } = {}) => {
element: el,
rows,
buffer: { active: { type: alt ? 'alternate' : 'normal' } },
+ modes: { mouseTrackingMode },
input: vi.fn(),
scrollLines: vi.fn(),
};
@@ -149,10 +150,29 @@ describe('attachTerminalWheelScroll', () => {
detach();
});
+ it('accumulates small pixel-mode deltas before sending a page key', () => {
+ const term = makeTerminal({ rows: 24, height: 480 }); // 20px rows, four-line threshold
+ const xtermListener = vi.fn();
+ term.element.addEventListener('wheel', xtermListener);
+ const detach = attachTerminalWheelScroll(term);
+
+ for (let i = 0; i < 3; i++) {
+ const event = new WheelEvent('wheel', { deltaY: -20, bubbles: true, cancelable: true });
+ term.element.dispatchEvent(event);
+ expect(event.defaultPrevented).toBe(true);
+ }
+ expect(term.input).not.toHaveBeenCalled();
+
+ term.element.dispatchEvent(new WheelEvent('wheel', { deltaY: -20, bubbles: true, cancelable: true }));
+ expect(term.input).toHaveBeenCalledWith('\x1b[5~', false);
+ expect(xtermListener).not.toHaveBeenCalled();
+ detach();
+ });
+
it('maps a downward wheel to PageDown', () => {
const term = makeTerminal();
const detach = attachTerminalWheelScroll(term);
- term.element.dispatchEvent(new WheelEvent('wheel', { deltaY: 1, bubbles: true, cancelable: true }));
+ term.element.dispatchEvent(new WheelEvent('wheel', { deltaY: 80, bubbles: true, cancelable: true }));
expect(term.input).toHaveBeenCalledWith('\x1b[6~', false);
detach();
});
@@ -182,6 +202,21 @@ describe('attachTerminalWheelScroll', () => {
detach();
});
+ it('leaves wheel input to xterm when the app enabled mouse tracking', () => {
+ const term = makeTerminal({ mouseTrackingMode: 'any' });
+ const xtermListener = vi.fn();
+ term.element.addEventListener('wheel', xtermListener);
+ const detach = attachTerminalWheelScroll(term);
+ const event = new WheelEvent('wheel', { deltaY: -120, bubbles: true, cancelable: true });
+
+ term.element.dispatchEvent(event);
+
+ expect(term.input).not.toHaveBeenCalled();
+ expect(xtermListener).toHaveBeenCalledTimes(1);
+ expect(event.defaultPrevented).toBe(false);
+ detach();
+ });
+
it('detaches the wheel listener', () => {
const term = makeTerminal();
const detach = attachTerminalWheelScroll(term);