feat(ingest): POST /triplets/ingest 寫入端 + deprecate-then-append (T3.2-3.5)

對應 issue #1 T3 B 段。

- templates: TRIPLET_SLOTS 加 status/superseded_by/source_uri/content_hash;
  ENTITY_SLOTS 加 gloss;recordToTriplet 映射新欄位(缺省 status=active 相容舊資料)
- kbdb-client: ensureTemplate 改 slot-diff 補丁(既有 template 走 PATCH /templates/:id
  補缺 slot,取代 early-return → 免遷移腳本);新增 updateRecord(PATCH /records/:id)
- triplet-ingest action(88 行純函式):Zod strict 鏡射 ingest-candidate 契約 →
  idempotency(uri+hash 同→no-op)→ 先 append 後 deprecate(無「全無 active」空窗)
- POST /triplets/ingest route:strict 驗證失敗 → 422(禁送 graph 領域欄位)
- queryTriplets 預設 active-only(traverse/search/neighbors 皆經此),
  includeDeprecated opt-out 供 rollback/考古
- 6 測試案全綠(vitest 16 passed);mock-client 同步 slot-diff + updateRecord

gates: zero SQL / zero migration / 無 D1·Vectorize·AI 綁定 / dry-run bundle 乾淨

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-26 18:13:49 +08:00
parent 98b221b435
commit 27f7448914
9 changed files with 279 additions and 13 deletions
+7 -7
View File
@@ -6,17 +6,17 @@
## A. 契約 + template slot
- [x] **3.1**`contracts/ingest-candidate.json` 進本 repo + `contracts/README.md` 標明候選≠已存(2026-06-26
- [ ] **3.2** `ensureTemplate` 改 slot-diff 補丁(命中既有 → base `PATCH /templates/:id` 補缺 slot,不再 early-return);`TRIPLET_SLOTS``status` + `superseded_by` + `source_uri` + `content_hash`
- [ ] **3.2b** `ENTITY_SLOTS``gloss`(已核實現無)
- [x] **3.2** `ensureTemplate` 改 slot-diff 補丁(命中既有 → base `PATCH /templates/:id` 補缺 slot,不再 early-return);`TRIPLET_SLOTS``status`+`superseded_by`+`source_uri`+`content_hash`2026-06-26`kbdb-client.ts`+`templates.ts`
- [x] **3.2b** `ENTITY_SLOTS``gloss`(已核實現無)2026-06-26
- [ ] **3.2c** normalize 分層 fallback 接口:exact-only 先做;semantic 留接口(待 base embedArcrun #7
## B. 寫入端 + 取代(核心)
- [ ] **3.3a** `KbdbClient.updateRecord(id, values)` → base `PATCH /records/:id`已核實現無
- [ ] **3.3b** `src/actions/triplet-ingest.ts`:驗證 envelope422 擋禁送欄位)→ idempotencyuri+hash)→ deprecate-then-append(先 append 後翻舊批 status)。<100 行純函式
- [ ] **3.3c** `POST /triplets/ingest` route驗證 + 呼叫 action
- [ ] **3.4** 測試(mock,不打真網路):正常 envelope / 同 hash no-op / 新 hash deprecate / 污染 envelope(帶 bridge_score) 422 / rollback(翻回 status)
- [ ] **3.5** 查詢 active-onlytraverse/search/neighbors 組圖前 filter `status==='active'`缺省視為 active,相容舊資料
- [x] **3.3a** `KbdbClient.updateRecord(id, values)` → base `PATCH /records/:id`2026-06-26mock 同步
- [x] **3.3b** `src/actions/triplet-ingest.ts`Zod strict 驗證 → idempotencyuri+hash)→ **先 append 後 deprecate**。88 行純函式(2026-06-26
- [x] **3.3c** `POST /triplets/ingest` route(驗證失敗 → 422 hook,只驗證+呼叫 action)(2026-06-26
- [x] **3.4** 測試 6 案全綠:正常 / 同 hash no-op / 新 hash deprecate / 污染(bridge_score+頂層 id) 422 / rollback`vitest run` 16 passed)(2026-06-26
- [x] **3.5** 查詢 active-only`queryTriplets` 缺省 filter `status==='active'`traverse/search/neighbors 皆經此;`includeDeprecated` opt-out 供 rollback/考古)(2026-06-26
## C. MCP(⚠️ 跨 repo,需 arcrun 配合 → issue 標清)