agl 43.2.0 → 43.3.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.
Files changed (213) hide show
  1. package/changelog.md +29 -0
  2. package/dist_serve/bundle.js +2845 -2638
  3. package/dist_serve/bundle.js.map +2 -2
  4. package/dist_serve/bundle.js.third-party-notices.json +1 -1
  5. package/dist_serve/bundle.js.third-party-notices.txt +1 -1
  6. package/dist_ts/00_commitinfo_data.js +1 -1
  7. package/dist_ts/aglapi/aglapisurface.document.js +197 -17
  8. package/dist_ts/classes.accountsactions.d.ts +3 -1
  9. package/dist_ts/classes.accountsactions.js +21 -3
  10. package/dist_ts/classes.authstore.d.ts +7 -0
  11. package/dist_ts/classes.authstore.js +9 -1
  12. package/dist_ts/classes.claudeharness.d.ts +29 -2
  13. package/dist_ts/classes.claudeharness.js +35 -6
  14. package/dist_ts/classes.codexclientadapter.d.ts +11 -0
  15. package/dist_ts/classes.codexclientadapter.js +14 -2
  16. package/dist_ts/classes.controller.d.ts +187 -12
  17. package/dist_ts/classes.controller.js +1208 -186
  18. package/dist_ts/classes.controllerdevices.d.ts +2 -0
  19. package/dist_ts/classes.controllerdevices.js +6 -1
  20. package/dist_ts/classes.inbox.d.ts +72 -0
  21. package/dist_ts/classes.inbox.js +231 -0
  22. package/dist_ts/classes.inferencerouter.d.ts +10 -0
  23. package/dist_ts/classes.inferencerouter.js +5 -3
  24. package/dist_ts/classes.inferenceservice.js +2 -2
  25. package/dist_ts/classes.mcpclient.d.ts +1 -1
  26. package/dist_ts/classes.mcpclient.js +24 -6
  27. package/dist_ts/classes.mcpcontrollerhost.js +6 -1
  28. package/dist_ts/classes.mcptools.js +18 -8
  29. package/dist_ts/classes.mcpvalidation.d.ts +5 -0
  30. package/dist_ts/classes.mcpvalidation.js +32 -2
  31. package/dist_ts/classes.nativesessions.d.ts +29 -4
  32. package/dist_ts/classes.nativesessions.js +41 -9
  33. package/dist_ts/classes.opencodeclient.d.ts +23 -2
  34. package/dist_ts/classes.opencodeclient.js +47 -3
  35. package/dist_ts/classes.publishedset.d.ts +38 -0
  36. package/dist_ts/classes.publishedset.js +50 -0
  37. package/dist_ts/classes.sessionfeed.d.ts +3 -3
  38. package/dist_ts/classes.sessionfeed.js +18 -26
  39. package/dist_ts/classes.systemmetricssampler.d.ts +6 -0
  40. package/dist_ts/classes.systemmetricssampler.js +15 -3
  41. package/dist_ts/classes.ticketstore.d.ts +50 -3
  42. package/dist_ts/classes.ticketstore.js +45 -8
  43. package/dist_ts/classes.workercallers.js +4 -2
  44. package/dist_ts/driver/classes.directreports.d.ts +14 -4
  45. package/dist_ts/driver/classes.directreports.js +42 -23
  46. package/dist_ts/driver/classes.directreportstore.d.ts +8 -1
  47. package/dist_ts/driver/classes.directreportstore.js +20 -10
  48. package/dist_ts/driver/classes.driverservice.d.ts +44 -3
  49. package/dist_ts/driver/classes.driverservice.js +50 -16
  50. package/dist_ts/fleet/classes.claudeworkers.d.ts +21 -5
  51. package/dist_ts/fleet/classes.claudeworkers.js +142 -46
  52. package/dist_ts/fleet/classes.codexworkers.d.ts +16 -4
  53. package/dist_ts/fleet/classes.codexworkers.js +22 -5
  54. package/dist_ts/fleet/classes.workercommand.d.ts +6 -1
  55. package/dist_ts/fleet/classes.workercommand.js +15 -4
  56. package/dist_ts/fleet/classes.workers.d.ts +21 -1
  57. package/dist_ts/fleet/classes.workers.js +80 -40
  58. package/dist_ts/fleet/classes.workerstore.js +14 -8
  59. package/dist_ts/fleet/functions.unbounddrivers.js +2 -2
  60. package/dist_ts/fleet/functions.workervalidation.js +11 -4
  61. package/dist_ts/fleet/interfaces.workers.d.ts +27 -5
  62. package/dist_ts/fleet/interfaces.workers.js +8 -4
  63. package/dist_ts/functions.agentmessage.d.ts +3 -0
  64. package/dist_ts/functions.agentmessage.js +4 -1
  65. package/dist_ts/functions.deviceapi.d.ts +198 -4
  66. package/dist_ts/functions.deviceapi.js +1060 -38
  67. package/dist_ts/functions.exactpersistence.d.ts +3 -0
  68. package/dist_ts/functions.exactpersistence.js +4 -0
  69. package/dist_ts/functions.fleetworkercli.d.ts +1 -1
  70. package/dist_ts/functions.fleetworkercli.js +11 -8
  71. package/dist_ts/functions.inferencecli.js +3 -1
  72. package/dist_ts/functions.mcpfleetworkertools.js +3 -3
  73. package/dist_ts/functions.ticketactor.d.ts +17 -1
  74. package/dist_ts/functions.ticketactor.js +55 -15
  75. package/dist_ts/functions.ticketvalidation.js +11 -2
  76. package/dist_ts/interfaces.auth.d.ts +1 -1
  77. package/dist_ts/interfaces.auth.js +9 -1
  78. package/dist_ts/plugins.d.ts +3 -1
  79. package/dist_ts/plugins.js +7 -2
  80. package/dist_ts_authswitch/authority-contract.d.ts +25 -0
  81. package/dist_ts_authswitch/authority-contract.js +1 -1
  82. package/dist_ts_authswitch/authority-overview.d.ts +8 -0
  83. package/dist_ts_authswitch/authority-overview.js +17 -6
  84. package/dist_ts_authswitch/authority-placement.d.ts +20 -16
  85. package/dist_ts_authswitch/authority-placement.js +17 -10
  86. package/dist_ts_authswitch/authority-renewal.d.ts +34 -0
  87. package/dist_ts_authswitch/authority-renewal.js +56 -0
  88. package/dist_ts_authswitch/classes.authoritybroker.d.ts +8 -0
  89. package/dist_ts_authswitch/classes.authoritybroker.js +35 -2
  90. package/dist_ts_authswitch/classes.authoritycli.d.ts +1 -0
  91. package/dist_ts_authswitch/classes.authoritycli.js +44 -3
  92. package/dist_ts_authswitch/classes.authorityclient.d.ts +6 -1
  93. package/dist_ts_authswitch/classes.authorityclient.js +12 -4
  94. package/dist_ts_authswitch/classes.authoritydaemon.js +8 -1
  95. package/dist_ts_authswitch/classes.authoritydatabase.js +6 -2
  96. package/dist_ts_authswitch/classes.authoritymodels.d.ts +7 -0
  97. package/dist_ts_authswitch/classes.authoritymodels.js +21 -5
  98. package/dist_ts_interfaces/devices.d.ts +1027 -7
  99. package/dist_ts_interfaces/devices.js +68 -2
  100. package/dist_ts_interfaces/fleetworkers.d.ts +37 -10
  101. package/dist_ts_interfaces/fleetworkers.js +19 -8
  102. package/dist_ts_interfaces/inbox.d.ts +234 -0
  103. package/dist_ts_interfaces/inbox.js +101 -0
  104. package/dist_ts_interfaces/index.d.ts +1 -0
  105. package/dist_ts_interfaces/index.js +2 -1
  106. package/dist_ts_interfaces/interfaces.d.ts +10 -3
  107. package/dist_ts_interfaces/interfaces.js +4 -2
  108. package/dist_ts_interfaces/mcprequests.d.ts +34 -4
  109. package/dist_ts_interfaces/mcprequests.js +11 -1
  110. package/dist_ts_interfaces/mcpworkspacerequests.d.ts +4 -1
  111. package/dist_ts_interfaces/mcpworkspacerequests.js +1 -1
  112. package/dist_ts_interfaces/nativesessions.d.ts +16 -3
  113. package/dist_ts_interfaces/plugins.d.ts +2 -1
  114. package/dist_ts_interfaces/plugins.js +4 -2
  115. package/dist_ts_interfaces/requests.accounts.d.ts +21 -0
  116. package/dist_ts_interfaces/requests.accounts.js +3 -1
  117. package/dist_ts_interfaces/requests.d.ts +3 -2
  118. package/dist_ts_interfaces/requests.js +1 -1
  119. package/dist_ts_interfaces/workercallers.d.ts +2 -0
  120. package/dist_ts_migration/classes.documentmigrationrunner.d.ts +14 -0
  121. package/dist_ts_migration/classes.documentmigrationrunner.js +20 -1
  122. package/dist_ts_migration/index.d.ts +1 -0
  123. package/dist_ts_migration/index.js +2 -1
  124. package/dist_ts_migration/v43_ticketactornames.d.ts +32 -0
  125. package/dist_ts_migration/v43_ticketactornames.js +236 -0
  126. package/docs/authswitch.md +20 -1
  127. package/package.json +3 -3
  128. package/readme.md +144 -27
  129. package/ts/00_commitinfo_data.ts +1 -1
  130. package/ts/aglapi/aglapisurface.document.ts +196 -16
  131. package/ts/classes.accountsactions.ts +30 -3
  132. package/ts/classes.authstore.ts +10 -0
  133. package/ts/classes.claudeharness.ts +45 -5
  134. package/ts/classes.codexclientadapter.ts +14 -1
  135. package/ts/classes.controller.ts +1412 -262
  136. package/ts/classes.controllerdevices.ts +6 -0
  137. package/ts/classes.inbox.ts +239 -0
  138. package/ts/classes.inferencerouter.ts +15 -2
  139. package/ts/classes.inferenceservice.ts +1 -1
  140. package/ts/classes.mcpclient.ts +24 -3
  141. package/ts/classes.mcpcontrollerhost.ts +5 -0
  142. package/ts/classes.mcptools.ts +17 -7
  143. package/ts/classes.mcpvalidation.ts +27 -1
  144. package/ts/classes.nativesessions.ts +63 -12
  145. package/ts/classes.opencodeclient.ts +55 -4
  146. package/ts/classes.publishedset.ts +56 -0
  147. package/ts/classes.sessionfeed.ts +17 -20
  148. package/ts/classes.systemmetricssampler.ts +13 -2
  149. package/ts/classes.ticketstore.ts +73 -12
  150. package/ts/classes.workercallers.ts +3 -1
  151. package/ts/driver/classes.directreports.ts +42 -23
  152. package/ts/driver/classes.directreportstore.ts +20 -9
  153. package/ts/driver/classes.driverservice.ts +75 -14
  154. package/ts/fleet/classes.claudeworkers.ts +112 -39
  155. package/ts/fleet/classes.codexworkers.ts +21 -6
  156. package/ts/fleet/classes.workercommand.ts +14 -4
  157. package/ts/fleet/classes.workers.ts +75 -41
  158. package/ts/fleet/classes.workerstore.ts +11 -7
  159. package/ts/fleet/functions.unbounddrivers.ts +1 -1
  160. package/ts/fleet/functions.workervalidation.ts +8 -3
  161. package/ts/fleet/interfaces.workers.ts +26 -7
  162. package/ts/functions.agentmessage.ts +3 -0
  163. package/ts/functions.deviceapi.ts +1292 -34
  164. package/ts/functions.exactpersistence.ts +5 -0
  165. package/ts/functions.fleetworkercli.ts +10 -7
  166. package/ts/functions.inferencecli.ts +2 -0
  167. package/ts/functions.mcpfleetworkertools.ts +2 -2
  168. package/ts/functions.ticketactor.ts +58 -14
  169. package/ts/functions.ticketvalidation.ts +11 -1
  170. package/ts/interfaces.auth.ts +8 -0
  171. package/ts/plugins.ts +7 -0
  172. package/ts_authswitch/authority-contract.ts +20 -0
  173. package/ts_authswitch/authority-overview.ts +28 -6
  174. package/ts_authswitch/authority-placement.ts +25 -17
  175. package/ts_authswitch/authority-renewal.ts +64 -0
  176. package/ts_authswitch/classes.authoritybroker.ts +34 -1
  177. package/ts_authswitch/classes.authoritycli.ts +49 -2
  178. package/ts_authswitch/classes.authorityclient.ts +14 -4
  179. package/ts_authswitch/classes.authoritydaemon.ts +9 -1
  180. package/ts_authswitch/classes.authoritydatabase.ts +5 -1
  181. package/ts_authswitch/classes.authoritymodels.ts +23 -3
  182. package/ts_authswitch/native-contracts.md +21 -0
  183. package/ts_authswitch/readme.md +1 -1
  184. package/ts_interfaces/devices.schema.json +3576 -603
  185. package/ts_interfaces/devices.ts +1111 -6
  186. package/ts_interfaces/fleetworkers.ts +38 -10
  187. package/ts_interfaces/inbox.ts +287 -0
  188. package/ts_interfaces/index.ts +1 -0
  189. package/ts_interfaces/interfaces.ts +9 -2
  190. package/ts_interfaces/mcprequests.ts +43 -4
  191. package/ts_interfaces/mcpworkspacerequests.ts +4 -2
  192. package/ts_interfaces/nativesessions.ts +17 -3
  193. package/ts_interfaces/plugins.ts +3 -1
  194. package/ts_interfaces/requests.accounts.ts +20 -0
  195. package/ts_interfaces/requests.ts +4 -0
  196. package/ts_interfaces/workercallers.ts +2 -0
  197. package/ts_migration/classes.documentmigrationrunner.ts +21 -0
  198. package/ts_migration/index.ts +1 -0
  199. package/ts_migration/v43_ticketactornames.ts +225 -0
  200. package/ts_web/00_commitinfo_data.ts +1 -1
  201. package/ts_web/accounts.plugins.ts +4 -2
  202. package/ts_web/classes.accountsreadmodel.ts +33 -0
  203. package/ts_web/classes.browserpresentation.ts +10 -5
  204. package/ts_web/classes.inboxfeed.ts +329 -0
  205. package/ts_web/classes.nativesessionstate.ts +9 -23
  206. package/ts_web/elements.accounts.ts +81 -0
  207. package/ts_web/elements.deployments.ts +66 -2
  208. package/ts_web/elements.fleetworker.ts +4 -2
  209. package/ts_web/elements.harnesscontrollerapp.ts +107 -37
  210. package/ts_web/elements.inbox.ts +808 -0
  211. package/ts_web/functions.inbox.ts +95 -0
  212. package/ts_web/functions.sessioncards.ts +40 -0
  213. package/ts_web/plugins.ts +2 -0
@@ -19,6 +19,7 @@ import { authSwitchApiKeyPaymentProblemText, authSwitchPaymentProblemText,
19
19
  authSwitchRecheckOutcomeText } from './authority-subscription.js';
20
20
  import { localDateTime } from './timetext.js';
21
21
  import { authSwitchAccountLifecycle, lapseHorizonMs } from './authority-placement.js';
22
+ import { authSwitchRenewal, isAuthSwitchRenewsAt } from './authority-renewal.js';
22
23
  import { authSwitchPackageIdentity, authSwitchRelease } from './packageidentity.js';
23
24
  import { describeOomScoreAdjust } from './serviceoom.js';
24
25
  import * as plugins from './plugins.js';
@@ -59,6 +60,7 @@ export interface IAuthSwitchAuthorityCliClient {
59
60
  setAccountMaxUsage(accountId: string, expectedRevision: number,
60
61
  maxUsagePercent: number | null): Promise<IAuthSwitchAccount>;
61
62
  setAccountLapse(accountId: string, expectedRevision: number, lapsesAt: string | null): Promise<IAuthSwitchAccount>;
63
+ setAccountRenewal(accountId: string, expectedRevision: number, renewsAt: string | null): Promise<IAuthSwitchAccount>;
62
64
  setAccountSpendLimit(accountId: string, expectedRevision: number,
63
65
  spendLimitMicroUsd: number | null): Promise<IAuthSwitchAccount>;
64
66
  setAccountClaudeCode(accountId: string, expectedRevision: number, claudeCode: boolean): Promise<IAuthSwitchAccount>;
@@ -102,6 +104,7 @@ type TAuthorityCliCommand =
102
104
  | { kind: 'remove'; accountId: string; revoke: boolean; json: boolean }
103
105
  | { kind: 'setMaxUsage'; accountId: string; maxUsagePercent: number | null; json: boolean }
104
106
  | { kind: 'setLapse'; accountId: string; lapsesAt: string | null; json: boolean }
107
+ | { kind: 'setRenewal'; accountId: string; renewsAt: string | null; json: boolean }
105
108
  | { kind: 'setSpendLimit'; accountId: string; spendLimitMicroUsd: number | null; json: boolean }
106
109
  | { kind: 'setClaudeCode'; accountId: string; claudeCode: boolean; json: boolean }
107
110
  | { kind: 'get'; operationId: string; json: boolean }
@@ -120,7 +123,7 @@ class AuthorityCliFailure extends Error {
120
123
  }
121
124
  }
