@aikdna/kdna-core 0.17.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 (38) hide show
  1. package/CHANGELOG.md +227 -64
  2. package/README.md +114 -77
  3. package/package.json +8 -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 +42 -3
  9. package/schema/consumption-plan.schema.json +428 -0
  10. package/schema/digest-evidence.schema.json +212 -0
  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 +7 -5
  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.schema.json +116 -0
  18. package/src/asset-reader.js +106 -120
  19. package/src/{v1 → container}/index.js +566 -209
  20. package/src/container/index.mjs +20 -0
  21. package/src/container-dispatcher.js +10 -7
  22. package/src/crypto-profile.js +37 -107
  23. package/src/external-key-grant.js +41 -15
  24. package/src/index.js +11 -4
  25. package/src/index.mjs +143 -24
  26. package/src/loader-compatibility.js +59 -0
  27. package/src/loader.js +1 -1
  28. package/src/public-api.js +59 -163
  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 +9 -10
  33. package/src/runtime-capsule.js +529 -0
  34. package/src/runtime-contract.js +1882 -0
  35. package/src/types.d.ts +1127 -136
  36. package/src/workpack-pure.js +1 -1
  37. package/src/lint-pure.js +0 -430
  38. package/src/v1/index.mjs +0 -20
package/README.md CHANGED
@@ -1,138 +1,175 @@
1
1
  # @aikdna/kdna-core
2
2
 
3
- Core library for `.kdna` judgment assets. It implements the single KDNA Asset
4
- Container, strict-CBOR payload decoding, validation, LoadPlan authorization,
5
- and Runtime Capsule projection used by the CLI, Studio, skills, MCP
6
- integrations, and downstream Agent runtimes.
3
+ Core library for packaged `.kdna` judgment assets. It implements one current
4
+ container contract, authorization planning, integrity evidence, Runtime Capsule
5
+ projection, and the correlated Agent Host execution boundary.
7
6
 
8
- ## Installation
7
+ ## Install
9
8
 
10
9
  ```bash
11
10
  npm install @aikdna/kdna-core
12
11
  ```
13
12
 
14
- If you need full JSON Schema validation through Ajv, also install:
13
+ ## Pack, validate, plan, and load
15
14
 
16
- ```bash
17
- npm install ajv ajv-formats
18
- ```
19
-
20
- ## Public API
21
-
22
- Use the package root. Version-qualified entrypoints and API names are not part
23
- of the public contract.
15
+ Use the package root. Version-qualified entry points and parallel generation
16
+ APIs are not part of the public contract.
24
17
 
25
18
  ```js
26
19
  const {
27
- inspect,
20
+ pack,
28
21
  validate,
29
22
  planLoad,
30
23
  loadAuthorized,
31
- pack,
32
- unpack,
33
- buildChecksums
34
24
  } = require('@aikdna/kdna-core');
35
25
 
26
+ pack('./authoring-source', './asset.kdna');
27
+
36
28
  const validation = validate('./asset.kdna');
37
29
  if (!validation.overall_valid) {
38
30
  throw new Error(validation.problems.join('\n'));
39
31
  }
40
32
 
41
33
  const plan = planLoad('./asset.kdna');
42
- if (plan.can_load_now !== true) {
43
- throw new Error(`Asset is not loadable yet: ${plan.required_action}`);
34
+ if (!plan.can_load_now) {
35
+ throw new Error(`Asset is not loadable: ${plan.required_action}`);
44
36
  }
45
37
 
46
38
  const capsule = loadAuthorized('./asset.kdna', {
47
39
  profile: 'compact',
48
- as: 'json'
40
+ as: 'json',
49
41
  });
50
42
 
51
- if (capsule.type !== 'kdna.context.capsule') {
52
- throw new Error('Expected a Runtime Capsule');
43
+ if (
44
+ capsule.type !== 'kdna.runtime-capsule' ||
45
+ capsule.contract_version !== '0.1.0'
46
+ ) {
47
+ throw new Error('Unexpected Runtime Capsule contract');
53
48
  }
54
49
  ```
55
50
 
56
- ## Supported Runtime Flow
51
+ Runtime entry points accept final packaged bytes or a packaged file. Authoring
52
+ directories must be packed before they can produce a Runtime Capsule.
53
+
54
+ `compatibility.min_loader_version` is a strict `x.y.z` loader package
55
+ coordinate. `inspect` and `validate` expose it together with
56
+ `loader_version` and `loader_compatible`. Structural validation remains
57
+ separate from loadability: `planLoad` and every load path block a valid asset
58
+ that requires a newer loader with `KDNA_LOADER_VERSION_UNSUPPORTED` before
59
+ projection.
60
+
61
+ ## Stable Runtime contracts
62
+
63
+ There is one current responsibility chain:
57
64
 
58
65
  ```text
59
- .kdna file
66
+ packaged .kdna
60
67
  → validate
61
68
  → planLoad
62
- → loadAuthorized
69
+ → authorize
63
70
  → Runtime Capsule
64
- → Agent/runtime context
71
+ → Consumption Plan
72
+ → Agent Host request and correlated receipt
73
+ → Judgment Trace
65
74
  ```
66
75
 
67
- The default compact Capsule preserves the asset's scoped judgment context:
68
- `highest_question`, `worldview`, ordered `value_order`, `judgment_role`,
69
- applicability-aware axioms, boundaries, self-checks, failure modes, and a
70
- bounded pattern set. Core copies the three optional scoped fields without
71
- trimming, reordering, or treating them as facts, policy, or quality evidence.
76
+ Every KDNA-owned contract uses an explicit compatibility coordinate:
72
77
 
73
- For authoring and test fixtures, `pack()` can turn a local working folder into
74
- a `.kdna` file before validation:
78
+ | Contract | Identity | Compatibility coordinate |
79
+ | --- | --- | --- |
80
+ | Container manifest | `format_version` | `0.1.0` |
81
+ | Payload profile | `profile` + `profile_version` | `kdna.payload.judgment` + `0.1.0` |
82
+ | Runtime Capsule | `type` + `contract_version` | `kdna.runtime-capsule` + `0.1.0` |
83
+ | Consumption Plan | `type` + `contract_version` | `kdna.consumption-plan` + `0.1.0` |
84
+ | Agent Host | `protocol` + `protocol_version` | `kdna.agent-host` + `0.1.0` |
85
+ | Judgment Trace | `type` + `contract_version` | `kdna.judgment-trace` + `0.1.0` |
75
86
 
76
- ```text
77
- local working folder
78
- → pack
79
- → .kdna file
80
- → validate
81
- → planLoad
82
- → loadAuthorized
83
- ```
87
+ There is no public adapter between competing Capsule or Host generations.
88
+ Unsupported compatibility coordinates fail closed.
89
+
90
+ ## Digest responsibilities
91
+
92
+ Core keeps four digest bases separate:
93
+
94
+ - **A** — final packaged container bytes;
95
+ - **C** — the canonical content tree;
96
+ - **E** — the raw `kdna.json` and `payload.kdnab` runtime entry set;
97
+ - **P** — the canonical Runtime Capsule delivered to a Host.
98
+
99
+ Use `computeDigestEvidence()` for A/C/E and
100
+ `computeCapsuleDeliveryDigest()` for P. A grant or registry expectation for A
101
+ must never be compared with E from `checksums.json`.
84
102
 
85
- ## KDNA Asset Container
103
+ ## Consumption and Host execution
86
104
 
87
- A `.kdna` asset contains:
105
+ `buildConsumptionPlan()` creates the single-asset execution plan and its
106
+ detached integrity digest. `buildAgentHostRequest()` validates the accepted
107
+ Plan digest, observed Host capabilities, Capsule compatibility coordinate,
108
+ task, asset identity, budgets, and P before producing a request.
88
109
 
