@indigoai-us/hq-cli 5.345.215-beta.0 → 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.
- package/CHANGELOG.md +65 -1
- package/assets/scaffold/core/scripts/hq-delegate-verify.sh +5 -2
- package/dist/command-catalog.generated.d.ts +46 -6
- package/dist/command-catalog.generated.js +53 -6
- package/dist/commands/bot.js +64 -6
- package/dist/commands/capacity.d.ts +4 -1
- package/dist/commands/capacity.js +46 -10
- package/dist/commands/cloud.js +1 -1
- package/dist/commands/core-delegate-w1b.js +15 -1
- package/dist/commands/core-policy.js +67 -8
- package/dist/commands/daemon.js +5 -0
- package/dist/commands/files-browse.d.ts +11 -4
- package/dist/commands/files-browse.js +21 -4
- package/dist/commands/files.d.ts +1 -1
- package/dist/commands/files.js +25 -11
- package/dist/commands/integrations-auth-rules.d.ts +27 -0
- package/dist/commands/integrations-auth-rules.js +79 -0
- package/dist/commands/integrations-import.js +124 -12
- package/dist/commands/lanes.js +2 -2
- package/dist/commands/mesh.d.ts +2 -0
- package/dist/commands/mesh.js +60 -35
- package/dist/commands/sync-held.js +5 -2
- package/dist/lazy-commands.js +3 -5
- package/dist/lib/bot/fleet-cron.d.ts +8 -0
- package/dist/lib/bot/fleet-cron.js +35 -3
- package/dist/lib/bot/fleet-daemon.d.ts +46 -0
- package/dist/lib/bot/fleet-daemon.js +99 -1
- package/dist/lib/bot/probe.js +7 -1
- package/dist/lib/bot/run.js +20 -1
- package/dist/lib/bot/runtime/codex.js +1 -1
- package/dist/lib/bot/runtime/grok-acp.d.ts +5 -1
- package/dist/lib/bot/runtime/grok-acp.js +6 -3
- package/dist/lib/bot/runtime/index.js +19 -9
- package/dist/lib/bot/runtime/messages-stream.js +2 -2
- package/dist/lib/bot/runtime/types.d.ts +15 -0
- package/dist/lib/bot/runtime/types.js +9 -0
- package/dist/lib/bot/runtime-failure.d.ts +23 -0
- package/dist/lib/bot/runtime-failure.js +43 -1
- package/dist/lib/capacity/accounts.d.ts +8 -0
- package/dist/lib/capacity/accounts.js +19 -0
- package/dist/lib/capacity/available.d.ts +154 -0
- package/dist/lib/capacity/available.js +905 -0
- package/dist/lib/capacity/codex-availability.d.ts +14 -1
- package/dist/lib/capacity/codex-availability.js +26 -1
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +29 -2
- package/dist/lib/capacity/collectors/claude-oauth.js +104 -7
- package/dist/lib/capacity/collectors/codex.js +10 -7
- package/dist/lib/capacity/ledger.d.ts +37 -1
- package/dist/lib/capacity/ledger.js +207 -30
- package/dist/lib/capacity/project.d.ts +26 -0
- package/dist/lib/capacity/project.js +137 -8
- package/dist/lib/capacity/refusal-rows.d.ts +31 -0
- package/dist/lib/capacity/refusal-rows.js +61 -0
- package/dist/lib/capacity/refusal.d.ts +53 -2
- package/dist/lib/capacity/refusal.js +284 -65
- package/dist/lib/capacity/route.js +46 -11
- package/dist/lib/capacity/widget.d.ts +12 -1
- package/dist/lib/capacity/widget.js +91 -3
- package/dist/lib/daemon/resolver.d.ts +2 -0
- package/dist/lib/daemon/resolver.js +3 -0
- package/dist/lib/daemon/run.d.ts +9 -0
- package/dist/lib/daemon/run.js +54 -1
- package/dist/lib/daemon/server.d.ts +2 -0
- package/dist/lib/daemon/server.js +10 -1
- package/dist/lib/daemon/tcc-eperm.d.ts +153 -0
- package/dist/lib/daemon/tcc-eperm.js +310 -0
- package/dist/lib/delivery/admission.d.ts +86 -0
- package/dist/lib/delivery/admission.js +148 -0
- package/dist/lib/delivery/artifacts.d.ts +7 -1
- package/dist/lib/delivery/artifacts.js +29 -10
- package/dist/lib/delivery/attempt-id.d.ts +13 -0
- package/dist/lib/delivery/attempt-id.js +16 -0
- package/dist/lib/delivery/disposable-target.d.ts +42 -0
- package/dist/lib/delivery/disposable-target.js +111 -0
- package/dist/lib/delivery/effects.d.ts +136 -0
- package/dist/lib/delivery/effects.js +541 -0
- package/dist/lib/delivery/enrollment.d.ts +21 -17
- package/dist/lib/delivery/enrollment.js +83 -5
- package/dist/lib/delivery/escalations.d.ts +51 -0
- package/dist/lib/delivery/escalations.js +60 -0
- package/dist/lib/delivery/lease.d.ts +80 -0
- package/dist/lib/delivery/lease.js +134 -0
- package/dist/lib/delivery/migrations.d.ts +120 -4
- package/dist/lib/delivery/migrations.js +215 -15
- package/dist/lib/delivery/mqtt.d.ts +2 -0
- package/dist/lib/delivery/mqtt.js +7 -0
- package/dist/lib/delivery/reconciler.d.ts +65 -1
- package/dist/lib/delivery/reconciler.js +224 -13
- package/dist/lib/delivery/rpc/client.d.ts +22 -0
- package/dist/lib/delivery/rpc/client.js +159 -0
- package/dist/lib/delivery/rpc/port.d.ts +40 -0
- package/dist/lib/delivery/rpc/port.js +16 -0
- package/dist/lib/delivery/rpc/server.d.ts +30 -0
- package/dist/lib/delivery/rpc/server.js +205 -0
- package/dist/lib/delivery/rpc/wire.d.ts +85 -0
- package/dist/lib/delivery/rpc/wire.js +143 -0
- package/dist/lib/delivery/store.d.ts +2 -0
- package/dist/lib/delivery/store.js +4 -0
- package/dist/lib/delivery/windows-service-install.d.ts +262 -0
- package/dist/lib/delivery/windows-service-install.js +892 -0
- package/dist/lib/delivery/workers/macos.d.ts +16 -1
- package/dist/lib/delivery/workers/macos.js +54 -12
- package/dist/lib/delivery/workers/windows-service-live.d.ts +121 -0
- package/dist/lib/delivery/workers/windows-service-live.js +711 -0
- package/dist/lib/delivery/workers/windows-service-runner.d.ts +33 -0
- package/dist/lib/delivery/workers/windows-service-runner.js +82 -0
- package/dist/lib/delivery/workers/windows-service.d.ts +140 -0
- package/dist/lib/delivery/workers/windows-service.js +584 -0
- package/dist/lib/delivery/workers/windows.d.ts +32 -22
- package/dist/lib/delivery/workers/windows.js +50 -64
- package/dist/lib/hot-channels/adapters/meetings.d.ts +15 -0
- package/dist/lib/hot-channels/adapters/meetings.js +36 -3
- package/dist/lib/hot-channels/signals-pass.d.ts +10 -0
- package/dist/lib/hot-channels/signals-pass.js +71 -2
- package/dist/lib/hot-channels/signals-redo.js +10 -2
- package/dist/lib/lanes/watcher.js +35 -0
- package/dist/lib/signals/steps/extract.js +40 -4
- package/dist/schemas/hq-available-ai.v1.schema.json +76 -0
- package/dist/utils/catalog-runtime-paths.d.ts +34 -0
- package/dist/utils/catalog-runtime-paths.js +53 -0
- package/dist/utils/files-browse-acl.js +1 -1
- package/package.json +7 -7
- package/dist/lib/delivery/workers/windows-boundary.d.ts +0 -453
- package/dist/lib/delivery/workers/windows-boundary.js +0 -693
|
@@ -24,12 +24,16 @@ export const STORE_SCHEMA_V3 = "hq-delivery.store.v3";
|
|
|
24
24
|
export const STORE_SCHEMA_V4 = "hq-delivery.store.v4";
|
|
25
25
|
/** v5 (US-008) adds artifact provenance records and cache entries. */
|
|
26
26
|
export const STORE_SCHEMA_V5 = "hq-delivery.store.v5";
|
|
27
|
+
/** v6 (US-009) adds the deployment ledger: policy decisions and fenced deployments. */
|
|
28
|
+
export const STORE_SCHEMA_V6 = "hq-delivery.store.v6";
|
|
29
|
+
/** v7 (US-011 slice 4) adds a claim lease to every attempt (leaseExpiresAt). */
|
|
30
|
+
export const STORE_SCHEMA_V7 = "hq-delivery.store.v7";
|
|
27
31
|
/** The store schema version this code writes. */
|
|
28
|
-
export const STORE_SCHEMA_VERSION =
|
|
32
|
+
export const STORE_SCHEMA_VERSION = STORE_SCHEMA_V7;
|
|
29
33
|
/** Every version this code can open, oldest first. Older ones migrate forward on open. */
|
|
30
|
-
export const KNOWN_STORE_SCHEMA_VERSIONS = [STORE_SCHEMA_V1, STORE_SCHEMA_V2, STORE_SCHEMA_V3, STORE_SCHEMA_V4, STORE_SCHEMA_V5];
|
|
34
|
+
export const KNOWN_STORE_SCHEMA_VERSIONS = [STORE_SCHEMA_V1, STORE_SCHEMA_V2, STORE_SCHEMA_V3, STORE_SCHEMA_V4, STORE_SCHEMA_V5, STORE_SCHEMA_V6, STORE_SCHEMA_V7];
|
|
31
35
|
const VERSION_PATTERN = /^hq-delivery\.store\.v(\d+)$/;
|
|
32
|
-
const CURRENT_VERSION_NUMBER =
|
|
36
|
+
const CURRENT_VERSION_NUMBER = 7;
|
|
33
37
|
/** Every refusal from the delivery store. The message reads "CODE: found ...; expected .... action". */
|
|
34
38
|
export class DeliveryStoreError extends Error {
|
|
35
39
|
code;
|
|
@@ -47,8 +51,25 @@ export class DeliveryStoreError extends Error {
|
|
|
47
51
|
}
|
|
48
52
|
export const WORKER_CAPABILITIES = ["claim", "read", "report"];
|
|
49
53
|
export const WORKER_TRUSTS = ["standard", "release"];
|
|
54
|
+
export const DEPLOYMENT_STATUSES = ["blocked", "in-flight", "unknown", "applied", "not-applied", "rejected"];
|
|
55
|
+
export const DECISION_CODES = [
|
|
56
|
+
"POLICY_INVALID",
|
|
57
|
+
"POLICY_MISSING",
|
|
58
|
+
"POLICY_TAMPERED",
|
|
59
|
+
"ENVIRONMENT_UNLISTED",
|
|
60
|
+
"ENVIRONMENT_UNAPPROVED",
|
|
61
|
+
"TARGET_MISMATCH",
|
|
62
|
+
"ATTEMPT_NOT_CURRENT",
|
|
63
|
+
"ARTIFACT_UNKNOWN",
|
|
64
|
+
"ARTIFACT_OTHER_TENANT",
|
|
65
|
+
"ARTIFACT_UNTRUSTED",
|
|
66
|
+
"ARTIFACT_CHANGED",
|
|
67
|
+
"ARTIFACT_UNPROMOTED",
|
|
68
|
+
"SOURCE_NOT_ALLOWED",
|
|
69
|
+
];
|
|
70
|
+
export const OBSERVATION_SOURCES = ["apply-response", "apply-rejected", "transport-error", "stale-publication", "lease-lost", "target-query"];
|
|
50
71
|
export function emptyState() {
|
|
51
|
-
return { epoch: 0, controllers: [], runs: [], jobs: [], attempts: [], workers: [], artifacts: [], cache: [] };
|
|
72
|
+
return { epoch: 0, controllers: [], runs: [], jobs: [], attempts: [], workers: [], artifacts: [], cache: [], deployments: [], deployPolicies: [] };
|
|
52
73
|
}
|
|
53
74
|
export function stateChecksum(state) {
|
|
54
75
|
return createHash("sha256").update(JSON.stringify(state)).digest("hex");
|
|
@@ -101,15 +122,20 @@ export function parseStoreText(text, source) {
|
|
|
101
122
|
action: "Check that this directory is a delivery store. The store was not changed; restore it from a backup or move it aside.",
|
|
102
123
|
});
|
|
103
124
|
}
|
|
104
|
-
const
|
|
125
|
+
const envelope = () => readEnvelope(parsed, source);
|
|
126
|
+
const state = version === STORE_SCHEMA_V7
|
|
105
127
|
? readEnvelope(parsed, source)
|
|
106
|
-
: version ===
|
|
107
|
-
?
|
|
108
|
-
: version ===
|
|
109
|
-
?
|
|
110
|
-
: version ===
|
|
111
|
-
?
|
|
112
|
-
:
|
|
128
|
+
: version === STORE_SCHEMA_V6
|
|
129
|
+
? migrateV6(envelope(), source)
|
|
130
|
+
: version === STORE_SCHEMA_V5
|
|
131
|
+
? migrateV6(migrateV5(envelope(), source), source)
|
|
132
|
+
: version === STORE_SCHEMA_V4
|
|
133
|
+
? migrateV6(migrateV5(migrateV4(envelope(), source), source), source)
|
|
134
|
+
: version === STORE_SCHEMA_V3
|
|
135
|
+
? migrateV6(migrateV5(migrateV4(migrateV3(envelope(), source), source), source), source)
|
|
136
|
+
: version === STORE_SCHEMA_V2
|
|
137
|
+
? migrateV6(migrateV5(migrateV4(migrateV3(migrateV2(envelope(), source), source), source), source), source)
|
|
138
|
+
: migrateV6(migrateV5(migrateV4(migrateV1(parsed, source), source), source), source);
|
|
113
139
|
const errors = validateState(state);
|
|
114
140
|
if (errors.length > 0)
|
|
115
141
|
throw invalidStore(source, errors);
|
|
@@ -131,9 +157,37 @@ function invalidStore(source, errors) {
|
|
|
131
157
|
function migrateV4(state, source) {
|
|
132
158
|
if ("artifacts" in state || "cache" in state)
|
|
133
159
|
throw invalidStore(source, ["v4 state has an artifacts or cache field; v4 has none"]);
|
|
160
|
+
if ("deployments" in state || "deployPolicies" in state)
|
|
161
|
+
throw invalidStore(source, ["v4 state has a deployments or deployPolicies field; v4 has none"]);
|
|
134
162
|
return { ...state, artifacts: [], cache: [] };
|
|
135
163
|
}
|
|
136
|
-
/**
|
|
164
|
+
/**
|
|
165
|
+
* v5 → v6. v6 adds the deployment ledger, which starts empty. The v5
|
|
166
|
+
* checksum is checked first, by readEnvelope.
|
|
167
|
+
*/
|
|
168
|
+
function migrateV5(state, source) {
|
|
169
|
+
if ("deployments" in state || "deployPolicies" in state)
|
|
170
|
+
throw invalidStore(source, ["v5 state has a deployments or deployPolicies field; v5 has none"]);
|
|
171
|
+
return { ...state, deployments: [], deployPolicies: [] };
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* v6 → v7. v7 adds leaseExpiresAt to every attempt. v6 had no claim lease, so
|
|
175
|
+
* every migrated attempt gets null: it never expires and behaves exactly as it
|
|
176
|
+
* did. An open v6 attempt is from an older epoch and is abandoned by the
|
|
177
|
+
* recovery rule when a controller opens, as before. The v6 checksum is checked
|
|
178
|
+
* first, by readEnvelope.
|
|
179
|
+
*/
|
|
180
|
+
function migrateV6(state, source) {
|
|
181
|
+
if (!Array.isArray(state.attempts))
|
|
182
|
+
return state;
|
|
183
|
+
const attempts = state.attempts.map((a) => {
|
|
184
|
+
if (typeof a === "object" && a !== null && "leaseExpiresAt" in a)
|
|
185
|
+
throw invalidStore(source, ["v6 attempt has a leaseExpiresAt field; v6 has none"]);
|
|
186
|
+
return { ...a, leaseExpiresAt: null };
|
|
187
|
+
});
|
|
188
|
+
return { ...state, attempts };
|
|
189
|
+
}
|
|
190
|
+
/** The v2 to v7 file envelope: exactly storeSchemaVersion, sha256 and state, with a matching checksum. */
|
|
137
191
|
function readEnvelope(parsed, source) {
|
|
138
192
|
const keys = Object.keys(parsed).sort().join(",");
|
|
139
193
|
if (keys !== "sha256,state,storeSchemaVersion" || typeof parsed.sha256 !== "string" || !isObject(parsed.state)) {
|
|
@@ -294,7 +348,7 @@ function checkRecord(kind, input, where, errors) {
|
|
|
294
348
|
/** All problems with a store state, or [] when it is valid. Never throws. */
|
|
295
349
|
export function validateState(input) {
|
|
296
350
|
const errors = [];
|
|
297
|
-
if (!hasExactKeys(input, ["epoch", "controllers", "runs", "jobs", "attempts", "workers", "artifacts", "cache"], "state", errors))
|
|
351
|
+
if (!hasExactKeys(input, ["epoch", "controllers", "runs", "jobs", "attempts", "workers", "artifacts", "cache", "deployments", "deployPolicies"], "state", errors))
|
|
298
352
|
return errors;
|
|
299
353
|
const epoch = isCount(input.epoch) ? input.epoch : null;
|
|
300
354
|
if (epoch === null)
|
|
@@ -389,10 +443,14 @@ export function validateState(input) {
|
|
|
389
443
|
const perJob = new Map();
|
|
390
444
|
arrayAt(input, "attempts", errors).forEach((entry, i) => {
|
|
391
445
|
const where = `attempts[${i}]`;
|
|
392
|
-
if (!hasExactKeys(entry, ["record", "claimedAt", "claimedEpoch", "claimedBy", "resolution", "resolvedAt", "resolvedEpoch"], where, errors))
|
|
446
|
+
if (!hasExactKeys(entry, ["record", "claimedAt", "claimedEpoch", "claimedBy", "leaseExpiresAt", "resolution", "resolvedAt", "resolvedEpoch"], where, errors))
|
|
393
447
|
return;
|
|
394
448
|
if (entry.claimedBy !== null && (typeof entry.claimedBy !== "string" || entry.claimedBy === ""))
|
|
395
449
|
errors.push(`${where}.claimedBy: not a workerId or null`);
|
|
450
|
+
if (!isTimeOrNull(entry.leaseExpiresAt))
|
|
451
|
+
errors.push(`${where}.leaseExpiresAt: not a timestamp or null`);
|
|
452
|
+
else if (entry.leaseExpiresAt !== null && entry.claimedBy === null)
|
|
453
|
+
errors.push(`${where}.leaseExpiresAt: a lease needs the worker that claimed the attempt`);
|
|
396
454
|
if (!isTimeOrNull(entry.claimedAt))
|
|
397
455
|
errors.push(`${where}.claimedAt: not a timestamp or null`);
|
|
398
456
|
if (!isTimeOrNull(entry.resolvedAt))
|
|
@@ -496,6 +554,8 @@ export function validateState(input) {
|
|
|
496
554
|
errors.push(`${where}.status: unknown ${JSON.stringify(w.status)}`);
|
|
497
555
|
});
|
|
498
556
|
validateArtifacts(input, attemptsById, checkEpoch, errors);
|
|
557
|
+
validateDeployments(input, attemptsById, checkEpoch, errors);
|
|
558
|
+
validateDeployPolicies(input, checkEpoch, errors);
|
|
499
559
|
return errors;
|
|
500
560
|
}
|
|
501
561
|
const isHex64 = (v) => typeof v === "string" && SHA256_HEX.test(v);
|
|
@@ -620,4 +680,144 @@ function validateArtifacts(input, attempts, checkEpoch, errors) {
|
|
|
620
680
|
}
|
|
621
681
|
});
|
|
622
682
|
}
|
|
683
|
+
const DEPLOYMENT_KEYS = [
|
|
684
|
+
"deploymentId",
|
|
685
|
+
"tenantId",
|
|
686
|
+
"environment",
|
|
687
|
+
"artifactId",
|
|
688
|
+
"digest",
|
|
689
|
+
"workerId",
|
|
690
|
+
"attemptId",
|
|
691
|
+
"targetId",
|
|
692
|
+
"fence",
|
|
693
|
+
"status",
|
|
694
|
+
"snapshot",
|
|
695
|
+
"snapshotDigest",
|
|
696
|
+
"snapshotSignature",
|
|
697
|
+
"decision",
|
|
698
|
+
"requestedAt",
|
|
699
|
+
"requestedEpoch",
|
|
700
|
+
"resolvedAt",
|
|
701
|
+
"resolvedEpoch",
|
|
702
|
+
"observation",
|
|
703
|
+
];
|
|
704
|
+
/**
|
|
705
|
+
* US-009 deployment ledger. Each snapshot must hash to its snapshotDigest, so
|
|
706
|
+
* an edited snapshot does not open even with the store checksum recomputed.
|
|
707
|
+
* Fences are unique per tenant/environment and at most one deployment per
|
|
708
|
+
* tenant/environment is in flight or unknown.
|
|
709
|
+
*/
|
|
710
|
+
function validateDeployments(input, attempts, checkEpoch, errors) {
|
|
711
|
+
const ids = new Set();
|
|
712
|
+
const fences = new Map();
|
|
713
|
+
const open = new Set();
|
|
714
|
+
arrayAt(input, "deployments", errors).forEach((d, i) => {
|
|
715
|
+
const where = `deployments[${i}]`;
|
|
716
|
+
if (!hasExactKeys(d, DEPLOYMENT_KEYS, where, errors))
|
|
717
|
+
return;
|
|
718
|
+
for (const key of ["deploymentId", "tenantId", "environment", "artifactId", "digest", "workerId", "attemptId"]) {
|
|
719
|
+
if (!isText(d[key]))
|
|
720
|
+
errors.push(`${where}.${key}: not a non-empty string`);
|
|
721
|
+
}
|
|
722
|
+
if (isText(d.deploymentId)) {
|
|
723
|
+
if (ids.has(d.deploymentId))
|
|
724
|
+
errors.push(`${where}: duplicate deploymentId ${d.deploymentId}`);
|
|
725
|
+
ids.add(d.deploymentId);
|
|
726
|
+
}
|
|
727
|
+
if (d.targetId !== null && !isText(d.targetId))
|
|
728
|
+
errors.push(`${where}.targetId: not a string or null`);
|
|
729
|
+
const status = d.status;
|
|
730
|
+
if (!DEPLOYMENT_STATUSES.includes(status))
|
|
731
|
+
errors.push(`${where}.status: unknown ${JSON.stringify(d.status)}`);
|
|
732
|
+
if (!isTimeOrNull(d.requestedAt) || d.requestedAt === null)
|
|
733
|
+
errors.push(`${where}.requestedAt: not a timestamp`);
|
|
734
|
+
checkEpoch(d.requestedEpoch, `${where}.requestedEpoch`);
|
|
735
|
+
if (!isTimeOrNull(d.resolvedAt))
|
|
736
|
+
errors.push(`${where}.resolvedAt: not a timestamp or null`);
|
|
737
|
+
if (d.resolvedEpoch !== null)
|
|
738
|
+
checkEpoch(d.resolvedEpoch, `${where}.resolvedEpoch`);
|
|
739
|
+
if (!isObject(d.snapshot))
|
|
740
|
+
errors.push(`${where}.snapshot: not an object`);
|
|
741
|
+
else {
|
|
742
|
+
if (d.snapshotDigest !== sha256Hex(canonicalJson(d.snapshot)))
|
|
743
|
+
errors.push(`${where}.snapshotDigest: does not match the snapshot`);
|
|
744
|
+
const sig = d.snapshotSignature;
|
|
745
|
+
if (!isObject(sig) || sig.algorithm !== "hmac-sha256" || !isText(sig.keyRef) || !isHex64(sig.value))
|
|
746
|
+
errors.push(`${where}.snapshotSignature: not an hmac-sha256 signature`);
|
|
747
|
+
const ctx = d.snapshot.context;
|
|
748
|
+
if (!isObject(ctx) || ctx.tenantId !== d.tenantId || ctx.environment !== d.environment || ctx.attemptId !== d.attemptId || ctx.workerId !== d.workerId) {
|
|
749
|
+
errors.push(`${where}.snapshot.context: does not name this deployment's tenant, environment, worker and attempt`);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
const key = `${String(d.tenantId)}\u0000${String(d.environment)}`;
|
|
753
|
+
if (status === "blocked") {
|
|
754
|
+
if (d.fence !== null)
|
|
755
|
+
errors.push(`${where}.fence: a blocked request has no fence`);
|
|
756
|
+
const dec = d.decision;
|
|
757
|
+
if (!hasExactKeys(dec, ["code", "found", "scope", "escalateTo", "resolution"], `${where}.decision`, errors))
|
|
758
|
+
return;
|
|
759
|
+
if (!DECISION_CODES.includes(dec.code))
|
|
760
|
+
errors.push(`${where}.decision.code: unknown ${JSON.stringify(dec.code)}`);
|
|
761
|
+
const scope = dec.scope;
|
|
762
|
+
if (!isObject(scope) || scope.tenantId !== d.tenantId || scope.environment !== d.environment)
|
|
763
|
+
errors.push(`${where}.decision.scope: not this deployment's tenant and environment`);
|
|
764
|
+
if (!isText(dec.escalateTo) || dec.resolution !== "pending" || typeof dec.found !== "string")
|
|
765
|
+
errors.push(`${where}.decision: malformed`);
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
if (d.decision !== null)
|
|
769
|
+
errors.push(`${where}.decision: only a blocked request has a decision`);
|
|
770
|
+
if (typeof d.fence !== "number" || !Number.isInteger(d.fence) || d.fence < 1)
|
|
771
|
+
errors.push(`${where}.fence: not a positive integer`);
|
|
772
|
+
else {
|
|
773
|
+
const seen = fences.get(key) ?? new Set();
|
|
774
|
+
if (seen.has(d.fence))
|
|
775
|
+
errors.push(`${where}.fence: duplicate fence ${d.fence} for this tenant and environment`);
|
|
776
|
+
seen.add(d.fence);
|
|
777
|
+
fences.set(key, seen);
|
|
778
|
+
}
|
|
779
|
+
const attempt = typeof d.attemptId === "string" ? attempts.get(d.attemptId) : undefined;
|
|
780
|
+
if (!attempt)
|
|
781
|
+
errors.push(`${where}.attemptId: no attempt ${String(d.attemptId)}`);
|
|
782
|
+
else if (attempt.tenantId !== d.tenantId)
|
|
783
|
+
errors.push(`${where}.attemptId: attempt of another tenant`);
|
|
784
|
+
if (status === "in-flight" || status === "unknown") {
|
|
785
|
+
if (open.has(key))
|
|
786
|
+
errors.push(`${where}: a second in-flight or unknown deployment for this tenant and environment`);
|
|
787
|
+
open.add(key);
|
|
788
|
+
}
|
|
789
|
+
if (d.observation !== null) {
|
|
790
|
+
const o = d.observation;
|
|
791
|
+
if (!hasExactKeys(o, ["source", "detail", "fence", "digest"], `${where}.observation`, errors))
|
|
792
|
+
return;
|
|
793
|
+
if (!OBSERVATION_SOURCES.includes(o.source))
|
|
794
|
+
errors.push(`${where}.observation.source: unknown ${JSON.stringify(o.source)}`);
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
function validateDeployPolicies(input, checkEpoch, errors) {
|
|
799
|
+
const tenants = new Set();
|
|
800
|
+
arrayAt(input, "deployPolicies", errors).forEach((p, i) => {
|
|
801
|
+
const where = `deployPolicies[${i}]`;
|
|
802
|
+
if (!hasExactKeys(p, ["tenantId", "policy", "setBy", "setAt", "setEpoch", "signature"], where, errors))
|
|
803
|
+
return;
|
|
804
|
+
if (!isText(p.tenantId))
|
|
805
|
+
errors.push(`${where}.tenantId: not a non-empty string`);
|
|
806
|
+
else if (tenants.has(p.tenantId))
|
|
807
|
+
errors.push(`${where}: a second policy for ${p.tenantId}`);
|
|
808
|
+
else
|
|
809
|
+
tenants.add(p.tenantId);
|
|
810
|
+
if (!isObject(p.policy) || p.policy.tenantId !== p.tenantId)
|
|
811
|
+
errors.push(`${where}.policy: not a policy of ${String(p.tenantId)}`);
|
|
812
|
+
if (!isText(p.setBy))
|
|
813
|
+
errors.push(`${where}.setBy: not a credential ref`);
|
|
814
|
+
if (!isTimeOrNull(p.setAt) || p.setAt === null)
|
|
815
|
+
errors.push(`${where}.setAt: not a timestamp`);
|
|
816
|
+
checkEpoch(p.setEpoch, `${where}.setEpoch`);
|
|
817
|
+
const s = p.signature;
|
|
818
|
+
if (!hasExactKeys(s, ["algorithm", "keyRef", "value"], `${where}.signature`, errors) || s.algorithm !== "hmac-sha256" || !isText(s.keyRef) || !isHex64(s.value)) {
|
|
819
|
+
errors.push(`${where}.signature: not an hmac-sha256 signature`);
|
|
820
|
+
}
|
|
821
|
+
});
|
|
822
|
+
}
|
|
623
823
|
//# sourceMappingURL=migrations.js.map
|
|
@@ -25,6 +25,8 @@ export interface NotificationBroker {
|
|
|
25
25
|
subscribe(filter: string, handler: BrokerHandler): () => void;
|
|
26
26
|
}
|
|
27
27
|
export declare const NOTIFICATION_TOPIC_ROOT = "hq/delivery/v1";
|
|
28
|
+
/** US-009: escalated deployment decisions for a company's admins. Separate from worker events. */
|
|
29
|
+
export declare function escalationTopic(tenantId: string): string;
|
|
28
30
|
/** The one topic a tenant's notifications use. Tenant ids that could widen a filter are refused. */
|
|
29
31
|
export declare function notificationTopic(tenantId: string): string;
|
|
30
32
|
/** MQTT topic filter matching with `+` (one level) and a trailing `#` (any remaining levels). */
|
|
@@ -13,6 +13,13 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export const NOTIFICATION_TOPIC_ROOT = "hq/delivery/v1";
|
|
15
15
|
const TOPIC_SEGMENT = /^[A-Za-z0-9._-]+$/;
|
|
16
|
+
/** US-009: escalated deployment decisions for a company's admins. Separate from worker events. */
|
|
17
|
+
export function escalationTopic(tenantId) {
|
|
18
|
+
if (!TOPIC_SEGMENT.test(tenantId)) {
|
|
19
|
+
throw new Error("tenant id is not a valid notification topic segment");
|
|
20
|
+
}
|
|
21
|
+
return `${NOTIFICATION_TOPIC_ROOT}/${tenantId}/escalations`;
|
|
22
|
+
}
|
|
16
23
|
/** The one topic a tenant's notifications use. Tenant ids that could widen a filter are refused. */
|
|
17
24
|
export function notificationTopic(tenantId) {
|
|
18
25
|
if (!TOPIC_SEGMENT.test(tenantId)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Attempt, type Job, type Run } from "./contracts.js";
|
|
2
|
-
import { DeliveryStoreError, type AttemptResolution, type StoredWorker, type StoreState } from "./migrations.js";
|
|
2
|
+
import { DeliveryStoreError, type AttemptResolution, type StoredAttempt, type StoredDeployment, type StoredDeployPolicy, type StoredWorker, type StoreState } from "./migrations.js";
|
|
3
3
|
import { type LedgerEvent } from "./outbox.js";
|
|
4
4
|
import type { StoredArtifact, StoredCacheEntry } from "./provenance.js";
|
|
5
5
|
import { type OpenReport, type StoreOpenOptions } from "./store.js";
|
|
@@ -7,6 +7,17 @@ export { DeliveryStoreError } from "./migrations.js";
|
|
|
7
7
|
export interface ControllerOptions extends StoreOpenOptions {
|
|
8
8
|
/** Attempt id generator. Default `attempt-<uuid>`. */
|
|
9
9
|
ids?: () => string;
|
|
10
|
+
/** Lease of a worker's claim, in ms on the store clock. A positive integer. Default DEFAULT_CLAIM_LEASE_MS. */
|
|
11
|
+
claimLeaseMs?: number;
|
|
12
|
+
}
|
|
13
|
+
/** Default claim lease: 120 s. A worker renews it every third of that (startLeaseHeartbeat). */
|
|
14
|
+
export declare const DEFAULT_CLAIM_LEASE_MS = 120000;
|
|
15
|
+
/** True when `a` is open, has a lease, and the lease time has been reached at `nowMs`. */
|
|
16
|
+
export declare function leaseExpired(a: StoredAttempt, nowMs: number): boolean;
|
|
17
|
+
/** The result of renewLease: the attempt and its new lease time. */
|
|
18
|
+
export interface LeaseView {
|
|
19
|
+
attemptId: string;
|
|
20
|
+
leaseExpiresAt: string;
|
|
10
21
|
}
|
|
11
22
|
export interface JobInput {
|
|
12
23
|
job: Job;
|
|
@@ -54,10 +65,13 @@ export declare class DeliveryController {
|
|
|
54
65
|
readonly recovery: RecoveryReport;
|
|
55
66
|
private readonly store;
|
|
56
67
|
private readonly ids;
|
|
68
|
+
private readonly leaseMs;
|
|
57
69
|
private constructor();
|
|
58
70
|
static open(opts: ControllerOptions): DeliveryController;
|
|
59
71
|
/** The fencing epoch this controller writes with. */
|
|
60
72
|
get epoch(): number;
|
|
73
|
+
/** ISO timestamp from the store clock, the one commits are stamped with. */
|
|
74
|
+
now(): string;
|
|
61
75
|
runs(): Run[];
|
|
62
76
|
jobs(runId?: string): JobView[];
|
|
63
77
|
/** One job's view, or undefined when no such job was accepted. Scans the attempts once, not once per job. */
|
|
@@ -105,6 +119,42 @@ export declare class DeliveryController {
|
|
|
105
119
|
returnAttempt(attemptId: string, opts?: {
|
|
106
120
|
guard?: CommitGuard;
|
|
107
121
|
}): AttemptView;
|
|
122
|
+
/**
|
|
123
|
+
* Extend the lease of an open attempt to now + claimLeaseMs on the store clock.
|
|
124
|
+
* Refused with ATTEMPT_ABANDONED when the lease has already expired (at
|
|
125
|
+
* exactly leaseExpiresAt it has), with ATTEMPT_CONFLICT for a reported attempt
|
|
126
|
+
* or one without a lease, and ACCESS_DENIED for another claimant. The guard and
|
|
127
|
+
* every check run again inside the commit, so the renewal and the expiry it
|
|
128
|
+
* races are decided once, at one clock reading.
|
|
129
|
+
*/
|
|
130
|
+
renewLease(attemptId: string, opts?: {
|
|
131
|
+
guard?: CommitGuard;
|
|
132
|
+
workerId?: string;
|
|
133
|
+
}): LeaseView;
|
|
134
|
+
/** The lease time of an attempt, or null when it has none. */
|
|
135
|
+
leaseExpiresAt(attemptId: string): string | null;
|
|
136
|
+
/** The claim lease length in ms that this controller gives a worker's claim. A heartbeat derives its period from it. */
|
|
137
|
+
get claimLeaseMs(): number;
|
|
138
|
+
/** True when the attempt is open under a lease that has run out on the store clock, but has not been swept yet. */
|
|
139
|
+
leaseLapsed(attemptId: string): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Abandon every open attempt whose lease has run out at the store clock's
|
|
142
|
+
* current time, in one commit. Returns the abandoned attemptIds (none: no commit).
|
|
143
|
+
*/
|
|
144
|
+
expireLeases(): string[];
|
|
145
|
+
/** Abandon the attempts whose lease has run out at `nowMs`. One commit, or none when nothing has expired. */
|
|
146
|
+
private expireDue;
|
|
147
|
+
/**
|
|
148
|
+
* Revoke a worker and abandon its open attempts in the same fenced commit, so
|
|
149
|
+
* a revoked worker's claims are freed at once. `mutate` changes the worker
|
|
150
|
+
* records and may throw to refuse; nothing is written then. Returns the
|
|
151
|
+
* abandoned attemptIds.
|
|
152
|
+
* @internal Used by enrollment.ts revoke().
|
|
153
|
+
*/
|
|
154
|
+
commitRevocation(workerId: string, mutate: (workers: StoredWorker[], at: {
|
|
155
|
+
epoch: number;
|
|
156
|
+
now: string;
|
|
157
|
+
}) => void): string[];
|
|
108
158
|
/**
|
|
109
159
|
* Throw unless this handle still owns the store: STORE_CLOSED for a closed
|
|
110
160
|
* or failed handle, FENCED when another controller has taken over. Read only.
|
|
@@ -142,6 +192,20 @@ export declare class DeliveryController {
|
|
|
142
192
|
epoch: number;
|
|
143
193
|
now: string;
|
|
144
194
|
}) => void): void;
|
|
195
|
+
/** US-009: copies of the deployment ledger. */
|
|
196
|
+
deploymentRecords(): StoredDeployment[];
|
|
197
|
+
/** US-009: copies of the stored company deploy policies. */
|
|
198
|
+
deployPolicyRecords(): StoredDeployPolicy[];
|
|
199
|
+
/**
|
|
200
|
+
* Change the deployment ledger in one fenced store commit. `mutate` gets the
|
|
201
|
+
* whole draft so it can re-check attempts against the state being written;
|
|
202
|
+
* it may throw to refuse, and nothing is written then.
|
|
203
|
+
* @internal Used by effects.ts; other callers must not write deployments.
|
|
204
|
+
*/
|
|
205
|
+
commitDeployments(mutate: (draft: StoreState, at: {
|
|
206
|
+
epoch: number;
|
|
207
|
+
now: string;
|
|
208
|
+
}) => void): void;
|
|
145
209
|
/** Release ownership of the store. Idempotent. */
|
|
146
210
|
close(): void;
|
|
147
211
|
private unknownJob;
|