1实现原理 · 为什么它能做到
两步分离是核心 trick:先在被测 CLI 的真实 shell 里把全保真 ANSI 落成 .ansi 文件,再单独渲染成 PNG——绝不让渲染器替你执行命令,因为 freeze 的子 pty 会让 delta/lazygit 探测到降级环境而静默丢掉背景块/行号列/头框。
The single most important rule: **never let the renderer run the command for you.**
渲染侧双层回退:render_ansi.sh 优先 freeze(charmbracelet,背景块/行号盒忠实),找不到则 python3 ansi2html.py(纯 stdlib 的 ANSI→HTML)+ 无头 Chrome 截图。
# Prefers charmbracelet/freeze (faithful background blocks, line-number boxes, # window chrome). Falls back to a zero-dependency stdlib HTML renderer + # headless Chrome when freeze is not installed.
ansi2html.py 只处理真实 CLI 会发的 SGR 子集:24-bit truecolor(38;2;r;g;b/48;2;r;g;b)、256 色(38;5;n + xterm 调色板映射)、bold、reset(0/39/49);关键是把背景色块(delta 的增删底色)保真下来,文本一律 html.escape 防注入。
Background color blocks (48;...) are preserved faithfully — that is the whole point, since tools like delta encode add/remove as background blocks.
背景色必须匹配真实终端,否则深色主题在白底上误判对比度;SKILL 给 macOS Ghostty 取背景命令与常见默认值(#282c34/#1d1f21)。
**Background color must match the real terminal**, or a dark theme verified on a white page looks wrong.
TUI 程序(lazygit/htop/top)被显式划出范围:它们用光标定位画全屏,不是线性 ANSI 流,无法用此法捕获;验证其颜色要拆出底层(如 lazygit 的 diff 走 delta 配置)。
## TUI programs (lazygit, htop, top) — out of scope
渲染结果由 agent 用 Read/图像工具读回做视觉判断——把『十六进制猜色』换成『看真实渲染的对比度/对齐/背景块』。
Then read the PNG with the Read tool and judge the colors.
2核心能力
3外部依赖
| 类型 | 依赖 |
|---|---|
| cli | freeze(charmbracelet/freeze,首选渲染器,可选) |
| cli | Google Chrome(无头模式,回退渲染路径;路径硬编码 macOS) |
| cli | python3(ansi2html.py 运行环境,纯 stdlib) |
| cli | go/brew(仅安装 freeze 时的可选项) |
4风险提醒 风险提醒:蓝色 · 知晓即可
- Chrome 回退路径的 --no-sandbox — 无沙箱渲染本地 HTML;内容虽已转义,若上游 .ansi 来自不可信/远程来源仍应警惕(正常用法是本地 CLI 输出)。
- 平台局限 — Chrome 路径硬编码 macOS;Windows/Linux 无 freeze 时回退不可用(会报错退出),需改脚本或装 freeze。
- 视觉判断仍是模型主观 — 渲染保真度依赖 freeze/Chrome 的字体与背景处理;模型对 PNG 的『对比度是否足够』判断可能有偏差,SKILL 定位为辅助证据。
5第二遍独立确认
- [ok] 文本是否先转义再进 HTML(防注入) — ansi2html.py 'esc = H.escape(p)' 后拼入 span/裸文本;输出文档无其他用户可控拼接。
- [ok] Chrome --no-sandbox 与降级面 — render_ansi.sh 回退路径含 --no-sandbox;渲染对象为本地生成、已转义的 HTML;freeze 存在时该路径不触发。
- [ok] 无网络外发/凭证读取 — 两脚本无 curl/wget/http/url/env 密钥访问;go install 仅出现在 SKILL.md 安装指引(用户主动)。
- [ok] SKILL 声称的每工具捕获配方 — 配方表为文档层指引(agent 在 shell 执行),脚本不含这些 CLI 调用,无隐藏依赖。
- [ok] TUI 边界声明与实现一致 — SKILL 明确 TUI 光标定位无法线性捕获;脚本只处理线性 ANSI 流输入。
- [unlocatable] freeze/Chrome 实际渲染保真度 — 依赖外部渲染器行为(背景块/行号盒/字体度量),本环境未实装 freeze/Chrome,未做端到端截图验证。
6结论
f71128c440db3c5b…d5c4678cb5