
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
概覽
把 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。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Prefire,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
[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.
🤖 Using an AI agent?
brew install barredewe/prefire/prefire, thenclaude mcp add prefire -- prefire mcpin 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 renderand an MCP server - 🧩 UIKit + AppKit Support — support for
UIView/UIViewControllerandNSView/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
2. Write #Preview
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
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:
Exclude a preview with .prefireIgnored():
To opt in instead of opting out, set preview_default_enabled: false in .prefire.yml and mark the previews you want with .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:
For previews that load or animate, wait instead of guessing a delay:
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: truelists all the ViewsisComponent: falsegroups them by UserStory
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:
States
[TestView in the Default and Loading states]If a preview contains more than one View, mark the State of each:
Parameterized previews
Prefire expands each argument of a native SwiftUI parameterized preview into its own snapshot and Playbook preview:
🧰 API
💡 CLI Usage
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]Add the MCP server to your agent, from the folder with .prefire.yml:
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
All options are in the Configuration guide. To change the generated code, see Templates.
🧠 How It Works
- 🔍 Parses all source files — finds
#PreviewandPreviewProviderblocks and the.prefireEnabled()/.prefireIgnored()modifiers - 📂 Caches
TypesandPreviewBodies— keyed by file modification date + SHA-256 of inputs, so nothing is re-parsed if nothing changed - 🔢 Generates snapshot tests — from
Stenciltemplates, respecting.prefire.yml - 📘 Generates Playbook models — groups by
UserStoryandStateintoPreviewModels.generated.swift
🩺 Troubleshooting
🐱 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版本歷史
2- v6.6.0最新Oct 31, 2026
- v6.5.0Oct 26, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分