fix(cli,sdk,broker): send and receive file attachments (screenshots) over DMs and channels
Summary
Agents and people can send screenshots and other files by DM and on channels, and a recipient PTY agent gets a local path it can open. Fixes #1398.
Root cause (#1398)
agent-relay message file upload passed [{type:'file', path}], and serializeAttachmentInputs JSON-stringified it into the attachment id. No bytes were ever uploaded, so every call failed with Invalid attachments: file ids must exist in workspace and be complete. Reproduced on CLI 13.1.1 and npx agent-relay@13.2.0. message dm send also had no way to attach a file, and the broker dropped attachments from inbound events.
Changes
- SDK:
files.upload/get/downloadonAgentRelayandRelaycastMessagingClient.- Shared
uploadRelayFile/downloadRelayFilehelpers: request the upload, PUT the bytes, then complete. A failed PUT never completes, and the signed URL query never appears in errors.
- CLI:
- A repeatable
--file <path>onmessage dm send,message postandmessage dm send_group. message file upload <path> --channel <ch> | --to <agent>; text defaults to the file name.- New
message file get <id>. - New
message file download <id> [--out], which saves to.agent-relay/attachments/<id>/<name>by default and prints the path.
- A repeatable
- MCP (
agent-relay mcp):upload_file(local path or base64) anddownload_file;send_group_dmacceptsattachments. - Broker: inbound node deliveries (and the WS path) carry attachments.
- Before injecting, each file is downloaded (25 MiB cap, 20 s per file, 60 s per message) to
<worker cwd>/.agent-relay/attachments/<file_id>/<name>. That directory gets a.gitignoreof*. - The message is held until its downloads finish, and later messages to the same agent wait behind it, so per-agent order and the sequence book are preserved.
- Attachment-only messages are injected.
- Injected text:
On failure, the line instead reads:Relay message from alice [<msg_id>]: see screenshot Attachments: - shot.png (image/png, 153.1 KB) saved to /abs/agent-cwd/.agent-relay/attachments/<id>/shot.pngfile <id> (not downloaded: <reason>); fetch with: agent-relay message file download <id>.
- Before injecting, each file is downloaded (25 MiB cap, 20 s per file, 60 s per message) to
Companion PRs:
- relaycast #490: engine, MCP, conformance.
- relaycast-cloud #220: prod R2 uploads and downloads were 403.
- relay-desktop #361: same rendering for desktop sessions, plus
/sendwith files to DMs and channels.
Tests: red, then green
packages/cli/src/cli/commands/message-files.test.ts(new): 8/8 failed against the originalmessage.ts, 8/8 pass with this change.packages/sdk/src/__tests__/files.test.ts(new): 7/7 pass.packages/cli/src/cli/mcp/messaging-tools.files.test.ts(new): 4/4 pass.- Existing
relaycast-groupsandmessaging-tools.protocolsuites still pass: 90/90 across the CLI and MCP files. - Broker:
fleet_delivery_with_attachment_injects_attachment_referenceanddm_with_attachments_injects_attachment_referencefailed on base with the body"see screenshot".- Focused attachment suite: 29/29 pass after review hardening (parsing, rendering, sanitization, size cap, download, timeout, fallback directory, ordering, symlink refusal).
- Local suite:
cargo test -p agent-relay-broker --no-fail-faston the merged branch: lib 1431 passed / 0 failed; continuity 12, fleet_wire_fixtures 2, journal_lock_cli 3, muse_startup_cli 2 all pass. Run withenv -u RELAY_INJECT_RATE_MS -u GIT_CONFIG_* -u RELAY_ATTEST_*and/usr/sbinon PATH.cargo fmt --checkandcargo clippy -- -D warnings(the CI form): pass.packages/clitsc --noEmit: pass.npm run lint: 0 errors.- prettier: clean on all changed files.
Local end-to-end proof
Local end-to-end proof (self-hosted engine from this relaycast branch + agent-relay CLI from the relay branch)
node packages/engine/dist/bin/serve.js --db e2e.db --port 8799 --env development
# workspace + two agents (mac-sender, linux-receiver) created via POST /v1/workspaces, /v1/agents
agent-relay message dm send linux-receiver "e2e DM screenshot" --file shot.png --token $SENDER --base-url http://localhost:8799
# -> attachments: [{ id: 234084343292145664, filename: shot.png, contentType: image/png, sizeBytes: 156748 }]
agent-relay message file upload shot.png --channel general --text "e2e channel screenshot" --token $SENDER --base-url http://localhost:8799
# -> attachments: [{ id: 234084508111515648, filename: shot.png, contentType: image/png, sizeBytes: 156748 }]
curl -s http://localhost:8799/v1/deliveries -H "authorization: Bearer $RECEIVER" | jq -c '.data[] | {reason, text:.message.text, attachments:.message.attachments}'
# {"reason":"dm","text":"e2e DM screenshot","attachments":[{"file_id":"234084343292145664","filename":"shot.png","content_type":"image/png","size_bytes":156748}]}
# {"reason":"message","text":"e2e channel screenshot","attachments":[{"file_id":"234084508111515648","filename":"shot.png","content_type":"image/png","size_bytes":156748}]}
agent-relay message file download 234084343292145664 --token $RECEIVER --base-url http://localhost:8799
# -> path: <cwd>/.agent-relay/attachments/234084343292145664/shot.png
shasum shot.png .agent-relay/attachments/234084343292145664/shot.png
# 058059839811fa67f36043694c0f15ba51ddd6a9 (both)
file .agent-relay/attachments/234084343292145664/shot.png
# PNG image data, 640 x 400, 8-bit/color RGB
The receiving Claude session opened the downloaded PNG with Read and saw the test image (red square, blue circle, green stripe, noise band).
RELEASE NEEDED: the CLI, MCP and broker changes reach users only in a new agent-relay release. Releases are not cut from this PR.
Live cross-machine proof: all four Mac↔Linux directions pass. DM and channel attachments crossed Mac→Linux byte-identically (3eeedee2…, b84b11b6…); Linux→Mac DM and channel files were downloaded, SHA-1 verified and opened (3850791d…, 353b2e30…). The final channel proof used relay-desktop#361 POST /send with channel + files (message 234368095965777920, file 234368083952877568, 34,900 bytes). relaycast-cloud #220 is merged and its production upload/download path was verified.
Main-target review follow-up
- Terminal
delivery_failednow clearsBlockedOnSendwhen it removes the final pending delivery for a worker; blocked/stuck events are emitted only while another delivery remains. Idle, stream, and delivery activity also preserve blocking only while pending work exists. - Default attachment downloads now use exclusive creation and numbered collision names, matching explicit-directory downloads, so existing files and planted target symlinks are not overwritten.
- The PTY delivery changelog entry is under
[Unreleased - Minor]/Fixed, with the release-only rollout sentence removed. - Red: the two broker regressions reported
BlockedOnSendinstead ofWorking/Idle; CLI attachment helpers failed 2/5 because repeat and symlink targets were overwritten. - Green: both broker regressions pass; CLI attachment helpers 5/5; broker library 1,462 passed / 7 ignored / 0 failed;
cargo clippy -p agent-relay-broker -- -D warnings,cargo fmt --check, CLI TypeScript, ESLint, Prettier, andgit diff --checkpass.
Agent Relay sessions
- 12457d35-c3d7-44f9-9717-84911b5f957b (dogpatch-mini, finish-relay-screenshots)
🤖 Generated with Claude Code
[!NOTE]
High Risk
Changes broker message injection, on-disk file handling, and when fleet deliveries are ACKed—security-sensitive paths (signed URLs, path sanitization) plus behavior that can block or duplicate delivery if acceptance logic is wrong.
Overview
Adds end-to-end file attachments for Relaycast messages and hardens how the broker delivers them into PTY agents.
Inbound WS and fleet deliver frames now parse attachment metadata and append an Attachments: block to the injected body. For fleet/node delivery, the broker downloads files (caps, timeouts, bounded concurrency) into .agent-relay/attachments/<file_id>/, stages deliveries per agent until downloads finish, and supports attachment-only messages. Failed or oversized downloads still inject fetch hints (agent-relay message file download <id>) with sanitized filenames and injection-safe rendering.
PTY delivery confirmation moves beyond raw echo: verification allows up to three submit-only retries, tracks composer “parked” vs accepted state (Codex, Claude, Gemini, Devin, cat), and emits richer DeliveryVerified / DeliveryUnconfirmed / DeliveryResubmitted events. Supporting changes include cursor-bounded PTY snapshots and Codex-specific busy-line activity detection. Docs/skills/changelog document CLI --file, file upload/download, and MCP upload_file / download_file (SDK/CLI implementation referenced in changelog; not all paths appear in this diff slice).
Reviewed by Cursor Bugbot for commit 8f32137b5e30316f22142b0e220301b8f9c25528. Bugbot is set up for automated code reviews on this repo. Configure here.
Agent Relay sessions