Extract PreviewsEngine library target from PreviewsCLI monolith#121
Merged
obj-p merged 2 commits intocli-mcp-parityfrom Apr 16, 2026
Merged
Extract PreviewsEngine library target from PreviewsCLI monolith#121obj-p merged 2 commits intocli-mcp-parityfrom
obj-p merged 2 commits intocli-mcp-parityfrom
Conversation
Creates a new `PreviewsEngine` library containing the business logic that has no MCP or ArgumentParser dependency: Moved from MCPServer.swift: - IOSState → IOSSessionManager (public actor) - ConfigCache (public actor) - traitsSummary, formatPreviewList (public functions) - cleanupStaleTempDirs (public function) Moved from BuildHelpers.swift (entire file): - StderrProgressReporter, loadProjectConfig, buildSetupFromConfig, detectAndBuild, resolveDeviceUDID PreviewsEngine depends on PreviewsCore, PreviewsMacOS, PreviewsIOS. It does NOT depend on MCP or ArgumentParser — it can be consumed independently for embedding preview capabilities in any Swift app. Injection changes: - configureMCPServer now takes (host:iosManager:configCache: sharedCompiler:) — all engine instances are injected rather than created internally. - DaemonListener.start creates ONE shared IOSSessionManager and ConfigCache for all connections (preserves session persistence across CLI invocations). - ServeCommand.runStdio creates its own instances (single-connection mode, no sharing needed). - MCPServer.swift stores the injected instances in nonisolated(unsafe) file-private vars (set-once-before-use pattern, Swift 6 requires the annotation). MCPServer.swift is ~100 lines shorter. Everything that remains in it depends on MCP types (CallTool.Parameters, Server, Value). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Critical: - NoSimulatorError now conforms to LocalizedError with errorDescription (was CustomStringConvertible, which causes localizedDescription to return the generic "operation could not be completed" per AGENTS.md convention). Important: - Removed PreviewsMacOS from PreviewsEngine's Package.swift dependencies — no engine file imports it. Engine stays platform-agnostic. - Deleted orphaned doc comment in MCPServer.swift (leftover from cleanupStaleTempDirs extraction). - Updated DaemonListener doc comment: IOSState → IOSSessionManager, module-level → shared instances. Co-Authored-By: Claude Opus 4.6 (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
PR 1 of the package rearchitecture (plan at
.claude/plans/package-rearchitecture.md). Creates a newPreviewsEnginelibrary target containing business logic that has no MCP or ArgumentParser dependency.What moved to PreviewsEngine
IOSState→IOSSessionManager(public actor)ConfigCache(public actor)traitsSummary,formatPreviewList(public functions)cleanupStaleTempDirs(public function)BuildHelpers.swift(entire file:StderrProgressReporter,loadProjectConfig,detectAndBuild,resolveDeviceUDID,buildSetupFromConfig)What stays in PreviewsCLI
Dependency graph
Injection
configureMCPServer(host:iosManager:configCache:sharedCompiler:)— all engine instances injectedDaemonListener.startcreates ONE sharedIOSSessionManager+ConfigCachefor all connectionsServeCommand.runStdiocreates its own instances (single-connection)Test plan
swift build— cleansimulators,list --json,statusall work through the daemon🤖 Generated with Claude Code