docs(codex): 補齊 read_account_email docstring 與指令檔註解並重建 README
This commit is contained in:
@@ -10,6 +10,21 @@ import time
|
||||
|
||||
|
||||
def read_account_email(timeout_seconds: float = 25.0) -> str:
|
||||
"""透過 codex app-server 的 JSON-RPC account/read 取得目前登入帳號的 email。
|
||||
|
||||
啟動 ``codex app-server`` 子行程,依序送出 initialize / initialized /
|
||||
account/read 三筆 JSON-RPC 訊息,並讀取其回報的登入帳號 email。
|
||||
|
||||
Args:
|
||||
timeout_seconds: 等待 app-server 回應的秒數上限,預設 25.0。
|
||||
|
||||
Returns:
|
||||
登入帳號的 email;取不到或逾時時回傳空字串 ""。
|
||||
|
||||
使用情境:
|
||||
在 CI 中驗證登入身分時呼叫。前置條件為 codex CLI 已安裝,
|
||||
且 $HOME/.codex/auth.json 已寫入有效的 OAuth token。
|
||||
"""
|
||||
process = subprocess.Popen(
|
||||
["codex", "app-server"],
|
||||
stdin=subprocess.PIPE,
|
||||
@@ -20,6 +35,7 @@ def read_account_email(timeout_seconds: float = 25.0) -> str:
|
||||
)
|
||||
|
||||
def send(obj):
|
||||
"""將 dict 物件序列化成 JSON 後寫入 app-server 的 stdin 並 flush。"""
|
||||
process.stdin.write(json.dumps(obj) + "\n")
|
||||
process.stdin.flush()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user