Repository navigation
feat(tui): bracketed paste and image attach (#560) - #564
Merged
Merged
Conversation
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).
🔍 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.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The TUI handles terminal paste as one block and can attach images to the next message:
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;Entersends./image <path|data-url>,/image clear, bare/image(lists), consistent withchat's/imagefrom 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 animage: shot.png (image/png, 12 KiB) · next messagerow above the editor (sharing the three rows with the follow-up queue). A refused path shows the host's error.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.docs/tui.md.Closes #560
Why
Reproduction on the base branch (a pty e2e that sends what a terminal sends):
\x1b[?2004h. A 3-line paste with CR line endings was replayed as keys.paste-onewas submitted as a message at the first CR,paste-twosteered that running turn ([owner interrupt …] paste-two), andpaste-threestayed in the editor.bracketed-pastefeature, enabled through ratatui-crossterm) parsesESC[200~…ESC[201~intoEvent::Pasteeven when the mode is off (event/sys/unix/parse.rs,parse_csi_bracketed_paste), and the event loop ignored that event.Changes
tole-tui:Inputis now an enum:Input::Key(KeyPress)|Input::Paste(String). Thenew/ctrl/alt/shiftconstructors are unchanged.term_input::input_from_eventmapsEvent::KeyandEvent::Paste.pastemodule providesnormalizeandimage_spec(the detection rule).Editor::paste(one edit).App::on_paste: ignored at an approval, filters an open picker, otherwise inserts. While idle, an image candidate becomesAction::PasteImage { spec, text }.TerminalGuardenables and disables bracketed paste.crosstermnow declares thebracketed-pastefeature explicitly.HostCmd::{AttachImage(String), ClearImages, Images}andHostReply::Images(Vec<ImageItem>). The reply is data only; the wording is the UI's.applyanswersImageswith an empty list.tole-cli:TuiSession::applymaps 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)./imageadded to the command menu. Pasted tabs are drawn as spaces in the editor; the text keeps the tab.@-panel entry. The panel inserts a path as text, and making a selection attach would give one key two meanings. Use/image <path>.--image. WithTOLE_VISION=0, the turn stops with themodel-capability error: …note and no request is sent. As withchat, the message is recorded with its image, so later messages in that session hit the same error.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 ontodevelopat 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:?2004henable at start and the?2004ldisable on exit;Entersends exactlyline-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./imageoutside the jail is refused with the host's error. A pasted outside path becomes text with the reason./image cleardrops the queue.e2e
tui_image_on_a_non_vision_model_reports_the_capability_error.tole-tuiunit tests with a fake host and no crossterm types coverInput::Paste:/imagemapping and notes;There is also a loop test that feeds a crossterm
Event::Paste, and atui_hosttest for theapplymapping.Mutation checks, each confirmed failing and then restored:
corais not installed locally. I reviewed the diff myself in its place. CI Cora Review is the gate.