Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(web): copy chat and terminal selections automatically, Herdr-style #9409

ClosedSotoAugusto(GitHub profile, opens in a new tab)wants to merge 6 commits intomain fromrefs/pull/9409/headopened View on GitHub

What Changed

Adds opt-in, Herdr-style copy-on-select for the web and desktop clients. When Settings → General → Copy on select is enabled, completing a fresh mouse selection in chat or the integrated terminal writes that selection to the clipboard. Copy on select toast independently controls the success confirmation.

  • The master setting remains off by default; the toast setting defaults on and is only shown while copy-on-select is enabled.
  • Chat ignores collapsed, unchanged, multi-range, modifier-key, editable, and explicitly opted-out selections. A range is rejected when any part of it crosses an input, textarea, select, editable content, or data-no-copy-on-select subtree, even if both endpoints are ordinary text.
  • Links, buttons, and contenteditable="false" citation chips remain selectable.
  • Terminal copying uses the browser Clipboard API directly. It does not prime, focus, select, or mutate Ghostty's hidden input, so failed clipboard writes leave terminal input and in-progress IME composition unchanged.
  • Clipboard failures remain silent, same-text writes are deduplicated, failed writes can be retried, and double/triple clicks coalesce into one copy.

Why

Herdr copies mouse selections automatically. T3 Code previously required an explicit copy action. This adds the same fast workflow without changing behavior for existing users who do not opt in.

Relationship to #9091

#9091 proposed terminal-only auto-copy. This PR supersedes it with chat and terminal coverage, an opt-out, optional success feedback, stale-selection guards, and a Clipboard API path that avoids hidden terminal-input mutation. Credit to @jonathanmeier5 for the original proposal and implementation direction.

Surfaces Checklist

  • Entry points: chat timeline and terminal selection gestures; searchable Settings → General controls; restore-defaults wiring.
  • Clients: web and desktop. Mobile keeps native long-press selection behavior.
  • Providers: not provider-shaped; all adapters are unaffected.
  • Contracts: backward-compatible ClientSettingsSchema and patch defaults.
  • Connection modes: local, remote, relay, and tunnel share the same client behavior; unavailable clipboard access produces no false toast.
  • Docs: Terminal user guide.

Verification

  • vp test run apps/web/src/lib/copyOnSelect.test.ts apps/web/src/components/ThreadTerminalDrawer.test.ts apps/web/src/hooks/useCopyToClipboard.test.ts packages/contracts/src/settings.test.ts apps/desktop/src/settings/DesktopClientSettings.test.ts — 117 tests passed.
  • Targeted lint on the four changed TypeScript files — no new warnings.
  • Targeted typechecks for @t3tools/web, @t3tools/contracts, and @t3tools/desktop — passed.
  • Merge-tree against origin/main at 9e1fb459a — clean.
  • Integrated browser pass in an isolated T3 environment:
    • default-off and dependent-setting visibility;
    • chat copy with toast on and off;
    • plain click over an existing selection leaves a clipboard sentinel unchanged;
    • real DOM range crossing an interior textarea leaves the clipboard unchanged;
    • real Ghostty canvas selection copies terminal-copy-check;
    • failed Clipboard API unit path preserves a sentinel terminal input/selection and emits no toast.

Evidence

Default (off)Enabled
Copy on select disabled by defaultCopy on select enabled with its toast option

The clip covers chat selection, the plain-click no-op, toggling toast feedback off, and terminal selection:

Watch the 20-second interaction demo. Review-only assets are hosted in the fork evidence release and are not committed to this branch.

Built with GPT-5.6 Sol in Codex via the T3 Code harness.


Note

Low Risk Opt-in client-local clipboard behavior with extensive gesture guards and tests; default-off preserves existing workflows, with main risk being unexpected clipboard writes for users who enable the setting.

Overview Adds opt-in copy-on-select for web/desktop: new client settings copyOnSelect (default off) and copyOnSelectToast (default on, shown only when copy-on-select is enabled), wired through contracts, desktop settings tests, General settings UI/search, and restore-defaults.

Chat uses a new useCopyOnSelect hook on the message timeline: on mouse release after a fresh left-drag or settled multi-click, eligible selections copy via the clipboard API, with guards for unchanged selections, modifiers, editables, and opted-out subtrees. Terminal auto-copies on selection release via createTerminalSelectionAutoCopy, sharing normalization/dedup logic in copyOnSelect.ts; explicit Copy still toasts and records the selection so auto-copy does not immediately repeat.

Clipboard writes stay silent on failure; success toasts only after a confirmed write. Terminal copying does not touch Ghostty’s hidden input. Docs rename/extend the terminal user guide for the new behavior.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 8b9c050a74a529f54cde7d92598d568ff41e3d02. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add automatic copy-on-select for chat timeline and terminal selections

  • Adds copyOnSelect and copyOnSelectToast client settings with defaults of disabled and enabled respectively, wired into settings.ts and the desktop settings fixture
  • Introduces useCopyOnSelect.ts to auto-copy qualifying single-range mouse selections in the chat timeline on release, deferring multi-click sequences and ignoring editable/modifier/non-primary gestures
  • Adds terminal auto-copy coordination in copyOnSelect.ts that de-duplicates pending and repeated writes, normalizes terminal line endings, retries after failure, and toasts only on successful writes when enabled
  • Integrates both paths into ThreadTerminalDrawer.tsx and MessagesTimeline.tsx, and adds settings UI toggles plus search entries in SettingsPanels.tsx
  • Behavioral Change: terminal and chat selections are now copied automatically when the new copyOnSelect setting is enabled; existing selection-menu and citation-toolbar flows are unchanged when it is disabled
