@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
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "https://github.com/aikdna/kdna/schema/load-plan.schema.json",
4
- "title": "KDNA LoadPlan v1",
4
+ "title": "KDNA LoadPlan",
5
5
  "description": "Machine-readable pre-load authorization and runtime planning result for packaged KDNA assets.",
6
6
  "type": "object",
7
7
  "required": [
8
- "kdna_version",
8
+ "format_version",
9
9
  "asset",
10
10
  "access",
11
11
  "access_alias",
@@ -21,7 +21,9 @@
21
21
  ],
22
22
  "additionalProperties": false,
23
23
  "properties": {
24
- "kdna_version": { "type": ["string", "null"] },
24
+ "format_version": {
25
+ "oneOf": [{ "const": "0.1.0" }, { "type": "null" }]
26
+ },
25
27
  "asset": {
26
28
  "type": "object",
27
29
  "required": ["asset_id", "asset_uid", "title", "version", "judgment_version"],
@@ -2,10 +2,10 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "https://github.com/aikdna/kdna/schema/manifest.schema.json",
4
4
  "title": "KDNA Manifest",
5
- "description": "Schema for kdna.json, the public metadata layer of a .kdna container (kdna_version 1.0).",
5
+ "description": "Schema for kdna.json, the public metadata layer of a .kdna container.",
6
6
  "type": "object",
7
7
  "required": [
8
- "kdna_version",
8
+ "format_version",
9
9
  "asset_id",
10
10
  "asset_uid",
11
11
  "asset_type",
@@ -18,11 +18,35 @@
18
18
  "payload"
19
19
  ],
20
20
  "additionalProperties": true,
21
+ "allOf": [
22
+ {
23
+ "if": {
24
+ "properties": {
25
+ "payload": {
26
+ "required": ["encrypted"],
27
+ "properties": { "encrypted": { "const": true } }
28
+ }
29
+ }
30
+ },
31
+ "then": { "required": ["encryption"] }
32
+ },
33
+ {
34
+ "if": { "required": ["encryption"] },
35
+ "then": {
36
+ "properties": {
37
+ "payload": {
38
+ "required": ["encrypted"],
39
+ "properties": { "encrypted": { "const": true } }
40
+ }
41
+ }
42
+ }
43
+ }
44
+ ],
21
45
  "properties": {
22
- "kdna_version": {
46
+ "format_version": {
23
47
  "type": "string",
24
- "description": "KDNA container version this manifest conforms to.",
25
- "enum": ["1.0"]
48
+ "description": "Compatibility coordinate for the KDNA container format.",
49
+ "const": "0.1.0"
26
50
  },
27
51
  "asset_id": {
28
52
  "type": "string",
@@ -81,17 +105,22 @@
81
105
  },
82
106
  "compatibility": {
83
107
  "type": "object",
84
- "required": ["min_loader_version", "profile"],
108
+ "required": ["min_loader_version", "profile", "profile_version"],
85
109
  "additionalProperties": true,
86
110
  "properties": {
87
111
  "min_loader_version": {
88
112
  "type": "string",
89
- "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+([+-].+)?$"
113
+ "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$",
114
+ "description": "Minimum compatible KDNA loader package coordinate. It must be strict x.y.z with no leading zeros, prerelease suffix, or build metadata."
90
115
  },
91
116
  "profile": {
92
117
  "type": "string",
93
- "description": "Payload profile identifier (e.g. judgment-profile-v1).",
94
- "enum": ["judgment-profile-v1", "bundle-profile-v1"]
118
+ "description": "Payload profile identifier (e.g. kdna.payload.judgment).",
119
+ "enum": ["kdna.payload.judgment", "kdna.payload.bundle"]
120
+ },
121
+ "profile_version": {
122
+ "const": "0.1.0",
123
+ "description": "Compatibility coordinate for the selected payload profile."
95
124
  }
96
125
  }
97
126
  },
@@ -105,6 +134,11 @@
105
134
  "encrypted": { "type": "boolean" }
106
135
  }
107
136
  },
137
+ "access": {
138
+ "type": "string",
139
+ "enum": ["public", "licensed", "remote"],
140
+ "description": "Stable delivery and authorization mode for the asset."
141
+ },
108
142
  "summary": { "type": "string" },
109
143
  "description": { "type": "string" },
110
144
  "language": { "type": "string" },
@@ -218,7 +252,33 @@
218
252
  }
219
253
  ]
220
254
  },
221
- "encryption": { "type": "object" },
255
+ "encryption": {
256
+ "type": "object",
257
+ "required": ["profile", "profile_version", "encrypted_entries"],
258
+ "additionalProperties": true,
259
+ "properties": {
260
+ "profile": {
261
+ "type": "string",
262
+ "enum": [
263
+ "kdna.encryption.licensed-entry",
264
+ "kdna.encryption.password",
265
+ "kdna.encryption.password.scrypt",
266
+ "kdna.envelope.external-grant"
267
+ ]
268
+ },
269
+ "profile_version": {
270
+ "const": "0.1.0",
271
+ "description": "Compatibility coordinate for the selected encryption or envelope profile."
272
+ },
273
+ "encrypted_entries": {
274
+ "type": "array",
275
+ "minItems": 1,
276
+ "maxItems": 1,
277
+ "uniqueItems": true,
278
+ "items": { "const": "payload.kdnab" }
279
+ }
280
+ }
281
+ },
222
282
  "load_contract": { "$ref": "load-contract.schema.json" },
223
283
  "scope": { "type": "object" },
224
284
  "evidence_claims": { "type": "object" }
@@ -1,16 +1,20 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://github.com/aikdna/kdna/schema/payload-profile-v1.schema.json",
4
- "title": "Judgment Profile v1",
3
+ "$id": "https://github.com/aikdna/kdna/schema/payload-profile.schema.json",
4
+ "title": "KDNA Judgment Payload Profile",
5
5
  "description": "Schema for the payload entry of a .kdna container. The payload is the actual judgment data.",
6
6
  "type": "object",
7
- "required": ["profile", "core"],
7
+ "required": ["profile", "profile_version", "core"],
8
8
  "additionalProperties": true,
9
9
  "properties": {
10
10
  "profile": {
11
11
  "type": "string",
12
- "const": "judgment-profile-v1",
13
- "description": "Profile identifier. Must be the literal string 'judgment-profile-v1'."
12
+ "const": "kdna.payload.judgment",
13
+ "description": "Profile identifier. Must be the literal string 'kdna.payload.judgment'."
14
+ },
15
+ "profile_version": {
16
+ "const": "0.1.0",
17
+ "description": "Compatibility coordinate for the judgment payload profile."
14
18
  },
15
19
  "core": {
16
20
  "type": "object",
@@ -76,7 +80,27 @@
76
80
  "type": "object",
77
81
  "additionalProperties": true,
78
82
  "properties": {
79
- "self_checks": { "type": "array", "items": { "type": "string" } },
83
+ "self_check": {
84
+ "type": "array",
85
+ "description": "Self-check questions. Each item is either a string or an object with a required string `question` field and optional metadata.",
86
+ "items": {
87
+ "oneOf": [
88
+ { "type": "string" },
89
+ {
90
+ "type": "object",
91
+ "required": ["question"],
92
+ "additionalProperties": true,
93
+ "properties": {
94
+ "question": { "type": "string" },
95
+ "applies_when": { "type": "array" },
96
+ "does_not_apply_when": { "type": "array" },
97
+ "failure_risk": { "type": "string" }
98
+ }
99
+ }
100
+ ]
101
+ }
102
+ },
103
+ "self_checks": false,
80
104
  "failure_modes": {
81
105
  "type": "array",
82
106
  "items": { "type": "object" }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://github.com/aikdna/kdna/specs/runtime-capsule-2.schema.json",
4
- "title": "KDNA Runtime Capsule 2",
5
- "description": "Opt-in Runtime Capsule carrying explicit A/C/E digest evidence. P is external delivery metadata and is never embedded here.",
3
+ "$id": "https://github.com/aikdna/kdna/specs/runtime-capsule.schema.json",
4
+ "title": "KDNA Runtime Capsule",
5
+ "description": "Current Runtime Capsule carrying explicit A/C/E digest evidence. P is external delivery metadata and is never embedded here.",
6
6
  "type": "object",
7
7
  "required": [
8
8
  "type",
9
- "version",
9
+ "contract_version",
10
10
  "asset",
11
11
  "digests",
12
12
  "signature",
@@ -18,8 +18,8 @@
18
18
  ],
19
19
  "additionalProperties": false,
20
20
  "properties": {
21
- "type": { "const": "kdna.context.capsule" },
22
- "version": { "const": "2.0" },
21
+ "type": { "const": "kdna.runtime-capsule" },
22
+ "contract_version": { "const": "0.1.0" },
23
23
  "asset": { "$ref": "#/$defs/asset" },
24
24
  "digests": {
25
25
  "allOf": [
@@ -40,8 +40,7 @@
40
40
  "risk_level": { "type": ["string", "null"] },
41
41
  "profile": { "enum": ["index", "compact", "scenario", "full"] },
42
42
  "context": { "type": "object" },
43
- "trace": { "$ref": "#/$defs/trace" },
44
- "compatibility": { "$ref": "#/$defs/compatibility" }
43
+ "trace": { "$ref": "#/$defs/trace" }
45
44
  },
46
45
  "$defs": {
47
46
  "sha256": {
@@ -112,29 +111,6 @@
112
111
  "signature_state": { "enum": ["verified", "not_checked", "absent"] },
113
112
  "profile": { "enum": ["index", "compact", "scenario", "full"] }
114
113
  }
115
- },
116
- "compatibility": {
117
- "description": "Adapter-only values with no Capsule 2 identity or routing authority.",
118
- "type": "object",
119
- "minProperties": 1,
120
- "additionalProperties": false,
121
- "properties": {
122
- "capsule_1_domain": { "type": "string", "minLength": 1 },
123
- "capsule_1_access": { "enum": ["open", "protected", "runtime"] },
124
- "capsule_1_extensions": { "$ref": "#/$defs/capsule1Extensions" }
125
- }
126
- },
127
- "capsule1Extensions": {
128
- "description": "Frozen Capsule 1 extension values carried only for exact one-way adapter parity.",
129
- "type": "object",
130
- "minProperties": 1,
131
- "additionalProperties": false,
132
- "properties": {
133
- "extends_chain": { "type": "array" },
134
- "inheritance_applied": { "type": "boolean" },
135
- "resolved_dependencies": { "type": "array" },
136
- "rag_isolation_policy": { "type": "object" }
137
- }
138
114
  }
139
115
  }
140
116
  }
@@ -6,6 +6,7 @@ const fs = require('fs');
6
6
  const crypto = require('crypto');
7
7
  const zlib = require('zlib');
8
8
  const cbor = require('cbor-x');
9
+ const { loaderVersionUnsupportedMessage } = require('./loader-compatibility');
9
10
 
10
11
  const KDNA_MEDIA_TYPE = 'application/vnd.kdna.asset';
11
12
  const ASSET_SOURCE_BYTES = Symbol.for('@aikdna/kdna-core.asset-source-bytes');
@@ -412,13 +413,18 @@ function validateCurrentContainer(asset) {
412
413
  if (!Buffer.isBuffer(bytes)) {
413
414
  throw new Error('Current KDNA validation requires the original .kdna container bytes');
414
415
  }
415
- return require('./v1').validate(bytes);
416
+ return require('./container').validate(bytes);
416
417
  }
417
418
 
418
419
  function appendCurrentValidationErrors(asset, errors) {
419
420
  try {
420
421
  const validation = validateCurrentContainer(asset);
421
422
  if (!validation.overall_valid) errors.push(...validation.problems);
423
+ if (validation.loader_compatible === false) {
424
+ errors.push(
425
+ loaderVersionUnsupportedMessage(validation.min_loader_version),
426
+ );
427
+ }
422
428
  } catch (e) {
423
429
  errors.push(e.message);
424
430
  }
@@ -456,7 +462,7 @@ function verifySync(asset, options = {}) {
456
462
  const warnings = [];
457
463
  const entries = listEntries(asset);
458
464
 
459
- // The current v1 implementation is the sole authority for container,
465
+ // The current implementation is the sole authority for container,
460
466
  // manifest, CBOR payload, checksum, and load-contract validity. The reader
461
467
  // adds transport identity and legacy signature hooks; it must not maintain a
462
468
  // second manifest or payload dialect.