@@ -98,7 +98,7 @@ import {
9898 OFFER_SKIP_TTL_MS ,
9999 type EngineOffer ,
100100} from "@/altimate/workspace/engine-offer"
101- import { useClipboard } from "@opencode-ai/tui/context/clipboard"
101+ import { useClipboard , type ClipboardService } from "@opencode-ai/tui/context/clipboard"
102102import { AltimateApi } from "@/altimate/api/client"
103103import { Log } from "@/altimate/util/log"
104104
@@ -1906,21 +1906,12 @@ function EngineInstallOfferDialog(props: EngineOfferProps) {
19061906 const copyCommand = ( ) => {
19071907 const cmd = command ( )
19081908 void ( async ( ) => {
1909- try {
1910- await clipboard . write ?.( cmd )
1911- // A resolved write is NOT proof of a copy. The host's writer picks
1912- // xclip/xsel on Linux and otherwise falls back to clipboardy, and it
1913- // swallows backend failures (`.catch(() => undefined)`), so on the many
1914- // Linux/WSL boxes with neither tool installed the write silently does
1915- // nothing. Read back and compare before claiming success. (Caught by
1916- // E2E: the toast said "Copied:" while the clipboard was untouched.)
1917- const back = await clipboard . read ?.( )
1918- if ( back ?. data . trim ( ) === cmd ) {
1919- props . api . ui . toast ( { variant : "info" , message : `Copied: ${ cmd } ` } )
1920- return
1921- }
1922- } catch {
1923- // Unreadable or unwritable clipboard — fall through and show it.
1909+ if ( await confirmedCopy ( clipboard , cmd ) ) {
1910+ // `copied` only once the read-back confirms the clipboard holds the command: the
1911+ // selection itself proves nothing (an unconfirmed copy tracks no row).
1912+ trackInstallPrompt ( "copied" , props . offer )
1913+ props . api . ui . toast ( { variant : "info" , message : `Copied: ${ cmd } ` } )
1914+ return
19241915 }
19251916 props . api . ui . toast ( {
19261917 variant : "warning" ,
@@ -1972,7 +1963,6 @@ function EngineInstallOfferDialog(props: EngineOfferProps) {
19721963 return
19731964 }
19741965 if ( option . value === "copy" ) {
1975- trackInstallPrompt ( "copied" , props . offer )
19761966 copyCommand ( )
19771967 props . api . ui . dialog . clear ( )
19781968 return
@@ -1987,6 +1977,23 @@ function EngineInstallOfferDialog(props: EngineOfferProps) {
19871977 )
19881978}
19891979
1980+ /** Write `text` to the clipboard and read it back: true only when the clipboard then holds it.
1981+ *
1982+ * A resolved write is NOT proof of a copy. The host's writer picks xclip/xsel on Linux and
1983+ * otherwise falls back to clipboardy, and it swallows backend failures (`.catch(() => undefined)`),
1984+ * so on the many Linux/WSL boxes with neither tool installed the write silently does nothing.
1985+ * (Caught by E2E: the toast said "Copied:" while the clipboard was untouched.) An unreadable or
1986+ * unwritable clipboard is the same unconfirmed outcome. */
1987+ export async function confirmedCopy ( clipboard : Pick < ClipboardService , "write" | "read" > , text : string ) {
1988+ try {
1989+ await clipboard . write ?.( text )
1990+ const back = await clipboard . read ?.( )
1991+ return back ?. data . trim ( ) === text
1992+ } catch {
1993+ return false
1994+ }
1995+ }
1996+
19901997/** Show the offer unless the 7-day latch suppresses it.
19911998 *
19921999 * The overlay raises this as a bare command over the event bus — it cannot hand
0 commit comments