---
name: Stop hook で auto-publish 自動実行 (2026-05-04 導入)
description: ★★★★ 2026-05-04 Layer 1 自動化導入. Claude のターン終了毎に auto-publish.ts が自動実行されるよう .claude/settings.local.json に Stop hook 追加. timestamp drift で commit が連発しないよう generate-stats.ts も修正. Claude が手動で auto-publish を起動する必要が一切なくなった.
type: project
originSessionId: b3cff341-13fb-4ce3-b7d6-d194d09359a4
---
# Stop hook で auto-publish 自動実行 (2026-05-04 導入)

## 藤本さん要請

「上記の完全自動更新を何度もClaude先生が上記を行わなくて済むようなシステムには出来ないでしょうか？」 → Layer 1 (Stop hook) を選択.

## What changed

### 1. `.claude/settings.local.json` Stop hook 追加

```json
"Stop": [
  {
    "hooks": [
      {
        "type": "command",
        "command": "cd /c/Users/user/rei-aios && npx tsx scripts/auto-publish.ts --auto 2>&1 | tail -5",
        "timeout": 300,
        "statusMessage": "📤 auto-publish (rei-aios.pages.dev sync)..."
      }
    ]
  }
]
```

**効果**: Claude の全ターン終了後に auto-publish.ts が走る. 変更なし時は no-op 終了, 変更ありなら bundle rebuild + commit + push まで一気通貫.

### 2. `scripts/generate-stats.ts` timestamp preservation

数値フィールド (seed/step/test/papers/lean/metadb 等) が変わっていない時は updatedAt を既存の値に保持. Stop hook が毎ターン走る環境で、 timestamp だけ更新される無意味な commit が連発するのを防ぐ.

```typescript
if (fs.existsSync(outPath)) {
  try {
    const existing = JSON.parse(fs.readFileSync(outPath, 'utf-8'));
    const numericKeys = ['seed', 'step', 'test', 'peace', 'categories', 'papers', 'leanTheorems', 'metadbEntries'];
    const same = numericKeys.every(k => existing[k] === stats[k]);
    if (same && existing.updatedAt) stats.updatedAt = existing.updatedAt;
  } catch { /* fall through */ }
}
```

## 副次的に earlier same-day 修正された gap

Stop hook 導入の前段で (同 session 内で) 以下も完成:
- **build-site-stats.ts** が auto-publish.ts に Phase 1.13 として組み込まれた (commit c1d7b7d4) → invention 承認毎に index.html OGP/Twitter description も自動 patch される
- **community/discussions-templates/{charter-introduction, first-call-for-feedback}.md** の hardcoded 1554 → 1559 sync
- **TheoryExplorer.tsx** の hardcoded `1539→1554 反映済` を runtime fetch 説明に置換 (drift 防止)

## Performance characteristics

- **No-op turn** (source 変更なし): ~5-10 秒 (Phase 1-1.13 の各 build script は contentHash guard あり, timestamp preserved → Phase 3 stagedDiff 空 → 即 exit)
- **Real change turn** (invention 承認 / source 編集 etc.): ~30-90 秒 (vite build + commit + push)

## Layer 2/3 (未実装, 将来検討)

- **Layer 2**: Markdown 数値の template 化 ({{seed}} placeholder + build-time substitute) → 新 markdown でも hardcoded 数値が物理的に書けなくなる
- **Layer 3**: Pre-commit drift linter → hardcoded \d{4} (SEED count 候補) を markdown / .tsx で検出すれば commit 拒否

これらは構造的 drift 根絶用. 後付けで腰を据える時に検討.

## 関連 commits

- `c1d7b7d4` Wire build-site-stats into auto-publish + sync 1559 in community markdown
- `99e88a1f` Hook auto-publish to Claude Stop event (hands-off site sync)

## 関連 memory

- `project_auto_publish_system.md` ★★★★★ — auto-publish 仕様 (2026-05-01 起源)
- `project_next_session_auto_update_audit.md` — audit 結果 (2026-05-02 着手予定だった)
- `project_invention_approval_20260504.md` — 本日の invention 承認 (本 session トリガ)
