@indigoai-us/hq-cli 5.345.214 → 5.345.215

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 (200) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/assets/scaffold/core/scripts/hq-delegate-verify.sh +5 -2
  3. package/dist/command-catalog.generated.d.ts +180 -13
  4. package/dist/command-catalog.generated.js +221 -13
  5. package/dist/commands/agents.d.ts +51 -1
  6. package/dist/commands/agents.js +154 -2
  7. package/dist/commands/bot-jobs.d.ts +2 -15
  8. package/dist/commands/bot-jobs.js +2 -94
  9. package/dist/commands/bot-runtime.d.ts +46 -5
  10. package/dist/commands/bot-runtime.js +228 -18
  11. package/dist/commands/bot.d.ts +16 -9
  12. package/dist/commands/bot.js +231 -55
  13. package/dist/commands/capacity.d.ts +4 -1
  14. package/dist/commands/capacity.js +46 -10
  15. package/dist/commands/cloud.d.ts +66 -13
  16. package/dist/commands/cloud.js +121 -40
  17. package/dist/commands/company-restore.d.ts +23 -0
  18. package/dist/commands/company-restore.js +128 -0
  19. package/dist/commands/company.js +2 -0
  20. package/dist/commands/core-delegate-w1b.js +15 -1
  21. package/dist/commands/core-policy.js +67 -8
  22. package/dist/commands/daemon.js +5 -0
  23. package/dist/commands/files-browse.d.ts +11 -4
  24. package/dist/commands/files-browse.js +21 -4
  25. package/dist/commands/files.d.ts +1 -1
  26. package/dist/commands/files.js +25 -11
  27. package/dist/commands/integrations-auth-rules.d.ts +27 -0
  28. package/dist/commands/integrations-auth-rules.js +79 -0
  29. package/dist/commands/integrations-connect.d.ts +10 -3
  30. package/dist/commands/integrations-connect.js +87 -13
  31. package/dist/commands/integrations-import.js +124 -12
  32. package/dist/commands/lanes.js +28 -11
  33. package/dist/commands/mesh.d.ts +2 -0
  34. package/dist/commands/mesh.js +60 -35
  35. package/dist/commands/sources.js +6 -0
  36. package/dist/commands/storage-offload.d.ts +12 -0
  37. package/dist/commands/storage-offload.js +41 -3
  38. package/dist/commands/sync-held.js +5 -2
  39. package/dist/commands/sync-mode.js +5 -0
  40. package/dist/commands/whoami.js +4 -0
  41. package/dist/lazy-commands.js +3 -5
  42. package/dist/lib/bot/config.d.ts +1 -0
  43. package/dist/lib/bot/config.js +10 -0
  44. package/dist/lib/bot/eventbridge-cron.d.ts +22 -0
  45. package/dist/lib/bot/eventbridge-cron.js +104 -0
  46. package/dist/lib/bot/fleet-cron.d.ts +8 -0
  47. package/dist/lib/bot/fleet-cron.js +35 -3
  48. package/dist/lib/bot/fleet-daemon.d.ts +46 -0
  49. package/dist/lib/bot/fleet-daemon.js +99 -1
  50. package/dist/lib/bot/fleet-local.d.ts +33 -1
  51. package/dist/lib/bot/fleet-local.js +215 -31
  52. package/dist/lib/bot/fleet-python.d.ts +3 -0
  53. package/dist/lib/bot/fleet-python.js +34 -4
  54. package/dist/lib/bot/fleet-runtime-sources.d.ts +15 -0
  55. package/dist/lib/bot/fleet-runtime-sources.js +30 -0
  56. package/dist/lib/bot/legacy-provider-login.d.ts +8 -0
  57. package/dist/lib/bot/legacy-provider-login.js +19 -2
  58. package/dist/lib/bot/probe.js +7 -1
  59. package/dist/lib/bot/prompt.js +1 -1
  60. package/dist/lib/bot/readiness.d.ts +8 -0
  61. package/dist/lib/bot/readiness.js +17 -3
  62. package/dist/lib/bot/run.js +20 -1
  63. package/dist/lib/bot/runtime/codex.js +1 -1
  64. package/dist/lib/bot/runtime/grok-acp.d.ts +5 -1
  65. package/dist/lib/bot/runtime/grok-acp.js +6 -3
  66. package/dist/lib/bot/runtime/index.js +19 -9
  67. package/dist/lib/bot/runtime/messages-stream.js +2 -2
  68. package/dist/lib/bot/runtime/types.d.ts +15 -0
  69. package/dist/lib/bot/runtime/types.js +9 -0
  70. package/dist/lib/bot/runtime-auth.d.ts +30 -0
  71. package/dist/lib/bot/runtime-auth.js +94 -3
  72. package/dist/lib/bot/runtime-failure.d.ts +23 -0
  73. package/dist/lib/bot/runtime-failure.js +43 -1
  74. package/dist/lib/bot/status.d.ts +2 -0
  75. package/dist/lib/capacity/accounts.d.ts +8 -0
  76. package/dist/lib/capacity/accounts.js +19 -0
  77. package/dist/lib/capacity/available.d.ts +154 -0
  78. package/dist/lib/capacity/available.js +905 -0
  79. package/dist/lib/capacity/codex-availability.d.ts +14 -1
  80. package/dist/lib/capacity/codex-availability.js +26 -1
  81. package/dist/lib/capacity/collectors/claude-oauth.d.ts +29 -2
  82. package/dist/lib/capacity/collectors/claude-oauth.js +104 -7
  83. package/dist/lib/capacity/collectors/codex.js +10 -7
  84. package/dist/lib/capacity/collectors/grok-refresh.d.ts +80 -0
  85. package/dist/lib/capacity/collectors/grok-refresh.js +189 -0
  86. package/dist/lib/capacity/collectors/grok.d.ts +5 -0
  87. package/dist/lib/capacity/collectors/grok.js +56 -5
  88. package/dist/lib/capacity/ledger.d.ts +37 -1
  89. package/dist/lib/capacity/ledger.js +207 -30
  90. package/dist/lib/capacity/project.d.ts +26 -0
  91. package/dist/lib/capacity/project.js +137 -8
  92. package/dist/lib/capacity/refusal-rows.d.ts +31 -0
  93. package/dist/lib/capacity/refusal-rows.js +61 -0
  94. package/dist/lib/capacity/refusal.d.ts +53 -2
  95. package/dist/lib/capacity/refusal.js +284 -65
  96. package/dist/lib/capacity/route.js +46 -11
  97. package/dist/lib/capacity/widget.d.ts +12 -1
  98. package/dist/lib/capacity/widget.js +91 -3
  99. package/dist/lib/daemon/catalog.js +11 -1
  100. package/dist/lib/daemon/resolver.d.ts +2 -0
  101. package/dist/lib/daemon/resolver.js +3 -0
  102. package/dist/lib/daemon/run.d.ts +9 -0
  103. package/dist/lib/daemon/run.js +54 -1
  104. package/dist/lib/daemon/server.d.ts +2 -0
  105. package/dist/lib/daemon/server.js +10 -1
  106. package/dist/lib/daemon/tcc-eperm.d.ts +153 -0
  107. package/dist/lib/daemon/tcc-eperm.js +310 -0
  108. package/dist/lib/db/sqlite-binding.d.ts +1 -0
  109. package/dist/lib/db/sqlite-binding.js +1 -1
  110. package/dist/lib/delivery/admission.d.ts +86 -0
  111. package/dist/lib/delivery/admission.js +148 -0
  112. package/dist/lib/delivery/artifacts.d.ts +105 -0
  113. package/dist/lib/delivery/artifacts.js +567 -0
  114. package/dist/lib/delivery/attempt-id.d.ts +13 -0
  115. package/dist/lib/delivery/attempt-id.js +16 -0
  116. package/dist/lib/delivery/backup.d.ts +78 -0
  117. package/dist/lib/delivery/backup.js +343 -0
  118. package/dist/lib/delivery/cache.d.ts +29 -0
  119. package/dist/lib/delivery/cache.js +33 -0
  120. package/dist/lib/delivery/contracts.d.ts +142 -0
  121. package/dist/lib/delivery/contracts.js +289 -0
  122. package/dist/lib/delivery/credentials.d.ts +54 -0
  123. package/dist/lib/delivery/credentials.js +119 -0
  124. package/dist/lib/delivery/disposable-target.d.ts +42 -0
  125. package/dist/lib/delivery/disposable-target.js +111 -0
  126. package/dist/lib/delivery/effects.d.ts +136 -0
  127. package/dist/lib/delivery/effects.js +541 -0
  128. package/dist/lib/delivery/enrollment.d.ts +146 -0
  129. package/dist/lib/delivery/enrollment.js +460 -0
  130. package/dist/lib/delivery/escalations.d.ts +51 -0
  131. package/dist/lib/delivery/escalations.js +60 -0
  132. package/dist/lib/delivery/identity.d.ts +25 -0
  133. package/dist/lib/delivery/identity.js +82 -0
  134. package/dist/lib/delivery/inbox.d.ts +116 -0
  135. package/dist/lib/delivery/inbox.js +260 -0
  136. package/dist/lib/delivery/lease.d.ts +80 -0
  137. package/dist/lib/delivery/lease.js +134 -0
  138. package/dist/lib/delivery/migrations.d.ts +255 -0
  139. package/dist/lib/delivery/migrations.js +823 -0
  140. package/dist/lib/delivery/mqtt-adapter.d.ts +50 -0
  141. package/dist/lib/delivery/mqtt-adapter.js +242 -0
  142. package/dist/lib/delivery/mqtt.d.ts +63 -0
  143. package/dist/lib/delivery/mqtt.js +119 -0
  144. package/dist/lib/delivery/outbox.d.ts +95 -0
  145. package/dist/lib/delivery/outbox.js +187 -0
  146. package/dist/lib/delivery/provenance.d.ts +129 -0
  147. package/dist/lib/delivery/provenance.js +93 -0
  148. package/dist/lib/delivery/reconciler.d.ts +215 -0
  149. package/dist/lib/delivery/reconciler.js +703 -0
  150. package/dist/lib/delivery/restore.d.ts +35 -0
  151. package/dist/lib/delivery/restore.js +134 -0
  152. package/dist/lib/delivery/rpc/client.d.ts +22 -0
  153. package/dist/lib/delivery/rpc/client.js +159 -0
  154. package/dist/lib/delivery/rpc/port.d.ts +40 -0
  155. package/dist/lib/delivery/rpc/port.js +16 -0
  156. package/dist/lib/delivery/rpc/server.d.ts +30 -0
  157. package/dist/lib/delivery/rpc/server.js +205 -0
  158. package/dist/lib/delivery/rpc/wire.d.ts +85 -0
  159. package/dist/lib/delivery/rpc/wire.js +143 -0
  160. package/dist/lib/delivery/store.d.ts +163 -0
  161. package/dist/lib/delivery/store.js +944 -0
  162. package/dist/lib/delivery/windows-service-install.d.ts +262 -0
  163. package/dist/lib/delivery/windows-service-install.js +892 -0
  164. package/dist/lib/delivery/workers/macos-job-helper.d.ts +103 -0
  165. package/dist/lib/delivery/workers/macos-job-helper.js +927 -0
  166. package/dist/lib/delivery/workers/macos.d.ts +191 -0
  167. package/dist/lib/delivery/workers/macos.js +943 -0
  168. package/dist/lib/delivery/workers/windows-job-helper.d.ts +35 -0
  169. package/dist/lib/delivery/workers/windows-job-helper.js +264 -0
  170. package/dist/lib/delivery/workers/windows-service-live.d.ts +121 -0
  171. package/dist/lib/delivery/workers/windows-service-live.js +711 -0
  172. package/dist/lib/delivery/workers/windows-service-runner.d.ts +33 -0
  173. package/dist/lib/delivery/workers/windows-service-runner.js +82 -0
  174. package/dist/lib/delivery/workers/windows-service.d.ts +140 -0
  175. package/dist/lib/delivery/workers/windows-service.js +584 -0
  176. package/dist/lib/delivery/workers/windows.d.ts +251 -0
  177. package/dist/lib/delivery/workers/windows.js +594 -0
  178. package/dist/lib/hot-channels/adapters/meetings.d.ts +15 -0
  179. package/dist/lib/hot-channels/adapters/meetings.js +36 -3
  180. package/dist/lib/hot-channels/signals-pass.d.ts +10 -0
  181. package/dist/lib/hot-channels/signals-pass.js +71 -2
  182. package/dist/lib/hot-channels/signals-redo.js +10 -2
  183. package/dist/lib/install/provider-wrappers.d.ts +2 -0
  184. package/dist/lib/install/provider-wrappers.js +68 -3
  185. package/dist/lib/lanes/watcher.js +35 -0
  186. package/dist/lib/signals/steps/extract.js +40 -4
  187. package/dist/schemas/hq-available-ai.v1.schema.json +76 -0
  188. package/dist/utils/catalog-runtime-paths.d.ts +34 -0
  189. package/dist/utils/catalog-runtime-paths.js +53 -0
  190. package/dist/utils/cognito-callback-port.d.ts +14 -0
  191. package/dist/utils/cognito-callback-port.js +24 -0
  192. package/dist/utils/cognito-session.js +3 -3
  193. package/dist/utils/deleted-company-notice.d.ts +59 -0
  194. package/dist/utils/deleted-company-notice.js +156 -0
  195. package/dist/utils/files-browse-acl.js +1 -1
  196. package/dist/utils/login-browser.d.ts +1 -1
  197. package/dist/utils/login-browser.js +7 -5
  198. package/dist/utils/resident-package-preload.js +30 -15
  199. package/dist/utils/vault-api.js +7 -0
  200. package/package.json +7 -7
@@ -0,0 +1,136 @@
1
+ import { type DeployPolicy, type DeployRequest } from "./admission.js";
2
+ import type { ArtifactStore } from "./artifacts.js";
3
+ import type { CredentialSource } from "./credentials.js";
4
+ import type { ApplyOutcome, DeploymentTarget } from "./disposable-target.js";
5
+ import type { AdminScope, DeliveryAccess } from "./enrollment.js";
6
+ import { type WorkerIdentity } from "./identity.js";
7
+ import { type DeploymentDecision, type DeploymentObservation, type DeploymentSnapshot, type DeploymentStatus, type StoredDeployPolicy } from "./migrations.js";
8
+ export interface DeploymentManagerOptions {
9
+ access: DeliveryAccess;
10
+ artifacts: ArtifactStore;
11
+ target: DeploymentTarget;
12
+ /** Bound on each target call, in ms. Default 5000. */
13
+ timeoutMs?: number;
14
+ /**
15
+ * Longest an in-flight deployment may hold its environment, in ms from requestedAt. Past it
16
+ * the deployment is lease-lost (unknown) and must be reconciled. Must exceed timeoutMs.
17
+ * Default: env HQ_DELIVERY_DEPLOY_MAX_HOLD_MS, else DEFAULT_DEPLOY_MAX_HOLD_MS (15 minutes).
18
+ */
19
+ maxHoldMs?: number;
20
+ ids?: () => string;
21
+ /** Provenance signing key (the US-008 key ref): signs stored policies and deployment snapshots. */
22
+ signing: {
23
+ ref: string;
24
+ source: CredentialSource;
25
+ };
26
+ /**
27
+ * Company admin credentials for setPolicy: the credential at refPrefix + "/" + tenantId
28
+ * authenticates an admin of that company. Workers never hold it.
29
+ */
30
+ policyAdmin: {
31
+ refPrefix: string;
32
+ source: CredentialSource;
33
+ };
34
+ }
35
+ /** What a worker holds between request and publish. */
36
+ export interface DeploymentTicket {
37
+ deploymentId: string;
38
+ tenantId: string;
39
+ environment: string;
40
+ fence: number;
41
+ digest: string;
42
+ attemptId: string;
43
+ workerId: string;
44
+ /** Controller epoch that issued the fence. */
45
+ epoch: number;
46
+ targetId: string;
47
+ /** Verified artifact bytes from ArtifactStore.read(). */
48
+ bytes: Buffer;
49
+ }
50
+ export interface DeploymentView {
51
+ deploymentId: string;
52
+ tenantId: string;
53
+ environment: string;
54
+ artifactId: string;
55
+ digest: string;
56
+ workerId: string;
57
+ attemptId: string;
58
+ targetId: string | null;
59
+ fence: number | null;
60
+ /** An in-flight deployment from an earlier controller epoch, or whose worker lost its attempt, shows as unknown. */
61
+ status: DeploymentStatus;
62
+ snapshot: DeploymentSnapshot;
63
+ snapshotDigest: string;
64
+ /** True when snapshotSignature verifies with the signing key. */
65
+ snapshotVerified: boolean;
66
+ decision: DeploymentDecision | null;
67
+ observation: DeploymentObservation | null;
68
+ requestedAt: string;
69
+ requestedEpoch: number;
70
+ resolvedAt: string | null;
71
+ }
72
+ /** Default max hold of an in-flight deployment: 15 minutes, well above the request-perform-publish time of a live worker. */
73
+ export declare const DEFAULT_DEPLOY_MAX_HOLD_MS: number;
74
+ /** Environment variable that overrides the default max hold, in whole ms. */
75
+ export declare const DEPLOY_MAX_HOLD_ENV = "HQ_DELIVERY_DEPLOY_MAX_HOLD_MS";
76
+ export declare function openDeploymentManager(opts: DeploymentManagerOptions): DeploymentManager;
77
+ export declare class DeploymentManager {
78
+ private readonly access;
79
+ private readonly artifacts;
80
+ private readonly target;
81
+ private readonly timeoutMs;
82
+ /** Longest an in-flight deployment holds its environment, in ms from requestedAt. */
83
+ readonly maxHoldMs: number;
84
+ private readonly ids;
85
+ private readonly signing;
86
+ private readonly policyAdmin;
87
+ constructor(opts: DeploymentManagerOptions);
88
+ /**
89
+ * Admit a deployment and issue its fence. Throws DEPLOY_BLOCKED after
90
+ * recording the decision, ENV_BUSY or DEPLOY_OUTCOME_UNKNOWN when the
91
+ * environment has an open deployment, INVALID_RECORD for a malformed request.
92
+ */
93
+ request(identity: WorkerIdentity, raw: DeployRequest): DeploymentTicket;
94
+ /** Send the fenced effect to the target. Worker side: writes nothing to the store. */
95
+ perform(ticket: DeploymentTicket): Promise<ApplyOutcome>;
96
+ /**
97
+ * Record the outcome of a performed effect. Refuses a stale publisher
98
+ * (STALE_PUBLICATION) and then leaves the deployment unknown.
99
+ */
100
+ publish(identity: WorkerIdentity, ticket: DeploymentTicket, outcome: ApplyOutcome): DeploymentView;
101
+ /** request, perform and publish. Returns the recorded outcome; unknown means reconcile next. */
102
+ deploy(identity: WorkerIdentity, req: DeployRequest): Promise<DeploymentView>;
103
+ /**
104
+ * Resolve an unknown deployment from the target's actual state. The target
105
+ * raises its fence floor to this deployment's fence before answering.
106
+ * Throws TARGET_UNREACHABLE (the outcome stays unknown) if it cannot ask.
107
+ */
108
+ reconcile(scope: AdminScope, deploymentId: string): Promise<DeploymentView>;
109
+ /** Deployments and decisions of the companies in scope, oldest first. */
110
+ deployments(scope: AdminScope): DeploymentView[];
111
+ private record;
112
+ private view;
113
+ /**
114
+ * Set a company's deploy policy. The caller must present that company's
115
+ * admin credential (the value at policyAdmin.refPrefix/<tenantId> in the
116
+ * credential source); the scope alone is not trusted. The version must
117
+ * increase. The stored record is signed with the provenance signing key.
118
+ */
119
+ setPolicy(admin: {
120
+ scope: AdminScope;
121
+ token: string;
122
+ }, policy: DeployPolicy): StoredDeployPolicy;
123
+ /** The stored policy of a company in scope (the first in scope by default), or null. */
124
+ policy(scope: AdminScope, tenantId?: string): (StoredDeployPolicy & {
125
+ policy: DeployPolicy;
126
+ verified: boolean;
127
+ }) | null;
128
+ private key;
129
+ private sign;
130
+ private verifies;
131
+ private policyVerifies;
132
+ private toView;
133
+ /** True while the worker that requested `d` still holds its deploy attempt in the current epoch. */
134
+ private held;
135
+ }
136
+ //# sourceMappingURL=effects.d.ts.map
@@ -0,0 +1,541 @@
1
+ /**
2
+ * Fenced deployment effects (US-009).
3
+ *
4
+ * Flow: request() admits (admission.ts) and, in one fenced store commit,
5
+ * either records a blocked decision or records an in-flight deployment with
6
+ * the next fence for its tenant/environment. perform() sends the effect to
7
+ * the target with that fence. publish() records the outcome, but only for a
8
+ * current publisher. deploy() is the three in order.
9
+ *
10
+ * Guarantees, and their limits:
11
+ * - One effect in flight per tenant/environment. A second request while one
12
+ * is in flight is refused ENV_BUSY; while one is unknown it is refused
13
+ * DEPLOY_OUTCOME_UNKNOWN until reconcile() resolves it. A deployment is in
14
+ * flight only while its worker holds the deploy attempt in the epoch that
15
+ * issued the fence; after a lost lease it counts as unknown even if the
16
+ * worker never tries to publish.
17
+ * - The in-flight guard has a max hold (maxHoldMs, measured from requestedAt
18
+ * on the store clock). A worker that dies or hangs without returning its
19
+ * attempt holds the environment no longer than that: past the hold the
20
+ * deployment is lease-lost. That only makes it unknown. It issues no fence
21
+ * and frees nothing; reconcile() must still seal the fence at the target
22
+ * before a retry, and the old worker's publication is refused.
23
+ * - The deploy attempt's claim lease (US-011 slice 4) works the same way: once
24
+ * it expires on the store clock the attempt is abandoned, the deployment is
25
+ * lease-lost (unknown) and goes to reconcile(). request(), publish() and
26
+ * reconcile() first sweep expired leases, and the in-commit checks treat a
27
+ * lease that has run out as lost even before a sweep.
28
+ * - Stale publication is refused (STALE_PUBLICATION): the publisher must be
29
+ * the worker that requested it, its deploy attempt must still be open and
30
+ * claimed by it in the controller epoch that issued the fence, and the
31
+ * ticket must match the record. A refused publication leaves the
32
+ * deployment unknown, never applied on the stale worker's word.
33
+ * - The target refuses fences at or below the highest it has seen for the
34
+ * environment, so a stale worker's late effect cannot overwrite a newer one.
35
+ * - A lost answer (timeout, dropped connection, crash of either side) leaves
36
+ * the outcome unknown. reconcile() queries the target, which first raises
37
+ * its fence floor to the deployment's fence so an effect still in transit
38
+ * cannot land afterwards, and records applied or not-applied. Only then can
39
+ * a retry run, with a new fence.
40
+ * - Not exactly-once. An effect is applied at most once per fence by a target
41
+ * that honours fences; whether it was applied is learned from the target,
42
+ * not assumed. A target that cannot be queried keeps the outcome unknown.
43
+ *
44
+ * The artifact bytes deployed are the ones ArtifactStore.read() verified at
45
+ * admission, never a path.
46
+ */
47
+ import { createHmac, randomUUID, timingSafeEqual } from "node:crypto";
48
+ import { admit, checkRequest, deployPolicyProblem } from "./admission.js";
49
+ import { authenticate } from "./identity.js";
50
+ import { DeliveryStoreError, WORKER_TRUSTS, } from "./migrations.js";
51
+ import { canonicalJson, sha256Hex } from "./provenance.js";
52
+ import { leaseExpired } from "./reconciler.js";
53
+ /** Default max hold of an in-flight deployment: 15 minutes, well above the request-perform-publish time of a live worker. */
54
+ export const DEFAULT_DEPLOY_MAX_HOLD_MS = 15 * 60 * 1000;
55
+ /** Environment variable that overrides the default max hold, in whole ms. */
56
+ export const DEPLOY_MAX_HOLD_ENV = "HQ_DELIVERY_DEPLOY_MAX_HOLD_MS";
57
+ function resolveMaxHoldMs(option, timeoutMs) {
58
+ const raw = process.env[DEPLOY_MAX_HOLD_ENV];
59
+ const fromEnv = option === undefined && raw !== undefined;
60
+ const value = option ?? (raw === undefined ? DEFAULT_DEPLOY_MAX_HOLD_MS : /^\d+$/.test(raw) ? Number(raw) : Number.NaN);
61
+ if (!Number.isSafeInteger(value) || value <= 0 || value <= timeoutMs) {
62
+ throw new DeliveryStoreError("INVALID_RECORD", {
63
+ found: `deployment max hold ${fromEnv ? `${DEPLOY_MAX_HOLD_ENV}=${JSON.stringify(raw)}` : String(value)}`,
64
+ expected: `a whole number of ms above the target call timeout of ${timeoutMs} ms`,
65
+ action: `Set maxHoldMs or ${DEPLOY_MAX_HOLD_ENV} to such a value, or leave both unset for the default of ${DEFAULT_DEPLOY_MAX_HOLD_MS} ms. Nothing was opened.`,
66
+ });
67
+ }
68
+ return value;
69
+ }
70
+ export function openDeploymentManager(opts) {
71
+ return new DeploymentManager(opts);
72
+ }
73
+ const OPEN = ["in-flight", "unknown"];
74
+ function denied(found, expected) {
75
+ return new DeliveryStoreError("ACCESS_DENIED", { found, expected, action: "Use a scope of the company that owns the deployment. Nothing was read or written." });
76
+ }
77
+ function checkScope(scope) {
78
+ const s = scope;
79
+ const ok = typeof scope === "object" &&
80
+ scope !== null &&
81
+ Array.isArray(s.tenantIds) &&
82
+ s.tenantIds.length > 0 &&
83
+ s.tenantIds.every((t) => typeof t === "string" && t !== "") &&
84
+ WORKER_TRUSTS.includes(s.maxTrust);
85
+ if (!ok)
86
+ throw denied("a missing or malformed admin scope", "tenantIds as a non-empty list and a known maxTrust");
87
+ return s;
88
+ }
89
+ export class DeploymentManager {
90
+ access;
91
+ artifacts;
92
+ target;
93
+ timeoutMs;
94
+ /** Longest an in-flight deployment holds its environment, in ms from requestedAt. */
95
+ maxHoldMs;
96
+ ids;
97
+ signing;
98
+ policyAdmin;
99
+ constructor(opts) {
100
+ this.access = opts.access;
101
+ this.artifacts = opts.artifacts;
102
+ this.target = opts.target;
103
+ this.timeoutMs = opts.timeoutMs ?? 5000;
104
+ this.maxHoldMs = resolveMaxHoldMs(opts.maxHoldMs, this.timeoutMs);
105
+ this.ids = opts.ids ?? (() => `deploy-${randomUUID()}`);
106
+ this.signing = opts.signing;
107
+ this.policyAdmin = opts.policyAdmin;
108
+ }
109
+ /**
110
+ * Admit a deployment and issue its fence. Throws DEPLOY_BLOCKED after
111
+ * recording the decision, ENV_BUSY or DEPLOY_OUTCOME_UNKNOWN when the
112
+ * environment has an open deployment, INVALID_RECORD for a malformed request.
113
+ */
114
+ request(identity, raw) {
115
+ const req = checkRequest(raw);
116
+ const controller = this.access.controller;
117
+ controller.assertOwner();
118
+ controller.expireLeases();
119
+ const worker = authenticate(controller.workerRecords(), identity, { capability: "claim" });
120
+ const attempt = controller.attempts().find((a) => a.attempt.attemptId === req.attemptId);
121
+ // The policy comes from the store only, keyed by the authenticated worker's company.
122
+ const policyRec = controller.deployPolicyRecords().find((p) => p.tenantId === worker.tenantId);
123
+ const adm = admit({
124
+ identity,
125
+ worker,
126
+ attempt,
127
+ controllerEpoch: controller.epoch,
128
+ now: "",
129
+ targetId: this.target.targetId,
130
+ artifacts: this.artifacts,
131
+ request: req,
132
+ storedPolicy: policyRec ?? null,
133
+ policyVerified: policyRec ? this.policyVerifies(policyRec) : false,
134
+ });
135
+ const deploymentId = this.ids();
136
+ let fence = 0;
137
+ controller.commitDeployments((draft, at) => {
138
+ const current = draft.deployPolicies.find((p) => p.tenantId === worker.tenantId);
139
+ if ((current?.signature.value ?? null) !== (policyRec?.signature.value ?? null)) {
140
+ throw new DeliveryStoreError("DEPLOY_OUTCOME_UNKNOWN", {
141
+ found: `the deploy policy of ${worker.tenantId} changed during admission`,
142
+ expected: "the policy admission evaluated",
143
+ action: "Request again. Nothing was recorded or deployed.",
144
+ });
145
+ }
146
+ const snapshot = structuredClone(adm.snapshot);
147
+ snapshot.context.requestedAt = at.now;
148
+ const snapshotDigest = sha256Hex(canonicalJson(snapshot));
149
+ const base = {
150
+ deploymentId,
151
+ tenantId: worker.tenantId,
152
+ environment: req.environment,
153
+ artifactId: req.artifactId,
154
+ digest: req.digest,
155
+ workerId: worker.workerId,
156
+ attemptId: req.attemptId,
157
+ targetId: snapshot.context.targetId,
158
+ snapshot,
159
+ snapshotDigest,
160
+ snapshotSignature: this.sign({ kind: "deployment-snapshot", deploymentId, snapshotDigest }),
161
+ requestedAt: at.now,
162
+ requestedEpoch: at.epoch,
163
+ resolvedAt: null,
164
+ resolvedEpoch: null,
165
+ observation: null,
166
+ };
167
+ if (!adm.ok) {
168
+ draft.deployments.push({
169
+ ...base,
170
+ fence: null,
171
+ status: "blocked",
172
+ decision: { code: adm.code, found: adm.found, scope: { tenantId: worker.tenantId, environment: req.environment }, escalateTo: `company-admin:${worker.tenantId}`, resolution: "pending" },
173
+ });
174
+ return;
175
+ }
176
+ const same = draft.deployments.filter((d) => d.tenantId === worker.tenantId && d.environment === req.environment);
177
+ const open = same.find((d) => OPEN.includes(d.status));
178
+ if (open)
179
+ throw open.status === "in-flight" && open.requestedEpoch === at.epoch && leaseHeld(draft.attempts.find((x) => x.record.attemptId === open.attemptId), open, at.epoch, Date.parse(at.now), this.maxHoldMs) ? busy(open) : unknownOutcome(open);
180
+ const a = draft.attempts.find((x) => x.record.attemptId === req.attemptId);
181
+ if (!a || a.resolution !== "open" || a.claimedBy !== worker.workerId || a.claimedEpoch !== at.epoch || leaseExpired(a, Date.parse(at.now))) {
182
+ throw stale(`deploy attempt ${req.attemptId} stopped being current during admission`);
183
+ }
184
+ fence = same.reduce((m, d) => Math.max(m, d.fence ?? 0), 0) + 1;
185
+ draft.deployments.push({ ...base, fence, status: "in-flight", decision: null });
186
+ });
187
+ if (!adm.ok) {
188
+ throw new DeliveryStoreError("DEPLOY_BLOCKED", {
189
+ found: `${adm.code}: ${adm.found}`,
190
+ expected: "an approved environment in the requester's company policy and an exact, verified, promoted release artifact",
191
+ action: `Recorded as deployment ${deploymentId}, escalated to company-admin:${worker.tenantId}. Nothing was deployed; there is no bypass.`,
192
+ });
193
+ }
194
+ return {
195
+ deploymentId,
196
+ tenantId: worker.tenantId,
197
+ environment: req.environment,
198
+ fence,
199
+ digest: req.digest,
200
+ attemptId: req.attemptId,
201
+ workerId: worker.workerId,
202
+ epoch: controller.epoch,
203
+ targetId: this.target.targetId,
204
+ bytes: adm.bytes,
205
+ };
206
+ }
207
+ /** Send the fenced effect to the target. Worker side: writes nothing to the store. */
208
+ perform(ticket) {
209
+ return this.target.apply({ deploymentId: ticket.deploymentId, tenantId: ticket.tenantId, environment: ticket.environment, fence: ticket.fence, digest: ticket.digest, bytes: ticket.bytes }, this.timeoutMs);
210
+ }
211
+ /**
212
+ * Record the outcome of a performed effect. Refuses a stale publisher
213
+ * (STALE_PUBLICATION) and then leaves the deployment unknown.
214
+ */
215
+ publish(identity, ticket, outcome) {
216
+ const controller = this.access.controller;
217
+ controller.assertOwner();
218
+ controller.expireLeases();
219
+ const worker = authenticate(controller.workerRecords(), identity, { capability: "report" });
220
+ let refused = null;
221
+ controller.commitDeployments((draft, at) => {
222
+ const rec = this.record(draft, ticket.deploymentId);
223
+ if (rec.tenantId !== worker.tenantId)
224
+ throw denied(`deployment ${rec.deploymentId} of another company`, `a deployment of ${worker.tenantId}`);
225
+ const reasons = staleReasons(draft, rec, ticket, worker.workerId, at.epoch, outcome, Date.parse(at.now), this.maxHoldMs);
226
+ if (reasons.length > 0) {
227
+ refused = reasons.join("; ");
228
+ if (rec.status === "in-flight") {
229
+ rec.status = "unknown";
230
+ rec.observation = { source: "stale-publication", detail: `publication refused: ${refused}`, fence: null, digest: null };
231
+ }
232
+ return;
233
+ }
234
+ if (outcome.kind === "applied") {
235
+ resolve(rec, "applied", at, { source: "apply-response", detail: "target answered applied", fence: outcome.fence, digest: outcome.digest });
236
+ }
237
+ else if (outcome.kind === "rejected") {
238
+ resolve(rec, "rejected", at, { source: "apply-rejected", detail: outcome.detail, fence: null, digest: null });
239
+ }
240
+ else {
241
+ rec.status = "unknown";
242
+ rec.observation = { source: "transport-error", detail: outcome.detail, fence: null, digest: null };
243
+ }
244
+ });
245
+ if (refused !== null)
246
+ throw stale(refused);
247
+ return this.view(ticket.deploymentId);
248
+ }
249
+ /** request, perform and publish. Returns the recorded outcome; unknown means reconcile next. */
250
+ async deploy(identity, req) {
251
+ const ticket = this.request(identity, req);
252
+ const outcome = await this.perform(ticket);
253
+ return this.publish(identity, ticket, outcome);
254
+ }
255
+ /**
256
+ * Resolve an unknown deployment from the target's actual state. The target
257
+ * raises its fence floor to this deployment's fence before answering.
258
+ * Throws TARGET_UNREACHABLE (the outcome stays unknown) if it cannot ask.
259
+ */
260
+ async reconcile(scope, deploymentId) {
261
+ const s = checkScope(scope);
262
+ const controller = this.access.controller;
263
+ controller.assertOwner();
264
+ controller.expireLeases();
265
+ const rec = controller.deploymentRecords().find((d) => d.deploymentId === deploymentId);
266
+ if (!rec)
267
+ throw unknownDeployment(deploymentId);
268
+ if (!s.tenantIds.includes(rec.tenantId))
269
+ throw denied(`deployment ${deploymentId} of a company outside the admin scope`, `a deployment of ${s.tenantIds.join(", ")}`);
270
+ // Still in flight only while the requesting worker holds its attempt in this epoch and within the
271
+ // max hold. Once that lease is gone the worker can no longer publish, so the outcome is unknown and
272
+ // is reconciled here.
273
+ if (rec.status === "in-flight" && rec.requestedEpoch === controller.epoch && this.held(rec))
274
+ throw busy(rec);
275
+ if (!OPEN.includes(rec.status))
276
+ return this.view(deploymentId);
277
+ if (rec.targetId !== this.target.targetId || rec.fence === null) {
278
+ throw new DeliveryStoreError("INVALID_RECORD", {
279
+ found: `deployment ${deploymentId} went to target ${String(rec.targetId)}`,
280
+ expected: `a deployment of target ${this.target.targetId}`,
281
+ action: "Reconcile with a manager for that deployment's target. Nothing was written.",
282
+ });
283
+ }
284
+ const fence = rec.fence;
285
+ let observed;
286
+ try {
287
+ observed = await this.target.observe({ deploymentId, tenantId: rec.tenantId, environment: rec.environment, fence }, this.timeoutMs);
288
+ }
289
+ catch (err) {
290
+ if (err instanceof DeliveryStoreError && err.code === "TARGET_UNREACHABLE") {
291
+ controller.commitDeployments((draft) => {
292
+ const r = this.record(draft, deploymentId);
293
+ if (!OPEN.includes(r.status) || r.fence !== fence)
294
+ return;
295
+ r.status = "unknown";
296
+ r.observation = { source: "transport-error", detail: err.found, fence: null, digest: null };
297
+ });
298
+ }
299
+ throw err;
300
+ }
301
+ let mismatch = null;
302
+ controller.commitDeployments((draft, at) => {
303
+ const r = this.record(draft, deploymentId);
304
+ if (!OPEN.includes(r.status) || r.fence !== fence)
305
+ return;
306
+ if (observed.kind === "absent") {
307
+ resolve(r, "not-applied", at, { source: "target-query", detail: `target has no such deployment; fence floor now ${observed.floor}`, fence: null, digest: null });
308
+ }
309
+ else if (observed.fence === fence && observed.digest === r.digest) {
310
+ resolve(r, "applied", at, { source: "target-query", detail: "target reports the deployment applied", fence: observed.fence, digest: observed.digest });
311
+ }
312
+ else {
313
+ mismatch = `target reports fence ${observed.fence} digest ${observed.digest}, the record has fence ${fence} digest ${r.digest}`;
314
+ r.status = "unknown";
315
+ r.observation = { source: "target-query", detail: mismatch, fence: observed.fence, digest: observed.digest };
316
+ }
317
+ });
318
+ if (mismatch !== null) {
319
+ throw new DeliveryStoreError("DEPLOY_OUTCOME_UNKNOWN", { found: mismatch, expected: "the target's record to match the deployment", action: "Investigate the target. No retry is allowed." });
320
+ }
321
+ return this.view(deploymentId);
322
+ }
323
+ /** Deployments and decisions of the companies in scope, oldest first. */
324
+ deployments(scope) {
325
+ const s = checkScope(scope);
326
+ const controller = this.access.controller;
327
+ controller.assertOwner();
328
+ return controller
329
+ .deploymentRecords()
330
+ .filter((d) => s.tenantIds.includes(d.tenantId))
331
+ .map((d) => this.toView(d, controller.epoch));
332
+ }
333
+ record(draft, deploymentId) {
334
+ const rec = draft.deployments.find((d) => d.deploymentId === deploymentId);
335
+ if (!rec)
336
+ throw unknownDeployment(deploymentId);
337
+ return rec;
338
+ }
339
+ view(deploymentId) {
340
+ const controller = this.access.controller;
341
+ const rec = controller.deploymentRecords().find((d) => d.deploymentId === deploymentId);
342
+ if (!rec)
343
+ throw unknownDeployment(deploymentId);
344
+ return this.toView(rec, controller.epoch);
345
+ }
346
+ /**
347
+ * Set a company's deploy policy. The caller must present that company's
348
+ * admin credential (the value at policyAdmin.refPrefix/<tenantId> in the
349
+ * credential source); the scope alone is not trusted. The version must
350
+ * increase. The stored record is signed with the provenance signing key.
351
+ */
352
+ setPolicy(admin, policy) {
353
+ const s = checkScope(admin?.scope);
354
+ const problem = deployPolicyProblem(policy);
355
+ if (problem !== null) {
356
+ throw new DeliveryStoreError("INVALID_RECORD", { found: problem, expected: "a deploy policy { policyId, tenantId, version, environments }", action: "Fix the policy. Nothing was written." });
357
+ }
358
+ const tenantId = policy.tenantId;
359
+ if (!s.tenantIds.includes(tenantId))
360
+ throw denied(`a policy for ${tenantId} from an admin scope that does not cover it`, `an admin of ${tenantId}`);
361
+ const ref = `${this.policyAdmin.refPrefix}/${tenantId}`;
362
+ let expected;
363
+ try {
364
+ expected = this.policyAdmin.source.resolve(ref);
365
+ }
366
+ catch {
367
+ throw denied(`no admin credential is provisioned for ${tenantId}`, `an admin credential at ${ref}`);
368
+ }
369
+ // A blank or non-string credential is an unprovisioned one: it authenticates nobody.
370
+ if (typeof expected !== "string" || expected.trim() === "")
371
+ throw denied(`no admin credential is provisioned for ${tenantId}`, `a non-empty admin credential at ${ref}`);
372
+ if (typeof admin.token !== "string" || admin.token.trim() === "")
373
+ throw denied(`no admin credential was presented for ${tenantId}`, `the admin credential at ${ref}`);
374
+ const want = Buffer.from(sha256Hex(expected), "hex");
375
+ const have = Buffer.from(sha256Hex(admin.token), "hex");
376
+ if (!timingSafeEqual(want, have))
377
+ throw denied(`an admin credential that does not authenticate for ${tenantId}`, `the admin credential at ${ref}`);
378
+ const controller = this.access.controller;
379
+ controller.assertOwner();
380
+ controller.commitDeployments((draft, at) => {
381
+ const prior = draft.deployPolicies.find((p) => p.tenantId === tenantId);
382
+ const priorVersion = prior ? prior.policy.version : 0;
383
+ if (policy.version <= priorVersion) {
384
+ throw new DeliveryStoreError("INVALID_RECORD", {
385
+ found: `policy version ${policy.version} for ${tenantId}`,
386
+ expected: `a version above the stored ${priorVersion}`,
387
+ action: "Increase the version. Nothing was written.",
388
+ });
389
+ }
390
+ const body = { tenantId, policy: structuredClone(policy), setBy: ref, setAt: at.now, setEpoch: at.epoch };
391
+ const rec = { ...body, signature: this.sign({ kind: "deploy-policy", ...body }) };
392
+ draft.deployPolicies = [...draft.deployPolicies.filter((p) => p.tenantId !== tenantId), rec];
393
+ });
394
+ return this.policy(s, tenantId);
395
+ }
396
+ /** The stored policy of a company in scope (the first in scope by default), or null. */
397
+ policy(scope, tenantId) {
398
+ const s = checkScope(scope);
399
+ const t = tenantId ?? s.tenantIds[0];
400
+ if (!s.tenantIds.includes(t))
401
+ throw denied(`a policy of ${t} outside the admin scope`, `a company in ${s.tenantIds.join(", ")}`);
402
+ const rec = this.access.controller.deployPolicyRecords().find((p) => p.tenantId === t);
403
+ return rec ? { ...rec, policy: rec.policy, verified: this.policyVerifies(rec) } : null;
404
+ }
405
+ key() {
406
+ try {
407
+ const value = this.signing.source.resolve(this.signing.ref);
408
+ // A blank key is an unprovisioned one: it signs nothing.
409
+ if (typeof value === "string" && value.trim() !== "")
410
+ return value;
411
+ }
412
+ catch {
413
+ // fall through
414
+ }
415
+ throw new DeliveryStoreError("SIGNING_KEY_UNCONFIGURED", {
416
+ found: `no signing key at ${this.signing.ref}`,
417
+ expected: "the provenance signing key",
418
+ action: "Provision the key with HQ secrets. Nothing was signed or written.",
419
+ });
420
+ }
421
+ sign(body) {
422
+ return { algorithm: "hmac-sha256", keyRef: this.signing.ref, value: createHmac("sha256", this.key()).update(canonicalJson(body)).digest("hex") };
423
+ }
424
+ verifies(body, sig) {
425
+ if (sig.algorithm !== "hmac-sha256" || sig.keyRef !== this.signing.ref)
426
+ return false;
427
+ const want = createHmac("sha256", this.key()).update(canonicalJson(body)).digest();
428
+ const have = Buffer.from(sig.value, "hex");
429
+ return have.length === want.length && timingSafeEqual(have, want);
430
+ }
431
+ policyVerifies(p) {
432
+ const { signature, ...body } = p;
433
+ return this.verifies({ kind: "deploy-policy", ...body }, signature);
434
+ }
435
+ toView(d, epoch) {
436
+ const snapshotVerified = d.snapshotDigest === sha256Hex(canonicalJson(d.snapshot)) && this.verifies({ kind: "deployment-snapshot", deploymentId: d.deploymentId, snapshotDigest: d.snapshotDigest }, d.snapshotSignature);
437
+ return toView(d, epoch, snapshotVerified, this.held(d));
438
+ }
439
+ /** True while the worker that requested `d` still holds its deploy attempt in the current epoch. */
440
+ held(d) {
441
+ const controller = this.access.controller;
442
+ const view = controller.attempts().find((x) => x.attempt.attemptId === d.attemptId);
443
+ // AttemptView does not carry the claim lease, so read it from the controller.
444
+ const a = view && { ...view, leaseExpiresAt: controller.leaseExpiresAt(d.attemptId) };
445
+ return leaseHeld(a, d, controller.epoch, Date.parse(controller.now()), this.maxHoldMs);
446
+ }
447
+ }
448
+ /**
449
+ * The lease of a deployment: its attempt is open and claimed by the requesting worker in `epoch`,
450
+ * its claim lease has not run out, and the deployment has not been in flight longer than the max hold.
451
+ * `leaseExpiresAt` is required so that no caller can drop the claim lease by passing a view without it.
452
+ */
453
+ function leaseHeld(a, d, epoch, nowMs, maxHoldMs) {
454
+ const claimExpired = a !== undefined && a.leaseExpiresAt !== null && nowMs >= Date.parse(a.leaseExpiresAt);
455
+ return a !== undefined && a.resolution === "open" && a.claimedBy === d.workerId && a.claimedEpoch === epoch && !claimExpired && !holdExpired(d, nowMs, maxHoldMs);
456
+ }
457
+ /** True once `d` has been in flight for maxHoldMs since requestedAt. A time that cannot be read counts as expired. */
458
+ function holdExpired(d, nowMs, maxHoldMs) {
459
+ return !(nowMs - Date.parse(d.requestedAt) < maxHoldMs);
460
+ }
461
+ function toView(d, epoch, snapshotVerified, held) {
462
+ const status = d.status === "in-flight" && (d.requestedEpoch < epoch || !held) ? "unknown" : d.status;
463
+ return {
464
+ snapshotVerified,
465
+ deploymentId: d.deploymentId,
466
+ tenantId: d.tenantId,
467
+ environment: d.environment,
468
+ artifactId: d.artifactId,
469
+ digest: d.digest,
470
+ workerId: d.workerId,
471
+ attemptId: d.attemptId,
472
+ targetId: d.targetId,
473
+ fence: d.fence,
474
+ status,
475
+ snapshot: d.snapshot,
476
+ snapshotDigest: d.snapshotDigest,
477
+ decision: d.decision,
478
+ observation: d.observation,
479
+ requestedAt: d.requestedAt,
480
+ requestedEpoch: d.requestedEpoch,
481
+ resolvedAt: d.resolvedAt,
482
+ };
483
+ }
484
+ function resolve(rec, status, at, observation) {
485
+ rec.status = status;
486
+ rec.resolvedAt = at.now;
487
+ rec.resolvedEpoch = at.epoch;
488
+ rec.observation = observation;
489
+ }
490
+ function staleReasons(draft, rec, ticket, workerId, epoch, outcome, nowMs, maxHoldMs) {
491
+ const reasons = [];
492
+ if (rec.status !== "in-flight")
493
+ reasons.push(`deployment ${rec.deploymentId} is ${rec.status}, not in flight`);
494
+ if (rec.fence !== ticket.fence)
495
+ reasons.push(`ticket fence ${ticket.fence} is not the issued fence ${String(rec.fence)}`);
496
+ if (rec.digest !== ticket.digest || rec.attemptId !== ticket.attemptId)
497
+ reasons.push("ticket does not match the recorded artifact and attempt");
498
+ if (rec.workerId !== workerId)
499
+ reasons.push(`worker ${workerId} did not request this deployment`);
500
+ if (rec.requestedEpoch !== epoch || ticket.epoch !== epoch)
501
+ reasons.push(`the fence was issued at controller epoch ${rec.requestedEpoch}; the current epoch is ${epoch} (lease lost)`);
502
+ const a = draft.attempts.find((x) => x.record.attemptId === rec.attemptId);
503
+ if (!a || a.resolution !== "open" || a.claimedBy !== workerId || a.claimedEpoch !== epoch || leaseExpired(a, nowMs)) {
504
+ reasons.push(`deploy attempt ${rec.attemptId} is ${a ? a.resolution : "missing"}, no longer held by ${workerId} (lease lost)`);
505
+ }
506
+ if (rec.status === "in-flight" && holdExpired(rec, nowMs, maxHoldMs)) {
507
+ reasons.push(`deployment ${rec.deploymentId} was in flight longer than the max hold of ${maxHoldMs} ms since ${rec.requestedAt} (lease lost)`);
508
+ }
509
+ if (outcome.kind === "applied" && (outcome.fence !== ticket.fence || outcome.digest !== ticket.digest))
510
+ reasons.push("the reported effect is not the ticket's fence and digest");
511
+ return reasons;
512
+ }
513
+ function stale(found) {
514
+ return new DeliveryStoreError("STALE_PUBLICATION", {
515
+ found,
516
+ expected: "a publication by the requesting worker, holding its open deploy attempt, in the epoch that issued the fence",
517
+ action: "The deployment is left unknown. Reconcile it against the target before any retry.",
518
+ });
519
+ }
520
+ function busy(d) {
521
+ return new DeliveryStoreError("ENV_BUSY", {
522
+ found: `deployment ${d.deploymentId} (fence ${String(d.fence)}) is in flight for ${d.tenantId}/${d.environment}`,
523
+ expected: "no other effect in flight for this environment",
524
+ action: "Wait for it to publish, then request again. If its worker is gone, it becomes unknown after the max hold and can then be reconciled. Nothing was written.",
525
+ });
526
+ }
527
+ function unknownOutcome(d) {
528
+ return new DeliveryStoreError("DEPLOY_OUTCOME_UNKNOWN", {
529
+ found: `deployment ${d.deploymentId} (fence ${String(d.fence)}) for ${d.tenantId}/${d.environment} has an unknown outcome`,
530
+ expected: "the previous effect reconciled against the target",
531
+ action: `Run reconcile for ${d.deploymentId} first. Nothing was written or deployed.`,
532
+ });
533
+ }
534
+ function unknownDeployment(deploymentId) {
535
+ return new DeliveryStoreError("UNKNOWN_DEPLOYMENT", {
536
+ found: `no deployment ${String(deploymentId)}`,
537
+ expected: "a deploymentId returned by request",
538
+ action: "Check the id. Nothing was written.",
539
+ });
540
+ }
541
+ //# sourceMappingURL=effects.js.map