@peppa_q/attach-image-path
v1.0.0
Published
Pi extension that detects image file paths in your prompt, reads the file, and injects the real image into the model so it always sees the picture.
Maintainers
Readme
attach-image-path
A Pi extension that detects image file paths in your prompt, reads the file, and injects the real image into the model — so the model always sees the picture instead of treating the path as plain text.
This fixes the common case where you paste a local screenshot path (e.g. from Snipping Tool) and the model never actually looks at the image.
What it does
Detects an image path in your message (Windows C:\..., WSL /mnt/c/..., or relative paths), reads the file, converts it to base64, and attaches it directly to the prompt via the input transform's images field. The image is fed to the model as a real image, so it's guaranteed to be seen.
Features
- Windows + WSL paths — converts
C:\...to/mnt/c/...using the WSL-nativewslpath, honoring your configured mount point in/etc/wsl.conf - Space-tolerant — handles paths with spaces like
C:\Program Files\My App\shot.png - Magic-byte mime detection — detects PNG/JPEG/GIF/WebP/BMP from file headers, not just the extension
- Size guard — rejects images over 20MB with a clear warning
Install
pi install npm:@peppa_q/attach-image-pathOr try it for one session:
pi -e npm:@peppa_q/attach-image-pathPlatform support
This extension is built for Windows + WSL — it exists to turn the Windows screenshot paths you paste (like C:\Users\...\ScreenClip\xxx.png) into images the model can actually see.
- Windows drive paths (
C:\...) are converted via the WSL-nativewslpathcommand, so this works when pi runs inside WSL. If you run pi directly on Windows (not through WSL), thewslpathcommand is unavailable and drive paths won't resolve. - macOS / Linux: native paths (
/Users/...,/home/...,./x.png,/tmp/...) work out of the box. Windows drive paths (C:\...) are not converted — they only make sense on a machine with the matching drive.
If you primarily use pi on Windows, the typical setup is: screenshots live on the Windows filesystem, and you run pi inside WSL so wslpath bridges the two.
Usage
Just paste an image path into your prompt. For example:
C:\Users\demo\Pictures\screenshot.png 这是什么The extension reads the file, attaches the image, and the model sees it directly.
How it works
It subscribes to the input event. When the prompt contains an image path, it:
- Extracts the path (Windows, WSL, or relative)
- Normalizes it to a readable absolute path (
wslpathfor Windows paths) - Reads the file and converts it to base64
- Injects the image via the
transformresult'simagesfield
Notes
- Uses only Node built-in modules (
node:fs/promises,node:path,node:child_process) and Pi core packages (declared as peer dependencies). No bundled runtime dependencies.
License
MIT
