@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.
Files changed (97) 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 +11 -705
  7. package/dist/clidocs.d.ts +0 -2
  8. package/dist/clidocs.js +5 -27
  9. package/dist/clock.js +1 -1
  10. package/dist/command-table.d.ts +134 -0
  11. package/dist/command-table.js +82 -0
  12. package/dist/commands/documents.d.ts +3 -0
  13. package/dist/commands/documents.js +250 -0
  14. package/dist/commands/getting-started.d.ts +3 -0
  15. package/dist/commands/getting-started.js +135 -0
  16. package/dist/commands/housekeeping.d.ts +3 -0
  17. package/dist/commands/housekeeping.js +203 -0
  18. package/dist/commands/modeling.d.ts +3 -0
  19. package/dist/commands/modeling.js +433 -0
  20. package/dist/commands/planning.d.ts +3 -0
  21. package/dist/commands/planning.js +212 -0
  22. package/dist/commands/reviewing.d.ts +3 -0
  23. package/dist/commands/reviewing.js +177 -0
  24. package/dist/commands/skills.d.ts +3 -0
  25. package/dist/commands/skills.js +52 -0
  26. package/dist/commands.d.ts +10 -22
  27. package/dist/commands.js +15 -622
  28. package/dist/diff.d.ts +85 -0
  29. package/dist/diff.js +323 -0
  30. package/dist/export.d.ts +1 -1
  31. package/dist/export.js +1 -1
  32. package/dist/families.d.ts +1 -1
  33. package/dist/families.js +1 -1
  34. package/dist/help.d.ts +11 -2
  35. package/dist/help.js +51 -57
  36. package/dist/kbdocs.d.ts +18 -0
  37. package/dist/kbdocs.js +393 -0
  38. package/dist/metakb.d.ts +1 -1
  39. package/dist/metakb.js +1 -1
  40. package/dist/naming.d.ts +2 -2
  41. package/dist/naming.js +2 -2
  42. package/dist/ontology-ref.d.ts +20 -0
  43. package/dist/ontology-ref.js +108 -0
  44. package/dist/ops/admin.d.ts +1 -1
  45. package/dist/ops/admin.js +24 -7
  46. package/dist/ops/classes.d.ts +1 -1
  47. package/dist/ops/classes.js +13 -5
  48. package/dist/ops/instances.d.ts +2 -1
  49. package/dist/ops/instances.js +7 -1
  50. package/dist/ops/links.d.ts +1 -1
  51. package/dist/ops/links.js +1 -1
  52. package/dist/ops/naming.d.ts +1 -1
  53. package/dist/ops/naming.js +3 -1
  54. package/dist/ops/scope.d.ts +5 -1
  55. package/dist/ops/scope.js +19 -1
  56. package/dist/ops/slots.d.ts +1 -1
  57. package/dist/ops/slots.js +15 -2
  58. package/dist/ops/values.d.ts +1 -1
  59. package/dist/ops/values.js +5 -1
  60. package/dist/provenance.d.ts +4 -2
  61. package/dist/provenance.js +58 -17
  62. package/dist/release.d.ts +52 -0
  63. package/dist/release.js +337 -0
  64. package/dist/render.d.ts +64 -1
  65. package/dist/render.js +240 -3
  66. package/dist/resync.d.ts +98 -0
  67. package/dist/resync.js +234 -0
  68. package/dist/review.d.ts +1 -1
  69. package/dist/review.js +1 -1
  70. package/dist/reviewdocs.d.ts +42 -0
  71. package/dist/reviewdocs.js +263 -0
  72. package/dist/runner.d.ts +3 -0
  73. package/dist/runner.js +79 -0
  74. package/dist/skills.js +1 -1
  75. package/dist/status.d.ts +1 -1
  76. package/dist/status.js +1 -1
  77. package/dist/types.d.ts +1 -1
  78. package/dist/types.js +1 -1
  79. package/dist/verifynote.d.ts +18 -0
  80. package/dist/verifynote.js +92 -0
  81. package/dist/workflows.d.ts +256 -0
  82. package/dist/workflows.js +223 -0
  83. package/meta-kb/data/manifest.json +2 -2
  84. package/meta-kb/data/nodes.json +8 -8
  85. package/package.json +9 -4
  86. package/schema/edge.schema.json +68 -0
  87. package/schema/edges.schema.json +9 -0
  88. package/schema/node.schema.json +893 -0
  89. package/schema/nodes.schema.json +9 -0
  90. package/schema/okb.schema.json +41 -0
  91. package/skills/build-domain-kb-from-docs/SKILL.md +20 -2
  92. package/skills/ontology-coach/SKILL.md +6 -2
  93. package/skills/ontology-maintainer/SKILL.md +152 -0
  94. package/skills/ontology-review/SKILL.md +3 -1
  95. package/skills/ontology-signoff/SKILL.md +182 -0
  96. package/templates/okb-check.yml +132 -0
  97. package/templates/pull_request_template.md +16 -0
