@kw-yeh/vibeflow 4.11.68 → 4.11.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +1 -1
  2. package/dist/builtin-skills/address-review/scripts/pr-lib.mjs +29 -1
  3. package/dist/builtin-skills/pr/SKILL.md +112 -16
  4. package/dist/builtin-skills/pr-watch/SKILL.md +64 -31
  5. package/dist/builtin-skills/pr-watch/scripts/pr-lib.mjs +29 -1
  6. package/dist/builtin-skills/pr-watch/scripts/pr-watch.mjs +27 -11
  7. package/dist/builtin-skills/visual-parity/README.md +225 -0
  8. package/dist/builtin-skills/visual-parity/SKILL.md +168 -12
  9. package/dist/builtin-skills/visual-parity/scripts/parity.py +854 -63
  10. package/dist/builtin-skills/visual-parity/scripts/scaffold_verify.py +126 -0
  11. package/dist/builtin-skills/visual-parity/scripts/vendor/README +1 -0
  12. package/dist/builtin-skills/visual-parity/scripts/vendor/axe-core.LICENSE +362 -0
  13. package/dist/builtin-skills/visual-parity/scripts/vendor/axe.min.js +12 -0
  14. package/dist/builtin-skills/visual-parity/templates/verify-app/SKILL.md +46 -0
  15. package/dist/builtin-skills/visual-parity/templates/verify-app/features/README.md +18 -0
  16. package/dist/builtin-skills/visual-parity/templates/verify-app/features/home.md +19 -0
  17. package/dist/builtin-skills/visual-parity/templates/verify-app/flows/home.json +5 -0
  18. package/dist/builtin-skills/visual-parity/templates/verify-app/scripts/check-map.sh +33 -0
  19. package/dist/builtin-skills/visual-parity/templates/verify-app/scripts/cleanup.sh +27 -0
  20. package/dist/builtin-skills/visual-parity/templates/verify-app/scripts/doctor.sh +31 -0
  21. package/dist/builtin-skills/visual-parity/templates/verify-app/scripts/launch.sh +31 -0
  22. package/dist/builtin-skills/visual-parity/templates/verify-app/scripts/lib.sh +54 -0
  23. package/dist/builtin-skills/visual-parity/templates/verify-app/scripts/verify.sh +19 -0
  24. package/dist/builtin-skills/work-mode/SKILL.md +114 -0
  25. package/dist/builtin-skills/work-mode/playbooks/babysit-pr.md +19 -0
  26. package/dist/builtin-skills/work-mode/playbooks/bug-fix.md +19 -0
  27. package/dist/builtin-skills/work-mode/playbooks/feature.md +17 -0
  28. package/dist/builtin-skills/work-mode/playbooks/investigation.md +16 -0
  29. package/dist/builtin-skills/work-mode/playbooks/refactor.md +18 -0
  30. package/dist/web/404/index.html +1 -1
  31. package/dist/web/404.html +1 -1
  32. package/dist/web/home/index.html +1 -1
  33. package/package.json +1 -1
  34. /package/dist/web/_next/static/{JfjneYm100TdfyZFMjfVI → VYsg0UtYDVl6PsB_NgjIH}/_buildManifest.js +0 -0
  35. /package/dist/web/_next/static/{JfjneYm100TdfyZFMjfVI → VYsg0UtYDVl6PsB_NgjIH}/_ssgManifest.js +0 -0
