Skip to content

Add switch command for changing active #Preview in a live session#104

Merged
obj-p merged 2 commits intocli-mcp-parityfrom
switch-command
Apr 15, 2026
Merged

Add switch command for changing active #Preview in a live session#104
obj-p merged 2 commits intocli-mcp-parityfrom
switch-command

Conversation

@obj-p
Copy link
Copy Markdown
Owner

@obj-p obj-p commented Apr 15, 2026

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.

  • `@State` resets; traits (color scheme, dynamic type, locale, …) persist.
  • Session resolution mirrors `configure`/`snapshot` (`--session` > `--file` > sole-running).
  • No ephemeral fallback — switching a session that doesn't exist is an error.
  • Client-side validation rejects negative indices before the RPC.

Test plan

4 new tests in `SwitchCommandTests`:

  • Negative index rejected locally
  • No session → descriptive error
  • Happy-path round-trip — snapshot preview 0, switch to preview 1, snapshot, assert byte diff
  • Out-of-range index surfaces the daemon's error

Regression:

  • All daemon-touching suites still green

Stack

🤖 Generated with Claude Code

obj-p and others added 2 commits April 15, 2026 12:13
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>
@obj-p obj-p merged commit b045cee into cli-mcp-parity Apr 15, 2026
@obj-p obj-p deleted the switch-command branch April 15, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant