Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 0 additions & 172 deletions .auto-claude-security.json

This file was deleted.

25 changes: 0 additions & 25 deletions .auto-claude-status

This file was deleted.

39 changes: 0 additions & 39 deletions .claude_settings.json

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ node_modules/

# Auto Claude data directory
.auto-claude/
.auto-claude-security.json
.auto-claude-status
.claude_settings.json

# State persistence data (keep structure, ignore content)
data/*
Expand Down
18 changes: 12 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { Client, GatewayIntentBits, EmbedBuilder, ChannelType } from 'discord.js';
import { config as dotenvConfig } from 'dotenv';
import { readFileSync, writeFileSync, existsSync } from 'fs';
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';

Expand Down Expand Up @@ -102,6 +102,12 @@ function addToHistory(channelId, role, content) {
*/
function saveState() {
try {
// Ensure data directory exists
const dataDir = dirname(statePath);
if (!existsSync(dataDir)) {
mkdirSync(dataDir, { recursive: true });
}

const stateData = {
conversationHistory: Array.from(conversationHistory.entries()),
timestamp: new Date().toISOString(),
Expand Down Expand Up @@ -325,11 +331,7 @@ process.on('unhandledRejection', (error) => {
async function gracefulShutdown(signal) {
console.log(`\n🛑 Received ${signal}, shutting down gracefully...`);

// 1. Save state
console.log('💾 Saving conversation state...');
saveState();

// 2. Wait for pending requests with timeout
// 1. Wait for pending requests with timeout
const SHUTDOWN_TIMEOUT = 10000; // 10 seconds
if (pendingRequests.size > 0) {
console.log(`⏳ Waiting for ${pendingRequests.size} pending request(s)...`);
Expand All @@ -346,6 +348,10 @@ async function gracefulShutdown(signal) {
}
}

// 2. Save state after pending requests complete
console.log('💾 Saving conversation state...');
saveState();

// 3. Destroy Discord client
console.log('🔌 Disconnecting from Discord...');
client.destroy();
Expand Down