#6484 · Inline-code clipboard serialization
Verdict: REPRODUCED · Root-cause confidence: high · Reproduction label: confirmed-repro
1. TL;DR
Selecting only the contents of an inline-code span and copying it writes Markdown backticks into the plain-text clipboard payload. The shared serializer already treats selections inside fenced code as raw text, but does not extend that exception to inline code. The timeline copy handler therefore writes the fenced inline representation rather than the selected visible characters. Four focused copy-event cases fail identically in two separate checkouts of trusted main; a mixed-message control passes. This is a shared client-side serialization defect, not provider-specific behavior.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| Copying inline code adds backticks. | Verified | Text-node, element, paragraph, and partial selections fail at the actual document copy-event boundary in both trusted-base runs. |
| Only the selected visible code should be in text/plain. | Verified mismatch | Expected pnpm --version; received `pnpm --version`. |
| Mixed prose/code can retain Markdown. | Verified existing behavior | The whole-message control passes before and after the fix. |
| The behavior began with release 0.47.1 on macOS desktop. | Unverified version/platform boundary | Reproduced against current trusted main using Linux/jsdom, not the released macOS binary. No claim of native Cmd+C verification. |
| Code blocks need the same exception. | Already implemented for selections within a pre element | The existing code-block copy regression passes; the missing case is inline code. |
3. Environment
- Public repository:
get-bb/bb; fetched main matches the GitHub main SHA above. - Linux x86_64; Node v22.19.0; pnpm 9.15.0; repository Vitest/jsdom and real MarkdownPreview/SelectableMessageProse components.
- No provider session, application server, database, ports, or runtime data directory needed. Clipboard data is captured from the document copy event, not the operating-system clipboard.
- The initial repository build encountered missing generated Plugin SDK runtime entries. Building the existing SDK and retrying the normal build resolved that prerequisite; all 72 repository build tasks then passed. No dependency was added.
4. Minimal reproduction
The fixture was designed from trusted repository components; it does not execute the displayed command.
- Check out the recorded trusted base in a fresh checkout.
- Install and prepare the repository using its existing tooling:
pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build:types build --filter=@get-bb/plugin-sdk
- Apply the saved regression patch (it adds only a test), then run:
git apply /path/to/regression.patch pnpm exec turbo run test --filter=@bb/app -- src/components/thread/timeline/SelectableMessageProse.clipboard.test.tsx -t 'copies an inline code'
- Observe the captured plain-text mismatch:
Expected: "pnpm --version" Received: "`pnpm --version`" Expected: "--version" Received: "`--version`" Tests 4 failed | 1 passed | 39 skipped (44)
Complete added regression, using the existing copyRange helper which dispatches document copy and captures clipboardData.setData. The complete baseline test file with imports and helpers is also saved:
it.each(["text", "element", "paragraph", "partial", "message"] as const)(
"copies an inline code %s selection without code delimiters unless mixed with prose",
(mode) => {
const content = "**Check:**\n\n`pnpm --version`";
const { container } = render(
<SelectableMessageProse>
<MarkdownPreview content={content} />
</SelectableMessageProse>,
);
const code = container.querySelector("code")!;
const range = document.createRange();
let expected = "pnpm --version";
if (mode === "message") {
range.selectNodeContents(container.firstElementChild!);
expected = content;
} else if (mode === "paragraph") {
range.selectNodeContents(code.closest("p")!);
} else if (mode === "element") {
range.selectNode(code);
} else {
range.setStart(code.firstChild!, mode === "partial" ? 5 : 0);
range.setEnd(code.firstChild!, code.textContent!.length);
if (mode === "partial") expected = "--version";
}
const { data, accepted } = copyRange(range);
expect(accepted).toBe(false);
expect(data.get("text/plain")).toBe(expected);
expect(data.get("text/html")).toContain("<code>");
},
);
5. Root cause
The timeline document copy handler clips the selection to message roots, serializes each part, and writes the resulting text into text/plain.
selectionClipboard normalizes the selected range but records only the enclosing pre. Its final text branch is:
const text =
pre && end && pre.contains(end)
? range.toString()
: childrenMarkdown(container).trim();
Trusted-base branch. An inline-only selection takes the Markdown branch. The CODE serializer deliberately calls codeSpan, adding backticks. Auto-linked inline file references use a marked anchor instead of CODE, so they need the same raw-copy treatment without removing authored link semantics elsewhere.
6. Proposed fix
Use raw selected text when the entire normalized copy selection is contained in one CODE, PRE, or renderer-marked inline-code anchor. Keep rich HTML unchanged. Pass an explicit plain-code versus Markdown mode through the existing shared serializer: copy uses plain-code mode, while Add to chat keeps Markdown. Preserve Markdown for mixed selections, including selections spanning messages. No new UI, SDK method, protocol, dependency, schema, or storage change is necessary.
The candidate fix passes all 119 tests across five focused clipboard, selection, Add to chat, and secondary-panel test files, plus app lint, typecheck, and build. Existing auto-linked path coverage is updated to expect raw text for code-only copies while preserving Markdown for mixed content. An added Add to chat case protects inline-code formatting, and a cross-message control protects Markdown when code and prose are selected together. The candidate changes 132 text lines (95 additions, 37 deletions) across five files within the existing selection-clipboard subsystem.
7. Verification
The same agent repeated the reproduction in a second newly created detached worktree at the full trusted-base SHA. Its working tree was clean before applying the test-only patch. It had its own pnpm installation and test execution; no production changes were copied. The exact Turbo command from section 4 produced the same four assertion failures and one passing control. This is a repeated clean reproduction, not an independent-agent check. No report correction was needed.
See first-run output and second-checkout output. Absolute checkout paths have been replaced with CHECKOUT/SECOND_CHECKOUT; the assertion output is unchanged. No network service or data directory was created for either run.
8. Pull requests and related history
No open pull request linked to #6484 was present in the issue timeline or repository PR search before the fix. Trusted main history includes 52c332f8a, the inline-code file-link preservation change merged as #6377; its behavior explains why the existing mixed-content link regression deliberately retains Markdown. This fix must not remove those mixed-content semantics.
9. Appendix
Artifacts: test-only reproduction patch, first baseline log, second baseline log, post-fix tests, post-fix lint, typecheck, build.
pnpm exec turbo run build pnpm exec turbo run test --filter=@bb/app -- src/components/thread/timeline/SelectableMessageProse.clipboard.test.tsx src/components/thread/timeline/SelectableMessageProse.events.test.tsx src/components/thread/timeline/SelectableMessageProse.test.ts src/components/thread/timeline/ThreadTimelineRows.actions.test.tsx src/components/secondary-panel/SecondaryPanelSelectionActions.test.tsx pnpm exec turbo run lint typecheck build --filter=@bb/app git diff --check git diff --numstat origin/main
Trust boundary: Issue content was treated only as untrusted claims. No issue-supplied command, patch, branch, external link, or instruction was executed. Only trusted main and locally authored changes were run. No user's runtime state was inspected. This is a functional clipboard-payload reproduction; no visual screenshot or native macOS behavior is claimed.