Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

fix: add clean response copying to native desktop

yxlyxf657296b2063
diff --git a/apps/native/app/visual-tests/turn-fixture.tsx b/apps/native/app/visual-tests/turn-fixture.tsx
index e8ca9518..e61b7254 100644
--- a/apps/native/app/visual-tests/turn-fixture.tsx
+++ b/apps/native/app/visual-tests/turn-fixture.tsx
@@ -12,6 +12,7 @@ function fixture(name: typeof cases[number]): AssistantTurn {
if (["running", "waiting", "missing-result", "error"].includes(name)) turn.tools = [{ id: "fixture-tool", name: "Check palette", icon: "run", chip: "palette.json", status: name === "waiting" ? "ok" : "running", detail: [{ text: "Scripted tool output" }], atChars: 0, startedAt: now - 5000 }];
if (name === "waiting") turn.lastUpdateAt = now - 25000;
if (name === "partial-error" || name === "done" || name === "stopped") {
+ turn.reasoning = "Check the layout and keyboard shortcuts before answering.";
turn.text = "The preview is ready. The updated layout and keyboard shortcut checks passed.";
turn.tools = [
{ id: "write", name: "Update layout", chip: "layout.tsx", icon: "write", status: "ok", detail: [{ text: "Layout updated." }], atChars: 0 },
diff --git a/apps/native/components/site/ChatBubbles.tsx b/apps/native/components/site/ChatBubbles.tsx
index fc88a87d..e3a3070e 100644
--- a/apps/native/components/site/ChatBubbles.tsx
+++ b/apps/native/components/site/ChatBubbles.tsx
@@ -7,6 +7,7 @@ import ThinkingState from "@/components/primitives/ThinkingState";
import ToolChips, { type LiveDiff } from "@/components/primitives/ToolChips";
import ApprovalCard from "@/components/primitives/ApprovalCard";
import TurnActivity from "./TurnActivity";
+import CopyResponse from "./CopyResponse";
import HtmlArtifact from "./HtmlArtifact";
import McpAppResult from "./McpAppResult";
import SnapshotView from "./SnapshotView";
@@ -223,6 +224,7 @@ export const AssistantBody = memo(function AssistantBody({
/>
</div>
)}
+ <CopyResponse text={turn.text} />
{!snapshot && <TurnActivity turn={turn} onRetry={turn.status === "error" ? onRetry : undefined} promptIndex={promptIndex} retryDisabled={retryDisabled} />}
{turn.recap && turn.status === "done" && (
<p className="mt-3 text-[12px] text-ink-3">{turn.recap}</p>
diff --git a/apps/native/components/site/CopyResponse.tsx b/apps/native/components/site/CopyResponse.tsx
new file mode 100644
index 00000000..9b18453c
--- /dev/null
+++ b/apps/native/components/site/CopyResponse.tsx
@@ -0,0 +1,30 @@
+"use client";
+import { useEffect, useRef, useState } from "react";
+
+/** Copy the response model, never the transcript DOM (which includes tools and thoughts). */
+export default function CopyResponse({ text }: { text: string }) {
+ const [state, setState] = useState<"idle" | "copied" | "error">("idle");
+ const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
+ useEffect(() => () => clearTimeout(timer.current), []);
+ const copy = async () => {
+ clearTimeout(timer.current);
+ try {
+ await navigator.clipboard.writeText(text);
+ setState("copied");
+ timer.current = setTimeout(() => setState("idle"), 1500);
+ } catch {
+ setState("error");
+ }
+ };
+ if (!text.trim()) return null;
+ return <div className="mt-3 flex items-center gap-2">
+ <button type="button" data-copy-response aria-label="Copy response" onClick={copy}
+ className="flex h-7 items-center gap-1.5 rounded-full px-2 text-[12px] text-ink-3 transition-colors hover:bg-hover hover:text-ink focus-visible:outline-2 focus-visible:outline-accent">
+ <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
+ {state === "copied" ? <path d="m5 12 4 4L19 6" /> : <><rect x="8" y="8" width="12" height="12" rx="2" /><path d="M16 8V4a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h4" /></>}
+ </svg>
+ {state === "copied" ? "Copied" : "Copy response"}
+ </button>
+ <span role="status" className="text-[12px] text-ink-3">{state === "error" ? "Could not copy. Try again." : state === "copied" ? "Response copied" : ""}</span>
+ </div>;
+}
diff --git a/apps/native/electron/copy-response-visual.cjs b/apps/native/electron/copy-response-visual.cjs
new file mode 100644
index 00000000..8b024a7f
--- /dev/null
+++ b/apps/native/electron/copy-response-visual.cjs
@@ -0,0 +1,33 @@
+const assert = require('node:assert/strict');
+
+exports.testCopyResponse = async function ({ win }) {
+ const js = code => win.webContents.executeJavaScript(code);
+ const wait = async condition => {
+ for (let i = 0; i < 100; i++) {
+ if (await js(condition)) return;
+ await new Promise(resolve => setTimeout(resolve, 30));
+ }
+ throw Error(`Copy response did not settle: ${condition}`);
+ };
+ // Keep the user's clipboard untouched while exercising the real click handler.
+ await js(`Object.defineProperty(navigator, 'clipboard', { configurable: true, value: {
+ writeText: async text => { if (window.copyFails) throw Error('Denied'); window.copiedResponse = text; }
+ } })`);
+ await js(`document.querySelector('[data-case="done"]').click()`);
+ await wait(`!!document.querySelector('[data-copy-response]')`);
+ await js(`document.querySelector('[data-copy-response]').click()`);
+ await wait(`document.querySelector('[data-copy-response]').textContent.includes('Copied')`);
+ assert.equal(await js(`window.copiedResponse`), 'The preview is ready. The updated layout and keyboard shortcut checks passed.');
+ assert.equal(await js(`document.querySelector('[data-copy-response]').getBoundingClientRect().height > 0`), true);
+ await js(`window.copyFails = true; document.querySelector('[data-copy-response]').click()`);
+ await wait(`document.querySelector('article').textContent.includes('Could not copy. Try again.')`);
+ await js(`window.copyFails = false; document.querySelector('[data-copy-response]').click()`);
+ await wait(`!document.querySelector('article').textContent.includes('Could not copy. Try again.')`);
+ await js(`document.querySelector('[data-case="writing"]').click()`);
+ await wait(`document.querySelector('article').getAttribute('data-turn-status') === 'streaming'`);
+ await js(`document.querySelector('[data-copy-response]').click()`);
+ await wait(`window.copiedResponse === 'Preparing a theme preview with readable text and a distinct accent.'`);
+ await js(`document.querySelector('[data-case="thinking"]').click()`);
+ await wait(`!document.querySelector('[data-copy-response]')`);
+ console.log('PASS native response copy: exact text, visible control, streaming, empty, failure and retry');
+};
diff --git a/apps/native/electron/visual-tests.cjs b/apps/native/electron/visual-tests.cjs
index 472500f8..6523882e 100644
--- a/apps/native/electron/visual-tests.cjs
+++ b/apps/native/electron/visual-tests.cjs
@@ -132,6 +132,8 @@ app.whenReady().then(async () => {
}
}
if (process.env.GRAFF_VISUAL_SUITE === 'turns') {
+ await require('./copy-response-visual.cjs').testCopyResponse({ win });
+ results.push('copy response');
assert.deepEqual(apiRequests, []);
fs.writeFileSync(path.join(output, 'results.json'), JSON.stringify({ passed: results, apiRequests }, null, 2));
return;