Repository navigation
feat: shared broker-core for both brokers (0.3.0) - #2
Merged
Merged
Conversation
Co-Authored-By: Claude & Lothrop (cycle.five@proton.me)
Co-Authored-By: Claude & Lothrop (cycle.five@proton.me)
Co-Authored-By: Claude & Lothrop (cycle.five@proton.me)
Co-Authored-By: Claude & Lothrop (cycle.five@proton.me)
…nd the error catch Co-Authored-By: Claude & Lothrop (cycle.five@proton.me)
Co-Authored-By: Claude & Lothrop (cycle.five@proton.me)
…ng-token answer Co-Authored-By: Claude & Lothrop (cycle.five@proton.me)
… weaker assertions from final review Co-Authored-By: Claude & Lothrop (cycle.five@proton.me)
…to broker-core Co-Authored-By: Claude & Lothrop (cycle.five@proton.me)
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.
What this is
discord-brokerandgithub-brokerwere the same program written twice, and in two weeks the copies had drifted: one had hardening the other lacked. This pull request puts everything both use into one package,packages/core(broker-core), so it exists once. It is step two ofdocs/superpowers/specs/2026-11-19-brokers-monorepo-design.md; step one (#1) was the workspace layout.Released as 0.3.0. It deploys over 0.2.0 with no migration: same Workers, URLs, KV namespaces and secrets, and nobody signs in again.
Design
Core holds only what both brokers use today; nothing is shaped for a third.
broker-corehandleMcp(the MCP server), taking the tool list and acallfunctionsrc/mcp.ts, byte-identical in bothvalidateArgs,truncate,ToolInputErrortools.tsno-store, escaping)auth.tshandleAuthorize,handleCallback, PKCE, behind aSignInProviderinterfaceauth.tscreateBroker: OAuth roles, routes, per-request allowlist re-check, top-level error catchindex.tsjsonandauditedFeedfor the internalFeedentrypointfeed.tsVERSION,publicUrl,required,base64url; test support (MemoryKV, thecloudflare:workersstub)Each broker keeps its API client, its tools and
callTool, itsFeedroutes, and a smallsrc/signin.tsimplementingSignInProvider(authorize URL, code exchange and token revocation, allowlist, config check). A broker'sindex.tsis now onecreateBroker({...})call plusexport { Feed }. Core exports TypeScript source; wrangler bundles it from the workspace, so there is no build step.The sign-in flow and router were taken from Discord's code, the more complete of the two, and moved rather than rewritten.
Behaviour that changes, on purpose
GitHub broker gains what Discord already had:
DISABLE_CIMD="true"makes clients register instead of using a client ID metadata document; an unfetchable metadata document gets an explanatory 502 page.authorize_error,authorize_exception,sign_in_cancelled,config_error,oauth_endpoint,unhandled.Discord broker:
Feedno longer echoes an exception's message in the response body. The status is kept (the upstream status for a Discord API error, otherwise 500), the body is generic, the detail goes to the log line. A missing bot token is answered the same way.Feed's audit line gainsmethod:{ event, method, path, status, ms }, as GitHub's already was.Feed's JSON answers sendContent-Type: application/json; charset=utf-8(was without the charset).Both:
{ id, username }/{ login, id }; was{ username }/{ login }). The props themselves are unchanged.sign_inandsign_in_refusedlog lines carryidas a string.VERSIONin core, checked by a test against everypackage.json.What does not change
discord,github), issuer, resource, endpoint paths and token lifetime are identical. The final review ran both versions against one shared KV store, for both brokers: a token and a refresh token issued by 0.2.0 work on this branch with the same props; removing the user from the allowlist refuses the old token; and tokens issued by this branch work on 0.2.0, so a rollback is safe.Feed: every path, status code and non-exception answer shape.Checked
npm run typecheckclean; tests: broker-core 48, discord-broker 65, github-broker 51.flow.test.ts, which drives the real Worker entry through the real OAuth library, passes with nothing changed in it except the sharedMemoryKVimport and tests added.wrangler deploy --dry-runbuilds both bundles with core included.After merge
Deploy all four Workers, verify (banners, OAuth metadata against the saved 0.2.0 metadata, a tool call through the already-connected connectors, mailroom's polling), then tag
v0.3.0and release.🤖 Generated with Claude Code
https://claude.ai/code/session_017zqkE8grD6nh1bNnb2r1X8