Skip to content

Make terminal touch scrolling work on phones - #28

Merged
devswha merged 1 commit into
mainfrom
fix/touch-scroll
Sep 24, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/touch-scroll

Conversation

@devswha

@devswha devswha commented Sep 24, 2026

Copy link
Copy Markdown
Owner

Summary

On a phone, dragging the terminal didn't scroll herdr's history. The drag ended up scrolling the page or the composer instead, which is where the "the input box scrolls" report came from. I reproduced it with CDP touch events on a real Claude Code pane in terminal view, and found three causes.

  1. The gesture was lost after its first move. The first scroll made xterm redraw, and xterm replaces its row <span>s on a redraw. A touch event keeps its first target for the whole gesture, so once that row was replaced, the later touchmoves and even the touchend never reached our handler. The browser then took the drag. A 12-step downward drag delivered 1 touchmove.
    • Fix: on touch screens (pointer: coarse), .xterm-rows has pointer-events: none, so touches land on .xterm-screen, which stays.
  2. The direction was reversed. Dragging down (to see older lines) sent wheel-down, which does nothing at the bottom. Now the text follows the finger, as it does everywhere else on a phone.
  3. The wheel had no position. The synthetic WheelEvent had no clientX/clientY, so xterm reported every notch at row 1, column 1. It now carries the finger's position.

Also, .pane-terminal sets touch-action: none and overscroll-behavior: contain, so the browser never starts its own pan or pull-to-refresh on the terminal.

Testing

  • Mobile emulation (390×844, touch), Claude Code 2.1.282 in an owned herdr pane, terminal view:
    • before: a 12-step downward drag delivered 1 move and 1 report, all at (1,1), and in the wrong direction.
    • after: every drag delivers all 12 moves, each reported at the finger's cell. herdr's offset_from_bottom went 0 → 36 → 72 dragging down and 39 → 3 → 0 dragging up, and every gesture ended with touchend.
  • A tap on the terminal still focuses xterm's textarea, which opens the keyboard.
  • Desktop is unaffected: the row rule only applies to coarse pointers. A mouse wheel on the same pane still scrolls (offset 0 → 9).
  • bun run typecheck passes, bun test passes, and bun run test:ui passes 7/7.

🤖 Generated with Claude Code

Dragging the terminal on a phone didn't scroll herdr's history. Three
causes, all reproduced with CDP touch events on a Claude Code pane:

- The first scroll redrew the rows, and xterm swaps its row elements on a
  redraw. A touch keeps its first target for the whole gesture, so a finger
  that landed on a row lost every later move and its end, and the browser
  took the drag and scrolled the page or the composer instead. On touch
  screens the rows now take no touches, so the gesture lands on the screen
  element, which stays. A 12-step drag used to deliver 1 move; it now
  delivers all 12.
- The direction was reversed: dragging down, to see older lines, sent
  wheel-down. The text now follows the finger.
- The synthetic wheel had no position, so every report said row 1,
  column 1. It now carries the finger's.

