(
allowlistBundleIds: string[],
displayId?: number,
)
| 405 | // ── Pre-action sequence (hide + defocus) ──────────────────────────── |
| 406 | |
| 407 | async prepareForAction( |
| 408 | allowlistBundleIds: string[], |
| 409 | displayId?: number, |
| 410 | ): Promise<string[]> { |
| 411 | if (!getHideBeforeActionEnabled()) { |
| 412 | return [] |
| 413 | } |
| 414 | // prepareDisplay isn't @MainActor (plain Task{}), but its .hide() calls |
| 415 | // trigger window-manager events that queue on CFRunLoop. Without the |
| 416 | // pump, those pile up during Swift's ~1s of usleeps and flush all at |
| 417 | // once when the next pumped call runs — visible window flashing. |
| 418 | // Electron drains CFRunLoop continuously so Cowork doesn't see this. |
| 419 | // Worst-case 100ms + 5×200ms safety-net ≈ 1.1s, well under the 30s |
| 420 | // drainRunLoop ceiling. |
| 421 | // |
| 422 | // "Continue with action execution even if switching fails" — the |
| 423 | // frontmost gate in toolCalls.ts catches any actual unsafe state. |
| 424 | return drainRunLoop(async () => { |
| 425 | try { |
| 426 | const result = await cu.apps.prepareDisplay( |
| 427 | allowlistBundleIds, |
| 428 | surrogateHost, |
| 429 | displayId, |
| 430 | ) |
| 431 | if (result.activated) { |
| 432 | logForDebugging( |
| 433 | `[computer-use] prepareForAction: activated ${result.activated}`, |
| 434 | ) |
| 435 | } |
| 436 | return result.hidden |
| 437 | } catch (err) { |
| 438 | logForDebugging( |
| 439 | `[computer-use] prepareForAction failed; continuing to action: ${errorMessage(err)}`, |
| 440 | { level: 'warn' }, |
| 441 | ) |
| 442 | return [] |
| 443 | } |
| 444 | }) |
| 445 | }, |
| 446 | |
| 447 | async previewHideSet( |
| 448 | allowlistBundleIds: string[], |
nothing calls this directly
no test coverage detected