import { c as _c } from "react/compiler-runtime"; import chalk from 'chalk'; import * as path from 'path'; import React, { useCallback, useEffect, useRef, useState } from 'react'; import { logEvent } from 'src/services/analytics/index.js'; import type { CommandResultDisplay, LocalJSXCommandContext } from '../../commands.js'; import { Select } from '../../components/CustomSelect/index.js'; import { Dialog } from '../../components/design-system/Dialog.js'; import { IdeAutoConnectDialog, IdeDisableAutoConnectDialog, shouldShowAutoConnectDialog, shouldShowDisableAutoConnectDialog } from '../../components/IdeAutoConnectDialog.js'; import { Box, Text } from '../../ink.js'; import { clearServerCache } from '../../services/mcp/client.js'; import type { ScopedMcpServerConfig } from '../../services/mcp/types.js'; import { useAppState, useSetAppState } from '../../state/AppState.js'; import { getCwd } from '../../utils/cwd.js'; import { execFileNoThrow } from '../../utils/execFileNoThrow.js'; import { type DetectedIDEInfo, detectIDEs, detectRunningIDEs, type IdeType, isJetBrainsIde, isSupportedJetBrainsTerminal, isSupportedTerminal, toIDEDisplayName } from '../../utils/ide.js'; import { getCurrentWorktreeSession } from '../../utils/worktree.js'; type IDEScreenProps = { availableIDEs: DetectedIDEInfo[]; unavailableIDEs: DetectedIDEInfo[]; selectedIDE?: DetectedIDEInfo | null; onClose: () => void; onSelect: (ide?: DetectedIDEInfo) => void; }; function IDEScreen(t0) { const $ = _c(39); const { availableIDEs, unavailableIDEs, selectedIDE, onClose, onSelect } = t0; let t1; if ($[0] !== selectedIDE?.port) { t1 = selectedIDE?.port?.toString() ?? "None"; $[0] = selectedIDE?.port; $[1] = t1; } else { t1 = $[1]; } const [selectedValue, setSelectedValue] = useState(t1); const [showAutoConnectDialog, setShowAutoConnectDialog] = useState(false); const [showDisableAutoConnectDialog, setShowDisableAutoConnectDialog] = useState(false); let t2; if ($[2] !== availableIDEs || $[3] !== onSelect) { t2 = value => { if (value !== "None" && shouldShowAutoConnectDialog()) { setShowAutoConnectDialog(true); } else { if (value === "None" && shouldShowDisableAutoConnectDialog()) { setShowDisableAutoConnectDialog(true); } else { onSelect(availableIDEs.find(ide => ide.port === parseInt(value))); } } }; $[2] = availableIDEs; $[3] = onSelect; $[4] = t2; } else { t2 = $[4]; } const handleSelectIDE = t2; let t3; if ($[5] !== availableIDEs) { t3 = availableIDEs.reduce(_temp, {}); $[5] = availableIDEs; $[6] = t3; } else { t3 = $[6]; } const ideCounts = t3; let t4; if ($[7] !== availableIDEs || $[8] !== ideCounts) { let t5; if ($[10] !== ideCounts) { t5 = ide_1 => { const hasMultipleInstances = (ideCounts[ide_1.name] || 0) > 1; const showWorkspace = hasMultipleInstances && ide_1.workspaceFolders.length > 0; return { label: ide_1.name, value: ide_1.port.toString(), description: showWorkspace ? formatWorkspaceFolders(ide_1.workspaceFolders) : undefined }; }; $[10] = ideCounts; $[11] = t5; } else { t5 = $[11]; } t4 = availableIDEs.map(t5).concat([{ label: "None", value: "None", description: undefined }]); $[7] = availableIDEs; $[8] = ideCounts; $[9] = t4; } else { t4 = $[9]; } const options = t4; if (showAutoConnectDialog) { let t5; if ($[12] !== handleSelectIDE || $[13] !== selectedValue) { t5 = handleSelectIDE(selectedValue)} />; $[12] = handleSelectIDE; $[13] = selectedValue; $[14] = t5; } else { t5 = $[14]; } return t5; } if (showDisableAutoConnectDialog) { let t5; if ($[15] !== onSelect) { t5 = { onSelect(undefined); }} />; $[15] = onSelect; $[16] = t5; } else { t5 = $[16]; } return t5; } let t5; if ($[17] !== availableIDEs.length) { t5 = availableIDEs.length === 0 && {isSupportedJetBrainsTerminal() ? "No available IDEs detected. Please install the plugin and restart your IDE:\nhttps://docs.claude.com/s/claude-code-jetbrains" : "No available IDEs detected. Make sure your IDE has the Claude Code extension or plugin installed and is running."}; $[17] = availableIDEs.length; $[18] = t5; } else { t5 = $[18]; } let t6; if ($[19] !== availableIDEs.length || $[20] !== handleSelectIDE || $[21] !== options || $[22] !== selectedValue) { t6 = availableIDEs.length !== 0 && ; $[11] = options; $[12] = selectedValue; $[13] = t5; $[14] = t6; } else { t6 = $[14]; } let t7; if ($[15] !== handleCancel || $[16] !== t6) { t7 = {t6}; $[15] = handleCancel; $[16] = t6; $[17] = t7; } else { t7 = $[17]; } return t7; } function _temp4(ide_0) { return { label: ide_0.name, value: ide_0.port.toString() }; } function RunningIDESelector(t0) { const $ = _c(15); const { runningIDEs, onSelectIDE, onDone } = t0; const [selectedValue, setSelectedValue] = useState(runningIDEs[0] ?? ""); let t1; if ($[0] !== onSelectIDE) { t1 = value => { onSelectIDE(value as IdeType); }; $[0] = onSelectIDE; $[1] = t1; } else { t1 = $[1]; } const handleSelectIDE = t1; let t2; if ($[2] !== runningIDEs) { t2 = runningIDEs.map(_temp5); $[2] = runningIDEs; $[3] = t2; } else { t2 = $[3]; } const options = t2; let t3; if ($[4] !== onDone) { t3 = function handleCancel() { onDone("IDE selection cancelled", { display: "system" }); }; $[4] = onDone; $[5] = t3; } else { t3 = $[5]; } const handleCancel = t3; let t4; if ($[6] !== handleSelectIDE) { t4 = value_0 => { setSelectedValue(value_0); handleSelectIDE(value_0); }; $[6] = handleSelectIDE; $[7] = t4; } else { t4 = $[7]; } let t5; if ($[8] !== options || $[9] !== selectedValue || $[10] !== t4) { t5 =