@indigoai-us/hq-cli 5.345.215-beta.0 → 5.345.217

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 (241) hide show
  1. package/CHANGELOG.md +206 -1
  2. package/README.md +45 -0
  3. package/assets/scaffold/core/scripts/hq-delegate-verify.sh +5 -2
  4. package/assets/scaffold/core/scripts/lib/epochrealtime.sh +30 -0
  5. package/assets/scaffold/core/scripts/lib/work-mesh-enqueue.sh +12 -5
  6. package/dist/command-catalog.generated.d.ts +105 -10
  7. package/dist/command-catalog.generated.js +127 -10
  8. package/dist/command-help.js +3 -1
  9. package/dist/command-registration-plan.d.ts +6 -0
  10. package/dist/command-registration-plan.js +1 -0
  11. package/dist/commands/auth.d.ts +1 -1
  12. package/dist/commands/auth.js +11 -52
  13. package/dist/commands/bot.js +75 -10
  14. package/dist/commands/capacity.d.ts +4 -1
  15. package/dist/commands/capacity.js +46 -10
  16. package/dist/commands/cloud-demote.d.ts +19 -4
  17. package/dist/commands/cloud-demote.js +85 -12
  18. package/dist/commands/cloud-provision.d.ts +5 -1
  19. package/dist/commands/cloud-provision.js +6 -2
  20. package/dist/commands/cloud.d.ts +36 -0
  21. package/dist/commands/cloud.js +110 -27
  22. package/dist/commands/core-delegate-w1b.js +15 -1
  23. package/dist/commands/core-policy.js +67 -8
  24. package/dist/commands/core.js +1 -0
  25. package/dist/commands/daemon.js +9 -1
  26. package/dist/commands/dm.js +7 -0
  27. package/dist/commands/doctor-usage.d.ts +8 -0
  28. package/dist/commands/doctor-usage.js +20 -0
  29. package/dist/commands/doctor.js +7 -1
  30. package/dist/commands/env.d.ts +18 -0
  31. package/dist/commands/env.js +82 -0
  32. package/dist/commands/files-browse.d.ts +11 -4
  33. package/dist/commands/files-browse.js +21 -4
  34. package/dist/commands/files.d.ts +1 -1
  35. package/dist/commands/files.js +25 -11
  36. package/dist/commands/install-global.js +2 -2
  37. package/dist/commands/integrations-auth-rules.d.ts +27 -0
  38. package/dist/commands/integrations-auth-rules.js +79 -0
  39. package/dist/commands/integrations-import.js +124 -12
  40. package/dist/commands/lanes.js +102 -26
  41. package/dist/commands/logout.d.ts +7 -0
  42. package/dist/commands/logout.js +41 -34
  43. package/dist/commands/mesh.d.ts +2 -0
  44. package/dist/commands/mesh.js +60 -35
  45. package/dist/commands/sources.d.ts +8 -2
  46. package/dist/commands/sources.js +65 -9
  47. package/dist/commands/sync-held.js +5 -2
  48. package/dist/commands/whoami.js +26 -1
  49. package/dist/data/command-states.json +15 -0
  50. package/dist/index.js +52 -4
  51. package/dist/lazy-commands.js +5 -6
  52. package/dist/lib/anywhere-person-setting.d.ts +2 -0
  53. package/dist/lib/anywhere-person-setting.js +6 -3
  54. package/dist/lib/billing/usage-card.d.ts +25 -4
  55. package/dist/lib/billing/usage-card.js +76 -9
  56. package/dist/lib/billing/usage-cost.d.ts +3 -3
  57. package/dist/lib/billing/usage-cost.js +35 -13
  58. package/dist/lib/billing/usage-only.js +4 -2
  59. package/dist/lib/billing/usage-rate-card.d.ts +2 -2
  60. package/dist/lib/billing/usage-rate-card.js +3 -0
  61. package/dist/lib/bot/fleet-cron.d.ts +8 -0
  62. package/dist/lib/bot/fleet-cron.js +126 -7
  63. package/dist/lib/bot/fleet-daemon.d.ts +46 -0
  64. package/dist/lib/bot/fleet-daemon.js +99 -1
  65. package/dist/lib/bot/inflight.d.ts +9 -0
  66. package/dist/lib/bot/inflight.js +10 -0
  67. package/dist/lib/bot/jobs/hot-signal-sync.js +12 -1
  68. package/dist/lib/bot/probe.js +7 -1
  69. package/dist/lib/bot/run.js +20 -1
  70. package/dist/lib/bot/runtime/codex.js +1 -1
  71. package/dist/lib/bot/runtime/grok-acp.d.ts +6 -1
  72. package/dist/lib/bot/runtime/grok-acp.js +32 -14
  73. package/dist/lib/bot/runtime/grok.js +1 -1
  74. package/dist/lib/bot/runtime/index.js +19 -9
  75. package/dist/lib/bot/runtime/messages-stream.js +2 -2
  76. package/dist/lib/bot/runtime/types.d.ts +15 -0
  77. package/dist/lib/bot/runtime/types.js +9 -0
  78. package/dist/lib/bot/runtime-failure.d.ts +23 -0
  79. package/dist/lib/bot/runtime-failure.js +43 -1
  80. package/dist/lib/capacity/accounts.d.ts +8 -0
  81. package/dist/lib/capacity/accounts.js +19 -0
  82. package/dist/lib/capacity/available.d.ts +154 -0
  83. package/dist/lib/capacity/available.js +905 -0
  84. package/dist/lib/capacity/codex-availability.d.ts +14 -1
  85. package/dist/lib/capacity/codex-availability.js +26 -1
  86. package/dist/lib/capacity/collectors/claude-oauth.d.ts +29 -2
  87. package/dist/lib/capacity/collectors/claude-oauth.js +104 -7
  88. package/dist/lib/capacity/collectors/codex.js +10 -7
  89. package/dist/lib/capacity/ledger.d.ts +37 -1
  90. package/dist/lib/capacity/ledger.js +207 -30
  91. package/dist/lib/capacity/project.d.ts +26 -0
  92. package/dist/lib/capacity/project.js +137 -8
  93. package/dist/lib/capacity/refusal-rows.d.ts +31 -0
  94. package/dist/lib/capacity/refusal-rows.js +61 -0
  95. package/dist/lib/capacity/refusal.d.ts +53 -2
  96. package/dist/lib/capacity/refusal.js +284 -65
  97. package/dist/lib/capacity/route.js +46 -11
  98. package/dist/lib/capacity/widget.d.ts +12 -1
  99. package/dist/lib/capacity/widget.js +91 -3
  100. package/dist/lib/daemon/flag-monitor.d.ts +8 -0
  101. package/dist/lib/daemon/flag-monitor.js +17 -6
  102. package/dist/lib/daemon/flag.d.ts +65 -1
  103. package/dist/lib/daemon/flag.js +190 -40
  104. package/dist/lib/daemon/ops/policy.js +62 -5
  105. package/dist/lib/daemon/paths.d.ts +72 -2
  106. package/dist/lib/daemon/paths.js +154 -3
  107. package/dist/lib/daemon/resolver.d.ts +2 -0
  108. package/dist/lib/daemon/resolver.js +3 -0
  109. package/dist/lib/daemon/run.d.ts +9 -0
  110. package/dist/lib/daemon/run.js +79 -21
  111. package/dist/lib/daemon/selfcheck.d.ts +22 -0
  112. package/dist/lib/daemon/selfcheck.js +40 -1
  113. package/dist/lib/daemon/server.d.ts +5 -1
  114. package/dist/lib/daemon/server.js +17 -23
  115. package/dist/lib/daemon/state-file-switch.d.ts +57 -0
  116. package/dist/lib/daemon/state-file-switch.js +88 -0
  117. package/dist/lib/daemon/state-file.d.ts +198 -0
  118. package/dist/lib/daemon/state-file.js +419 -0
  119. package/dist/lib/daemon/tcc-eperm.d.ts +153 -0
  120. package/dist/lib/daemon/tcc-eperm.js +310 -0
  121. package/dist/lib/daemon/timed-flag-monitors.d.ts +47 -0
  122. package/dist/lib/daemon/timed-flag-monitors.js +75 -0
  123. package/dist/lib/delivery/admission.d.ts +86 -0
  124. package/dist/lib/delivery/admission.js +148 -0
  125. package/dist/lib/delivery/artifacts.d.ts +7 -1
  126. package/dist/lib/delivery/artifacts.js +29 -10
  127. package/dist/lib/delivery/attempt-id.d.ts +13 -0
  128. package/dist/lib/delivery/attempt-id.js +16 -0
  129. package/dist/lib/delivery/disposable-target.d.ts +42 -0
  130. package/dist/lib/delivery/disposable-target.js +111 -0
  131. package/dist/lib/delivery/effects.d.ts +136 -0
  132. package/dist/lib/delivery/effects.js +541 -0
  133. package/dist/lib/delivery/enrollment.d.ts +21 -17
  134. package/dist/lib/delivery/enrollment.js +83 -5
  135. package/dist/lib/delivery/escalations.d.ts +51 -0
  136. package/dist/lib/delivery/escalations.js +60 -0
  137. package/dist/lib/delivery/lease.d.ts +80 -0
  138. package/dist/lib/delivery/lease.js +134 -0
  139. package/dist/lib/delivery/migrations.d.ts +120 -4
  140. package/dist/lib/delivery/migrations.js +215 -15
  141. package/dist/lib/delivery/mqtt.d.ts +2 -0
  142. package/dist/lib/delivery/mqtt.js +7 -0
  143. package/dist/lib/delivery/reconciler.d.ts +65 -1
  144. package/dist/lib/delivery/reconciler.js +224 -13
  145. package/dist/lib/delivery/rpc/client.d.ts +22 -0
  146. package/dist/lib/delivery/rpc/client.js +159 -0
  147. package/dist/lib/delivery/rpc/port.d.ts +40 -0
  148. package/dist/lib/delivery/rpc/port.js +16 -0
  149. package/dist/lib/delivery/rpc/server.d.ts +30 -0
  150. package/dist/lib/delivery/rpc/server.js +205 -0
  151. package/dist/lib/delivery/rpc/wire.d.ts +85 -0
  152. package/dist/lib/delivery/rpc/wire.js +143 -0
  153. package/dist/lib/delivery/store.d.ts +2 -0
  154. package/dist/lib/delivery/store.js +4 -0
  155. package/dist/lib/delivery/windows-service-install.d.ts +262 -0
  156. package/dist/lib/delivery/windows-service-install.js +892 -0
  157. package/dist/lib/delivery/workers/macos.d.ts +16 -1
  158. package/dist/lib/delivery/workers/macos.js +54 -12
  159. package/dist/lib/delivery/workers/windows-service-live.d.ts +121 -0
  160. package/dist/lib/delivery/workers/windows-service-live.js +711 -0
  161. package/dist/lib/delivery/workers/windows-service-runner.d.ts +33 -0
  162. package/dist/lib/delivery/workers/windows-service-runner.js +82 -0
  163. package/dist/lib/delivery/workers/windows-service.d.ts +140 -0
  164. package/dist/lib/delivery/workers/windows-service.js +584 -0
  165. package/dist/lib/delivery/workers/windows.d.ts +32 -22
  166. package/dist/lib/delivery/workers/windows.js +50 -64
  167. package/dist/lib/doctor/checks/host-core.d.ts +50 -0
  168. package/dist/lib/doctor/checks/host-core.js +269 -0
  169. package/dist/lib/doctor/checks/replay-recorder.d.ts +39 -0
  170. package/dist/lib/doctor/checks/replay-recorder.js +261 -0
  171. package/dist/lib/doctor/registry.js +4 -0
  172. package/dist/lib/environment/profile.d.ts +239 -0
  173. package/dist/lib/environment/profile.js +251 -0
  174. package/dist/lib/hook-engine/reconcile.js +39 -13
  175. package/dist/lib/hook-engine/registration.d.ts +9 -0
  176. package/dist/lib/hook-engine/registration.js +19 -0
  177. package/dist/lib/hot-channels/adapters/meetings.d.ts +15 -0
  178. package/dist/lib/hot-channels/adapters/meetings.js +36 -3
  179. package/dist/lib/hot-channels/adapters/slack.d.ts +21 -5
  180. package/dist/lib/hot-channels/adapters/slack.js +64 -21
  181. package/dist/lib/hot-channels/alert.d.ts +2 -0
  182. package/dist/lib/hot-channels/alert.js +8 -1
  183. package/dist/lib/hot-channels/contract.d.ts +12 -0
  184. package/dist/lib/hot-channels/contract.js +7 -0
  185. package/dist/lib/hot-channels/loop.js +1 -0
  186. package/dist/lib/hot-channels/run.d.ts +6 -0
  187. package/dist/lib/hot-channels/run.js +4 -0
  188. package/dist/lib/hot-channels/signals-pass.d.ts +74 -1
  189. package/dist/lib/hot-channels/signals-pass.js +82 -41
  190. package/dist/lib/hot-channels/signals-redo.js +10 -2
  191. package/dist/lib/install/claude-targets.d.ts +12 -1
  192. package/dist/lib/install/claude-targets.js +57 -5
  193. package/dist/lib/install/codex-targets.d.ts +2 -2
  194. package/dist/lib/install/codex-targets.js +36 -6
  195. package/dist/lib/install/hook-target.d.ts +3 -0
  196. package/dist/lib/install/hook-target.js +11 -0
  197. package/dist/lib/lanes/canonical-host.d.ts +35 -0
  198. package/dist/lib/lanes/canonical-host.js +65 -0
  199. package/dist/lib/lanes/host-capacity.d.ts +30 -0
  200. package/dist/lib/lanes/host-capacity.js +29 -3
  201. package/dist/lib/lanes/watcher.js +35 -0
  202. package/dist/lib/mesh/live/daemon/run.d.ts +2 -0
  203. package/dist/lib/mesh/live/daemon/run.js +5 -2
  204. package/dist/lib/mesh/live/flush.d.ts +5 -1
  205. package/dist/lib/mesh/live/flush.js +12 -6
  206. package/dist/lib/mesh/live/reporting-privacy.d.ts +32 -0
  207. package/dist/lib/mesh/live/reporting-privacy.js +56 -1
  208. package/dist/lib/mesh/live/spool.d.ts +7 -0
  209. package/dist/lib/mesh/live/spool.js +25 -0
  210. package/dist/lib/person-setting-cache.d.ts +38 -0
  211. package/dist/lib/person-setting-cache.js +98 -0
  212. package/dist/lib/safe-store.d.ts +245 -0
  213. package/dist/lib/safe-store.js +777 -0
  214. package/dist/lib/signals/engine.d.ts +29 -2
  215. package/dist/lib/signals/engine.js +103 -4
  216. package/dist/lib/signals/reply.js +73 -18
  217. package/dist/lib/signals/steps/adapters.js +7 -2
  218. package/dist/lib/signals/steps/extract.d.ts +13 -0
  219. package/dist/lib/signals/steps/extract.js +122 -6
  220. package/dist/main.js +46 -3
  221. package/dist/schemas/hq-available-ai.v1.schema.json +76 -0
  222. package/dist/schemas/hq-environment-profile.v1.schema.json +438 -0
  223. package/dist/utils/auth-expiry.d.ts +8 -0
  224. package/dist/utils/auth-expiry.js +53 -0
  225. package/dist/utils/catalog-runtime-paths.d.ts +34 -0
  226. package/dist/utils/catalog-runtime-paths.js +53 -0
  227. package/dist/utils/cli-telemetry.d.ts +21 -0
  228. package/dist/utils/cli-telemetry.js +34 -0
  229. package/dist/utils/command-usage.d.ts +275 -0
  230. package/dist/utils/command-usage.js +797 -0
  231. package/dist/utils/files-browse-acl.js +1 -1
  232. package/dist/utils/hook-trust.d.ts +7 -0
  233. package/dist/utils/hook-trust.js +31 -4
  234. package/dist/utils/host-registration.d.ts +126 -0
  235. package/dist/utils/host-registration.js +378 -0
  236. package/dist/utils/resident-package-preload.js +2 -0
  237. package/package.json +10 -8
  238. package/scripts/bench-core.mjs +1096 -0
  239. package/scripts/check-function-manifest.mjs +702 -0
  240. package/dist/lib/delivery/workers/windows-boundary.d.ts +0 -453
  241. package/dist/lib/delivery/workers/windows-boundary.js +0 -693
