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

- 專案骨架: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 就緒後實作。
This commit is contained in:
2026-09-07 22:59:05 +08:00
parent c26420303e
commit 93176c0eb1
15 changed files with 1279 additions and 3 deletions
+14
View File
@@ -0,0 +1,14 @@
defmodule BearCli do
@moduledoc """
Bear CLI — Bear SSO 的終端機客戶端。
以 Bear 個人存取權杖(Personal Access Token, PAT)在終端機登入,查詢身分
(`whoami`)、取得 Token(`token`),作為 SSO 的終端入口。Device
Authorization Grant(RFC 8628)登入待伺服器端 P1(bear 倉庫)完成後再接上。
"""
@version "0.1.0"
@doc "回傳 CLI 版本字串(與 mix.exs 的 version 同步)。"
def version, do: @version
end