Prefire

io.github.BarredEwe由 GitHub 账号 BarredEwe 发布v6.6.0更新于 Oct 31, 2026

Render SwiftUI #Preview as PNG images, so an AI agent sees the views it changes

已验证STDIO仅桌面开发者工具媒体与设计

概览

AI 生成的概览

把 SwiftUI 的 #Preview 渲染成 PNG 图片,让 AI 助手看到自己刚改动的界面,并生成预览看板。

可以做什么
  • 列出项目中找到的 SwiftUI 预览
  • 按指定设备、配色方案和动态字体把预览渲染成 PNG 图片
  • 为最近一次渲染生成按用户故事分组的 HTML 看板
适用场景
适合助手修改 iOS 项目的 SwiftUI 视图后需要肉眼确认效果,而不是靠猜测;在 Xcode 之外或 CI 中 Xcode Previews 不可靠时尤其有用。
运行要求
以本地进程运行,通过 Homebrew 或 Mint 安装,并以 prefire mcp 命令注册到助手。需要 Swift 6.0+、Xcode 16.0+,项目目录中要有 .prefire.yml 并在 render_configuration 中指定 scheme。仅支持 macOS。
安装前请注意
渲染会构建项目,可能耗时并执行构建脚本。服务器需从包含 .prefire.yml 的目录添加,助手因此会作用于该项目的源码。不要求任何凭据。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Prefire,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

