@cortexkit/opencode-antigravity-auth 3.0.34 → 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.
Files changed (107) hide show
  1. package/dist/cli.js +413 -182
  2. package/dist/cli.js.map +4 -4
  3. package/dist/cli.meta.json +196 -69
  4. package/dist/index.js +506 -245
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +217 -90
  7. package/dist/server.js +1185 -860
  8. package/dist/server.js.map +4 -4
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/common-auth-embedded/auth-menu/accounts.js +9 -3
  11. package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +5 -1
  12. package/dist/src/common-auth-embedded/claustrum/consumer.js +14 -5
  13. package/dist/src/common-auth-embedded/claustrum/custody.d.ts +11 -8
  14. package/dist/src/common-auth-embedded/claustrum/custody.js +26 -15
  15. package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +2 -0
  16. package/dist/src/common-auth-embedded/claustrum/enrollment.js +7 -0
  17. package/dist/src/common-auth-embedded/claustrum/host.d.ts +8 -0
  18. package/dist/src/common-auth-embedded/claustrum/host.js +113 -0
  19. package/dist/src/common-auth-embedded/claustrum/hub.d.ts +5 -1
  20. package/dist/src/common-auth-embedded/claustrum/hub.js +5 -2
  21. package/dist/src/common-auth-embedded/claustrum/index.d.ts +2 -1
  22. package/dist/src/common-auth-embedded/claustrum/index.js +2 -1
  23. package/dist/src/common-auth-embedded/opencode2/install.js +42 -9
  24. package/dist/src/common-auth-embedded/opencode2/types.d.ts +3 -1
  25. package/dist/src/common-auth-embedded/setup/command.js +8 -4
  26. package/dist/src/common-auth-embedded/setup/enroll.js +3 -0
  27. package/dist/src/common-auth-embedded/source-output.json +68 -52
  28. package/dist/src/ga/rpc/protocol.d.ts +1 -0
  29. package/dist/src/ga/rpc/protocol.d.ts.map +1 -1
  30. package/dist/src/ga/rpc/protocol.js +4 -1
  31. package/dist/src/ga/rpc/protocol.js.map +1 -1
  32. package/dist/src/ga/server/auth.d.ts.map +1 -1
  33. package/dist/src/ga/server/auth.js +27 -4
  34. package/dist/src/ga/server/auth.js.map +1 -1
  35. package/dist/src/ga/server/index.d.ts.map +1 -1
  36. package/dist/src/ga/server/index.js +5 -1
  37. package/dist/src/ga/server/index.js.map +1 -1
  38. package/dist/src/ga/tui/host-ga.d.ts +22 -58
  39. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  40. package/dist/src/ga/tui/host-ga.js +161 -248
  41. package/dist/src/ga/tui/host-ga.js.map +1 -1
  42. package/dist/src/plugin/__fixtures__/verified-store.d.ts +1 -1
  43. package/dist/src/plugin/__fixtures__/verified-store.js +4 -4
  44. package/dist/src/plugin/auth-loader.js +1 -1
  45. package/dist/src/plugin/auth-loader.js.map +1 -1
  46. package/dist/src/plugin/background-vault-quota-refresh.js +1 -1
  47. package/dist/src/plugin/background-vault-quota-refresh.js.map +1 -1
  48. package/dist/src/plugin/ga-location-services.d.ts +1 -0
  49. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  50. package/dist/src/plugin/ga-location-services.js +87 -51
  51. package/dist/src/plugin/ga-location-services.js.map +1 -1
  52. package/dist/src/plugin/index.d.ts.map +1 -1
  53. package/dist/src/plugin/index.js +2 -2
  54. package/dist/src/plugin/index.js.map +1 -1
  55. package/dist/src/plugin/shared/source-sidebar.js +1 -1
  56. package/dist/src/plugin/shared/source-sidebar.js.map +1 -1
  57. package/dist/src/plugin/vault-activation.d.ts.map +1 -1
  58. package/dist/src/plugin/vault-activation.js +10 -2
  59. package/dist/src/plugin/vault-activation.js.map +1 -1
  60. package/dist/src/plugin/vault-custody.d.ts.map +1 -1
  61. package/dist/src/plugin/vault-custody.js +25 -3
  62. package/dist/src/plugin/vault-custody.js.map +1 -1
  63. package/dist/src/runtime-layout.js +3 -3
  64. package/dist/src/runtime-layout.js.map +1 -1
  65. package/dist/src/setup.d.ts.map +1 -1
  66. package/dist/src/setup.js +8 -5
  67. package/dist/src/setup.js.map +1 -1
  68. package/dist/tui-build-map.json +1 -1
  69. package/dist/tui-ga-build-map.json +5 -5
  70. package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +5 -1
  71. package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +11 -8
  72. package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +2 -0
  73. package/dist/types/src/common-auth-embedded/claustrum/host.d.ts +8 -0
  74. package/dist/types/src/common-auth-embedded/claustrum/hub.d.ts +5 -1
  75. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +2 -1
  76. package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +3 -1
  77. package/dist/types/src/ga/rpc/protocol.d.ts +1 -0
  78. package/dist/types/src/ga/rpc/protocol.d.ts.map +1 -1
  79. package/dist/types/src/ga/server/auth.d.ts.map +1 -1
  80. package/dist/types/src/ga/server/index.d.ts.map +1 -1
  81. package/dist/types/src/plugin/ga-location-services.d.ts +1 -0
  82. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  83. package/dist/types/src/plugin/index.d.ts.map +1 -1
  84. package/dist/types/src/plugin/vault-activation.d.ts.map +1 -1
  85. package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
  86. package/dist/types/src/setup.d.ts.map +1 -1
  87. package/package.json +2 -2
  88. package/src/common-auth-embedded/auth-menu/accounts.js +9 -3
  89. package/src/common-auth-embedded/claustrum/consumer.d.ts +5 -1
  90. package/src/common-auth-embedded/claustrum/consumer.js +14 -5
  91. package/src/common-auth-embedded/claustrum/custody.d.ts +11 -8
  92. package/src/common-auth-embedded/claustrum/custody.js +26 -15
  93. package/src/common-auth-embedded/claustrum/enrollment.d.ts +2 -0
  94. package/src/common-auth-embedded/claustrum/enrollment.js +7 -0
  95. package/src/common-auth-embedded/claustrum/host.d.ts +8 -0
  96. package/src/common-auth-embedded/claustrum/host.js +113 -0
  97. package/src/common-auth-embedded/claustrum/hub.d.ts +5 -1
  98. package/src/common-auth-embedded/claustrum/hub.js +5 -2
  99. package/src/common-auth-embedded/claustrum/index.d.ts +2 -1
  100. package/src/common-auth-embedded/claustrum/index.js +2 -1
  101. package/src/common-auth-embedded/opencode2/install.js +42 -9
  102. package/src/common-auth-embedded/opencode2/types.d.ts +3 -1
  103. package/src/common-auth-embedded/setup/command.js +8 -4
  104. package/src/common-auth-embedded/setup/enroll.js +3 -0
  105. package/src/common-auth-embedded/source-output.json +68 -52
  106. package/src/tui-ga-compiled/host-ga.js +133 -241
  107. package/src/tui-ga-raw/host-ga.tsx +222 -315
