Files
Arcrun/cypher-executor
uncle6me-web 179dd60571 fix(kbdb): 三元組版標庫批次補存量+對外通道(Arcrun#87 二次收尾)
藏書地圖(library-map.ts)讀的是三元組 record 自己的 'library' slot(entry_values),
不是 entries.metadata_json.library——Arcrun#85 建的 POST /entries/backfill-library
補的是後者,補了地圖依然是 0。既有能補三元組 library 值的通道只有單筆
PATCH /kbdb/records/:id(b6ef0f0,已在 main),母體上千筆時逐筆呼叫不現實,也沒有
節流/冪等保護。

新增:
- kbdb/src/actions/library-backfill.ts:backfillTripletLibraryTags +
  tripletLibraryBackfillStatus,安全原則與既有 entries 版逐條對齊——呼叫端決定
  library 值+source_prefix 篩選(base 不猜語意)、冪等(NOT EXISTS 找缺 library 的
  那半)、與 entries 版/embed reconcile 共用同一顆 D69 每日 D1 寫入額度、owner_id 必填、
  寫入沿用既有 updateRecord(不手刻第二套 entry_values UPSERT SQL)。
- kbdb/src/routes/records.ts:POST /records/backfill-library + GET .../status。
- cypher-executor/src/routes/kbdb-proxy.ts:對外通道,owner_id 強制用租戶身份(同本檔
  既有 POST /kbdb/records 慣例,不信任 caller 自帶 owner_id)。

測試:kbdb 新增 5 案(含跨租戶隔離/冪等/D69 共用額度截斷/status 統計),全套
218/218 綠燈;cypher-executor 新增 5 案(租戶閘/參數驗證/轉發/owner_id 覆蓋),
兩份既有失敗(auth.test.ts ExecutionContext 型別缺陷、portal-data/portal-admin/
console-library-map-page/executor.test.ts 訊息措辭)複驗與本次改動無關(stash 前後
一致,pre-existing)。

紅線:未併 main、未部署、未對 leo21c 執行任何實際 backfill(缺安全的寫入通道——
MCP 工具集無 update/patch record 能力,CLI 全域設定指著 leo21c 不可裸跑)。
批次執行是下一步,需總管/leo 決定執行方式與時機。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-13 11:12:56 +08:00
..