Skip to content

Commit 589f845

Browse files
fix: track copied only on a confirmed copy; an unbound precedence row names no workspace
`confirmedCopy` writes and reads back; the dialog tracks `copied` only when the clipboard then holds the command. `precedenceEvent` sets `workspace_id` explicitly (undefined when unbound and unlinked), as the attach row does. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_011AhtJPr3nmT1Po92ZQk4VE
1 parent c8f5a70 commit 589f845

4 files changed

Lines changed: 67 additions & 21 deletions

File tree

‎packages/opencode/src/altimate/workspace/engine-telemetry.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ export function precedenceEvent(
178178
shadowed_connections: opts.connections,
179179
extensions: p.extensions?.length ?? 0,
180180
escape_hatch: opts.escapeHatch,
181-
...(id !== undefined && Number.isInteger(id) && id > 0 ? { workspace_id: id } : {}),
181+
// Present and undefined for an unbound or disabled snapshot with no linked workspace, as on the
182+
// attach row: the row names no workspace, and nothing else may name one for it.
183+
workspace_id: id !== undefined && Number.isInteger(id) && id > 0 ? id : undefined,
182184
}
183185
}
184186

‎packages/opencode/src/plugin/tui/altimate/workspace.tsx‎

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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"
102102
import { AltimateApi } from "@/altimate/api/client"
103103
import { 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

‎packages/opencode/test/altimate/plugin/workspace.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const {
3535
recordEngineSkip,
3636
awaitKvReady,
3737
canInstallWith,
38+
confirmedCopy,
3839
engineOfferInternals,
3940
showEngineInstallOffer,
4041
linkDialogInternals,
@@ -1249,3 +1250,38 @@ describe("/integrations", () => {
12491250
expect(h.selects[1]!.options[0]!.description).toContain("No session has attached yet")
12501251
})
12511252
})
1253+
1254+
describe("confirmedCopy", () => {
1255+
const cmd = "npm i -g @altimateai/altimate-code-engine"
1256+
test("true only when the read-back holds the command", async () => {
1257+
let held = ""
1258+
const clipboard = {
1259+
write: async (data: string) => {
1260+
held = data
1261+
},
1262+
read: async () => ({ data: `${held}\n`, mime: "text/plain" }),
1263+
}
1264+
expect(await confirmedCopy(clipboard, cmd)).toBe(true)
1265+
})
1266+
test("false when the writer silently did nothing", async () => {
1267+
const clipboard = {
1268+
write: async () => {},
1269+
read: async () => ({ data: "something else", mime: "text/plain" }),
1270+
}
1271+
expect(await confirmedCopy(clipboard, cmd)).toBe(false)
1272+
})
1273+
test("false when the clipboard throws or cannot be read", async () => {
1274+
expect(
1275+
await confirmedCopy(
1276+
{
1277+
write: async () => {
1278+
throw new Error("no backend")
1279+
},
1280+
read: async () => ({ data: cmd, mime: "text/plain" }),
1281+
},
1282+
cmd,
1283+
),
1284+
).toBe(false)
1285+
expect(await confirmedCopy({ write: async () => {}, read: undefined }, cmd)).toBe(false)
1286+
})
1287+
})

‎packages/opencode/test/altimate/workspace/engine-telemetry.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ describe("workspace engine telemetry builders", () => {
134134
expect(
135135
(precedenceEvent(offSnap, { escapeHatch: true, connections: 0, types: 0, workspaceId: 7 }) as any).workspace_id,
136136
).toBe(7)
137-
expect("workspace_id" in (precedenceEvent(offSnap, { escapeHatch: true, connections: 0, types: 0 }) as any)).toBe(
138-
false,
139-
)
137+
// Unbound and no linked workspace: the key is present and undefined, so the row names none.
138+
const unboundRow = precedenceEvent(offSnap, { escapeHatch: true, connections: 0, types: 0 }) as any
139+
expect("workspace_id" in unboundRow).toBe(true)
140+
expect(unboundRow.workspace_id).toBeUndefined()
140141
expect(precedenceEvent(on, { escapeHatch: false, connections: 1, types: 2 })).toEqual(
141142
expect.objectContaining({
142143
type: "workspace_engine_precedence",

0 commit comments

Comments
 (0)