(opts: EnsureDaemonRunningOptions)
| 199 | * This is the main entry point for auto-start behavior. |
| 200 | */ |
| 201 | export async function ensureDaemonRunning(opts: EnsureDaemonRunningOptions): Promise<void> { |
| 202 | const client = new DaemonClient({ socketPath: opts.socketPath }); |
| 203 | const timeoutMs = opts.startupTimeoutMs ?? DEFAULT_DAEMON_STARTUP_TIMEOUT_MS; |
| 204 | |
| 205 | const isRunning = await client.isRunning(); |
| 206 | if (isRunning) { |
| 207 | try { |
| 208 | await client.status(); |
| 209 | return; |
| 210 | } catch (error) { |
| 211 | if (error instanceof DaemonVersionMismatchError) { |
| 212 | await forceStopDaemon(opts.socketPath); |
| 213 | } else { |
| 214 | return; |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | startDaemonBackground({ |
| 220 | socketPath: opts.socketPath, |
| 221 | workspaceRoot: opts.workspaceRoot, |
| 222 | env: opts.env, |
| 223 | }); |
| 224 | |
| 225 | await waitForDaemonReady({ |
| 226 | socketPath: opts.socketPath, |
| 227 | timeoutMs, |
| 228 | }); |
| 229 | } |
| 230 | |
| 231 | export interface StartDaemonForegroundOptions { |
| 232 | socketPath: string; |
no test coverage detected