d2618758e2
- 位置統一:舊 docs/3-specs/ 五份 SDD git mv 到 system-dev/docs/3-specs/,舊位置留 README 指針 - 狀態判定:0 份 active(無現行開發,合法);paused×3(ingest-contract/kbdb-graph-extraction/plugin-install,等跨 repo 接通);closed×2 入 archive/(arcrun-key-auth/blocks-edit-api 死件,附封存原因) - 鋪檔(自 system-dev-template v1.15.0):SDD-LIFECYCLE.md、pending-changes.md、sdd-guard.sh 新版、sdd-check.md、sdd-active-check.sh - hook 掛載:settings.json PreToolUse Write|Edit 加 sdd-guard.sh - CLAUDE.md:SDD 鐵律段(濃縮五條+0-active 註明重啟先升 active)+修正遷移後舊路徑 - 驗證:sdd-active-check exit 0;guard pipe-test 0-active 擋 code 寫入(exit 2)/md 放行(exit 0) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
61 lines
2.3 KiB
Markdown
61 lines
2.3 KiB
Markdown
# 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 callback(UserRecord 建立/取得後)呼叫 `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` endpoint(upsert 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 1–3 全部 `[ ]`,等認可後動工
|