feat: KBDB-graph 插件獨立 — 全面改寫成走基本盤 API(API-as-Wall)

按 leo 鐵律(2026-06-14)把插件從「直接 SQL 操作基本盤表」改寫成
「只透過基本盤 arcrun/kbdb HTTP API 讀寫」。零建表、零 migration、零 SQL。

- 新增 src/lib/kbdb-client.ts:唯一對外通道,封裝 entries/templates/records API
- 新增 src/lib/templates.ts:triplet/entity template 定義(替代建表)
- 改寫 21 個違規 action(triplet/graph/entity/search)→ 走 client,圖在插件層記憶體組裝
- 移除所有 migrations、D1/Vectorize/AI 綁定;embedding/語意搜尋歸基本盤 optional 模組
- index.ts 只掛 triplets/graph/entities/search 路由;基本盤路由歸 arcrun/kbdb
- 測試改走 mock client(純 node);裁剪 CLAUDE.md 只留 graph 插件 + 鐵律
- 修正 SDD design.md「讀現狀推翻鐵律」的錯誤判斷(共用 D1 → API-as-Wall)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-14 20:59:41 +08:00
commit efe8e165cf
62 changed files with 7671 additions and 0 deletions
@@ -0,0 +1,38 @@
# KBDB-graph 抽出 — Requirements
> 建立:2026-06-14
> 來源:InkStoneCo 頂層 `matrix-rearrange` R2 + 本目錄 `docs/HANDOFF-kbdb-plugin.md`
> 定調:leo 2026-06-13
---
## 背景
本目錄(`matrix/kbdb-graph-plugin`,原 `matrix/kbdb`)原是「整套 KBDB」。leo 2026-06-13 拍板拆分:
- **基本盤** = `arcrun/kbdb`D1 三表(blocks/templates/slots)的基本存儲讀寫,已併進 arcrun。
- **本目錄(KBDB-graph** = 掛在基本盤之上的 triplet 採集 + graph 查詢插件,**類比 Apache AGE 之於 Postgres**。
為何獨立:graph 能力較龐大、非基本存儲、leo 產權較複雜 → 獨立成 repo 不留 arcrun。
## 需求
1. **R-EXT-1 確認邊界**:把現有 `src/actions/``src/routes/``migrations/``contracts/` 逐一分類為「插件(triplet/graph/entity/search)」或「基本盤(block CRUD/template/tag/profile)」。基本盤的歸 arcrun/kbdb,插件的留本目錄。順便裁剪 CLAUDE.md(移除基本盤規範,只留 graph 插件相關)。
2. **R-EXT-2 獨立成 repo**:改名 KBDB-graph`git init` + 設 remote(帳號問 leo+ 推 GitHub。由本 CC 自己推,不經總管。
3. **R-EXT-3 定義掛載介面**KBDB-graph 如何掛在 arcrun/kbdb 基本盤上(AGE-on-Postgres 模式)——插件怎麼讀基本盤的 blocks 表、怎麼宣告自己的 triplet/entity/graph schema。
## 約束(硬性)
- **修改不是重建**:在現有實作上改,不重寫。
- **部署繞開 GitHub**wrangler 直推 Cloudflare,禁跨 repo 同步 Actions(當初害帳號被 flag 的模式)。新 repo 預設不開 Actions。
- **本目錄現無獨立 git**matrix 降級後脫離、被 InkStoneCo 頂層 gitignore)→ R-EXT-2 才 git init。在那之前用普通 mv 不是 git mv。
- **API-as-Wall / 萬物皆 Block** 仍適用於基本盤;插件對 graph 資料同樣經 API。
- **樂高法**`src/actions/` 單檔 < 100 行、一檔一事、無狀態。
## leo 已拍板(2026-06-14
- 獨立 repo = **新 repo `uncle6me-web/kbdb-graph-plugin`**(沿用現目錄名,非「KBDB-graph」字面)。
- 灰色地帶處理方式 = 先 grep 查引用再提建議(已完成,見 design.md)。
## 仍待確認(與 arcrun 對齊,非 leo
- 0005/0007 等基本盤 migration 歸屬與 HANDOFF 清單有出入,移交前對齊 arcrun。