@kya-os/checkpoint-shared 1.2.1 → 1.3.0

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.
@@ -3,6 +3,7 @@
3
3
  var zod = require('zod');
4
4
 
5
5
  // src/deploy/index.ts
6
+ var KYA_OS_EVENTS_PATH = "/api/v1/kya-os/events";
6
7
  var DidStringSchema = zod.z.string().min(8, "DID must be at least 8 characters").regex(/^did:[a-z0-9]+:\S+$/, "DID must match format did:<method>:<method-specific-id>");
7
8
  var FlyRegionSchema = zod.z.enum([
8
9
  "ams",
@@ -74,7 +75,232 @@ var FlyRegionSchema = zod.z.enum([
74
75
  "yyz"
75
76
  // Toronto, Canada
76
77
  ]);
77
- var HostingModeSchema = zod.z.enum(["byok", "managed"]);
78
+ var HostingModeSchema = zod.z.enum(["byok", "managed", "managed-byoa"]);
79
+ var AuditAssuranceProfileSchema = zod.z.enum(["AAP-0", "AAP-1", "AAP-2", "AAP-3", "AAP-4"]);
80
+ var AuditDeliveryModeSchema = zod.z.enum(["best-effort", "buffered", "required"]);
81
+ var AuditDeploymentConfigSchema = zod.z.object({
82
+ enabled: zod.z.boolean(),
83
+ requestedProfile: AuditAssuranceProfileSchema,
84
+ delivery: AuditDeliveryModeSchema,
85
+ evidenceMode: zod.z.enum(["none", "encrypted-separate", "encrypted-inline"]),
86
+ retentionClass: zod.z.string().min(1).max(128),
87
+ retentionDays: zod.z.number().int().min(0).max(3650),
88
+ residency: zod.z.enum(["inherit-project", "us", "eu", "global"]),
89
+ keyCustody: zod.z.enum(["none", "checkpoint-managed", "customer-managed-kms"]),
90
+ recorderTopology: zod.z.enum(["none", "self-hosted", "managed", "verified-mirror"])
91
+ }).strict().superRefine((value, context) => {
92
+ if (!value.enabled && value.requestedProfile !== "AAP-0") {
93
+ context.addIssue({
94
+ code: zod.z.ZodIssueCode.custom,
95
+ path: ["requestedProfile"],
96
+ message: "Disabled audit configuration must request AAP-0"
97
+ });
98
+ }
99
+ if (value.enabled && value.requestedProfile === "AAP-0") {
100
+ context.addIssue({
101
+ code: zod.z.ZodIssueCode.custom,
102
+ path: ["requestedProfile"],
103
+ message: "Enabled audit configuration must request AAP-1 or higher"
104
+ });
105
+ }
106
+ if (Number(value.requestedProfile.slice(-1)) >= 2 && value.delivery === "best-effort") {
107
+ context.addIssue({
108
+ code: zod.z.ZodIssueCode.custom,
109
+ path: ["delivery"],
110
+ message: "AAP-2 or higher cannot use best-effort delivery"
111
+ });
112
+ }
113
+ if (!value.enabled && (value.keyCustody !== "none" || value.recorderTopology !== "none")) {
114
+ context.addIssue({
115
+ code: zod.z.ZodIssueCode.custom,
116
+ message: "Disabled audit configuration cannot claim key custody or recorder topology"
117
+ });
118
+ }
119
+ });
120
+ var NEW_MANAGED_AUDIT_DEPLOYMENT_DEFAULT = Object.freeze({
121
+ enabled: true,
122
+ requestedProfile: "AAP-2",
123
+ delivery: "buffered",
124
+ evidenceMode: "encrypted-separate",
125
+ retentionClass: "integrity-ledger",
126
+ retentionDays: 365,
127
+ residency: "inherit-project",
128
+ keyCustody: "checkpoint-managed",
129
+ recorderTopology: "managed"
130
+ });
131
+ var ABSENT_AUDIT_DEPLOYMENT_CONFIG = Object.freeze({
132
+ enabled: false,
133
+ requestedProfile: "AAP-0",
134
+ delivery: "best-effort",
135
+ evidenceMode: "none",
136
+ retentionClass: "none",
137
+ retentionDays: 0,
138
+ residency: "inherit-project",
139
+ keyCustody: "none",
140
+ recorderTopology: "none"
141
+ });
142
+ var AuditRuntimeCapabilitiesSchema = zod.z.object({
143
+ recorderTopology: zod.z.enum(["none", "self-hosted", "managed", "verified-mirror"]),
144
+ delivery: AuditDeliveryModeSchema,
145
+ journalDurability: zod.z.enum(["none", "ephemeral", "durable"]),
146
+ atomicAppend: zod.z.boolean(),
147
+ sourceHighWater: zod.z.boolean(),
148
+ merkleCheckpoints: zod.z.boolean(),
149
+ independentObservation: zod.z.boolean(),
150
+ supportingAnchors: zod.z.array(zod.z.enum(["worm", "rfc3161", "scitt"])),
151
+ evidenceRetention: zod.z.enum(["none", "inline", "separate"])
152
+ }).strict();
153
+ var AuditRuntimeCanaryResultSchema = zod.z.object({
154
+ passed: zod.z.boolean(),
155
+ observedAt: zod.z.number().int().nonnegative(),
156
+ capabilities: AuditRuntimeCapabilitiesSchema,
157
+ checks: zod.z.array(
158
+ zod.z.object({
159
+ id: zod.z.string().min(1).max(128),
160
+ passed: zod.z.boolean()
161
+ }).strict()
162
+ ).min(1),
163
+ bundleHash: zod.z.string().min(1).max(256).optional()
164
+ }).strict().superRefine((value, context) => {
165
+ if (value.passed !== value.checks.every((check) => check.passed)) {
166
+ context.addIssue({
167
+ code: zod.z.ZodIssueCode.custom,
168
+ path: ["passed"],
169
+ message: "Canary result must equal the aggregate of its mechanical checks"
170
+ });
171
+ }
172
+ });
173
+ function requiredAuditRuntimeCanaryChecks(capabilities) {
174
+ const checks = [
175
+ "recorder_round_trip",
176
+ "verified_receipt",
177
+ "idempotent_retry",
178
+ "event_identity_conflict",
179
+ "source_state"
180
+ ];
181
+ if (capabilities.delivery === "buffered") checks.push("buffered_outbox");
182
+ if (capabilities.evidenceRetention !== "none") checks.push("evidence_write_verified");
183
+ return checks;
184
+ }
185
+ var AuditDeploymentReadinessSchema = zod.z.object({
186
+ requestedProfile: AuditAssuranceProfileSchema,
187
+ effectiveProfile: AuditAssuranceProfileSchema,
188
+ status: zod.z.enum(["disabled", "ready", "degraded"]),
189
+ capabilities: AuditRuntimeCapabilitiesSchema.nullable(),
190
+ canary: AuditRuntimeCanaryResultSchema.nullable(),
191
+ reasonCodes: zod.z.array(zod.z.string().min(1).max(128))
192
+ }).strict();
193
+ var PROFILE_BY_LEVEL = ["AAP-0", "AAP-1", "AAP-2", "AAP-3", "AAP-4"];
194
+ function resolveAuditDeploymentReadiness(config, capabilities, canary) {
195
+ const requested = AuditDeploymentConfigSchema.parse(config ?? ABSENT_AUDIT_DEPLOYMENT_CONFIG);
196
+ const observedCanary = canary ? AuditRuntimeCanaryResultSchema.parse(canary) : null;
197
+ if (!requested.enabled) {
198
+ return {
199
+ requestedProfile: "AAP-0",
200
+ effectiveProfile: "AAP-0",
201
+ status: "disabled",
202
+ capabilities: capabilities ?? null,
203
+ canary: observedCanary,
204
+ reasonCodes: ["audit_not_configured"]
205
+ };
206
+ }
207
+ const observedCapabilities = capabilities ?? observedCanary?.capabilities;
208
+ if (!observedCapabilities) {
209
+ return {
210
+ requestedProfile: requested.requestedProfile,
211
+ effectiveProfile: "AAP-0",
212
+ status: "degraded",
213
+ capabilities: null,
214
+ canary: observedCanary,
215
+ reasonCodes: ["runtime_capabilities_unavailable"]
216
+ };
217
+ }
218
+ const observed = AuditRuntimeCapabilitiesSchema.parse(observedCapabilities);
219
+ if (!observedCanary) {
220
+ return {
221
+ requestedProfile: requested.requestedProfile,
222
+ effectiveProfile: "AAP-0",
223
+ status: "degraded",
224
+ capabilities: observed,
225
+ canary: null,
226
+ reasonCodes: ["runtime_canary_required"]
227
+ };
228
+ }
229
+ if (!observedCanary.passed || JSON.stringify(observedCanary.capabilities) !== JSON.stringify(observed)) {
230
+ return {
231
+ requestedProfile: requested.requestedProfile,
232
+ effectiveProfile: "AAP-0",
233
+ status: "degraded",
234
+ capabilities: observed,
235
+ canary: observedCanary,
236
+ reasonCodes: [
237
+ observedCanary.passed ? "runtime_canary_capability_mismatch" : "runtime_canary_failed"
238
+ ]
239
+ };
240
+ }
241
+ const passedChecks = new Set(
242
+ observedCanary.checks.filter((check) => check.passed).map((check) => check.id)
243
+ );
244
+ if (requiredAuditRuntimeCanaryChecks(observed).some((check) => !passedChecks.has(check))) {
245
+ return {
246
+ requestedProfile: requested.requestedProfile,
247
+ effectiveProfile: "AAP-0",
248
+ status: "degraded",
249
+ capabilities: observed,
250
+ canary: observedCanary,
251
+ reasonCodes: ["runtime_canary_incomplete"]
252
+ };
253
+ }
254
+ let maximum = 0;
255
+ const reasons = [];
256
+ if (observed.recorderTopology !== requested.recorderTopology) {
257
+ reasons.push("recorder_topology_mismatch");
258
+ }
259
+ const deliveryRank = { "best-effort": 0, buffered: 1, required: 2 };
260
+ if (deliveryRank[observed.delivery] < deliveryRank[requested.delivery]) {
261
+ reasons.push("delivery_mode_mismatch");
262
+ }
263
+ const expectedEvidence = requested.evidenceMode === "none" ? "none" : requested.evidenceMode === "encrypted-inline" ? "inline" : "separate";
264
+ if (expectedEvidence !== observed.evidenceRetention) {
265
+ reasons.push("evidence_retention_mismatch");
266
+ }
267
+ if (reasons.length > 0) {
268
+ return {
269
+ requestedProfile: requested.requestedProfile,
270
+ effectiveProfile: "AAP-0",
271
+ status: "degraded",
272
+ capabilities: observed,
273
+ canary: observedCanary,
274
+ reasonCodes: reasons
275
+ };
276
+ }
277
+ if (observed.recorderTopology !== "none" && observed.journalDurability !== "none") maximum = 1;
278
+ else reasons.push("recorder_or_journal_unavailable");
279
+ if (maximum >= 1 && observed.journalDurability === "durable" && observed.atomicAppend && observed.delivery !== "best-effort") {
280
+ maximum = 2;
281
+ } else if (Number(requested.requestedProfile.slice(-1)) >= 2) {
282
+ reasons.push("durable_atomic_buffered_append_unavailable");
283
+ }
284
+ if (maximum >= 2 && observed.merkleCheckpoints && observed.sourceHighWater) maximum = 3;
285
+ else if (Number(requested.requestedProfile.slice(-1)) >= 3) {
286
+ reasons.push("checkpoint_or_source_high_water_unavailable");
287
+ }
288
+ if (maximum >= 3 && observed.independentObservation && observed.supportingAnchors.length > 0) {
289
+ maximum = 4;
290
+ } else if (Number(requested.requestedProfile.slice(-1)) >= 4) {
291
+ reasons.push("independent_observation_or_anchor_unavailable");
292
+ }
293
+ const requestedLevel = Number(requested.requestedProfile.slice(-1));
294
+ const effectiveLevel = Math.min(requestedLevel, maximum);
295
+ return {
296
+ requestedProfile: requested.requestedProfile,
297
+ effectiveProfile: PROFILE_BY_LEVEL[effectiveLevel],
298
+ status: effectiveLevel === requestedLevel && reasons.length === 0 ? "ready" : "degraded",
299
+ capabilities: observed,
300
+ canary: observedCanary,
301
+ reasonCodes: reasons
302
+ };
303
+ }
78
304
  var ManagedDeployStepStatusSchema = zod.z.enum([
79
305
  "pending",
80
306
  "in_progress",
@@ -206,6 +432,13 @@ var ControlStatusSchema = zod.z.object({
206
432
  cpuPercent: zod.z.number().nonnegative().max(100)
207
433
  });
208
434
 
435
+ exports.ABSENT_AUDIT_DEPLOYMENT_CONFIG = ABSENT_AUDIT_DEPLOYMENT_CONFIG;
436
+ exports.AuditAssuranceProfileSchema = AuditAssuranceProfileSchema;
437
+ exports.AuditDeliveryModeSchema = AuditDeliveryModeSchema;
438
+ exports.AuditDeploymentConfigSchema = AuditDeploymentConfigSchema;
439
+ exports.AuditDeploymentReadinessSchema = AuditDeploymentReadinessSchema;
440
+ exports.AuditRuntimeCanaryResultSchema = AuditRuntimeCanaryResultSchema;
441
+ exports.AuditRuntimeCapabilitiesSchema = AuditRuntimeCapabilitiesSchema;
209
442
  exports.ComputeCommandSchema = ComputeCommandSchema;
210
443
  exports.ConfigBundleSchema = ConfigBundleSchema;
211
444
  exports.ControlStatusSchema = ControlStatusSchema;
@@ -214,8 +447,12 @@ exports.FlyRegionSchema = FlyRegionSchema;
214
447
  exports.HeartbeatRequestSchema = HeartbeatRequestSchema;
215
448
  exports.HeartbeatResponseSchema = HeartbeatResponseSchema;
216
449
  exports.HostingModeSchema = HostingModeSchema;
450
+ exports.KYA_OS_EVENTS_PATH = KYA_OS_EVENTS_PATH;
217
451
  exports.ManagedDeployStepStatusSchema = ManagedDeployStepStatusSchema;
452
+ exports.NEW_MANAGED_AUDIT_DEPLOYMENT_DEFAULT = NEW_MANAGED_AUDIT_DEPLOYMENT_DEFAULT;
218
453
  exports.RestartCommandSchema = RestartCommandSchema;
219
454
  exports.StopCommandSchema = StopCommandSchema;
220
455
  exports.UpdateConfigCommandSchema = UpdateConfigCommandSchema;
221
456
  exports.UpdateVersionCommandSchema = UpdateVersionCommandSchema;
457
+ exports.requiredAuditRuntimeCanaryChecks = requiredAuditRuntimeCanaryChecks;
458
+ exports.resolveAuditDeploymentReadiness = resolveAuditDeploymentReadiness;
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
2
 
3
3
  // src/deploy/index.ts
4
+ var KYA_OS_EVENTS_PATH = "/api/v1/kya-os/events";
4
5
  var DidStringSchema = z.string().min(8, "DID must be at least 8 characters").regex(/^did:[a-z0-9]+:\S+$/, "DID must match format did:<method>:<method-specific-id>");
5
6
  var FlyRegionSchema = z.enum([
6
7
  "ams",
@@ -72,7 +73,232 @@ var FlyRegionSchema = z.enum([
72
73
  "yyz"
73
74
  // Toronto, Canada
74
75
  ]);
75
- var HostingModeSchema = z.enum(["byok", "managed"]);
76
+ var HostingModeSchema = z.enum(["byok", "managed", "managed-byoa"]);
77
+ var AuditAssuranceProfileSchema = z.enum(["AAP-0", "AAP-1", "AAP-2", "AAP-3", "AAP-4"]);
78
+ var AuditDeliveryModeSchema = z.enum(["best-effort", "buffered", "required"]);
79
+ var AuditDeploymentConfigSchema = z.object({
80
+ enabled: z.boolean(),
81
+ requestedProfile: AuditAssuranceProfileSchema,
82
+ delivery: AuditDeliveryModeSchema,
83
+ evidenceMode: z.enum(["none", "encrypted-separate", "encrypted-inline"]),
84
+ retentionClass: z.string().min(1).max(128),
85
+ retentionDays: z.number().int().min(0).max(3650),
86
+ residency: z.enum(["inherit-project", "us", "eu", "global"]),
87
+ keyCustody: z.enum(["none", "checkpoint-managed", "customer-managed-kms"]),
88
+ recorderTopology: z.enum(["none", "self-hosted", "managed", "verified-mirror"])
89
+ }).strict().superRefine((value, context) => {
90
+ if (!value.enabled && value.requestedProfile !== "AAP-0") {
91
+ context.addIssue({
92
+ code: z.ZodIssueCode.custom,
93
+ path: ["requestedProfile"],
94
+ message: "Disabled audit configuration must request AAP-0"
95
+ });
96
+ }
97
+ if (value.enabled && value.requestedProfile === "AAP-0") {
98
+ context.addIssue({
99
+ code: z.ZodIssueCode.custom,
100
+ path: ["requestedProfile"],
101
+ message: "Enabled audit configuration must request AAP-1 or higher"
102
+ });
103
+ }
104
+ if (Number(value.requestedProfile.slice(-1)) >= 2 && value.delivery === "best-effort") {
105
+ context.addIssue({
106
+ code: z.ZodIssueCode.custom,
107
+ path: ["delivery"],
108
+ message: "AAP-2 or higher cannot use best-effort delivery"
109
+ });
110
+ }
111
+ if (!value.enabled && (value.keyCustody !== "none" || value.recorderTopology !== "none")) {
112
+ context.addIssue({
113
+ code: z.ZodIssueCode.custom,
114
+ message: "Disabled audit configuration cannot claim key custody or recorder topology"
115
+ });
116
+ }
117
+ });
118
+ var NEW_MANAGED_AUDIT_DEPLOYMENT_DEFAULT = Object.freeze({
119
+ enabled: true,
120
+ requestedProfile: "AAP-2",
121
+ delivery: "buffered",
122
+ evidenceMode: "encrypted-separate",
123
+ retentionClass: "integrity-ledger",
124
+ retentionDays: 365,
125
+ residency: "inherit-project",
126
+ keyCustody: "checkpoint-managed",
127
+ recorderTopology: "managed"
128
+ });
129
+ var ABSENT_AUDIT_DEPLOYMENT_CONFIG = Object.freeze({
130
+ enabled: false,
131
+ requestedProfile: "AAP-0",
132
+ delivery: "best-effort",
133
+ evidenceMode: "none",
134
+ retentionClass: "none",
135
+ retentionDays: 0,
136
+ residency: "inherit-project",
137
+ keyCustody: "none",
138
+ recorderTopology: "none"
139
+ });
140
+ var AuditRuntimeCapabilitiesSchema = z.object({
141
+ recorderTopology: z.enum(["none", "self-hosted", "managed", "verified-mirror"]),
142
+ delivery: AuditDeliveryModeSchema,
143
+ journalDurability: z.enum(["none", "ephemeral", "durable"]),
144
+ atomicAppend: z.boolean(),
145
+ sourceHighWater: z.boolean(),
146
+ merkleCheckpoints: z.boolean(),
147
+ independentObservation: z.boolean(),
148
+ supportingAnchors: z.array(z.enum(["worm", "rfc3161", "scitt"])),
149
+ evidenceRetention: z.enum(["none", "inline", "separate"])
150
+ }).strict();
151
+ var AuditRuntimeCanaryResultSchema = z.object({
152
+ passed: z.boolean(),
153
+ observedAt: z.number().int().nonnegative(),
154
+ capabilities: AuditRuntimeCapabilitiesSchema,
155
+ checks: z.array(
156
+ z.object({
157
+ id: z.string().min(1).max(128),
158
+ passed: z.boolean()
159
+ }).strict()
160
+ ).min(1),
161
+ bundleHash: z.string().min(1).max(256).optional()
162
+ }).strict().superRefine((value, context) => {
163
+ if (value.passed !== value.checks.every((check) => check.passed)) {
164
+ context.addIssue({
165
+ code: z.ZodIssueCode.custom,
166
+ path: ["passed"],
167
+ message: "Canary result must equal the aggregate of its mechanical checks"
168
+ });
169
+ }
170
+ });
171
+ function requiredAuditRuntimeCanaryChecks(capabilities) {
172
+ const checks = [
173
+ "recorder_round_trip",
174
+ "verified_receipt",
175
+ "idempotent_retry",
176
+ "event_identity_conflict",
177
+ "source_state"
178
+ ];
179
+ if (capabilities.delivery === "buffered") checks.push("buffered_outbox");
180
+ if (capabilities.evidenceRetention !== "none") checks.push("evidence_write_verified");
181
+ return checks;
182
+ }
183
+ var AuditDeploymentReadinessSchema = z.object({
184
+ requestedProfile: AuditAssuranceProfileSchema,
185
+ effectiveProfile: AuditAssuranceProfileSchema,
186
+ status: z.enum(["disabled", "ready", "degraded"]),
187
+ capabilities: AuditRuntimeCapabilitiesSchema.nullable(),
188
+ canary: AuditRuntimeCanaryResultSchema.nullable(),
189
+ reasonCodes: z.array(z.string().min(1).max(128))
190
+ }).strict();
191
+ var PROFILE_BY_LEVEL = ["AAP-0", "AAP-1", "AAP-2", "AAP-3", "AAP-4"];
192
+ function resolveAuditDeploymentReadiness(config, capabilities, canary) {
193
+ const requested = AuditDeploymentConfigSchema.parse(config ?? ABSENT_AUDIT_DEPLOYMENT_CONFIG);
194
+ const observedCanary = canary ? AuditRuntimeCanaryResultSchema.parse(canary) : null;
195
+ if (!requested.enabled) {
196
+ return {
197
+ requestedProfile: "AAP-0",
198
+ effectiveProfile: "AAP-0",
199
+ status: "disabled",
200
+ capabilities: capabilities ?? null,
201
+ canary: observedCanary,
202
+ reasonCodes: ["audit_not_configured"]
203
+ };
204
+ }
205
+ const observedCapabilities = capabilities ?? observedCanary?.capabilities;
206
+ if (!observedCapabilities) {
207
+ return {
208
+ requestedProfile: requested.requestedProfile,
209
+ effectiveProfile: "AAP-0",
210
+ status: "degraded",
211
+ capabilities: null,
212
+ canary: observedCanary,
213
+ reasonCodes: ["runtime_capabilities_unavailable"]
214
+ };
215
+ }
216
+ const observed = AuditRuntimeCapabilitiesSchema.parse(observedCapabilities);
217
+ if (!observedCanary) {
218
+ return {
219
+ requestedProfile: requested.requestedProfile,
220
+ effectiveProfile: "AAP-0",
221
+ status: "degraded",
222
+ capabilities: observed,
223
+ canary: null,
224
+ reasonCodes: ["runtime_canary_required"]
225
+ };
226
+ }
227
+ if (!observedCanary.passed || JSON.stringify(observedCanary.capabilities) !== JSON.stringify(observed)) {
228
+ return {
229
+ requestedProfile: requested.requestedProfile,
230
+ effectiveProfile: "AAP-0",
231
+ status: "degraded",
232
+ capabilities: observed,
233
+ canary: observedCanary,
234
+ reasonCodes: [
235
+ observedCanary.passed ? "runtime_canary_capability_mismatch" : "runtime_canary_failed"
236
+ ]
237
+ };
238
+ }
239
+ const passedChecks = new Set(
240
+ observedCanary.checks.filter((check) => check.passed).map((check) => check.id)
241
+ );
242
+ if (requiredAuditRuntimeCanaryChecks(observed).some((check) => !passedChecks.has(check))) {
243
+ return {
244
+ requestedProfile: requested.requestedProfile,
245
+ effectiveProfile: "AAP-0",
246
+ status: "degraded",
247
+ capabilities: observed,
248
+ canary: observedCanary,
249
+ reasonCodes: ["runtime_canary_incomplete"]
250
+ };
251
+ }
252
+ let maximum = 0;
253
+ const reasons = [];
254
+ if (observed.recorderTopology !== requested.recorderTopology) {
255
+ reasons.push("recorder_topology_mismatch");
256
+ }
257
+ const deliveryRank = { "best-effort": 0, buffered: 1, required: 2 };
258
+ if (deliveryRank[observed.delivery] < deliveryRank[requested.delivery]) {
259
+ reasons.push("delivery_mode_mismatch");
260
+ }
261
+ const expectedEvidence = requested.evidenceMode === "none" ? "none" : requested.evidenceMode === "encrypted-inline" ? "inline" : "separate";
262
+ if (expectedEvidence !== observed.evidenceRetention) {
263
+ reasons.push("evidence_retention_mismatch");
264
+ }
265
+ if (reasons.length > 0) {
266
+ return {
267
+ requestedProfile: requested.requestedProfile,
268
+ effectiveProfile: "AAP-0",
269
+ status: "degraded",
270
+ capabilities: observed,
271
+ canary: observedCanary,
272
+ reasonCodes: reasons
273
+ };
274
+ }
275
+ if (observed.recorderTopology !== "none" && observed.journalDurability !== "none") maximum = 1;
276
+ else reasons.push("recorder_or_journal_unavailable");
277
+ if (maximum >= 1 && observed.journalDurability === "durable" && observed.atomicAppend && observed.delivery !== "best-effort") {
278
+ maximum = 2;
279
+ } else if (Number(requested.requestedProfile.slice(-1)) >= 2) {
280
+ reasons.push("durable_atomic_buffered_append_unavailable");
281
+ }
282
+ if (maximum >= 2 && observed.merkleCheckpoints && observed.sourceHighWater) maximum = 3;
283
+ else if (Number(requested.requestedProfile.slice(-1)) >= 3) {
284
+ reasons.push("checkpoint_or_source_high_water_unavailable");
285
+ }
286
+ if (maximum >= 3 && observed.independentObservation && observed.supportingAnchors.length > 0) {
287
+ maximum = 4;
288
+ } else if (Number(requested.requestedProfile.slice(-1)) >= 4) {
289
+ reasons.push("independent_observation_or_anchor_unavailable");
290
+ }
291
+ const requestedLevel = Number(requested.requestedProfile.slice(-1));
292
+ const effectiveLevel = Math.min(requestedLevel, maximum);
293
+ return {
294
+ requestedProfile: requested.requestedProfile,
295
+ effectiveProfile: PROFILE_BY_LEVEL[effectiveLevel],
296
+ status: effectiveLevel === requestedLevel && reasons.length === 0 ? "ready" : "degraded",
297
+ capabilities: observed,
298
+ canary: observedCanary,
299
+ reasonCodes: reasons
300
+ };
301
+ }
76
302
  var ManagedDeployStepStatusSchema = z.enum([
77
303
  "pending",
78
304
  "in_progress",
@@ -204,4 +430,4 @@ var ControlStatusSchema = z.object({
204
430
  cpuPercent: z.number().nonnegative().max(100)
205
431
  });
206
432
 
207
- export { ComputeCommandSchema, ConfigBundleSchema, ControlStatusSchema, DidStringSchema, FlyRegionSchema, HeartbeatRequestSchema, HeartbeatResponseSchema, HostingModeSchema, ManagedDeployStepStatusSchema, RestartCommandSchema, StopCommandSchema, UpdateConfigCommandSchema, UpdateVersionCommandSchema };
433
+ export { ABSENT_AUDIT_DEPLOYMENT_CONFIG, AuditAssuranceProfileSchema, AuditDeliveryModeSchema, AuditDeploymentConfigSchema, AuditDeploymentReadinessSchema, AuditRuntimeCanaryResultSchema, AuditRuntimeCapabilitiesSchema, ComputeCommandSchema, ConfigBundleSchema, ControlStatusSchema, DidStringSchema, FlyRegionSchema, HeartbeatRequestSchema, HeartbeatResponseSchema, HostingModeSchema, KYA_OS_EVENTS_PATH, ManagedDeployStepStatusSchema, NEW_MANAGED_AUDIT_DEPLOYMENT_DEFAULT, RestartCommandSchema, StopCommandSchema, UpdateConfigCommandSchema, UpdateVersionCommandSchema, requiredAuditRuntimeCanaryChecks, resolveAuditDeploymentReadiness };