1仕組みと動作原理
2つのパイプラインは同一の仕上がり外観と設計哲学を共有:スクリプトは機械的実行に専念し、自動化不能な2つの判断(内容に基づくページ順序整列、全ドキュメント検証)はエージェントが担う。
**Division of labor**: scripts carry execution; you (the agent) carry the two judgment steps — content-based page ordering, and whole-document verification. Neither can be automated away: filenames lie about order, and per-page spot checks miss wrong-slot bugs.
透視投影補正とホワイトバランスには内製OpenCVスクリプトを使用:photo_to_scan.py が最大輝度領域の四角形を検出してA4(200dpi)にワープ補正。--raw モードは補正のみ実行し、デフォルトモードでは色紙向けの前処理として「用紙背景色で除算」するホワイトバランスを追加実行。EXIF回転はPILの exif_transpose で事前修正(cv2.imread がEXIFを無視するため)。
The script handles EXIF rotation internally (`cv2.imread` ignores EXIF; phone photos come rotated — this silently produces sideways pages if you rectify with raw OpenCV).
「スキャン感」は noteshrink(uvx 外部ツール)のパレット量子化により実現:白紙は -w -g -K の一括グローバルパレットでインクや印章の色調を統一し、-c "true" で内部PDF生成をスキップして本スキル側で結合を実施。
uvx noteshrink -w -g -K -q -b ns -c "true" page_03.jpg page_01.jpg page_07.jpg ...
A4結合時のフチ刈り込み:assemble_pdf.py が各ページの上部24px・両脇12px(200dpi)をあらかじめトリミングして補正時に生じたデスク写り込みを除去。img2pdf によりパレットPNGを再エンコードなしで直接埋め込み、約0.05MB/ページを実現。
Edge crop (default 24px top / 12px sides at 200 dpi) removes the sliver of desk surface that rectification drags in along page borders; document margins dwarf it.
検証規律としての「全ドキュメントコンタクトシートの確認必須」:make_contact_sheet.py で一覧画像を生成し、エージェントがページ順・色被り・印章や署名を全ページ確認した上で、1〜2ページを原寸大でサンプリングして鮮鋭度を点検する。
**"I verified the pages I changed" is not verification.**
デジタル署名ブランチ(digital-signature-synthesis.md)は synthesize_signature.py の5つのサブコマンド(fonts/candidates/generate/locate/composite/scanify)で完結。フォントは candidates 比較シートからユーザーが選定(エージェントによる独断選択は禁止)、--seed で再現性を保証。
**Send the candidates sheet to the user and get a number back — do not pick one yourself.** Which style reads as a plausible signature is a taste call, not something derivable from the document or the font's technical properties.
合成署名の位置決めは pdftotext -bbox で署名欄ラベルを検出。フェイルセーフ機構として、ラベルと下線が1つの単語枠に結合された場合は WARNING を出力し、署名が宙に浮くのを防ぐためピクセル走査による右端特定を促す。
This means `pdftotext` tokenized your label together with whatever sits right after it on the same line — most commonly a signature blank authored as underscores immediately following the label with no space (`簽名:_____`, an entirely ordinary way to type this in Word).
2コア機能
3外部依存関係
| Kind | Dependency / Endpoint |
|---|---|
| cli | uvx noteshrink(扫描感增强,PEP 723 首跑 ~30s 构建) |
| cli | poppler pdftoppm / pdftotext(contact sheet / -bbox 定位) |
| package | opencv-python-headless / numpy / pillow / img2pdf(PEP 723 内联依赖) |
| cli | LibreOffice soffice(签名分支把 docx 渲染成页图) |
| cli | fc-list(fontconfig,发现手写体字体) |
4推奨統制措置と判定根拠
- scripts/: ローカルスクリプトまたはコマンドの実行: python photo_to_scan.py / assemble_pdf.py / make_contact_sheet.py / synthes
- 外部端点: ローカルコンテンツまたは会話のサードパーティクラウドストレージへの外部送信
- 本地工作目录: ファイルの読み書きおよび成果物の出力: rectify/enhance の中間PNG、結合された scanned.pdf、contact.png の指定作業ディレクトリへの書き出し。署名ブランチにおける署名ファイルの出力
5二重目の独立検証
- [ok] 主流水线 rectify→noteshrink→assemble→contact sheet — 四个环节命令与脚本均在;photo_to_scan.py --raw 与默认白平衡模式分支存在。
- [ok] EXIF/quad/白平衡实现 — load_exif_corrected 用 ImageOps.exif_transpose;find_page_quad/warp_a4/flatten_whitebalance 函数在 photo_to_scan.py 源码可定位。
- [ok] 边缘裁剪默认值 24/12px — assemble_pdf.py argparse default crop_top=24/crop_side=12 与 SKILL 一致。
- [ok] noteshrink 参数 -w -g -K -c "true" — SKILL 命令与外部工具语义一致(noteshrink 为 uvx 外部包,未在本仓捆绑,命令调用方式可核)。
- [ok] 『只查改动页不算验证』纪律 — SKILL 原文 + 两个 shipped-bug 叙事(错槽覆盖邻页、调色板污染)在 Step 5。
- [ok] 签名分支六子命令 — synthesize_signature.py subparsers fonts/candidates/generate/locate/composite/scanify 均实现;candidates→用户挑选→generate 流程与 reference 一致。
- [ok] 候选人选门禁(agent 不自选字体) — reference 原文 'do not pick one yourself';脚本 generate 需 --font/--face/--ink 显式参数。
- [ok] 无网络/凭证/删除面 — 全脚本扫描零网络代码、零 env 密钥读取;无删除用户文件逻辑;子进程均列表参数。
6結論
0e8f936e0a123f3a…