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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: make mobile shell drags responsive and scroll mouse-aware apps by row
[._.]/ Adam Eivy0d41d567deb7
diff --git a/client/src/lib/README.md b/client/src/lib/README.mdindex d6700ec5ec..c00d302c41 100644--- a/client/src/lib/README.md+++ b/client/src/lib/README.md@@ -229,7 +229,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, 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`. |+| `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) reserves one-finger panning while preserving pinch zoom; mouse-aware apps receive row-granular wheel events at the touch coordinates, and only apps without wheel support fall back to page keys. `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. || `textUtils.js` | `escapeRegExp(value)` and `countWords(text)` re-exported from `server/lib/textUtils.js` — the two members the bundle has callers for (the Writers Room editor and exercise panel and the autobiography tab count words with the same `\S+` rule the server stores). Named exports rather than `export *`, so the file stays the list of what the browser actually uses. || `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. |diff --git a/client/src/lib/terminalScroll.js b/client/src/lib/terminalScroll.jsindex 554ea6dbe1..6eb3c66489 100644--- a/client/src/lib/terminalScroll.js+++ b/client/src/lib/terminalScroll.js@@ -21,7 +21,7 @@// translated to PageUp/PageDown escape sequences through `terminal.input()`. That// keeps the event from becoming unsupported application mouse input while still// letting the TUI own its conversation scroll region. The page buttons and touch-// gestures use the same key path.+// gestures use that key path only when the app has not enabled mouse tracking.//// Scrolling back PAST a TUI, into what the shell printed before it started, stays// impossible while it holds the alternate screen. That is terminal semantics, not a@@ -185,13 +185,19 @@ export const planTouchScrollSteps = (accumPx, rowHeightPx) => {/*** Make a one-finger drag scroll the terminal. Returns a detach function.*- * Normal shell sessions scroll row-by-row. Alternate-screen TUIs use a half-viewport- * drag threshold because their PageUp/PageDown bindings move a page, not one row.+ * Shell scrollback and mouse-aware apps scroll row-by-row. Apps without mouse+ * tracking retain page-key scrolling because they expose no generic line-scroll API.*/export const attachTerminalTouchScroll = (terminal) => {const el = terminal?.element;if (!el?.addEventListener) return () => {};+ // Reserve one-finger panning before the browser can claim the gesture. Keep+ // pinch zoom and taps available; waiting for a whole row in touchmove is too late+ // on mobile browsers, which can already have started scrolling an ancestor.+ const previousTouchAction = el.style.touchAction;+ el.style.touchAction = 'pinch-zoom';+let lastY = null;let accumPx = 0;let geometry = null;@@ -212,19 +218,37 @@ export const attachTerminalTouchScroll = (terminal) => {const y = ev.touches[0].clientY;accumPx += lastY - y;lastY = y;+ // Cancel even sub-row movement: it still belongs to this terminal gesture.+ if (ev.cancelable) ev.preventDefault();+ const mouseMode = terminal.modes?.mouseTrackingMode;+ // X10 reports presses only, not wheel events.+ const mouseScroll = mouseMode && mouseMode !== 'none' && mouseMode !== 'x10';// OpenCode's PageUp/PageDown bindings move the message viewport by a page,// not by one terminal row. Wait for roughly half a viewport before sending a// page key; normal shell scrollback remains row-granular.- const stepHeight = isAltBuffer(terminal)+ const stepHeight = isAltBuffer(terminal) && !mouseScroll? Math.max(geometry.rowHeightPx, (terminal.rows || 1) * geometry.rowHeightPx / 2): geometry.rowHeightPx;const { steps, remainderPx } = planTouchScrollSteps(accumPx, stepHeight);if (!steps) return;accumPx = remainderPx;- // Swallow the gesture only once it has resolved into a scroll — before that it- // may still be a tap, and a TUI with mouse tracking on wants the click.- if (ev.cancelable) ev.preventDefault();- scrollTerminalLines(terminal, steps);+ if (mouseScroll) {+ // Let xterm encode the negotiated mouse protocol and coordinates. One wheel+ // event produces one report, regardless of delta magnitude, so emit bounded+ // row steps instead of turning a drag into one large jump or a page key.+ for (let i = 0; i < Math.min(Math.abs(steps), MAX_SCROLL_STEPS); i++) {+ el.dispatchEvent(new WheelEvent('wheel', {+ bubbles: true,+ cancelable: true,+ deltaMode: WHEEL_DELTA_MODE_LINE,+ deltaY: Math.sign(steps),+ clientX: ev.touches[0].clientX,+ clientY: y,+ }));+ }+ } else {+ scrollTerminalLines(terminal, steps);+ }};el.addEventListener('touchstart', onStart, { passive: true });@@ -233,6 +257,8 @@ export const attachTerminalTouchScroll = (terminal) => {el.addEventListener('touchcancel', end, { passive: true });return () => {+ end();+ el.style.touchAction = previousTouchAction;el.removeEventListener('touchstart', onStart);el.removeEventListener('touchmove', onMove);el.removeEventListener('touchend', end);diff --git a/client/src/lib/terminalScroll.test.js b/client/src/lib/terminalScroll.test.jsindex a29ca1a9eb..80532a3f15 100644--- a/client/src/lib/terminalScroll.test.js+++ b/client/src/lib/terminalScroll.test.js@@ -32,7 +32,7 @@ const makeTerminal = ({ alt = true, rows = 24, height = 480, mouseTrackingMode =const touchEvent = (type, touches) => {const ev = new Event(type, { bubbles: true, cancelable: true });- ev.touches = touches.map((clientY) => ({ clientY }));+ ev.touches = touches.map((clientY) => ({ clientX: 150, clientY }));return ev;};@@ -278,15 +278,55 @@ describe('attachTerminalTouchScroll', () => {detach();});- it('leaves a sub-row drag alone so a tap still reaches the TUI', () => {+ it('claims sub-row movement before the browser starts panning an ancestor', () => {const term = makeTerminal({ rows: 24, height: 480 });const detach = attachTerminalTouchScroll(term);term.element.dispatchEvent(touchEvent('touchstart', [300]));const move = touchEvent('touchmove', [305]);term.element.dispatchEvent(move);expect(term.input).not.toHaveBeenCalled();- expect(move.defaultPrevented).toBe(false);+ expect(move.defaultPrevented).toBe(true);+ detach();+ });++ it('routes small bidirectional drags through mouse wheel input, not page keys', () => {+ const term = makeTerminal({ mouseTrackingMode: 'vt200' });+ // happy-dom's WheelEvent omits MouseEvent coordinates; assert constructor+ // options as well as delivery until its inheritance matches browsers.+ const wheelConstructor = vi.spyOn(globalThis, 'WheelEvent');+ const wheelEvents = [];+ term.element.addEventListener('wheel', event => wheelEvents.push(event));+ const detachWheel = attachTerminalWheelScroll(term);+ const detach = attachTerminalTouchScroll(term);+ term.element.dispatchEvent(touchEvent('touchstart', [300]));+ term.element.dispatchEvent(touchEvent('touchmove', [325]));+ term.element.dispatchEvent(touchEvent('touchmove', [300]));+ expect(wheelEvents.map(event => [event.deltaY, event.deltaMode]))+ .toEqual([[-1, 1], [1, 1]]);+ expect(wheelConstructor).toHaveBeenNthCalledWith(1, 'wheel', expect.objectContaining({ clientX: 150, clientY: 325 }));+ expect(wheelConstructor).toHaveBeenNthCalledWith(2, 'wheel', expect.objectContaining({ clientX: 150, clientY: 300 }));+ expect(term.input).not.toHaveBeenCalled();+ expect(term.scrollLines).not.toHaveBeenCalled();+ detach();+ detachWheel();+ wheelConstructor.mockRestore();+ });++ it('reserves panning while preserving pinch zoom, taps, and the previous style on detach', () => {+ const term = makeTerminal();+ term.element.style.touchAction = 'auto';+ const detach = attachTerminalTouchScroll(term);+ expect(term.element.style.touchAction).toBe('pinch-zoom');+ const start = touchEvent('touchstart', [300]);+ term.element.dispatchEvent(start);+ expect(start.defaultPrevented).toBe(false);+ const pinch = touchEvent('touchmove', [280, 400]);+ term.element.dispatchEvent(pinch);+ expect(pinch.defaultPrevented).toBe(false);+ term.element.dispatchEvent(touchEvent('touchmove', [600]));+ expect(term.input).not.toHaveBeenCalled();detach();+ expect(term.element.style.touchAction).toBe('auto');});it('still scrolls an alternate buffer before layout is available', () => {