Skip to content

fix(chat): preserve markdown when copying messages - #6903

Open
j15z wants to merge 7 commits into
stagingfrom
fix/chat-code-not-copied-inline
Open

fix(chat): preserve markdown when copying messages#6903
j15z wants to merge 7 commits into
stagingfrom
fix/chat-code-not-copied-inline

Conversation

@j15z

@j15z j15z commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Preserve Markdown formatting when copying chat messages, including fenced code blocks and language labels
  • Convert visible workspace resources into portable Markdown links using resolved resource IDs

Type of Change

  • Bug fix

Testing

  • Focused chat copy, resource resolution, and Markdown mention tests
  • bun run type-check
  • bun run lint:check
  • bun run lint
  • bun run check:audits
  • Block registry audit against origin/staging

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Aug 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 21, 2026 3:25am

Request Review

@cursor

cursor Bot commented Aug 20, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Clipboard/copy-path change only; no auth, persistence, or message-send behavior is modified.

Overview
Copying a chat message now keeps Markdown (headings, emphasis, fenced code with language) instead of flattening it to plain text.

Copy uses the same visible transcript tree as the UI (getRenderableMessageText), strips internal tags, and turns workspace resource chips into portable sim: mention links with resolved IDs. Mention serialization is centralized in toSimMarkdownLink.

Home and the workflow copilot panel pass workspace files into chat so file mentions can resolve on copy.

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

@greptile-apps

greptile-apps Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR preserves assistant-message Markdown during copying and converts parsed workspace resources into portable sim: links.

  • Shares workspace-resource label and spacing logic between rendering and copy preparation
  • Builds copy content from the rendered message-segment tree
  • Adds regression coverage for Markdown, special tags, and resource conversion

Confidence Score: 4/5

The PR is not yet safe to merge because visible file-resource links can still be dropped from copied Markdown while resource metadata is unavailable.

File resource conversion depends on the asynchronously loaded workspace-file list and falls back to bare text whenever resolution misses, leaving the previously reported link-preservation failure reachable.

Files Needing Attention: apps/sim/app/workspace/[workspaceId]/home/components/mothership-chat/copyable-markdown.ts and apps/sim/app/workspace/[workspaceId]/home/home.tsx

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/home/components/mothership-chat/copyable-markdown.ts Introduces Markdown-preserving copy serialization, but unresolved visible file resources still lose their links.
apps/sim/app/workspace/[workspaceId]/home/components/mothership-chat/mothership-chat.tsx Connects rendered message text and workspace-file metadata to the copy action.
apps/sim/app/workspace/[workspaceId]/home/components/message-content/message-content.tsx Extracts copyable text from the same visible segment tree used by transcript rendering.
apps/sim/app/workspace/[workspaceId]/home/components/message-content/components/chat-content/workspace-resource-markdown.ts Centralizes workspace-resource labels, display links, and inline spacing behavior.
apps/sim/app/workspace/[workspaceId]/components/message-actions/message-actions.tsx Replaces plain-text stripping with injectable Markdown copy preparation.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Rendered assistant message] --> B[getRenderableMessageText]
  B --> C[sanitize and parse special tags]
  C --> D{Workspace resource?}
  D -->|No| E[Preserve Markdown text]
  D -->|Yes| F[Resolve canonical resource ID]
  F -->|Resolved| G[Portable sim Markdown link]
  F -->|Unresolved| H[Bare label]
  E --> I[Clipboard]
  G --> I
  H --> I
Loading

Reviews (4): Last reviewed commit: "fix(chat): copy only rendered subagent t..." | Re-trigger Greptile

@j15z

j15z commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator Author

@greptile

@j15z

j15z commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator Author

@cursor review

@j15z

j15z commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator Author

@greptile

@j15z

j15z commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit e066200. Configure here.

@j15z
j15z force-pushed the fix/chat-code-not-copied-inline branch from e066200 to d409b0d Compare August 20, 2026 22:58
@j15z

j15z commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator Author

@cursor review

@j15z

j15z commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator Author

@greptile

Comment on lines +19 to +20
const resource = resolveWorkspaceResourceRef({ ...data, title: label }, workspaceFiles)
return resource ? toSimMarkdownLink(resource.type, resource.id, label) : label

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.

P1 Unresolved file links are dropped

When a message is copied before the workspace-file query contains a matching file, resolveWorkspaceResourceRef returns no resource and this branch serializes the visible file reference as its bare label, causing the copied Markdown to lose the resource link and destination.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c943386. Configure here.

): string {
const label = workspaceResourceLabel(data)
const resource = resolveWorkspaceResourceRef({ ...data, title: label }, workspaceFiles)
return resource ? toSimMarkdownLink(resource.type, resource.id, label) : label

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Escaped links break chat paste

Medium Severity

Copied resources are serialized with toSimMarkdownLink, which backslash-escapes \, [, and ] in labels. The chat composer’s parseChipLinks expects unescaped [label](sim:kind/id) links and does not unescape. Titles with those characters therefore fail to round-trip into chips on paste, even though the PR presents these links as the portable chat format.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c943386. Configure here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant