Skip to content

Add attachment-to-reference image bridge tool - #39

Open
kvandre12-commits wants to merge 1 commit into
mpfaffenberger:mainfrom
kvandre12-commits:feat/attachment-references
Open

Add attachment-to-reference image bridge tool#39
kvandre12-commits wants to merge 1 commit into
mpfaffenberger:mainfrom
kvandre12-commits:feat/attachment-references

Conversation

@kvandre12-commits

Copy link
Copy Markdown

Summary

Add save_attachments_as_references, a tool that materializes the images a user attached in their latest message into real files on disk and returns their paths.

Why

Pasted or dragged images arrive as BinaryContent stapled onto the user message and never touch the filesystem (the clipboard queue is even drained during prompt resolution). Tools like codex_imagegen condition on reference_images paths, so there was previously no way to point image generation at something the user just pasted. This closes that gap: paste a picture, then generate a new image that preserves its subject or style.

Design

  • Self-contained plugin; no core edits.
  • Reuses bytes that already exist in RunContext.messages rather than re-persisting at ingestion (DRY, single responsibility).
  • Captures images from the latest user turn only ("the thing I just pasted"), skipping tool-return parts and non-image binaries.
  • Explicit, composable tool: the model calls it to get paths, then passes them to codex_imagegen as reference_images. No hidden auto-wiring into the imagegen plugin.
  • Writes atomically under ~/.code_puppy/attachment_references/ with 0o600 files.

Usage

save_attachments_as_references()
  -> {"success": true, "paths": ["/.../attachment-<uuid>.png"], "count": 1}
codex_imagegen(prompt="same subject, cinematic night scene", reference_images=[<that path>])

Validation

  • 8 focused unit tests plus the builtin plugin-lock/entry-point guard: 19 passed
  • Ruff correctness checks passed
  • Ruff formatting check passed
  • git diff --check passed
  • wheel build passed; wheel contains the new plugin module

Empirically verified against pydantic-ai 2.31.0 that RunContext.messages exposes history and that image BinaryContent survives in UserPromptPart.content.

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