Files
claude-code/src/utils/computerUse/gates.ts
unraid e3264a1691 feat: enable Computer Use with macOS + Windows + Linux support
Phase 1: Replace @ant/computer-use-mcp stub (12 files, 6517 lines).

Phase 2: Remove 8 macOS-only guards in src/:
- main.tsx: remove getPlatform()==='macos' check
- swiftLoader.ts: remove darwin-only throw
- executor.ts: extend platform guard, clipboard dispatch, paste key
- drainRunLoop.ts: skip CFRunLoop pump on non-darwin
- escHotkey.ts: non-darwin returns false (Ctrl+C fallback)
- hostAdapter.ts: non-darwin permissions granted
- common.ts: dynamic platform + screenshotFiltering
- gates.ts: enabled:true, subscription check removed

Phase 3: Add Linux backends (xdotool/scrot/xrandr/wmctrl):
- computer-use-input/backends/linux.ts (173 lines)
- computer-use-swift/backends/linux.ts (278 lines)

Verified on Windows x64: mouse, screenshot, displays, foreground app.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 23:17:14 +08:00

71 lines
2.4 KiB
TypeScript

import type { CoordinateMode, CuSubGates } from '@ant/computer-use-mcp/types'
import { getDynamicConfig_CACHED_MAY_BE_STALE } from '../../services/analytics/growthbook.js'
import { getSubscriptionType } from '../auth.js'
import { isEnvTruthy } from '../envUtils.js'
type ChicagoConfig = CuSubGates & {
enabled: boolean
coordinateMode: CoordinateMode
}
const DEFAULTS: ChicagoConfig = {
enabled: true,
pixelValidation: false,
clipboardPasteMultiline: true,
mouseAnimation: true,
hideBeforeAction: true,
autoTargetDisplay: true,
clipboardGuard: true,
coordinateMode: 'pixels',
}
// Spread over defaults so a partial JSON ({"enabled": true} alone) inherits the
// rest. The generic on getDynamicConfig is a type assertion, not a validator —
// GB returning a partial object would otherwise surface undefined fields.
function readConfig(): ChicagoConfig {
return {
...DEFAULTS,
...getDynamicConfig_CACHED_MAY_BE_STALE<Partial<ChicagoConfig>>(
'tengu_malort_pedway',
DEFAULTS,
),
}
}
// Max/Pro only for external rollout. Ant bypass so dogfooding continues
// regardless of subscription tier — not all ants are max/pro, and per
// CLAUDE.md:281, USER_TYPE !== 'ant' branches get zero antfooding.
function hasRequiredSubscription(): boolean {
return true
}
export function getChicagoEnabled(): boolean {
// Disable for ants whose shell inherited monorepo dev config.
// MONOREPO_ROOT_DIR is exported by config/local/zsh/zshrc, which
// laptop-setup.sh wires into ~/.zshrc — its presence is the cheap
// proxy for "has monorepo access". Override: ALLOW_ANT_COMPUTER_USE_MCP=1.
if (
process.env.USER_TYPE === 'ant' &&
process.env.MONOREPO_ROOT_DIR &&
!isEnvTruthy(process.env.ALLOW_ANT_COMPUTER_USE_MCP)
) {
return false
}
return hasRequiredSubscription() && readConfig().enabled
}
export function getChicagoSubGates(): CuSubGates {
const { enabled: _e, coordinateMode: _c, ...subGates } = readConfig()
return subGates
}
// Frozen at first read — setup.ts builds tool descriptions and executor.ts
// scales coordinates off the same value. A live read here lets a mid-session
// GB flip tell the model "pixels" while transforming clicks as normalized.
let frozenCoordinateMode: CoordinateMode | undefined
export function getChicagoCoordinateMode(): CoordinateMode {
frozenCoordinateMode ??= readConfig().coordinateMode
return frozenCoordinateMode
}