(
socketPath: string,
workspaceRoot: string,
foreground: boolean,
logOpts: { logPath?: string; logLevel?: string },
)
| 165 | } |
| 166 | |
| 167 | async function handleStart( |
| 168 | socketPath: string, |
| 169 | workspaceRoot: string, |
| 170 | foreground: boolean, |
| 171 | logOpts: { logPath?: string; logLevel?: string }, |
| 172 | ): Promise<void> { |
| 173 | const client = new DaemonClient({ socketPath }); |
| 174 | |
| 175 | // Check if already running |
| 176 | const isRunning = await client.isRunning(); |
| 177 | if (isRunning) { |
| 178 | writeLine('Daemon is already running'); |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | const envOverrides: Record<string, string> = {}; |
| 183 | if (logOpts.logPath) { |
| 184 | envOverrides.XCODEBUILDMCP_DAEMON_LOG_PATH = logOpts.logPath; |
| 185 | } |
| 186 | if (logOpts.logLevel) { |
| 187 | envOverrides.XCODEBUILDMCP_DAEMON_LOG_LEVEL = logOpts.logLevel; |
| 188 | } |
| 189 | |
| 190 | if (foreground) { |
| 191 | // Run in foreground (useful for debugging) |
| 192 | writeLine('Starting daemon in foreground...'); |
| 193 | writeLine(`Workspace: ${workspaceRoot}`); |
| 194 | writeLine(`Socket: ${socketPath}`); |
| 195 | writeLine('Press Ctrl+C to stop\n'); |
| 196 | |
| 197 | const exitCode = await startDaemonForeground({ |
| 198 | socketPath, |
| 199 | workspaceRoot, |
| 200 | env: Object.keys(envOverrides).length > 0 ? envOverrides : undefined, |
| 201 | }); |
| 202 | process.exit(exitCode); |
| 203 | } else { |
| 204 | // Run in background with auto-start helper |
| 205 | try { |
| 206 | await ensureDaemonRunning({ |
| 207 | socketPath, |
| 208 | workspaceRoot, |
| 209 | startupTimeoutMs: DEFAULT_DAEMON_STARTUP_TIMEOUT_MS, |
| 210 | env: Object.keys(envOverrides).length > 0 ? envOverrides : undefined, |
| 211 | }); |
| 212 | writeLine('Daemon started'); |
| 213 | writeLine(`Workspace: ${workspaceRoot}`); |
| 214 | writeLine(`Socket: ${socketPath}`); |
| 215 | } catch (err) { |
| 216 | console.error('Failed to start daemon:', err instanceof Error ? err.message : String(err)); |
| 217 | process.exitCode = 1; |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | async function handleRestart( |
| 223 | client: DaemonClient, |
no test coverage detected