@@ -31,11 +31,10 @@ import { jsx as _jsx } from "@opentui/solid/jsx-runtime";
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.
@@ -43,7 +42,7 @@ import { jsx as _jsx } from "@opentui/solid/jsx-runtime";
43
42
  import { createSignal } from 'solid-js';
44
43
  import { projectAccount, projectSidebar, } from '../../sidebar-projection';
45
44
  import { MenuRefusedError, openAntigravityMenu, } from '../../tui/command-dialogs';
46
- import { ANTIGRAVITY_MENU_COMMAND, ANTIGRAVITY_MENU_TITLE, } from '../../tui/host-api';
45
+ import { ANTIGRAVITY_MENU_COMMAND, ANTIGRAVITY_MENU_TITLE, parseMenuApplyResult, parseMenuDialogPayload, parseMenuNotifyPayload, } from '../../tui/host-api';
47
46
  import { AntigravitySidebar, DEFAULT_FRAME_SETTINGS, } from '../../tui/sidebar-frame';
48
47
  export const GA_TUI_ID = 'cortexkit.antigravity-auth';
49
48
  export const GA_RPC_ID = 'antigravity-auth';
@@ -52,14 +51,6 @@ export const GA_RPC_VERSION = 1;
52
51
  export const GA_SIDEBAR_PULL_MS = 1_000;
