Skip to content

feat(codex-fleet): robust pane paste helper with MIME validation + structured logging#148

Merged
NagyVikt merged 1 commit into
mainfrom
agent/claude/robust-paste-helper-2026-05-16-02-10
May 16, 2026
Merged

feat(codex-fleet): robust pane paste helper with MIME validation + structured logging#148
NagyVikt merged 1 commit into
mainfrom
agent/claude/robust-paste-helper-2026-05-16-02-10

Conversation

@NagyVikt
Copy link
Copy Markdown
Contributor

Automated by gx branch finish (PR flow).

…ructured logging

PR #140's inline image-paste in pane-context-menu.sh only matched png/jpeg/gif/webp/bmp
and didn't validate the captured payload, causing silent "didn't quite work" failures
when modern browsers/screenshots provided avif/heic/svg, when wl-paste exited zero with
empty output, or when the wrong MIME landed first in --list-types output.

Extract a single source-of-truth helper that drives both the bash menu (pane-context-menu.sh)
and the tmux display-menu (style-tabs.sh):

- pane-menu-paste.sh (new): enumerates MIME types once, walks an extended image preference
  list (png > webp > jpeg > avif > heic > heif > gif > bmp > tiff > svg+xml > x-icon),
  validates each saved image by size guard (>100 bytes) + magic-byte sniff (PNG/JPEG/GIF/
  WebP/BMP/TIFF/ICO/AVIF/HEIC ftyp box/SVG xml header), falls through to the next MIME on
  failure, then to text/uri-list (pastes file paths from file managers), then text/plain.
  Saves images under /tmp/codex-fleet-clipboard/ (mode 700, auto-prunes >1h files), logs
  every invocation to /tmp/codex-fleet-paste.log with mime/size/path/error for tail -f
  debugging, caps the log at 100KB. Falls back to tmux's own paste-buffer when wl-paste
  is missing entirely.
- pane-context-menu.sh: replaces the 30-line inline p) case with a one-line shellout.
- style-tabs.sh: rewires the MouseDown3Pane Paste row to call the same helper so the two
  menu surfaces stay behaviorally identical.

Verification: bash -n + shellcheck (docker koalaman/shellcheck:stable) clean on all three
files (only pre-existing SC1091 source-resolution info on pane-context-menu.sh remains).
Smoke tests covered text/empty-clipboard/PNG-too-small/PNG-magic-validated paths against
a fake pane id; helper exits cleanly with structured log lines in all cases.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@NagyVikt NagyVikt merged commit 0a3383a into main May 16, 2026
@NagyVikt NagyVikt deleted the agent/claude/robust-paste-helper-2026-05-16-02-10 branch May 16, 2026 00:18
NagyVikt added a commit that referenced this pull request May 16, 2026
#153)

The PR #148 helper iterates `wl-paste --type <mime>` for each advertised
image MIME. That works for most sources, but hits an intermittent
gnome-screenshot quirk where `wl-paste --type image/png` returns the
literal text "No suitable type of content copied" (35 bytes, no PNG
magic) even though `image/png` is in --list-types and plain `wl-paste`
DOES return the actual PNG bytes.

Also: Wayland clipboard sources can be one-shot — once `wl-paste --type X`
consumes the source, a subsequent plain `wl-paste` returns 0 bytes. So
the fallback HAS to run BEFORE the --type loop, not after.

New section (1a) before the existing (1) IMG_PREF loop:
- Gated on at least one image MIME being advertised (so we don't swallow
  text content here)
- Single plain `wl-paste` call into a temp file
- Magic-byte sniff for PNG/JPEG/GIF/WebP/BMP/AVIF/HEIC/HEIF
- On match: save with detected extension, paste the path, log
  outcome=image-no-type, exit 0
- On no match / empty / too-small: fall through to the existing
  (1) IMG_PREF loop which still works for sources that allow re-reads

Smoke-tested against the project's actual clipboard mid-session.
Synthetic `wl-copy --type X` doesn't repro the real bug cleanly, so
relied on field repro via the user's prior `/tmp/clipboard-img-...png`
that captured 35 bytes of the error text.

Co-authored-by: NagyVikt <nagy.viktordp@gmail.com>
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.

1 participant