@cortexkit/opencode-antigravity-auth 3.0.39 → 3.0.40

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 (69) hide show
  1. package/dist/cli.js +266 -40
  2. package/dist/cli.js.map +4 -4
  3. package/dist/cli.meta.json +48 -19
  4. package/dist/index.js +708 -279
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.meta.json +85 -22
  7. package/dist/server.js +840 -411
  8. package/dist/server.js.map +4 -4
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +25 -4
  11. package/dist/src/common-auth-embedded/claustrum/enrollment.js +81 -4
  12. package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  13. package/dist/src/common-auth-embedded/claustrum/index.js +1 -1
  14. package/dist/src/common-auth-embedded/setup/command-error.d.ts +1 -1
  15. package/dist/src/common-auth-embedded/setup/command-error.js +3 -2
  16. package/dist/src/common-auth-embedded/setup/command.js +18 -5
  17. package/dist/src/common-auth-embedded/setup/enroll.d.ts +2 -2
  18. package/dist/src/common-auth-embedded/setup/enroll.js +13 -3
  19. package/dist/src/common-auth-embedded/setup/enrollment-access.js +77 -0
  20. package/dist/src/common-auth-embedded/setup/index.d.ts +1 -1
  21. package/dist/src/common-auth-embedded/setup/types.d.ts +12 -1
  22. package/dist/src/common-auth-embedded/source-output.json +48 -40
  23. package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
  24. package/dist/src/plugin/logger.d.ts +3 -1
  25. package/dist/src/plugin/logger.d.ts.map +1 -1
  26. package/dist/src/plugin/logger.js +15 -7
  27. package/dist/src/plugin/logger.js.map +1 -1
  28. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  29. package/dist/src/plugin/shared/request-services.js +34 -9
  30. package/dist/src/plugin/shared/request-services.js.map +1 -1
  31. package/dist/src/plugin/shared/vault-billing.d.ts +30 -0
  32. package/dist/src/plugin/shared/vault-billing.d.ts.map +1 -0
  33. package/dist/src/plugin/shared/vault-billing.js +196 -0
  34. package/dist/src/plugin/shared/vault-billing.js.map +1 -0
  35. package/dist/src/plugin/vault-custody.d.ts.map +1 -1
  36. package/dist/src/plugin/vault-custody.js +3 -0
  37. package/dist/src/plugin/vault-custody.js.map +1 -1
  38. package/dist/src/setup.d.ts.map +1 -1
  39. package/dist/src/setup.js +12 -0
  40. package/dist/src/setup.js.map +1 -1
  41. package/dist/tui-build-map.json +1 -1
  42. package/dist/tui-ga-build-map.json +1 -1
  43. package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +25 -4
  44. package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  45. package/dist/types/src/common-auth-embedded/setup/command-error.d.ts +1 -1
  46. package/dist/types/src/common-auth-embedded/setup/enroll.d.ts +2 -2
  47. package/dist/types/src/common-auth-embedded/setup/index.d.ts +1 -1
  48. package/dist/types/src/common-auth-embedded/setup/types.d.ts +12 -1
  49. package/dist/types/src/plugin/logger.d.ts +3 -1
  50. package/dist/types/src/plugin/logger.d.ts.map +1 -1
  51. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  52. package/dist/types/src/plugin/shared/vault-billing.d.ts +30 -0
  53. package/dist/types/src/plugin/shared/vault-billing.d.ts.map +1 -0
  54. package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
  55. package/dist/types/src/setup.d.ts.map +1 -1
  56. package/package.json +3 -3
  57. package/src/common-auth-embedded/claustrum/enrollment.d.ts +25 -4
  58. package/src/common-auth-embedded/claustrum/enrollment.js +81 -4
  59. package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
  60. package/src/common-auth-embedded/claustrum/index.js +1 -1
  61. package/src/common-auth-embedded/setup/command-error.d.ts +1 -1
  62. package/src/common-auth-embedded/setup/command-error.js +3 -2
  63. package/src/common-auth-embedded/setup/command.js +18 -5
  64. package/src/common-auth-embedded/setup/enroll.d.ts +2 -2
  65. package/src/common-auth-embedded/setup/enroll.js +13 -3
  66. package/src/common-auth-embedded/setup/enrollment-access.js +77 -0
  67. package/src/common-auth-embedded/setup/index.d.ts +1 -1
  68. package/src/common-auth-embedded/setup/types.d.ts +12 -1
  69. package/src/common-auth-embedded/source-output.json +48 -40
package/dist/cli.js CHANGED
@@ -17414,6 +17414,25 @@ function validEnrollmentDisplayName(displayName) {
17414
17414
  const length = Array.from(displayName).length;
17415
17415
  return length >= 1 && length <= 40 && !/[\p{Cc}\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069\u200b-\u200d\u2060\ufeff]/u.test(displayName);
17416
17416
  }
17417
+ function validEnrollmentRequestedGrants(grants) {
17418
+ return Array.isArray(grants) && grants.length >= 1 && grants.length <= 4 && Array.from(grants).every((grant) => {
17419
+ if (!isRecord6(grant) || Object.keys(grant).length !== 2 || grant.operation !== "read" && grant.operation !== "list" || !isRecord6(grant.selector))
17420
+ return false;
17421
+ const keys = Object.keys(grant.selector);
17422
+ const key = keys[0];
17423
+ return keys.length === 1 && (key === "category" || key === "exact") && typeof grant.selector[key] === "string" && grant.selector[key].trim().length > 0;
17424
+ });
17425
+ }
17426
+ function grantProposal(state) {
17427
+ return {
17428
+ ...state.requestedGrants !== void 0 && {
17429
+ requestedGrants: state.requestedGrants
17430
+ },
17431
+ ...state.requestedGrantsStatus !== void 0 && {
17432
+ requestedGrantsStatus: state.requestedGrantsStatus
17433
+ }
17434
+ };
17435
+ }
17417
17436
  function connectClaustrumEnrollmentClient(options) {
17418
17437
  return ClaustrumWireClient.connect(options);
17419
17438
  }
