@origintrail-official/dkg-okf 10.0.2

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 (51) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +55 -0
  3. package/dist/bundle.d.ts +16 -0
  4. package/dist/bundle.d.ts.map +1 -0
  5. package/dist/bundle.js +132 -0
  6. package/dist/bundle.js.map +1 -0
  7. package/dist/constants.d.ts +52 -0
  8. package/dist/constants.d.ts.map +1 -0
  9. package/dist/constants.js +55 -0
  10. package/dist/constants.js.map +1 -0
  11. package/dist/document.d.ts +30 -0
  12. package/dist/document.d.ts.map +1 -0
  13. package/dist/document.js +72 -0
  14. package/dist/document.js.map +1 -0
  15. package/dist/export.d.ts +21 -0
  16. package/dist/export.d.ts.map +1 -0
  17. package/dist/export.js +210 -0
  18. package/dist/export.js.map +1 -0
  19. package/dist/index.d.ts +24 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +23 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/loader.d.ts +20 -0
  24. package/dist/loader.d.ts.map +1 -0
  25. package/dist/loader.js +42 -0
  26. package/dist/loader.js.map +1 -0
  27. package/dist/mapping.d.ts +38 -0
  28. package/dist/mapping.d.ts.map +1 -0
  29. package/dist/mapping.js +253 -0
  30. package/dist/mapping.js.map +1 -0
  31. package/dist/nquads.d.ts +13 -0
  32. package/dist/nquads.d.ts.map +1 -0
  33. package/dist/nquads.js +26 -0
  34. package/dist/nquads.js.map +1 -0
  35. package/dist/paths.d.ts +57 -0
  36. package/dist/paths.d.ts.map +1 -0
  37. package/dist/paths.js +126 -0
  38. package/dist/paths.js.map +1 -0
  39. package/dist/types.d.ts +134 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/dist/types.js +10 -0
  42. package/dist/types.js.map +1 -0
  43. package/dist/utils.d.ts +27 -0
  44. package/dist/utils.d.ts.map +1 -0
  45. package/dist/utils.js +53 -0
  46. package/dist/utils.js.map +1 -0
  47. package/dist/validation.d.ts +17 -0
  48. package/dist/validation.d.ts.map +1 -0
  49. package/dist/validation.js +80 -0
  50. package/dist/validation.js.map +1 -0
  51. package/package.json +38 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2018 OriginTrail
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # @origintrail-official/dkg-okf
2
+
3
+ Deterministic **Google Open Knowledge Format (OKF) → DKG** mapper.
4
+
5
+ OKF standardises *how* knowledge is written and exchanged — portable Markdown +
6
+ YAML frontmatter + untyped cross-links — but ships **no** verification,
7
+ provenance or ownership layer (OKF SPEC §1, §10). This package is the bridge: it
8
+ turns an OKF bundle into owned, verifiable RDF **Knowledge Assets**,
9
+ reconstructing the bundle's cross-concept link graph. The same portable Markdown,
10
+ now cryptographically provenanced, owned and shareable across agents.
11
+
12
+ Pure, no LLM, no network — the same bundle always yields **identical triples and
13
+ IRIs**.
14
+
15
+ ## Use it from the CLI
16
+
17
+ ```bash
18
+ # Deterministic, offline — prints the mapping summary, never touches a node
19
+ dkg okf import ./bundle --dry-run --print-nquads
20
+
21
+ # Import into a Context Graph (defaults to private Working Memory)
22
+ dkg okf import ./bundle --context-graph-id my-graph --create-context-graph
23
+
24
+ # Finalize + share to Shared Working Memory (free, team-visible)
25
+ dkg okf import ./bundle --context-graph-id my-graph --share
26
+
27
+ # Serialise a Context Graph back into a conformant OKF bundle (clean inverse)
28
+ dkg okf export my-graph ./out
29
+ ```
30
+
31
+ Import defaults to **Working Memory** and never publishes to Verifiable Memory.
32
+ `--share` advances to **Shared Working Memory**. On-chain VM promotion (real
33
+ TRAC) is a separate, explicitly-gated operator step — see `DEMO.md`.
34
+
35
+ ## Use it as a library
36
+
37
+ ```ts
38
+ import { loadBundleDir, importBundle, quadsToNQuads } from '@origintrail-official/dkg-okf';
39
+
40
+ const result = importBundle(loadBundleDir('./bundle'));
41
+ console.log(result.concepts.length, 'Knowledge Assets');
42
+ console.log(quadsToNQuads(result.quads)); // canonical, byte-stable N-Quads
43
+ ```
44
+
45
+ ## Docs
46
+
47
+ - **`CONTEXT.md`** — Language / Relationships / Flagged ambiguities.
48
+ - **`docs/adr/0005-okf-rdf-mapping.md`** — the locked OKF→RDF mapping and the
49
+ reuse-vs-fork decision.
50
+ - **`docs/integrations/okf.md`** — the full-lifecycle article.
51
+ - **`DEMO.md`** — the live mainnet runbook (WM → SWM → join invitation → Hermes
52
+ agent → rendered graph; VM promotion held as a deferred capstone).
53
+
54
+ License: Apache-2.0. The vendored `test/fixtures/crypto_bitcoin/` bundle is © Google
55
+ LLC, Apache-2.0 (see its `ATTRIBUTION`).
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Bundle-aware OKF import (the two passes from ADR 0005 / SPEC §3–§5).
3
+ *
4
+ * Pass 1 — index the bundle: classify concept vs. reserved files, parse each
5
+ * concept's frontmatter, derive a deterministic subject IRI per concept ID, and
6
+ * read `okf_version` from the root `index.md` if present.
7
+ *
8
+ * Pass 2 — extract + link: map each concept (frontmatter + body) to quads and
9
+ * resolve its Markdown links against the Pass-1 map into untyped directed edges.
10
+ *
11
+ * Pure and deterministic: same `BundleFile[]` ⇒ identical quads and IRIs. No
12
+ * filesystem, no network — `loadBundleDir` (loader.ts) is the only I/O surface.
13
+ */
14
+ import type { BundleFile, BundleImport, OkfMappingOptions } from './types.js';
15
+ export declare function importBundle(files: BundleFile[], opts?: OkfMappingOptions): BundleImport;
16
+ //# sourceMappingURL=bundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAYH,OAAO,KAAK,EACV,UAAU,EACV,YAAY,EAGZ,iBAAiB,EAGlB,MAAM,YAAY,CAAC;AAMpB,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,IAAI,GAAE,iBAAsB,GAAG,YAAY,CA+G5F"}
package/dist/bundle.js ADDED
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Bundle-aware OKF import (the two passes from ADR 0005 / SPEC §3–§5).
3
+ *
4
+ * Pass 1 — index the bundle: classify concept vs. reserved files, parse each
5
+ * concept's frontmatter, derive a deterministic subject IRI per concept ID, and
6
+ * read `okf_version` from the root `index.md` if present.
7
+ *
8
+ * Pass 2 — extract + link: map each concept (frontmatter + body) to quads and
9
+ * resolve its Markdown links against the Pass-1 map into untyped directed edges.
10
+ *
11
+ * Pure and deterministic: same `BundleFile[]` ⇒ identical quads and IRIs. No
12
+ * filesystem, no network — `loadBundleDir` (loader.ts) is the only I/O surface.
13
+ */
14
+ import { parseDocument, OkfDocumentError } from './document.js';
15
+ import { mapConcept } from './mapping.js';
16
+ import { isConceptFile, isReservedFile, isValidSegment, pathToConceptId, conceptIdToIri, } from './paths.js';
17
+ import { DEFAULT_IRI_BASE, SCHEMA_MENTIONS } from './constants.js';
18
+ function byPath(a, b) {
19
+ return a.path < b.path ? -1 : a.path > b.path ? 1 : 0;
20
+ }
21
+ export function importBundle(files, opts = {}) {
22
+ const iriBase = opts.iriBase ?? DEFAULT_IRI_BASE;
23
+ const warnings = [];
24
+ // Deterministic ordering, independent of how the caller enumerated the tree.
25
+ const ordered = [...files].sort(byPath);
26
+ const reservedSkipped = ordered.filter((f) => isReservedFile(f.path)).map((f) => f.path);
27
+ // --- Pass 1: index ---
28
+ const docs = [];
29
+ const iriByConceptId = {};
30
+ const typeByConceptId = {};
31
+ for (const f of ordered) {
32
+ if (!isConceptFile(f.path))
33
+ continue;
34
+ let doc;
35
+ try {
36
+ doc = parseDocument(f.path, f.content);
37
+ }
38
+ catch (err) {
39
+ // Unparseable frontmatter is a §9 conformance issue; for import we skip the
40
+ // concept with a warning rather than aborting the whole bundle.
41
+ warnings.push({
42
+ conceptId: pathToConceptId(f.path),
43
+ code: 'parse',
44
+ message: err instanceof OkfDocumentError ? err.message : String(err),
45
+ });
46
+ continue;
47
+ }
48
+ // A concept whose path has a non-OKF segment would mint a malformed subject IRI
49
+ // (e.g. `bad name.md` → `urn:okf:bad name`, a space-bearing IRI that breaks
50
+ // N-Quads / node writes). Skip it with a warning rather than emit bad RDF.
51
+ if (!doc.conceptId.split('/').every(isValidSegment)) {
52
+ warnings.push({
53
+ conceptId: doc.conceptId,
54
+ code: 'invalid-path',
55
+ message: `invalid concept path segment(s) — must match [A-Za-z0-9_][A-Za-z0-9_.-]* (§2); skipped`,
56
+ });
57
+ continue;
58
+ }
59
+ docs.push(doc);
60
+ iriByConceptId[doc.conceptId] = conceptIdToIri(doc.conceptId, iriBase);
61
+ typeByConceptId[doc.conceptId] =
62
+ doc.frontmatter.type != null ? String(doc.frontmatter.type) : undefined;
63
+ const type = doc.frontmatter.type;
64
+ if (type === undefined || type === null || String(type).trim() === '') {
65
+ warnings.push({
66
+ conceptId: doc.conceptId,
67
+ code: 'missing-type',
68
+ message: 'concept has no non-empty `type` (a hard §9 conformance requirement; the bundle will not validate)',
69
+ });
70
+ }
71
+ }
72
+ // `okf_version` may be declared only in the bundle-root `index.md` (SPEC §11).
73
+ let okfVersion = null;
74
+ const rootIndex = ordered.find((f) => f.path === 'index.md');
75
+ if (rootIndex) {
76
+ try {
77
+ const parsed = parseDocument('index.md', rootIndex.content);
78
+ const v = parsed.frontmatter.okf_version;
79
+ if (v !== undefined && v !== null)
80
+ okfVersion = String(v);
81
+ }
82
+ catch {
83
+ // Reserved files need no frontmatter; ignore.
84
+ }
85
+ }
86
+ // --- Pass 2: extract + link ---
87
+ const exists = (id) => Object.prototype.hasOwnProperty.call(iriByConceptId, id);
88
+ // Opt-in: retype cross-concept edges by their endpoints' OKF `type` pair
89
+ // (deterministic; default keeps every edge as schema:mentions).
90
+ const typeRelations = opts.typeRelations ?? [];
91
+ const relationPredicate = (fromType, toType) => {
92
+ if (typeRelations.length === 0 || fromType == null || toType == null)
93
+ return undefined;
94
+ return typeRelations.find((r) => r.from === fromType && r.to === toType)?.predicate;
95
+ };
96
+ const concepts = [];
97
+ const quads = [];
98
+ for (const doc of docs) {
99
+ const mapping = mapConcept(doc, iriByConceptId[doc.conceptId], exists, opts);
100
+ if (typeRelations.length > 0) {
101
+ const fromType = typeByConceptId[doc.conceptId];
102
+ for (const q of mapping.quads) {
103
+ if (q.predicate !== SCHEMA_MENTIONS || !q.object.startsWith(iriBase))
104
+ continue;
105
+ const targetId = q.object.slice(iriBase.length);
106
+ const pred = relationPredicate(fromType, typeByConceptId[targetId]);
107
+ if (pred)
108
+ q.predicate = pred;
109
+ }
110
+ }
111
+ concepts.push(mapping);
112
+ quads.push(...mapping.quads);
113
+ for (const bl of mapping.brokenLinks) {
114
+ warnings.push({
115
+ conceptId: doc.conceptId,
116
+ code: 'broken-link',
117
+ message: `unresolved cross-link "${bl.raw}" (not in bundle — not an error, SPEC §5.3/§9)`,
118
+ });
119
+ }
120
+ if (!opts.includeCodeSpanLinks) {
121
+ for (const cs of mapping.codeSpanLinks) {
122
+ warnings.push({
123
+ conceptId: doc.conceptId,
124
+ code: 'code-span-link',
125
+ message: `link "${cs.raw}" sits inside an inline code span — treated as literal text per CommonMark, not an edge`,
126
+ });
127
+ }
128
+ }
129
+ }
130
+ return { okfVersion, iriByConceptId, concepts, reservedSkipped, quads, warnings };
131
+ }
132
+ //# sourceMappingURL=bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.js","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EACL,aAAa,EACb,cAAc,EACd,cAAc,EACd,eAAe,EACf,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAWnE,SAAS,MAAM,CAAC,CAAa,EAAE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yFAAyF;iBAClH,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,eAAe,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AACpF,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * RDF predicate / namespace constants for the OKF → DKG mapping.
3
+ *
4
+ * These deliberately mirror the vocabulary already minted by the node's
5
+ * deterministic Markdown extractor (`packages/cli/src/extraction/
6
+ * markdown-extractor.ts`) so that an OKF import and a natively-ingested
7
+ * Markdown corpus converge on the same graph shape and join naturally.
8
+ * The extractor's predicate strings are private module constants there;
9
+ * we re-declare the same literal IRIs here (rather than import across the
10
+ * `cli → okf` boundary, which would be a dependency cycle) and pin the
11
+ * convergence with a test.
12
+ *
13
+ * The OKF-specific deltas — and the rationale for each — are recorded in
14
+ * `docs/adr/0005-okf-rdf-mapping.md` and `CONTEXT.md`.
15
+ */
16
+ export declare const RDF_TYPE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
17
+ export declare const XSD_DATE_TIME = "http://www.w3.org/2001/XMLSchema#dateTime";
18
+ export declare const XSD_BOOLEAN = "http://www.w3.org/2001/XMLSchema#boolean";
19
+ export declare const XSD_INTEGER = "http://www.w3.org/2001/XMLSchema#integer";
20
+ export declare const XSD_DECIMAL = "http://www.w3.org/2001/XMLSchema#decimal";
21
+ export declare const SCHEMA_NS = "http://schema.org/";
22
+ export declare const SCHEMA_NAME = "http://schema.org/name";
23
+ export declare const SCHEMA_DESCRIPTION = "http://schema.org/description";
24
+ export declare const SCHEMA_KEYWORDS = "http://schema.org/keywords";
25
+ /** Untyped directed concept→concept edge. Converges with the extractor's `[[wikilink]]` predicate. */
26
+ export declare const SCHEMA_MENTIONS = "http://schema.org/mentions";
27
+ /** OKF `timestamp` = last-modified time (SPEC §4.1). */
28
+ export declare const SCHEMA_DATE_MODIFIED = "http://schema.org/dateModified";
29
+ /** OKF `resource` = canonical URI of the underlying asset (SPEC §4.1). */
30
+ export declare const SCHEMA_URL = "http://schema.org/url";
31
+ /** `# Citations` links (SPEC §8) — semantically distinct from concept edges. */
32
+ export declare const SCHEMA_CITATION = "http://schema.org/citation";
33
+ /** Containment edge — opt-in target for type-pair relations (e.g. dataset→table). */
34
+ export declare const SCHEMA_HAS_PART = "http://schema.org/hasPart";
35
+ /** Optional folder hierarchy (off by default — see ADR 0005). */
36
+ export declare const SCHEMA_IS_PART_OF = "http://schema.org/isPartOf";
37
+ export declare const DKG_HAS_SECTION = "http://dkg.io/ontology/hasSection";
38
+ /**
39
+ * Infix for deterministic skolem IRIs minted for `dkg:hasSection` nodes.
40
+ * The daemon rejects blank-node RDF *objects* ("RDF object must be a quoted
41
+ * literal term or absolute IRI"), so section nodes are skolemized into
42
+ * concept-scoped IRIs `<conceptIri>/.well-known/genid/okfsec_<id>_<n>` — the
43
+ * same `.well-known/genid/` scheme the node uses internally, so stored data is
44
+ * identical whether or not the node would have skolemized them itself. Export
45
+ * uses this infix to exclude section nodes from being rebuilt as concepts.
46
+ */
47
+ export declare const SECTION_GENID_INFIX = "/.well-known/genid/";
48
+ /** Default IRI namespace for concept Knowledge Asset subjects. */
49
+ export declare const DEFAULT_IRI_BASE = "urn:okf:";
50
+ /** The OKF version this consumer targets (SPEC is v0.1 draft). */
51
+ export declare const OKF_TARGET_VERSION = "0.1";
52
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,eAAO,MAAM,QAAQ,oDAAoD,CAAC;AAC1E,eAAO,MAAM,aAAa,8CAA8C,CAAC;AACzE,eAAO,MAAM,WAAW,6CAA6C,CAAC;AACtE,eAAO,MAAM,WAAW,6CAA6C,CAAC;AACtE,eAAO,MAAM,WAAW,6CAA6C,CAAC;AAGtE,eAAO,MAAM,SAAS,uBAAuB,CAAC;AAC9C,eAAO,MAAM,WAAW,2BAA2B,CAAC;AACpD,eAAO,MAAM,kBAAkB,kCAAkC,CAAC;AAClE,eAAO,MAAM,eAAe,+BAA+B,CAAC;AAC5D,sGAAsG;AACtG,eAAO,MAAM,eAAe,+BAA+B,CAAC;AAC5D,wDAAwD;AACxD,eAAO,MAAM,oBAAoB,mCAAmC,CAAC;AACrE,0EAA0E;AAC1E,eAAO,MAAM,UAAU,0BAA0B,CAAC;AAClD,gFAAgF;AAChF,eAAO,MAAM,eAAe,+BAA+B,CAAC;AAC5D,qFAAqF;AACrF,eAAO,MAAM,eAAe,8BAA8B,CAAC;AAC3D,iEAAiE;AACjE,eAAO,MAAM,iBAAiB,+BAA+B,CAAC;AAG9D,eAAO,MAAM,eAAe,sCAAsC,CAAC;AAEnE;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AAEzD,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,aAAa,CAAC;AAE3C,kEAAkE;AAClE,eAAO,MAAM,kBAAkB,QAAQ,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * RDF predicate / namespace constants for the OKF → DKG mapping.
3
+ *
4
+ * These deliberately mirror the vocabulary already minted by the node's
5
+ * deterministic Markdown extractor (`packages/cli/src/extraction/
6
+ * markdown-extractor.ts`) so that an OKF import and a natively-ingested
7
+ * Markdown corpus converge on the same graph shape and join naturally.
8
+ * The extractor's predicate strings are private module constants there;
9
+ * we re-declare the same literal IRIs here (rather than import across the
10
+ * `cli → okf` boundary, which would be a dependency cycle) and pin the
11
+ * convergence with a test.
12
+ *
13
+ * The OKF-specific deltas — and the rationale for each — are recorded in
14
+ * `docs/adr/0005-okf-rdf-mapping.md` and `CONTEXT.md`.
15
+ */
16
+ // --- RDF / XSD ---
17
+ export const RDF_TYPE = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';
18
+ export const XSD_DATE_TIME = 'http://www.w3.org/2001/XMLSchema#dateTime';
19
+ export const XSD_BOOLEAN = 'http://www.w3.org/2001/XMLSchema#boolean';
20
+ export const XSD_INTEGER = 'http://www.w3.org/2001/XMLSchema#integer';
21
+ export const XSD_DECIMAL = 'http://www.w3.org/2001/XMLSchema#decimal';
22
+ // --- schema.org (converges with the extractor) ---
23
+ export const SCHEMA_NS = 'http://schema.org/';
24
+ export const SCHEMA_NAME = 'http://schema.org/name';
25
+ export const SCHEMA_DESCRIPTION = 'http://schema.org/description';
26
+ export const SCHEMA_KEYWORDS = 'http://schema.org/keywords';
27
+ /** Untyped directed concept→concept edge. Converges with the extractor's `[[wikilink]]` predicate. */
28
+ export const SCHEMA_MENTIONS = 'http://schema.org/mentions';
29
+ /** OKF `timestamp` = last-modified time (SPEC §4.1). */
30
+ export const SCHEMA_DATE_MODIFIED = 'http://schema.org/dateModified';
31
+ /** OKF `resource` = canonical URI of the underlying asset (SPEC §4.1). */
32
+ export const SCHEMA_URL = 'http://schema.org/url';
33
+ /** `# Citations` links (SPEC §8) — semantically distinct from concept edges. */
34
+ export const SCHEMA_CITATION = 'http://schema.org/citation';
35
+ /** Containment edge — opt-in target for type-pair relations (e.g. dataset→table). */
36
+ export const SCHEMA_HAS_PART = 'http://schema.org/hasPart';
37
+ /** Optional folder hierarchy (off by default — see ADR 0005). */
38
+ export const SCHEMA_IS_PART_OF = 'http://schema.org/isPartOf';
39
+ // --- DKG ontology (converges with the extractor) ---
40
+ export const DKG_HAS_SECTION = 'http://dkg.io/ontology/hasSection';
41
+ /**
42
+ * Infix for deterministic skolem IRIs minted for `dkg:hasSection` nodes.
43
+ * The daemon rejects blank-node RDF *objects* ("RDF object must be a quoted
44
+ * literal term or absolute IRI"), so section nodes are skolemized into
45
+ * concept-scoped IRIs `<conceptIri>/.well-known/genid/okfsec_<id>_<n>` — the
46
+ * same `.well-known/genid/` scheme the node uses internally, so stored data is
47
+ * identical whether or not the node would have skolemized them itself. Export
48
+ * uses this infix to exclude section nodes from being rebuilt as concepts.
49
+ */
50
+ export const SECTION_GENID_INFIX = '/.well-known/genid/';
51
+ /** Default IRI namespace for concept Knowledge Asset subjects. */
52
+ export const DEFAULT_IRI_BASE = 'urn:okf:';
53
+ /** The OKF version this consumer targets (SPEC is v0.1 draft). */
54
+ export const OKF_TARGET_VERSION = '0.1';
55
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,oBAAoB;AACpB,MAAM,CAAC,MAAM,QAAQ,GAAG,iDAAiD,CAAC;AAC1E,MAAM,CAAC,MAAM,aAAa,GAAG,2CAA2C,CAAC;AACzE,MAAM,CAAC,MAAM,WAAW,GAAG,0CAA0C,CAAC;AACtE,MAAM,CAAC,MAAM,WAAW,GAAG,0CAA0C,CAAC;AACtE,MAAM,CAAC,MAAM,WAAW,GAAG,0CAA0C,CAAC;AAEtE,oDAAoD;AACpD,MAAM,CAAC,MAAM,SAAS,GAAG,oBAAoB,CAAC;AAC9C,MAAM,CAAC,MAAM,WAAW,GAAG,wBAAwB,CAAC;AACpD,MAAM,CAAC,MAAM,kBAAkB,GAAG,+BAA+B,CAAC;AAClE,MAAM,CAAC,MAAM,eAAe,GAAG,4BAA4B,CAAC;AAC5D,sGAAsG;AACtG,MAAM,CAAC,MAAM,eAAe,GAAG,4BAA4B,CAAC;AAC5D,wDAAwD;AACxD,MAAM,CAAC,MAAM,oBAAoB,GAAG,gCAAgC,CAAC;AACrE,0EAA0E;AAC1E,MAAM,CAAC,MAAM,UAAU,GAAG,uBAAuB,CAAC;AAClD,gFAAgF;AAChF,MAAM,CAAC,MAAM,eAAe,GAAG,4BAA4B,CAAC;AAC5D,qFAAqF;AACrF,MAAM,CAAC,MAAM,eAAe,GAAG,2BAA2B,CAAC;AAC3D,iEAAiE;AACjE,MAAM,CAAC,MAAM,iBAAiB,GAAG,4BAA4B,CAAC;AAE9D,sDAAsD;AACtD,MAAM,CAAC,MAAM,eAAe,GAAG,mCAAmC,CAAC;AAEnE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAEzD,kEAAkE;AAClE,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CAAC;AAE3C,kEAAkE;AAClE,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * OKF concept document parsing — the frontmatter/body split.
3
+ *
4
+ * This mirrors the reference agent's `OKFDocument.parse`
5
+ * (`okf/src/reference_agent/bundle/document.py`) byte-for-byte in behaviour so
6
+ * our IRIs, triples and round-trips agree with the canonical producer:
7
+ *
8
+ * - frontmatter is delimited by `---` on its own line at the very start and a
9
+ * closing `---` on its own line; matching is on the *stripped* line, so a
10
+ * `---` with trailing whitespace still closes the block;
11
+ * - a file with no leading `---` is treated as all-body (this is how
12
+ * `index.md` / `log.md` parse cleanly — they carry no frontmatter, §6/§7);
13
+ * - exactly one leading newline is stripped from the body.
14
+ *
15
+ * NOTE on requiredness: the reference *producer* enforces four keys
16
+ * (`REQUIRED_FRONTMATTER_KEYS = ("type","title","description","timestamp")`),
17
+ * but SPEC §9 binds *consumers* to require only a non-empty `type`. We are a
18
+ * consumer: parsing never enforces the producer's four keys. `validation.ts`
19
+ * applies the §9 consumer rule.
20
+ */
21
+ import type { OkfDocument } from './types.js';
22
+ export declare class OkfDocumentError extends Error {
23
+ constructor(message: string);
24
+ }
25
+ /**
26
+ * Parse a concept file's raw text into `{ conceptId, segments, frontmatter, body }`.
27
+ * `bundlePath` is the bundle-relative POSIX path (e.g. `tables/blocks.md`).
28
+ */
29
+ export declare function parseDocument(bundlePath: string, text: string): OkfDocument;
30
+ //# sourceMappingURL=document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAK9C,qBAAa,gBAAiB,SAAQ,KAAK;gBAC7B,OAAO,EAAE,MAAM;CAI5B;AAOD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAsC3E"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * OKF concept document parsing — the frontmatter/body split.
3
+ *
4
+ * This mirrors the reference agent's `OKFDocument.parse`
5
+ * (`okf/src/reference_agent/bundle/document.py`) byte-for-byte in behaviour so
6
+ * our IRIs, triples and round-trips agree with the canonical producer:
7
+ *
8
+ * - frontmatter is delimited by `---` on its own line at the very start and a
9
+ * closing `---` on its own line; matching is on the *stripped* line, so a
10
+ * `---` with trailing whitespace still closes the block;
11
+ * - a file with no leading `---` is treated as all-body (this is how
12
+ * `index.md` / `log.md` parse cleanly — they carry no frontmatter, §6/§7);
13
+ * - exactly one leading newline is stripped from the body.
14
+ *
15
+ * NOTE on requiredness: the reference *producer* enforces four keys
16
+ * (`REQUIRED_FRONTMATTER_KEYS = ("type","title","description","timestamp")`),
17
+ * but SPEC §9 binds *consumers* to require only a non-empty `type`. We are a
18
+ * consumer: parsing never enforces the producer's four keys. `validation.ts`
19
+ * applies the §9 consumer rule.
20
+ */
21
+ import { load as loadYaml } from 'js-yaml';
22
+ import { pathToConceptId } from './paths.js';
23
+ const DELIM = '---';
24
+ export class OkfDocumentError extends Error {
25
+ constructor(message) {
26
+ super(message);
27
+ this.name = 'OkfDocumentError';
28
+ }
29
+ }
30
+ /** Python `str.splitlines()` semantics: split on \r\n, \r, or \n. */
31
+ function splitLines(text) {
32
+ return text.split(/\r\n|\r|\n/);
33
+ }
34
+ /**
35
+ * Parse a concept file's raw text into `{ conceptId, segments, frontmatter, body }`.
36
+ * `bundlePath` is the bundle-relative POSIX path (e.g. `tables/blocks.md`).
37
+ */
38
+ export function parseDocument(bundlePath, text) {
39
+ const conceptId = pathToConceptId(bundlePath);
40
+ const segments = conceptId.split('/');
41
+ const lines = splitLines(text);
42
+ if (lines.length === 0 || lines[0].trim() !== DELIM) {
43
+ // No frontmatter block — entire file is body.
44
+ return { conceptId, segments, frontmatter: {}, body: text };
45
+ }
46
+ let endIdx = -1;
47
+ for (let i = 1; i < lines.length; i++) {
48
+ if (lines[i].trim() === DELIM) {
49
+ endIdx = i;
50
+ break;
51
+ }
52
+ }
53
+ if (endIdx === -1) {
54
+ throw new OkfDocumentError(`Unterminated YAML frontmatter block in ${bundlePath}`);
55
+ }
56
+ const fmText = lines.slice(1, endIdx).join('\n');
57
+ let parsed;
58
+ try {
59
+ parsed = loadYaml(fmText) ?? {};
60
+ }
61
+ catch (err) {
62
+ throw new OkfDocumentError(`Invalid YAML frontmatter in ${bundlePath}: ${err.message}`);
63
+ }
64
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
65
+ throw new OkfDocumentError(`Frontmatter must be a YAML mapping in ${bundlePath}`);
66
+ }
67
+ let body = lines.slice(endIdx + 1).join('\n');
68
+ if (body.startsWith('\n'))
69
+ body = body.slice(1);
70
+ return { conceptId, segments, frontmatter: parsed, body };
71
+ }
72
+ //# sourceMappingURL=document.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.js","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,KAAK,GAAG,KAAK,CAAC;AAEpB,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAED,qEAAqE;AACrE,SAAS,UAAU,CAAC,IAAY;IAC9B,OAAO,IAAI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