agent-orchestrator icon indicating copy to clipboard operation
agent-orchestrator copied to clipboard

bug(terminal): clicking in the input box doesn't move the caret — forceSelectionMode suppresses all mouse reporting to the PTY

Open homeshrawat opened this issue 3 months ago • 2 comments

Summary

Clicking inside the agent's input box does not move the text caret. To edit something earlier in a line you have already typed, you must arrow left/right — clicking where you want to edit does nothing.

Root cause: AO unconditionally suppresses all mouse button reporting to the PTY, so mouse-aware agent TUIs (cursor-agent, claude-code) never receive the click that would place the caret.

Root cause

frontend/src/renderer/components/XtermTerminal.tsx:243-251, called at line 400:

function forceSelectionMode(term: Terminal): void {
	const internal = term as XtermInternal;
	const selectionService = internal._core?._selectionService;
	const element = internal._core?.element;
	if (!selectionService || !element) return;
	selectionService.shouldForceSelection = () => true;
	selectionService.enable();
	element.classList.remove("enable-mouse-events");
}

shouldForceSelection = () => true makes xterm treat every mouse press as a text-selection drag. Removing enable-mouse-events stops xterm's MouseService / CoreMouseService from encoding button reports at all. So even when the TUI enables mouse tracking (DECSET 1000/1002/1006), press/drag/release are never encoded and never written to the PTY.

The only mouse input ever forwarded is the wheel, hand-rolled as SGR reports at XtermTerminal.tsx:220-241 (sgrWheelReport, buttons 64/65) and dispatched in the wheel handler at :700-750, which correctly branches on term.modes.mouseTrackingMode. There is no button equivalent, and no click-to-position logic anywhere.

Scope — one of these two cases is a bug, the other is not

  1. Plain shell / readline (bash, zsh) — not a bug. Terminals do not move the shell cursor on click; that is expected behavior.
  2. Mouse-aware TUIs (cursor-agent, claude-code, tmux with mouse on) — this is a bug. Those TUIs enable mouse tracking specifically so a click can place the caret, and forceSelectionMode overrides them unconditionally. This is the reported case: clicking into already-typed text in the agent's input box to edit it.

Regression risk — please read before fixing

forceSelectionMode was introduced by commit 7ba860741, "fix: add terminal controls and restore copy/scroll (#372)". It exists to make copy/selection work, and it bought that by trading away mouse forwarding. A naive revert reintroduces #372.

Suggested approach that preserves both:

  • Make forced selection conditional — force it only when term.modes.mouseTrackingMode === "none", so selection still works in a plain shell while mouse-aware TUIs get their events.
  • Keep Alt/Option-click for selection while tracking is active. This is the standard terminal convention, and macOptionClickForcesSelection = true is already set at XtermTerminal.tsx:399 — it is redundant today only because forceSelectionMode forces selection unconditionally.

Whatever the fix, it should be verified against #372's original symptoms (copy and scroll) as well as the click-to-position case.

Steps to reproduce

  1. Open a session running a mouse-aware agent TUI (cursor-agent or claude-code).
  2. Type a sentence into the input box.
  3. Click on a word in the middle of what you typed.
  4. The caret does not move; typing continues at the end. Arrow keys are the only way to reposition.

Environment

  • macOS (darwin 23.6.0), AO desktop app
  • Repo at 3934bc86a

homeshrawat avatar Aug 05 '26 23:08 homeshrawat

Thanks for contributing to Agent Orchestrator.

This issue is being picked up by the current external contributor on-call pair:

  • @illegalcall
  • @somewherelostt

If someone is already working on this, please continue as usual. The on-call pair is added for visibility, tracking, and support, not to take over the work. If you need help with review, direction, reproduction, or next steps, please tag @illegalcall and @somewherelostt here.

For faster context or live questions, you can also join the AO Discord.

Join the session here: https://discord.gg/H6ZDcUXmq

Come by if you want to see what is being built, ask questions, or just hang around with the community.

somewherelostt avatar Aug 06 '26 15:08 somewherelostt

This matches the behavior of Claude Code, Codex, and other terminal-based agents. Clicking does not reposition the input caret, so we are closing this as expected behavior.

Rishet11 avatar Sep 10 '26 18:09 Rishet11