Files
kbdb-graph-plugin/docs/3-specs/arcrun-key-auth/tasks.md
T
Leo efe8e165cf 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>
2026-06-14 20:59:41 +08:00

61 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# KBDB Arcrun Key Auth — Tasks
> 建立:2026-05-05
> 權威進度來源:本檔。完成一項立刻 `[x]`,不批次。
---
## Phase 0 — SDD 建立
- [x] 撰寫 `design.md`
- [x] 撰寫 `tasks.md`(本檔)
- [ ] richblack review + 認可 → 開 Phase 1
---
## Phase 1 — KBDB auth middleware 接受 `ak_` Key
**修改檔案**`matrix/kbdb/src/index.ts`
- [x] 1.1 將 line 103 的 `effectiveToken.startsWith('pk_')` 改為
`effectiveToken.startsWith('pk_') || effectiveToken.startsWith('ak_')`
- [ ] 1.2 本地跑現有測試確認不 break:`pnpm test`
---
## Phase 2 — Arcrun OAuth callback 寫入 KBDB partner 記錄
**修改檔案**`matrix/arcrun/cypher-executor/src/routes/auth.ts`
> 注意:此 Phase 需要 Arcrun 側有 `KBDB_INTERNAL_TOKEN` 和 `KBDB_BASE_URL` 兩個 env binding。
- [x] 2.1 在 `Bindings` type`types.ts`)加入 `KBDB_INTERNAL_TOKEN?: string``KBDB_BASE_URL?: string`
- [x] 2.2 建立 helper `src/lib/kbdb-partner.ts`
- `ensureKbdbPartner(env, email, apiKey)` → PUT /admin/partners/by-key-hash,失敗靜默 log
- `revokeKbdbPartner(env, oldApiKey)` → DELETE /admin/partners/{id},失敗靜默 log
- [x] 2.3 在 OAuth callbackUserRecord 建立/取得後)呼叫 `ensureKbdbPartner`fire-and-forget
- [x] 2.4 在 `PUT /me/api-key/rotate` 呼叫:`revokeKbdbPartner(oldKey)` + `ensureKbdbPartner(newKey)`
- [x] 2.5 在 `DELETE /me/api-key` 呼叫 `revokeKbdbPartner`
- [ ] 2.6 `wrangler secret put KBDB_INTERNAL_TOKEN`cypher-executor Worker)← 需要人工執行
- [x] 2.7 在 `wrangler.toml``KBDB_BASE_URL = "https://kbdb.finally.click"`
另外:KBDB `admin.ts` 新增 `PUT /admin/partners/by-key-hash` endpointupsert by hash,不產生新 key)。
KBDB `types.ts` 加入 `KBDB_INTERNAL_TOKEN` 到 Bindings。
KBDB `admin.ts` 放寬 `org_namespace` regex(允許 `arcrun:email@domain` 格式)。
---
## Phase 3 — 驗證
- [ ] 3.1 新用戶 OAuth 登入 → 確認 KBDB partner 記錄建立(`GET /admin/partners` 查詢)
- [ ] 3.2 用 `ak_xxx` Key 直接打 KBDB `GET /blocks` → 確認 200(非 401
- [ ] 3.3 Key rotate → 確認舊 Key 401,新 Key 200
- [ ] 3.4 Key revoke → 確認舊 Key 401
---
## 目前狀態
- Phase 0 已完成(等 richblack 認可)
- Phase 13 全部 `[ ]`,等認可後動工