Collapse iOS/macOS dual paths in MCP handlers behind PreviewSessionHandle#159
Open
Collapse iOS/macOS dual paths in MCP handlers behind PreviewSessionHandle#159
Conversation
…ndle Every multi-platform MCP tool handler hand-coded `if let iosSession = ... / else macOS ...`, with `preview_variants` carrying ~95 nearly-identical lines per branch and the still-registered guard duplicated at MCPServer.swift:1049 and :1137. Introduce a `PreviewSessionHandle` protocol with iOS and macOS adapters, plus a `SessionRouter` that resolves a session ID to whichever backend owns it. Handler dispatch becomes single-path; the macOS-specific `host.loadPreview` after `setTraits` and the 300ms layout-settle pause move into `MacOSPreviewHandle.setTraits`. MCPServer.swift drops 194 lines (1325 → 1131); the new abstractions add 214. Net +20 LOC for the collapse, but `handlePreviewVariants` shrinks 195 → 100, `handlePreviewSwitch` 84 → 47, `handlePreviewConfigure` 50 → 28, `handlePreviewStop` 41 → 23, `handlePreviewSnapshot` 51 → 22, and `configQualityForSession` 9 → 4. Step #2 of the architectural roadmap. Handler-per-file split (#1) is the follow-up. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ttle The previous commit folded the post-loadPreview pause into MacOSPreviewHandle.setTraits, which meant the variants restore step (which doesn't snapshot) also paid 300ms per call. That was negligible in isolation but compounded with CI's slower compile times — the preview_variants test on build-and-test wedged past its 60s callTool budget (44s on main → timeout on PR). Add an explicit `awaitLayoutSettle()` to PreviewSessionHandle. macOS sleeps 300ms; iOS no-ops. The variants handler calls it between setTraits and snapshot inside the loop only — restore reverts to original zero-sleep behavior. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
PreviewSessionHandleprotocol withMacOSPreviewHandleandIOSPreviewHandleadapters, plus aSessionRouteractor that resolves a session ID to whichever backend owns it.`MCPServer.swift` drops 194 lines (1325 → 1131). Per-handler shrinkage:
This is step #2 of the architectural-refactor roadmap. The follow-up handler-per-file split (#1) is now a smaller, more reviewable diff because the dual-path collapse halved the file first.
Behavior preserved
Behavior changes (intentional, minor)
Test plan
🤖 Generated with Claude Code