53
52
  /** Pulls in one tick while the server reports more notifications waiting. */
54
53
  const MAX_PULLS_PER_TICK = 4;
55
- /** The dialog commands the server names in notifications and text applies. */
56
- export const GA_COMMANDS = [
57
- 'antigravity-quota',
58
- 'antigravity-account',
59
- 'antigravity-killswitch',
60
- 'antigravity-dump',
61
- 'antigravity-logging',
62
- ];
63
54
  export const GA_LOG_LEVELS = [
64
55
  'error',
65
56
  'warn',
@@ -72,13 +63,6 @@ const SESSION_ID = /^[\x21-\x7e]{1,256}$/;
72
63
  const ACCOUNT_ID = /^acct-(0|[1-9][0-9]{0,5})$/;
73
64
  const ACCOUNT_LABEL = /^Account [1-9][0-9]{0,5}$/;
74
65
  const SELECTOR = /^sel-[A-Za-z0-9_-]{32}$/;
75
- const TARGET_OUTCOMES = [
76
- 'applied',
77
- 'stale-target',
78
- 'unknown-target',
79
- 'unsupported-index-action',
80
- 'failed',
81
- ];
82
66
  function isRecord(value) {
83
67
  if (typeof value !== 'object' || value === null || Array.isArray(value)) {
84
68
  return false;
@@ -282,18 +266,15 @@ function checkNotification(value, path, issues) {
282
266
  issues.push(`${path}: expected a notification`);
283
267
  return;
284
268
  }
285
- keys(value, ['cursor', 'type', 'command', 'text'], [], path, issues);
269
+ keys(value, ['cursor', 'payload'], [], path, issues);
286
270
  if (!isCursor(value.cursor) || value.cursor < 1) {
287
271
  issues.push(`${path}.cursor: expected a positive cursor`);
288
272
  }
289
- if (value.type !== 'open-dialog') {
290
- issues.push(`${path}.type: unknown notification type`);
291
- }
292
- if (!GA_COMMANDS.includes(value.command)) {
293
- issues.push(`${path}.command: unknown command`);
294
- }
295
- if (typeof value.text !== 'string')
296
- issues.push(`${path}.text: expected text`);
273
+ const parsed = isRecord(value.payload) && Object.hasOwn(value.payload, 'notify')
274
+ ? parseMenuNotifyPayload(value.payload)
275
+ : parseMenuDialogPayload(value.payload);
276
+ if (!parsed.ok)
277
+ issues.push(...parsed.issues.map((issue) => `${path}.payload: ${issue}`));
297
278
  }
298
279
  function checkBool(value, path, issues) {
299
280
  if (typeof value !== 'boolean')
@@ -345,63 +326,6 @@ function checkAccountsStatus(value, path, issues) {
345
326
  }
346
327
  issues.push(`${path}.kind: unknown accounts status`);
347
328
  }
348
- function checkAccountList(value, path, issues) {
349
- if (value === null)
350
- return;
351
- if (!Array.isArray(value) || value.length > 64) {
352
- issues.push(`${path}: expected at most 64 accounts`);
353
- return;
354
- }
355
- value.forEach((entry, index) => {
356
- checkAccount(entry, `${path}.${index}`, issues);
357
- });
358
- }
359
- /** One command result, with the closed field list of its command. */
360
- function checkCommandResult(value, path, issues) {
361
- if (!isRecord(value)) {
362
- issues.push(`${path}: expected a command result`);
363
- return;
364
- }
365
- const base = ['command', 'status', 'text'];
366
- if (value.status !== 'applied' &&
367
- value.status !== 'rejected' &&
368
- value.status !== 'failed') {
369
- issues.push(`${path}.status: unknown status`);
370
- }
371
- if (typeof value.text !== 'string')
372
- issues.push(`${path}.text: expected text`);
373
- switch (value.command) {
374
- case 'antigravity-quota':
375
- keys(value, [...base, 'accounts'], [], path, issues);
376
- checkAccountList(value.accounts, `${path}.accounts`, issues);
377
- return;
378
- case 'antigravity-account':
379
- keys(value, [...base, 'accounts', 'authorizationUrl', 'targetOutcome'], [], path, issues);
380
- checkAccountList(value.accounts, `${path}.accounts`, issues);
381
- if (value.authorizationUrl !== null &&
382
- !(typeof value.authorizationUrl === 'string' &&
383
- /^https:\/\//.test(value.authorizationUrl) &&
384
- value.authorizationUrl.length <= 4096)) {
385
- issues.push(`${path}.authorizationUrl: expected an https link or null`);
386
- }
387
- if (value.targetOutcome !== null &&
388
- !TARGET_OUTCOMES.includes(value.targetOutcome)) {
389
- issues.push(`${path}.targetOutcome: unknown outcome`);
390
- }
391
- return;
392
- case 'antigravity-killswitch':
393
- keys(value, [...base, 'killswitch'], [], path, issues);
394
- return;
395
- case 'antigravity-dump':
396
- keys(value, [...base, 'dump'], [], path, issues);
397
- return;
398
- case 'antigravity-logging':
399
- keys(value, [...base, 'logLevel'], [], path, issues);
400
- return;
401
- default:
402
- issues.push(`${path}.command: unknown command`);
403
- }
404
- }
405
329
  /** Unwraps the host's `{ output }` answer. */
406
330
  function unwrap(raw, issues) {
407
331
  if (!isRecord(raw)) {
@@ -449,9 +373,12 @@ export function parseGaStateAnswer(raw) {
449
373
  'route',
450
374
  'status',
451
375
  'settings',
452
- ], [], 'output', issues);
376
+ ], ['vaultHostStatus'], 'output', issues);
453
377
  if (!isCursor(output.readSeq))
454
378
  issues.push('output.readSeq: expected a count');
379
+ if (Object.hasOwn(output, 'vaultHostStatus') &&
380
+ output.vaultHostStatus !== 'Served by Thalamus')
381
+ issues.push('output.vaultHostStatus: expected the hosted vault status');
455
382
  checkAccountsStatus(output.accountsStatus, 'output.accountsStatus', issues);
456
383
  checkSettings(output.settings, 'output.settings', issues);
457
384
  checkGeneration(output.generation, 'output.generation', issues);
@@ -509,7 +436,9 @@ export function parseGaApplyAnswer(raw) {
509
436
  keys(output, ['version', 'kind', 'generation', 'scope', 'result'], [], 'output', issues);
510
437
  checkGeneration(output.generation, 'output.generation', issues);
511
438
  checkScope(output.scope, 'output.scope', issues);
512
- checkCommandResult(output.result, 'output.result', issues);
439
+ const result = parseMenuApplyResult(output.result);
440
+ if (!result.ok)
441
+ issues.push(...result.issues);
513
442
  return finish(output, issues);
514
443
  }
515
444
  // ── Location client ─────────────────────────────────────────────────────────
@@ -642,24 +571,6 @@ export function createGaLocationClient(options) {
642
571
  };
643
572
  }
