1仕組みと動作原理
パイプラインは extract → look → (translate) → build → verify で構成され、中間の「確認(look)」と末尾の「検証(verify)」が忠実性の真の源泉と位置付けられています(PDFはテキストストリームではなく視覚的レイアウトであるため)。
The pipeline is **extract → look → (translate) → build → verify**. The middle "look" and final "verify" steps are where faithfulness actually comes from: a PDF is a layout, not just a text stream, so you read the rendered pages before building and the rendered HTML before delivering.
extract_pdf.py は再確認可能な中間状態を出力します:structure.json(各ページのテキストブロックとbbox・最大フォントサイズ、装飾画像フラグ付きの画像ブロック)+ images/ + 各ページのレンダリングPNG。閲覧順序はPyMuPDFの get_text('dict') のブロック順を継承します。
The point of a separate extraction step is a *verifiable intermediate output*: structure.json is the plan. Inspect it (and the rendered page PNGs) before building, instead of going PDF -> HTML in one opaque jump.
build_html.py はデータ駆動型の汎用ビルダーです。フォントサイズの統計から見出しレベルを推定(最頻サイズ=本文、それより大きいものを順次 h3/h2/h1 に昇格)、装飾画像を除去し、コンテンツ画像をbase64としてインライン圧縮することで、ダブルクリックで開ける単一ファイルを生成します。
`build_html.py` is **data-driven**: it infers heading levels from font size (most common size = body; larger steps up to h3/h2/h1), drops decorative images, and inlines content images as compressed base64 → one portable file. It is not hand-tuned to any document.
翻訳ブランチは「全文機械翻訳」を行わず、references/translation_workflow.md に従いエージェントが Dynamic Workflow でページ並行翻訳、図表・キャプションの個別処理、用語統一を行い、build に渡す2つのオーバーレイ(units.json/caps.json)を生成します。
It produces two overlay files (`units.json`, `caps.json`) that step 4 consumes. **Do not** hand-translate inline for anything longer than a page — the workflow keeps terminology consistent and is far faster.
強制的な視覚検証:verify_render.py はヘッドレスChromeでスクリーンショットを取得し、約2600pxごとにスライスします(16384pxの制限を回避するため、まず1倍で実際の高さを計測し、最大device-scale-factorを選択)。エージェントは各 seg-*.png を Read で確認する必要があります。
```bash uv run --with Pillow --with numpy python scripts/verify_render.py output.html ``` Then **Read every `seg-*.png`** and check: fonts render (no tofu boxes), no clipped tables/figures, headings/lists look right, all expected images present.
忠実性に関する鉄則は references/failure_cases.md に記載されています。人名や固有名詞を推測で翻訳することは一切禁止し、すべての数値や固有名詞は一字一句そのまま転記すること(failure_cases #6)が翻訳前に求められます。
The one that bites hardest: **never give a real person an inferred translated name, and copy every number/proper-noun verbatim** (failure_cases #6). Read that file before any translation run; skim it before any run.
2コア機能
3外部依存関係
| Kind | Dependency / Endpoint |
|---|---|
| package | PyMuPDF (fitz)(extract_pdf.py,uv run --with pymupdf) |
| cli | Google Chrome / Chromium(headless 视觉验证) |
| package | Pillow / numpy(build 与 verify,uv --with) |
4推奨統制措置と判定根拠
- scripts/: ローカルスクリプトまたはコマンドの実行: python extract_pdf.py / build_html.py / verify_render.py(ローカル解析/ビルド)
- 外部端点: ローカルコンテンツやセッションのサードパーティクラウドストレージへの外部送信
- 本地工作目录: ファイルの読み書きおよび成果物の出力: input-build/(structure.json、images/、pages/ 各ページのPNG)
5二重目の独立検証
- [ok] extract→look→build→verify 管线 — SKILL 三步命令与三个脚本一一对应;structure.json 字段(bbox/字号/decorative)在 extract_pdf.py 实现。
- [ok] 字号推断标题层级 — build_html.py 从 font size 推断 h3/h2/h1 的逻辑在 docstring 与代码中均有('larger sizes step up to h3/h2/h1')。
- [ok] base64 内联单文件 — build_html.py data_uri():压缩→JPEG/PNG→base64;'single portable .html you can double-click' 相符。
- [ok] decorative 判定启发式 — extract_pdf.py:DECORATIVE_MAX_BYTES=3000 + bbox 重复 > 半数页面(max(2, npages//2))。
- [ok] 强制视觉验证 headless Chrome 分片 — verify_render.py:1x 探高 + device-scale-factor 选择 + SEGMENT_PHYSICAL 分片;SKILL 要求 Read every seg-*.png。
- [ok] 翻译 overlay 机制 — translation_workflow.md 存在且描述 units.json/caps.json 产出;build_html.py 接受 --translation/--captions 参数。
- [ok] 无网络外发/转义防注入 — 三脚本无 requests/urllib/http;build_html.py md() 对段落文本 html.escape;--no-proxy-server 防代理泄漏。
- [ok] 元数据 — GitHub API:MIT / 1385 stars / pushed 2026-09-09T12:33:29Z;本地 HEAD==pin d5c4678。
6結論
a8f3ffec2f8cdcaa…