Repository navigation
feat: add @wolfstar/plugin-gateway with GatewayClient - #93
Conversation
◈ PR LensPR Lens paused analysis for this repository — the fair-use limit was reached. It resumes automatically at 2026-09-25T18:00:00.000Z. |
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 37555854 | Triggered | Generic High Entropy Secret | 675bbdc | packages/plugin-gateway/tests/EventGatewayListener.test.ts | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secret safely. Learn here the best practices.
- Revoke and rotate this secret.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
Important
One correctness bug found in the manager/cache layer, otherwise this is a clean, well-tested addition.
Reviewed changes
Reviewed the full diff adding @wolfstar/plugin-gateway: GatewayClient (wraps @discordjs/ws, per-shard dispatch queue, handleDispatch), the declarative DispatchHandlers table, seven CachedManager-based entity managers, six Structure-based wrappers (User, Guild, Channel, Message, GuildMember, Role), EventGatewayListener/RegisterAsGatewayListener, tests, README, package scaffolding, and workspace wiring (labeler/labels/changeset/root README).
GatewayClient: connects to the gateway, serializes dispatches per shard through a queue so an async cache can't reorder them, writes every dispatch to the optional cache, then emits the mapped event.DispatchHandlers: a single table mapping eachGatewayDispatchEventsentry to abefore(pre-cache-write, reads old state) /build(post-cache-write, constructs event args) pair — verified the ordering is correct and everyGatewayEventMaptuple shape matches whatbuildactually returns.- Managers:
CachedManagerbase withget/fetch/refreshsemantics;ChannelManagerandThreadManagershare the same REST route (Routes.channel) for two different cache buckets — see the inline comment. - Structures: thin wrappers around raw API data via
kData/kPatch/kClone, modelled on@discordjs/structuressince that package isn't usable yet (documented rationale in the README). - Verified the
discordTokennon-null assertion inGatewayClient's constructor against the installed@wolfstar/[email protected]build: the baseClientalready throws on an empty token and scrubs it fromthis.options, so it's safe.
Claude Sonnet | 𝕏
@wolfstar/plugin-api
@wolfstar/plugin-cache
@wolfstar/plugin-gateway
@wolfstar/plugin-i18next
@wolfstar/plugin-logger
@wolfstar/plugin-subcommands-advanced
commit: |
There was a problem hiding this comment.
ℹ️ No critical issues — minor suggestions inline.
Reviewed changes
Reviewed commit b58df16, a large restructure since the last Pullfrog review: flattened src/lib/* → src/*, and replaced the flat channel structure with a mixin-composed per-channel-type system.
- Confirmed the previously flagged bug (
ChannelManager.fetch()/refresh()mis-caching thread data into the"channels"bucket) is fixed:refresh()now checkschannel.isThread()and routes the cache write toclient.cache.threadsvsclient.cache.channelsaccordingly, with a regression test asserting the correct bucket. Resolved the thread. - Verified
createChannel()'s dispatch switch covers all 12 concrete channel types plus aBaseChannelfallback, and thatstructures/index.ts/structures/mixins/index.tsbarrel exports are complete. - Verified
Mixin()'s prototype-copy precedence (target wins, earlier mixin wins over later) against its dedicated test, and that the new.oxlintrc.jsondeclaration-merging override is scoped correctly tostructures/**. - Cross-checked every mixin composition list (
Mixin(X, [...])) against the actual fields in[email protected]'s vendored.d.tsfor the correspondingAPIXChanneltype — found two channel types that are missing a slowmode getter their underlying API payload actually carries (see inline comments). - Spot-checked
GatewayClient.ts,CachedManager.ts,util/decorators.ts,util/dispatch.ts,util/events.ts,util/container.ts,util/cache.ts,util/cdn.ts,EventGatewayListener.ts,exports/rest.ts/exports/ws.ts,package.json,.oxlintrc.json, root/package-gatewayREADME,.changeset,.github/labeler.yml/labels.yml,tsconfig.json,tsdown.config.ts, all remaining structure and mixin files, and both test files — all consistent with the refactor, no regressions from the prior review.
Claude Sonnet | 𝕏
There was a problem hiding this comment.
Important
One dependency/engines inconsistency to fix, plus an architectural question worth discussing before this grows further.
Reviewed changes
Reviewed commit a06592f, which pivots @wolfstar/plugin-gateway's Structure base to actually extend @discordjs/structures' private BaseStructure (via shared Symbol.for("djs.structures.data"/"patch"/"clone") registry keys) instead of hand-rolling it, and adds a cluster of supporting pieces:
Structure.ts: rewritten to extend@discordjs/structures'Structurethrough the well-known symbol trick, since that package'skData/kPatch/kClonesymbols aren't exported. Installed the real dev-preview dependency and ran the fullplugin-gatewaytest suite against it (45/45 passing) to confirm the symbol keys actually line up with the installed package rather than trusting the pattern on inspection alone.Role.ts: now declares aDataTemplate/Omitted/Partialize<Data, Omitted>triple, matching the convention every@discordjs/structuressubclass follows upstream — correct pattern, currently applied to only one structure (see inline nit).- New
Typing.tsstructure andTYPING_STARTdispatch/event wiring — cross-checkedGatewayTypingStartDispatchData.memberand theGuildMemberconstruction against the vendored[email protected]payload shapes, looks correct. - New
flags.ts/PermissionsBitField.ts/bitfield.test.ts: abigint-backedBitFieldwrapper (NumberFlagsBitField) coercing 32-bit flag enums tobigint, again modelled on@discordjs/structures'sBitField. - New
messages.ts,events.tsadditions,events.test.ts,package.json/pnpm-lock.yamlupdates. - Confirmed
pnpm build(tsdown + attw + publint) andpnpm lint(oxlint/oxfmt) both pass clean on the new code. - The previously open review threads on
AnnouncementChannel.tsandForumChannel.ts(slowmode mixin gaps) are on files untouched by this commit, so they're left open rather than retired.
⚠️ Hand-rolled channel/mixin system now duplicates what @discordjs/structures already ships
Now that @discordjs/structures is a real runtime dependency (not just a documented rationale for why it "isn't usable yet"), it already ships fully-built AnnouncementChannel, TextChannel, ForumChannel, MediaChannel, DMChannel, CategoryChannel, StageChannel, VoiceChannel, GroupDMChannel, and thread channel classes, plus the same-named mixins (Mixin(), ChannelSlowmodeMixin, etc.) that packages/plugin-gateway/src/structures/* hand-rolls independently.
Technical details
Two concrete signals that these have drifted apart rather than merely being parallel implementations:
- Upstream's
AnnouncementChannelalready composesChannelSlowmodeMixin— exactly the gap flagged as still-open in review threadPRRT_kwDOTNxric6lkENaon wolfstar's ownAnnouncementChannel.ts. Building on the dependency instead would have gotten this for free. - Upstream's
ForumChannel/MediaChanneldo not compose a slowmode mixin either, so that half of the open nit (threadPRRT_kwDOTNxric6lkENe) isn't unique to wolfstar's implementation — it's a gap shared with upstream.
This isn't a request to rewrite the channel/mixin layer in this PR — the Structure base pivot alone is a meaningful, well-tested step. But worth deciding deliberately: continue hand-rolling Channel subclasses/mixins that duplicate (and can silently diverge from) what the dependency already provides, or migrate to importing them directly now that the package is pulled in for real? Since Guild/GuildMember aren't shipped upstream, a full migration isn't a drop-in win — but the channel side looks like it could be.
Claude Sonnet | 𝕏
❌ 4 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
There was a problem hiding this comment.
ℹ️ No new issues — this round is a single test-infrastructure fix, verified by running the suite.
Reviewed changes
Reviewed the one commit since the last Pullfrog review (9a68506), which resolves @wolfstar/plugin-cache to its sources in the shared Vitest config.
- Added a
@wolfstar/plugin-cachealias to rootvitest.config.ts: an anchored regex (/^@wolfstar\/plugin-cache$/) now redirects the bare specifier topackages/plugin-cache/src/index.tsinstead of its builtdist/esmoutput, soplugin-gateway's tests exercise the cache package's current source instead of depending on a prior build step. - Confirmed the fix does what it claims: ran
plugin-gateway's suite against a workspace withpackages/plugin-cache/dist/absent (unbuilt) — all 5 test files / 45 tests passed, where they previously failed with "Failed to resolve entry for package".plugin-cache's own suite (23 tests) is unaffected. The regex is anchored to the exact bare specifier andplugin-cacheonly ships a single"."export, so there's no subpath-import case this alias misses.
Claude Sonnet | 𝕏
9a68506 to
d556ca1
Compare
There was a problem hiding this comment.
ℹ️ No new issues — this round is a small dependency-alignment chore, verified against the real upstream changelog and the installed package's types rather than taken on faith.
Reviewed changes
Reviewed commit d556ca1 — the only genuinely new commit since the last review; the base branch (feat/plugin-cache) was rebased forward in between, which rewrote every other commit's SHA without changing its content (confirmed via git diff --stat against the previous review's commit).
packages/plugin-gateway/package.jsonbumps the@wolfstar/http-frameworkdevDependency^3.4.0→^5.1.0and widens thepeerDependenciesrange to"^3.4.0 || ^5.0.0"(pnpm-lock.yamlupdated to match).- Checked this against the real upstream changelog (
wolfstar-project/stars-components/packages/http-framework/CHANGELOG.md) for every major crossed: 4.0.0 only changes CLI/build-tooling defaults; 5.0.0 addsClient#fetch()(additive) and removes/replaces the/fetchsubmodule and/config'sConfigError— both confirmed absent fromplugin-gateway's imports via grep; 5.1.0 splitsstars.configloading into a new package, re-exported unchanged. - Cross-checked the installed
@wolfstar/[email protected]build's.d.tsdirectly: every surfaceGatewayClientdepends on (Client extends AsyncEventEmitter<MappedClientEvents>,ClientOptions.discordToken,readonly logger: ILogger,load(),listen()) is unchanged and marked@since 3.4.0. - The
engines.nodefield on the samepackage.json(still">=20.0.0", the open thread below) was untouched by this commit.
The 5 threads from prior rounds remain open — none of their files (AnnouncementChannel.ts, ForumChannel.ts, package.json's engines block, README.md, Role.ts) were touched by this commit, so they carry forward unchanged.
Claude Sonnet | 𝕏
d556ca1 to
117215a
Compare
|
Your Claude subscription has hit its usage limit. It resets at 7:20pm (UTC). Re-trigger Pullfrog after the reset, or add an Add repo secret → · Model settings → · Setup docs → · Ask in Discord →
|
Implements the Gateway RFC: GatewayClient extends the framework Client with a @discordjs/ws connection, cache-backed managers, events carrying structures, and EventGatewayListener/RegisterAsGatewayListener. Refs #54
… channel structures Flatten src/ into GatewayClient, managers/, structures/ (with mixins/) and util/, one class per channel type composed through Mixin(), a ThreadManager, CDN URLs from @discordjs/rest, and /ws and /rest subpath re-exports.
…ructures Structures extend @discordjs/structures' Structure, reaching its kData/kPatch/kClone through the Symbol.for registry. Bitfields come from it too, with a resolve override working around number flag values mixed with bigint bits. Adds typingStart, channelPinsUpdate, webhooksUpdate and voiceServerUpdate events. Refs #54
CI runs vitest right after install, so the gateway tests failed to resolve the unbuilt plugin-cache dist.
…a channels Also require Node.js 24.17 like @discordjs/structures, and describe how Structure builds on it.
117215a to
7ebe6c5
Compare
|
Your Claude subscription has hit its usage limit. It resets at 7:20pm (UTC). Re-trigger Pullfrog after the reset, or add an Add repo secret → · Model settings → · Setup docs → · Ask in Discord →
|

Stacked on #92.
🔗 Linked issue
Resolves #54
🧭 Context
@wolfstar/http-frameworkonly talks to Discord through the interactions endpoint, so a bot has no way to react toMESSAGE_CREATE, member updates, or anything else that only exists on the gateway. Today that means pulling in a second framework or hand-rolling a WebSocket client. The RFC in #54 proposes aGatewayClientthat extendsClientrather than wrapping it, so existing commands, handlers,load()andlisten()keep working unchanged.📚 Description
@wolfstar/plugin-gatewaywraps@discordjs/wsfor the connection. Every dispatch goes into the optional cache from #92, and the matching event is emitted with Structures instead of raw JSON. Dispatch-to-event mapping is a single declarative table (DispatchHandlers), type-checked againstGatewayEventMap, per the RFC's point about not hand-writing aswitchper event.The biggest deviation from the RFC: it planned to extend
@discordjs/structures, but that package is only published asdevsnapshots, requires Node 24.17, and doesn't exportkData/kPatch. The RFC's ownUser extends Structuresnippet can't compile against it, and there's noGuildorGuildMemberyet. So the package ships a smallStructurebase modelled on theirs, with the symbols exported so it can be subclassed. Worth revisiting once theirs reaches 1.0.How I answered the RFC's open problems:
emitter: 'client'works as-is: the baseClientsetscontainer.client = thisin its constructor.RegisterAsGatewayListenercopies the constructor-wrapping mechanism ofRegisterAsSubcommand.INTERACTION_CREATEis dropped unconditionally. It still shows up in therawevent.WorkerShardingStrategycan be passed throughgateway.buildStrategy, but I haven't tried it.GatewayClient. Shard options follow@discordjs/ws(shardCount,shardIds) instead of the RFC'sshards: number | number[] | 'auto', which was ambiguous about the total count.Left open: interaction handlers still read the raw interaction payload and don't go through
client.users. Same for the question of whether these packages belong instars-componentsinstead.Key changes
GatewayClientClient+ gateway connection,connect()/destroy()users,guilds,channels,threads,messages,members,rolesget(cache),fetch(cache then REST),refresh(REST)User,Guild,Channel,Message,GuildMember,RoleStructure/kData/kPatch/kCloneEventGatewayListener,RegisterAsGatewayListeneronceType of Change
Pre-flight Checklist
pnpm changeset(orpnpm changeset add --emptyif no release is needed). See .changeset/README.md.