@cortexkit/opencode-antigravity-auth 3.0.38 → 3.0.39

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 (94) hide show
  1. package/README.md +1 -1
  2. package/dist/cli.js +602 -320
  3. package/dist/cli.js.map +4 -4
  4. package/dist/cli.meta.json +100 -32
  5. package/dist/index.js +807 -384
  6. package/dist/index.js.map +4 -4
  7. package/dist/index.meta.json +115 -39
  8. package/dist/server.js +828 -398
  9. package/dist/server.js.map +4 -4
  10. package/dist/server.meta.json +1 -1
  11. package/dist/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
  12. package/dist/src/common-auth-embedded/claustrum/availability.js +9 -1
  13. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
  14. package/dist/src/common-auth-embedded/claustrum/custody.js +89 -31
  15. package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +4 -0
  16. package/dist/src/common-auth-embedded/claustrum/enrollment.js +33 -2
  17. package/dist/src/common-auth-embedded/claustrum/host.js +11 -7
  18. package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  19. package/dist/src/common-auth-embedded/claustrum/index.js +1 -1
  20. package/dist/src/common-auth-embedded/fs/lock-record.js +55 -0
  21. package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +148 -92
  22. package/dist/src/common-auth-embedded/fs/with-lock.js +19 -13
  23. package/dist/src/common-auth-embedded/quota-sidebar/index.d.ts +2 -36
  24. package/dist/src/common-auth-embedded/quota-sidebar/index.tsx +49 -607
  25. package/dist/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
  26. package/dist/src/common-auth-embedded/routing-accessor/cache-policy.js +11 -0
  27. package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
  28. package/dist/src/common-auth-embedded/routing-accessor/index.js +136 -5
  29. package/dist/src/common-auth-embedded/setup/enroll.js +2 -1
  30. package/dist/src/common-auth-embedded/setup/types.d.ts +1 -0
  31. package/dist/src/common-auth-embedded/source-output.json +72 -64
  32. package/dist/src/ga/tui/host-ga.d.ts +20 -3
  33. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  34. package/dist/src/ga/tui/host-ga.js +102 -25
  35. package/dist/src/ga/tui/host-ga.js.map +1 -1
  36. package/dist/src/plugin/__fixtures__/release-model-ids.d.ts.map +1 -1
  37. package/dist/src/plugin/__fixtures__/release-model-ids.js +1 -0
  38. package/dist/src/plugin/__fixtures__/release-model-ids.js.map +1 -1
  39. package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
  40. package/dist/src/plugin/ga-location-services.d.ts +1 -0
  41. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  42. package/dist/src/plugin/ga-location-services.js +6 -0
  43. package/dist/src/plugin/ga-location-services.js.map +1 -1
  44. package/dist/src/plugin/request.d.ts.map +1 -1
  45. package/dist/src/plugin/request.js +3 -1
  46. package/dist/src/plugin/request.js.map +1 -1
  47. package/dist/src/setup.d.ts.map +1 -1
  48. package/dist/src/setup.js +2 -0
  49. package/dist/src/setup.js.map +1 -1
  50. package/dist/tui-build-map.json +19 -5
  51. package/dist/tui-ga-build-map.json +23 -9
  52. package/dist/types/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
  53. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
  54. package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +4 -0
  55. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  56. package/dist/types/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
  57. package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
  58. package/dist/types/src/common-auth-embedded/setup/types.d.ts +1 -0
  59. package/dist/types/src/plugin/ga-location-services.d.ts +1 -0
  60. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  61. package/dist/types/src/plugin/request.d.ts.map +1 -1
  62. package/dist/types/src/setup.d.ts.map +1 -1
  63. package/package.json +4 -3
  64. package/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
  65. package/src/common-auth-embedded/claustrum/availability.js +9 -1
  66. package/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
  67. package/src/common-auth-embedded/claustrum/custody.js +89 -31
  68. package/src/common-auth-embedded/claustrum/enrollment.d.ts +4 -0
  69. package/src/common-auth-embedded/claustrum/enrollment.js +33 -2
  70. package/src/common-auth-embedded/claustrum/host.js +11 -7
  71. package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  72. package/src/common-auth-embedded/claustrum/index.js +1 -1
  73. package/src/common-auth-embedded/fs/lock-record.js +55 -0
  74. package/src/common-auth-embedded/fs/refresh-file-lock.js +148 -92
  75. package/src/common-auth-embedded/fs/with-lock.js +19 -13
  76. package/src/common-auth-embedded/quota-sidebar/index.d.ts +2 -36
  77. package/src/common-auth-embedded/quota-sidebar/index.tsx +49 -607
  78. package/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
  79. package/src/common-auth-embedded/routing-accessor/cache-policy.js +11 -0
  80. package/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
  81. package/src/common-auth-embedded/routing-accessor/index.js +136 -5
  82. package/src/common-auth-embedded/setup/enroll.js +2 -1
  83. package/src/common-auth-embedded/setup/types.d.ts +1 -0
  84. package/src/common-auth-embedded/source-output.json +72 -64
  85. package/src/tui-compiled/common-auth-embedded/quota-sidebar/index.js +36 -674
  86. package/src/tui-compiled/shared/a75d0d866c227b3f-index.js +678 -0
  87. package/src/tui-ga-compiled/host-ga.js +86 -26
  88. package/src/tui-ga-compiled/shared/a75d0d866c227b3f-index.js +678 -0
  89. package/src/tui-ga-compiled/shared/e4ec36f367492969-index.js +36 -674
  90. package/src/tui-ga-raw/host-ga.tsx +122 -25
  91. package/src/tui-ga-raw/shared/a75d0d866c227b3f-index.tsx +681 -0
  92. package/src/tui-ga-raw/shared/e4ec36f367492969-index.tsx +49 -607
  93. package/src/tui-raw/common-auth-embedded/quota-sidebar/index.tsx +49 -607
  94. package/src/tui-raw/shared/a75d0d866c227b3f-index.tsx +681 -0
