fix(cli): acr update/deploy 下載源改指 Gitea archive(Arcrun#4) #26

Merged
Leo merged 1 commits from fix/acr-update-gitea-source into main 2026-07-07 08:40:02 +00:00
Owner

Arcrun#4:acr update / 部署下載源 GitHub codeload → Gitea archive

為什麼

  • D20 防 flag:self-hosted 用戶(如 Mira)不能碰 GitHub,但重裝零件的唯一管道 acr update 綁死 codeload.github.com → 沒有乾淨的重裝路徑。
  • install ≈ updateinitupdate 共用 downloadAndDeploy,其內容指紋 manifest 天然「新裝零件補上、內容未變者略過」(冪等)。所以修 update ≈ 把下載源重指 Gitea,用戶跑 acr update 就會把 init 之後新增的零件(如 code)補上、已裝的略過。

改了什麼(只碰 CLI 下載邏輯)

  • cli/src/lib/deploy.ts
    • ARCRUN_REPO 預設 uncle6me-web/ArcrunLeo/Arcrun(Gitea 路徑)。
    • 新增 ARCRUN_GITEA_BASE(預設 https://git.uncle6.me)供 fork/自架站台覆蓋。
    • 新增 giteaToken()ARCRUN_GITEA_TOKEN > GITEA_TOKEN不寫死;public repo 可不設。
    • 抽出純函式 buildArchiveUrl() / buildDownloadHeaders()(好離線測),走 Gitea archive API:GET {base}/api/v1/repos/{owner}/{repo}/archive/{ref}.tar.gz。保留 #13 P2 的 cache-buster query + no-cache header 防 stale;private repo 帶 Authorization: token <TOKEN>
    • downloadRepoTarball 改用上述;401/403 給「設 GITEA_TOKEN」可行動提示。
  • cli/src/commands/update.ts:docstring 對齊(GitHub release → Gitea archive),標註 install≈update 由共用 downloadAndDeploy 保證。
  • cli/tests/deploy-url.test.ts(新):Node 內建 test runner(node --test零新依賴),8 顆全綠。

為什麼選 Gitea archive API

  • Gitea 原生 archive endpoint,與原 codeload tarball「下載 tar.gz → 解壓單一頂層目錄」流程一對一對應(實測頂層目錄 arcrun/,既有 generic 頂層目錄偵測自然吃)。
  • token 走 header(Authorization: token),與既有 GITEA_TOKEN env 機制一致,private repo 直接可用。
  • 不引入額外依賴、不改部署後段(注入/wrangler deploy/seed)邏輯。

驗證(離線 + 唯讀)

  • npm test(cli)8/8 綠:URL 組裝、repo/base 覆蓋、token→header、public 無 token、env 優先序。
  • tsc --noEmit 綠。
  • 唯讀 probe Gitea archive endpoint:200 application/octet-stream ~9.3MB;tarball 含全部 tier1(.component-builds/*)+ tier2(cypher-executor/kbdb/mcp/registry)worker 目錄。
  • 真正打 Gitea 下載 + wrangler deploy 是 leo 的閘,不在本 PR。

leo 要做什麼才能真正 acr update

  1. 確認 self-hosted 用戶端有 GITEA_TOKEN(或 ARCRUN_GITEA_TOKEN)env,且該 token 對 Leo/Arcrun 有讀取權限(若 repo 為 private)。probe 顯示帶 token 可 200。
  2. ⚠️ code 零件目前只有原始碼registry/components/code/),.component-builds/code/component.wasm 尚未 build/commit;tier1 gate 要求 component.wasm 才部署。故本 PR 讓下載源可用,但 code 零件要真正被 acr update 裝上,仍需先 build 其 wasm 並 commit 進 .component-builds/code/(與 claude_api/km_writer 等同類情況)。

草稿 PR,不 merge、不部署、未碰 README(README 由 #22 負責)。

## Arcrun#4:`acr update` / 部署下載源 GitHub codeload → Gitea archive ### 為什麼 - **D20 防 flag**:self-hosted 用戶(如 Mira)不能碰 GitHub,但重裝零件的唯一管道 `acr update` 綁死 `codeload.github.com` → 沒有乾淨的重裝路徑。 - **install ≈ update**:`init` 與 `update` 共用 `downloadAndDeploy`,其內容指紋 manifest 天然「新裝零件補上、內容未變者略過」(冪等)。所以修 update ≈ 把下載源重指 Gitea,用戶跑 `acr update` 就會把 init 之後新增的零件(如 code)補上、已裝的略過。 ### 改了什麼(只碰 CLI 下載邏輯) - `cli/src/lib/deploy.ts` - `ARCRUN_REPO` 預設 `uncle6me-web/Arcrun` → **`Leo/Arcrun`**(Gitea 路徑)。 - 新增 `ARCRUN_GITEA_BASE`(預設 `https://git.uncle6.me`)供 fork/自架站台覆蓋。 - 新增 `giteaToken()`:`ARCRUN_GITEA_TOKEN` > `GITEA_TOKEN`,**不寫死**;public repo 可不設。 - 抽出純函式 `buildArchiveUrl()` / `buildDownloadHeaders()`(好離線測),走 Gitea archive API:`GET {base}/api/v1/repos/{owner}/{repo}/archive/{ref}.tar.gz`。保留 #13 P2 的 cache-buster query + `no-cache` header 防 stale;private repo 帶 `Authorization: token <TOKEN>`。 - `downloadRepoTarball` 改用上述;401/403 給「設 GITEA_TOKEN」可行動提示。 - `cli/src/commands/update.ts`:docstring 對齊(GitHub release → Gitea archive),標註 install≈update 由共用 `downloadAndDeploy` 保證。 - `cli/tests/deploy-url.test.ts`(新):Node 內建 test runner(`node --test`,**零新依賴**),8 顆全綠。 ### 為什麼選 Gitea archive API - Gitea 原生 archive endpoint,與原 codeload tarball「下載 tar.gz → 解壓單一頂層目錄」流程一對一對應(實測頂層目錄 `arcrun/`,既有 generic 頂層目錄偵測自然吃)。 - token 走 header(`Authorization: token`),與既有 `GITEA_TOKEN` env 機制一致,private repo 直接可用。 - 不引入額外依賴、不改部署後段(注入/wrangler deploy/seed)邏輯。 ### 驗證(離線 + 唯讀) - `npm test`(cli)8/8 綠:URL 組裝、`repo`/`base` 覆蓋、token→header、public 無 token、env 優先序。 - `tsc --noEmit` 綠。 - 唯讀 probe Gitea archive endpoint:`200 application/octet-stream ~9.3MB`;tarball 含全部 tier1(`.component-builds/*`)+ tier2(cypher-executor/kbdb/mcp/registry)worker 目錄。 - **真正打 Gitea 下載 + wrangler deploy 是 leo 的閘,不在本 PR。** ### leo 要做什麼才能真正 `acr update` 1. 確認 self-hosted 用戶端有 `GITEA_TOKEN`(或 `ARCRUN_GITEA_TOKEN`)env,且該 token 對 `Leo/Arcrun` 有讀取權限(若 repo 為 private)。probe 顯示帶 token 可 200。 2. ⚠️ **code 零件目前只有原始碼**(`registry/components/code/`),`.component-builds/code/component.wasm` **尚未 build/commit**;tier1 gate 要求 `component.wasm` 才部署。故本 PR 讓下載源可用,但 code 零件要真正被 `acr update` 裝上,仍需先 build 其 wasm 並 commit 進 `.component-builds/code/`(與 claude_api/km_writer 等同類情況)。 草稿 PR,不 merge、不部署、未碰 README(README 由 #22 負責)。
Leo added 1 commit 2026-07-07 08:13:53 +00:00
動機:D20 防 flag 鐵律下 self-hosted 用戶(如 Mira)不能碰 GitHub,
而「init 之後才新增的零件」(如 code 零件)唯一重裝管道 acr update 綁死
GitHub codeload → 沒有乾淨重裝路徑。

改動(只碰 CLI 下載邏輯,不動 README/cypher/mcp/tools):
- deploy.ts:ARCRUN_REPO 預設 uncle6me-web/Arcrun → Leo/Arcrun;
  新增 ARCRUN_GITEA_BASE(預設 https://git.uncle6.me)與 giteaToken()
  (ARCRUN_GITEA_TOKEN > GITEA_TOKEN,不寫死)。
- 抽出純函式 buildArchiveUrl / buildDownloadHeaders 走 Gitea archive API
  GET {base}/api/v1/repos/{owner}/{repo}/archive/{ref}.tar.gz,保留 #13 P2
  cache-buster + no-cache 防 stale;private repo 帶 Authorization: token。
- downloadRepoTarball 改用上述;401/403 給「設 GITEA_TOKEN」提示。
- update.ts docstring 對齊(GitHub release → Gitea archive;標註 install≈update)。

install≈update:init 與 update 共用 downloadAndDeploy,其內容指紋 manifest
天然「新零件補、內容未變者略過」,故用戶跑 acr update 即補裝新零件。

測試:cli/tests/deploy-url.test.ts(Node 內建 test runner,零新依賴)8 顆全綠,
涵蓋 URL 組裝、repo/base 覆蓋、token→header、public 無 token、env 優先序。
真正打 Gitea 下載/部署是 leo 的閘,不在本 PR。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015d5jDbuqT5Htwv3Q88XXKk
Leo marked the pull request as work in progress 2026-07-07 08:14:10 +00:00
Author
Owner

[總管] 審查 可 merge

  • 核實:ARCRUN_REPO 預設改 Leo/ArcrunARCRUN_GITEA_BASE/token env 覆蓋、token 走 header 不寫死、純函式抽出可離線測、保留 cache-buster。
  • 本機實跑:cli npm test 8/8 綠、tsc --noEmit 過。
  • 這條修掉 D20 下 self-hosted 唯一重裝管道斷裂(Arcrun#4),對 rag 產品安裝器(rag-wave1 T6)也是前置。
  • ⚠️ merge 後提醒:npm 上的 acr 仍是舊 binary(Arcrun#1 漏發)——本機/雲端要用此修復需 repo 重 build CLI,或把 #1 npm 發版一起排。
[總管] 審查 ✅ **可 merge**。 - 核實:`ARCRUN_REPO` 預設改 `Leo/Arcrun`、`ARCRUN_GITEA_BASE`/token env 覆蓋、token 走 header 不寫死、純函式抽出可離線測、保留 cache-buster。 - 本機實跑:cli `npm test` 8/8 綠、`tsc --noEmit` 過。 - 這條修掉 D20 下 self-hosted 唯一重裝管道斷裂(Arcrun#4),對 rag 產品安裝器(rag-wave1 T6)也是前置。 - ⚠️ merge 後提醒:**npm 上的 acr 仍是舊 binary(Arcrun#1 漏發)**——本機/雲端要用此修復需 repo 重 build CLI,或把 #1 npm 發版一起排。
Leo marked the pull request as ready for review 2026-07-07 08:40:01 +00:00
Leo merged commit 020ccdf085 into main 2026-07-07 08:40:02 +00:00
Sign in to join this conversation.