openmeld 0.3.206 → 0.3.207

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 (86) hide show
  1. package/dist/{add-me-membership-BkHWMxE4.js → add-me-membership-1JHMjZoR.js} +2 -2
  2. package/dist/{add-me-membership-BkHWMxE4.js.map → add-me-membership-1JHMjZoR.js.map} +1 -1
  3. package/dist/{agents-BOTlKiwS.js → agents-CIDsThyG.js} +150 -108
  4. package/dist/agents-CIDsThyG.js.map +1 -0
  5. package/dist/{api-client-foundation-6ms5gSu8.js → api-client-foundation-D6_NXHPV.js} +1 -1
  6. package/dist/{api-client-foundation-DpgDs0rw.js → api-client-foundation-DSurenul.js} +3 -3
  7. package/dist/{api-client-foundation-DpgDs0rw.js.map → api-client-foundation-DSurenul.js.map} +1 -1
  8. package/dist/auth-session-B7QMhHwh.js +4 -0
  9. package/dist/{auth-session-BjSqMLTz.js → auth-session-CO5XtFaq.js} +266 -75
  10. package/dist/auth-session-CO5XtFaq.js.map +1 -0
  11. package/dist/{base-url-CRAYNW-4.js → base-url-BE3pFiOZ.js} +1 -1
  12. package/dist/{base-url-9A557X2K.js → base-url-C6sHRNGu.js} +2 -2
  13. package/dist/{base-url-9A557X2K.js.map → base-url-C6sHRNGu.js.map} +1 -1
  14. package/dist/cli-binary-manifest-DiUulkp0.js +117 -0
  15. package/dist/cli-binary-manifest-DiUulkp0.js.map +1 -0
  16. package/dist/{command-CkbzbvXy.js → command-Bzt9zgnI.js} +13 -11
  17. package/dist/{command-CkbzbvXy.js.map → command-Bzt9zgnI.js.map} +1 -1
  18. package/dist/computer-connection-BOl79Ftf.js +54 -0
  19. package/dist/computer-connection-BOl79Ftf.js.map +1 -0
  20. package/dist/computer-connection-review-BTOvbJYL.js +39 -0
  21. package/dist/computer-connection-review-BTOvbJYL.js.map +1 -0
  22. package/dist/{computer-setup-continuation-Cd9nhLQ-.js → computer-setup-continuation-DmKdhR5u.js} +4 -4
  23. package/dist/{computer-setup-continuation-Cd9nhLQ-.js.map → computer-setup-continuation-DmKdhR5u.js.map} +1 -1
  24. package/dist/control-plane-D9jDcbMZ.js +1211 -0
  25. package/dist/control-plane-D9jDcbMZ.js.map +1 -0
  26. package/dist/daemon-local-state-file-jOXuXrky.js +45 -0
  27. package/dist/daemon-local-state-file-jOXuXrky.js.map +1 -0
  28. package/dist/daemon-runtime-lease-Dd4hdHNo.js +50 -0
  29. package/dist/daemon-runtime-lease-Dd4hdHNo.js.map +1 -0
  30. package/dist/{daemon-runtime-lease-BG9g0a6Z.js → daemon-runtime-lease-y3n1K0-C.js} +1 -1
  31. package/dist/{daemon-service-manager-DqVtRLBY.js → daemon-service-manager-Bh0LoLed.js} +1 -1
  32. package/dist/{daemon-service-manager-BVipiZwK.js → daemon-service-manager-GiMCiTmu.js} +99 -85
  33. package/dist/daemon-service-manager-GiMCiTmu.js.map +1 -0
  34. package/dist/daemon-service-runtime-DQW9gSLT.js +3642 -0
  35. package/dist/daemon-service-runtime-DQW9gSLT.js.map +1 -0
  36. package/dist/{daemon-state-BwIoDq7_.js → daemon-state-C37ZtIZK.js} +11 -5
  37. package/dist/daemon-state-C37ZtIZK.js.map +1 -0
  38. package/dist/{dist-CxadJClH.js → dist-D-kJdWZE.js} +726 -579
  39. package/dist/dist-D-kJdWZE.js.map +1 -0
  40. package/dist/dist-DTG_Vqc7.js +4 -0
  41. package/dist/distribution-DY2fBeSW.js +72 -0
  42. package/dist/distribution-DY2fBeSW.js.map +1 -0
  43. package/dist/{elapsed-time-C7P-nWIO.js → elapsed-time-CcoM2R3N.js} +7 -4
  44. package/dist/{elapsed-time-C7P-nWIO.js.map → elapsed-time-CcoM2R3N.js.map} +1 -1
  45. package/dist/{installation-inventory-P49sTjhe.js → installation-inventory-DJlwXa1q.js} +7 -6
  46. package/dist/{installation-inventory-P49sTjhe.js.map → installation-inventory-DJlwXa1q.js.map} +1 -1
  47. package/dist/{lock-CvBnBcFK.js → lock-Dxp6o_t_.js} +56 -7
  48. package/dist/lock-Dxp6o_t_.js.map +1 -0
  49. package/dist/{openmeld-ChOHuaqH.js → openmeld-CiL4AiB0.js} +226 -21
  50. package/dist/openmeld-CiL4AiB0.js.map +1 -0
  51. package/dist/openmeld-dev.js +1 -1
  52. package/dist/openmeld-environment-target-NtJYJe1D.js +256 -0
  53. package/dist/openmeld-environment-target-NtJYJe1D.js.map +1 -0
  54. package/dist/{openmeld-maintenance-worker-C7WykyDt.js → openmeld-maintenance-worker-DjdmRASI.js} +9 -8
  55. package/dist/{openmeld-maintenance-worker-C7WykyDt.js.map → openmeld-maintenance-worker-DjdmRASI.js.map} +1 -1
  56. package/dist/{openmeld-tools-update-coordinator-BBZhGo1A.js → openmeld-tools-update-coordinator-D9Skj8IE.js} +52 -4013
  57. package/dist/openmeld-tools-update-coordinator-D9Skj8IE.js.map +1 -0
  58. package/dist/openmeld.js +3 -3
  59. package/dist/{prepare-session-executor-CLmDoHom.js → prepare-session-executor-B0NtjHEL.js} +15 -13
  60. package/dist/{prepare-session-executor-CLmDoHom.js.map → prepare-session-executor-B0NtjHEL.js.map} +1 -1
  61. package/dist/{profiles-BCecj4Pj.js → runtime-transport-QIZmAo4-.js} +936 -2127
  62. package/dist/runtime-transport-QIZmAo4-.js.map +1 -0
  63. package/dist/service-account-authorization-Dt8kGvq8.js +56 -0
  64. package/dist/service-account-authorization-Dt8kGvq8.js.map +1 -0
  65. package/dist/service-control-capabilities-BU5F75zi.js +54 -0
  66. package/dist/service-control-capabilities-BU5F75zi.js.map +1 -0
  67. package/dist/service-control-capabilities-CzUB1ovW.js +4 -0
  68. package/dist/upgrade-DLECkjMt.js +4 -0
  69. package/dist/{upgrade-l_5Tge_z.js → upgrade-NxpTydHp.js} +6 -4
  70. package/dist/upgrade-NxpTydHp.js.map +1 -0
  71. package/package.json +2 -2
  72. package/dist/agents-BOTlKiwS.js.map +0 -1
  73. package/dist/auth-session-BjSqMLTz.js.map +0 -1
  74. package/dist/auth-session-ahQ5VXiF.js +0 -4
  75. package/dist/daemon-runtime-lease-CXlGR-iA.js +0 -87
  76. package/dist/daemon-runtime-lease-CXlGR-iA.js.map +0 -1
  77. package/dist/daemon-service-manager-BVipiZwK.js.map +0 -1
  78. package/dist/daemon-state-BwIoDq7_.js.map +0 -1
  79. package/dist/dist-0boZRalP.js +0 -4
  80. package/dist/dist-CxadJClH.js.map +0 -1
  81. package/dist/lock-CvBnBcFK.js.map +0 -1
  82. package/dist/openmeld-ChOHuaqH.js.map +0 -1
  83. package/dist/openmeld-tools-update-coordinator-BBZhGo1A.js.map +0 -1
  84. package/dist/profiles-BCecj4Pj.js.map +0 -1
  85. package/dist/upgrade-BKEAZKre.js +0 -4
  86. package/dist/upgrade-l_5Tge_z.js.map +0 -1
