| 124 | |
| 125 | // Detect terminal type with fallbacks for all platforms |
| 126 | function detectTerminal(): string | null { |
| 127 | if (process.env.CURSOR_TRACE_ID) return 'cursor' |
| 128 | // Cursor and Windsurf under WSL have TERM_PROGRAM=vscode |
| 129 | if (process.env.VSCODE_GIT_ASKPASS_MAIN?.includes('cursor')) { |
| 130 | return 'cursor' |
| 131 | } |
| 132 | if (process.env.VSCODE_GIT_ASKPASS_MAIN?.includes('windsurf')) { |
| 133 | return 'windsurf' |
| 134 | } |
| 135 | if (process.env.VSCODE_GIT_ASKPASS_MAIN?.includes('antigravity')) { |
| 136 | return 'antigravity' |
| 137 | } |
| 138 | const bundleId = process.env.__CFBundleIdentifier?.toLowerCase() |
| 139 | if (bundleId?.includes('vscodium')) return 'codium' |
| 140 | if (bundleId?.includes('windsurf')) return 'windsurf' |
| 141 | if (bundleId?.includes('com.google.android.studio')) return 'androidstudio' |
| 142 | // Check for JetBrains IDEs in bundle ID |
| 143 | if (bundleId) { |
| 144 | for (const ide of JETBRAINS_IDES) { |
| 145 | if (bundleId.includes(ide)) return ide |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | if (process.env.VisualStudioVersion) { |
| 150 | // This is desktop Visual Studio, not VS Code |
| 151 | return 'visualstudio' |
| 152 | } |
| 153 | |
| 154 | // Check for JetBrains terminal on Linux/Windows |
| 155 | if (process.env.TERMINAL_EMULATOR === 'JetBrains-JediTerm') { |
| 156 | // For macOS, bundle ID detection above already handles JetBrains IDEs |
| 157 | if (process.platform === 'darwin') return 'pycharm' |
| 158 | |
| 159 | // For finegrained detection on Linux/Windows use envDynamic.getTerminalWithJetBrainsDetection() |
| 160 | return 'pycharm' |
| 161 | } |
| 162 | |
| 163 | // Check for specific terminals by TERM before TERM_PROGRAM |
| 164 | // This handles cases where TERM and TERM_PROGRAM might be inconsistent |
| 165 | if (process.env.TERM === 'xterm-ghostty') { |
| 166 | return 'ghostty' |
| 167 | } |
| 168 | if (process.env.TERM?.includes('kitty')) { |
| 169 | return 'kitty' |
| 170 | } |
| 171 | |
| 172 | if (process.env.TERM_PROGRAM) { |
| 173 | return process.env.TERM_PROGRAM |
| 174 | } |
| 175 | |
| 176 | if (process.env.TMUX) return 'tmux' |
| 177 | if (process.env.STY) return 'screen' |
| 178 | |
| 179 | // Check for terminal-specific environment variables (common on Linux) |
| 180 | if (process.env.KONSOLE_VERSION) return 'konsole' |
| 181 | if (process.env.GNOME_TERMINAL_SERVICE) return 'gnome-terminal' |
| 182 | if (process.env.XTERM_VERSION) return 'xterm' |
| 183 | if (process.env.VTE_VERSION) return 'vte-based' |