@cortexkit/opencode-antigravity-auth 3.0.35 → 3.0.36

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.
@@ -31,11 +31,10 @@
31
31
  * not match is refused and logged by field name only.
32
32
  *
33
33
  * The wire shapes mirror the facade's `ga/rpc/protocol.ts` (clean v1:
34
- * accounts carry opaque `selector`s, typed account actions name accounts
35
- * only by selector, every snapshot carries the location's settings). GA
36
- * notifications name a dialog command only, so this host builds the
37
- * `/antigravity` menu from the latest snapshot and the shared drawer renders
38
- * it; after every apply the menu is rebuilt from a fresh `state` read.
34
+ * accounts carry opaque `selector`s and every snapshot carries the location's
35
+ * settings). Notifications and apply answers carry the server's shared menu.
36
+ * The drawer keeps its presentation while submitting the issued menu item
37
+ * and action ids, never a sidebar selector or an account position.
39
38
  *
40
39
  * Nothing here imports account storage, tokens, OAuth, the vault client or
41
40
  * server code, and nothing writes to the terminal or forces a theme.
@@ -59,10 +58,15 @@ import {
59
58
  type MenuAction,
60
59
  type MenuApplyRequest,
61
60
  type MenuApplyResult,
61
+ type MenuDialogPayload,
62
62
  type MenuModel,
63
+ type MenuNotifyPayload,
63
64
  type MenuParseResult,
64
65
  type MenuSection,
65
66
  type MenuUi,
67
+ parseMenuApplyResult,
68
+ parseMenuDialogPayload,
69
+ parseMenuNotifyPayload,
66
70
  } from "./shared/07365a7d2ccade4c-host-api.js"
67
71
  import {
68
72
  AntigravitySidebar,
@@ -186,16 +190,6 @@ export type GaScope =
186
190
  | { readonly kind: 'session'; readonly sessionID: string }
187
191
  | { readonly kind: 'sessionless' }
188
192
 
189
- /** The dialog commands the server names in notifications and text applies. */
190
- export const GA_COMMANDS = [
191
- 'antigravity-quota',
192
- 'antigravity-account',
193
- 'antigravity-killswitch',
194
- 'antigravity-dump',
195
- 'antigravity-logging',
196
- ] as const
197
- export type GaCommand = (typeof GA_COMMANDS)[number]
198
-
199
193
  export const GA_LOG_LEVELS = [
200
194
  'error',
201
195
  'warn',
@@ -207,9 +201,7 @@ export type GaLogLevel = (typeof GA_LOG_LEVELS)[number]
207
201
 
208
202
  export interface GaNotification {
209
203
  readonly cursor: number
210
- readonly type: 'open-dialog'
211
- readonly command: GaCommand
212
- readonly text: string
204
+ readonly payload: MenuDialogPayload | MenuNotifyPayload
213
205
  }
214
206
 
215
207
  /** A redacted account plus the opaque selector that names its credential. */
@@ -254,39 +246,9 @@ export type GaStateOutput =
254
246
  | GaSnapshot
255
247
  | { readonly kind: 'disposed'; readonly generation: string }
256
248
 
257
- /** A typed account action; accounts are named only by selector. */
258
- export type GaAccountAction =
259
- | {
260
- readonly kind: 'select'
261
- readonly selector: string
262
- readonly target: 'active' | 'claude' | 'gemini'
263
- }
264
- | { readonly kind: 'enable'; readonly selector: string }
265
- | { readonly kind: 'disable'; readonly selector: string }
266
- | { readonly kind: 'remove'; readonly selector: string }
267
-
268
249
  /** What the client sends besides version, generation and scope. */
269
- export type GaApplyBody =
270
- | { readonly command: GaCommand; readonly arguments: string }
271
- | {
272
- readonly command: 'antigravity-account'
273
- readonly action: GaAccountAction
274
- }
275
-
276
- export type GaTargetOutcome =
277
- | 'applied'
278
- | 'stale-target'
279
- | 'unknown-target'
280
- | 'unsupported-index-action'
281
- | 'failed'
282
-
283
- /** The command result fields this TUI reads; the rest are validated only. */
284
- export interface GaCommandResult {
285
- readonly command: GaCommand
286
- readonly status: 'applied' | 'rejected' | 'failed'
287
- readonly text: string
288
- readonly authorizationUrl?: string | null
289
- readonly targetOutcome?: GaTargetOutcome | null
250
+ export interface GaApplyBody {
251
+ readonly request: MenuApplyRequest
290
252
  }
291
253
 
292
254
  export type GaApplyOutput =
@@ -294,7 +256,7 @@ export type GaApplyOutput =
294
256
  readonly kind: 'applied'
295
257
  readonly generation: string
296
258
  readonly scope: GaScope
297
- readonly result: GaCommandResult
259
+ readonly result: MenuApplyResult
298
260
  }
299
261
  | { readonly kind: 'stale-generation'; readonly generation: string }
300
262
  | { readonly kind: 'disposed'; readonly generation: string }
@@ -304,13 +266,6 @@ const SESSION_ID = /^[\x21-\x7e]{1,256}$/
304
266
  const ACCOUNT_ID = /^acct-(0|[1-9][0-9]{0,5})$/
305
267
  const ACCOUNT_LABEL = /^Account [1-9][0-9]{0,5}$/
306
268
  const SELECTOR = /^sel-[A-Za-z0-9_-]{32}$/
307
- const TARGET_OUTCOMES: readonly GaTargetOutcome[] = [
308
- 'applied',
309
- 'stale-target',
310
- 'unknown-target',
311
- 'unsupported-index-action',
312
- 'failed',
313
- ]
314
269
 
315
270
  type Issues = string[]
316
271
 
@@ -587,17 +542,16 @@ function checkNotification(value: unknown, path: string, issues: Issues) {
587
542
  issues.push(`${path}: expected a notification`)
588
543
  return
589
544
  }
590
- keys(value, ['cursor', 'type', 'command', 'text'], [], path, issues)
545
+ keys(value, ['cursor', 'payload'], [], path, issues)
591
546
  if (!isCursor(value.cursor) || value.cursor < 1) {
592
547
  issues.push(`${path}.cursor: expected a positive cursor`)
593
548
  }
594
- if (value.type !== 'open-dialog') {
595
- issues.push(`${path}.type: unknown notification type`)
596
- }
597
- if (!GA_COMMANDS.includes(value.command as GaCommand)) {
598
- issues.push(`${path}.command: unknown command`)
599
- }
600
- if (typeof value.text !== 'string') issues.push(`${path}.text: expected text`)
549
+ const parsed =
550
+ isRecord(value.payload) && Object.hasOwn(value.payload, 'notify')
551
+ ? parseMenuNotifyPayload(value.payload)
552
+ : parseMenuDialogPayload(value.payload)
553
+ if (!parsed.ok)
554
+ issues.push(...parsed.issues.map((issue) => `${path}.payload: ${issue}`))
601
555
  }
602
556
 
603
557
  function checkBool(value: unknown, path: string, issues: Issues) {
@@ -671,77 +625,6 @@ function checkAccountsStatus(value: unknown, path: string, issues: Issues) {
671
625
  issues.push(`${path}.kind: unknown accounts status`)
672
626
  }
673
627
 
674
- function checkAccountList(value: unknown, path: string, issues: Issues) {
675
- if (value === null) return
676
- if (!Array.isArray(value) || value.length > 64) {
677
- issues.push(`${path}: expected at most 64 accounts`)
678
- return
679
- }
680
- value.forEach((entry, index) => {
681
- checkAccount(entry, `${path}.${index}`, issues)
682
- })
683
- }
684
-
685
- /** One command result, with the closed field list of its command. */
686
- function checkCommandResult(value: unknown, path: string, issues: Issues) {
687
- if (!isRecord(value)) {
688
- issues.push(`${path}: expected a command result`)
689
- return
690
- }
691
- const base = ['command', 'status', 'text']
692
- if (
693
- value.status !== 'applied' &&
694
- value.status !== 'rejected' &&
695
- value.status !== 'failed'
696
- ) {
697
- issues.push(`${path}.status: unknown status`)
698
- }
699
- if (typeof value.text !== 'string') issues.push(`${path}.text: expected text`)
700
- switch (value.command) {
701
- case 'antigravity-quota':
702
- keys(value, [...base, 'accounts'], [], path, issues)
703
- checkAccountList(value.accounts, `${path}.accounts`, issues)
704
- return
705
- case 'antigravity-account':
706
- keys(
707
- value,
708
- [...base, 'accounts', 'authorizationUrl', 'targetOutcome'],
709
- [],
710
- path,
711
- issues,
712
- )
713
- checkAccountList(value.accounts, `${path}.accounts`, issues)
714
- if (
715
- value.authorizationUrl !== null &&
716
- !(
717
- typeof value.authorizationUrl === 'string' &&
718
- /^https:\/\//.test(value.authorizationUrl) &&
719
- value.authorizationUrl.length <= 4096
720
- )
721
- ) {
722
- issues.push(`${path}.authorizationUrl: expected an https link or null`)
723
- }
724
- if (
725
- value.targetOutcome !== null &&
726
- !TARGET_OUTCOMES.includes(value.targetOutcome as GaTargetOutcome)
727
- ) {
728
- issues.push(`${path}.targetOutcome: unknown outcome`)
729
- }
730
- return
731
- case 'antigravity-killswitch':
732
- keys(value, [...base, 'killswitch'], [], path, issues)
733
- return
734
- case 'antigravity-dump':
735
- keys(value, [...base, 'dump'], [], path, issues)
736
- return
737
- case 'antigravity-logging':
738
- keys(value, [...base, 'logLevel'], [], path, issues)
739
- return
740
- default:
741
- issues.push(`${path}.command: unknown command`)
742
- }
743
- }
744
-
745
628
  /** Unwraps the host's `{ output }` answer. */
746
629
  function unwrap(raw: unknown, issues: Issues): unknown {
747
630
  if (!isRecord(raw)) {
@@ -870,7 +753,8 @@ export function parseGaApplyAnswer(
870
753
  )
871
754
  checkGeneration(output.generation, 'output.generation', issues)
872
755
  checkScope(output.scope, 'output.scope', issues)
873
- checkCommandResult(output.result, 'output.result', issues)
756
+ const result = parseMenuApplyResult(output.result)
757
+ if (!result.ok) issues.push(...result.issues)
874
758
  return finish(output, issues)
875
759
  }
876
760
 
@@ -912,7 +796,7 @@ export interface GaLocationClient {
912
796
  /** The next cursor this client sends for `scope`. */
913
797
  cursor(scope: GaScope): number
914
798
  pull(scope: GaScope): Promise<GaPullResult>
915
- apply(scope: GaScope, body: GaApplyBody): Promise<GaCommandResult>
799
+ apply(scope: GaScope, body: GaApplyBody): Promise<MenuApplyResult>
916
800
  dispose(): void
917
801
  disposed(): boolean
918
802
  }
@@ -1032,26 +916,6 @@ export function createGaLocationClient(options: {
1032
916
 
1033
917
  // ── Menu over the native state ──────────────────────────────────────────────
1034
918
 
1035
- /**
1036
- * GA notifications name only a dialog command, so this host builds the
1037
- * `/antigravity` menu itself from the latest `state` answer: the accounts
1038
- * with their opaque selectors and the location's settings, both read fresh
1039
- * for that answer. The shared drawer renders it like the OpenCode 1 menu.
1040
- * Each item and action id encodes what the action sends; an account is named
1041
- * only by its selector, never by position or `acct-<n>` id.
1042
- */
1043
- const SECTION_FOR_COMMAND: Readonly<Record<GaCommand, string>> = {
1044
- 'antigravity-account': 'accounts',
1045
- 'antigravity-quota': 'quota',
1046
- 'antigravity-killswitch': 'limits',
1047
- 'antigravity-dump': 'diagnostics',
1048
- 'antigravity-logging': 'diagnostics',
1049
- }
1050
-
1051
- export function sectionForCommand(command: GaCommand): string {
1052
- return SECTION_FOR_COMMAND[command]
1053
- }
1054
-
1055
919
  const ACCOUNT_ITEM_PREFIX = 'account:'
1056
920
 
1057
921
  function onOff(value: boolean): string {
@@ -1130,7 +994,8 @@ export function buildGaMenu(snapshot: GaSnapshot, now: number): MenuModel {
1130
994
  'Use for Gemini',
1131
995
  'Make this the current Gemini account.',
1132
996
  ),
1133
- ...(snapshot.vaultHostStatus
997
+ ...(snapshot.vaultHostStatus ||
998
+ settings.selectionStrategy === 'vault'
1134
999
  ? []
1135
1000
  : [
1136
1001
  {
@@ -1147,16 +1012,17 @@ export function buildGaMenu(snapshot: GaSnapshot, now: number): MenuModel {
1147
1012
  ],
1148
1013
  }
1149
1014
  }),
1150
- actions: snapshot.vaultHostStatus
1151
- ? []
1152
- : [
1153
- {
1154
- id: 'add',
1155
- label: 'Add account',
1156
- description: 'Sign in with Google in your browser.',
1157
- knobs: [],
1158
- },
1159
- ],
1015
+ actions:
1016
+ snapshot.vaultHostStatus || settings.selectionStrategy === 'vault'
1017
+ ? []
1018
+ : [
1019
+ {
1020
+ id: 'add',
1021
+ label: 'Add account',
1022
+ description: 'Sign in with Google in your browser.',
1023
+ knobs: [],
1024
+ },
1025
+ ],
1160
1026
  },
1161
1027
  {
1162
1028
  id: 'quota',
@@ -1285,7 +1151,7 @@ export function buildGaMenu(snapshot: GaSnapshot, now: number): MenuModel {
1285
1151
  }
1286
1152
  }
1287
1153
 
1288
- /** Why a drawer choice could not be turned into a native apply. */
1154
+ /** A displayed choice is no longer present in the server-issued menu. */
1289
1155
  export class GaMenuChoiceError extends Error {
1290
1156
  constructor(message: string) {
1291
1157
  super(message)
@@ -1293,130 +1159,144 @@ export class GaMenuChoiceError extends Error {
1293
1159
  }
1294
1160
  }
1295
1161
 
1296
- const TEXT_ACTIONS: Readonly<Record<string, GaApplyBody>> = {
1297
- 'accounts/add': {
1298
- command: 'antigravity-account',
1299
- arguments: 'add-oauth-start',
1300
- },
1301
- 'quota/refresh': { command: 'antigravity-quota', arguments: 'refresh' },
1302
- 'limits/killswitch-on': {
1303
- command: 'antigravity-killswitch',
1304
- arguments: 'enabled=true',
1305
- },
1306
- 'limits/killswitch-off': {
1307
- command: 'antigravity-killswitch',
1308
- arguments: 'enabled=false',
1309
- },
1310
- 'diagnostics/dump-on': { command: 'antigravity-dump', arguments: 'on' },
1311
- 'diagnostics/dump-off': { command: 'antigravity-dump', arguments: 'off' },
1162
+ export interface GaMenuPresentation {
1163
+ readonly menu: MenuModel
1164
+ readonly source: MenuModel
1165
+ request(choice: MenuApplyRequest): MenuApplyRequest
1312
1166
  }
1313
1167
 
1314
1168
  /**
1315
- * The native apply for one drawer choice. Explicit target values are sent
1316
- * ("turn on"), never a toggle, so a repeated or late choice cannot flip a
1317
- * setting back. An account item sends its selector exactly as the server
1318
- * issued it; a malformed one is refused here rather than guessed at.
1169
+ * Keep the drawer's labels and order, but bind every choice to an action
1170
+ * actually issued by the server. Snapshot selectors are display data, not
1171
+ * shared-menu item ids. The bindings retain the server's exact item id even
1172
+ * when the roster changes before a choice arrives.
1319
1173
  */
1320
- export function gaApplyBody(request: MenuApplyRequest): GaApplyBody {
1321
- const key = `${request.sectionId}/${request.actionId}`
1322
- if (request.sectionId === 'accounts' && request.itemId !== undefined) {
1323
- if (!request.itemId.startsWith(ACCOUNT_ITEM_PREFIX)) {
1324
- throw new GaMenuChoiceError('That account entry is not valid.')
1325
- }
1326
- const selector = request.itemId.slice(ACCOUNT_ITEM_PREFIX.length)
1327
- if (!SELECTOR.test(selector)) {
1328
- throw new GaMenuChoiceError('That account entry is not valid.')
1329
- }
1330
- const action: GaAccountAction | undefined =
1331
- request.actionId === 'enable'
1332
- ? { kind: 'enable', selector }
1333
- : request.actionId === 'disable'
1334
- ? { kind: 'disable', selector }
1335
- : request.actionId === 'remove'
1336
- ? { kind: 'remove', selector }
1337
- : request.actionId === 'select-active'
1338
- ? { kind: 'select', selector, target: 'active' }
1339
- : request.actionId === 'select-claude'
1340
- ? { kind: 'select', selector, target: 'claude' }
1341
- : request.actionId === 'select-gemini'
1342
- ? { kind: 'select', selector, target: 'gemini' }
1343
- : undefined
1344
- if (!action) throw new GaMenuChoiceError('Unknown account action.')
1345
- if (action.kind === 'remove' && request.confirmed !== true) {
1346
- throw new GaMenuChoiceError('Removing an account needs a confirmation.')
1347
- }
1348
- return { command: 'antigravity-account', action }
1349
- }
1350
- if (request.itemId !== undefined) {
1351
- throw new GaMenuChoiceError('Unknown menu entry.')
1352
- }
1353
- const fixed = TEXT_ACTIONS[key]
1354
- if (fixed) return fixed
1355
- if (key === 'limits/killswitch-minimum') {
1356
- const percent = request.values.percent
1357
- if (
1358
- typeof percent !== 'number' ||
1359
- !Number.isInteger(percent) ||
1360
- percent < 0 ||
1361
- percent > 100
1362
- ) {
1363
- throw new GaMenuChoiceError(
1364
- 'The minimum must be a whole number from 0 to 100.',
1365
- )
1366
- }
1174
+ export function presentGaMenu(
1175
+ snapshot: GaSnapshot,
1176
+ now: number,
1177
+ source: MenuModel,
1178
+ ): GaMenuPresentation {
1179
+ const bindings = new Map<
1180
+ string,
1181
+ (choice: MenuApplyRequest) => MenuApplyRequest
1182
+ >()
1183
+ const key = (
1184
+ sectionId: string,
1185
+ itemId: string | undefined,
1186
+ actionId: string,
1187
+ ) => JSON.stringify([sectionId, itemId, actionId])
1188
+ const bind = (
1189
+ sectionId: string,
1190
+ itemId: string | undefined,
1191
+ display: MenuAction,
1192
+ action: MenuAction,
1193
+ values: (
1194
+ choice: MenuApplyRequest['values'],
1195
+ ) => MenuApplyRequest['values'] = (choice) => choice,
1196
+ ): MenuAction => {
1197
+ bindings.set(key(sectionId, itemId, display.id), (choice) => ({
1198
+ command: source.command,
1199
+ sectionId,
1200
+ ...(itemId === undefined ? {} : { itemId }),
1201
+ actionId: action.id,
1202
+ values: values(choice.values),
1203
+ ...(choice.confirmed ? { confirmed: true } : {}),
1204
+ }))
1367
1205
  return {
1368
- command: 'antigravity-killswitch',
1369
- arguments: `minimum_remaining_percent=${percent}`,
1206
+ ...display,
1207
+ ...(action.confirm ? { confirm: action.confirm } : {}),
1370
1208
  }
1371
1209
  }
1372
- if (key === 'diagnostics/log-level') {
1373
- const level = request.values.level
1374
- if (!GA_LOG_LEVELS.includes(level as GaLogLevel)) {
1375
- throw new GaMenuChoiceError('Unknown log level.')
1376
- }
1377
- return { command: 'antigravity-logging', arguments: String(level) }
1378
- }
1379
- throw new GaMenuChoiceError('Unknown menu action.')
1380
- }
1381
-
1382
- const TARGET_TEXT: Readonly<
1383
- Record<Exclude<GaTargetOutcome, 'applied'>, string>
1384
- > = {
1385
- 'stale-target':
1386
- 'That account changed since the list was shown; nothing was changed. Choose it again from the refreshed list.',
1387
- 'unknown-target':
1388
- 'That account is no longer known; nothing was changed. Choose it again from the refreshed list.',
1389
- 'unsupported-index-action':
1390
- 'Accounts can only be chosen from the list; nothing was changed.',
1391
- failed: 'The account action did not complete.',
1392
- }
1393
-
1394
- /**
1395
- * Turns a native command result into the drawer's result. `ok` is true only
1396
- * when the command applied and, for an account action, its target applied.
1397
- * A sign-in link is shown in full: on GA the browser returns to this
1398
- * machine's sign-in listener, so there is nothing to paste.
1399
- */
1400
- export function gaMenuResult(
1401
- result: GaCommandResult,
1402
- menu: MenuModel,
1403
- ): MenuApplyResult {
1404
- const outcome = result.targetOutcome ?? null
1405
- const ok =
1406
- result.status === 'applied' && (outcome === null || outcome === 'applied')
1407
- let text = result.text
1408
- if (outcome !== null && outcome !== 'applied') {
1409
- text = `${TARGET_TEXT[outcome]}`
1410
- }
1411
- if (result.authorizationUrl) {
1412
- text = `Open ${result.authorizationUrl} in your browser and sign in.\nThe account is added when the browser returns here; there is nothing to paste.`
1210
+ const display = buildGaMenu(snapshot, now)
1211
+ const sections = display.sections
1212
+ .filter((section) => section.slot !== 'extra')
1213
+ .flatMap((section) => {
1214
+ const actual = source.sections.find(
1215
+ (candidate) => candidate.id === section.id,
1216
+ )
1217
+ if (!actual) return []
1218
+ const actions = section.actions.flatMap((action) => {
1219
+ const id =
1220
+ section.id === 'limits'
1221
+ ? 'set'
1222
+ : action.id === 'log-level'
1223
+ ? 'logging'
1224
+ : action.id.startsWith('dump-')
1225
+ ? 'dump'
1226
+ : action.id
1227
+ const offered = actual.actions.find((candidate) => candidate.id === id)
1228
+ if (!offered) return []
1229
+ const values =
1230
+ section.id !== 'limits'
1231
+ ? undefined
1232
+ : action.id === 'killswitch-minimum'
1233
+ ? (input: MenuApplyRequest['values']) => ({
1234
+ minimumRemainingPercent: input.percent ?? null,
1235
+ })
1236
+ : () => ({ enabled: action.id === 'killswitch-on' })
1237
+ return [bind(actual.id, undefined, action, offered, values)]
1238
+ })
1239
+ const items = actual.items.map((item) => {
1240
+ const projected = section.items.find(
1241
+ (candidate) => candidate.label === item.label,
1242
+ )
1243
+ if (!projected) return { ...item, actions: [] }
1244
+ return {
1245
+ ...projected,
1246
+ id: item.id,
1247
+ actions: projected.actions.flatMap((action) => {
1248
+ const target = action.id.startsWith('select-')
1249
+ ? action.id.slice('select-'.length)
1250
+ : undefined
1251
+ const offered = item.actions.find(
1252
+ (candidate) => candidate.id === (target ? 'select' : action.id),
1253
+ )
1254
+ if (!offered) return []
1255
+ return [
1256
+ bind(
1257
+ actual.id,
1258
+ item.id,
1259
+ action,
1260
+ offered,
1261
+ target ? () => ({ target }) : undefined,
1262
+ ),
1263
+ ]
1264
+ }),
1265
+ }
1266
+ })
1267
+ return [{ ...section, items, actions }]
1268
+ })
1269
+ // Enrollment and hosted status remain the server's own sections, including
1270
+ // their authority-dependent Connect/Disconnect actions and read-only host.
1271
+ for (const section of source.sections.filter(
1272
+ (candidate) => candidate.slot === 'extra',
1273
+ )) {
1274
+ sections.push({
1275
+ ...section,
1276
+ actions: section.actions.map((action) =>
1277
+ bind(section.id, undefined, action, action),
1278
+ ),
1279
+ items: section.items.map((item) => ({
1280
+ ...item,
1281
+ actions: item.actions.map((action) =>
1282
+ bind(section.id, item.id, action, action),
1283
+ ),
1284
+ })),
1285
+ })
1413
1286
  }
1414
1287
  return {
1415
- command: ANTIGRAVITY_MENU_COMMAND,
1416
- ok,
1417
- text,
1418
- ...(ok ? {} : { code: outcome ?? result.status }),
1419
- menu,
1288
+ menu: { ...display, sections },
1289
+ source,
1290
+ request(choice) {
1291
+ const resolve = bindings.get(
1292
+ key(choice.sectionId, choice.itemId, choice.actionId),
1293
+ )
1294
+ if (choice.command !== source.command || !resolve)
1295
+ throw new GaMenuChoiceError(
1296
+ 'That action is no longer offered. Open the menu again.',
1297
+ )
1298
+ return resolve(choice)
1299
+ },
1420
1300
  }
1421
1301
  }
1422
1302
 
@@ -1701,7 +1581,7 @@ export function setupGaTui(
1701
1581
  ),
1702
1582
  })
1703
1583
 
1704
- // The latest snapshot per scope; the drawer's menu is built from it.
1584
+ // Sidebar readings and presentation are scoped to the menu's own session.
1705
1585
  const latest = new Map<string, GaSnapshot>()
1706
1586
 
1707
1587
  const showSnapshot = (snapshot: GaSnapshot) => {
@@ -1717,45 +1597,42 @@ export function setupGaTui(
1717
1597
  }
1718
1598
 
1719
1599
  /**
1720
- * Pulls fresh state for `scope` and returns the menu built from it. Any
1600
+ * Pulls fresh state for `scope`. Any
1721
1601
  * notifications the pull carries are handled like a poll tick's.
1722
1602
  */
1723
- const freshMenu = async (scope: GaScope): Promise<MenuModel | undefined> => {
1724
- let fresh: GaSnapshot | undefined
1603
+ const refresh = async (scope: GaScope): Promise<void> => {
1725
1604
  await pollGaOnce({
1726
1605
  client,
1727
1606
  scope: () => scope,
1728
1607
  onSnapshot: (snapshot) => {
1729
- fresh = snapshot
1730
1608
  showSnapshot(snapshot)
1731
1609
  },
1732
1610
  onNotification,
1733
1611
  ...(logger ? { logger } : {}),
1734
1612
  })
1735
- return fresh ? buildGaMenu(fresh, now()) : undefined
1736
1613
  }
1737
1614
 
1738
1615
  const applyChoice = async (
1739
1616
  scope: GaScope,
1740
1617
  request: MenuApplyRequest,
1741
- shown: () => MenuModel,
1618
+ shown: GaMenuPresentation,
1742
1619
  ): Promise<MenuApplyResult> => {
1743
1620
  const refused = async (text: string, code: string) => ({
1744
1621
  command: ANTIGRAVITY_MENU_COMMAND,
1745
1622
  ok: false,
1746
1623
  text,
1747
1624
  code,
1748
- menu: (await freshMenu(scope)) ?? shown(),
1625
+ menu: shown.source,
1749
1626
  })
1750
1627
  let body: GaApplyBody
1751
1628
  try {
1752
- body = gaApplyBody(request)
1629
+ body = { request: shown.request(request) }
1753
1630
  } catch (error) {
1754
1631
  if (error instanceof GaMenuChoiceError)
1755
1632
  return refused(error.message, 'invalid-choice')
1756
1633
  throw error
1757
1634
  }
1758
- let result: GaCommandResult
1635
+ let result: MenuApplyResult
1759
1636
  try {
1760
1637
  result = await client.apply(scope, body)
1761
1638
  } catch (error) {
@@ -1763,23 +1640,30 @@ export function setupGaTui(
1763
1640
  return refused(error.message, error.reason)
1764
1641
  throw error
1765
1642
  }
1766
- // Settings and accounts shown next come from a fresh read, not from the
1767
- // apply's answer.
1768
- const menu = (await freshMenu(scope)) ?? shown()
1769
- return gaMenuResult(result, menu)
1643
+ await refresh(scope)
1644
+ return result
1770
1645
  }
1771
1646
 
1772
1647
  function onNotification(notification: GaNotification, scope: GaScope) {
1648
+ const payload = notification.payload
1649
+ if ('notify' in payload) {
1650
+ ui.toast(payload.notify.message, payload.notify.kind)
1651
+ return
1652
+ }
1773
1653
  const snapshot = latest.get(scopeKey(scope))
1774
1654
  if (!snapshot) return
1775
- let shown = buildGaMenu(snapshot, now())
1655
+ let shown = presentGaMenu(snapshot, now(), payload.menu)
1776
1656
  void openAntigravityMenu(
1777
1657
  {
1778
1658
  ui,
1779
1659
  apply: async (request) => {
1780
- const result = await applyChoice(scope, request, () => shown)
1781
- shown = result.menu
1782
- return result
1660
+ const result = await applyChoice(scope, request, shown)
1661
+ shown = presentGaMenu(
1662
+ latest.get(scopeKey(scope)) ?? snapshot,
1663
+ now(),
1664
+ result.menu,
1665
+ )
1666
+ return { ...result, menu: shown.menu }
1783
1667
  },
1784
1668
  ...(context.renderer?.copyToClipboardOSC52
1785
1669
  ? {
@@ -1788,9 +1672,8 @@ export function setupGaTui(
1788
1672
  }
1789
1673
  : {}),
1790
1674
  onError: (message, detail) => logger?.warn(message, detail),
1791
- startSection: sectionForCommand(notification.command),
1792
1675
  },
1793
- { command: ANTIGRAVITY_MENU_COMMAND, menu: shown },
1676
+ { command: ANTIGRAVITY_MENU_COMMAND, menu: shown.menu },
1794
1677
  ).catch((error: unknown) => {
1795
1678
  logger?.warn('menu-drawer-failed', {
1796
1679
  error: error instanceof Error ? error.name : typeof error,