
pixelpact
io.github.jamalkamaladdin由 GitHub 帳號 jamalkamaladdin 發布v0.1.6更新於 Oct 27, 2026
Extract a visual contract from a reference page and measure an implementation against it
概覽
把已實作的網頁與從參考設計擷取的視覺契約逐項比對,回傳每個屬性的偏差數值,讓編碼代理自行檢查介面還原度。
- 可以做什麼
- 從參考頁面擷取視覺契約:尺寸、顏色、間距、字體排版、滑鼠移入與聚焦狀態、動畫關鍵影格和設計權杖
- 用契約檢查實作頁面,逐行列出生偏差的屬性及期望值、實測值和差值
- 對截圖做像素級比對並給出差異百分比
- 讀取已儲存契約的摘要
- 適用情境
- 適合代理正依照參考設計撰寫 CSS 或介面程式碼、需要具體數值來收斂流程而不是靠人眼查看的情況。也適合團隊在宣告某個區塊完成前想要客觀量測結果的時候。
- 執行需求
- 透過 npx pixelpact-mcp 以 stdio 在本機執行。需要 Node 22.12 或更新版本,以及作為 peer 相依套件的 Playwright 和 Chromium。必須先擷取契約。若改為讀取 Figma 畫框而非網址,需要環境變數 FIGMA_TOKEN。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 pixelpact,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
Your coding agent cannot see the page it just built. pixelpact measures it against the reference and hands back numbers.
A coding agent writes the CSS and says it is done. It never sees the result. Nothing hands it a number, so the loop cannot close: the agent guesses, you open the page, you send it back, it guesses again. Every round costs you the one thing the agent was supposed to save.
The same gap exists without an agent, when a teammate says a section is finished and nobody in the room has a measurement. The difference is that a person can at least look.
pixelpact reads the reference page and writes down what it actually renders: sizes, colors, spacing, typography, hover and focus states, animation keyframes, design tokens. That file is the contract. Point pixelpact at the implementation and it answers with one line per property that drifted, which is precisely what an agent can act on.
Works with
If a browser can render it, pixelpact can measure it.
For coding agents
An agent that writes UI code cannot tell whether it succeeded. pixelpact-mcp gives it the
measurement, so the loop closes without a person in the middle: extract the contract once,
then let the agent check its own work, read the deviation list, fix, and check again.
Tools exposed: extract_contract, check_implementation, diff_pixels,
read_contract_summary.
Why this is not visual regression testing
Percy, Chromatic, Applitools, BackstopJS and Pixeleye all compare your page against a baseline that you approved earlier. That model works once the page already looks right and you want to keep it that way. While you are still building toward a design, there is no baseline to compare with, and the first run of a regression tool simply records whatever you produced.
The two models are complementary. Use a regression tool to keep a finished page finished, and pixelpact to get it finished in the first place.
Problems pixelpact solves
Install
playwright is a peer dependency, so the browser download stays under your control and a
project that already has Playwright installs nothing extra. Node 22.12 or newer is required.
Quickstart
1. Extract the contract from the reference.
2. Measure your implementation.
3. Fix what it reports, then run it again. The command exits 0 when everything is inside
tolerance and 1 when it is not, so it drops straight into a script or a CI job.
What a contract looks like
A contract is plain JSON, readable and diffable, with no proprietary format and no service behind it.
Because it is a file, you can commit it, review it in a pull request, hand it to another developer, or hand it to an agent.
What a check prints
That is a real run against two copies of one page with four declarations changed. Four edits
produce ten measured deviations, because padding moves the box width and one border-radius
shorthand sets four corners. Run the same check against the reference itself and all 1066
assertions pass, which is the property that matters: a passing check has to mean something.
Add --json to get the same report as a data structure, which is what CI jobs and agents read.
What a side by side run shows
check says which values moved. diff says how many pixels moved. Neither tells a person
where to look. side splits both pages into sections, puts them next to each other, and boxes
what differs.
[One section compared side by side, differences boxed in red]
That is a real run against the two files in examples/side, which are
copies of one page where the card gap and the corner radius were changed. Reproduce it with:
This is the command to run before telling anyone that a page is finished.
Features
Commands
Shared flags cover the browser context (--viewport, --selector, --wait, --timeout,
--locale, --timezone, --channel, --headful), the output (--out, --json,
--quiet), and the parts of extraction you may want to cap (--max-elements, --max-states,
--mask). Run pixelpact <command> --help for the full list.
Exit codes
Programmatic use
Everything is typed, and the contract and report shapes are validated at the boundary, so a malformed file fails with a readable message instead of a stack trace.
In CI
The Action measures a preview deployment against the contract committed in the repository and keeps a single pull request comment up to date instead of adding one per push.
It needs permissions: pull-requests: write and no secret beyond the automatic
GITHUB_TOKEN. Every input, every output and a complete workflow are in
action/README.md.
Reading a Figma frame
extract recognises a Figma url and reads the frame through the REST API. No browser is
launched for this step.
A Figma layer has no CSS selector, so a Figma contract binds to your markup through
data-contract attributes. Name the element after the layer and matching stops depending on
how the design happened to nest its frames:
Anything with no match is reported as missing rather than guessed from tag names.
Published styles come across as tokens: a color style as its color, a text style as a css font
shorthand such as 600 60px/72px Geist, an effect style as a box shadow. A fill that is a
gradient or an image has no single css value, so it is left out and named in the warnings
rather than approximated.
How it works
- Playwright opens the reference at each requested viewport, waits for fonts, network and paint to settle, and dismisses cookie overlays.
- A single function is evaluated inside the page. It walks the DOM under your root selector and records the computed style of every visible element, plus custom properties, keyframes, and the geometry of each box.
- Interactive elements are hovered and focused, and only the properties that actually change are stored, so a contract stays small enough to read.
- Checking repeats step 2 against your implementation, matches elements by
data-contractattribute, then by selector, then by tag and text, and compares property by property. Lengths use a pixel tolerance, colors use a perceptual distance, and animations are compared by name and timing rather than by string equality.
Repository layout
FAQ
How does an agent use it? Install pixelpact-mcp, point the MCP client at it, extract the
contract once, then let the agent call check_implementation after every edit and read the
deviation table it gets back.
How is this different from Percy or Chromatic? They compare your page against a snapshot you approved earlier, which assumes the page is already right. pixelpact compares it against the reference, which is what you actually have while you are still building. The two fit together: pixelpact to get the page correct, a regression tool to keep it that way.
Do I need a baseline? No. The reference is the baseline, and that is the entire point.
My markup does not match the reference structure. Will anything match? Element matching
tries the data-contract attribute first, then the selector, then the tag and its text. Put
data-contract="hero-cta" on your element and matching stops depending on how the reference
happened to nest its divs.
The page has content that changes on every load. Will a check ever pass? Mask it.
--mask ".carousel" keeps a region out of the pixel comparison, and --max-elements stops a
long page from producing a contract nobody can read.
Which browsers? Chromium through Playwright. Running a matrix across engines is out of scope on purpose: this tool measures agreement with a design, not differences between browsers.
Does a passing check mean the page is correct? It means every value in the contract matched
inside tolerance. Elements that exist in your page but not in the reference are not flagged,
because the contract only describes what the reference contains. Run diff as well when
nothing extra is allowed.
Status
Everything described above is built and every number shown came from a real run: extraction from a live page and from Figma, checking, the pixel diff, the side by side images, the MCP server and the Action.
Version 0.3. Settled enough to use, not settled enough to promise: the contract format will gain fields before 1.0. If a value you need is missing from it, open an issue and say which one, because that is the fastest way for it to appear.
Contributing
Development setup, the commands, and the pull request flow are in CONTRIBUTING.md. Security reports go through SECURITY.md.
License
MIT © Jamal Kamaladdin
來源:README.md,提交 fd7387f
工具
0版本歷史
1- v0.1.6最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分