Skip to content

feat(widget): add copy action to completed replies - #504

Merged
anurag629 merged 6 commits into
codercops:devfrom
piyusshhjangid:codex/477-copy-reply
Oct 31, 2026
Merged

anurag629 merged 6 commits into
codercops:devfrom
piyusshhjangid:codex/477-copy-reply

Conversation

@piyusshhjangid

Copy link
Copy Markdown
Collaborator

Closes #477

Summary

  • Add a localized copy button to completed assistant replies.
  • Copy readable text from rendered replies, preserving code and line breaks without Markdown syntax.
  • Keep the action hidden while replies are streaming.
  • Announce copy success or failure through the existing reply live region, including when clipboard access is unavailable.
  • Add translations, focus styling, tests, and a minor changeset for @chatcops/widget.

How I tested this

  • Widget build: Vite bundles and declaration build passed. The package build script’s rm -f cleanup step is unsupported in Windows Command Prompt.
  • Widget typecheck — passed.
  • Widget tests — 784 passed in the full run; two unrelated timeout failures passed when rerun individually.
  • pnpm size — passed; panel is 17.75 kB gzipped against the 18 kB limit.
  • git diff --check — passed.

AI assistance

OpenAI Codex assisted with implementation and verification. I reviewed the changes and test results.

@anurag629 anurag629 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @piyusshhjangid, this covers what #477 asks for, and the translations are a nice touch. With dev merged in: build, typecheck, lint (38, same as dev), api:check, docs:check, coverage and the 79 e2e tests in Chrome all pass. pnpm size fails, though:

  • panel 17.93 of 18 kB
  • single file 20.05 of 20 kB

#502 has merged since and adds 0.22 kB to both, so on dev now it's further over.

Two things:

  1. packages/widget/src/dom/messages.ts, readableText(): the tree walker after the innerText line only runs where innerText is missing. That's jsdom, not any browser the widget supports, so it's test-only code shipped to every page, and it's 0.21 kB of the panel (17.93 to 17.72 without it). Make the function return element.innerText.trim(); and give the tests an innerText. For example, in the test file's beforeEach:
    Object.defineProperty(HTMLElement.prototype, 'innerText', { configurable: true, get() { return this.textContent; } });
    Or stub it on the one element in the formatted-content test, which is closer to what a browser returns.
  2. The budget itself: even trimmed, this plus #502 puts the single file just over 20 kB. That's on me, not you. I'm opening a PR now to make room in the panel and the single file. Once it's merged, update your branch from dev, and pnpm size should pass with (1) done.

@anurag629

Copy link
Copy Markdown
Member

@piyusshhjangid the budgets have room now (#508: panel 19 kB, single file 22 kB). Update your branch from dev after the readableText() change and pnpm size should pass.

@anurag629 anurag629 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @piyusshhjangid, the innerText change is right, and the copy works end to end. I checked it in Chrome against the e2e server with real clipboard access: Copy puts the reply's text on the clipboard and announces "Reply copied.". With dev merged in:

  • build, typecheck, api:check, docs:check, coverage and all 85 e2e tests pass
  • pnpm size passes: panel 18.63 of 19 kB, single file 21.9 of 22 kB

One last thing. Lint is at 39, against 38 on dev, and the new warning is your test:

packages/widget/tests/dom/messages.test.ts:204, lint/style/noNonNullAssertion:

const content = parent.querySelector<HTMLElement>('[data-id="copy-1"] .cc-message-content')!;

Drop the ! and check it instead, for example if (!content) throw new Error('no reply content');. Then pnpm lint says 38 and I'll merge.

anurag629 added a commit that referenced this pull request Oct 31, 2026
…file budget (#523)

theme.tokens takes surface-raised (the header menu's background). The single-file budget goes to 23 kB for copy (#504); loader and panel unchanged.
@anurag629

Copy link
Copy Markdown
Member

@piyusshhjangid also: dev now has #521, which pushed the single file closer to its limit, so I raised it to 23 kB in #523. Update from dev with the lint fix and pnpm size will pass.

@anurag629 anurag629 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @piyusshhjangid. Lint is at 38. With dev merged in, everything passes, including all 85 e2e tests. Sizes are fine: panel 18.79 of 19 kB, single file 22.05 of 23 kB.

@anurag629
anurag629 merged commit 065662a into codercops:dev Oct 31, 2026
@github-actions github-actions Bot added codercops-accepted Merged PR that counts on the monthly leaderboard (oss.codercops.com) hacktoberfest-accepted PR counts for Hacktoberfest labels Oct 31, 2026
@anurag629

Copy link
Copy Markdown
Member

Merged, thanks @piyusshhjangid. With #477 done you have a free slot, so #525 is yours once #524 is in.

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

Labels

codercops-accepted Merged PR that counts on the monthly leaderboard (oss.codercops.com) hacktoberfest-accepted PR counts for Hacktoberfest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Widget: copy a completed assistant reply

2 participants