[Prefire: your previews are already tests. Snapshot tests, a Playbook and renders your AI agent can see, all from #Preview]

[Release] [Stars] [Platform] [Swift6] [Swift Package Manager] [Xcode Plugins]

Quick Start · Installation · Usage · AI agents · Configuration · Docs · Website

🔥 What is Prefire?

Your previews are already tests. Prefire turns the #Preview blocks you write anyway into snapshot tests, a Playbook catalog and images your AI agent can see. You don't write a line of test code.

📸 Snapshot tests

Every preview becomes a snapshot test on the devices you pick. A changed padding fails the build, not the release.

How it works →

📚 Playbook

A catalog of every component and user story inside your app, with their states and render times.

See Playbook →

🤖 Renders for AI agents

Claude Code, Cursor and Codex render your previews through an MCP server and see the UI they just changed.

Set up →

🤖 Using an AI agent? brew install barredewe/prefire/prefire, then claude mcp add prefire -- prefire mcp in your project. The agent renders SwiftUI previews on any iPhone or iPad, light or dark, without Xcode Previews. Setup →

🚀 Key Features

[Playbook: user stories built from previews]
  • 🧠 Smart Preview Parsing — including #Preview, @Previewable
  • 📸 Snapshot Testing — automatic test generation from previews (iOS, tvOS, macOS)
  • 📚 Playbook View — auto-generated interactive component catalog (iOS)
  • 🏃 Flow-aware — build user stories from multiple preview steps
  • 🤖 AI-ready — render previews to PNG for agents with prefire render and an MCP server
  • 🧩 UIKit + AppKit Support — support for UIView/UIViewController and NSView/NSViewController
  • ⚙️ SPM + Xcode Plugins — works in CLI, Xcode build phases, or CI
  • 🧠 Fast Caching — fingerprint-based AST and body caching avoids redundant work
  • ✍️ Stencil Templates — customize output with your own templates

Why Prefire?

  • 🔥 No second set of UI states. Tests come from the previews you already keep up to date.
  • 🔥 Regressions fail CI. Snapshots are compared on every run, on every device you list.
  • 🔥 Designers and QA see every state. Playbook shows components and user stories on a device.
  • 🔥 Agents check their own UI work. They render the previews they changed before calling a task done.


⚡ Quick Start

📦 Example project available at: Prefire Example

1. Add Prefire to Your Project

swift
// Package.swiftdependencies: [    .package(url: "https://github.com/BarredEwe/Prefire.git", from: "6.3.0"),    .package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.18.0"),],.testTarget(    dependencies: [      .product(name: "Prefire", package: "Prefire"),      .product(name: "SnapshotTesting", package: "swift-snapshot-testing"),    ],    plugins: [        .plugin(name: "PrefireTestsPlugin", package: "Prefire")    ])

2. Write #Preview

swift
#Preview {    Button("Submit")}

3. Run tests

Just run the test target 🚀 — Prefire will auto-generate snapshots based on your previews.

💡 If your test target is empty, Prefire will still generate files and snapshot code during build.

[图片]

📦 Installation

MethodHow
SPM PluginPrefireTestsPlugin / PrefirePlaybookPlugin in Package.swift
Xcode Build Tool PluginAdd PrefireTestsPlugin to the test target's build phases
CLIbrew install barredewe/prefire/prefire
Mint (Beta)mint install BarredEwe/Prefire
GitHub Actions / CIAny of the above, see Troubleshooting

Step-by-step setup is in the Installation guide.

Requirements

  • Swift 6.0 or higher
  • Xcode 16.0 or higher
  • iOS 14 or higher; macOS 13 or higher (macOS: snapshot tests only, see Configuration)

🛠 Usage

Choose previews

Prefire finds every #Preview automatically. For PreviewProvider, add the PrefireProvider protocol:

swift
struct Text_Previews: PreviewProvider, PrefireProvider {    static var previews: some View { ... }}

Exclude a preview with .prefireIgnored():

swift
#Preview {    Text("")        .prefireIgnored()}

To opt in instead of opting out, set preview_default_enabled: false in .prefire.yml and mark the previews you want with .prefireEnabled():

swift
#Preview {    Text("")        .prefireEnabled()}

Snapshot tests

PrefireTestsPlugin generates the tests into the DerivedData folder when the test target builds. Run the test target as usual.

Tune the timing and precision of a single snapshot:

swift
#Preview {    TestView()        .snapshot(delay: 0.3, precision: 0.95, perceptualPrecision: 0.98)}

For previews that load or animate, wait instead of guessing a delay:

swift
.snapshot(waitForIdle: true)                     // until nothing changes on screen.snapshot(waitUntil: { viewModel.isLoaded })     // until a condition is true

How waiting works, its limits and how the modifiers combine: Snapshot timing and precision.

Snapshots are compared with swift-snapshot-testing.

Playbook (Demo) View

Show all previews as an interactive catalog with PlaybookView:

  • isComponent: true lists all the Views
  • isComponent: false groups them by UserStory
swift
import Prefire 
struct ContentView: View {    var body: some View {        PlaybookView(isComponent: true, previewModels: PreviewModels.models)    }}

To keep previews and PreviewModels out of release builds, see Excluding previews from release builds.

Flows

[The auth user story in Playbook: PrefireView, then AuthView]

Connect previews into one Flow with .previewUserStory. Playbook shows them together, in order:

swift
static var previews: some View {    PrefireView()        .previewUserStory(.auth)}
static var previews: some View {    AuthView()        .previewUserStory(.auth)}

States

[TestView in the Default and Loading states]

If a preview contains more than one View, mark the State of each:

swift
static var previews: some View {    TestView("Default")
    TestView("Loading")        .previewState(.loading)}

Parameterized previews

Prefire expands each argument of a native SwiftUI parameterized preview into its own snapshot and Playbook preview:

swift
#Preview("TextView", traits: .sizeThatFitsLayout, arguments: ["- A", "- B", "- C"]) { suffix in    Text("1 \(suffix)")}

🧰 API

FeatureModifier
Include in snapshot.prefireEnabled()
Exclude from snapshot.prefireIgnored()
Group in a flow.previewUserStory(.auth)
Mark a UI state.previewState(.error)
Customize snapshot.snapshot(delay: 0.3, precision: 0.95)
Wait until the preview settles.snapshot(waitForIdle: true, timeout: 2.0)
Wait for a condition.snapshot(waitUntil: { viewModel.isLoaded })
Parameterized preview#Preview(..., arguments: values)

💡 CLI Usage

bash
# Generate snapshot testsprefire tests
# Generate playbook modelsprefire playbook

Run prefire tests --help or prefire playbook --help for more options.


🤖 Let AI agents see SwiftUI

Prefire renders previews in its snapshot tests, built anew and on the devices you choose, so it can show them to an AI agent as images, which Xcode Previews can't do reliably outside Xcode.

[An agent calls render_previews for three previews of the Trip screen and gets dark mode PNGs back]
bash
# Render previews to PNG + JSONprefire render "Sign in" --device "iPhone 16 Pro" --color-scheme dark
# An HTML board of the last render, grouped by user storyprefire board

Add the MCP server to your agent, from the folder with .prefire.yml:

AgentInstall
Claude Codeclaude mcp add prefire -- prefire mcp, or the plugin with a skill: /plugin marketplace add BarredEwe/Prefire then /plugin install prefire@prefire
Cursor[Add to Cursor]
Codexcodex mcp add prefire -- prefire mcp
VS Codecode --add-mcp '{"name":"prefire","command":"prefire","args":["mcp"]}'

An agent then calls list_previews, render_previews and build_board. Set the scheme to build in render_configuration of .prefire.yml; see the AI guide. Why not Xcode's own RenderPreview? Prefire needs no running Xcode, renders many previews in one build, on the devices, color scheme and Dynamic Type you ask for, and works in CI.


🗂 Configuration: .prefire.yml

yaml
test_configuration:  target: MyApp
playbook_configuration:  preview_default_enabled: true

All options are in the Configuration guide. To change the generated code, see Templates.


🧠 How It Works

  1. 🔍 Parses all source files — finds #Preview and PreviewProvider blocks and the .prefireEnabled() / .prefireIgnored() modifiers
  2. 📂 Caches Types and PreviewBodies — keyed by file modification date + SHA-256 of inputs, so nothing is re-parsed if nothing changed
  3. 🔢 Generates snapshot tests — from Stencil templates, respecting .prefire.yml
  4. 📘 Generates Playbook models — groups by UserStory and State into PreviewModels.generated.swift

🩺 Troubleshooting

ProblemFix
NavigationView in a preview doesn't work in PlaybookUse other views or layouts for your Playbook needs
Plugins don't run on CIdefaults write com.apple.dt.Xcode IDESkipPackagePluginFingerprintValidatation -bool YES
Xcode can't generate tests in a custom pathDisable the plugin sandbox: defaults write com.apple.dt.Xcode IDEPackageSupportDisablePluginExecutionSandbox -bool YES

🐱 Also by the author

[Mewmori]

Mewmori is a pixel cat that lives on your Mac desktop. He reads what's on screen, says something about it, and remembers you between sessions. A 2B model runs on the machine through llama.cpp, so screen text, chats and memory stay on your Mac.

Swift, AppKit + SwiftUI, 29 MB. Free; only skins are paid.


🤝 Contributing

We welcome contributions! Development setup, tests and the internal architecture are described in CONTRIBUTING.md.

Logo, colors and templates for talks and posts about Prefire are in the brand kit.

⭐ Star history

If Prefire saves you time, give it a star: it helps other iOS developers find it.

[Star history of Prefire]

📄 License

Prefire is released under the Apache License 2.0. See LICENSE for details.

来源:README.md,提交 c49c1ae

工具

0
SourceWeft 曾在隔离沙箱中以无凭据方式启动该软件包一次,以列出其工具,但未能完成:该软件包类型无法在沙箱中运行。

版本历史

2
  1. v6.6.0最新Oct 31, 2026
  2. v6.5.0Oct 26, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分