Skip to content

feat(plugin-gateway): add ClientApplication and client.application - #238

Merged
kodiakhq[bot] merged 2 commits into
mainfrom
t3code/implement-issue-208
Oct 9, 2026
Merged

kodiakhq[bot] merged 2 commits into
mainfrom
t3code/implement-issue-208

Conversation

@RedStar071

Copy link
Copy Markdown
Member

🔗 Linked issue

Resolves #208

🧭 Context

@wolfstar/plugin-gateway had no Application/ClientApplication, so there was no client.application. In discord.js it is the entry point for everything the application owns rather than a guild, and #207 (ApplicationEmoji, ApplicationCommand and their managers) cannot land without it. This is that prerequisite on its own.

📚 Description

Adds client.application, a ClientApplication modeled on discord.js's, plus the Application, Team and TeamMember structures it needs.

  • client.application is built in the GatewayClient constructor from clientId, so it exists before READY and without a gateway connection. It is partial (only id known) until fetch() or edit() resolves. READY patches the same instance in place with the application's flags, so references held by user code stay valid, and broker workers that never see READY still have it.
  • It lives on the client and not in @wolfstar/plugin-cache: it is one small object per client, has no gateway update event, and every process gets the same READY.
  • owner is the Team (members as TeamMembers) when a team owns the application, the owner User bound to the client otherwise.
  • Methods: fetch() (GET /applications/@me), edit() (PATCH /applications/@me, images through resolveImageOption), fetchRoleConnectionMetadataRecords() and editRoleConnectionMetadataRecords(), with camelCased records like discord.js.
  • No placeholder commands/emojis/entitlements properties: plugin-gateway: port ApplicationEmoji (with its manager) and ApplicationCommand (discord.js parity) #207 and the entitlements work add those getters themselves.

Departures from the Pullfrog plan, and from discord.js:

  • client.application is typed non-null, discord.js types it nullable. This follows the plan (clientId is a required option) and is a superset of discord.js's behavior. The three open points of the plan (non-null application, Team/TeamMember shipped here, cache stays on the client) were taken as recommended.
  • Application#name is string | null (and toString() falls back to the id) because the partial application has no name.
  • The plan suggested checking whether @wolfstar/http-framework exposes the public key. It is not needed: nothing here uses it, and verify_key stays available from fetch() through the raw data.

Key changes

Area Change
structures/applications/ New Application, ClientApplication, Team, TeamMember, exported from the package
GatewayClient New readonly application, built from clientId
util/dispatch.ts READY patches client.application in place
Tests tests/applications.test.ts (9 tests) and tests/types/application.ts
Docs README "Application" section, and the replay note
Release minor changeset for @wolfstar/plugin-gateway

Verification, run locally: pnpm build and pnpm typecheck pass, pnpm test passes (121 files, 1688 tests). oxlint reports no errors and oxfmt --check passes on the files of this PR. The repo-wide pnpm lint fails oxfmt --check on a Windows checkout only because its working-tree files are CRLF; I did not touch them.

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation change
  • Workflow / CI change

Pre-flight Checklist

  • I have read the Contributing Guidelines (if applicable)
  • My code follows the code style of this project
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly
  • I added a changeset with pnpm changeset (or pnpm changeset add --empty if no release is needed). See .changeset/README.md.

🤖 AI disclosure: Claude Code was used on this PR. Code written with claude-sonnet-5-5; PR description written with claude-sonnet-5-5. AI policy.

Add the Application, ClientApplication, Team and TeamMember structures,
like discord.js. client.application is built from clientId when the client
is, so it exists before READY (partial); READY patches the same instance
with the flags and fetch() with the rest. Also add fetch, edit and the
role connection metadata methods.

Refs #208
@coldtea-pr-lens

coldtea-pr-lens Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Nothing flagged · reviewed ee3a210


Architecture

Architecture diagram for wolfstar-project/plugins at ee3a210

Play the walkthrough


Inside the changed components — 2 views

Component view — Client Application Lifecycle

Lifecycle, event patching, and API synchronization of ClientApplication within Gateway Client

Architecture view of Component view — Client Application Lifecycle in wolfstar-project/plugins

Component view — Application Ownership and Teams

Team and member domain structures modeling application ownership

Architecture view of Component view — Application Ownership and Teams in wolfstar-project/plugins

Data flow

Data flow diagram for wolfstar-project/plugins at ee3a210

Follow each request


Tip

The diagrams are links. Click one to open it on the canvas, then press W or click play to walk through the change