@@ -0,0 +1,256 @@
1
+ import { Ontology, type OkbNode } from "@ontology-kit/reader";
2
+ import { type Explainable } from "./metakb.js";
3
+ import { type ResyncReport } from "./resync.js";
4
+ import type { ReviewItem } from "./review.js";
5
+ /** `okb init`: create the folder and stamp the meta-KB version. */
6
+ export declare function initOntology(folder: string, name: string): {
7
+ ont: Ontology;
8
+ guide: string;
9
+ };
10
+ /** `okb show`: the node and the edges on both sides of it. */
11
+ export declare function showData(ont: Ontology, n: OkbNode): {
12
+ node: OkbNode;
13
+ out: import("@ontology-kit/reader").GraphEdge[];
14
+ in: import("@ontology-kit/reader").GraphEdge[];
15
+ };
16
+ /** `okb validate`: run the checks and say whether the command should fail. */
17
+ export declare function validate(ont: Ontology, o: {
18
+ all?: boolean;
19
+ rule?: string[];
20
+ strict?: boolean;
21
+ }): Promise<{
22
+ findings: import("./types.js").Finding[];
23
+ hiddenLater: number;
24
+ fail: boolean;
25
+ data: {
26
+ step: number;
27
+ metaKbVersion: string;
28
+ hiddenLater: number;
29
+ findings: import("./types.js").Finding[];
30
+ };
31
+ }>;
32
+ /** `okb status`: every finding (not just this step's) and the step progress. */
33
+ export declare function status(ont: Ontology): Promise<{
34
+ findings: import("./types.js").Finding[];
35
+ st: {
36
+ steps: import("./status.js").StepStatus[];
37
+ suggested: number;
38
+ };
39
+ data: {
40
+ steps: import("./status.js").StepStatus[];
41
+ suggested: number;
42
+ currentStep: number;
43
+ };
44
+ }>;
45
+ /** `okb step <n|next|prev>`: move to the step, saving under the lock. */
46
+ export declare function moveToStep(dir: string, which: string): {
47
+ target: number;
48
+ leaving: import("./status.js").StepStatus;
49
+ };
50
+ /** The step to show a guide for: the folder's, or step 1 when there is no ontology here. */
51
+ export declare function currentStep(dir: string): number;
52
+ /** `okb review --json`: the scope, the judgment prompts, every class and the decisions. */
53
+ export declare function reviewData(ont: Ontology, items: ReviewItem[]): {
54
+ step: number;
55
+ scope: import("@ontology-kit/reader").OntologyNode;
56
+ judgmentRules: ReviewItem[];
57
+ classes: {
58
+ id: string;
59
+ name: string;
60
+ description: string | undefined;
61
+ parents: string[];
62
+ children: string[];
63
+ ownSlots: string[];
64
+ abstract: boolean | undefined;
65
+ terminological: boolean | undefined;
66
+ instances: number;
67
+ }[];
68
+ decisions: import("@ontology-kit/reader").DesignDecisionNode[];
69
+ };
70
+ /** `okb source outline`: the document's blocks and which lines already have a quote. */
71
+ export declare function outline(ont: Ontology, sourceRef: string, o: {
72
+ quotable?: boolean;
73
+ }): {
74
+ src: import("@ontology-kit/reader").SourceNode;
75
+ doc: import("./markdown.js").MdDoc;
76
+ blocks: import("./markdown.js").MdBlock[];
77
+ quoted: Map<number, string[]>;
78
+ data: () => {
79
+ source: string;
80
+ title: string | undefined;
81
+ frontmatter: Record<string, unknown> | null;
82
+ problems: {
83
+ line: number;
84
+ message: string;
85
+ }[];
86
+ blocks: {
87
+ index: number;
88
+ kind: import("./markdown.js").BlockKind;
89
+ headingPath: string[];
90
+ lines: number[];
91
+ quotable: boolean;
92
+ note: string | undefined;
93
+ calloutType: string | undefined;
94
+ row: {
95
+ columns: string[];
96
+ cells: string[];
97
+ key: string;
98
+ } | undefined;
99
+ text: string | undefined;
100
+ alreadyQuoted: string[];
101
+ }[];
102
+ };
103
+ };
104
+ /** `okb source refresh --all`: re-check every quote against its document, and write only when something moved. */
105
+ export declare function refreshAll(dir: string, o: {
106
+ dryRun?: boolean;
107
+ record?: boolean;
108
+ }): Promise<{
109
+ report: ResyncReport;
110
+ write: boolean;
111
+ }>;
112
+ /** `okb drift`: near-duplicate quotes across the ontologies in these folders. */
113
+ export declare function drift(folders: readonly string[]): import("./checks.js").Hit[];
114
+ /** `okb release <version>`: run the checks and cut the release under the lock. */
115
+ export declare function release(dir: string, version: string): Promise<import("./release.js").ReleaseResult>;
116
+ /** `okb pin`: record the installed okb version in okb.json. */
117
+ export declare function pin(dir: string): string;
118
+ /** `okb check`. */
119
+ export declare function check(ont: Ontology): Promise<import("./check.js").CheckReport>;
120
+ /** What `okb docs` wrote, for the message and --json. */
121
+ export interface DocsResult {
122
+ files: string[];
123
+ what: string;
124
+ hint: string;
125
+ extra?: object;
126
+ }
127
+ /** `okb docs`: the reference pages, the changed-since-<ref> view, or the rules-in-context page. */
128
+ export declare function docs(dir: string, outDir: string, o: {
129
+ changed?: string;
130
+ hops?: string;
131
+ context?: boolean;
132
+ }): Promise<DocsResult>;
133
+ /** `okb diff <old> [<new>]`: each side a folder or a git ref; with one, the new side is the folder itself. */
134
+ export declare function diff(dir: string, oldRef: string, newRef?: string): import("./diff.js").OntologyDiff;
135
+ /** `okb release verify`: check the folder against its manifest.json (read-only). */
136
+ export declare function releaseVerify(dir: string): import("./release.js").VerifyResult;
137
+ /** `okb export`: the graph, as text. The format follows --out's extension when --format is left out. */
138
+ export declare function exportOntology(ont: Ontology, o: {
139
+ format?: string;
140
+ out?: string;
141
+ schema?: boolean;
142
+ noInherited?: boolean;
143
+ noRules?: boolean;
144
+ includeUnverified?: boolean;
145
+ }): {
146
+ fmt: string;
147
+ graph: import("./export.js").ExportGraph;
148
+ text: string;
149
+ };
150
+ /** `okb instance set`: move to other classes, assign values, change the description, in that order. */
151
+ export declare function setInstance(ont: Ontology, name: string, o: {
152
+ of?: string[];
153
+ desc?: string;
154
+ assignments: string[];
155
+ }): string[];
156
+ /** `okb quote list`: every quote, or the quotes from one source. */
157
+ export declare function quotes(ont: Ontology, sourceRef?: string): {
158
+ locs: import("@ontology-kit/reader").SourceLocationNode[];
159
+ data: () => {
160
+ createdAt?: string;
161
+ updatedAt?: string;
162
+ type: "SourceLocation";
163
+ id: string;
164
+ quote: string;
165
+ locator?: string;
166
+ headingPath?: string[];
167
+ startLine?: number;
168
+ endLine?: number;
169
+ lines?: string;
170
+ blockKind?: string;
171
+ sourceLink?: string;
172
+ pageLink?: string;
173
+ page?: number | string;
174
+ citedBy: string[];
175
+ }[];
176
+ };
177
+ /** `okb explain <topic>`: what matches, with the citations and rationale `--json` adds. */
178
+ export declare function explainData(hits: readonly Explainable[]): ({
179
+ type: "Concept";
180
+ id: string;
181
+ name: string;
182
+ aliases?: string[];
183
+ definition: string;
184
+ plainLanguage: string;
185
+ example?: string;
186
+ inThisToolkit?: string;
187
+ origin: "source" | "operational";
188
+ citations: import("./metakb.js").MetaLocation[];
189
+ rationale: string | undefined;
190
+ } | {
191
+ type: "Decision";
192
+ id: string;
193
+ name: string;
194
+ plainLanguage: string;
195
+ whenYouFaceIt: string;
196
+ tests: import("./metakb.js").DecisionTest[];
197
+ note?: string;
198
+ wine: string;
199
+ citations: import("./metakb.js").MetaLocation[];
200
+ rationale: string | undefined;
201
+ } | {
202
+ type: "Principle";
203
+ id: string;
204
+ name: string;
205
+ statement: string;
206
+ plainLanguage: string;
207
+ citations: import("./metakb.js").MetaLocation[];
208
+ rationale: string | undefined;
209
+ } | {
210
+ type: "Rule";
211
+ id: string;
212
+ key: string;
213
+ modality: import("@ontology-kit/reader").Modality;
214
+ basis: "direct" | "interpretive" | "operational";
215
+ check: "mechanical" | "heuristic" | "judgment";
216
+ severity: import("./types.js").Severity;
217
+ severityReason?: string;
218
+ fromStep: number;
219
+ statement: string;
220
+ plainLanguage: string;
221
+ review?: string;
222
+ fix: string;
223
+ citations: import("./metakb.js").MetaLocation[];
224
+ rationale: string | undefined;
225
+ } | {
226
+ type: "Step";
227
+ id: string;
228
+ order: number;
229
+ name: string;
230
+ goal: string;
231
+ whyItMatters: string;
232
+ guidingQuestions: string[];
233
+ outputs: string[];
234
+ doneWhen: import("./metakb.js").DoneWhen[];
235
+ tips: string[];
236
+ wine: string;
237
+ commands: string[];
238
+ citations: import("./metakb.js").MetaLocation[];
239
+ rationale: string | undefined;
240
+ })[];
241
+ /** `okb version`. */
242
+ export declare const versionLine: () => string;
243
+ /** `okb skills install` and `okb skills status`, for the packaged skills and this meta-KB version. */
244
+ export declare function skillsInstallReport(o: {
245
+ dir?: string;
246
+ copy?: boolean;
247
+ force?: boolean;
248
+ }): import("./skills.js").InstallResult;
249
+ export declare function skillsStatusReport(o: {
250
+ dir?: string;
251
+ }): {
252
+ dir: string;
253
+ skills: import("./skills.js").SkillReport[];
254
+ metaVersion: string;
255
+ allCurrent: boolean;
256
+ };
@@ -0,0 +1,223 @@
1
+ /**
2
+ * The multi-step work behind a few commands, kept out of their records so `run` stays a few lines:
3
+ * the data an output shows (`--json`), and the steps that load, compute and write more than one thing.
4
+ * Nothing here prints; `render.ts` does.
5
+ */
6
+ import { resolve } from "node:path";
7
+ import { OkbError, Ontology } from "@ontology-kit/reader";
8
+ import { duplicateQuotes, loadSourcePages, runChecks } from "./checks.js";
9
+ import { MetaKB } from "./metakb.js";
10
+ import { exportGraph, toCypher } from "./export.js";
11
+ import { diffOntologies } from "./diff.js";
12
+ import { installSkills, skillsStatus } from "./skills.js";
13
+ import * as ops from "./ops.js";
14
+ import * as prov from "./provenance.js";
15
+ import { computeStatus } from "./status.js";
16
+ import { kbDocs, writeChangedPages, writeKbDocs, writePages } from "./kbdocs.js";
17
+ import { changedPageSet, changesPage, contextPage } from "./reviewdocs.js";
18
+ import { loadSide } from "./ontology-ref.js";
19
+ import { resync } from "./resync.js";
20
+ import { runCheck } from "./check.js";
21
+ import { cutRelease, verifyRelease } from "./release.js";
22
+ import { PACKAGE_VERSION } from "./version.js";
23
+ import { stepGuide } from "./render.js";
24
+ /** `okb init`: create the folder and stamp the meta-KB version. */
25
+ export function initOntology(folder, name) {
26
+ const ont = ops.createOntology(folder, name);
27
+ ont.manifest.metaKbVersion = MetaKB.get().version;
28
+ ont.save();
29
+ return { ont, guide: stepGuide(MetaKB.get().step(1)) };
30
+ }
31
+ /** `okb show`: the node and the edges on both sides of it. */
32
+ export function showData(ont, n) {
33
+ return { node: n, out: ont.edges.filter((e) => e.from === n.id), in: ont.edges.filter((e) => e.to === n.id) };
34
+ }
35
+ /** `okb validate`: run the checks and say whether the command should fail. */
36
+ export async function validate(ont, o) {
37
+ const { findings, hiddenLater } = runChecks(ont, { all: o.all, only: o.rule }, { pages: await loadSourcePages(ont) });
38
+ const open = findings.filter((f) => !f.explainedBy);
39
+ const fail = open.some((f) => f.severity === "error") || (!!o.strict && open.some((f) => f.severity === "warning"));
40
+ return { findings, hiddenLater, fail, data: { step: ont.step, metaKbVersion: MetaKB.get().version, hiddenLater, findings } };
41
+ }
42
+ /** `okb status`: every finding (not just this step's) and the step progress. */
43
+ export async function status(ont) {
44
+ const { findings } = runChecks(ont, { all: true }, { pages: await loadSourcePages(ont) });
45
+ const st = computeStatus(ont, findings);
46
+ return { findings, st, data: { currentStep: ont.step, ...st } };
47
+ }
48
+ /** `okb step <n|next|prev>`: move to the step, saving under the lock. */
49
+ export function moveToStep(dir, which) {
50
+ const meta = MetaKB.get();
51
+ return Ontology.edit(dir, (ont) => {
52
+ const target = which === "next" ? ont.step + 1 : which === "prev" ? ont.step - 1 : Number(which);
53
+ if (!meta.step(target))
54
+ throw new OkbError(`There is no step ${which}. Steps are 1–${meta.steps.length}.`);
55
+ const leaving = computeStatus(ont).steps.find((s) => s.order === ont.step);
56
+ ont.manifest.currentStep = target;
57
+ ont.save();
58
+ return { target, leaving };
59
+ });
60
+ }
61
+ /** The step to show a guide for: the folder's, or step 1 when there is no ontology here. */
62
+ export function currentStep(dir) {
63
+ try {
64
+ return Ontology.load(dir).step;
65
+ }
66
+ catch {
67
+ return 1;
68
+ }
69
+ }
70
+ /** `okb review --json`: the scope, the judgment prompts, every class and the decisions. */
71
+ export function reviewData(ont, items) {
72
+ const classes = ont.ofType("Class").map((cl) => ({
73
+ id: cl.id, name: cl.name, description: cl.description, parents: ont.parents(cl.id).map((x) => ont.label(x)),
74
+ children: ont.children(cl.id).map((x) => ont.label(x)), ownSlots: ont.ownSlots(cl.id).map((s) => ont.label(s)),
75
+ abstract: cl.abstract, terminological: cl.terminological, instances: ont.sources(cl.id, "INSTANCE_OF").length,
76
+ }));
77
+ return { step: ont.step, scope: ont.meta, judgmentRules: items, classes, decisions: ont.ofType("DesignDecision") };
78
+ }
79
+ /** `okb source outline`: the document's blocks and which lines already have a quote. */
80
+ export function outline(ont, sourceRef, o) {
81
+ const src = ont.find(sourceRef, "Source");
82
+ if (src.format !== "markdown")
83
+ throw new OkbError("outline works on markdown sources.");
84
+ const doc = prov.readMarkdownSource(ont, src);
85
+ const quoted = new Map();
86
+ for (const id of ont.sources(src.id, "PART_OF")) {
87
+ const l = ont.get(id);
88
+ if (l?.type !== "SourceLocation" || l.startLine === undefined)
89
+ continue;
90
+ const { startLine, endLine } = l;
91
+ for (let n = startLine; n <= (endLine ?? startLine); n++)
92
+ quoted.set(n, [...(quoted.get(n) ?? []), id]);
93
+ }
94
+ const blocks = doc.blocks.filter((b) => !o.quotable || b.quotable);
95
+ const data = () => ({
96
+ source: src.id, title: doc.title, frontmatter: doc.frontmatter, problems: doc.problems,
97
+ blocks: blocks.map((b) => ({ index: b.index, kind: b.kind, headingPath: b.headingPath, lines: [b.startLine, b.endLine], quotable: b.quotable, note: b.note, calloutType: b.calloutType, row: b.row, text: b.kind === "code" ? undefined : b.text, alreadyQuoted: [...new Set(Array.from({ length: b.endLine - b.startLine + 1 }, (_, k) => quoted.get(b.startLine + k) ?? []).flat())] })),
98
+ });
99
+ return { src, doc, blocks, quoted, data };
100
+ }
101
+ /** `okb source refresh --all`: re-check every quote against its document, and write only when something moved. */
102
+ export async function refreshAll(dir, o) {
103
+ const ont = Ontology.load(dir);
104
+ const pages = await loadSourcePages(ont);
105
+ const w = { write: !o.dryRun, record: !!o.record && !o.dryRun };
106
+ let report = resync(ont, pages, { write: false, record: false });
107
+ // Take the lock only when something has to be written.
108
+ if (w.write && (report.moved.length || w.record)) {
109
+ report = Ontology.edit(dir, (locked) => {
110
+ const r = locked.tick(() => resync(locked, pages, w));
111
+ locked.save();
112
+ return r;
113
+ });
114
+ }
115
+ return { report, write: w.write };
116
+ }
117
+ /** `okb drift`: near-duplicate quotes across the ontologies in these folders. */
118
+ export function drift(folders) {
119
+ const onts = (folders.length ? folders : ["."]).map((d) => Ontology.load(d));
120
+ const merged = Ontology.fromData(onts.flatMap((o) => o.nodes.filter((n) => n.type !== "Ontology")), onts.flatMap((o) => o.edges));
121
+ return duplicateQuotes(merged);
122
+ }
123
+ /** `okb release <version>`: run the checks and cut the release under the lock. */
124
+ export function release(dir, version) {
125
+ return Ontology.edit(dir, async (ont) => {
126
+ const findings = runChecks(ont, { all: false }, { pages: await loadSourcePages(ont) }).findings;
127
+ return cutRelease(ont, version, findings);
128
+ });
129
+ }
130
+ /** `okb pin`: record the installed okb version in okb.json. */
131
+ export function pin(dir) {
132
+ Ontology.edit(dir, (ont) => {
133
+ ont.manifest.okbVersion = PACKAGE_VERSION;
134
+ ont.save();
135
+ });
136
+ return PACKAGE_VERSION;
137
+ }
138
+ /** `okb check`. */
139
+ export async function check(ont) {
140
+ return runCheck(ont, PACKAGE_VERSION);
141
+ }
142
+ /** `okb docs`: the reference pages, the changed-since-<ref> view, or the rules-in-context page. */
143
+ export async function docs(dir, outDir, o) {
144
+ const out = resolve(outDir);
145
+ if (o.context && (o.changed !== undefined || o.hops !== undefined))
146
+ throw new OkbError("--context is its own view of every rule; it doesn't combine with --changed or --hops.");
147
+ if (o.hops !== undefined && o.changed === undefined)
148
+ throw new OkbError("--hops adds neighbors to a --changed view; give --changed <ref> too.");
149
+ if (o.context) {
150
+ const ont = Ontology.load(dir);
151
+ return { files: writePages(out, { "rules-in-context.md": contextPage(ont, await loadSourcePages(ont)) }), what: "rules-in-context.md", hint: "" };
152
+ }
153
+ if (o.changed !== undefined) {
154
+ if (o.hops !== undefined && !/^\d+$/.test(o.hops))
155
+ throw new OkbError("--hops needs a whole number (0 or more).");
156
+ const hops = o.hops === undefined ? 0 : Number(o.hops);
157
+ const ont = Ontology.load(dir);
158
+ const old = loadSide(o.changed, dir);
159
+ const { pages, changes } = changedPageSet(kbDocs(old.ont), kbDocs(ont), hops);
160
+ const after = kbDocs(ont);
161
+ const report = resync(ont, await loadSourcePages(ont), { write: false, record: false });
162
+ const files = Object.fromEntries(pages.map((n) => [n, after[n]]));
163
+ files["changes.md"] = changesPage({ against: o.changed, name: ont.meta.name, changes, hops, resync: report });
164
+ const stale = report.gone.length + report.moved.length + report.worklist.length;
165
+ return {
166
+ files: writeChangedPages(out, files),
167
+ what: `${pages.length} changed ${pages.length === 1 ? "page" : "pages"} and changes.md (${stale} source ${stale === 1 ? "change" : "changes"} not yet in the KB)`,
168
+ hint: " (start at changes.md)",
169
+ extra: changes,
170
+ };
171
+ }
172
+ const files = writeKbDocs(Ontology.load(dir), out);
173
+ return { files, what: `${files.length} pages`, hint: " (start at index.md)" };
174
+ }
175
+ /** `okb diff <old> [<new>]`: each side a folder or a git ref; with one, the new side is the folder itself. */
176
+ export function diff(dir, oldRef, newRef) {
177
+ const a = loadSide(oldRef, dir);
178
+ const b = newRef ? loadSide(newRef, dir) : { ont: Ontology.load(dir), name: "working folder" };
179
+ return diffOntologies(a.ont, b.ont, a.name, b.name);
180
+ }
181
+ /** `okb release verify`: check the folder against its manifest.json (read-only). */
182
+ export function releaseVerify(dir) {
183
+ return verifyRelease(resolve(dir));
184
+ }
185
+ /** `okb export`: the graph, as text. The format follows --out's extension when --format is left out. */
186
+ export function exportOntology(ont, o) {
187
+ const fmt = o.format ?? (o.out?.endsWith(".cypher") || o.out?.endsWith(".cql") ? "cypher" : "json");
188
+ if (!["json", "cypher"].includes(fmt))
189
+ throw new OkbError("--format must be json or cypher.");
190
+ const graph = exportGraph(ont, { inherited: !o.noInherited, schema: o.schema, rules: !o.noRules, unverified: o.includeUnverified });
191
+ return { fmt, graph, text: fmt === "cypher" ? toCypher(graph) : JSON.stringify(graph, null, 2) + "\n" };
192
+ }
193
+ /** `okb instance set`: move to other classes, assign values, change the description, in that order. */
194
+ export function setInstance(ont, name, o) {
195
+ const notes = [
196
+ ...(o.of?.length ? ops.setInstanceClasses(ont, name, o.of) : []),
197
+ ...(o.assignments.length ? ops.assign(ont, ont.find(name, "Instance").id, o.assignments) : []),
198
+ ];
199
+ if (o.desc !== undefined)
200
+ notes.push(...ops.setInstanceDescription(ont, name, o.desc));
201
+ return notes;
202
+ }
203
+ /** `okb quote list`: every quote, or the quotes from one source. */
204
+ export function quotes(ont, sourceRef) {
205
+ const locs = ont.ofType("SourceLocation").filter((l) => !sourceRef || ont.targets(l.id, "PART_OF").includes(ont.find(sourceRef, "Source").id));
206
+ return { locs, data: () => locs.map((l) => ({ ...l, citedBy: ont.sources(l.id, "CITES") })) };
207
+ }
208
+ /** `okb explain <topic>`: what matches, with the citations and rationale `--json` adds. */
209
+ export function explainData(hits) {
210
+ const meta = MetaKB.get();
211
+ return hits.map((h) => ({ ...h, citations: meta.citations(h.id), rationale: h.type === "Rule" ? meta.rationale(h) : undefined }));
212
+ }
213
+ /** `okb version`. */
214
+ export const versionLine = () => `okb ${PACKAGE_VERSION} · meta-KB ${MetaKB.get().version}`;
215
+ /** `okb skills install` and `okb skills status`, for the packaged skills and this meta-KB version. */
216
+ export function skillsInstallReport(o) {
217
+ return installSkills({ dir: o.dir, metaVersion: MetaKB.get().version, copy: o.copy, force: o.force });
218
+ }
219
+ export function skillsStatusReport(o) {
220
+ const metaVersion = MetaKB.get().version;
221
+ const { dir, skills } = skillsStatus({ dir: o.dir, metaVersion });
222
+ return { dir, skills, metaVersion, allCurrent: skills.every((s) => s.state === "current") };
223
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "2.4.2",
3
- "formatVersion": "okb-lpg/2",
2
+ "version": "2.6.3",
3
+ "formatVersion": "okb-lpg/3",
4
4
  "nodeCounts": {
5
5
  "MetaKB": 1,
6
6
  "Source": 2,
@@ -2,8 +2,8 @@
2
2
  {
3
3
  "type": "MetaKB",
4
4
  "id": "metakb",
5
- "version": "2.4.2",
6
- "formatVersion": "okb-lpg/2",
5
+ "version": "2.6.3",
6
+ "formatVersion": "okb-lpg/3",
7
7
  "description": "Rules, method and vocabulary for building ontologies, derived from Ontology 101 (Noy & McGuinness 2001) and Gruber (1993)."
8
8
  },
9
9
  {
@@ -1110,7 +1110,7 @@
1110
1110
  "definition": "An ontology together with a set of individual instances of classes. The line between where the ontology ends and the knowledge base begins is a fine one.",
1111
1111
  "plainLanguage": "The ontology is the empty form: which fields exist and what's allowed in them. The knowledge base is the form filled in with real things.",
1112
1112
  "example": "The ontology defines the Wine class and its slots; adding 'Château Morgon Beaujolais' with body=light turns it into a knowledge base.",
1113
- "inThisToolkit": "The same nodes.json/edges.json hold both. Instance nodes are the knowledge-base part.",
1113
+ "inThisToolkit": "The same nodes.jsonl/edges.jsonl hold both. Instance nodes are the knowledge-base part.",
1114
1114
  "origin": "source"
1115
1115
  },
1116
1116
  {
@@ -1437,7 +1437,7 @@
1437
1437
  "definition": "The storage format used by this toolkit: nodes and edges that each carry a type label and a set of key/value properties.",
1438
1438
  "plainLanguage": "Your ontology is saved as two JSON lists, nodes and edges, which is how graph databases like Neo4j and Neptune think. Classes, slots and instances are nodes. Structural links (IS_A, HAS_SLOT...) and relationship values ((wine)-[:MAKER]->(winery)) are edges. `okb export` writes the data the way a graph database expects it: instances as nodes labeled with their classes. It's still just the storage format, so model the meaning first (see principle.knowledge-level).",
1439
1439
  "example": "{\"type\": \"Class\", \"id\": \"c.red-wine\", \"name\": \"RedWine\"} and {\"from\": \"c.red-wine\", \"type\": \"IS_A\", \"to\": \"c.wine\"}",
1440
- "inThisToolkit": "nodes.json and edges.json in your ontology folder. See docs/FORMAT.md.",
1440
+ "inThisToolkit": "nodes.jsonl and edges.jsonl in your ontology folder. See docs/FORMAT.md.",
1441
1441
  "origin": "operational"
1442
1442
  },
1443
1443
  {
@@ -3230,7 +3230,7 @@
3230
3230
  "id",
3231
3231
  "name"
3232
3232
  ],
3233
- "description": "description, synonyms[], abstract, terminological, fixedValues{slotId: value}, defaults{slotId: value}, facetOverrides{slotId: {allowedValues, minCardinality, maxCardinality}}."
3233
+ "description": "description, formerNames[] (earlier names, set by okb rename), synonyms[], abstract, terminological, fixedValues{slotId: value}, defaults{slotId: value}, facetOverrides{slotId: {allowedValues, minCardinality, maxCardinality}}."
3234
3234
  },
3235
3235
  {
3236
3236
  "type": "NodeType",
@@ -3241,7 +3241,7 @@
3241
3241
  "id",
3242
3242
  "name"
3243
3243
  ],
3244
- "description": "description, valueType (String|Integer|Float|Number|Boolean|Enumerated|Instance), allowedValues[], cardinality (single|multiple), minCardinality, maxCardinality, default, relType (Instance slots only: the edge type its values are stored as), appliesToRules (Boolean, property slots only: the slot applies to every Rule)."
3244
+ "description": "description, formerNames[], formerRelTypes[] (edge types before renames), valueType (String|Integer|Float|Number|Boolean|Enumerated|Instance), allowedValues[], cardinality (single|multiple), minCardinality, maxCardinality, default, relType (Instance slots only: the edge type its values are stored as), appliesToRules (Boolean, property slots only: the slot applies to every Rule)."
3245
3245
  },
