@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,428 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/aikdna/kdna/specs/consumption-plan.schema.json",
4
+ "title": "KDNA ConsumptionPlan",
5
+ "description": "Single-asset plan for Runtime Capsule delivery to an Agent Host.",
6
+ "type": "object",
7
+ "required": [
8
+ "type",
9
+ "contract_version",
10
+ "plan_id",
11
+ "created_at",
12
+ "mode",
13
+ "task",
14
+ "asset_ref",
15
+ "projection_request",
16
+ "host_request",
17
+ "result_request",
18
+ "budget",
19
+ "constraints",
20
+ "trace_policy",
21
+ "integrity"
22
+ ],
23
+ "additionalProperties": false,
24
+ "properties": {
25
+ "type": {
26
+ "const": "kdna.consumption-plan"
27
+ },
28
+ "plan_id": {
29
+ "type": "string",
30
+ "pattern": "^plan_[0-9a-f]{16}$"
31
+ },
32
+ "created_at": {
33
+ "type": "string",
34
+ "format": "date-time"
35
+ },
36
+ "mode": {
37
+ "const": "single"
38
+ },
39
+ "task": {
40
+ "$ref": "#/$defs/task"
41
+ },
42
+ "asset_ref": {
43
+ "$ref": "#/$defs/assetRef"
44
+ },
45
+ "projection_request": {
46
+ "$ref": "#/$defs/projectionRequest"
47
+ },
48
+ "host_request": {
49
+ "$ref": "#/$defs/hostRequest"
50
+ },
51
+ "result_request": {
52
+ "$ref": "#/$defs/resultRequest"
53
+ },
54
+ "budget": {
55
+ "$ref": "#/$defs/budget"
56
+ },
57
+ "constraints": {
58
+ "$ref": "#/$defs/constraints"
59
+ },
60
+ "trace_policy": {
61
+ "$ref": "#/$defs/tracePolicy"
62
+ },
63
+ "integrity": {
64
+ "$ref": "#/$defs/integrity"
65
+ },
66
+ "contract_version": {
67
+ "const": "0.1.0"
68
+ }
69
+ },
70
+ "$defs": {
71
+ "sha256": {
72
+ "type": "string",
73
+ "pattern": "^sha256:[0-9a-f]{64}$"
74
+ },
75
+ "semver": {
76
+ "type": "string",
77
+ "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+([+-].+)?$"
78
+ },
79
+ "assetId": {
80
+ "type": "string",
81
+ "pattern": "^[a-zA-Z][a-zA-Z0-9_-]*(:[a-zA-Z0-9_.-]+)+$"
82
+ },
83
+ "task": {
84
+ "type": "object",
85
+ "required": ["summary", "task_family", "context"],
86
+ "additionalProperties": false,
87
+ "properties": {
88
+ "summary": {
89
+ "type": "string",
90
+ "minLength": 1,
91
+ "maxLength": 500
92
+ },
93
+ "task_family": {
94
+ "type": ["string", "null"],
95
+ "minLength": 1
96
+ },
97
+ "context": true
98
+ }
99
+ },
100
+ "expectedDigest": {
101
+ "type": "object",
102
+ "required": ["value", "basis", "source", "comparison"],
103
+ "additionalProperties": false,
104
+ "properties": {
105
+ "value": {
106
+ "$ref": "#/$defs/sha256"
107
+ },
108
+ "basis": {
109
+ "type": "string"
110
+ },
111
+ "source": {
112
+ "enum": [
113
+ "caller",
114
+ "registry",
115
+ "install_receipt",
116
+ "lockfile",
117
+ "kdna.json.content_digest",
118
+ "checksums.json.entry_set_digest"
119
+ ]
120
+ },
121
+ "comparison": {
122
+ "enum": ["matched", "not_compared"]
123
+ }
124
+ },
125
+ "allOf": [
126
+ {
127
+ "if": {
128
+ "properties": {
129
+ "source": {
130
+ "const": "caller"
131
+ }
132
+ },
133
+ "required": ["source"]
134
+ },
135
+ "then": {
136
+ "properties": {
137
+ "comparison": {
138
+ "const": "not_compared"
139
+ }
140
+ }
141
+ },
142
+ "else": {
143
+ "properties": {
144
+ "comparison": {
145
+ "const": "matched"
146
+ }
147
+ }
148
+ }
149
+ }
150
+ ]
151
+ },
152
+ "assetRef": {
153
+ "type": "object",
154
+ "required": [
155
+ "asset_id",
156
+ "asset_uid",
157
+ "version",
158
+ "judgment_version",
159
+ "access",
160
+ "expected_digests"
161
+ ],
162
+ "additionalProperties": false,
163
+ "properties": {
164
+ "asset_id": {
165
+ "$ref": "#/$defs/assetId"
166
+ },
167
+ "asset_uid": {
168
+ "type": "string",
169
+ "format": "uri"
170
+ },
171
+ "version": {
172
+ "$ref": "#/$defs/semver"
173
+ },
174
+ "judgment_version": {
175
+ "$ref": "#/$defs/semver"
176
+ },
177
+ "access": {
178
+ "enum": ["public", "licensed", "remote"]
179
+ },
180
+ "expected_digests": {
181
+ "$ref": "#/$defs/expectedDigests"
182
+ }
183
+ }
184
+ },
185
+ "expectedDigests": {
186
+ "type": "object",
187
+ "required": ["asset", "content", "runtime_entry_set"],
188
+ "additionalProperties": false,
189
+ "properties": {
190
+ "asset": {
191
+ "oneOf": [
192
+ {
193
+ "allOf": [
194
+ {
195
+ "$ref": "#/$defs/expectedDigest"
196
+ },
197
+ {
198
+ "properties": {
199
+ "basis": {
200
+ "const": "kdna.digest-basis.container-bytes"
201
+ },
202
+ "source": {
203
+ "enum": ["caller", "registry", "install_receipt", "lockfile"]
204
+ }
205
+ }
206
+ }
207
+ ]
208
+ },
209
+ {
210
+ "type": "null"
211
+ }
212
+ ]
213
+ },
214
+ "content": {
215
+ "oneOf": [
216
+ {
217
+ "allOf": [
218
+ {
219
+ "$ref": "#/$defs/expectedDigest"
220
+ },
221
+ {
222
+ "properties": {
223
+ "basis": {
224
+ "const": "kdna.digest-basis.content-tree"
225
+ },
226
+ "source": {
227
+ "enum": [
228
+ "caller",
229
+ "registry",
230
+ "install_receipt",
231
+ "lockfile",
232
+ "kdna.json.content_digest"
233
+ ]
234
+ }
235
+ }
236
+ }
237
+ ]
238
+ },
239
+ {
240
+ "type": "null"
241
+ }
242
+ ]
243
+ },
244
+ "runtime_entry_set": {
245
+ "oneOf": [
246
+ {
247
+ "allOf": [
248
+ {
249
+ "$ref": "#/$defs/expectedDigest"
250
+ },
251
+ {
252
+ "properties": {
253
+ "basis": {
254
+ "const": "kdna.digest-basis.runtime-entry-set"
255
+ },
256
+ "source": {
257
+ "enum": [
258
+ "caller",
259
+ "registry",
260
+ "install_receipt",
261
+ "lockfile",
262
+ "checksums.json.entry_set_digest"
263
+ ]
264
+ }
265
+ }
266
+ }
267
+ ]
268
+ },
269
+ {
270
+ "type": "null"
271
+ }
272
+ ]
273
+ }
274
+ }
275
+ },
276
+ "projectionRequest": {
277
+ "type": "object",
278
+ "required": [
279
+ "profile",
280
+ "accepted_capsule_versions",
281
+ "required_digest_profile",
282
+ "required_digest_profile_version",
283
+ "require_packaged_asset"
284
+ ],
285
+ "additionalProperties": false,
286
+ "properties": {
287
+ "profile": {
288
+ "enum": ["index", "compact", "scenario", "full"]
289
+ },
290
+ "accepted_capsule_versions": {
291
+ "type": "array",
292
+ "prefixItems": [
293
+ {
294
+ "const": "0.1.0"
295
+ }
296
+ ],
297
+ "minItems": 1,
298
+ "maxItems": 1
299
+ },
300
+ "required_digest_profile": {
301
+ "const": "kdna.digest-evidence"
302
+ },
303
+ "require_packaged_asset": {
304
+ "const": true
305
+ },
306
+ "required_digest_profile_version": {
307
+ "const": "0.1.0"
308
+ }
309
+ }
310
+ },
311
+ "hostRequest": {
312
+ "type": "object",
313
+ "required": ["accepted_protocols"],
314
+ "additionalProperties": false,
315
+ "properties": {
316
+ "accepted_protocols": {
317
+ "type": "array",
318
+ "prefixItems": [
319
+ {
320
+ "const": "kdna.agent-host"
321
+ }
322
+ ],
323
+ "minItems": 1,
324
+ "maxItems": 1
325
+ }
326
+ }
327
+ },
328
+ "resultRequest": {
329
+ "type": "object",
330
+ "required": ["shape"],
331
+ "additionalProperties": false,
332
+ "properties": {
333
+ "shape": {
334
+ "const": "structured_judgment"
335
+ }
336
+ }
337
+ },
338
+ "budget": {
339
+ "type": "object",
340
+ "required": [
341
+ "max_projection_chars",
342
+ "max_task_chars",
343
+ "deadline_ms",
344
+ "max_tokens",
345
+ "max_model_calls"
346
+ ],
347
+ "additionalProperties": false,
348
+ "properties": {
349
+ "max_projection_chars": {
350
+ "type": "integer",
351
+ "minimum": 0
352
+ },
353
+ "max_task_chars": {
354
+ "type": "integer",
355
+ "minimum": 0
356
+ },
357
+ "deadline_ms": {
358
+ "type": "integer",
359
+ "minimum": 1
360
+ },
361
+ "max_tokens": {
362
+ "oneOf": [
363
+ {
364
+ "type": "integer",
365
+ "minimum": 0
366
+ },
367
+ {
368
+ "type": "null"
369
+ }
370
+ ]
371
+ },
372
+ "max_model_calls": {
373
+ "oneOf": [
374
+ {
375
+ "type": "integer",
376
+ "minimum": 0
377
+ },
378
+ {
379
+ "type": "null"
380
+ }
381
+ ]
382
+ }
383
+ }
384
+ },
385
+ "constraints": {
386
+ "type": "object",
387
+ "required": ["enforce_before_host", "reject_on_exceed"],
388
+ "additionalProperties": false,
389
+ "properties": {
390
+ "enforce_before_host": {
391
+ "const": true
392
+ },
393
+ "reject_on_exceed": {
394
+ "const": true
395
+ }
396
+ }
397
+ },
398
+ "tracePolicy": {
399
+ "type": "object",
400
+ "required": ["emit", "storage"],
401
+ "additionalProperties": false,
402
+ "properties": {
403
+ "emit": {
404
+ "const": true
405
+ },
406
+ "storage": {
407
+ "enum": ["ephemeral", "session", "persistent"]
408
+ }
409
+ }
410
+ },
411
+ "integrity": {
412
+ "type": "object",
413
+ "required": ["profile", "profile_version", "plan_digest"],
414
+ "additionalProperties": false,
415
+ "properties": {
416
+ "profile": {
417
+ "const": "kdna.canonicalization.consumption-plan-jcs"
418
+ },
419
+ "plan_digest": {
420
+ "$ref": "#/$defs/sha256"
421
+ },
422
+ "profile_version": {
423
+ "const": "0.1.0"
424
+ }
425
+ }
426
+ }
427
+ }
428
+ }
@@ -4,26 +4,55 @@
4
4
  "title": "KDNA Digest Evidence",
5
5
  "description": "Observed A/C/E digest values, their fixed bases, and factual comparison evidence.",
6
6
  "type": "object",
7
- "required": ["profile", "asset", "content", "runtime_entry_set"],
7
+ "required": ["profile", "profile_version", "asset", "content", "runtime_entry_set"],
8
8
  "additionalProperties": false,
9
9
  "properties": {
10
- "profile": { "const": "kdna-capsule-digests-v1" },
10
+ "profile": {
11
+ "const": "kdna.digest-evidence"
12
+ },
13
+ "profile_version": {
14
+ "const": "0.1.0"
15
+ },
11
16
  "asset": {
12
17
  "allOf": [
13
- { "$ref": "#/$defs/digest" },
14
- { "properties": { "basis": { "const": "kdna-container-bytes-v1" } } }
18
+ {
19
+ "$ref": "#/$defs/digest"
20
+ },
21
+ {
22
+ "properties": {
23
+ "basis": {
24
+ "const": "kdna.digest-basis.container-bytes"
25
+ }
26
+ }
27
+ }
15
28
  ]
16
29
  },
17
30
  "content": {
18
31
  "allOf": [
19
- { "$ref": "#/$defs/digest" },
20
- { "properties": { "basis": { "const": "kdna-content-tree-v1" } } }
32
+ {
33
+ "$ref": "#/$defs/digest"
34
+ },
35
+ {
36
+ "properties": {
37
+ "basis": {
38
+ "const": "kdna.digest-basis.content-tree"
39
+ }
40
+ }
41
+ }
21
42
  ]
22
43
  },
23
44
  "runtime_entry_set": {
24
45
  "allOf": [
25
- { "$ref": "#/$defs/digest" },
26
- { "properties": { "basis": { "const": "kdna-runtime-entry-set-v1" } } }
46
+ {
47
+ "$ref": "#/$defs/digest"
48
+ },
49
+ {
50
+ "properties": {
51
+ "basis": {
52
+ "const": "kdna.digest-basis.runtime-entry-set"
53
+ }
54
+ }
55
+ }
27
56
  ]
28
57
  }
29
58
  },
@@ -40,8 +69,7 @@
40
69
  "lockfile",
41
70
  "kdna.json.content_digest",
42
71
  "kdna.json.authoring.content_digest",
43
- "checksums.json.entry_set_digest",
44
- "checksums.json.asset_digest"
72
+ "checksums.json.entry_set_digest"
45
73
  ]
46
74
  },
47
75
  "comparison": {
@@ -57,36 +85,70 @@
57
85
  "enum": ["external_expected", "manifest_declaration", "checksum_declaration", null]
58
86
  },
59
87
  "expected": {
60
- "oneOf": [{ "$ref": "#/$defs/sha256" }, { "type": "null" }]
88
+ "oneOf": [
89
+ {
90
+ "$ref": "#/$defs/sha256"
91
+ },
92
+ {
93
+ "type": "null"
94
+ }
95
+ ]
61
96
  },
62
97
  "source": {
63
- "oneOf": [{ "$ref": "#/$defs/comparisonSource" }, { "type": "null" }]
98
+ "oneOf": [
99
+ {
100
+ "$ref": "#/$defs/comparisonSource"
101
+ },
102
+ {
103
+ "type": "null"
104
+ }
105
+ ]
64
106
  }
65
107
  },
66
108
  "allOf": [
67
109
  {
68
110
  "if": {
69
- "properties": { "state": { "enum": ["matched", "mismatched"] } },
111
+ "properties": {
112
+ "state": {
113
+ "enum": ["matched", "mismatched"]
114
+ }
115
+ },
70
116
  "required": ["state"]
71
117
  },
72
118
  "then": {
73
119
  "properties": {
74
- "against": { "type": "string" },
75
- "expected": { "$ref": "#/$defs/sha256" },
76
- "source": { "$ref": "#/$defs/comparisonSource" }
120
+ "against": {
121
+ "type": "string"
122
+ },
123
+ "expected": {
124
+ "$ref": "#/$defs/sha256"
125
+ },
126
+ "source": {
127
+ "$ref": "#/$defs/comparisonSource"
128
+ }
77
129
  }
78
130
  }
79
131
  },
80
132
  {
81
133
  "if": {
82
- "properties": { "state": { "enum": ["not_compared", "unavailable"] } },
134
+ "properties": {
135
+ "state": {
136
+ "enum": ["not_compared", "unavailable"]
137
+ }
138
+ },
83
139
  "required": ["state"]
84
140
  },
85
141
  "then": {
86
142
  "properties": {
87
- "against": { "type": "null" },
88
- "expected": { "type": "null" },
89
- "source": { "type": "null" }
143
+ "against": {
144
+ "type": "null"
145
+ },
146
+ "expected": {
147
+ "type": "null"
148
+ },
149
+ "source": {
150
+ "type": "null"
151
+ }
90
152
  }
91
153
  }
92
154
  }
@@ -98,24 +160,51 @@
98
160
  "additionalProperties": false,
99
161
  "properties": {
100
162
  "value": {
101
- "oneOf": [{ "$ref": "#/$defs/sha256" }, { "type": "null" }]
163
+ "oneOf": [
164
+ {
165
+ "$ref": "#/$defs/sha256"
166
+ },
167
+ {
168
+ "type": "null"
169
+ }
170
+ ]
102
171
  },
103
- "basis": { "type": "string" },
104
- "comparison": { "$ref": "#/$defs/comparison" }
172
+ "basis": {
173
+ "type": "string"
174
+ },
175
+ "comparison": {
176
+ "$ref": "#/$defs/comparison"
177
+ }
105
178
  },
106
179
  "allOf": [
107
180
  {
108
181
  "if": {
109
182
  "properties": {
110
183
  "comparison": {
111
- "properties": { "state": { "const": "unavailable" } },
184
+ "properties": {
185
+ "state": {
186
+ "const": "unavailable"
187
+ }
188
+ },
112
189
  "required": ["state"]
113
190
  }
114
191
  },
115
192
  "required": ["comparison"]
116
193
  },
117
- "then": { "properties": { "value": { "type": "null" } } },
118
- "else": { "properties": { "value": { "$ref": "#/$defs/sha256" } } }
194
+ "then": {
195
+ "properties": {
196
+ "value": {
197
+ "type": "null"
198
+ }
199
+ }
200
+ },
201
+ "else": {
202
+ "properties": {
203
+ "value": {
204
+ "$ref": "#/$defs/sha256"
205
+ }
206
+ }
207
+ }
119
208
  }
120
209
  ]
121
210
  }
@@ -1,12 +1,25 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://kdna.ai/specs/kdna-envelope-external-grant-v1.schema.json",
4
- "title": "KDNA external grant envelope v1",
3
+ "$id": "https://kdna.ai/specs/external-grant-envelope.schema.json",
4
+ "title": "KDNA External Grant Envelope",
5
5
  "type": "object",
6
6
  "additionalProperties": false,
7
- "required": ["profile", "alg", "cek_derivation", "key_ref", "issuer_key_id", "entry_path", "plaintext_digest", "iv", "tag", "ciphertext"],
7
+ "required": [
8
+ "profile",
9
+ "contract_version",
10
+ "alg",
11
+ "cek_derivation",
12
+ "key_ref",
13
+ "issuer_key_id",
14
+ "entry_path",
15
+ "plaintext_digest",
16
+ "iv",
17
+ "tag",
18
+ "ciphertext"
19
+ ],
8
20
  "properties": {
9
- "profile": { "const": "kdna-envelope-external-grant-v1" },
21
+ "profile": { "const": "kdna.envelope.external-grant" },
22
+ "contract_version": { "const": "0.1.0" },
10
23
  "alg": { "const": "A256GCM" },
11
24
  "cek_derivation": { "const": "HKDF-SHA256" },
12
25
  "key_ref": { "type": "string", "minLength": 1, "maxLength": 256 },