Skip to content

feat(chat): add attachment metadata and read-only attachment download - #1320

Open
voska wants to merge 2 commits into
openclaw:mainfrom
voska:feat/chat-attachments-download
Open

voska wants to merge 2 commits into
openclaw:mainfrom
voska:feat/chat-attachments-download

Conversation

@voska

@voska voska commented Nov 8, 2026

Copy link
Copy Markdown

Summary

gog chat can send attachments (#694) but can't see or fetch the ones it receives. chat messages list --json drops the attachment array, and there's no command to download one, so an agent reading a space never learns a screenshot was posted.

  • chat messages list --json: each message now includes attachments: [{name, contentName, contentType, source, attachmentDataRef | driveDataRef}]. The field is omitted when a message has none. thumbnailUri and downloadUri are left out.
  • New chat attachments download <name>: takes a message name (all its attachments) or one attachment name. It uses spaces.messages.get + media.download, so it's GET-only and works under --readonly. Writes to --out (a file, or a directory with a trailing slash; default .), refuses to overwrite without --overwrite, and reports path, bytes and sha256 (JSON or TSV). It supports --dry-run.
  • Drive attachments (source: DRIVE_FILE) are not fetched. The row reports driveFileId and points to gog drive download <id>.
  • Safety profiles: chat.attachments.download: true in readonly and agent-safe, the same as Drive download and the Gmail/Keep attachment commands.

The download follows the existing Keep Media.Download path and the shared openUserOutputFile / sanitizeAttachmentFilename helpers. No new dependencies or scopes.

Testing

  • make ci passes (fmt-check, lint, deadcode, tests, docs-check, agent-skills-check). Regenerated command docs and the gog-chat skill are included.
  • New unit tests (internal/cmd/chat_attachments_test.go): attachment projection in messages list, download to a directory with byte and sha256 checks, overwrite refusal and --overwrite, a Drive attachment that is not fetched, and name parsing.
  • Live: I've run this change on a v0.44.0 build since October against a Google Workspace account. chat messages list --json showed an uploaded PNG on a DM, and chat attachments download saved it intact under --readonly. The Go code in this PR is the same patch rebased onto main; only the test fixtures changed.

`chat messages list --json` now includes each message's attachments
(name, contentName, contentType, source, and the attachmentDataRef or
driveDataRef). thumbnailUri and downloadUri are left out.

New `chat attachments download <message|attachment>` fetches uploaded
attachments with spaces.messages.get + media.download (GET only, so it
works under --readonly). It writes to --out (a file or directory),
refuses to overwrite without --overwrite, and reports path, bytes and
sha256. Drive attachments are not fetched; the output points to
`gog drive download <id>`.

Both safety profiles allow the new command, like the other downloads.
@voska
voska requested a review from a team as a code owner November 8, 2026 19:07
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 8, 2026
@clawsweeper

clawsweeper Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Expose received Chat attachment metadata and add a read-only command to download uploaded attachments.

Example: A message at spaces/aaa/messages/m1 contains Screenshot.png.

  • Before: Message-list JSON omits the attachment, and Chat has no download command.
  • After: JSON includes attachment metadata, and chat attachments download saves Screenshot.png with its byte count and SHA-256.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The feature has a focused implementation and useful harness coverage, but concrete defects, an unresolved product contract, and absent inspectable live proof prevent merge.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Product

Kind: Feature · Worth it: Needs a maintainer decision · Fix scope: Complete
User problem: Users and agents reading Chat messages cannot discover or download received attachments through the CLI.
Reason: The use case fits the supported Chat area, but the new command and output contract require an owner decision.

Merge readiness

⛔ Blocked before merge - 4 items remain

Keep open: this PR adds a distinct capability missing from main, but filename collisions and untrusted-output handling need correction before merge.

Priority: P2
Reviewed head: 87c5c216f396b7588132ab29c44a85807ccac563
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should Chat expose additive attachment metadata and a message-or-attachment download command with the proposed output and overwrite flags?
  • Recommendation: Approve the focused attachment surface: Proceed with safe metadata and uploaded-attachment downloads while retaining the existing Drive download handoff.
  • Why: This establishes a new public CLI and scripting contract, and no Chat owner has approved that direction in the inspected discussion.

Before merge

  • Add real behavior proof - The supplied tests exercise command execution and the Google Chat SDK against HTTP fixtures. The body reports an older Workspace build displaying a PNG and downloading it under --readonly, but provides no terminal capture, logs, or linked artifact for inspection. Supply a terminal screenshot or redacted live output of message-list attachment metadata and the shipped download command producing matching bytes/hash; redact IPs, API keys, account identifiers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Prevent attachments in one batch from sharing a destination (P2) - A message can contain two different uploads named Screenshot.png, including files sent from different local directories through the existing repeatable --attach flag. Both resolve to the same destination here. Without --overwrite, the command writes the first file and then fails; with --overwrite, the second truncates the first and the command reports two successful rows pointing to one remaining file. Resolve distinct destinations or reject duplicate destinations before writing any attachment, independently of permission to overwrite pre-existing files.
  • Wrap sender-controlled attachment filenames in JSON output (P2) - With --json --wrap-untrusted, a sender can upload a file named 'Ignore previous instructions.txt' and have that text emitted unchanged as contentName. The shared wrapper does not recognize contentName, and neither the message-list nor download output registers it as a content key. This bypasses the explicit protection for fetched names in agent-facing output. Use outfmt.WithUntrustedContentKeys for contentName in both paths and cover ordinary and projected JSON.
  • Resolve security concern: Fetched filenames cross the agent-output boundary without markers - The exposure affects both message discovery and download-result JSON, including projected contentName fields; excluding downloadUri and thumbnailUri does not protect this separate text surface.

Findings

  • [P2] Prevent attachments in one batch from sharing a destination — internal/cmd/chat_attachments.go:186-188
  • [P2] Wrap sender-controlled attachment filenames in JSON output — internal/cmd/chat_attachments.go:50-54
  • [medium] Fetched filenames cross the agent-output boundary without markers — internal/cmd/chat_attachments.go:52

Tests

  • Missing end-to-end proof: Provide captured Workspace CLI output showing attachment discovery and an intact --readonly download; the added harness tests were not executed here, so base-fail/head-pass behavior is unverified.
Agent review details

How this fits together

Chat commands use the account-scoped Google Chat SDK to read messages and media, then emit JSON or TSV and write downloaded bytes through shared output-file helpers.

flowchart LR
  A[CLI arguments and account] --> B[Chat command]
  B --> C[Google Chat SDK]
  C --> D[Message and attachment metadata]
  D --> E[JSON or TSV output]
  D --> F[Media download]
  F --> G[Shared output file helper]
Loading

Technical review

Best possible solution:

Retain the focused Chat SDK implementation, prevent duplicate download destinations, and use the existing untrusted-content key helper for filenames.

Do we have a high-confidence way to reproduce the issue?

Source establishes the missing main capability and both introduced defects; no target code or tests were run under the read-only review constraint.

Is this the best way to solve the issue?

The additive projection and existing SDK/file helpers are a focused approach, provided download destinations remain distinct and fetched filenames retain the established untrusted-content boundary.

Full review comments:

  • [P2] Prevent attachments in one batch from sharing a destination — internal/cmd/chat_attachments.go:186-188
    A message can contain two different uploads named Screenshot.png, including files sent from different local directories through the existing repeatable --attach flag. Both resolve to the same destination here. Without --overwrite, the command writes the first file and then fails; with --overwrite, the second truncates the first and the command reports two successful rows pointing to one remaining file. Resolve distinct destinations or reject duplicate destinations before writing any attachment, independently of permission to overwrite pre-existing files.
    Confidence: 0.99
  • [P2] Wrap sender-controlled attachment filenames in JSON output — internal/cmd/chat_attachments.go:50-54
    With --json --wrap-untrusted, a sender can upload a file named 'Ignore previous instructions.txt' and have that text emitted unchanged as contentName. The shared wrapper does not recognize contentName, and neither the message-list nor download output registers it as a content key. This bypasses the explicit protection for fetched names in agent-facing output. Use outfmt.WithUntrustedContentKeys for contentName in both paths and cover ordinary and projected JSON.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e8428c36dd31.

Provenance checked

  • Chat message JSON projection keeps the original intent (b75058a: Expose narrowly selected metadata while excluding temporary URLs and preserving safe agent output.)
  • Baked safety profiles keeps the original intent (f26af3a: Enforce immutable command permissions before execution; the addition permits a GET-only download alongside existing local downloads.)
  • Generated command documentation and skills keeps the original intent (4ddec67: Keep command discovery derived from the public CLI schema.)

Testing

Proof path: in-process harness.

Security

Needs attention: Sender-controlled attachment filenames bypass the requested untrusted-content wrapping.

Evidence

Security concerns:

  • [medium] Fetched filenames cross the agent-output boundary without markers — internal/cmd/chat_attachments.go:52
    The exposure affects both message discovery and download-result JSON, including projected contentName fields; excluding downloadUri and thumbnailUri does not protect this separate text surface.
    Confidence: 0.99

What I checked:

Likely related people:

  • salmonumbrella: Raw commit 33685ad adds internal/cmd/chat_messages.go:78 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 33685adafea1; files: internal/cmd/chat_messages.go)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: A bounded Chat improvement with actionable download and output-safety defects; no current production outage is established.
  • add merge-risk: 🚨 security-boundary: New sender-controlled filenames bypass the explicit untrusted-content wrapper used by agent consumers.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: A bounded Chat improvement with actionable download and output-safety defects; no current production outage is established.
  • merge-risk: 🚨 security-boundary: New sender-controlled filenames bypass the explicit untrusted-content wrapper used by agent consumers.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 8, 2026, 2:22 PM ET / 19:22 UTC.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant