Commit Graph

16 Commits

Author SHA1 Message Date
uncle6me-web 90777e3877 fix(auth-recipe): 回灌 telegram/line_notify/kbdb 種子,補 AuthInjectSpec.path(修 source/live 漂移)
issue #13 升級:根因不只 acr parts 殘留,是 auth-recipe-seeds.ts source 漏了 3 個 static_key
auth recipe(telegram/line_notify/kbdb),但 prod KV 手動 seed 過 → 任何全新 self-hosted
`POST /init/seed` 只 seed 23 個、漏 telegram → self-host(leo21c/mira)telegram_send 的
auth_service:'telegram' resolve 不到 → {{auth.bot_token}} 注入空 → telegram 發訊壞掉。

實測 smoking gun(2026-06-29):
- prod cypher.arcrun.dev/auth-recipes = 27 個(含 telegram)
- self-host arcrun-cypher-executor.leo21c.workers.dev = 23 個(無 telegram/line_notify/kbdb)

修法(資料/型別,非業務邏輯,守 mindset §1 不建 component):
- auth-recipe-seeds.ts 補 telegram(inject.path bot_token)/line_notify(header Bearer)/kbdb(header Bearer)
- recipes.ts AuthInjectSpec 補 path?(WASM auth_static_key + SDD §六早有此欄、source 介面漏 → tsc 擋)
- google_user(oauth2)暫不回灌:內嵌 client_secret 不可進 git + 介面無 oauth2 欄 → 留 Phase D

形態取自 prod GET /auth-recipes/{service};設計權威 auth-recipe.md §六(telegram path)/§七(kbdb 共用)。
telegram 自此與 notion(header)/gsheets(service_account) 同一條 recipe+auth-recipe 鏈,一致。
tsc 全綠;local 模擬 token-in-path 注入 PASS。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-29 12:37:19 +08:00
uncle6me-web 934b9265d9 feat: KBDB self-hosted 查詢 + embed 模組 + thin-shell 收窄 + search_workflow(code done 待端到端)
按 issue 分段標明(檔 #5/#8 改動交疊處無法乾淨拆檔,故併一個 commit):

#4 thin-shell §3.1 自力救濟階梯 + code-node 規則(純文檔/規則,code-node 零件未實作)
#5 KBDB source filter(json_extract metadata_json 零建表)+ 能力對照;documents 聚合與
   DELETE proxy 部分擱置等頂層 T8
#7 base embed 模組(kbdb/src/embed.ts)+ vectorize 開關(deploy/config/wrangler.toml 註解範本)
   + 語義查詢降級閉環(mode=semantic 未開→LIKE+capability_hint)
#8 部分(workflow-discovery):
   - KBDB /entries/search 加 base 通用 entry_type filter(entry-crud/embed/route/kbdb-proxy 透傳)
   - /webhooks/named 強制 description(空→400,訊息要求操盤 AI 據實寫一句)
   - 部署雙寫 entry_type=workflow embeddable entry(waitUntil 非阻塞,供 search)
   - cypher GET /workflows/search + MCP u6u_search_workflows(優先語意、降級 hint)
   - cypher POST /workflows/backfill-search-entries(無 desc 列出不編造)
   - GET /webhooks/named 補回 description/created_at 欄位(為 list 來源收斂備)

⚠️ tsc 綠 = code done,非完成(mindset §7 禁假綠):
- #7/#8 端到端待 leo21c 部署驗(Vectorize 需官方憑證、CC 跑不了)
- #8 ①-a(MCP deploy 改打 /webhooks/named)未做、MCP deploy 那半仍 404
- #8 端到端(強制填擋空/語義命中/租戶隔離/降級 hint)未驗

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-27 17:52:52 +08:00
uncle6me-web b1e302b3b5 fix(kbdb): cypher proxy 補 /kbdb/entries CRUD + report_feedback 改打 /entries
kbdb-base Phase 9.6/9.7(HANDOFF §2 缺口① + §3b 連帶):

- 9.6 cypher kbdb-proxy 補 /kbdb/entries CRUD(POST/GET list/GET :id/PATCH :id)
  純轉發到 KBDB 基本盤 /entries,解鎖 mira _kbdb_client.py 主線遷移。
  租戶隔離同 9.5:寫入注入 owner_id、list 強制本租戶過濾、PATCH 剝 owner_id。
  刻意不開 DELETE(基本盤 delete 無 owner 檢查 → 跨租戶刪除風險)。
- 9.7 arcrun_report_feedback 從死 route /blocks 改打基本盤 /entries
  (entry_type=agent-feedback)。9.4 漏網的同類修;基本盤無 /blocks → 原本 404 假紅。

順帶(HANDOFF §6 harness 表達優化):
- 重寫 cli/harness/CLAUDE.block.md 補三盲點(recipe 是公共投稿 / 缺能力補 API 不拼裝 /
  自製零件退場路徑),目標 Haiku 級 CC 讀懂。
- README 零件 vs recipe 段對齊同三點。

cypher + mcp tsc exit 0。端到端 smoke test 隨後。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 13:06:58 +08:00
uncle6me-web a410af0b6c fix(cypher): KBDB proxy 指向現役 arcrun-kbdb(舊 fallback kbdb.finally.click 已死)
煙霧測試發現 proxy fallback 寫死舊的 kbdb.finally.click(inkstone 遺留、
回 Missing token),非現役 KBDB。改:
- kbdb-proxy.ts fallback → arcrun-kbdb.uncle6-me.workers.dev(現役、無 auth)
- cypher wrangler.toml [vars] KBDB_BASE_URL 明設現役 URL(self-host fork 覆蓋自己的)

現役 arcrun-kbdb 無 auth middleware,不需 KBDB_INTERNAL_TOKEN。
cli 版本檔 1.3.8→1.3.9(deploy 腳本自動 bump,含 acr kbdb 命令)。

cypher tsc exit 0。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 22:16:18 +08:00
uncle6me-web 886a8e31d0 feat(kbdb,mcp): KBDB 資料層薄殼 + self-hosted MCP 認證 + cypher KBDB proxy
三件一條鏈(HANDOFF §2/§3b,kbdb-base Phase 9):

A. KBDB MCP 薄殼(9.1):mcp/src/tools/kbdb_data.ts 6 工具
   template/record/query/search,調基本盤 API。鐵律:不給建表/SQL,只 template+slot。

B. MCP self-hosted 認證 401(mcp-account-source §5.5):
   - partner-auth.ts:MULTI_TENANT=false 時 Bearer 明碼直接當 org_namespace,
     繞 KBDB partner 驗證(對齊 cypher 的 opaque-key 模型)。官方 SaaS 行為不變、共用同碼。
   - mcp-setup.ts:把 namespace/api_key 寫進 .mcp.json headers.Authorization。
   - 新增 self-hosted vs SaaS 分支單測(9 tests 綠)。

C. cypher KBDB proxy(9.5)+ CLI 薄殼(9.2):
   - routes/kbdb-proxy.ts 純轉發 /kbdb/* → KBDB 基本盤(KBDB_BASE_URL HTTP fetch,
     不新增 service binding)。讓 CLI(只認證到 cypher)能達獨立 KBDB worker。
   - 租戶隔離:X-Arcrun-API-Key 自動當 owner_id 注入 records/entries(強制覆寫防跨租戶);
     templates 全域共享(虛擬表定義是 schema 非資料)。
   - cli/src/commands/kbdb.ts:acr kbdb template/record/query/search,與 MCP kbdb_* 同能力。
   - kbdb base:entries 加 page_name 過濾(9.3)。

cypher + cli + mcp tsc exit 0。未驗收:端到端需 deploy + KBDB_BASE_URL 可達後實測。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 22:12:32 +08:00
uncle6me-web eba87b9ea9 fix(deploy): release-check 全形括號 set-u crash + pnpm allowBuilds 範本未填
- check-release.sh: 5 處 $VAR( → ${VAR}(,修 set -u unbound var crash
  (全形括號 U+FF09 緊貼變數名被 bash 併入變數名 → 非零退出 → 誤判 git 未同步擋 deploy)
- cypher-executor/ + auth_static_key/ pnpm-workspace.yaml: allowBuilds 改真布林
  (原 'set this to true or false' 範本 → pnpm install 拒絕 → deploy 掛)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 23:14:57 +08:00
uncle6me-web da84425d25 feat(credential-injection): {{credential.X}} 用戶面語法(credential-primitives §8)
壓測 401 根因:{{credential.X}} 系統沒實裝,三條 template 展開路徑都不認
credential. namespace → 注入空值 → 目標 API 401(test_arcrun/5 Haiku 實證)。

修法(design §8,richblack 確認方向 B「讓 {{credential.X}} 真的能用」):
- auth_static_key 加 resolve_credentials action:給 names → WASM 內 kv_get +
  crypto_decrypt → 回明文 map(不查 recipe、缺則誠實報錯)
- auth-dispatcher 加 resolveCredentialRefs:遞迴偵測 {{credential.X}} → 交 WASM
  解密 → 回填(無 ref 則零開銷不打 WASM)
- graph-executor 在 node.data interpolate 後呼叫,不碰 ENCRYPTION_KEY(rule 02 §2.2)

解密全程在 WASM,TS 只偵測+回填。tinygo build OK + tsc 0 + §2.2 自檢綠。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 13:55:31 +08:00
uncle6me-web c152f5fc1d feat(onboarding+kbdb): 8.P0 cron 止血 + §7.8 onboarding + .env.example 範本
kbdb-base 8.P0:scheduled.ts cron 每分鐘 KV list → 單一 key get(lib/cron-index.ts);
  webhooks-named 維護單 key + 一次性 migrate-cron-index;acr update 自動遷移。1440 list/日 → 0。

self-hosted-init §7.8 onboarding:
  P0 init 偵測+裝完驗收(lib/preflight.ts,pip 式,冪等)
  P1 acr whoami(+--json)+ MCP arcrun_whoami(AI 不繞 CLI 猜帳號)
  P2 mcp-setup 寫完印「請重啟 client」
  P3(部分)repo .env.example 範本(每格白話說明、值留空)+ llms.txt 教 AI 幫用戶 cp 建 .env

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-09 19:15:51 +08:00
uncle6me-web 6a75117ba3 feat(kbdb): recipe 公庫/私庫雙向機制 + UUID 身份 + KBDB Base + 市場數據
kbdb-base SDD §7.5(公庫/私庫雙向機制,richblack 2026-06-07 拍板)。

## KBDB Base worker(新)
- kbdb/:D1-only 核心三表(entries/templates/entry_values)+ CRUD + LIKE search
  + recipe-stats 端點(市場數據)+ 0001_base.sql migration(含 recipe_stat seed)

## Phase 2.3:init 建 D1 + 套 migration
- cli cf-api.ts 加 listD1Databases/ensureD1Database;init 建 arcrun-kbdb D1
- deploy.ts 部署後對 D1 套 0001_base.sql(CF /d1/query API,idempotent)+ 注入 database_id

## Phase 5.1:recipe 成功記錄(市場數據來源)
- GraphExecutor 收集本次用到的 recipe uuid(usedRecipeKeys)
- executeWebhookGraph 執行結束一次性記 per-uuid 成功/失敗到 KBDB(fire-and-forget)

## Phase 7.5:recipe UUID 身份 + app-store 模型
- recipe 領 uuid=唯一身份;canonical_id/author/公私=屬性(§7.5.5)
- recipe:{uuid} + idx:canonical/installed/hash;resolveRecipe 向後相容不破執行鏈
- POST /recipes/submit=領新 uuid 新增作者版本(非覆蓋,app-store)
- GET /public-recipes 搜尋(多作者+per-uuid 市場星數)/ :id pull(選市場最佳)
- 落空→found:false 創作引導(§7.5.6 閉環)
- POST /recipes/migrate-uuid 一次性轉舊 key(增量寫不刪舊、冪等)
- init-seed 用 UUID(author=system)

## 薄殼(rule 07 §5:CLI + MCP 覆蓋同組能力)
- CLI: acr recipe search/pull/submit-p(config 加 DEFAULT_PUBLIC_LIBRARY_URL)
- MCP: arcrun_recipe_search/pull/submit_p/push/list/delete(補齊漂移)

## 壓測修正
- api-recipe-seeds: google_sheets_append PUT→POST(:append 正確動詞,階段12)

四 worker tsc 全綠(cypher/cli/kbdb/mcp)。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-07 16:18:10 +08:00
uncle6me-web 95a1462b65 fix(cypher): 改用 global_fetch_strictly_public flag 解 same-zone 1042(revert service binding)
richblack 拍板:service binding(前一 commit)靜態、加/改要重 deploy cypher,廢。
改用 global_fetch_strictly_public compatibility flag——cypher wrangler.toml 加一行,
讓 fetch() 走公網前門,self-hosted 的 same-zone fetch(cypher 與 auth 同在
{sub}.workers.dev zone)也能通。

- wrangler.toml:compatibility_flags 加 global_fetch_strictly_public(移除 SVC_AUTH_*)
- auth-dispatcher.ts / types.ts:還原到 service binding 之前(單純 fetch workers.dev)
- 安全(官方 docs):唯一副作用 self-loop 僅在 fetch 自己 hostname;cypher 不 self-loop
- 官方/self-host 共用同一份 toml:官方本就跨 zone 行為不變,self-host 被修好
- 規範還原:rule 02/03/CLAUDE.md/pre-bash-guard 的 service binding 禁令維持原狀

SDD: credential-primitives-wasm Phase 7(A→廢→B)。tsc exit 0。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-06 21:44:13 +08:00
uncle6me-web d2048e26a7 fix(cypher): auth primitive 改走 service binding(解 self-hosted CF 1042)
壓測階段 11:self-hosted 帳號 cypher 用 fetch(workers.dev) 打同帳號
auth worker 被 CF 子請求限制回 1042,service account token 換不到 →
表單寫不進 Google Sheets。token/解密鏈本身正常(直打 auth worker 回真 ya29)。

架構演化(richblack 2026-06-06 拍板):用戶產生的是 recipe(KV 資料,不 deploy),
primitive 是平台固定基礎設施、用戶不新增 → 解除「auth primitive 禁 service binding」
舊禁令。service binding 是 CF 內部 RPC,繞開同 zone 522 + 同帳號 workers.dev 1042。

- wrangler.toml:加 SVC_AUTH_STATIC_KEY/SERVICE_ACCOUNT/OAUTH2(已部署者;mtls 未部署留註解)
- auth-dispatcher.ts:binding 優先 svc.fetch(),無 binding fallback fetch(workers.dev)
- types.ts:4 個 optional SVC_AUTH_*
- deploy.ts 無需改:stripOfficialOnlyBindings 不碰 services,tier1 auth 先於 tier2 cypher
- 已驗證 self-hosted(leo21c)13 邏輯零件 binding 實綁成功,auth binding 走同路

規範同步:rule 02 / 03 / CLAUDE.md / pre-bash-guard 例外。SDD: Phase 7。tsc exit 0。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-06 21:09:49 +08:00
uncle6me-web 99c3454ce8 feat(recipes): auth recipe help_url 一律必填(不分冷熱門)
每個 required_secret 必須有 help_url(官方文件連結 http(s)://),POST /auth-recipes
驗證缺則 400。讓 AI/使用者設定 credential 時直接讀官方來源,不必猜/不會搜錯。
薄殼原則:驗證在 API,CLI/MCP 等介面 push auth recipe 自動受約束。
種子 23/23 已含 help_url。SDD: auth-recipe.md「help_url 一律必填」。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-06 17:41:38 +08:00
uncle6me-web 44b915554b fix(self-hosted): 身份改明碼 namespace(.env)+ path-based webhook trigger
壓測 §7.2:seed 通了但 creds push/push/runtime 全卡「缺少 api_key」——
self-hosted init 從不發 api_key,但三條路徑都建在多租戶 {api_key}:cred 模型上。

richblack 拍板:self-hosted 不需祕密 api_key,只需 namespace(分區標籤):
- config:ENV_MAP 加 NAMESPACE/ENCRYPTION_KEY + .env 自動載入(無 dotenv 依賴)
- namespace 明碼用戶自填(.env NAMESPACE=leo),沿用 api_key 路徑 → 零分叉
- encryption_key 用戶 .env 自填(工具不生成不 hash),須與 worker secret 一致
- creds/push/init:缺值改引導設 .env,不再叫去 register
- runtime:cypher 加 POST /webhooks/named/:ns/:name/trigger(namespace 走 path,
  公開表單免 header);與 header 路徑共用 triggerNamed,不分叉
- push:self-hosted 顯示 path-based 公開 webhook URL

誠實限制:namespace 明碼非密碼;防外部呼叫靠 webhook 保護(mindset §6)。
CLI 1.3.0 → 1.3.1。SDD: self-hosted-init.md §7.7。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-06 17:30:16 +08:00
uncle6me-web 3e65e22775 feat: 薄殼原則落地 + seed 下沉 API + MCP 進主庫 + 部署一致性
壓測四橫向問題修正(docs 壓測報告):

① 薄殼原則成鐵律:能力長在 API,CLI/MCP/lib 只暴露
   - seed 下沉成 API 行為:cypher-executor POST /init/seed(一次灌 API+auth recipe),
     種子資料移到 server src/lib/api-recipe-seeds.ts,CLI 改薄殼一次呼叫
   - 解除 deployFullyOk 連坐 + init 補 seed auth recipe + update 補 seed/全 KV
   - registry SUBMISSIONS_KV 補進 REQUIRED_KV_NAMESPACES(修 20/21)

② MCP 統一帳號來源(單一 remote MCP + .env 切 MCP URL)
   - MCP 從 sibling repo 搬進 arcrun/mcp/(remote Worker,route 改 mcp.arcrun.dev)
   - config 加 mcp_url 三層解析 + getMcpUrl + DEFAULT_MCP_URL
   - 新增 acr mcp-setup:依 config 寫專案 .mcp.json(接案切資料夾自動切 MCP)
   - acr --version 改動態讀 package.json(根治漂移)

③ Deploy 一致性
   - tests/release.feature + scripts/check-release.sh
   - local-deploy.sh:CLI npm publish + auto patch bump + CHANGELOG
   - local-deploy.sh bash 3.2 相容修正(mapfile / 空陣列 set -u)
   - builtins/pnpm-lock.yaml

④ README self-hosted 同步現況(移除 R2 殘留、加 flag/env、多帳號)

CLI bump → 1.3.0

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-06 15:45:35 +08:00
uncle6me-web 5f381a44a6 fix(self-hosted): 修壓測四阻斷項 + 設定分層 + init 非互動
壓測(docs/壓測報告.md)發現 acr init --self-hosted 對任何非官方 CF
帳號都裝不起來,且設定寫死全域單檔 + 強制 TTY。本次一併修:

R2 dead storage 全清(#3#4,registry-canon Phase 1.5 補完):
- cypher-executor wrangler.toml/test.toml/types.ts 移除 WASM_BUCKET binding
- CLI deploy.ts/init.ts/cf-api.ts/config.ts 移除 R2 建立邏輯與 wasm_bucket
- R2 綁信用卡違背「開源免費自架」核心;bucket 名 WASM_BUCKET 本就非法
  → self-hosted 改為只需 Workers + KV(皆免費額度、不綁卡)

fork 帳號部署阻斷(#1#2):
- deploy.ts 新增 stripOfficialOnlyBindings(),注入暫存副本時移除
  [[routes]]/zone_name/[[r2_buckets]]/[ai](fork 沒有 arcrun.dev zone)
- 不刪 repo 內 toml(官方 prod CI 部署仍需 routes),只在 CLI self-hosted 路徑 strip

設定分層 + 非互動(#7#8):
- config.ts loadConfig 改三層:env > 專案層 .arcrun.yaml(就近往上找)> 全域
- init 支援 --account-id/--api-token flag + CLOUDFLARE_* env,缺才互動
- 新增 acr config --where 顯示每個值的來源層(token 自動遮罩)
- gitignore 一併排除 .arcrun.yaml

驗收:tsc 全綠;三層 merge 端對端測試 8/8;strip 對真實 toml 驗證
routes/R2/AI 移除而 name/workers_dev/KV 保留。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 07:22:37 +08:00
uncle6me-web 922a57fe34 arcrun — AI workflow execution engine (clean history)
Self-hosted 開源:WASM 零件 + recipe + cypher-executor,跑在你自己的 Cloudflare。

此為重建的乾淨歷史起點(移除曾誤 commit 的 GCP SA 金鑰,舊歷史保留在
richblack/arcrun 與本地 backup 分支)。含:
- acr init --self-hosted installer(建 KV/R2 + codeload 拉預編譯 wasm + wrangler deploy + seed recipe)
- recipe push 把關(資料外流提醒 + 打通檢查)
- 19 個正當零件預編譯 wasm(claude_api/km_writer/kbdb_upsert_block 排除:違反 DECISIONS §1)
- CLI / cypher-executor / registry / 完整 SDD

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-03 15:52:38 +08:00