fix: load project .env vars and cleanup stale sessions

- Load project's .env file when spawning Claude so API credentials work
- Check isClaudeRunning() before routing messages to sessions
- Auto-cleanup stale sessions when Claude has exited
- Fixes ESO Logs API access from spawned Claude instances

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
RichardDillman
2025-11-25 18:22:46 -05:00
parent 0d277e4ae2
commit 0ce65d7120
2 changed files with 49 additions and 1 deletions

View File

@@ -419,7 +419,10 @@ bot.on('text', async (ctx) => {
const activeSession = Array.from(activeSessions.values())
.find(s => s.projectName.toLowerCase() === targetProject.toLowerCase());
if (activeSession) {
// Check if Claude is actually running (not just session registered)
const claudeActuallyRunning = isClaudeRunning(targetProject);
if (activeSession && claudeActuallyRunning) {
// Add to message queue with session ID
messageQueue.push({
from,
@@ -430,6 +433,11 @@ bot.on('text', async (ctx) => {
});
await ctx.reply(`💬 Message sent to active session: *${activeSession.projectName}*`, { parse_mode: 'Markdown' });
} else {
// Clean up stale session if Claude exited
if (activeSession && !claudeActuallyRunning) {
console.log(`[CLEANUP] Removing stale session for ${activeSession.projectName} (Claude not running)`);
activeSessions.delete(activeSession.id);
}
// No active session - check if project is registered and should auto-spawn
try {
const project = await findProject(targetProject);