Feature Request: 切换账号时同步更新 Antigravity CLI (agy) 凭据,并支持 CLI 侧独立后台热切

Open
#19 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
40/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active

Research direction

Start from AccountSwitchService.switchAccount(id, target) and trace its files snapshot list (before/after/afterDigest) plus restoreFiles() to see how writes and rollback are wired, then read selectBestAccount() for the quota logic the CLI target would reuse. The four payload shapes live under ~/.gemini/, so map each one to an existing in-memory account object before touching the transaction. Done means target='all'/'cli' writes those files atomically and rolls back cleanly, with current_agy_account_id recorded in accounts.json; expect design choices (new target mode, coexistence with guardStopped()) rather than a single edit.

Written by the indexing model from the issue text.

Description

背景与痛点

目前 AccountSwitchService.switchAccount(id, target = 'all') 在切换账号时,通过四阶段原子事务更新了:

  1. 桌面客户端 SQLite (~/Library/Application Support/Antigravity/User/globalStorage/state.vscdb)
  2. macOS 系统钥匙串 (service="gemini", account="antigravity")
  3. GravityBox 账号库 (~/Library/Application Support/GravityBox/accounts.json)

但 Antigravity CLI (agy) 在运行时实际读取的是 ~/.gemini/ 目录下的 4 个独立 CLI 凭据文件。由于目前切号没有同步覆写这 4 个文件,导致:

  • 用户在 GravityBox 中切换账号后,桌面客户端已经变成新账号,但终端里的 agy CLI 仍然停留在旧账号(直到旧账号 429 限流)。
  • 此外,很多重度用户会在后台用 launchd / cron 跑基于 agy CLI 的自动化无人值守任务;桌面客户端因为持有 state.vscdb 锁必须 guardStopped() 先关闭才能切号,但 CLI 并不持有 state.vscdb 锁,完全可以在桌面客户端开启期间独立热切。

建议方案

1. 在 switchAccount() 原子事务中同步写入 CLI 凭据文件(target = 'all' 或 'cli')

AccountSwitchService 现有的 files 快照列表(带 before / after / afterDigest 与异常自动回滚 restoreFiles())已经非常完善,只需在 target === 'all'(或新增 target === 'cli')时,将 ~/.gemini/ 下的 4 个 CLI 凭据文件一并纳入原子事务写入与回滚即可:

目标文件路径(位于 ~/.gemini/ 下) Payload 结构
oauth_creds JSON 文件 {"access_token", "refresh_token", "token_type": "Bearer", "expiry_date": expiry_timestamp * 1000, "id_token", "scope": "https://www.googleapis.com/auth/userinfo.email openid https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/userinfo.profile"}
google_accounts.json {"active": email, "old": []}
antigravity-cli/antigravity-oauth-token {"token": {"access_token", "token_type": "Bearer", "refresh_token", "expiry": "<RFC3339Z>", "expires_in"}, "auth_method": "consumer", "id_token_email": email, "id_token"}
jetski-standalone-oauth-token 同上 (antigravity-cli/antigravity-oauth-token)

(注:若部分上述文件尚不存在,可在回滚日志中记录 existedBefore: false 或仅在检测到用户安装了 agy CLI 时自动同步。)

2. 支持 CLI 侧免关客户端的后台自动热切(target = 'cli' / Hybrid Follow)

目前 selectBestAccount() 已经具备非常精准的双窗口(5h + weekly)配额熔合计算与 ULTRA > PRO > FREE 候选推荐能力:

  • 桌面客户端 (target = 'app'):必须等待用户退出 Antigravity.app 后才允许写 state.vscdb,避免破坏数据库锁;
  • CLI 端 (target = 'cli'):不碰 state.vscdb,仅原子更新 ~/.gemini/ 下的上述 4 个 CLI 凭据文件(并在 accounts.json 中记录 current_agy_account_id)。
  • 这样当后台定时刷新配额发现当前 CLI 绑定账号低于 reserve_percentage(如 10%)时,即使 Antigravity.app 桌面端正开着,GravityBox 也可以先为 agy CLI 静默切换到 selectBestAccount() 选出的健康账号,保证后台 CLI 任务永不撞 429,等用户稍后关闭桌面客户端时再一键对齐桌面端账号。

我们在本地通过一个独立的 Python 守护脚本(agy-account-follow,监听 accounts.json 与 quota_groups 并幂等同步上述 4 个文件)验证了这套机制,在日常桌面交互 + 后台高频 agy 定时任务的混合场景下非常稳定。如果能原生合入 GravityBox 的 AccountSwitchService,体验就完全闭环了!

Dominant language
JavaScript
Stars
21
Forks
0
Avg merge
30m
Merged PRs (30d)
9

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Enzoo404/gravitybox

All issues in Enzoo404/gravitybox

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.