Feature Request: 切换账号时同步更新 Antigravity CLI (agy) 凭据,并支持 CLI 侧独立后台热切
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
- Tech stack
- javascript, swift, typescript
- Domain
- authentication, cli, desktop
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') 在切换账号时,通过四阶段原子事务更新了:
- 桌面客户端 SQLite (
~/Library/Application Support/Antigravity/User/globalStorage/state.vscdb) - macOS 系统钥匙串 (
service="gemini",account="antigravity") - GravityBox 账号库 (
~/Library/Application Support/GravityBox/accounts.json)
但 Antigravity CLI (agy) 在运行时实际读取的是 ~/.gemini/ 目录下的 4 个独立 CLI 凭据文件。由于目前切号没有同步覆写这 4 个文件,导致:
- 用户在 GravityBox 中切换账号后,桌面客户端已经变成新账号,但终端里的
agyCLI 仍然停留在旧账号(直到旧账号 429 限流)。 - 此外,很多重度用户会在后台用
launchd/cron跑基于agyCLI 的自动化无人值守任务;桌面客户端因为持有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 也可以先为agyCLI 静默切换到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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Enzoo404/gravitybox
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Enzoo404/gravitybox#21 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 60/100
Enzoo404/gravitybox#18 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
Enzoo404/gravitybox#20 ·
Maintainers usually reply within 1 day
-
[FEAT] 搞个Windows版本Openenhancement help wanted
Difficulty 5/5 Over a week Newbie friendliness 8/100
Enzoo404/gravitybox#17 · 1 comment ·
Maintainers usually reply within 1 day
All issues in Enzoo404/gravitybox
Similar issues
-
bug pydanty:is-working
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
pydantic/pydantic-ai#13939 ·
Maintainers usually reply within 1 day
-
self-host
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
funmusicplace/mirlo#2625 ·
Maintainers usually reply within 1 day
-
Bug Tests
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
JSPrismarine/JSPrismarine#3271 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Half a day Newbie friendliness 85/100
sindresorhus/eslint-plugin-unicorn#4034 ·
Maintainers usually reply within 1 day
-
Content:WebExt needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day