3246
3246
  {
3247
3247
  "type": "NodeType",
@@ -3252,7 +3252,7 @@
3252
3252
  "id",
3253
3253
  "name"
3254
3254
  ],
3255
- "description": "description, values{slotId: value | [values]} for property (non-Instance) slots. Relationship values are edges."
3255
+ "description": "description, formerNames[], values{slotId: value | [values]} for property (non-Instance) slots. Relationship values are edges."
3256
3256
  },
3257
3257
  {
3258
3258
  "type": "NodeType",
@@ -3275,7 +3275,7 @@
3275
3275
  "id",
3276
3276
  "title"
3277
3277
  ],
3278
- "description": "Provenance: a document content was extracted from (`okb source add`). localPath (checked by okb validate), format (markdown | pdf | text), url (rendered page), repoUrl (GitHub file URL, for line links), meta (markdown frontmatter)."
3278
+ "description": "Provenance: a document content was extracted from (`okb source add`). localPath (checked by okb validate), format (markdown | pdf | text), url (rendered page), repoUrl (GitHub file URL, for line links), meta (markdown frontmatter), blocks[] (hash, kind, headingPath, rowKey, preview of each quotable block the KB last saw, so `okb source refresh --all` can list new and changed blocks)."
3279
3279
  },
3280
3280
  {
3281
3281
  "type": "NodeType",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ontology-kit/okb",
3
- "version": "0.1.0",
3
+ "version": "0.3.0-alpha.210",
4
4
  "license": "MIT",
5
5
  "description": "A toolkit for building knowledge graphs with guardrails: a checked file format, rules from a meta-KB, provenance down to verbatim quotes, and skills that drive it.",
6
6
  "homepage": "https://ontology-kit.dev",
@@ -31,6 +31,8 @@
31
31
  "bin",
32
32
  "dist",
33
33
  "meta-kb/data",
34
+ "schema",
35
+ "templates",
34
36
  "!meta-kb/README.md",
35
37
  "skills",
36
38
  "README.md",
@@ -42,6 +44,7 @@
42
44
  "development": "./src/cli.ts",
43
45
  "default": "./dist/cli.js"
44
46
  },
