feat: 實作 bear CLI 骨架與 PAT 模式共用基礎(issue #6) #8

Merged
queena merged 2 commits from feat/cli-skeleton into main 2026-09-07 23:05:19 +08:00
Member

實作 bear CLI 的專案骨架與共用基礎(issue #6 的可先行部分),拆自 #4。

範圍(骨架部分)

  • 專案骨架:Elixir + Mix escript(單檔可執行 bear,開放問題 2 先採 escript),HTTP 一律 Req
  • 設定/憑證檔:~/.config/bear/config.json(BEAR_CONFIG 可覆寫)與 ~/.local/state/bear/credentials.json(0600、原子寫入 rename、O_CREAT|O_EXCL 防 symlink)
  • PAT Bearer 認證:GET /userinfo;401/網路/伺服器錯誤分類
  • --json 輸出與退出碼:依 docs/commands.md 規格對齊(無效 PAT → 3;token --refresh → 用法錯誤 2)
  • BEAR_TOKEN 環境變數:main 規格(issue #1 文件)承諾但未實作,本 PR 補齊——優先於憑證檔、不寫入
  • P2 指令:login --token / whoami / token / logout / status(沿用已關閉 PR #3 的實作,文件改依 main 現行版本)

未包含(依 #6 順序)

  • bear apps 管理指令:待 #5(規格)與 alterminal/bear#28(API)就緒

驗證

  • 35 個單元測試全綠;mix precommit(compile --warnings-as-errors + format + test)通過
  • mix escript.build 產出可執行 bear,--help/--version/status/whoami 未登入路徑實測退出碼正確

issue #6(apps 指令實作待依賴就緒後續做,本 PR 先落骨架)。

實作 bear CLI 的專案骨架與共用基礎(issue #6 的可先行部分),拆自 #4。 ## 範圍(骨架部分) - **專案骨架**:Elixir + Mix escript(單檔可執行 `bear`,開放問題 2 先採 escript),HTTP 一律 Req - **設定/憑證檔**:`~/.config/bear/config.json`(BEAR_CONFIG 可覆寫)與 `~/.local/state/bear/credentials.json`(0600、原子寫入 rename、O_CREAT|O_EXCL 防 symlink) - **PAT Bearer 認證**:`GET /userinfo`;401/網路/伺服器錯誤分類 - **--json 輸出與退出碼**:依 docs/commands.md 規格對齊(無效 PAT → 3;token --refresh → 用法錯誤 2) - **BEAR_TOKEN 環境變數**:main 規格(issue #1 文件)承諾但未實作,本 PR 補齊——優先於憑證檔、不寫入 - **P2 指令**:login --token / whoami / token / logout / status(沿用已關閉 PR #3 的實作,文件改依 main 現行版本) ## 未包含(依 #6 順序) - bear apps 管理指令:待 #5(規格)與 alterminal/bear#28(API)就緒 ## 驗證 - 35 個單元測試全綠;mix precommit(compile --warnings-as-errors + format + test)通過 - mix escript.build 產出可執行 `bear`,--help/--version/status/whoami 未登入路徑實測退出碼正確 issue #6(apps 指令實作待依賴就緒後續做,本 PR 先落骨架)。
alex requested review from queena 2026-09-07 22:44:38 +08:00
Owner

請rebase

請rebase
Member

審核結果(queena):

已對照 issue #6 骨架範圍與 docs/commands.md 規格逐項檢視,並在本機(Elixir 1.20 / OTP 29)實測:

  • mix precommit(compile --warnings-as-errors + format + test):35 個測試全綠。
  • mix escript.build 產出單檔 bear,實測 --help/--version/status(未登入 → exit 3)/whoami(未登入 → exit 3)/token --refresh(已登入 PAT → exit 2,符合 §3.3;未登入 → exit 3,符合退出碼總表)/未知指令 → exit 2。
  • 憑證檔 0600、原子寫入(暫存檔 :exclusive + rename、防 symlink)、BEAR_TOKEN 不寫入憑證檔、/bear 已進 .gitignore,均確認無誤。

一件需要修改後再合併的問題:

mix.lock 鎖定 mint 1.9.3,該版帶 HIGH 安全通報 CVE-2026-82728(HTTP/1 status line 與 chunk extension 無界緩衝,記憶體耗盡 DoS)與 MEDIUM 的 CVE-2026-82729(chunk-size 解析二次方複雜度)。mint 位於本 CLI 的請求路徑(Req → Finch → Mint),且 --issuer 可指向任意伺服器,屬可觸及面,建議合併前更新鎖定版本。

修法很單純:執行 mix deps.update mint(1.9.3 → 1.10.0),把 mix.lock 一起 commit 後 push 到同一分支即可,不需要改任何程式碼。我已在本機驗證升級後 35 個測試全綠、escript 建置與執行正常。

更新後請在這裡留言,我再核准並合併。

審核結果(queena): 已對照 issue #6 骨架範圍與 docs/commands.md 規格逐項檢視,並在本機(Elixir 1.20 / OTP 29)實測: - mix precommit(compile --warnings-as-errors + format + test):35 個測試全綠。 - mix escript.build 產出單檔 bear,實測 --help/--version/status(未登入 → exit 3)/whoami(未登入 → exit 3)/token --refresh(已登入 PAT → exit 2,符合 §3.3;未登入 → exit 3,符合退出碼總表)/未知指令 → exit 2。 - 憑證檔 0600、原子寫入(暫存檔 :exclusive + rename、防 symlink)、BEAR_TOKEN 不寫入憑證檔、/bear 已進 .gitignore,均確認無誤。 一件需要修改後再合併的問題: mix.lock 鎖定 mint 1.9.3,該版帶 HIGH 安全通報 CVE-2026-82728(HTTP/1 status line 與 chunk extension 無界緩衝,記憶體耗盡 DoS)與 MEDIUM 的 CVE-2026-82729(chunk-size 解析二次方複雜度)。mint 位於本 CLI 的請求路徑(Req → Finch → Mint),且 --issuer 可指向任意伺服器,屬可觸及面,建議合併前更新鎖定版本。 修法很單純:執行 mix deps.update mint(1.9.3 → 1.10.0),把 mix.lock 一起 commit 後 push 到同一分支即可,不需要改任何程式碼。我已在本機驗證升級後 35 個測試全綠、escript 建置與執行正常。 更新後請在這裡留言,我再核准並合併。
alex added 2 commits 2026-09-07 22:59:53 +08:00
- 專案骨架:Elixir + Mix escript(單檔可執行 bear),HTTP 一律 Req
- 設定/憑證檔讀寫:0600、原子寫入(rename)、O_CREAT|O_EXCL 防 symlink
- PAT Bearer 呼叫 /userinfo;--json 輸出;規格化退出碼
- 補齊 main 規格承諾的 BEAR_TOKEN 環境變數(優先於憑證檔、不寫入)
- login 無效 PAT 退出碼 3(依 docs/commands.md §3.1);token --refresh 用法錯誤 2(§3.3)
- 35 個單元測試;mix precommit(compile --warnings-as-errors + format + test)全綠
- 沿用已關閉 PR #3 的實作(feat/pat-mode-mvp 分支),文件改依 main 現行版本更新

apps 管理指令待 #5 規格與 alterminal/bear#28 API 就緒後實作。
alex force-pushed feat/cli-skeleton from 76a14686c1 to bd0b0da309 2026-09-07 22:59:53 +08:00 Compare
Author
Member

已完成兩項跟進:

1. Rebase 至最新 main(c264203)
docs/commands.md 有衝突,解法:第 8 節「對應關係」採用 main(#7)的 apps 實際 API 端點列(取代舊的 P3 佔位列),並保留本 PR 新增的第 9 節「現行實作狀態(PAT 模式 MVP)」。程式碼無改動。

2. mix deps.update mint(1.9.3 → 1.10.0)
mix.lock 已更新並 commit,修 CVE-2026-82728(HIGH)與 CVE-2026-82729(MEDIUM),未改任何程式碼。

驗證(本機重跑):

  • mix precommit(compile --warnings-as-errors + format + test):35 個測試全綠
  • mix escript.build 正常,實測 --version/--help/status(未登入 → exit 3)/whoami(未登入 → exit 3)/token --refresh(未登入 → exit 3)/未知指令 → exit 2
  • PR 現已 rebase 在 main 之上(merge base = main HEAD),可乾淨合併

麻煩 @queena 再審,謝謝。

已完成兩項跟進: **1. Rebase 至最新 main(c264203)** docs/commands.md 有衝突,解法:第 8 節「對應關係」採用 main(#7)的 apps 實際 API 端點列(取代舊的 P3 佔位列),並保留本 PR 新增的第 9 節「現行實作狀態(PAT 模式 MVP)」。程式碼無改動。 **2. mix deps.update mint(1.9.3 → 1.10.0)** mix.lock 已更新並 commit,修 CVE-2026-82728(HIGH)與 CVE-2026-82729(MEDIUM),未改任何程式碼。 **驗證**(本機重跑): - mix precommit(compile --warnings-as-errors + format + test):35 個測試全綠 - mix escript.build 正常,實測 --version/--help/status(未登入 → exit 3)/whoami(未登入 → exit 3)/token --refresh(未登入 → exit 3)/未知指令 → exit 2 - PR 現已 rebase 在 main 之上(merge base = main HEAD),可乾淨合併 麻煩 @queena 再審,謝謝。
queena approved these changes 2026-09-07 23:05:16 +08:00
queena merged commit 34797dfe0d into main 2026-09-07 23:05:19 +08:00
Member

複審通過,已核准並合併(queena)。

本機(Elixir 1.20 / OTP 29)重驗:

  • mix precommit(compile --warnings-as-errors + format + test):35 個測試全綠
  • mix escript.build 正常,實測 --version/--help/status(未登入 → exit 3)/whoami(未登入 → exit 3)/token --refresh(未登入 → exit 3)/未知指令 → exit 2
  • mix.lock 已鎖定 mint 1.10.0(CVE-2026-82728/82729 已解),跟進 commit 僅改 mix.lock
  • PR 已 rebase 在 main(c264203)之上,merge base = main HEAD,乾淨合併
複審通過,已核准並合併(queena)。 本機(Elixir 1.20 / OTP 29)重驗: - mix precommit(compile --warnings-as-errors + format + test):35 個測試全綠 - mix escript.build 正常,實測 --version/--help/status(未登入 → exit 3)/whoami(未登入 → exit 3)/token --refresh(未登入 → exit 3)/未知指令 → exit 2 - mix.lock 已鎖定 mint 1.10.0(CVE-2026-82728/82729 已解),跟進 commit 僅改 mix.lock - PR 已 rebase 在 main(c264203)之上,merge base = main HEAD,乾淨合併
Sign in to join this conversation.
No Reviewers
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: alterminal/bear-cli#8