🪧 More tips
  • Run npx skills add coldteadotai/pr-lens, then tell your coding agent: "Diagram the change you just made with PR Lens and attach it to the pull request."
  • Run npx @coldtea/pr-lens-cli analyze --base origin/main on a branch, then npx @coldtea/pr-lens-cli render .pr-lens/graph.json. Same lenses, your own model key, before the pull request exists
  • Click the link under each diagram to open it on a canvas you can zoom, pan and step through
  • Open a diagram on the canvas, then press W or click play to walk through the change one step at a time
  • The CLI's render reads .github/pr-lens.yml and applies your renames, exclusions and lane pins at draw time
  • Set github.comment.collapsed: true in .github/pr-lens.yml to fold the comment behind one View architecture and data flow row. Drawing still runs as before
  • Set github.draw: on-demand in .github/pr-lens.yml and PR Lens stops drawing pull requests on its own. Comment @pr-lens draw on a pull request when you want that one drawn
  • Add .github/workflows/pr-lens.yml with coldteadotai/pr-lens/packages/action@v0 and your model provider's key as its api-key to run PR Lens from your own CI. Any /chat/completions endpoint works
  • Push a commit and the drawing stays, with a note that it is out of date. Tick Redraw in the note to draw the new head
  • Switch GitHub to dark mode and the diagrams follow. The moving dots are this pull request's data in motion

Thanks for using PR Lens! It's built by Coldtea, free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

@wolfstarbot wolfstarbot added the packages:plugin-gateway Changes in plugin-gateway label Oct 9, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one minor suggestion inline.

Reviewed changes

Reviewed the full diff of the single commit, and checked the @discordjs/core and @discordjs/rest typings the new code calls.

  • client.application: built in the GatewayClient constructor from the client ID, so it exists before READY, and READY patches the same instance in place.
  • ClientApplication / Application: partial-aware getters, fetch(), edit() (images through resolveImageOption), and role connection metadata records with camelCased fields.
  • Team / TeamMember: memoized per payload, with owner the team's TeamMember when it is among the members.
  • Tests, docs, changeset: tests/applications.test.ts, a type-level test, the README section and a minor changeset.

getCurrent, editCurrent, getMetadataRecords, updateMetadataRecords, CDN#appIcon and CDN#teamIcon all exist in the installed typings, and the shallow-merge kPatch matches how READY (id and flags only) is applied. I found no correctness problems.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using claude-sonnet-5-5 | 𝕏

The owner Team, its members and their users were not bound to the client
that built them, so their client fell back to the most recently
constructed GatewayClient. Bind the team like the owner user, and have
Team#members pass the client on to each TeamMember.
@pkg-pr-new

pkg-pr-new Bot commented Oct 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

@wolfstar/plugin-api

pnpm add https://pkg.pr.new/@wolfstar/plugin-api@238

@wolfstar/plugin-broker

pnpm add https://pkg.pr.new/@wolfstar/plugin-broker@238

@wolfstar/plugin-cache

pnpm add https://pkg.pr.new/@wolfstar/plugin-cache@238

@wolfstar/plugin-gateway

pnpm add https://pkg.pr.new/@wolfstar/plugin-gateway@238

@wolfstar/plugin-i18next

pnpm add https://pkg.pr.new/@wolfstar/plugin-i18next@238

@wolfstar/plugin-logger

pnpm add https://pkg.pr.new/@wolfstar/plugin-logger@238

@wolfstar/plugin-scheduled-tasks

pnpm add https://pkg.pr.new/@wolfstar/plugin-scheduled-tasks@238

@wolfstar/plugin-sharder

pnpm add https://pkg.pr.new/@wolfstar/plugin-sharder@238

@wolfstar/plugin-subcommands-advanced

pnpm add https://pkg.pr.new/@wolfstar/plugin-subcommands-advanced@238

commit: ee3a210

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Reviewed the incremental commit since the prior pullfrog review (11f7e3b).

  • Owner bound to the client: ClientApplication#owner now binds both the Team and the owner User to the client with bindClient.
  • Members bound to the client: Team#members passes kClient on to each TeamMember, so TeamMember#user is bound too.
  • Test coverage: the team application test asserts .client === client on the application, its owner and the owner's user.

Pullfrog  | View workflow run | Using claude-sonnet-5-5 | 𝕏

@kodiakhq
kodiakhq Bot merged commit 74ef5dd into main Oct 9, 2026
18 checks passed
@kodiakhq
kodiakhq Bot deleted the t3code/implement-issue-208 branch October 9, 2026 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages:plugin-gateway Changes in plugin-gateway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugin-gateway: add ClientApplication and client.application (discord.js parity)

2 participants