From e57e7dc57f8b4e268a988aaa8b662cccceb0e198 Mon Sep 17 00:00:00 2001 From: yudshj Date: Tue, 8 Sep 2026 11:29:08 +0800 Subject: [PATCH] feat(skills): record browser GIFs with Playwright video --- ...08-08-browser-gif-evidence-chain.i18n.yaml | 4 +- .../2026-08-08-browser-gif-evidence-chain.md | 2 +- ...026-08-08-browser-gif-evidence-chain.zh.md | 2 +- .../2026-09-08-playwright-video-gif.i18n.yaml | 6 + .../2026-09-08-playwright-video-gif.md | 29 ++++ .../2026-09-08-playwright-video-gif.zh.md | 29 ++++ .agents/skills/record-browser-gif/SKILL.md | 95 ++++++++----- .../record-browser-gif/scripts/encode_gif.py | 126 +++++++++++++----- .../scripts/test_encode_gif.py | 103 ++++++++++++++ 9 files changed, 326 insertions(+), 70 deletions(-) create mode 100644 .agents/notes/implemented/process/2026-09-08-playwright-video-gif.i18n.yaml create mode 100644 .agents/notes/implemented/process/2026-09-08-playwright-video-gif.md create mode 100644 .agents/notes/implemented/process/2026-09-08-playwright-video-gif.zh.md create mode 100644 .agents/skills/record-browser-gif/scripts/test_encode_gif.py diff --git a/.agents/notes/implemented/process/2026-08-08-browser-gif-evidence-chain.i18n.yaml b/.agents/notes/implemented/process/2026-08-08-browser-gif-evidence-chain.i18n.yaml index e09c768aba..9c2446d606 100644 --- a/.agents/notes/implemented/process/2026-08-08-browser-gif-evidence-chain.i18n.yaml +++ b/.agents/notes/implemented/process/2026-08-08-browser-gif-evidence-chain.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write .agents/notes/implemented/process/2026-08-08-browser-gif-evidence-chain.md -2026-08-08-browser-gif-evidence-chain.md: 8a7c28792bbab178cac6ba6743628882a15fdf6e -2026-08-08-browser-gif-evidence-chain.zh.md: ff9b6cc729c23dd9f3ba170752fa05fe65c7fb53 +2026-08-08-browser-gif-evidence-chain.md: 66d4679de6fa462a5287b262cc6df3ed5f75084c +2026-08-08-browser-gif-evidence-chain.zh.md: 1d87768fcfd8460cdf1b7958ee562137f2b8e1ea diff --git a/.agents/notes/implemented/process/2026-08-08-browser-gif-evidence-chain.md b/.agents/notes/implemented/process/2026-08-08-browser-gif-evidence-chain.md index 8a7c28792b..66d4679de6 100644 --- a/.agents/notes/implemented/process/2026-08-08-browser-gif-evidence-chain.md +++ b/.agents/notes/implemented/process/2026-08-08-browser-gif-evidence-chain.md @@ -16,7 +16,7 @@ The [`record-browser-gif`](../../../skills/record-browser-gif/SKILL.md) workflow Browser automation waits for unique, exact semantic states. When the claim concerns a tool call, rejection, or recovery, the storyboard includes a detail or trajectory frame that identifies the tool, shows its status or stable error code, and shows the downstream result. The final encoded GIF remains the verification subject; when a viewer cannot animate it, representative frames are decoded from that GIF instead of treating source screenshots as equivalent evidence. -The available browser-control workflow remains preferred. When it is unavailable, the recorder uses the repository-declared Playwright dependency in an isolated headless browser rather than installing another driver or opening the user's browser. A native production surface may be replaced only through normal application configuration with an official browser-operable production backend, and that override is stated next to the GIF. Fixtures, mock transports, synthetic events, and test-only hooks do not substantiate a real-production claim. +The [Playwright video decision](2026-09-08-playwright-video-gif.md) owns recording-backend selection and timing. The recorder uses the repository-declared browser dependency without installing another driver or opening the user's browser. A native production surface may be replaced only through normal application configuration with an official browser-operable production backend, and that override is stated next to the GIF. Fixtures, mock transports, synthetic events, and test-only hooks do not substantiate a real-production claim. Publication verifies the boundary again. The preferred path attaches with `gh --attach` (v2.99.0 or later; github.com only; at most 10 MB): the body file references the local GIF path, the command uploads the verified artifact and rewrites that reference in place, and the live body must then show the rewritten uploaded URL, which must respond with `200` and `image/gif`. When attach cannot apply — the GIF exceeds 10 MB, `gh` is older, or the repository is GitHub Enterprise Server — the assets-branch path remains: the branch contains media only, the staged and published bytes match the verified artifact, and a private-repository asset is checked through authenticated API or raw requests for its path, byte size, checksum, response status, and media type, proving only the repository-member review path (the [documentation-site image decision](../../archived/process/2026-08-06-doc-site-carries-its-images.md) owns why a public site cannot depend on a private raw URL). Immediately before the pull-request body changes, the live head must still equal the recorded head. After the edit, the live head is checked again and must remain at that recorded value; GitHub's Markdown renderer separately must produce the expected image. diff --git a/.agents/notes/implemented/process/2026-08-08-browser-gif-evidence-chain.zh.md b/.agents/notes/implemented/process/2026-08-08-browser-gif-evidence-chain.zh.md index ff9b6cc729..1d87768fcf 100644 --- a/.agents/notes/implemented/process/2026-08-08-browser-gif-evidence-chain.zh.md +++ b/.agents/notes/implemented/process/2026-08-08-browser-gif-evidence-chain.zh.md @@ -16,7 +16,7 @@ Status: implemented 浏览器自动化会等待唯一且精确的语义状态。如果需要证明工具调用、拒绝或恢复,分镜就必须包含详情帧或轨迹帧:标明工具、显示其状态或稳定错误码,并展示后续结果。最终编码出的 GIF 始终是验证对象;如果查看器无法播放动画,应从该 GIF 中解码出代表性帧,而不能将源截图视为等效证据。 -仍应优先使用已有的浏览器控制工作流。如果该工作流不可用,录制程序应在隔离的无头浏览器中使用仓库已声明的 Playwright 依赖,而不是安装其他驱动或打开用户的浏览器。只有通过正常应用配置选用官方且可由浏览器操作的生产后端,才能替换原生生产界面,并且必须在 GIF 旁注明这一覆盖。fixture(测试前置数据)、mock 传输层、合成事件和测试专用钩子均不能支撑真实生产实现的主张。 +[Playwright 视频决策](2026-09-08-playwright-video-gif.zh.md)规定录制后端的选择和时序。录制程序使用仓库已声明的浏览器依赖,不安装其他驱动,也不打开用户的浏览器。只有通过正常应用配置选用官方且可由浏览器操作的生产后端,才能替换原生生产界面,并且必须在 GIF 旁注明这一覆盖。fixture(测试前置数据)、mock 传输层、合成事件和测试专用钩子均不能支撑真实生产实现的主张。 发布环节会再次验证边界。首选路径使用 `gh --attach` 上传(v2.99.0 或更高版本;仅限 github.com;不超过 10 MB):正文文件引用本地 GIF 路径,命令上传已验证的产物并把该引用就地改写,之后在线正文必须显示改写后的上传 URL,且该 URL 必须返回 `200` 与 `image/gif`。当 attach 无法使用时——GIF 超过 10 MB、`gh` 版本过旧或仓库位于 GitHub Enterprise Server——仍保留资产分支路径:该分支只包含媒体文件,暂存和发布的字节必须与已验证产物一致,私有仓库中的资产须通过经身份验证的 API 或原始内容请求检查其路径、字节大小、校验和、响应状态和媒体类型,这只能证明仓库成员的评审访问路径([文档站点图片决策](../../archived/process/2026-08-06-doc-site-carries-its-images.md)解释了公共站点为何不能依赖私有的原始内容 URL)。修改 PR 正文之前,必须再次确认在线 head 仍与录制时的 head 相同。编辑后还要再次检查在线 head,且它必须保持为该记录值;GitHub 的 Markdown 渲染器则须单独生成预期图片。 diff --git a/.agents/notes/implemented/process/2026-09-08-playwright-video-gif.i18n.yaml b/.agents/notes/implemented/process/2026-09-08-playwright-video-gif.i18n.yaml new file mode 100644 index 0000000000..1982c9ff56 --- /dev/null +++ b/.agents/notes/implemented/process/2026-09-08-playwright-video-gif.i18n.yaml @@ -0,0 +1,6 @@ +# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each +# side as of the last confirmed-consistent state. Both languages carry equal authority; +# after editing either side, bring the other along and re-record with: +# pnpm run verify-translation-pairing --write .agents/notes/implemented/process/2026-09-08-playwright-video-gif.md +2026-09-08-playwright-video-gif.md: d3512ebdbfa781f178ee2e891db2bd5e79a5d7e5 +2026-09-08-playwright-video-gif.zh.md: 17c082fcfb36dd8d1e099a867b0ef185c770fde2 diff --git a/.agents/notes/implemented/process/2026-09-08-playwright-video-gif.md b/.agents/notes/implemented/process/2026-09-08-playwright-video-gif.md new file mode 100644 index 0000000000..d3512ebdbf --- /dev/null +++ b/.agents/notes/implemented/process/2026-09-08-playwright-video-gif.md @@ -0,0 +1,29 @@ +# Agent Note: Playwright video captures continuous browser demos + +Status: implemented + +English | [中文](2026-09-08-playwright-video-gif.zh.md) + +## Problem + +A screenshot storyboard omits motion between verified UI states and can miss short-lived progress indicators. Browser tooling also varies between agent environments. GIF production needs a repeatable recording path that preserves interactions and keeps text readable without adding a browser driver dependency. + +## Decision + +The [recording skill](../../../skills/record-browser-gif/SKILL.md) prefers the repository-declared Playwright dependency with `recordVideo` in an isolated context. Viewport and video dimensions match explicitly, avoiding Playwright's default scaling to fit 800×800. The recorder retains the page video, awaits context closure, and saves the completed WebM before encoding. Screenshot storyboards remain available when video recording is unavailable or explicitly unwanted. + +One encoder accepts either a video file or a screenshot directory. Video input selects one continuous interval, applies a declared playback multiplier, and extends its final frame. The JSON summary records source duration, selected interval, speed, final hold, and encoded dimensions, duration, frame count, and size. Mode-inappropriate options and invalid intervals fail. The original video remains available for review; trimming and speed never establish model response latency. + +This choice replaces only the browser-control-first preference in the [evidence-chain decision](2026-08-08-browser-gif-evidence-chain.md). That note continues to own isolated application state, real model execution, exact commit attribution, and verified publication. Failed recordings cannot contribute frames to a successful run. + +## Alternatives considered + +**Keep screenshots as the default.** Explicit state holds make small, legible GIFs, but omit scrolling, animation, and interactions between states. They remain useful as a fallback and for a requested storyboard. + +**Install a separate recorder or capture the desktop.** The repository already declares Playwright. Another driver adds setup and version management; desktop capture can include unrelated windows and personal state. + +## Consequences + +Continuous recording preserves intermediate states, so reviewers must inspect the selected interval for sensitive content and readability. Raw video consumes additional scratch storage, and encoding may require trimming or scaling to meet the byte limit. Context closure is part of successful recording, not optional cleanup. + +The encoder's local Python unittest suite invokes real ffmpeg and ffprobe to check timing, palette order, screenshot holds, rejected options, overwrite protection, and size limits. It requires the skill's media prerequisites and is run explicitly; repository CI does not provision these media binaries. Product demonstrations additionally exercise the pull request's built server and real model flow. diff --git a/.agents/notes/implemented/process/2026-09-08-playwright-video-gif.zh.md b/.agents/notes/implemented/process/2026-09-08-playwright-video-gif.zh.md new file mode 100644 index 0000000000..17c082fcfb --- /dev/null +++ b/.agents/notes/implemented/process/2026-09-08-playwright-video-gif.zh.md @@ -0,0 +1,29 @@ +# Agent Note: Playwright 视频录制连续浏览器演示 + +Status: implemented + +[English](2026-09-08-playwright-video-gif.md) | 中文 + +## 问题 + +截图分镜省略了已验证 UI 状态之间的运动,也可能遗漏短暂的进度指示。不同代理环境提供的浏览器工具也不一致。GIF 制作需要可重复的录制路径,保留交互、保证文字可读,同时不增加浏览器驱动依赖。 + +## 决策 + +[录制 skill](../../../skills/record-browser-gif/SKILL.md) 优先使用仓库已声明的 Playwright 依赖,在隔离上下文中启用 `recordVideo`。显式设置相同的 viewport 与视频尺寸,避免 Playwright 默认缩放到 800×800 以内。录制程序保留页面视频对象,等待上下文关闭,再保存完整 WebM 并编码。视频录制不可用或用户明确不需要时,仍可使用截图分镜。 + +同一编码器接受视频文件或截图目录。视频输入选择一个连续区间,应用明确标注的播放倍率,并延长末帧。JSON 摘要记录源视频时长、所选区间、倍率、末帧停留时间,以及编码后的尺寸、时长、帧数和大小。与输入模式不符的选项及无效区间会失败。保留原视频供检查;裁剪与变速不能证明模型响应延迟。 + +本决策仅替代[证据链决策](2026-08-08-browser-gif-evidence-chain.zh.md)中优先使用浏览器控制工作流的偏好。该记录继续规定应用状态隔离、真实模型执行、准确提交归属及发布验证。失败录制的画面不得用于成功运行。 + +## 曾考虑的替代方案 + +**默认使用截图。**明确的状态停留可以生成小巧、易读的 GIF,但会省略状态之间的滚动、动画和交互。截图仍适合作为备用方案,或用于用户要求的分镜。 + +**安装独立录制器或录制桌面。**仓库已经声明 Playwright。另一套驱动增加安装与版本管理成本;桌面录制可能包含无关窗口和个人状态。 + +## 后果 + +连续录制保留中间状态,因此检查者必须查看所选区间是否包含敏感内容,以及画面是否易读。原始视频占用额外临时空间,编码时可能需要裁剪或缩放以满足字节上限。关闭上下文是成功录制的一部分,不是可选清理。 + +编码器的本地 Python unittest 测试调用真实 ffmpeg 和 ffprobe,检查时序、调色板顺序、截图停留、选项拒绝、覆盖保护和大小限制。测试依赖 skill 要求的媒体工具,需显式运行;仓库 CI 不预装这些媒体程序。产品演示还会执行 PR 构建后的服务器与真实模型流程。 diff --git a/.agents/skills/record-browser-gif/SKILL.md b/.agents/skills/record-browser-gif/SKILL.md index 93a55769c0..5cca387f54 100644 --- a/.agents/skills/record-browser-gif/SKILL.md +++ b/.agents/skills/record-browser-gif/SKILL.md @@ -1,11 +1,11 @@ --- name: record-browser-gif -description: Record browser or Web UI interaction demos as optimized GIFs using the available built-in browser, state-based frame capture, and deterministic encoding, then attach the GIF to a pull request with `gh --attach`, falling back to a dedicated assets branch where attach cannot apply. Use when asked to make, record, or generate a GIF that demonstrates a browser workflow, and for every pull request that changes product-user-visible GUI behavior, which MUST include a GIF recorded from the pull request's real server and model flow. +description: Record browser or Web UI interaction demos as optimized GIFs using Playwright Videos and deterministic encoding, with screenshot capture when video is unavailable, then attach the GIF to a pull request with `gh --attach`, falling back to a dedicated assets branch where attach cannot apply. Use when asked to make, record, or generate a GIF that demonstrates a browser workflow, and for every pull request that changes product-user-visible GUI behavior, which MUST include a GIF recorded from the pull request's real server and model flow. --- # Record Browser GIF -Produce a short, truthful UI demonstration as a local GIF, and — only when the task includes attaching it to a pull request — publish it through the attach workflow at the end of this skill. Use the browser-control skill for interaction and the bundled encoder for repeatable timing, dimensions, and size. +Produce a short, truthful UI demonstration as a local GIF, and — only when the task includes attaching it to a pull request — publish it through the attach workflow at the end of this skill. Prefer the repository-declared Playwright dependency with [Videos](https://playwright.dev/docs/videos); use the bundled encoder for trimming, playback speed, final hold, dimensions, and size. The [evidence-chain decision](../../notes/implemented/process/2026-08-08-browser-gif-evidence-chain.md) owns why one storyboard comes from one isolated run and why publication revalidates both the artifact and the demonstrated pull-request head. @@ -17,7 +17,7 @@ The recording itself is part of the evidence: use a real server booted from that ## Keep recording separate from publication -- Recording produces frame images and one local `.gif` artifact only; it never mutates remote state. +- Recording produces local video or screenshots and one `.gif` artifact only; it never mutates remote state. - Publication — attaching the GIF to a pull request body with `gh --attach`, or pushing it to an assets branch and embedding its URL where attach cannot apply — is the separate final step, performed only when the task includes attaching the GIF to a pull request. It never touches the pull request's own branch. - Preserve the requested recording conditions. A real-server or real-API demo must not use fixture queries, mock transports, synthetic event injection, or test-only hooks. If credentials or the server are unavailable, report that limitation instead of substituting a fixture. - Never read or expose credential values. Use the application's normal configuration path and a benign demonstration prompt. @@ -31,51 +31,80 @@ A GIF for a specific pull request demonstrates that pull request's tree, so stag 3. Treat one storyboard as one evidence run: every published frame comes from that server and those state roots, workspace, session, and model-backed scenario run. If capture automation fails, discard its frames and rerun from fresh roots; never splice frames from separate runs. 4. When switching between pull requests, stop the old server by PID or an exact match on its command line. A broad `pkill -f` pattern can match and kill the shell that launched it — including your own. -## Record the flow +## Record with Playwright Videos -1. Invoke the available browser-control skill and follow its setup, interaction, and cleanup instructions. Use the user's existing Chrome state only when requested or required; state that exception in the provenance and do not claim fresh client state. If browser control is unavailable, use the repository-declared Playwright dependency in an isolated headless browser; do not install another driver or launch the user's browser. State that fallback in the provenance. -2. Before recording, identify the exact origin, whether the app is built or in development, the transport, and any fixture or mock mode. Record only claims that the observed setup supports. -3. When a production default opens a native operating-system surface that headless automation cannot drive, select an official browser-operable production backend through the application's normal configuration. State the override in the provenance; a fixture, mock transport, or test-only hook is not an acceptable substitute. -4. Choose three to six states that tell one story, such as typed, running, settled, and detail. Prefer semantic state changes over continuous capture; omit loading churn that does not help the viewer. -5. Keep one viewport and crop for every frame, and name frames lexically: `00-initial.png`, `01-typed.png`, and so on. -6. Store frames under the repository's gitignored `.playwright-mcp/` directory — browser-tool screenshots can only be written under the tool's allowed roots, and relative filenames resolve against the repository root. Create the frame subdirectory first (`mkdir -p .playwright-mcp/gif-frames-