Skip to content

Render saved screenshots and recordings in chat markdown#4321

Open
juliusmarminge wants to merge 4 commits into
mainfrom
t3code/render-chat-media
Open

Render saved screenshots and recordings in chat markdown#4321
juliusmarminge wants to merge 4 commits into
mainfrom
t3code/render-chat-media

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Jul 22, 2026

Copy link
Copy Markdown
Member

Summary

  • Add secure asset access for saved screenshots, videos, and browser artifacts.
  • Support saving preview screenshots to workspace paths or browser artifact storage.
  • Render saved media directly in chat markdown.
  • Extend preview recording and snapshot contracts and handlers.
  • Tighten pull request head matching and simplify related UI logic.

Testing

  • Added focused coverage for asset URL issuance and browser artifact validation.
  • Added MCP snapshot save-path and artifact persistence tests.
  • Not run: lint and test commands were not provided.

Note

Medium Risk
New filesystem write paths and asset signing for browser artifacts add security-sensitive surface area, though workspace saves include extensive symlink/traversal guards and tests.

Overview
Agents can persist preview snapshots via preview_snapshot with save (writes to browserArtifactsDir) or savePath (workspace-relative .png), with symlink-safe containment checks on workspace writes; results include savedScreenshotPath for embedding in replies.

The asset API gains a browser-artifact resource backed by <stateDir>/browser-artifacts, with issuance limited to media file names (no traversal). Workspace videos (.webm, .mp4, etc.) use exact-file signed URLs like images.

Chat markdown renders img/video through MarkdownMedia, resolving workspace paths and absolute browser-artifacts paths to signed URLs; sanitization allows video tags and preserves Windows drive-letter src values.

Preview tool descriptions document embedding recordings and screenshots in chat.

Reviewed by Cursor Bugbot for commit a035fa0. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Render saved screenshots and recordings in chat markdown

  • Adds save and savePath parameters to the preview_snapshot MCP tool: savePath writes a PNG to a workspace-relative path with symlink/traversal protection; save=true writes to a server-side browser artifacts directory with a timestamp+UUID filename.
  • Introduces a new browser-artifact asset claim type in assets.ts, allowing the server to issue and resolve signed URLs for files in browserArtifactsDir by filename only.
  • Adds a MarkdownMedia.tsx component that resolves img and video tags in chat markdown from direct URLs, workspace-relative signed URLs, or browser artifact filenames, with loading/error states and image expansion.
  • Extends chat markdown sanitization in ChatMarkdown.tsx to allow video tags and adds a rehype plugin to preserve Windows drive-letter paths through sanitization.
  • Risk: the new browser-artifact claim resolves files by filename from a server directory; invalid or missing filenames return null rather than an error to the client.

Macroscope summarized a035fa0.

- Add secure asset access for workspace media and browser artifacts
- Support saving preview screenshots and embedding playable recordings
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b0f95bd2-63a3-4cf5-a609-fedd820cf2ac

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch t3code/render-chat-media

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Jul 22, 2026

@macroscopeapp macroscopeapp Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effect service review: one convention issue found regarding error cause preservation. See inline comment.

Posted via Macroscope — Effect Service Conventions

Comment thread packages/contracts/src/previewAutomation.ts
Comment thread apps/web/src/components/ChatMarkdown.tsx
Comment thread apps/web/src/components/chat/MarkdownMedia.tsx
Comment thread apps/server/src/assets/AssetAccess.ts
Comment thread apps/web/src/components/chat/MarkdownMedia.tsx
Comment thread packages/contracts/src/previewAutomation.ts
Comment thread apps/server/src/mcp/toolkits/preview/handlers.ts
Comment thread apps/web/src/components/chat/MarkdownMedia.tsx
Comment thread apps/web/src/components/chat/MarkdownMedia.tsx Outdated
Comment thread apps/server/src/mcp/toolkits/preview/handlers.ts Outdated
Comment thread apps/web/src/components/chat/MarkdownMedia.tsx Outdated
@macroscopeapp

macroscopeapp Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

New feature introducing browser artifact handling, media rendering in chat, and screenshot-saving capabilities across server and web packages. The scope includes new asset types, new UI components, and security-sensitive path resolution logic that warrants human review.

You can customize Macroscope's approvability policy. Learn more.

- Preserve error causes in screenshot save failures
- Reject save+savePath combinations and describe both schema fields
- Verify canonical (symlink-resolved) containment before workspace writes
- Add collision-resistant suffix to artifact screenshot names
- Fix Windows drive paths, protocol-relative URLs, query strings, and
  extensionless video sources in markdown media resolution
- Only treat absolute browser-artifacts paths as server artifacts

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions github-actions Bot added size:XL 500-999 changed lines (additions + deletions). and removed size:L 100-499 changed lines (additions + deletions). labels Jul 23, 2026
Comment thread apps/server/src/mcp/toolkits/preview/handlers.ts
Comment thread apps/server/src/mcp/toolkits/preview/handlers.ts
Verify the deepest existing ancestor canonicalizes inside the workspace
before mkdir, and reject existing destination symlinks that resolve
outside the root.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread apps/server/src/mcp/toolkits/preview/handlers.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON, but a cloud agent failed to start.

Reviewed by Cursor Bugbot for commit f38f3a7. Configure here.

Comment thread apps/server/src/mcp/toolkits/preview/handlers.ts
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500-999 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant