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

Function createCliExecutor

src/utils/computerUse/executor.ts:259–645  ·  view source on GitHub ↗
(opts: {
  getMouseAnimationEnabled: () => boolean
  getHideBeforeActionEnabled: () => boolean
})

Source from the content-addressed store, hash-verified

257// ── Factory ───────────────────────────────────────────────────────────────
258
259export function createCliExecutor(opts: {
260 getMouseAnimationEnabled: () => boolean
261 getHideBeforeActionEnabled: () => boolean
262}): ComputerExecutor {
263 if (process.platform !== 'darwin') {
264 throw new Error(
265 `createCliExecutor called on ${process.platform}. Computer control is macOS-only.`,
266 )
267 }
268
269 // Swift loaded once at factory time — every executor method needs it.
270 // Input loaded lazily via requireComputerUseInput() on first mouse/keyboard
271 // call — it caches internally, so screenshot-only flows never pull the
272 // enigo .node.
273 const cu = requireComputerUseSwift()
274
275 const { getMouseAnimationEnabled, getHideBeforeActionEnabled } = opts
276 const terminalBundleId = getTerminalBundleId()
277 const surrogateHost = terminalBundleId ?? CLI_HOST_BUNDLE_ID
278 // Swift 0.2.1's captureExcluding/captureRegion take an ALLOW list despite the
279 // name (apps#30355 — complement computed Swift-side against running apps).
280 // The terminal isn't in the user's grants so it's naturally excluded, but if
281 // the package ever passes it through we strip it here so the terminal never
282 // photobombs a screenshot.
283 const withoutTerminal = (allowed: readonly string[]): string[] =>
284 terminalBundleId === null
285 ? [...allowed]
286 : allowed.filter(id => id !== terminalBundleId)
287
288 logForDebugging(
289 terminalBundleId
290 ? `[computer-use] terminal ${terminalBundleId} → surrogate host (hide-exempt, activate-skip, screenshot-excluded)`
291 : '[computer-use] terminal not detected; falling back to sentinel host',
292 )
293
294 return {
295 capabilities: {
296 ...CLI_CU_CAPABILITIES,
297 hostBundleId: CLI_HOST_BUNDLE_ID,
298 },
299
300 // ── Pre-action sequence (hide + defocus) ────────────────────────────
301
302 async prepareForAction(
303 allowlistBundleIds: string[],
304 displayId?: number,
305 ): Promise<string[]> {
306 if (!getHideBeforeActionEnabled()) {
307 return []
308 }
309 // prepareDisplay isn't @MainActor (plain Task{}), but its .hide() calls
310 // trigger window-manager events that queue on CFRunLoop. Without the
311 // pump, those pile up during Swift's ~1s of usleeps and flush all at
312 // once when the next pumped call runs — visible window flashing.
313 // Electron drains CFRunLoop continuously so Cowork doesn't see this.
314 // Worst-case 100ms + 5×200ms safety-net ≈ 1.1s, well under the 30s
315 // drainRunLoop ceiling.
316 //

Callers 1

Calls 3

requireComputerUseSwiftFunction · 0.85
getTerminalBundleIdFunction · 0.85
logForDebuggingFunction · 0.85

Tested by

no test coverage detected