@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
@@ -80,11 +80,12 @@ export const GA_TUI_ID = 'cortexkit.antigravity-auth' as const
80
80
  export const GA_RPC_ID = 'antigravity-auth' as const
81
81
  export const GA_RPC_VERSION = 1 as const
82
82
 
83
- /** How often the TUI pulls state and notifications from its location. */
83
+ /** How often the TUI pulls state and notifications for the visible route. */
84
84
  export const GA_SIDEBAR_PULL_MS = 1_000
85
85
 
86
86
  /** Pulls in one tick while the server reports more notifications waiting. */
87
87
  const MAX_PULLS_PER_TICK = 4
88
+ const MAX_SESSION_LOCATIONS = 32
88
89
 
89
90
  // ── Host surface (structural subset of the GA TUI context) ─────────────────
90
91
 
@@ -134,6 +135,11 @@ export interface GaTuiContext {
134
135
  readonly storage?: GaStorage
135
136
  readonly location: GaLocationRef | undefined
136
137
  readonly client: {
138
+ readonly session: {
139
+ get(input: { readonly sessionID: string }): Promise<{
140
+ readonly location: GaLocationRef
141
+ }>
142
+ }
137
143
  readonly rpc: {
138
144
  call(input: GaRpcCallInput): Promise<unknown>
139
145
  }
@@ -914,6 +920,37 @@ export function createGaLocationClient(options: {
914
920
  }
915
921
  }
916
922
 
923
+ /** Keep the home client, but retain at most one other visible location. */
924
+ export function createGaLocationClients(options: {
925
+ readonly call: (input: GaRpcCallInput) => Promise<unknown>
926
+ readonly location: GaLocationRef | undefined
927
+ readonly logger?: GaLogger
928
+ }) {
929
+ const home = createGaLocationClient(options)
930
+ let shown = home
931
+ let shownKey = ''
932
+ const key = (location: GaLocationRef | undefined) =>
933
+ JSON.stringify([location?.directory, location?.workspaceID])
934
+ return {
935
+ current: () => shown,
936
+ select(location: GaLocationRef | undefined): GaLocationClient {
937
+ const nextKey = key(location)
938
+ if (shown !== home && nextKey === shownKey) return shown
939
+ if (shown !== home) shown.dispose()
940
+ shown =
941
+ nextKey === key(options.location)
942
+ ? home
943
+ : createGaLocationClient({ ...options, location })
944
+ shownKey = nextKey
945
+ return shown
946
+ },
947
+ dispose() {
948
+ shown.dispose()
949
+ home.dispose()
950
+ },
951
+ }
952
+ }
953
+
917
954
  // ── Menu over the native state ──────────────────────────────────────────────
918
955
 
919
956
  const ACCOUNT_ITEM_PREFIX = 'account:'
@@ -1302,6 +1339,46 @@ export function presentGaMenu(
1302
1339
 
1303
1340
  // ── Dialogs ─────────────────────────────────────────────────────────────────
1304
1341
 
1342
+ /** The drawer owns this prompt, so a browser callback can dismiss it. */
1343
+ export async function runGaDrawerLogin(input: {
1344
+ ui: MenuUi
1345
+ request: MenuApplyRequest
1346
+ apply(request: MenuApplyRequest): Promise<MenuApplyResult>
1347
+ completed: Promise<boolean>
1348
+ }): Promise<MenuApplyResult> {
1349
+ const started = await input.apply(input.request)
1350
+ if (!started.ok) return started
1351
+ let promptOpen = true
1352
+ const completed = input.completed.then((ok) => {
1353
+ if (promptOpen) input.ui.clear()
1354
+ return {
1355
+ ...started,
1356
+ ok,
1357
+ text: ok
1358
+ ? 'Account added.'
1359
+ : 'The Antigravity pool login could not be completed.',
1360
+ }
1361
+ })
1362
+ const answer = input.ui
1363
+ .prompt({
1364
+ title: 'Add account',
1365
+ description: started.text,
1366
+ placeholder: "Paste the redirect URL from your browser's address bar",
1367
+ })
1368
+ .then((value) => ({ value }))
1369
+ const winner = await Promise.race([completed, answer])
1370
+ promptOpen = false
1371
+ if (!('value' in winner)) return winner
1372
+ if (winner.value === undefined) {
1373
+ return input.apply({ ...input.request, values: { cancel: true } })
1374
+ }
1375
+ if (!winner.value.trim()) return completed
1376
+ return Promise.race([
1377
+ input.apply({ ...input.request, values: { callback: winner.value } }),
1378
+ completed,
1379
+ ])
1380
+ }
1381
+
1305
1382
  /**
1306
1383
  * `MenuUi` over the GA dialog API. After `isActive()` turns false every call
1307
1384
  * is inert: a select resolves as dismissed and nothing is shown.
@@ -1557,13 +1634,18 @@ export function setupGaTui(
1557
1634
  ): () => Promise<void> {
1558
1635
  const logger = options.logger
1559
1636
  const now = options.now ?? Date.now
1560
- const client = createGaLocationClient({
1637
+ const clients = createGaLocationClients({
1561
1638
  call: (input) => context.client.rpc.call(input),
1562
1639
  location: context.location,
1563
1640
  ...(logger ? { logger } : {}),
1564
1641
  })
1565
- const active = () => !client.disposed()
1566
- const ui = createGaMenuUi(context, active)
1642
+ let cleaned = false
1643
+ const active = () => !cleaned
1644
+ const isCurrent = (client: GaLocationClient, scope: GaScope) =>
1645
+ active() &&
1646
+ !client.disposed() &&
1647
+ clients.current() === client &&
1648
+ scopeKey(currentScope(context.ui.router.current())) === scopeKey(scope)
1567
1649
  const [view, setView] = createSignal<SidebarView | undefined>(undefined)
1568
1650
  const collapse = createGaCollapse(context.storage, logger)
1569
1651
 
@@ -1600,19 +1682,26 @@ export function setupGaTui(
1600
1682
  * Pulls fresh state for `scope`. Any
1601
1683
  * notifications the pull carries are handled like a poll tick's.
1602
1684
  */
1603
- const refresh = async (scope: GaScope): Promise<void> => {
1685
+ const refresh = async (
1686
+ client: GaLocationClient,
1687
+ scope: GaScope,
1688
+ ): Promise<void> => {
1604
1689
  await pollGaOnce({
1605
1690
  client,
1606
1691
  scope: () => scope,
1607
1692
  onSnapshot: (snapshot) => {
1608
- showSnapshot(snapshot)
1693
+ if (isCurrent(client, scope)) showSnapshot(snapshot)
1694
+ },
1695
+ onNotification: (notification) => {
1696
+ if (isCurrent(client, scope))
1697
+ onNotification(client, notification, scope)
1609
1698
  },
1610
- onNotification,
1611
1699
  ...(logger ? { logger } : {}),
1612
1700
  })
1613
1701
  }
1614
1702
 
1615
- const applyChoice = async (
1703
+ const applyRequest = async (
1704
+ client: GaLocationClient,
1616
1705
  scope: GaScope,
1617
1706
  request: MenuApplyRequest,
1618
1707
  shown: GaMenuPresentation,
@@ -1624,6 +1713,8 @@ export function setupGaTui(
1624
1713
  code,
1625
1714
  menu: shown.source,
1626
1715
  })
1716
+ if (!isCurrent(client, scope))
1717
+ return refused('That session is no longer shown.', 'stale-session')
1627
1718
  let body: GaApplyBody
1628
1719
  try {
1629
1720
  body = { request: shown.request(request) }
@@ -1640,13 +1731,57 @@ export function setupGaTui(
1640
1731
  return refused(error.message, error.reason)
1641
1732
  throw error
1642
1733
  }
1643
- await refresh(scope)
1734
+ if (isCurrent(client, scope)) await refresh(client, scope)
1644
1735
  return result
1645
1736
  }
1646
1737
 
1647
- function onNotification(notification: GaNotification, scope: GaScope) {
1738
+ let pendingLogin: { scope: string; finish(ok: boolean): void } | undefined
1739
+ const applyChoice = async (
1740
+ client: GaLocationClient,
1741
+ ui: MenuUi,
1742
+ scope: GaScope,
1743
+ request: MenuApplyRequest,
1744
+ shown: GaMenuPresentation,
1745
+ ) => {
1746
+ if (
1747
+ request.sectionId !== 'accounts' ||
1748
+ request.actionId !== 'add' ||
1749
+ request.itemId !== undefined
1750
+ )
1751
+ return applyRequest(client, scope, request, shown)
1752
+ const completed = Promise.withResolvers<boolean>()
1753
+ const pending = { scope: scopeKey(scope), finish: completed.resolve }
1754
+ pendingLogin = pending
1755
+ try {
1756
+ return await runGaDrawerLogin({
1757
+ ui,
1758
+ request,
1759
+ completed: completed.promise,
1760
+ apply: (next) => applyRequest(client, scope, next, shown),
1761
+ })
1762
+ } finally {
1763
+ if (pendingLogin === pending) pendingLogin = undefined
1764
+ }
1765
+ }
1766
+
1767
+ function onNotification(
1768
+ client: GaLocationClient,
1769
+ notification: GaNotification,
1770
+ scope: GaScope,
1771
+ ) {
1772
+ const ui = createGaMenuUi(context, () => isCurrent(client, scope))
1648
1773
  const payload = notification.payload
1649
1774
  if ('notify' in payload) {
1775
+ if (
1776
+ pendingLogin?.scope === scopeKey(scope) &&
1777
+ [
1778
+ 'Account added.',
1779
+ 'The Antigravity pool login could not be completed.',
1780
+ ].includes(payload.notify.message)
1781
+ ) {
1782
+ pendingLogin.finish(payload.notify.kind !== 'error')
1783
+ return
1784
+ }
1650
1785
  ui.toast(payload.notify.message, payload.notify.kind)
1651
1786
  return
1652
1787
  }
@@ -1657,7 +1792,7 @@ export function setupGaTui(
1657
1792
  {
1658
1793
  ui,
1659
1794
  apply: async (request) => {
1660
- const result = await applyChoice(scope, request, shown)
1795
+ const result = await applyChoice(client, ui, scope, request, shown)
1661
1796
  shown = presentGaMenu(
1662
1797
  latest.get(scopeKey(scope)) ?? snapshot,
1663
1798
  now(),
@@ -1682,36 +1817,76 @@ export function setupGaTui(
1682
1817
  }
1683
1818
 
1684
1819
  let inFlight = false
1820
+ let shownScope = ''
1821
+ // Session locations are immutable; keep only the most recently viewed sessions.
1822
+ const sessionLocations = new Map<string, GaLocationRef>()
1823
+ const sessionLocation = async (sessionID: string): Promise<GaLocationRef> => {
1824
+ const location =
1825
+ sessionLocations.get(sessionID) ??
1826
+ (await context.client.session.get({ sessionID })).location
1827
+ if (active()) {
1828
+ sessionLocations.delete(sessionID)
1829
+ sessionLocations.set(sessionID, location)
1830
+ if (sessionLocations.size > MAX_SESSION_LOCATIONS) {
1831
+ const oldest = sessionLocations.keys().next().value
1832
+ if (oldest !== undefined) sessionLocations.delete(oldest)
1833
+ }
1834
+ }
1835
+ return location
1836
+ }
1685
1837
  const tick = () => {
1686
1838
  if (inFlight || !active()) return
1687
1839
  inFlight = true
1688
- void pollGaOnce({
1689
- client,
1690
- scope: () => currentScope(context.ui.router.current()),
1691
- onSnapshot: showSnapshot,
1692
- onNotification,
1693
- ...(logger ? { logger } : {}),
1694
- }).finally(() => {
1695
- inFlight = false
1696
- })
1840
+ void (async () => {
1841
+ const scope = currentScope(context.ui.router.current())
1842
+ const nextScope = scopeKey(scope)
1843
+ if (shownScope !== nextScope) {
1844
+ latest.clear()
1845
+ setView(undefined)
1846
+ pendingLogin?.finish(false)
1847
+ shownScope = nextScope
1848
+ }
1849
+ // Session lookup is global; RPC queues remain local to its returned location.
1850
+ const location =
1851
+ scope.kind === 'session'
1852
+ ? await sessionLocation(scope.sessionID)
1853
+ : context.location
1854
+ if (
1855
+ !active() ||
1856
+ nextScope !== scopeKey(currentScope(context.ui.router.current()))
1857
+ )
1858
+ return
1859
+ await refresh(clients.select(location), scope)
1860
+ })()
1861
+ .catch((error: unknown) => {
1862
+ if (!active()) return
1863
+ clients.select(context.location)
1864
+ logger?.warn('ga-session-location-failed', {
1865
+ error: error instanceof Error ? error.name : typeof error,
1866
+ })
1867
+ })
1868
+ .finally(() => {
1869
+ inFlight = false
1870
+ })
1697
1871
  }
1698
1872
  const stop = (options.schedule ?? defaultSchedule)(tick, GA_SIDEBAR_PULL_MS)
1699
1873
  tick()
1700
1874
 
1701
- let cleaned = false
1702
1875
  return async () => {
1703
1876
  if (cleaned) return
1704
1877
  cleaned = true
1878
+ pendingLogin?.finish(false)
1705
1879
  stop()
1706
- client.dispose()
1880
+ clients.dispose()
1881
+ sessionLocations.clear()
1707
1882
  releaseSlot()
1708
1883
  }
1709
1884
  }
1710
1885
 
1711
1886
  /**
1712
1887
  * The GA TUI plugin definition (`{ id, setup }`, the 2.0.22 TUI plugin
1713
- * shape). Importing this module starts nothing; `setup` binds to the
1714
- * context's location and returns the cleanup that stops everything it
1888
+ * shape). Importing this module starts nothing; `setup` follows the current
1889
+ * session's location and returns the cleanup that stops everything it
1715
1890
  * started. The host calls `setup(context)`; the package's `./tui` entry
1716
1891
  * passes the plugin version as the second argument. This module's graph
1717
1892
  * may use no Node built-in (the build refuses one), so it cannot read