@modelprofile.com/authswitch 9.1.0 → 10.0.0

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.
Files changed (75) hide show
  1. package/dist_ts/00_commitinfo_data.js +2 -2
  2. package/dist_ts/authority-contract.d.ts +56 -6
  3. package/dist_ts/authority-contract.js +1 -1
  4. package/dist_ts/authority-runtime-contract.d.ts +29 -0
  5. package/dist_ts/classes.authoritybroker.d.ts +36 -4
  6. package/dist_ts/classes.authoritybroker.js +71 -12
  7. package/dist_ts/classes.authoritycli.d.ts +4 -1
  8. package/dist_ts/classes.authoritycli.js +42 -7
  9. package/dist_ts/classes.authorityclient.d.ts +15 -2
  10. package/dist_ts/classes.authorityclient.js +31 -8
  11. package/dist_ts/classes.authoritydaemon.d.ts +17 -0
  12. package/dist_ts/classes.authoritydaemon.js +50 -14
  13. package/dist_ts/classes.authoritydatabase.d.ts +14 -3
  14. package/dist_ts/classes.authoritydatabase.js +25 -10
  15. package/dist_ts/classes.authorityimport.d.ts +4 -4
  16. package/dist_ts/classes.authorityimport.js +8 -7
  17. package/dist_ts/classes.authoritymodels.d.ts +11 -3
  18. package/dist_ts/classes.authoritymodels.js +43 -13
  19. package/dist_ts/classes.authoritypreuse.d.ts +8 -2
  20. package/dist_ts/classes.authoritypreuse.js +27 -17
  21. package/dist_ts/classes.authorityusage.d.ts +4 -3
  22. package/dist_ts/classes.authorityusage.js +3 -5
  23. package/dist_ts/classes.cli.js +3 -5
  24. package/dist_ts/classes.codexpreuse.d.ts +14 -3
  25. package/dist_ts/classes.codexpreuse.js +127 -44
  26. package/dist_ts/classes.codexstatus.js +44 -95
  27. package/dist_ts/classes.login.d.ts +20 -10
  28. package/dist_ts/classes.login.js +14 -13
  29. package/dist_ts/classes.openaiprovider.d.ts +53 -0
  30. package/dist_ts/classes.openaiprovider.js +340 -0
  31. package/dist_ts/classes.opencodeharness.js +3 -2
  32. package/dist_ts/classes.service.js +3 -5
  33. package/dist_ts/index.d.ts +2 -0
  34. package/dist_ts/index.js +3 -1
  35. package/dist_ts/interfaces.openai.d.ts +118 -0
  36. package/dist_ts/interfaces.openai.js +3 -0
  37. package/dist_ts/openaiauth.d.ts +76 -0
  38. package/dist_ts/openaiauth.js +371 -0
  39. package/dist_ts/openaiusage.d.ts +59 -0
  40. package/dist_ts/openaiusage.js +222 -0
  41. package/dist_ts/plugins.d.ts +1 -3
  42. package/dist_ts/plugins.js +2 -4
  43. package/dist_ts/preuse.d.ts +50 -0
  44. package/dist_ts/preuse.js +63 -4
  45. package/dist_ts/ts_migration/legacysources/shared.js +4 -3
  46. package/openai-codex-license.txt +201 -0
  47. package/package.json +6 -4
  48. package/readme.md +121 -26
  49. package/third-party-notices.md +29 -0
  50. package/ts/00_commitinfo_data.ts +1 -1
  51. package/ts/authority-contract.ts +60 -8
  52. package/ts/authority-runtime-contract.ts +30 -0
  53. package/ts/classes.authoritybroker.ts +80 -17
  54. package/ts/classes.authoritycli.ts +48 -6
  55. package/ts/classes.authorityclient.ts +32 -9
  56. package/ts/classes.authoritydaemon.ts +54 -14
  57. package/ts/classes.authoritydatabase.ts +28 -11
  58. package/ts/classes.authorityimport.ts +12 -12
  59. package/ts/classes.authoritymodels.ts +42 -14
  60. package/ts/classes.authoritypreuse.ts +30 -17
  61. package/ts/classes.authorityusage.ts +8 -9
  62. package/ts/classes.cli.ts +3 -3
  63. package/ts/classes.codexpreuse.ts +130 -40
  64. package/ts/classes.codexstatus.ts +40 -73
  65. package/ts/classes.login.ts +34 -21
  66. package/ts/classes.openaiprovider.ts +365 -0
  67. package/ts/classes.opencodeharness.ts +3 -2
  68. package/ts/classes.service.ts +3 -4
  69. package/ts/index.ts +2 -0
  70. package/ts/interfaces.openai.ts +142 -0
  71. package/ts/openaiauth.ts +422 -0
  72. package/ts/openaiusage.ts +247 -0
  73. package/ts/plugins.ts +1 -3
  74. package/ts/preuse.ts +88 -3
  75. package/ts/ts_migration/legacysources/shared.ts +4 -3
@@ -0,0 +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 2025 OpenAI
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelprofile.com/authswitch",
3
- "version": "9.1.0",
3
+ "version": "10.0.0",
4
4
  "private": false,
5
5
  "description": "Manage Codex, OpenCode and Claude Code accounts with guided switching and live usage status",
6
6
  "main": "dist_ts/index.js",
@@ -66,8 +66,8 @@
66
66
  "@api.global/typedrequest-interfaces": "7.1.0",
67
67
  "@lossless.org/client": "1.6.0",
68
68
  "@lossless.org/nosqldb": "10.6.0",
69
- "@modelprofile.com/flexharness-models": "^9.0.0",
70
- "@modelprofile.com/flexharness-providers": "^9.0.0",
69
+ "@modelprofile.com/flexharness-models": "^9.3.1",
70
+ "@modelprofile.com/flexharness-providers": "^9.3.1",
71
71
  "@modelprofile.com/mcp-crossharness": "5.6.0",
72
72
  "@push.rocks/smartconsole": "^1.3.0",
73
73
  "@push.rocks/smartdaemon": "2.7.2",
@@ -79,7 +79,9 @@
79
79
  "ts/**/*",
80
80
  "dist_ts/**/*",
81
81
  "cli.js",
82
- "readme.md"
82
+ "readme.md",
83
+ "third-party-notices.md",
84
+ "openai-codex-license.txt"
83
85
  ],
