source dump of claude code
at main 61 lines 2.6 kB view raw
1import { normalizeNameForMCP } from '../../services/mcp/normalization.js' 2import { env } from '../env.js' 3 4export const COMPUTER_USE_MCP_SERVER_NAME = 'computer-use' 5 6/** 7 * Sentinel bundle ID for the frontmost gate. Claude Code is a terminal — it has 8 * no window. This never matches a real `NSWorkspace.frontmostApplication`, so 9 * the package's "host is frontmost" branch (mouse click-through exemption, 10 * keyboard safety-net) is dead code for us. `prepareForAction`'s "exempt our 11 * own window" is likewise a no-op — there is no window to exempt. 12 */ 13export const CLI_HOST_BUNDLE_ID = 'com.anthropic.claude-code.cli-no-window' 14 15/** 16 * Fallback `env.terminal` → bundleId map for when `__CFBundleIdentifier` is 17 * unset. Covers the macOS terminals we can distinguish — Linux entries 18 * (konsole, gnome-terminal, xterm) are deliberately absent since 19 * `createCliExecutor` is darwin-guarded. 20 */ 21const TERMINAL_BUNDLE_ID_FALLBACK: Readonly<Record<string, string>> = { 22 'iTerm.app': 'com.googlecode.iterm2', 23 Apple_Terminal: 'com.apple.Terminal', 24 ghostty: 'com.mitchellh.ghostty', 25 kitty: 'net.kovidgoyal.kitty', 26 WarpTerminal: 'dev.warp.Warp-Stable', 27 vscode: 'com.microsoft.VSCode', 28} 29 30/** 31 * Bundle ID of the terminal emulator we're running inside, so `prepareDisplay` 32 * can exempt it from hiding and `captureExcluding` can keep it out of 33 * screenshots. Returns null when undetectable (ssh, cleared env, unknown 34 * terminal) — caller must handle the null case. 35 * 36 * `__CFBundleIdentifier` is set by LaunchServices when a .app bundle spawns a 37 * process and is inherited by children. It's the exact bundleId, no lookup 38 * needed — handles terminals the fallback table doesn't know about. Under 39 * tmux/screen it reflects the terminal that started the SERVER, which may 40 * differ from the attached client. That's harmless here: we exempt A 41 * terminal window, and the screenshots exclude it regardless. 42 */ 43export function getTerminalBundleId(): string | null { 44 const cfBundleId = process.env.__CFBundleIdentifier 45 if (cfBundleId) return cfBundleId 46 return TERMINAL_BUNDLE_ID_FALLBACK[env.terminal ?? ''] ?? null 47} 48 49/** 50 * Static capabilities for macOS CLI. `hostBundleId` is not here — it's added 51 * by `executor.ts` per `ComputerExecutor.capabilities`. `buildComputerUseTools` 52 * takes this shape (no `hostBundleId`, no `teachMode`). 53 */ 54export const CLI_CU_CAPABILITIES = { 55 screenshotFiltering: 'native' as const, 56 platform: 'darwin' as const, 57} 58 59export function isComputerUseMCPServer(name: string): boolean { 60 return normalizeNameForMCP(name) === COMPUTER_USE_MCP_SERVER_NAME 61}