diff --git a/src/commands/cursor-command.ts b/src/commands/cursor-command.ts index 2385a3be..99cd7551 100644 --- a/src/commands/cursor-command.ts +++ b/src/commands/cursor-command.ts @@ -48,7 +48,8 @@ export async function handleCursorCommand(args: string[]): Promise { default: console.error(fail(`Unknown subcommand: ${subcommand}`)); console.error(''); - return handleHelp(); + handleHelp(); + return 1; } } diff --git a/src/cursor/cursor-daemon.ts b/src/cursor/cursor-daemon.ts index 0f016677..07243a4d 100644 --- a/src/cursor/cursor-daemon.ts +++ b/src/cursor/cursor-daemon.ts @@ -205,6 +205,14 @@ export async function startDaemon( if (await isDaemonRunning(config.port)) { safeResolve({ success: true, pid: proc.pid }); } else if (attempts >= maxAttempts) { + // Kill orphaned process + if (proc.pid) { + try { + process.kill(proc.pid, 'SIGTERM'); + } catch { + /* already dead */ + } + } safeResolve({ success: false, error: 'Daemon did not start within 30 seconds', @@ -230,7 +238,7 @@ export async function startDaemon( success: false, error: 'Daemon process exited unexpectedly with code 0', }); - } else if (code !== null) { + } else { safeResolve({ success: false, error: `Daemon process exited with code ${code}`,