@@ -0,0 +1,225 @@
1
+ # visual-parity
2
+
3
+ 給 [Claude Code](https://claude.com/claude-code) 用的 skill:比對兩個已渲染網頁的樣式落差、跑互動 E2E 驗收、檢查 RWD 破版。
4
+
5
+ 改版驗收時最常見的兩個問題是「新頁面跟舊的長得不一樣,但講不出哪裡不一樣」和「agent 改一項就截圖一次,把 context 燒光」。這個 skill 一次跑完全部比對,把細節寫進報告檔案,只回傳一張壓縮過的落差表。
6
+
7
+ ---
8
+
9
+ ## 安裝
10
+
11
+ 這個 skill 隨 VibeFlow 內建在 Library 裡,啟動任務時自動交給 agent,不需要另外 clone。下文的 `<skill-dir>` 是 Library 裡這個 skill 的目錄(本 README 所在的資料夾)。
12
+
13
+ ### 1. 裝相依
14
+
15
+
16
+ ```bash
17
+ pip install playwright pillow && playwright install chromium
18
+ ```
19
+
20
+ `pillow` 只有 `snapshot` 會用到;`pixel` 另外需要 `pip install opencv-python-headless numpy`,沒裝時只有 `pixel` 會停下並提示。axe-core 已放在 `scripts/vendor/`,不用另外裝。
21
+
22
+ Windows 上 `python` 若指向 Microsoft Store 的空殼,改用 `py`(例如 `py -m pip install playwright pillow`、`py scripts\parity.py selftest`)。
23
+
24
+ 錄影要輸出 MP4 才需要 ffmpeg,選配:
25
+
26
+ ```bash
27
+ brew install ffmpeg # macOS
28
+ winget install Gyan.FFmpeg # Windows(或 choco install ffmpeg)
29
+ ```
30
+
31
+ Windows 裝完要重開終端機讓 `ffmpeg` 進 PATH。
32
+
33
+ 沒裝也不會壞,錄影會自動退回 `.webm` 並在 stdout 提示。
34
+
35
+ ### 2. 驗證
36
+
37
+ ```bash
38
+ python "<skill-dir>/scripts/parity.py" selftest
39
+ ```
40
+
41
+ 印出 `selftest OK` 就成功了。
42
+
43
+ ---
44
+
45
+ ## 怎麼觸發
46
+
47
+ 裝好之後在 Claude Code 裡用白話講就會自動載入,不用記指令。這些說法都會觸發:
48
+
49
+ > 「新舊頁面長得不一樣」「跟測試環境比對」「像素比對」「樣式對不上」「visual diff」「RWD 檢查」「開 dev server 驗收」「E2E 驗收」
50
+
51
+ 也可以直接跑 CLI,下表的子指令都是。
52
+
53
+ ---
54
+
55
+ ## 子指令
56
+
57
+ | 子指令 | 用途 | Exit code |
58
+ |---|---|---|
59
+ | `diff` | 比對兩個 URL 的 computed style 落差,含沒有文字的圖片與 icon | 有落差或缺漏 `1`,完全一致 `0` |
60
+ | `responsive` | 在 375 / 768 / 1440 各跑一次 diff,另查水平溢出 | 同上 |
61
+ | `flow` | 依 JSON 腳本跑互動流程(含樣式斷言、axe),蒐集 console / network 錯誤,可錄影 | 有步驟失敗 `1` |
62
+ | `pixel` | 用 OpenCV 比對兩個 URL 的整頁截圖,依元素配對對齊並與 computed style 交叉比對 | 有看得到的落差 `1` |
63
+ | `snapshot` | 把頁面或區塊截圖,跟設計稿 PNG(Figma 匯出)做像素比對 | 落差超過門檻 `1` |
64
+
65
+ 完整用法見 [SKILL.md](SKILL.md)。
66
+
67
+ ### diff — 新舊頁面樣式落差
68
+
69
+ ```bash
70
+ python "<skill-dir>/scripts/parity.py" diff \
71
+ --ref https://staging.example.com/faq/content?id=28473 \
72
+ --local https://localhost:3000/faq/content?id=28473 \
73
+ --out parity-diff.md
74
+ ```
75
+
76
+ stdout 會回五個數字:
77
+
78
+ - `matched` — 成功配對並比對的元素數
79
+ - `diffs` — 屬性落差總數
80
+ - `missing-locally` — 舊頁有、新頁完全沒有的內容(含圖片與 icon),**抓漏掉的區塊看這個**
81
+ - `skipped-ambiguous` — 文字或圖檔在頁面上重複、無法 1:1 配對而略過。數字大不代表有問題,但代表覆蓋率沒滿
82
+ - `skipped-textless` — 沒有文字也沒有識別屬性的末端元素(CSS icon、分隔線),未被比對
83
+
84
+ 元素配對順序:先套 `--map` 的手動對照 → 「標籤 + 文字」自動配對 → 「純文字」補配。最後這步是為了吸收 SPA→SSR 造成的標籤變化(例如 `<p>` 變成 `<div>`)。
85
+
86
+ DOM 結構差太多時(舊 iframe vs 新 SSR),用 `--map` 指定 JSON 對照表補:
87
+
88
+ ```json
89
+ {
90
+ "#faqAnswer": ".faq-body",
91
+ ".uform_search": "[data-testid=search-hero]"
92
+ }
93
+ ```
94
+
95
+ 左邊是 ref 的 selector、右邊是 local 的,支援尾綴比對,不必寫完整路徑。
96
+
97
+ 其他參數:`--width` / `--widths` / `--height` / `--wait-selector` / `--extra-wait`。
98
+
99
+ ### responsive — RWD 破版
100
+
101
+ ```bash
102
+ python "<skill-dir>/scripts/parity.py" responsive \
103
+ --ref <URL> --local <URL> --out parity-responsive.md
104
+ ```
105
+
106
+ 等同在三種寬度各跑一次 diff,另外檢查 local 是否出現 `scrollWidth > clientWidth`——這是 RWD 破版最常見的徵兆。
107
+
108
+ ### flow — 互動驗收
109
+
110
+ 用 JSON 描述步驟,不用每次現寫 Playwright:
111
+
112
+ ```json
113
+ [
114
+ {"action": "goto", "url": "https://localhost:3000/products"},
115
+ {"action": "click", "selector": ".ba-free-download", "desc": "點 Free Download"},
116
+ {"action": "wait", "selector": "[role=dialog]"},
117
+ {"action": "expect_focused", "selector": "[role=dialog] input[type=email]", "desc": "focus 應落在 input 而非 close button"},
118
+ {"action": "fill", "selector": "input[type=email]", "value": "a@b.com"},
119
+ {"action": "click", "selector": "button[type=submit]"},
120
+ {"action": "expect_text", "selector": "[role=dialog]", "value": "Check your email"}
121
+ ]
122
+ ```
123
+
124
+ ```bash
125
+ python "<skill-dir>/scripts/parity.py" flow \
126
+ --steps steps.json --out parity-flow.md
127
+ ```
128
+
129
+ 可用 action:
130
+
131
+ | action | 用途 |
132
+ |---|---|
133
+ | `goto` `click` `fill` `press` `hover` | 操作 |
134
+ | `wait` `wait_animations` | 等 selector/毫秒數;等動畫跑完 |
135
+ | `emulate` | 切換 reduced motion、color scheme、media |
136
+ | `expect_text` `expect_visible` `expect_focused` | 內容與 focus 斷言 |
137
+ | `expect_style` | computed style 斷言(含 pseudo、transition、動畫結束值) |
138
+ | `save_box` `expect_box` | 記下位置大小,之後斷言沒有位移 |
139
+ | `axe` | 無障礙檢查 |
140
+ | `screenshot` | 存檔 |
141
+
142
+ 每個 action 的參數見 [SKILL.md](SKILL.md)。
143
+
144
+ `wait` 吃 `selector`,或改吃 `{"action": "wait", "ms": 800}` 單純停一段時間——動畫沒有對應 selector 可等時用這個。
145
+
146
+ 預設第一個失敗就停,`--keep-going` 可跑完全部。console error / warning 與失敗的 request 一律蒐集,這類問題不會反映在樣式比對裡。`--headed` 可開有頭瀏覽器讓人工旁觀。
147
+
148
+ **把 flow 的 JSON 存進專案(例如 `e2e/`),下次改版直接重跑,就是回歸測試。**
149
+
150
+ ### flow --video — 錄下整段互動
151
+
152
+ 截圖看不出 transition、loading、hover 這類會動的東西:
153
+
154
+ ```bash
155
+ python "<skill-dir>/scripts/parity.py" flow \
156
+ --steps steps.json --out parity-flow.md --video parity-flow.mp4
157
+ ```
158
+
159
+ | 參數 | 預設 | 說明 |
160
+ |---|---|---|
161
+ | `--video PATH` | 關閉 | 副檔名 `.mp4` 會用 ffmpeg 轉 H.264 並刪除中間的 webm;寫 `.webm` 則不轉檔 |
162
+ | `--video-size WxH` | `1280x720` | 同時決定錄影解析度與 viewport |
163
+ | `--video-tail 秒` | `1` | 最後一步跑完後繼續錄的時間,避免收尾動畫被切掉 |
164
+ | `--no-cursor` | 游標預設開啟 | 關掉合成游標。開啟時 `click`/`fill` 前先讓指標走到目標中心,按下時有藍色擴散環 |
165
+
166
+ 影格率是 Playwright screencast 的 **25fps**。判斷「動畫有沒有做對」夠用;要判斷「掉不掉幀」不夠,要另外錄 60fps:macOS 用內建的 `screencapture -v`;Windows 沒有內建等效指令,用 OBS Studio 或 Xbox Game Bar(`Win+Alt+R`,影格率要在設定調成 60),都沒有就把它列為未驗。
167
+
168
+ ### flow --mutate — 確認斷言真的會失敗
169
+
170
+ ```bash
171
+ python "<skill-dir>/scripts/parity.py" flow --steps steps.json --mutate
172
+ ```
173
+
174
+ 每個通過的 `expect_*` 會在刻意弄壞的頁面(移除 CSS、清空文字、隱藏元素、移走 focus)上重跑;還是通過的標為 `INVALID` 並讓整次 exit 1。
175
+
176
+ 影片路徑會同時寫進報告開頭與 stdout。
177
+
178
+ ---
179
+
180
+ ## 專案驗證入口:scaffold_verify.py
181
+
182
+ 在 app repo 產生 `.claude/skills/verify-<app>/`:啟動/檢查/清理 dev server 的腳本、可搜尋的功能地圖(`features/`),以及每個功能一份 flow(`flows/<id>.json`,底層跑 `parity.py flow`,報告自帶 commit)。
183
+
184
+ ```bash
185
+ python "<skill-dir>/scripts/scaffold_verify.py" --repo <app repo> \
186
+ [--host auth.example.test --entry /auth/login --port 8443 --start "npm run dev -- --port $PORT"]
187
+ ```
188
+
189
+ 沒給的值會從 `package.json`、`vite.config.*`、`next.config.*` 偵測,猜的會標 `GUESSED`。產生後:
190
+
191
+ - `scripts/launch.sh` → `scripts/doctor.sh` → `scripts/verify.sh <feature-id> [--mutate]` → `scripts/cleanup.sh`
192
+ - `scripts/check-map.sh [--live]` 檢查地圖格式、索引、每個功能都有 flow,`--live` 再確認地圖裡每個路由都回 200。新增或改名頁面時跟著更新地圖,地圖才不會過時。
193
+
194
+ ## 報告來源欄位
195
+
196
+ 每份報告開頭與 stdout 都記錄 `commit`、`working tree`(clean/dirty)、比對的 `url` 與執行時間;不在 git repo 內執行時寫 `(not a git repo)`。PR 的 Evidence 用這個 commit 證明「驗的就是要交付的版本」。
197
+
198
+ ## 給 agent 的使用規範
199
+
200
+ SKILL.md 裡有四條鐵則,直接影響這個 skill 划不划算,摘要在這裡讓人也知道:
201
+
202
+ 1. **不要 Read `scripts/parity.py`。** 它是黑箱,`--help` 就夠。
203
+ 2. **不要把報告全文讀進 context。** stdout 摘要已含「最常出現的落差屬性」,要細節用 `grep` 撈特定屬性或 selector。
204
+ 3. **不要逐項修。** 落差通常是少數幾條系統性規則(一條 `margin-bottom`、一組 token)造成的,不是幾十個獨立問題。
205
+ 4. **改完重跑一次全量比對**,而不是只驗剛改的那一項。
206
+
207
+ 第 2 條是這個 skill 存在的主因:改一項就截圖一次,會把每張截圖與每份 computed style 永久留在 context 裡,同一份工作在 600k context 下做,成本是 100k 時的六倍。
208
+
209
+ ---
210
+
211
+ ## dev server
212
+
213
+ 受測頁面要先跑起來;server 已經在跑就直接呼叫 `parity.py`。自簽憑證預設接受(`ignore_https_errors`)。
214
+
215
+ ---
216
+
217
+ ## 更新與維護
218
+
219
+ VibeFlow 升級時,沒改過的內建 skill 會跟著更新;改過的保留不覆蓋,可在 Library 面板還原成內建版。
220
+
221
+ 改過 `scripts/parity.py` 後一定要跑 selftest,它會用內建 fixture 驗證配對與 diff 邏輯仍正確:
222
+
223
+ ```bash
224
+ python scripts/parity.py selftest
225
+ ```
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: visual-parity
3
- description: 比對兩個已渲染網頁的樣式落差(新舊版對照 / 改版驗收)與 OpenCV 像素落差,跑互動 E2E 流程並蒐集 console 與 network 錯誤,以及在 375/768/1440 三種寬度檢查 RWD 與水平溢出。當使用者提到「新舊頁面長得不一樣」「跟測試環境比對」「像素比對」「樣式對不上」「visual diff」「RWD 檢查」「開 dev server 驗收」「E2E 驗收」時使用。比對與驗收的結果寫進檔案,只回傳壓縮過的落差表。
3
+ description: 比對兩個已渲染網頁的樣式落差(新舊版對照 / 改版驗收)與 OpenCV 像素落差、把畫面跟 Figma 設計稿做截圖比對,跑互動 E2E 流程(含 hover/動畫狀態的樣式斷言與 axe 無障礙檢查)並蒐集 console 與 network 錯誤,以及在 375/768/1440 三種寬度檢查 RWD 與水平溢出。當使用者提到「新舊頁面長得不一樣」「跟測試環境比對」「跟 Figma 比對」「設計稿驗收」「像素比對」「樣式對不上」「visual diff」「RWD 檢查」「無障礙檢查」「開 dev server 驗收」「E2E 驗收」時使用。比對與驗收的結果寫進檔案,只回傳壓縮過的落差表。
4
4
  ---
5
5
 
6
6
  # Visual Parity
@@ -24,7 +24,7 @@ description: 比對兩個已渲染網頁的樣式落差(新舊版對照 / 改
24
24
 
25
25
  - `<skill-dir>` 是本 SKILL.md 所在的目錄;script 在 `<skill-dir>/scripts/parity.py`。
26
26
  - 下文指令寫 `python`;macOS / Linux 沒有 `python` 時改用 `python3`。
27
- - 需要 `pip install playwright && playwright install chromium`(macOS / Linux 用 `pip3` 或 `python3 -m pip`);錄 `.mp4` 才需要 ffmpeg(選配)。
27
+ - 需要 `pip install playwright pillow && playwright install chromium`(`pillow` 只有 `snapshot` 用到;macOS / Linux 用 `pip3` 或 `python3 -m pip`);錄 `.mp4` 才需要 ffmpeg(選配)。
28
28
  - `pixel` 另外需要 `pip install opencv-python-headless numpy`;沒裝時只有 `pixel` 會停下並提示,其他模式照常。
29
29
  - 受測頁面要先跑起來。server 已經在跑就直接呼叫 `parity.py`;自簽憑證已預設接受(`ignore_https_errors`)。
30
30
  - 頁面需要登入或一次性 token 時,`--ref` / `--local` 直接給帶 token 的完整 URL,或先用 `flow` 的步驟登入。
@@ -70,18 +70,26 @@ TMPDIR="$PARITY_SCRATCH" python "<skill-dir>/scripts/parity.py" diff \
70
70
  --out "$PARITY_OUT/parity-diff.md"
71
71
  ```
72
72
 
73
- 元素配對:先套 `--map` 的手動對照,再以「標籤+文字」自動配對,最後以「純文字」補配(吸收 SPA→SSR 的標籤變化,例如 `<p>` 變 `<div>`)。
73
+ 元素配對:先套 `--map` 的手動對照,再以「標籤+文字」自動配對,接著以「純文字」補配(吸收 SPA→SSR 的標籤變化,例如 `<p>` 變 `<div>`),最後用「視覺識別」配對沒有文字的元素:
74
74
 
75
- stdout 會回報四個數字:
75
+ | 元素 | 配對依據 |
76
+ |---|---|
77
+ | `img`/`video`/`iframe` | 檔名。會去掉網域、query、內容 hash(`logo.3f2a9c1d.png`、Strapi 的 `banner_95de82a84f.webp`),並解開 `next/image` 的 `?url=` |
78
+ | `svg` | `<use href>` → `aria-label` → `<title>` → 第一個 `path` 的 `d` |
79
+ | `input`/`textarea`/`select` | `type`、`name`、`placeholder`、`aria-label` |
80
+ | 其他 | `aria-label` → `title` → `background-image` 檔名 |
81
+
82
+ stdout 會回報五個數字:
76
83
 
77
84
  - `matched` — 成功配對並比對的元素數
78
85
  - `diffs` — 屬性落差總數
79
- - `missing-locally` — 舊頁有、新頁完全沒有的內容(**抓漏掉的區塊用這個**)
80
- - `skipped-ambiguous` — 文字在頁面上重複、無法 1:1 配對,**未被比對**。數字大不代表有問題,但代表覆蓋率沒滿;關鍵區塊落在這裡就用 `--map` 補。
86
+ - `missing-locally` — 舊頁有、新頁完全沒有的內容,包含圖片與 icon(**抓漏掉的區塊用這個**)
87
+ - `skipped-ambiguous` — 文字或圖檔在頁面上重複、無法 1:1 配對,**未被比對**。數字大不代表有問題,但代表覆蓋率沒滿;關鍵區塊落在這裡就用 `--map` 補。
88
+ - `skipped-textless` — 沒有文字、也沒有任何識別屬性的末端元素(CSS 畫的 icon、分隔線、裝飾色塊),**未被比對**。報告會列出它們的 selector;重要的用 `--map` 補,或改用 `snapshot` 涵蓋。
81
89
 
82
90
  其他參數:`--width` / `--widths`、`--wait-selector`(等內容渲染完)、`--extra-wait`(動畫或延遲載入)。
83
- Exit code 1 表示有落差,0 表示完全一致。
84
- 此模式比對 DOM/computed styles,不產生像素 diff 圖;像素級比對用下面的 `pixel`。
91
+ Exit code 1 表示有屬性落差或有 `missing-locally`,0 表示完全一致。
92
+ 此模式比對 DOM/computed styles,不產生像素 diff 圖;像素級比對用下面的 `pixel`,跟設計稿比對用 `snapshot`。
85
93
 
86
94
  ### --map:手動指定對照
87
95
 
@@ -167,8 +175,51 @@ TMPDIR="$PARITY_SCRATCH" python "<skill-dir>/scripts/parity.py" flow \
167
175
  --steps "$PARITY_OUT/steps.json" --out "$PARITY_OUT/parity-flow.md"
168
176
  ```
169
177
 
170
- 可用 action:`goto` `click` `fill` `press` `wait` `expect_text` `expect_visible` `expect_focused` `screenshot`。
171
- `wait` 吃 `selector`,或改吃 `{"action":"wait","ms":800}` 單純停一段時間——動畫沒有對應的 selector 可等時用這個。
178
+ 可用 action:
179
+
180
+ | action | 用途 |
181
+ |---|---|
182
+ | `goto` `click` `fill` `press` `hover` | 操作 |
183
+ | `wait` | 等 `selector`,或 `{"ms":800}` 單純停一段時間 |
184
+ | `wait_animations` | 等 `selector`(省略則整頁)底下所有有限次的 CSS/Web 動畫跑完 |
185
+ | `emulate` | 切換 `reduced_motion`(`reduce`/`no-preference`)、`color_scheme`、`media` |
186
+ | `expect_text` `expect_visible` `expect_focused` | 內容與 focus 斷言 |
187
+ | `expect_style` | computed style 斷言,見下方 |
188
+ | `save_box` `expect_box` | 記下元素位置大小,之後斷言沒有位移,或直接給 `x`/`y`/`width`/`height` |
189
+ | `axe` | 無障礙檢查,見下方 |
190
+ | `screenshot` | 存檔 |
191
+
192
+ ### expect_style:狀態與動畫的定量斷言
193
+
194
+ ```json
195
+ [
196
+ {"action": "hover", "selector": ".cta"},
197
+ {"action": "wait_animations", "selector": ".cta"},
198
+ {"action": "expect_style", "selector": ".cta", "styles": {"background-color": "#1565c0", "transition-duration": "200ms"}},
199
+ {"action": "expect_style", "selector": ".cta", "pseudo": "::after", "styles": {"opacity": "1"}},
200
+ {"action": "save_box", "selector": ".card", "as": "before"},
201
+ {"action": "click", "selector": ".card .expand"},
202
+ {"action": "wait_animations"},
203
+ {"action": "expect_box", "selector": ".card", "same_as": "before", "tolerance": 2},
204
+ {"action": "emulate", "reduced_motion": "reduce"},
205
+ {"action": "expect_style", "selector": ".cta", "styles": {"transition-duration": "0s"}}
206
+ ]
207
+ ```
208
+
209
+ - 期望值照設計稿的寫法就好(`#fff`、`300ms`、`1rem`),會先換算成瀏覽器的 computed 格式再比。
210
+ - 單一數值(px、s、ms)容許 `tolerance`(預設 0.5,時間以 ms 計);`expect_box` 預設容許 2px。
211
+ - 斷言「動畫結束後的狀態」一律先 `wait_animations`,不要用 `wait ms` 猜時間。
212
+
213
+ ### axe:無障礙檢查
214
+
215
+ ```json
216
+ {"action": "axe", "selector": "main", "exclude": [".third-party-widget"], "fail_on": "serious"}
217
+ ```
218
+
219
+ - 預設規則集 `wcag2a`、`wcag2aa`、`wcag21a`、`wcag21aa`,可用 `tags` 覆寫。
220
+ - `fail_on`(`minor`/`moderate`/`serious`/`critical`,預設 `serious`)以上的違規會讓這一步失敗;所有違規都會寫進報告。
221
+ - 在每個要驗的狀態各跑一次(例如 dialog 打開後),axe 只看得到當下的 DOM。
222
+ - axe-core 4.14.0 已 vendor 在 `scripts/vendor/`,不需要網路。
172
223
  預設第一個失敗就停(`--keep-going` 可跑完全部)。console error/warning 與失敗的 request 一律蒐集,這類問題不會反映在樣式比對裡。
173
224
  `--headed` 可開有頭瀏覽器讓人工旁觀。
174
225
 
@@ -185,11 +236,116 @@ TMPDIR="$PARITY_SCRATCH" python "<skill-dir>/scripts/parity.py" flow \
185
236
  - 副檔名 `.mp4` 會在錄完後用 ffmpeg 轉成 H.264(QuickTime 直接開),中間的 webm 自動刪除。**ffmpeg 不存在時不會失敗**,保留 `.webm` 並在 stdout 提示。副檔名寫 `.webm` 則完全不轉檔。
186
237
  - `--video-size WxH`(預設 `1280x720`)同時決定錄影解析度與 viewport。
187
238
  - `--video-tail <秒>`(預設 `1`)最後一步跑完後繼續錄的時間,避免收尾的動畫被切掉。
188
- - 影格率是 Playwright screencast 的 **25fps**,判斷「動畫有沒有做對」夠用;要判斷「掉不掉幀」不夠,那種要用 macOS `screencapture -v` 錄 60fps。
239
+ - **游標預設會畫**(`--no-cursor` 關掉)。Playwright 的 click 是直接派發事件、沒有指標移動,錄出來看不出點了哪裡;開了之後每個 `click`/`fill` 前會先讓游標走到目標中心(約 0.4 秒),按下時有藍色擴散環。要讓 reviewer 看懂互動的是哪個元件就加這個。
240
+ - 影格率是 Playwright screencast 的 **25fps**,判斷「動畫有沒有做對」夠用;要判斷「掉不掉幀」不夠,那種要錄 60fps:macOS 用 `screencapture -v`;Windows 沒有內建等效指令,用 OBS Studio(設定 60 FPS)或 Xbox Game Bar(`Win+Alt+R`,需在設定把影格率調成 60),兩者都沒有就標為「未驗:本機無法錄 60fps」。
189
241
  - 影片路徑會同時寫進報告開頭與 stdout。
190
242
 
243
+ ### --mutate:確認斷言真的會失敗
244
+
245
+ 新寫的 `expect_*` 沒看過它失敗就不算數——它可能在壞掉的頁面上也會過(例如對不存在的 `::after` 斷言 `content: none`)。加 `--mutate`,每個通過的斷言會在一個刻意弄壞的頁面上重跑一次:
246
+
247
+ | action | 怎麼弄壞 |
248
+ |---|---|
249
+ | `expect_style` `expect_box` | 移除所有 CSS |
250
+ | `expect_text` | 清空元素文字 |
251
+ | `expect_visible` | 隱藏元素 |
252
+ | `expect_focused` | 把 focus 移走 |
253
+
254
+ 弄壞後仍然通過的斷言標為 `INVALID`,寫進報告的 `mutation check` 段落並讓整次執行 exit 1。重跑會從頭執行到該斷言前一步,表單送出之類有副作用的步驟也會再跑一次。交付驗收證據前,新寫的 flow 至少用 `--mutate` 跑一次。
255
+
256
+
191
257
  新建的驗收 JSON 預設留在 `PARITY_OUT`,下次可用其實際路徑重跑。只有使用者明確要求保留程式碼回歸測試時,才放入專案(例如 `e2e/`);截圖、影片與其他驗收證據仍留在 Artifact,不 commit。
192
258
 
259
+ ## snapshot — 跟 Figma 設計稿截圖比對
260
+
261
+ Figma 的數值(`get_design_context` 給的字級、間距)跟瀏覽器實際 render 出來的結果常有落差:字體 metrics、行高計算、auto layout 換成 flex 後的取整。所以設計稿驗收看的是**畫面**,不是數值。
262
+
263
+ 1. 用 Figma MCP 的 `get_screenshot` 取得該 frame 的 PNG(它回傳短期 URL,照它給的 curl 指令下載到 `$PARITY_SCRATCH`;設計稿本身不是證據,diff 圖才是)。記下回應裡的 `original_width`,這是 frame 的 CSS 寬度。`maxDimension` 設成 `original_width × 2` 以上,比對精度才夠。
264
+ 2. 截本機同一區塊來比:
265
+
266
+ ```bash
267
+ TMPDIR="$PARITY_SCRATCH" python "<skill-dir>/scripts/parity.py" snapshot \
268
+ --ref-image "$PARITY_SCRATCH/figma-hero.png" \
269
+ --url https://localhost:3000/products \
270
+ --selector "section.hero" --width 1440 \
271
+ --out "$PARITY_OUT/parity-snapshot.md" --diff-image "$PARITY_OUT/a2-hero-vs-figma-1440.png"
272
+ ```
273
+
274
+ - `--selector` 對應 Figma frame 的那個區塊;省略則截整頁。`--width` 給 `original_width`。
275
+ - 本機截圖會縮放到設計稿的寬度再比。高度不同時只比重疊的部分,並把高度差列出來(超過 `--max-height-diff`,預設 8px,就算失敗)。
276
+ - **預設容忍反鋸齒**:先輕微模糊、再去掉孤立的像素,字體與曲線的 rasterize 差異不會被算進去,位置、尺寸、顏色、缺漏的變化會留下來。要逐像素比對就加 `--strict`。
277
+ - 預設凍結動畫、transition 與游標閃爍,並等 webfont 載入完成(`--no-freeze` 關掉凍結)。webfont 沒載入、退回系統字型,會直接顯示成大片落差。
278
+ - stdout 回報落差比例,以及前 5 個落差區域的 CSS 座標與該位置的本機元素;完整清單在報告裡。超過 `--max-mismatch`(預設 1%)就 exit 1。
279
+ - diff 圖是三格並排:設計稿|本機|落差(紅色是落差像素,藍框是編號區域)。**這張圖要人看**:agent 先讀報告的區域表,只在需要判斷「這是設計稿用了假資料,還是真的做錯」時才打開圖。
280
+
281
+ 設計稿常用假文案或假圖,這類區域一定會有落差。判斷方式:落差區域對到的元素如果是 CMS 內容,記為「內容不同」而不是「做錯」,並在回報裡分開列。
282
+
283
+ ## 驗收交付物規範
284
+
285
+ 被驗收流程(例如 `work-mode`)當成驗收證據時,除了跑得動,還要符合這些:
286
+
287
+ - **檔名** `<編號>-<驗收目標英文 slug>[-<寬度>].<png|mp4>`,一律小寫 kebab-case(中文與空白在 CLI/git/PR 連結會出事)。檔名要說「這在驗什麼」不是「這是什麼畫面」:`a3-faq-empty-state-no-results-375.png` ✅;`faq-page-375.png`、`after.png` ❌。
288
+ - **截圖逐張讀過才算檢查**,存檔不算。每張查五件事:元素重疊、內容溢出容器、非預期空白、文字截斷、水平溢出。
289
+ - **動畫與轉場不靠肉眼判**,要有定量斷言,用 flow 的 `wait_animations` + `expect_style`/`expect_box`/`emulate` 寫:動畫結束後的最終 computed style 與可見性、`transition-duration`/`animation-name` 確實掛上、`prefers-reduced-motion: reduce` 下確實關閉、轉場前後 bounding box 無非預期位移。
290
+ > 判斷測試:這條斷言重跑一百次結果一樣嗎?不一樣 → 它驗的是手感,不能拿來決定通過或失敗。
291
+ - **錄影**一段只涵蓋一條互動路徑、15 秒內,用 `flow --video`(見上節)。**不要用 `screencapture` 錄互動**——Playwright 派發的是合成事件,macOS 真實指標不會動,錄到的游標停在原地;`screencapture -v` 只在需要判斷掉幀時才用。agent 讀不了影片,唯一觀眾是人。
292
+
293
+ ## 專案驗證入口:scaffold_verify.py
294
+
295
+ 在 app repo 產生專案層的 `verify-<app>` skill(放在 repo 的 Claude Code 專案 skill 目錄):啟動/檢查/清理 dev server 的腳本、可搜尋的功能地圖(`features/`),以及每個功能一份 flow(`flows/<id>.json`,底層跑 `parity.py flow`,報告自帶 commit)。
296
+
297
+ ```bash
298
+ python "<skill-dir>/scripts/scaffold_verify.py" --repo <app repo> \
299
+ [--host auth.example.test --entry /auth/login --port 8443 --start "npm run dev -- --port $PORT"]
300
+ ```
301
+
302
+ 沒給的值會從 `package.json`、`vite.config.*`、`next.config.*` 偵測,猜的會標 `GUESSED`。產生後:
303
+
304
+ - `scripts/launch.sh` → `scripts/doctor.sh` → `scripts/verify.sh <feature-id> [--mutate]` → `scripts/cleanup.sh`
305
+ - `scripts/check-map.sh [--live]` 檢查地圖格式、索引、每個功能都有 flow,`--live` 再確認地圖裡每個路由都回 200。新增或改名頁面時跟著更新地圖,地圖才不會過時。
306
+
307
+ ## 報告開頭的來源欄位
308
+
309
+ 每份 `.md` 報告開頭與 stdout 都會寫:`commit`(`git rev-parse HEAD`,不在 git repo 裡是 `(not a git repo)`)、`working tree`(clean 或 dirty 與檔案數)、`url`、`run at`。PR 的 `**Verified at:**` 填這裡的 commit;`working tree` 是 dirty 時,證據對應的不是任何一個 commit,要在 `Not verified` 註明。
310
+
311
+ ## 驗收回報格式
312
+
313
+ 跑完 diff/responsive/flow/snapshot 後,回報**以驗收條件(AC)為主軸,不以工具為主軸**。讀者要知道的是「哪些條件過了、哪些沒過、哪些沒驗到」,不是「flow 跑了幾步」。各子指令的 `.md` 報告是證據,不要整份貼進回報。
314
+
315
+ ```markdown
316
+ ## 驗收結果:<功能或頁面名稱>
317
+
318
+ **結論**:<一句話。例如「3 項通過、1 項失敗、1 項內容不同待確認」>
319
+
320
+ | AC | 結果 | 證據 | 備註 |
321
+ |---|---|---|---|
322
+ | A1 hero 區塊符合設計稿 | ⚠️ 內容不同 | `snapshot` 2.1%,`a1-hero-vs-figma-1440.png` | 落差都在 CMS 標題,設計稿是假文案 |
323
+ | A2 hover 時 CTA 變色,reduced motion 下不做動畫 | ✅ | `flow` 步驟 3–6(`expect_style`) | |
324
+ | A3 dialog 打開後無 serious 以上無障礙違規 | ❌ | `flow` axe:`color-contrast` ×2 | `.dialog .hint` 對比 3.1:1 |
325
+
326
+ ### 覆蓋率缺口
327
+ - diff 1440px:`skipped-ambiguous` 159、`skipped-textless` 7。<其中有沒有關鍵區塊;有的話補了 `--map` 沒有>
328
+
329
+ ### 沒驗到的
330
+ - <例如:Figma 只有桌機版,375/768 只做了 diff 沒有設計稿比對>
331
+
332
+ ### 附檔
333
+ - `a1-hero-vs-figma-1440.png`、`a2-cta-hover-reduced-motion.mp4`、`parity-flow.md`
334
+ ```
335
+
336
+ 規則:
337
+
338
+ - **結果只有四種**,不要自創:
339
+ - ✅ 通過:有一個重跑會得到相同結果的證據。
340
+ - ❌ 失敗:附上失敗的值,例如「expected `#1565c0`, got `rgb(21, 101, 191)`」,不要只寫「顏色不對」。
341
+ - ⚠️ 內容不同:落差來自資料而不是實作(設計稿假文案、假圖,stage 與 local 的 CMS 資料不同)。必須寫出落差落在哪個元素、為什麼判斷是資料。
342
+ - ⏭️ 未驗:寫原因,並同時列進「沒驗到的」。
343
+ > 判斷測試:把這筆落差的資料換成一樣的,落差會消失嗎?會 → ⚠️ 內容不同;不會 → ❌ 失敗。判斷不了 → ❌,並在備註寫出疑點。
344
+ - **證據要能重跑**:寫出子指令、步驟編號或檔名。「看起來沒問題」「截圖確認過」不算證據,除非附上那張截圖,並寫出檢查了哪五件事(見上節)。
345
+ - **覆蓋率缺口不可省略**:`skipped-ambiguous` 或 `skipped-textless` 不是 0 時要列出來。數字是 0 也寫一行「無」,讓讀者知道有看過。
346
+ - **console 錯誤與失敗的 request** 有出現就列在對應 AC 的備註;不屬於任何 AC 的,另列在「沒驗到的」之後,標明「與本次改動無關」或「待確認」。
347
+ - AC 從 spec、issue 或 PLAN.md 抄過來,**編號沿用來源**。沒有正式 AC 時,用「頁面區塊+狀態」自己編,並在結論註明是自編的。
348
+
193
349
  ## 維護
194
350
 
195
- 改過 `parity.py` 後跑 `TMPDIR="$PARITY_SCRATCH" python "<skill-dir>/scripts/parity.py" selftest`,會用內建 fixture 驗證配對與 diff 邏輯仍正確;有安裝 OpenCV 時也驗證 `pixel` 的對齊、分類與遮罩,沒裝則略過並註明。
351
+ 改過 `parity.py` 後跑 `selftest`:`TMPDIR="$PARITY_SCRATCH" python "<skill-dir>/scripts/parity.py" selftest`,會用內建 fixture 驗證配對、diff、flow、`--mutate`、snapshot 與報告來源欄位仍正確,並檢查每個子指令與 flow action 都有寫進 README.md 與 SKILL.md(新增 action 卻沒寫文件就會失敗);有安裝 OpenCV 時也驗證 `pixel` 的對齊、分類與遮罩,沒裝則略過並註明。