@aikdna/kdna-core 0.18.0 → 0.20.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 +136 -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 +78 -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 -33
  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} +95 -254
  34. package/src/{execution-contract-v1.js → runtime-contract.js} +184 -152
  35. package/src/types.d.ts +200 -278
  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,371 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/aikdna/kdna/specs/agent-host-receipt.schema.json",
4
+ "title": "KDNA Agent Host Receipt",
5
+ "description": "Correlated Host response envelope. A matched runtime receipt proves only that the Host boundary accepted the exact Runtime Capsule value; it does not prove semantic consumption or conformance.",
6
+ "type": "object",
7
+ "required": ["protocol", "protocol_version", "request_id", "runtime_receipt", "outcome"],
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "protocol": {
11
+ "const": "kdna.agent-host"
12
+ },
13
+ "request_id": {
14
+ "type": "string",
15
+ "pattern": "^host_[0-9a-f]{24}$"
16
+ },
17
+ "runtime_receipt": {
18
+ "$ref": "#/$defs/runtimeReceipt"
19
+ },
20
+ "outcome": {
21
+ "oneOf": [
22
+ {
23
+ "$ref": "#/$defs/outcome"
24
+ },
25
+ {
26
+ "type": "null"
27
+ }
28
+ ]
29
+ },
30
+ "protocol_version": {
31
+ "const": "0.1.0"
32
+ }
33
+ },
34
+ "allOf": [
35
+ {
36
+ "if": {
37
+ "properties": {
38
+ "runtime_receipt": {
39
+ "properties": {
40
+ "provider_execution_status": {
41
+ "const": "completed"
42
+ }
43
+ },
44
+ "required": ["provider_execution_status"]
45
+ }
46
+ },
47
+ "required": ["runtime_receipt"]
48
+ },
49
+ "then": {
50
+ "properties": {
51
+ "outcome": {
52
+ "$ref": "#/$defs/outcome"
53
+ }
54
+ }
55
+ },
56
+ "else": {
57
+ "properties": {
58
+ "outcome": {
59
+ "type": "null"
60
+ }
61
+ }
62
+ }
63
+ }
64
+ ],
65
+ "$defs": {
66
+ "sha256": {
67
+ "type": "string",
68
+ "pattern": "^sha256:[0-9a-f]{64}$"
69
+ },
70
+ "runtimeReceipt": {
71
+ "type": "object",
72
+ "required": [
73
+ "type",
74
+ "contract_version",
75
+ "capsule_version",
76
+ "capsule_digest_profile",
77
+ "capsule_digest_profile_version",
78
+ "sender_capsule_delivery_digest",
79
+ "host_recomputed_capsule_delivery_digest",
80
+ "echoed_capsule_delivery_digest",
81
+ "capsule_delivery_comparison",
82
+ "capsule_schema_validation",
83
+ "asset_id_correlation",
84
+ "provider_execution_status",
85
+ "usage",
86
+ "semantic_consumption",
87
+ "model_identity"
88
+ ],
89
+ "additionalProperties": false,
90
+ "properties": {
91
+ "type": {
92
+ "const": "kdna.agent-host.runtime-receipt"
93
+ },
94
+ "capsule_version": {
95
+ "const": "0.1.0"
96
+ },
97
+ "capsule_digest_profile": {
98
+ "const": "kdna.canonicalization.runtime-capsule-jcs"
99
+ },
100
+ "sender_capsule_delivery_digest": {
101
+ "$ref": "#/$defs/sha256"
102
+ },
103
+ "host_recomputed_capsule_delivery_digest": {
104
+ "$ref": "#/$defs/sha256"
105
+ },
106
+ "echoed_capsule_delivery_digest": {
107
+ "$ref": "#/$defs/sha256"
108
+ },
109
+ "capsule_delivery_comparison": {
110
+ "enum": ["matched", "mismatched"]
111
+ },
112
+ "capsule_schema_validation": {
113
+ "const": "passed"
114
+ },
115
+ "asset_id_correlation": {
116
+ "const": "matched"
117
+ },
118
+ "provider_execution_status": {
119
+ "enum": ["completed", "not_started", "failed", "cancelled", "timed_out"]
120
+ },
121
+ "usage": {
122
+ "$ref": "#/$defs/observedUsage"
123
+ },
124
+ "semantic_consumption": {
125
+ "$ref": "#/$defs/semanticConsumption"
126
+ },
127
+ "model_identity": {
128
+ "$ref": "#/$defs/modelIdentity"
129
+ },
130
+ "contract_version": {
131
+ "const": "0.1.0"
132
+ },
133
+ "capsule_digest_profile_version": {
134
+ "const": "0.1.0"
135
+ }
136
+ },
137
+ "allOf": [
138
+ {
139
+ "if": {
140
+ "properties": {
141
+ "capsule_delivery_comparison": {
142
+ "const": "matched"
143
+ }
144
+ },
145
+ "required": ["capsule_delivery_comparison"]
146
+ },
147
+ "then": {
148
+ "properties": {
149
+ "provider_execution_status": {
150
+ "enum": ["completed", "failed", "cancelled", "timed_out"]
151
+ }
152
+ }
153
+ },
154
+ "else": {
155
+ "properties": {
156
+ "provider_execution_status": {
157
+ "const": "not_started"
158
+ },
159
+ "usage": {
160
+ "properties": {
161
+ "tokens_used": {
162
+ "type": "null"
163
+ },
164
+ "model_calls": {
165
+ "type": "null"
166
+ },
167
+ "basis": {
168
+ "const": "not_observed"
169
+ }
170
+ }
171
+ },
172
+ "model_identity": {
173
+ "properties": {
174
+ "value": {
175
+ "type": "null"
176
+ },
177
+ "basis": {
178
+ "const": "not_observed"
179
+ }
180
+ }
181
+ }
182
+ }
183
+ }
184
+ }
185
+ ]
186
+ },
187
+ "semanticConsumption": {
188
+ "type": "object",
189
+ "required": ["state", "basis"],
190
+ "additionalProperties": false,
191
+ "properties": {
192
+ "state": {
193
+ "const": "not_observed"
194
+ },
195
+ "basis": {
196
+ "type": "null"
197
+ }
198
+ }
199
+ },
200
+ "observedUsage": {
201
+ "type": "object",
202
+ "required": ["elapsed_ms", "elapsed_basis", "tokens_used", "model_calls", "basis"],
203
+ "additionalProperties": false,
204
+ "properties": {
205
+ "elapsed_ms": {
206
+ "type": "integer",
207
+ "minimum": 0
208
+ },
209
+ "elapsed_basis": {
210
+ "const": "host_monotonic"
211
+ },
212
+ "tokens_used": {
213
+ "oneOf": [
214
+ {
215
+ "type": "integer",
216
+ "minimum": 0
217
+ },
218
+ {
219
+ "type": "null"
220
+ }
221
+ ]
222
+ },
223
+ "model_calls": {
224
+ "oneOf": [
225
+ {
226
+ "type": "integer",
227
+ "minimum": 0
228
+ },
229
+ {
230
+ "type": "null"
231
+ }
232
+ ]
233
+ },
234
+ "basis": {
235
+ "enum": ["host_reported", "not_observed"]
236
+ }
237
+ },
238
+ "allOf": [
239
+ {
240
+ "if": {
241
+ "properties": {
242
+ "basis": {
243
+ "const": "host_reported"
244
+ }
245
+ },
246
+ "required": ["basis"]
247
+ },
248
+ "then": {
249
+ "properties": {
250
+ "tokens_used": {
251
+ "type": "integer",
252
+ "minimum": 0
253
+ },
254
+ "model_calls": {
255
+ "type": "integer",
256
+ "minimum": 0
257
+ }
258
+ }
259
+ },
260
+ "else": {
261
+ "properties": {
262
+ "tokens_used": {
263
+ "type": "null"
264
+ },
265
+ "model_calls": {
266
+ "type": "null"
267
+ }
268
+ }
269
+ }
270
+ }
271
+ ]
272
+ },
273
+ "modelIdentity": {
274
+ "type": "object",
275
+ "required": ["value", "basis"],
276
+ "additionalProperties": false,
277
+ "properties": {
278
+ "value": {
279
+ "type": ["string", "null"],
280
+ "minLength": 1
281
+ },
282
+ "basis": {
283
+ "enum": ["host_reported", "not_observed"]
284
+ }
285
+ },
286
+ "allOf": [
287
+ {
288
+ "if": {
289
+ "properties": {
290
+ "basis": {
291
+ "const": "host_reported"
292
+ }
293
+ },
294
+ "required": ["basis"]
295
+ },
296
+ "then": {
297
+ "properties": {
298
+ "value": {
299
+ "type": "string",
300
+ "minLength": 1
301
+ }
302
+ }
303
+ },
304
+ "else": {
305
+ "properties": {
306
+ "value": {
307
+ "type": "null"
308
+ }
309
+ }
310
+ }
311
+ }
312
+ ]
313
+ },
314
+ "outcome": {
315
+ "type": "object",
316
+ "required": ["judgment", "usage"],
317
+ "additionalProperties": false,
318
+ "properties": {
319
+ "judgment": {
320
+ "$ref": "#/$defs/judgment"
321
+ },
322
+ "usage": {
323
+ "oneOf": [
324
+ {
325
+ "$ref": "#/$defs/usage"
326
+ },
327
+ {
328
+ "type": "null"
329
+ }
330
+ ]
331
+ }
332
+ }
333
+ },
334
+ "judgment": {
335
+ "type": "object",
336
+ "required": ["answer", "reasoning", "confidence"],
337
+ "additionalProperties": false,
338
+ "properties": {
339
+ "answer": {
340
+ "type": "string",
341
+ "minLength": 1
342
+ },
343
+ "reasoning": {
344
+ "type": "array",
345
+ "items": {
346
+ "type": "string"
347
+ }
348
+ },
349
+ "confidence": {
350
+ "type": ["string", "null"],
351
+ "minLength": 1
352
+ }
353
+ }
354
+ },
355
+ "usage": {
356
+ "type": "object",
357
+ "required": ["tokens_used", "model_calls"],
358
+ "additionalProperties": false,
359
+ "properties": {
360
+ "tokens_used": {
361
+ "type": "integer",
362
+ "minimum": 0
363
+ },
364
+ "model_calls": {
365
+ "type": "integer",
366
+ "minimum": 0
367
+ }
368
+ }
369
+ }
370
+ }
371
+ }
@@ -0,0 +1,223 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/aikdna/kdna/specs/agent-host-request.schema.json",
4
+ "title": "KDNA Agent Host Request",
5
+ "description": "Agent Host request carrying one exact Runtime Capsule, plan correlation, detached delivery digest P, projection/result contracts, and enforceable limits.",
6
+ "type": "object",
7
+ "required": [
8
+ "protocol",
9
+ "protocol_version",
10
+ "request_id",
11
+ "plan_ref",
12
+ "runtime_contract",
13
+ "projection_contract",
14
+ "result_contract",
15
+ "budget",
16
+ "constraints",
17
+ "phase",
18
+ "task",
19
+ "authority",
20
+ "asset",
21
+ "capsule"
22
+ ],
23
+ "additionalProperties": false,
24
+ "properties": {
25
+ "protocol": {
26
+ "const": "kdna.agent-host"
27
+ },
28
+ "request_id": {
29
+ "type": "string",
30
+ "pattern": "^host_[0-9a-f]{24}$"
31
+ },
32
+ "plan_ref": {
33
+ "$ref": "#/$defs/planRef"
34
+ },
35
+ "runtime_contract": {
36
+ "$ref": "#/$defs/runtimeContract"
37
+ },
38
+ "projection_contract": {
39
+ "$ref": "#/$defs/projectionContract"
40
+ },
41
+ "result_contract": {
42
+ "$ref": "#/$defs/resultContract"
43
+ },
44
+ "budget": {
45
+ "$ref": "#/$defs/budget"
46
+ },
47
+ "constraints": {
48
+ "$ref": "#/$defs/constraints"
49
+ },
50
+ "phase": {
51
+ "const": "single_judgment"
52
+ },
53
+ "task": {
54
+ "$ref": "#/$defs/task"
55
+ },
56
+ "authority": {
57
+ "$ref": "#/$defs/authority"
58
+ },
59
+ "asset": {
60
+ "$ref": "#/$defs/asset"
61
+ },
62
+ "capsule": {
63
+ "$ref": "https://github.com/aikdna/kdna/specs/runtime-capsule.schema.json"
64
+ },
65
+ "protocol_version": {
66
+ "const": "0.1.0"
67
+ }
68
+ },
69
+ "$defs": {
70
+ "sha256": {
71
+ "type": "string",
72
+ "pattern": "^sha256:[0-9a-f]{64}$"
73
+ },
74
+ "assetId": {
75
+ "type": "string",
76
+ "pattern": "^[a-zA-Z][a-zA-Z0-9_-]*(:[a-zA-Z0-9_.-]+)+$"
77
+ },
78
+ "semver": {
79
+ "type": "string",
80
+ "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+([+-].+)?$"
81
+ },
82
+ "planRef": {
83
+ "type": "object",
84
+ "required": ["plan_id", "plan_digest_profile", "plan_digest_profile_version", "plan_digest"],
85
+ "additionalProperties": false,
86
+ "properties": {
87
+ "plan_id": {
88
+ "type": "string",
89
+ "pattern": "^plan_[0-9a-f]{16}$"
90
+ },
91
+ "plan_digest_profile": {
92
+ "const": "kdna.canonicalization.consumption-plan-jcs"
93
+ },
94
+ "plan_digest": {
95
+ "$ref": "#/$defs/sha256"
96
+ },
97
+ "plan_digest_profile_version": {
98
+ "const": "0.1.0"
99
+ }
100
+ }
101
+ },
102
+ "runtimeContract": {
103
+ "type": "object",
104
+ "required": [
105
+ "capsule_version",
106
+ "capsule_digest_profile",
107
+ "capsule_digest_profile_version",
108
+ "capsule_delivery_digest"
109
+ ],
110
+ "additionalProperties": false,
111
+ "properties": {
112
+ "capsule_version": {
113
+ "const": "0.1.0"
114
+ },
115
+ "capsule_digest_profile": {
116
+ "const": "kdna.canonicalization.runtime-capsule-jcs"
117
+ },
118
+ "capsule_delivery_digest": {
119
+ "$ref": "#/$defs/sha256"
120
+ },
121
+ "capsule_digest_profile_version": {
122
+ "const": "0.1.0"
123
+ }
124
+ }
125
+ },
126
+ "projectionContract": {
127
+ "type": "object",
128
+ "required": [
129
+ "profile",
130
+ "required_digest_profile",
131
+ "required_digest_profile_version",
132
+ "require_packaged_asset"
133
+ ],
134
+ "additionalProperties": false,
135
+ "properties": {
136
+ "profile": {
137
+ "enum": ["index", "compact", "scenario", "full"]
138
+ },
139
+ "required_digest_profile": {
140
+ "const": "kdna.digest-evidence"
141
+ },
142
+ "require_packaged_asset": {
143
+ "const": true
144
+ },
145
+ "required_digest_profile_version": {
146
+ "const": "0.1.0"
147
+ }
148
+ }
149
+ },
150
+ "resultContract": {
151
+ "type": "object",
152
+ "required": ["shape"],
153
+ "additionalProperties": false,
154
+ "properties": {
155
+ "shape": {
156
+ "const": "structured_judgment"
157
+ }
158
+ }
159
+ },
160
+ "budget": {
161
+ "$ref": "https://github.com/aikdna/kdna/specs/consumption-plan.schema.json#/$defs/budget"
162
+ },
163
+ "constraints": {
164
+ "$ref": "https://github.com/aikdna/kdna/specs/consumption-plan.schema.json#/$defs/constraints"
165
+ },
166
+ "task": {
167
+ "$ref": "https://github.com/aikdna/kdna/specs/consumption-plan.schema.json#/$defs/task"
168
+ },
169
+ "authority": {
170
+ "type": "object",
171
+ "required": ["asset_id", "role", "final_decision"],
172
+ "additionalProperties": false,
173
+ "properties": {
174
+ "asset_id": {
175
+ "$ref": "#/$defs/assetId"
176
+ },
177
+ "role": {
178
+ "const": "primary"
179
+ },
180
+ "final_decision": {
181
+ "const": true
182
+ }
183
+ }
184
+ },
185
+ "asset": {
186
+ "type": "object",
187
+ "required": [
188
+ "asset_id",
189
+ "asset_uid",
190
+ "version",
191
+ "judgment_version",
192
+ "access",
193
+ "role",
194
+ "expected_digests"
195
+ ],
196
+ "additionalProperties": false,
197
+ "properties": {
198
+ "asset_id": {
199
+ "$ref": "#/$defs/assetId"
200
+ },
201
+ "asset_uid": {
202
+ "type": "string",
203
+ "format": "uri"
204
+ },
205
+ "version": {
206
+ "$ref": "#/$defs/semver"
207
+ },
208
+ "judgment_version": {
209
+ "$ref": "#/$defs/semver"
210
+ },
211
+ "access": {
212
+ "enum": ["public", "licensed", "remote"]
213
+ },
214
+ "role": {
215
+ "const": "primary"
216
+ },
217
+ "expected_digests": {
218
+ "$ref": "https://github.com/aikdna/kdna/specs/consumption-plan.schema.json#/$defs/expectedDigests"
219
+ }
220
+ }
221
+ }
222
+ }
223
+ }
@@ -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/bundle-profile-v1.schema.json",
4
- "title": "Bundle Profile v1",
3
+ "$id": "https://github.com/aikdna/kdna/schema/bundle-profile.schema.json",
4
+ "title": "KDNA Bundle Payload Profile",
5
5
  "description": "Schema for the payload entry of a KDNA bundle container.",
