MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / createCliExecutor

Function createCliExecutor

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

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 3

requireComputerUseSwiftFunction · 0.85
getTerminalBundleIdFunction · 0.85
logForDebuggingFunction · 0.85

Tested by

no test coverage detected