84
86
  "browserslist": [
85
87
  "last 1 chrome versions"
package/readme.md CHANGED
@@ -29,8 +29,8 @@ Node.js 24 or newer is required.
29
29
  The package also exports a typed client for a per-user authswitch authority daemon. Its
30
30
  SmartData registry stores account identity separately from sealed refresh grants, runtime
31
31
  bindings, durable device-operation receipts, Codex enrollment records, and native-handoff and migration journals. A daemon
32
- owns OpenAI device login, targeted reauthentication, and proactive refresh for grants
33
- added through this API. Management snapshots expose separate account and login rows,
32
+ owns OpenAI device login, targeted reauthentication, proactive refresh, and, on request,
33
+ revocation at removal for grants added through this API. Management snapshots expose separate account and login rows,
34
34
  including each login's purpose, owner, health, problem and available actions; neither
35
35
  snapshots nor events contain credentials. A login that a native tool refreshes also names
36
36
  that tool -- `ownerTool` is `claude_code`, `codex` or `opencode`, and `null` exactly when no
@@ -73,12 +73,13 @@ Browser code can import the credential-free DTOs from
73
73
  `@modelprofile.com/authswitch/authority-contract`. The backend-only binding, access and release
74
74
  requests are named by `@modelprofile.com/authswitch/authority-runtime-contract`, and the one-time
75
75
  import's own DTOs by `@modelprofile.com/authswitch/authority-import-contract`; those capabilities must
76
- never reach a browser. Two of the three runtime requests are served on the runtime socket -- resolving
77
- access and releasing a binding -- while `authswitch.authority.bind` is served on the **management** socket
78
- by design: minting a capability is the act that authorizes a runtime, so only a trusted management caller
79
- may perform it, and a container that is given the runtime directory can use a binding it was handed but can
80
- never create one. A backend binds an account to a runtime incarnation by exact account ID, login ID and
81
- purpose, and keeps the returned capability private. Targeted reauthentication likewise requires the
76
+ never reach a browser. Two of the four runtime requests are served on the runtime socket -- resolving
77
+ access and releasing a binding -- while `authswitch.authority.bind` and its inverse
78
+ `authswitch.authority.unbind` are served on the **management** socket by design: minting a capability is the
79
+ act that authorizes a runtime, so only a trusted management caller may perform it, and a container that is
80
+ given the runtime directory can use and release a binding it was handed but can never create one or
81
+ release one it was not handed. A backend binds an account to a runtime incarnation by exact account ID,
82
+ login ID and purpose, and keeps the returned capability private. Targeted reauthentication likewise requires the
82
83
  exact login; an account's presentation default never selects a grant for either action. Completed and
83
84
  interrupted operations remain discoverable through `getOperation()` and paged
84
85
  `listOperations()`. `watchOperation(id, afterRevision, waitMs = 30000)` is the same read as a long poll,
@@ -91,8 +92,14 @@ callers supply one UUID for the logical start and reuse it after a lost response
91
92
  UUID returns the same matching receipt without starting another provider login; using it for a
92
93
  different target is rejected. Cancelling a durable `starting` receipt prevents a late provider
93
94
  handle from promoting or overwriting it. Aborting a client request only detaches that request and
94
- does not cancel the daemon-owned login. The runtime-only socket
95
- resolves that binding to a current access token; its directory can be mounted into a
95
+ does not cancel the daemon-owned login. A client that disconnects before its answer -- a long poll it
96
+ stopped reading, or one the daemon's shutdown settles after the client went away -- ends only its own
97
+ connection: the daemon drops that request's pending work and keeps serving every other client. Each
98
+ request is bounded by its own deadline -- 35 s unless its route states another, 120 s for an import submit,
99
+ the wait plus 5 s for a long poll -- and nothing in the transport ends it sooner: the daemon gives a
100
+ connection 35 s from acceptance to deliver its complete request, however it trickles in, and sets no limit
101
+ once it is admitted.
102
+ The runtime-only socket resolves that binding to a current access token; its directory can be mounted into a
96
103
  container without exposing the management socket. A provider that rejects a specific
97
104
  access-token generation can request a newer one through `rejectedGrantGeneration`; the
98
105
  authority coalesces concurrent rejection callbacks and never replays an uncertain refresh.
@@ -105,20 +112,53 @@ server-side resolution handlers, but handler completion does not prove response
105
112
  cannot retract an access token already received or in use; the runtime owner therefore owns that
106
113
  drain. Generic release cannot revoke a managed Codex binding, whose daemon-owned stop still closes
107
114
  the runtime and clears its durable run before internal revocation. Binding release never transfers
108
- or changes ownership of the account grant. A holder that crashed and lost its capability recovers
109
- its binding without a new route: the snapshot (and `getBinding`) publishes each binding's runtime and
110
- scope, binding that runtime and scope again replaces the capability, and releasing the returned
111
- capability releases the binding. If binding again is refused because the account needs a new sign-in,
112
- reauthenticate it first.
115
+ or changes ownership of the account grant.
116
+
117
+ A holder that lost its capability -- a binding an earlier run of it left behind -- releases it with
118
+ `unbind({ runtime, scopeId, incarnationId, expectedRevision })` (`authswitch.authority.unbind`), naming the
119
+ binding by the identity it bound it under, as the snapshot and `getBinding` publish it. Unbinding needs no
120
+ ready login, so the leftover bindings of an account whose sign-in has ended are released, and the account
121
+ removed, without signing in again. It is authorized exactly as `bind` is: the management socket is the trust
122
+ boundary, and a runtime and scope are the namespace a holder binds under and owns -- AGL, for example, binds
123
+ under its own installation's scopes -- so a holder names only its own. The daemon releases only the binding
124
+ at exactly that runtime and scope, and only while it is still the incarnation and revision the holder read:
125
+ another scope, another runtime, or a successor bound in the meantime is left alone, and the answer is
126
+ `inactive`, as it is for a binding already released. A binding's revision is the authority revision of the
127
+ bind that wrote it, so it never repeats for a runtime and scope, even after a release: a repeated or stale
128
+ unbind never names a successor bound under the same incarnation. Its capability is fenced and released exactly as the
129
+ runtime release would, so admitted access resolutions finish first. Managed Codex bindings are never named
130
+ here. While the login is ready, a holder can instead bind the same runtime and scope again, which replaces
131
+ the capability, and release the returned one.
113
132
 
114
133
  `getBinding(bindingId)` (`authswitch.authority.binding`) reads one binding by the id `bind` returned,
115
134
  credential-free, or `null` once the authority holds none by that id, so a backend checks its binding without
116
135
  reading the whole snapshot.
117
136
 
118
137
  Removing an account that still backs a Flex, OpenCode or Claude binding is refused with `account_busy`, naming
119
- those runtimes: their holder stops them and releases the bindings first, so a removal never strands a
120
- runtime whose next access would fail. Managed Codex bindings are the daemon's own; removal drains managed
121
- Codex as before and then takes them with the account.
138
+ those runtimes: their holder stops them and releases the bindings first -- by capability, or by `unbind` when
139
+ it no longer holds one -- so a removal never strands a runtime whose next access would fail. Managed Codex
140
+ bindings are the daemon's own; removal drains managed Codex as before and then takes them with the account.
141
+
142
+ Removing an account never reaches the network unless the caller asks. `removeAccount(accountId,
143
+ expectedRevision, { revoke: true })` (`revoke: true` on `authswitch.authority.remove`, `--revoke` on the
144
+ command line) also revokes the ChatGPT sign-in the authority held for that account at OpenAI (`/oauth/revoke`,
145
+ the request Codex sends when it logs out). The revocation runs after the removal committed and is best effort,
146
+ like Codex's: the account is removed either way. The revocations get at most 10 seconds in all, so a revoking
147
+ removal answers within the 35 seconds the client allows any request. The answer carries `revoked`: `yes` when
148
+ OpenAI confirmed it, `failed` when it did not, or not within those 10 seconds (the sign-in may still be valid
149
+ there, and the daemon's log says so without the token), `not_applicable` when the authority held no ChatGPT sign-in of its own for the account (a login a
150
+ native tool refreshes is that tool's), and `not_requested` without `revoke`. A daemon older than this client
151
+ refuses `revoke` as an invalid request before changing anything.
152
+
153
+ **A revocation is irreversible, and authswitch cannot tell whether another tool still refreshes from the
154
+ same sign-in.** A token is opaque; the import ledger records of each source only its kind, a hash of its
155
+ location, a digest of its bytes and the account and login it resolved to; and a login does not record
156
+ whether its current sign-in came from an import or from a device sign-in the authority ran itself. The same
157
+ ChatGPT identity turning up both as an imported copy and as a native Codex store proves the same account, not
158
+ the same sign-in, so no check can tell a shared sign-in from two independent ones. Revoking an imported
159
+ login can therefore sign out a native Codex, OpenCode or other home that still runs on that sign-in. Ask for
160
+ `revoke` only for a sign-in made through `account add openai` or `account reauth`, or when every other copy
161
+ of it should stop working too.
122
162
 
123
163
  Every route on either socket answers in one of three ways: a result, a **refusal**, or a fault. A refusal
124
164
  is an answer -- the daemon completed its check, nothing was left half-done, and its message says what the
@@ -199,6 +239,7 @@ The authority CLI uses that daemon surface without constructing the legacy nativ
199
239
  authswitch account list [--json]
200
240
  authswitch account add openai [--json]
201
241
  authswitch account reauth <account-id> <login-id> [--json]
242
+ authswitch account remove <account-id> [--revoke] [--json]
202
243
  authswitch account operation get <operation-id> [--json]
203
244
  authswitch account operation cancel <operation-id> [--json]
204
245
  authswitch account operation resume <operation-id> [--json]
@@ -224,6 +265,12 @@ receipts until completion. `account operation resume` polls only the supplied du
224
265
  response is lost, the fixed diagnostic reports the caller-generated operation ID and exact resume
225
266
  command; the CLI does not replay the start request.
226
267
 
268
+ `account remove` removes one authority account by the id `account list` shows, at the revision it
269
+ reads just before, and prints the removal and what happened to its ChatGPT sign-in; `--json` prints the
270
+ daemon's answer, `{ account, revoked }`. `--revoke` asks for the revocation described under removal above,
271
+ with the same caveat: authswitch cannot tell whether another tool still runs on that sign-in. The command
272
+ exits nonzero when OpenAI did not confirm a requested revocation, although the account is removed.
273
+
227
274
  `account preuse` sends one quota-consuming prompt through the exact managed OpenAI account and
228
275
  login IDs. The default prompt is `Write 2000 words about strawberries.`; `--prompt` replaces it
229
276
  and `--model` requests one exact model. `--all` freezes one consistent authority snapshot, walks
@@ -234,11 +281,15 @@ reported as skipped with the snapshot revision, login revision, stored health, p
234
281
  observation time; no request or operation ID is created for that skip.
235
282
 
236
283
  Preuse operations run sequentially and are never retried automatically. Every terminal receipt
237
- advances an `--all` run, including `not_sent` and `outcome_unknown`, while any attempted operation
284
+ advances an `--all` run, including `not_sent`, `refused` and `outcome_unknown`, while any attempted operation
238
285
  that does not complete makes the final exit status nonzero. Snapshot-ineligible skips alone do not
239
286
  make an otherwise successful batch fail. Running `--all` again is a new quota-consuming run with
240
287
  new operation IDs. Use `account preuse operation resume` to continue observing an existing receipt.
241
- Only the explicit `cancel` command asks the daemon to cancel one.
288
+ Only the explicit `cancel` command asks the daemon to cancel one. A receipt stopped by a limit
289
+ carries it as `limit` (`{ kind, window, resetsAt }`); a sent request that failed for another stated
290
+ reason is `outcome_unknown` with problem `request_uncertain` and carries its cause as `failure`
291
+ (`{ kind, status, providerCode }`, for example `{ "kind": "http", "status": 503, "providerCode": null }`),
292
+ never the provider's text. Human output prints both as sentences.
242
293
 
243
294
  For `account add`, `account reauth` and `account operation resume`, `--json` writes JSON Lines:
244
295
  each line is one complete operation receipt, and unchanged revisions are omitted. `account
@@ -382,6 +433,10 @@ model catalog, then commits `request_may_have_started` immediately before FlexHa
382
433
  inference with retries disabled. Reusing the UUID with the same request returns its durable receipt; changing
383
434
  the target, prompt or requested model is rejected. A crash, cancellation or shutdown after the
384
435
  marker remains `outcome_unknown` and is never replayed. Before-marker refusals are `not_sent`.
436
+ A reached usage limit is named in the receipt: `problem` is `usage_limit` or `rate_limit` and `limit`
437
+ carries `{ kind, window, resetsAt }` (null otherwise). The account's usage reading stops the prompt
438
+ before the marker (`not_sent`); a provider that refuses the prompt with a limit before it begins to
439
+ answer settles it `refused`, a terminal state in which nothing was consumed.
385
440
  Only the request hash, selected model, timing and safe token counts are stored; the prompt,
386
441
  generated prose and credentials are absent from persistence and management responses. Account
387
442
  removal and targeted reauthentication refuse while that account has an active preuse request.
@@ -660,6 +715,22 @@ the new account without changing the active native login. Ctrl-C cancels login.
660
715
  Select the saved account with `use` when ready to switch. Claude Code and other
661
716
  OpenCode providers retain their native login commands.
662
717
 
718
+ ### The ChatGPT sign-in
719
+
720
+ authswitch runs the ChatGPT sign-in itself, as the one party that signs in and
721
+ refreshes: the device code and its poll, the authorization-code exchange, the
722
+ refresh-token grant, the revocation, the claims of the tokens, and the account's
723
+ `wham/usage` limits. `AuthSwitchOpenAiProvider` is that provider -- `beginLogin`,
724
+ `refreshCredential` (one shared request per refresh token, so a rotating grant is
725
+ sent once), `revokeCredential`, `inspectCredential` and `getAccountRateLimits` --
726
+ and `interfaces.openai` holds its types. It holds no credential of its own. The
727
+ protocol is the one Codex's own login uses, adapted from OpenAI Codex (Apache-2.0;
728
+ see `third-party-notices.md`), and every failure is a fixed message that carries no
729
+ response body, token or header. Inference with a login's access is not auth:
730
+ FlexHarness's `/openai` module serves it from `{ accessToken, accountId,
731
+ isFedrampAccount }` alone, which is exactly what the authority's `resolveAccess`
732
+ answers.
733
+
663
734
  ### Hosted account management
664
735
 
665
736
  `AuthSwitchService` exposes credential-free account lists, login capabilities,
@@ -670,9 +741,12 @@ ID and `cancel` cancels a pending login. Operations outlive a disconnected clien
670
741
  and completed results remain available for ten minutes. Call `close()` during
671
742
  host shutdown. The host must authenticate and authorize every request.
672
743
 
673
- Login requests identify the harness, provider and supported flow explicitly.
674
- `AuthSwitchLogin` is the backend login owner and accepts additional provider
675
- adapters. Its credential-bearing completion is for backend storage only.
744
+ Login requests identify the harness, provider and flow explicitly; the one flow is
745
+ `device`, which needs no browser on the machine that signs in. `AuthSwitchLogin` is
746
+ the backend login owner. Its default provider is `AuthSwitchOpenAiProvider`,
747
+ authswitch's own ChatGPT sign-in (see "The ChatGPT sign-in"), and it accepts any
748
+ other provider that implements `IAuthLoginProvider`. Its credential-bearing
749
+ completion is for backend storage only.
676
750
  When an enclosing registry owns an injected adapter, construct it with
677
751
  `{ disposeProviders: false }` as the second argument and dispose that registry
678
752
  after closing the login service.
@@ -924,9 +998,28 @@ prompt, the same window the single-account reset table lists first. An account
924
998
  that sent no prompt has no model, token count or deadline of its own, and says so
925
999
  rather than showing a zero. `Skipped` is a refusal the adapter stated before any
926
1000
  request -- an API-key login, a missing or expired credential, a model catalog
927
- that could not be read -- so nothing was consumed for it. `Failed` and
928
- `Interrupted` may both have consumed tokens and are never retried; `Not run` is
929
- an account the interruption never reached.
1001
+ that could not be read, a usage limit the account has reached -- so nothing was
1002
+ consumed for it. `Failed` and `Interrupted` may both have consumed tokens and are
1003
+ never retried; `Not run` is an account the interruption never reached. Every
1004
+ account that did not complete prints its reason, and a `Failed` one always names
1005
+ its cause without the provider's text: a limit, a rejected token, the 180-second
1006
+ deadline, a cancellation, an answer that ended unfinished, an HTTP error status
1007
+ (`the provider answered HTTP 503`), an answer that could not be read, an error the answer stream reported with the
1008
+ provider's error code, a connection that failed before any answer, or an error
1009
+ that names no cause.
1010
+
1011
+ Before it sends anything, Codex preuse reads the account's usage (`wham/usage`).
1012
+ When the account's limit is reached, the account is `Skipped` with the window and
1013
+ its reset in local time, for example `Weekly usage limit reached, resets in 16h
1014
+ 46min (2026-09-27 05:12). No preuse prompt was sent.` A reading that fails
1015
+ decides nothing: the prompt is sent and the provider's own answer counts, except a
1016
+ rejected token, which is refused before sending as the catalog read refuses it.
1017
+ When the provider still refuses the prompt with a usage or rate limit before it
1018
+ begins to answer -- a 429 naming `usage_limit_reached`, or a stream that fails with
1019
+ it before its first output -- the reason names that limit and says that no tokens
1020
+ were consumed. A limit reported after the answer began is named the same way, with
1021
+ its window and reset, and says that tokens may already have been consumed: the
1022
+ provider had begun to answer.
930
1023
 
931
1024
  The guide (`authswitch`, `authswitch -i`) offers **Preuse an account or all
932
1025
  accounts (consumes quota)** for a harness that supports it. It asks which account
@@ -1660,6 +1753,8 @@ The test suite builds a fixture `CODEX_HOME` with a real SQLite state database a
1660
1753
 
1661
1754
  This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the repository license file.
1662
1755
 
1756
+ The ChatGPT sign-in and usage-limit code is adapted from OpenAI Codex, which is licensed under the Apache License, Version 2.0. Its notices are in `third-party-notices.md` and its license in `openai-codex-license.txt`; both ship with the package.
1757
+
1663
1758
  **Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
1664
1759
 
1665
1760
  ### Trademarks
@@ -0,0 +1,29 @@
1
+ # Third-Party Notices
2
+
3
+ ## OpenAI Codex
4
+
5
+ OpenAI Codex
6
+ Copyright 2025 OpenAI
7
+
8
+ The OpenAI ChatGPT device sign-in, authorization-code exchange, refresh-token and
9
+ revocation protocol, the token claims, and the `wham/usage` account rate-limit
10
+ wire contract in this package are adapted in TypeScript from OpenAI Codex
11
+ (https://github.com/openai/codex). They were first adapted from rust-v0.146.1,
12
+ commit `79b4f03d35962b005b007a015113b38930711665`, and re-verified against
13
+ rust-v0.157.0, commit `00c972ed5d6ff6499317fd41b7f23605b8e6850d`
14
+ (`codex-rs/login/src/device_code_auth.rs`, `codex-rs/login/src/auth/manager.rs`,
15
+ `codex-rs/login/src/auth/revoke.rs`, `codex-rs/login/src/oauth/client.rs`,
16
+ `codex-rs/backend-client/src/client.rs` and the rate-limit models in
17
+ `codex-rs/codex-backend-openapi-models/src/models/`).
18
+
19
+ The adapted files, and their compiled counterparts in `dist_ts/`, are marked
20
+ with a header and contain modifications and integration work copyright 2026
21
+ Task Venture Capital GmbH:
22
+
23
+ - `ts/openaiauth.ts`
24
+ - `ts/openaiusage.ts`
25
+ - `ts/classes.openaiprovider.ts`
26
+ - `ts/interfaces.openai.ts`
27
+
28
+ OpenAI Codex is licensed under the Apache License, Version 2.0. A verbatim copy
29
+ of the upstream license is distributed in [openai-codex-license.txt](./openai-codex-license.txt).
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@modelprofile.com/authswitch',
6
- version: '9.1.0',
6
+ version: '10.0.0',
7
7
  description: 'Manage Codex, OpenCode and Claude Code accounts with guided switching and live usage status'
8
8
  }
@@ -178,6 +178,10 @@ export interface IAuthSwitchBinding {
178
178
  runtime: 'flex' | 'codex' | 'opencode' | 'claude';
179
179
  scopeId: string;
180
180
  incarnationId: string;
181
+ /**
182
+ * The authority revision at which this runtime and scope were last bound. It grows with every bind and never
183
+ * repeats for them, not even after a release and a new bind, so it names exactly one bind.
184
+ */
181
185
  revision: number;
182
186
  }
183
187
 
@@ -353,9 +357,8 @@ export interface IAuthSwitchAccountEvent {
353
357
  accountId: string;
354
358
  }
355
359
 
356
- export type TAuthSwitchLoginPrompt =
357
- | { flow: 'device'; verificationUrl: string; userCode: string }
358
- | { flow: 'browser'; authUrl: string };
360
+ /** What a device sign-in shows the person signing in; the authority signs in with a device code only. */
361
+ export type TAuthSwitchLoginPrompt = { flow: 'device'; verificationUrl: string; userCode: string };
359
362
 
360
363
  export interface IAuthSwitchOperation {
361
364
  id: string;
@@ -373,7 +376,38 @@ export interface IAuthSwitchOperation {
373
376
  revision: number;
374
377
  }
375
378
 
376
- /** Credential-free receipt for one exact, never-replayed quota-consuming request. */
379
+ /**
380
+ * A limit that kept a preuse prompt from being answered: `usage_limit` is the account's quota, spent until it
381
+ * resets, `rate_limit` a short throttle. `window` names the window by its length (`weekly`, `five-hour`) and
382
+ * `resetsAt` is an ISO time; either is null when neither the usage reading nor the provider stated it.
383
+ */
384
+ export interface IAuthSwitchPreuseLimit {
385
+ kind: 'usage_limit' | 'rate_limit';
386
+ window: string | null;
387
+ resetsAt: string | null;
388
+ }
389
+
390
+ /**
391
+ * Why a sent preuse prompt failed without a limit, never with the provider's text. `http` is an answer with an
392
+ * HTTP error status; `stream` an error the answer stream reported after it began, with the
393
+ * machine-readable code the error states and no status, since its answer was a success; `response` an answer that could not be read; `network` a connection
394
+ * that failed before any answer; `aborted` an abort that was neither a cancellation nor the deadline; `unknown`
395
+ * anything else. `status` and `providerCode` are null when the failure did not state them.
396
+ */
397
+ export interface IAuthSwitchPreuseFailure {
398
+ kind: 'http' | 'stream' | 'response' | 'network' | 'aborted' | 'unknown';
399
+ status: number | null;
400
+ providerCode: string | null;
401
+ }
402
+
403
+ /**
404
+ * Credential-free receipt for one exact, never-replayed quota-consuming request.
405
+ *
406
+ * `not_sent` with `usage_limit` is an account whose own usage reading showed a reached limit, so nothing was
407
+ * sent; `refused` is a prompt the provider refused with a limit before it began to answer, so nothing was
408
+ * consumed. `limit` describes the limit whenever `problem` is `usage_limit` or `rate_limit`, and is null otherwise.
409
+ * `failure` names the cause of a `request_uncertain` request when it failed with one, and is null otherwise.
410
+ */
377
411
  export interface IAuthSwitchPreuseOperation {
378
412
  id: string;
379
413
  accountId: string;
@@ -381,11 +415,13 @@ export interface IAuthSwitchPreuseOperation {
381
415
  purpose: 'openai_managed';
382
416
  requestedModel: string | null;
383
417
  model: string | null;
384
- state: 'preparing' | 'request_may_have_started' | 'complete' | 'not_sent' | 'outcome_unknown';
418
+ state: 'preparing' | 'request_may_have_started' | 'complete' | 'not_sent' | 'refused' | 'outcome_unknown';
385
419
  result: { inputTokens: number | null; outputTokens: number | null; totalTokens: number | null } | null;
386
420
  problem: 'none' | 'target_unavailable' | 'access_unavailable' | 'catalog_unavailable'
387
421
  | 'account_busy' | 'cancelled' | 'authority_closing' | 'interrupted'
388
- | 'request_uncertain';
422
+ | 'request_uncertain' | 'usage_limit' | 'rate_limit';
423
+ limit: IAuthSwitchPreuseLimit | null;
424
+ failure: IAuthSwitchPreuseFailure | null;
389
425
  createdAt: string;
390
426
  updatedAt: string;
391
427
  finishedAt: string | null;
@@ -545,10 +581,26 @@ export interface IReq_AuthSwitchGetBinding extends ITypedRequest {
545
581
  response: { binding: IAuthSwitchBinding | null };
546
582
  }
547
583
 
584
+ /**
585
+ * What a removal did about the account's ChatGPT sign-in at OpenAI:
586
+ * - `not_requested`: the caller did not ask; nothing reached the network.
587
+ * - `yes`: OpenAI confirmed the revocation.
588
+ * - `failed`: OpenAI did not confirm it, or not within the 10 seconds a removal's revocations are given in all;
589
+ * the sign-in may still be valid there. The account is removed anyway.
590
+ * - `not_applicable`: the authority held no ChatGPT sign-in of its own for the account.
591
+ */
592
+ export type TAuthSwitchRevocation = 'not_requested' | 'yes' | 'failed' | 'not_applicable';
593
+
594
+ /**
595
+ * Removes an account. With `revoke: true` the authority also revokes, after the removal committed, the ChatGPT
596
+ * sign-in it held for the account, and `revoked` says whether OpenAI confirmed it. The revocations take at most 10
597
+ * seconds in all, so a revoking removal answers within a request's usual 35 seconds. A revocation is irreversible
598
+ * and reaches everything that still refreshes from that sign-in, which the authority cannot see: see the readme.
599
+ */
548
600
  export interface IReq_AuthSwitchRemoveAccount extends ITypedRequest {
549
601
  method: 'authswitch.authority.remove';
550
- request: { accountId: string; expectedRevision: number };
551
- response: { account: IAuthSwitchAccount };
602
+ request: { accountId: string; expectedRevision: number; revoke?: true };
603
+ response: { account: IAuthSwitchAccount; revoked: TAuthSwitchRevocation };
552
604
  }
553
605
 
554
606
  /** Runtime capability is returned only to trusted backend callers; do not expose this response in a browser API. */