47
+ "./schema/*": "./schema/*",
45
48
  "./package.json": "./package.json"
46
49
  },
47
50
  "bin": {
@@ -52,13 +55,14 @@
52
55
  },
53
56
  "devDependencies": {
54
57
  "@types/node": "^26.6.6",
55
- "typescript": "^5.9.0"
58
+ "ajv": "^8.20.0",
59
+ "typescript": "^7.0.2"
56
60
  },
57
61
  "optionalDependencies": {
58
62
  "pdfjs-dist": "^6.3.289"
59
63
  },
60
64
  "dependencies": {
61
- "@ontology-kit/format": "0.1.0",
65
+ "@ontology-kit/reader": "0.3.0-alpha.210",
62
66
  "yaml": "^2.8.0"
63
67
  },
64
68
  "scripts": {
@@ -68,7 +72,8 @@
68
72
  "docs": "node src/gendocs.ts",
69
73
  "example": "node examples/build-wine.ts && node examples/build-espresso.ts",
70
74
  "typecheck": "tsc",
75
+ "bench": "node scripts/bench-scale.ts",
71
76
  "test": "node --test --test-concurrency=1 \"tests/*.test.ts\"",
72
- "build": "pnpm --filter @ontology-kit/format run build && rm -rf dist && tsc -p tsconfig.build.json && node ../../scripts/rewrite-dts.ts"
77
+ "build": "pnpm --filter @ontology-kit/reader run build && rm -rf dist && tsc -p tsconfig.build.json && node ../../scripts/rewrite-dts.ts"
73
78
  }
