@cortexkit/opencode-antigravity-auth 3.0.14 → 3.0.16

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 (63) hide show
  1. package/dist/cli.js +257 -57
  2. package/dist/cli.js.map +3 -3
  3. package/dist/cli.meta.json +11 -11
  4. package/dist/index.js +468 -90
  5. package/dist/index.js.map +3 -3
  6. package/dist/index.meta.json +14 -14
  7. package/dist/server.js +499 -95
  8. package/dist/server.js.map +3 -3
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/ga/tui/host-ga.d.ts +55 -2
  11. package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
  12. package/dist/src/ga/tui/host-ga.js +73 -43
  13. package/dist/src/ga/tui/host-ga.js.map +1 -1
  14. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  15. package/dist/src/plugin/ga-location-services.js +49 -5
  16. package/dist/src/plugin/ga-location-services.js.map +1 -1
  17. package/dist/src/plugin/shared/vault-request-credentials.d.ts +33 -13
  18. package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  19. package/dist/src/plugin/shared/vault-request-credentials.js +97 -44
  20. package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
  21. package/dist/src/plugin/storage.d.ts +17 -0
  22. package/dist/src/plugin/storage.d.ts.map +1 -1
  23. package/dist/src/plugin/storage.js +44 -10
  24. package/dist/src/plugin/storage.js.map +1 -1
  25. package/dist/src/runtime-paths.d.ts +2 -1
  26. package/dist/src/runtime-paths.d.ts.map +1 -1
  27. package/dist/src/runtime-paths.js +5 -5
  28. package/dist/src/runtime-paths.js.map +1 -1
  29. package/dist/src/tui/quota-layout.d.ts +1 -1
  30. package/dist/src/tui/quota-layout.js +1 -1
  31. package/dist/src/tui/sidebar-frame.d.ts +109 -0
  32. package/dist/src/tui/sidebar-frame.d.ts.map +1 -0
  33. package/dist/src/tui/sidebar-frame.js +244 -0
  34. package/dist/src/tui/sidebar-frame.js.map +1 -0
  35. package/dist/src/tui.d.ts.map +1 -1
  36. package/dist/src/tui.js +11 -251
  37. package/dist/src/tui.js.map +1 -1
  38. package/dist/tui-build-map.json +120 -92
  39. package/dist/tui-ga-build-map.json +22 -8
  40. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  41. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +33 -13
  42. package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
  43. package/dist/types/src/plugin/storage.d.ts +17 -0
  44. package/dist/types/src/plugin/storage.d.ts.map +1 -1
  45. package/dist/types/src/runtime-paths.d.ts +2 -1
  46. package/dist/types/src/runtime-paths.d.ts.map +1 -1
  47. package/package.json +2 -2
  48. package/src/tui/entry.mjs +19 -1
  49. package/src/tui-compiled/sidebar-projection.js +119 -0
  50. package/src/tui-compiled/tui/quota-layout.js +1 -1
  51. package/src/tui-compiled/tui/sidebar-frame.js +657 -0
  52. package/src/tui-compiled/tui.js +25 -606
  53. package/src/tui-ga-compiled/host-ga.js +116 -124
  54. package/src/tui-ga-compiled/shared/ced204104a639c9c-sidebar-frame.js +657 -0
  55. package/src/tui-ga-compiled/shared/dd4c9e1a907f8ef0-quota-layout.js +1 -1
  56. package/src/tui-ga-raw/host-ga.tsx +157 -95
  57. package/src/tui-ga-raw/shared/ced204104a639c9c-sidebar-frame.tsx +603 -0
  58. package/src/tui-ga-raw/shared/dd4c9e1a907f8ef0-quota-layout.tsx +1 -1
  59. package/src/tui-raw/sidebar-projection.js +119 -0
  60. package/src/tui-raw/tui/quota-layout.tsx +1 -1
  61. package/src/tui-raw/tui/sidebar-frame.tsx +603 -0
  62. package/src/tui-raw/tui.tsx +25 -523
  63. package/src/tui.tsx +25 -523
package/dist/index.js CHANGED
@@ -14635,14 +14635,52 @@ function decodeAccountStorePointer(value, legacyPath) {
14635
14635
  throw new AccountMigrationError("pointer directory basename differs from its derived generation");
14636
14636
  return { schemaVersion: 1, id, directoryBasename: basename(paths.storeDir) };
14637
14637
  }
