@cortexkit/opencode-antigravity-auth 3.0.37 → 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 (126) hide show
  1. package/README.md +1 -1
  2. package/dist/cli.js +608 -321
  3. package/dist/cli.js.map +4 -4
  4. package/dist/cli.meta.json +106 -38
  5. package/dist/index.js +815 -386
  6. package/dist/index.js.map +4 -4
  7. package/dist/index.meta.json +122 -46
  8. package/dist/server.js +1056 -492
  9. package/dist/server.js.map +4 -4
  10. package/dist/server.meta.json +1 -1
  11. package/dist/src/auth-method-labels.d.ts +2 -0
  12. package/dist/src/auth-method-labels.d.ts.map +1 -1
  13. package/dist/src/auth-method-labels.js +2 -0
  14. package/dist/src/auth-method-labels.js.map +1 -1
  15. package/dist/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
  16. package/dist/src/common-auth-embedded/claustrum/availability.js +9 -1
  17. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
  18. package/dist/src/common-auth-embedded/claustrum/custody.js +89 -31
  19. package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +4 -0
  20. package/dist/src/common-auth-embedded/claustrum/enrollment.js +33 -2
  21. package/dist/src/common-auth-embedded/claustrum/host.js +11 -7
  22. package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  23. package/dist/src/common-auth-embedded/claustrum/index.js +1 -1
  24. package/dist/src/common-auth-embedded/fs/lock-record.js +55 -0
  25. package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +148 -92
  26. package/dist/src/common-auth-embedded/fs/with-lock.js +19 -13
  27. package/dist/src/common-auth-embedded/quota-sidebar/index.d.ts +2 -36
  28. package/dist/src/common-auth-embedded/quota-sidebar/index.tsx +49 -607
  29. package/dist/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
  30. package/dist/src/common-auth-embedded/routing-accessor/cache-policy.js +11 -0
  31. package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
  32. package/dist/src/common-auth-embedded/routing-accessor/index.js +136 -5
  33. package/dist/src/common-auth-embedded/setup/enroll.js +2 -1
  34. package/dist/src/common-auth-embedded/setup/types.d.ts +1 -0
  35. package/dist/src/common-auth-embedded/source-output.json +72 -64
  36. package/dist/src/ga/server/auth.js +1 -1
  37. package/dist/src/ga/server/auth.js.map +1 -1
  38. package/dist/src/ga/server/pool-login.d.ts +9 -0
  39. package/dist/src/ga/server/pool-login.d.ts.map +1 -1
  40. package/dist/src/ga/server/pool-login.js +155 -73
  41. package/dist/src/ga/server/pool-login.js.map +1 -1
  42. package/dist/src/ga/tui/host-ga.d.ts +27 -3
  43. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  44. package/dist/src/ga/tui/host-ga.js +168 -22
  45. package/dist/src/ga/tui/host-ga.js.map +1 -1
  46. package/dist/src/logging/provider-key-policy.d.ts +2 -0
  47. package/dist/src/logging/provider-key-policy.d.ts.map +1 -1
  48. package/dist/src/logging/provider-key-policy.js +5 -1
  49. package/dist/src/logging/provider-key-policy.js.map +1 -1
  50. package/dist/src/plugin/__fixtures__/release-model-ids.d.ts.map +1 -1
  51. package/dist/src/plugin/__fixtures__/release-model-ids.js +1 -0
  52. package/dist/src/plugin/__fixtures__/release-model-ids.js.map +1 -1
  53. package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
  54. package/dist/src/plugin/ga-location-services.d.ts +1 -0
  55. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  56. package/dist/src/plugin/ga-location-services.js +81 -10
  57. package/dist/src/plugin/ga-location-services.js.map +1 -1
  58. package/dist/src/plugin/logger.d.ts.map +1 -1
  59. package/dist/src/plugin/logger.js +2 -1
  60. package/dist/src/plugin/logger.js.map +1 -1
  61. package/dist/src/plugin/request.d.ts.map +1 -1
  62. package/dist/src/plugin/request.js +3 -1
  63. package/dist/src/plugin/request.js.map +1 -1
  64. package/dist/src/setup.d.ts.map +1 -1
  65. package/dist/src/setup.js +2 -0
  66. package/dist/src/setup.js.map +1 -1
  67. package/dist/src/tui/file-logger.d.ts.map +1 -1
  68. package/dist/src/tui/file-logger.js +2 -1
  69. package/dist/src/tui/file-logger.js.map +1 -1
  70. package/dist/tui-build-map.json +27 -13
  71. package/dist/tui-ga-build-map.json +23 -9
  72. package/dist/types/src/auth-method-labels.d.ts +2 -0
  73. package/dist/types/src/auth-method-labels.d.ts.map +1 -1
  74. package/dist/types/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
  75. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
  76. package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +4 -0
  77. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  78. package/dist/types/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
  79. package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
  80. package/dist/types/src/common-auth-embedded/setup/types.d.ts +1 -0
  81. package/dist/types/src/ga/server/pool-login.d.ts +9 -0
  82. package/dist/types/src/ga/server/pool-login.d.ts.map +1 -1
  83. package/dist/types/src/logging/provider-key-policy.d.ts +2 -0
  84. package/dist/types/src/logging/provider-key-policy.d.ts.map +1 -1
  85. package/dist/types/src/plugin/ga-location-services.d.ts +1 -0
  86. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  87. package/dist/types/src/plugin/logger.d.ts.map +1 -1
  88. package/dist/types/src/plugin/request.d.ts.map +1 -1
  89. package/dist/types/src/setup.d.ts.map +1 -1
  90. package/package.json +4 -3
  91. package/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
  92. package/src/common-auth-embedded/claustrum/availability.js +9 -1
  93. package/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
  94. package/src/common-auth-embedded/claustrum/custody.js +89 -31
  95. package/src/common-auth-embedded/claustrum/enrollment.d.ts +4 -0
  96. package/src/common-auth-embedded/claustrum/enrollment.js +33 -2
  97. package/src/common-auth-embedded/claustrum/host.js +11 -7
  98. package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  99. package/src/common-auth-embedded/claustrum/index.js +1 -1
  100. package/src/common-auth-embedded/fs/lock-record.js +55 -0
  101. package/src/common-auth-embedded/fs/refresh-file-lock.js +148 -92
  102. package/src/common-auth-embedded/fs/with-lock.js +19 -13
  103. package/src/common-auth-embedded/quota-sidebar/index.d.ts +2 -36
  104. package/src/common-auth-embedded/quota-sidebar/index.tsx +49 -607
  105. package/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
  106. package/src/common-auth-embedded/routing-accessor/cache-policy.js +11 -0
  107. package/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
  108. package/src/common-auth-embedded/routing-accessor/index.js +136 -5
  109. package/src/common-auth-embedded/setup/enroll.js +2 -1
  110. package/src/common-auth-embedded/setup/types.d.ts +1 -0
  111. package/src/common-auth-embedded/source-output.json +72 -64
  112. package/src/tui/file-logger.ts +5 -1
  113. package/src/tui-compiled/common-auth-embedded/quota-sidebar/index.js +36 -674
  114. package/src/tui-compiled/logging/provider-key-policy.js +4 -1
  115. package/src/tui-compiled/shared/a75d0d866c227b3f-index.js +678 -0
  116. package/src/tui-compiled/tui/file-logger.js +5 -1
  117. package/src/tui-ga-compiled/host-ga.js +148 -23
  118. package/src/tui-ga-compiled/shared/a75d0d866c227b3f-index.js +678 -0
  119. package/src/tui-ga-compiled/shared/e4ec36f367492969-index.js +36 -674
  120. package/src/tui-ga-raw/host-ga.tsx +199 -24
  121. package/src/tui-ga-raw/shared/a75d0d866c227b3f-index.tsx +681 -0
  122. package/src/tui-ga-raw/shared/e4ec36f367492969-index.tsx +49 -607
  123. package/src/tui-raw/common-auth-embedded/quota-sidebar/index.tsx +49 -607
  124. package/src/tui-raw/logging/provider-key-policy.js +4 -1
  125. package/src/tui-raw/shared/a75d0d866c227b3f-index.tsx +681 -0
  126. package/src/tui-raw/tui/file-logger.js +5 -1