6
6
  "type": "object",
7
- "required": ["profile", "components"],
7
+ "required": ["profile", "profile_version", "components"],
8
8
  "additionalProperties": true,
9
9
  "properties": {
10
10
  "profile": {
11
11
  "type": "string",
12
- "const": "bundle-profile-v1",
13
- "description": "Profile identifier. Must be the literal string 'bundle-profile-v1'."
12
+ "const": "kdna.payload.bundle",
13
+ "description": "Profile identifier. Must be the literal string 'kdna.payload.bundle'."
14
+ },
15
+ "profile_version": {
16
+ "const": "0.1.0",
17
+ "description": "Compatibility coordinate for the bundle payload profile."
14
18
  },
15
19
  "components": {
16
20
  "type": "array",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "https://github.com/aikdna/kdna/schema/checksums.schema.json",
4
- "title": "KDNA Checksums v1",
4
+ "title": "KDNA Checksums",
5
5
  "description": "Per-entry digests for a .kdna container. Stored as checksums.json at the container root.",
6
6
  "type": "object",
7
7
  "required": ["algorithm"],
@@ -27,6 +27,7 @@
27
27
  "then": {
28
28
  "required": [
29
29
  "digest_profile",
30
+ "digest_profile_version",
30
31
  "covered_entries",
31
32
  "manifest_digest",
32
33
  "payload_digest",
@@ -37,12 +38,16 @@
37
38
  ],
38
39
  "properties": {
39
40
  "digest_profile": {
40
- "const": "kdna-runtime-entry-set-v1",
41
+ "const": "kdna.digest-basis.runtime-entry-set",
41
42
  "description": "Algorithm and coverage profile for entry_set_digest."
42
43
  },
44
+ "digest_profile_version": {
45
+ "const": "0.1.0",
46
+ "description": "Compatibility coordinate for the entry-set digest basis."
47
+ },
43
48
  "covered_entries": {
44
49
  "type": "array",
45
- "description": "Ordered entries covered by kdna-runtime-entry-set-v1.",
50
+ "description": "Ordered entries covered by kdna.digest-basis.runtime-entry-set.",
46
51
  "prefixItems": [
47
52
  { "const": "kdna.json" },
48
53
  { "const": "payload.kdnab" }
@@ -64,11 +69,6 @@
64
69
  "description": "Digest of the payload.kdnab entry.",
65
70
  "$ref": "#/$defs/sha256Digest"
66
71
  },
67
- "asset_digest": {
68
- "deprecated": true,
69
- "description": "Deprecated v1 alias of entry_set_digest. This is not the final .kdna file digest.",
70
- "$ref": "#/$defs/sha256Digest"
71
- },
72
72
  "entry_set_digest": {
73
73
  "description": "Digest of the protected runtime entry set, combined deterministically from kdna.json and payload.kdnab entry digests.",
74
74
  "$ref": "#/$defs/sha256Digest"