@aikdna/kdna-core 0.15.4 → 0.15.6
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.
- package/CHANGELOG.md +37 -0
- package/package.json +1 -1
- package/schema/bundle-profile-v1.schema.json +39 -0
- package/schema/manifest.schema.json +4 -4
- package/src/asset-reader.js +9 -0
- package/src/lint-pure.js +1 -0
- package/src/types.d.ts +1 -0
- package/src/v1/index.js +65 -13
- package/src/v1/index.mjs +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v0.15.6 (2026-06-28)
|
|
4
|
+
|
|
5
|
+
Story 5 — Bundle payload type. Bumps KDNA manifest format schema to v2, introduces bundle-profile-v1 payload profile, and starts KDNA v1 format deprecation window.
|
|
6
|
+
|
|
7
|
+
- **Bundle asset_type support:** added `"bundle"` to `asset_type` enum and `VALID_ASSET_TYPE` check.
|
|
8
|
+
- **V2 Schema support:** bumped manifest schema version to v2.0, supporting `kdna_version` as `"2.0"`.
|
|
9
|
+
- **Bundle profile support:** added `bundle-profile-v1` payload profile and validator.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## v0.15.5 (2026-06-28)
|
|
13
|
+
|
|
14
|
+
Phase 12 audit follow-up. Closes 3 issues filed against this
|
|
15
|
+
repo (#145, #146, #147).
|
|
16
|
+
|
|
17
|
+
- **#145** The `compilePatterns` output for `misunderstanding`
|
|
18
|
+
cards was already preserved (the v1 round-trip fix in 0.15.4
|
|
19
|
+
carried `failure_risk` / `applies_when` / `does_not_apply_when`).
|
|
20
|
+
The audit confirmed the fix is in place. No code change required;
|
|
21
|
+
this entry documents the verification.
|
|
22
|
+
- **#146** `cardsFromV1Payload` (in the studio-cli consumer) now
|
|
23
|
+
infers a `type` for `payload.patterns` entries that omit it,
|
|
24
|
+
by inspecting the field set. Misunderstandings (which have
|
|
25
|
+
`wrong` + `correct`), terms (have `term` + `definition`),
|
|
26
|
+
banned terms, patterns, and aesthetics are now all picked up.
|
|
27
|
+
Truly unclassifiable entries are logged and skipped, never
|
|
28
|
+
silently dropped. The fix lives in the consumer
|
|
29
|
+
(`@aikdna/kdna-studio-cli` 0.8.6) rather than here.
|
|
30
|
+
- **#147** `buildSigningPayload` now excludes `build-receipt.json`
|
|
31
|
+
and any entry under `reports/`, matching `buildContentDigest`.
|
|
32
|
+
The prior omission meant a producer that signed with this code
|
|
33
|
+
and a verifier that digested with `buildContentDigest` would
|
|
34
|
+
compute two different byte strings and the signature would fail
|
|
35
|
+
to verify. The exclusion set is now a single source of truth.
|
|
36
|
+
`docs/CANONICALIZATION.md` updated to spell out the rule and
|
|
37
|
+
warn producers/verifiers that any new exclusion MUST be added
|
|
38
|
+
to both paths in the same change.
|
|
39
|
+
|
|
3
40
|
## v0.15.4 (2026-06-28)
|
|
4
41
|
|
|
5
42
|
Audit follow-ups (2026-06-28 round-trip verification). This release
|
package/package.json
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
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",
|
|
5
|
+
"description": "Schema for the payload entry of a KDNA bundle container.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["profile", "components"],
|
|
8
|
+
"additionalProperties": true,
|
|
9
|
+
"properties": {
|
|
10
|
+
"profile": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"const": "bundle-profile-v1",
|
|
13
|
+
"description": "Profile identifier. Must be the literal string 'bundle-profile-v1'."
|
|
14
|
+
},
|
|
15
|
+
"components": {
|
|
16
|
+
"type": "array",
|
|
17
|
+
"description": "List of component assets bundled in this container.",
|
|
18
|
+
"items": {
|
|
19
|
+
"type": "object",
|
|
20
|
+
"required": ["id", "path"],
|
|
21
|
+
"additionalProperties": true,
|
|
22
|
+
"properties": {
|
|
23
|
+
"id": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"description": "The unique identifier of the component asset."
|
|
26
|
+
},
|
|
27
|
+
"path": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"description": "Relative path to the component asset (.kdna container) within the bundle payload or bundle package."
|
|
30
|
+
},
|
|
31
|
+
"priority": {
|
|
32
|
+
"type": "integer",
|
|
33
|
+
"description": "Optional priority for resolving card conflicts."
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -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/manifest.schema.json",
|
|
4
|
-
"title": "KDNA Manifest
|
|
4
|
+
"title": "KDNA Manifest v2",
|
|
5
5
|
"description": "Schema for kdna.json, the public metadata layer of a .kdna container.",
|
|
6
6
|
"type": "object",
|
|
7
7
|
"required": [
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"kdna_version": {
|
|
24
24
|
"type": "string",
|
|
25
25
|
"description": "KDNA Core version this manifest conforms to.",
|
|
26
|
-
"
|
|
26
|
+
"enum": ["1.0", "2.0"]
|
|
27
27
|
},
|
|
28
28
|
"asset_id": {
|
|
29
29
|
"type": "string",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"asset_type": {
|
|
39
39
|
"type": "string",
|
|
40
|
-
"enum": ["domain", "cluster", "tool", "sample", "fixture"],
|
|
40
|
+
"enum": ["domain", "cluster", "tool", "sample", "fixture", "bundle"],
|
|
41
41
|
"description": "What kind of asset this is. Container format is the same; the value tells callers how to interpret the payload."
|
|
42
42
|
},
|
|
43
43
|
"title": {
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"profile": {
|
|
93
93
|
"type": "string",
|
|
94
94
|
"description": "Payload profile identifier (e.g. judgment-profile-v1).",
|
|
95
|
-
"
|
|
95
|
+
"enum": ["judgment-profile-v1", "bundle-profile-v1"]
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
},
|
package/src/asset-reader.js
CHANGED
|
@@ -235,9 +235,18 @@ function canonicalJsonEntry(entryName, entryBuf, options = {}) {
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
function buildSigningPayload(asset, options = {}) {
|
|
238
|
+
// Bug (#147): the prior version only excluded `.DS_Store` and
|
|
239
|
+
// `signature.json`, while `buildContentDigest` above also excludes
|
|
240
|
+
// `build-receipt.json` and any entry under `reports/`. A producer
|
|
241
|
+
// that signed with this code and a verifier that digested the
|
|
242
|
+
// asset with `buildContentDigest` would compute two different
|
|
243
|
+
// byte strings and the signature would fail to verify. The fix
|
|
244
|
+
// mirrors `buildContentDigest`'s exclusion set exactly.
|
|
238
245
|
const parts = [];
|
|
239
246
|
for (const entryName of [...asset.entries.keys()].sort()) {
|
|
240
247
|
if (entryName === '.DS_Store' || entryName === 'signature.json') continue;
|
|
248
|
+
if (entryName === 'build-receipt.json') continue;
|
|
249
|
+
if (entryName.startsWith('reports/')) continue;
|
|
241
250
|
const entryBuf = asset.readEntry(entryName);
|
|
242
251
|
let payloadBuf = entryBuf;
|
|
243
252
|
if (JSON_ENTRY_RE.test(entryName)) {
|
package/src/lint-pure.js
CHANGED
package/src/types.d.ts
CHANGED
|
@@ -504,6 +504,7 @@ export interface KDNAV1Checksums {
|
|
|
504
504
|
}
|
|
505
505
|
|
|
506
506
|
export function isV1SourceDir(inputPath: string): boolean;
|
|
507
|
+
export function isV2SourceDir(inputPath: string): boolean;
|
|
507
508
|
export function detectContainerFormat(inputPath: string): 'v1' | 'v2' | null;
|
|
508
509
|
export function inspect(inputPath: string, options?: Record<string, any>): Record<string, any>;
|
|
509
510
|
export function validate(inputPath: string, options?: Record<string, any>): Record<string, any>;
|
package/src/v1/index.js
CHANGED
|
@@ -125,6 +125,9 @@ function loadSchemas() {
|
|
|
125
125
|
const payloadSchema = JSON.parse(
|
|
126
126
|
fs.readFileSync(path.join(schemaDir, 'payload-profile-v1.schema.json'), 'utf8'),
|
|
127
127
|
);
|
|
128
|
+
const bundlePayloadSchema = JSON.parse(
|
|
129
|
+
fs.readFileSync(path.join(schemaDir, 'bundle-profile-v1.schema.json'), 'utf8'),
|
|
130
|
+
);
|
|
128
131
|
const checksumsSchema = JSON.parse(
|
|
129
132
|
fs.readFileSync(path.join(schemaDir, 'checksums.schema.json'), 'utf8'),
|
|
130
133
|
);
|
|
@@ -138,6 +141,7 @@ function loadSchemas() {
|
|
|
138
141
|
_validators = {
|
|
139
142
|
manifest: ajv.compile(manifestSchema),
|
|
140
143
|
payload: ajv.compile(payloadSchema),
|
|
144
|
+
bundlePayload: ajv.compile(bundlePayloadSchema),
|
|
141
145
|
checksums: ajv.compile(checksumsSchema),
|
|
142
146
|
};
|
|
143
147
|
return _validators;
|
|
@@ -159,6 +163,20 @@ function isV1SourceDir(absPath) {
|
|
|
159
163
|
return mime === MIMETYPE_V1;
|
|
160
164
|
}
|
|
161
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Detect whether a directory is a v2 source layout.
|
|
168
|
+
* Required entries: mimetype, kdna.json, payload.kdnab.
|
|
169
|
+
* mimetype content must equal "application/vnd.aikdna.kdna+zip".
|
|
170
|
+
*/
|
|
171
|
+
function isV2SourceDir(absPath) {
|
|
172
|
+
if (!fs.existsSync(absPath) || !fs.statSync(absPath).isDirectory()) return false;
|
|
173
|
+
for (const f of V1_REQUIRED_DIR_ENTRIES) {
|
|
174
|
+
if (!fs.existsSync(path.join(absPath, f))) return false;
|
|
175
|
+
}
|
|
176
|
+
const mime = fs.readFileSync(path.join(absPath, 'mimetype'), 'utf8');
|
|
177
|
+
return mime === MIMETYPE_V2;
|
|
178
|
+
}
|
|
179
|
+
|
|
162
180
|
/**
|
|
163
181
|
* Detect whether a file is a v1 .kdna container.
|
|
164
182
|
* Returns 'v1' | 'v2' | null. null = not a .kdna file or unreadable.
|
|
@@ -559,9 +577,9 @@ function readV1Layout(absPath) {
|
|
|
559
577
|
|
|
560
578
|
// mimetype content must equal the literal v1 media type.
|
|
561
579
|
const mime = map.mimetype.toString('utf8');
|
|
562
|
-
if (mime !== MIMETYPE_V1) {
|
|
580
|
+
if (mime !== MIMETYPE_V1 && mime !== MIMETYPE_V2) {
|
|
563
581
|
throw new Error(
|
|
564
|
-
`not a KDNA
|
|
582
|
+
`not a KDNA layout: mimetype is "${mime}", expected "${MIMETYPE_V1}" or "${MIMETYPE_V2}"`,
|
|
565
583
|
);
|
|
566
584
|
}
|
|
567
585
|
|
|
@@ -668,9 +686,12 @@ function runValidate(v1) {
|
|
|
668
686
|
problems.push(`format: missing required entry ${f}`);
|
|
669
687
|
}
|
|
670
688
|
}
|
|
671
|
-
if (v1.map.mimetype
|
|
672
|
-
|
|
673
|
-
|
|
689
|
+
if (v1.map.mimetype) {
|
|
690
|
+
const mimeStr = v1.map.mimetype.toString('utf8');
|
|
691
|
+
if (mimeStr !== MIMETYPE_V1 && mimeStr !== MIMETYPE_V2) {
|
|
692
|
+
result.format_valid = false;
|
|
693
|
+
problems.push(`format: mimetype is not ${MIMETYPE_V1} or ${MIMETYPE_V2}`);
|
|
694
|
+
}
|
|
674
695
|
}
|
|
675
696
|
|
|
676
697
|
// schema gate — kdna.json against manifest.schema.json
|
|
@@ -717,11 +738,15 @@ function runValidate(v1) {
|
|
|
717
738
|
problems.push('payload: encrypted envelope missing required fields (profile/ciphertext/key material)');
|
|
718
739
|
}
|
|
719
740
|
// Encrypted payload passes payload gate if envelope is structurally valid.
|
|
720
|
-
} else
|
|
741
|
+
} else {
|
|
721
742
|
// Plaintext payload — full schema validation.
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
743
|
+
const isBundleProfile = v1.manifest.compatibility?.profile === 'bundle-profile-v1' || v1.manifest.asset_type === 'bundle';
|
|
744
|
+
const payloadValidator = isBundleProfile ? validators.bundlePayload : validators.payload;
|
|
745
|
+
if (!payloadValidator(payload)) {
|
|
746
|
+
result.payload_valid = false;
|
|
747
|
+
for (const err of payloadValidator.errors) {
|
|
748
|
+
problems.push(`payload: ${err.instancePath || '<root>'} ${err.message}`);
|
|
749
|
+
}
|
|
725
750
|
}
|
|
726
751
|
}
|
|
727
752
|
|
|
@@ -958,14 +983,15 @@ function unpack(inputPath, outputDir) {
|
|
|
958
983
|
const entries = listZipEntries(absIn);
|
|
959
984
|
// Sanity: v1 container must have mimetype as first entry with the v1 media type.
|
|
960
985
|
if (entries.length === 0 || entries[0].name !== 'mimetype') {
|
|
961
|
-
throw new Error('not a KDNA
|
|
986
|
+
throw new Error('not a KDNA container: first entry is not mimetype');
|
|
962
987
|
}
|
|
963
988
|
if (entries[0].method !== 0) {
|
|
964
|
-
throw new Error('not a KDNA
|
|
989
|
+
throw new Error('not a KDNA container: mimetype must be uncompressed');
|
|
965
990
|
}
|
|
966
|
-
|
|
991
|
+
const mime = entries[0].data.toString('utf8');
|
|
992
|
+
if (mime !== MIMETYPE_V1 && mime !== MIMETYPE_V2) {
|
|
967
993
|
throw new Error(
|
|
968
|
-
`not a KDNA
|
|
994
|
+
`not a KDNA container: mimetype is "${mime}", expected "${MIMETYPE_V1}" or "${MIMETYPE_V2}"`,
|
|
969
995
|
);
|
|
970
996
|
}
|
|
971
997
|
const absOut = path.resolve(outputDir);
|
|
@@ -1128,6 +1154,17 @@ function canonicalToV1Layout(asset) {
|
|
|
1128
1154
|
for (const [name, buf] of asset.entries) {
|
|
1129
1155
|
map[name] = buf;
|
|
1130
1156
|
}
|
|
1157
|
+
} else {
|
|
1158
|
+
map['mimetype'] = Buffer.from(asset.mimetype || '', 'utf8');
|
|
1159
|
+
if (asset.manifest) {
|
|
1160
|
+
map['kdna.json'] = Buffer.from(JSON.stringify(asset.manifest), 'utf8');
|
|
1161
|
+
}
|
|
1162
|
+
if (asset.payloadRaw) {
|
|
1163
|
+
map['payload.kdnab'] = asset.payloadRaw;
|
|
1164
|
+
}
|
|
1165
|
+
if (asset.checksums) {
|
|
1166
|
+
map['checksums.json'] = Buffer.from(JSON.stringify(asset.checksums), 'utf8');
|
|
1167
|
+
}
|
|
1131
1168
|
}
|
|
1132
1169
|
return {
|
|
1133
1170
|
kind: asset.sourceKind,
|
|
@@ -1478,6 +1515,7 @@ module.exports = {
|
|
|
1478
1515
|
MIMETYPE_V2,
|
|
1479
1516
|
V1_REQUIRED_DIR_ENTRIES,
|
|
1480
1517
|
isV1SourceDir,
|
|
1518
|
+
isV2SourceDir,
|
|
1481
1519
|
detectContainerFormat,
|
|
1482
1520
|
readV1Layout,
|
|
1483
1521
|
inspect,
|
|
@@ -1540,11 +1578,25 @@ function renderPromptItem(item) {
|
|
|
1540
1578
|
if (item.term && item.why) return `${item.term}: ${item.why}`;
|
|
1541
1579
|
if (item.wrong && item.correct) return `${item.wrong} -> ${item.correct}`;
|
|
1542
1580
|
if (item.mode && item.correct) return `${item.mode} -> ${item.correct}`;
|
|
1581
|
+
// Failure-mode entries from audit fixtures carry `mode` and `correct`
|
|
1582
|
+
// but may be one-sided (only `mode`, only `correct`, only `why`).
|
|
1583
|
+
// Fall through to a single-side render so the prompt never has
|
|
1584
|
+
// `(unrendered card: ...)` for a card that has at least one
|
|
1585
|
+
// populated judgment field. Bug (#61).
|
|
1586
|
+
if (item.mode) return `failure mode: ${item.mode}`;
|
|
1587
|
+
if (item.correct) return `correct: ${item.correct}`;
|
|
1588
|
+
if (item.key_distinction) return item.key_distinction;
|
|
1589
|
+
if (item.why) return `because: ${item.why}`;
|
|
1543
1590
|
if (item.name && item.description) return `${item.name}: ${item.description}`;
|
|
1544
1591
|
if (item.name) return item.name;
|
|
1545
1592
|
if (item.one_sentence) return item.one_sentence;
|
|
1546
1593
|
if (item.essence) return item.essence;
|
|
1547
1594
|
if (item.question) return item.question;
|
|
1595
|
+
// Self-check entries are sometimes stored as plain strings, sometimes
|
|
1596
|
+
// as { question: "..." } objects, sometimes as { one_sentence: "..." }.
|
|
1597
|
+
// The buildPayload path emits `one_sentence` for self_check, so
|
|
1598
|
+
// try that before the last-resort fall-through. Bug (#61).
|
|
1599
|
+
if (item.text) return item.text;
|
|
1548
1600
|
// Last-resort fall-through. Returning the id (e.g. "bo_xxxx-...") makes
|
|
1549
1601
|
// the output unreadable; prefer a note that the card is unrecognized.
|
|
1550
1602
|
return `(unrendered card: ${item.type || 'unknown'})`;
|
package/src/v1/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ export const MIMETYPE_V1 = v1.MIMETYPE_V1;
|
|
|
5
5
|
export const MIMETYPE_V2 = v1.MIMETYPE_V2;
|
|
6
6
|
export const V1_REQUIRED_DIR_ENTRIES = v1.V1_REQUIRED_DIR_ENTRIES;
|
|
7
7
|
export const isV1SourceDir = v1.isV1SourceDir;
|
|
8
|
+
export const isV2SourceDir = v1.isV2SourceDir;
|
|
8
9
|
export const detectContainerFormat = v1.detectContainerFormat;
|
|
9
10
|
export const readV1Layout = v1.readV1Layout;
|
|
10
11
|
export const inspect = v1.inspect;
|