()
| 208 | * Bash commands will run without tmux isolation. |
| 209 | */ |
| 210 | export async function ensureSocketInitialized(): Promise<void> { |
| 211 | // Already initialized |
| 212 | if (isSocketInitialized()) { |
| 213 | return |
| 214 | } |
| 215 | |
| 216 | // Check if tmux is available before trying to use it |
| 217 | const available = await checkTmuxAvailable() |
| 218 | if (!available) { |
| 219 | return |
| 220 | } |
| 221 | |
| 222 | // Another call is already initializing - wait for it but don't propagate errors |
| 223 | // The original caller handles the error and sets up graceful degradation |
| 224 | if (isInitializing && initPromise) { |
| 225 | try { |
| 226 | await initPromise |
| 227 | } catch { |
| 228 | // Ignore - the original caller logs the error |
| 229 | } |
| 230 | return |
| 231 | } |
| 232 | |
| 233 | isInitializing = true |
| 234 | initPromise = doInitialize() |
| 235 | |
| 236 | try { |
| 237 | await initPromise |
| 238 | } catch (error) { |
| 239 | // Log error but don't throw - graceful degradation |
| 240 | const err = toError(error) |
| 241 | logError(err) |
| 242 | logForDebugging( |
| 243 | `[Socket] Failed to initialize tmux socket: ${err.message}. Tmux isolation will be disabled.`, |
| 244 | ) |
| 245 | } finally { |
| 246 | isInitializing = false |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Kills the tmux server for Claude's isolated socket. |
no test coverage detected