Skip to content

feat(tui): bracketed paste and image attach (#560) - #564

Merged
ajianaz merged 2 commits into
developfrom
feat/560-tui-paste-images
Nov 11, 2026
Merged

ajianaz merged 2 commits into
developfrom
feat/560-tui-paste-images

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What

The TUI handles terminal paste as one block and can attach images to the next message:

  • Bracketed paste. Enabled on start, disabled on exit and when a panic unwinds (same drop guard as raw mode / keyboard enhancement). A pasted block arrives as one UI-neutral Input::Paste(String) and is inserted into the editor as one edit: CRLF and lone CR become LF, control characters other than newline and tab are dropped. It never submits, steers or answers an approval; Enter sends.
  • /image <path|data-url>, /image clear, bare /image (lists), consistent with chat's /image from feat(core,cli): images on any turn, ACP image blocks, and a decision on an image-reading tool #559: same jail, 10 MiB cap and sniffing as --image. Queued images show as an image: shot.png (image/png, 12 KiB) · next message row above the editor (sharing the three rows with the follow-up queue). A refused path shows the host's error.
  • Paste an image. While idle, a paste that is exactly one image reference (a data:image/… URL, or one path ending in .png .jpg .jpeg .gif .webp, optionally quoted or with \ -escaped spaces) is attached instead of inserted. If the host refuses it (missing, outside the jail, not an image), it is inserted as text, with a note giving the reason. Anything else is text.
  • Decision (owner): no OS clipboard images in the TUI. A terminal only delivers text, and reading the clipboard would need a native, platform-specific dependency. GUI clients (feat(desktop): tole-desktop — GPUI desktop client (first graphical client) #527–feat(web): web client of tole serve (low priority — Svelte vs React undecided) #529) own clipboard images. This is recorded in docs/tui.md.

Closes #560

Why

Reproduction on the base branch (a pty e2e that sends what a terminal sends):

  • The TUI never sent \x1b[?2004h. A 3-line paste with CR line endings was replayed as keys. paste-one was submitted as a message at the first CR, paste-two steered that running turn ([owner interrupt …] paste-two), and paste-three stayed in the editor.
  • A block wrapped in bracketed-paste markers was silently dropped. crossterm 0.29.0 (bracketed-paste feature, enabled through ratatui-crossterm) parses ESC[200~…ESC[201~ into Event::Paste even when the mode is off (event/sys/unix/parse.rs, parse_csi_bracketed_paste), and the event loop ignored that event.

Changes

  • tole-tui:
    • Input is now an enum: Input::Key(KeyPress) | Input::Paste(String). The new/ctrl/alt/shift constructors are unchanged.
    • term_input::input_from_event maps Event::Key and Event::Paste.
    • The new paste module provides normalize and image_spec (the detection rule).
    • New Editor::paste (one edit).
    • App::on_paste: ignored at an approval, filters an open picker, otherwise inserts. While idle, an image candidate becomes Action::PasteImage { spec, text }.
    • TerminalGuard enables and disables bracketed paste.
    • crossterm now declares the bracketed-paste feature explicitly.
  • Host seam:
    • New HostCmd::{AttachImage(String), ClearImages, Images} and HostReply::Images(Vec<ImageItem>). The reply is data only; the wording is the UI's.
    • The default apply answers Images with an empty list.
    • The UI mirrors the host's queue for the row. It clears the mirror when a message starts a turn. After a turn that took images, it asks the host again, because an unrecorded message hands its images back.
  • tole-cli: TuiSession::apply maps the three commands onto the feat(core,cli): images on any turn, ACP image blocks, and a decision on an image-reading tool #559 queue (attach_image, clear_pending_images, pending_images).
  • /image added to the command menu. Pasted tabs are drawn as spaces in the editor; the text keeps the tab.
  • No @-panel entry. The panel inserts a path as text, and making a selection attach would give one key two meanings. Use /image <path>.
  • Non-vision model: verified that it surfaces like --image. With TOLE_VISION=0, the turn stops with the model-capability error: … note and no request is sent. As with chat, the message is recorded with its image, so later messages in that session hit the same error.
  • Docs: docs/tui.md (keys, commands, a Paste and images section, architecture, clipboard decision), CHANGELOG Unreleased, README image section, docs/epics.md.

Testing

  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, cargo check -p tole-cli --no-default-features: clean.

  • cargo test --workspace: 1250 passed, 0 failed (after rebasing onto develop at aaff09c, which contains feat(cli): images on any turn and ACP image blocks (#559) #563 and feat(serve): image upload, prompt images and image read route (#558) #562).

  • Regression e2e tui_bracketed_paste_is_one_block_that_waits_for_enter (pty, real binary, mock provider). It asserts:

    • the ?2004h enable at start and the ?2004l disable on exit;
    • a CRLF/CR/BEL-laden 3-line paste sends nothing;
    • Enter sends exactly line-one\nline-two\nline-three.

    It fails on the unfixed code and passes now.

  • e2e tui_attaches_pasted_and_slash_image_paths_to_the_next_message: the pasted path is attached and rides on the next message only. /image outside the jail is refused with the host's error. A pasted outside path becomes text with the reason. /image clear drops the queue.

  • e2e tui_image_on_a_non_vision_model_reports_the_capability_error.

  • tole-tui unit tests with a fake host and no crossterm types cover Input::Paste:

    • a paste is one edit and does not submit (idle) or steer (running);
    • a paste never answers an approval and disarms Ctrl+C;
    • a paste filters a picker;
    • the image detection rule;
    • attach or text fallback;
    • the /image mapping and notes;
    • the queue mirror across a turn.

    There is also a loop test that feeds a crossterm Event::Paste, and a tui_host test for the apply mapping.

  • Mutation checks, each confirmed failing and then restored:

    1. Not enabling bracketed paste fails the e2e.
    2. Not normalizing lone CR fails 2 unit tests.
    3. Dropping the approval guard fails the approval test.
    4. Not re-reading images after an image turn fails the queue test.
    5. Making a paste with a newline submit fails 3 unit tests and the e2e.
  • cora is not installed locally. I reviewed the diff myself in its place. CI Cora Review is the gate.

Enable bracketed paste in the TUI so a pasted block arrives as one
Input::Paste and is inserted into the editor as one edit (CRLF/CR become
LF, control chars except newline/tab dropped); it never submits, steers
or answers an approval. Before, a multi-line paste was replayed as keys:
the first line was sent, the second steered that turn.

Add /image <path|data-url> | clear (and bare /image to list), backed by
new HostCmd::{AttachImage, ClearImages, Images} and HostReply::Images,
mapped onto TuiSession's #559 pending-image queue. Queued images show as
a row above the editor. A paste that is exactly one image path or a
data:image URL is attached instead of inserted; when the host refuses
it, it is inserted as text with the reason.

No OS clipboard images in the TUI (owner decision; GUI clients own them).
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

image_spec checked the data: prefix with t[..5], which panics when byte 5
falls inside a multi-byte character (pasting "日本" or two emoji while
idle crashed the TUI). Use get(..5) and cover non-ASCII pastes and image
paths in the unit tests.
@ajianaz
ajianaz merged commit 34468ac into develop Nov 11, 2026
15 of 36 checks passed
@ajianaz
ajianaz deleted the feat/560-tui-paste-images branch November 11, 2026 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(tui): handle terminal paste and attach images (paste, path, optional clipboard)

2 participants