Files
2f0cc97392 feat(paste): devvm paste and devvm paste rm (#38)
feat(paste): devvm paste, an image, PDF or copied file from the clipboard into the VM (#38)

devvm paste reads the host's clipboard and streams what's on it into the
running VM's paste folder over the backend's Exec, with no SSH agent and no
new channel, then copies the file's path in the VM to the host clipboard for
the agent's prompt. devvm paste rm empties the folder after a question, and
a launch that starts a stopped VM offers to.

What it reads:
- an image (PNG, JPEG, GIF, WebP; TIFF is converted to PNG), checked by its
  bytes; browsers hand over a PNG, so an animated GIF arrives as one frame
- PDF data, sent as it is, and preferred over a file reference beside it
  (Preview's page copies)
- one copied file, after a question that shows its path on this machine;
  --send-file answers it only for a file inside the project folder reached
  without links, and never for a --clone VM
- never text; several files are refused

Security:
- macOS reads file URLs only through NSPasteboard (FileURLsOnly): AppleScript's
  «class furl» coercion turned any text, such as a path a web page or the
  VM's OSC 52 put there, into a file to send
- copied files are opened with openat and O_NOFOLLOW|O_NOCTTY|O_NONBLOCK,
  following a root-owned link only in a folder only root can change, and read
  through internal/safefile (Checked), capped at 64 MiB
- osascript and pbcopy by absolute path, Linux's tools only from system
  folders, never PATH
- time limits on every clipboard tool and on paste.sh in the VM; bounded
  reads of everything the VM prints
- the path copied back is built on the host, keeping only the file's
  extension: nothing the VM says reaches the clipboard

Also: the paste-dir setting (default /tmp/devvm-paste, made at each
launch), --json with sent, the agents' guide line, messages with doc links,
stubs, CLI tests, an e2e check in the project section, and docs on
coding-agents, settings, design, security and attack-vectors.

Co-authored-by: dustypolk <[email protected]>
Co-authored-by: w3cj <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-11 22:29:46 -07:00

48 lines
2.0 KiB
Bash

#!/bin/sh
# devvm paste's side in the VM, run as sh -c SCRIPT devvm-paste COMMAND DIR [NAME] with the
# script itself as the argument, so nothing of it is left on disk. The host names the folder DIR
# (config.toml's paste-dir) and the file NAME, both from a fixed set of characters.
# put DIR NAME writes stdin to DIR/NAME: to NAME.part first, mode 600, then renamed over NAME,
# so a reader never sees half of it. DIR is made, mode 700, when it's missing, and
# refused when it's a symbolic link, isn't a folder or isn't this user's.
# count DIR prints how many files devvm paste left in DIR
# rm DIR deletes them and prints how many
# count and rm see only regular files at DIR's top level whose names devvm paste gives, and its
# .part leftovers, never anything else in a folder that may be yours.
set -eu
cmd=$1 dir=$2
h='[0-9a-f]'
d='[0-9]'
pat="paste-$d$d$d$d$d$d$d$d-$d$d$d$d$d$d-$h$h$h$h$h$h$h$h*"
# mine lists devvm paste's files in $dir, one a line: regular files, never links, named from the
# characters devvm uses and no other, so a name with a newline past devvm's prefix, which would
# read as two lines, isn't devvm's.
mine() { find "$dir" -maxdepth 1 -type f -name "$pat" ! -name '*[!A-Za-z0-9._-]*'; }
case $cmd in
put)
name=$3
if [ -L "$dir" ]; then echo "devvm: $dir is a symbolic link, so devvm paste can't use it" >&2; exit 1; fi
if [ ! -e "$dir" ]; then (umask 077 && mkdir -p "$dir"); fi
if [ ! -d "$dir" ]; then echo "devvm: $dir isn't a folder, so devvm paste can't use it" >&2; exit 1; fi
if [ -z "$(find "$dir" -prune -user "$(id -un)")" ]; then
echo "devvm: $dir isn't yours, so devvm paste can't use it" >&2; exit 1
fi
umask 077
cat > "$dir/$name.part"
mv -f "$dir/$name.part" "$dir/$name"
;;
count)
[ -d "$dir" ] || { echo 0; exit 0; }
mine | wc -l | tr -d ' '
;;
rm)
[ -d "$dir" ] || { echo 0; exit 0; }
n=$(mine | wc -l | tr -d ' ')
mine | while IFS= read -r f; do rm -f -- "$f"; done
echo "$n"
;;
*)
echo "devvm: paste.sh: unknown command $cmd" >&2; exit 2
;;
esac