* Port of Cowork's `typeViaClipboard`. Sequence: * 1. Save the user's clipboard. * 2. Write our text. * 3. READ-BACK VERIFY — clipboard writes can silently fail. If the * read-back doesn't match, never press Cmd+V (would paste junk). * 4. Cmd+V via keys(). * 5. Sleep 100ms — bat
(input: Input, text: string)
| 178 | * user's clipboard clobbered. Restore failures are swallowed. |
| 179 | */ |
| 180 | async function typeViaClipboard(input: Input, text: string): Promise<void> { |
| 181 | let saved: string | undefined |
| 182 | try { |
| 183 | saved = await readClipboardViaPbpaste() |
| 184 | } catch { |
| 185 | logForDebugging( |
| 186 | '[computer-use] pbpaste before paste failed; proceeding without restore', |
| 187 | ) |
| 188 | } |
| 189 | |
| 190 | try { |
| 191 | await writeClipboardViaPbcopy(text) |
| 192 | if ((await readClipboardViaPbpaste()) !== text) { |
| 193 | throw new Error('Clipboard write did not round-trip.') |
| 194 | } |
| 195 | await input.keys(['command', 'v']) |
| 196 | await sleep(100) |
| 197 | } finally { |
| 198 | if (typeof saved === 'string') { |
| 199 | try { |
| 200 | await writeClipboardViaPbcopy(saved) |
| 201 | } catch { |
| 202 | logForDebugging('[computer-use] clipboard restore after paste failed') |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Port of Cowork's `animateMouseMovement` + `animatedMove`. Ease-out-cubic at |
no test coverage detected