644
573
  // ── Menu over the native state ──────────────────────────────────────────────
645
- /**
646
- * GA notifications name only a dialog command, so this host builds the
647
- * `/antigravity` menu itself from the latest `state` answer: the accounts
648
- * with their opaque selectors and the location's settings, both read fresh
649
- * for that answer. The shared drawer renders it like the OpenCode 1 menu.
650
- * Each item and action id encodes what the action sends; an account is named
651
- * only by its selector, never by position or `acct-<n>` id.
652
- */
653
- const SECTION_FOR_COMMAND = {
654
- 'antigravity-account': 'accounts',
655
- 'antigravity-quota': 'quota',
656
- 'antigravity-killswitch': 'limits',
657
- 'antigravity-dump': 'diagnostics',
658
- 'antigravity-logging': 'diagnostics',
659
- };
660
- export function sectionForCommand(command) {
661
- return SECTION_FOR_COMMAND[command];
662
- }
663
574
  const ACCOUNT_ITEM_PREFIX = 'account:';
664
575
  function onOff(value) {
665
576
  return value ? 'on' : 'off';
@@ -708,27 +619,34 @@ export function buildGaMenu(snapshot, now) {
708
619
  use('select-active', 'Use for all models', 'Make this the current account.'),
709
620
  use('select-claude', 'Use for Claude', 'Make this the current Claude account.'),
710
621
  use('select-gemini', 'Use for Gemini', 'Make this the current Gemini account.'),
711
- {
712
- id: 'remove',
713
- label: 'Remove',
714
- description: 'Delete this account from this machine.',
715
- knobs: [],
716
- confirm: {
717
- message: `Remove ${account.label}? This cannot be undone.`,
718
- irreversible: true,
719
- },
720
- },
622
+ ...(snapshot.vaultHostStatus ||
623
+ settings.selectionStrategy === 'vault'
624
+ ? []
625
+ : [
626
+ {
627
+ id: 'remove',
628
+ label: 'Remove',
629
+ description: 'Delete this account from this machine.',
630
+ knobs: [],
631
+ confirm: {
632
+ message: `Remove ${account.label}? This cannot be undone.`,
633
+ irreversible: true,
634
+ },
635
+ },
636
+ ]),
721
637
  ],
722
638
  };
