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