@aikdna/kdna-core 0.18.0 → 0.19.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +128 -94
  2. package/README.md +109 -215
  3. package/package.json +7 -2
  4. package/schema/agent-host-capabilities.schema.json +62 -0
  5. package/schema/agent-host-receipt.schema.json +371 -0
  6. package/schema/agent-host-request.schema.json +223 -0
  7. package/schema/{bundle-profile-v1.schema.json → bundle-profile.schema.json} +9 -5
  8. package/schema/checksums.schema.json +8 -8
  9. package/schema/consumption-plan.schema.json +428 -0
  10. package/schema/digest-evidence.schema.json +115 -26
  11. package/schema/{kdna-envelope-external-grant-v1.schema.json → external-grant-envelope.schema.json} +17 -4
  12. package/schema/{kdna-key-grant-v1.schema.json → external-key-grant.schema.json} +39 -7
  13. package/schema/judgment-trace.schema.json +1251 -0
  14. package/schema/load-plan.schema.json +5 -3
  15. package/schema/manifest.schema.json +70 -10
  16. package/schema/{payload-profile-v1.schema.json → payload-profile.schema.json} +30 -6
  17. package/schema/{runtime-capsule-2.schema.json → runtime-capsule.schema.json} +7 -31
  18. package/src/asset-reader.js +8 -2
  19. package/src/{v1 → container}/index.js +385 -198
  20. package/src/container/index.mjs +20 -0
  21. package/src/container-dispatcher.js +6 -6
  22. package/src/crypto-profile.js +37 -107
  23. package/src/external-key-grant.js +41 -15
  24. package/src/index.js +11 -8
  25. package/src/index.mjs +49 -45
  26. package/src/loader-compatibility.js +59 -0
  27. package/src/loader.js +1 -1
  28. package/src/public-api.js +5 -5
  29. package/src/remote-runtime.d.ts +13 -0
  30. package/src/remote-runtime.js +27 -0
  31. package/src/remote-runtime.mjs +3 -0
  32. package/src/runtime-api.js +5 -5
  33. package/src/{capsule-v2.js → runtime-capsule.js} +96 -254
  34. package/src/{execution-contract-v1.js → runtime-contract.js} +184 -152
  35. package/src/types.d.ts +200 -277
  36. package/src/workpack-pure.js +1 -1
  37. package/schema/agent-host-2-receipt.schema.json +0 -206
  38. package/schema/agent-host-2-request.schema.json +0 -135
  39. package/schema/agent-host-capabilities-1.schema.json +0 -40
  40. package/schema/consumption-plan-1.schema.json +0 -280
  41. package/schema/judgment-trace-1.schema.json +0 -748
  42. package/schema/runtime-capsule-1.schema.json +0 -68
  43. package/src/lint-pure.js +0 -433
  44. package/src/v1/index.mjs +0 -21
@@ -0,0 +1,1251 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/aikdna/kdna/specs/judgment-trace.schema.json",
4
+ "title": "KDNA JudgmentTrace",
5
+ "description": "Authoritative strict terminal evidence for Runtime contract execution.",
6
+ "type": "object",
7
+ "required": [
8
+ "type",
9
+ "contract_version",
10
+ "trace_id",
11
+ "plan_ref",
12
+ "parent_trace_id",
13
+ "timestamp",
14
+ "overall_status",
15
+ "runtime_contract",
16
+ "asset_identity",
17
+ "digest_evidence",
18
+ "capsule_delivery_evidence",
19
+ "projection_actual",
20
+ "host_receipt",
21
+ "execution",
22
+ "budget",
23
+ "result_ref",
24
+ "errors",
25
+ "warnings"
26
+ ],
27
+ "additionalProperties": false,
28
+ "properties": {
29
+ "type": {
30
+ "const": "kdna.judgment-trace"
31
+ },
32
+ "trace_id": {
33
+ "type": "string",
34
+ "pattern": "^trace_[0-9a-f]{16}$"
35
+ },
36
+ "plan_ref": {
37
+ "$ref": "#/$defs/planRef"
38
+ },
39
+ "parent_trace_id": {
40
+ "oneOf": [
41
+ {
42
+ "type": "string",
43
+ "pattern": "^trace_[0-9a-f]{16}$"
44
+ },
45
+ {
46
+ "type": "null"
47
+ }
48
+ ]
49
+ },
50
+ "timestamp": {
51
+ "type": "string",
52
+ "format": "date-time"
53
+ },
54
+ "overall_status": {
55
+ "enum": ["execution_completed", "blocked", "execution_failed", "cancelled", "timed_out"]
56
+ },
57
+ "runtime_contract": {
58
+ "$ref": "#/$defs/runtimeContract"
59
+ },
60
+ "asset_identity": {
61
+ "$ref": "#/$defs/assetIdentity"
62
+ },
63
+ "digest_evidence": {
64
+ "$ref": "https://github.com/aikdna/kdna/specs/digest-evidence.schema.json"
65
+ },
66
+ "capsule_delivery_evidence": {
67
+ "$ref": "#/$defs/capsuleDeliveryEvidence"
68
+ },
69
+ "projection_actual": {
70
+ "$ref": "#/$defs/projectionActual"
71
+ },
72
+ "host_receipt": {
73
+ "oneOf": [
74
+ {
75
+ "$ref": "https://github.com/aikdna/kdna/specs/agent-host-receipt.schema.json"
76
+ },
77
+ {
78
+ "type": "null"
79
+ }
80
+ ]
81
+ },
82
+ "execution": {
83
+ "$ref": "#/$defs/execution"
84
+ },
85
+ "budget": {
86
+ "$ref": "#/$defs/budgetEvidence"
87
+ },
88
+ "result_ref": {
89
+ "oneOf": [
90
+ {
91
+ "$ref": "#/$defs/resultRef"
92
+ },
93
+ {
94
+ "type": "null"
95
+ }
96
+ ]
97
+ },
98
+ "errors": {
99
+ "type": "array",
100
+ "items": {
101
+ "$ref": "#/$defs/issue"
102
+ }
103
+ },
104
+ "warnings": {
105
+ "type": "array",
106
+ "items": {
107
+ "type": "string"
108
+ }
109
+ },
110
+ "contract_version": {
111
+ "const": "0.1.0"
112
+ }
113
+ },
114
+ "allOf": [
115
+ {
116
+ "if": {
117
+ "properties": {
118
+ "overall_status": {
119
+ "enum": ["execution_completed", "execution_failed", "cancelled", "timed_out"]
120
+ }
121
+ },
122
+ "required": ["overall_status"]
123
+ },
124
+ "then": {
125
+ "properties": {
126
+ "runtime_contract": {
127
+ "properties": {
128
+ "negotiation_state": {
129
+ "const": "selected"
130
+ },
131
+ "selected_capsule_version": {
132
+ "const": "0.1.0"
133
+ },
134
+ "selected_host_protocol": {
135
+ "const": "kdna.agent-host"
136
+ },
137
+ "issue_code": {
138
+ "type": "null"
139
+ }
140
+ }
141
+ },
142
+ "digest_evidence": {
143
+ "properties": {
144
+ "asset": {
145
+ "$ref": "#/$defs/successfulDigest"
146
+ },
147
+ "content": {
148
+ "$ref": "#/$defs/successfulDigest"
149
+ },
150
+ "runtime_entry_set": {
151
+ "$ref": "#/$defs/successfulDigest"
152
+ }
153
+ }
154
+ },
155
+ "capsule_delivery_evidence": {
156
+ "properties": {
157
+ "host_boundary_comparison": {
158
+ "const": "matched"
159
+ }
160
+ }
161
+ },
162
+ "host_receipt": {
163
+ "$ref": "https://github.com/aikdna/kdna/specs/agent-host-receipt.schema.json"
164
+ },
165
+ "projection_actual": {
166
+ "properties": {
167
+ "profile": {
168
+ "type": "string"
169
+ },
170
+ "capsule_delivery_digest": {
171
+ "$ref": "#/$defs/sha256"
172
+ },
173
+ "profile_deviated_from_plan": {
174
+ "type": "boolean"
175
+ }
176
+ }
177
+ },
178
+ "budget": {
179
+ "properties": {
180
+ "actual": {
181
+ "properties": {
182
+ "projection_chars": {
183
+ "type": "integer",
184
+ "minimum": 0
185
+ }
186
+ }
187
+ }
188
+ }
189
+ }
190
+ }
191
+ }
192
+ },
193
+ {
194
+ "if": {
195
+ "properties": {
196
+ "overall_status": {
197
+ "const": "execution_completed"
198
+ }
199
+ },
200
+ "required": ["overall_status"]
201
+ },
202
+ "then": {
203
+ "properties": {
204
+ "host_receipt": {
205
+ "properties": {
206
+ "runtime_receipt": {
207
+ "properties": {
208
+ "provider_execution_status": {
209
+ "const": "completed"
210
+ }
211
+ }
212
+ },
213
+ "outcome": {
214
+ "type": "object"
215
+ }
216
+ }
217
+ },
218
+ "execution": {
219
+ "properties": {
220
+ "delivery_status": {
221
+ "const": "correlated_response"
222
+ },
223
+ "execution_status": {
224
+ "const": "completed"
225
+ }
226
+ }
227
+ },
228
+ "budget": {
229
+ "properties": {
230
+ "comparison": {
231
+ "properties": {
232
+ "overall": {
233
+ "enum": ["within_limit", "not_observed"]
234
+ }
235
+ }
236
+ }
237
+ }
238
+ },
239
+ "result_ref": {
240
+ "$ref": "#/$defs/resultRef"
241
+ },
242
+ "errors": {
243
+ "maxItems": 0
244
+ }
245
+ }
246
+ }
247
+ },
248
+ {
249
+ "if": {
250
+ "properties": {
251
+ "overall_status": {
252
+ "const": "blocked"
253
+ }
254
+ },
255
+ "required": ["overall_status"]
256
+ },
257
+ "then": {
258
+ "properties": {
259
+ "runtime_contract": {
260
+ "properties": {
261
+ "negotiation_state": {
262
+ "enum": ["selected", "blocked", "not_started"]
263
+ }
264
+ }
265
+ },
266
+ "capsule_delivery_evidence": {
267
+ "properties": {
268
+ "host_boundary_comparison": {
269
+ "enum": ["mismatched", "not_delivered", "not_observed", "unavailable"]
270
+ }
271
+ }
272
+ },
273
+ "host_receipt": {
274
+ "oneOf": [
275
+ {
276
+ "type": "null"
277
+ },
278
+ {
279
+ "allOf": [
280
+ {
281
+ "$ref": "https://github.com/aikdna/kdna/specs/agent-host-receipt.schema.json"
282
+ },
283
+ {
284
+ "properties": {
285
+ "runtime_receipt": {
286
+ "properties": {
287
+ "capsule_delivery_comparison": {
288
+ "const": "mismatched"
289
+ },
290
+ "provider_execution_status": {
291
+ "const": "not_started"
292
+ }
293
+ }
294
+ },
295
+ "outcome": {
296
+ "type": "null"
297
+ }
298
+ }
299
+ }
300
+ ]
301
+ }
302
+ ]
303
+ },
304
+ "execution": {
305
+ "properties": {
306
+ "delivery_status": {
307
+ "enum": ["not_delivered", "rejected_before_execution"]
308
+ },
309
+ "execution_status": {
310
+ "const": "not_started"
311
+ }
312
+ }
313
+ },
314
+ "result_ref": {
315
+ "type": "null"
316
+ },
317
+ "errors": {
318
+ "minItems": 1
319
+ }
320
+ }
321
+ }
322
+ },
323
+ {
324
+ "if": {
325
+ "properties": {
326
+ "overall_status": {
327
+ "const": "execution_failed"
328
+ }
329
+ },
330
+ "required": ["overall_status"]
331
+ },
332
+ "then": {
333
+ "properties": {
334
+ "host_receipt": {
335
+ "properties": {
336
+ "runtime_receipt": {
337
+ "properties": {
338
+ "provider_execution_status": {
339
+ "const": "failed"
340
+ }
341
+ }
342
+ },
343
+ "outcome": {
344
+ "type": "null"
345
+ }
346
+ }
347
+ },
348
+ "execution": {
349
+ "properties": {
350
+ "delivery_status": {
351
+ "const": "correlated_response"
352
+ },
353
+ "execution_status": {
354
+ "const": "failed"
355
+ }
356
+ }
357
+ },
358
+ "result_ref": {
359
+ "type": "null"
360
+ },
361
+ "errors": {
362
+ "minItems": 1
363
+ }
364
+ }
365
+ }
366
+ },
367
+ {
368
+ "if": {
369
+ "properties": {
370
+ "overall_status": {
371
+ "const": "cancelled"
372
+ }
373
+ },
374
+ "required": ["overall_status"]
375
+ },
376
+ "then": {
377
+ "properties": {
378
+ "host_receipt": {
379
+ "properties": {
380
+ "runtime_receipt": {
381
+ "properties": {
382
+ "provider_execution_status": {
383
+ "const": "cancelled"
384
+ }
385
+ }
386
+ },
387
+ "outcome": {
388
+ "type": "null"
389
+ }
390
+ }
391
+ },
392
+ "execution": {
393
+ "properties": {
394
+ "delivery_status": {
395
+ "const": "correlated_response"
396
+ },
397
+ "execution_status": {
398
+ "const": "cancelled"
399
+ }
400
+ }
401
+ },
402
+ "result_ref": {
403
+ "type": "null"
404
+ },
405
+ "errors": {
406
+ "minItems": 1
407
+ }
408
+ }
409
+ }
410
+ },
411
+ {
412
+ "if": {
413
+ "properties": {
414
+ "overall_status": {
415
+ "const": "timed_out"
416
+ }
417
+ },
418
+ "required": ["overall_status"]
419
+ },
420
+ "then": {
421
+ "properties": {
422
+ "host_receipt": {
423
+ "properties": {
424
+ "runtime_receipt": {
425
+ "properties": {
426
+ "provider_execution_status": {
427
+ "const": "timed_out"
428
+ }
429
+ }
430
+ },
431
+ "outcome": {
432
+ "type": "null"
433
+ }
434
+ }
435
+ },
436
+ "execution": {
437
+ "properties": {
438
+ "delivery_status": {
439
+ "const": "correlated_response"
440
+ },
441
+ "execution_status": {
442
+ "const": "timed_out"
443
+ }
444
+ }
445
+ },
446
+ "budget": {
447
+ "properties": {
448
+ "comparison": {
449
+ "properties": {
450
+ "elapsed_ms": {
451
+ "const": "exceeded"
452
+ },
453
+ "overall": {
454
+ "const": "exceeded"
455
+ }
456
+ }
457
+ }
458
+ }
459
+ },
460
+ "result_ref": {
461
+ "type": "null"
462
+ },
463
+ "errors": {
464
+ "minItems": 1
465
+ }
466
+ }
467
+ }
468
+ }
469
+ ],
470
+ "$defs": {
471
+ "sha256": {
472
+ "type": "string",
473
+ "pattern": "^sha256:[0-9a-f]{64}$"
474
+ },
475
+ "assetId": {
476
+ "type": "string",
477
+ "pattern": "^[a-zA-Z][a-zA-Z0-9_-]*(:[a-zA-Z0-9_.-]+)+$"
478
+ },
479
+ "semver": {
480
+ "type": "string",
481
+ "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+([+-].+)?$"
482
+ },
483
+ "planRef": {
484
+ "type": "object",
485
+ "required": [
486
+ "plan_id",
487
+ "plan_digest_profile",
488
+ "plan_digest_profile_version",
489
+ "plan_digest",
490
+ "comparison"
491
+ ],
492
+ "additionalProperties": false,
493
+ "properties": {
494
+ "plan_id": {
495
+ "type": "string",
496
+ "pattern": "^plan_[0-9a-f]{16}$"
497
+ },
498
+ "plan_digest_profile": {
499
+ "const": "kdna.canonicalization.consumption-plan-jcs"
500
+ },
501
+ "plan_digest": {
502
+ "$ref": "#/$defs/sha256"
503
+ },
504
+ "comparison": {
505
+ "const": "matched"
506
+ },
507
+ "plan_digest_profile_version": {
508
+ "const": "0.1.0"
509
+ }
510
+ }
511
+ },
512
+ "runtimeContract": {
513
+ "type": "object",
514
+ "required": [
515
+ "plan_capsule_versions",
516
+ "core_capsule_versions",
517
+ "plan_host_protocols",
518
+ "host_capabilities",
519
+ "negotiation_state",
520
+ "selected_capsule_version",
521
+ "selected_host_protocol",
522
+ "issue_code"
523
+ ],
524
+ "additionalProperties": false,
525
+ "properties": {
526
+ "plan_capsule_versions": {
527
+ "type": "array",
528
+ "prefixItems": [
529
+ {
530
+ "const": "0.1.0"
531
+ }
532
+ ],
533
+ "minItems": 1,
534
+ "maxItems": 1
535
+ },
536
+ "core_capsule_versions": {
537
+ "type": "array",
538
+ "minItems": 1,
539
+ "uniqueItems": true,
540
+ "items": {
541
+ "enum": ["0.1.0"]
542
+ }
543
+ },
544
+ "plan_host_protocols": {
545
+ "type": "array",
546
+ "prefixItems": [
547
+ {
548
+ "const": "kdna.agent-host"
549
+ }
550
+ ],
551
+ "minItems": 1,
552
+ "maxItems": 1
553
+ },
554
+ "host_capabilities": {
555
+ "$ref": "https://github.com/aikdna/kdna/specs/agent-host-capabilities.schema.json"
556
+ },
557
+ "negotiation_state": {
558
+ "enum": ["selected", "blocked", "not_started"]
559
+ },
560
+ "selected_capsule_version": {
561
+ "type": ["string", "null"],
562
+ "enum": ["0.1.0", null]
563
+ },
564
+ "selected_host_protocol": {
565
+ "type": ["string", "null"],
566
+ "enum": ["kdna.agent-host", null]
567
+ },
568
+ "issue_code": {
569
+ "type": ["string", "null"],
570
+ "enum": [
571
+ "KDNA_CAPSULE_CONTRACT_VERSION_UNSUPPORTED",
572
+ "KDNA_HOST_PROTOCOL_UNSUPPORTED",
573
+ "KDNA_HOST_CAPSULE_PAIR_UNSUPPORTED",
574
+ null
575
+ ]
576
+ }
577
+ },
578
+ "allOf": [
579
+ {
580
+ "if": {
581
+ "properties": {
582
+ "negotiation_state": {
583
+ "const": "selected"
584
+ }
585
+ },
586
+ "required": ["negotiation_state"]
587
+ },
588
+ "then": {
589
+ "properties": {
590
+ "selected_capsule_version": {
591
+ "const": "0.1.0"
592
+ },
593
+ "selected_host_protocol": {
594
+ "const": "kdna.agent-host"
595
+ },
596
+ "issue_code": {
597
+ "type": "null"
598
+ }
599
+ }
600
+ },
601
+ "else": {
602
+ "properties": {
603
+ "selected_capsule_version": {
604
+ "type": "null"
605
+ },
606
+ "selected_host_protocol": {
607
+ "type": "null"
608
+ }
609
+ }
610
+ }
611
+ },
612
+ {
613
+ "if": {
614
+ "properties": {
615
+ "negotiation_state": {
616
+ "const": "blocked"
617
+ }
618
+ },
619
+ "required": ["negotiation_state"]
620
+ },
621
+ "then": {
622
+ "properties": {
623
+ "issue_code": {
624
+ "type": "string"
625
+ }
626
+ }
627
+ }
628
+ },
629
+ {
630
+ "if": {
631
+ "properties": {
632
+ "negotiation_state": {
633
+ "const": "not_started"
634
+ }
635
+ },
636
+ "required": ["negotiation_state"]
637
+ },
638
+ "then": {
639
+ "properties": {
640
+ "issue_code": {
641
+ "type": "null"
642
+ }
643
+ }
644
+ }
645
+ }
646
+ ]
647
+ },
648
+ "assetIdentity": {
649
+ "type": "object",
650
+ "required": ["asset_id", "asset_uid", "version", "judgment_version", "access"],
651
+ "additionalProperties": false,
652
+ "properties": {
653
+ "asset_id": {
654
+ "$ref": "#/$defs/assetId"
655
+ },
656
+ "asset_uid": {
657
+ "type": "string",
658
+ "format": "uri"
659
+ },
660
+ "version": {
661
+ "$ref": "#/$defs/semver"
662
+ },
663
+ "judgment_version": {
664
+ "$ref": "#/$defs/semver"
665
+ },
666
+ "access": {
667
+ "enum": ["public", "licensed", "remote"]
668
+ }
669
+ }
670
+ },
671
+ "successfulDigest": {
672
+ "type": "object",
673
+ "required": ["value", "basis", "comparison"],
674
+ "additionalProperties": false,
675
+ "properties": {
676
+ "value": {
677
+ "$ref": "#/$defs/sha256"
678
+ },
679
+ "basis": {
680
+ "type": "string"
681
+ },
682
+ "comparison": {
683
+ "type": "object",
684
+ "required": ["state", "against", "expected", "source"],
685
+ "additionalProperties": false,
686
+ "properties": {
687
+ "state": {
688
+ "enum": ["matched", "not_compared"]
689
+ },
690
+ "against": {
691
+ "type": ["string", "null"]
692
+ },
693
+ "expected": {
694
+ "oneOf": [
695
+ {
696
+ "$ref": "#/$defs/sha256"
697
+ },
698
+ {
699
+ "type": "null"
700
+ }
701
+ ]
702
+ },
703
+ "source": {
704
+ "type": ["string", "null"]
705
+ }
706
+ }
707
+ }
708
+ }
709
+ },
710
+ "capsuleDeliveryEvidence": {
711
+ "type": "object",
712
+ "required": [
713
+ "basis",
714
+ "basis_version",
715
+ "observed",
716
+ "sender_computed",
717
+ "host_recomputed",
718
+ "host_echoed",
719
+ "delivered_capsule_version",
720
+ "host_boundary_comparison",
721
+ "request_id"
722
+ ],
723
+ "additionalProperties": false,
724
+ "properties": {
725
+ "basis": {
726
+ "const": "kdna.canonicalization.runtime-capsule-jcs"
727
+ },
728
+ "observed": {
729
+ "oneOf": [
730
+ {
731
+ "$ref": "#/$defs/sha256"
732
+ },
733
+ {
734
+ "type": "null"
735
+ }
736
+ ]
737
+ },
738
+ "sender_computed": {
739
+ "type": "boolean"
740
+ },
741
+ "host_recomputed": {
742
+ "oneOf": [
743
+ {
744
+ "$ref": "#/$defs/sha256"
745
+ },
746
+ {
747
+ "type": "null"
748
+ }
749
+ ]
750
+ },
751
+ "host_echoed": {
752
+ "oneOf": [
753
+ {
754
+ "$ref": "#/$defs/sha256"
755
+ },
756
+ {
757
+ "type": "null"
758
+ }
759
+ ]
760
+ },
761
+ "delivered_capsule_version": {
762
+ "type": ["string", "null"],
763
+ "enum": ["0.1.0", null]
764
+ },
765
+ "host_boundary_comparison": {
766
+ "enum": ["matched", "mismatched", "not_delivered", "not_observed", "unavailable"]
767
+ },
768
+ "request_id": {
769
+ "oneOf": [
770
+ {
771
+ "type": "string",
772
+ "pattern": "^host_[0-9a-f]{24}$"
773
+ },
774
+ {
775
+ "type": "null"
776
+ }
777
+ ]
778
+ },
779
+ "basis_version": {
780
+ "const": "0.1.0"
781
+ }
782
+ },
783
+ "allOf": [
784
+ {
785
+ "if": {
786
+ "properties": {
787
+ "host_boundary_comparison": {
788
+ "const": "matched"
789
+ }
790
+ },
791
+ "required": ["host_boundary_comparison"]
792
+ },
793
+ "then": {
794
+ "properties": {
795
+ "observed": {
796
+ "$ref": "#/$defs/sha256"
797
+ },
798
+ "sender_computed": {
799
+ "const": true
800
+ },
801
+ "host_recomputed": {
802
+ "$ref": "#/$defs/sha256"
803
+ },
804
+ "host_echoed": {
805
+ "$ref": "#/$defs/sha256"
806
+ },
807
+ "delivered_capsule_version": {
808
+ "const": "0.1.0"
809
+ },
810
+ "request_id": {
811
+ "type": "string",
812
+ "pattern": "^host_[0-9a-f]{24}$"
813
+ }
814
+ }
815
+ }
816
+ },
817
+ {
818
+ "if": {
819
+ "properties": {
820
+ "host_boundary_comparison": {
821
+ "const": "mismatched"
822
+ }
823
+ },
824
+ "required": ["host_boundary_comparison"]
825
+ },
826
+ "then": {
827
+ "properties": {
828
+ "observed": {
829
+ "$ref": "#/$defs/sha256"
830
+ },
831
+ "sender_computed": {
832
+ "const": true
833
+ },
834
+ "host_recomputed": {
835
+ "$ref": "#/$defs/sha256"
836
+ },
837
+ "host_echoed": {
838
+ "$ref": "#/$defs/sha256"
839
+ },
840
+ "delivered_capsule_version": {
841
+ "const": "0.1.0"
842
+ },
843
+ "request_id": {
844
+ "type": "string",
845
+ "pattern": "^host_[0-9a-f]{24}$"
846
+ }
847
+ }
848
+ }
849
+ },
850
+ {
851
+ "if": {
852
+ "properties": {
853
+ "host_boundary_comparison": {
854
+ "const": "not_observed"
855
+ }
856
+ },
857
+ "required": ["host_boundary_comparison"]
858
+ },
859
+ "then": {
860
+ "properties": {
861
+ "observed": {
862
+ "$ref": "#/$defs/sha256"
863
+ },
864
+ "sender_computed": {
865
+ "const": true
866
+ },
867
+ "host_recomputed": {
868
+ "type": "null"
869
+ },
870
+ "host_echoed": {
871
+ "type": "null"
872
+ },
873
+ "delivered_capsule_version": {
874
+ "const": "0.1.0"
875
+ },
876
+ "request_id": {
877
+ "type": "string",
878
+ "pattern": "^host_[0-9a-f]{24}$"
879
+ }
880
+ }
881
+ }
882
+ },
883
+ {
884
+ "if": {
885
+ "properties": {
886
+ "host_boundary_comparison": {
887
+ "enum": ["not_delivered", "unavailable"]
888
+ }
889
+ },
890
+ "required": ["host_boundary_comparison"]
891
+ },
892
+ "then": {
893
+ "properties": {
894
+ "host_recomputed": {
895
+ "type": "null"
896
+ },
897
+ "host_echoed": {
898
+ "type": "null"
899
+ },
900
+ "delivered_capsule_version": {
901
+ "type": "null"
902
+ },
903
+ "request_id": {
904
+ "type": "null"
905
+ }
906
+ }
907
+ }
908
+ },
909
+ {
910
+ "if": {
911
+ "properties": {
912
+ "host_boundary_comparison": {
913
+ "const": "unavailable"
914
+ }
915
+ },
916
+ "required": ["host_boundary_comparison"]
917
+ },
918
+ "then": {
919
+ "properties": {
920
+ "observed": {
921
+ "type": "null"
922
+ },
923
+ "sender_computed": {
924
+ "const": false
925
+ }
926
+ }
927
+ }
928
+ }
929
+ ]
930
+ },
931
+ "projectionActual": {
932
+ "type": "object",
933
+ "required": ["profile", "capsule_delivery_digest", "profile_deviated_from_plan"],
934
+ "additionalProperties": false,
935
+ "properties": {
936
+ "profile": {
937
+ "type": ["string", "null"],
938
+ "enum": ["index", "compact", "scenario", "full", null]
939
+ },
940
+ "capsule_delivery_digest": {
941
+ "oneOf": [
942
+ {
943
+ "$ref": "#/$defs/sha256"
944
+ },
945
+ {
946
+ "type": "null"
947
+ }
948
+ ]
949
+ },
950
+ "profile_deviated_from_plan": {
951
+ "type": ["boolean", "null"]
952
+ }
953
+ }
954
+ },
955
+ "execution": {
956
+ "type": "object",
957
+ "required": [
958
+ "delivery_status",
959
+ "semantic_consumption",
960
+ "execution_status",
961
+ "conformance_status",
962
+ "model_identity"
963
+ ],
964
+ "additionalProperties": false,
965
+ "properties": {
966
+ "delivery_status": {
967
+ "enum": ["correlated_response", "rejected_before_execution", "not_delivered"]
968
+ },
969
+ "semantic_consumption": {
970
+ "$ref": "#/$defs/semanticConsumption"
971
+ },
972
+ "execution_status": {
973
+ "enum": ["completed", "not_started", "failed", "cancelled", "timed_out"]
974
+ },
975
+ "conformance_status": {
976
+ "const": "not_evaluated"
977
+ },
978
+ "model_identity": {
979
+ "$ref": "#/$defs/modelIdentity"
980
+ }
981
+ }
982
+ },
983
+ "semanticConsumption": {
984
+ "type": "object",
985
+ "required": ["state", "basis"],
986
+ "additionalProperties": false,
987
+ "properties": {
988
+ "state": {
989
+ "const": "not_observed"
990
+ },
991
+ "basis": {
992
+ "type": "null"
993
+ }
994
+ }
995
+ },
996
+ "modelIdentity": {
997
+ "type": "object",
998
+ "required": ["value", "basis"],
999
+ "additionalProperties": false,
1000
+ "properties": {
1001
+ "value": {
1002
+ "type": ["string", "null"],
1003
+ "minLength": 1
1004
+ },
1005
+ "basis": {
1006
+ "enum": ["host_reported", "not_observed"]
1007
+ }
1008
+ },
1009
+ "allOf": [
1010
+ {
1011
+ "if": {
1012
+ "properties": {
1013
+ "basis": {
1014
+ "const": "host_reported"
1015
+ }
1016
+ },
1017
+ "required": ["basis"]
1018
+ },
1019
+ "then": {
1020
+ "properties": {
1021
+ "value": {
1022
+ "type": "string",
1023
+ "minLength": 1
1024
+ }
1025
+ }
1026
+ },
1027
+ "else": {
1028
+ "properties": {
1029
+ "value": {
1030
+ "type": "null"
1031
+ }
1032
+ }
1033
+ }
1034
+ }
1035
+ ]
1036
+ },
1037
+ "budgetEvidence": {
1038
+ "type": "object",
1039
+ "required": ["limits", "actual", "comparison"],
1040
+ "additionalProperties": false,
1041
+ "properties": {
1042
+ "limits": {
1043
+ "$ref": "https://github.com/aikdna/kdna/specs/consumption-plan.schema.json#/$defs/budget"
1044
+ },
1045
+ "actual": {
1046
+ "$ref": "#/$defs/budgetActual"
1047
+ },
1048
+ "comparison": {
1049
+ "$ref": "#/$defs/budgetComparison"
1050
+ }
1051
+ }
1052
+ },
1053
+ "budgetActual": {
1054
+ "type": "object",
1055
+ "required": [
1056
+ "projection_chars",
1057
+ "task_chars",
1058
+ "elapsed_ms",
1059
+ "elapsed_basis",
1060
+ "tokens_used",
1061
+ "model_calls",
1062
+ "usage_basis"
1063
+ ],
1064
+ "additionalProperties": false,
1065
+ "properties": {
1066
+ "projection_chars": {
1067
+ "oneOf": [
1068
+ {
1069
+ "type": "integer",
1070
+ "minimum": 0
1071
+ },
1072
+ {
1073
+ "type": "null"
1074
+ }
1075
+ ]
1076
+ },
1077
+ "task_chars": {
1078
+ "type": "integer",
1079
+ "minimum": 0
1080
+ },
1081
+ "elapsed_ms": {
1082
+ "oneOf": [
1083
+ {
1084
+ "type": "integer",
1085
+ "minimum": 0
1086
+ },
1087
+ {
1088
+ "type": "null"
1089
+ }
1090
+ ]
1091
+ },
1092
+ "elapsed_basis": {
1093
+ "enum": ["host_monotonic", "not_observed"]
1094
+ },
1095
+ "tokens_used": {
1096
+ "oneOf": [
1097
+ {
1098
+ "type": "integer",
1099
+ "minimum": 0
1100
+ },
1101
+ {
1102
+ "type": "null"
1103
+ }
1104
+ ]
1105
+ },
1106
+ "model_calls": {
1107
+ "oneOf": [
1108
+ {
1109
+ "type": "integer",
1110
+ "minimum": 0
1111
+ },
1112
+ {
1113
+ "type": "null"
1114
+ }
1115
+ ]
1116
+ },
1117
+ "usage_basis": {
1118
+ "enum": ["host_reported", "not_observed"]
1119
+ }
1120
+ },
1121
+ "allOf": [
1122
+ {
1123
+ "if": {
1124
+ "properties": {
1125
+ "elapsed_basis": {
1126
+ "const": "host_monotonic"
1127
+ }
1128
+ },
1129
+ "required": ["elapsed_basis"]
1130
+ },
1131
+ "then": {
1132
+ "properties": {
1133
+ "elapsed_ms": {
1134
+ "type": "integer",
1135
+ "minimum": 0
1136
+ }
1137
+ }
1138
+ },
1139
+ "else": {
1140
+ "properties": {
1141
+ "elapsed_ms": {
1142
+ "type": "null"
1143
+ }
1144
+ }
1145
+ }
1146
+ },
1147
+ {
1148
+ "if": {
1149
+ "properties": {
1150
+ "usage_basis": {
1151
+ "const": "host_reported"
1152
+ }
1153
+ },
1154
+ "required": ["usage_basis"]
1155
+ },
1156
+ "then": {
1157
+ "properties": {
1158
+ "tokens_used": {
1159
+ "type": "integer",
1160
+ "minimum": 0
1161
+ },
1162
+ "model_calls": {
1163
+ "type": "integer",
1164
+ "minimum": 0
1165
+ }
1166
+ }
1167
+ },
1168
+ "else": {
1169
+ "properties": {
1170
+ "tokens_used": {
1171
+ "type": "null"
1172
+ },
1173
+ "model_calls": {
1174
+ "type": "null"
1175
+ }
1176
+ }
1177
+ }
1178
+ }
1179
+ ]
1180
+ },
1181
+ "budgetComparison": {
1182
+ "type": "object",
1183
+ "required": [
1184
+ "projection_chars",
1185
+ "task_chars",
1186
+ "elapsed_ms",
1187
+ "tokens_used",
1188
+ "model_calls",
1189
+ "overall"
1190
+ ],
1191
+ "additionalProperties": false,
1192
+ "properties": {
1193
+ "projection_chars": {
1194
+ "enum": ["within_limit", "exceeded", "not_observed"]
1195
+ },
1196
+ "task_chars": {
1197
+ "enum": ["within_limit", "exceeded"]
1198
+ },
1199
+ "elapsed_ms": {
1200
+ "enum": ["within_limit", "exceeded", "not_observed"]
1201
+ },
1202
+ "tokens_used": {
1203
+ "enum": ["within_limit", "exceeded", "not_limited", "not_observed"]
1204
+ },
1205
+ "model_calls": {
1206
+ "enum": ["within_limit", "exceeded", "not_limited", "not_observed"]
1207
+ },
1208
+ "overall": {
1209
+ "enum": ["within_limit", "exceeded", "not_observed"]
1210
+ }
1211
+ }
1212
+ },
1213
+ "resultRef": {
1214
+ "type": "object",
1215
+ "required": ["shape", "result_digest", "basis", "stored"],
1216
+ "additionalProperties": false,
1217
+ "properties": {
1218
+ "shape": {
1219
+ "const": "structured_judgment"
1220
+ },
1221
+ "result_digest": {
1222
+ "$ref": "#/$defs/sha256"
1223
+ },
1224
+ "basis": {
1225
+ "const": "kdna.canonicalization.result-jcs"
1226
+ },
1227
+ "stored": {
1228
+ "type": "boolean"
1229
+ }
1230
+ }
1231
+ },
1232
+ "issue": {
1233
+ "type": "object",
1234
+ "required": ["code", "message", "phase"],
1235
+ "additionalProperties": false,
1236
+ "properties": {
1237
+ "code": {
1238
+ "type": "string",
1239
+ "minLength": 1
1240
+ },
1241
+ "message": {
1242
+ "type": "string",
1243
+ "minLength": 1
1244
+ },
1245
+ "phase": {
1246
+ "enum": ["plan", "negotiation", "load", "budget", "delivery", "host", "execution"]
1247
+ }
1248
+ }
1249
+ }
1250
+ }
1251
+ }