@ontology-kit/okb 0.1.0-bootstrap.0 → 0.2.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 (74) hide show
  1. package/README.md +1 -1
  2. package/dist/check.d.ts +43 -0
  3. package/dist/check.js +83 -0
  4. package/dist/checks.d.ts +1 -1
  5. package/dist/checks.js +4 -4
  6. package/dist/cli.js +159 -45
  7. package/dist/clock.js +1 -1
  8. package/dist/commands.js +96 -2
  9. package/dist/diff.d.ts +85 -0
  10. package/dist/diff.js +323 -0
  11. package/dist/export.d.ts +1 -1
  12. package/dist/export.js +1 -1
  13. package/dist/families.d.ts +1 -1
  14. package/dist/families.js +1 -1
  15. package/dist/help.d.ts +1 -1
  16. package/dist/help.js +9 -2
  17. package/dist/kbdocs.d.ts +18 -0
  18. package/dist/kbdocs.js +393 -0
  19. package/dist/metakb.d.ts +1 -1
  20. package/dist/metakb.js +1 -1
  21. package/dist/naming.d.ts +2 -2
  22. package/dist/naming.js +2 -2
  23. package/dist/ontology-ref.d.ts +20 -0
  24. package/dist/ontology-ref.js +108 -0
  25. package/dist/ops/admin.d.ts +1 -1
  26. package/dist/ops/admin.js +24 -7
  27. package/dist/ops/classes.d.ts +1 -1
  28. package/dist/ops/classes.js +13 -5
  29. package/dist/ops/instances.d.ts +2 -1
  30. package/dist/ops/instances.js +7 -1
  31. package/dist/ops/links.d.ts +1 -1
  32. package/dist/ops/links.js +1 -1
  33. package/dist/ops/naming.d.ts +1 -1
  34. package/dist/ops/naming.js +3 -1
  35. package/dist/ops/scope.d.ts +5 -1
  36. package/dist/ops/scope.js +19 -1
  37. package/dist/ops/slots.d.ts +1 -1
  38. package/dist/ops/slots.js +15 -2
  39. package/dist/ops/values.d.ts +1 -1
  40. package/dist/ops/values.js +5 -1
  41. package/dist/provenance.d.ts +4 -2
  42. package/dist/provenance.js +58 -17
  43. package/dist/release.d.ts +48 -0
  44. package/dist/release.js +318 -0
  45. package/dist/render.d.ts +4 -1
  46. package/dist/render.js +21 -2
  47. package/dist/resync.d.ts +98 -0
  48. package/dist/resync.js +234 -0
  49. package/dist/review.d.ts +1 -1
  50. package/dist/review.js +1 -1
  51. package/dist/reviewdocs.d.ts +42 -0
  52. package/dist/reviewdocs.js +263 -0
  53. package/dist/skills.js +1 -1
  54. package/dist/status.d.ts +1 -1
  55. package/dist/status.js +1 -1
  56. package/dist/types.d.ts +1 -1
  57. package/dist/types.js +1 -1
  58. package/dist/verifynote.d.ts +18 -0
  59. package/dist/verifynote.js +92 -0
  60. package/meta-kb/data/manifest.json +2 -2
  61. package/meta-kb/data/nodes.json +8 -8
  62. package/package.json +7 -3
  63. package/schema/edge.schema.json +68 -0
  64. package/schema/edges.schema.json +9 -0
  65. package/schema/node.schema.json +893 -0
  66. package/schema/nodes.schema.json +9 -0
  67. package/schema/okb.schema.json +41 -0
  68. package/skills/build-domain-kb-from-docs/SKILL.md +20 -2
  69. package/skills/ontology-coach/SKILL.md +6 -2
  70. package/skills/ontology-maintainer/SKILL.md +152 -0
  71. package/skills/ontology-review/SKILL.md +3 -1
  72. package/skills/ontology-signoff/SKILL.md +182 -0
  73. package/templates/okb-check.yml +132 -0
  74. package/templates/pull_request_template.md +16 -0
