Files
kandev/apps/web/lib/terminal/send-shell-input.ts
T
José Almeida 2e52e96aaf feat(web): mobile session/terminal/repo pickers + multi-terminal support
Address parity gaps on mobile by introducing per-pane header pills that
open bottom-sheet pickers, scoped to the relevant view rather than
overloading the left task sheet.

Pickers:
- Sessions pill in chat header → bottom sheet with launch / set-primary
  / stop / resume / delete (with confirm). Pill shows agent label +
  idx/total badge.
- Terminals pill in terminal header → bottom sheet with add / close
  (with confirm) / switch. Replaces an earlier chip-strip prototype.
- Repos pill on the top bar (multi-repo only) → bottom sheet listing
  task repositories; switching jumps to a session on that repo.

Each pill renders with a chevron-down icon + count badge so the
trigger reads as a button, not a status badge.

Multi-terminal:
- New useMobileTerminals hook wraps useTerminals and auto-creates a
  first shell when the env reports zero.
- MobileTerminalPane multi-mounts PassthroughTerminal instances keyed
  by terminalId so switching preserves scrollback. Active xterm
  registers itself in a small mobile-active-terminal sender registry;
  the existing key-bar reroutes input through xterm.paste() so Ctrl /
  ^C / arrows reach whichever terminal is currently visible, not just
  the per-session default shell.
- Skip the WebGL renderer addon on mobile (new disableWebgl prop on
  PassthroughTerminal). The WebGL atlas miscomputed glyph scaling
  after the desktop→mobile responsive switch and rendered text at
  several times the intended font size; the canvas renderer is correct
  and fast enough for shell use.

Refactors:
- Left sheet reverts to a single-purpose task list (the sectioned-hub
  variant was rolled back in favour of per-pane pickers).
- session-task-switcher-sheet-hooks extracted from the sheet to keep
  it under the file-size lint cap.
2026-05-06 01:40:38 +01:00

42 lines
1.7 KiB
TypeScript

import { getWebSocketClient } from "@/lib/ws/connection";
import { applyShellModifiers } from "./apply-shell-modifiers";
import { getActiveTerminalSender } from "./mobile-active-terminal";
import { useShellModifiersStore, isActive } from "./shell-modifiers";
/**
* Single entry point for shell input. Applies active ctrl/shift modifiers,
* sends over the WS, then consumes latched (non-sticky) modifiers.
*
* Used by both the virtual key-bar and xterm's own `onData` callback so that
* a Ctrl latch set from the key-bar modifies the next character the user
* types on the OS keyboard — which is the whole point of the modifier.
*
* Mobile multi-terminal: when a PassthroughTerminal is registered as the
* active key-bar target, route input through it (xterm.paste → onData → its
* dedicated WS) instead of the per-session default shell. Falls back to the
* default `shell.input` action when no active terminal is registered.
*/
export function sendShellInput(sessionId: string, data: string): void {
if (!data) return;
const store = useShellModifiersStore.getState();
const ctrlActive = isActive(store.ctrl);
const shiftActive = isActive(store.shift);
const transformed = applyShellModifiers(data, { ctrl: ctrlActive, shift: shiftActive });
const activeSender = getActiveTerminalSender();
if (activeSender) {
activeSender(transformed);
} else {
const client = getWebSocketClient();
if (!client) return; // keep modifiers armed; user can retry once reconnected
client.send({
type: "request",
action: "shell.input",
payload: { session_id: sessionId, data: transformed },
});
}
if (ctrlActive) store.consumeCtrl();
if (shiftActive) store.consumeShift();
}