@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,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
@@ -0,0 +1,255 @@
1
+ import { type Attempt, type Job, type Run } from "./contracts.js";
2
+ import { type ProvenanceSignature, type StoredArtifact, type StoredCacheEntry } from "./provenance.js";
3
+ export declare const STORE_SCHEMA_V1 = "hq-delivery.store.v1";
4
+ export declare const STORE_SCHEMA_V2 = "hq-delivery.store.v2";
5
+ /** v3 (US-004) adds the worker list. */
6
+ export declare const STORE_SCHEMA_V3 = "hq-delivery.store.v3";
7
+ /** v4 binds each attempt to the worker that claimed it (claimedBy). */
8
+ export declare const STORE_SCHEMA_V4 = "hq-delivery.store.v4";
9
+ /** v5 (US-008) adds artifact provenance records and cache entries. */
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";
15
+ /** The store schema version this code writes. */
16
+ export declare const STORE_SCHEMA_VERSION = "hq-delivery.store.v7";
17
+ /** Every version this code can open, oldest first. Older ones migrate forward on open. */
18
+ export declare const KNOWN_STORE_SCHEMA_VERSIONS: readonly string[];
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";
20
+ export interface ErrorDetail {
21
+ /** What the store saw. */
22
+ found: string;
23
+ /** What it needed instead. */
24
+ expected: string;
25
+ /** What the operator or caller should do next. */
26
+ action: string;
27
+ }
28
+ /** Every refusal from the delivery store. The message reads "CODE: found ...; expected .... action". */
29
+ export declare class DeliveryStoreError extends Error {
30
+ readonly code: DeliveryStoreErrorCode;
31
+ readonly found: string;
32
+ readonly expected: string;
33
+ readonly action: string;
34
+ constructor(code: DeliveryStoreErrorCode, detail: ErrorDetail);
35
+ }
36
+ export type AttemptResolution = "open" | "reported" | "abandoned";
37
+ export type TakeoverReason = "stale-pid" | "operator-override";
38
+ /** One entry per controller that has owned the store, in epoch order. */
39
+ export interface ControllerEntry {
40
+ epoch: number;
41
+ controllerId: string;
42
+ host: string;
43
+ pid: number;
44
+ acquiredAt: string;
45
+ /** Set when this controller replaced an earlier lock holder. previousOwner is the old lock text. */
46
+ takeover: {
47
+ reason: TakeoverReason;
48
+ previousOwner: string;
49
+ note: string | null;
50
+ } | null;
51
+ }
52
+ export interface StoredRun {
53
+ record: Run;
54
+ /** null for runs migrated from v1, which did not record accept times. */
55
+ acceptedAt: string | null;
56
+ acceptedEpoch: number;
57
+ }
58
+ export interface StoredJob {
59
+ record: Job;
60
+ /** jobIds in the same run that must pass before this job is claimable. */
61
+ dependsOn: string[];
62
+ acceptedAt: string | null;
63
+ acceptedEpoch: number;
64
+ }
65
+ export interface StoredAttempt {
66
+ record: Attempt;
67
+ claimedAt: string | null;
68
+ claimedEpoch: number;
69
+ /**
70
+ * workerId of the enrolled worker that claimed the attempt. Only that worker
71
+ * may report or return it. null for a claim made without a worker (direct
72
+ * controller use) and for attempts migrated from v3 or older.
73
+ */
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;
82
+ /**
83
+ * open: outcome pending, owned by the controller of claimedEpoch.
84
+ * reported: outcome passed or failed, reported by a controller.
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.
87
+ */
88
+ resolution: AttemptResolution;
89
+ resolvedAt: string | null;
90
+ resolvedEpoch: number | null;
91
+ }
92
+ /** What an enrolled worker may do. Checked on every operation. */
93
+ export type WorkerCapability = "claim" | "read" | "report";
94
+ /** standard workers run untrusted build and test jobs; only release workers run release jobs. */
95
+ export type WorkerTrust = "standard" | "release";
96
+ export type WorkerStatus = "pending" | "active" | "revoked";
97
+ export declare const WORKER_CAPABILITIES: readonly WorkerCapability[];
98
+ export declare const WORKER_TRUSTS: readonly WorkerTrust[];
99
+ /** One worker of one tenant (US-004). Only a SHA-256 digest of its secret is stored. */
100
+ export interface StoredWorker {
101
+ workerId: string;
102
+ tenantId: string;
103
+ capabilities: WorkerCapability[];
104
+ trust: WorkerTrust;
105
+ /** pending: enrollment ticket issued, not redeemed. active: enrolled. revoked: final. */
106
+ status: WorkerStatus;
107
+ /** Digest of the enrollment ticket while pending, of the worker token once enrolled. */
108
+ secretSha256: string;
109
+ issuedAt: string;
110
+ issuedEpoch: number;
111
+ enrolledAt: string | null;
112
+ enrolledEpoch: number | null;
113
+ revokedAt: string | null;
114
+ revokedEpoch: number | null;
115
+ }
116
+ export interface StoreState {
117
+ /** Fencing epoch of the current owner. Bumped on every acquisition. */
118
+ epoch: number;
119
+ controllers: ControllerEntry[];
120
+ runs: StoredRun[];
121
+ jobs: StoredJob[];
122
+ attempts: StoredAttempt[];
123
+ workers: StoredWorker[];
124
+ /** US-008: one provenance record per stored artifact. */
125
+ artifacts: StoredArtifact[];
126
+ /** US-008: cache entries, partitioned by tenant and trust. */
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;
217
+ }
218
+ export declare function emptyState(): StoreState;
219
+ export declare function stateChecksum(state: StoreState): string;
220
+ /** The exact bytes of a current-version store file for `state`. */
221
+ export declare function serializeState(state: StoreState): string;
222
+ export interface ParsedStore {
223
+ state: StoreState;
224
+ /** The version the file was migrated from, or null when it was already current. */
225
+ fromVersion: string | null;
226
+ }
227
+ /**
228
+ * Parse and validate a store file. A known older version is migrated forward
229
+ * in memory. Throws DeliveryStoreError for anything that cannot be opened
230
+ * exactly as written.
231
+ */
232
+ export declare function parseStoreText(text: string, source: string): ParsedStore;
233
+ /**
234
+ * Return one dependency cycle as a path (a -> b -> a, where a depends on b),
235
+ * or null. Edges to nodes not in the graph are ignored.
236
+ */
237
+ export declare function findCycle(graph: ReadonlyMap<string, readonly string[]>): string[] | null;
238
+ /** All problems with a store state, or [] when it is valid. Never throws. */
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
+ }
255
+ //# sourceMappingURL=migrations.d.ts.map