@ontology-kit/okb 0.2.0 → 0.3.0-alpha.135
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/dist/check.js +21 -2
- package/dist/checks.js +23 -0
- package/dist/cli.js +11 -819
- package/dist/clidocs.d.ts +0 -2
- package/dist/clidocs.js +5 -27
- 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 -716
- package/dist/cqanswer.d.ts +51 -0
- package/dist/cqanswer.js +76 -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 +33 -2
- package/dist/export.js +69 -11
- package/dist/help.d.ts +11 -2
- package/dist/help.js +51 -64
- package/dist/ops/admin.d.ts +1 -1
- package/dist/ops/admin.js +2 -1
- package/dist/ops/classes.js +2 -2
- package/dist/ops/common.d.ts +12 -2
- package/dist/ops/common.js +3 -0
- package/dist/ops/instances.js +2 -2
- package/dist/ops/links.d.ts +1 -1
- package/dist/ops/links.js +2 -1
- package/dist/ops/scope.d.ts +9 -2
- package/dist/ops/scope.js +19 -3
- package/dist/ops/slots.js +6 -6
- package/dist/provenance.d.ts +1 -1
- package/dist/provenance.js +3 -2
- package/dist/release.d.ts +4 -0
- package/dist/release.js +22 -3
- package/dist/render.d.ts +85 -1
- package/dist/render.js +244 -1
- package/dist/runner.d.ts +3 -0
- package/dist/runner.js +84 -0
- package/dist/skills.d.ts +19 -3
- package/dist/skills.js +129 -13
- package/dist/verifynote.d.ts +4 -3
- package/dist/verifynote.js +3 -2
- 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 +4 -4
- package/meta-kb/data/nodes.json +39 -2
- package/package.json +4 -3
- package/schema/node.schema.json +22 -1
- package/skills/build-domain-kb-from-docs/SKILL.md +2 -2
- package/skills/ontology-coach/SKILL.md +3 -3
- package/skills/ontology-maintainer/SKILL.md +2 -2
- package/skills/ontology-review/SKILL.md +2 -2
- package/skills/ontology-signoff/SKILL.md +2 -2
- package/templates/okb-check.yml +17 -1
package/dist/export.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `okb export`: writes the ontology's DATA the way a graph database expects it.
|
|
3
3
|
*
|
|
4
|
+
* It reads the ontology directly, not through the reader's query layer (query.ts, decision 0034): the export needs
|
|
5
|
+
* raw typed values, edge properties and inheritance details (which class a value came from) that the layer's
|
|
6
|
+
* name-based results don't carry.
|
|
7
|
+
*
|
|
4
8
|
* In the okb file, classes are nodes (so the schema itself can be queried and
|
|
5
9
|
* validated). In a graph database you usually want the opposite: each instance is a
|
|
6
10
|
* node labeled with its class and every ancestor class (labels are flat, so
|
|
@@ -254,8 +258,8 @@ function compact(o) {
|
|
|
254
258
|
return Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined && !(Array.isArray(v) && v.length === 0)));
|
|
255
259
|
}
|
|
256
260
|
// Cypher
|
|
257
|
-
const ident = (s) => (/^[A-Za-z_][A-Za-z0-9_]*$/.test(s) ? s : "`" + s.replace(/`/g, "``") + "`");
|
|
258
|
-
function literal(v) {
|
|
261
|
+
export const ident = (s) => (/^[A-Za-z_][A-Za-z0-9_]*$/.test(s) ? s : "`" + s.replace(/`/g, "``") + "`");
|
|
262
|
+
export function literal(v) {
|
|
259
263
|
if (v === null || v === undefined)
|
|
260
264
|
return "null";
|
|
261
265
|
if (Array.isArray(v))
|
|
@@ -266,17 +270,53 @@ function literal(v) {
|
|
|
266
270
|
return String(v);
|
|
267
271
|
return JSON.stringify(JSON.stringify(v));
|
|
268
272
|
}
|
|
269
|
-
function mapLiteral(props) {
|
|
273
|
+
export function mapLiteral(props) {
|
|
270
274
|
return "{" + Object.entries(props).map(([k, v]) => `${ident(k)}: ${literal(v)}`).join(", ") + "}";
|
|
271
275
|
}
|
|
272
|
-
/**
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
276
|
+
/** Rows per UNWIND statement: large enough to amortize each statement, small enough to stay under typical query-size limits. */
|
|
277
|
+
const BATCH = 500;
|
|
278
|
+
/** The label every node gets in the default style, so one uniqueness constraint covers the `okbId` lookups. */
|
|
279
|
+
export const CYPHER_NODE_LABEL = "OkbNode";
|
|
280
|
+
/** The label of the one node per ontology that holds the release a database was loaded at. */
|
|
281
|
+
export const RELEASE_LABEL = "OkbRelease";
|
|
282
|
+
/** openCypher script (Neo4j, Memgraph, Amazon Neptune). The default style is idempotent for what it writes: loading it again gives the same graph with the new values. It sets every property of the nodes and relationships it writes (`SET n = row`), and deletes nothing. */
|
|
283
|
+
export function toCypher(g, opts = {}) {
|
|
284
|
+
return opts.style === "simple" ? simpleCypher(g, opts.release) : batchedCypher(g, opts.release);
|
|
285
|
+
}
|
|
286
|
+
/** Records the loaded release. MERGE keeps one node per ontology, so loading a newer full export moves it forward. */
|
|
287
|
+
export function releaseStatement(r) {
|
|
288
|
+
return `MERGE (r:${RELEASE_LABEL} {ontology: ${literal(r.ontology)}}) SET r.version = ${literal(r.version)};`;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* One `//` comment line. Names, notes and versions come from user data, and a line break in one would end the
|
|
292
|
+
* comment and run the rest as Cypher, so every control character and Unicode line break becomes a space.
|
|
293
|
+
*/
|
|
294
|
+
export const comment = (text) => "// " + text.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]+/g, " ");
|
|
295
|
+
function header(g, line) {
|
|
296
|
+
return [comment(`${g.ontology}: exported by okb (meta-KB ${g.metaKbVersion})`), comment(line), ...g.notes.map(comment), ""];
|
|
297
|
+
}
|
|
298
|
+
function batchedCypher(g, release) {
|
|
299
|
+
const out = header(g, `Every node carries the ${CYPHER_NODE_LABEL} label and okbId, and MERGE matches on them, so you can run this script again without clearing the database. Neptune has no constraints: drop the first statement there.`);
|
|
300
|
+
out.push(`CREATE CONSTRAINT okb_id_unique IF NOT EXISTS FOR (n:${CYPHER_NODE_LABEL}) REQUIRE n.okbId IS UNIQUE;`, "");
|
|
301
|
+
// Labels can't be parameters, so nodes go in one batch series per label set, edges per relationship type.
|
|
302
|
+
const byLabels = groupBy(g.nodes, (n) => n.labels.join("\0"));
|
|
303
|
+
for (const group of byLabels.values()) {
|
|
304
|
+
const labels = group[0].labels.length ? ", n:" + group[0].labels.map(ident).join(":") : "";
|
|
305
|
+
for (const rows of chunks(group)) {
|
|
306
|
+
out.push("UNWIND [", rows.map((n) => " " + mapLiteral(n.properties)).join(",\n"), `] AS row MERGE (n:${CYPHER_NODE_LABEL} {okbId: row.okbId}) SET n = row${labels};`, "");
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
for (const [type, group] of groupBy(g.relationships, (r) => r.type)) {
|
|
310
|
+
for (const rows of chunks(group)) {
|
|
311
|
+
out.push("UNWIND [", rows.map((r) => ` {from: ${literal(r.from)}, to: ${literal(r.to)}, props: ${mapLiteral(r.properties)}}`).join(",\n"), `] AS row MATCH (a:${CYPHER_NODE_LABEL} {okbId: row.from}) MATCH (b:${CYPHER_NODE_LABEL} {okbId: row.to}) MERGE (a)-[r:${ident(type)}]->(b) SET r = row.props;`, "");
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (release)
|
|
315
|
+
out.push(comment(`The release this script loads: \`okb export --since ${release.version}\` change sets check it before they run.`), releaseStatement(release), "");
|
|
316
|
+
return out.join("\n");
|
|
317
|
+
}
|
|
318
|
+
function simpleCypher(g, release) {
|
|
319
|
+
const out = header(g, "Every node carries okbId. To re-import, first run: MATCH (n) WHERE n.okbId IS NOT NULL DETACH DELETE n;");
|
|
280
320
|
for (const n of g.nodes) {
|
|
281
321
|
const labels = n.labels.length ? ":" + n.labels.map(ident).join(":") : "";
|
|
282
322
|
out.push(`CREATE (${labels} ${mapLiteral(n.properties)});`);
|
|
@@ -286,5 +326,23 @@ export function toCypher(g) {
|
|
|
286
326
|
const props = Object.keys(r.properties).length ? " " + mapLiteral(r.properties) : "";
|
|
287
327
|
out.push(`MATCH (a {okbId: ${literal(r.from)}}), (b {okbId: ${literal(r.to)}}) CREATE (a)-[:${ident(r.type)}${props}]->(b);`);
|
|
288
328
|
}
|
|
329
|
+
if (release)
|
|
330
|
+
out.push("", releaseStatement(release));
|
|
289
331
|
return out.join("\n") + "\n";
|
|
290
332
|
}
|
|
333
|
+
export function groupBy(items, key) {
|
|
334
|
+
const m = new Map();
|
|
335
|
+
for (const t of items) {
|
|
336
|
+
const k = key(t);
|
|
337
|
+
const g = m.get(k);
|
|
338
|
+
if (g)
|
|
339
|
+
g.push(t);
|
|
340
|
+
else
|
|
341
|
+
m.set(k, [t]);
|
|
342
|
+
}
|
|
343
|
+
return m;
|
|
344
|
+
}
|
|
345
|
+
export function* chunks(items) {
|
|
346
|
+
for (let i = 0; i < items.length; i += BATCH)
|
|
347
|
+
yield items.slice(i, i + BATCH);
|
|
348
|
+
}
|
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,64 +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
|
-
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
|
|
63
|
-
Names: when a class and a slot share a name, say which: class:Genre / slot:genre
|
|
64
|
-
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/ops/admin.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Ontology, type NodeType } from "@ontology-kit/reader";
|
|
2
|
-
import type
|
|
2
|
+
import { type Notes } from "./common.js";
|
|
3
3
|
/** Start an empty ontology folder: the manifest, the one Ontology node, no edges. Saved before it returns. */
|
|
4
4
|
export declare function createOntology(root: string, name: string): Ontology;
|
|
5
5
|
export declare function addDecision(ont: Ontology, o: {
|
package/dist/ops/admin.js
CHANGED
|
@@ -6,6 +6,7 @@ import { runChecks } from "../checks.js";
|
|
|
6
6
|
import { today } from "../clock.js";
|
|
7
7
|
import { MetaKB } from "../metakb.js";
|
|
8
8
|
import { FORMAT, MANIFEST, OkbError, Ontology, nameOrText } from "@ontology-kit/reader";
|
|
9
|
+
import { tip } from "./common.js";
|
|
9
10
|
import { checkName } from "./naming.js";
|
|
10
11
|
/** Start an empty ontology folder: the manifest, the one Ontology node, no edges. Saved before it returns. */
|
|
11
12
|
export function createOntology(root, name) {
|
|
@@ -50,7 +51,7 @@ export function addDecision(ont, o) {
|
|
|
50
51
|
: `Note: it doesn't match any current finding from ${o.waives.join(", ")}. Check the --about target (a decision about a class also covers its subclasses).`);
|
|
51
52
|
}
|
|
52
53
|
if (!o.rationale)
|
|
53
|
-
notes.push("Tip: add --why so future readers know the reason, not just the choice.");
|
|
54
|
+
notes.push(tip("Tip: add --why so future readers know the reason, not just the choice."));
|
|
54
55
|
return notes;
|
|
55
56
|
}
|
|
56
57
|
export function rename(ont, ref, next, force = false) {
|
package/dist/ops/classes.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** The class hierarchy: adding and changing classes, parents and disjointness. */
|
|
2
2
|
import * as naming from "../naming.js";
|
|
3
3
|
import { OkbError } from "@ontology-kit/reader";
|
|
4
|
-
import { an, splitList as list } from "./common.js";
|
|
4
|
+
import { an, splitList as list, tip } from "./common.js";
|
|
5
5
|
import { checkName } from "./naming.js";
|
|
6
6
|
import { linkTermIfAny } from "./scope.js";
|
|
7
7
|
export function addClass(ont, name, o = {}) {
|
|
@@ -40,7 +40,7 @@ export function addClass(ont, name, o = {}) {
|
|
|
40
40
|
if (asValue)
|
|
41
41
|
notes.push(`Careful: '${name}' is also an allowed value of the slot ${asValue.name}. Model it as a class OR a value, not both (okb explain decision.class-or-value).`);
|
|
42
42
|
if (!o.description)
|
|
43
|
-
notes.push(`Add a one-line description: okb class set "${name}" --desc "..."`);
|
|
43
|
+
notes.push(tip(`Add a one-line description: okb class set "${name}" --desc "..."`));
|
|
44
44
|
linkTermIfAny(ont, name, id, "class");
|
|
45
45
|
return notes;
|
|
46
46
|
}
|
package/dist/ops/common.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
/** Shared by the ops modules. */
|
|
2
|
-
/**
|
|
3
|
-
export
|
|
2
|
+
/** A teaching tip: advice about what to do next, shown dimmed. It carries its own `kind`, so rendering never guesses from the text. */
|
|
3
|
+
export interface Tip {
|
|
4
|
+
kind: "tip";
|
|
5
|
+
text: string;
|
|
6
|
+
}
|
|
7
|
+
/** One line about what an operation did: a plain string (a result or a warning) or a {@link Tip}. */
|
|
8
|
+
export type Note = string | Tip;
|
|
9
|
+
/** What an operation tells the user, including gentle warnings and tips, so beginners learn as they go. */
|
|
10
|
+
export type Notes = Note[];
|
|
11
|
+
export declare const tip: (text: string) => Tip;
|
|
12
|
+
/** The text of a note, for tests and plain output. */
|
|
13
|
+
export declare const noteText: (n: Note) => string;
|
|
4
14
|
export { an } from "../naming.js";
|
|
5
15
|
/** Command-line list values: repeated flags and/or comma-separated ("a,b" "c" -> [a, b, c]). */
|
|
6
16
|
export declare const splitList: (s: string | string[] | undefined) => string[];
|
package/dist/ops/common.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
/** Shared by the ops modules. */
|
|
2
|
+
export const tip = (text) => ({ kind: "tip", text });
|
|
3
|
+
/** The text of a note, for tests and plain output. */
|
|
4
|
+
export const noteText = (n) => (typeof n === "string" ? n : n.text);
|
|
2
5
|
export { an } from "../naming.js";
|
|
3
6
|
/** Command-line list values: repeated flags and/or comma-separated ("a,b" "c" -> [a, b, c]). */
|
|
4
7
|
export const splitList = (s) => (Array.isArray(s) ? s : s ? [s] : []).flatMap((x) => x.split(",")).map((x) => x.trim()).filter(Boolean);
|
package/dist/ops/instances.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Instances and the classes they belong to. */
|
|
2
2
|
import * as naming from "../naming.js";
|
|
3
3
|
import { OkbError, literalValues } from "@ontology-kit/reader";
|
|
4
|
-
import { an } from "./common.js";
|
|
4
|
+
import { an, tip } from "./common.js";
|
|
5
5
|
import { assign } from "./values.js";
|
|
6
6
|
import { checkParents } from "./classes.js";
|
|
7
7
|
export function addInstance(ont, name, o) {
|
|
@@ -16,7 +16,7 @@ export function addInstance(ont, name, o) {
|
|
|
16
16
|
if (cl.abstract)
|
|
17
17
|
throw new OkbError(`${cl.name} is abstract, so it can't have direct instances. Pick one of its subclasses: ${ont.children(cl.id).map((k) => ont.label(k)).join(", ")}.`);
|
|
18
18
|
if (ont.children(cl.id).length)
|
|
19
|
-
notes.push(`Tip: ${cl.name} has subclasses (${ont.children(cl.id).map((k) => ont.label(k)).join(", ")}). Use the most specific class that fits.`);
|
|
19
|
+
notes.push(tip(`Tip: ${cl.name} has subclasses (${ont.children(cl.id).map((k) => ont.label(k)).join(", ")}). Use the most specific class that fits.`));
|
|
20
20
|
}
|
|
21
21
|
const id = ont.newId("Instance", name);
|
|
22
22
|
const inst = ont.addNode({ type: "Instance", id, name, ...(o.description ? { description: o.description } : {}), values: {} });
|
package/dist/ops/links.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Ontology } from "@ontology-kit/reader";
|
|
2
|
-
import type
|
|
2
|
+
import { type Notes } from "./common.js";
|
|
3
3
|
/** Create (or update) one relationship value, with edge properties. */
|
|
4
4
|
export declare function link(ont: Ontology, fromRef: string, relRef: string, toRef: string, o?: {
|
|
5
5
|
props?: string[];
|
package/dist/ops/links.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** One relationship value at a time, with edge properties (okb link / unlink). */
|
|
2
2
|
import * as naming from "../naming.js";
|
|
3
3
|
import { OkbError, edgeProps } from "@ontology-kit/reader";
|
|
4
|
+
import { tip } from "./common.js";
|
|
4
5
|
import { assign, findSlotFor, parseAssignments } from "./values.js";
|
|
5
6
|
function coerceEdgeValue(decl, raw, relName) {
|
|
6
7
|
switch (decl.valueType) {
|
|
@@ -71,7 +72,7 @@ export function link(ont, fromRef, relRef, toRef, o = {}) {
|
|
|
71
72
|
if (missing.length)
|
|
72
73
|
notes.push(`Still required on this edge: ${missing.join(", ")}.`);
|
|
73
74
|
if (!props.rule && !edge.rule && ont.ofType("Rule").length)
|
|
74
|
-
notes.push(`Tip: if a documented rule justifies this link, add --rule <rule id> so the edge shares its quote and verification.`);
|
|
75
|
+
notes.push(tip(`Tip: if a documented rule justifies this link, add --rule <rule id> so the edge shares its quote and verification.`));
|
|
75
76
|
return notes;
|
|
76
77
|
}
|
|
77
78
|
export function unlink(ont, fromRef, relRef, toRef) {
|
package/dist/ops/scope.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Ontology, type Disposition } from "@ontology-kit/reader";
|
|
2
|
-
import { type Notes } from "./common.js";
|
|
2
|
+
import { type Notes, type Tip } from "./common.js";
|
|
3
|
+
import { type MatchMode } from "../cqanswer.js";
|
|
3
4
|
export declare function setScope(ont: Ontology, o: {
|
|
4
5
|
name?: string;
|
|
5
6
|
domain?: string;
|
|
@@ -14,13 +15,19 @@ export declare function setCQ(ont: Ontology, ref: string, o: {
|
|
|
14
15
|
text?: string;
|
|
15
16
|
status?: string;
|
|
16
17
|
}): Notes;
|
|
18
|
+
/** Store the expected answer on a question. The query must run now, so a misspelled name fails here, not in CI. */
|
|
19
|
+
export declare function answerCQ(ont: Ontology, ref: string, o: {
|
|
20
|
+
query: string;
|
|
21
|
+
expect: string[];
|
|
22
|
+
match: MatchMode;
|
|
23
|
+
}): Notes;
|
|
17
24
|
export declare function linkCQ(ont: Ontology, cqRef: string, refs: string[], unlink?: boolean): Notes;
|
|
18
25
|
/**
|
|
19
26
|
* Once a question is answered, suggest its family (rule scope-cq-families): the same
|
|
20
27
|
* question about similar things, and more about the same subject. One line, and
|
|
21
28
|
* only after something is built, so nobody has to list every question up front.
|
|
22
29
|
*/
|
|
23
|
-
export declare function familyTip(ont: Ontology, cqId: string):
|
|
30
|
+
export declare function familyTip(ont: Ontology, cqId: string): Tip;
|
|
24
31
|
export declare function addTerms(ont: Ontology, terms: string[], note?: string): Notes;
|
|
25
32
|
export declare function setTerm(ont: Ontology, ref: string, as: string, nodeRef?: string, note?: string): Notes;
|
|
26
33
|
export declare function addReuse(ont: Ontology, o: {
|
package/dist/ops/scope.js
CHANGED
|
@@ -3,8 +3,9 @@ import * as naming from "../naming.js";
|
|
|
3
3
|
import { questionFamilies } from "../families.js";
|
|
4
4
|
import { OkbError, DISPOSITIONS } from "@ontology-kit/reader";
|
|
5
5
|
import { isOneOf } from "../types.js";
|
|
6
|
-
import { splitList as list } from "./common.js";
|
|
6
|
+
import { splitList as list, tip } from "./common.js";
|
|
7
7
|
import { addDecision } from "./admin.js";
|
|
8
|
+
import { compare, describeResult, evaluate, parseQuery } from "../cqanswer.js";
|
|
8
9
|
export function setScope(ont, o) {
|
|
9
10
|
const m = ont.meta;
|
|
10
11
|
if (o.name) {
|
|
@@ -35,7 +36,7 @@ export function addCQ(ont, text) {
|
|
|
35
36
|
ont.addNode({ type: "CompetencyQuestion", id, text, status: "draft" });
|
|
36
37
|
const notes = [`Added ${id}.`];
|
|
37
38
|
if (!text.trim().endsWith("?"))
|
|
38
|
-
notes.push("Tip: phrase competency questions as actual questions.");
|
|
39
|
+
notes.push(tip("Tip: phrase competency questions as actual questions."));
|
|
39
40
|
return notes;
|
|
40
41
|
}
|
|
41
42
|
export function setCQ(ont, ref, o) {
|
|
@@ -50,6 +51,21 @@ export function setCQ(ont, ref, o) {
|
|
|
50
51
|
ont.touch(q);
|
|
51
52
|
return o.status === "answerable" ? [`Updated ${q.id}.`, familyTip(ont, q.id)] : [`Updated ${q.id}.`];
|
|
52
53
|
}
|
|
54
|
+
/** Store the expected answer on a question. The query must run now, so a misspelled name fails here, not in CI. */
|
|
55
|
+
export function answerCQ(ont, ref, o) {
|
|
56
|
+
const q = ont.find(ref, "CompetencyQuestion");
|
|
57
|
+
const query = parseQuery(o.query);
|
|
58
|
+
const expect = list(o.expect);
|
|
59
|
+
if (!expect.length)
|
|
60
|
+
throw new OkbError("--expect needs at least one name. Use --expect A,B,C.");
|
|
61
|
+
const actual = evaluate(ont, query);
|
|
62
|
+
q.answer = { query, expect, match: o.match };
|
|
63
|
+
ont.touch(q);
|
|
64
|
+
const r = compare(actual, q.answer);
|
|
65
|
+
const n = ont.displayNumber(q);
|
|
66
|
+
const now = { number: n, id: q.id, text: q.text, ...r };
|
|
67
|
+
return [`Stored the expected answer on ${q.id}.`, r.status === "pass" ? "The ontology answers it today." : `Heads up, the ontology doesn't answer it yet: ${describeResult(now)}`];
|
|
68
|
+
}
|
|
53
69
|
export function linkCQ(ont, cqRef, refs, unlink = false) {
|
|
54
70
|
const q = ont.find(cqRef, "CompetencyQuestion");
|
|
55
71
|
const notes = [];
|
|
@@ -78,7 +94,7 @@ export function familyTip(ont, cqId) {
|
|
|
78
94
|
return [same, more].filter(Boolean).join(", or ");
|
|
79
95
|
});
|
|
80
96
|
const ideas = parts.length ? ` Would you also ask ${parts.join("; ")}?` : "";
|
|
81
|
-
return `Tip: ${cqId} is one example of a family of questions.${ideas} Add the ones you want (okb cq add "..."), note the rest as out of scope (okb scope --out-of-scope "..."), or keep it narrow
|
|
97
|
+
return tip(`Tip: ${cqId} is one example of a family of questions.${ideas} Add the ones you want (okb cq add "..."), note the rest as out of scope (okb scope --out-of-scope "..."), or keep it narrow.`);
|
|
82
98
|
}
|
|
83
99
|
export function addTerms(ont, terms, note) {
|
|
84
100
|
const notes = [];
|
package/dist/ops/slots.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as naming from "../naming.js";
|
|
3
3
|
import { OkbError, isRelationship, CARDINALITIES, VALUE_TYPES } from "@ontology-kit/reader";
|
|
4
4
|
import { isOneOf } from "../types.js";
|
|
5
|
-
import { splitList as list } from "./common.js";
|
|
5
|
+
import { splitList as list, tip } from "./common.js";
|
|
6
6
|
import { checkName } from "./naming.js";
|
|
7
7
|
import { linkTermIfAny } from "./scope.js";
|
|
8
8
|
import { coerce } from "./values.js";
|
|
@@ -25,11 +25,11 @@ export function addSlot(ont, name, o) {
|
|
|
25
25
|
? `Added relationship ${name}: (${o.on?.join("|") || "?"})-[:${added.relType}]->(${ont.range(id).map((r) => ont.label(r)).join("|") || "?"}).`
|
|
26
26
|
: `Added property ${name}${o.on?.length ? ` on ${o.on.join(", ")}` : ""} (${added.valueType}).`);
|
|
27
27
|
if (!o.on?.length && !added.appliesToRules)
|
|
28
|
-
notes.push(`Attach it to a class: okb slot set ${name} --on <Class> (or to every rule: --on-rules)`);
|
|
28
|
+
notes.push(tip(`Attach it to a class: okb slot set ${name} --on <Class> (or to every rule: --on-rules)`));
|
|
29
29
|
if (!o.card)
|
|
30
|
-
notes.push(`Decide how many values it holds: --card single or --card multiple (Step 6).`);
|
|
30
|
+
notes.push(tip(`Decide how many values it holds: --card single or --card multiple (Step 6).`));
|
|
31
31
|
if (!o.description)
|
|
32
|
-
notes.push(`Add a one-line description: okb slot set ${name} --desc "..."`);
|
|
32
|
+
notes.push(tip(`Add a one-line description: okb slot set ${name} --desc "..."`));
|
|
33
33
|
linkTermIfAny(ont, name, id, "slot");
|
|
34
34
|
return notes;
|
|
35
35
|
}
|
|
@@ -139,9 +139,9 @@ export function updateSlot(ont, ref, o, creating = false) {
|
|
|
139
139
|
throw new OkbError(`${s.name}: minimum ${mn} is more than maximum ${mx}${s.cardinality === "single" ? " (single cardinality means at most 1)" : ""}. Nothing could ever satisfy that.`);
|
|
140
140
|
}
|
|
141
141
|
if (s.valueType === "Enumerated" && !s.allowedValues?.length)
|
|
142
|
-
notes.push(`List the allowed values: okb slot set ${s.name} --values a,b,c`);
|
|
142
|
+
notes.push(tip(`List the allowed values: okb slot set ${s.name} --values a,b,c`));
|
|
143
143
|
if (s.valueType === "Instance" && ont.range(s.id).length === 0)
|
|
144
|
-
notes.push(`Say which class its values come from: okb slot set ${s.name} --range <Class>`);
|
|
144
|
+
notes.push(tip(`Say which class its values come from: okb slot set ${s.name} --range <Class>`));
|
|
145
145
|
if (!creating && !notes.length)
|
|
146
146
|
notes.push(`Updated ${s.name}.`);
|
|
147
147
|
return notes;
|
package/dist/provenance.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MdDoc, type QuoteHit } from "./markdown.js";
|
|
2
2
|
import { type Ontology, type SourceLocationNode, type SourceNode } from "@ontology-kit/reader";
|
|
3
|
-
import type
|
|
3
|
+
import { type Notes } from "./ops.js";
|
|
4
4
|
export declare const isMarkdown: (p: string) => boolean;
|
|
5
5
|
export declare function sourcePath(ont: Ontology, src: SourceNode): string;
|
|
6
6
|
export declare function readMarkdownSource(ont: Ontology, src: SourceNode): MdDoc;
|
package/dist/provenance.js
CHANGED
|
@@ -10,6 +10,7 @@ import { OkbError, nameOrText, MODALITIES, VERIFICATION_STATUSES as STATUSES } f
|
|
|
10
10
|
import { isOneOf } from "./types.js";
|
|
11
11
|
import { UNSUPPORTED_NOTE_TIP, overreachNoteTips, shellQuote, statedModality } from "./verifynote.js";
|
|
12
12
|
import * as naming from "./naming.js";
|
|
13
|
+
import { tip } from "./ops.js";
|
|
13
14
|
import { assign } from "./ops/values.js";
|
|
14
15
|
import { findQuote, loadPages } from "./quotes.js";
|
|
15
16
|
import { blockRecords } from "./resync.js";
|
|
@@ -58,7 +59,7 @@ export function addSource(ont, file, o) {
|
|
|
58
59
|
ont.addNode(Object.fromEntries(Object.entries(node).filter(([, v]) => v !== undefined)));
|
|
59
60
|
notes.unshift(`Registered source ${node.id}: ${node.title}`);
|
|
60
61
|
if (node.format === "markdown" && !o.repoUrl)
|
|
61
|
-
notes.push("Tip: add --repo-url <GitHub URL of this file> so quotes get links to the exact lines.");
|
|
62
|
+
notes.push(tip("Tip: add --repo-url <GitHub URL of this file> so quotes get links to the exact lines."));
|
|
62
63
|
notes.push(`Next: okb source outline ${node.id} (the list of quotable blocks to work through)`);
|
|
63
64
|
return notes;
|
|
64
65
|
}
|
|
@@ -235,7 +236,7 @@ export function refine(ont, ruleRef, broaderRef, o = {}) {
|
|
|
235
236
|
ont.addEdge(rule.id, "REFINES", broader.id, adds ? { adds } : {});
|
|
236
237
|
const notes = [`${rule.id} refines ${broader.id}${adds ? ` (adds: ${adds})` : ""}.`];
|
|
237
238
|
if (!adds)
|
|
238
|
-
notes.push("Tip: say what it adds with --adds \"...\" so a verifier can check that detail appears in its quote.");
|
|
239
|
+
notes.push(tip("Tip: say what it adds with --adds \"...\" so a verifier can check that detail appears in its quote."));
|
|
239
240
|
return notes;
|
|
240
241
|
}
|
|
241
242
|
/** `instance` FULFILLS `rule`: a descriptive fact that meets the rule. Many instances may fulfill one rule. */
|
package/dist/release.d.ts
CHANGED
|
@@ -25,6 +25,10 @@ export declare function compareVersions(a: string, b: string): number;
|
|
|
25
25
|
export declare const isVersion: (v: string) => boolean;
|
|
26
26
|
/** Read and check the shape of a manifest.json. Throws OkbError naming the problem. */
|
|
27
27
|
export declare function readReleaseManifest(file: string): ReleaseManifest;
|
|
28
|
+
/** The writer `writeFileAtomic` uses; tests swap `write` to simulate a failed write. */
|
|
29
|
+
export declare const releaseIo: {
|
|
30
|
+
write: (file: string, text: string) => void;
|
|
31
|
+
};
|
|
28
32
|
export interface ReleaseResult {
|
|
29
33
|
version: string;
|
|
30
34
|
previous?: string;
|
package/dist/release.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* says where it differs.
|
|
15
15
|
*/
|
|
16
16
|
import { createHash } from "node:crypto";
|
|
17
|
-
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
18
18
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
19
19
|
import { OkbError, Ontology, slug } from "@ontology-kit/reader";
|
|
20
20
|
import { today } from "./clock.js";
|
|
@@ -194,6 +194,25 @@ function writeReleasesMd(root, name) {
|
|
|
194
194
|
const sections = releasedVersions(root).map((v) => readFileSync(join(root, RELEASES_DIR, v, "CHANGES.md"), "utf8").trimEnd());
|
|
195
195
|
writeFileSync(join(root, "RELEASES.md"), `# Releases of ${name}\n\nEach release's changes, newest first. \`manifest.json\` pins the latest one; \`okb release verify\` checks the files against it.\n\n${sections.join("\n\n")}\n`);
|
|
196
196
|
}
|
|
197
|
+
/** The writer `writeFileAtomic` uses; tests swap `write` to simulate a failed write. */
|
|
198
|
+
export const releaseIo = {
|
|
199
|
+
write: (file, text) => writeFileSync(file, text, "utf8"),
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Write `text` to a temp file next to `file`, then rename it into place, so a failed write leaves the
|
|
203
|
+
* previous `file` whole. The temp file is removed if the write or the rename fails.
|
|
204
|
+
*/
|
|
205
|
+
function writeFileAtomic(file, text) {
|
|
206
|
+
const tmp = `${file}.tmp`;
|
|
207
|
+
try {
|
|
208
|
+
releaseIo.write(tmp, text);
|
|
209
|
+
renameSync(tmp, file);
|
|
210
|
+
}
|
|
211
|
+
catch (e) {
|
|
212
|
+
rmSync(tmp, { force: true });
|
|
213
|
+
throw e;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
197
216
|
/**
|
|
198
217
|
* Cut release `version` of the folder `ont` was loaded from. Call it inside `Ontology.edit` (it saves
|
|
199
218
|
* and writes files under the lock). `findings` are the validator's results; any open error stops the release.
|
|
@@ -261,8 +280,8 @@ export function cutRelease(ont, version, findings) {
|
|
|
261
280
|
// The manifests go last: they are what makes the release exist, so a failure above leaves nothing pinned.
|
|
262
281
|
// Dataset paths are relative to the manifest, so the snapshot's copy points at the sources from its own folder.
|
|
263
282
|
const snapManifest = { ...manifest, datasets: { ...manifest.datasets, ...(docs ? { docs: { ...docs, path: posix(relative(snap, resolve(root, docs.path))) || "." } } : {}) } };
|
|
264
|
-
|
|
265
|
-
|
|
283
|
+
writeFileAtomic(join(snap, MANIFEST_FILE), json(snapManifest));
|
|
284
|
+
writeFileAtomic(lastFile, json(manifest));
|
|
266
285
|
const notes = [`Released ${version}${last ? ` (was ${last.version})` : ""}: ${countsLine(ont)}`];
|
|
267
286
|
if (diff) {
|
|
268
287
|
const s = diff.summary;
|