@@ -17449,6 +17468,7 @@ function decodeEnrollmentState(value) {
17449
17468
  throw invalidState();
17450
17469
  }
17451
17470
  if (value.phase === "pending") {
17471
+ const grants = decodeGrantProposal(value);
17452
17472
  if (!TOKEN_RE.test(String(value.requestSecret ?? "")) || value.requestId !== void 0 && (typeof value.requestId !== "string" || value.requestId.length === 0) || !validTimestamp(value.createdAt) || !validTimestamp(value.updatedAt)) {
17453
17473
  throw invalidState();
17454
17474
  }
@@ -17461,10 +17481,12 @@ function decodeEnrollmentState(value) {
17461
17481
  requestId: value.requestId
17462
17482
  },
17463
17483
  createdAt: value.createdAt,
17464
- updatedAt: value.updatedAt
17484
+ updatedAt: value.updatedAt,
17485
+ ...grants
17465
17486
  };
17466
17487
  }
17467
17488
  if (value.phase === "approved") {
17489
+ const grants = decodeGrantProposal(value);
17468
17490
  if (value.approvedName !== void 0 && (typeof value.approvedName !== "string" || value.approvedName.length === 0) || !validGeneration(value.tokenGeneration) || !validTimestamp(value.updatedAt)) {
17469
17491
  throw invalidState();
17470
17492
  }
@@ -17476,7 +17498,8 @@ function decodeEnrollmentState(value) {
17476
17498
  approvedName: value.approvedName
17477
17499
  },
17478
17500
  tokenGeneration: value.tokenGeneration,
17479
- updatedAt: value.updatedAt
17501
+ updatedAt: value.updatedAt,
17502
+ ...grants
17480
17503
  };
17481
17504
  }
17482
17505
  if (value.phase === "denied" || value.phase === "blocked") {
@@ -17495,6 +17518,11 @@ function decodeEnrollmentState(value) {
17495
17518
  }
17496
17519
  throw invalidState();
17497
17520
  }
17521
+ function decodeGrantProposal(value) {
17522
+ if (value.requestedGrants !== void 0 && !validEnrollmentRequestedGrants(value.requestedGrants) || value.requestedGrantsStatus !== void 0 && (value.requestedGrants === void 0 || value.requestedGrantsStatus !== "sent" && value.requestedGrantsStatus !== "dropped"))
17523
+ return {};
17524
+ return grantProposal(value);
17525
+ }
17498
17526
  function decodeTokenFile(value) {
17499
17527
  if (!isRecord6(value) || !TOKEN_RE.test(String(value.token ?? "")) || !validGeneration(value.token_generation)) {
17500
17528
  throw new ClaustrumConsumerError("invalid-token", "invalid Claustrum enrollment token file");
@@ -17708,7 +17736,8 @@ async function readEnrollmentStatus(paths, proposedName) {
17708
17736
  ...state?.phase === "approved" && state.approvedName !== void 0 && {
17709
17737
  approvedName: state.approvedName
17710
17738
  },
17711
- tokenGeneration: token.token_generation
17739
+ tokenGeneration: token.token_generation,
17740
+ ...state && (state.phase === "approved" || state.phase === "pending") && grantProposal(state)
17712
17741
  }
17713
17742
  };
17714
17743
  }
@@ -17767,7 +17796,8 @@ function statusFromState(state) {
17767
17796
  return {
17768
17797
  state: "pending",
17769
17798
  proposedName: state.proposedName,
17770
- ...state.requestId !== void 0 && { requestId: state.requestId }
17799
+ ...state.requestId !== void 0 && { requestId: state.requestId },
17800
+ ...grantProposal(state)
17771
17801
  };
17772
17802
  }
17773
17803
  if (state.phase === "approved") {
@@ -17777,7 +17807,8 @@ function statusFromState(state) {
17777
17807
  ...state.approvedName !== void 0 && {
17778
17808
  approvedName: state.approvedName
17779
17809
  },
17780
- tokenGeneration: state.tokenGeneration
17810
+ tokenGeneration: state.tokenGeneration,
17811
+ ...grantProposal(state)
17781
17812
  };
17782
17813
  }
17783
17814
  if (state.phase === "denied")
