@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
package/src/types.d.ts CHANGED
@@ -198,7 +198,7 @@ export interface KDNAFileDataMap {
198
198
  }
199
199
 
200
200
  export interface KDNAManifest {
201
- kdna_version: '1.0';
201
+ format_version: '0.1.0';
202
202
  asset_id: string;
203
203
  asset_uid: string;
204
204
  asset_type: 'domain' | 'cluster' | 'tool' | 'sample' | 'fixture' | 'bundle';
@@ -209,7 +209,8 @@ export interface KDNAManifest {
209
209
  updated_at: string;
210
210
  compatibility: {
211
211
  min_loader_version: string;
212
- profile: 'judgment-profile-v1' | 'bundle-profile-v1';
212
+ profile: 'kdna.payload.judgment' | 'kdna.payload.bundle';
213
+ profile_version: '0.1.0';
213
214
  [key: string]: any;
214
215
  };
215
216
  payload: {
@@ -238,20 +239,11 @@ export interface KDNAManifest {
238
239
  encrypted_entries?: string[];
239
240
  [key: string]: any;
240
241
  };
241
- /** @deprecated Legacy source/signature compatibility only. */
242
- name?: string;
243
- /** @deprecated Legacy source/signature compatibility only. */
244
- author?: { name: string; id?: string; pubkey?: string; public_key_pem?: string };
245
242
  content_digest?: string;
246
243
  signature?: string;
247
244
  [key: string]: any;
248
245
  }
249
246
 
250
- export interface LintResult {
251
- errors: string[];
252
- warnings: string[];
253
- }
254
-
255
247
  export interface ValidationResult {
256
248
  valid: boolean;
257
249
  errors: string[];
@@ -382,21 +374,21 @@ export interface KdnaDecryptOptions {
382
374
 
383
375
  export function createKdnaAssetReader(): KdnaAssetReader;
384
376
 
385
- export const LICENSED_ENTRY_PROFILE: 'kdna-licensed-entry-v1';
386
- export const LICENSED_EXPERIMENTAL_PROFILE: 'kdna-licensed-entry-experimental';
387
- export const PASSWORD_PROTECTED_PROFILE: 'kdna-password-protected-v1';
388
- export const PASSWORD_PROTECTED_SCRYPT_PROFILE: 'kdna-password-protected-v1-scrypt';
377
+ export const LICENSED_ENTRY_PROFILE: 'kdna.encryption.licensed-entry';
378
+ export const PASSWORD_PROTECTED_PROFILE: 'kdna.encryption.password';
379
+ export const PASSWORD_PROTECTED_SCRYPT_PROFILE: 'kdna.encryption.password.scrypt';
380
+ export const ENCRYPTION_PROFILE_VERSION: '0.1.0';
389
381
  export const ALG: 'AES-256-GCM';
390
382
  export const RFC_KDF: 'HKDF-SHA256';
391
383
  export const RFC_KEY_WRAPPING: 'AES-256-KW';
392
- export const LEGACY_KDF: 'scrypt-sha256';
393
384
  export const PASSWORD_KDF: 'Argon2id';
394
385
  export const SCRYPT_KDF: 'scrypt-sha256';
395
386
 
396
387
  export type KDNACryptoInput = string | Uint8Array;
397
388
 
398
389
  export interface LicensedEntryEnvelope {
399
- profile: 'kdna-licensed-entry-v1';
390
+ profile: 'kdna.encryption.licensed-entry';
391
+ profile_version: '0.1.0';
400
392
  alg: 'AES-256-GCM';
401
393
  kdf: 'HKDF-SHA256';
402
394
  key_wrapping: 'AES-256-KW';
@@ -406,16 +398,6 @@ export interface LicensedEntryEnvelope {
406
398
  ciphertext: string;
407
399
  }
408
400
 
409
- export interface LicensedEntryLegacyEnvelope {
410
- profile: 'kdna-licensed-entry-experimental';
411
- alg: 'AES-256-GCM';
412
- kdf: 'scrypt-sha256';
413
- salt: string;
414
- iv: string;
415
- tag: string;
416
- ciphertext: string;
417
- }
418
-
419
401
  export interface KDNAPasswordKdfParams {
420
402
  salt: string;
421
403
  memory_kib?: number;
@@ -439,7 +421,8 @@ export interface KDNAScryptKdfParams {
439
421
  }
440
422
 
441
423
  export interface KDNAProtectedEntryEnvelope {
442
- profile: 'kdna-password-protected-v1';
424
+ profile: 'kdna.encryption.password';
425
+ profile_version: '0.1.0';
443
426
  alg: 'AES-256-GCM';
444
427
  kdf: 'Argon2id';
445
428
  key_wrapping: 'AES-256-KW';
@@ -455,7 +438,8 @@ export interface KDNAProtectedEntryEnvelope {
455
438
  }
456
439
 
457
440
  export interface KDNAScryptProtectedEntryEnvelope {
458
- profile: 'kdna-password-protected-v1-scrypt';
441
+ profile: 'kdna.encryption.password.scrypt';
442
+ profile_version: '0.1.0';
459
443
  alg: 'AES-256-GCM';
460
444
  kdf: 'scrypt-sha256';
461
445
  key_wrapping: 'AES-256-KW';
@@ -476,17 +460,6 @@ export interface KDNALicensedEntryOptions {
476
460
  licenseKey: KDNACryptoInput;
477
461
  }
478
462
 
479
- export interface KDNALicensedEntryLegacyOptions extends KDNALicensedEntryOptions {
480
- machineFingerprint: string;
481
- }
482
-
483
- export function deriveLicensedEntryKey(options: {
484
- licenseKey: string;
485
- machineFingerprint: string;
486
- salt: string | Uint8Array;
487
- keyLength?: number;
488
- }): Uint8Array;
489
-
490
463
  export function hkdfSha256(
491
464
  ikm: KDNACryptoInput,
492
465
  salt?: Uint8Array | null,
@@ -500,11 +473,11 @@ export function generateCEK(): Uint8Array;
500
473
  export function wrapCEK(cek: Uint8Array, wrappingKey: Uint8Array): Uint8Array;
501
474
  export function unwrapCEK(wrappedCek: Uint8Array, wrappingKey: Uint8Array): Uint8Array;
502
475
 
503
- export function encryptLicensedEntryV1(
476
+ export function encryptLicensedEntry(
504
477
  plaintext: KDNACryptoInput,
505
478
  options: KDNALicensedEntryOptions,
506
479
  ): LicensedEntryEnvelope;
507
- export function decryptLicensedEntryV1(
480
+ export function decryptLicensedEntry(
508
481
  envelope: KDNACryptoInput | LicensedEntryEnvelope,
509
482
  options: KDNALicensedEntryOptions,
510
483
  ): Uint8Array;
@@ -563,53 +536,23 @@ export function decryptProtectedEntryScrypt(
563
536
  export function createPasswordDecryptEntryScrypt(options: {
564
537
  password: KDNACryptoInput;
565
538
  }): NonNullable<KdnaDecryptOptions['decryptEntry']>;
566
- export function encryptLicensedEntryLegacy(
567
- plaintext: KDNACryptoInput,
568
- options: KDNALicensedEntryLegacyOptions,
569
- ): LicensedEntryLegacyEnvelope;
570
- export function decryptLicensedEntryLegacy(
571
- envelope: KDNACryptoInput | LicensedEntryLegacyEnvelope,
572
- options: KDNALicensedEntryLegacyOptions,
573
- ): Uint8Array;
574
-
575
- export function encryptLicensedEntry(
576
- plaintext: string | Uint8Array,
577
- options: KDNALicensedEntryOptions,
578
- ): LicensedEntryEnvelope;
579
-
580
- export function decryptLicensedEntry(
581
- envelope: LicensedEntryEnvelope,
582
- options: KDNALicensedEntryOptions,
583
- ): Uint8Array;
584
- export function decryptLicensedEntry(
585
- envelope: LicensedEntryLegacyEnvelope,
586
- options: KDNALicensedEntryLegacyOptions,
587
- ): Uint8Array;
588
- export function decryptLicensedEntry(
589
- envelope: KDNACryptoInput,
590
- options: KDNALicensedEntryLegacyOptions,
591
- ): Uint8Array;
592
- export function decryptLicensedEntry(
593
- envelope: KDNACryptoInput | LicensedEntryEnvelope | LicensedEntryLegacyEnvelope,
594
- options: KDNALicensedEntryLegacyOptions,
595
- ): Uint8Array;
596
-
597
539
  export function createLicensedDecryptEntry(options: {
598
540
  licenseKey: KDNACryptoInput;
599
- machineFingerprint?: string;
600
541
  }): NonNullable<KdnaDecryptOptions['decryptEntry']>;
601
542
 
602
- export const EXTERNAL_ENVELOPE_PROFILE: 'kdna-envelope-external-grant-v1';
603
- export const EXTERNAL_GRANT_PROFILE: 'kdna-key-grant-v1';
604
- export const EXTERNAL_AAD_PROFILE: 'kdna-external-asset-cek-v1';
605
- export const DEVICE_KEK_PROFILE: 'kdna-device-grant-kek-v1';
543
+ export const EXTERNAL_ENVELOPE_PROFILE: 'kdna.envelope.external-grant';
544
+ export const EXTERNAL_GRANT_PROFILE: 'kdna.grant.external-key';
545
+ export const EXTERNAL_AAD_PROFILE: 'kdna.key-context.asset-content';
546
+ export const DEVICE_KEK_PROFILE: 'kdna.key-context.device-grant';
547
+ export const EXTERNAL_GRANT_CONTRACT_VERSION: '0.1.0';
606
548
 
607
549
  export class KDNAExternalGrantError extends Error {
608
550
  code: string;
609
551
  }
610
552
 
611
553
  export interface KDNAExternalGrantEnvelope {
612
- profile: 'kdna-envelope-external-grant-v1';
554
+ profile: 'kdna.envelope.external-grant';
555
+ contract_version: '0.1.0';
613
556
  alg: 'A256GCM';
614
557
  cek_derivation: 'HKDF-SHA256';
615
558
  key_ref: string;
@@ -622,7 +565,8 @@ export interface KDNAExternalGrantEnvelope {
622
565
  }
623
566
 
624
567
  export interface KDNAExternalKeyGrant {
625
- profile: 'kdna-key-grant-v1';
568
+ profile: 'kdna.grant.external-key';
569
+ contract_version: '0.1.0';
626
570
  grant_id: string;
627
571
  issuer: string;
628
572
  signing_key_id: string;
@@ -664,7 +608,7 @@ export interface KDNADeviceKeyPairs {
664
608
  /** Runtime-branded by authorizeExternalKeyGrant; a structurally similar object is not accepted. */
665
609
  export interface KDNAVerifiedExternalEntitlement {
666
610
  readonly status: 'active' | 'offline_grace';
667
- readonly profile: 'kdna-key-grant-v1';
611
+ readonly profile: 'kdna.grant.external-key';
668
612
  readonly grant_id: string;
669
613
  readonly entitlement_id: string;
670
614
  readonly account_id: string;
@@ -754,7 +698,8 @@ export function authorizeExternalKeyGrant(options: {
754
698
  grant: KDNAExternalKeyGrant;
755
699
  issuerPublicKeys: Map<string, unknown> | Record<string, unknown>;
756
700
  manifest: KDNAManifest;
757
- checksums: KDNAChecksums;
701
+ /** Final immutable container digest A; never checksums entry-set digest E. */
702
+ expectedAssetDigest: string;
758
703
  envelope: KDNAExternalGrantEnvelope | Uint8Array;
759
704
  deviceAgreementKey: KDNADeviceKeyPairs['agreement'] | unknown;
760
705
  expectedAccountId: string;
@@ -773,7 +718,7 @@ export function isVerifiedExternalEntitlement(
773
718
  export type KDNAAssetInput = string | Uint8Array | KdnaAsset;
774
719
 
775
720
  export interface KDNAInspectResult {
776
- kdna_version: string | null;
721
+ format_version: '0.1.0' | null;
777
722
  asset_id: string | null;
778
723
  asset_uid: string | null;
779
724
  asset_type: string | null;
@@ -783,6 +728,9 @@ export interface KDNAInspectResult {
783
728
  payload: string | null;
784
729
  payload_encrypted: boolean | null;
785
730
  profile: string | null;
731
+ loader_version: string;
732
+ min_loader_version: string | null;
733
+ loader_compatible: boolean | null;
786
734
  load_contract_default_profile: string | null;
787
735
  checksums_present?: boolean;
788
736
  entries: string[];
@@ -801,36 +749,13 @@ export interface KDNAValidationReport {
801
749
  payload_valid: boolean;
802
750
  checksums_valid: boolean;
803
751
  load_contract_valid: boolean;
752
+ loader_version: string;
753
+ min_loader_version: string | null;
754
+ loader_compatible: boolean | null;
804
755
  overall_valid: boolean;
805
756
  problems: string[];
806
757
  }
807
758
 
808
- export interface KDNARuntimeCapsule {
809
- type: 'kdna.context.capsule';
810
- version: '1.0';
811
- domain: string | null;
812
- judgment_version: string | null;
813
- asset_digest: string;
814
- signature: { state: 'verified' | 'not_checked' | 'absent'; issuer?: string };
815
- access: string;
816
- risk_level: string | null;
817
- profile: string;
818
- context: Record<string, any>;
819
- trace: Record<string, any>;
820
- extends_chain?: Array<Record<string, any>>;
821
- inheritance_applied?: boolean;
822
- resolved_dependencies?: Array<Record<string, any>>;
823
- rag_isolation_policy?: Record<string, any>;
824
- [key: string]: any;
825
- }
826
-
827
- export interface KDNACapsule1Extensions {
828
- extends_chain?: Array<Record<string, any>>;
829
- inheritance_applied?: boolean;
830
- resolved_dependencies?: Array<Record<string, any>>;
831
- rag_isolation_policy?: Record<string, any>;
832
- }
833
-
834
759
  export type KDNADigestComparisonState = 'matched' | 'mismatched' | 'not_compared' | 'unavailable';
835
760
 
836
761
  export type KDNADigestComparisonSource =
@@ -840,8 +765,7 @@ export type KDNADigestComparisonSource =
840
765
  | 'lockfile'
841
766
  | 'kdna.json.content_digest'
842
767
  | 'kdna.json.authoring.content_digest'
843
- | 'checksums.json.entry_set_digest'
844
- | 'checksums.json.asset_digest';
768
+ | 'checksums.json.entry_set_digest';
845
769
 
846
770
  export interface KDNADigestComparison {
847
771
  state: KDNADigestComparisonState;
@@ -857,15 +781,16 @@ export interface KDNADigestValue {
857
781
  }
858
782
 
859
783
  export interface KDNADigestEvidence {
860
- profile: 'kdna-capsule-digests-v1';
784
+ profile: 'kdna.digest-evidence';
785
+ profile_version: '0.1.0';
861
786
  asset: KDNADigestValue;
862
787
  content: KDNADigestValue;
863
788
  runtime_entry_set: KDNADigestValue;
864
789
  }
865
790
 
866
- export interface KDNARuntimeCapsuleV2 {
867
- type: 'kdna.context.capsule';
868
- version: '2.0';
791
+ export interface KDNARuntimeCapsule {
792
+ type: 'kdna.runtime-capsule';
793
+ contract_version: '0.1.0';
869
794
  asset: {
870
795
  asset_id: string;
871
796
  asset_uid: string;
@@ -888,19 +813,17 @@ export interface KDNARuntimeCapsuleV2 {
888
813
  signature_state: 'verified' | 'not_checked' | 'absent';
889
814
  profile: 'index' | 'compact' | 'scenario' | 'full';
890
815
  };
891
- compatibility?: {
892
- capsule_1_domain?: string;
893
- capsule_1_access?: 'open' | 'protected' | 'runtime';
894
- capsule_1_extensions?: KDNACapsule1Extensions;
895
- };
896
816
  }
897
817
 
898
- export const DIGEST_PROFILE: 'kdna-capsule-digests-v1';
899
- export const CAPSULE_DIGEST_PROFILE: 'kdna-capsule-jcs-v1';
818
+ export const DIGEST_PROFILE: 'kdna.digest-evidence';
819
+ export const DIGEST_PROFILE_VERSION: '0.1.0';
820
+ export const CAPSULE_DIGEST_PROFILE: 'kdna.canonicalization.runtime-capsule-jcs';
821
+ export const CANONICALIZATION_PROFILE_VERSION: '0.1.0';
822
+ export const RUNTIME_CAPSULE_CONTRACT_VERSION: '0.1.0';
900
823
  export const BASIS: Readonly<{
901
- asset: 'kdna-container-bytes-v1';
902
- content: 'kdna-content-tree-v1';
903
- runtime_entry_set: 'kdna-runtime-entry-set-v1';
824
+ asset: 'kdna.digest-basis.container-bytes';
825
+ content: 'kdna.digest-basis.content-tree';
826
+ runtime_entry_set: 'kdna.digest-basis.runtime-entry-set';
904
827
  }>;
905
828
  export function computeAssetDigest(assetBytes: Uint8Array): string;
906
829
  export function computeRuntimeEntrySetDigest(
@@ -920,23 +843,22 @@ export function computeDigestEvidence(
920
843
  }
921
844
  >
922
845
  >;
923
- /** @deprecated Use expectedDigests.asset. */
924
- expectedAssetDigest?:
925
- string | { value: string; source: 'caller' | 'registry' | 'install_receipt' | 'lockfile' };
926
846
  },
927
847
  ): KDNADigestEvidence;
928
848
  export function canonicalizeJcs(value: unknown): string;
929
849
  export function computeCapsuleDeliveryDigest(
930
- capsule: KDNARuntimeCapsuleV2 | Record<string, any>,
850
+ capsule: KDNARuntimeCapsule | Record<string, any>,
931
851
  ): string;
932
- export function buildCapsuleV2(input: {
933
- capsule1: KDNARuntimeCapsule;
852
+ export function buildRuntimeCapsule(input: {
853
+ projection: Record<string, any>;
934
854
  manifest: KDNAManifest;
935
855
  digests: KDNADigestEvidence;
856
+ signature: { state: 'verified' | 'not_checked' | 'absent'; issuer?: string };
936
857
  inputKind: 'packaged_file' | 'packaged_bytes';
937
858
  loadedAt?: string;
938
- }): KDNARuntimeCapsuleV2;
939
- export function loadCapsuleV2(
859
+ schemaValid?: boolean;
860
+ }): KDNARuntimeCapsule;
861
+ export function loadRuntimeCapsule(
940
862
  input: string | Uint8Array,
941
863
  options?: {
942
864
  profile?: 'index' | 'compact' | 'scenario' | 'full';
@@ -951,13 +873,8 @@ export function loadCapsuleV2(
951
873
  }
952
874
  >
953
875
  >;
954
- /** @deprecated Use expectedDigests.asset. */
955
- expectedAssetDigest?:
956
- string | { value: string; source: 'caller' | 'registry' | 'install_receipt' | 'lockfile' };
957
876
  } & KdnaDecryptOptions,
958
- ): KDNARuntimeCapsuleV2;
959
- export function adaptCapsuleV2ToV1(capsule: KDNARuntimeCapsuleV2): KDNARuntimeCapsule;
960
-
877
+ ): KDNARuntimeCapsule;
961
878
  export type KDNAJsonValue =
962
879
  null | boolean | number | string | KDNAJsonValue[] | { [key: string]: KDNAJsonValue };
963
880
 
@@ -971,13 +888,13 @@ export type KDNAExecutionContractValidationResult =
971
888
  | { valid: true; code: null; errors: []; value?: unknown }
972
889
  | { valid: false; code: string; errors: KDNAExecutionContractValidationError[] };
973
890
 
974
- export class KDNAExecutionContractError extends Error {
891
+ export class KDNARuntimeContractError extends Error {
975
892
  code: string;
976
893
  details?: unknown;
977
894
  constructor(code: string, message: string, details?: unknown);
978
895
  }
979
896
 
980
- export interface KDNAExpectedDigestV1 {
897
+ export interface KDNAExpectedDigest {
981
898
  value: string;
982
899
  basis: string;
983
900
  source:
@@ -986,14 +903,13 @@ export interface KDNAExpectedDigestV1 {
986
903
  | 'install_receipt'
987
904
  | 'lockfile'
988
905
  | 'kdna.json.content_digest'
989
- | 'checksums.json.entry_set_digest'
990
- | 'checksums.json.asset_digest';
906
+ | 'checksums.json.entry_set_digest';
991
907
  comparison: 'matched' | 'not_compared';
992
908
  }
993
909
 
994
- export interface KDNAConsumptionPlanV1 {
995
- type: 'kdna.consumption.plan';
996
- plan_version: '1.0.0';
910
+ export interface KDNAConsumptionPlan {
911
+ type: 'kdna.consumption-plan';
912
+ contract_version: '0.1.0';
997
913
  plan_id: string;
998
914
  created_at: string;
999
915
  mode: 'single';
@@ -1005,26 +921,31 @@ export interface KDNAConsumptionPlanV1 {
1005
921
  judgment_version: string;
1006
922
  access: 'public' | 'licensed' | 'remote';
1007
923
  expected_digests: {
1008
- asset: KDNAExpectedDigestV1 | null;
1009
- content: KDNAExpectedDigestV1 | null;
1010
- runtime_entry_set: KDNAExpectedDigestV1 | null;
924
+ asset: KDNAExpectedDigest | null;
925
+ content: KDNAExpectedDigest | null;
926
+ runtime_entry_set: KDNAExpectedDigest | null;
1011
927
  };
1012
928
  };
1013
929
  projection_request: {
1014
930
  profile: 'index' | 'compact' | 'scenario' | 'full';
1015
- accepted_capsule_versions: ['2.0'];
1016
- required_digest_profile: 'kdna-capsule-digests-v1';
931
+ accepted_capsule_versions: ['0.1.0'];
932
+ required_digest_profile: 'kdna.digest-evidence';
933
+ required_digest_profile_version: '0.1.0';
1017
934
  require_packaged_asset: true;
1018
935
  };
1019
- host_request: { accepted_protocols: ['kdna.agent-host/2'] };
936
+ host_request: { accepted_protocols: ['kdna.agent-host'] };
1020
937
  result_request: { shape: 'structured_judgment' };
1021
- budget: KDNAExecutionBudgetV1;
938
+ budget: KDNAExecutionBudget;
1022
939
  constraints: { enforce_before_host: true; reject_on_exceed: true };
1023
940
  trace_policy: { emit: true; storage: 'ephemeral' | 'session' | 'persistent' };
1024
- integrity: { profile: 'kdna-consumption-plan-jcs-v1'; plan_digest: string };
941
+ integrity: {
942
+ profile: 'kdna.canonicalization.consumption-plan-jcs';
943
+ profile_version: '0.1.0';
944
+ plan_digest: string;
945
+ };
1025
946
  }
1026
947
 
1027
- export interface KDNAExecutionBudgetV1 {
948
+ export interface KDNAExecutionBudget {
1028
949
  max_projection_chars: number;
1029
950
  max_task_chars: number;
1030
951
  deadline_ms: number;
@@ -1032,49 +953,55 @@ export interface KDNAExecutionBudgetV1 {
1032
953
  max_model_calls: number | null;
1033
954
  }
1034
955
 
1035
- export interface KDNAAgentHostCapabilitiesV1 {
1036
- type: 'kdna.agent-host.capabilities';
1037
- version: '1.0';
956
+ export interface KDNAAgentHostCapabilities {
957
+ type: 'kdna.agent-host-capabilities';
958
+ protocol_version: '0.1.0';
1038
959
  capability_basis: 'registered_descriptor' | 'legacy_assumption';
1039
- host_protocols: string[];
1040
- capsule_versions: string[];
1041
- capsule_digest_profiles: string[];
960
+ host_protocols: Array<'kdna.agent-host'>;
961
+ capsule_versions: Array<'0.1.0'>;
962
+ capsule_digest_profiles: Array<'kdna.canonicalization.runtime-capsule-jcs'>;
963
+ capsule_digest_profile_versions: ['0.1.0'];
1042
964
  }
1043
965
 
1044
- export interface KDNAAgentHost2RequestV1 {
1045
- protocol: 'kdna.agent-host/2';
966
+ export interface KDNAAgentHostRequest {
967
+ protocol: 'kdna.agent-host';
968
+ protocol_version: '0.1.0';
1046
969
  request_id: string;
1047
970
  plan_ref: {
1048
971
  plan_id: string;
1049
- plan_digest_profile: 'kdna-consumption-plan-jcs-v1';
972
+ plan_digest_profile: 'kdna.canonicalization.consumption-plan-jcs';
973
+ plan_digest_profile_version: '0.1.0';
1050
974
  plan_digest: string;
1051
975
  };
1052
976
  runtime_contract: {
1053
- capsule_version: '2.0';
1054
- capsule_digest_profile: 'kdna-capsule-jcs-v1';
977
+ capsule_version: '0.1.0';
978
+ capsule_digest_profile: 'kdna.canonicalization.runtime-capsule-jcs';
979
+ capsule_digest_profile_version: '0.1.0';
1055
980
  capsule_delivery_digest: string;
1056
981
  };
1057
- projection_contract: KDNAConsumptionPlanV1['projection_request'] extends infer T
982
+ projection_contract: KDNAConsumptionPlan['projection_request'] extends infer T
1058
983
  ? Omit<Extract<T, object>, 'accepted_capsule_versions'>
1059
984
  : never;
1060
985
  result_contract: { shape: 'structured_judgment' };
1061
- budget: KDNAExecutionBudgetV1;
1062
- constraints: KDNAConsumptionPlanV1['constraints'];
986
+ budget: KDNAExecutionBudget;
987
+ constraints: KDNAConsumptionPlan['constraints'];
1063
988
  phase: 'single_judgment';
1064
- task: KDNAConsumptionPlanV1['task'];
989
+ task: KDNAConsumptionPlan['task'];
1065
990
  authority: { asset_id: string; role: 'primary'; final_decision: true };
1066
- asset: KDNAConsumptionPlanV1['asset_ref'] & { role: 'primary' };
1067
- capsule: KDNARuntimeCapsuleV2;
991
+ asset: KDNAConsumptionPlan['asset_ref'] & { role: 'primary' };
992
+ capsule: KDNARuntimeCapsule;
1068
993
  }
1069
994
 
1070
- export interface KDNAAgentHost2ReceiptV1 {
1071
- protocol: 'kdna.agent-host/2';
995
+ export interface KDNAAgentHostReceipt {
996
+ protocol: 'kdna.agent-host';
997
+ protocol_version: '0.1.0';
1072
998
  request_id: string;
1073
999
  runtime_receipt: {
1074
1000
  type: 'kdna.agent-host.runtime-receipt';
1075
- receipt_version: '1.0.0';
1076
- capsule_version: '2.0';
1077
- capsule_digest_profile: 'kdna-capsule-jcs-v1';
1001
+ contract_version: '0.1.0';
1002
+ capsule_version: '0.1.0';
1003
+ capsule_digest_profile: 'kdna.canonicalization.runtime-capsule-jcs';
1004
+ capsule_digest_profile_version: '0.1.0';
1078
1005
  sender_capsule_delivery_digest: string;
1079
1006
  host_recomputed_capsule_delivery_digest: string;
1080
1007
  echoed_capsule_delivery_digest: string;
@@ -1098,8 +1025,8 @@ export interface KDNAAgentHost2ReceiptV1 {
1098
1025
  } | null;
1099
1026
  }
1100
1027
 
1101
- export interface KDNABudgetEvidenceV1 {
1102
- limits: KDNAExecutionBudgetV1;
1028
+ export interface KDNABudgetEvidence {
1029
+ limits: KDNAExecutionBudget;
1103
1030
  actual: {
1104
1031
  projection_chars: number | null;
1105
1032
  task_chars: number;
@@ -1119,19 +1046,20 @@ export interface KDNABudgetEvidenceV1 {
1119
1046
  };
1120
1047
  }
1121
1048
 
1122
- export interface KDNAJudgmentTraceIssueV1 {
1049
+ export interface KDNAJudgmentTraceIssue {
1123
1050
  code: string;
1124
1051
  message: string;
1125
1052
  phase: 'plan' | 'negotiation' | 'load' | 'budget' | 'delivery' | 'host' | 'execution';
1126
1053
  }
1127
1054
 
1128
- export interface KDNAJudgmentTraceV1 {
1129
- type: 'kdna.judgment.trace';
1130
- trace_version: '1.0.0';
1055
+ export interface KDNAJudgmentTrace {
1056
+ type: 'kdna.judgment-trace';
1057
+ contract_version: '0.1.0';
1131
1058
  trace_id: string;
1132
1059
  plan_ref: {
1133
1060
  plan_id: string;
1134
- plan_digest_profile: 'kdna-consumption-plan-jcs-v1';
1061
+ plan_digest_profile: 'kdna.canonicalization.consumption-plan-jcs';
1062
+ plan_digest_profile_version: '0.1.0';
1135
1063
  plan_digest: string;
1136
1064
  comparison: 'matched';
1137
1065
  };
@@ -1140,15 +1068,15 @@ export interface KDNAJudgmentTraceV1 {
1140
1068
  overall_status:
1141
1069
  'execution_completed' | 'blocked' | 'execution_failed' | 'cancelled' | 'timed_out';
1142
1070
  runtime_contract: {
1143
- plan_capsule_versions: ['2.0'];
1144
- core_capsule_versions: Array<'2.0' | '1.0'>;
1145
- plan_host_protocols: ['kdna.agent-host/2'];
1146
- host_capabilities: KDNAAgentHostCapabilitiesV1;
1071
+ plan_capsule_versions: ['0.1.0'];
1072
+ core_capsule_versions: Array<'0.1.0'>;
1073
+ plan_host_protocols: ['kdna.agent-host'];
1074
+ host_capabilities: KDNAAgentHostCapabilities;
1147
1075
  negotiation_state: 'selected' | 'blocked' | 'not_started';
1148
- selected_capsule_version: '2.0' | null;
1149
- selected_host_protocol: 'kdna.agent-host/2' | null;
1076
+ selected_capsule_version: '0.1.0' | null;
1077
+ selected_host_protocol: 'kdna.agent-host' | null;
1150
1078
  issue_code:
1151
- | 'KDNA_CAPSULE_VERSION_UNSUPPORTED'
1079
+ | 'KDNA_CAPSULE_CONTRACT_VERSION_UNSUPPORTED'
1152
1080
  | 'KDNA_HOST_PROTOCOL_UNSUPPORTED'
1153
1081
  | 'KDNA_HOST_CAPSULE_PAIR_UNSUPPORTED'
1154
1082
  | null;
@@ -1162,12 +1090,13 @@ export interface KDNAJudgmentTraceV1 {
1162
1090
  };
1163
1091
  digest_evidence: KDNADigestEvidence;
1164
1092
  capsule_delivery_evidence: {
1165
- basis: 'kdna-capsule-jcs-v1';
1093
+ basis: 'kdna.canonicalization.runtime-capsule-jcs';
1094
+ basis_version: '0.1.0';
1166
1095
  observed: string | null;
1167
1096
  sender_computed: boolean;
1168
1097
  host_recomputed: string | null;
1169
1098
  host_echoed: string | null;
1170
- delivered_capsule_version: '2.0' | null;
1099
+ delivered_capsule_version: '0.1.0' | null;
1171
1100
  host_boundary_comparison:
1172
1101
  'matched' | 'mismatched' | 'not_delivered' | 'not_observed' | 'unavailable';
1173
1102
  request_id: string | null;
@@ -1177,7 +1106,7 @@ export interface KDNAJudgmentTraceV1 {
1177
1106
  capsule_delivery_digest: string | null;
1178
1107
  profile_deviated_from_plan: boolean | null;
1179
1108
  };
1180
- host_receipt: KDNAAgentHost2ReceiptV1 | null;
1109
+ host_receipt: KDNAAgentHostReceipt | null;
1181
1110
  execution: {
1182
1111
  delivery_status: 'correlated_response' | 'rejected_before_execution' | 'not_delivered';
1183
1112
  semantic_consumption: { state: 'not_observed'; basis: null };
@@ -1185,118 +1114,120 @@ export interface KDNAJudgmentTraceV1 {
1185
1114
  conformance_status: 'not_evaluated';
1186
1115
  model_identity: { value: string | null; basis: 'host_reported' | 'not_observed' };
1187
1116
  };
1188
- budget: KDNABudgetEvidenceV1;
1117
+ budget: KDNABudgetEvidence;
1189
1118
  result_ref: {
1190
1119
  shape: 'structured_judgment';
1191
1120
  result_digest: string;
1192
- basis: 'kdna-result-jcs-v1';
1121
+ basis: 'kdna.canonicalization.result-jcs';
1193
1122
  stored: boolean;
1194
1123
  } | null;
1195
- errors: KDNAJudgmentTraceIssueV1[];
1124
+ errors: KDNAJudgmentTraceIssue[];
1196
1125
  warnings: string[];
1197
1126
  }
1198
1127
 
1199
- export interface KDNAExecutionPairContextV1 {
1128
+ export interface KDNARuntimePairContext {
1200
1129
  trustedPlanDigest: string;
1201
- capabilities: KDNAAgentHostCapabilitiesV1;
1130
+ capabilities: KDNAAgentHostCapabilities;
1202
1131
  coreCapsuleVersions: readonly string[];
1203
1132
  }
1204
1133
 
1205
- export interface KDNAHost2ValidationContextV1 extends KDNAExecutionPairContextV1 {
1206
- plan: KDNAConsumptionPlanV1;
1134
+ export interface KDNAAgentHostValidationContext extends KDNARuntimePairContext {
1135
+ plan: KDNAConsumptionPlan;
1207
1136
  }
1208
1137
 
1209
- export interface KDNAJudgmentTraceContextV1 extends KDNAHost2ValidationContextV1 {
1210
- request: KDNAAgentHost2RequestV1 | null;
1211
- receipt: KDNAAgentHost2ReceiptV1 | null;
1138
+ export interface KDNAJudgmentTraceContext extends KDNAAgentHostValidationContext {
1139
+ request: KDNAAgentHostRequest | null;
1140
+ receipt: KDNAAgentHostReceipt | null;
1212
1141
  trustedDeliveryObservation: 'host_receipt' | 'not_delivered' | 'not_observed';
1213
1142
  }
1214
1143
 
1215
- export interface KDNAPreHostBudgetBlockedTraceContextV1
1216
- extends KDNAHost2ValidationContextV1 {
1217
- capsule: KDNARuntimeCapsuleV2;
1144
+ export interface KDNAPreHostBudgetBlockedTraceContext
1145
+ extends KDNAAgentHostValidationContext {
1146
+ capsule: KDNARuntimeCapsule;
1218
1147
  }
1219
1148
 
1220
- export const PLAN_DIGEST_PROFILE: 'kdna-consumption-plan-jcs-v1';
1221
- export const HOST_PROTOCOL: 'kdna.agent-host/2';
1222
- export const DEFAULT_CORE_CAPSULE_VERSIONS: readonly ['2.0', '1.0'];
1223
- export function parseExecutionContractJsonV1(
1149
+ export const PLAN_DIGEST_PROFILE: 'kdna.canonicalization.consumption-plan-jcs';
1150
+ export const PLAN_DIGEST_PROFILE_VERSION: '0.1.0';
1151
+ export const HOST_PROTOCOL: 'kdna.agent-host';
1152
+ export const HOST_PROTOCOL_VERSION: '0.1.0';
1153
+ export const DEFAULT_CORE_CAPSULE_CONTRACT_VERSIONS: readonly ['0.1.0'];
1154
+ export function parseRuntimeContractJson(
1224
1155
  input: string | Uint8Array,
1225
1156
  options?: { maxBytes?: number; maxDepth?: number },
1226
1157
  ): KDNAJsonValue;
1227
- export function computeConsumptionPlanDigestV1(plan: KDNAConsumptionPlanV1): string;
1228
- export function buildConsumptionPlanV1(input: {
1158
+ export function computeConsumptionPlanDigest(plan: KDNAConsumptionPlan): string;
1159
+ export function buildConsumptionPlan(input: {
1229
1160
  plan_id: string;
1230
1161
  created_at: string;
1231
- task: KDNAConsumptionPlanV1['task'];
1232
- asset_ref: KDNAConsumptionPlanV1['asset_ref'];
1233
- projection_profile: KDNAConsumptionPlanV1['projection_request']['profile'];
1234
- budget: KDNAExecutionBudgetV1;
1235
- constraints: KDNAConsumptionPlanV1['constraints'];
1236
- trace_policy: KDNAConsumptionPlanV1['trace_policy'];
1237
- }): KDNAConsumptionPlanV1;
1238
- export function validateConsumptionPlanV1(
1162
+ task: KDNAConsumptionPlan['task'];
1163
+ asset_ref: KDNAConsumptionPlan['asset_ref'];
1164
+ projection_profile: KDNAConsumptionPlan['projection_request']['profile'];
1165
+ budget: KDNAExecutionBudget;
1166
+ constraints: KDNAConsumptionPlan['constraints'];
1167
+ trace_policy: KDNAConsumptionPlan['trace_policy'];
1168
+ }): KDNAConsumptionPlan;
1169
+ export function validateConsumptionPlan(
1239
1170
  plan: unknown,
1240
1171
  context: { trustedPlanDigest: string },
1241
1172
  ): KDNAExecutionContractValidationResult;
1242
- export function negotiateExecutionPairV1(
1243
- plan: KDNAConsumptionPlanV1,
1244
- context: KDNAExecutionPairContextV1,
1173
+ export function negotiateRuntimePair(
1174
+ plan: KDNAConsumptionPlan,
1175
+ context: KDNARuntimePairContext,
1245
1176
  ): {
1246
1177
  state: 'selected' | 'blocked';
1247
- capsule_version: '2.0' | null;
1248
- host_protocol: 'kdna.agent-host/2' | null;
1178
+ capsule_version: '0.1.0' | null;
1179
+ host_protocol: 'kdna.agent-host' | null;
1249
1180
  issue_code: string | null;
1250
1181
  };
1251
- export function buildAgentHost2RequestV1(
1252
- input: { request_id: string; capsule: KDNARuntimeCapsuleV2 },
1253
- context: KDNAHost2ValidationContextV1,
1254
- ): KDNAAgentHost2RequestV1;
1255
- export function validateAgentHost2RequestV1(
1182
+ export function buildAgentHostRequest(
1183
+ input: { request_id: string; capsule: KDNARuntimeCapsule },
1184
+ context: KDNAAgentHostValidationContext,
1185
+ ): KDNAAgentHostRequest;
1186
+ export function validateAgentHostRequest(
1256
1187
  request: unknown,
1257
- context: KDNAHost2ValidationContextV1,
1188
+ context: KDNAAgentHostValidationContext,
1258
1189
  ): KDNAExecutionContractValidationResult;
1259
- export function validateAgentHost2ReceiptV1(
1190
+ export function validateAgentHostReceipt(
1260
1191
  receipt: unknown,
1261
- context: { request: KDNAAgentHost2RequestV1 },
1192
+ context: { request: KDNAAgentHostRequest },
1262
1193
  ): KDNAExecutionContractValidationResult;
1263
- export function deriveBudgetEvidenceV1(
1264
- plan: KDNAConsumptionPlanV1,
1194
+ export function deriveBudgetEvidence(
1195
+ plan: KDNAConsumptionPlan,
1265
1196
  context: {
1266
1197
  trustedPlanDigest: string;
1267
- request: KDNAAgentHost2RequestV1 | null;
1268
- receipt: KDNAAgentHost2ReceiptV1 | null;
1198
+ request: KDNAAgentHostRequest | null;
1199
+ receipt: KDNAAgentHostReceipt | null;
1269
1200
  },
1270
- ): KDNABudgetEvidenceV1;
1271
- export function buildPreHostBudgetBlockedTraceV1(
1201
+ ): KDNABudgetEvidence;
1202
+ export function buildPreHostBudgetBlockedTrace(
1272
1203
  input: {
1273
1204
  trace_id: string;
1274
1205
  timestamp: string;
1275
- capsule: KDNARuntimeCapsuleV2;
1206
+ capsule: KDNARuntimeCapsule;
1276
1207
  parent_trace_id?: string | null;
1277
1208
  warnings?: string[];
1278
1209
  },
1279
- context: KDNAHost2ValidationContextV1,
1280
- ): KDNAJudgmentTraceV1;
1281
- export function validatePreHostBudgetBlockedTraceV1(
1210
+ context: KDNAAgentHostValidationContext,
1211
+ ): KDNAJudgmentTrace;
1212
+ export function validatePreHostBudgetBlockedTrace(
1282
1213
  trace: unknown,
1283
- context: KDNAPreHostBudgetBlockedTraceContextV1,
1214
+ context: KDNAPreHostBudgetBlockedTraceContext,
1284
1215
  ): KDNAExecutionContractValidationResult;
1285
- export function buildJudgmentTraceV1(
1216
+ export function buildJudgmentTrace(
1286
1217
  input: {
1287
1218
  trace_id: string;
1288
1219
  timestamp: string;
1289
- overall_status: KDNAJudgmentTraceV1['overall_status'];
1220
+ overall_status: KDNAJudgmentTrace['overall_status'];
1290
1221
  parent_trace_id?: string | null;
1291
1222
  result_stored?: boolean;
1292
- errors?: KDNAJudgmentTraceIssueV1[];
1223
+ errors?: KDNAJudgmentTraceIssue[];
1293
1224
  warnings?: string[];
1294
1225
  },
1295
- context: KDNAJudgmentTraceContextV1,
1296
- ): KDNAJudgmentTraceV1;
1297
- export function validateJudgmentTraceV1(
1226
+ context: KDNAJudgmentTraceContext,
1227
+ ): KDNAJudgmentTrace;
1228
+ export function validateJudgmentTrace(
1298
1229
  trace: unknown,
1299
- context: KDNAJudgmentTraceContextV1,
1230
+ context: KDNAJudgmentTraceContext,
1300
1231
  ): KDNAExecutionContractValidationResult;
1301
1232
 
1302
1233
  export interface KDNAMatchResult extends KDNAInspectResult {
@@ -1447,14 +1378,13 @@ export interface KDNAChecksumEntry {
1447
1378
  }
1448
1379
 
1449
1380
  export interface KDNAChecksums {
1450
- digest_profile?: 'kdna-runtime-entry-set-v1';
1381
+ digest_profile?: 'kdna.digest-basis.runtime-entry-set';
1382
+ digest_profile_version?: '0.1.0';
1451
1383
  covered_entries?: ['kdna.json', 'payload.kdnab'];
1452
1384
  algorithm: 'sha256';
1453
1385
  manifest_digest?: string;
1454
1386
  payload_digest?: string;
1455
1387
  entry_set_digest?: string;
1456
- /** @deprecated Use entry_set_digest. This is not the final .kdna file digest. */
1457
- asset_digest?: string;
1458
1388
  entries?: Record<string, KDNAChecksumEntry>;
1459
1389
  }
1460
1390
 
@@ -1464,6 +1394,15 @@ export function inspect(
1464
1394
  input: string | Uint8Array,
1465
1395
  options?: Record<string, any>,
1466
1396
  ): Record<string, any>;
1397
+ export const KDNA_LOADER_VERSION: '0.19.0';
1398
+ export const STRICT_LOADER_VERSION: RegExp;
1399
+ export function parseLoaderVersion(version: unknown): readonly [string, string, string] | null;
1400
+ export function compareLoaderVersions(left: string, right: string): -1 | 0 | 1;
1401
+ export function assessLoaderCompatibility(manifest: Partial<KDNAManifest> | null | undefined): {
1402
+ loader_version: string;
1403
+ min_loader_version: string | null;
1404
+ loader_compatible: boolean | null;
1405
+ };
1467
1406
  export function validate(
1468
1407
  input: string | Uint8Array,
1469
1408
  options?: Record<string, any>,
@@ -1474,7 +1413,7 @@ export interface KDNALoadPlanIssue {
1474
1413
  message: string;
1475
1414
  }
1476
1415
  export interface KDNALoadPlan {
1477
- kdna_version: string | null;
1416
+ format_version: '0.1.0' | null;
1478
1417
  asset: {
1479
1418
  asset_id: string | null;
1480
1419
  asset_uid: string | null;
@@ -1510,7 +1449,11 @@ export interface KDNALoadPlan {
1510
1449
  | string;
1511
1450
  can_load_now: boolean;
1512
1451
  projection_policy: 'minimal' | 'remote' | 'none' | string;
1513
- input_fingerprint: string | null;
1452
+ input_fingerprint: {
1453
+ has_password_input: boolean;
1454
+ entitlement_input: 'active' | 'expired' | 'revoked' | 'offline_grace' | null;
1455
+ source_fingerprint: string;
1456
+ } | null;
1514
1457
  checks: Record<string, boolean>;
1515
1458
  issues: KDNALoadPlanIssue[];
1516
1459
  source: {
@@ -1550,22 +1493,6 @@ export function loadAsset(
1550
1493
  as?: 'json' | 'prompt' | string;
1551
1494
  },
1552
1495
  ): KDNARuntimeCapsule | Record<string, any>;
1553
- export function buildCapsule(
1554
- loadResult: {
1555
- profile: string;
1556
- content?: Record<string, unknown>;
1557
- extends_chain?: unknown[];
1558
- inheritance_applied?: boolean;
1559
- resolved_dependencies?: unknown[];
1560
- rag_isolation_policy?: Record<string, unknown>;
1561
- [key: string]: unknown;
1562
- },
1563
- layout: KDNALayout,
1564
- profile: string,
1565
- options?: {
1566
- _validation?: { schema_valid?: boolean; signature_valid?: boolean | null };
1567
- },
1568
- ): KDNARuntimeCapsule;
1569
1496
  export const FORBIDDEN_OUTPUT_TERMS: readonly string[];
1570
1497
 
1571
1498
  export interface KDNASemver {
@@ -1578,10 +1505,6 @@ export function parseSemver(version: string): KDNASemver | null;
1578
1505
  export function compareSemver(left: string, right: string): number;
1579
1506
  export function satisfies(version: string, range: string): boolean;
1580
1507
 
1581
- // Lint
1582
- export function lintDomain(dataMap: KDNAFileDataMap): LintResult;
1583
- export function validateManifest(manifest: unknown): LintResult;
1584
-
1585
1508
  // Validate
1586
1509
  export function validateDomainSchema(
1587
1510
  dataMap: KDNAFileDataMap,