Skip to content

Add preview_playground tool and fix build system detection - #38

Merged
obj-p merged 5 commits into
mainfrom
playground-and-detection-fix
Mar 22, 2026
Merged

Add preview_playground tool and fix build system detection#38
obj-p merged 5 commits into
mainfrom
playground-and-detection-fix

Conversation

@obj-p

@obj-p obj-p commented Mar 21, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #27. Adds a playground feature for quick SwiftUI prototyping — no project setup needed. Also fixes a build system detection bug found during development.

Playground

  • MCP tool preview_playground: Creates a temp Swift file (with provided code or default skeleton), starts a preview session, returns the file path so the agent can edit it for hot-reload
  • CLI command previewsmcp playground: Creates a temp file, prints its path, starts a live preview with file watching

Bug fix: build system detection false positive

BazelBuildSystem.detect used FileManager.fileExists which returns true for directories. On macOS's case-insensitive filesystem, a ~/workspace/ directory matched Bazel's WORKSPACE marker, causing standalone files under ~/ to fail with a Bazel detection false positive. Fixed in all three detectors (Bazel, SPM, BuildSystemDetector) to reject directories.

Test plan

  • preview_playground with no code — creates default skeleton, renders
  • preview_playground with custom code — login form renders correctly
  • Hot-reload on playground file — literal edit reflected in snapshot
  • Bazel false positive fix — preview_start on ~/.previewsmcp/playground/ no longer falsely detects Bazel
  • swift build passes
  • swift test --filter BuildSystem — 37/37 tests pass

🤖 Generated with Claude Code

obj-p and others added 4 commits March 21, 2026 17:00
Add a playground feature for quick SwiftUI prototyping without any
project setup:

- preview_playground MCP tool: creates a temp file with provided code
  (or default skeleton), starts a preview session, returns file path
  for editing with hot-reload
- `previewsmcp playground` CLI command: creates temp file, prints path,
  starts live preview with file watching
- Fix build system detection false positive: fileExists now rejects
  directories, preventing case-insensitive matches (e.g., ~/workspace/
  directory matching Bazel's WORKSPACE marker)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…tion tests

Extract shared helpers (launchMacOSPreview, launchIOSPreview, createPlaygroundFile,
defaultPlaygroundCode) into BuildHelpers.swift, eliminating duplicated compile→load→watch
logic across MCPServer, RunCommand, and PlaygroundCommand. Extract startMacOSPreview in
MCPServer.swift shared by handlePreviewStart and handlePreviewPlayground.

Add 3 tests verifying that directories named Package.swift or MODULE.bazel are correctly
ignored by SPMBuildSystem and BuildSystemDetector (covers the isDirectory fix).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
playground now accepts an optional file path to use an existing Swift file
instead of creating a temp one. Path is printed to stdout for piping to editors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@obj-p
obj-p force-pushed the playground-and-detection-fix branch from ad11768 to 6004e43 Compare March 22, 2026 00:43
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@obj-p
obj-p merged commit 625c55a into main Mar 22, 2026
2 checks passed
@obj-p
obj-p deleted the playground-and-detection-fix branch March 22, 2026 01:28
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.

Add /playground command for quick single-file SwiftUI prototyping

1 participant