@@ -51,11 +51,12 @@ export const GA_TUI_ID = 'cortexkit.antigravity-auth';
51
51
  export const GA_RPC_ID = 'antigravity-auth';
52
52
  export const GA_RPC_VERSION = 1;
53
53
 
54
- /** How often the TUI pulls state and notifications from its location. */
54
+ /** How often the TUI pulls state and notifications for the visible route. */
55
55
  export const GA_SIDEBAR_PULL_MS = 1_000;
56
56
 
57
57
  /** Pulls in one tick while the server reports more notifications waiting. */
58
58
  const MAX_PULLS_PER_TICK = 4;
59
+ const MAX_SESSION_LOCATIONS = 32;
59
60
 
60
61
  // ── Host surface (structural subset of the GA TUI context) ─────────────────
61
62
 
@@ -554,6 +555,32 @@ export function createGaLocationClient(options) {
554
555
  };
555
556
  }
556
557
 
558
+ /** Keep the home client, but retain at most one other visible location. */
559
+ export function createGaLocationClients(options) {
560
+ const home = createGaLocationClient(options);
561
+ let shown = home;
562
+ let shownKey = '';
563
+ const key = location => JSON.stringify([location?.directory, location?.workspaceID]);
564
+ return {
565
+ current: () => shown,
566
+ select(location) {
567
+ const nextKey = key(location);
568
+ if (shown !== home && nextKey === shownKey) return shown;
569
+ if (shown !== home) shown.dispose();
570
+ shown = nextKey === key(options.location) ? home : createGaLocationClient({
571
+ ...options,
572
+ location
573
+ });
574
+ shownKey = nextKey;
575
+ return shown;
576
+ },
577
+ dispose() {
578
+ shown.dispose();
579
+ home.dispose();
580
+ }
581
+ };
582
+ }
583
+
557
584
  // ── Menu over the native state ──────────────────────────────────────────────
558
585
 
559
586
  const ACCOUNT_ITEM_PREFIX = 'account:';
@@ -1064,15 +1091,16 @@ function defaultSchedule(tick, intervalMs) {
1064
1091
  export function setupGaTui(context, options = {}) {
1065
1092
  const logger = options.logger;
1066
1093
  const now = options.now ?? Date.now;
1067
- const client = createGaLocationClient({
1094
+ const clients = createGaLocationClients({
1068
1095
  call: input => context.client.rpc.call(input),
1069
1096
  location: context.location,
1070
1097
  ...(logger ? {
1071
1098
  logger
1072
1099
  } : {})
1073
1100
  });
1074
- const active = () => !client.disposed();
1075
- const ui = createGaMenuUi(context, active);
1101
+ let cleaned = false;
1102
+ const active = () => !cleaned;
1103
+ const isCurrent = (client, scope) => active() && !client.disposed() && clients.current() === client && scopeKey(currentScope(context.ui.router.current())) === scopeKey(scope);
1076
1104
  const [view, setView] = createSignal(undefined);
1077
1105
  const collapse = createGaCollapse(context.storage, logger);
1078
1106
  const releaseSlot = context.ui.slot({
@@ -1113,20 +1141,22 @@ export function setupGaTui(context, options = {}) {
1113
1141
  * Pulls fresh state for `scope`. Any
1114
1142
  * notifications the pull carries are handled like a poll tick's.
1115
1143
  */
1116
- const refresh = async scope => {
1144
+ const refresh = async (client, scope) => {
1117
1145
  await pollGaOnce({
1118
1146
  client,
1119
1147
  scope: () => scope,
1120
1148
  onSnapshot: snapshot => {
1121
- showSnapshot(snapshot);
1149
+ if (isCurrent(client, scope)) showSnapshot(snapshot);
1150
+ },
1151
+ onNotification: notification => {
1152
+ if (isCurrent(client, scope)) onNotification(client, notification, scope);
1122
1153
  },
1123
- onNotification,
1124
1154
  ...(logger ? {
1125
1155
  logger
1126
1156
  } : {})
1127
1157
  });
1128
1158
  };
1129
- const applyRequest = async (scope, request, shown) => {
1159
+ const applyRequest = async (client, scope, request, shown) => {
1130
1160
  const refused = async (text, code) => ({
1131
1161
  command: ANTIGRAVITY_MENU_COMMAND,
1132
1162
  ok: false,
@@ -1134,6 +1164,7 @@ export function setupGaTui(context, options = {}) {
1134
1164
  code,
1135
1165
  menu: shown.source
1136
1166
  });
1167
+ if (!isCurrent(client, scope)) return refused('That session is no longer shown.', 'stale-session');
1137
1168
  let body;
1138
1169
  try {
1139
1170
  body = {
@@ -1150,12 +1181,12 @@ export function setupGaTui(context, options = {}) {
1150
1181
  if (error instanceof GaStaleError) return refused(error.message, error.reason);
1151
1182
  throw error;
1152
1183
  }
1153
- await refresh(scope);
1184
+ if (isCurrent(client, scope)) await refresh(client, scope);
1154
1185
  return result;
1155
1186
  };
1156
1187
  let pendingLogin;
1157
- const applyChoice = async (scope, request, shown) => {
1158
- if (request.sectionId !== 'accounts' || request.actionId !== 'add' || request.itemId !== undefined) return applyRequest(scope, request, shown);
1188
+ const applyChoice = async (client, ui, scope, request, shown) => {
1189
+ if (request.sectionId !== 'accounts' || request.actionId !== 'add' || request.itemId !== undefined) return applyRequest(client, scope, request, shown);
1159
1190
  const completed = Promise.withResolvers();
1160
1191
  const pending = {
1161
1192
  scope: scopeKey(scope),
@@ -1167,13 +1198,14 @@ export function setupGaTui(context, options = {}) {
1167
1198
  ui,
1168
1199
  request,
1169
1200
  completed: completed.promise,
1170
- apply: next => applyRequest(scope, next, shown)
1201
+ apply: next => applyRequest(client, scope, next, shown)
1171
1202
  });
1172
1203
  } finally {
1173
1204
  if (pendingLogin === pending) pendingLogin = undefined;
1174
1205
  }
1175
1206
  };
1176
- function onNotification(notification, scope) {
1207
+ function onNotification(client, notification, scope) {
1208
+ const ui = createGaMenuUi(context, () => isCurrent(client, scope));
1177
1209
  const payload = notification.payload;
1178
1210
  if ('notify' in payload) {
1179
1211
  if (pendingLogin?.scope === scopeKey(scope) && ['Account added.', 'The Antigravity pool login could not be completed.'].includes(payload.notify.message)) {
@@ -1189,7 +1221,7 @@ export function setupGaTui(context, options = {}) {
1189
1221
  void openAntigravityMenu({
1190
1222
  ui,
1191
1223
  apply: async request => {
1192
- const result = await applyChoice(scope, request, shown);
1224
+ const result = await applyChoice(client, ui, scope, request, shown);
1193
1225
  shown = presentGaMenu(latest.get(scopeKey(scope)) ?? snapshot, now(), result.menu);
1194
1226
  return {
1195
1227
  ...result,
@@ -1210,38 +1242,66 @@ export function setupGaTui(context, options = {}) {
1210
1242
  });
1211
1243
  }
1212
1244
  let inFlight = false;
1245
+ let shownScope = '';
1246
+ // Session locations are immutable; keep only the most recently viewed sessions.
1247
+ const sessionLocations = new Map();
1248
+ const sessionLocation = async sessionID => {
1249
+ const location = sessionLocations.get(sessionID) ?? (await context.client.session.get({
1250
+ sessionID
1251
+ })).location;
1252
+ if (active()) {
1253
+ sessionLocations.delete(sessionID);
1254
+ sessionLocations.set(sessionID, location);
1255
+ if (sessionLocations.size > MAX_SESSION_LOCATIONS) {
1256
+ const oldest = sessionLocations.keys().next().value;
1257
+ if (oldest !== undefined) sessionLocations.delete(oldest);
1258
+ }
1259
+ }
1260
+ return location;
1261
+ };
1213
1262
  const tick = () => {
1214
1263
  if (inFlight || !active()) return;
1215
1264
  inFlight = true;
1216
- void pollGaOnce({
1217
- client,
1218
- scope: () => currentScope(context.ui.router.current()),
1219
- onSnapshot: showSnapshot,
1220
- onNotification,
1221
- ...(logger ? {
1222
- logger
1223
- } : {})
1265
+ void (async () => {
1266
+ const scope = currentScope(context.ui.router.current());
1267
+ const nextScope = scopeKey(scope);
1268
+ if (shownScope !== nextScope) {
1269
+ latest.clear();
1270
+ setView(undefined);
1271
+ pendingLogin?.finish(false);
1272
+ shownScope = nextScope;
1273
+ }
1274
+ // Session lookup is global; RPC queues remain local to its returned location.
1275
+ const location = scope.kind === 'session' ? await sessionLocation(scope.sessionID) : context.location;
1276
+ if (!active() || nextScope !== scopeKey(currentScope(context.ui.router.current()))) return;
1277
+ await refresh(clients.select(location), scope);
1278
+ })().catch(error => {
1279
+ if (!active()) return;
1280
+ clients.select(context.location);
1281
+ logger?.warn('ga-session-location-failed', {
1282
+ error: error instanceof Error ? error.name : typeof error
1283
+ });
1224
1284
  }).finally(() => {
1225
1285
  inFlight = false;
1226
1286
  });
1227
1287
  };
1228
1288
  const stop = (options.schedule ?? defaultSchedule)(tick, GA_SIDEBAR_PULL_MS);
1229
1289
  tick();
1230
- let cleaned = false;
1231
1290
  return async () => {
1232
1291
  if (cleaned) return;
1233
1292
  cleaned = true;
1234
1293
  pendingLogin?.finish(false);
1235
1294
  stop();
1236
- client.dispose();
1295
+ clients.dispose();
1296
+ sessionLocations.clear();
1237
1297
  releaseSlot();
1238
1298
  };
1239
1299
  }
1240
1300
 
1241
1301
  /**
1242
1302
  * The GA TUI plugin definition (`{ id, setup }`, the 2.0.22 TUI plugin
1243
- * shape). Importing this module starts nothing; `setup` binds to the
1244
- * context's location and returns the cleanup that stops everything it
1303
+ * shape). Importing this module starts nothing; `setup` follows the current
1304
+ * session's location and returns the cleanup that stops everything it
1245
1305
  * started. The host calls `setup(context)`; the package's `./tui` entry
1246
1306
  * passes the plugin version as the second argument. This module's graph
1247
1307
  * may use no Node built-in (the build refuses one), so it cannot read