---
name: project-rei-memory-mcp-phase1-arc-2026-08-19
description: rei-memory-mcp Phase 1 (read-only SEED_KERNEL MCP) 単日 arc — 実装指示書 → 実データ dump → skeleton → 53/53 test PASS → GitHub public + Claude Desktop launcher fix + 3 finding (lone surrogate / trigram 2-char / remote deploy lag 2 件差)
metadata:
  type: project
---

# rei-memory-mcp Phase 1 arc (2026-08-19)

## 契機

藤本さん Downloads asset `rei-memory-mcp_実装指示書_Phase1.md` (chat-Claude 事前設計版) 起点。 前提: **Phase 1 は読み取り専用**。 「書き込みから作ると、 誤った記憶が定着する経路が最初からできてしまう」 = 書き込みは Phase 2 以降の `seed_propose` 承認 flow に閉じる。

## 3 turn 前工程 (勝手に仕様を補完しない discipline 遵守)

藤本さん明示: 「Claude Code が仕様を勝手に補完しようとしたら、 そこは止めて相談してください。 特に投入スクリプトは、 既存 SEED_KERNEL の実データ形式を見ないと書けないので、 まず形式を確認させるのが確実です」

### spec vs 現実 gap 5 点 特定 → AskUserQuestion 3 決定

指示書は JSON/JSONL/SQLite/Markdown を想定していたが SEED_KERNEL は TypeScript source (100+ file、 `src/axiom-os/seed-kernel*.ts` 経由で 1,677 統合)、 `SeedTheory` interface に spec 要求の `tier` field 不在 (近接 field `judgmentStatus?` は STEP 1276 追加、 2 件のみ set)、 id 3 pattern 混在 (T-\d+=89 / invented-*=120 / slug=1468)、 title field 不在 (axiom のみ)、 step は axiom 本文 embed で 3.1% coverage。

**藤本さん judgment**:
- **tier**: 全件 `hypothesis` default 投入 → Phase 2 seed_propose で 昇降格
- **repo**: 別 repo `fc0web/rei-memory-mcp` (rei-verify / rei-automator-mcp 系と同 pattern)
- **spec tightening**: title = axiom 先頭 80 文字、 step = /STEP\s+(\d+)/ 抽出、 id 3 pattern 全許容

## 実装 (single session、 半日)

### rei-aios 側 (TS→JSONL 一方向 boundary adapter)
`scripts/dump-seed-kernel-json.ts` (commit `9d76b51f5`、 rei-aios main)。 SEED_KERNEL 全 1,677 を stdout JSONL + stats stderr で出力。

