@ontology-kit/okb 0.3.0-alpha.23 → 0.3.0-alpha.66
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 +2 -2
- package/dist/command-table.d.ts +21 -11
- package/dist/command-table.js +24 -21
- package/dist/commands/documents.js +2 -2
- package/dist/commands/modeling.js +68 -34
- package/dist/commands/planning.js +40 -1
- package/dist/commands/reviewing.js +52 -10
- 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.d.ts +33 -2
- package/dist/export.js +69 -11
- 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/render.d.ts +15 -2
- package/dist/render.js +25 -5
- package/dist/runner.js +22 -17
- package/dist/verifynote.d.ts +4 -3
- package/dist/verifynote.js +3 -2
- package/dist/workflows.d.ts +31 -7
- package/dist/workflows.js +56 -9
- 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 +2 -2
- package/schema/node.schema.json +22 -1
- package/skills/build-domain-kb-from-docs/SKILL.md +1 -1
- package/skills/ontology-coach/SKILL.md +2 -2
- package/skills/ontology-maintainer/SKILL.md +1 -1
- package/skills/ontology-review/SKILL.md +1 -1
- package/skills/ontology-signoff/SKILL.md +1 -1
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/render.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { Note } from "./ops.js";
|
|
1
2
|
import { type Explainable, type MetaStep } from "./metakb.js";
|
|
2
3
|
import { type CompetencyQuestionNode, type DesignDecisionNode, type Ontology, type OkbNode, type SourceLocationNode, type SourceNode } from "@ontology-kit/reader";
|
|
3
4
|
import { type Finding } from "./types.js";
|
|
5
|
+
import type { QueryResult } from "@ontology-kit/reader";
|
|
4
6
|
import type { CheckReport } from "./check.js";
|
|
5
7
|
import type { MdDoc } from "./markdown.js";
|
|
6
8
|
import type { ReviewItem } from "./review.js";
|
|
@@ -36,7 +38,8 @@ export declare function show(ont: Ontology, n: OkbNode): string;
|
|
|
36
38
|
export declare function mermaid(ont: Ontology): string;
|
|
37
39
|
/** The `okb check` summary: one line per check, the problems under the ones that failed, and a verdict. */
|
|
38
40
|
export declare function formatCheck(report: CheckReport, name: string): string;
|
|
39
|
-
|
|
41
|
+
/** A tip teaches rather than reports, so it is shown dimmed and indented. */
|
|
42
|
+
export declare function formatNotes(notes: readonly Note[]): string[];
|
|
40
43
|
export declare function renderInit(name: string, root: string, folder: string, guide: string): string[];
|
|
41
44
|
export declare function renderScope(m: Ontology["meta"]): string[];
|
|
42
45
|
export declare function renderConvention(ont: Ontology): string;
|
|
@@ -85,9 +88,19 @@ export declare function renderSkillsStatus(dir: string, metaVersion: string, ski
|
|
|
85
88
|
export declare function renderWrote(out: string, what: string, hint: string): string;
|
|
86
89
|
export declare function renderStepGuide(order: number): string;
|
|
87
90
|
export declare function renderDiagramWritten(out: string): string;
|
|
91
|
+
export declare function renderChangeSetWritten(out: string, s: {
|
|
92
|
+
nodesAdded: number;
|
|
93
|
+
nodesChanged: number;
|
|
94
|
+
nodesRemoved: number;
|
|
95
|
+
relationshipsAdded: number;
|
|
96
|
+
relationshipsChanged: number;
|
|
97
|
+
relationshipsRemoved: number;
|
|
98
|
+
}): string[];
|
|
88
99
|
export declare function renderExportWritten(out: string, g: {
|
|
89
100
|
nodes: unknown[];
|
|
90
101
|
relationships: unknown[];
|
|
91
102
|
notes: string[];
|
|
92
|
-
}, fmt: string): string[];
|
|
103
|
+
}, fmt: string, files?: string[]): string[];
|
|
104
|
+
/** `okb query` as text: one line per hit, the kind in a heading. */
|
|
105
|
+
export declare function renderQueryResult(ont: Ontology, r: QueryResult): string[];
|
|
93
106
|
export {};
|
package/dist/render.js
CHANGED
|
@@ -431,10 +431,9 @@ export function formatCheck(report, name) {
|
|
|
431
431
|
return out.join("\n");
|
|
432
432
|
}
|
|
433
433
|
// ---- Terminal output for the command records (src/commands/). Each returns lines; the runner prints them. ----
|
|
434
|
-
/** A
|
|
435
|
-
const TIP = /^(Tip|Add a|Attach|Decide|Say which|List the)/;
|
|
434
|
+
/** A tip teaches rather than reports, so it is shown dimmed and indented. */
|
|
436
435
|
export function formatNotes(notes) {
|
|
437
|
-
return notes.map((n) => (
|
|
436
|
+
return notes.map((n) => (typeof n === "string" ? n : c.dim(" " + n.text)));
|
|
438
437
|
}
|
|
439
438
|
export function renderInit(name, root, folder, guide) {
|
|
440
439
|
return [`${SYMBOL.ok} Created ontology '${name}' in ${root}\n`, guide, c.dim(`\nNext: cd ${folder} && okb scope --domain "..." --purpose "..." --users "..."`)];
|
|
@@ -456,6 +455,7 @@ export function renderQuestions(ont, qs) {
|
|
|
456
455
|
const num = ont.displayNumber(q);
|
|
457
456
|
out.push(`${c.bold(String(num).padEnd(3))} ${q.text} ${c.dim(`[${q.status ?? "draft"}]`)}`);
|
|
458
457
|
out.push(c.dim(` needs: ${needs.length ? needs.join(", ") : "(not linked yet: okb cq link " + num + " <Class|slot>...)"}`));
|
|
458
|
+
out.push(c.dim(` answer: ${q.answer ? q.answer.expect.join(", ") + (q.answer.match === "includes" ? " (and maybe more)" : "") : "(none stored: okb cq answer " + num + " --query '...' --expect ...)"}`));
|
|
459
459
|
}
|
|
460
460
|
return out;
|
|
461
461
|
}
|
|
@@ -645,6 +645,26 @@ export function renderStepGuide(order) {
|
|
|
645
645
|
export function renderDiagramWritten(out) {
|
|
646
646
|
return `Wrote ${out}. Open it in GitHub, VS Code (Markdown preview), or mermaid.live.`;
|
|
647
647
|
}
|
|
648
|
-
export function
|
|
649
|
-
return [`Wrote ${out}: ${
|
|
648
|
+
export function renderChangeSetWritten(out, s) {
|
|
649
|
+
return [`Wrote ${out}: a change set (cypher). Nodes: ${s.nodesAdded} added, ${s.nodesChanged} changed, ${s.nodesRemoved} removed. Relationships: ${s.relationshipsAdded} added, ${s.relationshipsChanged} changed, ${s.relationshipsRemoved} removed.`];
|
|
650
|
+
}
|
|
651
|
+
export function renderExportWritten(out, g, fmt, files) {
|
|
652
|
+
const where = files ? `${out}/ (${files.join(", ")})` : out;
|
|
653
|
+
return [`Wrote ${where}: ${g.nodes.length} nodes, ${g.relationships.length} relationships (${fmt}).`, ...g.notes.map((n) => c.dim(" " + n))];
|
|
654
|
+
}
|
|
655
|
+
/** `okb query` as text: one line per hit, the kind in a heading. */
|
|
656
|
+
export function renderQueryResult(ont, r) {
|
|
657
|
+
if (!r.hits.length)
|
|
658
|
+
return [c.dim(`No ${r.kind} results.`)];
|
|
659
|
+
const out = [];
|
|
660
|
+
if (r.kind === "find")
|
|
661
|
+
for (const h of r.hits)
|
|
662
|
+
out.push(h.name);
|
|
663
|
+
else if (r.kind === "slots")
|
|
664
|
+
for (const h of r.hits)
|
|
665
|
+
out.push(`${h.name} ${c.dim(`(${h.relationship ? "relationship" : "property"}${h.valueType ? `, ${h.valueType}` : ""})`)}`);
|
|
666
|
+
else
|
|
667
|
+
for (const h of r.hits)
|
|
668
|
+
out.push(`${h.name}${h.type ? " " + c.dim(`(${h.type})`) : ""} ${c.dim(`from ${ont.label(h.from)}${h.depth > 1 ? `, hop ${h.depth}` : ""}${h.inheritedFrom ? `, inherited from ${ont.label(h.inheritedFrom)}` : ""}`)}`);
|
|
669
|
+
return out;
|
|
650
670
|
}
|
package/dist/runner.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* The runners a command record uses through its `Ctx`: load the folder, change it under the
|
|
3
3
|
* lock, print. Records never touch the filesystem, the lock or `console` themselves.
|
|
4
4
|
*/
|
|
5
|
-
import { writeFileSync } from "node:fs";
|
|
6
|
-
import { resolve as resolvePath } from "node:path";
|
|
5
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { dirname, resolve as resolvePath } from "node:path";
|
|
7
7
|
import { OkbError, Ontology } from "@ontology-kit/reader";
|
|
8
8
|
import { formatNotes } from "./render.js";
|
|
9
9
|
import { resolve, parseForm } from "./command-table.js";
|
|
@@ -18,10 +18,20 @@ function makeCtx(commands, opts, args, globals) {
|
|
|
18
18
|
};
|
|
19
19
|
const say = (notes) => print(formatNotes(notes));
|
|
20
20
|
const edit = (fn) => Ontology.edit(dir, fn);
|
|
21
|
+
const json = globals.json ?? !!opts.json;
|
|
22
|
+
/** One clock read, save and print around `fn`, which may be async (`Ontology.edit` takes either). */
|
|
23
|
+
const mutateWith = (fn) => edit((ont) => {
|
|
24
|
+
const finish = (notes) => {
|
|
25
|
+
ont.save();
|
|
26
|
+
say(notes);
|
|
27
|
+
};
|
|
28
|
+
const notes = ont.tick(() => fn(ont));
|
|
29
|
+
return notes instanceof Promise ? notes.then(finish) : finish(notes);
|
|
30
|
+
});
|
|
21
31
|
return {
|
|
22
32
|
opts,
|
|
23
33
|
args,
|
|
24
|
-
json
|
|
34
|
+
json,
|
|
25
35
|
commands,
|
|
26
36
|
dir,
|
|
27
37
|
int(name) {
|
|
@@ -34,23 +44,14 @@ function makeCtx(commands, opts, args, globals) {
|
|
|
34
44
|
},
|
|
35
45
|
load: () => Ontology.load(dir),
|
|
36
46
|
edit,
|
|
37
|
-
editAsync: (fn) => Ontology.edit(dir, fn),
|
|
38
47
|
mutate(fn) {
|
|
39
|
-
|
|
40
|
-
const notes = ont.tick(() => fn(ont));
|
|
41
|
-
ont.save();
|
|
42
|
-
say(notes);
|
|
43
|
-
});
|
|
48
|
+
mutateWith(fn);
|
|
44
49
|
},
|
|
45
50
|
async mutateAsync(fn) {
|
|
46
|
-
await
|
|
47
|
-
const notes = await fn(ont);
|
|
48
|
-
ont.save();
|
|
49
|
-
say(notes);
|
|
50
|
-
});
|
|
51
|
+
await mutateWith(fn);
|
|
51
52
|
},
|
|
52
53
|
emit(data, build) {
|
|
53
|
-
if (
|
|
54
|
+
if (json)
|
|
54
55
|
console.log(JSON.stringify(data(), null, 2));
|
|
55
56
|
else {
|
|
56
57
|
const out = lines(build());
|
|
@@ -59,7 +60,7 @@ function makeCtx(commands, opts, args, globals) {
|
|
|
59
60
|
}
|
|
60
61
|
},
|
|
61
62
|
emitRaw(data, text) {
|
|
62
|
-
if (
|
|
63
|
+
if (json)
|
|
63
64
|
console.log(JSON.stringify(data(), null, 2));
|
|
64
65
|
else
|
|
65
66
|
process.stdout.write(text());
|
|
@@ -67,7 +68,11 @@ function makeCtx(commands, opts, args, globals) {
|
|
|
67
68
|
say,
|
|
68
69
|
print,
|
|
69
70
|
printRaw: (text) => void process.stdout.write(text),
|
|
70
|
-
write: (path, text) =>
|
|
71
|
+
write: (path, text) => {
|
|
72
|
+
const full = resolvePath(path);
|
|
73
|
+
mkdirSync(dirname(full), { recursive: true });
|
|
74
|
+
writeFileSync(full, text);
|
|
75
|
+
},
|
|
71
76
|
exit: (code) => void (process.exitCode = code),
|
|
72
77
|
};
|
|
73
78
|
}
|
package/dist/verifynote.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Modality } from "@ontology-kit/reader";
|
|
2
|
+
import { type Notes } from "./ops/common.js";
|
|
2
3
|
/**
|
|
3
4
|
* One sentence naming what changed: a modality, a number, or a few words. Null when the difference
|
|
4
5
|
* can't be named this way (a rewording, or a change too big to list), so the caller falls back to the
|
|
@@ -12,7 +13,7 @@ export declare function suggestNote(original: string, corrected: string): string
|
|
|
12
13
|
export declare function statedModality(statement: string): Modality | null;
|
|
13
14
|
/** A double-quoted shell argument. */
|
|
14
15
|
export declare const shellQuote: (s: string) => string;
|
|
15
|
-
export declare const GENERIC_NOTE_TIP
|
|
16
|
-
export declare const UNSUPPORTED_NOTE_TIP
|
|
16
|
+
export declare const GENERIC_NOTE_TIP: import("./ops/common.js").Tip;
|
|
17
|
+
export declare const UNSUPPORTED_NOTE_TIP: import("./ops/common.js").Tip;
|
|
17
18
|
/** Lines to print after OVERREACH with no --note. */
|
|
18
|
-
export declare function overreachNoteTips(id: string, original: string, corrected: string, extra: string):
|
|
19
|
+
export declare function overreachNoteTips(id: string, original: string, corrected: string, extra: string): Notes;
|
package/dist/verifynote.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { tip } from "./ops/common.js";
|
|
1
2
|
const MODALITY = /\b(MUST\s+NOT|SHOULD\s+NOT|MUST|SHOULD|MAY)\b/gi;
|
|
2
3
|
const keyword = (m) => m.toUpperCase().replace(/\s+/g, " ");
|
|
3
4
|
const NUMBER = /\d+(?:[.,]\d+)*/g;
|
|
@@ -81,8 +82,8 @@ export function statedModality(statement) {
|
|
|
81
82
|
}
|
|
82
83
|
/** A double-quoted shell argument. */
|
|
83
84
|
export const shellQuote = (s) => `"${s.replace(/(["\\$`])/g, "\\$1")}"`;
|
|
84
|
-
export const GENERIC_NOTE_TIP = 'Tip: add a note so a reviewer sees why, not just the verdict: --note "<one sentence naming the word or number you changed>". Skip it when the correction speaks for itself.';
|
|
85
|
-
export const UNSUPPORTED_NOTE_TIP = 'Tip: add --note "<which part of the statement the quote doesn\'t support>". One sentence naming the word or claim; don\'t restate UNSUPPORTED.';
|
|
85
|
+
export const GENERIC_NOTE_TIP = tip('Tip: add a note so a reviewer sees why, not just the verdict: --note "<one sentence naming the word or number you changed>". Skip it when the correction speaks for itself.');
|
|
86
|
+
export const UNSUPPORTED_NOTE_TIP = tip('Tip: add --note "<which part of the statement the quote doesn\'t support>". One sentence naming the word or claim; don\'t restate UNSUPPORTED.');
|
|
86
87
|
/** Lines to print after OVERREACH with no --note. */
|
|
87
88
|
export function overreachNoteTips(id, original, corrected, extra) {
|
|
88
89
|
const s = suggestNote(original, corrected);
|
package/dist/workflows.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Ontology, type OkbNode } from "@ontology-kit/reader";
|
|
2
2
|
import { type Explainable } from "./metakb.js";
|
|
3
|
+
import { type CsvFiles } from "./export-csv.js";
|
|
4
|
+
import * as ops from "./ops.js";
|
|
3
5
|
import { type ResyncReport } from "./resync.js";
|
|
4
6
|
import type { ReviewItem } from "./review.js";
|
|
5
7
|
/** `okb init`: create the folder and stamp the meta-KB version. */
|
|
@@ -8,11 +10,7 @@ export declare function initOntology(folder: string, name: string): {
|
|
|
8
10
|
guide: string;
|
|
9
11
|
};
|
|
10
12
|
/** `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
|
-
};
|
|
13
|
+
export declare function showData(ont: Ontology, n: OkbNode): import("@ontology-kit/reader").GetResult;
|
|
16
14
|
/** `okb validate`: run the checks and say whether the command should fail. */
|
|
17
15
|
export declare function validate(ont: Ontology, o: {
|
|
18
16
|
all?: boolean;
|
|
@@ -134,7 +132,7 @@ export declare function docs(dir: string, outDir: string, o: {
|
|
|
134
132
|
export declare function diff(dir: string, oldRef: string, newRef?: string): import("./diff.js").OntologyDiff;
|
|
135
133
|
/** `okb release verify`: check the folder against its manifest.json (read-only). */
|
|
136
134
|
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. */
|
|
135
|
+
/** `okb export`: the graph, as text, or for the CSV formats a set of files for `--out` (a folder). The format follows --out's extension when --format is left out. */
|
|
138
136
|
export declare function exportOntology(ont: Ontology, o: {
|
|
139
137
|
format?: string;
|
|
140
138
|
out?: string;
|
|
@@ -142,17 +140,43 @@ export declare function exportOntology(ont: Ontology, o: {
|
|
|
142
140
|
noInherited?: boolean;
|
|
143
141
|
noRules?: boolean;
|
|
144
142
|
includeUnverified?: boolean;
|
|
143
|
+
style?: string;
|
|
144
|
+
since?: string;
|
|
145
145
|
}): {
|
|
146
146
|
fmt: string;
|
|
147
147
|
graph: import("./export.js").ExportGraph;
|
|
148
148
|
text: string;
|
|
149
|
+
files: undefined;
|
|
150
|
+
loadCommand: undefined;
|
|
151
|
+
changes: import("./export-changes.js").ChangeSetSummary;
|
|
152
|
+
} | {
|
|
153
|
+
fmt: string;
|
|
154
|
+
graph: {
|
|
155
|
+
format: "okb-export/2";
|
|
156
|
+
ontology: string;
|
|
157
|
+
metaKbVersion: string;
|
|
158
|
+
nodes: import("./export.js").ExportNode[];
|
|
159
|
+
relationships: import("./export.js").ExportRel[];
|
|
160
|
+
notes: string[];
|
|
161
|
+
};
|
|
162
|
+
text: string;
|
|
163
|
+
files: CsvFiles;
|
|
164
|
+
loadCommand: string | undefined;
|
|
165
|
+
changes: undefined;
|
|
166
|
+
} | {
|
|
167
|
+
fmt: string;
|
|
168
|
+
graph: import("./export.js").ExportGraph;
|
|
169
|
+
text: string;
|
|
170
|
+
files: undefined;
|
|
171
|
+
loadCommand: undefined;
|
|
172
|
+
changes: undefined;
|
|
149
173
|
};
|
|
150
174
|
/** `okb instance set`: move to other classes, assign values, change the description, in that order. */
|
|
151
175
|
export declare function setInstance(ont: Ontology, name: string, o: {
|
|
152
176
|
of?: string[];
|
|
153
177
|
desc?: string;
|
|
154
178
|
assignments: string[];
|
|
155
|
-
}):
|
|
179
|
+
}): ops.Note[];
|
|
156
180
|
/** `okb quote list`: every quote, or the quotes from one source. */
|
|
157
181
|
export declare function quotes(ont: Ontology, sourceRef?: string): {
|
|
158
182
|
locs: import("@ontology-kit/reader").SourceLocationNode[];
|
package/dist/workflows.js
CHANGED
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
* the data an output shows (`--json`), and the steps that load, compute and write more than one thing.
|
|
4
4
|
* Nothing here prints; `render.ts` does.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { join, resolve } from "node:path";
|
|
8
|
+
import { OkbError, Ontology, queryGet } from "@ontology-kit/reader";
|
|
8
9
|
import { duplicateQuotes, loadSourcePages, runChecks } from "./checks.js";
|
|
9
10
|
import { MetaKB } from "./metakb.js";
|
|
10
11
|
import { exportGraph, toCypher } from "./export.js";
|
|
12
|
+
import { changeSetCypher } from "./export-changes.js";
|
|
13
|
+
import { CSV_FORMATS, toNeo4jCsv, toNeptuneCsv } from "./export-csv.js";
|
|
11
14
|
import { diffOntologies } from "./diff.js";
|
|
12
15
|
import { installSkills, skillsStatus } from "./skills.js";
|
|
13
16
|
import * as ops from "./ops.js";
|
|
@@ -18,7 +21,7 @@ import { changedPageSet, changesPage, contextPage } from "./reviewdocs.js";
|
|
|
18
21
|
import { loadSide } from "./ontology-ref.js";
|
|
19
22
|
import { resync } from "./resync.js";
|
|
20
23
|
import { runCheck } from "./check.js";
|
|
21
|
-
import { cutRelease, verifyRelease } from "./release.js";
|
|
24
|
+
import { RELEASES_DIR, cutRelease, isVersion, verifyRelease } from "./release.js";
|
|
22
25
|
import { PACKAGE_VERSION } from "./version.js";
|
|
23
26
|
import { stepGuide } from "./render.js";
|
|
24
27
|
/** `okb init`: create the folder and stamp the meta-KB version. */
|
|
@@ -30,7 +33,7 @@ export function initOntology(folder, name) {
|
|
|
30
33
|
}
|
|
31
34
|
/** `okb show`: the node and the edges on both sides of it. */
|
|
32
35
|
export function showData(ont, n) {
|
|
33
|
-
return
|
|
36
|
+
return queryGet(ont, n.id);
|
|
34
37
|
}
|
|
35
38
|
/** `okb validate`: run the checks and say whether the command should fail. */
|
|
36
39
|
export async function validate(ont, o) {
|
|
@@ -182,13 +185,57 @@ export function diff(dir, oldRef, newRef) {
|
|
|
182
185
|
export function releaseVerify(dir) {
|
|
183
186
|
return verifyRelease(resolve(dir));
|
|
184
187
|
}
|
|
185
|
-
/** `okb export`: the graph, as text. The format follows --out's extension when --format is left out. */
|
|
188
|
+
/** `okb export`: the graph, as text, or for the CSV formats a set of files for `--out` (a folder). The format follows --out's extension when --format is left out. */
|
|
186
189
|
export function exportOntology(ont, o) {
|
|
187
190
|
const fmt = o.format ?? (o.out?.endsWith(".cypher") || o.out?.endsWith(".cql") ? "cypher" : "json");
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
191
|
+
const csv = CSV_FORMATS.includes(fmt);
|
|
192
|
+
if (!["json", "cypher"].includes(fmt) && !csv)
|
|
193
|
+
throw new OkbError("--format must be json, cypher, neo4j-csv or neptune-csv.");
|
|
194
|
+
if (o.style !== undefined && !["batched", "simple"].includes(o.style))
|
|
195
|
+
throw new OkbError("--style must be batched or simple.");
|
|
196
|
+
if (o.style !== undefined && fmt !== "cypher")
|
|
197
|
+
throw new OkbError("--style only applies to --format cypher.");
|
|
198
|
+
if (o.since !== undefined && (fmt !== "cypher" || o.style === "simple"))
|
|
199
|
+
throw new OkbError("--since writes a change set, which only exists as --format cypher in the default batched style.");
|
|
200
|
+
if (csv && !o.out)
|
|
201
|
+
throw new OkbError(`--format ${fmt} writes several files, so give a folder with --out.`);
|
|
202
|
+
const opts = { inherited: !o.noInherited, schema: o.schema, rules: !o.noRules, unverified: o.includeUnverified };
|
|
203
|
+
const graph = exportGraph(ont, opts);
|
|
204
|
+
if (o.since !== undefined) {
|
|
205
|
+
const cs = exportChangeSet(ont, o.since, opts, graph);
|
|
206
|
+
return { fmt, graph, text: cs.text, files: undefined, loadCommand: undefined, changes: cs.summary };
|
|
207
|
+
}
|
|
208
|
+
if (csv) {
|
|
209
|
+
const neo4j = fmt === "neo4j-csv" ? toNeo4jCsv(graph) : undefined;
|
|
210
|
+
const { files, notes } = neo4j ? { files: neo4j.files, notes: [] } : toNeptuneCsv(graph);
|
|
211
|
+
return { fmt, graph: { ...graph, notes: [...graph.notes, ...notes] }, text: "", files: files, loadCommand: neo4j?.command, changes: undefined };
|
|
212
|
+
}
|
|
213
|
+
const release = ont.manifest.version ? { ontology: ont.meta.name, version: ont.manifest.version } : undefined;
|
|
214
|
+
return { fmt, graph, text: fmt === "cypher" ? toCypher(graph, { style: o.style, release }) : JSON.stringify(graph, null, 2) + "\n", files: undefined, loadCommand: undefined, changes: undefined };
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* `okb export --since`: the change set from release `since` (a release in `releases/`, a folder, or a git ref) to this
|
|
218
|
+
* folder, which must be exactly its latest release so the script's end version is true.
|
|
219
|
+
*/
|
|
220
|
+
function exportChangeSet(ont, since, opts, graph) {
|
|
221
|
+
const to = ont.manifest.version;
|
|
222
|
+
if (!to)
|
|
223
|
+
throw new OkbError("This knowledge base has no release version yet, so a change set has no end version. Cut a release first: okb release <version>.");
|
|
224
|
+
if (existsSync(join(ont.root, "manifest.json"))) {
|
|
225
|
+
const v = verifyRelease(ont.root);
|
|
226
|
+
if (!v.ok)
|
|
227
|
+
throw new OkbError(`The folder has changed since release ${to} (${v.problems[0]}), so a change set to ${to} would be wrong. Cut a release first (okb release <version>), then export the change set.`);
|
|
228
|
+
}
|
|
229
|
+
const snapshot = isVersion(since) && existsSync(join(ont.root, RELEASES_DIR, since, "okb.json")) ? join(ont.root, RELEASES_DIR, since) : undefined;
|
|
230
|
+
const old = snapshot ? { ont: Ontology.load(snapshot), name: since } : loadSide(since, ont.root);
|
|
231
|
+
const from = old.ont.manifest.version;
|
|
232
|
+
if (!from)
|
|
233
|
+
throw new OkbError(`'${since}' has no release version, so a change set from it can't check the database it runs against. Pass a release (a folder in releases/, or a git ref of a commit made by okb release).`);
|
|
234
|
+
if (from === to)
|
|
235
|
+
throw new OkbError(`'${since}' is release ${from}, the same as the current version. Pass an earlier release.`);
|
|
236
|
+
const oldGraph = exportGraph(old.ont, opts);
|
|
237
|
+
const flags = [opts.schema ? "--with-schema" : "", opts.inherited ? "" : "--no-inherited", opts.rules ? "" : "--no-rules", opts.unverified ? "--include-unverified" : ""].filter(Boolean).join(" ");
|
|
238
|
+
return changeSetCypher(oldGraph, graph, { from: { ontology: old.ont.meta.name, version: from }, to: { ontology: ont.meta.name, version: to }, flags: flags || undefined });
|
|
192
239
|
}
|
|
193
240
|
/** `okb instance set`: move to other classes, assign values, change the description, in that order. */
|
|
194
241
|
export function setInstance(ont, name, o) {
|