Files
EJClaw/codex_relogin.sh
Codex a9eab5cb94 refactor: run Claude and Codex on one fixed account each
The deployment has a single Claude OAuth credential and a single Codex
ChatGPT account, so the N-account rotation machinery only added state
files, cooldown bookkeeping and code paths that never ran.

Removed:
- Claude token rotation (token-rotation.ts, token-rotation-base.ts):
  rotate-on-limit, per-token cooldowns, token-rotation-state.json.
  CLAUDE_CODE_OAUTH_TOKENS is still read, but only its first entry.
- Codex account rotation (codex-token-rotation.ts): account pool,
  rotate-on-429/auth, dead-auth/cooldown tracking, round-robin advance,
  d7 auto-rotate, codex-rotation-state.json, manual account switch.
- Account index plumbing in token-refresh, claude-credentials-path
  (CLAUDE_ACCOUNTS_DIR / ~/.claude-accounts/<n>), Claude/Codex usage
  collectors, the dashboard rows and the Codex warm-up.
- provider-retry.ts rotation loops and the Codex retry path.

Kept:
- Codex exclusive auth lease (one Codex run at a time), the 15-minute
  waitForCodexAuthLease, and a usage-poll lease that skips while a run
  holds the account (codex-auth.ts).
- Session auth copy and write-back of refreshed tokens
  (syncCodexSessionAuthBack, syncClaudeSessionAuthBack).
- Codex auth path: ~/.codex-accounts/0/auth.json, else ~/.codex/auth.json
  (now resolved per run, so a re-login needs no restart).
- Claude token refresh loop, CLAUDE_CREDENTIALS_PATH and the
  CLAUDE_TOKEN_REFRESH_* / CLAUDE_USAGE_USE_HOME_CREDENTIALS flags; an
  auth-expired run still force-refreshes the token and retries once.
- Error classification (classifyClaudeTrigger, classifyCodexTrigger).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 20:14:38 +09:00

88 lines
3.6 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# codex_relogin.sh — Codex(ChatGPT) 계정을 device-code OAuth 로 재로그인한다.
#
# 사용법:
# ./codex_relogin.sh
#
# 참고:
# * Codex 로그인은 이 호스트에서 두 봇(EJClaw / KAClaw)이 "공유"한다.
# 계정 저장 위치가 폴더별이 아니라 ~/.codex-accounts/0 이기 때문.
# → 한 번만 재로그인하면 두 봇 모두에 반영된다.
# * codex CLI 가 URL + 일회용 코드를 출력한다(15분 유효). 브라우저에서
# 로그인/코드입력을 마치면 codex 가 auth.json 을 자동 저장한다.
#
set -euo pipefail
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$DIR"
# --- codex 실행 파일 찾기 --------------------------------------------------
CODEX="$(command -v codex 2>/dev/null || true)"
if [ -z "$CODEX" ]; then
# fnm 로 설치된 node 전역 bin 에서 탐색
for c in "$HOME"/.local/share/fnm/node-versions/*/installation/bin/codex; do
[ -x "$c" ] && CODEX="$c" && break
done
fi
if [ -z "$CODEX" ]; then
echo "❌ codex CLI 를 찾을 수 없습니다. 'command -v codex' 로 확인하세요." >&2
exit 1
fi
# --- 대상 위치 결정 --------------------------------------------------------
# 앱은 ~/.codex-accounts/0/auth.json 를 읽는다. 없으면 ~/.codex 로 폴백.
if [ -d "$HOME/.codex-accounts/0" ]; then
CODEX_TARGET="$HOME/.codex-accounts/0"
else
CODEX_TARGET="$HOME/.codex"
fi
export CODEX_HOME="$CODEX_TARGET"
# --- 서비스명 자동 감지 (폴더명 소문자 + .service) -------------------------
SERVICE="$(basename "$DIR" | tr '[:upper:]' '[:lower:]').service"
echo "======================================================================"
echo " Codex 재로그인 (device-code OAuth)"
echo " codex : $CODEX"
echo " CODEX_HOME : $CODEX_HOME (auth.json 저장 위치)"
echo " 서비스 : $SERVICE"
echo " ※ Codex 로그인은 EJClaw/KAClaw 두 봇이 공유합니다."
echo "======================================================================"
echo
echo "▶ 아래 안내대로 브라우저에서 URL 을 열고 표시되는 코드를 입력하세요."
echo " (로그인이 끝나면 자동으로 저장되고 이 창이 넘어갑니다.)"
echo "----------------------------------------------------------------------"
# --- 로그인 실행 (codex 가 URL/코드 출력 + 폴링까지 담당) ------------------
if "$CODEX" login --device-auth; then
echo "----------------------------------------------------------------------"
echo "✅ Codex 로그인 성공 — auth.json 저장: $CODEX_HOME/auth.json"
else
echo "----------------------------------------------------------------------"
echo "❌ Codex 로그인 실패 또는 취소됨. 다시 실행해 시도하세요." >&2
exit 1
fi
# --- 상태 확인 -------------------------------------------------------------
echo
echo "▶ 로그인 상태 확인:"
"$CODEX" login status 2>&1 | sed 's/^/ /' || true
# --- 서비스 재시작 ---------------------------------------------------------
echo
echo "▶ $SERVICE 재시작..."
if systemctl --user restart "$SERVICE" 2>/dev/null; then
sleep 1
STATE="$(systemctl --user is-active "$SERVICE" 2>/dev/null || true)"
echo "✅ $SERVICE 상태: $STATE"
echo " (공유 계정이므로 다른 봇도 새 로그인을 사용합니다. 필요하면"
echo " 상대 봇도 재시작하세요: systemctl --user restart <다른서비스>)"
else
echo "⚠ $SERVICE 재시작 건너뜀(서비스 없음/권한 없음). 수동 재시작:" >&2
echo " systemctl --user restart $SERVICE" >&2
fi
echo
echo "완료. 🎉"