@cortexkit/opencode-antigravity-auth 3.0.29 → 3.0.30

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 (173) hide show
  1. package/dist/cli.js +689 -183
  2. package/dist/cli.js.map +4 -4
  3. package/dist/cli.meta.json +130 -67
  4. package/dist/index.js +734 -191
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +159 -72
  7. package/dist/server.js +734 -194
  8. package/dist/server.js.map +4 -4
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/cli.d.ts +1 -0
  11. package/dist/src/cli.d.ts.map +1 -1
  12. package/dist/src/cli.js +22 -2
  13. package/dist/src/cli.js.map +1 -1
  14. package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +12 -0
  15. package/dist/src/common-auth-embedded/claustrum/consumer.js +36 -0
  16. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +16 -4
  17. package/dist/src/common-auth-embedded/claustrum/custody.js +74 -9
  18. package/dist/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
  19. package/dist/src/common-auth-embedded/claustrum/hub.js +8 -0
  20. package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -0
  21. package/dist/src/common-auth-embedded/claustrum/roster.d.ts +2 -0
  22. package/dist/src/common-auth-embedded/claustrum/roster.js +2 -0
  23. package/dist/src/common-auth-embedded/claustrum/usage.d.ts +41 -0
  24. package/dist/src/common-auth-embedded/claustrum/usage.js +145 -0
  25. package/dist/src/common-auth-embedded/commands/builtins.d.ts +5 -0
  26. package/dist/src/common-auth-embedded/commands/builtins.js +38 -0
  27. package/dist/src/common-auth-embedded/fs/private-files.d.ts +5 -0
  28. package/dist/src/common-auth-embedded/fs/private-files.js +7 -0
  29. package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +142 -47
  30. package/dist/src/common-auth-embedded/fs/with-lock.js +2 -5
  31. package/dist/src/common-auth-embedded/limits/activity.d.ts +26 -0
  32. package/dist/src/common-auth-embedded/limits/axes.d.ts +63 -0
  33. package/dist/src/common-auth-embedded/limits/decide.d.ts +141 -0
  34. package/dist/src/common-auth-embedded/limits/duration.d.ts +8 -0
  35. package/dist/src/common-auth-embedded/limits/families.d.ts +57 -0
  36. package/dist/src/common-auth-embedded/limits/marker.d.ts +64 -0
  37. package/dist/src/common-auth-embedded/limits/request-history.d.ts +77 -0
  38. package/dist/src/common-auth-embedded/limits/scope.d.ts +12 -0
  39. package/dist/src/common-auth-embedded/limits/signal.d.ts +41 -0
  40. package/dist/src/common-auth-embedded/limits/terminal.d.ts +52 -0
  41. package/dist/src/common-auth-embedded/limits/wake.d.ts +21 -0
  42. package/dist/src/common-auth-embedded/limits/wording.d.ts +25 -0
  43. package/dist/src/common-auth-embedded/opencode2/index.d.ts +1 -1
  44. package/dist/src/common-auth-embedded/opencode2/install.d.ts +2 -2
  45. package/dist/src/common-auth-embedded/opencode2/install.js +161 -18
  46. package/dist/src/common-auth-embedded/opencode2/types.d.ts +95 -9
  47. package/dist/src/common-auth-embedded/routing/admission.d.ts +7 -2
  48. package/dist/src/common-auth-embedded/routing/admission.js +17 -7
  49. package/dist/src/common-auth-embedded/routing-accessor/handle.js +10 -0
  50. package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +13 -3
  51. package/dist/src/common-auth-embedded/routing-accessor/index.js +11 -10
  52. package/dist/src/common-auth-embedded/rpc/port-file.d.ts +12 -3
  53. package/dist/src/common-auth-embedded/rpc/port-file.js +46 -4
  54. package/dist/src/common-auth-embedded/source-output.json +254 -118
  55. package/dist/src/common-auth-embedded/store/attribution.js +3 -2
  56. package/dist/src/common-auth-embedded/store/errors.d.ts +1 -1
  57. package/dist/src/common-auth-embedded/store/hooks.d.ts +5 -1
  58. package/dist/src/common-auth-embedded/store/hooks.js +20 -5
  59. package/dist/src/common-auth-embedded/store/index.d.ts +1 -0
  60. package/dist/src/common-auth-embedded/store/limits-namespace.d.ts +7 -0
  61. package/dist/src/common-auth-embedded/store/limits-namespace.js +34 -0
  62. package/dist/src/common-auth-embedded/store/pool.d.ts +10 -1
  63. package/dist/src/common-auth-embedded/store/pool.js +2 -0
  64. package/dist/src/common-auth-embedded/store/provider-state.js +5 -5
  65. package/dist/src/common-auth-embedded/store/refresh.js +1 -1
  66. package/dist/src/common-auth-embedded/store/schema.js +9 -4
  67. package/dist/src/common-auth-embedded/store/settings.d.ts +2 -0
  68. package/dist/src/common-auth-embedded/store/settings.js +11 -4
  69. package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
  70. package/dist/src/runtime-layout.d.ts +9 -2
  71. package/dist/src/runtime-layout.d.ts.map +1 -1
  72. package/dist/src/runtime-layout.js +8 -8
  73. package/dist/src/runtime-layout.js.map +1 -1
  74. package/dist/src/setup.d.ts.map +1 -1
  75. package/dist/src/setup.js +29 -40
  76. package/dist/src/setup.js.map +1 -1
  77. package/dist/tui-build-map.json +9 -9
  78. package/dist/tui-ga-build-map.json +1 -1
  79. package/dist/types/src/cli.d.ts +1 -0
  80. package/dist/types/src/cli.d.ts.map +1 -1
  81. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +12 -0
  82. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +16 -4
  83. package/dist/types/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
  84. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -0
  85. package/dist/types/src/common-auth-embedded/claustrum/roster.d.ts +2 -0
  86. package/dist/types/src/common-auth-embedded/claustrum/usage.d.ts +41 -0
  87. package/dist/types/src/common-auth-embedded/commands/builtins.d.ts +5 -0
  88. package/dist/types/src/common-auth-embedded/limits/activity.d.ts +26 -0
  89. package/dist/types/src/common-auth-embedded/limits/axes.d.ts +63 -0
  90. package/dist/types/src/common-auth-embedded/limits/decide.d.ts +141 -0
  91. package/dist/types/src/common-auth-embedded/limits/duration.d.ts +8 -0
  92. package/dist/types/src/common-auth-embedded/limits/families.d.ts +57 -0
  93. package/dist/types/src/common-auth-embedded/limits/marker.d.ts +64 -0
  94. package/dist/types/src/common-auth-embedded/limits/request-history.d.ts +77 -0
  95. package/dist/types/src/common-auth-embedded/limits/scope.d.ts +12 -0
  96. package/dist/types/src/common-auth-embedded/limits/signal.d.ts +41 -0
  97. package/dist/types/src/common-auth-embedded/limits/terminal.d.ts +52 -0
  98. package/dist/types/src/common-auth-embedded/limits/wake.d.ts +21 -0
  99. package/dist/types/src/common-auth-embedded/limits/wording.d.ts +25 -0
  100. package/dist/types/src/common-auth-embedded/opencode2/index.d.ts +1 -1
  101. package/dist/types/src/common-auth-embedded/opencode2/install.d.ts +2 -2
  102. package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +95 -9
  103. package/dist/types/src/common-auth-embedded/routing/admission.d.ts +7 -2
  104. package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +13 -3
  105. package/dist/types/src/common-auth-embedded/store/errors.d.ts +1 -1
  106. package/dist/types/src/common-auth-embedded/store/hooks.d.ts +5 -1
  107. package/dist/types/src/common-auth-embedded/store/index.d.ts +1 -0
  108. package/dist/types/src/common-auth-embedded/store/limits-namespace.d.ts +7 -0
  109. package/dist/types/src/common-auth-embedded/store/pool.d.ts +10 -1
  110. package/dist/types/src/common-auth-embedded/store/settings.d.ts +2 -0
  111. package/dist/types/src/runtime-layout.d.ts +9 -2
  112. package/dist/types/src/runtime-layout.d.ts.map +1 -1
  113. package/dist/types/src/setup.d.ts.map +1 -1
  114. package/package.json +2 -2
  115. package/src/common-auth-embedded/claustrum/consumer.d.ts +12 -0
  116. package/src/common-auth-embedded/claustrum/consumer.js +36 -0
  117. package/src/common-auth-embedded/claustrum/custody.d.ts +16 -4
  118. package/src/common-auth-embedded/claustrum/custody.js +74 -9
  119. package/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
  120. package/src/common-auth-embedded/claustrum/hub.js +8 -0
  121. package/src/common-auth-embedded/claustrum/index.d.ts +1 -0
  122. package/src/common-auth-embedded/claustrum/roster.d.ts +2 -0
  123. package/src/common-auth-embedded/claustrum/roster.js +2 -0
  124. package/src/common-auth-embedded/claustrum/usage.d.ts +41 -0
  125. package/src/common-auth-embedded/claustrum/usage.js +145 -0
  126. package/src/common-auth-embedded/commands/builtins.d.ts +5 -0
  127. package/src/common-auth-embedded/commands/builtins.js +38 -0
  128. package/src/common-auth-embedded/fs/private-files.d.ts +5 -0
  129. package/src/common-auth-embedded/fs/private-files.js +7 -0
  130. package/src/common-auth-embedded/fs/refresh-file-lock.js +142 -47
  131. package/src/common-auth-embedded/fs/with-lock.js +2 -5
  132. package/src/common-auth-embedded/limits/activity.d.ts +26 -0
  133. package/src/common-auth-embedded/limits/axes.d.ts +63 -0
  134. package/src/common-auth-embedded/limits/decide.d.ts +141 -0
  135. package/src/common-auth-embedded/limits/duration.d.ts +8 -0
  136. package/src/common-auth-embedded/limits/families.d.ts +57 -0
  137. package/src/common-auth-embedded/limits/marker.d.ts +64 -0
  138. package/src/common-auth-embedded/limits/request-history.d.ts +77 -0
  139. package/src/common-auth-embedded/limits/scope.d.ts +12 -0
  140. package/src/common-auth-embedded/limits/signal.d.ts +41 -0
  141. package/src/common-auth-embedded/limits/terminal.d.ts +52 -0
  142. package/src/common-auth-embedded/limits/wake.d.ts +21 -0
  143. package/src/common-auth-embedded/limits/wording.d.ts +25 -0
  144. package/src/common-auth-embedded/opencode2/index.d.ts +1 -1
  145. package/src/common-auth-embedded/opencode2/install.d.ts +2 -2
  146. package/src/common-auth-embedded/opencode2/install.js +161 -18
  147. package/src/common-auth-embedded/opencode2/types.d.ts +95 -9
  148. package/src/common-auth-embedded/routing/admission.d.ts +7 -2
  149. package/src/common-auth-embedded/routing/admission.js +17 -7
  150. package/src/common-auth-embedded/routing-accessor/handle.js +10 -0
  151. package/src/common-auth-embedded/routing-accessor/index.d.ts +13 -3
  152. package/src/common-auth-embedded/routing-accessor/index.js +11 -10
  153. package/src/common-auth-embedded/rpc/port-file.d.ts +12 -3
  154. package/src/common-auth-embedded/rpc/port-file.js +46 -4
  155. package/src/common-auth-embedded/source-output.json +254 -118
  156. package/src/common-auth-embedded/store/attribution.js +3 -2
  157. package/src/common-auth-embedded/store/errors.d.ts +1 -1
  158. package/src/common-auth-embedded/store/hooks.d.ts +5 -1
  159. package/src/common-auth-embedded/store/hooks.js +20 -5
  160. package/src/common-auth-embedded/store/index.d.ts +1 -0
  161. package/src/common-auth-embedded/store/limits-namespace.d.ts +7 -0
  162. package/src/common-auth-embedded/store/limits-namespace.js +34 -0
  163. package/src/common-auth-embedded/store/pool.d.ts +10 -1
  164. package/src/common-auth-embedded/store/pool.js +2 -0
  165. package/src/common-auth-embedded/store/provider-state.js +5 -5
  166. package/src/common-auth-embedded/store/refresh.js +1 -1
  167. package/src/common-auth-embedded/store/schema.js +9 -4
  168. package/src/common-auth-embedded/store/settings.d.ts +2 -0
  169. package/src/common-auth-embedded/store/settings.js +11 -4
  170. package/src/tui-compiled/common-auth-embedded/fs/private-files.js +7 -0
  171. package/src/tui-compiled/common-auth-embedded/rpc/port-file.js +46 -4
  172. package/src/tui-raw/common-auth-embedded/fs/private-files.js +7 -0
  173. package/src/tui-raw/common-auth-embedded/rpc/port-file.js +46 -4
@@ -1,7 +1,7 @@
1
1
  import type { ChooseAccountResult, HeaderEdits, InstallOpenCode2AuthOptions, OpenCode2AuthAdapter, OpenCode2AuthInstallation, OpenCode2HookContext } from './types.js';
2
2
  export declare const DEFAULT_MAX_RECORDS = 512;
3
- /** Bound adapter waits while allowing a 15-minute reset plus session jitter. */
4
- export declare const MAX_RETRY_HOLD_MS: number;
3
+ /** Allow a one-hour cache lifetime plus the maximum session jitter. */
4
+ export declare const MAX_RETRY_HOLD_MS = 3621000;
5
5
  /**
6
6
  * The request header `model.request` sets to the attempt it started. The
7
7
  * host builds the HTTP request and the WebSocket handshake from the headers
@@ -1,5 +1,6 @@
1
1
  import type { Plugin } from '@opencode/plugin';
2
2
  import type { SessionRequestKind, SessionRetryDecision } from '@opencode/plugin/promise/session';
3
+ import type { WaitCheckpoint } from '../limits/decide.js';
3
4
  /** The parts of the OpenCode 2 plugin context the installer uses. */
4
5
  export type OpenCode2HookContext = {
5
6
  readonly session: Pick<Plugin.Context['session'], 'hook'>;
@@ -35,6 +36,8 @@ export interface EventVerdict<Q> {
35
36
  readonly outputStarted?: boolean;
36
37
  readonly quota?: Q;
37
38
  readonly limit?: LimitSignal;
39
+ /** Applies only to this attempt, after ownership and attribution checks. */
40
+ readonly hostRetry?: RetryDisposition['hostRetry'];
38
41
  /**
39
42
  * This is the last event of the response (completed or failed); the
40
43
  * attempt ends here. On WebSocket this is the only way an attempt ends
@@ -55,6 +58,16 @@ export type HeaderEdits = Readonly<Record<string, string | null>>;
55
58
  export interface ChooseAccountInput extends RequestScope {
56
59
  /** The retry hook's advance choice (which may hold), or a request's own choice. */
57
60
  readonly phase: 'retry' | 'request';
61
+ /** Retry hook draft's attempt count; also carried by a consumed hold's wake. */
62
+ readonly hostAttempt?: number;
63
+ /** Revalidate the held account before dispatch, even if the target is not due. */
64
+ readonly wake?: RetryWake;
65
+ /**
66
+ * Accounts refused by earlier reroutes of this logical request. Absent means
67
+ * empty. Holds and wakes do not exclude the held account. A snapshot, not a
68
+ * live set; supplied whether or not enforcement is enabled.
69
+ */
70
+ readonly excluded?: readonly string[];
58
71
  /**
59
72
  * The account of the attempt this one retries, when the retry hook just
60
73
  * asked the host to retry an attempt of this session and kind; otherwise
@@ -75,19 +88,43 @@ export interface ChooseAccountInput extends RequestScope {
75
88
  export interface AccountRequest extends RequestScope {
76
89
  readonly accountId: string;
77
90
  }
91
+ /** The held account is ChooseAccountInput.previousAccountId. */
92
+ export interface RetryWake {
93
+ readonly target: number;
94
+ readonly checkpoint?: WaitCheckpoint;
95
+ /** Terminal quota waits do not require the session's provider prompt-cache TTL. */
96
+ readonly kind?: 'hold' | 'terminal';
97
+ }
78
98
  /** An explicit retry on the refused account, without moving its routing pin. */
79
99
  export interface RetryHold {
80
100
  readonly hold: {
81
101
  /**
82
102
  * Adapter-computed wait in milliseconds, including per-session jitter.
83
- * Finite, non-negative values are clamped to MAX_RETRY_HOLD_MS (20 minutes).
84
- * Invalid values keep the host's decision and release the choice.
103
+ * Finite, non-negative values up to MAX_RETRY_HOLD_MS (3_621_000) are
104
+ * accepted. Larger or invalid values keep the host's decision and release
105
+ * the choice rather than dispatching before the requested wait has elapsed.
85
106
  */
86
107
  readonly delayMs: number;
108
+ /** An absolute wake target; its presence forces a request-phase re-check. */
109
+ readonly target?: number;
110
+ readonly checkpoint?: WaitCheckpoint;
111
+ /** Forwarded to wake.kind so terminal quota waits omit the cache bound. */
112
+ readonly kind?: RetryWake['kind'];
87
113
  };
88
114
  }
89
- /** Holds are valid only in phase `retry`, with a recognised account limit. */
90
- export type ChooseAccountResult = string | RetryHold | undefined;
115
+ /** Leave the host's retry decision alone, or forbid replay of this attempt. */
116
+ export interface RetryDisposition {
117
+ readonly hostRetry: 'leave' | 'veto';
118
+ }
119
+ /** Wait through one host retry, then choose afresh without reserving an account. */
120
+ export interface RetryWaitThenReselect {
121
+ readonly waitThenReselect: {
122
+ /** Same finite, non-negative delay bound as RetryHold.hold.delayMs. */
123
+ readonly delayMs: number;
124
+ };
125
+ }
126
+ /** Non-string choices are valid only in phase `retry`, after an account limit. */
127
+ export type ChooseAccountResult = string | RetryHold | RetryDisposition | RetryWaitThenReselect | undefined;
91
128
  /**
92
129
  * One physical send: created when an account is chosen for a request, and
93
130
  * handed back on every hook call and event that belongs to that send, so a
@@ -194,7 +231,7 @@ export interface SameAccountRetryResult {
194
231
  * quota reading type; the installer only carries it to the `quota` event.
195
232
  * `A` is the plugin's per-attempt value (see `Attempt`).
196
233
  * `Choice` defaults to the legacy ID-only result so existing adapters' direct
197
- * callers still see IDs. Opt into holds with `ChooseAccountResult`.
234
+ * callers still see IDs. Opt into retry directives with `ChooseAccountResult`.
198
235
  */
199
236
  export interface OpenCode2AuthAdapter<Q = unknown, A = unknown, Choice extends ChooseAccountResult = string | undefined> {
200
237
  /** Every hook is scoped to this provider; other providers are untouched. */
@@ -209,11 +246,24 @@ export interface OpenCode2AuthAdapter<Q = unknown, A = unknown, Choice extends C
209
246
  * After a limit before any output, the retry hook makes this call itself,
210
247
  * with `phase: 'retry'` and `rerouteFrom` set. Every returned account,
211
248
  * including the refused one, is kept for the next attempt of that session
212
- * and kind: it does not choose again. Another account retries at once;
249
+ * and kind: it does not choose again, except for a hold with a target.
250
+ * Another account retries at once;
213
251
  * the refused account keeps the host's decision and wait. `{ hold: { delayMs } }`
214
252
  * commits the refused account without changing its pin and replaces the host's
215
253
  * wait, even its no-retry decision, only for a recognised account limit before
216
- * output in an untainted session. Holds returned in phase `request` cannot
254
+ * output in a session with no foreign transport. A hold with a target releases its queued
255
+ * choice and calls again in phase `request` with `wake` and `hostAttempt`
256
+ * before fetching account headers. The adapter must check that the account
257
+ * is still eligible, still represents the same login, is still available
258
+ * from the credential store and has any required provider prompt-cache TTL
259
+ * remaining, then choose normally if invalid.
260
+ * A hold without a target takes the queued account as before.
261
+ * `{ hostRetry: 'veto' }` forbids replay; `'leave'` preserves the host's decision
262
+ * without reserving an account. `{ waitThenReselect: { delayMs } }` asks for one
263
+ * delayed host retry, then chooses afresh. It commits no account or routing pin.
264
+ * Like holds, its delay must fit MAX_RETRY_HOLD_MS and the host retry budget.
265
+ * These directives obey the same ownership, attribution and output fences.
266
+ * Non-string choices returned in phase `request` cannot
217
267
  * select an account and are treated as undefined. `undefined` or a
218
268
  * throw commits nothing: the host decides, and the next attempt chooses
219
269
  * with `phase: 'request'`, `previousAccountId` and no `rerouteFrom`.
@@ -222,7 +272,8 @@ export interface OpenCode2AuthAdapter<Q = unknown, A = unknown, Choice extends C
222
272
  /**
223
273
  * Releases a kept retry choice that will not be used: no retry, a changed
224
274
  * model or agent, cancellation of a queued retry (session idle), session forgetting/deletion,
225
- * disposal or record eviction. A hold releases the refused account's choice.
275
+ * disposal, record eviction or a targeted hold's wake re-check. A hold
276
+ * releases the refused account's choice.
226
277
  * Called once with the original choose input plus its returned accountId,
227
278
  * never for a used choice. Awaited before any later chooseAccount for the
228
279
  * same session; errors are logged and swallowed. A model/agent change
@@ -264,6 +315,21 @@ export interface OpenCode2AuthAdapter<Q = unknown, A = unknown, Choice extends C
264
315
  readonly response: Response;
265
316
  readonly attempt: Attempt<A>;
266
317
  }): Promise<Response | undefined> | Response | undefined;
318
+ /**
319
+ * Optional retry policy for the final HTTP response. Runs immediately after
320
+ * `rewriteResponse` (or on the unchanged response when no rewrite is returned).
321
+ * Return `veto` to forbid host replay of a refusal the adapter formatted,
322
+ * even without a recognised limit. A veto is sticky for this attempt.
323
+ * Ownership and attribution checks still run first: a veto cannot affect a
324
+ * foreign request, a session with mixed ownership, or a retry whose attempt is
325
+ * ambiguous. `leave` or `undefined` preserves the existing retry policy,
326
+ * including an earlier veto.
327
+ */
328
+ responseRetry?(input: AccountRequest & {
329
+ readonly request: Request;
330
+ readonly response: Response;
331
+ readonly attempt: Attempt<A>;
332
+ }): Promise<'leave' | 'veto' | undefined> | 'leave' | 'veto' | undefined;
267
333
  /**
268
334
  * Optional. For an adapter whose own sender can move a request to another
269
335
  * account after `rewriteRequest` (a bridge that answers a 401 or 403 by
@@ -435,6 +501,24 @@ export interface InstallOpenCode2AuthOptions {
435
501
  readonly hostCredentials?: readonly string[];
436
502
  /** Most attempts kept before the oldest is abandoned and dropped. */
437
503
  readonly maxRecords?: number;
504
+ /**
505
+ * Host retry budget, default 10. When hostAttempt leaves no retry available,
506
+ * limit holds and reroutes keep the host's decision and release their choice.
507
+ */
508
+ readonly hostRetryLimit?: number;
509
+ /**
510
+ * Reject chooser results naming a request-excluded account (default false).
511
+ * A rejected choice warns and acts like undefined: the host decides in retry,
512
+ * and request selection stops with no-account. Without this option, chooser
513
+ * results retain their existing meaning.
514
+ *
515
+ * The host supplies no logical request id. The first later attempt of the
516
+ * same session and kind consumes a queued retry's exclusions. If another
517
+ * attempt is in flight, that binding warns but keeps the exclusions. A new
518
+ * concurrent request can therefore inherit them; if it consumes the retry
519
+ * first, the actual retry instead starts a fresh token without them.
520
+ */
521
+ readonly enforceRequestExclusion?: boolean;
438
522
  readonly logger?: OpenCode2AuthLogger;
439
523
  }
440
524
  /**
@@ -449,13 +533,15 @@ export interface InstallOpenCode2AuthOptions {
449
533
  * (its wait, or its refusal to retry) stands and the next attempt may go
450
534
  * to the refused account again;
451
535
  * - `hold`: an explicit adapter wait on the refused account, before output;
536
+ * - `wait-then-reselect`: wait without reserving the next account;
537
+ * - `adapter-veto`: the attributed adapter disposition forbids host replay;
452
538
  * - `same-account`: the adapter requested immediate recovery on the same route,
453
539
  * without account selection, before output;
454
540
  * - `host-decides`: no limit was recognised, or the failing call cannot be
455
541
  * attributed safely (ambiguous attempts or mixed ownership in a gated
456
542
  * session), so the host's decision stands.
457
543
  */
458
- export type RetryReason = 'reroute' | 'hold' | 'same-account' | 'output-started' | 'no-account' | 'host-decides-last-account' | 'host-decides';
544
+ export type RetryReason = 'reroute' | 'hold' | 'wait-then-reselect' | 'adapter-veto' | 'same-account' | 'output-started' | 'no-account' | 'host-decides-last-account' | 'host-decides';
459
545
  /**
460
546
  * The hook that picked an account. Normally `model.request`; a transport hook
461
547
  * picks only when the host skipped `model.request` for that request, which a
@@ -23,11 +23,16 @@ export interface AdmissionInput extends ExclusionInputs {
23
23
  scope?: string;
24
24
  /** Labels the scope requires an entry for; defaults to `['primary']`. */
25
25
  requiredLabels?: readonly string[];
26
+ /**
27
+ * One-dispatch exemptions keyed by row; waive only gate 4. The caller first
28
+ * validates the current account incarnation and checkpointed reset times.
29
+ */
30
+ liftedWindows?: ReadonlyMap<string, readonly WindowRef[]>;
26
31
  now: number;
27
32
  /**
28
- * Called synchronously, once per refusal at gates 2 to 4, with the row id.
33
+ * Called synchronously once per row needing a pull, including lifted windows.
29
34
  * Its return value is ignored and never awaited, so a pull the caller
30
- * starts from here cannot delay the refusal.
35
+ * starts from here cannot delay admission or a refusal.
31
36
  */
32
37
  requestPull?: (rowId: string) => void;
33
38
  }
@@ -12,6 +12,14 @@ export interface AskRoutingInput<Candidate extends RoutingCandidate = RoutingCan
12
12
  candidates: readonly Candidate[];
13
13
  /** Defaults to 500 ms, clamped to 1–2000 ms. */
14
14
  deadlineMs?: number;
15
+ /**
16
+ * Longest same-account hold, in seconds, that routing may advise. The
17
+ * holdWaitMaxS helper from `./limits` caps it by the setting and the current
18
+ * account's cache expiry, returning 0 when there is no accepted prompt cache
19
+ * worth waiting for. Fractions are floored and negatives become 0. Omit it to leave
20
+ * routing's default cap in force.
21
+ */
22
+ holdWaitMaxS?: number;
15
23
  }
16
24
  export interface RoutingHold {
17
25
  /** Uncapped advice from routing. The plugin must apply its own hold cap. */
@@ -39,9 +47,11 @@ export type ReportRoutingInput = RoutingReportIdentity & ({
39
47
  /** The exhausted quota window; keep scoped quota groups in `pool`. */
40
48
  window: '5h' | '7d';
41
49
  /**
42
- * Scoped quota group, such as `non-gemini`.
43
- * Must be a non-empty string without `:`. Omit to block the whole
44
- * account; include to block only this pool.
50
+ * Scoped quota group, such as Antigravity's `3p` or `gemini`.
51
+ * Must match `^[a-z0-9._-]{1,64}$`. Routing compares names exactly, so
52
+ * callers must lowercase names from elsewhere (e.g. `Fable` to `fable`).
53
+ * Names are never rewritten here. Omit or pass `undefined` to block the
54
+ * whole account; include to block only this pool.
45
55
  */
46
56
  pool?: string;
47
57
  /** Optional reset time in epoch milliseconds. */
@@ -1,6 +1,6 @@
1
1
  import type { StoredCredential } from './schema.js';
2
2
  /** Every library operation that can fail, as named in the failure value. */
3
- export type PoolOperation = 'initialize' | 'add' | 'replace' | 'rotate' | 'disable' | 'enable' | 'remove' | 'reorder' | 'updateSettings' | 'recordIdentity' | 'updateProviderState' | 'refresh' | 'pull' | 'publishRoster';
3
+ export type PoolOperation = 'initialize' | 'add' | 'replace' | 'rotate' | 'disable' | 'enable' | 'remove' | 'reorder' | 'updateSettings' | 'updateLimitsNamespace' | 'recordIdentity' | 'updateProviderState' | 'refresh' | 'pull' | 'publishRoster';
4
4
  /**
5
5
  * How far an operation got before it failed.
6
6
  *
@@ -1,7 +1,11 @@
1
1
  import { type PoolOperation } from './errors.js';
2
2
  /** Refuses a row operation or refresh called from inside a hook. */
3
3
  export declare function assertNotInsideHook(operation: PoolOperation): void;
4
- export declare function runInsideHook<T>(operation: PoolOperation, fn: () => Promise<T> | T): Promise<T>;
4
+ /** Namespace writes need only the store locks, not the row lock a hook may retain. */
5
+ export declare function assertLimitsWriteAllowed(): void;
6
+ /** Codecs may run under store locks even when no asynchronous hook is active. */
7
+ export declare function runInsideCodec<T>(fn: () => T): T;
8
+ export declare function runInsideHook<T>(operation: PoolOperation, fn: () => Promise<T> | T, storeLocksReleased?: boolean): Promise<T>;
5
9
  export interface PoolLogger {
6
10
  warn(message: string, data?: unknown): void;
7
11
  }
@@ -3,6 +3,7 @@ export type { PoolFailureKind, PoolFailurePhase, PoolOperation, } from './errors
3
3
  export { PoolOperationError, PoolReentryError } from './errors.js';
4
4
  export type { PoolLogger } from './hooks.js';
5
5
  export { countUnknownIdentityRows, DUPLICATE_IDENTITY_REASON, } from './identity.js';
6
+ export type { PoolLimitsMutator, PoolLimitsRow } from './limits-namespace.js';
6
7
  export type { HoldPoint, InitializeOutcome, WriteStep } from './mutate.js';
7
8
  export type { OpenPoolStoreOptions, PoolLoad, PoolStore, } from './pool.js';
8
9
  export { openPoolStore } from './pool.js';
@@ -0,0 +1,7 @@
1
+ import type { StoreRuntime } from './runtime.js';
2
+ import type { PoolRow } from './schema.js';
3
+ /** Row IDs, credential epochs and identities only; mutators never receive credentials. */
4
+ export type PoolLimitsRow = Pick<PoolRow, 'id' | 'credentialEpoch' | 'identity'>;
5
+ export type PoolLimitsMutator = (envelope: unknown, rows: readonly PoolLimitsRow[]) => unknown | Promise<unknown>;
6
+ /** A namespace merge and its check of current row bindings share one locked config snapshot. */
7
+ export declare function updatePoolLimitsNamespace(rt: StoreRuntime, mutator: PoolLimitsMutator): Promise<void>;
@@ -2,6 +2,7 @@ import type { QuotaCommitTimer } from '../quota/commit-interval.js';
2
2
  import { type Attribution } from './attribution.js';
3
3
  import type { PoolOperationError } from './errors.js';
4
4
  import type { PoolLogger } from './hooks.js';
5
+ import { type PoolLimitsMutator } from './limits-namespace.js';
5
6
  import { type HoldPoint, type InitializeOutcome, type StoreContext } from './mutate.js';
6
7
  import { type ProviderStateMutator, type UpdateProviderStateResult } from './provider-state.js';
7
8
  import { type PublicationReceipt, type PublishOptions, type PublishPlan, type PublishResult } from './publication.js';
@@ -191,9 +192,17 @@ export interface PoolStore {
191
192
  /**
192
193
  * One locked write of the plugin's settings (since 0.2.6) beside the pool,
193
194
  * in the config file. Refuses a result that sets a pool-owned key
194
- * (`invalid-input`). Takes `extraLocks`, then the store locks.
195
+ * (`invalid-input`). Carries commonAuthLimits through unchanged and refuses
196
+ * an explicit alteration to it. Takes `extraLocks`, then the store locks.
195
197
  */
196
198
  updateSettings(mutator: SettingsMutator, options?: UpdateSettingsOptions): Promise<UpdateSettingsResult>;
199
+ /**
200
+ * Merges commonAuthLimits with current row bindings in one config write.
201
+ * Requires a ready pool and takes only the store locks. May run in an
202
+ * onPersisted/onFailure hook or a pull, but not in a lock-held mutator.
203
+ * Optional so existing structural implementations remain compatible.
204
+ */
205
+ updateLimitsNamespace?(mutator: PoolLimitsMutator): Promise<void>;
197
206
  /**
198
207
  * Records the identity a lookup found for the row's credential. Since
199
208
  * 0.3.1 it takes the credential epoch the lookup was issued for, and
@@ -59,5 +59,7 @@ export declare function readPoolSettings(rt: StoreRuntime): Promise<SettingsRead
59
59
  * pool-owned key refuses (`invalid-input`) with nothing written; a result
60
60
  * equal to the current settings writes nothing. The state file is never
61
61
  * touched, and the pool-owned keys are written back exactly as read.
62
+ * commonAuthLimits is also carried through unchanged, even when omitted by
63
+ * the mutator; an explicit change to it refuses before writing anything.
62
64
  */
63
65
  export declare function updatePoolSettings(rt: StoreRuntime, mutator: SettingsMutator, options?: UpdateSettingsOptions): Promise<UpdateSettingsResult>;
@@ -55,6 +55,11 @@ export interface RuntimeLayoutLogger {
55
55
  info(message: string, meta?: Record<string, unknown>): unknown;
56
56
  warn(message: string, meta?: Record<string, unknown>): unknown;
57
57
  }
58
+ interface OldFileCleanupIO {
59
+ platform: NodeJS.Platform;
60
+ readFile(path: string): Promise<Buffer>;
61
+ unlink(path: string): Promise<void>;
62
+ }
58
63
  export interface RuntimeLayoutOptions {
59
64
  /** This build's version, for the version fence. */
60
65
  version: string;
@@ -74,8 +79,8 @@ export interface RuntimeLayoutOptions {
74
79
  */
75
80
  destinationPrivate?: (dir: string) => Promise<boolean>;
76
81
  /**
77
- * Test seams, run at one step of the move. A step that throws stands in for
78
- * a crash there: nothing after it runs.
82
+ * Test seams for the move. A step callback that throws stands in for a
83
+ * crash there: nothing after it runs.
79
84
  */
80
85
  steps?: {
81
86
  afterManifest?: () => void | Promise<void>;
@@ -87,6 +92,8 @@ export interface RuntimeLayoutOptions {
87
92
  * check that guards it.
88
93
  */
89
94
  beforeRemove?: (path: string) => void | Promise<void>;
95
+ /** Isolate old-copy comparison/removal from OS sharing races in tests. */
96
+ oldFileIO?: OldFileCleanupIO;
90
97
  };
91
98
  /** Test seam: how long to wait for the layout lock. */
92
99
  layoutLockWaitMs?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-layout.d.ts","sourceRoot":"","sources":["../../../src/runtime-layout.ts"],"names":[],"mappings":"AAiJA,OAAO,EACL,KAAK,kBAAkB,EAUvB,KAAK,aAAa,EAQnB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,KAAK,kBAAkB,EAAoB,MAAM,iBAAiB,CAAA;AAE3E,YAAY,EAAE,aAAa,EAAE,CAAA;AAM7B,yEAAyE;AACzE,eAAO,MAAM,wBAAwB,mBAAmB,CAAA;AACxD,4EAA4E;AAC5E,eAAO,MAAM,4BAA4B,uBAAuB,CAAA;AAEhE;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,mCAAmC,CAAA;AAK3E;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,8IAMnB,CAAA;AA8CV,yEAAyE;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IAAI,EAAE,MAAM,EAAE,EACd,IAAI,EAAE,eAAe,EACrB,eAAe,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACtC,EAAE,GAAE,OAAY,GACf,OAAO,CAAC,IAAI,CAAC,CAOf"}
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../../src/setup.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,EAIL,KAAK,oBAAoB,EAEzB,KAAK,OAAO,EACZ,KAAK,WAAW,EACjB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAA;AAsF9E;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,oBAAoB,CAAC,oBAAoB,CAAC,GACtD,OAAO,CAAC,IAAI,CAAC,CAwBf;AAED,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC,CAE7D;AA4CD,2EAA2E;AAC3E,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,+BAA+B,EACvC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,IAAI,CAAC,CAWf;AAED,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,eAAe,EACrB,eAAe,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACtC,UAAU,UAAQ,GACjB,OAAO,CAAC,WAAW,CAAC,CAoVtB;AAED,2FAA2F;AAC3F,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EAAE,EACd,IAAI,EAAE,eAAe,EACrB,eAAe,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACtC,EAAE,GAAE,OAAY,GACf,OAAO,CAAC,IAAI,CAAC,CAOf"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/opencode-antigravity-auth",
3
- "version": "3.0.29",
3
+ "version": "3.0.30",
4
4
  "description": "Google Antigravity OAuth auth plugin for OpenCode - access Gemini and Claude models using Google credentials",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -130,7 +130,7 @@
130
130
  "dependencies": {
131
131
  "@cortexkit/claustrum-client": "0.12.0",
132
132
  "@cortexkit/subc-client": "0.22.5",
133
- "@cortexkit/antigravity-auth-core": "3.0.29",
133
+ "@cortexkit/antigravity-auth-core": "3.0.30",
134
134
  "@cortexkit/private-files": "0.2.2",
135
135
  "jsonc-parser": "^3.3.1",
136
136
  "xdg-basedir": "^5.1.0",
@@ -6,6 +6,7 @@ import { type ClaustrumLogger } from './errors.js';
6
6
  import type { CustodyLease } from './hub.js';
7
7
  import { type InsulaQuotaOptions, type InsulaQuotaResult } from './insula.js';
8
8
  import { type AccountMapper, type ProjectionOptions, type QuotaReceipt, type ReorderVaultRosterResult, type VaultRosterFile } from './roster.js';
9
+ import type { ClaustrumUsageReading, ClaustrumUsageReportState } from './usage.js';
9
10
  import { type WatchMode } from './watch.js';
10
11
  export interface ClaustrumConsumerOptions<Q = QuotaObservation> {
11
12
  /**
@@ -229,6 +230,17 @@ export declare class ClaustrumConsumer<Q = QuotaObservation> {
229
230
  * poll, and a route whose credential or account changed is refused.
230
231
  */
231
232
  authorize(routeId: string, signal?: AbortSignal): Promise<ClaustrumScopedAttempt>;
233
+ /**
234
+ * Queue reply quota metadata without waiting or throwing. Pass rate-limit
235
+ * headers only, never tokens: the library does not filter header names.
236
+ * The credential must have been served by this host and still belong to the route.
237
+ */
238
+ reportUsage(input: {
239
+ routeId: string;
240
+ credentialId: string;
241
+ reading: ClaustrumUsageReading;
242
+ }): void;
243
+ usageReportState(): ClaustrumUsageReportState;
232
244
  reportFailure(attempt: ClaustrumScopedAttempt, status: number, source: ClaustrumReporterSource): Promise<void>;
233
245
  /**
234
246
  * Send on a vault route. `dispatch` builds and sends the request with the
@@ -738,6 +738,42 @@ export class ClaustrumConsumer {
738
738
  combined.dispose();
739
739
  }
740
740
  }
741
+ /**
742
+ * Queue reply quota metadata without waiting or throwing. Pass rate-limit
743
+ * headers only, never tokens: the library does not filter header names.
744
+ * The credential must have been served by this host and still belong to the route.
745
+ */
746
+ reportUsage(input) {
747
+ if (this.#shutdown.signal.aborted)
748
+ return;
749
+ try {
750
+ const row = this.#roster?.rows.find((row) => row.routeId === input.routeId);
751
+ if (!row?.enabled ||
752
+ row.state !== 'active' ||
753
+ (row.credentialId !== input.credentialId &&
754
+ !row.aliases?.includes(input.credentialId)))
755
+ return;
756
+ if (this.#hub) {
757
+ if (this.#lease && this.#hub.leaseLive(this.#lease))
758
+ this.#lease.custody.reportUsage(input);
759
+ }
760
+ else
761
+ this.#custody?.reportUsage(input);
762
+ }
763
+ catch {
764
+ // Quota bookkeeping must never reject a provider request.
765
+ }
766
+ }
767
+ usageReportState() {
768
+ try {
769
+ return ((this.#hub
770
+ ? this.#lease?.custody
771
+ : this.#custody)?.usageReportState() ?? { pending: 0, inFlight: false, dropped: 0 });
772
+ }
773
+ catch {
774
+ return { pending: 0, inFlight: false, dropped: 0 };
775
+ }
776
+ }
741
777
  async reportFailure(attempt, status, source) {
742
778
  this.#assertOpen();
743
779
  if (this.#hub) {
@@ -1,14 +1,15 @@
1
1
  import { type ClaustrumClient, type ClaustrumReporterSource, type EnrollmentTokenFile } from '@cortexkit/claustrum-client';
2
2
  import { type ClaustrumLogger } from './errors.js';
3
3
  import type { InsulaUsageTransport } from './insula.js';
4
+ import { type ClaustrumUsageReading, type ClaustrumUsageReportState, type ScopedUsageSource } from './usage.js';
4
5
  import { type ScopedWatchSource, type WatchMode } from './watch.js';
5
6
  /**
6
- * `watchScoped` is present from claustrum-client 0.12.0. Hosts detect it at
7
- * run time and keep polling without it.
7
+ * claustrum-client adds watchScoped in 0.12.0 and reportUsageScoped in 0.14.0.
8
+ * Older clients keep polling and simply do not send reply quota readings.
8
9
  */
9
10
  export type ClaustrumScopedClient = Pick<ClaustrumClient, 'listScoped' | 'getScoped' | 'reportAuthFailureScoped' | 'close'> & {
10
11
  insula?: InsulaUsageTransport;
11
- } & ScopedWatchSource;
12
+ } & ScopedWatchSource & ScopedUsageSource;
12
13
  /** The two credential types a plugin's family can hold; routing differs by type. */
13
14
  export type VaultCredentialType = 'oauth' | 'api_key';
14
15
  /**
@@ -332,7 +333,18 @@ export declare class ClaustrumScopedCustody {
332
333
  * other mode the host keeps its usual list timer.
333
334
  */
334
335
  watchRoster(options: ClaustrumRosterWatchOptions): ClaustrumRosterWatch;
336
+ /**
337
+ * Queue reply quota metadata and return synchronously. Pass rate-limit
338
+ * headers only, never tokens: the library does not filter header names.
339
+ * Only credentials served by this custody and retained in its roster report.
340
+ * Hosts managing their own roster must call retain() when that roster changes.
341
+ */
342
+ reportUsage(input: {
343
+ credentialId: string;
344
+ reading: ClaustrumUsageReading;
345
+ }): void;
346
+ usageReportState(): ClaustrumUsageReportState;
335
347
  close(): void;
336
- /** Stop immediately; allow token reads 2 s and share an owner's timeout warning. */
348
+ /** Stop accepting work; give token reads and reply reports one shared 2 s drain. */
337
349
  dispose(onTimeout?: (pendingOperations: number) => void): Promise<void>;
338
350
  }