Add switch command for changing active #Preview in a live session#104
Merged
obj-p merged 2 commits intocli-mcp-parityfrom Apr 15, 2026
Merged
Add switch command for changing active #Preview in a live session#104obj-p merged 2 commits intocli-mcp-parityfrom
obj-p merged 2 commits intocli-mcp-parityfrom
Conversation
Fifth PR in the CLI/MCP parity stack. \`previewsmcp switch <index>\` forwards to the daemon's \`preview_switch\` MCP tool — recompiles the session with a different #Preview block selected. @State is reset; traits (color scheme, dynamic type, locale, …) persist across the switch. Session targeting mirrors \`configure\` and \`snapshot\`: - \`--session <uuid>\` — explicit - \`--file <path>\` — resolve by source file - no flag — use the sole running session As with \`configure\`, switching a session that doesn't exist is an error (no ephemeral fallback — a switch only makes sense against a live session). Client-side validation rejects negative indices before the RPC round trip. Out-of-range positive indices surface the daemon's "No preview at index N" error. Tests (4): negative-index validation, no-session error path, happy- path round trip (snapshot preview 0, switch to 1, snapshot, assert different bytes), and out-of-range-index error. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The review of PR #104 flagged that textFromContent was now duplicated across SessionResolver, SnapshotCommand, ConfigureCommand, and SwitchCommand (4 files) — past the rule-of-three, worth extracting. Adds MCPContentHelpers.swift with an extension on [Tool.Content]: extension Array where Element == Tool.Content { func joinedText() -> String { ... } } Call sites become `response.content.joinedText()` instead of `textFromContent(response.content)`. Reads slightly better at the call site as a property-like accessor, matches the shape future commands (elements, touch, stop, simulators) will want. No behavior change — the four private helpers were byte-identical. All 35 daemon-touching tests still pass. 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
Fifth PR in the CLI/MCP parity stack. Adds `previewsmcp switch ` — forwards to the daemon's existing `preview_switch` MCP tool to recompile the session with a different `#Preview` block selected.
Test plan
4 new tests in `SwitchCommandTests`:
Regression:
Stack
🤖 Generated with Claude Code