paper-agy-switch 0.1.0 → 0.1.1

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.
package/LICENSE CHANGED
@@ -1,201 +1,201 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,129 +1,140 @@
1
- # paper-agy-switch
2
-
3
- **Multi-account switcher for Google Antigravity, with a quota dashboard for the agy CLI and Antigravity desktop app.**
4
-
5
- [Tiếng Việt](README.vi.md)
6
-
7
- Save several Google logins, see each account's plan and quota, and switch with one command. The `agy` CLI and Antigravity 2.x desktop app share one login in Windows Credential Manager (`gemini:antigravity`); this tool saves several logins and swaps that entry.
8
-
9
- ## Features
10
-
11
- - Save accounts, add more through Google sign-in in the browser, rename them, and recover deleted profiles.
12
- - Numbered, aligned `list` table and interactive `tui` dashboard with the plan, used percentages and relative reset times.
13
- - Separate Claude/GPT 5-hour and weekly quotas and Gemini 5-hour and weekly quotas, from Google Cloud Code's `retrieveUserQuotaSummary`.
14
- - Switch by alias, by number, or to the best account in the selected scoring pool; launch `agy` or use `auto` for automatic switching.
15
-
16
- ## Requirements
17
-
18
- Windows only for now. macOS Keychain and Linux secret-service are not supported yet. Install `agy` to sign in and launch Antigravity.
19
-
20
- ## Install
21
-
22
- ```sh
23
- npm i -g paper-agy-switch
24
- ```
25
-
26
- The npm package downloads a prebuilt binary from [GitHub Releases](https://github.com/Cazorlas/Paper_agy_switcher/releases).
27
-
28
- Or build from source:
29
-
30
- ```sh
31
- cargo install --git https://github.com/Cazorlas/Paper_agy_switcher
32
- ```
33
-
34
- Data lives in `~/.paper-agy-switch`; set `PAPER_AGY_SWITCH_HOME` to override this folder.
35
-
36
- ## Setup (first time)
37
-
38
- 1. Start `agy`, run `/login` inside it, and sign in with your first Google account.
39
- 2. Save that login:
40
- ```sh
41
- paper-agy-switch login main
42
- ```
43
- 3. Add another account:
44
- ```sh
45
- paper-agy-switch add work
46
- ```
47
- Sign in with Google in the browser. The login is saved straight to the profile: nothing to close and no `/logout` needed.
48
- 4. Check your accounts with `paper-agy-switch list`.
49
-
50
- **Do not use `/logout` in agy for an account you saved:** it may revoke that saved login. To renew an expired login, run `/login` inside agy, then `paper-agy-switch login <alias>` again.
51
-
52
- ## Everyday use
53
-
54
- ```sh
55
- paper-agy-switch list # numbered quota table
56
- paper-agy-switch use main # switch by alias
57
- paper-agy-switch use 2 # switch by number in list
58
- paper-agy-switch use # best account in the scoring pool
59
- paper-agy-switch launch work -- --continue # switch, then start agy with these arguments
60
- paper-agy-switch tui # interactive dashboard and Settings
61
- paper-agy-switch auto # automatic switching
62
- paper-agy-switch doctor # check setup and current login
63
- ```
64
-
65
- Numbers follow alias order in `list`, matching `use <n>`. A literal numeric alias takes priority over a row number. `*` marks the active profile; reset cells such as `↻2h13m` and `↻5d4h` show time remaining, and `--` means absent data. Fetch errors appear in Status.
66
-
67
- ### Running sessions and credential overwrites
68
-
69
- Measured limitation: an already running `agy` process keeps the account it started with. This includes an agy terminal, the Antigravity hub started by VS Code, and the desktop app. When that process refreshes its token (about hourly), it writes its account back into Credential Manager, undoing the switch. New agy processes use the switched account immediately.
70
-
71
- `use` lists running agy processes. To stop them when switching:
72
-
73
- ```sh
74
- paper-agy-switch use main --restart-agy
75
- ```
76
-
77
- `auto` reports when the credential was overwritten.
78
-
79
- ### Scoring pool
80
-
81
- Choose the pool used to select the best account in `~/.paper-agy-switch/config.toml`, or in TUI Settings:
82
-
83
- ```toml
84
- [use]
85
- pool = "claude" # default: Claude/GPT group; use "gemini" for Gemini
86
- ```
87
-
88
- ### Quota limitations
89
-
90
- Observed once (2026-10-21, one account): agy refused Gemini 3.8 Flash with **"Individual quota reached ... Resets in 61h"** while both `retrieveUserQuotaSummary` and the per-model `fetchAvailableModels` reported that model at 100% remaining, and Claude models on the same account still worked. Google enforces limits these endpoints do not report, so the dashboard can show room that a model does not have. Try another model (`agy --model ...`) or another account.
91
-
92
- ## Manage accounts
93
-
94
- | Task | Command |
95
- |---|---|
96
- | Save the current agy login | `paper-agy-switch login [alias]` |
97
- | Add through browser sign-in | `paper-agy-switch add <alias>` |
98
- | Refresh quota without the cache | `paper-agy-switch list --force` |
99
- | Rename | `paper-agy-switch rename <old> <new>` |
100
- | Delete, with recovery available | `paper-agy-switch delete <alias-or-number> [--yes]` |
101
- | List deleted profiles | `paper-agy-switch restore` |
102
- | Restore a profile | `paper-agy-switch restore <alias> [--as <new>]` |
103
-
104
- ## Update / uninstall
105
-
106
- ```sh
107
- paper-agy-switch self-update --check
108
- paper-agy-switch self-update
109
- ```
110
-
111
- For a source installation, rerun the `cargo install --git` command above.
112
-
113
- The **npm launcher** provides `uninstall`; it is not a command in the binary's `--help`:
114
-
115
- ```sh
116
- paper-agy-switch uninstall # asks whether to delete saved data in an interactive terminal
117
- paper-agy-switch uninstall --keep-data # keep accounts and settings
118
- paper-agy-switch uninstall --purge # delete accounts and settings
119
- ```
120
-
121
- ## How it works
122
-
123
- The tool saves logins in profiles under its data folder. Switching replaces the shared Windows Credential Manager entry `gemini:antigravity`, which new agy and Antigravity desktop processes read.
124
-
125
- ## Credits and license
126
-
127
- Inspired by [Cockpit Tools](https://github.com/jlcodes99/cockpit-tools) for Antigravity protocol research (behaviour only; no code copied). Forked from [Paper.Claude-switcher](https://github.com/Cazorlas/Paper.Claude-switcher).
128
-
129
- Apache-2.0 — see [LICENSE](LICENSE).
1
+ # paper-agy-switch
2
+
3
+ **Multi-account switcher for Google Antigravity, with a quota dashboard for the agy CLI and Antigravity desktop app.**
4
+
5
+ [Tiếng Việt](README.vi.md)
6
+
7
+ Save several Google logins, see each account's plan and quota, and switch with one command. The `agy` CLI and Antigravity 2.x desktop app share one login in Windows Credential Manager (`gemini:antigravity`); this tool saves several logins and swaps that entry.
8
+
9
+ ## Features
10
+
11
+ - Save accounts, add more through Google sign-in in the browser, rename them, and recover deleted profiles.
12
+ - Numbered, aligned `list` table and interactive `tui` dashboard with the plan, used percentages and relative reset times.
13
+ - Separate Claude/GPT 5-hour and weekly quotas and Gemini 5-hour and weekly quotas, from Google Cloud Code's `retrieveUserQuotaSummary`.
14
+ - Switch by alias, by number, or to the best account in the selected scoring pool; launch `agy` or use `auto` for automatic switching.
15
+
16
+ ## Requirements
17
+
18
+ Windows only for now. macOS Keychain and Linux secret-service are not supported yet. Install `agy` to sign in and launch Antigravity.
19
+
20
+ ## Install
21
+
22
+ ```sh
23
+ npm i -g paper-agy-switch
24
+ ```
25
+
26
+ The npm package downloads a prebuilt binary from [GitHub Releases](https://github.com/Cazorlas/Paper_agy_switcher/releases).
27
+
28
+ Or build from source:
29
+
30
+ ```sh
31
+ cargo install --git https://github.com/Cazorlas/Paper_agy_switcher
32
+ ```
33
+
34
+ Data lives in `~/.paper-agy-switch`; set `PAPER_AGY_SWITCH_HOME` to override this folder.
35
+
36
+ ## Setup (first time)
37
+
38
+ 1. Start `agy`, run `/login` inside it, and sign in with your first Google account.
39
+ 2. Save that login:
40
+ ```sh
41
+ paper-agy-switch login main
42
+ ```
43
+ 3. Add another account:
44
+ ```sh
45
+ paper-agy-switch add work
46
+ ```
47
+ Sign in with Google in the browser. The login is saved straight to the profile: nothing to close and no `/logout` needed.
48
+ 4. Check your accounts with `paper-agy-switch list`.
49
+
50
+ **Do not use `/logout` in agy for an account you saved:** it may revoke that saved login. To renew an expired login, run `/login` inside agy, then `paper-agy-switch login <alias>` again.
51
+
52
+ ## Everyday use
53
+
54
+ ```sh
55
+ paper-agy-switch list # numbered quota table
56
+ paper-agy-switch use main # switch by alias
57
+ paper-agy-switch use 2 # switch by number in list
58
+ paper-agy-switch use # best account in the scoring pool
59
+ paper-agy-switch launch work -- --continue # switch, then start agy with these arguments
60
+ paper-agy-switch tui # interactive dashboard and Settings
61
+ paper-agy-switch auto # automatic switching
62
+ paper-agy-switch doctor # check setup and current login
63
+ ```
64
+
65
+ Numbers follow alias order in `list`, matching `use <n>`. A literal numeric alias takes priority over a row number. `*` marks the active profile; reset cells such as `↻2h13m` and `↻5d4h` show time remaining, and `--` means absent data. Fetch errors appear in Status.
66
+
67
+ ### Running sessions and credential overwrites
68
+
69
+ Measured limitation: an already running `agy` process keeps the account it started with. This includes an agy terminal, the Antigravity hub started by VS Code, and the desktop app. When that process refreshes its token (about hourly), it writes its account back into Credential Manager, undoing the switch. New agy processes use the switched account immediately.
70
+
71
+ `use` lists running agy processes. To stop them when switching:
72
+
73
+ ```sh
74
+ paper-agy-switch use main --restart-agy
75
+ ```
76
+
77
+ `auto` reports when the credential was overwritten.
78
+
79
+ ### Scoring pool
80
+
81
+ Choose the pool used to select the best account in `~/.paper-agy-switch/config.toml`, or in TUI Settings:
82
+
83
+ ```toml
84
+ [use]
85
+ pool = "claude" # default: Claude/GPT group; use "gemini" for Gemini
86
+ ```
87
+
88
+ ### Quota source
89
+
90
+ Google keeps separate Gemini quotas for the `agy` CLI and for the Antigravity IDE/desktop app, and the two show different numbers. By default the tool shows the **agy CLI** quota, the one `agy -p /usage` prints. Switch to the IDE quota in `~/.paper-agy-switch/config.toml`, or in TUI Settings:
91
+
92
+ ```toml
93
+ [quota]
94
+ source = "cli" # default: agy CLI quota; use "ide" for the Antigravity IDE quota
95
+ ```
96
+
97
+ `list` and the TUI title say which quota is shown (`quota: agy CLI` or `quota: Antigravity IDE`), `list --json` adds `quota_source` to every row, and `doctor` prints the setting. Protocol notes are in [docs/agy-protocol.md](docs/agy-protocol.md).
98
+
99
+ ### Quota limitations
100
+
101
+ Observed once (2026-10-21, one account): agy refused Gemini 3.8 Flash with **"Individual quota reached ... Resets in 61h"** while both `retrieveUserQuotaSummary` and the per-model `fetchAvailableModels` reported that model at 100% remaining, and Claude models on the same account still worked. Google enforces limits these endpoints do not report, so the dashboard can show room that a model does not have. Try another model (`agy --model ...`) or another account.
102
+
103
+ ## Manage accounts
104
+
105
+ | Task | Command |
106
+ |---|---|
107
+ | Save the current agy login | `paper-agy-switch login [alias]` |
108
+ | Add through browser sign-in | `paper-agy-switch add <alias>` |
109
+ | Refresh quota without the cache | `paper-agy-switch list --force` |
110
+ | Rename | `paper-agy-switch rename <old> <new>` |
111
+ | Delete, with recovery available | `paper-agy-switch delete <alias-or-number> [--yes]` |
112
+ | List deleted profiles | `paper-agy-switch restore` |
113
+ | Restore a profile | `paper-agy-switch restore <alias> [--as <new>]` |
114
+
115
+ ## Update / uninstall
116
+
117
+ ```sh
118
+ paper-agy-switch self-update --check
119
+ paper-agy-switch self-update
120
+ ```
121
+
122
+ For a source installation, rerun the `cargo install --git` command above.
123
+
124
+ The **npm launcher** provides `uninstall`; it is not a command in the binary's `--help`:
125
+
126
+ ```sh
127
+ paper-agy-switch uninstall # asks whether to delete saved data in an interactive terminal
128
+ paper-agy-switch uninstall --keep-data # keep accounts and settings
129
+ paper-agy-switch uninstall --purge # delete accounts and settings
130
+ ```
131
+
132
+ ## How it works
133
+
134
+ The tool saves logins in profiles under its data folder. Switching replaces the shared Windows Credential Manager entry `gemini:antigravity`, which new agy and Antigravity desktop processes read.
135
+
136
+ ## Credits and license
137
+
138
+ Inspired by [Cockpit Tools](https://github.com/jlcodes99/cockpit-tools) for Antigravity protocol research (behaviour only; no code copied). Forked from [Paper.Claude-switcher](https://github.com/Cazorlas/Paper.Claude-switcher).
139
+
140
+ Apache-2.0 — see [LICENSE](LICENSE).
@@ -1,81 +1,81 @@
1
- This project began as a fork of Paper.Claude-switcher (MIT, Copyright (c) 2026 Cazorlas).
2
-
3
- # Third-party notices
4
-
5
- paper-claude-switch includes code adapted from [codex-switch](https://github.com/xjoker/codex-switch), used under the following license:
6
-
7
- ---
8
-
9
- MIT License
10
-
11
- Copyright (c) 2025 xjoker
12
-
13
- Permission is hereby granted, free of charge, to any person obtaining a copy
14
- of this software and associated documentation files (the "Software"), to deal
15
- in the Software without restriction, including without limitation the rights
16
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
- copies of the Software, and to permit persons to whom the Software is
18
- furnished to do so, subject to the following conditions:
19
-
20
- The above copyright notice and this permission notice shall be included in all
21
- copies or substantial portions of the Software.
22
-
23
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
- SOFTWARE.
30
-
31
- ---
32
-
33
- claude-swap - https://github.com/realiti4/claude-swap - MIT License
34
-
35
- MIT License
36
-
37
- Copyright (c) 2026 Onur Cetinkol
38
-
39
- Permission is hereby granted, free of charge, to any person obtaining a copy
40
- of this software and associated documentation files (the "Software"), to deal
41
- in the Software without restriction, including without limitation the rights
42
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43
- copies of the Software, and to permit persons to whom the Software is
44
- furnished to do so, subject to the following conditions:
45
-
46
- The above copyright notice and this permission notice shall be included in all
47
- copies or substantial portions of the Software.
48
-
49
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55
- SOFTWARE.
56
-
57
- ---
58
-
59
- paper-codex-switch - https://github.com/Cazorlas/Paper.Codex-switcher - MIT License
60
-
61
- MIT License
62
-
63
- Copyright (c) 2026 Cazorlas
64
-
65
- Permission is hereby granted, free of charge, to any person obtaining a copy
66
- of this software and associated documentation files (the "Software"), to deal
67
- in the Software without restriction, including without limitation the rights
68
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
69
- copies of the Software, and to permit persons to whom the Software is
70
- furnished to do so, subject to the following conditions:
71
-
72
- The above copyright notice and this permission notice shall be included in all
73
- copies or substantial portions of the Software.
74
-
75
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
76
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
77
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
78
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
79
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
80
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
81
- SOFTWARE.
1
+ This project began as a fork of Paper.Claude-switcher (MIT, Copyright (c) 2026 Cazorlas).
2
+
3
+ # Third-party notices
4
+
5
+ paper-claude-switch includes code adapted from [codex-switch](https://github.com/xjoker/codex-switch), used under the following license:
6
+
7
+ ---
8
+
9
+ MIT License
10
+
11
+ Copyright (c) 2025 xjoker
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.
30
+
31
+ ---
32
+
33
+ claude-swap - https://github.com/realiti4/claude-swap - MIT License
34
+
35
+ MIT License
36
+
37
+ Copyright (c) 2026 Onur Cetinkol
38
+
39
+ Permission is hereby granted, free of charge, to any person obtaining a copy
40
+ of this software and associated documentation files (the "Software"), to deal
41
+ in the Software without restriction, including without limitation the rights
42
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43
+ copies of the Software, and to permit persons to whom the Software is
44
+ furnished to do so, subject to the following conditions:
45
+
46
+ The above copyright notice and this permission notice shall be included in all
47
+ copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55
+ SOFTWARE.
56
+
57
+ ---
58
+
59
+ paper-codex-switch - https://github.com/Cazorlas/Paper.Codex-switcher - MIT License
60
+
61
+ MIT License
62
+
63
+ Copyright (c) 2026 Cazorlas
64
+
65
+ Permission is hereby granted, free of charge, to any person obtaining a copy
66
+ of this software and associated documentation files (the "Software"), to deal
67
+ in the Software without restriction, including without limitation the rights
68
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
69
+ copies of the Software, and to permit persons to whom the Software is
70
+ furnished to do so, subject to the following conditions:
71
+
72
+ The above copyright notice and this permission notice shall be included in all
73
+ copies or substantial portions of the Software.
74
+
75
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
76
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
77
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
78
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
79
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
80
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
81
+ SOFTWARE.
package/bin/cli.js CHANGED
@@ -1,112 +1,112 @@
1
- #!/usr/bin/env node
2
- const fs = require("fs");
3
- const os = require("os");
4
- const path = require("path");
5
- const { spawnSync, spawn } = require("child_process");
6
-
7
- const isWin = process.platform === "win32";
8
- const exe = path.join(__dirname, isWin ? "paper-agy-switch.exe" : "paper-agy-switch");
9
- const current = require("../package.json").version;
10
- const args = process.argv.slice(2);
11
-
12
- function newer(a, b) {
13
- const pa = a.split(".").map(Number), pb = b.split(".").map(Number);
14
- for (let i = 0; i < 3; i++) if ((pa[i] || 0) !== (pb[i] || 0)) return (pa[i] || 0) > (pb[i] || 0);
15
- return false;
16
- }
17
-
18
- function latestVersion() {
19
- const r = spawnSync("npm", ["view", "paper-agy-switch", "version"], { encoding: "utf8", shell: isWin });
20
- return r.status === 0 ? r.stdout.trim() : null;
21
- }
22
-
23
- // `self-update [--check]`: handled here because a running binary cannot be replaced
24
- // (Windows locks it), and a background `auto` keeps it running.
25
- if (args[0] === "self-update") {
26
- const latest = latestVersion();
27
- if (!latest) {
28
- console.error("paper-agy-switch: cannot reach the npm registry (is npm on PATH?)");
29
- process.exit(1);
30
- }
31
- if (!newer(latest, current)) {
32
- console.log(`paper-agy-switch ${current} is up to date`);
33
- process.exit(0);
34
- }
35
- console.log(`paper-agy-switch ${current} -> ${latest}`);
36
- if (args.includes("--check")) process.exit(0);
37
-
38
- const running = isWin
39
- ? spawnSync("tasklist", ["/FI", "IMAGENAME eq paper-agy-switch.exe", "/NH"], { encoding: "utf8" }).stdout.includes("paper-agy-switch.exe")
40
- : spawnSync("pgrep", ["-x", "paper-agy-switch"]).status === 0;
41
- if (running) {
42
- console.log("stopping the background auto so the binary can be replaced...");
43
- if (isWin) spawnSync("taskkill", ["/IM", "paper-agy-switch.exe", "/F"], { stdio: "ignore" });
44
- else spawnSync("pkill", ["-x", "paper-agy-switch"]);
45
- }
46
- const r = spawnSync("npm", ["i", "-g", "paper-agy-switch@latest"], { stdio: "inherit", shell: isWin });
47
- if (r.status !== 0) process.exit(r.status || 1);
48
- if (running) console.log("start `paper-agy-switch auto` again to resume automatic switching");
49
- process.exit(0);
50
- }
51
-
52
- // `uninstall [--purge | --keep-data]`: handled here so it works even when the binary is
53
- // missing or blocked, and because a running binary cannot delete itself.
54
- if (args[0] === "uninstall") {
55
- const dataDir = process.env.PAPER_AGY_SWITCH_HOME || path.join(os.homedir(), ".paper-agy-switch");
56
- const finish = (wipe) => {
57
- if (isWin) spawnSync("taskkill", ["/IM", "paper-agy-switch.exe", "/F"], { stdio: "ignore" });
58
- else spawnSync("pkill", ["-x", "paper-agy-switch"]);
59
- if (isWin) {
60
- const vbs = path.join(process.env.APPDATA || "", "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "paper-agy-switch-auto.vbs");
61
- try { fs.rmSync(vbs, { force: true }); } catch {}
62
- }
63
- if (wipe) {
64
- try { fs.rmSync(dataDir, { recursive: true, force: true }); console.log(`deleted ${dataDir}`); }
65
- catch (e) { console.error(`could not delete ${dataDir}: ${e.message}`); }
66
- } else {
67
- console.log(`kept your accounts and settings in ${dataDir}`);
68
- }
69
- const r = spawnSync("npm", ["rm", "-g", "paper-agy-switch"], { stdio: "inherit", shell: isWin });
70
- console.log(r.status === 0 ? "paper-agy-switch uninstalled" : "npm could not remove the package; run: npm rm -g paper-agy-switch");
71
- process.exit(r.status || 0);
72
- };
73
- if (args.includes("--purge")) finish(true);
74
- else if (args.includes("--keep-data") || !process.stdin.isTTY) finish(false);
75
- else {
76
- const rl = require("readline").createInterface({ input: process.stdin, output: process.stdout });
77
- rl.question(`Also delete your saved accounts and settings (${dataDir})? [y/N] `, (a) => {
78
- rl.close();
79
- finish(/^y(es)?$/i.test(a.trim()));
80
- });
81
- }
82
- } else {
83
- // npm may skip the postinstall script (allow-scripts); fetch the binary on first run instead.
84
- if (!fs.existsSync(exe)) {
85
- const r = spawnSync(process.execPath, [path.join(__dirname, "..", "install.js")], { stdio: "inherit" });
86
- if (r.status !== 0 || !fs.existsSync(exe)) {
87
- console.error("paper-agy-switch: could not download the binary; see https://github.com/Cazorlas/Paper_agy_switcher/releases");
88
- process.exit(1);
89
- }
90
- }
91
-
92
- // Once a day, look for a newer version in the background and print a hint; never installs by itself.
93
- try {
94
- const cache = path.join(os.tmpdir(), "paper-agy-switch-update.json");
95
- let info = {};
96
- try { info = JSON.parse(fs.readFileSync(cache, "utf8")); } catch {}
97
- if (!info.at || Date.now() - info.at > 24 * 3600 * 1000) {
98
- const code = `const {execFileSync}=require("child_process");try{const v=execFileSync("npm",["view","paper-agy-switch","version"],{encoding:"utf8",shell:process.platform==="win32"}).trim();require("fs").writeFileSync(${JSON.stringify(cache)},JSON.stringify({at:Date.now(),latest:v}))}catch{}`;
99
- spawn(process.execPath, ["-e", code], { detached: true, stdio: "ignore" }).unref();
100
- }
101
- if (info.latest && newer(info.latest, current) && process.stderr.isTTY && !args.includes("--json") && !args.includes("--json-pretty") && args[0] !== "auto") {
102
- console.error(`paper-agy-switch ${info.latest} is available (you have ${current}); run: paper-agy-switch self-update`);
103
- }
104
- } catch {}
105
-
106
- const r = spawnSync(exe, args, { stdio: "inherit" });
107
- if (r.error) {
108
- console.error(`paper-agy-switch: cannot run ${exe}: ${r.error.message}`);
109
- process.exit(1);
110
- }
111
- process.exit(r.status ?? 1);
112
- }
1
+ #!/usr/bin/env node
2
+ const fs = require("fs");
3
+ const os = require("os");
4
+ const path = require("path");
5
+ const { spawnSync, spawn } = require("child_process");
6
+
7
+ const isWin = process.platform === "win32";
8
+ const exe = path.join(__dirname, isWin ? "paper-agy-switch.exe" : "paper-agy-switch");
9
+ const current = require("../package.json").version;
10
+ const args = process.argv.slice(2);
11
+
12
+ function newer(a, b) {
13
+ const pa = a.split(".").map(Number), pb = b.split(".").map(Number);
14
+ for (let i = 0; i < 3; i++) if ((pa[i] || 0) !== (pb[i] || 0)) return (pa[i] || 0) > (pb[i] || 0);
15
+ return false;
16
+ }
17
+
18
+ function latestVersion() {
19
+ const r = spawnSync("npm", ["view", "paper-agy-switch", "version"], { encoding: "utf8", shell: isWin });
20
+ return r.status === 0 ? r.stdout.trim() : null;
21
+ }
22
+
23
+ // `self-update [--check]`: handled here because a running binary cannot be replaced
24
+ // (Windows locks it), and a background `auto` keeps it running.
25
+ if (args[0] === "self-update") {
26
+ const latest = latestVersion();
27
+ if (!latest) {
28
+ console.error("paper-agy-switch: cannot reach the npm registry (is npm on PATH?)");
29
+ process.exit(1);
30
+ }
31
+ if (!newer(latest, current)) {
32
+ console.log(`paper-agy-switch ${current} is up to date`);
33
+ process.exit(0);
34
+ }
35
+ console.log(`paper-agy-switch ${current} -> ${latest}`);
36
+ if (args.includes("--check")) process.exit(0);
37
+
38
+ const running = isWin
39
+ ? spawnSync("tasklist", ["/FI", "IMAGENAME eq paper-agy-switch.exe", "/NH"], { encoding: "utf8" }).stdout.includes("paper-agy-switch.exe")
40
+ : spawnSync("pgrep", ["-x", "paper-agy-switch"]).status === 0;
41
+ if (running) {
42
+ console.log("stopping the background auto so the binary can be replaced...");
43
+ if (isWin) spawnSync("taskkill", ["/IM", "paper-agy-switch.exe", "/F"], { stdio: "ignore" });
44
+ else spawnSync("pkill", ["-x", "paper-agy-switch"]);
45
+ }
46
+ const r = spawnSync("npm", ["i", "-g", "paper-agy-switch@latest"], { stdio: "inherit", shell: isWin });
47
+ if (r.status !== 0) process.exit(r.status || 1);
48
+ if (running) console.log("start `paper-agy-switch auto` again to resume automatic switching");
49
+ process.exit(0);
50
+ }
51
+
52
+ // `uninstall [--purge | --keep-data]`: handled here so it works even when the binary is
53
+ // missing or blocked, and because a running binary cannot delete itself.
54
+ if (args[0] === "uninstall") {
55
+ const dataDir = process.env.PAPER_AGY_SWITCH_HOME || path.join(os.homedir(), ".paper-agy-switch");
56
+ const finish = (wipe) => {
57
+ if (isWin) spawnSync("taskkill", ["/IM", "paper-agy-switch.exe", "/F"], { stdio: "ignore" });
58
+ else spawnSync("pkill", ["-x", "paper-agy-switch"]);
59
+ if (isWin) {
60
+ const vbs = path.join(process.env.APPDATA || "", "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "paper-agy-switch-auto.vbs");
61
+ try { fs.rmSync(vbs, { force: true }); } catch {}
62
+ }
63
+ if (wipe) {
64
+ try { fs.rmSync(dataDir, { recursive: true, force: true }); console.log(`deleted ${dataDir}`); }
65
+ catch (e) { console.error(`could not delete ${dataDir}: ${e.message}`); }
66
+ } else {
67
+ console.log(`kept your accounts and settings in ${dataDir}`);
68
+ }
69
+ const r = spawnSync("npm", ["rm", "-g", "paper-agy-switch"], { stdio: "inherit", shell: isWin });
70
+ console.log(r.status === 0 ? "paper-agy-switch uninstalled" : "npm could not remove the package; run: npm rm -g paper-agy-switch");
71
+ process.exit(r.status || 0);
72
+ };
73
+ if (args.includes("--purge")) finish(true);
74
+ else if (args.includes("--keep-data") || !process.stdin.isTTY) finish(false);
75
+ else {
76
+ const rl = require("readline").createInterface({ input: process.stdin, output: process.stdout });
77
+ rl.question(`Also delete your saved accounts and settings (${dataDir})? [y/N] `, (a) => {
78
+ rl.close();
79
+ finish(/^y(es)?$/i.test(a.trim()));
80
+ });
81
+ }
82
+ } else {
83
+ // npm may skip the postinstall script (allow-scripts); fetch the binary on first run instead.
84
+ if (!fs.existsSync(exe)) {
85
+ const r = spawnSync(process.execPath, [path.join(__dirname, "..", "install.js")], { stdio: "inherit" });
86
+ if (r.status !== 0 || !fs.existsSync(exe)) {
87
+ console.error("paper-agy-switch: could not download the binary; see https://github.com/Cazorlas/Paper_agy_switcher/releases");
88
+ process.exit(1);
89
+ }
90
+ }
91
+
92
+ // Once a day, look for a newer version in the background and print a hint; never installs by itself.
93
+ try {
94
+ const cache = path.join(os.tmpdir(), "paper-agy-switch-update.json");
95
+ let info = {};
96
+ try { info = JSON.parse(fs.readFileSync(cache, "utf8")); } catch {}
97
+ if (!info.at || Date.now() - info.at > 24 * 3600 * 1000) {
98
+ const code = `const {execFileSync}=require("child_process");try{const v=execFileSync("npm",["view","paper-agy-switch","version"],{encoding:"utf8",shell:process.platform==="win32"}).trim();require("fs").writeFileSync(${JSON.stringify(cache)},JSON.stringify({at:Date.now(),latest:v}))}catch{}`;
99
+ spawn(process.execPath, ["-e", code], { detached: true, stdio: "ignore" }).unref();
100
+ }
101
+ if (info.latest && newer(info.latest, current) && process.stderr.isTTY && !args.includes("--json") && !args.includes("--json-pretty") && args[0] !== "auto") {
102
+ console.error(`paper-agy-switch ${info.latest} is available (you have ${current}); run: paper-agy-switch self-update`);
103
+ }
104
+ } catch {}
105
+
106
+ const r = spawnSync(exe, args, { stdio: "inherit" });
107
+ if (r.error) {
108
+ console.error(`paper-agy-switch: cannot run ${exe}: ${r.error.message}`);
109
+ process.exit(1);
110
+ }
111
+ process.exit(r.status ?? 1);
112
+ }
package/install.js CHANGED
@@ -1,40 +1,40 @@
1
- // Downloads the prebuilt binary for this platform from the GitHub release
2
- // that matches this package's version.
3
- const fs = require("fs");
4
- const path = require("path");
5
- const https = require("https");
6
- const { version } = require("./package.json");
7
-
8
- const targets = {
9
- "win32-x64": "paper-agy-switch-windows-x64.exe",
10
- "darwin-x64": "paper-agy-switch-macos-x64",
11
- "darwin-arm64": "paper-agy-switch-macos-arm64",
12
- "linux-x64": "paper-agy-switch-linux-x64",
13
- };
14
- const key = `${process.platform}-${process.arch}`;
15
- const asset = targets[key];
16
- if (!asset) {
17
- console.error(`paper-agy-switch: no prebuilt binary for ${key}; build from source with cargo.`);
18
- process.exit(1);
19
- }
20
- const url = `https://github.com/Cazorlas/Paper_agy_switcher/releases/download/v${version}/${asset}`;
21
- const dest = path.join(__dirname, "bin", process.platform === "win32" ? "paper-agy-switch.exe" : "paper-agy-switch");
22
-
23
- function get(u, redirects = 5) {
24
- https.get(u, { headers: { "User-Agent": "paper-agy-switch-installer" } }, (res) => {
25
- if ([301, 302, 303, 307, 308].includes(res.statusCode) && res.headers.location && redirects > 0) {
26
- res.resume();
27
- return get(res.headers.location, redirects - 1);
28
- }
29
- if (res.statusCode !== 200) {
30
- console.error(`paper-agy-switch: download failed (${res.statusCode}) ${u}`);
31
- process.exit(1);
32
- }
33
- const tmp = dest + ".part";
34
- const out = fs.createWriteStream(tmp, { mode: 0o755 });
35
- res.pipe(out);
36
- out.on("finish", () => out.close(() => { fs.renameSync(tmp, dest); fs.chmodSync(dest, 0o755); }));
37
- out.on("error", (e) => { console.error(e.message); process.exit(1); });
38
- }).on("error", (e) => { console.error(e.message); process.exit(1); });
39
- }
40
- get(url);
1
+ // Downloads the prebuilt binary for this platform from the GitHub release
2
+ // that matches this package's version.
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const https = require("https");
6
+ const { version } = require("./package.json");
7
+
8
+ const targets = {
9
+ "win32-x64": "paper-agy-switch-windows-x64.exe",
10
+ "darwin-x64": "paper-agy-switch-macos-x64",
11
+ "darwin-arm64": "paper-agy-switch-macos-arm64",
12
+ "linux-x64": "paper-agy-switch-linux-x64",
13
+ };
14
+ const key = `${process.platform}-${process.arch}`;
15
+ const asset = targets[key];
16
+ if (!asset) {
17
+ console.error(`paper-agy-switch: no prebuilt binary for ${key}; build from source with cargo.`);
18
+ process.exit(1);
19
+ }
20
+ const url = `https://github.com/Cazorlas/Paper_agy_switcher/releases/download/v${version}/${asset}`;
21
+ const dest = path.join(__dirname, "bin", process.platform === "win32" ? "paper-agy-switch.exe" : "paper-agy-switch");
22
+
23
+ function get(u, redirects = 5) {
24
+ https.get(u, { headers: { "User-Agent": "paper-agy-switch-installer" } }, (res) => {
25
+ if ([301, 302, 303, 307, 308].includes(res.statusCode) && res.headers.location && redirects > 0) {
26
+ res.resume();
27
+ return get(res.headers.location, redirects - 1);
28
+ }
29
+ if (res.statusCode !== 200) {
30
+ console.error(`paper-agy-switch: download failed (${res.statusCode}) ${u}`);
31
+ process.exit(1);
32
+ }
33
+ const tmp = dest + ".part";
34
+ const out = fs.createWriteStream(tmp, { mode: 0o755 });
35
+ res.pipe(out);
36
+ out.on("finish", () => out.close(() => { fs.renameSync(tmp, dest); fs.chmodSync(dest, 0o755); }));
37
+ out.on("error", (e) => { console.error(e.message); process.exit(1); });
38
+ }).on("error", (e) => { console.error(e.message); process.exit(1); });
39
+ }
40
+ get(url);
package/package.json CHANGED
@@ -1,13 +1,38 @@
1
- {
2
- "name": "paper-agy-switch",
3
- "version": "0.1.0",
4
- "description": "Multi-account switcher for Google Antigravity, with a quota dashboard for the agy CLI and Antigravity desktop app.",
5
- "license": "Apache-2.0",
6
- "repository": "github:Cazorlas/Paper_agy_switcher",
7
- "bin": { "paper-agy-switch": "bin/cli.js" },
8
- "scripts": { "postinstall": "node install.js" },
9
- "files": ["bin/cli.js", "install.js", "README.md", "LICENSE", "THIRD_PARTY_NOTICES.md"],
10
- "engines": { "node": ">=18" },
11
- "os": ["win32", "darwin", "linux"],
12
- "keywords": ["antigravity", "agy", "gemini", "account", "switcher"]
13
- }
1
+ {
2
+ "name": "paper-agy-switch",
3
+ "version": "0.1.1",
4
+ "description": "Multi-account switcher for Google Antigravity, with a quota dashboard for the agy CLI and Antigravity desktop app.",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/Cazorlas/Paper_agy_switcher.git"
9
+ },
10
+ "bin": {
11
+ "paper-agy-switch": "bin/cli.js"
12
+ },
13
+ "scripts": {
14
+ "postinstall": "node install.js"
15
+ },
16
+ "files": [
17
+ "bin/cli.js",
18
+ "install.js",
19
+ "README.md",
20
+ "LICENSE",
21
+ "THIRD_PARTY_NOTICES.md"
22
+ ],
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "os": [
27
+ "win32",
28
+ "darwin",
29
+ "linux"
30
+ ],
31
+ "keywords": [
32
+ "antigravity",
33
+ "agy",
34
+ "gemini",
35
+ "account",
36
+ "switcher"
37
+ ]
38
+ }