### rei-memory-mcp 側 (新 public repo)
[github.com/fc0web/rei-memory-mcp](https://github.com/fc0web/rei-memory-mcp) 公開 (commit `dbcb4b9`)、 続いて mcp 2.0 API + launcher fix (`fca7d05`)。

- `src/rei_memory_mcp/`: models (Tier / LinkKind / TypedDict) + db (FTS5 trigram schema) + search (bm25 + snippet + phrase-quote escape) + retrieve (get_theory + list_steps + LEFT JOIN link fan-out) + server (MCPServer + 3 tool + graceful ImportError)
- `scripts/ingest.py`: JSONL → SQLite、 4 validation rule fail-loud + immutable 保護 + 全 transaction rollback on error
- `run_server.py`: launcher (sys.path bootstrap、 UWP sandbox env-strip 対策、 Claude Desktop config は benchtop pattern と一致)
- `tests/`: 53 test (test_search 14 + test_get 11 + test_steps 10 + test_ingest 14 + test_immutable 4)、 in-memory DB fixture

**Live smoke (1,677 rows ingested)**: 「七値論理」 → 35 hits、 「平和公理」 → 9 hits、 「D-FUMT」 → 409、 「BOTH」 → 380、 「NEITHER」 → 338、 not-found handling ✅、 seed_list_steps 33 buckets covering 52 theories (残 1,625 = step:null bucket)。

## 3 finding (発見的付加価値)

### Finding 1: SEED_KERNEL に lone UTF-16 surrogate 1 件混入
`invented-20260503-zero-ext-interdimensional-topology` の axiom に truncated 半分 surrogate。 dump script の境界 sanitizer で U+FFFD 置換 + stats 報告 (SEED_KERNEL 側は無変更、 boundary で吸収)。 副次的発見: `extractTitle(.slice(0, 80))` が 有効 surrogate pair を分断する path も 同 sanitizer で吸収。 追加スキャンで `bonsai-1bit-local-llm` に既存 U+FFFD 潜在 (SEED_KERNEL 側の別 damage、 修復候補は別 STEP)。

**藤本さん洞察**: 「これが今日一番の収穫かもしれません。 SEED_KERNEL に UTF-16 破損データが混入していたことは、 コネクタを作らなければ発見できなかった。 『1,677 件全部を機械が一度舐める』 という行為自体に検査効果があったわけです」 = **connector 実装 = 検査 pipeline** の operational 実証。

### Finding 2: trigram tokenizer の 2 文字日本語 blind spot 実害数値化
Trigram FTS5 は 3+ char query でのみ hit。 藤本さん指摘の 「空」 「禅」 「圏」 「双対」 「龍樹」 「中観」 等 Rei 中核領域 の 2 char クエリで 0 hit。

**数値化**:
- 「龍樹の」 (3 char, trigram OK) = 31 hits (rei-aios substring と一致)
- 「龍樹」 (2 char, trigram NG) = 0 hits (rei-aios substring では 39 hits)
- 差 = **8 件見えない** (龍樹思想 / 龍樹曼荼羅 等の後続助詞なし複合語)

**Phase 2 backlog**: `seed_search` に LIKE substring fallback 追加。 rei-aios `search_theories` (`src/mcp/rei-mcp-server.ts:494-`) が示す通り `String.prototype.includes()` 生 substring で解決可能、 MeCab 形態素解析は不要 (1,677 rows は O(N) scan で 数 ms)。 `keywords[]` array を index として活用も相補的。

### Finding 3: remote rei-aios MCP deploy lag 2 件差
藤本さんが claude.ai 経由 `rei-aios/search_theories` で 「SEED_KERNEL 全 1675 理論中」 と受け取った vs 私の dump 1,677 の **2 件差**。

**特定**:
- `invented-20260815-zero-ext-thermodynamics-izutsu-landauer` (2026-08-17 追加、 commit `56b5a0dd1`、 井筒×Landauer D-approve)
- `invented-20260816-zero-ext-evolutionary-biology-wumen-selfish-gene` (2026-08-17 追加、 commit `6eafd8db4`、 無門関×Selfish Gene D-approve)

両者 D-downgrade approve = `analogy_marker` category。

**判定**: **bug ではなく remote deploy lag**。 claude.ai の rei-aios MCP は remote-devices ホスト deployment で、 2026-08-06 (`fb86bc5dd` STEP 1276) 前後の commit で deploy 停止。 以降の SEED_KERNEL 変更 (2 SEED add + STEP 1279 型 discipline lens + STEP 1280+ arc 編集) は **すべて未反映**。 藤本さんが claude.ai から見ている rei-aios は 常に約 13 日前の Rei。

**Ops 示唆**: remote rei-aios MCP redeploy trigger 整備 (SEED_KERNEL commit 検知 → 自動 rebuild + redeploy) が Phase 2 (別 arc) 相当 backlog。 rei-memory-mcp は ローカル HEAD 直結で 「fresh index」 として補完的に機能する位置付け。

## Claude Desktop 登録 (Windows Store UWP sandbox pitfall)

初期 config は `-m rei_memory_mcp.server + PYTHONPATH env` pattern で書いたが、 Claude Desktop v1.32885.1 (WindowsApps sandbox) が PYTHONPATH を子プロセスに propagate しない → `ModuleNotFoundError` → Desktop 「not connected」。 stripped-env spawn simulate で再現確認済。

**Fix**: `run_server.py` launcher で sys.path を script 自身の filesystem location から bootstrap、 config は benchtop pattern (直接 file path + `env: {}`) に統一。 clean-env spawn (PATH + SYSTEMROOT のみ) で MCP initialize 成功 exit 0 verify 済。 藤本さん Desktop 側動作確認は 別 session で。

過去 memory `mcp-lens A 柱 起動 PC restart 前 pause (2026-08-15)` の 「Windows Store dual path pitfall」 学習が 直接活用された事例。

## Phase 1 完了条件 (spec § 8)

| # | 条件 | 状態 |
|---|---|---|
| 1 | pytest 全 PASS | ✅ 53/53 |
| 2 | Claude Desktop 3 tool 認識 | ⏸ 藤本さん Desktop 再起動待ち (config edited + launcher verified) |
| 3 | 実 SEED_KERNEL データ投入 | ✅ 1,677/1,677 inserted、 6.1 MB SQLite |
| 4 | 日本語クエリで妥当な結果 | ✅ 「七値論理」 35 hits / 「平和公理」 9 hits |
| 5 | README 設定手順 + 投入手順 | ✅ |
| 6 | AGPL-3.0 ライセンス | ✅ rei-aios と同じ dual license |

## Rei stack impact

- **MCP systems 6 → 7** (rei-memory-mcp NEW via public GitHub repo、 PyPI publish は 別 arc)
- **別 project OSS repo 4 → 5** (rei-memory-mcp NEW)
- **Phase 2 backlog (deliberate defer)**:
  - `seed_propose` staging table + human approval → promotion into `theories`
  - LIKE substring fallback for 2-char Japanese queries (Finding 2 対策)
  - keywords[] index の活用
  - Phase 3 promotion history table (hypothesis → proven 軌跡が自身 artifact)
  - Phase 4 access-count decay ranking (immutable 除外)
- **Ops backlog (別 arc)**:
  - remote rei-aios MCP redeploy trigger (Finding 3 対策)
  - `bonsai-1bit-local-llm` U+FFFD 修復 (Finding 1 副次)

## 順序原則遵守 (SAC-4)

途中 lone surrogate 発見 (Finding 1) 時、 「dump script 側の bug」 と 誤帰属せず 実データ状態を先に verify → SEED_KERNEL 側の既存破損と判明 → sanitizer は境界処理として実装 (SEED_KERNEL 側は無変更) の順序を守った。 [[feedback-one-reproduction-over-ten-unverified]] 「1 件でも説明できない差があれば計器は未検証、 説明できたら検証済み」 適用。 Finding 3 の 2 件差も同様 (bug 疑いより先に commit 履歴を diff して deploy lag と特定)。

## 関連

- [[feedback-ai-usable-tool-design-5-conditions-2026-08-18]] (5 条件 6 例目 operational): (1) 3 tool + validation rule 有限 allowlist + (2) 危険操作関門 (fail-loud validation + immutable 保護) + (3) 構造化 return (TypedDict + JSON serialise) + (4) graceful degradation (mcp package 無しでも core module import 可) + (5) 自己 test 53/53
- [[feedback-projection-self-audit-pattern]] SAC-4 (勝手に仕様補完しない、 Finding 3 の bug 誤帰属回避)
- [[feedback-one-reproduction-over-ten-unverified]] (順序原則)
- [[feedback-world-uniqueness-claim-controllable]] (novelty 主張ゼロ = read-only MCP は 汎用 pattern の Rei stack 適用のみ)
- [[feedback-no-rush-publication]] (Phase 2 は 別 session、 「急がずゆっくりと」 遵守)
- [[feedback-all-research-site-reflection-default]] (2026-08-06 protocol、 site 反映済)
- [[project-rei-verify-arc-2026-08-19]] (同日別 arc、 別 project OSS PyPI live)
- [[feedback-windows-store-uwp-env-strip-2026-08-19]] (Claude Desktop launcher fix 学習)
- [[feedback-remote-mcp-deploy-lag-2026-08-19]] (Finding 3 学習)
