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