@@ -1,15 +1,19 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { t as isLoopbackHostname } from "./loopback-hostname-DHQPKq8N.js";
4
- import { S as isProcessIdentityAlive, r as isOpenMeldLockError, t as acquireLock, tt as openMeldRootDir, u as runWithHeldLock, x as CURRENT_PROCESS_START_IDENTITY } from "./lock-CvBnBcFK.js";
5
- import { $r as int, Jr as boolean, Oi as openMeldProfileIdSchema, Qr as enumFactory, Xr as discriminatedUnion, _ as localAgentCatalogSchema, ci as record, d as START_BOUNDED_ID_SCHEMA, ei as iso, f as START_BOUNDED_VERSION_SCHEMA, h as startReplyReadinessSummarySchema, i as authProfileManagedRoleSchema, ii as nullFactory, li as strictObject, mi as unknown, ni as literal, oi as object, p as START_ISO_DATE_TIME_SCHEMA, pi as union, qr as array, r as authProfileKindSchema, ui as string, y as CURRENT_DAEMON_EXECUTION_CONTRACT_EPOCH } from "./profiles-BCecj4Pj.js";
4
+ import { C as isProcessIdentityAlive, S as CURRENT_PROCESS_START_IDENTITY, d as runWithHeldLock, i as isOpenMeldLockError, rt as openMeldRootDir, t as acquireLock, w as readProcessStartIdentity } from "./lock-Dxp6o_t_.js";
5
+ import { Dr as START_BOUNDED_ID_SCHEMA, Gr as openMeldProfileIdSchema, Lr as authProfileKindSchema, Nr as localAgentCatalogSchema, Or as START_BOUNDED_VERSION_SCHEMA, Rr as authProfileManagedRoleSchema, jr as startReplyReadinessSummarySchema, kr as START_ISO_DATE_TIME_SCHEMA, t as CURRENT_DAEMON_EXECUTION_CONTRACT_EPOCH } from "./runtime-transport-QIZmAo4-.js";
6
+ import { $ as literal, G as boolean, W as array, X as int, Y as enumFactory, Z as iso, at as record, dt as unknown, ot as strictObject, q as discriminatedUnion, rt as object, st as string, tt as nullFactory, ut as union } from "./control-plane-D9jDcbMZ.js";
6
7
  import { r as daemonServiceLaneSchema } from "./service-contract-CRyDcIIf.js";