Macroscope summarized 8b9c050.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

      There are 4 total unresolved issues (including 2 from previous reviews).

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit c06bbfec855017a085db56eec53b18db6fddc9a7. Configure [here](https://www.cursor.com/dashboard/bugbot).
    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR introduces a substantial new clipboard capability spanning chat, terminal, shared settings, and asynchronous gesture handling. It also adds product defaults for the new settings, so the change requires human review despite being opt-in.

      Notes:

      • Diff unchanged. Approvability was decided on eligibility alone.
      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Reviewers + bots: requesting a fresh look — HEAD (73c2a5f98) postdates all existing reviews (latest ran against c06bbfec8). What's changed since:

      d481fcb52 — unblocks chips, coalesces multi-click

      • COPY_ON_SELECT_EDITABLE_SELECTOR now enumerates editable contenteditable values only ("", true, plaintext-only), so contenteditable="false" islands (AssistantCitationChip) stay selectable; genuinely editable regions still excluded.
      • Multi-click releases (detail >= 2) defer by SELECTION_MULTI_CLICK_INTERVAL_MS with supersede on the next press, so a triple-click copies the paragraph once (mirrors the terminal path).

      73c2a5f98 — opt-in instead of default-on

      • copyOnSelect now defaults to false; the toast still defaults on for when enabled. This addresses the approbability concern about imposing automatic clipboard writes as a product default — existing users see zero behavior change until they enable Settings → General → Copy on select.

      On the 2 still-open Cursor threads (both filed against older revisions, carried forward unverified in the c06bbfec8 review):

      • Interactive selections never auto-copy — addressed in c06bbfec8: the selector was split to editable-only and the mouseup-target guard removed (clicks without a drag are filtered by gesture-identity comparison). See apps/web/src/lib/copyOnSelect.ts:17-40.
      • Chat copy ignores outside release — addressed in c06bbfec8: listeners moved to the window with container-gated arming. See `apps/web/src/hooks/useCopyOnSelect.ts:52-122".

      Also noting: no test/typecheck/lint workflows have reported on this fork PR yet (merge state BLOCKED on missing checks), so CI verification is still pending. Unit tests for the selection guards (copyOnSelect.test.ts, 15 tests) pass locally; repo suites need CI.

    5. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium lib/copyOnSelect.ts:80

      A selection that starts and ends in ordinary chat text but crosses a data-no-copy-on-select or editable subtree is returned and copied, so opted-out content reaches the clipboard. The function only checks the range endpoints; inspect the full range contents before returning text.

      -  if (nodeInEditable(range.startContainer) || nodeInEditable(range.endContainer)) return null;
      +  if (nodeInEditable(range.startContainer) || nodeInEditable(range.endContainer)) return null;
      +  if (range.cloneContents().querySelector(COPY_ON_SELECT_EDITABLE_SELECTOR) !== null) return null;
      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/web/src/lib/copyOnSelect.ts around line 80:
      
      A selection that starts and ends in ordinary chat text but crosses a `data-no-copy-on-select` or editable subtree is returned and copied, so opted-out content reaches the clipboard. The function only checks the range endpoints; inspect the full range contents before returning `text`.
    6. Note

      🤖 GPT-6 Astra (preview) responding on behalf of Theo

      This note is part of an automated cleanup pass.

      The original terminal copy-on-select proposal is #9091 at eb0e487. Keep that contribution linked as review continues here. Its implementation also exposes a useful failure case: priming the hidden terminal input before execCommand can leave copied text in the IME buffer when copying fails. Keep automatic clipboard writes separate from terminal input state, and verify that a copy failure leaves the user's terminal input unchanged. This is credit and test guidance, not a claim that the old helper was ported.

    7. Fixed in 6026538a7 by checking the cloned full Range for every excluded selector before copying. Added the ordinary-endpoints/interior-exclusion regression and verified the same case with a real DOM Range in the integrated browser pass.

    8. Sorry, I'm unable to act on this request because you do not have permissions within this repository.

    9. Contributor-side merge work is complete on 6026538a7:

      • rebased onto current main (13427ecd8) with a clean merge-tree;
      • fixed the full-range editable/opt-out boundary defect and resolved all three remaining review threads;
      • separated terminal auto-copy from Ghostty's hidden input and covered rejected Clipboard API writes, IME/input preservation, retry, pending deduplication, and manual-copy parity;
      • added user docs plus before/after screenshots and a 20-second interaction clip to the PR body;
      • 117 focused tests and the web/contracts/desktop typechecks pass locally.

      Cursor and Macroscope are running again on the latest head. Ready for a fresh maintainer review once those checks settle.

    10. main advanced again immediately after the prior update with the documentation restructures in #9755/#9756. I rebased onto 9e1fb459a; the only conflict was the docs index, resolved by keeping the new index structure and renaming its existing Terminal link to match the expanded guide.

      Latest head is 8b9c050a7. The merge-tree is clean, and the same 117 focused tests plus web/contracts/desktop typechecks pass after the rebase.

    11. juliusmarminge added labelsmacroscope-review

    12. Note

      Written by claude-opus-5-5 on behalf of Maria

      Hi! We are cleaning up open PRs, and this one appears to have been created with an older model (gpt-5.6-sol). If this change is really important, we recommend rebuilding the PR with a newer model if possible.

    13. maria-rcks closed this

Sign in to join this conversation.