refactor(transport): extract oversized helpers and clean discovery tags#41
Merged
ContextVM-org merged 9 commits intoContextVM:masterfrom Apr 21, 2026
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the Nostr transport layer by extracting previously inlined/duplicated logic into focused internal submodules, reducing file size and improving separation of concerns while preserving existing behavior (plus a small capability-flag fix).
Changes:
- Extracted CEP-22 oversized transfer sending/handling into dedicated client/server helper modules.
- Extracted client relay resolution (configured/hint/discovery/fallback probing) into a standalone resolver.
- Consolidated discovery tag helpers and introduced a dedicated server-side peer capability learner (including a fix where
oversizedEnabled=falsenow correctly disables oversized capability learning).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/transport/nostr-server/oversized-server-handler.ts | New helper for publishing oversized server responses + CEP-22 accept frames. |
| src/transport/nostr-server/capability-learner.ts | New helper to learn peer capability flags from inbound tags (includes bug fix). |
| src/transport/nostr-server-transport.ts | Rewired server transport to use extracted oversized sender/accept + capability learner. |
| src/transport/nostr-client/relay-resolution.ts | New module for operational relay resolution logic extracted from client transport. |
| src/transport/nostr-client/oversized-client-sender.ts | New helper for publishing oversized client requests (CEP-22 frames + accept wait). |
| src/transport/nostr-client-transport.ts | Uses extracted relay resolution + oversized client sender; removes inlined logic. |
| src/transport/discovery-tags.ts | Centralizes tag helpers (hasSingleTag, hasEventTag) and keeps discovery parsing/merge utilities. |
| src/core/utils/utils.ts | Removes tag helper exports that were moved into discovery-tags.ts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…module Move the PeerCapabilities interface and learnPeerCapabilities function from the separate capability-learner.ts file into discovery-tags.ts. This consolidates all discovery tag parsing logic in one place and simplifies the capability detection by handling the oversizedEnabled check in the caller. The capability-learner.ts file is now redundant and has been deleted.
Contributor
|
I removed the src/transport/nostr-server/capability-learner.ts and consolidated it in the src/transport/discovery-tags.ts |
Add unit tests for sendOversizedClientRequest and sendOversizedServerResponse functions, covering accept frame waiting behavior and frame publishing with correct tags. Also refactor OversizedServerHandlerDeps into separate OversizedServerResponseDeps and OversizedAcceptFrameDeps interfaces for better separation of concerns.
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.
Closes #40
What
Post-merge cleanup for #35. Extracts focused submodules from the two largest
transport files without changing any public API or behavior.
Why
After the CEP-22 oversized transfer feature landed, both main transport files
exceeded the project's ~700 LOC guideline at ~1,140 LOC each. Several
self-contained concerns were inlined that are better expressed as dedicated
modules following the existing extraction pattern (
correlation-store.ts,stateless-mode-handler.ts,session-store.ts).Changes
New modules
discovery-tags.tshasSingleTag,hasEventTag,parseDiscoveredPeerCapabilities,mergeDiscoveryTags) — previously duplicated across both transportsnostr-client/oversized-client-sender.tsNostrClientTransport.sendOversizedRequestnostr-client/relay-resolution.tsresolveOperationalRelayHandlernostr-server/oversized-server-handler.tssendOversizedServerResponse+sendAcceptFramefor CEP-22 server-side frame publishingnostr-server/capability-learner.tslearnPeerCapabilities— inspects inbound tags to learn peer support flagsModified files
nostr-client-transport.tsnostr-server-transport.tsdiscovery-tags.tsBug fix
capability-learner.ts: Fixed dead ternary where theoversizedEnabledparameter had no effect — both branches were identical. The
falsebranchnow correctly returns
false.Cleanup
hasKnownDiscoveryTagandhasDiscoveryTagsfromdiscovery-tags.ts(exported but never imported).KNOWN_DISCOVERY_TAGSconstant.Design decisions
*Deps/*Config), not classinheritance. Follows the existing pattern in
correlation-store.tsandannouncement-manager.ts.src/transport/index.ts.extracted logic is exercised through the same integration paths.
Verification
bun run buildbun test src/transport/— 158 pass, 0 failindex.ts