14638
- async function readPointer(legacyPath) {
14638
+ function decodeAccountStorePointerRecord(value, legacyPath) {
14639
+ if (object(value, "pointer").schemaVersion !== 2)
14640
+ return decodeAccountStorePointer(value, legacyPath);
14641
+ const raw = exact(value, ["schemaVersion", "id", "directoryBasename", "relocatedTo"], "forward");
14642
+ const id = text(raw.id, UUID, "forward source generation");
14643
+ const paths = generationPaths(legacyPath, id);
14644
+ if (raw.directoryBasename !== basename(paths.storeDir))
14645
+ throw new AccountMigrationError("forward directory basename differs from its derived generation");
14646
+ const target = exact(raw.relocatedTo, ["legacyPath", "id"], "forward target");
14647
+ if (typeof target.legacyPath !== "string")
14648
+ throw new AccountMigrationError("forward target path is invalid");
14649
+ const targetId = text(target.id, UUID, "forward target generation");
14650
+ const targetPaths = generationPaths(target.legacyPath, targetId);
14651
+ if (sameFilesystemPath(targetPaths.legacyPath, legacyPath))
14652
+ throw new AccountMigrationError("forward names its own anchor");
14653
+ return {
14654
+ schemaVersion: 2,
14655
+ id,
14656
+ directoryBasename: basename(paths.storeDir),
14657
+ relocatedTo: {
14658
+ legacyPath: targetPaths.legacyPath,
14659
+ id: targetId
14660
+ }
14661
+ };
14662
+ }
14663
+ async function readPointerRecord(legacyPath) {
14639
14664
  const logical = resolveAccountStorePaths(legacyPath);
14640
14665
  if (await exists(logical.storeDir))
14641
14666
  throw new AccountMigrationError("foreign logical store directory is not pointer authority");
14642
14667
  const path5 = accountStorePointerPath(legacyPath);
14643
14668
  if (!await exists(path5))
14644
14669
  return void 0;
14645
- return decodeAccountStorePointer(jsonBytes(await secureRead(path5)), legacyPath);
14670
+ return decodeAccountStorePointerRecord(jsonBytes(await secureRead(path5)), legacyPath);
14671
+ }
14672
+ async function readPointer(legacyPath) {
14673
+ const record3 = await readPointerRecord(legacyPath);
14674
+ if (record3?.schemaVersion === 2)
14675
+ throw new AccountMigrationError(`the account store moved to ${record3.relocatedTo.legacyPath}; this operation does not follow a moved store`);
14676
+ return record3;
14677
+ }
14678
+ async function forwardTarget(legacyPath, forward) {
14679
+ const target = forward.relocatedTo.legacyPath;
14680
+ const published = await readPointerRecord(target);
14681
+ if (published?.schemaVersion !== 1 || published.id !== forward.relocatedTo.id)
14682
+ throw new AccountMigrationError(`the forwarding pointer ${accountStorePointerPath(legacyPath)} names generation ${forward.relocatedTo.id}, which ${accountStorePointerPath(target)} does not publish`);
14683
+ return target;
14646
14684
  }
14647
14685
  async function resolvePublishedAccountStorePaths(legacyPath) {
14648
14686
  const pointer = await readPointer(legacyPath);
@@ -14898,7 +14936,7 @@ function decodeAccountStoreGeneration(value) {
14898
14936
  "sourceKind",
14899
14937
  "initialManifestSha256"
14900
14938
  ], "generation");
14901
- if (raw.schemaVersion !== 1 || typeof raw.legacyPath !== "string" || raw.sourceKind !== "file" && raw.sourceKind !== "absent")
14939
+ if (raw.schemaVersion !== 1 || typeof raw.legacyPath !== "string" || raw.sourceKind !== "file" && raw.sourceKind !== "absent" && raw.sourceKind !== "generation")
14902
14940
  throw new AccountMigrationError("generation schema is invalid");
14903
14941
  const id = text(raw.id, UUID, "generation id");
14904
14942
  const paths = generationPaths(raw.legacyPath, id);
@@ -14997,7 +15035,8 @@ function decodeAccountMigrationJournal(value) {
14997
15035
  "verification",
14998
15036
  "retiredSha256",
14999
15037
  "rollback",
15000
- "cancelled"
15038
+ "cancelled",
15039
+ "relocation"
15001
15040
  ], "journal");
15002
15041
  if (raw.schemaVersion !== 1)
15003
15042
  throw new AccountMigrationError("unsupported journal schema");
@@ -15017,10 +15056,10 @@ function decodeAccountMigrationJournal(value) {
15017
15056
  if (phase === void 0)
15018
15057
  throw new AccountMigrationError("journal phase is invalid");
15019
15058
  const sourceKind = raw.sourceKind;
15020
- if (sourceKind !== "file" && sourceKind !== "absent")
15059
+ if (sourceKind !== "file" && sourceKind !== "absent" && sourceKind !== "generation")
15021
15060
  throw new AccountMigrationError("journal source kind is invalid");
15022
- const sourceSha256 = sourceKind === "file" ? text(raw.sourceSha256, SHA256, "journal.sourceSha256") : void 0;
15023
- const captureSha256 = sourceKind === "file" ? text(raw.captureSha256, SHA256, "journal.captureSha256") : void 0;
15061
+ const sourceSha256 = sourceKind !== "absent" ? text(raw.sourceSha256, SHA256, "journal.sourceSha256") : void 0;
15062
+ const captureSha256 = sourceKind !== "absent" ? text(raw.captureSha256, SHA256, "journal.captureSha256") : void 0;
15024
15063
  if (sourceKind === "absent" && Object.hasOwn(raw, "captureSha256"))
15025
15064
  throw new AccountMigrationError("absent source cannot claim a captured file snapshot");
15026
15065
  if (sourceKind === "absent" && Object.hasOwn(raw, "sourceSha256"))
@@ -15037,7 +15076,7 @@ function decodeAccountMigrationJournal(value) {
15037
15076
  const sourceVersion = m.sourceVersion;
15038
15077
  if (sourceVersion !== null && sourceVersion !== 1 && sourceVersion !== 2 && sourceVersion !== 3 && sourceVersion !== 4)
15039
15078
  throw new AccountMigrationError("manifest source version is invalid");
15040
- if (sourceKind === "file" && sourceVersion === null || sourceKind === "absent" && sourceVersion !== null)
15079
+ if (sourceKind === "file" && sourceVersion === null || sourceKind !== "file" && sourceVersion !== null)
15041
15080
  throw new AccountMigrationError("manifest version differs from source kind");
15042
15081
  if (!finite(m.normalizationClock) || !finite(m.effectiveActiveIndex))
15043
15082
  throw new AccountMigrationError("manifest clock or cursor is invalid");
@@ -15067,6 +15106,10 @@ function decodeAccountMigrationJournal(value) {
15067
15106
  schemaVersion: 1
15068
15107
  }) || manifest.effectiveActiveIndex !== 0))
15069
15108
  throw new AccountMigrationError("absent-source manifest must be explicitly empty with no invented cursors");
15109
+ if (sourceKind === "generation" && (accounts.length || !isDeepStrictEqual(encodeRoutingSettings(manifest.routing), {
15110
+ schemaVersion: 1
15111
+ }) || manifest.effectiveActiveIndex !== 0))
15112
+ throw new AccountMigrationError("moved-store manifest must be explicitly empty");
15070
15113
  const effective = accounts.length ? Math.max(0, Math.min(manifest.routing.activeIndex ?? 0, accounts.length - 1)) : 0;
15071
15114
  if (effective !== manifest.effectiveActiveIndex)
15072
15115
  throw new AccountMigrationError("manifest effective cursor differs");
