@ontology-kit/okb 0.1.0 → 0.3.0-alpha.210
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/README.md +1 -1
- package/dist/check.d.ts +43 -0
- package/dist/check.js +83 -0
- package/dist/checks.d.ts +1 -1
- package/dist/checks.js +4 -4
- package/dist/cli.js +11 -705
- package/dist/clidocs.d.ts +0 -2
- package/dist/clidocs.js +5 -27
- package/dist/clock.js +1 -1
- package/dist/command-table.d.ts +134 -0
- package/dist/command-table.js +82 -0
- package/dist/commands/documents.d.ts +3 -0
- package/dist/commands/documents.js +250 -0
- package/dist/commands/getting-started.d.ts +3 -0
- package/dist/commands/getting-started.js +135 -0
- package/dist/commands/housekeeping.d.ts +3 -0
- package/dist/commands/housekeeping.js +203 -0
- package/dist/commands/modeling.d.ts +3 -0
- package/dist/commands/modeling.js +433 -0
- package/dist/commands/planning.d.ts +3 -0
- package/dist/commands/planning.js +212 -0
- package/dist/commands/reviewing.d.ts +3 -0
- package/dist/commands/reviewing.js +177 -0
- package/dist/commands/skills.d.ts +3 -0
- package/dist/commands/skills.js +52 -0
- package/dist/commands.d.ts +10 -22
- package/dist/commands.js +15 -622
- package/dist/diff.d.ts +85 -0
- package/dist/diff.js +323 -0
- package/dist/export.d.ts +1 -1
- package/dist/export.js +1 -1
- package/dist/families.d.ts +1 -1
- package/dist/families.js +1 -1
- package/dist/help.d.ts +11 -2
- package/dist/help.js +51 -57
- package/dist/kbdocs.d.ts +18 -0
- package/dist/kbdocs.js +393 -0
- package/dist/metakb.d.ts +1 -1
- package/dist/metakb.js +1 -1
- package/dist/naming.d.ts +2 -2
- package/dist/naming.js +2 -2
- package/dist/ontology-ref.d.ts +20 -0
- package/dist/ontology-ref.js +108 -0
- package/dist/ops/admin.d.ts +1 -1
- package/dist/ops/admin.js +24 -7
- package/dist/ops/classes.d.ts +1 -1
- package/dist/ops/classes.js +13 -5
- package/dist/ops/instances.d.ts +2 -1
- package/dist/ops/instances.js +7 -1
- package/dist/ops/links.d.ts +1 -1
- package/dist/ops/links.js +1 -1
- package/dist/ops/naming.d.ts +1 -1
- package/dist/ops/naming.js +3 -1
- package/dist/ops/scope.d.ts +5 -1
- package/dist/ops/scope.js +19 -1
- package/dist/ops/slots.d.ts +1 -1
- package/dist/ops/slots.js +15 -2
- package/dist/ops/values.d.ts +1 -1
- package/dist/ops/values.js +5 -1
- package/dist/provenance.d.ts +4 -2
- package/dist/provenance.js +58 -17
- package/dist/release.d.ts +52 -0
- package/dist/release.js +337 -0
- package/dist/render.d.ts +64 -1
- package/dist/render.js +240 -3
- package/dist/resync.d.ts +98 -0
- package/dist/resync.js +234 -0
- package/dist/review.d.ts +1 -1
- package/dist/review.js +1 -1
- package/dist/reviewdocs.d.ts +42 -0
- package/dist/reviewdocs.js +263 -0
- package/dist/runner.d.ts +3 -0
- package/dist/runner.js +79 -0
- package/dist/skills.js +1 -1
- package/dist/status.d.ts +1 -1
- package/dist/status.js +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/dist/verifynote.d.ts +18 -0
- package/dist/verifynote.js +92 -0
- package/dist/workflows.d.ts +256 -0
- package/dist/workflows.js +223 -0
- package/meta-kb/data/manifest.json +2 -2
- package/meta-kb/data/nodes.json +8 -8
- package/package.json +9 -4
- package/schema/edge.schema.json +68 -0
- package/schema/edges.schema.json +9 -0
- package/schema/node.schema.json +893 -0
- package/schema/nodes.schema.json +9 -0
- package/schema/okb.schema.json +41 -0
- package/skills/build-domain-kb-from-docs/SKILL.md +20 -2
- package/skills/ontology-coach/SKILL.md +6 -2
- package/skills/ontology-maintainer/SKILL.md +152 -0
- package/skills/ontology-review/SKILL.md +3 -1
- package/skills/ontology-signoff/SKILL.md +182 -0
- package/templates/okb-check.yml +132 -0
- 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/
|
|
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/
|
|
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;
|
package/dist/families.d.ts
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 { type Ontology } from "@ontology-kit/
|
|
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/
|
|
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,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The text of `okb help`, rendered from the command records so it can't drift from what the
|
|
3
|
+
* commands do. Its own module so the docs generator can read it without running the CLI.
|
|
4
|
+
*/
|
|
5
|
+
import type { Arg, Command } from "./command-table.js";
|
|
6
|
+
/** The first sentence of a description. */
|
|
7
|
+
export declare function summary(text: string): string;
|
|
8
|
+
/** A required option shows its operand without brackets (`--out <folder>`); an optional one stays in brackets. */
|
|
9
|
+
export declare function optionUsage([name, type]: Arg, required?: readonly string[]): string;
|
|
10
|
+
/** One line per command, grouped by what you are trying to do: its name, its subcommands, and what it does. */
|
|
11
|
+
export declare function renderHelp(commands: readonly Command[]): string;
|
package/dist/help.js
CHANGED
|
@@ -1,57 +1,51 @@
|
|
|
1
|
-
/** The
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
Skills okb skills install [--copy] [--dir <folder>] [--force] link (or copy) the packaged skills into ~/.claude/skills
|
|
53
|
-
okb skills status [--dir <folder>] which are installed, where, and whether they match this okb
|
|
54
|
-
|
|
55
|
-
Also: okb show <name> · okb rename <old> <new> · okb remove <name> · okb drift <folder>...
|
|
56
|
-
Names: when a class and a slot share a name, say which: class:Genre / slot:genre
|
|
57
|
-
Global options: -C <folder> (default: current folder) · --json (machine-readable output where supported)`;
|
|
1
|
+
/** The first sentence of a description. */
|
|
2
|
+
export function summary(text) {
|
|
3
|
+
return text.split(/(?<=\.)\s+(?=[A-Z`])/)[0].replace(/`/g, "").replace(/\.$/, "");
|
|
4
|
+
}
|
|
5
|
+
const MAX_FLAGS = 4;
|
|
6
|
+
/** A usage wider than this puts its summary on the next line. */
|
|
7
|
+
const MAX_USAGE = 48;
|
|
8
|
+
/** `okb init <folder> [--name]`: a single-form command shows its arguments, from the record; several forms show their subcommands. */
|
|
9
|
+
function usageOf(cmd) {
|
|
10
|
+
const forms = cmd.forms.filter((f) => !f.sub?.startsWith("--") && !f.hidden);
|
|
11
|
+
const subs = forms.filter((f) => f.sub).map((f) => f.sub);
|
|
12
|
+
const bare = forms.find((f) => !f.sub);
|
|
13
|
+
const rows = (bare?.args ?? []).filter((a) => a[0] !== "--json");
|
|
14
|
+
const words = rows.filter((a) => !a[0].startsWith("--")).map((a) => a[0]);
|
|
15
|
+
if (subs.length) {
|
|
16
|
+
// A bare form that needs an argument (`okb release <version>`) is not optional: show it as one of the alternatives.
|
|
17
|
+
if (bare && (bare.min ?? 0) > 0)
|
|
18
|
+
return `${cmd.name} ${[words.join(" "), ...subs].join("|")}`;
|
|
19
|
+
return `${cmd.name} ${bare ? `[${subs.join("|")}]` : subs.join("|")}`;
|
|
20
|
+
}
|
|
21
|
+
const flags = rows.filter((a) => a[0].startsWith("--"));
|
|
22
|
+
const shown = flags.length > MAX_FLAGS ? ["[options]"] : flags.map((a) => optionUsage(a, bare?.require));
|
|
23
|
+
return [cmd.name, ...words, ...shown].join(" ");
|
|
24
|
+
}
|
|
25
|
+
/** A required option shows its operand without brackets (`--out <folder>`); an optional one stays in brackets. */
|
|
26
|
+
export function optionUsage([name, type], required = []) {
|
|
27
|
+
if (!required.includes(name.replace(/^--/, "")))
|
|
28
|
+
return `[${name}]`;
|
|
29
|
+
return `${name} <${/^[\w-]+$/.test(type) ? type : "value"}>`;
|
|
30
|
+
}
|
|
31
|
+
/** One line per command, grouped by what you are trying to do: its name, its subcommands, and what it does. */
|
|
32
|
+
export function renderHelp(commands) {
|
|
33
|
+
const rows = [];
|
|
34
|
+
for (const cmd of commands) {
|
|
35
|
+
if (cmd.hidden)
|
|
36
|
+
continue;
|
|
37
|
+
rows.push({ group: cmd.group, usage: `okb ${usageOf(cmd)}`, what: cmd.summary ?? summary(cmd.description) });
|
|
38
|
+
}
|
|
39
|
+
const width = Math.max(...rows.filter((r) => r.usage.length <= MAX_USAGE).map((r) => r.usage.length)) + 3;
|
|
40
|
+
const lines = ["okb: build an ontology step by step (Ontology 101 method)"];
|
|
41
|
+
let group = "";
|
|
42
|
+
for (const r of rows) {
|
|
43
|
+
if (r.group !== group) {
|
|
44
|
+
lines.push("", r.group);
|
|
45
|
+
group = r.group;
|
|
46
|
+
}
|
|
47
|
+
lines.push(r.usage.length > MAX_USAGE ? ` ${r.usage}\n ${"".padEnd(width)}${r.what}` : ` ${r.usage.padEnd(width)}${r.what}`);
|
|
48
|
+
}
|
|
49
|
+
lines.push("", "Start with: okb init <folder> --name \"My Ontology\", then okb status and okb step.", "Learn a concept or rule: okb explain <topic>.", "Every command, with examples and options: docs/CLI.md, or https://ontology-kit.dev/reference/cli-reference/", "", "Names: when a class and a slot share a name, say which: class:Genre / slot:genre", "Global options: -C <folder> (default: current folder) · --json (machine-readable output where supported)");
|
|
50
|
+
return lines.join("\n");
|
|
51
|
+
}
|
package/dist/kbdocs.d.ts
ADDED
|
@@ -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[];
|