89
- - `mimetype`
90
- - `kdna.json`
91
- - `payload.kdnab`
92
- - `checksums.json`
110
+ Untrusted Host JSON must enter through `parseRuntimeContractJson()` before
111
+ object validation. It rejects duplicate keys, invalid UTF-8, non-JSON numeric
112
+ values, trailing input, and excessive input before correlation checks run.
93
113
 
94
- `validate()` checks:
114
+ `buildJudgmentTrace()` records delivery, Host execution, budget, result, and
115
+ error evidence. A correlated receipt proves a technical boundary event; it
116
+ does not prove semantic consumption, behavioral influence, judgment quality,
117
+ or model conformance.
95
118
 
96
- - format
97
- - manifest schema
98
- - payload parseability
99
- - checksum consistency
100
- - load-profile contract
119
+ If the exact projection or task exceeds an enforceable pre-Host budget,
120
+ `buildAgentHostRequest()` fails closed. Use
121
+ `buildPreHostBudgetBlockedTrace()` to retain a terminal evidence record without
122
+ creating a deliverable Host request.
101
123
 
102
- `payload.kdnab` is CBOR. A password-protected or licensed asset stores a CBOR
103
- encryption envelope in the same entry; authorized plaintext is decrypted in
104
- memory and projected into the Runtime Capsule.
124
+ ## Licensed account/device grants
105
125
 
106
- ### Account/device external grants
126
+ `authorizeExternalKeyGrant()` verifies the issuer signature, time window,
127
+ status, account, device, final packaged asset digest A, and encrypted entry.
128
+ It returns a branded entitlement and an in-memory decrypt hook. A plain object
129
+ such as `{ status: 'active' }` is not authorization.
107
130
 
108
- RFC-0019 licensed assets can keep the encrypted container publicly available
109
- while an issuer grants independent account/device access. `authorizeExternalKeyGrant()`
110
- verifies the issuer signature, lease, revocation state, account, device, asset
111
- UID/version/digest, and encrypted entry before returning a branded entitlement
112
- and in-memory decrypt hook. A plain `{status: "active"}` object is not accepted.
131
+ Keep device private keys in the platform secret store, dispose the returned
132
+ session after loading, and expose only the Runtime Capsule to Agent-facing
133
+ callers. Account grants never silently fall back to password authorization.
113
134
 
114
- Device private keys belong in the platform SecretStore. The returned session
115
- must be disposed after loading; Agent-facing callers should receive only the
116
- Runtime Capsule. Account grants never fall back to the password profile.
135
+ ## Projection profiles
117
136
 
118
- ## Load Profiles
137
+ `loadAuthorized()` supports `index`, `compact`, `scenario`, and `full`, with
138
+ `json` or `prompt` output. The requested profile controls the emitted context
139
+ shape; implementations must not label one projection as another.
119
140
 
120
- `loadAuthorized()` supports:
141
+ ## Deployer-controlled remote Runtime
121
142
 
122
- - `index`
123
- - `compact`
124
- - `scenario`
125
- - `full`
143
+ Ordinary consumers always receive `needs_runtime` / `connect_runtime` when an
144
+ asset declares `access: "remote"`. A deployer that physically controls the
145
+ server-side packaged asset uses the separate package subpath:
146
+
147
+ ```js
148
+ const {
149
+ loadRemoteRuntimeAsset,
150
+ } = require('@aikdna/kdna-core/remote-runtime');
151
+
152
+ const fullCapsule = loadRemoteRuntimeAsset('./deployed-judgment.kdna');
153
+ ```
126
154
 
127
- Output formats:
155
+ The function accepts one final packaged file path or packaged byte buffer. It
156
+ validates and plans one immutable byte snapshot, accepts only a single remote
157
+ asset, and returns a full JSON Runtime Capsule for the server's projection
158
+ engine. It does not accept caller-selected access, profile, output, dependency,
159
+ or inheritance options.
128
160
 