@@ -1,3 +1,19 @@
1
+ /**
2
+ * Worker enrollment and the authenticated access layer (US-004).
3
+ *
4
+ * An admin with a company scope issues a one-time enrollment ticket for a
5
+ * worker of one tenant, with fixed capabilities and trust. The worker redeems
6
+ * the ticket for a token. Every worker operation then authenticates against
7
+ * the stored worker records: company scope, capability and status.
8
+ *
9
+ * Revocation is a fenced store commit. Each worker write re-authenticates
10
+ * inside the same commit, against the state about to be written, so a
11
+ * revocation that lands while an operation is in flight refuses that
12
+ * operation instead of racing it. Requests beyond the ticket, the admin's
13
+ * scope or the worker's trust are rejected, never downgraded.
14
+ */
15
+ import { createHash } from "node:crypto";
16
+ import { MAX_CHOSEN_ATTEMPT_ID, isSafeAttemptId } from "./attempt-id.js";
1
17
  import { assertJobTrust, injectCredentials, planCredentials, } from "./credentials.js";
2
18
  import { authenticate, newSecret, secretDigest, secretMatches, trustAllows } from "./identity.js";
3
19
  import { DeliveryStoreError, WORKER_CAPABILITIES, WORKER_TRUSTS, } from "./migrations.js";
@@ -18,6 +34,24 @@ function rejected(found, expected, action) {
18
34
  function invalid(found, expected) {
19
35
  return new DeliveryStoreError("INVALID_RECORD", { found, expected, action: "Fix the input and retry. Nothing was written." });
20
36
  }
37
+ /** A worker-chosen attemptId: a safe name (attempt-id.ts) of at most MAX_CHOSEN_ATTEMPT_ID characters. */
38
+ function checkAttemptId(id) {
39
+ if (id === undefined)
40
+ return undefined;
41
+ if (!isSafeAttemptId(id) || id.length > MAX_CHOSEN_ATTEMPT_ID) {
42
+ throw invalid(`attemptId ${JSON.stringify(id)?.slice(0, 80)}`, `1 to ${MAX_CHOSEN_ATTEMPT_ID} letters, digits, dot, underscore or dash, starting with a letter or digit, and no '..'`);
43
+ }
44
+ return id;
45
+ }
46
+ /**
47
+ * The stored id of a worker-chosen attemptId (review I1): the chosen id behind
48
+ * a prefix derived from the worker's company and id. Ids of different workers
49
+ * can never collide, so no worker can squat another's ids or learn anything by
50
+ * reusing them, and a replay can only ever find the worker's own attempts.
51
+ */
52
+ function scopedAttemptId(worker, chosen) {
53
+ return `w${createHash("sha256").update(`${worker.tenantId}\u0000${worker.workerId}`).digest("hex").slice(0, 12)}-${chosen}`;
54
+ }
21
55
  function checkScope(scope) {
22
56
  const s = scope;
23
57
  const ok = typeof scope === "object" &&
@@ -175,7 +209,9 @@ export class DeliveryAccess {
175
209
  const current = find(this.ownedRecords());
176
210
  if (current.status === "revoked")
177
211
  return view(current);
178
- this.controller.commitWorkers((workers, at) => {
212
+ // US-011 slice 4: the worker's open attempts are abandoned in the same commit, so its claims are freed
213
+ // at once. Its late reports are then refused (WORKER_REVOKED), and each job can be claimed again.
214
+ this.controller.commitRevocation(workerId, (workers, at) => {
179
215
  const w = find(workers);
180
216
  if (w.status === "revoked")
181
217
  return;
@@ -185,6 +221,27 @@ export class DeliveryAccess {
185
221
  });
186
222
  return view(find(this.ownedRecords()));
187
223
  }
224
+ /**
225
+ * US-011 slice 4: extend the lease of the worker's own open attempt. Needs
226
+ * "report". The claimant, the open attempt, the lease and that the worker is
227
+ * not revoked are checked again inside the commit. Refused with
228
+ * ATTEMPT_ABANDONED once the lease has expired.
229
+ */
230
+ renewLease(identity, attemptId) {
231
+ const worker = authenticate(this.ownedRecords(), identity, { capability: "report" });
232
+ const attempt = this.controller.attempts().find((a) => a.attempt.attemptId === attemptId);
233
+ if (!attempt) {
234
+ throw new DeliveryStoreError("UNKNOWN_ATTEMPT", {
235
+ found: `no attempt ${attemptId}`,
236
+ expected: "an attemptId returned by claim",
237
+ action: "Check the attemptId. Nothing was written.",
238
+ });
239
+ }
240
+ this.sameTenant(worker, attempt.attempt.tenantId, `attempt ${attemptId}`);
241
+ if (attempt.claimedBy !== worker.workerId)
242
+ throw notClaimant(worker.workerId, attemptId);
243
+ return this.controller.renewLease(attemptId, { guard: this.attemptGuard(identity, worker.tenantId, attemptId), workerId: worker.workerId });
244
+ }
188
245
  /** Workers in the admin's scope, without secret digests. */
189
246
  workers(scope) {
190
247
  this.controller.assertOwner();
@@ -208,10 +265,18 @@ export class DeliveryAccess {
208
265
  this.sameTenant(worker, run.tenantId, `run ${runId}`);
209
266
  return { run, jobs: this.controller.jobs(runId) };
210
267
  }
211
- /** Claim a ready job of the worker's own company. Needs "claim". */
212
- claim(identity, jobId) {
268
+ /**
269
+ * Claim a ready job of the worker's own company. Needs "claim". A worker may
270
+ * choose the attemptId (US-011 slice 4 B): claiming again with the same id
271
+ * replays the stored claim instead of opening a second attempt, so a retry
272
+ * after a lost answer is safe. The id must be a safe name (it becomes a
273
+ * directory name on the worker).
274
+ */
275
+ claim(identity, jobId, opts = {}) {
276
+ const chosen = checkAttemptId(opts?.attemptId);
213
277
  const { worker, guard } = this.prepareClaim(identity, jobId);
214
- return this.controller.claim(jobId, { guard, workerId: worker.workerId });
278
+ const attemptId = chosen === undefined ? undefined : scopedAttemptId(worker, chosen);
279
+ return this.controller.claim(jobId, { guard, workerId: worker.workerId, ...(attemptId === undefined ? {} : { attemptId }) });
215
280
  }
216
281
  /** Report the outcome of an attempt of the worker's own company. Needs "report". */
217
282
  recordOutcome(identity, attemptId, outcome) {
@@ -251,7 +316,9 @@ export class DeliveryAccess {
251
316
  * before the claim, so a lookup failure claims nothing.
252
317
  */
253
318
  dispatch(identity, jobId, request) {
319
+ const chosen = checkAttemptId(request?.attemptId);
254
320
  const { worker, job, guard } = this.prepareClaim(identity, jobId);
321
+ const attemptId = chosen === undefined ? undefined : scopedAttemptId(worker, chosen);
255
322
  const plan = planCredentials(this.policy, { job, workerTrust: worker.trust, requested: request?.credentials });
256
323
  if (plan.refs.length > 0 && !this.source) {
257
324
  throw new DeliveryStoreError("CREDENTIAL_UNAVAILABLE", {
@@ -260,10 +327,21 @@ export class DeliveryAccess {
260
327
  action: "Open the access layer with a credential source. Nothing was claimed.",
261
328
  });
262
329
  }
330
+ const claimOpts = { guard, workerId: worker.workerId, ...(attemptId === undefined ? {} : { attemptId }) };
331
+ // A replay is checked against the live claim before any credential is looked up (review C1):
332
+ // a refused replay resolves nothing. A new claim keeps the old order, so a lookup failure claims nothing.
333
+ if (attemptId !== undefined && this.controller.attempts().some((a) => a.attempt.attemptId === attemptId)) {
334
+ const claim = this.controller.claim(jobId, claimOpts);
335
+ return { claim, jobClass: plan.jobClass, credentials: injectCredentials(this.source ?? NO_CREDENTIALS, plan.refs) };
336
+ }
263
337
  const credentials = injectCredentials(this.source ?? NO_CREDENTIALS, plan.refs);
264
- const claim = this.controller.claim(jobId, { guard, workerId: worker.workerId });
338
+ const claim = this.controller.claim(jobId, claimOpts);
265
339
  return { claim, jobClass: plan.jobClass, credentials };
266
340
  }
341
+ /** The trust an authenticated worker was enrolled with. Needs "claim". */
342
+ workerTrust(identity) {
343
+ return authenticate(this.ownedRecords(), identity, { capability: "claim" }).trust;
344
+ }
267
345
  /** The company of an authenticated worker. Needs "claim". */
268
346
  workerTenant(identity) {
269
347
  return authenticate(this.ownedRecords(), identity, { capability: "claim" }).tenantId;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Delivery of escalated deployment decisions (US-009).
3
+ *
4
+ * Same transactional-outbox model as outbox.ts: events are derived from the
5
+ * committed ledger, here one `deployment.escalated` per blocked deployment,
6
+ * so an event exists exactly when the decision commit exists. They go to the
7
+ * company's escalation topic (mqtt.ts escalationTopic), never to the worker
8
+ * event topic, so worker inboxes are unaffected. The publisher keeps only
9
+ * the ids the broker acked in its own sqlite file; delivery is at-least-once
10
+ * with stable event ids.
11
+ */
12
+ import type { DeliveryAccess } from "./enrollment.js";
13
+ import type { StoredDeployment } from "./migrations.js";
14
+ import { type NotificationBroker } from "./mqtt.js";
15
+ export declare const ESCALATION_SCHEMA = "hq-delivery.escalation.v1";
16
+ export interface EscalationEvent {
17
+ schemaVersion: typeof ESCALATION_SCHEMA;
18
+ eventId: string;
19
+ type: "deployment.escalated";
20
+ tenantId: string;
21
+ environment: string;
22
+ deploymentId: string;
23
+ code: string;
24
+ found: string;
25
+ escalateTo: string;
26
+ epoch: number;
27
+ }
28
+ /** Every escalation the committed ledger implies, in ledger order. */
29
+ export declare function escalationEvents(deployments: readonly StoredDeployment[]): EscalationEvent[];
30
+ export interface EscalationPublisherOptions {
31
+ access: DeliveryAccess;
32
+ broker: NotificationBroker;
33
+ /** The publisher's own sqlite file. Not the ledger. */
34
+ path: string;
35
+ }
36
+ export declare class EscalationPublisher {
37
+ private readonly access;
38
+ private readonly broker;
39
+ private readonly db;
40
+ private constructor();
41
+ static open(opts: EscalationPublisherOptions): EscalationPublisher;
42
+ pending(): EscalationEvent[];
43
+ /** Publish every pending escalation, oldest first. Stops at the first broker error. */
44
+ publishPending(): Promise<{
45
+ published: number;
46
+ remaining: number;
47
+ error: string | null;
48
+ }>;
49
+ close(): void;
50
+ }
51
+ //# sourceMappingURL=escalations.d.ts.map
@@ -0,0 +1,60 @@
1
+ import { escalationTopic } from "./mqtt.js";
2
+ import { openTransportDb } from "./outbox.js";
3
+ export const ESCALATION_SCHEMA = "hq-delivery.escalation.v1";
4
+ /** Every escalation the committed ledger implies, in ledger order. */
5
+ export function escalationEvents(deployments) {
6
+ return deployments
7
+ .filter((d) => d.status === "blocked" && d.decision !== null)
8
+ .map((d) => ({
9
+ schemaVersion: ESCALATION_SCHEMA,
10
+ eventId: `deployment.escalated:${d.deploymentId}`,
11
+ type: "deployment.escalated",
12
+ tenantId: d.decision.scope.tenantId,
13
+ environment: d.decision.scope.environment,
14
+ deploymentId: d.deploymentId,
15
+ code: d.decision.code,
16
+ found: d.decision.found,
17
+ escalateTo: d.decision.escalateTo,
18
+ epoch: d.requestedEpoch,
19
+ }));
20
+ }
21
+ export class EscalationPublisher {
22
+ access;
23
+ broker;
24
+ db;
25
+ constructor(access, broker, db) {
26
+ this.access = access;
27
+ this.broker = broker;
28
+ this.db = db;
29
+ }
30
+ static open(opts) {
31
+ const db = openTransportDb(opts.path);
32
+ db.exec("CREATE TABLE IF NOT EXISTS published (event_id TEXT PRIMARY KEY, at INTEGER NOT NULL)");
33
+ return new EscalationPublisher(opts.access, opts.broker, db);
34
+ }
35
+ pending() {
36
+ const done = new Set(this.db.prepare("SELECT event_id FROM published").all().map((r) => r.event_id));
37
+ return escalationEvents(this.access.controller.deploymentRecords()).filter((e) => !done.has(e.eventId));
38
+ }
39
+ /** Publish every pending escalation, oldest first. Stops at the first broker error. */
40
+ async publishPending() {
41
+ const pending = this.pending();
42
+ const insert = this.db.prepare("INSERT OR IGNORE INTO published (event_id, at) VALUES (?, ?)");
43
+ let published = 0;
44
+ for (const event of pending) {
45
+ try {
46
+ await this.broker.publish(escalationTopic(event.tenantId), JSON.stringify(event));
47
+ }
48
+ catch (err) {
49
+ return { published, remaining: pending.length - published, error: err instanceof Error ? err.message : "broker error" };
50
+ }
51
+ insert.run(event.eventId, Date.now());
52
+ published += 1;
53
+ }
54
+ return { published, remaining: 0, error: null };
55
+ }
56
+ close() {
57
+ this.db.close();
58
+ }
59
+ }
60
+ //# sourceMappingURL=escalations.js.map
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Worker heartbeat for a claim lease (US-011 slice 4).
3
+ *
4
+ * A worker's claim carries a lease of claimLeaseMs on the controller's clock
5
+ * (reconciler.ts). While the worker runs the attempt, startLeaseHeartbeat
6
+ * renews it every leaseMs / 3, so two missed beats still leave the lease
7
+ * alive. The lease length comes from the controller (`controller.claimLeaseMs`)
8
+ * unless the caller passes it, so the period cannot drift from the lease. A
9
+ * worker on the RPC port has no controller object and passes leaseMs.
10
+ *
11
+ * A store refusal means the lease is gone or the controller can no longer hold
12
+ * it: the attempt was abandoned, reported or is not the worker's, the worker
13
+ * was revoked, or the controller was fenced, closed, retired or is restoring.
14
+ * The heartbeat then stops and calls onLost once: the worker must stop work on
15
+ * the attempt and discard its result.
16
+ *
17
+ * A transient failure (store I/O, an RPC timeout, a closed or unreachable
18
+ * controller, or an error that is not a store refusal) goes to onError and the
19
+ * heartbeat keeps beating, but only until the renewal deadline (slice 4 B):
20
+ * the lease the controller confirmed last runs from no earlier than the moment
21
+ * that renewal was sent, so the worker gives the claim up at
22
+ * send time of the last confirmed renewal + leaseMs - callDeadlineMs - marginMs
23
+ * on a one-shot timer (not on the next tick), stopping with LEASE_UNCONFIRMED.
24
+ * callDeadlineMs is how long a call may take to fail (pass the RPC client's
25
+ * total deadline); marginMs defaults to one beat. A partitioned worker thus
26
+ * gives the claim up strictly before the controller's lease can run out and
27
+ * hand the job to someone else. A renewal that never answers counts the same.
28
+ *
29
+ * renewLease may answer synchronously (the in-process access layer) or with a
30
+ * promise (the RPC client). A beat is skipped while the previous one is still
31
+ * waiting for its answer.
32
+ */
33
+ import type { LeaseView } from "./reconciler.js";
34
+ import type { WorkerIdentity } from "./identity.js";
35
+ import { DeliveryStoreError } from "./migrations.js";
36
+ export interface HeartbeatTimers {
37
+ setInterval(fn: () => void, ms: number): unknown;
38
+ clearInterval(handle: unknown): void;
39
+ /** The give-up timer. Injected timers without it are checked on each tick and each failed renewal only. */
40
+ setTimeout?(fn: () => void, ms: number): unknown;
41
+ clearTimeout?(handle: unknown): void;
42
+ }
43
+ export interface LeaseHeartbeatOptions {
44
+ /** Renews the lease. When it also exposes `controller.claimLeaseMs`, the period derives from it. */
45
+ access: {
46
+ renewLease(identity: WorkerIdentity, attemptId: string): LeaseView | Promise<LeaseView>;
47
+ readonly controller?: {
48
+ readonly claimLeaseMs: number;
49
+ };
50
+ };
51
+ identity: WorkerIdentity;
52
+ attemptId: string;
53
+ /** The controller's claimLeaseMs. Default: `access.controller.claimLeaseMs`. One of the two is required. */
54
+ leaseMs?: number;
55
+ /** How long a renewal call may take before it fails (for the RPC client: retries + 1 times its timeout). Default 0. */
56
+ callDeadlineMs?: number;
57
+ /** Safety margin before the controller's expiry. Default floor(leaseMs / 3), one beat. */
58
+ marginMs?: number;
59
+ /**
60
+ * The worker's clock in ms, used only for intervals (the renewal deadline).
61
+ * Default performance.now, a monotonic clock, so a wall-clock step cannot
62
+ * move the deadline. An injected clock should be monotonic too.
63
+ */
64
+ now?: () => number;
65
+ /** Called once when the lease is refused or unconfirmed past the deadline; the heartbeat has stopped. */
66
+ onLost?: (err: DeliveryStoreError) => void;
67
+ /** Called for a transient failure; the heartbeat keeps going until the deadline. */
68
+ onError?: (err: unknown) => void;
69
+ /** Injected timers, for tests. Default the global setInterval and clearInterval. */
70
+ timers?: HeartbeatTimers;
71
+ }
72
+ export interface LeaseHeartbeat {
73
+ stop(): void;
74
+ /** Renewals the controller accepted so far. */
75
+ renewals(): number;
76
+ /** Resolves when no renewal is waiting for its answer. */
77
+ settled(): Promise<void>;
78
+ }
79
+ export declare function startLeaseHeartbeat(opts: LeaseHeartbeatOptions): LeaseHeartbeat;
80
+ //# sourceMappingURL=lease.d.ts.map
@@ -0,0 +1,134 @@
1
+ import { DeliveryStoreError } from "./migrations.js";
2
+ /** Failures worth retrying on the next beat, until the renewal deadline. Every other store refusal ends the heartbeat. */
3
+ // RPC_BUSY is transient too: a flood of local connections must not make a worker drop a live claim.
4
+ const TRANSIENT = ["STORE_IO", "RPC_TIMEOUT", "RPC_CLOSED", "RPC_UNREACHABLE", "RPC_SERVER_ERROR", "RPC_BUSY"];
5
+ function isThenable(v) {
6
+ return typeof v?.then === "function";
7
+ }
8
+ export function startLeaseHeartbeat(opts) {
9
+ const leaseMs = opts.leaseMs ?? opts.access.controller?.claimLeaseMs;
10
+ if (leaseMs === undefined)
11
+ throw new RangeError("leaseMs is required when the access does not report the controller's claimLeaseMs");
12
+ if (!Number.isSafeInteger(leaseMs) || leaseMs < 3)
13
+ throw new RangeError(`leaseMs must be an integer of at least 3 ms, got ${String(leaseMs)}`);
14
+ const period = Math.floor(leaseMs / 3);
15
+ const callDeadlineMs = opts.callDeadlineMs ?? 0;
16
+ const marginMs = opts.marginMs ?? period;
17
+ if (!Number.isSafeInteger(callDeadlineMs) || callDeadlineMs < 0 || !Number.isSafeInteger(marginMs) || marginMs < 0) {
18
+ throw new RangeError(`callDeadlineMs and marginMs must be non-negative integers, got ${String(opts.callDeadlineMs)} and ${String(opts.marginMs)}`);
19
+ }
20
+ const giveUpAfterMs = leaseMs - callDeadlineMs - marginMs;
21
+ if (giveUpAfterMs < period) {
22
+ throw new RangeError(`leaseMs ${leaseMs} minus callDeadlineMs ${callDeadlineMs} and marginMs ${marginMs} leaves ${giveUpAfterMs} ms, less than one beat (${period} ms) to renew`);
23
+ }
24
+ const now = opts.now ?? (() => performance.now());
25
+ const timers = opts.timers ?? {
26
+ setInterval: (fn, ms) => {
27
+ const handle = setInterval(fn, ms);
28
+ handle.unref?.();
29
+ return handle;
30
+ },
31
+ clearInterval: (handle) => clearInterval(handle),
32
+ setTimeout: (fn, ms) => {
33
+ const handle = setTimeout(fn, ms);
34
+ handle.unref?.();
35
+ return handle;
36
+ },
37
+ clearTimeout: (handle) => clearTimeout(handle),
38
+ };
39
+ let stopped = false;
40
+ let renewed = 0;
41
+ // The claim was just made, so the lease is confirmed as of the start (its lease ran from the claim, before now).
42
+ let confirmedAt = now();
43
+ let inFlight = null;
44
+ let giveUpTimer = null;
45
+ const stop = () => {
46
+ if (stopped)
47
+ return;
48
+ stopped = true;
49
+ timers.clearInterval(handle);
50
+ if (giveUpTimer !== null)
51
+ timers.clearTimeout?.(giveUpTimer);
52
+ };
53
+ const lose = (err) => {
54
+ if (stopped)
55
+ return;
56
+ stop();
57
+ opts.onLost?.(err);
58
+ };
59
+ const unconfirmed = () => new DeliveryStoreError("LEASE_UNCONFIRMED", {
60
+ found: `no renewal of attempt ${opts.attemptId} confirmed for ${now() - confirmedAt} ms`,
61
+ expected: `a confirmed renewal at least every ${giveUpAfterMs} ms`,
62
+ action: "Stop work on the attempt and discard its result: the controller may already have given the job to another worker.",
63
+ });
64
+ const failed = (err) => {
65
+ if (stopped)
66
+ return;
67
+ if (err instanceof DeliveryStoreError && !TRANSIENT.includes(err.code)) {
68
+ lose(err);
69
+ return;
70
+ }
71
+ opts.onError?.(err);
72
+ if (now() - confirmedAt >= giveUpAfterMs)
73
+ lose(unconfirmed());
74
+ };
75
+ /** (Re)arm the give-up timer for the current confirmation. */
76
+ const arm = () => {
77
+ if (stopped || !timers.setTimeout)
78
+ return;
79
+ if (giveUpTimer !== null)
80
+ timers.clearTimeout?.(giveUpTimer);
81
+ giveUpTimer = timers.setTimeout(() => {
82
+ giveUpTimer = null;
83
+ if (stopped)
84
+ return;
85
+ if (now() - confirmedAt >= giveUpAfterMs)
86
+ lose(unconfirmed());
87
+ // Fired before the deadline by the given clock (an injected clock that stepped back,
88
+ // or a timer that fired early): arm again rather than leave only the tick check.
89
+ else
90
+ arm();
91
+ }, Math.max(0, confirmedAt + giveUpAfterMs - now()));
92
+ };
93
+ /** A renewal sent at `sentAt` was confirmed: the controller's new lease runs from no earlier than that. */
94
+ const ok = (sentAt) => {
95
+ if (stopped)
96
+ return;
97
+ renewed += 1;
98
+ if (sentAt > confirmedAt)
99
+ confirmedAt = sentAt;
100
+ arm();
101
+ };
102
+ const beat = () => {
103
+ if (stopped)
104
+ return;
105
+ if (now() - confirmedAt >= giveUpAfterMs) {
106
+ lose(unconfirmed());
107
+ return;
108
+ }
109
+ if (inFlight)
110
+ return;
111
+ const sentAt = now();
112
+ let answer;
113
+ try {
114
+ answer = opts.access.renewLease(opts.identity, opts.attemptId);
115
+ }
116
+ catch (err) {
117
+ failed(err);
118
+ return;
119
+ }
120
+ if (!isThenable(answer)) {
121
+ ok(sentAt);
122
+ return;
123
+ }
124
+ inFlight = Promise.resolve(answer)
125
+ .then(() => ok(sentAt), failed)
126
+ .finally(() => {
127
+ inFlight = null;
128
+ });
129
+ };
130
+ const handle = timers.setInterval(beat, period);
131
+ arm();
132
+ return { stop, renewals: () => renewed, settled: async () => void (await inFlight) };
133
+ }
134
+ //# sourceMappingURL=lease.js.map
@@ -1,5 +1,5 @@
1
1
  import { type Attempt, type Job, type Run } from "./contracts.js";
2
- import { type StoredArtifact, type StoredCacheEntry } from "./provenance.js";
2
+ import { type ProvenanceSignature, type StoredArtifact, type StoredCacheEntry } from "./provenance.js";
3
3
  export declare const STORE_SCHEMA_V1 = "hq-delivery.store.v1";
4
4
  export declare const STORE_SCHEMA_V2 = "hq-delivery.store.v2";
5
5
  /** v3 (US-004) adds the worker list. */
@@ -8,11 +8,15 @@ export declare const STORE_SCHEMA_V3 = "hq-delivery.store.v3";
8
8
  export declare const STORE_SCHEMA_V4 = "hq-delivery.store.v4";
9
9
  /** v5 (US-008) adds artifact provenance records and cache entries. */
10
10
  export declare const STORE_SCHEMA_V5 = "hq-delivery.store.v5";
11
+ /** v6 (US-009) adds the deployment ledger: policy decisions and fenced deployments. */
12
+ export declare const STORE_SCHEMA_V6 = "hq-delivery.store.v6";
13
+ /** v7 (US-011 slice 4) adds a claim lease to every attempt (leaseExpiresAt). */
14
+ export declare const STORE_SCHEMA_V7 = "hq-delivery.store.v7";
11
15
  /** The store schema version this code writes. */
12
- export declare const STORE_SCHEMA_VERSION = "hq-delivery.store.v5";
16
+ export declare const STORE_SCHEMA_VERSION = "hq-delivery.store.v7";
13
17
  /** Every version this code can open, oldest first. Older ones migrate forward on open. */
14
18
  export declare const KNOWN_STORE_SCHEMA_VERSIONS: readonly string[];
15
- export type DeliveryStoreErrorCode = "STORE_CORRUPT" | "STORE_SCHEMA_NEWER" | "STORE_SCHEMA_UNKNOWN" | "STORE_INVALID_RECORD" | "CONTROLLER_OWNED" | "CONTROLLER_AMBIGUOUS" | "FENCED" | "STORE_CLOSED" | "STORE_IO" | "INVALID_RECORD" | "DUPLICATE_CONFLICT" | "UNKNOWN_RUN" | "UNKNOWN_JOB" | "UNKNOWN_DEPENDENCY" | "DEPENDENCY_CYCLE" | "NOT_CLAIMABLE" | "UNKNOWN_ATTEMPT" | "ATTEMPT_CONFLICT" | "ATTEMPT_ABANDONED" | "ACCESS_DENIED" | "WORKER_REVOKED" | "PRIVILEGE_REJECTED" | "CREDENTIAL_UNAVAILABLE" | "NOTIFICATION_UNVERIFIED" | "ARTIFACT_UNKNOWN" | "ARTIFACT_TAMPERED" | "ARTIFACT_NOT_PROMOTABLE" | "SIGNING_KEY_UNCONFIGURED" | "BACKUP_INVALID" | "RESTORE_PENDING" | "STORE_RETIRED";
19
+ export type DeliveryStoreErrorCode = "STORE_CORRUPT" | "STORE_SCHEMA_NEWER" | "STORE_SCHEMA_UNKNOWN" | "STORE_INVALID_RECORD" | "CONTROLLER_OWNED" | "CONTROLLER_AMBIGUOUS" | "FENCED" | "STORE_CLOSED" | "STORE_IO" | "INVALID_RECORD" | "DUPLICATE_CONFLICT" | "UNKNOWN_RUN" | "UNKNOWN_JOB" | "UNKNOWN_DEPENDENCY" | "DEPENDENCY_CYCLE" | "NOT_CLAIMABLE" | "UNKNOWN_ATTEMPT" | "ATTEMPT_CONFLICT" | "ATTEMPT_ABANDONED" | "ACCESS_DENIED" | "WORKER_REVOKED" | "PRIVILEGE_REJECTED" | "CREDENTIAL_UNAVAILABLE" | "NOTIFICATION_UNVERIFIED" | "ARTIFACT_UNKNOWN" | "ARTIFACT_TAMPERED" | "ARTIFACT_NOT_PROMOTABLE" | "SIGNING_KEY_UNCONFIGURED" | "BACKUP_INVALID" | "RESTORE_PENDING" | "STORE_RETIRED" | "DEPLOY_BLOCKED" | "ENV_BUSY" | "DEPLOY_OUTCOME_UNKNOWN" | "STALE_PUBLICATION" | "UNKNOWN_DEPLOYMENT" | "TARGET_UNREACHABLE" | "RPC_TIMEOUT" | "RPC_CLOSED" | "RPC_UNREACHABLE" | "RPC_BAD_REQUEST" | "RPC_UNKNOWN_METHOD" | "RPC_TOO_LARGE" | "RPC_BAD_ANSWER" | "RPC_SERVER_ERROR" | "RPC_NOT_LOOPBACK" | "RPC_BUSY" | "LEASE_UNCONFIRMED";
16
20
  export interface ErrorDetail {
17
21
  /** What the store saw. */
18
22
  found: string;
@@ -68,10 +72,18 @@ export interface StoredAttempt {
68
72
  * controller use) and for attempts migrated from v3 or older.
69
73
  */
70
74
  claimedBy: string | null;
75
+ /**
76
+ * v7: when the claimant's lease runs out, as an ISO time on the controller's
77
+ * clock. The claimant extends it with renewLease. At or after this time the
78
+ * open attempt is abandoned. null when the attempt has no lease: a claim made
79
+ * without a worker, and every attempt migrated from v6 or older.
80
+ */
81
+ leaseExpiresAt: string | null;
71
82
  /**
72
83
  * open: outcome pending, owned by the controller of claimedEpoch.
73
84
  * reported: outcome passed or failed, reported by a controller.
74
- * abandoned: was open when its controller stopped; outcome is "failed".
85
+ * abandoned: outcome is "failed"; the attempt was open when its controller
86
+ * stopped, its lease expired, its worker was revoked or its worker returned it.
75
87
  */
76
88
  resolution: AttemptResolution;
77
89
  resolvedAt: string | null;
@@ -113,6 +125,95 @@ export interface StoreState {
113
125
  artifacts: StoredArtifact[];
114
126
  /** US-008: cache entries, partitioned by tenant and trust. */
115
127
  cache: StoredCacheEntry[];
128
+ /** US-009: deployment decisions and fenced deployments, oldest first. */
129
+ deployments: StoredDeployment[];
130
+ /** US-009: one admin-set, signed deploy policy per company. Workers never write it. */
131
+ deployPolicies: StoredDeployPolicy[];
132
+ }
133
+ /**
134
+ * blocked: refused by admission; carries a decision, no fence, no effect.
135
+ * in-flight: fence issued, effect may be in progress.
136
+ * unknown: the effect may or may not have happened; reconcile before any retry.
137
+ * applied / not-applied: the target's answer. rejected: the target refused the fence.
138
+ */
139
+ export type DeploymentStatus = "blocked" | "in-flight" | "unknown" | "applied" | "not-applied" | "rejected";
140
+ export declare const DEPLOYMENT_STATUSES: readonly DeploymentStatus[];
141
+ export type DecisionCode = "POLICY_INVALID" | "POLICY_MISSING" | "POLICY_TAMPERED" | "ENVIRONMENT_UNLISTED" | "ENVIRONMENT_UNAPPROVED" | "TARGET_MISMATCH" | "ATTEMPT_NOT_CURRENT" | "ARTIFACT_UNKNOWN" | "ARTIFACT_OTHER_TENANT" | "ARTIFACT_UNTRUSTED" | "ARTIFACT_CHANGED" | "ARTIFACT_UNPROMOTED" | "SOURCE_NOT_ALLOWED";
142
+ export declare const DECISION_CODES: readonly DecisionCode[];
143
+ /** An escalated exception. There is no bypass: only a new request under a changed policy can proceed. */
144
+ export interface DeploymentDecision {
145
+ code: DecisionCode;
146
+ found: string;
147
+ scope: {
148
+ tenantId: string;
149
+ environment: string;
150
+ };
151
+ /** Who must decide, always inside the requester's company. */
152
+ escalateTo: string;
153
+ resolution: "pending";
154
+ }
155
+ /** What admission saw, frozen at request time. Hashed into snapshotDigest; never changed after. */
156
+ export interface DeploymentSnapshot {
157
+ /** The policy as given, or null when it belongs to another company (only its digest is kept). */
158
+ policy: unknown;
159
+ policyDigest: string | null;
160
+ policyTenantId: string | null;
161
+ /** Credential ref of the admin that set the policy, and the policy signature value. */
162
+ policySetBy: string | null;
163
+ policySignature: string | null;
164
+ artifact: {
165
+ artifactId: string;
166
+ digest: string | null;
167
+ partition: string | null;
168
+ promoted: boolean;
169
+ promotedAt: string | null;
170
+ repository: string | null;
171
+ commitSha: string | null;
172
+ builder: string | null;
173
+ provenanceSignature: string | null;
174
+ };
175
+ context: {
176
+ tenantId: string;
177
+ environment: string;
178
+ workerId: string;
179
+ attemptId: string;
180
+ targetId: string | null;
181
+ requestedDigest: string;
182
+ controllerEpoch: number;
183
+ requestedAt: string;
184
+ };
185
+ }
186
+ export type ObservationSource = "apply-response" | "apply-rejected" | "transport-error" | "stale-publication" | "lease-lost" | "target-query";
187
+ export declare const OBSERVATION_SOURCES: readonly ObservationSource[];
188
+ export interface DeploymentObservation {
189
+ source: ObservationSource;
190
+ detail: string;
191
+ fence: number | null;
192
+ digest: string | null;
193
+ }
194
+ export interface StoredDeployment {
195
+ deploymentId: string;
196
+ tenantId: string;
197
+ environment: string;
198
+ artifactId: string;
199
+ /** The digest the request named. */
200
+ digest: string;
201
+ workerId: string;
202
+ attemptId: string;
203
+ targetId: string | null;
204
+ /** Per tenant/environment, strictly increasing. null for a blocked request. */
205
+ fence: number | null;
206
+ status: DeploymentStatus;
207
+ snapshot: DeploymentSnapshot;
208
+ snapshotDigest: string;
209
+ /** HMAC over deploymentId and snapshotDigest with the provenance signing key; checked by effects.ts, which holds the key. */
210
+ snapshotSignature: ProvenanceSignature;
211
+ decision: DeploymentDecision | null;
212
+ requestedAt: string;
213
+ requestedEpoch: number;
214
+ resolvedAt: string | null;
215
+ resolvedEpoch: number | null;
216
+ observation: DeploymentObservation | null;
116
217
  }
117
218
  export declare function emptyState(): StoreState;
118
219
  export declare function stateChecksum(state: StoreState): string;
@@ -136,4 +237,19 @@ export declare function parseStoreText(text: string, source: string): ParsedStor
136
237
  export declare function findCycle(graph: ReadonlyMap<string, readonly string[]>): string[] | null;
137
238
  /** All problems with a store state, or [] when it is valid. Never throws. */
138
239
  export declare function validateState(input: unknown): string[];
240
+ /**
241
+ * US-009 company deploy policy as set by an authenticated company admin.
242
+ * `policy` is the admission.ts DeployPolicy. The signature (HMAC with the
243
+ * provenance signing key, over tenantId, policy, setBy, setAt, setEpoch) is
244
+ * checked by effects.ts at admission; an edited policy is refused there.
245
+ */
246
+ export interface StoredDeployPolicy {
247
+ tenantId: string;
248
+ policy: unknown;
249
+ /** Credential ref of the admin credential that authenticated the write. */
250
+ setBy: string;
251
+ setAt: string;
252
+ setEpoch: number;
253
+ signature: ProvenanceSignature;
254
+ }
139
255
  //# sourceMappingURL=migrations.d.ts.map