74
79
  }
@@ -0,0 +1,68 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://ontology-kit.dev/schema/okb-lpg-3/edge.schema.json",
4
+ "title": "An okb edge (okb-lpg/3): one line of edges.jsonl",
5
+ "description": "An edge is {from, type, to} plus optional properties. The type is one of the reserved types below or the relType of a relationship slot (UPPER_SNAKE case). Whether the ends exist and have the right node types is checked by `okb validate`.",
6
+ "type": "object",
7
+ "required": [
8
+ "from",
9
+ "type",
10
+ "to"
11
+ ],
12
+ "properties": {
13
+ "from": {
14
+ "type": "string",
15
+ "minLength": 1
16
+ },
17
+ "type": {
18
+ "type": "string",
19
+ "pattern": "^[A-Z0-9][A-Z0-9_]*$",
20
+ "examples": [
21
+ "IS_A",
22
+ "INSTANCE_OF",
23
+ "HAS_SLOT",
24
+ "RANGE",
25
+ "INVERSE_OF",
26
+ "DISJOINT_WITH",
27
+ "NEEDS",
28
+ "BECAME",
29
+ "ABOUT",
30
+ "CITES",
31
+ "PART_OF",
32
+ "GOVERNS",
33
+ "REFINES",
34
+ "FULFILLS"
35
+ ]
36
+ },
37
+ "to": {
38
+ "type": "string",
39
+ "minLength": 1
40
+ },
41
+ "rule": {
42
+ "type": "string",
43
+ "description": "The Rule node whose quote and verification justify this link."
44
+ }
45
+ },
46
+ "allOf": [
47
+ {
48
+ "if": {
49
+ "properties": {
50
+ "type": {
51
+ "const": "REFINES"
52
+ }
53
+ },
54
+ "required": [
55
+ "type"
56
+ ]
57
+ },
58
+ "then": {
59
+ "properties": {
60
+ "adds": {
61
+ "type": "string"
62
+ }
63
+ },
64
+ "required": []
65
+ }
66
+ }
67
+ ]
68
+ }