122
125
 
123
- const usage = 'Usage: authswitch --help | authswitch --version [--json] | authswitch list [--json] | authswitch limits [--json] | authswitch account list [--json] | authswitch account add openai|claude [--json] | authswitch account add anthropic-api-key|openai-api-key [--label <label>] [--spend-limit <dollars>] [--json] | authswitch account use codex <account-id> [--json] | authswitch account release codex <account-id> [--end-running-turns] [--json] | authswitch account release claude <account-id> [--end-native-sessions] [--json] | authswitch account repair claude [--json] | authswitch account reauth <account-id> <login-id> [--json] | authswitch account recheck <account-id> [--json] | authswitch account remove <account-id> [--revoke] [--json] | authswitch account set <account-id> --max-usage <percent>|--clear|--lapses-at <date-time>|--clear-lapse|--spend-limit <dollars>|--clear-spend-limit [--json] | authswitch account operation get|cancel|resume <operation-id> [--json] | authswitch account preuse <account-id> <login-id>|--all [--prompt <text>] [--model <id>] [--json] | authswitch account preuse operation get|cancel|resume <operation-id> [--json] | authswitch authority doctor [--json] | authswitch authority import inventory [--json] | authswitch authority import status [--json] | authswitch authority import submit <source-id> --digest <source-digest> [--json] | authswitch authority service install|status|enable|start|stop | authswitch authority daemon';
126
+ const usage = 'Usage: authswitch --help | authswitch --version [--json] | authswitch list [--json] | authswitch limits [--json] | authswitch account list [--json] | authswitch account add openai|claude [--json] | authswitch account add anthropic-api-key|openai-api-key [--label <label>] [--spend-limit <dollars>] [--json] | authswitch account use codex <account-id> [--json] | authswitch account release codex <account-id> [--end-running-turns] [--json] | authswitch account release claude <account-id> [--end-native-sessions] [--json] | authswitch account repair claude [--json] | authswitch account reauth <account-id> <login-id> [--json] | authswitch account recheck <account-id> [--json] | authswitch account remove <account-id> [--revoke] [--json] | authswitch account set <account-id> --max-usage <percent>|--clear|--lapses-at <date-time>|--clear-lapse|--renews-at <date-time>|--clear-renewal|--spend-limit <dollars>|--clear-spend-limit [--json] | authswitch account operation get|cancel|resume <operation-id> [--json] | authswitch account preuse <account-id> <login-id>|--all [--prompt <text>] [--model <id>] [--json] | authswitch account preuse operation get|cancel|resume <operation-id> [--json] | authswitch authority doctor [--json] | authswitch authority import inventory [--json] | authswitch authority import status [--json] | authswitch authority import submit <source-id> --digest <source-digest> [--json] | authswitch authority service install|status|enable|start|stop | authswitch authority daemon';
124
127
 
125
128
  /** Every command, one per line, with what it does; `authswitch --help` prints it. */
126
129
  const help = (): string => `authswitch ${authSwitchRelease.version}
@@ -173,6 +176,11 @@ Usage
173
176
  new sessions on it only as a last resort in its last day,
174
177
  and from then on routes nothing to it and moves its
175
178
  sessions; --clear-lapse makes it active again
179
+ authswitch account set <account-id> --renews-at <date-time>|--clear-renewal [--json]
180
+ a Claude sign-in renews monthly from that date and time
181
+ (a past one too): the AGL proxy spends first the usage a
182
+ window would still hold at the next renewal;
183
+ --clear-renewal removes it
176
184
  authswitch account set <account-id> --spend-limit <dollars>|--clear-spend-limit [--json]
177
185
  an API key's monthly spend limit (calendar month, UTC) on
178
186
  what AGL's proxy relayed on it: at the limit the proxy places
@@ -385,6 +393,12 @@ const parse = (argv: readonly string[]): TAuthorityCliCommand | null => {
385
393
  if (options.length === 2 && options[0] === '--lapses-at' && isAuthSwitchLapsesAt(options[1])) {
386
394
  return { kind: 'setLapse', accountId: argv[2], lapsesAt: options[1], json };
387
395
  }
396
+ if (options.length === 1 && options[0] === '--clear-renewal') {
397
+ return { kind: 'setRenewal', accountId: argv[2], renewsAt: null, json };
398
+ }
399
+ if (options.length === 2 && options[0] === '--renews-at' && isAuthSwitchRenewsAt(options[1])) {
400
+ return { kind: 'setRenewal', accountId: argv[2], renewsAt: options[1], json };
401
+ }
388
402
  if (options.length === 1 && options[0] === '--clear-spend-limit') {
389
403
  return { kind: 'setSpendLimit', accountId: argv[2], spendLimitMicroUsd: null, json };
390
404
  }
@@ -519,6 +533,10 @@ class ScopedAuthorityCliClient implements IAuthSwitchAuthorityCliClient {
519
533
  return this.client.setAccountLapse(accountId, expectedRevision, lapsesAt, this.controller.signal);
520
534
  }
521
535
 
536
+ public setAccountRenewal(accountId: string, expectedRevision: number, renewsAt: string | null): Promise<IAuthSwitchAccount> {
537
+ return this.client.setAccountRenewal(accountId, expectedRevision, renewsAt, this.controller.signal);
538
+ }
539
+
522
540
  public addApiKey(providerId: TAuthSwitchApiKeyProvider, apiKey: string,
523
541
  options: { label?: string; spendLimitMicroUsd?: number }): Promise<IReq_AuthSwitchAddApiKey['response']> {
524
542
  return this.client.addApiKey(providerId, apiKey, options, this.controller.signal);
@@ -623,6 +641,20 @@ const lapseText = (account: IAuthSwitchAccount, nowArg: number): string => {
623
641
  const renderLapse = (account: IAuthSwitchAccount, nowArg: number): string =>
624
642
  `Account ${safe(account.email ?? account.label)} (${safe(account.id)}): ${lapseText(account, nowArg)}.\n`;
625
643
 
644
+ /**
645
+ * An account's renewal in words, as `account set --renews-at` and `account list` state it: the next renewal, rolled
646
+ * forward from the anchor the owner set. Empty for an account without one.
647
+ */
648
+ const renewalText = (account: IAuthSwitchAccount, nowArg: number): string => {
649
+ const renewal = authSwitchRenewal(account.renewsAt, nowArg);
650
+ return renewal === null ? '' : `renews ${safe(renewal.at)} (set by the owner)`;
651
+ };
652
+
653
+ const renderRenewal = (account: IAuthSwitchAccount, nowArg: number): string =>
654
+ `Account ${safe(account.email ?? account.label)} (${safe(account.id)}): `
655
+ + (account.renewsAt === null ? 'no renewal set.\n'
656
+ : `${renewalText(account, nowArg)}; usage it would still hold then is used first.\n`);
657
+
626
658
  /** A re-check as `account recheck` states it: how the read went, and whether the account is still held. */
627
659
  const renderRecheck = (account: IAuthSwitchAccount, recheck: IAuthSwitchUsageRecheck): string =>
628
660
  `Account ${safe(account.email ?? account.label)} (${safe(account.id)}): ${authSwitchRecheckOutcomeText(recheck.outcome)}\n`
@@ -677,7 +709,8 @@ const renderList = (snapshot: IAuthSwitchSnapshot, nowArg: number): string => {
677
709
  lines.push(`${safe(identity)} [${safe(account.providerId)}]`,
678
710
  ` account ${safe(account.id)}; organization ${account.organizationId === undefined ? 'not published'
679
711
  : safe(account.organizationId)}; plan ${safe(account.plan)}; max usage ${account.maxUsagePercent === null ? 'not set'
680
- : `${account.maxUsagePercent}%`}; ${lapseText(account, nowArg)}; ${account.removed ? 'removed' : 'registered'}; `
712
+ : `${account.maxUsagePercent}%`}; ${lapseText(account, nowArg)}; `
713
+ + `${account.renewsAt === null ? '' : `${renewalText(account, nowArg)}; `}${account.removed ? 'removed' : 'registered'}; `
681
714
  + `stored ${safe(account.statusObservedAt)}`);
682
715
  const logins = snapshot.logins.filter(login => login.accountId === account.id);
683
716
  if (logins.length === 0) lines.push(' logins: none');
@@ -1497,6 +1530,20 @@ export const runAuthSwitchAuthorityCli = async (argv: readonly string[],
1497
1530
  await writeOutput(command.json ? JSON.stringify({ account: changed }) + '\n' : renderLapse(changed, now()));
1498
1531
  return 0;
1499
1532
  }
1533
+ if (command.kind === 'setRenewal') {
1534
+ const account = (await activeClient.snapshotAll()).accounts.find(item => item.id === command.accountId && !item.removed);
1535
+ if (!account) {
1536
+ await writeDiagnostic('No authority account has this id. Run `authswitch account list` for the ids.\n');
1537
+ return 1;
1538
+ }
1539
+ const changed = await activeClient.setAccountRenewal(account.id, account.revision, command.renewsAt);
1540
+ if (changed.id !== account.id || (command.renewsAt === null ? changed.renewsAt !== null
1541
+ : changed.renewsAt === null || Date.parse(changed.renewsAt) !== Date.parse(command.renewsAt))) {
1542
+ throw new AuthorityCliFailure('response');
1543
+ }
1544
+ await writeOutput(command.json ? JSON.stringify({ account: changed }) + '\n' : renderRenewal(changed, now()));
1545
+ return 0;
1546
+ }
1500
1547
  if (command.kind === 'setSpendLimit') {
1501
1548
  const account = (await activeClient.snapshotAll()).accounts.find(item => item.id === command.accountId && !item.removed);
1502
1549
  if (!account) {
@@ -7,7 +7,7 @@ import type {
7
7
  IReq_AuthSwitchClaudeHostLogin, IReq_AuthSwitchEvents, IReq_AuthSwitchReleaseClaudeNative,
8
8
  IReq_AuthSwitchClaudeNativeReleaseOperation, IReq_AuthSwitchRepairClaudeHost,
9
9
  IReq_AuthSwitchGetBinding, IReq_AuthSwitchGetOperation, IReq_AuthSwitchListOperations,
10
- IReq_AuthSwitchRemoveAccount, IReq_AuthSwitchRenameAccount, IReq_AuthSwitchSetAccountLapse, IReq_AuthSwitchSetAccountMaxUsage, IReq_AuthSwitchLiftAccountReserve,
10
+ IReq_AuthSwitchRemoveAccount, IReq_AuthSwitchRenameAccount, IReq_AuthSwitchSetAccountLapse, IReq_AuthSwitchSetAccountRenewal, IReq_AuthSwitchSetAccountMaxUsage, IReq_AuthSwitchLiftAccountReserve,
11
11
  IReq_AuthSwitchCancelPreuse, IReq_AuthSwitchGetPreuse, IReq_AuthSwitchSnapshot,
12
12
  IReq_AuthSwitchStartPreuse, IReq_AuthSwitchUsage, IReq_AuthSwitchObserveUsage, IReq_AuthSwitchReportPaymentProblem,
13
13
  IReq_AuthSwitchRecordSpend, IAuthSwitchSpendAnswer, TAuthSwitchPaymentProblemCause, TAuthSwitchApiKeyProvider,
@@ -122,8 +122,8 @@ export class AuthSwitchDaemonOutdatedError extends Error {
122
122
  * A snapshot page carries every member of this release's contract. `schemaVersion` is not bumped for an
123
123
  * additive member; version 3 adds the gateway runtime, every account states its `maxUsagePercent` from 38.3.0
124
124
  * on, its `lapsesAt` from 38.4.0 on, its `reserveLiftUntil` with reserve lifts, its `spendLimitMicroUsd` and
125
- * `keyHint` with API keys of both providers, and its `claudeCode` from AGL-1146 on. Consumers still check their
126
- * supported version.
125
+ * `keyHint` with API keys of both providers, its `claudeCode` from AGL-1146 on, and its `renewsAt` from AGL-1644 on.
126
+ * Consumers still check their supported version.
127
127
  */
128
128
  const assertCurrentSnapshot = (snapshot: IAuthSwitchSnapshot): IAuthSwitchSnapshot => {
129
129
  const page: Partial<IAuthSwitchSnapshot> = snapshot;
@@ -134,7 +134,8 @@ const assertCurrentSnapshot = (snapshot: IAuthSwitchSnapshot): IAuthSwitchSnapsh
134
134
  || (account as Partial<IAuthSwitchAccount>).reserveLiftUntil === undefined
135
135
  || (account as Partial<IAuthSwitchAccount>).spendLimitMicroUsd === undefined
136
136
  || (account as Partial<IAuthSwitchAccount>).keyHint === undefined
137
- || (account as Partial<IAuthSwitchAccount>).claudeCode === undefined)) {
137
+ || (account as Partial<IAuthSwitchAccount>).claudeCode === undefined
138
+ || (account as Partial<IAuthSwitchAccount>).renewsAt === undefined)) {
138
139
  throw new AuthSwitchDaemonOutdatedError();
139
140
  }
140
141
  return snapshot;
@@ -553,6 +554,15 @@ export class AuthSwitchClient {
553
554
  return (await this.request<IReq_AuthSwitchSetAccountLapse>('authswitch.authority.lapse',
554
555
  { accountId, expectedRevision, lapsesAt }, 35_000, false, signal)).account;
555
556
  }
557
+ /**
558
+ * Sets the anchor of a Claude sign-in's monthly renewal, or clears it with `null` (see
559
+ * `IReq_AuthSwitchSetAccountRenewal`).
560
+ */
561
+ public async setAccountRenewal(accountId: string, expectedRevision: number, renewsAt: string | null,
562
+ signal?: AbortSignal): Promise<IReq_AuthSwitchSetAccountRenewal['response']['account']> {
563
+ return (await this.request<IReq_AuthSwitchSetAccountRenewal>('authswitch.authority.renewal',
564
+ { accountId, expectedRevision, renewsAt }, 35_000, false, signal)).account;
565
+ }
556
566
  /**
557
567
  * Removes an account; `revoke: true` also revokes its ChatGPT sign-in at OpenAI (see
558
568
  * `IReq_AuthSwitchRemoveAccount`). An older daemon refuses `revoke` as an invalid request before it changes
@@ -8,7 +8,7 @@ import type {
8
8
  IReq_AuthSwitchRepairClaudeHost,
9
9
  IReq_AuthSwitchEvents, IReq_AuthSwitchGetBinding, IReq_AuthSwitchGetOperation, IReq_AuthSwitchListOperations,
10
10
  IReq_AuthSwitchRemoveAccount,
11
- IReq_AuthSwitchRenameAccount, IReq_AuthSwitchSetAccountLapse, IReq_AuthSwitchSetAccountMaxUsage, IReq_AuthSwitchSetAccountSpendLimit, IReq_AuthSwitchSetAccountClaudeCode, IReq_AuthSwitchLiftAccountReserve, IReq_AuthSwitchSnapshot,
11
+ IReq_AuthSwitchRenameAccount, IReq_AuthSwitchSetAccountLapse, IReq_AuthSwitchSetAccountRenewal, IReq_AuthSwitchSetAccountMaxUsage, IReq_AuthSwitchSetAccountSpendLimit, IReq_AuthSwitchSetAccountClaudeCode, IReq_AuthSwitchLiftAccountReserve, IReq_AuthSwitchSnapshot,
12
12
  IReq_AuthSwitchCancelPreuse, IReq_AuthSwitchGetPreuse, IReq_AuthSwitchStartPreuse, IReq_AuthSwitchUsage,
13
13
  IReq_AuthSwitchObserveUsage, IReq_AuthSwitchReportPaymentProblem, IReq_AuthSwitchRecheckUsage, IReq_AuthSwitchRecordSpend,
14
14
  IReq_AuthSwitchMoveClaudeHomeIn, IReq_AuthSwitchMoveClaudeHomeOut, IReq_AuthSwitchRegisterClaudeHome,
@@ -754,6 +754,14 @@ export class AuthSwitchAuthorityDaemon {
754
754
  return { account: await this.broker.setAccountLapse(request.accountId, request.expectedRevision,
755
755
  request.lapsesAt) };
756
756
  }));
757
+ this.managementRouter.addTypedHandler(this.handler<IReq_AuthSwitchSetAccountRenewal>(
758
+ 'authswitch.authority.renewal', async request => {
759
+ if (!hasKeys(request, ['accountId', 'expectedRevision', 'renewsAt']) || typeof request.accountId !== 'string'
760
+ || typeof request.expectedRevision !== 'number'
761
+ || (request.renewsAt !== null && typeof request.renewsAt !== 'string')) invalid();
762
+ return { account: await this.broker.setAccountRenewal(request.accountId, request.expectedRevision,
763
+ request.renewsAt) };
764
+ }));
757
765
  this.managementRouter.addTypedHandler(this.handler<IReq_AuthSwitchGetBinding>(
758
766
  'authswitch.authority.binding', async request => {
759
767
  if (!hasKeys(request, ['bindingId']) || !validBindingId(request.bindingId)) invalid();
@@ -1577,7 +1577,11 @@ export class AuthSwitchAuthorityDatabase {
1577
1577
  || draft.subject !== prior.subject || draft.workspaceId !== prior.workspaceId
1578
1578
  || draft.id !== prior.id) throw new Error('Account identity cannot change.');
1579
1579
  const result = await AuthSwitchAuthorityAccountModel.exact.transition({
1580
- current, change: model => Object.assign(model, draft),
1580
+ current, change: model => {
1581
+ Object.assign(model, draft);
1582
+ // Optional: a draft without it drops it, which `Object.assign` alone would keep (AGENTS.md, rollback floor).
1583
+ model.renewsAt = draft.renewsAt;
1584
+ },
1581
1585
  }, { session });
1582
1586
  if (result.status !== 'transitioned') throw new Error('Account changed concurrently.');
1583
1587
  } else {
@@ -6,6 +6,7 @@ import type { IAuthSwitchStoredUsage, IAuthSwitchStoredUsageEstimate } from './c
6
6
  import { isAuthSwitchUsageEstimateState } from './classes.authorityusageestimate.js';
7
7
  import { isAuthSwitchUsageObservation } from './authority-usageheaders.js';
8
8
  import { authSwitchSpendPeriod, isAuthSwitchSpendLimitMicroUsd, isAuthSwitchSpendPeriodKey } from './authority-spend.js';
9
+ import { isAuthSwitchRenewsAt } from './authority-renewal.js';
9
10
 
10
11
  export interface IStoredAuthorityMeta {
11
12
  id: 'authswitch-authority';
@@ -30,6 +31,12 @@ export interface IStoredAuthorityAccount {
30
31
  reserveLiftUntil: string | null;
31
32
  /** When the account's subscription ends, ISO 8601 UTC, or `null` while it renews (`IAuthSwitchAccount.lapsesAt`). */
32
33
  lapsesAt: string | null;
34
+ /**
35
+ * A Claude sign-in's renewal anchor, ISO 8601 UTC (`IAuthSwitchAccount.renewsAt`, AGL-1644). Present only while the
36
+ * owner holds one set: a record without it is the record an earlier accounts service reads, so clearing it removes the
37
+ * member (the transition sets it to `undefined`), never stores null.
38
+ */
39
+ renewsAt?: string;
33
40
  /** An API key account's monthly spend limit in micro-dollars, or `null` (`IAuthSwitchAccount.spendLimitMicroUsd`). */
34
41
  spendLimitMicroUsd: number | null;
35
42
  /** How an API key account's key ends, or `null` (`IAuthSwitchAccount.keyHint`). */
@@ -727,10 +734,22 @@ export const assertStoredAuthorityMeta: (value: unknown) => asserts value is ISt
727
734
  || !revision(value.revision) || !uuid(value.updateId)) throw new Error('Invalid authswitch authority metadata.');
728
735
  };
729
736
 
737
+ const storedAccountKeys = ['id', 'providerId', 'issuer', 'subject', 'workspaceId', 'label', 'email', 'plan',
738
+ 'primaryGrantId', 'maxUsagePercent', 'reserveLiftUntil', 'lapsesAt', 'spendLimitMicroUsd', 'keyHint', 'claudeCode',
739
+ 'removed', 'revision', 'statusObservedAt', 'updateId'] as const;
740
+
741
+ /**
742
+ * An account record holds every member of `storedAccountKeys` and nothing else, or those and a renewal anchor
743
+ * (`renewsAt`, only on a Claude sign-in). The optional member is checked on its own: a record that holds it holds a
744
+ * valid anchor, never null.
745
+ */
746
+ const storedAccountMembers = (value: Record<string, unknown>): boolean =>
747
+ exactKeys(value, storedAccountKeys)
748
+ || (exactKeys(value, [...storedAccountKeys, 'renewsAt']) && iso(value.renewsAt) && isAuthSwitchRenewsAt(value.renewsAt)
749
+ && value.providerId === 'anthropic' && value.workspaceId !== 'api-key');
750
+
730
751
  export const assertStoredAuthorityAccount: (value: unknown) => asserts value is IStoredAuthorityAccount = value => {
731
- if (!object(value) || !exactKeys(value, ['id', 'providerId', 'issuer', 'subject', 'workspaceId', 'label',
732
- 'email', 'plan', 'primaryGrantId', 'maxUsagePercent', 'reserveLiftUntil', 'lapsesAt', 'spendLimitMicroUsd', 'keyHint',
733
- 'claudeCode', 'removed', 'revision', 'statusObservedAt', 'updateId'])
752
+ if (!object(value) || !storedAccountMembers(value)
734
753
  || !hash(value.id) || typeof value.providerId !== 'string'
735
754
  || !/^[a-z][a-z0-9-]{0,63}$/.test(value.providerId)
736
755
  || !bounded(value.issuer) || !bounded(value.subject) || !bounded(value.workspaceId)
@@ -1301,6 +1320,7 @@ export class AuthSwitchAuthorityAccountModel extends plugins.nosqldb.SmartDataDb
1301
1320
  @plugins.nosqldb.svDb() public maxUsagePercent!: number | null;
1302
1321
  @plugins.nosqldb.svDb() public reserveLiftUntil!: string | null;
1303
1322
  @plugins.nosqldb.svDb() public lapsesAt!: string | null;
1323
+ @plugins.nosqldb.svDb() public renewsAt?: string;
1304
1324
  @plugins.nosqldb.svDb() public spendLimitMicroUsd!: number | null;
1305
1325
  @plugins.nosqldb.svDb() public keyHint!: string | null;
1306
1326
  @plugins.nosqldb.svDb() public claudeCode!: boolean;
@@ -562,6 +562,10 @@ are marked:
562
562
  as an option; workspace trust in `.claude.json` (`projects[<dir>].hasTrustDialogAccepted`).
563
563
  - Relay stream-json: `system`/`init` and `result` (`subtype`, `is_error`, `permission_denials`, `api_error_status`,
564
564
  `terminal_reason`, `errors`).
565
+ - Relay tools (AGL-382): `--tools=SendMessage,Read,ToolSearch` (one `=` argument) and `--strict-mcp-config` must leave
566
+ exactly `Read`, `SendMessage` and `ToolSearch` in the init record's `tools`, in every permission mode, bypassPermissions
567
+ included, and the init record must come before the model is called. The relay refuses every run whose init record
568
+ lists anything else, so a change fails visibly: relays stop.
565
569
  - Transcript growth against the 4 MiB window: the fleet reads a transcript's last 4 MiB and refuses an incremental read
566
570
  of more as an observation gap. Measure what the release adds and how much time and how many turns the window still
567
571
  covers, and check that the Agent SDK's chain reader (`getSessionMessages`, used for history) skips record types it does
@@ -653,6 +657,23 @@ contradicts the bundle read gets a fix ticket:
653
657
  of the dispatcher is 2.1.282's.
654
658
  - Relay stream-json (bundle only): `system`/`init` (@33617187), and the `result` fields `permission_denials`, `api_error_status`,
655
659
  `terminal_reason`, `errors` and `is_api_error_message` are in the bundle. No relay ran on 2.1.306.
660
+ - Relay tools (AGL-382, 2026-11-11), run on 2.1.306 itself in a disposable home without any credential, in a user, mount
661
+ and network namespace (no network, private `/run/user` and `/tmp`), `claude -p --output-format stream-json --verbose`:
662
+ - `--tools=SendMessage,Read,ToolSearch --strict-mcp-config` prints `system`/`init` first, before any model call, with
663
+ `tools` `["Read","SendMessage","ToolSearch"]` (sorted, whatever order was passed) and `mcp_servers` `[]`, in the
664
+ modes `default`, `acceptEdits` and `bypassPermissions` (run as a mapped non-root user: Claude Code refuses
665
+ bypassPermissions for root). Without `--tools` the same init lists 21 tools, `Bash`, `Edit` and `Write` among them.
666
+ - `--tools` alone does not reach MCP tools: a user-scoped stdio MCP server's tool (`mcp__probe__probe`) stays in `tools`
667
+ until `--strict-mcp-config` drops the server. The host's user config names the `agl` and `playwright` servers, so
668
+ before AGL-382 a relay in bypassPermissions could run their tools.
669
+ - `--tools` takes several values: `--tools SendMessage,Read,ToolSearch <prompt>` takes the prompt as a tool name and
670
+ exits 1 with `Input must be provided either through stdin or as a prompt argument`. An unknown name is dropped
671
+ without an error (`--tools=…,Bogus` lists the three), so only the init record proves the list.
672
+ - Without a credential the run ends after init with the synthetic `Not logged in · Please run /login`
673
+ (`authentication_failed`), exit 1; with a made-up key it retries the unreachable API (`api_retry`). The init record
674
+ names the run's own socket (`messaging_socket_path`, under `$XDG_RUNTIME_DIR/cc-socks`).
675
+ - Not checked here: plugin MCP servers under `--strict-mcp-config` (the host's settings enable no plugin), and a real relay's
676
+ delivery with the restricted tools (it needs a model call). The relay's init check refuses either change.
656
677
  - Transcript growth. `api-request`, `api-request-shape` and `api-request-blob` records are 27 % of the bytes written after
657
678
  each file's first 2.1.306 record (26 of 95 MB, three quarters of it blobs), and 26 % of the two driver workers' 4 MiB
658
679
  windows.
@@ -8,6 +8,6 @@ Keep the authority in its own process. The controller never owns refresh grants.
8
8
 
9
9
  Native credential files belong to their tools: the authority writes one only through a verified, journaled handoff, and never destroys or overwrites a native credential it has not first proven it can restore. Every operation that stops the owned Codex app-server restarts it on both success and failure. Structured authority state uses the existing NoSQLDB models and versioned migrations.
10
10
 
11
- Tests isolate all harness homes and use injected provider/process adapters. Never run account-mutating tests against the developer's own installations. Module import, CLI help/version and the browser leaves (`authority-contract.ts`, `authority-spend.ts`, `authority-usagewindows.ts`, `authority-usagelimit.ts`, `authority-usageheaders.ts`, `authority-usagetokens.ts`, `authority-placement.ts`, `authority-subscription.ts`, `preuse-text.ts`) must not initialize a controller or touch credentials. `authority-subscription.ts` holds the one map of what Claude's `subscription_status` values mean (empty until a value is confirmed) and the words of a payment problem and a re-check, which the command line and the Accounts screen share; `classes.authorityusage.ts` holds a payment problem on the usage record (`reportPaymentProblem`) and clears it on a read that finds a changed subscription or a healthy re-check (`recheck`); a problem held without a subscription takes the one the next healthy read finds, and that read clears nothing. `authority-placement.ts` is the one rule of an account's lifecycle against its `lapsesAt` and of the placement score the proxy places new sessions by. `authority-usageheaders.ts` reads the usage a provider's answer headers state and joins it to the authority's own reading; the authority holds such observations in memory and answers every usage read with them (`authswitch.authority.usage.observe`). `classes.authorityusage.ts` owns the one usage-read schedule: each account is read from the provider every 10 minutes on the authority's timer and at once after an inference 429, a failed read keeps the held reading `stale` and waits for `retry-after` or the next slot, and no question waits for a read or an unseal. `authority-usagetokens.ts` (browser-safe) weighs the tokens the proxy reports by Anthropic's published prices, and `classes.authorityusageestimate.ts` carries each Claude window forward between reads with a ratio learned per account and window, in memory only. `authority-usagelimit.ts` is the one rule of whether an account's usage, against its `maxUsagePercent`, lets it take work -- a switch on the reading's `kind`, where an API key's `spend` reading is judged by its spend limit alone; the proxy, Flex, the CLI and the Accounts screen all call it rather than restating it. `authority-spend.ts` (imports nothing) is the calendar month in UTC a key's spend counts in (`authSwitchSpendPeriod`, the one calendar function), the spend reading, the spend limit rule and dollar amounts. `authority-apikeys.ts` holds the key verifier (`authSwitchApiKeyVerifier`, a read of the provider's model list) and the guard against a key of the other provider; `AuthSwitchAuthorityDatabase.recordSpend` / `readSpend` keep the monthly ledger (`authswitch_authority_spend_entries`, `authswitch_authority_spend_periods`), and `classes.authorityusage.ts` answers a key's usage from it and holds a key's payment problem, by cause, on the key's usage record. A sealed key is `{ kind: 'anthropicApiKey' | 'openaiApiKey', apiKey }`, one kind per provider; never add a kind a reader must keep forever.
11
+ Tests isolate all harness homes and use injected provider/process adapters. Never run account-mutating tests against the developer's own installations. Module import, CLI help/version and the browser leaves (`authority-contract.ts`, `authority-spend.ts`, `authority-usagewindows.ts`, `authority-usagelimit.ts`, `authority-usageheaders.ts`, `authority-usagetokens.ts`, `authority-placement.ts`, `authority-subscription.ts`, `preuse-text.ts`) must not initialize a controller or touch credentials. `authority-subscription.ts` holds the one map of what Claude's `subscription_status` values mean (empty until a value is confirmed) and the words of a payment problem and a re-check, which the command line and the Accounts screen share; `classes.authorityusage.ts` holds a payment problem on the usage record (`reportPaymentProblem`) and clears it on a read that finds a changed subscription or a healthy re-check (`recheck`); a problem held without a subscription takes the one the next healthy read finds, and that read clears nothing. `authority-placement.ts` is the one rule of an account's lifecycle against its `lapsesAt` and of the placement score the proxy places new sessions by; `authority-renewal.ts` (imports nothing) is the one rule of a Claude sign-in's monthly renewal as its owner set it (`renewsAt`), which placement counts as a window deadline. `authority-usageheaders.ts` reads the usage a provider's answer headers state and joins it to the authority's own reading; the authority holds such observations in memory and answers every usage read with them (`authswitch.authority.usage.observe`). `classes.authorityusage.ts` owns the one usage-read schedule: each account is read from the provider every 10 minutes on the authority's timer and at once after an inference 429, a failed read keeps the held reading `stale` and waits for `retry-after` or the next slot, and no question waits for a read or an unseal. `authority-usagetokens.ts` (browser-safe) weighs the tokens the proxy reports by Anthropic's published prices, and `classes.authorityusageestimate.ts` carries each Claude window forward between reads with a ratio learned per account and window, in memory only. `authority-usagelimit.ts` is the one rule of whether an account's usage, against its `maxUsagePercent`, lets it take work -- a switch on the reading's `kind`, where an API key's `spend` reading is judged by its spend limit alone; the proxy, Flex, the CLI and the Accounts screen all call it rather than restating it. `authority-spend.ts` (imports nothing) is the calendar month in UTC a key's spend counts in (`authSwitchSpendPeriod`, the one calendar function), the spend reading, the spend limit rule and dollar amounts. `authority-apikeys.ts` holds the key verifier (`authSwitchApiKeyVerifier`, a read of the provider's model list) and the guard against a key of the other provider; `AuthSwitchAuthorityDatabase.recordSpend` / `readSpend` keep the monthly ledger (`authswitch_authority_spend_entries`, `authswitch_authority_spend_periods`), and `classes.authorityusage.ts` answers a key's usage from it and holds a key's payment problem, by cause, on the key's usage record. A sealed key is `{ kind: 'anthropicApiKey' | 'openaiApiKey', apiKey }`, one kind per provider; never add a kind a reader must keep forever.
12
12
 
13
13
  Imported from authswitch 11.4.1, commit `c3fed26`; future fixes and releases belong to AGL. OpenAI adaptations retain their headers and the notices in the repository's `third-party-notices.md` and `openai-codex-license.txt`.