diff --git a/src/main/cli.ts b/src/main/cli.ts index 8220b440ba..72055dabf0 100644 --- a/src/main/cli.ts +++ b/src/main/cli.ts @@ -99,6 +99,10 @@ async function main() { }) } + // Track current session for cancellation + let currentSessionId: string | null = null + let isCancelling = false + const conductor = new Conductor({ onSessionUpdate: (params) => { // Log the raw update for debugging @@ -202,6 +206,39 @@ async function main() { }, }) + // Handle Ctrl+C gracefully - send cancel request to agent + const handleSigint = async () => { + if (isCancelling) { + console.log('\nāš ļø Force quit...') + process.exit(1) + } + + isCancelling = true + console.log('\n\nšŸ›‘ Cancelling request...') + + if (currentSessionId) { + try { + await conductor.cancelRequest(currentSessionId) + console.log('āœ“ Cancel request sent to agent') + } catch (err) { + console.error('Failed to send cancel:', err) + } + } + + // Save log before exit + if (logFile && sessionLog.length > 0) { + writeFileSync(logFile, JSON.stringify(sessionLog, null, 2)) + console.log(`šŸ“„ Session log saved to: ${logFile}`) + } + + await conductor.stopAgent() + process.exit(0) + } + + process.on('SIGINT', () => { + handleSigint().catch(console.error) + }) + try { // Start the agent await conductor.startAgent(agentConfig) @@ -209,6 +246,7 @@ async function main() { // Create a session with specified working directory console.log(`šŸ“ Working directory: ${cwd}`) const session = await conductor.createSession(cwd) + currentSessionId = session.id console.log(`šŸ“ Session: ${session.id}`) // Send the prompt diff --git a/src/main/config/defaults.ts b/src/main/config/defaults.ts index 62ac4be123..5c3564cd82 100644 --- a/src/main/config/defaults.ts +++ b/src/main/config/defaults.ts @@ -13,10 +13,12 @@ export const DEFAULT_AGENTS: Record = { }, codex: { id: 'codex', - name: 'Codex CLI', - command: 'codex', - args: ['--acp'], + name: 'Codex CLI (ACP)', + command: 'codex-acp', + args: [], enabled: true, + // Note: Uses https://github.com/zed-industries/codex-acp + // Official Codex CLI doesn't support ACP }, gemini: { id: 'gemini',