8
+ import { i as serviceAccountAdmissionSchema, t as isBinaryDistribution } from "./distribution-DY2fBeSW.js";
9
+ import { n as writeDaemonLocalStateFile } from "./daemon-local-state-file-jOXuXrky.js";
7
10
  import { createRequire } from "node:module";
8
11
  import { createHash, randomUUID } from "node:crypto";
9
12
  import { join, resolve } from "node:path";
10
13
  import { chmod, link, mkdir, open, readFile, rename, rm, writeFile } from "node:fs/promises";
11
14
  import * as z$1 from "zod/v4";
12
15
  import { spawn } from "node:child_process";
16
+ import { AsyncLocalStorage } from "node:async_hooks";
13
17
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
14
18
  import { fileURLToPath } from "node:url";
15
19
  //#region ../../packages/schemas/dist/schemas/start/device-projection.js
@@ -81,63 +85,6 @@ z$1.strictObject({
81
85
  deviceReplyReadiness: startReplyReadinessSummarySchema
82
86
  });
83
87
  //#endregion
84
- //#region ../../packages/schemas/dist/schemas/local-machine/macos-keychain-helper.js
85
- const MAC_OS_KEYCHAIN_AUTHENTICATION_INTERACTION = "disallow";
86
- const macOsKeychainServiceSchema = z$1.string().trim().min(1).max(512);
87
- const macOsKeychainAccountSchema = z$1.string().trim().min(1).max(512);
88
- const macOsKeychainAccessTokenSchema = z$1.string().min(1).max(65536);
89
- const macOsKeychainHelperOperationSchema = z$1.enum([
90
- "store",
91
- "read",
92
- "delete"
93
- ]);
94
- const macOsKeychainHelperRequestSchema = z$1.discriminatedUnion("operation", [
95
- z$1.strictObject({
96
- schemaVersion: z$1.literal(2),
97
- operation: z$1.literal("store"),
98
- service: macOsKeychainServiceSchema,
99
- account: macOsKeychainAccountSchema,
100
- accessToken: macOsKeychainAccessTokenSchema,
101
- authenticationInteraction: z$1.literal(MAC_OS_KEYCHAIN_AUTHENTICATION_INTERACTION)
102
- }),
103
- z$1.strictObject({
104
- schemaVersion: z$1.literal(2),
105
- operation: z$1.literal("read"),
106
- service: macOsKeychainServiceSchema,
107
- account: macOsKeychainAccountSchema,
108
- authenticationInteraction: z$1.literal(MAC_OS_KEYCHAIN_AUTHENTICATION_INTERACTION)
109
- }),
110
- z$1.strictObject({
111
- schemaVersion: z$1.literal(2),
112
- operation: z$1.literal("delete"),
113
- service: macOsKeychainServiceSchema,
114
- account: macOsKeychainAccountSchema,
115
- authenticationInteraction: z$1.literal(MAC_OS_KEYCHAIN_AUTHENTICATION_INTERACTION)
116
- })
117
- ]);
118
- const macOsKeychainHelperMutationSuccessSchema = z$1.strictObject({
119
- schemaVersion: z$1.literal(2),
120
- ok: z$1.literal(true),
121
- operation: z$1.enum(["store", "delete"])
122
- });
123
- const macOsKeychainHelperReadSuccessSchema = z$1.strictObject({
124
- schemaVersion: z$1.literal(2),
125
- ok: z$1.literal(true),
126
- operation: z$1.literal("read"),
127
- accessToken: z$1.union([macOsKeychainAccessTokenSchema, z$1.null()])
128
- });
129
- const macOsKeychainHelperErrorSchema = z$1.strictObject({
130
- schemaVersion: z$1.literal(2),
131
- ok: z$1.literal(false),
132
- operation: macOsKeychainHelperOperationSchema,
133
- errorMessage: z$1.string().trim().min(1).max(2048)
134
- });
135
- const macOsKeychainHelperResponseSchema = z$1.union([
136
- macOsKeychainHelperMutationSuccessSchema,
137
- macOsKeychainHelperReadSuccessSchema,
138
- macOsKeychainHelperErrorSchema
139
- ]);
140
- //#endregion
141
88
  //#region ../../packages/schemas/dist/schemas/prepare/session.js
142
89
  const PREPARE_BOUNDED_ID_SCHEMA = string().trim().min(1).max(256);