723
639
  }),
724
- actions: [
725
- {
726
- id: 'add',
727
- label: 'Add account',
728
- description: 'Sign in with Google in your browser.',
729
- knobs: [],
730
- },
731
- ],
640
+ actions: snapshot.vaultHostStatus || settings.selectionStrategy === 'vault'
641
+ ? []
642
+ : [
643
+ {
644
+ id: 'add',
645
+ label: 'Add account',
646
+ description: 'Sign in with Google in your browser.',
647
+ knobs: [],
648
+ },
649
+ ],
732
650
  },
733
651
  {
734
652
  id: 'quota',
@@ -838,125 +756,121 @@ export function buildGaMenu(snapshot, now) {
838
756
  return {
839
757
  command: ANTIGRAVITY_MENU_COMMAND,
840
758
  title: ANTIGRAVITY_MENU_TITLE,
841
- sections,
759
+ sections: snapshot.vaultHostStatus
760
+ ? [
761
+ ...sections,
762
+ {
763
+ id: 'vault',
764
+ slot: 'extra',
765
+ title: 'Vault',
766
+ lines: [snapshot.vaultHostStatus],
767
+ items: [],
768
+ actions: [],
769
+ },
770
+ ]
771
+ : sections,
842
772
  };
843
773
  }
844
- /** Why a drawer choice could not be turned into a native apply. */
774
+ /** A displayed choice is no longer present in the server-issued menu. */
845
775
  export class GaMenuChoiceError extends Error {
846
776
  constructor(message) {
847
777
  super(message);
848
778
  this.name = 'GaMenuChoiceError';
849
779
  }
850
780
  }
851
- const TEXT_ACTIONS = {
852
- 'accounts/add': {
853
- command: 'antigravity-account',
854
- arguments: 'add-oauth-start',
855
- },
856
- 'quota/refresh': { command: 'antigravity-quota', arguments: 'refresh' },
857
- 'limits/killswitch-on': {
858
- command: 'antigravity-killswitch',
859
- arguments: 'enabled=true',
860
- },
861
- 'limits/killswitch-off': {
862
- command: 'antigravity-killswitch',
863
- arguments: 'enabled=false',
864
- },
865
- 'diagnostics/dump-on': { command: 'antigravity-dump', arguments: 'on' },
866
- 'diagnostics/dump-off': { command: 'antigravity-dump', arguments: 'off' },
867
- };
868
781
  /**
869
- * The native apply for one drawer choice. Explicit target values are sent
870
- * ("turn on"), never a toggle, so a repeated or late choice cannot flip a
871
- * setting back. An account item sends its selector exactly as the server
872
- * issued it; a malformed one is refused here rather than guessed at.
782
+ * Keep the drawer's labels and order, but bind every choice to an action
783
+ * actually issued by the server. Snapshot selectors are display data, not
784
+ * shared-menu item ids. The bindings retain the server's exact item id even
785
+ * when the roster changes before a choice arrives.
873
786
  */
874
- export function gaApplyBody(request) {
875
- const key = `${request.sectionId}/${request.actionId}`;
876
- if (request.sectionId === 'accounts' && request.itemId !== undefined) {
877
- if (!request.itemId.startsWith(ACCOUNT_ITEM_PREFIX)) {
878
- throw new GaMenuChoiceError('That account entry is not valid.');
879
- }
880
- const selector = request.itemId.slice(ACCOUNT_ITEM_PREFIX.length);
881
- if (!SELECTOR.test(selector)) {
882
- throw new GaMenuChoiceError('That account entry is not valid.');
883
- }
884
- const action = request.actionId === 'enable'
885
- ? { kind: 'enable', selector }
886
- : request.actionId === 'disable'
887
- ? { kind: 'disable', selector }
888
- : request.actionId === 'remove'
889
- ? { kind: 'remove', selector }
890
- : request.actionId === 'select-active'
891
- ? { kind: 'select', selector, target: 'active' }
892
- : request.actionId === 'select-claude'
893
- ? { kind: 'select', selector, target: 'claude' }
894
- : request.actionId === 'select-gemini'
895
- ? { kind: 'select', selector, target: 'gemini' }
896
- : undefined;
897
- if (!action)
898
- throw new GaMenuChoiceError('Unknown account action.');
899
- if (action.kind === 'remove' && request.confirmed !== true) {
900
- throw new GaMenuChoiceError('Removing an account needs a confirmation.');
901
- }
902
- return { command: 'antigravity-account', action };
903
- }
904
- if (request.itemId !== undefined) {
905
- throw new GaMenuChoiceError('Unknown menu entry.');
906
- }
907
- const fixed = TEXT_ACTIONS[key];
908
- if (fixed)
909
- return fixed;
910
- if (key === 'limits/killswitch-minimum') {
911
- const percent = request.values.percent;
912
- if (typeof percent !== 'number' ||
913
- !Number.isInteger(percent) ||
914
- percent < 0 ||
915
- percent > 100) {
916
- throw new GaMenuChoiceError('The minimum must be a whole number from 0 to 100.');
917
- }
787
+ export function presentGaMenu(snapshot, now, source) {
788
+ const bindings = new Map();
789
+ const key = (sectionId, itemId, actionId) => JSON.stringify([sectionId, itemId, actionId]);
790
+ const bind = (sectionId, itemId, display, action, values = (choice) => choice) => {
791
+ bindings.set(key(sectionId, itemId, display.id), (choice) => ({
792
+ command: source.command,
793
+ sectionId,
794
+ ...(itemId === undefined ? {} : { itemId }),
795
+ actionId: action.id,
796
+ values: values(choice.values),
797
+ ...(choice.confirmed ? { confirmed: true } : {}),
798
+ }));
918
799
  return {
919
- command: 'antigravity-killswitch',
920
- arguments: `minimum_remaining_percent=${percent}`,
800
+ ...display,
801
+ ...(action.confirm ? { confirm: action.confirm } : {}),
921
802
  };
922
- }
923
- if (key === 'diagnostics/log-level') {
924
- const level = request.values.level;
925
- if (!GA_LOG_LEVELS.includes(level)) {
926
- throw new GaMenuChoiceError('Unknown log level.');
927
- }
928
- return { command: 'antigravity-logging', arguments: String(level) };
929
- }
930
- throw new GaMenuChoiceError('Unknown menu action.');
931
- }
932
- const TARGET_TEXT = {
933
- 'stale-target': 'That account changed since the list was shown; nothing was changed. Choose it again from the refreshed list.',
934
- 'unknown-target': 'That account is no longer known; nothing was changed. Choose it again from the refreshed list.',
935
- 'unsupported-index-action': 'Accounts can only be chosen from the list; nothing was changed.',
936
- failed: 'The account action did not complete.',
937
- };
938
- /**
939
- * Turns a native command result into the drawer's result. `ok` is true only
940
- * when the command applied and, for an account action, its target applied.
941
- * A sign-in link is shown in full: on GA the browser returns to this
942
- * machine's sign-in listener, so there is nothing to paste.
943
- */
944
- export function gaMenuResult(result, menu) {
945
- const outcome = result.targetOutcome ?? null;
946
- const ok = result.status === 'applied' && (outcome === null || outcome === 'applied');
947
- let text = result.text;
948
- if (outcome !== null && outcome !== 'applied') {
949
- text = `${TARGET_TEXT[outcome]}`;
950
- }
951
- if (result.authorizationUrl) {
952
- text = `Open ${result.authorizationUrl} in your browser and sign in.\nThe account is added when the browser returns here; there is nothing to paste.`;
803
+ };
804
+ const display = buildGaMenu(snapshot, now);
805
+ const sections = display.sections
806
+ .filter((section) => section.slot !== 'extra')
807
+ .flatMap((section) => {
808
+ const actual = source.sections.find((candidate) => candidate.id === section.id);
809
+ if (!actual)
810
+ return [];
811
+ const actions = section.actions.flatMap((action) => {
812
+ const id = section.id === 'limits'
813
+ ? 'set'
814
+ : action.id === 'log-level'
815
+ ? 'logging'
816
+ : action.id.startsWith('dump-')
817
+ ? 'dump'
818
+ : action.id;
819
+ const offered = actual.actions.find((candidate) => candidate.id === id);
820
+ if (!offered)
821
+ return [];
822
+ const values = section.id !== 'limits'
823
+ ? undefined
824
+ : action.id === 'killswitch-minimum'
825
+ ? (input) => ({
826
+ minimumRemainingPercent: input.percent ?? null,
827
+ })
828
+ : () => ({ enabled: action.id === 'killswitch-on' });
829
+ return [bind(actual.id, undefined, action, offered, values)];
830
+ });
831
+ const items = actual.items.map((item) => {
832
+ const projected = section.items.find((candidate) => candidate.label === item.label);
833
+ if (!projected)
834
+ return { ...item, actions: [] };
835
+ return {
836
+ ...projected,
837
+ id: item.id,
838
+ actions: projected.actions.flatMap((action) => {
839
+ const target = action.id.startsWith('select-')
840
+ ? action.id.slice('select-'.length)
841
+ : undefined;
842
+ const offered = item.actions.find((candidate) => candidate.id === (target ? 'select' : action.id));
843
+ if (!offered)
844
+ return [];
845
+ return [
846
+ bind(actual.id, item.id, action, offered, target ? () => ({ target }) : undefined),
847
+ ];
848
+ }),
849
+ };
850
+ });
851
+ return [{ ...section, items, actions }];
852
+ });
853
+ // Enrollment and hosted status remain the server's own sections, including
854
+ // their authority-dependent Connect/Disconnect actions and read-only host.
855
+ for (const section of source.sections.filter((candidate) => candidate.slot === 'extra')) {
856
+ sections.push({
857
+ ...section,
858
+ actions: section.actions.map((action) => bind(section.id, undefined, action, action)),
859
+ items: section.items.map((item) => ({
860
+ ...item,
861
+ actions: item.actions.map((action) => bind(section.id, item.id, action, action)),
862
+ })),
863
+ });
953
864
  }
954
865
  return {
955
- command: ANTIGRAVITY_MENU_COMMAND,
956
- ok,
957
- text,
958
- ...(ok ? {} : { code: outcome ?? result.status }),
959
- menu,
866
+ menu: { ...display, sections },
867
+ source,
868
+ request(choice) {
869
+ const resolve = bindings.get(key(choice.sectionId, choice.itemId, choice.actionId));
870
+ if (choice.command !== source.command || !resolve)
871
+ throw new GaMenuChoiceError('That action is no longer offered. Open the menu again.');
872
+ return resolve(choice);
873
+ },
960
874
  };
961
875
  }
962
876
  // ── Dialogs ─────────────────────────────────────────────────────────────────
@@ -1143,7 +1057,7 @@ export function setupGaTui(context, options = {}) {
1143
1057
  append: 'sidebar.content',
1144
1058
  render: (input) => (_jsx(GaSidebar, { view: view, sessionID: input.sessionID, theme: () => context.theme, version: options.version ?? '', collapsed: collapse.collapsed, toggleCollapsed: collapse.toggle })),
1145
1059
  });
1146
- // The latest snapshot per scope; the drawer's menu is built from it.
1060
+ // Sidebar readings and presentation are scoped to the menu's own session.
1147
1061
  const latest = new Map();
1148
1062
  const showSnapshot = (snapshot) => {
1149
1063
  latest.set(scopeKey(snapshot.scope), snapshot);
@@ -1157,22 +1071,19 @@ export function setupGaTui(context, options = {}) {
1157
1071
  });
1158
1072
  };
1159
1073
  /**
1160
- * Pulls fresh state for `scope` and returns the menu built from it. Any
1074
+ * Pulls fresh state for `scope`. Any
1161
1075
  * notifications the pull carries are handled like a poll tick's.
1162
1076
  */
1163
- const freshMenu = async (scope) => {
1164
- let fresh;
1077
+ const refresh = async (scope) => {
1165
1078
  await pollGaOnce({
1166
1079
  client,
1167
1080
  scope: () => scope,
1168
1081
  onSnapshot: (snapshot) => {
1169
- fresh = snapshot;
1170
1082
  showSnapshot(snapshot);
1171
1083
  },
1172
1084
  onNotification,
1173
1085
  ...(logger ? { logger } : {}),
1174
1086
  });
1175
- return fresh ? buildGaMenu(fresh, now()) : undefined;
1176
1087
  };
1177
1088
  const applyChoice = async (scope, request, shown) => {
1178
1089
  const refused = async (text, code) => ({
@@ -1180,11 +1091,11 @@ export function setupGaTui(context, options = {}) {
1180
1091
  ok: false,
1181
1092
  text,
1182
1093
  code,
1183
- menu: (await freshMenu(scope)) ?? shown(),
1094
+ menu: shown.source,
1184
1095
  });
1185
1096
  let body;
1186
1097
  try {
1187
- body = gaApplyBody(request);
1098
+ body = { request: shown.request(request) };
1188
1099
  }
1189
1100
  catch (error) {
1190
1101
  if (error instanceof GaMenuChoiceError)
@@ -1200,22 +1111,25 @@ export function setupGaTui(context, options = {}) {
1200
1111
  return refused(error.message, error.reason);
1201
1112
  throw error;
1202
1113
  }
1203
- // Settings and accounts shown next come from a fresh read, not from the
1204
- // apply's answer.
1205
- const menu = (await freshMenu(scope)) ?? shown();
1206
- return gaMenuResult(result, menu);
1114
+ await refresh(scope);
1115
+ return result;
1207
1116
  };
1208
1117
  function onNotification(notification, scope) {
1118
+ const payload = notification.payload;
1119
+ if ('notify' in payload) {
1120
+ ui.toast(payload.notify.message, payload.notify.kind);
1121
+ return;
1122
+ }
1209
1123
  const snapshot = latest.get(scopeKey(scope));
1210
1124
  if (!snapshot)
1211
1125
  return;
1212
- let shown = buildGaMenu(snapshot, now());
1126
+ let shown = presentGaMenu(snapshot, now(), payload.menu);
1213
1127
  void openAntigravityMenu({
1214
1128
  ui,
1215
1129
  apply: async (request) => {
1216
- const result = await applyChoice(scope, request, () => shown);
1217
- shown = result.menu;
1218
- return result;
1130
+ const result = await applyChoice(scope, request, shown);
1131
+ shown = presentGaMenu(latest.get(scopeKey(scope)) ?? snapshot, now(), result.menu);
1132
+ return { ...result, menu: shown.menu };
1219
1133
  },
1220
1134
  ...(context.renderer?.copyToClipboardOSC52
1221
1135
  ? {
@@ -1223,8 +1137,7 @@ export function setupGaTui(context, options = {}) {
1223
1137
  }
1224
1138
  : {}),
1225
1139
  onError: (message, detail) => logger?.warn(message, detail),
1226
- startSection: sectionForCommand(notification.command),
1227
- }, { command: ANTIGRAVITY_MENU_COMMAND, menu: shown }).catch((error) => {
1140
+ }, { command: ANTIGRAVITY_MENU_COMMAND, menu: shown.menu }).catch((error) => {
1228
1141
  logger?.warn('menu-drawer-failed', {
1229
1142
  error: error instanceof Error ? error.name : typeof error,
1230
1143
  });