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