antigravity-swap 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ build/
5
+ dist/
6
+ *.egg-info/
7
+ .pytest_cache/
8
+ *.spec
9
+ *.aswap.json
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 hrmasss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,323 @@
1
+ Metadata-Version: 2.5
2
+ Name: antigravity-swap
3
+ Version: 0.1.0
4
+ Summary: Multi-account switcher for the Antigravity CLI (agy), with automatic rotation and quota-aware failover
5
+ Project-URL: Homepage, https://github.com/hrmasss/antigravity-swap
6
+ Project-URL: Repository, https://github.com/hrmasss/antigravity-swap
7
+ Project-URL: Issues, https://github.com/hrmasss/antigravity-swap/issues
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: account-switcher,agy,antigravity,cli,gemini
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: MacOS
15
+ Classifier: Operating System :: Microsoft :: Windows
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Utilities
22
+ Requires-Python: >=3.12
23
+ Description-Content-Type: text/markdown
24
+
25
+ # antigravity-swap
26
+
27
+ Multi-account switcher for the Antigravity CLI (`agy`). Switch between Google accounts without signing out, let `aswap` switch for you before an account runs out, see every account's quota in one table, and run long print-mode tasks that carry on to the next account when one hits its limit.
28
+
29
+ Modeled on [claude-swap](https://github.com/realiti4/claude-swap): same commands, same defaults where they make sense for agy.
30
+
31
+ ## Installation
32
+
33
+ ### Using uv (recommended)
34
+
35
+ ```bash
36
+ uv tool install antigravity-swap
37
+ ```
38
+
39
+ ### Using pipx
40
+
41
+ ```bash
42
+ pipx install antigravity-swap
43
+ ```
44
+
45
+ ### Standalone binary
46
+
47
+ No Python needed. Linux (x86_64, aarch64) and macOS (Apple silicon):
48
+
49
+ ```bash
50
+ curl -fsSL https://raw.githubusercontent.com/hrmasss/antigravity-swap/main/install.sh | sh
51
+ ```
52
+
53
+ Windows (PowerShell):
54
+
55
+ ```powershell
56
+ $d = "$env:LOCALAPPDATA\Programs\aswap"; New-Item -ItemType Directory -Force $d | Out-Null
57
+ irm https://github.com/hrmasss/antigravity-swap/releases/latest/download/aswap-windows-x86_64.exe -OutFile "$d\aswap.exe"
58
+ # then add $d to your PATH
59
+ ```
60
+
61
+ Every binary is listed with its checksum on the [releases page](https://github.com/hrmasss/antigravity-swap/releases).
62
+
63
+ ### From source
64
+
65
+ ```bash
66
+ git clone https://github.com/hrmasss/antigravity-swap.git
67
+ cd antigravity-swap
68
+ uv sync
69
+ uv run aswap --help
70
+ ```
71
+
72
+ ### Updating
73
+
74
+ ```bash
75
+ uv tool upgrade antigravity-swap # or: pipx upgrade antigravity-swap
76
+ ```
77
+
78
+ For the binary, run the install line again.
79
+
80
+ ## Usage
81
+
82
+ ### Add your accounts
83
+
84
+ Sign in to agy with your first account, then:
85
+
86
+ ```bash
87
+ aswap add
88
+ ```
89
+
90
+ Sign in to agy with the next account (just run `agy` and pick it; no need to sign out first) and run `aswap add` again. Repeat for each account. Re-running `aswap add` on an account that is already stored updates its login instead of duplicating it.
91
+
92
+ Already keep accounts in separate agy directories (`agy --gemini_dir=...`)? Import them directly:
93
+
94
+ ```bash
95
+ aswap add --from-dir ~/agy-accounts/work --alias work
96
+ ```
97
+
98
+ ### See every account
99
+
100
+ ```bash
101
+ aswap list
102
+ ```
103
+
104
+ ```
105
+ # account 5h week 3p 5h 3p wk 5h resets checked
106
+ * 1 you@example.com (home) 90% 44% 0% 0% 17:23 just now limited until 17:13
107
+ 2 work@example.com (work) 0% 0% 0% 0% 17:23 just now
108
+ 3 side@example.com 0% 21% 0% 33% 17:23 just now
109
+ ```
110
+
111
+ Numbers are **used** percent per window. `5h` and `week` are the Gemini models; `3p` is Claude and GPT through agy, which agy meters separately. `*` marks the account plain `agy` uses now. `aswap list --refresh` forces fresh readings; `--cached` skips the network.
112
+
113
+ Readings come from the same endpoint the agy CLI uses. When an account's access token has expired, aswap renews it by running `agy models`, which lists models and spends no quota.
114
+
115
+ ### Switch accounts
116
+
117
+ Rotate to the next account:
118
+
119
+ ```bash
120
+ aswap switch
121
+ ```
122
+
123
+ Or pick one:
124
+
125
+ ```bash
126
+ aswap switch 2
127
+ aswap switch work@example.com
128
+ aswap switch work # by alias, once set with `aswap alias 2 work`
129
+ ```
130
+
131
+ Or let aswap choose: `aswap switch --strategy best` (most quota left), `--strategy next-available` (skip spent accounts), `--strategy consume-first` (weekly window that resets soonest).
132
+
133
+ After writing the new login, aswap runs `agy models` to prove it works. If the login was revoked, aswap switches back, quarantines that account, and tells you to re-add it.
134
+
135
+ **New agy launches use the new account. A session that is already running keeps the account it started with**, because agy holds its token in memory. Restart it to move it over; `agy -c` resumes the last conversation.
136
+
137
+ ### Automatic switching
138
+
139
+ ```bash
140
+ aswap auto # foreground loop, checks every 60s
141
+ aswap auto --threshold 80 # switch earlier
142
+ aswap auto --pool 3p # decide on the Claude/GPT quota instead of Gemini
143
+ aswap auto --once # one check, for cron or scripts
144
+ aswap auto --dry-run # say what it would do, never switch
145
+ aswap auto --strategy consume-first
146
+ ```
147
+
148
+ <details>
149
+ <summary>How it decides</summary>
150
+
151
+ - The **binding window** is the most-used window in the chosen pool (`gemini` by default, `3p`, or `all`). At or above `threshold` (default 90%), aswap looks for a better account.
152
+ - A proactive switch only lands on an account below the threshold **and** at least `hysteresis_pct` (default 10) points less used, so two accounts near the line never ping-pong.
153
+ - A cooldown (default 5 min) separates proactive switches. An account that is fully spent, or held out after a quota error, skips the cooldown.
154
+ - `consume-first` keeps you on the account whose weekly window resets soonest, switching even below the threshold, so quota that is about to reset is not wasted.
155
+ - Polling is bounded: the active account every tick, at most two others per tick, each about every ten minutes.
156
+ - When every account is over the threshold, it reports `all-exhausted` and checks less often until the first hold ends.
157
+ - Accounts that are disabled, quarantined or held out are never picked.
158
+
159
+ For cron, `--once` reports in its exit code: `0` switched, `1` error, `2` nothing to do, `3` blocked (no viable target). `--json` prints one JSON event per line:
160
+
161
+ ```bash
162
+ */5 * * * * aswap auto --once --json >> ~/.aswap-auto.log 2>&1
163
+ ```
164
+
165
+ </details>
166
+
167
+ ### Long tasks that survive a quota limit: `aswap exec`
168
+
169
+ Some agy limits never show in the quota numbers: an account can read 100% left and still stop mid-run with `RESOURCE_EXHAUSTED (code 429): Individual quota reached ... Resets in 4h42m2s`. `aswap exec` handles that case:
170
+
171
+ ```bash
172
+ aswap exec -- -p "migrate the tests to pytest" --dangerously-skip-permissions
173
+ aswap exec work -- -p "..." # start on a specific account
174
+ aswap exec --strategy rotate --max-hops 3 -- -p "..."
175
+ ```
176
+
177
+ Everything after `--` goes to agy. When the run stops on a quota error, aswap:
178
+
179
+ 1. holds that account out until the reset time in the error (or `exec.limit_fallback_hours` if there is none),
180
+ 2. picks the next account (`exec.strategy`, default `best`),
181
+ 3. copies the conversation to that account and resumes it with `agy --conversation <id>` and a short "continue where you stopped" prompt (`exec.resume_prompt`).
182
+
183
+ A conversation is a local file, so the next account sees the whole history. Before each hop aswap checks the login with `agy models`; an account whose login is dead is quarantined and skipped instead of stalling on a sign-in prompt.
184
+
185
+ Output: with no `--output-format`, you get the final response as plain text. `--output-format json` gives agy's JSON; `stream-json` streams through. Exit code is agy's, or `3` when every account is spent.
186
+
187
+ On platforms where agy has one login per machine (see below), `exec` changes the default login as it hops, and says so.
188
+
189
+ ### Run accounts side by side: `aswap run` (Linux)
190
+
191
+ ```bash
192
+ aswap run 2 # agy as account 2, in this terminal only
193
+ aswap run work -- -c # everything after -- goes to agy
194
+ aswap run 2 --share-history # share conversations with your default agy
195
+ ```
196
+
197
+ Each account gets its own agy directory under aswap's data folder, with your settings, MCP config and skills mirrored from `~/.gemini` on every launch. When the session ends, the token agy renewed is saved back. Running the account that is already your default login just launches plain `agy`; `--require-session` refuses instead.
198
+
199
+ Bind a directory to an account and a bare `aswap run` there picks it:
200
+
201
+ ```bash
202
+ aswap map 2 ~/work/client-app
203
+ cd ~/work/client-app && aswap run # account 2
204
+ aswap map # list bindings
205
+ aswap unmap ~/work/client-app
206
+ ```
207
+
208
+ ## Platform support
209
+
210
+ Where agy keeps its login decides what is possible:
211
+
212
+ | | Linux (headless) | Windows | macOS, desktop Linux |
213
+ |---|---|---|---|
214
+ | Login lives in | `~/.gemini/antigravity-cli/antigravity-oauth-token` | Credential Manager, `gemini:antigravity` | system keyring |
215
+ | `add`, `list`, `switch`, `auto`, `exec` | yes | yes | experimental |
216
+ | `run` (two accounts at once) | yes | no | no |
217
+ | Quota for non-active accounts | always | until its token expires (~1h after last use) | until its token expires |
218
+
219
+ On Windows and keyring platforms the login is global: `agy --gemini_dir` changes where conversations go, not which account signs in. So one account is active per machine, and only the active one can renew its token. Force a backend with `ASWAP_BACKEND=file|wincred|keychain|secret-service`.
220
+
221
+ Tested against agy 1.2.x on Linux and Windows. macOS and desktop-keyring support follow how agy's keyring library stores the login and have not been tested on real machines yet; reports welcome.
222
+
223
+ ## Other commands
224
+
225
+ ```bash
226
+ aswap status # which account agy is using now
227
+ aswap refresh [N] # renew tokens and fetch quota now
228
+ aswap watch # live quota table
229
+ aswap disable 2 / aswap enable 2 # hold an account out of rotation (still a valid explicit target)
230
+ aswap limit 2 90m # hold it out for a while
231
+ aswap limit 2 --clear # clear a hold or a quarantine
232
+ aswap alias 2 work # short name, usable anywhere a number or email is
233
+ aswap alias 2 --unset
234
+ aswap remove 2 # forget an account (agy's own login is untouched)
235
+ aswap config # settings, see below
236
+ aswap export backup.json # all accounts to a file
237
+ aswap import backup.json # skips accounts that exist; --force replaces
238
+ aswap purge # delete all aswap data
239
+ ```
240
+
241
+ Bare `aswap` is `aswap list`.
242
+
243
+ ## Configuration
244
+
245
+ ```bash
246
+ aswap config # every key, its value, and whether it is the default
247
+ aswap config set autoswitch.threshold 80 # validated
248
+ aswap config get autoswitch.threshold
249
+ aswap config unset autoswitch.threshold
250
+ aswap config path
251
+ ```
252
+
253
+ | Key | Default | Meaning |
254
+ |---|---|---|
255
+ | `autoswitch.threshold` | `90` | used % that makes `auto` look for a better account |
256
+ | `autoswitch.interval_seconds` | `60` | seconds between checks |
257
+ | `autoswitch.cooldown_seconds` | `300` | minimum gap between proactive switches |
258
+ | `autoswitch.hysteresis_pct` | `10` | how much less used a target must be |
259
+ | `autoswitch.strategy` | `best` | `best` or `consume-first` |
260
+ | `autoswitch.pool` | `gemini` | `gemini`, `3p` or `all` |
261
+ | `switch.verify` | `true` | prove each new login with `agy models` |
262
+ | `exec.strategy` | `best` | `rotate`, `best`, `next-available`, `consume-first` |
263
+ | `exec.max_hops` | `0` | most account changes per run; `0` is every account once |
264
+ | `exec.resume_prompt` | (built in) | prompt sent when a conversation moves to the next account |
265
+ | `exec.limit_fallback_hours` | `5` | hold time when a quota error names no reset |
266
+ | `usage.max_age_seconds` | `300` | readings older than this are re-fetched |
267
+ | `usage.renew` | `true` | renew expired tokens with `agy models` before reading quota |
268
+ | `agy.path` | (PATH) | the agy binary to use |
269
+
270
+ ## JSON output
271
+
272
+ `list`, `status`, `switch` and `config` take `--json`. Every payload has `schemaVersion: 1`; fields are only ever added.
273
+
274
+ ```json
275
+ {
276
+ "schemaVersion": 1,
277
+ "activeAccountNumber": 1,
278
+ "backend": "file",
279
+ "accounts": [
280
+ { "number": 1, "email": "you@example.com", "active": true, "usageStatus": "ok", "usageAgeSeconds": 42,
281
+ "usage": { "gemini-5h": { "usedPct": 90.0, "resetsAt": "2026-10-01T17:23:31Z" },
282
+ "gemini-weekly": { "usedPct": 44.0, "resetsAt": "2026-10-05T07:02:44Z" } } }
283
+ ]
284
+ }
285
+ ```
286
+
287
+ Rows may also carry `alias`, `disabled`, `limitedUntil` / `limitedReason`, `quarantined` / `quarantineReason`, and `usageError`.
288
+
289
+ ## How it works
290
+
291
+ - `aswap add` copies agy's login (its OAuth token blob) into aswap's data folder, labelled by the email in its ID token.
292
+ - `aswap switch` saves the current login back to its slot first (agy may have renewed it), then writes the target's login where agy reads it, under a lock so two aswap processes never interleave.
293
+ - Which account is active is never stored: aswap reads agy's current login and matches it, so it cannot drift.
294
+ - Token renewal is agy's own: aswap runs `agy models`, which renews an expired access token and writes it back. aswap never holds an OAuth client secret.
295
+ - Quota comes from `loadCodeAssist` and `retrieveUserQuotaSummary` on Google's Cloud Code endpoint, called with each account's own access token.
296
+
297
+ ## Data locations
298
+
299
+ | Platform | Folder |
300
+ |---|---|
301
+ | Linux | `${XDG_DATA_HOME:-~/.local/share}/antigravity-swap/` |
302
+ | macOS | `~/Library/Application Support/antigravity-swap/` |
303
+ | Windows | `%LOCALAPPDATA%\antigravity-swap\` |
304
+
305
+ Override with `ASWAP_HOME`. Inside: `accounts.json`, `credentials/<n>.json` (0600, folder 0700), `usage/`, `sessions/<n>/` (agy directories for `run` and `exec`), `settings.json`. `ASWAP_GEMINI_DIR` overrides agy's default `~/.gemini`.
306
+
307
+ The stored logins and `aswap export` files are live credentials in plaintext. Treat them like SSH keys.
308
+
309
+ ## Uninstall
310
+
311
+ ```bash
312
+ aswap purge
313
+ uv tool uninstall antigravity-swap # or: pipx uninstall antigravity-swap
314
+ ```
315
+
316
+ ## Requirements
317
+
318
+ - The Antigravity CLI (`agy`), signed in
319
+ - Python 3.12+ (not needed for the standalone binary)
320
+
321
+ ## License
322
+
323
+ MIT
@@ -0,0 +1,299 @@
1
+ # antigravity-swap
2
+
3
+ Multi-account switcher for the Antigravity CLI (`agy`). Switch between Google accounts without signing out, let `aswap` switch for you before an account runs out, see every account's quota in one table, and run long print-mode tasks that carry on to the next account when one hits its limit.
4
+
5
+ Modeled on [claude-swap](https://github.com/realiti4/claude-swap): same commands, same defaults where they make sense for agy.
6
+
7
+ ## Installation
8
+
9
+ ### Using uv (recommended)
10
+
11
+ ```bash
12
+ uv tool install antigravity-swap
13
+ ```
14
+
15
+ ### Using pipx
16
+
17
+ ```bash
18
+ pipx install antigravity-swap
19
+ ```
20
+
21
+ ### Standalone binary
22
+
23
+ No Python needed. Linux (x86_64, aarch64) and macOS (Apple silicon):
24
+
25
+ ```bash
26
+ curl -fsSL https://raw.githubusercontent.com/hrmasss/antigravity-swap/main/install.sh | sh
27
+ ```
28
+
29
+ Windows (PowerShell):
30
+
31
+ ```powershell
32
+ $d = "$env:LOCALAPPDATA\Programs\aswap"; New-Item -ItemType Directory -Force $d | Out-Null
33
+ irm https://github.com/hrmasss/antigravity-swap/releases/latest/download/aswap-windows-x86_64.exe -OutFile "$d\aswap.exe"
34
+ # then add $d to your PATH
35
+ ```
36
+
37
+ Every binary is listed with its checksum on the [releases page](https://github.com/hrmasss/antigravity-swap/releases).
38
+
39
+ ### From source
40
+
41
+ ```bash
42
+ git clone https://github.com/hrmasss/antigravity-swap.git
43
+ cd antigravity-swap
44
+ uv sync
45
+ uv run aswap --help
46
+ ```
47
+
48
+ ### Updating
49
+
50
+ ```bash
51
+ uv tool upgrade antigravity-swap # or: pipx upgrade antigravity-swap
52
+ ```
53
+
54
+ For the binary, run the install line again.
55
+
56
+ ## Usage
57
+
58
+ ### Add your accounts
59
+
60
+ Sign in to agy with your first account, then:
61
+
62
+ ```bash
63
+ aswap add
64
+ ```
65
+
66
+ Sign in to agy with the next account (just run `agy` and pick it; no need to sign out first) and run `aswap add` again. Repeat for each account. Re-running `aswap add` on an account that is already stored updates its login instead of duplicating it.
67
+
68
+ Already keep accounts in separate agy directories (`agy --gemini_dir=...`)? Import them directly:
69
+
70
+ ```bash
71
+ aswap add --from-dir ~/agy-accounts/work --alias work
72
+ ```
73
+
74
+ ### See every account
75
+
76
+ ```bash
77
+ aswap list
78
+ ```
79
+
80
+ ```
81
+ # account 5h week 3p 5h 3p wk 5h resets checked
82
+ * 1 you@example.com (home) 90% 44% 0% 0% 17:23 just now limited until 17:13
83
+ 2 work@example.com (work) 0% 0% 0% 0% 17:23 just now
84
+ 3 side@example.com 0% 21% 0% 33% 17:23 just now
85
+ ```
86
+
87
+ Numbers are **used** percent per window. `5h` and `week` are the Gemini models; `3p` is Claude and GPT through agy, which agy meters separately. `*` marks the account plain `agy` uses now. `aswap list --refresh` forces fresh readings; `--cached` skips the network.
88
+
89
+ Readings come from the same endpoint the agy CLI uses. When an account's access token has expired, aswap renews it by running `agy models`, which lists models and spends no quota.
90
+
91
+ ### Switch accounts
92
+
93
+ Rotate to the next account:
94
+
95
+ ```bash
96
+ aswap switch
97
+ ```
98
+
99
+ Or pick one:
100
+
101
+ ```bash
102
+ aswap switch 2
103
+ aswap switch work@example.com
104
+ aswap switch work # by alias, once set with `aswap alias 2 work`
105
+ ```
106
+
107
+ Or let aswap choose: `aswap switch --strategy best` (most quota left), `--strategy next-available` (skip spent accounts), `--strategy consume-first` (weekly window that resets soonest).
108
+
109
+ After writing the new login, aswap runs `agy models` to prove it works. If the login was revoked, aswap switches back, quarantines that account, and tells you to re-add it.
110
+
111
+ **New agy launches use the new account. A session that is already running keeps the account it started with**, because agy holds its token in memory. Restart it to move it over; `agy -c` resumes the last conversation.
112
+
113
+ ### Automatic switching
114
+
115
+ ```bash
116
+ aswap auto # foreground loop, checks every 60s
117
+ aswap auto --threshold 80 # switch earlier
118
+ aswap auto --pool 3p # decide on the Claude/GPT quota instead of Gemini
119
+ aswap auto --once # one check, for cron or scripts
120
+ aswap auto --dry-run # say what it would do, never switch
121
+ aswap auto --strategy consume-first
122
+ ```
123
+
124
+ <details>
125
+ <summary>How it decides</summary>
126
+
127
+ - The **binding window** is the most-used window in the chosen pool (`gemini` by default, `3p`, or `all`). At or above `threshold` (default 90%), aswap looks for a better account.
128
+ - A proactive switch only lands on an account below the threshold **and** at least `hysteresis_pct` (default 10) points less used, so two accounts near the line never ping-pong.
129
+ - A cooldown (default 5 min) separates proactive switches. An account that is fully spent, or held out after a quota error, skips the cooldown.
130
+ - `consume-first` keeps you on the account whose weekly window resets soonest, switching even below the threshold, so quota that is about to reset is not wasted.
131
+ - Polling is bounded: the active account every tick, at most two others per tick, each about every ten minutes.
132
+ - When every account is over the threshold, it reports `all-exhausted` and checks less often until the first hold ends.
133
+ - Accounts that are disabled, quarantined or held out are never picked.
134
+
135
+ For cron, `--once` reports in its exit code: `0` switched, `1` error, `2` nothing to do, `3` blocked (no viable target). `--json` prints one JSON event per line:
136
+
137
+ ```bash
138
+ */5 * * * * aswap auto --once --json >> ~/.aswap-auto.log 2>&1
139
+ ```
140
+
141
+ </details>
142
+
143
+ ### Long tasks that survive a quota limit: `aswap exec`
144
+
145
+ Some agy limits never show in the quota numbers: an account can read 100% left and still stop mid-run with `RESOURCE_EXHAUSTED (code 429): Individual quota reached ... Resets in 4h42m2s`. `aswap exec` handles that case:
146
+
147
+ ```bash
148
+ aswap exec -- -p "migrate the tests to pytest" --dangerously-skip-permissions
149
+ aswap exec work -- -p "..." # start on a specific account
150
+ aswap exec --strategy rotate --max-hops 3 -- -p "..."
151
+ ```
152
+
153
+ Everything after `--` goes to agy. When the run stops on a quota error, aswap:
154
+
155
+ 1. holds that account out until the reset time in the error (or `exec.limit_fallback_hours` if there is none),
156
+ 2. picks the next account (`exec.strategy`, default `best`),
157
+ 3. copies the conversation to that account and resumes it with `agy --conversation <id>` and a short "continue where you stopped" prompt (`exec.resume_prompt`).
158
+
159
+ A conversation is a local file, so the next account sees the whole history. Before each hop aswap checks the login with `agy models`; an account whose login is dead is quarantined and skipped instead of stalling on a sign-in prompt.
160
+
161
+ Output: with no `--output-format`, you get the final response as plain text. `--output-format json` gives agy's JSON; `stream-json` streams through. Exit code is agy's, or `3` when every account is spent.
162
+
163
+ On platforms where agy has one login per machine (see below), `exec` changes the default login as it hops, and says so.
164
+
165
+ ### Run accounts side by side: `aswap run` (Linux)
166
+
167
+ ```bash
168
+ aswap run 2 # agy as account 2, in this terminal only
169
+ aswap run work -- -c # everything after -- goes to agy
170
+ aswap run 2 --share-history # share conversations with your default agy
171
+ ```
172
+
173
+ Each account gets its own agy directory under aswap's data folder, with your settings, MCP config and skills mirrored from `~/.gemini` on every launch. When the session ends, the token agy renewed is saved back. Running the account that is already your default login just launches plain `agy`; `--require-session` refuses instead.
174
+
175
+ Bind a directory to an account and a bare `aswap run` there picks it:
176
+
177
+ ```bash
178
+ aswap map 2 ~/work/client-app
179
+ cd ~/work/client-app && aswap run # account 2
180
+ aswap map # list bindings
181
+ aswap unmap ~/work/client-app
182
+ ```
183
+
184
+ ## Platform support
185
+
186
+ Where agy keeps its login decides what is possible:
187
+
188
+ | | Linux (headless) | Windows | macOS, desktop Linux |
189
+ |---|---|---|---|
190
+ | Login lives in | `~/.gemini/antigravity-cli/antigravity-oauth-token` | Credential Manager, `gemini:antigravity` | system keyring |
191
+ | `add`, `list`, `switch`, `auto`, `exec` | yes | yes | experimental |
192
+ | `run` (two accounts at once) | yes | no | no |
193
+ | Quota for non-active accounts | always | until its token expires (~1h after last use) | until its token expires |
194
+
195
+ On Windows and keyring platforms the login is global: `agy --gemini_dir` changes where conversations go, not which account signs in. So one account is active per machine, and only the active one can renew its token. Force a backend with `ASWAP_BACKEND=file|wincred|keychain|secret-service`.
196
+
197
+ Tested against agy 1.2.x on Linux and Windows. macOS and desktop-keyring support follow how agy's keyring library stores the login and have not been tested on real machines yet; reports welcome.
198
+
199
+ ## Other commands
200
+
201
+ ```bash
202
+ aswap status # which account agy is using now
203
+ aswap refresh [N] # renew tokens and fetch quota now
204
+ aswap watch # live quota table
205
+ aswap disable 2 / aswap enable 2 # hold an account out of rotation (still a valid explicit target)
206
+ aswap limit 2 90m # hold it out for a while
207
+ aswap limit 2 --clear # clear a hold or a quarantine
208
+ aswap alias 2 work # short name, usable anywhere a number or email is
209
+ aswap alias 2 --unset
210
+ aswap remove 2 # forget an account (agy's own login is untouched)
211
+ aswap config # settings, see below
212
+ aswap export backup.json # all accounts to a file
213
+ aswap import backup.json # skips accounts that exist; --force replaces
214
+ aswap purge # delete all aswap data
215
+ ```
216
+
217
+ Bare `aswap` is `aswap list`.
218
+
219
+ ## Configuration
220
+
221
+ ```bash
222
+ aswap config # every key, its value, and whether it is the default
223
+ aswap config set autoswitch.threshold 80 # validated
224
+ aswap config get autoswitch.threshold
225
+ aswap config unset autoswitch.threshold
226
+ aswap config path
227
+ ```
228
+
229
+ | Key | Default | Meaning |
230
+ |---|---|---|
231
+ | `autoswitch.threshold` | `90` | used % that makes `auto` look for a better account |
232
+ | `autoswitch.interval_seconds` | `60` | seconds between checks |
233
+ | `autoswitch.cooldown_seconds` | `300` | minimum gap between proactive switches |
234
+ | `autoswitch.hysteresis_pct` | `10` | how much less used a target must be |
235
+ | `autoswitch.strategy` | `best` | `best` or `consume-first` |
236
+ | `autoswitch.pool` | `gemini` | `gemini`, `3p` or `all` |
237
+ | `switch.verify` | `true` | prove each new login with `agy models` |
238
+ | `exec.strategy` | `best` | `rotate`, `best`, `next-available`, `consume-first` |
239
+ | `exec.max_hops` | `0` | most account changes per run; `0` is every account once |
240
+ | `exec.resume_prompt` | (built in) | prompt sent when a conversation moves to the next account |
241
+ | `exec.limit_fallback_hours` | `5` | hold time when a quota error names no reset |
242
+ | `usage.max_age_seconds` | `300` | readings older than this are re-fetched |
243
+ | `usage.renew` | `true` | renew expired tokens with `agy models` before reading quota |
244
+ | `agy.path` | (PATH) | the agy binary to use |
245
+
246
+ ## JSON output
247
+
248
+ `list`, `status`, `switch` and `config` take `--json`. Every payload has `schemaVersion: 1`; fields are only ever added.
249
+
250
+ ```json
251
+ {
252
+ "schemaVersion": 1,
253
+ "activeAccountNumber": 1,
254
+ "backend": "file",
255
+ "accounts": [
256
+ { "number": 1, "email": "you@example.com", "active": true, "usageStatus": "ok", "usageAgeSeconds": 42,
257
+ "usage": { "gemini-5h": { "usedPct": 90.0, "resetsAt": "2026-10-01T17:23:31Z" },
258
+ "gemini-weekly": { "usedPct": 44.0, "resetsAt": "2026-10-05T07:02:44Z" } } }
259
+ ]
260
+ }
261
+ ```
262
+
263
+ Rows may also carry `alias`, `disabled`, `limitedUntil` / `limitedReason`, `quarantined` / `quarantineReason`, and `usageError`.
264
+
265
+ ## How it works
266
+
267
+ - `aswap add` copies agy's login (its OAuth token blob) into aswap's data folder, labelled by the email in its ID token.
268
+ - `aswap switch` saves the current login back to its slot first (agy may have renewed it), then writes the target's login where agy reads it, under a lock so two aswap processes never interleave.
269
+ - Which account is active is never stored: aswap reads agy's current login and matches it, so it cannot drift.
270
+ - Token renewal is agy's own: aswap runs `agy models`, which renews an expired access token and writes it back. aswap never holds an OAuth client secret.
271
+ - Quota comes from `loadCodeAssist` and `retrieveUserQuotaSummary` on Google's Cloud Code endpoint, called with each account's own access token.
272
+
273
+ ## Data locations
274
+
275
+ | Platform | Folder |
276
+ |---|---|
277
+ | Linux | `${XDG_DATA_HOME:-~/.local/share}/antigravity-swap/` |
278
+ | macOS | `~/Library/Application Support/antigravity-swap/` |
279
+ | Windows | `%LOCALAPPDATA%\antigravity-swap\` |
280
+
281
+ Override with `ASWAP_HOME`. Inside: `accounts.json`, `credentials/<n>.json` (0600, folder 0700), `usage/`, `sessions/<n>/` (agy directories for `run` and `exec`), `settings.json`. `ASWAP_GEMINI_DIR` overrides agy's default `~/.gemini`.
282
+
283
+ The stored logins and `aswap export` files are live credentials in plaintext. Treat them like SSH keys.
284
+
285
+ ## Uninstall
286
+
287
+ ```bash
288
+ aswap purge
289
+ uv tool uninstall antigravity-swap # or: pipx uninstall antigravity-swap
290
+ ```
291
+
292
+ ## Requirements
293
+
294
+ - The Antigravity CLI (`agy`), signed in
295
+ - Python 3.12+ (not needed for the standalone binary)
296
+
297
+ ## License
298
+
299
+ MIT