.pane-terminal also sets touch-action: none and overscroll-behavior:
contain, so the browser never starts its own pan or pull-to-refresh there.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@devswha
devswha merged commit 632aca9 into main Sep 24, 2026
@devswha
devswha deleted the fix/touch-scroll branch September 26, 2026 14:48
devswha added a commit that referenced this pull request Nov 23, 2026
…ts six digits (#4532)

## What and why

A PC with no screen could not be used right after `ovis add`. The press
path ends with "Added. Open <name> from My PCs.", but the PC has no
account member yet. So the first device that opens it sends a **first
join**: six digits that only the PC's own window may accept
(`server/relay/session.ts` `accountJoin` returns `"first"` while
`hasAccountApprover()` is false). `ovis approve` skipped any join that
came with digits and then said "No device is waiting to pair." That left
nobody able to let the first device in.

The server already takes a first join from the own window with six typed
digits: `decideTyped` has no first-join check, and `POST /api/relay/join
{id, digits}` reaches it from the terminal, which counts as the own
window (loopback, not forwarded, `x-herdr-machine`). **No server change
was needed.** This PR changes `scripts/plugin*.ts`, their tests, the
docs and one changelog fragment.

## Decisions (the lead's, as implemented)

1. **`ovis approve` handles first joins.** Each one is listed with the
device's name, the account it comes from (the PC's account, short id)
and the time it asked: `Pixel asks to open this PC (from Ovis account
acct_1a2b3c4, asked at 10:02). Type the six digits Pixel shows (one
wrong entry ends this request), or press Enter to skip:`. The typed
digits go to the existing route (`POST /api/relay/join {id, digits}`),
and the PC compares them.
- A wrong number says so. The route's own limit applies: one wrong entry
ends that join. The command then says how to try again: have the device
ask again, then run `ovis approve` again.
- Enter by itself skips the join. It keeps waiting until its own
deadline.
- The terminal never shows the digits, although the route lists them for
the own window's card. Nothing is approved unless the digits are typed
at this terminal.
- Joins that are not first joins behave as before, with the same prompt,
wording and outcomes.
- With no terminal (stdin not a TTY), each first join is listed with
"Run ovis approve in a terminal on this PC and type the six digits
<device> shows.", followed by the existing not-a-terminal line. Nothing
is sent, and the exit code is 1, as before.
- **`--digits` is not added.** Every request `ovis approve` answers
today needs a terminal, and docs/relay.md and docs/account.md both say
that input that is not a terminal approves nothing. A `--digits` flag
would be the first way to approve from a script or an agent. It would
also put the digits in shell history and in `ps`. The existing options
pattern does not make it a natural fit.
2. **`ovis add` goes on after "Added."** at a terminal, meaning both
stdin and stdout are TTYs:
- It shows: `Added. Open <name> from My PCs on your phone. If the phone
shows six digits, type them here (Enter to finish without):`.
- It watches `GET /api/relay/joins`, the same read `ovis approve` uses,
for up to 10 minutes. Each first join is asked about by name, account
and time.
- Typed digits go to `POST /api/relay/join`. On success it says
`<device> is let in; it opens this PC in a moment.` and ends.
- A wrong number says so, and that join ends. When the device asks
again, its new request shows in the same run.
- If a device gets in by itself meanwhile, it says `<device> can open
this PC now: it got in through your account.` with the `ovis approve`
hint, and ends. "By itself" means, in `GET /api/devices` compared with
the snapshot taken before the watch started: a new member row or
`through_account` row, or a known `through_account` row that signs in
during the watch (its `last_seen_at` goes from null or an older day to a
new one, or a live `connection` appears with a new `since`). A session
that ended, or a member's `last_seen_at` moving, does not count.
- The account sign-in ends (after any `putListing`) before "Added." is
printed, so it is not kept during the watch.
- Enter by itself, Ctrl+C, Ctrl+D and the 10 minutes each end the watch
with the hint line below. The exit code is always 0, because the PC is
added.
- A line answers only the question it was typed under, after 1.5 s
(`DWELL_MS`), and the terminal input is discarded as each question first
shows. These are the same rules `askLine` and `asking` follow.
- With `--account` and no terminal it ends after "Added." with one plain
line: `If your phone asks for six digits when you open <name>, run ovis
approve on this PC and type them.` That line also ends the watch, ends
the "relay did not come online in 30 s" case, and covers an Ovis that
answers 404 for `/api/relay/joins`.
3. **Docs.**
- docs/relay.md, "A PC with no screen", now walks through add → open on
the phone → type the digits at the PC's terminal, including the
wrong-digit, Enter and timeout endings and the no-terminal line. The
step-7 paragraph now names first joins too.
- docs/account.md says that `ovis approve` (and `ovis add`) takes a
first join with its digits, and why that is the same authority as the
PC's own window.
- docs/guide.md: the `ovis approve` comment and the `login` paragraph
are updated.

## Who can do what after this

- **Approving a first join from the terminal needs local owner access.**
The request has to reach this PC's local server as its own window:
loopback, not forwarded, and with the access token when one is set.
Those are the same people who can open its own window. With no access
token, that means any local OS account on that machine; the docs already
tell shared machines to set a token.
- **The CLI only approves with typed digits.** It approves a first join
only when the six digits shown on the asking device are typed, and the
server compares them.
- **The asking device needs a fresh admission.** It needs an admission
at most 10 minutes old, from that PC's account, for its exact key
(condition 2 in account.md).
- **No remote party gains anything.** The route answers 403
`own_window_required` to everything else.

**Correction to the brief:** "only with the six digits" holds for the
CLI, not as a server guarantee. The own window, and so anyone with that
same local access, could already approve a first join with a tap and no
digits (`POST /api/relay/join {id, decision: "approve"}`, `decideOwn`).
The CLI deliberately uses the stricter typed-digits route. This PR adds
no new authority: it uses one that already existed, more strictly.

## Review

An independent review of 3c43ca0 found no HIGH. Each finding below was
checked against the code first, then fixed in one push.