package/dist/diff.d.ts ADDED
@@ -0,0 +1,85 @@
1
+ /**
2
+ * `okb diff`: what changed in the knowledge between two versions of an ontology, not in the JSON.
3
+ * `diffOntologies` is a pure function over two loaded `Ontology` objects (no git, no files);
4
+ * `diffMarkdown` writes it for a PR comment. Nodes are matched by id, so a rename keeps its
5
+ * identity and shows as a rename. `createdAt`/`updatedAt` are ignored: a node whose only change is
6
+ * a stamp isn't a change in the knowledge (it's counted in `summary.stampOnly`).
7
+ */
8
+ import { type OkbNode, type Ontology } from "@ontology-kit/reader";
9
+ /** One changed field. `path` is the raw key path; `field` is how it reads (slot ids become slot names). */
10
+ export interface FieldChange {
11
+ path: string[];
12
+ field: string;
13
+ before?: unknown;
14
+ after?: unknown;
15
+ }
16
+ export interface NodeRef {
17
+ id: string;
18
+ type: string;
19
+ name: string;
20
+ }
21
+ export interface NodeChange extends NodeRef {
22
+ /** The old name, when it differs from `name`. */
23
+ renamedFrom?: string;
24
+ /** Other names it has had (from `formerNames`, oldest first): earlier ones, or ones it passed through on the way here. */
25
+ otherFormerNames?: string[];
26
+ fields: FieldChange[];
27
+ /** For a quote: how it changed in words ("moved", "text changed"). */
28
+ note?: string;
29
+ }
30
+ export interface TypeDiff {
31
+ added: NodeRef[];
32
+ removed: NodeRef[];
33
+ changed: NodeChange[];
34
+ }
35
+ export interface EdgeRef {
36
+ from: string;
37
+ type: string;
38
+ to: string;
39
+ /** The link in words: `Merlot is a Red`, `Wine has slot body`, `Wine —maker→ Winery`. */
40
+ text: string;
41
+ props?: Record<string, unknown>;
42
+ }
43
+ export interface EdgeChange extends EdgeRef {
44
+ before: Record<string, unknown>;
45
+ after: Record<string, unknown>;
46
+ }
47
+ export interface TypeRename {
48
+ slot: string;
49
+ from: string;
50
+ to: string;
51
+ /** How many edges carry the type. */
52
+ edges: number;
53
+ /** Other edge types the slot has used (from `formerRelTypes`, oldest first), when there are any. */
54
+ otherFormerTypes?: string[];
55
+ }
56
+ export interface OntologyDiff {
57
+ old: string;
58
+ new: string;
59
+ summary: {
60
+ nodesAdded: number;
61
+ nodesRemoved: number;
62
+ nodesChanged: number;
63
+ edgesAdded: number;
64
+ edgesRemoved: number;
65
+ edgesChanged: number;
66
+ /** Nodes whose only difference is createdAt/updatedAt. */
67
+ stampOnly: number;
68
+ };
69
+ /** Only types with changes, in the format's order. */
70
+ types: Record<string, TypeDiff>;
71
+ /** Relationship slots whose edge type changed (a slot rename); their edges are not listed as changes. */
72
+ relationshipTypeRenames: TypeRename[];
73
+ edges: {
74
+ added: EdgeRef[];
75
+ removed: EdgeRef[];
76
+ changed: EdgeChange[];
77
+ };
78
+ }
79
+ /** What a node is called, for a reader. */
80
+ export declare function label(n: OkbNode, ont: Ontology): string;
81
+ /** Compare two ontologies. `oldName`/`newName` only label the result. */
82
+ export declare function diffOntologies(a: Ontology, b: Ontology, oldName?: string, newName?: string): OntologyDiff;
83
+ export declare function isEmpty(d: OntologyDiff): boolean;
84
+ /** The diff as Markdown, written for a PR comment. */
85
+ export declare function diffMarkdown(d: OntologyDiff): string;
package/dist/diff.js ADDED
@@ -0,0 +1,323 @@
1
+ /**
2
+ * `okb diff`: what changed in the knowledge between two versions of an ontology, not in the JSON.
3
+ * `diffOntologies` is a pure function over two loaded `Ontology` objects (no git, no files);
4
+ * `diffMarkdown` writes it for a PR comment. Nodes are matched by id, so a rename keeps its
5
+ * identity and shows as a rename. `createdAt`/`updatedAt` are ignored: a node whose only change is
6
+ * a stamp isn't a change in the knowledge (it's counted in `summary.stampOnly`).
7
+ */
8
+ import { NODE_TYPES, edgeProps, nodeLabel } from "@ontology-kit/reader";
9
+ const STAMPS = new Set(["createdAt", "updatedAt"]);
10
+ /** Bookkeeping that `okb rename` keeps; the rename itself is what a reader needs, so these aren't listed as field changes. */
11
+ const RENAME_TRAIL = new Set(["formerNames", "formerRelTypes"]);
12
+ const isPlain = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
13
+ /** What a node is called, for a reader. */
14
+ export function label(n, ont) {
15
+ if (n.type === "SourceLocation") {
16
+ const q = String(n.quote ?? "");
17
+ const text = q.length > 60 ? q.slice(0, 57) + "..." : q;
18
+ const src = ont.targets(n.id, "PART_OF").map((id) => ont.get(id)).find((s) => s?.type === "Source");
19
+ return `"${text}"` + (src && src.type === "Source" ? ` (${src.title})` : "");
20
+ }
21
+ return nodeLabel(n);
22
+ }
23
+ function leaves(node) {
24
+ const out = new Map();
25
+ const walk = (value, path) => {
26
+ if (isPlain(value)) {
27
+ for (const [k, v] of Object.entries(value))
28
+ if (v !== undefined)
29
+ walk(v, [...path, k]);
30
+ }
31
+ else
32
+ out.set(JSON.stringify(path), { path, value });
33
+ };
34
+ for (const [k, v] of Object.entries(node))
35
+ if (v !== undefined && !STAMPS.has(k) && k !== "id" && k !== "type")
36
+ walk(v, [k]);
37
+ return out;
38
+ }
39
+ const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
40
+ function fieldChanges(a, b, name) {
41
+ const la = leaves(a);
42
+ const lb = leaves(b);
43
+ const out = [];
44
+ const keys = new Set([...la.keys(), ...lb.keys()]);
45
+ for (const k of keys) {
46
+ const x = la.get(k);
47
+ const y = lb.get(k);
48
+ if (x && y && same(x.value, y.value))
49
+ continue;
50
+ const path = (x ?? y).path;
51
+ const field = path.map((seg, i) => (i === 0 ? seg : name(seg))).join(".");
52
+ const change = { path, field };
53
+ if (x)
54
+ change.before = x.value;
55
+ if (y)
56
+ change.after = y.value;
57
+ out.push(change);
58
+ }
59
+ return out.sort((p, q) => (p.field < q.field ? -1 : p.field > q.field ? 1 : 0));
60
+ }
61
+ const LOCATION_FIELDS = new Set(["locator", "headingPath", "startLine", "endLine", "lines", "blockKind", "sourceLink", "pageLink", "page"]);
62
+ const PHRASE = {
63
+ IS_A: (a, b) => `${a} is a ${b}`,
64
+ INSTANCE_OF: (a, b) => `${a} is an instance of ${b}`,
65
+ HAS_SLOT: (a, b) => `${a} has slot ${b}`,
66
+ RANGE: (a, b) => `${a} has range ${b}`,
67
+ INVERSE_OF: (a, b) => `${a} is the inverse of ${b}`,
68
+ DISJOINT_WITH: (a, b) => `${a} is disjoint with ${b}`,
69
+ NEEDS: (a, b) => `${a} needs ${b}`,
70
+ BECAME: (a, b) => `${a} became ${b}`,
71
+ ABOUT: (a, b) => `${a} is about ${b}`,
72
+ CITES: (a, b) => `${a} cites ${b}`,
73
+ PART_OF: (a, b) => `${a} is part of ${b}`,
74
+ GOVERNS: (a, b) => `${a} governs ${b}`,
75
+ REFINES: (a, b) => `${a} refines ${b}`,
76
+ FULFILLS: (a, b) => `${a} fulfills ${b}`,
77
+ };
78
+ const edgeKey = (from, type, to) => `${from}\u0000${type}\u0000${to}`;
79
+ /** Compare two ontologies. `oldName`/`newName` only label the result. */
80
+ export function diffOntologies(a, b, oldName = "old", newName = "new") {
81
+ const byIdA = new Map();
82
+ for (const n of a.nodes)
83
+ if (!byIdA.has(n.id))
84
+ byIdA.set(n.id, n);
85
+ const byIdB = new Map();
86
+ for (const n of b.nodes)
87
+ if (!byIdB.has(n.id))
88
+ byIdB.set(n.id, n);
89
+ // How a stored id reads: its name in the new version, else the old one, else the id itself.
90
+ const nameOf = (id) => {
91
+ const n = byIdB.get(id) ?? byIdA.get(id);
92
+ return n ? label(n, byIdB.has(id) ? b : a) : id;
93
+ };
94
+ const types = {};
95
+ const bucket = (t) => (types[t] ??= { added: [], removed: [], changed: [] });
96
+ const ref = (n, o) => ({ id: n.id, type: n.type, name: label(n, o) });
97
+ let stampOnly = 0;
98
+ for (const [id, nb] of byIdB) {
99
+ const na = byIdA.get(id);
100
+ if (!na) {
101
+ bucket(nb.type).added.push(ref(nb, b));
102
+ continue;
103
+ }
104
+ if (na.type !== nb.type) {
105
+ bucket(na.type).removed.push(ref(na, a));
106
+ bucket(nb.type).added.push(ref(nb, b));
107
+ continue;
108
+ }
109
+ const fields = fieldChanges(na, nb, nameOf).filter((f) => !RENAME_TRAIL.has(f.path[0]));
110
+ if (!fields.length) {
111
+ if (!same(na, nb))
112
+ stampOnly++;
113
+ continue;
114
+ }
115
+ const change = { ...ref(nb, b), fields };
116
+ const was = label(na, a);
117
+ if (was !== change.name) {
118
+ change.renamedFrom = was;
119
+ const earlier = "formerNames" in nb && Array.isArray(nb.formerNames) ? nb.formerNames.filter((x) => x !== was && x !== change.name) : undefined;
120
+ if (earlier?.length)
121
+ change.otherFormerNames = earlier;
122
+ }
123
+ if (nb.type === "SourceLocation") {
124
+ const parts = [];
125
+ if (fields.some((f) => LOCATION_FIELDS.has(f.path[0])))
126
+ parts.push("moved");
127
+ if (fields.some((f) => f.path[0] === "quote"))
128
+ parts.push("text changed");
129
+ if (parts.length)
130
+ change.note = parts.join(", ");
131
+ }
132
+ bucket(nb.type).changed.push(change);
133
+ }
134
+ for (const [id, na] of byIdA)
135
+ if (!byIdB.has(id))
136
+ bucket(na.type).removed.push(ref(na, a));
137
+ const byName = (x, y) => (x.name < y.name ? -1 : x.name > y.name ? 1 : x.id < y.id ? -1 : x.id > y.id ? 1 : 0);
138
+ const ordered = {};
139
+ const order = [...NODE_TYPES, ...Object.keys(types).filter((t) => !NODE_TYPES.includes(t))];
140
+ for (const t of order) {
141
+ const d = types[t];
142
+ if (!d)
143
+ continue;
144
+ d.added.sort(byName);
145
+ d.removed.sort(byName);
146
+ d.changed.sort(byName);
147
+ ordered[t] = d;
148
+ }
149
+ // A slot rename changes its edge type, and with it every edge of that type; say so once instead of listing them.
150
+ const renames = [];
151
+ const retype = new Map();
152
+ const slotTypesA = a.rel.edgeTypes();
153
+ const slotTypesB = b.rel.edgeTypes();
154
+ const countA = new Map();
155
+ for (const e of a.edges)
156
+ countA.set(e.type, (countA.get(e.type) ?? 0) + 1);
157
+ for (const [oldType, slotId] of slotTypesA) {
158
+ const nb = byIdB.get(slotId);
159
+ if (nb?.type !== "Slot" || !nb.relType || nb.relType === oldType)
160
+ continue;
161
+ // Skip if the old type is still some slot's type in the new version (types swapped or reused).
162
+ if (slotTypesB.has(oldType))
163
+ continue;
164
+ retype.set(oldType, nb.relType);
165
+ const rename = { slot: label(nb, b), from: oldType, to: nb.relType, edges: countA.get(oldType) ?? 0 };
166
+ const earlier = nb.formerRelTypes?.filter((x) => x !== oldType && x !== nb.relType);
167
+ if (Array.isArray(earlier) && earlier.length)
168
+ rename.otherFormerTypes = earlier;
169
+ renames.push(rename);
170
+ }
171
+ renames.sort((x, y) => (x.from < y.from ? -1 : 1));
172
+ const edgesA = new Map();
173
+ for (const e of a.edges)
174
+ edgesA.set(edgeKey(e.from, retype.get(e.type) ?? e.type, e.to), e);
175
+ const edgesB = new Map();
176
+ for (const e of b.edges)
177
+ edgesB.set(edgeKey(e.from, e.type, e.to), e);
178
+ const slotOfType = (t) => {
179
+ const id = slotTypesB.get(t) ?? slotTypesA.get(t);
180
+ const s = id ? (byIdB.get(id) ?? byIdA.get(id)) : undefined;
181
+ return s ? label(s, byIdB.has(s.id) ? b : a) : undefined;
182
+ };
183
+ const describe = (e) => {
184
+ const from = nameOf(e.from);
185
+ const to = nameOf(e.to);
186
+ const phrase = Object.hasOwn(PHRASE, e.type) ? PHRASE[e.type] : undefined;
187
+ const slot = phrase ? undefined : slotOfType(e.type);
188
+ const text = phrase ? phrase(from, to) : `${from} —${slot ?? e.type}→ ${to}`;
189
+ const props = edgeProps(e);
190
+ const r = { from: e.from, type: e.type, to: e.to, text };
191
+ if (Object.keys(props).length)
192
+ r.props = props;
193
+ return r;
194
+ };
195
+ const added = [];
196
+ const removed = [];
197
+ const changed = [];
198
+ for (const [k, eb] of edgesB) {
199
+ const ea = edgesA.get(k);
200
+ if (!ea)
201
+ added.push(describe(eb));
202
+ else if (!same(sortKeys(edgeProps(ea)), sortKeys(edgeProps(eb)))) {
203
+ changed.push({ ...describe(eb), before: edgeProps(ea), after: edgeProps(eb) });
204
+ }
205
+ }
206
+ for (const [k, ea] of edgesA)
207
+ if (!edgesB.has(k))
208
+ removed.push(describe({ ...ea, type: retype.get(ea.type) ?? ea.type }));
209
+ const byText = (x, y) => (x.text < y.text ? -1 : x.text > y.text ? 1 : 0);
210
+ added.sort(byText);
211
+ removed.sort(byText);
212
+ changed.sort(byText);
213
+ let nodesAdded = 0, nodesRemoved = 0, nodesChanged = 0;
214
+ for (const d of Object.values(ordered)) {
215
+ nodesAdded += d.added.length;
216
+ nodesRemoved += d.removed.length;
217
+ nodesChanged += d.changed.length;
218
+ }
219
+ return {
220
+ old: oldName,
221
+ new: newName,
222
+ summary: { nodesAdded, nodesRemoved, nodesChanged, edgesAdded: added.length, edgesRemoved: removed.length, edgesChanged: changed.length, stampOnly },
223
+ types: ordered,
224
+ relationshipTypeRenames: renames,
225
+ edges: { added, removed, changed },
226
+ };
227
+ }
228
+ function sortKeys(o) {
229
+ return Object.fromEntries(Object.keys(o).sort().map((k) => [k, o[k]]));
230
+ }
231
+ export function isEmpty(d) {
232
+ const s = d.summary;
233
+ return s.nodesAdded + s.nodesRemoved + s.nodesChanged + s.edgesAdded + s.edgesRemoved + s.edgesChanged + d.relationshipTypeRenames.length === 0;
234
+ }
235
+ const TYPE_TITLES = {
236
+ Ontology: "Ontology", CompetencyQuestion: "Competency questions", Term: "Terms", ReusedOntology: "Reused ontologies", Class: "Classes",
237
+ Slot: "Slots", Instance: "Instances", DesignDecision: "Design decisions", Source: "Sources", SourceLocation: "Quotes", Rule: "Rules",
238
+ };
239
+ /** A value on one line, for a table cell or a sentence. */
240
+ function show(v) {
241
+ if (v === undefined)
242
+ return "(none)";
243
+ if (typeof v === "string")
244
+ return JSON.stringify(v);
245
+ if (Array.isArray(v))
246
+ return v.length ? v.map((x) => (typeof x === "string" ? x : JSON.stringify(x))).join(", ") : "(empty)";
247
+ return JSON.stringify(v);
248
+ }
249
+ const cell = (s) => s.replace(/\|/g, "\\|").replace(/\r?\n/g, " ");
250
+ const code = (s) => "`" + s.replace(/`/g, "'") + "`";
251
+ /** A changed rule: statement, modality and verification status side by side, then any other field that changed. */
252
+ function ruleTable(c) {
253
+ const find = (p) => c.fields.find((f) => f.field === p);
254
+ const row = (name, f, unchanged) => f ? ` | ${name} | ${cell(show(f.before))} | ${cell(show(f.after))} |` : ` | ${name} | ${unchanged} | (same) |`;
255
+ const main = ["statement", "modality", "verification.status"];
256
+ return [
257
+ " | | Before | After |",
258
+ " |---|---|---|",
259
+ row("statement", find("statement"), "unchanged"),
260
+ row("modality", find("modality"), "unchanged"),
261
+ row("verification", find("verification.status"), "unchanged"),
262
+ ...c.fields.filter((f) => ![...main, "name"].includes(f.field)).map((f) => ` | ${cell(f.field)} | ${cell(show(f.before))} | ${cell(show(f.after))} |`),
263
+ ];
264
+ }
265
+ /** The diff as Markdown, written for a PR comment. */
266
+ export function diffMarkdown(d) {
267
+ const out = [`# Ontology changes: ${d.old} → ${d.new}`, ""];
268
+ if (isEmpty(d)) {
269
+ out.push("No changes to the knowledge." + (d.summary.stampOnly ? ` (${d.summary.stampOnly} node(s) differ only in createdAt/updatedAt.)` : ""));
270
+ return out.join("\n") + "\n";
271
+ }
272
+ const s = d.summary;
273
+ out.push(`${s.nodesAdded} added, ${s.nodesRemoved} removed and ${s.nodesChanged} changed node(s); ${s.edgesAdded} link(s) added, ${s.edgesRemoved} removed, ${s.edgesChanged} changed.`, "");
274
+ for (const [type, t] of Object.entries(d.types)) {
275
+ out.push(`## ${TYPE_TITLES[type] ?? type + "s"}`, "");
276
+ for (const n of t.added)
277
+ out.push(`- **Added** ${code(n.name)}`);
278
+ for (const n of t.removed)
279
+ out.push(`- **Removed** ${code(n.name)}${type === "SourceLocation" ? " (the quote disappeared)" : ""}`);
280
+ for (const c of t.changed) {
281
+ const head = c.renamedFrom !== undefined ? `**Renamed** ${code(c.renamedFrom)} → ${code(c.name)}` : `**Changed** ${code(c.name)}`;
282
+ const others = c.otherFormerNames ? ` (also named ${c.otherFormerNames.map(code).join(", ")})` : "";
283
+ out.push(`- ${head}${c.note ? ` (${c.note})` : ""}${others}`);
284
+ if (type === "Rule") {
285
+ out.push("", ...ruleTable(c), "");
286
+ continue;
287
+ }
288
+ for (const f of c.fields) {
289
+ if (f.field === "name" && c.renamedFrom !== undefined)
290
+ continue;
291
+ out.push(` - ${f.field}: ${show(f.before)} → ${show(f.after)}`);
292
+ }
293
+ }
294
+ out.push("");
295
+ }
296
+ if (d.relationshipTypeRenames.length) {
297
+ out.push("## Relationship edge types renamed", "");
298
+ for (const r of d.relationshipTypeRenames)
299
+ out.push(`- ${code(":" + r.from)} → ${code(":" + r.to)} (slot ${code(r.slot)}, ${r.edges} edge(s) keep their meaning${r.otherFormerTypes ? `; also used ${r.otherFormerTypes.map((t) => code(":" + t)).join(", ")}` : ""})`);
300
+ out.push("");
301
+ }
302
+ const links = (title, list, mark) => {
303
+ if (!list.length)
304
+ return;
305
+ out.push(`## ${title}`, "");
306
+ for (const e of list)
307
+ out.push(`- ${mark} ${e.text}${e.props ? ` (${Object.entries(e.props).map(([k, v]) => `${k}=${show(v)}`).join(", ")})` : ""}`);
308
+ out.push("");
309
+ };
310
+ links("Links added", d.edges.added, "+");
311
+ links("Links removed", d.edges.removed, "−");
312
+ if (d.edges.changed.length) {
313
+ out.push("## Link properties changed", "");
314
+ for (const e of d.edges.changed) {
315
+ const keys = new Set([...Object.keys(e.before), ...Object.keys(e.after)]);
316
+ out.push(`- ${e.text}: ${[...keys].sort().filter((k) => !same(e.before[k], e.after[k])).map((k) => `${k} ${show(e.before[k])} → ${show(e.after[k])}`).join("; ")}`);
317
+ }
318
+ out.push("");
319
+ }
320
+ if (s.stampOnly)
321
+ out.push(`${s.stampOnly} other node(s) differ only in createdAt/updatedAt and are not listed.`, "");
322
+ return out.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
323
+ }
package/dist/export.d.ts CHANGED
@@ -23,7 +23,7 @@
23
23
  * rules (default true) export verified domain rules with their quotes and sources
24
24
  * unverified also export rules that aren't verified yet, each with its verification status
25
25
  */
26
- import { type Ontology } from "@ontology-kit/format";
26
+ import { type Ontology } from "@ontology-kit/reader";
27
27
  export interface ExportNode {
28
28
  id: string;
29
29
  labels: string[];
package/dist/export.js CHANGED
@@ -23,7 +23,7 @@
23
23
  * rules (default true) export verified domain rules with their quotes and sources
24
24
  * unverified also export rules that aren't verified yet, each with its verification status
25
25
  */
26
- import { edgeProps } from "@ontology-kit/format";
26
+ import { edgeProps } from "@ontology-kit/reader";
27
27
  import { MetaKB } from "./metakb.js";
28
28
  export function exportGraph(ont, opts = {}) {
29
29
  const inherited = opts.inherited ?? true;
@@ -8,7 +8,7 @@
8
8
  * Things another question already needs are left out (they're covered), and each
9
9
  * suggestion appears once, under the first subject it came up for.
10
10
  */
11
- import { type Ontology } from "@ontology-kit/format";
11
+ import { type Ontology } from "@ontology-kit/reader";
12
12
  export interface QuestionFamily {
13
13
  /** What the question is about (a class, instance, or a slot's class). */
14
14
  subject: string;
package/dist/families.js CHANGED
@@ -8,7 +8,7 @@
8
8
  * Things another question already needs are left out (they're covered), and each
9
9
  * suggestion appears once, under the first subject it came up for.
10
10
  */
11
- import {} from "@ontology-kit/format";
11
+ import {} from "@ontology-kit/reader";
12
12
  /** At most this many suggestions per list, so a hint stays one line. */
13
13
  const MAX_SUGGESTIONS = 4;
14
14
  export function questionFamilies(ont, cqId) {
package/dist/help.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** The text of `okb help`. Its own module so the docs generator can read it without running the CLI. */
2
- export declare const HELP = "okb: build an ontology step by step (Ontology 101 method)\n\nGetting started\n okb init <folder> --name \"Wine and Food\" create a new ontology\n okb status where you are and what to do next\n okb step [n|next|prev] move between steps and show the guide\n okb explain [topic] learn a concept, rule, step (e.g. okb explain 5) or decision guide\n okb validate [--all] [--why] [--json] check your ontology against the rules\n\nStep 1: scope okb scope --domain \"...\" --purpose \"...\" --users a,b --maintainers x --out-of-scope \"...\"\n okb cq add \"Which wines go with fish?\" \u00B7 okb cq list\nStep 2: reuse okb reuse add --name \"...\" --url ... --decision reuse|adapt|reference|rejected\n okb reuse none --why \"...\"\nStep 3: terms okb term add wine grape winery color ... \u00B7 okb term list\nStep 4: classes okb convention [--class-case PascalCase] [--slot-case camelCase] [--number singular]\n okb class add RedWine --parent Wine [--desc \"...\"] [--synonym ...] [--abstract]\n okb class set RedWine [--desc] [--add-parent X] [--remove-parent X] [--synonym S]\n okb class disjoint RedWine WhiteWine RoseWine\n okb term set wine --as class|slot|instance|value|synonym|out-of-scope [--node Name]\n okb tree [--instances]\nStep 5: slots Two kinds (Ontology 101 calls both \"slots\"):\n okb property add body --on Wine --type Enumerated --values light,medium,full --card single\n okb relationship add maker --from Wine --to Winery --card single (stored as edges :MAKER)\n okb slot set body [--on X] [--off X] [--desc] ... \u00B7 okb show Wine\nStep 6: facets okb slot set maker --card single --min 1 \u00B7 okb slot set producer --range Winery\n okb relationship inverse maker produces (one edge, readable from both ends)\n okb relationship property preferredOver condition --type String [--required] [--values a,b]\n okb link Radio preferredOver SegmentedControl condition=\"2 to 7 options\" [--rule <rule id>]\n okb unlink Radio preferredOver SegmentedControl\n okb class fix DessertWine sugar=sweet (a value every member has)\n okb class default Wine body=full (a starting value, overridable)\n okb class restrict SingleVarietal grape --max 1\nStep 7: instances okb instance add \"Chateau Morgon Beaujolais\" --of Beaujolais body=light maker=\"Chateau Morgon\"\n okb instance set \"Chateau Morgon Beaujolais\" grape+=Gamay (+= adds, -= removes, slot= clears)\n okb instance set \"Chateau Morgon Beaujolais\" --of Beaujolais (move to another class)\nStep 8: review okb cq link 1 Wine Food goesWellWith \u00B7 okb validate --all \u00B7 okb review\n okb decision add --title \"...\" --decision \"...\" --why \"...\" [--about X] [--waives rule-id]\n okb diagram [--out diagram.md]\nExport okb export [--format json|cypher] [--with-schema] [--no-inherited] [--no-rules] [--include-unverified] [--out file]\n (instances as nodes labeled with their classes, ready for Neo4j / Neptune / Memgraph)\n\nDocuments okb source add docs/button.md [--repo-url https://github.com/.../button.md] [--url https://site/button]\n(extraction) okb source outline <source> [--quotable] [--json] every block, with heading path and lines\n okb quote add <source> \"verbatim text\" [--cites Node] [--line N] located automatically\n okb rule add --statement \"...\" --modality SHOULD --governs Button --cites <quote id> [--authored] [--value slot=value] [--refines <rule> --adds \"...\"]\n okb rule refines <rule> <broader rule> [--adds \"...\"] okb fulfills <instance> <rule>\n okb cite <node> <quote id> attach an existing quote to a node\n okb verify <node> --status SUPPORTED|OVERREACH|UNSUPPORTED [--corrected \"...\"] \u00B7 okb verify <node> --approve\n okb source refresh <source> after the document changes\n\nSkills okb skills install [--copy] [--dir <folder>] [--force] link (or copy) the packaged skills into ~/.claude/skills\n okb skills status [--dir <folder>] which are installed, where, and whether they match this okb\n\nAlso: okb show <name> \u00B7 okb rename <old> <new> \u00B7 okb remove <name> \u00B7 okb drift <folder>...\nNames: when a class and a slot share a name, say which: class:Genre / slot:genre\nGlobal options: -C <folder> (default: current folder) \u00B7 --json (machine-readable output where supported)";
2
+ export declare const HELP = "okb: build an ontology step by step (Ontology 101 method)\n\nGetting started\n okb init <folder> --name \"Wine and Food\" create a new ontology\n okb status where you are and what to do next\n okb step [n|next|prev] move between steps and show the guide\n okb explain [topic] learn a concept, rule, step (e.g. okb explain 5) or decision guide\n okb validate [--all] [--why] [--json] check your ontology against the rules\n\nStep 1: scope okb scope --domain \"...\" --purpose \"...\" --users a,b --maintainers x --out-of-scope \"...\"\n okb cq add \"Which wines go with fish?\" \u00B7 okb cq list\nStep 2: reuse okb reuse add --name \"...\" --url ... --decision reuse|adapt|reference|rejected\n okb reuse none --why \"...\"\nStep 3: terms okb term add wine grape winery color ... \u00B7 okb term list\nStep 4: classes okb convention [--class-case PascalCase] [--slot-case camelCase] [--number singular]\n okb class add RedWine --parent Wine [--desc \"...\"] [--synonym ...] [--abstract]\n okb class set RedWine [--desc] [--add-parent X] [--remove-parent X] [--synonym S]\n okb class disjoint RedWine WhiteWine RoseWine\n okb term set wine --as class|slot|instance|value|synonym|out-of-scope [--node Name]\n okb tree [--instances]\nStep 5: slots Two kinds (Ontology 101 calls both \"slots\"):\n okb property add body --on Wine --type Enumerated --values light,medium,full --card single\n okb relationship add maker --from Wine --to Winery --card single (stored as edges :MAKER)\n okb slot set body [--on X] [--off X] [--desc] ... \u00B7 okb show Wine\nStep 6: facets okb slot set maker --card single --min 1 \u00B7 okb slot set producer --range Winery\n okb relationship inverse maker produces (one edge, readable from both ends)\n okb relationship property preferredOver condition --type String [--required] [--values a,b]\n okb link Radio preferredOver SegmentedControl condition=\"2 to 7 options\" [--rule <rule id>]\n okb unlink Radio preferredOver SegmentedControl\n okb class fix DessertWine sugar=sweet (a value every member has)\n okb class default Wine body=full (a starting value, overridable)\n okb class restrict SingleVarietal grape --max 1\nStep 7: instances okb instance add \"Chateau Morgon Beaujolais\" --of Beaujolais body=light maker=\"Chateau Morgon\"\n okb instance set \"Chateau Morgon Beaujolais\" grape+=Gamay (+= adds, -= removes, slot= clears)\n okb instance set \"Chateau Morgon Beaujolais\" --of Beaujolais (move to another class)\nStep 8: review okb cq link 1 Wine Food goesWellWith \u00B7 okb validate --all \u00B7 okb review\n okb decision add --title \"...\" --decision \"...\" --why \"...\" [--about X] [--waives rule-id]\n okb diagram [--out diagram.md]\nExport okb export [--format json|cypher] [--with-schema] [--no-inherited] [--no-rules] [--include-unverified] [--out file]\n (instances as nodes labeled with their classes, ready for Neo4j / Neptune / Memgraph)\n\nDocuments okb source add docs/button.md [--repo-url https://github.com/.../button.md] [--url https://site/button]\n(extraction) okb source outline <source> [--quotable] [--json] every block, with heading path and lines\n okb quote add <source> \"verbatim text\" [--cites Node] [--line N] located automatically\n okb rule add --statement \"...\" --modality SHOULD --governs Button --cites <quote id> [--authored] [--value slot=value] [--refines <rule> --adds \"...\"]\n okb rule refines <rule> <broader rule> [--adds \"...\"] okb fulfills <instance> <rule>\n okb cite <node> <quote id> attach an existing quote to a node\n okb verify <node> --status SUPPORTED|OVERREACH|UNSUPPORTED [--corrected \"...\"] [--note \"...\"] [--ref <url>] \u00B7 okb verify <node> --approve\n okb source refresh <source> | --all [--dry-run] [--record] [--strict] [--json] after the document changes (--all: worklist)\n\nSkills okb skills install [--copy] [--dir <folder>] [--force] link (or copy) the packaged skills into ~/.claude/skills\n okb skills status [--dir <folder>] which are installed, where, and whether they match this okb\n\nAlso: okb show <name> \u00B7 okb rename <old> <new> \u00B7 okb remove <name> \u00B7 okb drift <folder>...\n okb check [--json] is this KB safe to merge? (validation, quotes, verification; non-zero exit if not)\n okb pin record this okb version in okb.json (CI installs it; okb check warns on older)\n okb docs --out <folder> write Markdown reference pages: classes, slots, rules and the quotes behind them\n --changed <ref> [--hops N] only the pages that differ from a git ref, plus the stale-quote worklist\n --context every rule beside the source text around its quote, problem cases first\n okb diff <old> [<new>] [--json] what changed in the knowledge between two folders or git refs (okb diff main)\n okb release <version> \u00B7 okb release verify cut a pinned release with a manifest and change log; check files against it\nNames: when a class and a slot share a name, say which: class:Genre / slot:genre\nGlobal options: -C <folder> (default: current folder) \u00B7 --json (machine-readable output where supported)";
package/dist/help.js CHANGED
@@ -46,12 +46,19 @@ Documents okb source add docs/button.md [--repo-url https://github.
46
46
  okb rule add --statement "..." --modality SHOULD --governs Button --cites <quote id> [--authored] [--value slot=value] [--refines <rule> --adds "..."]
47
47
  okb rule refines <rule> <broader rule> [--adds "..."] okb fulfills <instance> <rule>
48
48
  okb cite <node> <quote id> attach an existing quote to a node
49
- okb verify <node> --status SUPPORTED|OVERREACH|UNSUPPORTED [--corrected "..."] · okb verify <node> --approve
50
- okb source refresh <source> after the document changes
49
+ okb verify <node> --status SUPPORTED|OVERREACH|UNSUPPORTED [--corrected "..."] [--note "..."] [--ref <url>] · okb verify <node> --approve
50
+ okb source refresh <source> | --all [--dry-run] [--record] [--strict] [--json] after the document changes (--all: worklist)
51
51
 
52
52
  Skills okb skills install [--copy] [--dir <folder>] [--force] link (or copy) the packaged skills into ~/.claude/skills
53
53
  okb skills status [--dir <folder>] which are installed, where, and whether they match this okb
54
54
 
55
55
  Also: okb show <name> · okb rename <old> <new> · okb remove <name> · okb drift <folder>...
56
+ okb check [--json] is this KB safe to merge? (validation, quotes, verification; non-zero exit if not)
57
+ okb pin record this okb version in okb.json (CI installs it; okb check warns on older)
58
+ okb docs --out <folder> write Markdown reference pages: classes, slots, rules and the quotes behind them
59
+ --changed <ref> [--hops N] only the pages that differ from a git ref, plus the stale-quote worklist
60
+ --context every rule beside the source text around its quote, problem cases first
61
+ okb diff <old> [<new>] [--json] what changed in the knowledge between two folders or git refs (okb diff main)
62
+ okb release <version> · okb release verify cut a pinned release with a manifest and change log; check files against it
56
63
  Names: when a class and a slot share a name, say which: class:Genre / slot:genre
57
64
  Global options: -C <folder> (default: current folder) · --json (machine-readable output where supported)`;
@@ -0,0 +1,18 @@
1
+ import { type Ontology } from "@ontology-kit/reader";
2
+ export type DocFiles = Record<string, string>;
3
+ export declare const BANNER = "<!-- Generated by okb docs. Do not edit: change the knowledge base and run okb docs again. -->";
4
+ /** Every page for the ontology: file name (relative to the docs folder) → Markdown. */
5
+ export declare function kbDocs(ont: Ontology): DocFiles;
6
+ /** Write the pages into `dir`, removing pages an earlier run wrote (they carry the banner) that no longer exist. Other files stay. Returns the file names. */
7
+ export declare function writeKbDocs(ont: Ontology, dir: string): string[];
8
+ /**
9
+ * Write pages into `dir` (creating folders) and leave every other file alone. A page never replaces a file
10
+ * okb didn't write (no banner): that file is named in the error and nothing is written. Returns the file names.
11
+ */
12
+ export declare function writePages(dir: string, files: DocFiles): string[];
13
+ /**
14
+ * Write a changed-only view into `dir`, removing pages an earlier run wrote there (they carry the banner)
15
+ * that this view doesn't include, so a folder reused for a second `--changed` doesn't keep the first one's pages.
16
+ * `rules-in-context.md` is a separate view of the same folder and stays.
17
+ */
18
+ export declare function writeChangedPages(dir: string, files: DocFiles): string[];