fix(electrobun): hasSession checks running status (dead sessions no longer block startAgent)

This commit is contained in:
Hibryda 2026-03-26 02:35:23 +01:00
parent f1472848f8
commit 8031cf91cf
2 changed files with 10 additions and 2 deletions

View file

@ -132,11 +132,14 @@
}
function handleSend(text: string) {
console.log('[ProjectCard] handleSend called:', { id, provider, cwd, model, hasSession: appState.agent.hasSession(id), text: text.slice(0, 50) });
if (appState.agent.hasSession(id)) {
console.log('[ProjectCard] calling sendPrompt');
appState.agent.sendPrompt(id, text).catch((err) => {
console.error('[agent.prompt] error:', err);
});
} else {
console.log('[ProjectCard] calling startAgent');
appState.agent.startAgent(id, provider, text, { cwd, model }).catch((err) => {
console.error('[agent.start] error:', err);
});

View file

@ -602,9 +602,14 @@ export function getSession(projectId: string): AgentSession | undefined {
return sessions[sessionId];
}
/** Check if a project has an active session. */
/** Check if a project has an active (running) session. */
export function hasSession(projectId: string): boolean {
return projectSessionMap.has(projectId);
const sessionId = projectSessionMap.get(projectId);
if (!sessionId) return false;
const session = sessions[sessionId];
// Only return true if session exists AND is running
// Dead/error/done sessions should trigger startAgent, not sendPrompt
return !!session && session.status === 'running';
}
/**