mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-24 11:10:25 +02:00
feat: add graceful cancellation and fix codex config
- Handle Ctrl+C to send session/cancel before stopping agent - Support double Ctrl+C for force quit - Update Codex config to use codex-acp (zed-industries/codex-acp) since official Codex CLI doesn't support ACP Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -13,10 +13,12 @@ export const DEFAULT_AGENTS: Record<string, AgentConfig> = {
|
||||
},
|
||||
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',
|
||||
|
||||
Reference in New Issue
Block a user