diff --git a/src/commands/cursor-command.ts b/src/commands/cursor-command.ts index b7139586..c5547380 100644 --- a/src/commands/cursor-command.ts +++ b/src/commands/cursor-command.ts @@ -60,7 +60,7 @@ export async function handleCursorCommand(args: string[]): Promise { default: console.error(fail(`Unknown subcommand: ${subcommand}`)); console.error(''); - handleHelp(); + void handleHelp(); // Print help but keep exit code 1 return 1; } } diff --git a/src/cursor/cursor-daemon.ts b/src/cursor/cursor-daemon.ts index 1ed5a484..19ad0034 100644 --- a/src/cursor/cursor-daemon.ts +++ b/src/cursor/cursor-daemon.ts @@ -264,6 +264,18 @@ export async function stopDaemon(): Promise<{ success: boolean; error?: string } } try { + // Verify the PID belongs to our daemon before signaling + try { + const cmdline = fs.readFileSync(`/proc/${pid}/cmdline`, 'utf8'); + if (!cmdline.includes('cursor') && !cmdline.includes('/health')) { + // PID was reused by an unrelated process + removePidFile(); + return { success: true }; + } + } catch { + // /proc not available (macOS/Windows) or process gone — proceed with kill + } + // Send SIGTERM to the process process.kill(pid, 'SIGTERM'); diff --git a/src/cursor/cursor-models.ts b/src/cursor/cursor-models.ts index 931e89c5..cc74cb1e 100644 --- a/src/cursor/cursor-models.ts +++ b/src/cursor/cursor-models.ts @@ -2,7 +2,7 @@ * Cursor Model Catalog * * Manages available models from Cursor IDE. - * Based on Cursor's supported models as of Feb 2025. + * Based on Cursor's supported models catalog. */ import * as http from 'http'; @@ -165,7 +165,7 @@ export function getDefaultModel(): string { */ export function detectProvider(modelId: string): string { if (modelId.includes('claude')) return 'anthropic'; - if (modelId.includes('gpt') || /^o\d/.test(modelId)) return 'openai'; + if (modelId.includes('gpt') || /^o[1-9]\d*(-|$)/.test(modelId)) return 'openai'; if (modelId.includes('gemini')) return 'google'; if (modelId.includes('cursor')) return 'cursor'; return 'unknown'; diff --git a/tests/unit/cursor/cursor-daemon.test.ts b/tests/unit/cursor/cursor-daemon.test.ts index 1d0ab32a..4865dbed 100644 --- a/tests/unit/cursor/cursor-daemon.test.ts +++ b/tests/unit/cursor/cursor-daemon.test.ts @@ -137,6 +137,29 @@ describe('startDaemon', () => { expect(result.success).toBe(false); expect(result.error).toContain('Invalid port'); }); + + it( + 'starts and stops daemon successfully', + async () => { + const port = 18765; + const result = await startDaemon({ port, model: 'test' }); + expect(result.success).toBe(true); + expect(result.pid).toBeDefined(); + + // Verify health + const running = await isDaemonRunning(port); + expect(running).toBe(true); + + // Stop + const stopResult = await stopDaemon(); + expect(stopResult.success).toBe(true); + + // Verify stopped + const stillRunning = await isDaemonRunning(port); + expect(stillRunning).toBe(false); + }, + 35000 + ); }); describe('isDaemonRunning', () => {