129
- - `json`
130
- - `prompt`
161
+ Possession of the deployed asset is the authorization boundary for this
162
+ server-side API. The API does not authenticate network callers, verify their
163
+ entitlements, make plaintext confidential from the deployer, minimize the
164
+ projection returned to a client, or provide an AIKDNA-hosted service. The
165
+ embedding Runtime must implement those request and disclosure controls and
166
+ must never return the full server-side Capsule to an Agent client.
131
167
 
132
168
  ## Boundary
133
169
 
134
- KDNA Core is content-neutral. It validates file structure and loadability;
135
- it does not rank judgment quality or endorse specific assets.
170
+ Core validates technical structure, integrity, authorization, compatibility,
171
+ and observed execution facts. It does not rank judgment quality, endorse an
172
+ asset, or claim that a model understood or followed loaded judgment.
136
173
 
137
174
  ## License
138
175
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aikdna/kdna-core",
3
- "version": "0.17.0",
3
+ "version": "0.19.0",
4
4
  "description": "KDNA Core library for validating, planning, and loading local .kdna judgment assets.",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -14,6 +14,11 @@
14
14
  "require": "./src/index.js",
15
15
  "types": "./src/types.d.ts"
16
16
  },
17
+ "./remote-runtime": {
18
+ "import": "./src/remote-runtime.mjs",
19
+ "require": "./src/remote-runtime.js",
20
+ "types": "./src/remote-runtime.d.ts"
21
+ },
17
22
  "./package.json": "./package.json",
18
23
  "./schema/*": "./schema/*"
19
24
  },
@@ -21,7 +26,8 @@
21
26
  "scripts": {
22
27
  "test": "node ../../scripts/run-node-tests.js test/*.test.js && node -e \"const m = require('./src/index.js'); console.log('kdna-core exports:', Object.keys(m).join(', '));\"",
23
28
  "prepublishOnly": "npm run release:check",
24
- "release:check": "node scripts/check-release-readiness.js"
29
+ "release:check": "node ../../scripts/check-post-cutover-naming.mjs && node scripts/check-release-readiness.js",
30
+ "publish:guard": "node scripts/check-publish-duplicate.js"
25
31
  },
26
32
  "files": [
27
33
  "src/",
@@ -0,0 +1,62 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/aikdna/kdna/specs/agent-host-capabilities.schema.json",
4
+ "title": "KDNA Agent Host Capabilities",
5
+ "description": "Orthogonal capabilities observed before Runtime contract execution.",
6
+ "type": "object",
7
+ "required": [
8
+ "type",
9
+ "protocol_version",
10
+ "capability_basis",
11
+ "host_protocols",
12
+ "capsule_versions",
13
+ "capsule_digest_profiles",
14
+ "capsule_digest_profile_versions"
15
+ ],
16
+ "additionalProperties": false,
17
+ "properties": {
18
+ "type": {
19
+ "const": "kdna.agent-host-capabilities"
20
+ },
21
+ "capability_basis": {
22
+ "enum": ["registered_descriptor", "legacy_assumption"]
23
+ },
24
+ "host_protocols": {
25
+ "type": "array",
26
+ "minItems": 1,
27
+ "uniqueItems": true,
28
+ "items": {
29
+ "enum": ["kdna.agent-host"]
30
+ }
31
+ },
32
+ "capsule_versions": {
33
+ "type": "array",
34
+ "minItems": 1,
35
+ "uniqueItems": true,
36
+ "items": {
37
+ "enum": ["0.1.0"]
38
+ }
39
+ },
40
+ "capsule_digest_profiles": {
41
+ "type": "array",
42
+ "uniqueItems": true,
43
+ "items": {
44
+ "const": "kdna.canonicalization.runtime-capsule-jcs"
45
+ }
46
+ },
47
+ "protocol_version": {
48
+ "const": "0.1.0"
49
+ },
50
+ "capsule_digest_profile_versions": {
51
+ "type": "array",
52
+ "prefixItems": [
53
+ {
54
+ "const": "0.1.0"
55
+ }
56
+ ],
57
+ "items": false,
58
+ "minItems": 1,
59
+ "maxItems": 1
60
+ }
61
+ }
62
+ }