MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / prepareForAction

Function prepareForAction

src/utils/computerUse/executor.ts:361–399  ·  view source on GitHub ↗
(
      allowlistBundleIds: string[],
      displayId?: number,
    )

Source from the content-addressed store, hash-verified

359 // ── Pre-action sequence (hide + defocus) ────────────────────────────
360
361 async prepareForAction(
362 allowlistBundleIds: string[],
363 displayId?: number,
364 ): Promise<string[]> {
365 if (!getHideBeforeActionEnabled()) {
366 return []
367 }
368 // prepareDisplay isn't @MainActor (plain Task{}), but its .hide() calls
369 // trigger window-manager events that queue on CFRunLoop. Without the
370 // pump, those pile up during Swift's ~1s of usleeps and flush all at
371 // once when the next pumped call runs — visible window flashing.
372 // Electron drains CFRunLoop continuously so Cowork doesn't see this.
373 // Worst-case 100ms + 5×200ms safety-net ≈ 1.1s, well under the 30s
374 // drainRunLoop ceiling.
375 //
376 // "Continue with action execution even if switching fails" — the
377 // frontmost gate in toolCalls.ts catches any actual unsafe state.
378 return drainRunLoop(async () => {
379 try {
380 const result = await cu.apps.prepareDisplay(
381 allowlistBundleIds,
382 surrogateHost,
383 displayId,
384 )
385 if (result.activated) {
386 logForDebugging(
387 `[computer-use] prepareForAction: activated ${result.activated}`,
388 )
389 }
390 return result.hidden
391 } catch (err) {
392 logForDebugging(
393 `[computer-use] prepareForAction failed; continuing to action: ${errorMessage(err)}`,
394 { level: 'warn' },
395 )
396 return []
397 }
398 })
399 },
400
401 async previewHideSet(
402 allowlistBundleIds: string[],

Callers

nothing calls this directly

Calls 4

drainRunLoopFunction · 0.85
prepareDisplayMethod · 0.65
logForDebuggingFunction · 0.50
errorMessageFunction · 0.50

Tested by

no test coverage detected