- **MEDIUM 1, the watch missed the usual case.** One press reads the
account snapshot before it answers (`server/account/one-press.ts`), so
the phone's `through_account` row is already known when the watch
starts. With #4531 the phone signs in with the account key and no join,
no new row appears, and the terminal kept asking for digits. **Fixed:**
a known `through_account` row now counts as "got in" when it signs in
during the watch. `GET /api/devices` carries two signals for such rows:
`last_seen_at` (the day of its last sign-in here, null before its first;
`server/devices.ts` `joinedAsPaired`) and, to the PC's own window,
`connection.since` while a session is up. The row counts when either one
moves to a new non-null value, and the ending names that device.
- Unit tests: a known row signing in by `connection` and by
`last_seen_at`; and a session that ended plus a member in use, neither
counted.
- New contract test against the real server: the phone is on the
account's list before the press, so the one-press snapshot admits it. It
signs in with its account key once its 10 s join hold is over, and the
watch ends. This test fails without the fix (it times out) and passes
with it.
- **LOW 2, sign-in kept during the watch.** **Fixed:** `linkToAccount`
has one idempotent `signOut` (put a taken listing back first, then sign
out). `addByPress` calls it before "Added.", and `finally` calls it
again as a no-op. The harness asserts that `/v1/signout` came before
"Added.".
- **LOW 3, missing hint.** **Fixed:** the "got in through your account"
ending now ends with the `ovis approve` hint.
- **LOW 4, approval wording.** **Fixed:** an approval now says `<device>
is let in; it opens this PC in a moment.`, in both `ovis approve` and
the `add` watch.
- **LOW 5, prompts did not state the limit.** **Fixed:** both first-join
prompts now say `(one wrong entry ends this request)`.
- **LOW 6, docs assumed every phone shows digits.** **Fixed:**
docs/relay.md and docs/guide.md now say the phone usually opens the PC
at once. They add: "If the phone shows six digits instead…, it does when
this PC does not list that phone from the account yet (for example the
phone whose sign-in created the account, during that sign-in's first
day)". The relay.md walkthrough also names the watch's two signals and
says the sign-in ends as the PC is added. The changelog fragment is
reworded to match.
- Finding (a) from my first report: the reviewer confirmed it is
existing and harmless. A first-join row gets `account` only from the
device's own `POST /api/account/link`, which the contract test's raw
client never sends.

## Validation

- **Red first:** before the fix, 16 of the new or updated tests in
`scripts/plugin-link.test.ts` failed, and the new contract tests failed.
- `bun test scripts/plugin-link.test.ts`: 199 pass. New tests cover:
- `approveJoins` with first joins: name, account and time; no digits
shown; all six approve; wrong digits; Enter skips; account unknown; a
members join beside it; no terminal.
- The `add` watch: approve by typed digits; wrong then retry; Enter; a
line too soon and a line that is not digits; a device that got in
through the account; 10 minutes; Ctrl+C; an Ovis without the route.
- Updated endings of the existing press tests, and the `--account`
no-terminal hint line.
- `bun test scripts/plugin-link.contract.test.ts`: 6 pass, against a
real PC server and the fake account service:
- `ovis add --account` at a terminal: the PC is added in one press; a
phone sends a real first join through the relay (`approve_on: linux`);
the command asks without showing the digits; the typed digits let the
phone in (`AUTH_OK`, key stored).
- `ovis approve` (`approveJoins` against the real routes): Enter leaves
the join waiting; wrong digits end it (`auth_failed`); the same device
asks again and its digits let it in.
- `bun test scripts/plugin.test.ts -t "pair --approve"`: 12 pass. New
tests run the real CLI against a fake PC:
- at a real terminal (`script`): a first join approved with typed
digits, the next skipped with Enter, the screen never showing the
digits;
  - wrong digits;
  - piped stdin: the listing plus the instruction, nothing sent.
  - The existing #28 members-join tests still pass.
- `bun run typecheck`: clean.
- After the review: `scripts/plugin-link.test.ts` 201 pass,
`scripts/plugin-link.contract.test.ts` 7 pass, `scripts/plugin.test.ts
-t "pair --approve"` 12 pass, `scripts/conventions.test.ts` pass, `bun
run typecheck` clean, and `dori heavy approve -- bun run check fast`
green.
- Before the review: `dori heavy approve -- bun run check fast`: green.
The first run caught two fixed sleeps in `scripts/plugin.test.ts`
without a `// fixed wait:` note; they now have one.
- **Skipped:** screenshots (a CLI change with no UI) and browser
regressions (no shared UI component touched). Windows and macOS were not
run locally; the new `script`-based tests skip on Windows like the
existing ones.

## Known limits

- `ovis approve` is one pass over the joins it read. After a wrong
entry, run it again once the device asked again. `ovis add`'s watch
picks up the new request by itself.
- A row of the account's list that already signed in here before the
watch started (same day, no new session) gives no new signal. The watch
then waits until Enter, Ctrl+C or the 10 minutes, and says how to
finish.
- The watch reads `GET /api/relay/joins` and `GET /api/devices` on
loopback every 2 s for at most 10 minutes.
- This PR touches `scripts/plugin*`, so it waits for GitHub's checks and
an independent review.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant