Skip to content

MCP: place a mouse event inside a session's terminal (cell-addressed) #300

Description

@bastien-gallay

The pointer rung of the #90 control surface, terminal half: let a caller place
a mouse event inside a session's terminal, the way run_in_session places
text there.

Why

Two gaps, and the second is the one that blocks work today.

  1. The act→wait→observe loop has no pointer. press_keys and run_action
    drive termherd's own keyboard; run_in_session types into a PTY. Nothing
    can click. Every mouse-mode TUI a session hosts — Claude Code's /diff and
    /resume, lazygit, fzf, vim — is therefore unreachable to an agent, even
    though its keyboard is not.
  2. Mouse clicks are never forwarded to the child process (Claude Code /diff, vim, lazygit…) #155 cannot be verified by the agent that fixes it. That bug is the
    mouse button is never encoded to the child
    . Its whole contract is a
    pointer gesture, and no test in the tree can produce one: a unit test can
    pin sgr_bytes(...) in pty, but the path click → pane → core → PTY →
    child stays a human check. Shipping the encoder blind is how a
    platform-conditional or mode-gated mistake lands green.

Shape

One tool, cell-addressed — terminals are a grid, and a grid is what the SGR
report carries:

mouse_in_session(session, kind, col, row, button?, modifiers?)
  kind: "press" | "release" | "click" | "drag" | "move"
  • col/row are 0-based cells in the visible screen, bounded by the pane's
    reported geometry; out of range rejects the whole call, as a malformed chord
    does for press_keys.
  • The answer reports what the pane did with it, in the spirit of
    press_keys' ran / inert / typed: forwarded (the child had mouse
    reporting on and received a report), selection (reporting off, so it drove
    local text selection), rejected (out of bounds). A caller must be able to
    tell "the child ignored my click" from "termherd never sent one" — those
    need opposite responses, exactly as inert's reason does.

Ordering with #155

They share one seam and should not be built twice. This ticket introduces the
pointer event path — a core::Event carrying cell coordinates and button
state, through the shell to the focused pane — and exposes it over MCP; #155
introduces the SGR encoder in pty and the mode gate that decides between
forwarding and local selection, consuming that path. So this lands first (or
in the same PR, as its first commit), and #155 becomes verifiable at the
moment it is written rather than three merges later.

Local selection is the observable behaviour before #155 lands: a drag over
text that a subsequent copy action can read back. That is a real assertion,
so this rung has a test even standing alone.

Out of scope

The pointer at termherd's own chrome — sidebar rows, tab bar, split
gutters. Same family, different coordinate frame (pixels, not cells), and it
blocks nothing. Filed separately.

Blocks #155. Part of the #90 epic.

Activity

  1. added
    area:terminal
    area:mcp
    on Sep 5, 2026
  2. bastien-gallay commented on Sep 16, 2026

    @bastien-gallay
    CollaboratorAuthor

    Plan

    Seam. The pointer path mirrors the wheel's, end to end: a cell-addressed
    core::Event → Effect → PtyHost port method → the per-session terminal
    thread, which owns the grid and the mode. Nothing pixel-shaped enters core.

    mouse_in_session ─► Action::Pointer ─► Event::TerminalPointer ─► Effect::TerminalPointer
          (mcp)           (bridge)             (core, if_live)          ─► PtyHost::pointer
                                                                         ─► TermCmd::Pointer
                                                                            └─ pointer_select() → apply_select
    
    • core::PointerEvent { kind, col, row, button, modifiers } — kind is
      press | release | click | drag | move; col/row are 0-based visible
      cells (the tool's frame). The pty converts to a grid line with its live
      display_offset, not a snapshot's.
    • One pure predicate, core::pointer_select(&PointerEvent, display_offset) -> Option<SelectOp>, decides what a pointer does locally: left press → Start,
      left drag → Update, left click → Clear (a bare click drops the
      highlight, as the canvas does), release / move / other buttons → nothing. The
      pty applies it; the shell consults the same function to answer the caller —
      so the outcome cannot drift from the behaviour.
    • Bounds are checked in the shell against the session's last Screen
      (col < cols && row < rows); out of range, or a session not yet rendered,
      rejects the whole call before anything applies, as a malformed chord
      does for press_keys.
    • Wire outcome: { focused_handle, pointer: "selection" | "ignored" }.
      forwarded is not produced by this rung — it arrives with Mouse clicks are never forwarded to the child process (Claude Code /diff, vim, lazygit…) #155, which
      adds the mode gate and the SGR/X10 press encoder inside the same
      TermCmd::Pointer arm, beside wheel_bytes. Adding the variant now would be
      a value nothing emits.
    • The iced canvas keeps its own gesture handling for this rung (double-click
      word, shift-extend, link click depend on screen content and pixel side); Mouse clicks are never forwarded to the child process (Claude Code /diff, vim, lazygit…) #155
      routes its bare press/drag/release through the new path when the gate lands.

    Tests (red first).

    • core: TerminalPointer on a live session yields one TerminalPointer
      effect, on an unknown session none; pointer_select table for every
      kind × button; property: the grid line is always row − display_offset
      and the column is preserved, for any offset.
    • pty: TermCmd::Pointer press+drag over a real grid leaves a selection
      that CopySelection reads back as the dragged text; a click clears it.
    • shell (orchestrate): unknown handle rejected, nothing forwarded; out of
      bounds rejected naming the geometry, nothing forwarded; in-bounds press
      forwards exactly one pointer to the PTY and answers selection; a move
      answers ignored; a press then copy action reads the selection through
      the existing chord path.
    • mcp/handler: mouse_in_session builds Action::Pointer from its args;
      an unknown kind / button rejects before the bridge; the tool joins the
      router-derived sweeps (structured content is an object) without an
      exemption.

    Book: docs/src/mcp/live-bridge.md gains the tool and loses the #300 row of
    its open-gaps table; the roadmap entry flips when #155 follows.

  3. changed the title [-]MCP: place a mouse event inside a session's terminal (cell-addressed) — blocks #155[/-] [+]MCP: place a mouse event inside a session's terminal (cell-addressed)[/+] on Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area:mcparea:terminal

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions