@cortexkit/opencode-antigravity-auth 3.1.9 → 3.1.11

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/README.md +4 -0
  2. package/dist/cli.js +502 -160
  3. package/dist/cli.js.map +3 -3
  4. package/dist/cli.meta.json +52 -42
  5. package/dist/index.js +1306 -656
  6. package/dist/index.js.map +4 -4
  7. package/dist/index.meta.json +102 -74
  8. package/dist/server.js +1437 -767
  9. package/dist/server.js.map +4 -4
  10. package/dist/server.meta.json +1 -1
  11. package/dist/src/cli.d.ts +3 -1
  12. package/dist/src/cli.d.ts.map +1 -1
  13. package/dist/src/cli.js +19 -6
  14. package/dist/src/cli.js.map +1 -1
  15. package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +20 -1
  16. package/dist/src/common-auth-embedded/claustrum/consumer.js +32 -0
  17. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +54 -5
  18. package/dist/src/common-auth-embedded/claustrum/custody.js +176 -22
  19. package/dist/src/common-auth-embedded/claustrum/host.js +8 -0
  20. package/dist/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
  21. package/dist/src/common-auth-embedded/claustrum/hub.js +10 -0
  22. package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  23. package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +6 -1
  24. package/dist/src/common-auth-embedded/routing-accessor/index.js +5 -3
  25. package/dist/src/common-auth-embedded/setup/process-fence.js +20 -3
  26. package/dist/src/common-auth-embedded/source-output.json +41 -41
  27. package/dist/src/ga/rpc/protocol.d.ts +11 -5
  28. package/dist/src/ga/rpc/protocol.d.ts.map +1 -1
  29. package/dist/src/ga/rpc/protocol.js +11 -3
  30. package/dist/src/ga/rpc/protocol.js.map +1 -1
  31. package/dist/src/ga/server/index.d.ts.map +1 -1
  32. package/dist/src/ga/server/index.js +30 -14
  33. package/dist/src/ga/server/index.js.map +1 -1
  34. package/dist/src/ga/tui/host-ga.d.ts +2 -1
  35. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  36. package/dist/src/ga/tui/host-ga.js +9 -4
  37. package/dist/src/ga/tui/host-ga.js.map +1 -1
  38. package/dist/src/plugin/__fixtures__/release-model-ids.d.ts.map +1 -1
  39. package/dist/src/plugin/__fixtures__/release-model-ids.js +1 -0
  40. package/dist/src/plugin/__fixtures__/release-model-ids.js.map +1 -1
  41. package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
  42. package/dist/src/plugin/account-access.d.ts +1 -0
  43. package/dist/src/plugin/account-access.d.ts.map +1 -1
  44. package/dist/src/plugin/account-access.js +28 -0
  45. package/dist/src/plugin/account-access.js.map +1 -1
  46. package/dist/src/plugin/auth-loader.d.ts.map +1 -1
  47. package/dist/src/plugin/auth-loader.js +21 -12
  48. package/dist/src/plugin/auth-loader.js.map +1 -1
  49. package/dist/src/plugin/background-quota-refresh.d.ts +11 -24
  50. package/dist/src/plugin/background-quota-refresh.d.ts.map +1 -1
  51. package/dist/src/plugin/background-quota-refresh.js +54 -60
  52. package/dist/src/plugin/background-quota-refresh.js.map +1 -1
  53. package/dist/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
  54. package/dist/src/plugin/background-vault-quota-refresh.js +6 -3
  55. package/dist/src/plugin/background-vault-quota-refresh.js.map +1 -1
  56. package/dist/src/plugin/cache/signature-cache.d.ts +3 -0
  57. package/dist/src/plugin/cache/signature-cache.d.ts.map +1 -1
  58. package/dist/src/plugin/cache/signature-cache.js +73 -46
  59. package/dist/src/plugin/cache/signature-cache.js.map +1 -1
  60. package/dist/src/plugin/cache.d.ts.map +1 -1
  61. package/dist/src/plugin/cache.js +17 -7
  62. package/dist/src/plugin/cache.js.map +1 -1
  63. package/dist/src/plugin/config/models.d.ts +1 -1
  64. package/dist/src/plugin/config/models.d.ts.map +1 -1
  65. package/dist/src/plugin/config/models.js +10 -5
  66. package/dist/src/plugin/config/models.js.map +1 -1
  67. package/dist/src/plugin/core/streaming/displayed-thinking.d.ts +23 -0
  68. package/dist/src/plugin/core/streaming/displayed-thinking.d.ts.map +1 -0
  69. package/dist/src/plugin/core/streaming/displayed-thinking.js +58 -0
  70. package/dist/src/plugin/core/streaming/displayed-thinking.js.map +1 -0
  71. package/dist/src/plugin/fetch/warmup.d.ts +9 -2
  72. package/dist/src/plugin/fetch/warmup.d.ts.map +1 -1
  73. package/dist/src/plugin/fetch/warmup.js +22 -14
  74. package/dist/src/plugin/fetch/warmup.js.map +1 -1
  75. package/dist/src/plugin/quota.d.ts +10 -2
  76. package/dist/src/plugin/quota.d.ts.map +1 -1
  77. package/dist/src/plugin/quota.js +38 -10
  78. package/dist/src/plugin/quota.js.map +1 -1
  79. package/dist/src/plugin/request-helpers.d.ts.map +1 -1
  80. package/dist/src/plugin/request-helpers.js +51 -19
  81. package/dist/src/plugin/request-helpers.js.map +1 -1
  82. package/dist/src/plugin/request.d.ts +12 -1
  83. package/dist/src/plugin/request.d.ts.map +1 -1
  84. package/dist/src/plugin/request.js +34 -49
  85. package/dist/src/plugin/request.js.map +1 -1
  86. package/dist/src/plugin/shared/request-services.d.ts +4 -1
  87. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  88. package/dist/src/plugin/shared/request-services.js +142 -24
  89. package/dist/src/plugin/shared/request-services.js.map +1 -1
  90. package/dist/src/plugin/shared/runtime.d.ts +3 -4
  91. package/dist/src/plugin/shared/runtime.d.ts.map +1 -1
  92. package/dist/src/plugin/shared/runtime.js +2 -2
  93. package/dist/src/plugin/shared/runtime.js.map +1 -1
  94. package/dist/src/plugin/shared/vault-request-credentials.d.ts +13 -7
  95. package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  96. package/dist/src/plugin/shared/vault-request-credentials.js +24 -18
  97. package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
  98. package/dist/src/plugin/vault-sidebar-projection.d.ts.map +1 -1
  99. package/dist/src/setup.d.ts +3 -0
  100. package/dist/src/setup.d.ts.map +1 -1
  101. package/dist/src/setup.js +18 -6
  102. package/dist/src/setup.js.map +1 -1
  103. package/dist/src/sidebar-state.d.ts +20 -7
  104. package/dist/src/sidebar-state.d.ts.map +1 -1
  105. package/dist/src/sidebar-state.js +57 -8
  106. package/dist/src/sidebar-state.js.map +1 -1
  107. package/dist/src/tui.d.ts.map +1 -1
  108. package/dist/src/tui.js +43 -23
  109. package/dist/src/tui.js.map +1 -1
  110. package/dist/tui-build-map.json +9 -9
  111. package/dist/tui-ga-build-map.json +5 -5
  112. package/dist/types/src/cli.d.ts +3 -1
  113. package/dist/types/src/cli.d.ts.map +1 -1
  114. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +20 -1
  115. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +54 -5
  116. package/dist/types/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
  117. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  118. package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +6 -1
  119. package/dist/types/src/ga/rpc/protocol.d.ts +11 -5
  120. package/dist/types/src/ga/rpc/protocol.d.ts.map +1 -1
  121. package/dist/types/src/ga/server/index.d.ts.map +1 -1
  122. package/dist/types/src/plugin/account-access.d.ts +1 -0
  123. package/dist/types/src/plugin/account-access.d.ts.map +1 -1
  124. package/dist/types/src/plugin/auth-loader.d.ts.map +1 -1
  125. package/dist/types/src/plugin/background-quota-refresh.d.ts +11 -24
  126. package/dist/types/src/plugin/background-quota-refresh.d.ts.map +1 -1
  127. package/dist/types/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
  128. package/dist/types/src/plugin/cache/signature-cache.d.ts +3 -0
  129. package/dist/types/src/plugin/cache/signature-cache.d.ts.map +1 -1
  130. package/dist/types/src/plugin/cache.d.ts.map +1 -1
  131. package/dist/types/src/plugin/config/models.d.ts +1 -1
  132. package/dist/types/src/plugin/config/models.d.ts.map +1 -1
  133. package/dist/types/src/plugin/core/streaming/displayed-thinking.d.ts +23 -0
  134. package/dist/types/src/plugin/core/streaming/displayed-thinking.d.ts.map +1 -0
  135. package/dist/types/src/plugin/fetch/warmup.d.ts +9 -2
  136. package/dist/types/src/plugin/fetch/warmup.d.ts.map +1 -1
  137. package/dist/types/src/plugin/quota.d.ts +10 -2
  138. package/dist/types/src/plugin/quota.d.ts.map +1 -1
  139. package/dist/types/src/plugin/request-helpers.d.ts.map +1 -1
  140. package/dist/types/src/plugin/request.d.ts +12 -1
  141. package/dist/types/src/plugin/request.d.ts.map +1 -1
  142. package/dist/types/src/plugin/shared/request-services.d.ts +4 -1
  143. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  144. package/dist/types/src/plugin/shared/runtime.d.ts +3 -4
  145. package/dist/types/src/plugin/shared/runtime.d.ts.map +1 -1
  146. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +13 -7
  147. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  148. package/dist/types/src/plugin/vault-sidebar-projection.d.ts.map +1 -1
  149. package/dist/types/src/setup.d.ts +3 -0
  150. package/dist/types/src/setup.d.ts.map +1 -1
  151. package/dist/types/src/sidebar-state.d.ts +20 -7
  152. package/dist/types/src/sidebar-state.d.ts.map +1 -1
  153. package/package.json +3 -3
  154. package/src/common-auth-embedded/claustrum/consumer.d.ts +20 -1
  155. package/src/common-auth-embedded/claustrum/consumer.js +32 -0
  156. package/src/common-auth-embedded/claustrum/custody.d.ts +54 -5
  157. package/src/common-auth-embedded/claustrum/custody.js +176 -22
  158. package/src/common-auth-embedded/claustrum/host.js +8 -0
  159. package/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
  160. package/src/common-auth-embedded/claustrum/hub.js +10 -0
  161. package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  162. package/src/common-auth-embedded/routing-accessor/index.d.ts +6 -1
  163. package/src/common-auth-embedded/routing-accessor/index.js +5 -3
  164. package/src/common-auth-embedded/setup/process-fence.js +20 -3
  165. package/src/common-auth-embedded/source-output.json +41 -41
  166. package/src/sidebar-state.ts +77 -8
  167. package/src/tui-compiled/sidebar-state.js +40 -1
  168. package/src/tui-compiled/tui.js +49 -24
  169. package/src/tui-ga-compiled/host-ga.js +11 -5
  170. package/src/tui-ga-raw/host-ga.tsx +17 -6
  171. package/src/tui-raw/sidebar-state.js +40 -1
  172. package/src/tui-raw/tui.tsx +40 -24
  173. package/src/tui.tsx +40 -24
@@ -145,22 +145,66 @@ function credentialTypeOf(row, family) {
145
145
  }
146
146
  return { kind: 'refused', code: 'unclassified' };
147
147
  }
148
- if (row.credentialType !== 'oauth' && row.credentialType !== 'api_key')
148
+ const type = row.credentialType;
149
+ if (type === 'oauth') {
150
+ if (row.refreshAdapter !== family.refreshAdapter)
151
+ return notMine;
152
+ }
153
+ else if (type === 'api_key') {
154
+ if (!family.apiKeys || row.refreshAdapter !== undefined)
155
+ return notMine;
156
+ }
157
+ else {
149
158
  return notMine;
150
- if (row.credentialType === 'oauth')
151
- return row.refreshAdapter === family.refreshAdapter
152
- ? { kind: 'mine', type: 'oauth' }
153
- : notMine;
154
- if (row.credentialType === 'api_key' && family.apiKeys)
155
- return row.refreshAdapter === undefined
156
- ? { kind: 'mine', type: 'api_key' }
157
- : notMine;
158
- return notMine;
159
+ }
160
+ const { authMethod } = rowFactsOf(row, { includeProviderIds: false });
161
+ // Older vaults omit the method. If present, it must match the serving type.
162
+ if (authMethod !== undefined) {
163
+ const matchesType = type === 'oauth'
164
+ ? authMethod === 'chatgpt' ||
165
+ authMethod === 'antigravity' ||
166
+ authMethod === 'oauth'
167
+ : authMethod === 'apikey';
168
+ if (!matchesType)
169
+ return { kind: 'refused', code: 'unknown-auth-method' };
170
+ }
171
+ return { kind: 'mine', type };
159
172
  }
160
173
  /** Structural access keeps the public facts independent of client declarations. */
161
- function rowFactsOf(row) {
174
+ function rowFactsOf(row, { includeProviderIds = true } = {}) {
162
175
  const metadata = row;
163
- return { providerIds: metadata.providerIds, authMethod: metadata.authMethod };
176
+ return {
177
+ providerIds: includeProviderIds ? metadata.providerIds : undefined,
178
+ authMethod: metadata.authMethod,
179
+ };
180
+ }
181
+ function isVaultConditionReason(reason) {
182
+ return (reason === 'provider_verification_required' ||
183
+ reason === 'provider_ineligible');
184
+ }
185
+ function vaultConditionOf(row) {
186
+ const condition = row.condition;
187
+ if (!condition)
188
+ return undefined;
189
+ const { reason, sinceMs } = condition;
190
+ if (isVaultConditionReason(reason) &&
191
+ Number.isSafeInteger(sinceMs) &&
192
+ sinceMs > 0)
193
+ return Object.freeze({ reason, sinceMs });
194
+ return undefined;
195
+ }
196
+ function httpsActionUrl(actionUrl) {
197
+ if (typeof actionUrl !== 'string')
198
+ return undefined;
199
+ try {
200
+ // Keep the original spelling so the vault can enforce its own link rules.
201
+ if (new URL(actionUrl).protocol === 'https:')
202
+ return actionUrl;
203
+ }
204
+ catch {
205
+ // An unparseable link does not invalidate the condition itself.
206
+ }
207
+ return undefined;
164
208
  }
165
209
  /**
166
210
  * The grants named in the vault's list reply, or undefined when it names none.
@@ -195,6 +239,10 @@ export class ClaustrumScopedCustody {
195
239
  #logger;
196
240
  #provenance = new WeakMap();
197
241
  #reports = new WeakMap();
242
+ #conditionReports = new Map();
243
+ #conditionClears = new Map();
244
+ #conditionsUnsupported = false;
245
+ #pendingConditionCalls = 0;
198
246
  #kept = new Map();
199
247
  #keptAttempts = new WeakMap();
200
248
  #usage;
@@ -213,8 +261,9 @@ export class ClaustrumScopedCustody {
213
261
  #closed = false;
214
262
  /** The view of the last successful `discover()`, for `watchRoster`. */
215
263
  #discoveredView;
264
+ #discoveredConditions = new Map();
216
265
  #watches = new Set();
217
- #tokenReads = new Set();
266
+ #shutdownWork = new Set();
218
267
  #warnShutdown;
219
268
  #onDrainTimeout;
220
269
  #disposing;
@@ -276,6 +325,7 @@ export class ClaustrumScopedCustody {
276
325
  if (hasVaultHost() && !isVaultHostClient(next))
277
326
  throw new ClaustrumUnreachableError();
278
327
  this.#client = next;
328
+ this.#conditionsUnsupported = false;
279
329
  for (const watch of this.#watches)
280
330
  watch.restart();
281
331
  }
@@ -356,13 +406,13 @@ export class ClaustrumScopedCustody {
356
406
  phase: 'token read begin',
357
407
  });
358
408
  const pending = this.#readToken();
359
- this.#tokenReads.add(pending);
409
+ this.#shutdownWork.add(pending);
360
410
  let value;
361
411
  try {
362
412
  value = await pending;
363
413
  }
364
414
  finally {
365
- this.#tokenReads.delete(pending);
415
+ this.#shutdownWork.delete(pending);
366
416
  if (phaseDiagnostics.hasSubscribers)
367
417
  phaseDiagnostics.publish({
368
418
  logger: this.#logger,
@@ -422,6 +472,11 @@ export class ClaustrumScopedCustody {
422
472
  async discover(signal) {
423
473
  const inventory = await this.#list(signal);
424
474
  this.#discoveredView = inventory.view;
475
+ this.#discoveredConditions.clear();
476
+ for (const { credentialId, condition } of inventory.credentials) {
477
+ if (condition)
478
+ this.#discoveredConditions.set(credentialId, condition);
479
+ }
425
480
  return inventory;
426
481
  }
427
482
  async #list(signal) {
@@ -498,6 +553,7 @@ export class ClaustrumScopedCustody {
498
553
  });
499
554
  continue;
500
555
  }
556
+ const condition = vaultConditionOf(row);
501
557
  credentials.push(Object.freeze({
502
558
  credentialId: row.id,
503
559
  credentialType: type,
@@ -508,19 +564,21 @@ export class ClaustrumScopedCustody {
508
564
  state: row.state,
509
565
  ...(row.email !== undefined && { email: row.email }),
510
566
  ...(row.orgName !== undefined && { orgName: row.orgName }),
567
+ ...(condition && { condition }),
511
568
  }));
512
569
  }
513
570
  for (const record of skipped)
514
571
  this.#logger.warn('skipped malformed vault record', record);
515
572
  const grantReach = grantReachOf(inventory);
573
+ const classifying = 'classify' in this.#family;
516
574
  return {
517
575
  view: inventory.view,
518
576
  credentials: Object.freeze(credentials),
519
577
  skipped: Object.freeze(skipped),
520
- ...('classify' in this.#family && {
578
+ ...((classifying || refused.length > 0) && {
521
579
  refused: Object.freeze(refused),
522
- notMine,
523
580
  }),
581
+ ...(classifying && { notMine }),
524
582
  ...(grantReach && { grantReach }),
525
583
  };
526
584
  }
@@ -909,6 +967,101 @@ export class ClaustrumScopedCustody {
909
967
  throw error;
910
968
  }
911
969
  }
970
+ /**
971
+ * Report a provider login condition as bookkeeping after handing back the
972
+ * reply, never on the request path. Pass the receipt actually sent with it.
973
+ */
974
+ reportCondition(attempt, input) {
975
+ const provenance = this.#provenance.get(attempt);
976
+ if (!provenance)
977
+ return Promise.reject(new ClaustrumConsumerError('no-receipt', 'Claustrum condition report requires an original dispatch receipt'));
978
+ const { reason, providerStatus } = input ?? {};
979
+ if (this.#closed ||
980
+ this.#keptAttempts.has(attempt) ||
981
+ providerStatus !== 403 ||
982
+ !isVaultConditionReason(reason))
983
+ return Promise.resolve('skipped');
984
+ const { credentialId, recordVersion } = attempt;
985
+ const actionUrl = reason === 'provider_verification_required'
986
+ ? httpsActionUrl(input.actionUrl)
987
+ : undefined;
988
+ return this.#conditionOnce(this.#conditionReports, JSON.stringify([credentialId, recordVersion, reason]), { credentialId, recordVersion, reason }, (client) => client.reportCondition?.({
989
+ credentialId,
990
+ recordVersion,
991
+ reason,
992
+ providerStatus,
993
+ ...(actionUrl !== undefined && { actionUrl }),
994
+ enrollmentToken: provenance.token,
995
+ }));
996
+ }
997
+ /**
998
+ * Clear a listed condition as bookkeeping after handing back a successful
999
+ * reply, never on the request path. Pass the receipt actually sent with it.
1000
+ */
1001
+ clearCondition(attempt) {
1002
+ const provenance = this.#provenance.get(attempt);
1003
+ if (!provenance)
1004
+ return Promise.reject(new ClaustrumConsumerError('no-receipt', 'Claustrum condition clear requires an original dispatch receipt'));
1005
+ if (this.#closed || this.#keptAttempts.has(attempt))
1006
+ return Promise.resolve('skipped');
1007
+ const { credentialId, recordVersion } = attempt;
1008
+ const condition = this.#discoveredConditions.get(credentialId);
1009
+ if (!condition)
1010
+ return Promise.resolve('skipped');
1011
+ return this.#conditionOnce(this.#conditionClears, JSON.stringify([credentialId, condition.sinceMs]), { credentialId, recordVersion, reason: condition.reason }, (client) => client.clearCondition?.({
1012
+ credentialId,
1013
+ recordVersion,
1014
+ enrollmentToken: provenance.token,
1015
+ }));
1016
+ }
1017
+ #conditionOnce(outcomes, key, details, send) {
1018
+ const previous = outcomes.get(key);
1019
+ if (previous)
1020
+ return previous;
1021
+ if (this.#conditionsUnsupported)
1022
+ return Promise.resolve('unsupported');
1023
+ // A lost reply may already have committed. Keep the result so a later call
1024
+ // for the same key does not retry it, even after client replacement.
1025
+ const pending = Promise.resolve().then(async () => {
1026
+ const client = this.#client;
1027
+ if (this.#conditionsUnsupported)
1028
+ return 'unsupported';
1029
+ try {
1030
+ const sent = send(client);
1031
+ if (!sent)
1032
+ return 'unsupported';
1033
+ if ((await sent) === false)
1034
+ this.#debugCondition('scoped login condition not cleared', details);
1035
+ return 'reported';
1036
+ }
1037
+ catch (error) {
1038
+ if (error instanceof ClaustrumCredentialError &&
1039
+ error.code === 'unknown_method') {
1040
+ if (client === this.#client)
1041
+ this.#conditionsUnsupported = true;
1042
+ return 'unsupported';
1043
+ }
1044
+ this.#debugCondition('scoped login condition update failed', details);
1045
+ return 'failed';
1046
+ }
1047
+ });
1048
+ outcomes.set(key, pending);
1049
+ this.#pendingConditionCalls++;
1050
+ this.#shutdownWork.add(pending);
1051
+ void pending.then(() => {
1052
+ this.#pendingConditionCalls--;
1053
+ this.#shutdownWork.delete(pending);
1054
+ });
1055
+ return pending;
1056
+ }
1057
+ #debugCondition(message, details) {
1058
+ try {
1059
+ this.#logger.debug(message, details);
1060
+ }
1061
+ catch {
1062
+ // A caller's logger must not turn bookkeeping into a rejection.
1063
+ }
1064
+ }
912
1065
  /**
913
1066
  * Watch this consumer's visible vault accounts instead of listing them on a
914
1067
  * short timer. Opens one `watchScoped` on this custody's client and calls
@@ -1029,16 +1182,17 @@ export class ClaustrumScopedCustody {
1029
1182
  this.#watches.clear();
1030
1183
  this.#kept.clear();
1031
1184
  const usage = this.#usage.close();
1185
+ const keepClientOpen = usage !== undefined || this.#pendingConditionCalls > 0;
1032
1186
  if (usage) {
1033
- this.#tokenReads.add(usage);
1034
- void usage.then(() => this.#tokenReads.delete(usage));
1187
+ this.#shutdownWork.add(usage);
1188
+ void usage.then(() => this.#shutdownWork.delete(usage));
1035
1189
  }
1036
- else
1190
+ if (!keepClientOpen)
1037
1191
  this.#client.close();
1038
- this.#disposing = drainShutdown(this.#tokenReads, (count) => (this.#onDrainTimeout ?? this.#warnShutdown)(count)).finally(() => {
1192
+ this.#disposing = drainShutdown(this.#shutdownWork, (count) => (this.#onDrainTimeout ?? this.#warnShutdown)(count)).finally(() => {
1039
1193
  this.#usage.drop();
1040
1194
  this.#usageServed.clear();
1041
- if (usage)
1195
+ if (keepClientOpen)
1042
1196
  this.#client.close();
1043
1197
  });
1044
1198
  }
@@ -55,6 +55,8 @@ async function request(operation) {
55
55
  function wrapHostClient(client) {
56
56
  const watchScoped = client.watchScoped?.bind(client);
57
57
  const reportUsageScoped = client.reportUsageScoped?.bind(client);
58
+ const reportCondition = client.reportCondition?.bind(client);
59
+ const clearCondition = client.clearCondition?.bind(client);
58
60
  return {
59
61
  listScoped: (...args) => request(() => client.listScoped(...args)),
60
62
  getScoped: (...args) => request(() => client.getScoped(...args)),
@@ -77,6 +79,12 @@ function wrapHostClient(client) {
77
79
  ...(reportUsageScoped && {
78
80
  reportUsageScoped: (...args) => request(() => reportUsageScoped(...args)),
79
81
  }),
82
+ ...(reportCondition && {
83
+ reportCondition: (...args) => request(() => reportCondition(...args)),
84
+ }),
85
+ ...(clearCondition && {
86
+ clearCondition: (...args) => request(() => clearCondition(...args)),
87
+ }),
80
88
  ...(client.insula && {
81
89
  insula: wrapInsula(client.insula),
82
90
  }),
@@ -111,12 +111,13 @@ export interface ClaustrumHubMemberOptions<_Q = QuotaObservation> {
111
111
  logger?: ClaustrumLogger;
112
112
  }
113
113
  /** What a lease may do with the shared custody. */
114
- export type ClaustrumLeasedCustody = Pick<ClaustrumScopedCustody, 'authorize' | 'reportFailure' | 'reportUsage' | 'usageReportState' | 'forget' | 'keptReceiptState'>;
114
+ export type ClaustrumLeasedCustody = Pick<ClaustrumScopedCustody, 'authorize' | 'reportFailure' | 'reportCondition' | 'clearCondition' | 'reportUsage' | 'usageReportState' | 'forget' | 'keptReceiptState'>;
115
115
  /**
116
116
  * One acquisition of the hub's shared custody. `custody` throws `closed`
117
117
  * after `release()`, and once the connection it belongs to ended for any
118
118
  * reason, vault mode going off included. Best-effort `reportUsage` instead
119
- * ignores reports through an ended lease. `release()` is idempotent.
119
+ * ignores reports through an ended lease, and the condition calls resolve
120
+ * `skipped` through one. `release()` is idempotent.
120
121
  */
121
122
  export interface CustodyLease {
122
123
  readonly custody: ClaustrumLeasedCustody;
@@ -533,6 +533,16 @@ export class ClaustrumDiscoveryHub {
533
533
  check();
534
534
  return custody.reportFailure(attempt, status, source);
535
535
  },
536
+ reportCondition: async (attempt, input) => {
537
+ if (state.released || generation.ended)
538
+ return 'skipped';
539
+ return custody.reportCondition(attempt, input);
540
+ },
541
+ clearCondition: async (attempt) => {
542
+ if (state.released || generation.ended)
543
+ return 'skipped';
544
+ return custody.clearCondition(attempt);
545
+ },
536
546
  reportUsage: (input) => {
537
547
  if (!state.released && !generation.ended)
538
548
  custody.reportUsage(input);
@@ -3,7 +3,7 @@ import type { ClaustrumScopedClient } from './custody.js';
3
3
  export { ClaustrumCredentialError, type ClaustrumReporterSource, type EnrollmentTokenFile, } from '@cortexkit/claustrum-client';
4
4
  export { ClaustrumUnreachableError, classifyVaultFailure, VAULT_FAILURE_CLASSES, type VaultFailureClass, } from './availability.js';
5
5
  export { ClaustrumConsumer, type ClaustrumConsumerOptions, type ClaustrumWatchState, DEFAULT_CONNECT_TIMEOUT_MS, type SendOptions, } from './consumer.js';
6
- export { type AccountIdentitySource, type ClassifyingClaustrumFamily, type ClaustrumFamily, type ClaustrumFamilyInput, type ClaustrumRosterWatch, type ClaustrumRosterWatchOptions, type ClaustrumScopedAttempt, type ClaustrumScopedClient, ClaustrumScopedCustody, type ClaustrumScopedIdentity, decideScopedRetryAfter401, type IdentityParser, isScopedCredentialRotation, KEPT_RECEIPT_MARGIN_MS, type KeptReceiptState, type ScopedRetryReason, SERVING_MARGIN_MS, type SkippedVaultReason, type SkippedVaultRecord, VAULT_RECEIPT_WAIT_MS, VAULT_YOUNG_OUTAGE_MS, type VaultCredential, type VaultCredentialType, type VaultGrantReach, type VaultGrantTuple, type VaultInventory, type VaultRowFacts, } from './custody.js';
6
+ export { type AccountIdentitySource, type ClassifyingClaustrumFamily, type ClaustrumFamily, type ClaustrumFamilyInput, type ClaustrumRosterWatch, type ClaustrumRosterWatchOptions, type ClaustrumScopedAttempt, type ClaustrumScopedClient, ClaustrumScopedCustody, type ClaustrumScopedIdentity, decideScopedRetryAfter401, type IdentityParser, isScopedCredentialRotation, KEPT_RECEIPT_MARGIN_MS, type KeptReceiptState, type ScopedRetryReason, SERVING_MARGIN_MS, type SkippedVaultReason, type SkippedVaultRecord, VAULT_RECEIPT_WAIT_MS, VAULT_YOUNG_OUTAGE_MS, type VaultConditionOutcome, type VaultConditionReason, type VaultCredential, type VaultCredentialType, type VaultGrantReach, type VaultGrantTuple, type VaultInventory, type VaultRowFacts, } from './custody.js';
7
7
  export { type ClaustrumEnrollmentClient, type ClaustrumEnrollmentConnection, type ClaustrumEnrollmentDisconnectResult, ClaustrumEnrollmentManager, type ClaustrumEnrollmentPaths, type ClaustrumEnrollmentResetResult, type ClaustrumEnrollmentStatus, type ClaustrumRequestedGrant, classifyEnrollmentError, connectClaustrumEnrollmentClient, disconnectClaustrumEnrollment, type EnrollmentDisposition, enrollmentAuthority, enrollmentName, getClaustrumEnrollmentPaths, hostEnrollmentPaths, RETRYABLE_ENROLLMENT_CODES, readClaustrumEnrollmentStatus, readClaustrumEnrollmentToken, resetClaustrumEnrollmentState, TERMINAL_ENROLLMENT_CODES, validEnrollmentDisplayName, validEnrollmentRequestedGrants, vaultAuthority, } from './enrollment.js';
8
8
  export { ClaustrumConsumerError, type ClaustrumConsumerFailureKind, type ClaustrumLogger, } from './errors.js';
9
9
  export { connectVaultHost, hasVaultHost, VAULT_HOST_CONNECT_REFUSAL, VAULT_HOST_STATUS, } from './host.js';
@@ -37,7 +37,12 @@ export type AskRoutingInput<Candidate extends RoutingCandidate = RoutingCandidat
37
37
  sessionId: string;
38
38
  provider: string;
39
39
  modelId: string;
40
- /** Only routes eligible under the vault and the user's configured rules. */
40
+ /**
41
+ * The routable set: routes the vault allows, minus any the user's own rules
42
+ * exclude. It is not the account the plugin's local selection would choose,
43
+ * so it can include routes that selection would skip for model or quota
44
+ * reasons; routing picks among them.
45
+ */
41
46
  candidates: readonly Candidate[];
42
47
  /** Defaults to 1500 ms, above routing's normal tail; clamped to 1–2000 ms. */
43
48
  deadlineMs?: number;
@@ -184,8 +184,6 @@ function candidateView(candidates) {
184
184
  accounts.push({ account_id: accountId, credential_id: credentialId });
185
185
  }
186
186
  }
187
- if (accounts.length === 0)
188
- return undefined;
189
187
  const lines = accounts
190
188
  .map(({ account_id, credential_id }) => Buffer.from(`${account_id}\t${credential_id}\n`, 'utf8'))
191
189
  .sort(Buffer.compare);
@@ -290,7 +288,11 @@ export async function askRouting(input) {
290
288
  request.warm_credential = warmCredentialId;
291
289
  }
292
290
  const candidates = candidateView(input.candidates);
293
- if (candidates)
291
+ // A first ask with nothing usable sends no view, so routing is unrestricted
292
+ // as before. A continue ask always sends one: an empty view after the only
293
+ // account was refused tells routing nothing is left to offer, where a
294
+ // missing view would let it hand back the refused account.
295
+ if (candidates.accounts.length > 0 || request.mode === 'continue')
294
296
  request.candidates = candidates;
295
297
  const pending = accountFor.call(handle, request, { deadlineMs });
296
298
  if (!isObject(pending) || typeof pending.then !== 'function')
@@ -1,7 +1,9 @@
1
1
  import { statSync } from 'node:fs';
2
2
  import { win32 } from 'node:path';
3
+ import { createLogger } from '../logger/index.js';
3
4
  import { defaultCommandRunner } from './command-runner.js';
4
5
  const WINDOWS_CIM_TIMEOUT_MS = 45_000;
6
+ const log = createLogger('setup-process-fence');
5
7
  // Native Windows PowerShell 5.1 on ARM took 22–44 s per process query, with
6
8
  // one cold CIM timeout at 45.8 s; pwsh took less than a second. See
7
9
  // .cortexkit/internal-docs/investigations/windows-arm-process-fence/report.md.
@@ -207,7 +209,7 @@ export async function listSetupProcesses(runner = defaultCommandRunner, options
207
209
  options.onStep?.({ ...inspection });
208
210
  }
209
211
  };
210
- const inspectCim = (args) => {
212
+ const inspectCim = async (args) => {
211
213
  const pwsh = win32.resolve(windowsEnv(env, 'ProgramFiles') ?? 'C:\\Program Files', 'PowerShell', '7', 'pwsh.exe');
212
214
  const program = (options.isFile ?? isFile)(pwsh) ? 'pwsh' : 'powershell';
213
215
  const arm64 = (windowsEnv(env, 'PROCESSOR_ARCHITEW6432') ??
@@ -215,9 +217,24 @@ export async function listSetupProcesses(runner = defaultCommandRunner, options
215
217
  const slow = program === 'powershell' && arm64;
216
218
  if (slow)
217
219
  options.onProgress?.('Checking that OpenCode and Pi are not running. Without PowerShell 7 this can take up to a minute on Windows ARM; installing PowerShell 7 makes it fast.');
218
- return inspect('CIM', program === 'pwsh'
220
+ const file = program === 'pwsh'
219
221
  ? pwsh
220
- : win32.resolve(system32, 'WindowsPowerShell', 'v1.0', 'powershell.exe'), args, slow ? WINDOWS_ARM_POWERSHELL_TIMEOUT_MS : WINDOWS_CIM_TIMEOUT_MS, program);
222
+ : win32.resolve(system32, 'WindowsPowerShell', 'v1.0', 'powershell.exe');
223
+ const timeoutMs = slow
224
+ ? WINDOWS_ARM_POWERSHELL_TIMEOUT_MS
225
+ : WINDOWS_CIM_TIMEOUT_MS;
226
+ const started = performance.now();
227
+ const result = await inspect('CIM', file, args, timeoutMs, program);
228
+ const remaining = Math.floor(timeoutMs - (performance.now() - started));
229
+ if ((result.exitCode === 3221225477 || result.exitCode === -1073741819) &&
230
+ !result.timedOut &&
231
+ !result.signal &&
232
+ !result.spawnError &&
233
+ remaining > 0) {
234
+ log.warn('Windows process query crashed with an access violation; retrying once');
235
+ return inspect('CIM', file, args, remaining, program);
236
+ }
237
+ return result;
221
238
  };
222
239
  try {
223
240
  if (windows && options.hostImagesOnly) {
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "schema": 1,
3
3
  "package": "@cortexkit/common-auth",
4
- "version": "0.55.0",
4
+ "version": "0.56.1",
5
5
  "artifactStatus": "published",
6
- "archiveBytes": 502568,
6
+ "archiveBytes": 505365,
7
7
  "publicRoots": {
8
8
  "./rpc": {
9
9
  "types": "./dist/rpc/index.d.ts",
@@ -74,16 +74,16 @@
74
74
  "import": "./src/quota-sidebar/index.tsx"
75
75
  }
76
76
  },
77
- "input": "tools/common-auth-build/inputs/cortexkit-common-auth-0.55.0.tgz",
78
- "tarballSha256": "b629e10e9a39c5b1e6dc7576c2d5814a23a5bbb2dad8d6c1ccddb759c14d200c",
79
- "sri": "sha512-EScwmEDdxSdW/z+6n1v630bsTdAUSQYBuG4l16yziRqptG4MhjCAoH6aNelSy/I3hIJ2j6bV3IcqteoGWBLpSg==",
80
- "shasum": "8a5d3a07ec72662120305388d051c0bdcee416f4",
77
+ "input": "tools/common-auth-build/inputs/cortexkit-common-auth-0.56.1.tgz",
78
+ "tarballSha256": "32ce3a411b3a8f8034e4c5eb5b79550d7529834567520943ca962d1b13512aa0",
79
+ "sri": "sha512-5JTuezeHbodZacTXEB6mjoicODWsCYh6J/APShcB11/92KAz8xJjcLG+MVmDK+QtL2VmBNwa7yhHCFiKqqIKww==",
80
+ "shasum": "f8b2504321810ab59a448effc2c485c601a039de",
81
81
  "canonicalFiles": 257,
82
- "canonicalBytes": 1522655,
82
+ "canonicalBytes": 1535775,
83
83
  "generator": {
84
84
  "path": "packages/opencode/scripts/embed-common-auth.ts",
85
85
  "version": 4,
86
- "sha256": "d4f9c099ec2dd6a53cd0b7a35e5571be94e24176c7e01347e4ea20b92eed13fd"
86
+ "sha256": "4b56cc532fc60af40ef271ae24ab502d7b03e6b546f968066fe7997fc454de60"
87
87
  },
88
88
  "files": [
89
89
  {
@@ -265,33 +265,33 @@
265
265
  {
266
266
  "source": "package/dist/claustrum/consumer.d.ts",
267
267
  "output": "claustrum/consumer.d.ts",
268
- "bytes": 14722,
269
- "sourceSha256": "b4c4a006089b95a5b553fcc03b598851535ba8e5d184c277b7b2fa5ce172f7d9",
270
- "outputSha256": "b4c4a006089b95a5b553fcc03b598851535ba8e5d184c277b7b2fa5ce172f7d9",
268
+ "bytes": 15756,
269
+ "sourceSha256": "3118eb0112ebb100c4f0ec8528eae840fee076b99e39d30c9c204042a9e2fc5e",
270
+ "outputSha256": "3118eb0112ebb100c4f0ec8528eae840fee076b99e39d30c9c204042a9e2fc5e",
271
271
  "transform": "verbatim"
272
272
  },
273
273
  {
274
274
  "source": "package/dist/claustrum/consumer.js",
275
275
  "output": "claustrum/consumer.js",
276
- "bytes": 41187,
277
- "sourceSha256": "c566f9a86fcd7cacb64901f68d4d0399424e2f27135bbdc1855f5c8262be9604",
278
- "outputSha256": "c566f9a86fcd7cacb64901f68d4d0399424e2f27135bbdc1855f5c8262be9604",
276
+ "bytes": 42662,
277
+ "sourceSha256": "c257a0ed546c9e55ee93a77a3d2247d8e65274f0dfb944b676f9da1ad23a3df5",
278
+ "outputSha256": "c257a0ed546c9e55ee93a77a3d2247d8e65274f0dfb944b676f9da1ad23a3df5",
279
279
  "transform": "verbatim"
280
280
  },
281
281
  {
282
282
  "source": "package/dist/claustrum/custody.d.ts",
283
283
  "output": "claustrum/custody.d.ts",
284
- "bytes": 18127,
285
- "sourceSha256": "8c4cb2f52551ae36a32c4e68201767df0d19ba396302ed6c2d723d0e066166f6",
286
- "outputSha256": "8c4cb2f52551ae36a32c4e68201767df0d19ba396302ed6c2d723d0e066166f6",
284
+ "bytes": 20105,
285
+ "sourceSha256": "3e18a29925889dc0bcae4a23b57df3b6bf683ba9a3e58fe95d3132ca50a2417e",
286
+ "outputSha256": "3e18a29925889dc0bcae4a23b57df3b6bf683ba9a3e58fe95d3132ca50a2417e",
287
287
  "transform": "verbatim"
288
288
  },
289
289
  {
290
290
  "source": "package/dist/claustrum/custody.js",
291
291
  "output": "claustrum/custody.js",
292
- "bytes": 43686,
293
- "sourceSha256": "174adfdaa909149453a34666fdf656aff90c7357e0000338c5a0a2a29d7c1e90",
294
- "outputSha256": "174adfdaa909149453a34666fdf656aff90c7357e0000338c5a0a2a29d7c1e90",
292
+ "bytes": 50079,
293
+ "sourceSha256": "fdb2f9a4eee791b44d6bb953d31bb7f560159302e2f83932c03964e1ae24cf22",
294
+ "outputSha256": "fdb2f9a4eee791b44d6bb953d31bb7f560159302e2f83932c03964e1ae24cf22",
295
295
  "transform": "verbatim"
296
296
  },
297
297
  {
@@ -353,33 +353,33 @@
353
353
  {
354
354
  "source": "package/dist/claustrum/host.js",
355
355
  "output": "claustrum/host.js",
356
- "bytes": 4610,
357
- "sourceSha256": "c2eba15f35b996993ba7f0ec849ce84312d5f08e9b15e8f6458c6d8a0e03ae7b",
358
- "outputSha256": "c2eba15f35b996993ba7f0ec849ce84312d5f08e9b15e8f6458c6d8a0e03ae7b",
356
+ "bytes": 4993,
357
+ "sourceSha256": "d2e197db15bfe75de41a892709f4d7d69248293bd80bb5a720b9035e961ec6d7",
358
+ "outputSha256": "d2e197db15bfe75de41a892709f4d7d69248293bd80bb5a720b9035e961ec6d7",
359
359
  "transform": "verbatim"
360
360
  },
361
361
  {
362
362
  "source": "package/dist/claustrum/hub.d.ts",
363
363
  "output": "claustrum/hub.d.ts",
364
- "bytes": 9719,
365
- "sourceSha256": "489a3214a386ad2329d7348288c371d41e79427bfc2daa91e2743cd4ddeccec9",
366
- "outputSha256": "489a3214a386ad2329d7348288c371d41e79427bfc2daa91e2743cd4ddeccec9",
364
+ "bytes": 9816,
365
+ "sourceSha256": "71196e15856a31236ae0f77f2e8b37d5216e5f7d42170a1eda27a154d1542b67",
366
+ "outputSha256": "71196e15856a31236ae0f77f2e8b37d5216e5f7d42170a1eda27a154d1542b67",
367
367
  "transform": "verbatim"
368
368
  },
369
369
  {
370
370
  "source": "package/dist/claustrum/hub.js",
371
371
  "output": "claustrum/hub.js",
372
- "bytes": 48395,
373
- "sourceSha256": "77bb04f1e6956eb2419b4d497fd2c478f59833f0a1bcc7650a090bd5c8a6ec23",
374
- "outputSha256": "77bb04f1e6956eb2419b4d497fd2c478f59833f0a1bcc7650a090bd5c8a6ec23",
372
+ "bytes": 48839,
373
+ "sourceSha256": "31af42582b6e9694ce334403bc3105fce8864c12d69146f4938a7300a1f718ce",
374
+ "outputSha256": "31af42582b6e9694ce334403bc3105fce8864c12d69146f4938a7300a1f718ce",
375
375
  "transform": "verbatim"
376
376
  },
377
377
  {
378
378
  "source": "package/dist/claustrum/index.d.ts",
379
379
  "output": "claustrum/index.d.ts",
380
- "bytes": 5073,
381
- "sourceSha256": "9e6722e2c38df279563804af98297aa6558efd8e50eb253e348a23b22e6e9785",
382
- "outputSha256": "9e6722e2c38df279563804af98297aa6558efd8e50eb253e348a23b22e6e9785",
380
+ "bytes": 5128,
381
+ "sourceSha256": "522249e709781475b8458130a72ea6885e16e8ea59821100bead9f23ae34ddcb",
382
+ "outputSha256": "522249e709781475b8458130a72ea6885e16e8ea59821100bead9f23ae34ddcb",
383
383
  "transform": "verbatim"
384
384
  },
385
385
  {
@@ -1697,9 +1697,9 @@
1697
1697
  {
1698
1698
  "source": "package/dist/setup/process-fence.js",
1699
1699
  "output": "setup/process-fence.js",
1700
- "bytes": 15880,
1701
- "sourceSha256": "1d7ee431c9b63aec37e1868df53f0f9c776ccd45d7935282493d1f1d3d6c6127",
1702
- "outputSha256": "1d7ee431c9b63aec37e1868df53f0f9c776ccd45d7935282493d1f1d3d6c6127",
1700
+ "bytes": 16615,
1701
+ "sourceSha256": "008c119bd1cbac550370933093c89c0c8020010239b71d9407dacbb8d6125cd7",
1702
+ "outputSha256": "008c119bd1cbac550370933093c89c0c8020010239b71d9407dacbb8d6125cd7",
1703
1703
  "transform": "verbatim"
1704
1704
  },
1705
1705
  {
@@ -2129,17 +2129,17 @@
2129
2129
  {
2130
2130
  "source": "package/dist/routing-accessor/index.d.ts",
2131
2131
  "output": "routing-accessor/index.d.ts",
2132
- "bytes": 10161,
2133
- "sourceSha256": "9a53d387aea7a3423225372bd8a61000838e1c7bb5818c93a32455f2037c315f",
2134
- "outputSha256": "9a53d387aea7a3423225372bd8a61000838e1c7bb5818c93a32455f2037c315f",
2132
+ "bytes": 10377,
2133
+ "sourceSha256": "9273612fe071bfdf502d38cc07f5eeca8ecc60d082fa5f578788c7e856a1b15e",
2134
+ "outputSha256": "9273612fe071bfdf502d38cc07f5eeca8ecc60d082fa5f578788c7e856a1b15e",
2135
2135
  "transform": "verbatim"
2136
2136
  },
2137
2137
  {
2138
2138
  "source": "package/dist/routing-accessor/index.js",
2139
2139
  "output": "routing-accessor/index.js",
2140
- "bytes": 22848,
2141
- "sourceSha256": "13f13701391958c2e1f52d614a78da8d276594a90ee54b4f6af33bf81b4ca669",
2142
- "outputSha256": "13f13701391958c2e1f52d614a78da8d276594a90ee54b4f6af33bf81b4ca669",
2140
+ "bytes": 23158,
2141
+ "sourceSha256": "728aa2d9dd16d7e71ff3583aa767b74818850bdd4dbdca1f15e85d0c0c1b09bd",
2142
+ "outputSha256": "728aa2d9dd16d7e71ff3583aa767b74818850bdd4dbdca1f15e85d0c0c1b09bd",
2143
2143
  "transform": "verbatim"
2144
2144
  }
2145
2145
  ],