MCPcopy Index your code
hub / github.com/codeaashu/claude-code / typeViaClipboard

Function typeViaClipboard

src/utils/computerUse/executor.ts:180–206  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

178 * user's clipboard clobbered. Restore failures are swallowed.
179 */
180async 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

Callers 1

typeFunction · 0.85

Calls 5

readClipboardViaPbpasteFunction · 0.85
logForDebuggingFunction · 0.85
writeClipboardViaPbcopyFunction · 0.85
keysMethod · 0.80
sleepFunction · 0.50

Tested by

no test coverage detected