143
90
  const prepareSessionContinuationSchema = strictObject({
@@ -590,7 +537,7 @@ const prepareSessionEventSchema = strictObject({
590
537
  localAgentIds: prepareLocalAgentIdsSchema,
591
538
  createdAt: PREPARE_ISO_DATE_TIME_SCHEMA
592
539
  });
593
- strictObject({
540
+ const createPrepareSessionRequestSchema = strictObject({
594
541
  connectedComputerId: union([PREPARE_BOUNDED_ID_SCHEMA, nullFactory()]).optional(),
595
542
  humanProfileId: union([openMeldProfileIdSchema, nullFactory()]).optional(),
596
543
  deviceId: union([PREPARE_BOUNDED_ID_SCHEMA, nullFactory()]).optional(),
@@ -706,6 +653,63 @@ const prepareSessionStreamServerFrameSchema = discriminatedUnion("type", [
706
653
  })
707
654
  ]);
708
655
  //#endregion
656
+ //#region ../../packages/schemas/dist/schemas/local-machine/macos-keychain-helper.js
657
+ const MAC_OS_KEYCHAIN_AUTHENTICATION_INTERACTION = "disallow";
658
+ const macOsKeychainServiceSchema = z$1.string().trim().min(1).max(512);
659
+ const macOsKeychainAccountSchema = z$1.string().trim().min(1).max(512);
660
+ const macOsKeychainAccessTokenSchema = z$1.string().min(1).max(65536);
661
+ const macOsKeychainHelperOperationSchema = z$1.enum([
662
+ "store",
663
+ "read",
664
+ "delete"
665
+ ]);
666
+ const macOsKeychainHelperRequestSchema = z$1.discriminatedUnion("operation", [
667
+ z$1.strictObject({
668
+ schemaVersion: z$1.literal(2),
669
+ operation: z$1.literal("store"),
670
+ service: macOsKeychainServiceSchema,
671
+ account: macOsKeychainAccountSchema,
672
+ accessToken: macOsKeychainAccessTokenSchema,
673
+ authenticationInteraction: z$1.literal(MAC_OS_KEYCHAIN_AUTHENTICATION_INTERACTION)
674
+ }),
675
+ z$1.strictObject({
676
+ schemaVersion: z$1.literal(2),
677
+ operation: z$1.literal("read"),
678
+ service: macOsKeychainServiceSchema,
679
+ account: macOsKeychainAccountSchema,
680
+ authenticationInteraction: z$1.literal(MAC_OS_KEYCHAIN_AUTHENTICATION_INTERACTION)
681
+ }),
682
+ z$1.strictObject({
683
+ schemaVersion: z$1.literal(2),
684
+ operation: z$1.literal("delete"),
685
+ service: macOsKeychainServiceSchema,
686
+ account: macOsKeychainAccountSchema,
687
+ authenticationInteraction: z$1.literal(MAC_OS_KEYCHAIN_AUTHENTICATION_INTERACTION)
688
+ })
689
+ ]);
690
+ const macOsKeychainHelperMutationSuccessSchema = z$1.strictObject({
691
+ schemaVersion: z$1.literal(2),
692
+ ok: z$1.literal(true),
693
+ operation: z$1.enum(["store", "delete"])
694
+ });
695
+ const macOsKeychainHelperReadSuccessSchema = z$1.strictObject({
696
+ schemaVersion: z$1.literal(2),
697
+ ok: z$1.literal(true),
698
+ operation: z$1.literal("read"),
699
+ accessToken: z$1.union([macOsKeychainAccessTokenSchema, z$1.null()])
700
+ });
701
+ const macOsKeychainHelperErrorSchema = z$1.strictObject({
702
+ schemaVersion: z$1.literal(2),
703
+ ok: z$1.literal(false),
704
+ operation: macOsKeychainHelperOperationSchema,
705
+ errorMessage: z$1.string().trim().min(1).max(2048)
706
+ });
707
+ const macOsKeychainHelperResponseSchema = z$1.union([
708
+ macOsKeychainHelperMutationSuccessSchema,
709
+ macOsKeychainHelperReadSuccessSchema,
710
+ macOsKeychainHelperErrorSchema
711
+ ]);
712
+ //#endregion
709
713
  //#region src/strategy-constants.ts
710
714
  const DEFAULT_GATEWAY_CHAIN_TIMEOUT_MS = 3e4;
711
715
  const DEFAULT_REMOTE_SESSION_TIMEOUT_MS = 8e3;
@@ -791,19 +795,111 @@ async function acquireAuthSessionLock(input) {
791
795
  }
792
796
  }
793
797
  //#endregion
794
- //#region src/runtime/distribution.ts
795
- const BINARY_DISTRIBUTION = "binary";
796
- const NPM_DISTRIBUTION = "npm";
797
- /**
798
- * The distribution form this CLI build was compiled for. Falls back to `npm`
799
- * when the marker is absent (e.g. under Vitest, where no build-time define
800
- * runs), which keeps the safe, path-independent default.
801
- */
802
- function resolveOpenMeldDistribution() {
803
- return NPM_DISTRIBUTION;
804
- }
805
- function isBinaryDistribution() {
806
- return resolveOpenMeldDistribution() === BINARY_DISTRIBUTION;
798
+ //#region src/config/service-account-admission.ts
799
+ var ServiceAccountAdmissionError = class extends Error {
800
+ code;
801
+ constructor(reason, message) {
802
+ super(message);
803
+ this.name = "ServiceAccountAdmissionError";
804
+ this.code = `service.account_admission.${reason}`;
805
+ }
806
+ };
807
+ function admissionPath() {
808
+ return join(openMeldRootDir(), "auth", "service-account-admission.json");
809
+ }
810
+ async function readServiceAccountAdmission() {
811
+ let raw;
812
+ try {
813
+ raw = await readFile(admissionPath(), "utf8");
814
+ } catch (error) {
815
+ if (error.code === "ENOENT") return null;
816
+ throw error;
817
+ }
818
+ let value;
819
+ try {
820
+ value = JSON.parse(raw);
821
+ } catch {
822
+ value = null;
823
+ }
824
+ const parsed = serviceAccountAdmissionSchema.safeParse(value);
825
+ if (!parsed.success) throw new ServiceAccountAdmissionError("unknown", "OpenMeld could not verify the pending Service action. Run `openmeld service status --json` for diagnostics.");
826
+ return parsed.data;
827
+ }
828
+ async function writeAdmission(value) {
829
+ await writeDaemonLocalStateFile({
830
+ path: admissionPath(),
831
+ schema: serviceAccountAdmissionSchema,
832
+ value,
833
+ mode: 384
834
+ });
835
+ }
836
+ async function assertServiceAccountAdmissionMutationAvailable() {
837
+ const current = await readServiceAccountAdmission();
838
+ if (current?.state !== "pending") return;
839
+ if (isProcessIdentityAlive(current.requester)) throw new ServiceAccountAdmissionError("busy", "OpenMeld is starting or stopping this Service. Try the account change again when that action is accepted.");
840
+ await writeAdmission({
841
+ ...current,
842
+ state: "cancelled"
843
+ });
844
+ }
845
+ async function reserveServiceAccountAdmission(input) {
846
+ await assertServiceAccountAdmissionMutationAvailable();
847
+ const previous = await readServiceAccountAdmission();
848
+ if (!CURRENT_PROCESS_START_IDENTITY.startsWith("ps:")) throw new ServiceAccountAdmissionError("unknown", "OpenMeld could not verify this command's process identity. Try again from a supported local CLI.");
849
+ const reservation = {
850
+ version: 1,
851
+ id: randomUUID(),
852
+ operation: input.operation,
853
+ state: "pending",
854
+ identity: input.identity,
855
+ ...input.target ? { target: input.target } : {},
856
+ requester: {
857
+ ownerPid: process.pid,
858
+ ownerProcessStartedAt: CURRENT_PROCESS_START_IDENTITY
859
+ },
860
+ ...previous?.startupReceipt ? { startupReceipt: previous.startupReceipt } : {}
861
+ };
862
+ await writeAdmission(reservation);
863
+ return reservation;
864
+ }
865
+ async function cancelServiceAccountAdmission(id) {
866
+ await withAuthSessionTransitionMutationLock(async () => {
867
+ const current = await readServiceAccountAdmission();
868
+ if (current?.id === id && current.state === "pending") await writeAdmission({
869
+ ...current,
870
+ state: "cancelled"
871
+ });
872
+ });
873
+ }
874
+ async function admitServiceAccountOperation(input) {
875
+ const current = await readServiceAccountAdmission();
876
+ const contractBinding = bindServiceAccountIdentity(input.identity);
877
+ if (input.operation === "start" && current?.startupReceipt?.id === input.id && current.startupReceipt.contractBinding === contractBinding) return;
878
+ if (!current || current.id !== input.id || current.operation !== input.operation || current.state !== "pending" || readProcessStartIdentity(current.requester.ownerPid) !== current.requester.ownerProcessStartedAt || current.target !== void 0 && (current.target.ownerPid !== process.pid || current.target.ownerProcessStartedAt !== CURRENT_PROCESS_START_IDENTITY) || JSON.stringify(current.identity) !== JSON.stringify(input.identity)) throw new ServiceAccountAdmissionError("cancelled", "This Service action is no longer authorized. Check the signed-in account and try again.");
879
+ input.commit?.();
880
+ await writeAdmission({
881
+ ...current,
882
+ state: "admitted",
883
+ carrier: {
884
+ ownerPid: process.pid,
885
+ ownerProcessStartedAt: CURRENT_PROCESS_START_IDENTITY
886
+ },
887
+ ...input.operation === "start" ? { startupReceipt: {
888
+ id: input.id,
889
+ contractBinding
890
+ } } : {}
891
+ });
892
+ }
893
+ function bindServiceAccountIdentity(identity) {
894
+ return createHash("sha256").update(JSON.stringify([
895
+ identity.accountId,
896
+ identity.authBaseUrl,
897
+ identity.clientId,
898
+ identity.gatewayUrl,
899
+ identity.lane,
900
+ identity.deviceId,
901
+ identity.contractGeneration
902
+ ])).digest("hex");
807
903
  }
808
904
  //#endregion
809
905
  //#region src/config/macos-native-keychain.ts
@@ -1464,6 +1560,17 @@ function onAuthSessionCredentialAvailable(notify) {
1464
1560
  };
1465
1561
  }
1466
1562
  const activeAuthSessionTransitionIds = /* @__PURE__ */ new Set();
1563
+ const admittedServiceSession = new AsyncLocalStorage();
1564
+ const boundSessionPayloadKeys = /* @__PURE__ */ new WeakMap();
1565
+ function withAdmittedServiceSession(session, run) {
1566
+ return admittedServiceSession.run(structuredClone(session), run);
1567
+ }
1568
+ async function readServiceAdmissionSessionWithOwnership() {
1569
+ if (await readAuthSessionTransitionJournal()) throw new AuthSessionRecoveryInProgressError();
1570
+ const state = await getLocalAuthSessionState({ recover: false });
1571
+ if (state.state !== "valid" || !state.session?.user?.id) throw new Error("Service control requires a valid CLI sign-in. Sign in with the matching account and try again.");
1572
+ return state.session;
1573
+ }
1467
1574
  const credentialObservationListeners = /* @__PURE__ */ new Set();
1468
1575
  function onAuthSessionCredentialObservation(notify) {
1469
1576
  const listener = {
@@ -1482,6 +1589,8 @@ function observeCredential(reason) {
1482
1589
  } catch {}
1483
1590
  }
1484
1591
  async function getAuthSessionState(options = {}) {
1592
+ const bound = admittedServiceSession.getStore();
1593
+ if (bound) return await getBoundServiceSessionState(bound, options);
1485
1594
  const result = await getAuthSessionStateWithCandidateRefreshFence(options, false);
1486
1595
  if (result.reasonCode === "session_metadata_invalid") observeCredential("metadata_unavailable");
1487
1596
  return {
@@ -1492,6 +1601,71 @@ async function getAuthSessionState(options = {}) {
1492
1601
  ...result.retryAfterMs !== void 0 ? { retryAfterMs: result.retryAfterMs } : {}
1493
1602
  };
1494
1603
  }
1604
+ async function syncBoundServiceCredentials(bound) {
1605
+ const local = await getLocalAuthSessionState({ recover: false });
1606
+ const samePrincipal = isSameAuthPrincipal(local.session, bound);
1607
+ const localPayloadKey = samePrincipal && "payloadKey" in local ? local.payloadKey : null;
1608
+ if (samePrincipal && local.session && boundSessionPayloadKeys.get(bound) !== localPayloadKey) {
1609
+ Object.assign(bound, local.session, { activeOrganization: local.session.activeOrganization });
1610
+ boundSessionPayloadKeys.set(bound, localPayloadKey);
1611
+ }
1612
+ if (samePrincipal && local.session && bound.expiresAt && (bound.accessToken !== local.session.accessToken || bound.expiresAt !== local.session.expiresAt)) await persistBoundServiceRefresh(bound, {
1613
+ state: "valid",
1614
+ accessToken: bound.accessToken,
1615
+ expiresAt: bound.expiresAt
1616
+ }, localPayloadKey, local.session.accessToken);
1617
+ return samePrincipal ? boundSessionPayloadKeys.get(bound) ?? null : null;
1618
+ }
1619
+ async function getBoundServiceSessionState(bound, options) {
1620
+ const localPayloadKey = await syncBoundServiceCredentials(bound);
1621
+ if (options.validateRemote || options.refreshExpired && isExpired(bound.expiresAt)) {
1622
+ const remote = await getRemoteAuthSessionState(bound);
1623
+ if (remote.state === "revoked" || remote.state === "invalid") return {
1624
+ state: remote.state,
1625
+ session: null,
1626
+ reasonCode: resolveRemoteAuthSessionReasonCode(remote.state)
1627
+ };
1628
+ if (remote.state === "valid") {
1629
+ await persistBoundServiceRefresh(bound, remote, localPayloadKey);
1630
+ if (remote.accessToken) bound.accessToken = remote.accessToken;
1631
+ if (remote.expiresAt) bound.expiresAt = remote.expiresAt;
1632
+ }
1633
+ }
1634
+ const expiry = resolveAuthSessionExpiryEligibility(bound.expiresAt);
1635
+ if (expiry.status === "expired") return {
1636
+ session: bound,
1637
+ state: "expired",
1638
+ reasonCode: "session_expired"
1639
+ };
1640
+ if (expiry.status === "invalid") return {
1641
+ session: null,
1642
+ state: "invalid",
1643
+ reasonCode: "session_expiry_invalid"
1644
+ };
1645
+ return {
1646
+ session: bound,
1647
+ state: "valid"
1648
+ };
1649
+ }
1650
+ async function persistBoundServiceRefresh(bound, remote, localPayloadKey, previousAccessToken = bound.accessToken) {
1651
+ if (!(localPayloadKey && remote.expiresAt) || isExpired(remote.expiresAt)) return;
1652
+ try {
1653
+ if (await persistRemoteSessionRefresh({
1654
+ accessToken: remote.accessToken ?? bound.accessToken,
1655
+ previousAccessToken,
1656
+ expectedPayloadKey: localPayloadKey,
1657
+ expiresAt: remote.expiresAt
1658
+ })) {
1659
+ const current = await getLocalAuthSessionState({ recover: false });
1660
+ boundSessionPayloadKeys.set(bound, isSameAuthPrincipal(current.session, bound) && "payloadKey" in current ? current.payloadKey : null);
1661
+ }
1662
+ } catch (error) {
1663
+ if (!(error instanceof ServiceAccountAdmissionError && error.code === "service.account_admission.busy")) throw error;
1664
+ }
1665
+ }
1666
+ function isSameAuthPrincipal(current, expected) {
1667
+ return Boolean(expected.user?.id && current?.user?.id === expected.user.id && current.authBaseUrl === expected.authBaseUrl && current.clientId === expected.clientId);
1668
+ }
1495
1669
  async function getAuthSessionStateWithCandidateRefreshFence(options, candidateRefreshFenceHeld) {
1496
1670
  const localState = await getLocalAuthSessionState();
1497
1671
  const localPayloadKey = "payloadKey" in localState ? localState.payloadKey : null;
@@ -2011,6 +2185,11 @@ async function completeInterruptedComputerAuthSessionRecovery(id) {
2011
2185
  });
2012
2186
  }
2013
2187
  async function getAuthSessionMetadata() {
2188
+ const bound = admittedServiceSession.getStore();
2189
+ if (bound) {
2190
+ await getBoundServiceSessionState(bound, {});
2191
+ return buildAuthSessionMetadata(bound);
2192
+ }
2014
2193
  return buildAuthSessionMetadata(await readSessionPayload());
2015
2194
  }
2016
2195
  function buildAuthSessionMetadata(payload) {
@@ -2090,6 +2269,12 @@ async function assertAuthSessionMutationAvailable() {
2090
2269
  await withAuthSessionTransitionMutationLock(assertAuthSessionMutationAvailableWithOwnership);
2091
2270
  }
2092
2271
  async function assertAuthSessionMutationAvailableWithOwnership() {
2272
+ await assertServiceAccountAdmissionMutationAvailable();
2273
+ const bound = admittedServiceSession.getStore();
2274
+ if (bound) {
2275
+ const current = await readSessionPayloadFile();
2276
+ if (current?.user?.id !== bound.user?.id || current?.authBaseUrl !== bound.authBaseUrl || current?.clientId !== bound.clientId) throw new AuthSessionChangedBeforeTransitionError();
2277
+ }
2093
2278
  await recoverInterruptedAuthSessionTransitionWithOwnership();
2094
2279
  if (await readAuthSessionTransitionJournal()) throw new AuthSessionRecoveryInProgressError();
2095
2280
  }
@@ -2405,6 +2590,11 @@ async function cleanupCandidateTokenRefs(journal, keepTokenRef) {
2405
2590
  }
2406
2591
  async function persistRemoteSessionRefresh(input) {
2407
2592
  return await withAuthSessionTransitionMutationLock(async () => {
2593
+ const bound = admittedServiceSession.getStore();
2594
+ if (bound) {
2595
+ if (!isSameAuthPrincipal((await getLocalAuthSessionState({ recover: false })).session, bound)) return null;
2596
+ }
2597
+ await assertServiceAccountAdmissionMutationAvailable();
2408
2598
  await recoverInterruptedAuthSessionTransitionWithOwnership();
2409
2599
  const transitionJournal = await readAuthSessionTransitionJournal();
2410
2600
  if (transitionJournal) {
@@ -2632,6 +2822,7 @@ async function recoverInterruptedAuthSessionTransition() {
2632
2822
  async function recoverInterruptedAuthSessionTransitionWithOwnership() {
2633
2823
  let journal = await readAuthSessionTransitionJournal();
2634
2824
  if (!journal) return;
2825
+ await assertServiceAccountAdmissionMutationAvailable();
2635
2826
  if (activeAuthSessionTransitionIds.has(journal.id)) return;
2636
2827
  if (journal.state === "pending" && isProcessIdentityAlive({
2637
2828
  ownerPid: journal.ownerPid,
@@ -3004,6 +3195,6 @@ async function removeSessionFile() {
3004
3195
  await rm(authSessionPath(), { force: true });
3005
3196
  }
3006
3197
  //#endregion
3007
- export { redactPrepareStepDiagnosticsBundle as $, DAEMON_STREAM_KEEPALIVE_PONG_TIMEOUT_MS as A, PROVIDER_CONVERSATION_PROOF_SYNC_INTERVAL_MS as B, resolveOpenMeldDistribution as C, DAEMON_RUNTIME_CONTRACT_EPOCH as D, CATALOG_SYNC_SIGNAL_POLL_INTERVAL_MS as E, MAX_HEARTBEAT_INTERVAL_MS as F, RUNTIME_AGENT_CONTROLLER_REPORT_SYNC_RETRY_INTERVAL_MS as G, REGISTER_RESPONSE_TIMEOUT_MS as H, MAX_SPACE_REQUEST_TIMEOUT_MS as I, prepareSessionResponseSchema as J, RUNTIME_STATE_PERSIST_MIN_INTERVAL_MS as K, MIN_HEARTBEAT_INTERVAL_MS as L, DEFAULT_HEARTBEAT_INTERVAL_MS as M, DEFAULT_SPACE_REQUEST_TIMEOUT_MS as N, DAEMON_STREAM_CONNECT_TIMEOUT_MS as O, HEARTBEAT_RESPONSE_TIMEOUT_MS as P, prepareStepDiagnosticsBundleSchema as Q, MIN_SPACE_REQUEST_TIMEOUT_MS as R, isBinaryDistribution as S, CATALOG_SYNC_RETRY_INTERVAL_MS as T, ROUTE_CATALOG_LOAD_TIMEOUT_MS as U, PROVIDER_CONVERSATION_PROOF_SYNC_RETRY_INTERVAL_MS as V, RUNTIME_AGENT_CONTROLLER_REPORT_SYNC_INTERVAL_MS as W, prepareSessionWithTokenResponseSchema as X, prepareSessionStreamServerFrameSchema as Y, prepareSetupBootstrapWriteSchema as Z, recordInterruptedComputerAuthSessionRecoveryFailure as _, beginAuthSessionTransition as a, updateAuthSessionActiveOrganization as b, getAuthSessionMetadata as c, getInterruptedComputerAuthSessionRecovery as d, redactPrepareStepDiagnosticsText as et, hasPendingComputerSetupContinuation as f, onAuthSessionCredentialObservation as g, onAuthSessionCredentialAvailable as h, assertAuthSessionMutationAvailable as i, DEFAULT_GATEWAY_CHAIN_TIMEOUT_MS as j, DAEMON_STREAM_KEEPALIVE_INTERVAL_MS as k, getAuthSessionState as l, normalizeStoredActiveOrganization as m, AuthSessionRecoveryInProgressError as n, clearAuthSession as o, markInterruptedComputerAuthSessionRecovery as p, PREPARE_STEP_DIAGNOSTICS_MAX_CHARS as q, AuthSessionTransitionConflictError as r, completeInterruptedComputerAuthSessionRecovery as s, AuthSessionChangedBeforeTransitionError as t, redactPrepareStepDiagnosticsValue as tt, getCurrentAuthOwnerUserId as u, resumeInterruptedComputerSetup as v, resolveAuthSessionExpiryEligibility as w, runMacOsNativeKeychainHelperIfRequested as x, setAuthSession as y, OPENCLAW_CLI_TIMEOUT_MS as z };
3198
+ export { RUNTIME_STATE_PERSIST_MIN_INTERVAL_MS as $, withAuthSessionTransitionMutationLock as A, DEFAULT_SPACE_REQUEST_TIMEOUT_MS as B, withAdmittedServiceSession as C, cancelServiceAccountAdmission as D, admitServiceAccountOperation as E, DAEMON_STREAM_CONNECT_TIMEOUT_MS as F, MIN_SPACE_REQUEST_TIMEOUT_MS as G, MAX_HEARTBEAT_INTERVAL_MS as H, DAEMON_STREAM_KEEPALIVE_INTERVAL_MS as I, PROVIDER_CONVERSATION_PROOF_SYNC_RETRY_INTERVAL_MS as J, OPENCLAW_CLI_TIMEOUT_MS as K, DAEMON_STREAM_KEEPALIVE_PONG_TIMEOUT_MS as L, CATALOG_SYNC_RETRY_INTERVAL_MS as M, CATALOG_SYNC_SIGNAL_POLL_INTERVAL_MS as N, readServiceAccountAdmission as O, DAEMON_RUNTIME_CONTRACT_EPOCH as P, RUNTIME_AGENT_CONTROLLER_REPORT_SYNC_RETRY_INTERVAL_MS as Q, DEFAULT_GATEWAY_CHAIN_TIMEOUT_MS as R, updateAuthSessionActiveOrganization as S, ServiceAccountAdmissionError as T, MAX_SPACE_REQUEST_TIMEOUT_MS as U, HEARTBEAT_RESPONSE_TIMEOUT_MS as V, MIN_HEARTBEAT_INTERVAL_MS as W, ROUTE_CATALOG_LOAD_TIMEOUT_MS as X, REGISTER_RESPONSE_TIMEOUT_MS as Y, RUNTIME_AGENT_CONTROLLER_REPORT_SYNC_INTERVAL_MS as Z, onAuthSessionCredentialObservation as _, beginAuthSessionTransition as a, prepareSessionWithTokenResponseSchema as at, resumeInterruptedComputerSetup as b, completeInterruptedComputerAuthSessionRecovery as c, redactPrepareStepDiagnosticsBundle as ct, getCurrentAuthOwnerUserId as d, PREPARE_STEP_DIAGNOSTICS_MAX_CHARS as et, getInterruptedComputerAuthSessionRecovery as f, onAuthSessionCredentialAvailable as g, normalizeStoredActiveOrganization as h, assertAuthSessionMutationAvailable as i, prepareSessionStreamServerFrameSchema as it, resolveAuthSessionExpiryEligibility as j, reserveServiceAccountAdmission as k, getAuthSessionMetadata as l, redactPrepareStepDiagnosticsText as lt, markInterruptedComputerAuthSessionRecovery as m, AuthSessionRecoveryInProgressError as n, prepareSessionResponseSchema as nt, buildStoredAuthSessionIdentity as o, prepareSetupBootstrapWriteSchema as ot, hasPendingComputerSetupContinuation as p, PROVIDER_CONVERSATION_PROOF_SYNC_INTERVAL_MS as q, AuthSessionTransitionConflictError as r, prepareSessionSnapshotSchema as rt, clearAuthSession as s, prepareStepDiagnosticsBundleSchema as st, AuthSessionChangedBeforeTransitionError as t, createPrepareSessionRequestSchema as tt, getAuthSessionState as u, redactPrepareStepDiagnosticsValue as ut, readServiceAdmissionSessionWithOwnership as v, runMacOsNativeKeychainHelperIfRequested as w, setAuthSession as x, recordInterruptedComputerAuthSessionRecoveryFailure as y, DEFAULT_HEARTBEAT_INTERVAL_MS as z };
3008
3199
 
3009
- //# sourceMappingURL=auth-session-BjSqMLTz.js.map
3200
+ //# sourceMappingURL=auth-session-CO5XtFaq.js.map