---
name: Auto-Publish System (rei-aios.pages.dev)
description: 2026-05-01 構築の自動更新 pipeline. Claude/藤本さんが手動 push する必要なく、学習サイクルが site を自動公開する仕組み
type: project
originSessionId: 4ff4b965-234a-4258-b31d-a8bcf83f071b
---
## 概要

2026-05-01 に commit `29f098c5` で導入された自動更新 pipeline。
理論が増えたり STEP が実装されると、Cloudflare Pages (rei-aios.pages.dev) が無人で自動更新される。

**Why**: 従来は Claude が手動で `npm run dev:build` + git commit + push を毎回実行する必要があった。コンポーネントに hardcode された数値 (`1,265+ theories`, `500`, `1524` 等) が古いままになる問題も発生。藤本さん「Claude 先生が他の事に時間が使えるように」要請。

**How to apply**:
- 通常の learning cycle (`scripts/rei-learning-cycle.bat`) が定期実行されれば自動で site も更新される
- 即時反映が欲しい時は `npm run watch:auto-publish` (live mode, 30s debounce)
- 手動実行は `npm run auto-publish` / `npm run auto-publish:dry` / `npm run auto-publish:force`

## アーキテクチャ

### 1. データ層 (rei-stats.json) — 既存の Phase 8e

`scripts/generate-stats.ts` が SEED_KERNEL/STEP/Papers/Lean/META-DB を JSON 化:
- `src/renderer/rei-stats.json` (build-time 初期値)
- `data/rei-stats.json`
- `dist-renderer/data/rei-stats.json` (runtime fetch 配信用)

学習サイクル Phase 8e で auto-commit + push 済 (既存)。

### 2. Bundle 層 (新規) — Phase 10

`scripts/auto-publish.ts`:
- src/renderer/ の mtime が bundle (`dist-renderer/assets/app-*.js`) より新しいか判定
- 新しい場合のみ vite build + sync index.html
- `dist-renderer/assets/` の旧 bundle は `git ls-files --deleted` で検出して `git rm`
- 変更があれば `Auto: site rebuild + stats refresh (...)` で commit + push
- 変更なし時は no-op

`scripts/rei-learning-cycle.bat` Phase 10 で `--auto` モード呼出。

### 3. UI 層 — runtime fetch パターン

Components は build-time 値を初期表示 → fetch 完了で最新値に書き換え:

```tsx
import REI_STATS_BUILD from "../../rei-stats.json";

const [stats, setStats] = useState<typeof REI_STATS_BUILD>(REI_STATS_BUILD);
useEffect(() => {
  fetch('/data/rei-stats.json?t=' + Date.now())
    .then(r => r.ok ? r.json() : null)
    .then(d => { if (d && typeof d.seed === 'number') setStats(d); })
    .catch(() => {});
}, []);
```

これで **rei-stats.json の更新だけで site の数値が反映 (bundle 再ビルド不要)**。

### 4. Live mode (opt-in)

`scripts/auto-publish-watch.ts` (`npm run watch:auto-publish`):
- `src/renderer` + `data/eternal-seed-kernel.json` + `papers/` 等を監視
- 30s debounce で auto-publish.ts を起動
- 実装中の即時反映用 (default は学習サイクル経由で十分)

## ハードコード撤去済 components (2026-05-01 時点)

- `ReiLauncher` — MENU_ITEMS desc に `{seed}/{papers}/{lean}/{metadb}/{step}` placeholder + render 時 `substituteStats` で展開
- `ReiDashboard` — SEED/STEP/Papers/Lean/META-DB/分野 8-card grid + runtime fetch
- `ReiDiscovery` — savedCount fallback 1524 → `SEED_FALLBACK` (REI_STATS_BUILD.seed)
- `DfumtFilter` — footer dynamic SEED/Papers/Lean
- `KnowledgeVoyage` / `KnowledgeUnification` — 既に runtime fetch 済 (2026-05-01 earlier session)

## 残タスク (将来の改善)

未対応 components が他にも約 25 個 (KnowledgeStream / ReiFetcher / ReiDaily / TheoryExplorer / ReiWill / LifeformPanel / MetaDBExplorer / ReiSimulation / HypervisorDemo / ReiNote / ReiQuiz / ReiDiagnose / 等) — ただし sweep で目視できる範囲では major hardcoded count なし (timer 値や era 表記が大半)。

新コンポーネントを書く時は **rei-stats.json runtime fetch パターン**を使うこと。hardcoded counts (`1544`, `142`, etc.) は書かない。

## Verification

```bash
npm run auto-publish:dry  # 動作確認 (commit/push なし)
npm run auto-publish      # 実行
npm test                  # 既存 step127 routes test 50/50 PASS で regression なし
```

## 関連 commits

- `29f098c5` Auto-publish system + runtime stats fetch (4 components)
- `55d19c78` Update Voyage + Unification with current Rei-AIOS state
- `a93df080` Hide RadarButton in production builds (keep for local dev)