@@ -15114,6 +15157,24 @@ function decodeAccountMigrationJournal(value) {
15114
15157
  throw new AccountMigrationError("absent source cannot claim retired bytes");
15115
15158
  if (retiredSha256 !== void 0 && retiredSha256 !== sourceSha256)
15116
15159
  throw new AccountMigrationError("retired bytes are not associated with source");
15160
+ const relocation = decodeRelocation(raw, sourceKind, paths.legacyPath);
15161
+ if (sourceKind === "generation") {
15162
+ if (retiredSha256 !== void 0)
15163
+ throw new AccountMigrationError("moved source cannot claim retired pool-file bytes");
15164
+ if (relocation === void 0)
15165
+ throw new AccountMigrationError("moved source lacks its relocation evidence");
15166
+ if (operation === "rollback")
15167
+ throw new AccountMigrationError("a moved account store is not rolled back; move it back first with `antigravity-auth store relocate --back --offline`");
15168
+ if (relocation.sourceForwarded && !relocation.sourceTombstoned)
15169
+ throw new AccountMigrationError("source forward precedes its management tombstone");
15170
+ if ((relocation.sourceTombstoned || relocation.sourceForwarded) && (!verification || phase !== "retire" && phase !== "activate"))
15171
+ throw new AccountMigrationError("source tombstone or forward precedes durable verification");
15172
+ if (status === "active" && !relocation.sourceForwarded)
15173
+ throw new AccountMigrationError("active moved store lacks its source forward");
15174
+ if (phase === "activate" && !relocation.sourceForwarded)
15175
+ throw new AccountMigrationError("moved-store activation lacks its source forward");
15176
+ }
15177
+ const retirementRecorded = sourceKind === "file" ? retiredSha256 !== void 0 : sourceKind === "absent" ? raw.sourceAbsenceVerified === true : relocation?.sourceForwarded === true;
15117
15178
  let rollback;
15118
15179
  if (Object.hasOwn(raw, "rollback")) {
15119
15180
  const r = exact(raw.rollback, ["id", "snapshotSha256", "exportSha256", "rows", "successorInactive"], "rollback");
@@ -15139,13 +15200,13 @@ function decodeAccountMigrationJournal(value) {
15139
15200
  throw new AccountMigrationError("verification acknowledged an incomplete import");
15140
15201
  if (operation === "migrate" && (retiredSha256 !== void 0 || raw.sourceAbsenceVerified === true) && (!verification || phase !== "retire" && phase !== "activate"))
15141
15202
  throw new AccountMigrationError("retirement association precedes durable verification");
15142
- if (operation === "migrate" && phase === "activate" && (sourceKind === "file" ? retiredSha256 === void 0 : raw.sourceAbsenceVerified !== true))
15203
+ if (operation === "migrate" && phase === "activate" && !retirementRecorded)
15143
15204
  throw new AccountMigrationError("activation lacks its actual source retirement association");
15144
- if (status === "active" && (operation !== "migrate" || phase !== "activate" || (sourceKind === "file" ? retiredSha256 === void 0 : raw.sourceAbsenceVerified !== true) || rollback !== void 0 || cancelled))
15205
+ if (status === "active" && (operation !== "migrate" || phase !== "activate" || !retirementRecorded || rollback !== void 0 || cancelled))
15145
15206
  throw new AccountMigrationError("active receipt is incomplete");
15146
15207
  if (operation === "rollback" && rollback === void 0 && !cancelled)
15147
15208
  throw new AccountMigrationError("rollback lacks its current-credential snapshot");
15148
- if (operation === "rollback" && !cancelled && (verification === void 0 || (sourceKind === "file" ? retiredSha256 === void 0 : raw.sourceAbsenceVerified !== true)))
15209
+ if (operation === "rollback" && !cancelled && (verification === void 0 || !retirementRecorded))
15149
15210
  throw new AccountMigrationError("rollback lacks the original verified retirement");
15150
15211
  if (status === "inactive" && !cancelled && (operation !== "rollback" || phase !== "activate" || rollback === void 0))
15151
15212
  throw new AccountMigrationError("inactive receipt lacks a completed rollback");
@@ -15169,7 +15230,53 @@ function decodeAccountMigrationJournal(value) {
15169
15230
  ...verification === void 0 ? {} : { verification },
15170
15231
  ...retiredSha256 === void 0 ? {} : { retiredSha256 },
15171
15232
  ...rollback === void 0 ? {} : { rollback },
15172
- ...cancelled ? { cancelled: true } : {}
15233
+ ...cancelled ? { cancelled: true } : {},
15234
+ ...relocation === void 0 ? {} : { relocation }
15235
+ };
15236
+ }
15237
+ function decodeRelocation(raw, sourceKind, legacyPath) {
15238
+ if (!Object.hasOwn(raw, "relocation"))
15239
+ return void 0;
15240
+ if (sourceKind !== "generation")
15241
+ throw new AccountMigrationError("only a moved store records relocation evidence");
15242
+ const r = exact(raw.relocation, ["source", "rows", "sourceTombstoned", "sourceForwarded"], "relocation");
15243
+ const s = exact(r.source, [
15244
+ "legacyPath",
15245
+ "storeDir",
15246
+ "journalId",
15247
+ "configSha256",
15248
+ "stateSha256",
15249
+ "statePresent"
15250
+ ], "relocation source");
15251
+ if (typeof s.legacyPath !== "string")
15252
+ throw new AccountMigrationError("relocation source path is invalid");
15253
+ const journalId = text(s.journalId, UUID, "relocation source journal");
15254
+ const source = generationPaths(s.legacyPath, journalId);
15255
+ if (s.storeDir !== source.storeDir)
15256
+ throw new AccountMigrationError("relocation source association differs");
15257
+ if (sameFilesystemPath(source.legacyPath, legacyPath))
15258
+ throw new AccountMigrationError("relocation source and target share one anchor");
15259
+ if (typeof s.statePresent !== "boolean")
15260
+ throw new AccountMigrationError("relocation state presence is invalid");
15261
+ if (!s.statePresent && Object.hasOwn(s, "stateSha256"))
15262
+ throw new AccountMigrationError("absent source state cannot claim a file hash");
15263
+ const rows = list(r.rows, "relocation rows").map((id) => text(id, UUID, "relocation row id"));
15264
+ if (new Set(rows).size !== rows.length)
15265
+ throw new AccountMigrationError("relocation rows are duplicated");
15266
+ if (typeof r.sourceTombstoned !== "boolean" || typeof r.sourceForwarded !== "boolean")
15267
+ throw new AccountMigrationError("relocation progress flags are invalid");
15268
+ return {
15269
+ source: {
15270
+ legacyPath: source.legacyPath,
15271
+ storeDir: source.storeDir,
15272
+ journalId,
15273
+ configSha256: text(s.configSha256, SHA256, "relocation config hash"),
15274
+ ...s.statePresent ? { stateSha256: text(s.stateSha256, SHA256, "relocation state hash") } : {},
15275
+ statePresent: s.statePresent
15276
+ },
15277
+ rows,
15278
+ sourceTombstoned: r.sourceTombstoned,
15279
+ sourceForwarded: r.sourceForwarded
15173
15280
  };
15174
15281
  }
15175
15282
  function pendingLockFailure(modules, error) {
@@ -15459,6 +15566,8 @@ async function verifyCopies(paths, journal, retired) {
15459
15566
  const capture2 = await secureRead(join(paths.transfersDir, `${journal.id}.capture.json`));
15460
15567
  if (digest(capture2) !== journal.captureSha256 || !isDeepStrictEqual(jsonBytes(capture2), captureJson(journal)))
15461
15568
  throw new AccountMigrationError("journal differs from its exclusive capture snapshot");
15569
+ if (journal.sourceKind === "generation")
15570
+ return verifyRelocationSnapshot(backup, journal);
15462
15571
  const expected = parseLegacyAccountStorage(new TextDecoder("utf-8", { fatal: true }).decode(backup), journal.manifest.normalizationClock);
15463
15572
  if (!isDeepStrictEqual(manifestJson(expected), manifestJson(journal.manifest)))
15464
15573
  throw new AccountMigrationError("captured manifest differs from its verified original source");
@@ -15477,9 +15586,40 @@ function captureJson(journal) {
15477
15586
  sourceKind: journal.sourceKind,
15478
15587
  sourceSha256: journal.sourceSha256,
15479
15588
  manifest: manifestJson(journal.manifest),
15480
- mapping: journal.mapping
15589
+ mapping: journal.mapping,
15590
+ ...journal.relocation === void 0 ? {} : { relocation: { source: journal.relocation.source } }
15481
15591
  };
15482
15592
  }
15593
+ function base64Bytes(value, path5) {
15594
+ if (typeof value !== "string")
15595
+ throw new AccountMigrationError(`${path5} is invalid`);
15596
+ const bytes = Buffer.from(value, "base64");
15597
+ if (bytes.toString("base64") !== value)
15598
+ throw new AccountMigrationError(`${path5} is not canonical base64`);
15599
+ return bytes;
15600
+ }
15601
+ function decodeRelocationSnapshot(value) {
15602
+ const raw = exact(value, ["config", "state", "journal"], "moved snapshot");
15603
+ return {
15604
+ config: base64Bytes(raw.config, "moved snapshot config"),
15605
+ ...Object.hasOwn(raw, "state") ? { state: base64Bytes(raw.state, "moved snapshot state") } : {},
15606
+ journal: base64Bytes(raw.journal, "moved snapshot journal")
15607
+ };
15608
+ }
15609
+ function verifyRelocationSnapshot(backup, journal) {
15610
+ const source = journal.relocation?.source;
15611
+ if (source === void 0)
15612
+ throw new AccountMigrationError("moved source lacks its relocation evidence");
15613
+ const snapshot2 = decodeRelocationSnapshot(jsonBytes(backup));
15614
+ if (digest(snapshot2.config) !== source.configSha256 || snapshot2.state !== void 0 !== source.statePresent || snapshot2.state !== void 0 && digest(snapshot2.state) !== source.stateSha256)
15615
+ throw new AccountMigrationError("moved source snapshot differs from its recorded hashes");
15616
+ const copied = decodeAccountMigrationJournal(jsonBytes(snapshot2.journal));
15617
+ if (copied.id !== source.journalId || copied.legacyPath !== source.legacyPath || copied.storeDir !== source.storeDir || copied.status !== "active")
15618
+ throw new AccountMigrationError("moved source snapshot is not the active source generation");
15619
+ const config = object(jsonBytes(snapshot2.config), "moved source config");
15620
+ if (!isDeepStrictEqual(decodeAccountStoreGeneration(config[ACCOUNT_STORE_GENERATION_SETTINGS_KEY]), generationJson(copied)))
15621
+ throw new AccountMigrationError("moved source snapshot belongs to another generation");
15622
+ }
15483
15623
  async function synchronizedSnapshot(paths, boundary) {
15484
15624
  await syncFile(paths.configPath);
15485
15625
  const statePresent = await exists(paths.statePath);
@@ -15551,7 +15691,7 @@ function receipt(journal) {
15551
15691
  storeDir: journal.storeDir,
15552
15692
  sourceKind: journal.sourceKind,
15553
15693
  durability: journal.verification?.durability ?? accountMigrationDurability(),
15554
- restartRequired: journal.sourceKind === "file" || journal.operation === "rollback"
15694
+ restartRequired: journal.sourceKind !== "absent" || journal.operation === "rollback"
15555
15695
  };
15556
15696
  }
15557
15697
  async function currentSuccessor(store, paths, journal) {
@@ -15635,35 +15775,13 @@ async function trustedCurrentGeneration(store, paths, journal) {
15635
15775
  }
15636
15776
  async function readAccountStoreBinding(legacyPath, modules, now, expectedGeneration) {
15637
15777
  try {
15638
- const paths = await resolvePublishedAccountStorePaths(legacyPath);
15639
- if (!paths)
15640
- return await exists(legacyPath) ? { status: "pending" } : { status: "initialization-required" };
15641
- const journal = await readJournal(paths);
15642
- if (!journal)
15643
- throw new AccountMigrationError("published binding journal missing");
15644
- if (expectedGeneration !== void 0 && journal.id !== expectedGeneration)
15645
- throw new AccountMigrationError("bound repository generation differs from pointer");
15646
- if (journal.status === "pending")
15647
- return {
15648
- status: "pending",
15649
- phase: journal.phase,
15650
- operation: journal.operation
15651
- };
15652
- if (journal.status === "inactive")
15653
- return { status: "inactive", id: journal.id };
15654
- if (await exists(legacyPath))
15655
- throw new AccountMigrationError("legacy source was recreated after activation");
15656
- await verifyCopies(paths, journal, true);
15657
- const settings = await trustedCurrentGeneration(openAdmissionStore(modules, paths, now), paths, journal);
15658
- const pending = settings[MANAGEMENT_SETTINGS_KEY];
15659
- if (pending !== void 0) {
15660
- const record3 = object(pending, "repository management");
15661
- if (record3.kind === "migration")
15662
- return { status: "pending", phase: "activate", operation: "migrate" };
15663
- if (record3.kind !== "clear" && record3.kind !== "replace-pool")
15664
- throw new AccountMigrationError("unknown management owner prevents binding");
15778
+ const record3 = await readPointerRecord(legacyPath);
15779
+ if (record3?.schemaVersion === 2) {
15780
+ if (await exists(legacyPath))
15781
+ throw new AccountMigrationError(`a pool file reappeared at ${legacyPath} after the account store moved to ${record3.relocatedTo.legacyPath}`);
15782
+ return await bindPublishedGeneration(await forwardTarget(legacyPath, record3), modules, now, expectedGeneration, legacyPath);
15665
15783
  }
15666
- return { status: "bound", receipt: receipt(journal), paths };
15784
+ return await bindPublishedGeneration(legacyPath, modules, now, expectedGeneration);
15667
15785
  } catch (error) {
15668
15786
  return {
15669
15787
  status: "error",
@@ -15671,6 +15789,65 @@ async function readAccountStoreBinding(legacyPath, modules, now, expectedGenerat
15671
15789
  };
15672
15790
  }
15673
15791
  }
15792
+ async function assertSourceForwarded(journal, forwardedFrom) {
15793
+ const source = journal.relocation?.source;
15794
+ if (source === void 0)
15795
+ throw new AccountMigrationError("moved source lacks its relocation evidence");
15796
+ const pointer = accountStorePointerPath(source.legacyPath);
15797
+ if (forwardedFrom !== void 0 && forwardedFrom !== source.legacyPath)
15798
+ throw new AccountMigrationError(`the forwarding pointer ${accountStorePointerPath(forwardedFrom)} leads to a store moved from ${source.legacyPath}`);
15799
+ if (await exists(source.legacyPath))
15800
+ throw new AccountMigrationError(`a pool file reappeared at ${source.legacyPath} after the account store moved to ${journal.legacyPath}`);
15801
+ const record3 = await readPointerRecord(source.legacyPath);
15802
+ if (record3 === void 0)
15803
+ throw new AccountMigrationError(`the forwarding pointer ${pointer} to the moved account store at ${journal.storeDir} is missing; restore it`);
15804
+ if (record3.schemaVersion === 1)
15805
+ throw new AccountMigrationError(`the account store in ${dirname(source.legacyPath)} was reactivated: ${pointer} publishes generation ${record3.id} while the moved store at ${journal.storeDir} is active; restore the forwarding pointer, or run \`antigravity-auth store relocate\``);
15806
+ if (record3.id !== source.journalId || record3.relocatedTo.legacyPath !== journal.legacyPath || record3.relocatedTo.id !== journal.id)
15807
+ throw new AccountMigrationError(`the forwarding pointer ${pointer} names another store than the moved account store at ${journal.storeDir}`);
15808
+ }
15809
+ async function bindPublishedGeneration(legacyPath, modules, now, expectedGeneration, forwardedFrom) {
15810
+ const paths = await resolvePublishedAccountStorePaths(legacyPath);
15811
+ if (!paths) {
15812
+ if (forwardedFrom !== void 0)
15813
+ throw new AccountMigrationError("forwarded anchor publishes no generation");
15814
+ return await exists(legacyPath) ? { status: "pending" } : { status: "initialization-required" };
15815
+ }
15816
+ const journal = await readJournal(paths);
15817
+ if (!journal)
15818
+ throw new AccountMigrationError("published binding journal missing");
15819
+ if (expectedGeneration !== void 0 && journal.id !== expectedGeneration)
15820
+ throw new AccountMigrationError("bound repository generation differs from pointer");
15821
+ if (forwardedFrom !== void 0 && journal.sourceKind !== "generation")
15822
+ throw new AccountMigrationError(`the forwarding pointer ${accountStorePointerPath(forwardedFrom)} leads to a store that was not moved there`);
15823
+ if (journal.sourceKind === "generation" && journal.status === "pending")
15824
+ throw new AccountMigrationError(`a move of the account store to ${journal.storeDir} is unfinished; finish it with the version that started it`);
15825
+ if (journal.status === "pending")
15826
+ return {
15827
+ status: "pending",
15828
+ phase: journal.phase,
15829
+ operation: journal.operation
15830
+ };
15831
+ if (journal.status === "inactive")
15832
+ return { status: "inactive", id: journal.id };
15833
+ if (await exists(legacyPath))
15834
+ throw new AccountMigrationError("legacy source was recreated after activation");
15835
+ await verifyCopies(paths, journal, true);
15836
+ if (journal.sourceKind === "generation")
15837
+ await assertSourceForwarded(journal, forwardedFrom);
15838
+ const settings = await trustedCurrentGeneration(openAdmissionStore(modules, paths, now), paths, journal);
15839
+ const pending = settings[MANAGEMENT_SETTINGS_KEY];
15840
+ if (pending !== void 0) {
15841
+ const record3 = object(pending, "repository management");
15842
+ if (record3.kind === "migration" && record3.id !== journal.id)
15843
+ throw new AccountMigrationError(`the account store at ${paths.storeDir} was moved to generation ${String(record3.id)}, but ${accountStorePointerPath(legacyPath)} publishes the old store again; restore the forwarding pointer, or run \`antigravity-auth store relocate\``);
15844
+ if (record3.kind === "migration")
15845
+ return { status: "pending", phase: "activate", operation: "migrate" };
15846
+ if (record3.kind !== "clear" && record3.kind !== "replace-pool")
15847
+ throw new AccountMigrationError("unknown management owner prevents binding");
15848
+ }
15849
+ return { status: "bound", receipt: receipt(journal), paths };
15850
+ }
15674
15851
  async function readAccountStoreAdmission(legacyPath, modules, now, expectedGeneration) {
15675
15852
  const binding = await readAccountStoreBinding(legacyPath, modules, now, expectedGeneration);
15676
15853
  if (binding.status !== "bound")
@@ -15964,6 +16141,8 @@ function createAccountMigrationFactory(modules) {
15964
16141
  const existing = await readJournal(paths);
15965
16142
  if (!existing)
15966
16143
  throw new AccountMigrationError("published generation journal missing");
16144
+ if (existing.sourceKind === "generation")
16145
+ throw new AccountMigrationError("a moved account store is finished by `antigravity-auth store relocate`, not by migrate");
15967
16146
  if (existing.status === "inactive") {
15968
16147
  previous = existing;
15969
16148
  await modules.fs.withLock(paths.configPath, {
@@ -16139,6 +16318,9 @@ function createAccountRollbackFactory(modules) {
16139
16318
  throw new AccountMigrationError("stopped processes and timers must be explicitly confirmed");
16140
16319
  try {
16141
16320
  return await withParentTopology(modules, options.legacyPath, async () => {
16321
+ const record3 = await readPointerRecord(options.legacyPath);
16322
+ if (record3?.schemaVersion === 2)
16323
+ throw new AccountMigrationError(`the account store moved to ${record3.relocatedTo.legacyPath}; move it back with \`antigravity-auth store relocate --back --offline\` before rolling it back`);
16142
16324
  const paths = await resolvePublishedAccountStorePaths(options.legacyPath);
16143
16325
  if (!paths)
16144
16326
  throw new AccountMigrationError("rollback requires a published generation");
@@ -16151,6 +16333,8 @@ function createAccountRollbackFactory(modules) {
16151
16333
  const initialJournal = await readJournal(paths);
16152
16334
  if (!initialJournal)
16153
16335
  throw new AccountMigrationError("rollback requires an owned migration generation");
16336
+ if (initialJournal.sourceKind === "generation")
16337
+ throw new AccountMigrationError(`this account store was moved here from ${initialJournal.relocation?.source.legacyPath}; move it back with \`antigravity-auth store relocate --back --offline\` before rolling it back`);
16154
16338
  let journal = initialJournal;
16155
16339
  const store = openMigrationStore(modules, paths, options.now, writeObserver(paths, lease, options.onBoundary));
16156
16340
  if (journal.status === "inactive") {
@@ -26802,6 +26986,124 @@ async function commitVaultProviderState(input2) {
26802
26986
  return { result };
26803
26987
  });
26804
26988
  }
26989
+ async function commitVaultProviderStates(input2) {
26990
+ const { claustrum, fs: fs4, statePath } = input2;
26991
+ input2.signal?.throwIfAborted();
26992
+ const results = new Array(input2.entries.length);
26993
+ const refuse = (index, error) => {
26994
+ results[index] = { status: "refused", error };
26995
+ };
26996
+ let pending = [];
26997
+ for (const [index, entry] of input2.entries.entries()) {
26998
+ try {
26999
+ pending.push({
27000
+ index,
27001
+ attribution: pinAttribution(entry.attribution),
27002
+ update: entry.update
27003
+ });
27004
+ } catch (error) {
27005
+ refuse(index, error);
27006
+ }
27007
+ }
27008
+ const keepBound = (roster, entries) => entries.filter((entry) => {
27009
+ try {
27010
+ assertRosterBinding(roster, entry.attribution, claustrum);
27011
+ return true;
27012
+ } catch (error) {
27013
+ refuse(entry.index, error);
27014
+ return false;
27015
+ }
27016
+ });
27017
+ if (pending.length > 0)
27018
+ pending = keepBound(await claustrum.readVaultRoster(input2.rosterPath), pending);
27019
+ input2.signal?.throwIfAborted();
27020
+ if (pending.length === 0)
27021
+ return results;
27022
+ await claustrum.mutateVaultRoster(input2.rosterPath, async (roster, rosterLock) => {
27023
+ input2.signal?.throwIfAborted();
27024
+ const bound = keepBound(roster, pending);
27025
+ if (bound.length === 0)
27026
+ return { result: void 0 };
27027
+ await fs4.withLock(statePath, VAULT_PROVIDER_STATE_LOCK, async (stateLock) => {
27028
+ input2.signal?.throwIfAborted();
27029
+ const proofs = await Promise.allSettled(bound.map((entry) => input2.verify(entry.attribution)));
27030
+ input2.signal?.throwIfAborted();
27031
+ const proven = bound.filter((entry, at) => {
27032
+ const proof = proofs[at];
27033
+ if (proof?.status !== "rejected")
27034
+ return true;
27035
+ refuse(entry.index, proof.reason);
27036
+ return false;
27037
+ });
27038
+ if (proven.length === 0)
27039
+ return;
27040
+ const file = await readVaultProviderState(statePath);
27041
+ input2.signal?.throwIfAborted();
27042
+ const accounts = {
27043
+ ...file.accounts
27044
+ };
27045
+ const written = [];
27046
+ for (const entry of proven) {
27047
+ const identity3 = entry.attribution.accountIdentity;
27048
+ const current = Object.hasOwn(accounts, identity3) ? accounts[identity3] : void 0;
27049
+ try {
27050
+ const requested = entry.update(current);
27051
+ if (isRecord9(requested) && typeof requested.then === "function")
27052
+ throw new VaultProviderStateError("invalid-update", "a state update must be synchronous");
27053
+ if (requested === void 0 || requested === null && !current) {
27054
+ results[entry.index] = current ? { status: "unchanged", state: current } : { status: "unchanged" };
27055
+ continue;
27056
+ }
27057
+ if (requested === null) {
27058
+ delete accounts[identity3];
27059
+ written.push(entry);
27060
+ continue;
27061
+ }
27062
+ const next = Object.freeze({
27063
+ observed: Object.freeze({
27064
+ routeId: entry.attribution.routeId,
27065
+ credentialId: entry.attribution.credentialId,
27066
+ recordVersion: entry.attribution.recordVersion
27067
+ }),
27068
+ ...decodeValue(requested, "update", "typed")
27069
+ });
27070
+ accounts[identity3] = next;
27071
+ written.push({ ...entry, next });
27072
+ } catch (error) {
27073
+ refuse(entry.index, error);
27074
+ }
27075
+ }
27076
+ if (written.length === 0)
27077
+ return;
27078
+ const encoded = encodeVaultProviderState({ ...file, accounts });
27079
+ try {
27080
+ await fs4.writeJsonAtomic(statePath, encoded, {
27081
+ beforeRename: async () => {
27082
+ await rosterLock.assertOwned();
27083
+ await stateLock.assertOwned();
27084
+ input2.signal?.throwIfAborted();
27085
+ }
27086
+ });
27087
+ } catch (error) {
27088
+ let reloaded;
27089
+ try {
27090
+ reloaded = await readVaultProviderState(statePath);
27091
+ } catch {
27092
+ reloaded = void 0;
27093
+ }
27094
+ for (const entry of written) {
27095
+ const state = reloaded && vaultAccountState(reloaded, entry.attribution.accountIdentity);
27096
+ results[entry.index] = state ? { status: "uncertain", error, state } : { status: "uncertain", error };
27097
+ }
27098
+ return;
27099
+ }
27100
+ for (const entry of written)
27101
+ results[entry.index] = entry.next ? { status: "written", state: entry.next } : { status: "cleared" };
27102
+ });
27103
+ return { result: void 0 };
27104
+ });
27105
+ return results;
27106
+ }
26805
27107
 
26806
27108
  // ../core/dist/vault-account-source.js
26807
27109
  function untilAborted2(pending, signal) {
@@ -27058,6 +27360,20 @@ function createAntigravityVaultAccountSource(options) {
27058
27360
  update
27059
27361
  });
27060
27362
  },
27363
+ commitStates: async (entries, signal) => {
27364
+ assertOpen(signal);
27365
+ if (!options.state)
27366
+ throw new AntigravityVaultSourceError("state-unavailable", "No provider-state sidecar is configured for this vault source");
27367
+ return commitVaultProviderStates({
27368
+ claustrum,
27369
+ fs: options.state.fs,
27370
+ rosterPath: options.rosterPath,
27371
+ statePath: options.state.path,
27372
+ entries,
27373
+ verify: (by) => verifyAttribution(by, signal),
27374
+ signal
27375
+ });
27376
+ },
27061
27377
  decline: async (ref) => {
27062
27378
  assertOpen();
27063
27379
  await consumer.decline(ref.routeId);
@@ -28002,23 +28318,37 @@ function migrateLegacyWindowsConfig() {
28002
28318
  return false;
28003
28319
  }
28004
28320
  }
28321
+ function resolveWindowsAccountAnchor(newPath, legacyPath) {
28322
+ const standard = resolve12(newPath);
28323
+ const legacy = resolve12(legacyPath);
28324
+ if (standard.toLowerCase() === legacy.toLowerCase()) return newPath;
28325
+ const standardPointer = existsSync3(accountStorePointerPath(standard));
28326
+ const legacyPointer = existsSync3(accountStorePointerPath(legacy));
28327
+ if (standardPointer && legacyPointer) {
28328
+ throw new Error(
28329
+ `Two migrated account stores exist: one is published at ${newPath} and another at ${legacyPath}. Keep one store and remove the other, then restart OpenCode.`
28330
+ );
28331
+ }
28332
+ if (legacyPointer && !standardPointer) return legacyPath;
28333
+ if (!existsSync3(standard) && existsSync3(legacy)) return legacyPath;
28334
+ return newPath;
28335
+ }
28005
28336
  function getStoragePathWithMigration() {
28006
28337
  const newPath = join10(getConfigDir(), "antigravity-accounts.json");
28007
28338
  if (process.platform === "win32") {
28008
28339
  migrateLegacyWindowsConfig();
28009
- if (!existsSync3(newPath)) {
28010
- const legacyPath = join10(
28011
- getLegacyWindowsConfigDir(),
28012
- "antigravity-accounts.json"
28013
- );
28014
- if (existsSync3(legacyPath)) {
28015
- log5.info("Using legacy Windows config path (migration failed)", {
28016
- legacyPath,
28017
- newPath
28018
- });
28019
- return legacyPath;
28020
- }
28340
+ const legacyPath = join10(
28341
+ getLegacyWindowsConfigDir(),
28342
+ "antigravity-accounts.json"
28343
+ );
28344
+ const anchored = resolveWindowsAccountAnchor(newPath, legacyPath);
28345
+ if (resolve12(anchored).toLowerCase() !== resolve12(newPath).toLowerCase() && !existsSync3(accountStorePointerPath(resolve12(anchored)))) {
28346
+ log5.info("Using legacy Windows config path (migration failed)", {
28347
+ legacyPath,
28348
+ newPath
28349
+ });
28021
28350
  }
28351
+ return anchored;
28022
28352
  }
28023
28353
  return newPath;
28024
28354
  }
@@ -28412,9 +28742,11 @@ function stateHomeLogsDir() {
28412
28742
  }
28413
28743
  function legacyAccountFile(configDir = getConfigDir()) {
28414
28744
  const standard = join12(configDir, ACCOUNT_FILE_NAME);
28415
- if (process.platform !== "win32" || existsSync4(standard)) return standard;
28416
- const windows2 = join12(legacyWindowsConfigDir(), ACCOUNT_FILE_NAME);
28417
- return existsSync4(windows2) ? windows2 : standard;
28745
+ if (process.platform !== "win32") return standard;
28746
+ return resolveWindowsAccountAnchor(
28747
+ standard,
28748
+ join12(legacyWindowsConfigDir(), ACCOUNT_FILE_NAME)
28749
+ );
28418
28750
  }
28419
28751
  function legacyVaultDir(accountFile) {
28420
28752
  return join12(dirname16(accountFile), VAULT_DIR_NAME);
@@ -35720,6 +36052,13 @@ function applyDurableSelection(row, metadata) {
35720
36052
  function stateBelongsTo(state, row) {
35721
36053
  return state.observed.routeId === row.route.routeId && state.observed.credentialId === row.route.credentialId;
35722
36054
  }
36055
+ function quotaUpdate(quota) {
36056
+ return (current) => ({
36057
+ ...current?.metadata !== void 0 ? { metadata: current.metadata } : {},
36058
+ quota,
36059
+ ...current?.extensions !== void 0 ? { extensions: current.extensions } : {}
36060
+ });
36061
+ }
35723
36062
  function createVaultSelectionState(options) {
35724
36063
  const now = options.now ?? (() => Date.now());
35725
36064
  const attributions = /* @__PURE__ */ new WeakMap();
@@ -35793,15 +36132,30 @@ function createVaultSelectionState(options) {
35793
36132
  },
35794
36133
  flush: flush2,
35795
36134
  recordQuota(attribution, quota, signal) {
35796
- return options.source.commitState(
36135
+ return options.source.commitState(attribution, quotaUpdate(quota), signal);
36136
+ },
36137
+ async recordQuotas(readings, signal) {
36138
+ const entries = readings.map(({ attribution, quota }) => ({
35797
36139
  attribution,
35798
- (current) => ({
35799
- ...current?.metadata !== void 0 ? { metadata: current.metadata } : {},
35800
- quota,
35801
- ...current?.extensions !== void 0 ? { extensions: current.extensions } : {}
35802
- }),
35803
- signal
35804
- );
36140
+ update: quotaUpdate(quota)
36141
+ }));
36142
+ if (options.source.commitStates)
36143
+ return options.source.commitStates(entries, signal);
36144
+ const results = [];
36145
+ for (const { attribution, update } of entries) {
36146
+ if (signal?.aborted) {
36147
+ results.push({ status: "refused", error: signal.reason });
36148
+ continue;
36149
+ }
36150
+ try {
36151
+ results.push(
36152
+ await options.source.commitState(attribution, update, signal)
36153
+ );
36154
+ } catch (error) {
36155
+ results.push({ status: "refused", error });
36156
+ }
36157
+ }
36158
+ return results;
35805
36159
  }
35806
36160
  };
35807
36161
  }
@@ -35931,8 +36285,15 @@ async function checkVaultQuota(input2) {
35931
36285
  const state = input2.pool.state;
35932
36286
  const rows = [...input2.pool.selector.rows];
35933
36287
  const now = input2.now ?? (() => Date.now());
36288
+ const reportError = (error) => {
36289
+ try {
36290
+ input2.onError?.(error);
36291
+ } catch {
36292
+ }
36293
+ };
35934
36294
  let checked = 0;
35935
36295
  if (state === void 0) input2.onOutcome?.("state-invalid");
36296
+ const readings = [];
35936
36297
  for (const row of rows) {
35937
36298
  if (input2.signal.aborted || state === void 0) break;
35938
36299
  try {
@@ -35952,32 +36313,49 @@ async function checkVaultQuota(input2) {
35952
36313
  input2.onOutcome?.("unattributed");
35953
36314
  continue;
35954
36315
  }
35955
- const reading = vaultQuotaState(answer.quota, answer.observedAt ?? now());
35956
- input2.onStage?.("commit");
35957
- input2.signal.throwIfAborted();
35958
- const result = await state.recordQuota(attribution, reading, input2.signal);
35959
- if (result.status !== "written") {
35960
- input2.onOutcome?.(
35961
- result.status === "uncertain" ? "write-uncertain" : "commit-unchanged",
35962
- result.status === "uncertain" ? result.error : void 0
35963
- );
35964
- continue;
35965
- }
35966
- checked += 1;
35967
- input2.onOutcome?.("recorded");
35968
- const live = input2.pool.selector.rows.find(
35969
- (candidate) => candidate.route.routeId === attribution.routeId && candidate.route.credentialId === attribution.credentialId && candidate.route.accountIdentity === attribution.accountIdentity
35970
- );
35971
- if (live !== void 0) {
35972
- const cached = cachedQuotaOf(reading);
35973
- if (cached !== void 0) live.cachedQuota = cached;
35974
- live.cachedQuotaUpdatedAt = reading.cachedQuotaUpdatedAt ?? void 0;
35975
- }
36316
+ readings.push({
36317
+ attribution,
36318
+ quota: vaultQuotaState(answer.quota, answer.observedAt ?? now())
36319
+ });
35976
36320
  } catch (error) {
35977
- try {
35978
- input2.onError?.(error);
35979
- } catch {
35980
- }
36321
+ reportError(error);
36322
+ }
36323
+ }
36324
+ if (state === void 0 || readings.length === 0 || input2.signal.aborted)
36325
+ return { checked, notChecked: rows.length - checked };
36326
+ let results;
36327
+ try {
36328
+ input2.onStage?.("commit");
36329
+ input2.signal.throwIfAborted();
36330
+ results = await state.recordQuotas(readings, input2.signal);
36331
+ } catch (error) {
36332
+ for (const _ of readings) reportError(error);
36333
+ return { checked, notChecked: rows.length - checked };
36334
+ }
36335
+ for (const [at, { attribution, quota: reading }] of readings.entries()) {
36336
+ const result = results[at];
36337
+ if (result === void 0 || result.status === "refused") {
36338
+ reportError(
36339
+ result === void 0 ? new Error("The provider-state commit returned no result") : result.error
36340
+ );
36341
+ continue;
36342
+ }
36343
+ if (result.status !== "written") {
36344
+ input2.onOutcome?.(
36345
+ result.status === "uncertain" ? "write-uncertain" : "commit-unchanged",
36346
+ result.status === "uncertain" ? result.error : void 0
36347
+ );
36348
+ continue;
36349
+ }
36350
+ checked += 1;
36351
+ input2.onOutcome?.("recorded");
36352
+ const live = input2.pool.selector.rows.find(
36353
+ (candidate) => candidate.route.routeId === attribution.routeId && candidate.route.credentialId === attribution.credentialId && candidate.route.accountIdentity === attribution.accountIdentity
36354
+ );
36355
+ if (live !== void 0) {
36356
+ const cached = cachedQuotaOf(reading);
36357
+ if (cached !== void 0) live.cachedQuota = cached;
36358
+ live.cachedQuotaUpdatedAt = reading.cachedQuotaUpdatedAt ?? void 0;
35981
36359
  }
35982
36360
  }
35983
36361
  return { checked, notChecked: rows.length - checked };