summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-15 17:43:11 +0100
committersalmonik <salmonik@tuta.io>2026-11-15 17:43:11 +0100
commit371027a85f44470880b1436d59fa97774e9c8642 (patch)
treefc6d750fec65dd3a892a370baf16550efb6cb634
parent0.6.0: transcript viewer, turn summary, yolo floor, model/version records (diff)
downloadagent686-371027a85f44470880b1436d59fa97774e9c8642.tar.gz
agent686-371027a85f44470880b1436d59fa97774e9c8642.zip
0.6.1: redraw from the caret row, not the block height
A two-line prompt with the caret moved up made the next redraw overshoot by one row and clear the line above, erasing the model's output. The editor now tracks the caret's row. Adds scripts/ux-check.sh, which drives tmux and asserts the rendered screen: byte-level tests cannot see misplaced cursors or erased rows.
Diffstat (limited to '')
-rw-r--r--CHANGELOG.md11
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rwxr-xr-xscripts/ux-check.sh86
-rw-r--r--src/line.rs93
5 files changed, 179 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1fd94b9..d33608d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,17 @@ break the interface, **PATCH** for bug fixes.
7file, and the tool schemas the model sees. Anything a script or a resumed session 7file, and the tool schemas the model sees. Anything a script or a resumed session
8could depend on counts as API. 8could depend on counts as API.
9 9
10## 0.6.1
11
12### Fixed
13- The redraw moved up by the number of rows the prompt block occupied, but the
14 caret can be on any of those rows. With a two-line prompt and the caret moved
15 up (Home, Left, Up-history), the next redraw overshot by a row and cleared the
16 line above the prompt — usually the model's previous output. The editor now
17 tracks which row the caret is on and moves up by that.
18- Added `scripts/ux-check.sh`: drives the editor inside tmux and asserts on the
19 rendered screen. Byte-level tests could not see this class of bug.
20
10## 0.6.0 21## 0.6.0
11 22
12### Added 23### Added
diff --git a/Cargo.lock b/Cargo.lock
index 803a619..8b92fd5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
10 10
11[[package]] 11[[package]]
12name = "agent686" 12name = "agent686"
13version = "0.6.0" 13version = "0.6.1"
14dependencies = [ 14dependencies = [
15 "crossterm", 15 "crossterm",
16 "libc", 16 "libc",
diff --git a/Cargo.toml b/Cargo.toml
index e82f469..147541b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
1[package] 1[package]
2name = "agent686" 2name = "agent686"
3version = "0.6.0" 3version = "0.6.1"
4edition = "2021" 4edition = "2021"
5description = "A small coding agent for a 32-bit Debian box" 5description = "A small coding agent for a 32-bit Debian box"
6publish = false 6publish = false
diff --git a/scripts/ux-check.sh b/scripts/ux-check.sh
new file mode 100755
index 0000000..019f63d
--- /dev/null
+++ b/scripts/ux-check.sh
@@ -0,0 +1,86 @@
1#!/usr/bin/env bash
2# Drives the editor on a real terminal (tmux) and checks the things byte-level
3# tests cannot see: that a multi-line prompt is drawn where it belongs, and that
4# moving the caret inside it does not erase the output above.
5set -uo pipefail
6
7here=$(cd "$(dirname "$0")/.." && pwd)
8port=${PORT:-8791}
9session=agent686-ux
10work=$(mktemp -d)
11mock_pid=
12fail=0
13
14cleanup() {
15 tmux kill-session -t "$session" 2>/dev/null
16 [ -n "$mock_pid" ] && kill "$mock_pid" 2>/dev/null
17 rm -rf "$work"
18}
19trap cleanup EXIT
20
21fail_msg() {
22 echo "FAIL: $*" >&2
23 fail=1
24}
25
26python3 "$here/scripts/mock-provider.py" --port "$port" --quiet --delay 0 >/dev/null 2>&1 &
27mock_pid=$!
28sleep 0.6
29
30tmux kill-session -t "$session" 2>/dev/null
31tmux new-session -d -s "$session" -x 80 -y 24
32tmux send-keys -t "$session" \
33 "clear; cd $work && AGENT686_DATA=$work/.data OPENCODE_API_KEY=test \
34 $here/target/debug/agent686 --yolo --base-url http://127.0.0.1:$port/v1" Enter
35sleep 1.5
36
37# One turn so there is output above the prompt that must survive.
38tmux send-keys -t "$session" "hi" Enter
39sleep 1.2
40screen=$(tmux capture-pane -p -t "$session")
41echo "$screen" | grep -q "Hello from the mock provider" || fail_msg "the turn produced no answer"
42grep_line=$(echo "$screen" | grep -n "Hello from the mock provider" | head -1 | cut -d: -f1)
43
44# Two-line prompt, no trailing newline.
45printf 'line one\nline two' | tmux load-buffer -b uxcheck -
46tmux paste-buffer -p -b uxcheck -t "$session"
47sleep 0.5
48paste_y=$(tmux display-message -p -t "$session" '#{cursor_y}')
49
50tmux send-keys -t "$session" Home
51sleep 0.4
52home_y=$(tmux display-message -p -t "$session" '#{cursor_y}')
53[ "$home_y" -eq $((paste_y - 1)) ] || fail_msg "Home put the caret on row $home_y, expected $((paste_y - 1))"
54
55tmux send-keys -t "$session" Right
56sleep 0.4
57right_y=$(tmux display-message -p -t "$session" '#{cursor_y}')
58[ "$right_y" -eq "$home_y" ] || fail_msg "Right moved the caret to row $right_y, expected $home_y"
59
60screen=$(tmux capture-pane -p -t "$session")
61if ! echo "$screen" | grep -q "Hello from the mock provider"; then
62 fail_msg "moving the caret inside a two-line prompt erased the output above it"
63fi
64if ! echo "$screen" | grep -q "line two"; then
65 fail_msg "the second prompt line disappeared"
66fi
67if ! echo "$screen" | grep -q "^> line one"; then
68 fail_msg "the first prompt line is not drawn with its prompt"
69fi
70
71# Submitting must not duplicate the block or leave the answer mid-line.
72tmux send-keys -t "$session" Enter
73sleep 1.0
74screen=$(tmux capture-pane -p -t "$session")
75[ "$(echo "$screen" | grep -c '^line two$')" -eq 1 ] \
76 || fail_msg "the submitted prompt should appear exactly once"
77if echo "$screen" | grep -q 'line two.*Hello from the mock'; then
78 fail_msg "the answer was written on the same line as the prompt"
79fi
80
81if [ "$fail" -ne 0 ]; then
82 echo "--- final screen ---" >&2
83 echo "$screen" >&2
84 exit 1
85fi
86echo "ux-check: ok (two-line prompt, caret movement, output above intact)"
diff --git a/src/line.rs b/src/line.rs
index 1ae210a..613dffe 100644
--- a/src/line.rs
+++ b/src/line.rs
@@ -43,27 +43,27 @@ impl Editor {
43 let guard = RawGuard::enable()?; 43 let guard = RawGuard::enable()?;
44 let mut buffer: Vec<char> = Vec::new(); 44 let mut buffer: Vec<char> = Vec::new();
45 let mut cursor = 0usize; 45 let mut cursor = 0usize;
46 let mut rows = 1usize; 46 let mut state = DrawState::default();
47 47
48 self.history_index = self.history.len(); 48 self.history_index = self.history.len();
49 self.draft.clear(); 49 self.draft.clear();
50 50
51 draw(prompt, &buffer, cursor, &mut rows)?; 51 draw(prompt, &buffer, cursor, &mut state)?;
52 52
53 loop { 53 loop {
54 let event = event::read()?; 54 let event = event::read()?;
55 match event { 55 match event {
56 Event::Paste(text) => { 56 Event::Paste(text) => {
57 insert(&mut buffer, &mut cursor, &text); 57 insert(&mut buffer, &mut cursor, &text);
58 draw(prompt, &buffer, cursor, &mut rows)?; 58 draw(prompt, &buffer, cursor, &mut state)?;
59 } 59 }
60 Event::Resize(_, _) => { 60 Event::Resize(_, _) => {
61 // The terminal reflowed the block we were tracking, so the 61 // The terminal reflowed the block we were tracking, so the
62 // old row count is meaningless. Start a fresh prompt line 62 // old row count is meaningless. Start a fresh prompt line
63 // rather than risk erasing output above it. 63 // rather than risk erasing output above it.
64 println!(); 64 println!();
65 rows = 1; 65 state = DrawState::default();
66 draw(prompt, &buffer, cursor, &mut rows)?; 66 draw(prompt, &buffer, cursor, &mut state)?;
67 } 67 }
68 Event::Key(key) if key.kind == KeyEventKind::Press => { 68 Event::Key(key) if key.kind == KeyEventKind::Press => {
69 match handle_key(key, &mut buffer, &mut cursor, self) { 69 match handle_key(key, &mut buffer, &mut cursor, self) {
@@ -71,7 +71,7 @@ impl Editor {
71 Action::Submit => { 71 Action::Submit => {
72 // Redraw with the caret at the end so the submitted 72 // Redraw with the caret at the end so the submitted
73 // line looks complete before we move on. 73 // line looks complete before we move on.
74 draw(prompt, &buffer, buffer.len(), &mut rows)?; 74 draw(prompt, &buffer, buffer.len(), &mut state)?;
75 drop(guard); 75 drop(guard);
76 let line: String = buffer.iter().collect(); 76 let line: String = buffer.iter().collect();
77 self.remember(&line); 77 self.remember(&line);
@@ -89,7 +89,7 @@ impl Editor {
89 return Ok(Some(String::new())); 89 return Ok(Some(String::new()));
90 } 90 }
91 } 91 }
92 draw(prompt, &buffer, cursor, &mut rows)?; 92 draw(prompt, &buffer, cursor, &mut state)?;
93 } 93 }
94 _ => {} 94 _ => {}
95 } 95 }
@@ -303,15 +303,40 @@ fn cells(ch: char, col: usize) -> usize {
303 unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1) 303 unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1)
304} 304}
305 305
306fn draw(prompt: &str, buffer: &[char], cursor: usize, rows: &mut usize) -> io::Result<()> { 306/// Where the caret physically is, relative to the first row of the input block.
307 let width = terminal_width(); 307/// The previous draw can leave the caret on any row, so a redraw must move up by
308/// that row, not by the number of rows the block occupies.
309#[derive(Default, Clone, Copy)]
310struct DrawState {
311 rows: usize,
312 cursor_row: usize,
313}
314
315fn draw(
316 prompt: &str,
317 buffer: &[char],
318 cursor: usize,
319 state: &mut DrawState,
320) -> io::Result<()> {
308 let mut out = io::stdout(); 321 let mut out = io::stdout();
322 draw_to(&mut out, prompt, buffer, cursor, state)?;
323 out.flush()
324}
325
326fn draw_to<W: Write>(
327 out: &mut W,
328 prompt: &str,
329 buffer: &[char],
330 cursor: usize,
331 state: &mut DrawState,
332) -> io::Result<()> {
333 let width = terminal_width();
309 334
310 let (end_row, _) = layout(prompt, buffer, buffer.len(), width); 335 let (end_row, _) = layout(prompt, buffer, buffer.len(), width);
311 let (cursor_row, cursor_col) = layout(prompt, buffer, cursor, width); 336 let (cursor_row, cursor_col) = layout(prompt, buffer, cursor, width);
312 337
313 if *rows > 1 { 338 if state.cursor_row > 0 {
314 execute!(out, MoveUp(clamp(*rows - 1)))?; 339 execute!(out, MoveUp(clamp(state.cursor_row)))?;
315 } 340 }
316 execute!(out, MoveToColumn(0), Clear(ClearType::FromCursorDown))?; 341 execute!(out, MoveToColumn(0), Clear(ClearType::FromCursorDown))?;
317 342
@@ -330,9 +355,9 @@ fn draw(prompt: &str, buffer: &[char], cursor: usize, rows: &mut usize) -> io::R
330 execute!(out, MoveUp(clamp(end_row - cursor_row)))?; 355 execute!(out, MoveUp(clamp(end_row - cursor_row)))?;
331 } 356 }
332 execute!(out, MoveToColumn(clamp(cursor_col)))?; 357 execute!(out, MoveToColumn(clamp(cursor_col)))?;
333 out.flush()?;
334 358
335 *rows = end_row + 1; 359 state.rows = end_row + 1;
360 state.cursor_row = cursor_row;
336 Ok(()) 361 Ok(())
337} 362}
338 363
@@ -433,6 +458,48 @@ mod tests {
433 assert!(terminal_width() >= 1); 458 assert!(terminal_width() >= 1);
434 } 459 }
435 460
461 fn drawn(prompt: &str, buffer: &str, cursor: usize, state: &mut DrawState) -> String {
462 let chars: Vec<char> = buffer.chars().collect();
463 let mut out = Vec::new();
464 draw_to(&mut out, prompt, &chars, cursor, state).unwrap();
465 String::from_utf8(out).unwrap()
466 }
467
468 #[test]
469 fn redraw_moves_up_by_the_caret_row_not_the_block_height() {
470 let mut state = DrawState::default();
471
472 // First draw with the caret at the end of a two-line buffer.
473 let first = drawn("> ", "one\ntwo", 7, &mut state);
474 assert_eq!(state.cursor_row, 1, "caret ends on the second row");
475 assert!(!first.contains("\u{1b}[1A"), "first draw must not move up");
476
477 // Move the caret to the first row. The previous caret was on row 1, so
478 // the redraw may move up exactly one row — not `rows - 1` from row 0,
479 // which would land on the line above the prompt and erase it.
480 let second = drawn("> ", "one\ntwo", 0, &mut state);
481 assert!(
482 second.starts_with("\u{1b}[1A"),
483 "expected one MoveUp, got {:?}",
484 second
485 );
486 assert_eq!(state.cursor_row, 0);
487
488 // Drawing again with the caret already on row 0 must not move up
489 // *before* clearing; the only MoveUp is the one after writing, which
490 // puts the caret back on the first row.
491 let third = drawn("> ", "one\ntwo", 0, &mut state);
492 assert!(
493 !third.starts_with("\u{1b}[1A"),
494 "must not move up before clearing: {third:?}"
495 );
496 assert_eq!(
497 third.matches("\u{1b}[1A").count(),
498 1,
499 "exactly one repositioning move after writing: {third:?}"
500 );
501 }
502
436 #[test] 503 #[test]
437 fn layout_counts_wide_and_combining_characters() { 504 fn layout_counts_wide_and_combining_characters() {
438 let wide: Vec<char> = "日本語".chars().collect(); 505 let wide: Vec<char> = "日本語".chars().collect();