diff --git a/.auto-claude-security.json b/.auto-claude-security.json deleted file mode 100644 index eeb9f8f1..00000000 --- a/.auto-claude-security.json +++ /dev/null @@ -1,172 +0,0 @@ -{ - "base_commands": [ - ".", - "[", - "[[", - "ag", - "awk", - "basename", - "bash", - "bc", - "break", - "cat", - "cd", - "chmod", - "clear", - "cmp", - "column", - "comm", - "command", - "continue", - "cp", - "curl", - "cut", - "date", - "df", - "diff", - "dig", - "dirname", - "du", - "echo", - "egrep", - "env", - "eval", - "exec", - "exit", - "expand", - "export", - "expr", - "false", - "fd", - "fgrep", - "file", - "find", - "fmt", - "fold", - "gawk", - "gh", - "git", - "grep", - "gunzip", - "gzip", - "head", - "help", - "host", - "iconv", - "id", - "jobs", - "join", - "jq", - "kill", - "killall", - "less", - "let", - "ln", - "ls", - "lsof", - "man", - "mkdir", - "mktemp", - "more", - "mv", - "nl", - "paste", - "pgrep", - "ping", - "pkill", - "popd", - "printenv", - "printf", - "ps", - "pushd", - "pwd", - "read", - "readlink", - "realpath", - "reset", - "return", - "rev", - "rg", - "rm", - "rmdir", - "sed", - "seq", - "set", - "sh", - "shuf", - "sleep", - "sort", - "source", - "split", - "stat", - "tail", - "tar", - "tee", - "test", - "time", - "timeout", - "touch", - "tr", - "tree", - "true", - "type", - "uname", - "unexpand", - "uniq", - "unset", - "unzip", - "watch", - "wc", - "wget", - "whereis", - "which", - "whoami", - "xargs", - "yes", - "yq", - "zip", - "zsh" - ], - "stack_commands": [ - "node", - "npm", - "npx", - "pnpm", - "pnpx" - ], - "script_commands": [ - "bun", - "npm", - "pnpm", - "yarn" - ], - "custom_commands": [], - "detected_stack": { - "languages": [ - "javascript" - ], - "package_managers": [ - "pnpm" - ], - "frameworks": [], - "databases": [], - "infrastructure": [], - "cloud_providers": [], - "code_quality_tools": [], - "version_managers": [] - }, - "custom_scripts": { - "npm_scripts": [ - "start", - "dev" - ], - "make_targets": [], - "poetry_scripts": [], - "cargo_aliases": [], - "shell_scripts": [] - }, - "project_dir": "/Users/billchirico/Developer/bill-bot", - "created_at": "2026-02-03T19:51:09.135836", - "project_hash": "51a4f617fc8ece9b63e20f8a9950e73b", - "inherited_from": "/Users/billchirico/Developer/bill-bot" -} \ No newline at end of file diff --git a/.auto-claude-status b/.auto-claude-status deleted file mode 100644 index d14e010f..00000000 --- a/.auto-claude-status +++ /dev/null @@ -1,25 +0,0 @@ -{ - "active": true, - "spec": "002-graceful-shutdown-handling", - "state": "building", - "subtasks": { - "completed": 1, - "total": 7, - "in_progress": 1, - "failed": 0 - }, - "phase": { - "current": "Graceful Shutdown Implementation", - "id": null, - "total": 6 - }, - "workers": { - "active": 0, - "max": 1 - }, - "session": { - "number": 3, - "started_at": "2026-02-03T20:25:33.725137" - }, - "last_update": "2026-02-03T20:29:22.574996" -} \ No newline at end of file diff --git a/.claude_settings.json b/.claude_settings.json deleted file mode 100644 index a06ca043..00000000 --- a/.claude_settings.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "sandbox": { - "enabled": true, - "autoAllowBashIfSandboxed": true - }, - "permissions": { - "defaultMode": "acceptEdits", - "allow": [ - "Read(./**)", - "Write(./**)", - "Edit(./**)", - "Glob(./**)", - "Grep(./**)", - "Read(/Users/billchirico/Developer/bill-bot/.auto-claude/worktrees/tasks/002-graceful-shutdown-handling/**)", - "Write(/Users/billchirico/Developer/bill-bot/.auto-claude/worktrees/tasks/002-graceful-shutdown-handling/**)", - "Edit(/Users/billchirico/Developer/bill-bot/.auto-claude/worktrees/tasks/002-graceful-shutdown-handling/**)", - "Glob(/Users/billchirico/Developer/bill-bot/.auto-claude/worktrees/tasks/002-graceful-shutdown-handling/**)", - "Grep(/Users/billchirico/Developer/bill-bot/.auto-claude/worktrees/tasks/002-graceful-shutdown-handling/**)", - "Read(/Users/billchirico/Developer/bill-bot/.auto-claude/worktrees/tasks/002-graceful-shutdown-handling/.auto-claude/specs/002-graceful-shutdown-handling/**)", - "Write(/Users/billchirico/Developer/bill-bot/.auto-claude/worktrees/tasks/002-graceful-shutdown-handling/.auto-claude/specs/002-graceful-shutdown-handling/**)", - "Edit(/Users/billchirico/Developer/bill-bot/.auto-claude/worktrees/tasks/002-graceful-shutdown-handling/.auto-claude/specs/002-graceful-shutdown-handling/**)", - "Read(/Users/billchirico/Developer/bill-bot/.auto-claude/**)", - "Write(/Users/billchirico/Developer/bill-bot/.auto-claude/**)", - "Edit(/Users/billchirico/Developer/bill-bot/.auto-claude/**)", - "Glob(/Users/billchirico/Developer/bill-bot/.auto-claude/**)", - "Grep(/Users/billchirico/Developer/bill-bot/.auto-claude/**)", - "Bash(*)", - "WebFetch(*)", - "WebSearch(*)", - "mcp__context7__resolve-library-id(*)", - "mcp__context7__get-library-docs(*)", - "mcp__graphiti-memory__search_nodes(*)", - "mcp__graphiti-memory__search_facts(*)", - "mcp__graphiti-memory__add_episode(*)", - "mcp__graphiti-memory__get_episodes(*)", - "mcp__graphiti-memory__get_entity_edge(*)" - ] - } -} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 05dc4523..a07e7b97 100644 --- a/.gitignore +++ b/.gitignore @@ -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/* diff --git a/src/index.js b/src/index.js index 43e4b7db..2e822665 100644 --- a/src/index.js +++ b/src/index.js @@ -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'; @@ -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(), @@ -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)...`); @@ -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();