@@ -10,7 +10,10 @@ import {
10
10
  import { homedir } from "node:os";
11
11
  import { dirname, join } from "node:path";
12
12
  import { createLoggerInstance } from "../common-auth-embedded/logger/index.js";
13
- import { isProviderSecretKey } from "../logging/provider-key-policy.js";
13
+ import {
14
+ isProviderSecretKey,
15
+ OAUTH_REDIRECT_VALUE_PATTERNS
16
+ } from "../logging/provider-key-policy.js";
14
17
  const LOG_PREFIX = "[opencode-antigravity-auth/tui]", DEFAULT_MAX_BYTES = 1e6, MAX_KEEP_LINES = 200, FILE_MODE = 384;
15
18
  export function resolveTuiLogPath() {
16
19
  const override = process.env.ANTIGRAVITY_AUTH_TUI_LOG_FILE;
@@ -58,6 +61,7 @@ function createFileLogger(options) {
58
61
  }, channel = createLoggerInstance({
59
62
  level: "debug",
60
63
  extraSecretKeys: isProviderSecretKey,
64
+ extraValuePatterns: OAUTH_REDIRECT_VALUE_PATTERNS,
61
65
  captureSink: ({ level, message, data }) => {
62
66
  const extra = data !== null && typeof data === "object" && !Array.isArray(data) ? Object.fromEntries(Object.entries(data)) : void 0;
63
67
  write(level === "trace" ? "debug" : level, message, extra);
@@ -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:';
@@ -805,6 +832,46 @@ export function presentGaMenu(snapshot, now, source) {
805
832
 
806
833
  // ── Dialogs ─────────────────────────────────────────────────────────────────
807
834
 
835
+ /** The drawer owns this prompt, so a browser callback can dismiss it. */
836
+ export async function runGaDrawerLogin(input) {
837
+ const started = await input.apply(input.request);
838
+ if (!started.ok) return started;
839
+ let promptOpen = true;
840
+ const completed = input.completed.then(ok => {
841
+ if (promptOpen) input.ui.clear();
842
+ return {
843
+ ...started,
844
+ ok,
845
+ text: ok ? 'Account added.' : 'The Antigravity pool login could not be completed.'
846
+ };
847
+ });
848
+ const answer = input.ui.prompt({
849
+ title: 'Add account',
850
+ description: started.text,
851
+ placeholder: "Paste the redirect URL from your browser's address bar"
852
+ }).then(value => ({
853
+ value
854
+ }));
855
+ const winner = await Promise.race([completed, answer]);
856
+ promptOpen = false;
857
+ if (!('value' in winner)) return winner;
858
+ if (winner.value === undefined) {
859
+ return input.apply({
860
+ ...input.request,
861
+ values: {
862
+ cancel: true
863
+ }
864
+ });
865
+ }
866
+ if (!winner.value.trim()) return completed;
867
+ return Promise.race([input.apply({
868
+ ...input.request,
869
+ values: {
870
+ callback: winner.value
871
+ }
872
+ }), completed]);
873
+ }
874
+
808
875
  /**
809
876
  * `MenuUi` over the GA dialog API. After `isActive()` turns false every call
810
877
  * is inert: a select resolves as dismissed and nothing is shown.
@@ -1024,15 +1091,16 @@ function defaultSchedule(tick, intervalMs) {
1024
1091
  export function setupGaTui(context, options = {}) {
1025
1092
  const logger = options.logger;
1026
1093
  const now = options.now ?? Date.now;
1027
- const client = createGaLocationClient({
1094
+ const clients = createGaLocationClients({
1028
1095
  call: input => context.client.rpc.call(input),
1029
1096
  location: context.location,
1030
1097
  ...(logger ? {
1031
1098
  logger
1032
1099
  } : {})
1033
1100
  });
1034
- const active = () => !client.disposed();
1035
- 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);
1036
1104
  const [view, setView] = createSignal(undefined);
1037
1105
  const collapse = createGaCollapse(context.storage, logger);
1038
1106
  const releaseSlot = context.ui.slot({
@@ -1073,20 +1141,22 @@ export function setupGaTui(context, options = {}) {
1073
1141
  * Pulls fresh state for `scope`. Any
1074
1142
  * notifications the pull carries are handled like a poll tick's.
1075
1143
  */
1076
- const refresh = async scope => {
1144
+ const refresh = async (client, scope) => {
1077
1145
  await pollGaOnce({
1078
1146
  client,
1079
1147
  scope: () => scope,
1080
1148
  onSnapshot: snapshot => {
1081
- showSnapshot(snapshot);
1149
+ if (isCurrent(client, scope)) showSnapshot(snapshot);
1150
+ },
1151
+ onNotification: notification => {
1152
+ if (isCurrent(client, scope)) onNotification(client, notification, scope);
1082
1153
  },
1083
- onNotification,
1084
1154
  ...(logger ? {
1085
1155
  logger
1086
1156
  } : {})
1087
1157
  });
1088
1158
  };
1089
- const applyChoice = async (scope, request, shown) => {
1159
+ const applyRequest = async (client, scope, request, shown) => {
1090
1160
  const refused = async (text, code) => ({
1091
1161
  command: ANTIGRAVITY_MENU_COMMAND,
1092
1162
  ok: false,
@@ -1094,6 +1164,7 @@ export function setupGaTui(context, options = {}) {
1094
1164
  code,
1095
1165
  menu: shown.source
1096
1166
  });
1167
+ if (!isCurrent(client, scope)) return refused('That session is no longer shown.', 'stale-session');
1097
1168
  let body;
1098
1169
  try {
1099
1170
  body = {
@@ -1110,12 +1181,37 @@ export function setupGaTui(context, options = {}) {
1110
1181
  if (error instanceof GaStaleError) return refused(error.message, error.reason);
1111
1182
  throw error;
1112
1183
  }
1113
- await refresh(scope);
1184
+ if (isCurrent(client, scope)) await refresh(client, scope);
1114
1185
  return result;
1115
1186
  };
1116
- function onNotification(notification, scope) {
1187
+ let pendingLogin;
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);
1190
+ const completed = Promise.withResolvers();
1191
+ const pending = {
1192
+ scope: scopeKey(scope),
1193
+ finish: completed.resolve
1194
+ };
1195
+ pendingLogin = pending;
1196
+ try {
1197
+ return await runGaDrawerLogin({
1198
+ ui,
1199
+ request,
1200
+ completed: completed.promise,
1201
+ apply: next => applyRequest(client, scope, next, shown)
1202
+ });
1203
+ } finally {
1204
+ if (pendingLogin === pending) pendingLogin = undefined;
1205
+ }
1206
+ };
1207
+ function onNotification(client, notification, scope) {
1208
+ const ui = createGaMenuUi(context, () => isCurrent(client, scope));
1117
1209
  const payload = notification.payload;
1118
1210
  if ('notify' in payload) {
1211
+ if (pendingLogin?.scope === scopeKey(scope) && ['Account added.', 'The Antigravity pool login could not be completed.'].includes(payload.notify.message)) {
1212
+ pendingLogin.finish(payload.notify.kind !== 'error');
1213
+ return;
1214
+ }
1119
1215
  ui.toast(payload.notify.message, payload.notify.kind);
1120
1216
  return;
1121
1217
  }
@@ -1125,7 +1221,7 @@ export function setupGaTui(context, options = {}) {
1125
1221
  void openAntigravityMenu({
1126
1222
  ui,
1127
1223
  apply: async request => {
1128
- const result = await applyChoice(scope, request, shown);
1224
+ const result = await applyChoice(client, ui, scope, request, shown);
1129
1225
  shown = presentGaMenu(latest.get(scopeKey(scope)) ?? snapshot, now(), result.menu);
1130
1226
  return {
1131
1227
  ...result,
@@ -1146,37 +1242,66 @@ export function setupGaTui(context, options = {}) {
1146
1242
  });
1147
1243
  }
1148
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
+ };
1149
1262
  const tick = () => {
1150
1263
  if (inFlight || !active()) return;
1151
1264
  inFlight = true;
1152
- void pollGaOnce({
1153
- client,
1154
- scope: () => currentScope(context.ui.router.current()),
1155
- onSnapshot: showSnapshot,
1156
- onNotification,
1157
- ...(logger ? {
1158
- logger
1159
- } : {})
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
+ });
1160
1284
  }).finally(() => {
1161
1285
  inFlight = false;
1162
1286
  });
1163
1287
  };
1164
1288
  const stop = (options.schedule ?? defaultSchedule)(tick, GA_SIDEBAR_PULL_MS);
1165
1289
  tick();
1166
- let cleaned = false;
1167
1290
  return async () => {
1168
1291
  if (cleaned) return;
1169
1292
  cleaned = true;
1293
+ pendingLogin?.finish(false);
1170
1294
  stop();
1171
- client.dispose();
1295
+ clients.dispose();
1296
+ sessionLocations.clear();
1172
1297
  releaseSlot();
1173
1298
  };
1174
1299
  }
1175
1300
 
1176
1301
  /**
1177
1302
  * The GA TUI plugin definition (`{ id, setup }`, the 2.0.22 TUI plugin
1178
- * shape). Importing this module starts nothing; `setup` binds to the
1179
- * 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
1180
1305
  * started. The host calls `setup(context)`; the package's `./tui` entry
1181
1306
  * passes the plugin version as the second argument. This module's graph
1182
1307
  * may use no Node built-in (the build refuses one), so it cannot read