@ontology-kit/okb 0.1.0 → 0.3.0-alpha.133
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 +102 -0
- package/dist/checks.d.ts +1 -1
- package/dist/checks.js +27 -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 +144 -0
- package/dist/command-table.js +85 -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 +467 -0
- package/dist/commands/planning.d.ts +3 -0
- package/dist/commands/planning.js +251 -0
- package/dist/commands/reviewing.d.ts +3 -0
- package/dist/commands/reviewing.js +234 -0
- package/dist/commands/skills.d.ts +3 -0
- package/dist/commands/skills.js +53 -0
- package/dist/commands.d.ts +10 -22
- package/dist/commands.js +15 -622
- package/dist/cqanswer.d.ts +51 -0
- package/dist/cqanswer.js +76 -0
- package/dist/diff.d.ts +85 -0
- package/dist/diff.js +323 -0
- package/dist/export-changes.d.ts +40 -0
- package/dist/export-changes.js +115 -0
- package/dist/export-csv.d.ts +17 -0
- package/dist/export-csv.js +188 -0
- package/dist/export-eval-cases.d.ts +38 -0
- package/dist/export-eval-cases.js +40 -0
- package/dist/export.d.ts +34 -3
- package/dist/export.js +70 -12
- 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 +2 -2
- package/dist/ops/admin.js +26 -8
- package/dist/ops/classes.d.ts +1 -1
- package/dist/ops/classes.js +15 -7
- package/dist/ops/common.d.ts +12 -2
- package/dist/ops/common.js +3 -0
- package/dist/ops/instances.d.ts +2 -1
- package/dist/ops/instances.js +9 -3
- package/dist/ops/links.d.ts +2 -2
- package/dist/ops/links.js +3 -2
- package/dist/ops/naming.d.ts +1 -1
- package/dist/ops/naming.js +3 -1
- package/dist/ops/scope.d.ts +14 -3
- package/dist/ops/scope.js +38 -4
- package/dist/ops/slots.d.ts +1 -1
- package/dist/ops/slots.js +21 -8
- package/dist/ops/values.d.ts +1 -1
- package/dist/ops/values.js +5 -1
- package/dist/provenance.d.ts +5 -3
- package/dist/provenance.js +61 -19
- package/dist/release.d.ts +52 -0
- package/dist/release.js +337 -0
- package/dist/render.d.ts +88 -1
- package/dist/render.js +265 -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 +84 -0
- package/dist/skills.d.ts +19 -3
- package/dist/skills.js +130 -14
- 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 +19 -0
- package/dist/verifynote.js +93 -0
- package/dist/workflows.d.ts +283 -0
- package/dist/workflows.js +270 -0
- package/meta-kb/data/edges.json +25 -0
- package/meta-kb/data/manifest.json +5 -5
- package/meta-kb/data/nodes.json +46 -9
- package/package.json +9 -4
- package/schema/edge.schema.json +68 -0
- package/schema/edges.schema.json +9 -0
- package/schema/node.schema.json +914 -0
- package/schema/nodes.schema.json +9 -0
- package/schema/okb.schema.json +41 -0
- package/skills/build-domain-kb-from-docs/SKILL.md +21 -3
- package/skills/ontology-coach/SKILL.md +8 -4
- package/skills/ontology-maintainer/SKILL.md +152 -0
- package/skills/ontology-review/SKILL.md +4 -2
- package/skills/ontology-signoff/SKILL.md +182 -0
- package/templates/okb-check.yml +148 -0
- package/templates/pull_request_template.md +16 -0
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ The `okb` command-line tool from [Ontology Kit](https://ontology-kit.dev), a too
|
|
|
4
4
|
|
|
5
5
|
It's for a team that keeps a knowledge base and wants every fact to point back to its source. It's also for someone building their first: the Ontology 101 method (Noy & McGuinness, 2001), the Learn course and the tutorials walk you through it step by step.
|
|
6
6
|
|
|
7
|
-
The package ships the `okb` command, the meta-KB (a knowledge base about building knowledge bases, which holds the method and its rules), and skills that let Claude coach you, review your work, and extract a knowledge base from documents. Other tools can read the file format with the small [`@ontology-kit/
|
|
7
|
+
The package ships the `okb` command, the meta-KB (a knowledge base about building knowledge bases, which holds the method and its rules), and skills that let Claude coach you, review your work, and extract a knowledge base from documents. Other tools can read the file format with the small [`@ontology-kit/reader`](https://www.npmjs.com/package/@ontology-kit/reader) package, which okb itself builds on.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
package/dist/check.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `okb check`: the one answer to "is this KB safe to merge?". It reads the folder and never writes it
|
|
3
|
+
* or takes the lock. Each check is one entry in CHECK_STEPS; to add a check (the ledger check, `okb cq check`),
|
|
4
|
+
* add an entry and, if it handles a rule that `validate` also reports, list the rule in its `rules`.
|
|
5
|
+
*/
|
|
6
|
+
import type { Ontology } from "@ontology-kit/reader";
|
|
7
|
+
import type { Finding } from "./types.js";
|
|
8
|
+
export type StepStatus = "pass" | "warn" | "fail";
|
|
9
|
+
export interface StepResult {
|
|
10
|
+
id: string;
|
|
11
|
+
title: string;
|
|
12
|
+
status: StepStatus;
|
|
13
|
+
/** One line saying what was found, for the summary. */
|
|
14
|
+
summary: string;
|
|
15
|
+
/** What a reviewer should look at, one entry per problem. */
|
|
16
|
+
problems: string[];
|
|
17
|
+
}
|
|
18
|
+
export interface CheckInput {
|
|
19
|
+
ont: Ontology;
|
|
20
|
+
/** The report of `validate --all` (nothing hidden). */
|
|
21
|
+
findings: Finding[];
|
|
22
|
+
/** The okb version running this check. */
|
|
23
|
+
installed: string;
|
|
24
|
+
}
|
|
25
|
+
export interface CheckStep {
|
|
26
|
+
id: string;
|
|
27
|
+
title: string;
|
|
28
|
+
/** Rules this step reports. `validation` leaves them out so a problem shows once. */
|
|
29
|
+
rules?: string[];
|
|
30
|
+
run(input: CheckInput): Omit<StepResult, "id" | "title">;
|
|
31
|
+
}
|
|
32
|
+
/** Compare `a.b.c[-pre]` versions (a leading `v` and `+build` are ignored): negative when `a` is older than `b`. Null for text that isn't a version. */
|
|
33
|
+
export declare function compareVersions(a: string, b: string): number | null;
|
|
34
|
+
/** The checks, in the order they're reported. */
|
|
35
|
+
export declare const CHECK_STEPS: CheckStep[];
|
|
36
|
+
export interface CheckReport {
|
|
37
|
+
ok: boolean;
|
|
38
|
+
installed: string;
|
|
39
|
+
pinned: string | null;
|
|
40
|
+
steps: StepResult[];
|
|
41
|
+
}
|
|
42
|
+
/** Run every check. Reads the folder and its source files; writes nothing. */
|
|
43
|
+
export declare function runCheck(ont: Ontology, installed: string): Promise<CheckReport>;
|
package/dist/check.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { loadSourcePages, runChecks } from "./checks.js";
|
|
2
|
+
import { checkQuestions, describeResult } from "./cqanswer.js";
|
|
3
|
+
import { compareVersions as compareSemver } from "./release.js";
|
|
4
|
+
const open = (fs) => fs.filter((f) => !f.explainedBy);
|
|
5
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
6
|
+
/** Compare `a.b.c[-pre]` versions (a leading `v` and `+build` are ignored): negative when `a` is older than `b`. Null for text that isn't a version. */
|
|
7
|
+
export function compareVersions(a, b) {
|
|
8
|
+
const core = (v) => /^v?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)(?:\+.*)?$/.exec(v.trim())?.[1];
|
|
9
|
+
const x = core(a), y = core(b);
|
|
10
|
+
return x && y ? compareSemver(x, y) : null;
|
|
11
|
+
}
|
|
12
|
+
const SAVE_LEFTOVERS_RULE = "struct-no-save-leftovers";
|
|
13
|
+
const QUOTE_RULES = ["prov-quote-current"];
|
|
14
|
+
const VERIFY_RULES = ["prov-verified", "prov-cites-quote"];
|
|
15
|
+
/** The checks, in the order they're reported. */
|
|
16
|
+
export const CHECK_STEPS = [
|
|
17
|
+
{
|
|
18
|
+
id: "validate",
|
|
19
|
+
title: "Validation (okb validate --all)",
|
|
20
|
+
run({ findings }) {
|
|
21
|
+
const claimed = new Set(CHECK_STEPS.flatMap((s) => s.rules ?? []));
|
|
22
|
+
const mine = open(findings).filter((f) => !claimed.has(f.rule));
|
|
23
|
+
const errors = mine.filter((f) => f.severity === "error");
|
|
24
|
+
const warnings = mine.filter((f) => f.severity === "warning").length;
|
|
25
|
+
const tail = warnings ? ` (${plural(warnings, "warning")} ${warnings === 1 ? "doesn't" : "don't"} block a merge; okb validate --all lists them)` : "";
|
|
26
|
+
// Leftovers of an interrupted save say the files may not belong together, which the other warnings don't, so show them here.
|
|
27
|
+
const torn = mine.filter((f) => f.rule === SAVE_LEFTOVERS_RULE);
|
|
28
|
+
return errors.length
|
|
29
|
+
? { status: "fail", summary: `${plural(errors.length, "error")}${tail}`, problems: [...errors, ...torn].map((f) => `${f.rule}: ${f.message}`) }
|
|
30
|
+
: torn.length
|
|
31
|
+
? { status: "warn", summary: `no errors, but a save was cut short${tail}`, problems: torn.map((f) => `${f.rule}: ${f.message}`) }
|
|
32
|
+
: { status: "pass", summary: `no errors${tail}`, problems: [] };
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: "quotes",
|
|
37
|
+
title: "Quotes are still in their sources",
|
|
38
|
+
rules: QUOTE_RULES,
|
|
39
|
+
run({ ont, findings }) {
|
|
40
|
+
// A quote that can't be checked fails too: in CI a missing source file means the check proved nothing.
|
|
41
|
+
// A quote that only moved is still in its source (the validator reports it at info level), so it doesn't fail.
|
|
42
|
+
const found = open(findings).filter((f) => QUOTE_RULES.includes(f.rule));
|
|
43
|
+
const bad = found.filter((f) => f.severity !== "info");
|
|
44
|
+
const moved = found.length - bad.length;
|
|
45
|
+
const unchecked = ont.ofType("Source").filter((s) => !s.localPath && ont.sources(s.id, "PART_OF").some((i) => ont.get(i)?.type === "SourceLocation")).length;
|
|
46
|
+
const notes = [
|
|
47
|
+
unchecked ? `${plural(unchecked, "source")} with quotes has no localPath, so its quotes weren't checked` : "",
|
|
48
|
+
moved ? `${plural(moved, "quote")} moved; okb source refresh --all updates them` : "",
|
|
49
|
+
].filter(Boolean);
|
|
50
|
+
const note = notes.length ? ` (${notes.join("; ")})` : "";
|
|
51
|
+
return bad.length
|
|
52
|
+
? { status: "fail", summary: `${plural(bad.length, "quote")} can't be matched${note}`, problems: bad.map((f) => f.message) }
|
|
53
|
+
: { status: unchecked ? "warn" : "pass", summary: `every checked quote is still in its source${note}`, problems: [] };
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: "verification",
|
|
58
|
+
title: "Rules and extracted facts are verified",
|
|
59
|
+
rules: VERIFY_RULES,
|
|
60
|
+
run({ findings }) {
|
|
61
|
+
const bad = open(findings).filter((f) => VERIFY_RULES.includes(f.rule));
|
|
62
|
+
return bad.length
|
|
63
|
+
? { status: "fail", summary: `${plural(bad.length, "problem")}: something unverified, not supported by its quote, or without a quote`, problems: bad.map((f) => f.message) }
|
|
64
|
+
: { status: "pass", summary: "nothing is unverified, unsupported or waiting for approval", problems: [] };
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
id: "competency-questions",
|
|
69
|
+
title: "Competency questions are still answered (okb cq check)",
|
|
70
|
+
run({ ont }) {
|
|
71
|
+
const results = checkQuestions(ont);
|
|
72
|
+
const failed = results.filter((r) => r.status === "fail");
|
|
73
|
+
const none = results.filter((r) => r.status === "none").length;
|
|
74
|
+
const tail = none ? ` (${plural(none, "question")} with no answer stored)` : "";
|
|
75
|
+
return failed.length
|
|
76
|
+
? { status: "fail", summary: `${plural(failed.length, "question")} no longer get the expected answer${tail}`, problems: failed.map(describeResult) }
|
|
77
|
+
: { status: "pass", summary: `${results.length - none} of ${plural(results.length, "question")} get the expected answer${tail}`, problems: [] };
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: "okb-version",
|
|
82
|
+
title: "okb version",
|
|
83
|
+
run({ ont, installed }) {
|
|
84
|
+
const pinned = ont.manifest.okbVersion;
|
|
85
|
+
if (!pinned)
|
|
86
|
+
return { status: "pass", summary: `installed ${installed}; the KB pins no version (okbVersion in okb.json)`, problems: [] };
|
|
87
|
+
const cmp = compareVersions(installed, pinned);
|
|
88
|
+
if (cmp === null)
|
|
89
|
+
return { status: "warn", summary: `okbVersion '${pinned}' in okb.json isn't a version like 1.2.3`, problems: [] };
|
|
90
|
+
return cmp < 0
|
|
91
|
+
? { status: "warn", summary: `installed ${installed} is older than the ${pinned} this KB pins; install ${pinned} or newer (npm i -g @ontology-kit/okb@${pinned})`, problems: [] }
|
|
92
|
+
: { status: "pass", summary: `installed ${installed}, pinned ${pinned}`, problems: [] };
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
/** Run every check. Reads the folder and its source files; writes nothing. */
|
|
97
|
+
export async function runCheck(ont, installed) {
|
|
98
|
+
const ctx = { pages: await loadSourcePages(ont) };
|
|
99
|
+
const { findings } = runChecks(ont, { all: true }, ctx);
|
|
100
|
+
const steps = CHECK_STEPS.map((s) => ({ id: s.id, title: s.title, ...s.run({ ont, findings, installed }) }));
|
|
101
|
+
return { ok: steps.every((s) => s.status !== "fail"), installed, pinned: ont.manifest.okbVersion ?? null, steps };
|
|
102
|
+
}
|
package/dist/checks.d.ts
CHANGED
package/dist/checks.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { existsSync } from "node:fs";
|
|
11
11
|
import { isAbsolute, join } from "node:path";
|
|
12
12
|
import { MetaKB } from "./metakb.js";
|
|
13
|
-
import { Ontology, VALUE_TYPES, DISPOSITIONS } from "@ontology-kit/
|
|
13
|
+
import { Ontology, VALUE_TYPES, DISPOSITIONS } from "@ontology-kit/reader";
|
|
14
14
|
import { isOneOf } from "./types.js";
|
|
15
15
|
import * as naming from "./naming.js";
|
|
16
16
|
import { findQuote, loadPages, normalize } from "./quotes.js";
|
|
@@ -68,8 +68,27 @@ const pipeline = (n) => n;
|
|
|
68
68
|
function isTerminological(ont, c) {
|
|
69
69
|
return Boolean(c.terminological) || ont.meta.kind === "terminological";
|
|
70
70
|
}
|
|
71
|
+
/** The files a save leaves behind when it is cut short (see decision 0033). */
|
|
72
|
+
const SAVE_LEFTOVERS = [".okb.saving.tmp", "okb.json.tmp", "nodes.jsonl.tmp", "edges.jsonl.tmp"];
|
|
71
73
|
export const CHECKS = {
|
|
72
74
|
// Structure
|
|
75
|
+
// Reads the folder, not the graph. A load finishes a marked save, so this sees a marker only when a save began after
|
|
76
|
+
// the load (a command running now, which finishes it) and temp files with no marker (an older okb's save, or a
|
|
77
|
+
// save killed before its marker). An in-memory ontology has no okb.json on disk, so it has no leftovers.
|
|
78
|
+
"struct-no-save-leftovers": (ont) => {
|
|
79
|
+
if (!existsSync(join(ont.root, "okb.json")))
|
|
80
|
+
return [];
|
|
81
|
+
const found = SAVE_LEFTOVERS.filter((f) => existsSync(join(ont.root, f)));
|
|
82
|
+
if (!found.length)
|
|
83
|
+
return [];
|
|
84
|
+
const marked = found.includes(".okb.saving.tmp");
|
|
85
|
+
return [{
|
|
86
|
+
message: marked
|
|
87
|
+
? `A save of ${ont.root} didn't finish: ${found.join(", ")} ${found.length > 1 ? "are" : "is"} left over. If no okb command is running, run any okb command that changes this folder; it finishes the save.`
|
|
88
|
+
: `${found.join(", ")} ${found.length > 1 ? "are" : "is"} left over from a save that was cut short, so a file of this ontology may be older than the others. Compare ${found.length > 1 ? "each with the file it names" : "it with the file it names"} (git diff shows the real one), restore the folder from git or a backup if they differ, then delete the leftover${found.length > 1 ? "s" : ""}. If a command is running now, wait for it.`,
|
|
89
|
+
nodes: [],
|
|
90
|
+
}];
|
|
91
|
+
},
|
|
73
92
|
"struct-well-formed": (ont) => {
|
|
74
93
|
const hits = [];
|
|
75
94
|
const { nodeTypes, edgeTypes } = MetaKB.get().formatRegistry();
|
|
@@ -80,7 +99,7 @@ export const CHECKS = {
|
|
|
80
99
|
continue;
|
|
81
100
|
}
|
|
82
101
|
if (seen.has(n.id))
|
|
83
|
-
hits.push({ message: `Two nodes share the id '${n.id}'.`, nodes: [n.id] });
|
|
102
|
+
hits.push({ message: `Two nodes share the id '${n.id}'. A git merge that kept both sides' version of a node is the likely cause; keep one and delete the other.`, nodes: [n.id] });
|
|
84
103
|
seen.add(n.id);
|
|
85
104
|
const nt = nodeTypes.get(n.type);
|
|
86
105
|
if (!nt) {
|
|
@@ -113,7 +132,7 @@ export const CHECKS = {
|
|
|
113
132
|
const a = ont.get(e.from);
|
|
114
133
|
const b = ont.get(e.to);
|
|
115
134
|
if (!a || !b)
|
|
116
|
-
hits.push({ message: `Edge ${tag} points at a node that doesn't exist (${!a ? e.from : e.to}).`, nodes: [a ? e.from : e.to] });
|
|
135
|
+
hits.push({ message: `Edge ${tag} points at a node that doesn't exist (${!a ? e.from : e.to}). A git merge where one branch deleted the node and another added this edge is the likely cause; remove the edge or restore the node.`, nodes: [a ? e.from : e.to] });
|
|
117
136
|
else if (!["Instance", "Class"].includes(a.type) || !["Instance", "Class"].includes(b.type) || (a.type === "Instance" && b.type === "Class")) {
|
|
118
137
|
hits.push({ message: `Relationship ${tag} connects ${a.type} → ${b.type}; relationships link instances (or state a fixed value on a class).`, nodes: [e.from, e.to] });
|
|
119
138
|
}
|
|
@@ -125,7 +144,7 @@ export const CHECKS = {
|
|
|
125
144
|
const a = ont.get(e.from);
|
|
126
145
|
const b = ont.get(e.to);
|
|
127
146
|
if (!a || !b) {
|
|
128
|
-
hits.push({ message: `Edge ${tag} points at a node that doesn't exist (${!a ? e.from : e.to}).`, nodes: [a ? e.from : e.to] });
|
|
147
|
+
hits.push({ message: `Edge ${tag} points at a node that doesn't exist (${!a ? e.from : e.to}). A git merge where one branch deleted the node and another added this edge is the likely cause; remove the edge or restore the node.`, nodes: [a ? e.from : e.to] });
|
|
129
148
|
continue;
|
|
130
149
|
}
|
|
131
150
|
// Instance misuse in the hierarchy gets its own friendlier rule (inst-are-leaves).
|
|
@@ -730,6 +749,10 @@ export const CHECKS = {
|
|
|
730
749
|
const loose = ont.ofType("CompetencyQuestion").filter((q) => ont.targets(q.id, "NEEDS").length === 0);
|
|
731
750
|
return loose.map((q) => ({ message: `Competency question ${q.id} ("${q.text}") isn't linked to anything that answers it.`, nodes: [q.id] }));
|
|
732
751
|
},
|
|
752
|
+
"scope-cq-expected-answer": (ont) => {
|
|
753
|
+
const loose = ont.ofType("CompetencyQuestion").filter((q) => !q.answer);
|
|
754
|
+
return loose.map((q) => ({ message: `Competency question ${q.id} ("${q.text}") has no expected answer, so nothing checks that the ontology still answers it.`, nodes: [q.id] }));
|
|
755
|
+
},
|
|
733
756
|
"scope-no-unneeded": (ont) => {
|
|
734
757
|
const needs = ont.edgesOf("NEEDS").map((e) => e.to);
|
|
735
758
|
if (needs.length === 0)
|