1仕組みと動作原理
明確な役割分担:コンテンツ分析と構造化はClaude(LLM)がStep 1〜6で行い、スクリプトは最終ステップ(Step 7)で組版修復のみを実行します。
Claude performs content analysis and formatting (Steps 1-6), then runs the script for typography fixes (Step 7).
コンテンツタイプを先行判定:frontmatter/見出し/太字/リスト/コードブロック/引用のいずれかに一致すればmarkdownと判定し、すべて不一致の場合のみプレーンテキストとして扱います。
| Has `---` YAML frontmatter | Markdown |
markdown検出時はユーザーに3つの選択肢を提示:フォーマット最適化、現状維持、組版修復のみ(後者は元のファイルを直接変更)。
1. Optimize formatting (Recommended)
frontmatterの自動補完:title/slug/summary/coverImageなどのメタフィールドをYAMLに書き込み、summaryはモデルによって100〜150文字の要約として生成されます。
| `summary` | Generate engaging summary (100-150 characters) |
タイトルの重複排除:本文の1行目がH1の場合、frontmatterのtitleに抽出し本文から削除することで、本文内でのH1の重複を防ぎます。
2. If first line is H1 → extract to frontmatter `title`, remove H1 from body
出力ファイル名は {original-filename}-formatted.md に固定され、上書き前に同名の既存成果物をタイムスタンプ付きでリネームしてバックアップします。
mv "{filename}-formatted.md" "{filename}-formatted.backup-$(date +%Y%m%d-%H%M%S).md"
組版スクリプト main.ts がファイルを読み込み、オプションに従って処理した上でインプレースで書き戻します。処理は決定論的な文字列/構文木の変換です。
writeFileSync(filePath, formattedContent, "utf-8");
スクリプトは複数の組版スイッチを提供:CJK強調の修復、CJK/英字のスペース調整、ASCII→全角引用符の変換、frontmatter YAMLのフォーマット。
| `scripts/quotes.ts` | Replace ASCII quotes with fullwidth quotes |
スペースの修復は自前実装ではなく、execSync を介して外部の npx autocorrect-node CLI を呼び出して実行されます。
execSync(`npx autocorrect-node --fix "${filePath}"`, { stdio: "inherit" });
スクリプトはremarkエコシステム(remark-cjk-friendly / remark-frontmatter / remark-gfm / unified など)に依存し、YAMLライブラリでfrontmatterの読み書きを行います。
"remark-cjk-friendly": "^1.1.0",
2コア機能
3外部依存関係
| Kind | Dependency / Endpoint |
|---|---|
| cli | bun / npx(npx -y bun 运行 main.ts) |
| package | autocorrect-node(npx 第三方 CLI,由 autocorrect.ts 调起) |
| package | remark 生态(remark-cjk-friendly / remark-frontmatter / remark-gfm / unified 等) |
| network | registry.npmjs.org(依赖与 npx 包拉取来源) |
4推奨統制措置と判定根拠
- scripts/: ローカルスクリプトまたはコマンドの実行: scripts/main.ts(npx -y bun で実行:ファイル読み込み → 組版処理 → インプレース書き戻し)
- 网络端点: 外部ネットワークアクセスの宣言: registry.npmjs.org(npx が初回実行時に autocorrect-node と bun 依存関係を取得。npx パッケージのバージョンは本リポジトリで未固定)
- 本地工作目录: ファイル読み書きおよび成果物の出力: {filename}-formatted.md(正式成果物)
5二重目の独立検証
- [ok] 无业务网络请求,仅 npx 拉包 — §3 URL 命中集中在 package-lock.json 的 registry/赞助链接;脚本无业务端点调用,唯一外发是 npx 拉 autocorrect-node。
- [ok] 本地读写与原地修改 — main.ts 以 readFileSync/writeFileSync 同路径读写;SKILL.md 的「Typography fixes only」路径直接改原文件,无副本。
- [ok] CJK 排版三能力 — emphasis(remark-cjk-friendly)、spacing(autocorrect-node)、quotes(quotes.ts 全角替换)三项在脚本职责与 SKILL.md 选项中均有对应。
- [ok] execSync 命令注入面 — autocorrect.ts 用模板串把 filePath 插进 shell 命令;同类 baoyu 版用 spawnSync(npxCmd, [...args]) 的数组形式,本版更弱,已记入 injection_surface 与 risks。
- [ok] 无凭证读取 — 目录内无 env/keychain/cookie 读取;仅检查 EXTEND.md 偏好文件是否存在(非凭证)。
- [ok] 与 baoyu 同型实现的差异 — canghe 版无 references/ 与分析底稿,目录更精简(7 文件);排版脚本形态由 spawnSync 改为 execSync。
- [ok] 依赖可复现性 — remark 生态在 package.json/package-lock.json/bun.lock 有锁定;但 npx autocorrect-node 未锁定具体版本。
6結論
535df884a21e0d2e…