Files
loki/scripts/test/terminal-touch-scroll.ts
CatoandClaude Opus 5.5 77ad544875 feat(terminal): attach from a phone, swipe to scroll, one bar, no dead ends (#1042)
* feat(terminal): attach from a phone, swipe to scroll, and a full screen that is full

Attaching. The paperclip on a phone opened a chooser of capture apps (Camera,
Camera, Recorder, "Photos & Videos") with no way to the screenshot: one file
input with a mixed accept. The composer is chatkit's, so the fix is there
(bitbaum/chatkit: Camera / Photos / Files sheet, one input per source) and
this bumps the pin. Control's own paperclip (attachment-strip) now renders
chatkit's AttachMenu instead of its own mixed input, and a picked PDF gets a
sentence instead of being read as text.

Attaching in the conversation view. It had attach={false}. A message with a
screenshot is folded by the same lib/composer-attachments every dispatch
uses (new /api/control/fold-attachments: the fold and nothing else) and
pasted into the session like any message. sendKey is now one serialized
chain, so Enter can never overtake a long chunked paste.

Scrolling. xterm 6 scrolls on the wheel only, so on a phone a swipe moved
nothing. lib/terminal-touch-scroll.ts turns a vertical swipe into
scrollLines, carries sub-row movement, glides after a flick, and leaves taps
alone. Verified with real xterm in Chromium under touch emulation: 0 lines
before, ~1 line per row of finger travel after. A "Live" button returns to
the newest output while scrolled back.

Full screen. Expanded kept the whole dock (two key rows, mode chips,
composer: more than half the phone), so it bought a few rows and read as
four toolbars stacked under the session. Expanded now collapses the dock to
one bar: Keys and Write open their panel on demand, Esc and Enter stay on
the bar. The phone switch drops Voice (the composer's mic dictates) and its
Loki chip (the header's Loki button is the one entry point).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BWXjqiHm8jFta4FXuc7Tck

* feat(ux): one composer per screen, one bar on the phone, no dead ends

Verified on the real app (production build, local Postgres, demo tenant,
a stubbed live session) at 320/390/768/1440: responsive audit green on
every page; screenshots of each changed surface.

Terminal, phone. Both layouts are now one bar (Keys / Write; Esc / Enter
while watching) with one panel open. The normal page opens on Write, full
screen on nothing. The stacked dock (two key rows + chips + composer) is
gone from both.

Conversation view. A builder that never sends the transcript used to show
"The conversation isn't coming through … Fleet Runner 0.8.38" — now the
surface shows the terminal for that session and drops the toggle, without
touching the saved preference.

Loki panel. A working run said it three times ("Working · 2 min" /
"Agent is working" / "Agent is generating. Inject to steer…");
railStatusLines prints only lines that add something. In the conversation
view the panel is Ask-only, so the page never shows two composers for one
session. Plain empty copy; the "Full chat" text link is an icon button.

Sheets. On a phone a bottom panel is a real sheet on the bottom edge — it
floated ~90px up, clearing a bottom nav that is hidden while it is open.

Floating clutter. The Ask Loki bubble is gone from /terminal (it sat on
the Loki panel's Send); on phones the feedback launcher hides behind the
bottom nav and "Report a problem" lives in the account menu.

Dead ends. An offline/gated terminal offers "Use this computer" and "Get
Fleet Runner" as buttons. Control's never-connected banner is one
sentence and one button: the duplicate "Start a new project" card goes,
and the five CLI installers — which queued commands no builder would pick
up — only show where a builder can act on them.

Also: no-op input-mode chips hidden in the conversation view; memory
descriptions wrap instead of a hover-only ellipsis; the responsive audit
honours CHROMIUM_PATH. Tests: phone-chrome.ts, railStatusLines cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BWXjqiHm8jFta4FXuc7Tck

* fix(shell): Report a problem falls back through the router, not location.assign

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BWXjqiHm8jFta4FXuc7Tck

* chore(deps): pin chatkit to the merged commit of bitbaum/chatkit#7

Same tree as the branch head it replaces (5c2cdd6), which was deleted
after the squash-merge; pinning main's commit keeps the install
fetchable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BWXjqiHm8jFta4FXuc7Tck

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-05 05:27:53 -07:00

61 lines
2.1 KiB
TypeScript

// A swipe over the terminal must scroll it: xterm 6 only listens to the
// wheel, so on a phone the output could be watched but never read back
// (2026-10-05). These pin the arithmetic in src/lib/terminal-touch-scroll.ts.
// Run: npx tsx scripts/test/terminal-touch-scroll.ts
import {
TOUCH_SCROLL_MIN_VELOCITY,
decayVelocity,
linesForDrag,
} from "@/lib/terminal-touch-scroll";
let pass = 0;
let fail = 0;
function eq(actual: unknown, expected: unknown, label: string) {
const a = JSON.stringify(actual);
const e = JSON.stringify(expected);
if (a === e) pass++;
else {
fail++;
console.error(`✗ ${label}: expected ${e}, got ${a}`);
}
}
// Content follows the finger: dragging UP reveals newer output (scroll down).
eq(linesForDrag(-40, 0, 20), { lines: 2, carryPx: 0 }, "finger up 2 rows scrolls down 2");
eq(linesForDrag(40, 0, 20), { lines: -2, carryPx: 0 }, "finger down 2 rows scrolls up 2");
// A slow drag is as exact as a fast one: sub-row movement is carried, not lost.
let carry = 0;
let total = 0;
for (let i = 0; i < 10; i++) {
const step = linesForDrag(6, carry, 20);
carry = step.carryPx;
total += step.lines;
}
eq(total, -3, "ten 6px moves over 20px rows add up to three rows");
eq(Math.round(carry), -0, "nothing left over that a row would have used");
// No layout yet (cell height 0) must not divide by zero or scroll anywhere.
eq(linesForDrag(-100, 5, 0), { lines: 0, carryPx: 0 }, "no cell height, no scroll");
// The glide slows and then stops — it never runs forever.
let v = 2;
let frames = 0;
while (v !== 0 && frames < 1000) {
v = decayVelocity(v, 1000 / 60);
frames++;
}
eq(v, 0, "a flick comes to rest");
eq(frames < 200, true, `and within a few seconds (${frames} frames)`);
eq(decayVelocity(TOUCH_SCROLL_MIN_VELOCITY / 2, 16), 0, "too slow to see is stopped");
// A dropped frame decays as much as the frames it stands in for.
eq(
Math.abs(decayVelocity(1, 1000 / 30) - decayVelocity(decayVelocity(1, 1000 / 60), 1000 / 60)) <
1e-9,
true,
"frame-rate independent",
);
console.log(`terminal-touch-scroll: ${pass} passed, ${fail} failed`);
if (fail) process.exit(1);