1仕組みと動作原理
固定の折り返し幅で判定するのではなく、ステートマシン+次行先読み(look-ahead)が核となります。ハードラップが疑われる行に遭遇するたびに、「次の行が継続行に見えるか」(小文字開始/CJK文字開始/開き括弧/ハイフン・スラッシュ・アンダースコアでの継続)を判定し、幅の閾値ではなくこれに基づいて結合を決定します。
Instead of asking "was this line wrapped?" (fragile threshold), the script asks "does the next line look like a continuation?" by examining its content patterns — lowercase start, CJK ideograph start, opening bracket, hyphen/slash/underscore continuation.
10種類の内容(ユーザープロンプト、Claudeの返答、段落、テーブル、ツール呼び出し、ツール結果、planテキスト、agentツリー、区切り線、ツリー接続子)を個別に処理し、テーブルに対しては罫線の再構築および列幅に応じた再配置も行います。
The script handles 10 content types using a state-machine with next-line look-ahead
結合時にはCJKを意識した空白処理(pangu spacing)とトークン中間検出(mid-token detection)を実施します。ASCIIとCJKの境界には空白を挿入し、識別子・パス・ハイフンの中間で分割されている場合は空白を入れずに直接連結します。
**Pangu spacing**: Inserts spaces between ASCII alphanumeric characters and CJK ideographs at join boundaries.
出力は複数の再現性セーフティゲートを通過します。元ファイルの上書きは厳格に禁止され、マーカー記号(❯ ● ✻ ⎿ …)の入出力カウントの一致、極端に長い行(表示幅500超)への警告、およびサイレントフォールバックなしの厳格なUTF-8処理が強制されます。
- Never modifies the original file - Marker counts verified: `❯`, `●`, `✻`, `⎿`, `…` must match input/output
汎用(ファイル非依存)の自動検証スイート validate-claude-export-fix.py を付属させ、修正ごとの品質ゲートとして機能させます。
Runs a comprehensive suite of checks against a fixed file and its original, reporting PASS/FAIL for each with evidence.
完全ローカル・外部依存ゼロ:uv run で起動し、Python標準ライブラリのみを使用します。
Python 3.10+ via `uv run` — zero external packages (stdlib only: `unicodedata`, `argparse`, `re`, `pathlib`, `dataclasses`).
2コア機能
3外部依存関係
| Kind | Dependency / Endpoint |
|---|---|
| cli | uv |
| cli | python3 (>=3.10) |
4推奨統制措置と判定根拠
- scripts/: ローカルスクリプトまたはコマンドの実行: scripts/fix-claude-export.py
- 本地工作目录: ファイルの読み書きと成果物の出力: *-fixed.txt を出力(デフォルトは <input-stem>-fixed.txt、-o で指定可能。main() で output が input と同一にならないよう強制)
5二重目の独立検証
- [ok] 无网络外发(脚本层) — 全目录无 urllib/requests/http 调用,grep https?:// 零命中(连文档链接都没有)
- [ok] 无凭证读取 — 无 os.environ/getenv/API_KEY/settings.json 读取;脚本只读用户显式传入的 export 路径
- [ok] 不改原文件声明属实 — main() 先比较 resolve 后的 input/output 路径,相等即报错退出
- [ok] marker 计数保真声明属实 — _count_markers 统计 ❯/●/✻/⎿/…,输出不一致打印 WARNING
- [ok] '10 content types' 与 '53 automated checks' 能力声明 — SKILL.md What Gets Fixed 列出 10 类;validate 脚本为分 category 的断言套件,'53' 为 SKILL 侧声明数
- [ok] 零第三方依赖声明 — 脚本 import 仅标准库;uv 只作为启动器出现于 SKILL.md 命令
6結論
d5562a9e134ff1b7…