@@ -17897,6 +17928,7 @@ var init_enrollment = __esm({
17897
17928
  #paths;
17898
17929
  #proposedName;
17899
17930
  #displayName;
17931
+ #requestedGrants;
17900
17932
  #now;
17901
17933
  #mintSecret;
17902
17934
  #writeTokenFile;
@@ -17904,6 +17936,12 @@ var init_enrollment = __esm({
17904
17936
  constructor(options) {
17905
17937
  if (options.displayName !== void 0 && !validEnrollmentDisplayName(options.displayName))
17906
17938
  throw new ClaustrumConsumerError("invalid-state", "invalid Claustrum enrollment display name");
17939
+ if (options.requestedGrants !== void 0 && !validEnrollmentRequestedGrants(options.requestedGrants))
17940
+ throw new ClaustrumConsumerError("invalid-state", "invalid Claustrum enrollment requested grants");
17941
+ this.#requestedGrants = options.requestedGrants?.map((grant) => ({
17942
+ selector: { ...grant.selector },
17943
+ operation: grant.operation
17944
+ }));
17907
17945
  this.#ancestorOptions = options.ancestorOptions ?? {};
17908
17946
  this.#client = options.client;
17909
17947
  this.#paths = options.paths;
@@ -17954,6 +17992,7 @@ var init_enrollment = __esm({
17954
17992
  phase: "approved",
17955
17993
  proposedName: state?.proposedName ?? this.#proposedName,
17956
17994
  tokenGeneration: token.token_generation,
17995
+ ...state && grantProposal(state),
17957
17996
  updatedAt: this.#now()
17958
17997
  };
17959
17998
  await writeStateAtomic(this.#paths.statePath, approved, this.#ancestorOptions);
@@ -17965,7 +18004,8 @@ var init_enrollment = __esm({
17965
18004
  ...state.phase === "approved" && state.approvedName !== void 0 && {
17966
18005
  approvedName: state.approvedName
17967
18006
  },
17968
- tokenGeneration: token.token_generation
18007
+ tokenGeneration: token.token_generation,
18008
+ ...state.phase === "approved" && grantProposal(state)
17969
18009
  };
17970
18010
  }
17971
18011
  if (state?.phase === "approved") {
@@ -17989,7 +18029,10 @@ var init_enrollment = __esm({
17989
18029
  proposedName: this.#proposedName,
17990
18030
  requestSecret: this.#mintSecret(),
17991
18031
  createdAt: now,
17992
- updatedAt: now
18032
+ updatedAt: now,
18033
+ ...this.#requestedGrants !== void 0 && {
18034
+ requestedGrants: this.#requestedGrants
18035
+ }
17993
18036
  };
17994
18037
  if (!TOKEN_RE.test(state.requestSecret))
17995
18038
  throw new ClaustrumConsumerError("invalid-state", "invalid minted Claustrum enrollment secret");
@@ -18003,22 +18046,33 @@ var init_enrollment = __esm({
18003
18046
  requestSecretHash
18004
18047
  };
18005
18048
  let proposed;
18049
+ let requestedGrantsStatus = state.requestedGrantsStatus;
18006
18050
  try {
18007
18051
  proposed = await this.#client.enrollPropose({
18008
18052
  ...proposal,
18009
18053
  ...this.#displayName !== void 0 && {
18010
18054
  displayName: this.#displayName
18055
+ },
18056
+ ...state.requestedGrants !== void 0 && {
18057
+ requestedGrants: state.requestedGrants
18011
18058
  }
18012
18059
  });
18060
+ if (state.requestedGrants !== void 0)
18061
+ requestedGrantsStatus = "sent";
18013
18062
  } catch (error) {
18014
- if (this.#displayName === void 0 || !(error instanceof ClaustrumCredentialError3) || error.code !== "invalid_params")
18063
+ if (this.#displayName === void 0 && state.requestedGrants === void 0 || !(error instanceof ClaustrumCredentialError3) || error.code !== "invalid_params")
18015
18064
  throw error;
18016
18065
  proposed = await this.#client.enrollPropose(proposal);
18066
+ if (state.requestedGrants !== void 0)
18067
+ requestedGrantsStatus = "dropped";
18017
18068
  }
18018
18069
  state = {
18019
18070
  ...state,
18020
18071
  requestId: proposed.requestId,
18021
- updatedAt: this.#now()
18072
+ updatedAt: this.#now(),
18073
+ ...requestedGrantsStatus !== void 0 && {
18074
+ requestedGrantsStatus
18075
+ }
18022
18076
  };
18023
18077
  await writeStateAtomic(this.#paths.statePath, state, this.#ancestorOptions);
18024
18078
  } catch (error) {
@@ -18029,7 +18083,8 @@ var init_enrollment = __esm({
18029
18083
  return {
18030
18084
  state: "pending",
18031
18085
  proposedName: state.proposedName,
18032
- retryCode: refusal3.code
18086
+ retryCode: refusal3.code,
18087
+ ...grantProposal(state)
18033
18088
  };
18034
18089
  }
18035
18090
  if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE) {
@@ -18079,6 +18134,7 @@ var init_enrollment = __esm({
18079
18134
  proposedName: state.proposedName,
18080
18135
  approvedName: outcome.name,
18081
18136
  tokenGeneration: outcome.tokenGeneration,
18137
+ ...grantProposal(state),
18082
18138
  updatedAt: this.#now()
18083
18139
  };
18084
18140
  await writeStateAtomic(this.#paths.statePath, approved, this.#ancestorOptions);
@@ -18092,7 +18148,8 @@ var init_enrollment = __esm({
18092
18148
  state: "pending",
18093
18149
  proposedName: state.proposedName,
18094
18150
  requestId,
18095
- retryCode: refusal3.code
18151
+ retryCode: refusal3.code,
18152
+ ...grantProposal(state)
18096
18153
  };
18097
18154
  }
18098
18155
  return this.#block(state, refusal3.code);
@@ -21917,6 +21974,7 @@ __export(claustrum_exports, {
21917
21974
  resetClaustrumEnrollmentState: () => resetClaustrumEnrollmentState,
21918
21975
  resolveVaultPrimary: () => resolveVaultPrimary,
21919
21976
  validEnrollmentDisplayName: () => validEnrollmentDisplayName,
21977
+ validEnrollmentRequestedGrants: () => validEnrollmentRequestedGrants,
21920
21978
  vaultAuthority: () => vaultAuthority,
21921
21979
  vaultRosterSeed: () => vaultRosterSeed,
21922
21980
  vaultRoutingRows: () => vaultRoutingRows
@@ -27307,8 +27365,8 @@ var init_debug = __esm({
27307
27365
  // src/plugin/logger.ts
27308
27366
  function createLocationLogger(options) {
27309
27367
  let configuredLevel = options.level ? LOG_LEVEL_FROM_OPERATOR[options.level] ?? "debug" : "debug";
27310
- const emit = (record3) => {
27311
- if (options.sink && options.sinkEnabled()) {
27368
+ const emit = (record3, alwaysHost = false) => {
27369
+ if (options.sink && (alwaysHost || options.sinkEnabled())) {
27312
27370
  try {
27313
27371
  const pending = options.sink(record3);
27314
27372
  if (isThenable(pending)) {
@@ -27327,26 +27385,33 @@ function createLocationLogger(options) {
27327
27385
  }
27328
27386
  }
27329
27387
  };
27330
- const engine = createLoggerInstance2({
27388
+ const createEngine3 = (alwaysHost) => createLoggerInstance2({
27331
27389
  level: () => configuredLevel,
27332
27390
  extraSecretKeys: isProviderSecretKey,
27333
27391
  extraValuePatterns: OAUTH_REDIRECT_VALUE_PATTERNS,
27334
27392
  captureSink: ({ channel: channel3, level, message, data }) => {
27335
27393
  const extra = data !== null && typeof data === "object" && !Array.isArray(data) ? Object.fromEntries(Object.entries(data)) : void 0;
27336
- emit({
27337
- service: channel3,
27338
- level: level === "trace" ? "debug" : level,
27339
- message,
27340
- extra
27341
- });
27394
+ emit(
27395
+ {
27396
+ service: channel3,
27397
+ level: level === "trace" ? "debug" : level,
27398
+ message,
27399
+ extra
27400
+ },
27401
+ alwaysHost
27402
+ );
27342
27403
  }
27343
27404
  });
27405
+ const engine = createEngine3(false);
27406
+ const hostEngine = createEngine3(true);
27344
27407
  return {
27345
27408
  createLogger(module) {
27346
27409
  const channel3 = engine.createLogger(`antigravity.${module}`);
27410
+ const hostChannel = hostEngine.createLogger(`antigravity.${module}`);
27347
27411
  return {
27348
27412
  debug: (message, extra) => channel3.debug(message, extra),
27349
27413
  info: (message, extra) => channel3.info(message, extra),
27414
+ hostInfo: (message, extra) => hostChannel.info(message, extra),
27350
27415
  warn: (message, extra) => channel3.warn(message, extra),
27351
27416
  error: (message, extra) => channel3.error(message, extra)
27352
27417
  };
@@ -27390,6 +27455,10 @@ function createLogger4(module) {
27390
27455
  return {
27391
27456
  debug: (message, extra) => log9("debug", message, extra),
27392
27457
  info: (message, extra) => log9("info", message, extra),
27458
+ hostInfo: (message, extra) => {
27459
+ channel3 ??= getLegacyLogger().createLogger(module);
27460
+ channel3.hostInfo?.(message, extra);
27461
+ },
27393
27462
  warn: (message, extra) => log9("warn", message, extra),
27394
27463
  error: (message, extra) => log9("error", message, extra)
27395
27464
  };
@@ -29704,6 +29773,25 @@ function validEnrollmentDisplayName2(displayName) {
29704
29773
  const length = Array.from(displayName).length;
29705
29774
  return length >= 1 && length <= 40 && !/[\p{Cc}\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069\u200b-\u200d\u2060\ufeff]/u.test(displayName);
29706
29775
  }
29776
+ function validEnrollmentRequestedGrants2(grants) {
29777
+ return Array.isArray(grants) && grants.length >= 1 && grants.length <= 4 && Array.from(grants).every((grant) => {
29778
+ if (!isRecord10(grant) || Object.keys(grant).length !== 2 || grant.operation !== "read" && grant.operation !== "list" || !isRecord10(grant.selector))
29779
+ return false;
29780
+ const keys = Object.keys(grant.selector);
29781
+ const key = keys[0];
29782
+ return keys.length === 1 && (key === "category" || key === "exact") && typeof grant.selector[key] === "string" && grant.selector[key].trim().length > 0;
29783
+ });
29784
+ }
29785
+ function grantProposal2(state) {
29786
+ return {
29787
+ ...state.requestedGrants !== void 0 && {
29788
+ requestedGrants: state.requestedGrants
29789
+ },
29790
+ ...state.requestedGrantsStatus !== void 0 && {
29791
+ requestedGrantsStatus: state.requestedGrantsStatus
29792
+ }
29793
+ };
29794
+ }
29707
29795
  function connectClaustrumEnrollmentClient2(options) {
29708
29796
  return ClaustrumWireClient2.connect(options);
29709
29797
  }
@@ -29739,6 +29827,7 @@ function decodeEnrollmentState2(value) {
29739
29827
  throw invalidState2();
29740
29828
  }
29741
29829
  if (value.phase === "pending") {
29830
+ const grants = decodeGrantProposal2(value);
29742
29831
  if (!TOKEN_RE2.test(String(value.requestSecret ?? "")) || value.requestId !== void 0 && (typeof value.requestId !== "string" || value.requestId.length === 0) || !validTimestamp2(value.createdAt) || !validTimestamp2(value.updatedAt)) {
29743
29832
  throw invalidState2();
29744
29833
  }
@@ -29751,10 +29840,12 @@ function decodeEnrollmentState2(value) {
29751
29840
  requestId: value.requestId
29752
29841
  },
29753
29842
  createdAt: value.createdAt,
29754
- updatedAt: value.updatedAt
29843
+ updatedAt: value.updatedAt,
29844
+ ...grants
29755
29845
  };
29756
29846
  }
29757
29847
  if (value.phase === "approved") {
29848
+ const grants = decodeGrantProposal2(value);
29758
29849
  if (value.approvedName !== void 0 && (typeof value.approvedName !== "string" || value.approvedName.length === 0) || !validGeneration2(value.tokenGeneration) || !validTimestamp2(value.updatedAt)) {
29759
29850
  throw invalidState2();
29760
29851
  }
@@ -29766,7 +29857,8 @@ function decodeEnrollmentState2(value) {
29766
29857
  approvedName: value.approvedName
29767
29858
  },
29768
29859
  tokenGeneration: value.tokenGeneration,
29769
- updatedAt: value.updatedAt
29860
+ updatedAt: value.updatedAt,
29861
+ ...grants
29770
29862
  };
29771
29863
  }
29772
29864
  if (value.phase === "denied" || value.phase === "blocked") {
@@ -29785,6 +29877,11 @@ function decodeEnrollmentState2(value) {
29785
29877
  }
29786
29878
  throw invalidState2();
29787
29879
  }
29880
+ function decodeGrantProposal2(value) {
29881
+ if (value.requestedGrants !== void 0 && !validEnrollmentRequestedGrants2(value.requestedGrants) || value.requestedGrantsStatus !== void 0 && (value.requestedGrants === void 0 || value.requestedGrantsStatus !== "sent" && value.requestedGrantsStatus !== "dropped"))
29882
+ return {};
29883
+ return grantProposal2(value);
29884
+ }
29788
29885
  function decodeTokenFile2(value) {
29789
29886
  if (!isRecord10(value) || !TOKEN_RE2.test(String(value.token ?? "")) || !validGeneration2(value.token_generation)) {
29790
29887
  throw new ClaustrumConsumerError2("invalid-token", "invalid Claustrum enrollment token file");
@@ -29999,7 +30096,8 @@ async function readEnrollmentStatus2(paths, proposedName) {
29999
30096
  ...state?.phase === "approved" && state.approvedName !== void 0 && {
30000
30097
  approvedName: state.approvedName
30001
30098
  },
30002
- tokenGeneration: token.token_generation
30099
+ tokenGeneration: token.token_generation,
30100
+ ...state && (state.phase === "approved" || state.phase === "pending") && grantProposal2(state)
30003
30101
  }
30004
30102
  };
30005
30103
  }
@@ -30047,12 +30145,19 @@ async function vaultAuthority3(paths, proposedName) {
30047
30145
  return "host";
30048
30146
  return enrollmentAuthority2(paths, proposedName);
30049
30147
  }
30148
+ async function readClaustrumEnrollmentToken2(tokenPath) {
30149
+ const value = await readBoundedJson2(tokenPath);
30150
+ if (value === void 0)
30151
+ throw new ClaustrumConsumerError2("not-enrolled", "Claustrum enrollment is not configured");
30152
+ return decodeTokenFile2(value);
30153
+ }
30050
30154
  function statusFromState2(state) {
30051
30155
  if (state.phase === "pending") {
30052
30156
  return {
30053
30157
  state: "pending",
30054
30158
  proposedName: state.proposedName,
30055
- ...state.requestId !== void 0 && { requestId: state.requestId }
30159
+ ...state.requestId !== void 0 && { requestId: state.requestId },
30160
+ ...grantProposal2(state)
30056
30161
  };
30057
30162
  }
30058
30163
  if (state.phase === "approved") {
@@ -30062,7 +30167,8 @@ function statusFromState2(state) {
30062
30167
  ...state.approvedName !== void 0 && {
30063
30168
  approvedName: state.approvedName
30064
30169
  },
30065
- tokenGeneration: state.tokenGeneration
30170
+ tokenGeneration: state.tokenGeneration,
30171
+ ...grantProposal2(state)
30066
30172
  };
30067
30173
  }
30068
30174
  if (state.phase === "denied")
@@ -30081,6 +30187,7 @@ var ClaustrumEnrollmentManager2 = class {
30081
30187
  #paths;
30082
30188
  #proposedName;
30083
30189
  #displayName;
30190
+ #requestedGrants;
30084
30191
  #now;
30085
30192
  #mintSecret;
30086
30193
  #writeTokenFile;
@@ -30088,6 +30195,12 @@ var ClaustrumEnrollmentManager2 = class {
30088
30195
  constructor(options) {
30089
30196
  if (options.displayName !== void 0 && !validEnrollmentDisplayName2(options.displayName))
30090
30197
  throw new ClaustrumConsumerError2("invalid-state", "invalid Claustrum enrollment display name");
30198
+ if (options.requestedGrants !== void 0 && !validEnrollmentRequestedGrants2(options.requestedGrants))
30199
+ throw new ClaustrumConsumerError2("invalid-state", "invalid Claustrum enrollment requested grants");
30200
+ this.#requestedGrants = options.requestedGrants?.map((grant) => ({
30201
+ selector: { ...grant.selector },
30202
+ operation: grant.operation
30203
+ }));
30091
30204
  this.#ancestorOptions = options.ancestorOptions ?? {};
30092
30205
  this.#client = options.client;
30093
30206
  this.#paths = options.paths;
@@ -30138,6 +30251,7 @@ var ClaustrumEnrollmentManager2 = class {
30138
30251
  phase: "approved",
30139
30252
  proposedName: state?.proposedName ?? this.#proposedName,
30140
30253
  tokenGeneration: token.token_generation,
30254
+ ...state && grantProposal2(state),
30141
30255
  updatedAt: this.#now()
30142
30256
  };
30143
30257
  await writeStateAtomic2(this.#paths.statePath, approved, this.#ancestorOptions);
@@ -30149,7 +30263,8 @@ var ClaustrumEnrollmentManager2 = class {
30149
30263
  ...state.phase === "approved" && state.approvedName !== void 0 && {
30150
30264
  approvedName: state.approvedName
30151
30265
  },
30152
- tokenGeneration: token.token_generation
30266
+ tokenGeneration: token.token_generation,
30267
+ ...state.phase === "approved" && grantProposal2(state)
30153
30268
  };
30154
30269
  }
30155
30270
  if (state?.phase === "approved") {
@@ -30173,7 +30288,10 @@ var ClaustrumEnrollmentManager2 = class {
30173
30288
  proposedName: this.#proposedName,
30174
30289
  requestSecret: this.#mintSecret(),
30175
30290
  createdAt: now,
30176
- updatedAt: now
30291
+ updatedAt: now,
30292
+ ...this.#requestedGrants !== void 0 && {
30293
+ requestedGrants: this.#requestedGrants
30294
+ }
30177
30295
  };
30178
30296
  if (!TOKEN_RE2.test(state.requestSecret))
30179
30297
  throw new ClaustrumConsumerError2("invalid-state", "invalid minted Claustrum enrollment secret");
@@ -30187,22 +30305,33 @@ var ClaustrumEnrollmentManager2 = class {
30187
30305
  requestSecretHash
30188
30306
  };
30189
30307
  let proposed;
30308
+ let requestedGrantsStatus = state.requestedGrantsStatus;
30190
30309
  try {
30191
30310
  proposed = await this.#client.enrollPropose({
30192
30311
  ...proposal,
30193
30312
  ...this.#displayName !== void 0 && {
30194
30313
  displayName: this.#displayName
30314
+ },
30315
+ ...state.requestedGrants !== void 0 && {
30316
+ requestedGrants: state.requestedGrants
30195
30317
  }
30196
30318
  });
30319
+ if (state.requestedGrants !== void 0)
30320
+ requestedGrantsStatus = "sent";
30197
30321
  } catch (error) {
30198
- if (this.#displayName === void 0 || !(error instanceof ClaustrumCredentialError9) || error.code !== "invalid_params")
30322
+ if (this.#displayName === void 0 && state.requestedGrants === void 0 || !(error instanceof ClaustrumCredentialError9) || error.code !== "invalid_params")
30199
30323
  throw error;
30200
30324
  proposed = await this.#client.enrollPropose(proposal);
30325
+ if (state.requestedGrants !== void 0)
30326
+ requestedGrantsStatus = "dropped";
30201
30327
  }
30202
30328
  state = {
30203
30329
  ...state,
30204
30330
  requestId: proposed.requestId,
30205
- updatedAt: this.#now()
30331
+ updatedAt: this.#now(),
30332
+ ...requestedGrantsStatus !== void 0 && {
30333
+ requestedGrantsStatus
30334
+ }
30206
30335
  };
30207
30336
  await writeStateAtomic2(this.#paths.statePath, state, this.#ancestorOptions);
30208
30337
  } catch (error) {
@@ -30213,7 +30342,8 @@ var ClaustrumEnrollmentManager2 = class {
30213
30342
  return {
30214
30343
  state: "pending",
30215
30344
  proposedName: state.proposedName,
30216
- retryCode: refusal3.code
30345
+ retryCode: refusal3.code,
30346
+ ...grantProposal2(state)
30217
30347
  };
30218
30348
  }
30219
30349
  if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE2) {
@@ -30263,6 +30393,7 @@ var ClaustrumEnrollmentManager2 = class {
30263
30393
  proposedName: state.proposedName,
30264
30394
  approvedName: outcome.name,
30265
30395
  tokenGeneration: outcome.tokenGeneration,
30396
+ ...grantProposal2(state),
30266
30397
  updatedAt: this.#now()
30267
30398
  };
30268
30399
  await writeStateAtomic2(this.#paths.statePath, approved, this.#ancestorOptions);
@@ -30276,7 +30407,8 @@ var ClaustrumEnrollmentManager2 = class {
30276
30407
  state: "pending",
30277
30408
  proposedName: state.proposedName,
30278
30409
  requestId,
30279
- retryCode: refusal3.code
30410
+ retryCode: refusal3.code,
30411
+ ...grantProposal2(state)
30280
30412
  };
30281
30413
  }
30282
30414
  return this.#block(state, refusal3.code);
@@ -30455,6 +30587,68 @@ function runResolvedCommand(runner, platform, file, args, env3, timeoutMs = 15e3
30455
30587
  return runner.run(file, args, { env: env3, timeoutMs });
30456
30588
  }
30457
30589
 
30590
+ // src/common-auth-embedded/setup/enrollment-access.js
30591
+ function shellArgument(value) {
30592
+ if (/^[a-zA-Z0-9_:@./-]+$/.test(value))
30593
+ return value;
30594
+ return process.platform === "win32" ? `'${value.replaceAll("'", "''")}'` : `'${value.replaceAll("'", "'\\''")}'`;
30595
+ }
30596
+ async function confirmEnrollmentAccess(client, status, tokenPath, configuredGrants) {
30597
+ const requestedGrants = status.requestedGrants ?? configuredGrants;
30598
+ if (!requestedGrants)
30599
+ return void 0;
30600
+ const grants = requestedGrants.map((grant) => ({
30601
+ grant,
30602
+ ...status.approvedName !== void 0 && {
30603
+ grantCommand: `ck auth grant --principal ${shellArgument(`enrolled:${status.approvedName}`)} --selector-kind ${grant.selector.exact === void 0 ? "category" : "exact"} --selector ${shellArgument(grant.selector.exact ?? grant.selector.category)} --operation ${grant.operation}`
30604
+ }
30605
+ }));
30606
+ if (status.requestedGrantsStatus === "dropped")
30607
+ return { state: "older-vault", grants };
30608
+ try {
30609
+ if (!client.listScoped)
30610
+ return { state: "unconfirmed", grants };
30611
+ const { token } = await readClaustrumEnrollmentToken2(tokenPath);
30612
+ const inventory = await client.listScoped(token);
30613
+ const confirmed = grants.map((entry) => ({
30614
+ ...entry,
30615
+ reachableLogins: inventory.rows.filter((row) => row.operations.includes(entry.grant.operation) && (entry.grant.selector.exact !== void 0 ? row.id === entry.grant.selector.exact : row.categories.includes(entry.grant.selector.category))).length
30616
+ }));
30617
+ return {
30618
+ state: confirmed.every((entry) => entry.reachableLogins > 0) ? "reachable" : confirmed.some((entry) => entry.reachableLogins > 0) ? "partial" : "no-logins",
30619
+ grants: confirmed.map((entry) => {
30620
+ if (entry.reachableLogins === 0)
30621
+ return entry;
30622
+ const { grantCommand: _, ...reachable } = entry;
30623
+ return reachable;
30624
+ })
30625
+ };
30626
+ } catch {
30627
+ return { state: "unconfirmed", grants };
30628
+ }
30629
+ }
30630
+ function enrollmentAccessLines(access) {
30631
+ const lines = [];
30632
+ const remedy = access.grants.some((entry) => entry.grantCommand) ? "run:" : "check ck auth status for the approved name before granting access.";
30633
+ if (access.state === "older-vault")
30634
+ lines.push(`Approved. This vault is too old to grant access with the approval; ${remedy}`);
30635
+ else if (access.state === "no-logins")
30636
+ lines.push(`Approved, but no logins are reachable yet; ${remedy}`);
30637
+ else if (access.state === "partial")
30638
+ lines.push(`Approved, but some requested access has no reachable logins yet; ${remedy}`);
30639
+ else if (access.state === "unconfirmed")
30640
+ lines.push(`Approved, but access could not be confirmed; ${access.grants.some((entry) => entry.grantCommand) ? "check ck auth status or run:" : remedy}`);
30641
+ for (const { grant, reachableLogins, grantCommand } of access.grants) {
30642
+ if (reachableLogins !== void 0 && reachableLogins > 0) {
30643
+ const target = grant.selector.exact === void 0 ? `the vault's ${JSON.stringify(grant.selector.category)} accounts` : `credential ${JSON.stringify(grant.selector.exact)}`;
30644
+ lines.push(`Confirmed ${grant.operation} access to ${target} (${reachableLogins} reachable ${reachableLogins === 1 ? "login" : "logins"}).`);
30645
+ }
30646
+ if (grantCommand)
30647
+ lines.push(` ${grantCommand}`);
30648
+ }
30649
+ return lines;
30650
+ }
30651
+
30458
30652
  // src/common-auth-embedded/setup/command-error.js
30459
30653
  var PI_INSTALL_ERROR_MESSAGE = "Pi install failed; run pi install after checking your npm connection.";
30460
30654
  function utf8Tail(value) {
@@ -30495,8 +30689,8 @@ var OUTCOME_TEXT = {
30495
30689
  "not-enrolled": "not connected",
30496
30690
  unknown: "unknown, check with ck auth status"
30497
30691
  };
30498
- function setupEnrollmentLine({ host, outcome }) {
30499
- return `${HOST_LABELS[host]}: ${OUTCOME_TEXT[outcome]}`;
30692
+ function setupEnrollmentLine({ host, outcome, access }) {
30693
+ return `${HOST_LABELS[host]}: ${OUTCOME_TEXT[outcome]}${access ? ` \u2014 ${enrollmentAccessLines(access).join("\n")}` : ""}`;
30500
30694
  }
30501
30695
  var recordedEnrollment = /* @__PURE__ */ new WeakMap();
30502
30696
  function recordSetupEnrollment(failure, enrollment) {
@@ -31034,7 +31228,7 @@ function approveCommand(requestId, name) {
31034
31228
  async function connectSetupHost(plugin, host, io, terminal, fence) {
31035
31229
  if (hasVaultHost2())
31036
31230
  throw new Error(VAULT_HOST_CONNECT_REFUSAL2);
31037
- const { name, displayName, paths: input } = plugin.vault.hosts[host];
31231
+ const { name, displayName, requestedGrants, paths: input } = plugin.vault.hosts[host];
31038
31232
  const paths = hostEnrollmentPaths2(input);
31039
31233
  await fence();
31040
31234
  const client = await (io.connect ?? connectClaustrumEnrollmentClient2)({
@@ -31049,6 +31243,7 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
31049
31243
  const manager = new ClaustrumEnrollmentManager2({
31050
31244
  proposedName: name,
31051
31245
  displayName,
31246
+ requestedGrants,
31052
31247
  paths,
31053
31248
  // Each tick of the wait below checks the fence once, just before
31054
31249
  // reconcile proposes or polls. Checking again inside every vault call
@@ -31064,7 +31259,11 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
31064
31259
  const initial = await manager.status();
31065
31260
  if (initial.state === "approved") {
31066
31261
  printLine2(terminal, `Already connected as ${initial.approvedName ?? initial.proposedName}.`);
31067
- return;
31262
+ const access = await confirmEnrollmentAccess(client, initial, paths.tokenPath, requestedGrants);
31263
+ if (access)
31264
+ for (const line of enrollmentAccessLines(access))
31265
+ printLine2(terminal, line);
31266
+ return access;
31068
31267
  }
31069
31268
  printLine2(terminal, `Asking the vault to connect ${name}\u2026`);
31070
31269
  const deadline = now() + ENROLLMENT_WAIT_MS;
@@ -31076,7 +31275,11 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
31076
31275
  const status = await manager.reconcile();
31077
31276
  if (status.state === "approved") {
31078
31277
  printLine2(terminal, `Connected ${host} to Claustrum.`);
31079
- return;
31278
+ const access = await confirmEnrollmentAccess(client, status, paths.tokenPath, requestedGrants);
31279
+ if (access)
31280
+ for (const line of enrollmentAccessLines(access))
31281
+ printLine2(terminal, line);
31282
+ return access;
31080
31283
  }
31081
31284
  if (status.state === "unavailable" && status.code === UNSUPPORTED_ENROLLMENT_CODE2)
31082
31285
  throw new HostNotEnrolledError(UNSUPPORTED_VAULT_MESSAGE, {
@@ -31510,12 +31713,15 @@ function validatePlugin(plugin) {
31510
31713
  for (const host of Object.values(plugin.vault.hosts)) {
31511
31714
  if (!/^[a-z0-9][a-z0-9-]*$/.test(host.name))
31512
31715
  throw new Error("Setup requires lowercase vault names containing only letters, digits and dashes.");
31716
+ if (host.requestedGrants !== void 0 && !validEnrollmentRequestedGrants2(host.requestedGrants))
31717
+ throw new Error("invalid Claustrum enrollment requested grants");
31513
31718
  }
31514
31719
  }
31515
- async function enrollmentReport(plugin, hosts, recorded) {
31720
+ async function enrollmentReport(plugin, hosts, recorded, recordedAccess) {
31516
31721
  const report = [];
31517
31722
  for (const host of hosts) {
31518
31723
  let outcome = recorded.get(host) ?? "not-enrolled";
31724
+ let access = recordedAccess.get(host);
31519
31725
  if (outcome === "unknown") {
31520
31726
  const { name, paths } = plugin.vault.hosts[host];
31521
31727
  const authority = await vaultAuthority3(hostEnrollmentPaths2(paths), name).catch(() => "unreadable");
@@ -31523,8 +31729,13 @@ async function enrollmentReport(plugin, hosts, recorded) {
31523
31729
  outcome = "enrolled";
31524
31730
  else if (authority === "local")
31525
31731
  outcome = "not-enrolled";
31732
+ if (outcome === "enrolled") {
31733
+ const status = await readClaustrumEnrollmentStatus2(hostEnrollmentPaths2(paths), name).catch(() => void 0);
31734
+ if (status?.state === "approved")
31735
+ access = await confirmEnrollmentAccess({}, status, hostEnrollmentPaths2(paths).tokenPath, plugin.vault.hosts[host].requestedGrants);
31736
+ }
31526
31737
  }
31527
- report.push({ host, outcome });
31738
+ report.push({ host, outcome, ...access && { access } });
31528
31739
  }
31529
31740
  return report;
31530
31741
  }
@@ -31653,6 +31864,7 @@ ${write.content}`);
31653
31864
  piAgentDir: detection.pi.directory
31654
31865
  };
31655
31866
  const enrollment = /* @__PURE__ */ new Map();
31867
+ const enrollmentAccess = /* @__PURE__ */ new Map();
31656
31868
  try {
31657
31869
  for (const host of hosts) {
31658
31870
  await stopped();
@@ -31661,7 +31873,9 @@ ${write.content}`);
31661
31873
  if (useVault) {
31662
31874
  enrollment.set(host, "unknown");
31663
31875
  try {
31664
- await connectSetupHost(plugin, host, io, terminal, stopped);
31876
+ const access = await connectSetupHost(plugin, host, io, terminal, stopped);
31877
+ if (access)
31878
+ enrollmentAccess.set(host, access);
31665
31879
  } catch (error) {
31666
31880
  if (error instanceof HostNotEnrolledError)
31667
31881
  enrollment.set(host, "not-enrolled");
@@ -31686,7 +31900,7 @@ ${write.content}`);
31686
31900
  if (enrollment.size === 0)
31687
31901
  throw error;
31688
31902
  try {
31689
- const report = await enrollmentReport(plugin, hosts, enrollment);
31903
+ const report = await enrollmentReport(plugin, hosts, enrollment, enrollmentAccess);
31690
31904
  recordSetupEnrollment(error, report);
31691
31905
  for (const entry of report)
31692
31906
  printLine2(terminal, setupEnrollmentLine(entry));
@@ -31830,6 +32044,12 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
31830
32044
  opencode: {
31831
32045
  name: OPENCODE_VAULT_ENROLLMENT_NAME,
31832
32046
  displayName: "Antigravity sign-in for OpenCode",
32047
+ requestedGrants: [
32048
+ {
32049
+ selector: { category: "antigravity-native" },
32050
+ operation: "read"
32051
+ }
32052
+ ],
31833
32053
  // Read at each use: a real run settles the vault folder in
31834
32054
  // `beforeSignIn`, which may move it after this plugin is built.
31835
32055
  paths: {
@@ -31842,6 +32062,12 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
31842
32062
  pi: {
31843
32063
  name: "antigravity-auth-pi",
31844
32064
  displayName: "Antigravity sign-in for Pi",
32065
+ requestedGrants: [
32066
+ {
32067
+ selector: { category: "antigravity-native" },
32068
+ operation: "read"
32069
+ }
32070
+ ],
31845
32071
  paths: { stateDir: piDir, host: "pi" }
31846
32072
  }
31847
32073
  };