Surface inbound GMCP packets as raw module + JSON to the delegate#7
Merged
Merged
Conversation
jaborsh
force-pushed
the
add-gmcp-received-delegate
branch
from
May 9, 2026 22:53
19f59af to
d6f1edc
Compare
There was a problem hiding this comment.
Pull request overview
Adds a new additive delegate callback to surface inbound GMCP packets as a raw module name plus payload bytes (with a convenience decoding helper), while preserving the existing GMCP→MSDP flattening fallback behavior in TelnetSession.
Changes:
- Introduces
GMCPPacket(module + raw payloadData) and an optionalTelnetSessionDelegatecallback for inbound GMCP. - Updates
processSbGmcpto call the delegate before running the existingjson2msdp/MSDP processing path. - Ignores SwiftPM build artifacts by adding
.build/to.gitignore.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| Sources/SwiftMTH/TelnetSessionDelegate.swift | Adds GMCPPacket + new optional delegate method to receive inbound GMCP as module + raw payload. |
| Sources/SwiftMTH/TelnetSession.swift | Surfaces inbound GMCP packets to the delegate prior to the existing MSDP fallback processing. |
| .gitignore | Ignores SwiftPM .build/ output directory. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jaborsh
force-pushed
the
add-gmcp-received-delegate
branch
4 times, most recently
from
May 10, 2026 00:21
f957d45 to
05f6ea7
Compare
jaborsh
force-pushed
the
add-gmcp-received-delegate
branch
from
May 10, 2026 00:24
05f6ea7 to
06c4e16
Compare
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
Adds an optional
TelnetSessionDelegatemethodtelnetSession(_:gmcpReceived:)fired fromprocessSbGmcpbefore the existingjson2msdpfallback. The delegate receives aGMCPPacketcarrying the module name plus the JSON payload, with a genericdecode<T: Decodable>(_:)helper for typed consumption.Why
Hosts that consume nested-object GMCP packages (e.g. an authentication module sending
Char.Login.Credentials { account, password, device }) can't reconstruct the payload fromMSDPManager.processVarVal, which is a flat key/value pipeline. This delegate surfaces the raw packet directly. Consumer site:The MSDP fallback path is preserved — it still runs after the delegate returns — so existing flat-var consumers (
Core.Hello, etc.) keep working unchanged. The new method has a default-empty extension implementation, so the protocol change is additive.API surface
GMCPPacket:module: String— public read; always non-emptypayload: Data— internal; consumers go throughdecode(_:)byteCount: Int— public read; lets consumers enforce size policies (e.g. drop packets > N KB) without exposing bytesdecode<T: Decodable>(_:) -> T?— returnsnilfor module-only packets (Core.Ping), throwsDecodingErroron malformed JSONinit— internal; only MTH constructs themThe delegate is not called for:
IAC SB GMCP IAC SEblocks (no body)Test plan
swift buildcleanTests/MTHTests/TelnetSessionTests.swift:Core.Ping) —decodereturnsnildecodethrowsDecodingErrorbyteCountreports the payload byte sizeMSDP {"LIST":"COMMANDS"})