Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
31s copy-says-if-it-failed: Copy says "Couldn't copy" when the clipboard refused (#937)
Oleksandr Ivanchenko4442111002ee
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bac0f29e..f8739e0f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).## Unreleased+### Fixed+- Copy now says when it couldn't copy, instead of always saying Copied. The Copy on a code block and under a reply show "Couldn't copy" for 2 seconds when the browser blocks the clipboard (for example on a plain http address), and the code block's Copy is easier to click on a wide screen (#937)+## [Mac 0.9.34] - 2026-11-21kwant 0.9.34: long code blocks and logs that fold to 16 lines with a "Show all" button, files a bot shares that show a preview again, line charts whose last date label no longer overlaps the one before it, a sidebar that no longer shifts when you open Inbox, wide tables that fade at the edge while there is more to scroll, a composer whose New tag no longer sits on the chat and key numbers that show as tiles instead of one long line.diff --git a/frontend/src/components/ChatView.tsx b/frontend/src/components/ChatView.tsxindex 4fb2331b..cc71564b 100644--- a/frontend/src/components/ChatView.tsx+++ b/frontend/src/components/ChatView.tsx@@ -93,6 +93,7 @@ import { APPROVE_TEXT, approveRowId, changePlaceholder, refocusAfterApprove } frimport { DoneCheckLine } from './DoneMarker';import { ApproveRow } from './ApproveRow';import { CopyGhost } from './CopyGhost';+import { copyText } from '../copyText';import { ContinuedLine, MessageMore, MessageMoreError } from './MessageMore';import { CONTINUE_LABEL, canContinueFrom } from '../continueChat';import { RoutineRow } from './RoutineRow';@@ -780,7 +781,7 @@ export const ChatView: React.FC<ChatViewProps> = ({return () => clearTimeout(t);}, [dropAnnounce]);const [openThoughts, setOpenThoughts] = useState<Record<string, boolean>>({});- const [copiedId, setCopiedId] = useState<string | null>(null);+ const [copiedId, setCopiedId] = useState<{ id: string; ok: boolean } | null>(null);const scrollRef = useRef<HTMLDivElement>(null);const textareaRef = useRef<HTMLTextAreaElement>(null);// Dictation (design.md): the mic between @ and Send; one line at the top of the box says what's happening.@@ -1369,10 +1370,10 @@ export const ChatView: React.FC<ChatViewProps> = ({setOpenThoughts((prev) => ({ ...prev, [id]: !prev[id] }));};- const handleCopy = (text: string, id: string) => {- navigator.clipboard.writeText(text);- setCopiedId(id);- playSfx('click');+ const handleCopy = async (text: string, id: string) => {+ const ok = await copyText(text);+ setCopiedId({ id, ok });+ if (ok) playSfx('click');setTimeout(() => setCopiedId(null), 2000);};@@ -2162,7 +2163,7 @@ export const ChatView: React.FC<ChatViewProps> = ({)}</>)}- <CopyGhost copied={copiedId === msg.id} tipId={`copy-tip-${msg.id}`} onCopy={() => handleCopy(text, msg.id)} />+ <CopyGhost copied={copiedId?.id === msg.id ? (copiedId.ok ? 'ok' : 'failed') : null} tipId={`copy-tip-${msg.id}`} onCopy={() => handleCopy(text, msg.id)} />{continueMenu(msg, `${displayName}'s reply`, 'start')}{!phone && msg.results != null && <SmartActionsSlot messageId={msg.id} />}</div>diff --git a/frontend/src/components/CopyGhost.tsx b/frontend/src/components/CopyGhost.tsxindex 4fee133d..ebee0d9a 100644--- a/frontend/src/components/CopyGhost.tsx+++ b/frontend/src/components/CopyGhost.tsx@@ -1,11 +1,11 @@// reply-chrome part 3 (autonomy/reply-chrome/design.md): Copy as a quiet icon, after Reply and the thumbs, with// its label in a tooltip on hover (not on touch) and on keyboard focus. Copied shows a check and "Copied" for the-// parent's copied window, announced once.+// parent's copied window, announced once. When the clipboard refused, "Couldn't copy" shows and is announced instead.import React from 'react';import { Check, Copy } from 'lucide-react';-export const CopyGhost: React.FC<{ copied: boolean; tipId: string; onCopy: () => void }> = ({ copied, tipId, onCopy }) => (+export const CopyGhost: React.FC<{ copied: 'ok' | 'failed' | null; tipId: string; onCopy: () => void }> = ({ copied, tipId, onCopy }) => (<span className="relative inline-flex shrink-0" data-copy-ghost=""><buttontype="button"@@ -15,7 +15,11 @@ export const CopyGhost: React.FC<{ copied: boolean; tipId: string; onCopy: () =>data-copy-reply=""className="peer relative inline-flex h-11 w-11 sm:h-8 sm:w-8 items-center justify-center rounded-lg text-zinc-400 hover:bg-zinc-800 hover:text-zinc-100 transition-colors duration-[120ms] motion-reduce:transition-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sky-400 cursor-pointer">- {copied ? <Check size={14} className="text-ok" aria-hidden="true" /> : <Copy size={14} aria-hidden="true" />}+ {copied === 'ok' ? (+ <Check size={14} className="text-ok" aria-hidden="true" />+ ) : (+ <Copy size={14} className={copied === 'failed' ? 'text-bad' : undefined} aria-hidden="true" />+ )}</button><spanid={tipId}@@ -24,10 +28,10 @@ export const CopyGhost: React.FC<{ copied: boolean; tipId: string; onCopy: () =>copied ? 'opacity-100' : 'opacity-0'}`}>- {copied ? 'Copied' : 'Copy reply'}+ {copied === 'ok' ? 'Copied' : copied === 'failed' ? 'Couldn’t copy' : 'Copy reply'}</span><span className="sr-only" aria-live="polite">- {copied ? 'Copied' : ''}+ {copied === 'ok' ? 'Copied' : copied === 'failed' ? 'Couldn’t copy' : ''}</span></span>);diff --git a/frontend/src/components/GetStarted.tsx b/frontend/src/components/GetStarted.tsxindex cd4c5984..3bbc82bf 100644--- a/frontend/src/components/GetStarted.tsx+++ b/frontend/src/components/GetStarted.tsx@@ -60,6 +60,7 @@ import {import { type StepTeam, type TeamStepView, teamDoneValue, teamStepView } from '../firstScreen';import { type InstallTrack, forgetInstall, installDetails, startInstall, useInstallTrack, useStartVersion } from '../gettingStartedInstall';import { useFocusAfterRender } from '../focusAfterRender';+import { copyText } from '../copyText';const FOCUS = 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-400';const SLOW_S = 40;@@ -78,14 +79,6 @@ export function hostOf(w: { location?: { hostname?: string } } | undefined = typ}const isMac = () => typeof navigator !== 'undefined' && /Mac/i.test(navigator.platform || navigator.userAgent || '');-async function copyText(text: string): Promise<boolean> {- try {- await navigator.clipboard.writeText(text);- return true;- } catch {- return false;- }-}/** Counts seconds since `from` while `on`; the number is only shown, never announced. */function useSeconds(from: number | null, on: boolean) {diff --git a/frontend/src/components/MarkdownRenderer.tsx b/frontend/src/components/MarkdownRenderer.tsxindex 13bc830f..0c17ddc9 100644--- a/frontend/src/components/MarkdownRenderer.tsx+++ b/frontend/src/components/MarkdownRenderer.tsx@@ -10,6 +10,7 @@ import { ReplyText } from './results/ReplyText';import { inlineCodeClass, linkClass } from './markdownInline';import { DOC_SCHEME } from '../spaceDocs';import { DocQuoteChip } from './DocQuoteChip';+import { copyText } from '../copyText';import { ScrollTable } from './ScrollTable';/** react-markdown drops unknown schemes; a space document's address is kept for its quote chip. */@@ -38,10 +39,13 @@ const CodeBlock: React.FC<CodeBlockProps> = ({ language, value }) => {toggleRef.current?.scrollIntoView?.({ block: 'nearest' });}, [open]);- const handleCopy = () => {- navigator.clipboard.writeText(value);+ // 31s: "copied" is the 2 s result window; copyFailed says the clipboard refused (or there is none).+ const [copyFailed, setCopyFailed] = useState(false);+ const handleCopy = async () => {+ const ok = await copyText(value);+ setCopyFailed(!ok);setCopied(true);- playSfx('click');+ if (ok) playSfx('click');setTimeout(() => setCopied(false), 2000);};@@ -55,14 +59,19 @@ const CodeBlock: React.FC<CodeBlockProps> = ({ language, value }) => {<buttontype="button"onClick={handleCopy}- className="flex items-center gap-1 px-2 py-0.5 rounded text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800 transition-colors cursor-pointer"+ className="flex items-center gap-1 px-2 py-0.5 sm:py-1.5 sm:-my-1 rounded text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800 transition-colors cursor-pointer"title="Copy code">- {copied ? (+ {copied && !copyFailed ? (<><Check size={12} className="text-ok" /><span className="text-ok">Copied</span></>+ ) : copied ? (+ <>+ <Copy size={12} className="text-bad" />+ <span className="text-bad">Couldn’t copy</span>+ </>) : (<><Copy size={12} />@@ -70,6 +79,9 @@ const CodeBlock: React.FC<CodeBlockProps> = ({ language, value }) => {</>)}</button>+ <span className="sr-only" aria-live="polite">+ {copied ? (copyFailed ? 'Couldn’t copy' : 'Copied') : ''}+ </span></div><div className="relative"><pre className={`p-3.5 overflow-x-auto text-xs font-mono text-zinc-200 leading-relaxed${folded ? ' max-h-80 overflow-y-hidden' : ''}`}>diff --git a/frontend/src/copyText.ts b/frontend/src/copyText.tsnew file mode 100644index 00000000..53cb953d--- /dev/null+++ b/frontend/src/copyText.ts@@ -0,0 +1,12 @@+/** Puts text on the clipboard. True only when the browser says it did; false when it refused (an insecure+ * origin, a denied permission) or has no clipboard at all. Callers say "Copied" or "Couldn't copy" from this. */+export async function copyText(text: string): Promise<boolean> {+ const clip = typeof navigator !== 'undefined' ? navigator.clipboard : undefined;+ if (!clip || typeof clip.writeText !== 'function') return false;+ try {+ await clip.writeText(text);+ return true;+ } catch {+ return false;+ }+}diff --git a/frontend/tests/copyFails.test.mjs b/frontend/tests/copyFails.test.mjsnew file mode 100644index 00000000..2ab646c4--- /dev/null+++ b/frontend/tests/copyFails.test.mjs@@ -0,0 +1,131 @@+// 31s copy-says-if-it-failed: the code-block Copy and the reply Copy wait for the clipboard. "Copied" only when it+// took the text; "Couldn't copy" (same 2 s, same spot, same polite live line) when it refused or there is none.+import assert from 'node:assert/strict';+import test from 'node:test';+import { readFileSync } from 'node:fs';+import { JSDOM } from 'jsdom';+import { loadBundled } from './bundle.mjs';++const dom = new JSDOM('<!doctype html><html><body></body></html>', { url: 'http://192.168.1.20:8787/', pretendToBeVisual: true });+const g = globalThis;+for (const k of ['window', 'document', 'navigator', 'HTMLElement', 'Element', 'Node', 'Event', 'MouseEvent', 'requestAnimationFrame', 'cancelAnimationFrame', 'getComputedStyle', 'localStorage', 'sessionStorage']) {+ if (!(k in dom.window)) continue;+ Object.defineProperty(g, k, { value: dom.window[k], configurable: true, writable: true });+}+g.IS_REACT_ACT_ENVIRONMENT = false;++const copied = [];+const clipboards = {+ works: { writeText: async (t) => void copied.push(t) },+ refuses: { writeText: async () => { throw new DOMException('Write permission denied.', 'NotAllowedError'); } },+ missing: undefined,+};+const useClipboard = (kind) =>+ Object.defineProperty(dom.window.navigator, 'clipboard', { value: clipboards[kind], configurable: true });++const m = await loadBundled(`+ export { default as React } from 'react';+ export { createRoot } from 'react-dom/client';+ export { flushSync } from 'react-dom';+ export { MarkdownRenderer } from './src/components/MarkdownRenderer';+ export { CopyGhost } from './src/components/CopyGhost';+ export { copyText } from './src/copyText';+`);+const { React, createRoot, flushSync, MarkdownRenderer, CopyGhost, copyText } = m;+const h = React.createElement;+const tick = () => new Promise((r) => setTimeout(r, 0));++const draw = (el) => {+ const box = document.createElement('div');+ document.body.appendChild(box);+ const root = createRoot(box);+ flushSync(() => root.render(el));+ return { box, done: () => { root.unmount(); box.remove(); } };+};+const click = (b) => b.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));+const codeCopy = (box) => box.querySelector('button[title="Copy code"]');+const live = (box) => box.querySelector('[aria-live="polite"]');++test('copyText: true when the clipboard takes the text, false when it refuses or is missing', async () => {+ useClipboard('works');+ assert.equal(await copyText('a'), true);+ assert.equal(copied.at(-1), 'a');+ useClipboard('refuses');+ assert.equal(await copyText('b'), false);+ useClipboard('missing');+ assert.equal(await copyText('c'), false);+});++const fence = 'Run this:\n\n```bash\nnpm test\n```\n';++for (const [kind, word, cls] of [+ ['works', 'Copied', 'text-ok'],+ ['refuses', 'Couldn’t copy', 'text-bad'],+ ['missing', 'Couldn’t copy', 'text-bad'],+]) {+ test(`code-block Copy, clipboard ${kind}: says "${word}" and announces it, then back to Copy after 2 s`, async () => {+ useClipboard(kind);+ const { box, done } = draw(h(MarkdownRenderer, { content: fence }));+ try {+ const btn = codeCopy(box);+ assert.equal(btn.textContent.trim(), 'Copy');+ assert.equal(live(box).textContent, '', 'nothing announced before a click');+ const realTimeout = g.setTimeout;+ const timers = [];+ g.setTimeout = (fn, ms) => (ms === 2000 ? timers.push(fn) : realTimeout(fn, ms));+ try {+ click(btn);+ await tick();+ await tick();+ } finally {+ g.setTimeout = realTimeout;+ }+ assert.equal(btn.textContent.trim(), word);+ assert.ok(btn.querySelector(`span.${cls}`), `${word} uses ${cls}`);+ assert.equal(live(box).textContent, word, 'the polite live line says it once');+ assert.ok(!btn.contains(live(box)), 'the live line is outside the button, so its name stays one word');+ if (kind === 'works') assert.equal(copied.at(-1), 'npm test');+ assert.equal(timers.length, 1, 'one 2 s timer');+ flushSync(() => timers[0]());+ assert.equal(btn.textContent.trim(), 'Copy');+ assert.equal(live(box).textContent, '');+ } finally {+ done();+ }+ });+}++test('code-block Copy: 28 px or more on desktop by padding only (py-1.5 with -my-1 keeps the header row), phone unchanged', () => {+ useClipboard('works');+ const { box, done } = draw(h(MarkdownRenderer, { content: fence }));+ try {+ const c = codeCopy(box).className.split(/\s+/);+ for (const k of ['py-0.5', 'sm:py-1.5', 'sm:-my-1']) assert.ok(c.includes(k), k);+ assert.ok(!c.some((k) => /^(h|min-h)-/.test(k)), 'no fixed height');+ } finally {+ done();+ }+});++test('reply Copy (CopyGhost): Copied, Couldn’t copy, idle', () => {+ const at = (copied) => {+ const { box, done } = draw(h(CopyGhost, { copied, tipId: 'tip', onCopy() {} }));+ const out = { tip: box.querySelector('[role="tooltip"]').textContent, live: live(box).textContent, ok: !!box.querySelector('.text-ok'), bad: !!box.querySelector('.text-bad'), name: box.querySelector('button').getAttribute('aria-label') };+ done();+ return out;+ };+ assert.deepEqual(at('ok'), { tip: 'Copied', live: 'Copied', ok: true, bad: false, name: 'Copy reply' });+ assert.deepEqual(at('failed'), { tip: 'Couldn’t copy', live: 'Couldn’t copy', ok: false, bad: true, name: 'Copy reply' });+ assert.deepEqual(at(null), { tip: 'Copy reply', live: '', ok: false, bad: false, name: 'Copy reply' });+});++test('ChatView: the reply Copy waits for copyText and passes ok or failed to CopyGhost; sound only on success', () => {+ const src = readFileSync(new URL('../src/components/ChatView.tsx', import.meta.url), 'utf8');+ const fn = src.slice(src.indexOf('const handleCopy = async (text: string, id: string)'), src.indexOf('const patchUpload'));+ assert.match(fn, /const ok = await copyText\(text\);/);+ assert.match(fn, /setCopiedId\(\{ id, ok \}\);/);+ assert.match(fn, /if \(ok\) playSfx\('click'\);/);+ assert.match(fn, /setTimeout\(\(\) => setCopiedId\(null\), 2000\);/);+ assert.doesNotMatch(fn, /navigator\.clipboard/);+ assert.match(src, /<CopyGhost copied=\{copiedId\?\.id === msg\.id \? \(copiedId\.ok \? 'ok' : 'failed'\) : null\}/);+});diff --git a/frontend/tests/replyChrome.test.mjs b/frontend/tests/replyChrome.test.mjsindex 6f752b8b..07729a30 100644--- a/frontend/tests/replyChrome.test.mjs+++ b/frontend/tests/replyChrome.test.mjs@@ -186,7 +186,7 @@ test('approval words', () => {// ---- 3. Copy ----test('CopyGhost: an icon button named "Copy reply" with a tooltip, no border, 44 px on phone', () => {- const h = ui.html(ui.CopyGhost, { copied: false, tipId: 't1', onCopy() {} });+ const h = ui.html(ui.CopyGhost, { copied: null, tipId: 't1', onCopy() {} });assert.match(h, /aria-label="Copy reply"/);assert.match(h, /aria-describedby="t1"/);assert.match(h, /id="t1" role="tooltip"/);@@ -195,10 +195,16 @@ test('CopyGhost: an icon button named "Copy reply" with a tooltip, no border, 44assert.doesNotMatch(h, /title=/);assert.doesNotMatch(h, /Copy markdown/);assert.match(h, /\[@media\(hover:hover\)\]:peer-hover:opacity-100 peer-focus-visible:opacity-100/);- const done = ui.html(ui.CopyGhost, { copied: true, tipId: 't1', onCopy() {} });+ const done = ui.html(ui.CopyGhost, { copied: 'ok', tipId: 't1', onCopy() {} });assert.match(done, /text-ok/);assert.match(done, /role="tooltip"[^>]*class="[^"]*opacity-100[^"]*">Copied</);assert.match(done, /aria-live="polite">Copied</);+ // 31s: the clipboard refused: the same tooltip and live line say "Couldn't copy", no check.+ const failed = ui.html(ui.CopyGhost, { copied: 'failed', tipId: 't1', onCopy() {} });+ assert.doesNotMatch(failed, /text-ok/);+ assert.match(failed, /text-bad/);+ assert.match(failed, /role="tooltip"[^>]*class="[^"]*opacity-100[^"]*">Couldn’t copy</);+ assert.match(failed, /aria-live="polite">Couldn’t copy</);});test('ChatView: the action row is Reply, thumbs, Copy, then smart actions', () => {