The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
feat(mobile): add prompt tap detection and related tests for terminal interactions
Dev jacoba7c11bb13af5
diff --git a/mobile/lib/terminal/terminal_prompt_zone.dart b/mobile/lib/terminal/terminal_prompt_zone.dartnew file mode 100644index 000000000..92f25a077--- /dev/null+++ b/mobile/lib/terminal/terminal_prompt_zone.dart@@ -0,0 +1,58 @@+import 'dart:math';++import 'package:xterm/xterm.dart';++/// How far up from the cursor a prompt's own text can reach. A sentence+/// dictated into the prompt wraps, and its first line is as much the prompt as+/// the line the cursor ended on.+const _maxPromptRows = 6;++/// The rows at the foot of the screen that count whatever the cursor says.+const _footRows = 3;++/// A line a TUI draws around its input rather than a line anybody typed.+final _rule = RegExp(r'^[─━═╭╮╰╯┌┐└┘\-]+$');++/// Whether a tap on buffer row [row] is aimed at the program's prompt — on a+/// phone, the one tap that should raise the keyboard. A tap anywhere else on the+/// terminal is somebody reading.+///+/// **The cursor says where the prompt is.** Both agent TUIs park the REAL+/// terminal cursor on their input line — Codex on `› `, Claude Code on `❯ ` —+/// as measured in live tmux panes (`#{cursor_y}` against `capture-pane`), and+/// Claude Code keeps it there while it is hidden, on the trust dialog's+/// selection for one. So the prompt is the block of text the cursor sits in,+/// walked up to its first line, and everything under it: the footer, the mode+/// line, the empty screen below a session that has barely started.+///+/// One row of slack above that, because a terminal row is ~16pt and a thumb is+/// not.+///+/// ⚠️ The bottom [_footRows] rows always count. Every agent TUI keeps its input+/// at the foot of the screen, and a program that leaves its cursor on the last+/// row — under its input rather than on it — must not leave the keyboard, which+/// on the phone only a tap raises, out of reach.+///+/// [row] is an absolute buffer row, scrollback included: what+/// `RenderTerminal.getCellOffset` reports. A tap on history scrolled far above+/// the prompt is therefore never a prompt tap.+bool isPromptTap(Buffer buffer, int row) {+ final top = _promptTop(buffer, buffer.absoluteCursorY) - 1;+ return row >= min(top, buffer.height - _footRows);+}++int _promptTop(Buffer buffer, int cursorRow) {+ var top = cursorRow;+ while (top > 0 &&+ cursorRow - top < _maxPromptRows - 1 &&+ _isTyped(buffer.lines[top]) &&+ _isTyped(buffer.lines[top - 1])) {+ top--;+ }+ return top;+}++bool _isTyped(BufferLine line) {+ final text = line.getText().trim();+ return text.isNotEmpty && !_rule.hasMatch(text);+}diff --git a/mobile/lib/widgets/terminal_panel.dart b/mobile/lib/widgets/terminal_panel.dartindex 16408d961..49845ffd6 100644--- a/mobile/lib/widgets/terminal_panel.dart+++ b/mobile/lib/widgets/terminal_panel.dart@@ -21,6 +21,7 @@ import '../terminal/terminal_font_store.dart';import '../terminal/terminal_link_opener.dart';import '../terminal/remote_media_download.dart';import '../terminal/terminal_links.dart';+import '../terminal/terminal_prompt_zone.dart';import '../terminal/terminal_session.dart';import '../terminal/terminal_theme.dart';import '../terminal/terminal_theme_store.dart';@@ -98,6 +99,10 @@ class TerminalPanel extends StatefulWidget {/// the click to a mouse-tracking program — but run on tap UP, so a scroll/// that began as a press opens nothing. A tap that clears a selection, or/// opens a link, is still exactly that.+ ///+ /// Run only for a tap on the prompt ([isPromptTap]). Every other claimed tap+ /// is swallowed: somebody tapping the output is reading it, and a keyboard+ /// jumping up would cover half of what they were reading.final VoidCallback? onInputTap;/// Whether this tile's composer textbox is showing. Only consulted for a remote machine.@@ -1188,6 +1193,7 @@ class _TerminalPanelState extends State<TerminalPanel>return;}_inputTapClaimed = false;+ if (!isPromptTap(_viewTerminal.buffer, cell.y)) return;widget.onInputTap?.call();}diff --git a/mobile/test/terminal_panel_input_tap_test.dart b/mobile/test/terminal_panel_input_tap_test.dartindex fee916b49..bf09e2afd 100644--- a/mobile/test/terminal_panel_input_tap_test.dart+++ b/mobile/test/terminal_panel_input_tap_test.dart@@ -78,6 +78,32 @@ void main() {expect(tester.testTextInput.hasAnyClients, isFalse);});+ testWidgets('only a tap on the prompt runs the host; the output swallows it', (+ tester,+ ) async {+ await pumpPanel(tester, onInputTap: () => inputTaps++);+ session.terminal.write(+ '${List.generate(60, (i) => 'output $i').join('\r\n')}\r\n\r\n› prompt',+ );+ await tester.pump();+ // Aimed through the render box, not the widget: the widget's padding is no+ // row at all, and a tap there never reaches the terminal's gestures.+ final render = tester+ .state<TerminalViewState>(find.byType(TerminalView))+ .renderTerminal;++ await tester.tapAt(render.localToGlobal(const Offset(20, 4)));+ await tester.pump(kDoubleTapTimeout);+ expect(inputTaps, 0, reason: 'reading the output raises nothing');+ expect(tester.testTextInput.hasAnyClients, isFalse);++ await tester.tapAt(+ render.localToGlobal(Offset(20, render.size.height - 4)),+ );+ await tester.pump(kDoubleTapTimeout);+ expect(inputTaps, 1);+ });+testWidgets('without a host the tap is still xterm\'s, keyboard and all', (tester,) async {diff --git a/mobile/test/terminal_prompt_zone_test.dart b/mobile/test/terminal_prompt_zone_test.dartnew file mode 100644index 000000000..25767a91c--- /dev/null+++ b/mobile/test/terminal_prompt_zone_test.dart@@ -0,0 +1,93 @@+import 'dart:math';++import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/terminal/terminal_prompt_zone.dart';+import 'package:xterm/xterm.dart';++/// A 40×12 screen holding [lines], with the cursor put on [cursorLine] the way+/// the program would put it there. Lines past the screen's height scroll into+/// history, so a line's index is its absolute buffer row either way.+Terminal _screen(+ List<String> lines, {+ required int cursorLine,+ bool alt = false,+}) {+ const rows = 12;+ final terminal = Terminal(maxLines: 200)..resize(40, rows);+ if (alt) terminal.write('\x1b[?1049h');+ terminal.write(lines.join('\r\n'));+ final firstOnScreen = max(0, lines.length - rows);+ terminal.write('\x1b[${cursorLine - firstOnScreen + 1};3H');+ return terminal;+}++List<int> _promptRows(Terminal terminal) => [+ for (var row = 0; row < terminal.buffer.height; row++)+ if (isPromptTap(terminal.buffer, row)) row,+];++void main() {+ test('Codex: the prompt, a row of slack, and the footer under it', () {+ // As captured from a live Codex pane: the cursor sits on `› `.+ final terminal = _screen([+ for (var i = 0; i < 15; i++) ' answer line $i',+ '',+ '',+ '› Ask Codex to do anything',+ '',+ ' gpt-5.6-terra default · ~/work',+ ], cursorLine: 17);+ expect(_promptRows(terminal), [16, 17, 18, 19]);+ });++ test('a dictated sentence that wrapped counts from its first line', () {+ final terminal = _screen([+ ' the answer',+ '',+ '› check the payment flow and then',+ ' tell me which tests are failing',+ ' on the remote box',+ '',+ ' gpt-5.6-terra default · ~/work',+ ], cursorLine: 4);+ expect(_promptRows(terminal).first, 1);+ expect(isPromptTap(terminal.buffer, 0), isFalse);+ });++ test(+ 'Claude Code: the rule over the box is the edge, not the text above',+ () {+ // As captured from a live Claude Code pane: alternate screen, cursor on `❯ `.+ final terminal = _screen(+ [+ ' Claude Code',+ ' ~/work',+ '',+ '',+ '─────────────────────',+ '❯ ',+ '─────────────────────',+ ' ⏵⏵ auto mode on',+ ],+ cursorLine: 5,+ alt: true,+ );+ expect(_promptRows(terminal).first, 4);+ expect(isPromptTap(terminal.buffer, 3), isFalse);+ },+ );++ test(+ 'a cursor left under the input still reaches the foot of the screen',+ () {+ final terminal = _screen([+ for (var i = 0; i < 9; i++) 'output $i',+ '> type here',+ 'footer',+ '',+ ], cursorLine: 11);+ expect(isPromptTap(terminal.buffer, 9), isTrue);+ expect(isPromptTap(terminal.buffer, 8), isFalse);+ },+ );+}