refactor: replace hand-rolled WebSocket gateway with discord.js#61
Open
justmaker wants to merge 6 commits intomoazbuilds:masterfrom
Open
refactor: replace hand-rolled WebSocket gateway with discord.js#61justmaker wants to merge 6 commits intomoazbuilds:masterfrom
justmaker wants to merge 6 commits intomoazbuilds:masterfrom
Conversation
- config.ts: Remove reference to undefined `discordUserIds` variable in parseSettings(). Use raw.discord.allowedUserIds directly instead. - runner.ts: Keep `settings` variable in execClaude() scope so the later `(settings as any).sessionTimeoutMs` reference resolves. Previously, getSettings() was destructured directly, leaving `settings` undefined. Co-authored-by: Rex Hsu <rexhsu@qnap.com>
* feat: multi-session thread support for Discord - New sessionManager.ts: per-thread session lifecycle (CRUD, turn tracking, compact warnings) - runner.ts: per-thread queues enabling parallel execution across threads - discord.ts: thread detection via gateway events, auto-session routing, cleanup on archive/delete - /status shows thread session count and details - README.md: added multi-session threads section - docs/MULTI_SESSION.md: full technical documentation Backward compatible: non-thread messages use global session as before. * feat: hire/fire thread commands - 'hire <name>' creates a Discord thread with auto-session - 'fire <name>' deletes thread and cleans up session - Also supports Chinese: 建立/開, 刪除/關 --------- Co-authored-by: Rex Hsu <rexhsu@qnap.com>
Let Claude CLI create the session on first message, runner.ts captures the real UUID and saves it to sessions.json.
Bot must be a thread member to receive messages. After restart, bot loses thread membership. Now rejoins all threads from sessions.json on GUILD_CREATE.
Discord gateway RESUMED events don't trigger GUILD_CREATE, so thread membership was lost on lightweight reconnects. Now rejoin threads on both GUILD_CREATE and RESUMED.
- Use discord.js Client for gateway management (heartbeat, reconnect, resume, thread membership) — all handled automatically - Keep all business logic unchanged (handlers, intent classifier, thread management, slash commands) - Auto-join new threads via ThreadCreate event - Periodic 5-min thread rejoin still in place as safety net - ~80 fewer lines of code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the hand-rolled WebSocket gateway (~330 lines) with discord.js v14
Client, which automatically handles:What changed
sendWs,sendHeartbeat,startHeartbeat,stopHeartbeat,resetGatewayState,sendIdentify,sendResume,connectGateway,handleGatewayPayload,handleDispatchClientwith event listeners forMessageCreate,InteractionCreate,GuildCreate,ThreadCreate,ThreadDelete,ThreadUpdate,ThreadListSyncWhy
The hand-rolled gateway had persistent issues with thread liveness after reconnects —
RESUMEDevents don't triggerGUILD_CREATE, causing thread membership loss. discord.js handles all of this automatically.Dependencies
This PR builds on top of #60 (core fixes & multi-session support).
Testing
Running in production. Gateway reconnects, thread membership, and message delivery all working correctly.