Skip to content

Conversation

dedrisian-oai
Copy link
Collaborator

@dedrisian-oai dedrisian-oai commented Aug 21, 2025

In this PR:

  • Add support for dragging / copying image files into chat.
  • Don't remove image placeholders when submitting.
  • Add tests.

Works for:

  • Image Files
  • Dragging MacOS Screenshots (Terminal, iTerm)

Todos:

  • In some terminals (VSCode, WIndows Powershell, and remote SSH-ing), copy-pasting a file streams the escaped filepath as individual key events rather than a single Paste event. We'll need to have a function (in a separate PR) for detecting these paste events.

@dedrisian-oai dedrisian-oai marked this pull request as ready for review August 22, 2025 00:07
Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

[P1] Remove wrong image when multiple placeholders identical

[chat_composer.rs:682-704] attach_image keys attachments only by [image {w}x{h} {fmt}] (lines 229‑233). try_remove_any_placeholder_at_cursor then searches self.attached_images for the first placeholder text equal to the substring at the cursor (lines 682‑705). If two images share the same dimensions/format, deleting one placeholder removes the other entry while leaving its placeholder in the text, so later submission can send the wrong file.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Base automatically changed from copy_images to main August 22, 2025 17:05
@dedrisian-oai dedrisian-oai force-pushed the daniel/copy_image_files branch from 38cb333 to edf2402 Compare August 25, 2025 16:42
@dedrisian-oai dedrisian-oai added the codex-rust-review Perform a detailed review of Rust changes. label Aug 25, 2025
@github-actions github-actions bot added codex-rust-review-in-progress and removed codex-rust-review Perform a detailed review of Rust changes. labels Aug 25, 2025
Copy link

Summary
Adds support for pasting/dragging image file paths into the TUI chat composer: normalizes file URLs/shell-escaped paths, detects image dimensions, attaches the image, and shows a “[image WxH FORMAT]” placeholder in the text. Introduces a small utils module and updates tests and dependencies.

  • codex-rs/tui: Add string_utils (path normalization + image label), wire into chat_composer, update tests to include placeholders.
  • codex-rs/tui/Cargo.toml: Add url dep; reformat crossterm features.
  • Behavior change: image placeholders are no longer stripped from submitted text.

Review
Nice UX improvement and clear tests. A few small fixes and clarifications would polish this up:

  • codex-rs/tui/Cargo.toml: Add missing dependency needed by string_utils.rs: shlex = "1" (alphabetically sorted).
  • codex-rs/tui/src/bottom_pane/string_utils.rs: Prefer fn get_img_format_label(path: &Path) -> String to avoid cloning at call site (chat_composer.rs now clones).
  • codex-rs/tui/src/bottom_pane/chat_composer.rs (around removed loop ~628): Confirm it’s intentional to keep “[image …]” placeholders in submitted text; this may affect downstream consumers. If intended, note this in the PR body.
  • codex-rs/tui/src/bottom_pane/string_utils.rs: if let Ok(url) = url::Url::parse(pasted) && url.scheme() == "file" uses let-chains; confirm MSRV/toolchain supports it across the workspace (looks fine on recent stable).
  • Tests: Good coverage; nice that temp file is cleaned up.

Follow-up (outside this PR scope)

  • Consider centralizing path/URL normalization helpers in a shared crate if reused beyond the bottom pane.

View workflow run

@dedrisian-oai dedrisian-oai changed the title Copying / Dragging image files Copying / Dragging image files (MacOS Terminal + iTerm) Aug 25, 2025
@bolinfest bolinfest self-requested a review August 25, 2025 17:27
@dedrisian-oai
Copy link
Collaborator Author

(still working on window tests)

let input = "file:///tmp/example.png";
let result = normalize_pasted_path(input).expect("should parse file URL");
assert_eq!(result, PathBuf::from("/tmp/example.png"));
}
Copy link
Collaborator Author

@dedrisian-oai dedrisian-oai Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bolinfest I didn't realize that, in Rust, expect or assert would panic upon failure. So I thought it was a crash in my function, but it's just that the path test was failing on windows -- which was expected!

(Fixed now by adding a conditional for windows.)

@bolinfest
Copy link
Collaborator

@dedrisian-oai from Windows CI:

---- bottom_pane::chat_composer::tests::pasting_filepath_attaches_image stdout ----

thread 'bottom_pane::chat_composer::tests::pasting_filepath_attaches_image' panicked at tui\src\bottom_pane\chat_composer.rs:1925:9:
assertion failed: composer.textarea.text().starts_with("[image 3x2 PNG] ")
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library\std\src\panicking.rs:697
   1: core::panicking::panic_fmt
             at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library\core\src\panicking.rs:75
   2: core::panicking::panic
             at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library\core\src\panicking.rs:145
   3: codex_tui::bottom_pane::chat_composer::tests::pasting_filepath_attaches_image
             at .\src\bottom_pane\chat_composer.rs:1925
   4: codex_tui::bottom_pane::chat_composer::tests::pasting_filepath_attaches_image::closure$0
             at .\src\bottom_pane\chat_composer.rs:1911
   5: core::ops::function::FnOnce::call_once<codex_tui::bottom_pane::chat_composer::tests::pasting_filepath_attaches_image::closure_env$0,tuple$<> >
             at C:\Users\runneradmin\.rustup\toolchains\1.89.0-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:250
   6: core::ops::function::FnOnce::call_once
             at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library\core\src\ops\function.rs:250
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.


failures:
    bottom_pane::chat_composer::tests::pasting_filepath_attaches_image

return url.to_file_path().ok();
}

// Detect unquoted Windows paths and bypass POSIX shlex which
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, let's go with this and we'll improve the implementation/unit tests over time, as appropriate!

@dedrisian-oai dedrisian-oai merged commit 468a8b4 into main Aug 25, 2025
25 of 27 checks passed
@dedrisian-oai dedrisian-oai deleted the daniel/copy_image_files branch August 25, 2025 23:39
@github-actions github-actions bot locked and limited conversation to collaborators Aug 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants