@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/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);
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { Ontology, type OkbNode } from "@ontology-kit/reader";
|
|
2
|
+
import { type Explainable } from "./metakb.js";
|
|
3
|
+
import { type CsvFiles } from "./export-csv.js";
|
|
4
|
+
import { type Ask } from "./skills.js";
|
|
5
|
+
import * as ops from "./ops.js";
|
|
6
|
+
import { type ResyncReport } from "./resync.js";
|
|
7
|
+
import type { ReviewItem } from "./review.js";
|
|
8
|
+
/** `okb init`: create the folder and stamp the meta-KB version. */
|
|
9
|
+
export declare function initOntology(folder: string, name: string): {
|
|
10
|
+
ont: Ontology;
|
|
11
|
+
guide: string;
|
|
12
|
+
};
|
|
13
|
+
/** `okb show`: the node and the edges on both sides of it. */
|
|
14
|
+
export declare function showData(ont: Ontology, n: OkbNode): import("@ontology-kit/reader").GetResult;
|
|
15
|
+
/** `okb validate`: run the checks and say whether the command should fail. */
|
|
16
|
+
export declare function validate(ont: Ontology, o: {
|
|
17
|
+
all?: boolean;
|
|
18
|
+
rule?: string[];
|
|
19
|
+
strict?: boolean;
|
|
20
|
+
}): Promise<{
|
|
21
|
+
findings: import("./types.js").Finding[];
|
|
22
|
+
hiddenLater: number;
|
|
23
|
+
fail: boolean;
|
|
24
|
+
data: {
|
|
25
|
+
step: number;
|
|
26
|
+
metaKbVersion: string;
|
|
27
|
+
hiddenLater: number;
|
|
28
|
+
findings: import("./types.js").Finding[];
|
|
29
|
+
};
|
|
30
|
+
}>;
|
|
31
|
+
/** `okb status`: every finding (not just this step's) and the step progress. */
|
|
32
|
+
export declare function status(ont: Ontology): Promise<{
|
|
33
|
+
findings: import("./types.js").Finding[];
|
|
34
|
+
st: {
|
|
35
|
+
steps: import("./status.js").StepStatus[];
|
|
36
|
+
suggested: number;
|
|
37
|
+
};
|
|
38
|
+
data: {
|
|
39
|
+
steps: import("./status.js").StepStatus[];
|
|
40
|
+
suggested: number;
|
|
41
|
+
currentStep: number;
|
|
42
|
+
};
|
|
43
|
+
}>;
|
|
44
|
+
/** `okb step <n|next|prev>`: move to the step, saving under the lock. */
|
|
45
|
+
export declare function moveToStep(dir: string, which: string): {
|
|
46
|
+
target: number;
|
|
47
|
+
leaving: import("./status.js").StepStatus;
|
|
48
|
+
};
|
|
49
|
+
/** The step to show a guide for: the folder's, or step 1 when there is no ontology here. */
|
|
50
|
+
export declare function currentStep(dir: string): number;
|
|
51
|
+
/** `okb review --json`: the scope, the judgment prompts, every class and the decisions. */
|
|
52
|
+
export declare function reviewData(ont: Ontology, items: ReviewItem[]): {
|
|
53
|
+
step: number;
|
|
54
|
+
scope: import("@ontology-kit/reader").OntologyNode;
|
|
55
|
+
judgmentRules: ReviewItem[];
|
|
56
|
+
classes: {
|
|
57
|
+
id: string;
|
|
58
|
+
name: string;
|
|
59
|
+
description: string | undefined;
|
|
60
|
+
parents: string[];
|
|
61
|
+
children: string[];
|
|
62
|
+
ownSlots: string[];
|
|
63
|
+
abstract: boolean | undefined;
|
|
64
|
+
terminological: boolean | undefined;
|
|
65
|
+
instances: number;
|
|
66
|
+
}[];
|
|
67
|
+
decisions: import("@ontology-kit/reader").DesignDecisionNode[];
|
|
68
|
+
};
|
|
69
|
+
/** `okb source outline`: the document's blocks and which lines already have a quote. */
|
|
70
|
+
export declare function outline(ont: Ontology, sourceRef: string, o: {
|
|
71
|
+
quotable?: boolean;
|
|
72
|
+
}): {
|
|
73
|
+
src: import("@ontology-kit/reader").SourceNode;
|
|
74
|
+
doc: import("./markdown.js").MdDoc;
|
|
75
|
+
blocks: import("./markdown.js").MdBlock[];
|
|
76
|
+
quoted: Map<number, string[]>;
|
|
77
|
+
data: () => {
|
|
78
|
+
source: string;
|
|
79
|
+
title: string | undefined;
|
|
80
|
+
frontmatter: Record<string, unknown> | null;
|
|
81
|
+
problems: {
|
|
82
|
+
line: number;
|
|
83
|
+
message: string;
|
|
84
|
+
}[];
|
|
85
|
+
blocks: {
|
|
86
|
+
index: number;
|
|
87
|
+
kind: import("./markdown.js").BlockKind;
|
|
88
|
+
headingPath: string[];
|
|
89
|
+
lines: number[];
|
|
90
|
+
quotable: boolean;
|
|
91
|
+
note: string | undefined;
|
|
92
|
+
calloutType: string | undefined;
|
|
93
|
+
row: {
|
|
94
|
+
columns: string[];
|
|
95
|
+
cells: string[];
|
|
96
|
+
key: string;
|
|
97
|
+
} | undefined;
|
|
98
|
+
text: string | undefined;
|
|
99
|
+
alreadyQuoted: string[];
|
|
100
|
+
}[];
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
/** `okb source refresh --all`: re-check every quote against its document, and write only when something moved. */
|
|
104
|
+
export declare function refreshAll(dir: string, o: {
|
|
105
|
+
dryRun?: boolean;
|
|
106
|
+
record?: boolean;
|
|
107
|
+
}): Promise<{
|
|
108
|
+
report: ResyncReport;
|
|
109
|
+
write: boolean;
|
|
110
|
+
}>;
|
|
111
|
+
/** `okb drift`: near-duplicate quotes across the ontologies in these folders. */
|
|
112
|
+
export declare function drift(folders: readonly string[]): import("./checks.js").Hit[];
|
|
113
|
+
/** `okb release <version>`: run the checks and cut the release under the lock. */
|
|
114
|
+
export declare function release(dir: string, version: string): Promise<import("./release.js").ReleaseResult>;
|
|
115
|
+
/** `okb pin`: record the installed okb version in okb.json. */
|
|
116
|
+
export declare function pin(dir: string): string;
|
|
117
|
+
/** `okb check`. */
|
|
118
|
+
export declare function check(ont: Ontology): Promise<import("./check.js").CheckReport>;
|
|
119
|
+
/** What `okb docs` wrote, for the message and --json. */
|
|
120
|
+
export interface DocsResult {
|
|
121
|
+
files: string[];
|
|
122
|
+
what: string;
|
|
123
|
+
hint: string;
|
|
124
|
+
extra?: object;
|
|
125
|
+
}
|
|
126
|
+
/** `okb docs`: the reference pages, the changed-since-<ref> view, or the rules-in-context page. */
|
|
127
|
+
export declare function docs(dir: string, outDir: string, o: {
|
|
128
|
+
changed?: string;
|
|
129
|
+
hops?: string;
|
|
130
|
+
context?: boolean;
|
|
131
|
+
}): Promise<DocsResult>;
|
|
132
|
+
/** `okb diff <old> [<new>]`: each side a folder or a git ref; with one, the new side is the folder itself. */
|
|
133
|
+
export declare function diff(dir: string, oldRef: string, newRef?: string): import("./diff.js").OntologyDiff;
|
|
134
|
+
/** `okb release verify`: check the folder against its manifest.json (read-only). */
|
|
135
|
+
export declare function releaseVerify(dir: string): import("./release.js").VerifyResult;
|
|
136
|
+
/** `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. */
|
|
137
|
+
export declare function exportOntology(ont: Ontology, o: {
|
|
138
|
+
format?: string;
|
|
139
|
+
out?: string;
|
|
140
|
+
schema?: boolean;
|
|
141
|
+
noInherited?: boolean;
|
|
142
|
+
noRules?: boolean;
|
|
143
|
+
includeUnverified?: boolean;
|
|
144
|
+
style?: string;
|
|
145
|
+
since?: string;
|
|
146
|
+
}): {
|
|
147
|
+
fmt: string;
|
|
148
|
+
graph: import("./export.js").ExportGraph;
|
|
149
|
+
text: string;
|
|
150
|
+
files: undefined;
|
|
151
|
+
loadCommand: undefined;
|
|
152
|
+
changes: import("./export-changes.js").ChangeSetSummary;
|
|
153
|
+
} | {
|
|
154
|
+
fmt: string;
|
|
155
|
+
graph: {
|
|
156
|
+
format: "okb-export/2";
|
|
157
|
+
ontology: string;
|
|
158
|
+
metaKbVersion: string;
|
|
159
|
+
nodes: import("./export.js").ExportNode[];
|
|
160
|
+
relationships: import("./export.js").ExportRel[];
|
|
161
|
+
notes: string[];
|
|
162
|
+
};
|
|
163
|
+
text: string;
|
|
164
|
+
files: CsvFiles;
|
|
165
|
+
loadCommand: string | undefined;
|
|
166
|
+
changes: undefined;
|
|
167
|
+
} | {
|
|
168
|
+
fmt: string;
|
|
169
|
+
graph: import("./export.js").ExportGraph;
|
|
170
|
+
text: string;
|
|
171
|
+
files: undefined;
|
|
172
|
+
loadCommand: undefined;
|
|
173
|
+
changes: undefined;
|
|
174
|
+
};
|
|
175
|
+
/** `okb instance set`: move to other classes, assign values, change the description, in that order. */
|
|
176
|
+
export declare function setInstance(ont: Ontology, name: string, o: {
|
|
177
|
+
of?: string[];
|
|
178
|
+
desc?: string;
|
|
179
|
+
assignments: string[];
|
|
180
|
+
}): ops.Note[];
|
|
181
|
+
/** `okb quote list`: every quote, or the quotes from one source. */
|
|
182
|
+
export declare function quotes(ont: Ontology, sourceRef?: string): {
|
|
183
|
+
locs: import("@ontology-kit/reader").SourceLocationNode[];
|
|
184
|
+
data: () => {
|
|
185
|
+
createdAt?: string;
|
|
186
|
+
updatedAt?: string;
|
|
187
|
+
type: "SourceLocation";
|
|
188
|
+
id: string;
|
|
189
|
+
quote: string;
|
|
190
|
+
locator?: string;
|
|
191
|
+
headingPath?: string[];
|
|
192
|
+
startLine?: number;
|
|
193
|
+
endLine?: number;
|
|
194
|
+
lines?: string;
|
|
195
|
+
blockKind?: string;
|
|
196
|
+
sourceLink?: string;
|
|
197
|
+
pageLink?: string;
|
|
198
|
+
page?: number | string;
|
|
199
|
+
citedBy: string[];
|
|
200
|
+
}[];
|
|
201
|
+
};
|
|
202
|
+
/** `okb explain <topic>`: what matches, with the citations and rationale `--json` adds. */
|
|
203
|
+
export declare function explainData(hits: readonly Explainable[]): ({
|
|
204
|
+
type: "Concept";
|
|
205
|
+
id: string;
|
|
206
|
+
name: string;
|
|
207
|
+
aliases?: string[];
|
|
208
|
+
definition: string;
|
|
209
|
+
plainLanguage: string;
|
|
210
|
+
example?: string;
|
|
211
|
+
inThisToolkit?: string;
|
|
212
|
+
origin: "source" | "operational";
|
|
213
|
+
citations: import("./metakb.js").MetaLocation[];
|
|
214
|
+
rationale: string | undefined;
|
|
215
|
+
} | {
|
|
216
|
+
type: "Decision";
|
|
217
|
+
id: string;
|
|
218
|
+
name: string;
|
|
219
|
+
plainLanguage: string;
|
|
220
|
+
whenYouFaceIt: string;
|
|
221
|
+
tests: import("./metakb.js").DecisionTest[];
|
|
222
|
+
note?: string;
|
|
223
|
+
wine: string;
|
|
224
|
+
citations: import("./metakb.js").MetaLocation[];
|
|
225
|
+
rationale: string | undefined;
|
|
226
|
+
} | {
|
|
227
|
+
type: "Principle";
|
|
228
|
+
id: string;
|
|
229
|
+
name: string;
|
|
230
|
+
statement: string;
|
|
231
|
+
plainLanguage: string;
|
|
232
|
+
citations: import("./metakb.js").MetaLocation[];
|
|
233
|
+
rationale: string | undefined;
|
|
234
|
+
} | {
|
|
235
|
+
type: "Rule";
|
|
236
|
+
id: string;
|
|
237
|
+
key: string;
|
|
238
|
+
modality: import("@ontology-kit/reader").Modality;
|
|
239
|
+
basis: "direct" | "interpretive" | "operational";
|
|
240
|
+
check: "mechanical" | "heuristic" | "judgment";
|
|
241
|
+
severity: import("./types.js").Severity;
|
|
242
|
+
severityReason?: string;
|
|
243
|
+
fromStep: number;
|
|
244
|
+
statement: string;
|
|
245
|
+
plainLanguage: string;
|
|
246
|
+
review?: string;
|
|
247
|
+
fix: string;
|
|
248
|
+
citations: import("./metakb.js").MetaLocation[];
|
|
249
|
+
rationale: string | undefined;
|
|
250
|
+
} | {
|
|
251
|
+
type: "Step";
|
|
252
|
+
id: string;
|
|
253
|
+
order: number;
|
|
254
|
+
name: string;
|
|
255
|
+
goal: string;
|
|
256
|
+
whyItMatters: string;
|
|
257
|
+
guidingQuestions: string[];
|
|
258
|
+
outputs: string[];
|
|
259
|
+
doneWhen: import("./metakb.js").DoneWhen[];
|
|
260
|
+
tips: string[];
|
|
261
|
+
wine: string;
|
|
262
|
+
commands: string[];
|
|
263
|
+
citations: import("./metakb.js").MetaLocation[];
|
|
264
|
+
rationale: string | undefined;
|
|
265
|
+
})[];
|
|
266
|
+
/** `okb version`. */
|
|
267
|
+
export declare const versionLine: () => string;
|
|
268
|
+
/** `okb skills install` and `okb skills status`, for the packaged skills and this meta-KB version. */
|
|
269
|
+
export declare function skillsInstallReport(o: {
|
|
270
|
+
dir?: string;
|
|
271
|
+
copy?: boolean;
|
|
272
|
+
force?: boolean;
|
|
273
|
+
interactive?: boolean;
|
|
274
|
+
ask?: Ask;
|
|
275
|
+
}): Promise<import("./skills.js").InstallResult>;
|
|
276
|
+
export declare function skillsStatusReport(o: {
|
|
277
|
+
dir?: string;
|
|
278
|
+
}): {
|
|
279
|
+
dir: string;
|
|
280
|
+
skills: import("./skills.js").SkillReport[];
|
|
281
|
+
metaVersion: string;
|
|
282
|
+
allCurrent: boolean;
|
|
283
|
+
};
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The multi-step work behind a few commands, kept out of their records so `run` stays a few lines:
|
|
3
|
+
* the data an output shows (`--json`), and the steps that load, compute and write more than one thing.
|
|
4
|
+
* Nothing here prints; `render.ts` does.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { join, resolve } from "node:path";
|
|
8
|
+
import { OkbError, Ontology, queryGet } from "@ontology-kit/reader";
|
|
9
|
+
import { duplicateQuotes, loadSourcePages, runChecks } from "./checks.js";
|
|
10
|
+
import { MetaKB } from "./metakb.js";
|
|
11
|
+
import { exportGraph, toCypher } from "./export.js";
|
|
12
|
+
import { changeSetCypher } from "./export-changes.js";
|
|
13
|
+
import { CSV_FORMATS, toNeo4jCsv, toNeptuneCsv } from "./export-csv.js";
|
|
14
|
+
import { diffOntologies } from "./diff.js";
|
|
15
|
+
import { installSkills, skillsStatus } from "./skills.js";
|
|
16
|
+
import * as ops from "./ops.js";
|
|
17
|
+
import * as prov from "./provenance.js";
|
|
18
|
+
import { computeStatus } from "./status.js";
|
|
19
|
+
import { kbDocs, writeChangedPages, writeKbDocs, writePages } from "./kbdocs.js";
|
|
20
|
+
import { changedPageSet, changesPage, contextPage } from "./reviewdocs.js";
|
|
21
|
+
import { loadSide } from "./ontology-ref.js";
|
|
22
|
+
import { resync } from "./resync.js";
|
|
23
|
+
import { runCheck } from "./check.js";
|
|
24
|
+
import { RELEASES_DIR, cutRelease, isVersion, verifyRelease } from "./release.js";
|
|
25
|
+
import { PACKAGE_VERSION } from "./version.js";
|
|
26
|
+
import { stepGuide } from "./render.js";
|
|
27
|
+
/** `okb init`: create the folder and stamp the meta-KB version. */
|
|
28
|
+
export function initOntology(folder, name) {
|
|
29
|
+
const ont = ops.createOntology(folder, name);
|
|
30
|
+
ont.manifest.metaKbVersion = MetaKB.get().version;
|
|
31
|
+
ont.save();
|
|
32
|
+
return { ont, guide: stepGuide(MetaKB.get().step(1)) };
|
|
33
|
+
}
|
|
34
|
+
/** `okb show`: the node and the edges on both sides of it. */
|
|
35
|
+
export function showData(ont, n) {
|
|
36
|
+
return queryGet(ont, n.id);
|
|
37
|
+
}
|
|
38
|
+
/** `okb validate`: run the checks and say whether the command should fail. */
|
|
39
|
+
export async function validate(ont, o) {
|
|
40
|
+
const { findings, hiddenLater } = runChecks(ont, { all: o.all, only: o.rule }, { pages: await loadSourcePages(ont) });
|
|
41
|
+
const open = findings.filter((f) => !f.explainedBy);
|
|
42
|
+
const fail = open.some((f) => f.severity === "error") || (!!o.strict && open.some((f) => f.severity === "warning"));
|
|
43
|
+
return { findings, hiddenLater, fail, data: { step: ont.step, metaKbVersion: MetaKB.get().version, hiddenLater, findings } };
|
|
44
|
+
}
|
|
45
|
+
/** `okb status`: every finding (not just this step's) and the step progress. */
|
|
46
|
+
export async function status(ont) {
|
|
47
|
+
const { findings } = runChecks(ont, { all: true }, { pages: await loadSourcePages(ont) });
|
|
48
|
+
const st = computeStatus(ont, findings);
|
|
49
|
+
return { findings, st, data: { currentStep: ont.step, ...st } };
|
|
50
|
+
}
|
|
51
|
+
/** `okb step <n|next|prev>`: move to the step, saving under the lock. */
|
|
52
|
+
export function moveToStep(dir, which) {
|
|
53
|
+
const meta = MetaKB.get();
|
|
54
|
+
return Ontology.edit(dir, (ont) => {
|
|
55
|
+
const target = which === "next" ? ont.step + 1 : which === "prev" ? ont.step - 1 : Number(which);
|
|
56
|
+
if (!meta.step(target))
|
|
57
|
+
throw new OkbError(`There is no step ${which}. Steps are 1–${meta.steps.length}.`);
|
|
58
|
+
const leaving = computeStatus(ont).steps.find((s) => s.order === ont.step);
|
|
59
|
+
ont.manifest.currentStep = target;
|
|
60
|
+
ont.save();
|
|
61
|
+
return { target, leaving };
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/** The step to show a guide for: the folder's, or step 1 when there is no ontology here. */
|
|
65
|
+
export function currentStep(dir) {
|
|
66
|
+
try {
|
|
67
|
+
return Ontology.load(dir).step;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return 1;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** `okb review --json`: the scope, the judgment prompts, every class and the decisions. */
|
|
74
|
+
export function reviewData(ont, items) {
|
|
75
|
+
const classes = ont.ofType("Class").map((cl) => ({
|
|
76
|
+
id: cl.id, name: cl.name, description: cl.description, parents: ont.parents(cl.id).map((x) => ont.label(x)),
|
|
77
|
+
children: ont.children(cl.id).map((x) => ont.label(x)), ownSlots: ont.ownSlots(cl.id).map((s) => ont.label(s)),
|
|
78
|
+
abstract: cl.abstract, terminological: cl.terminological, instances: ont.sources(cl.id, "INSTANCE_OF").length,
|
|
79
|
+
}));
|
|
80
|
+
return { step: ont.step, scope: ont.meta, judgmentRules: items, classes, decisions: ont.ofType("DesignDecision") };
|
|
81
|
+
}
|
|
82
|
+
/** `okb source outline`: the document's blocks and which lines already have a quote. */
|
|
83
|
+
export function outline(ont, sourceRef, o) {
|
|
84
|
+
const src = ont.find(sourceRef, "Source");
|
|
85
|
+
if (src.format !== "markdown")
|
|
86
|
+
throw new OkbError("outline works on markdown sources.");
|
|
87
|
+
const doc = prov.readMarkdownSource(ont, src);
|
|
88
|
+
const quoted = new Map();
|
|
89
|
+
for (const id of ont.sources(src.id, "PART_OF")) {
|
|
90
|
+
const l = ont.get(id);
|
|
91
|
+
if (l?.type !== "SourceLocation" || l.startLine === undefined)
|
|
92
|
+
continue;
|
|
93
|
+
const { startLine, endLine } = l;
|
|
94
|
+
for (let n = startLine; n <= (endLine ?? startLine); n++)
|
|
95
|
+
quoted.set(n, [...(quoted.get(n) ?? []), id]);
|
|
96
|
+
}
|
|
97
|
+
const blocks = doc.blocks.filter((b) => !o.quotable || b.quotable);
|
|
98
|
+
const data = () => ({
|
|
99
|
+
source: src.id, title: doc.title, frontmatter: doc.frontmatter, problems: doc.problems,
|
|
100
|
+
blocks: blocks.map((b) => ({ index: b.index, kind: b.kind, headingPath: b.headingPath, lines: [b.startLine, b.endLine], quotable: b.quotable, note: b.note, calloutType: b.calloutType, row: b.row, text: b.kind === "code" ? undefined : b.text, alreadyQuoted: [...new Set(Array.from({ length: b.endLine - b.startLine + 1 }, (_, k) => quoted.get(b.startLine + k) ?? []).flat())] })),
|
|
101
|
+
});
|
|
102
|
+
return { src, doc, blocks, quoted, data };
|
|
103
|
+
}
|
|
104
|
+
/** `okb source refresh --all`: re-check every quote against its document, and write only when something moved. */
|
|
105
|
+
export async function refreshAll(dir, o) {
|
|
106
|
+
const ont = Ontology.load(dir);
|
|
107
|
+
const pages = await loadSourcePages(ont);
|
|
108
|
+
const w = { write: !o.dryRun, record: !!o.record && !o.dryRun };
|
|
109
|
+
let report = resync(ont, pages, { write: false, record: false });
|
|
110
|
+
// Take the lock only when something has to be written.
|
|
111
|
+
if (w.write && (report.moved.length || w.record)) {
|
|
112
|
+
report = Ontology.edit(dir, (locked) => {
|
|
113
|
+
const r = locked.tick(() => resync(locked, pages, w));
|
|
114
|
+
locked.save();
|
|
115
|
+
return r;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return { report, write: w.write };
|
|
119
|
+
}
|
|
120
|
+
/** `okb drift`: near-duplicate quotes across the ontologies in these folders. */
|
|
121
|
+
export function drift(folders) {
|
|
122
|
+
const onts = (folders.length ? folders : ["."]).map((d) => Ontology.load(d));
|
|
123
|
+
const merged = Ontology.fromData(onts.flatMap((o) => o.nodes.filter((n) => n.type !== "Ontology")), onts.flatMap((o) => o.edges));
|
|
124
|
+
return duplicateQuotes(merged);
|
|
125
|
+
}
|
|
126
|
+
/** `okb release <version>`: run the checks and cut the release under the lock. */
|
|
127
|
+
export function release(dir, version) {
|
|
128
|
+
return Ontology.edit(dir, async (ont) => {
|
|
129
|
+
const findings = runChecks(ont, { all: false }, { pages: await loadSourcePages(ont) }).findings;
|
|
130
|
+
return cutRelease(ont, version, findings);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/** `okb pin`: record the installed okb version in okb.json. */
|
|
134
|
+
export function pin(dir) {
|
|
135
|
+
Ontology.edit(dir, (ont) => {
|
|
136
|
+
ont.manifest.okbVersion = PACKAGE_VERSION;
|
|
137
|
+
ont.save();
|
|
138
|
+
});
|
|
139
|
+
return PACKAGE_VERSION;
|
|
140
|
+
}
|
|
141
|
+
/** `okb check`. */
|
|
142
|
+
export async function check(ont) {
|
|
143
|
+
return runCheck(ont, PACKAGE_VERSION);
|
|
144
|
+
}
|
|
145
|
+
/** `okb docs`: the reference pages, the changed-since-<ref> view, or the rules-in-context page. */
|
|
146
|
+
export async function docs(dir, outDir, o) {
|
|
147
|
+
const out = resolve(outDir);
|
|
148
|
+
if (o.context && (o.changed !== undefined || o.hops !== undefined))
|
|
149
|
+
throw new OkbError("--context is its own view of every rule; it doesn't combine with --changed or --hops.");
|
|
150
|
+
if (o.hops !== undefined && o.changed === undefined)
|
|
151
|
+
throw new OkbError("--hops adds neighbors to a --changed view; give --changed <ref> too.");
|
|
152
|
+
if (o.context) {
|
|
153
|
+
const ont = Ontology.load(dir);
|
|
154
|
+
return { files: writePages(out, { "rules-in-context.md": contextPage(ont, await loadSourcePages(ont)) }), what: "rules-in-context.md", hint: "" };
|
|
155
|
+
}
|
|
156
|
+
if (o.changed !== undefined) {
|
|
157
|
+
if (o.hops !== undefined && !/^\d+$/.test(o.hops))
|
|
158
|
+
throw new OkbError("--hops needs a whole number (0 or more).");
|
|
159
|
+
const hops = o.hops === undefined ? 0 : Number(o.hops);
|
|
160
|
+
const ont = Ontology.load(dir);
|
|
161
|
+
const old = loadSide(o.changed, dir);
|
|
162
|
+
const { pages, changes } = changedPageSet(kbDocs(old.ont), kbDocs(ont), hops);
|
|
163
|
+
const after = kbDocs(ont);
|
|
164
|
+
const report = resync(ont, await loadSourcePages(ont), { write: false, record: false });
|
|
165
|
+
const files = Object.fromEntries(pages.map((n) => [n, after[n]]));
|
|
166
|
+
files["changes.md"] = changesPage({ against: o.changed, name: ont.meta.name, changes, hops, resync: report });
|
|
167
|
+
const stale = report.gone.length + report.moved.length + report.worklist.length;
|
|
168
|
+
return {
|
|
169
|
+
files: writeChangedPages(out, files),
|
|
170
|
+
what: `${pages.length} changed ${pages.length === 1 ? "page" : "pages"} and changes.md (${stale} source ${stale === 1 ? "change" : "changes"} not yet in the KB)`,
|
|
171
|
+
hint: " (start at changes.md)",
|
|
172
|
+
extra: changes,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const files = writeKbDocs(Ontology.load(dir), out);
|
|
176
|
+
return { files, what: `${files.length} pages`, hint: " (start at index.md)" };
|
|
177
|
+
}
|
|
178
|
+
/** `okb diff <old> [<new>]`: each side a folder or a git ref; with one, the new side is the folder itself. */
|
|
179
|
+
export function diff(dir, oldRef, newRef) {
|
|
180
|
+
const a = loadSide(oldRef, dir);
|
|
181
|
+
const b = newRef ? loadSide(newRef, dir) : { ont: Ontology.load(dir), name: "working folder" };
|
|
182
|
+
return diffOntologies(a.ont, b.ont, a.name, b.name);
|
|
183
|
+
}
|
|
184
|
+
/** `okb release verify`: check the folder against its manifest.json (read-only). */
|
|
185
|
+
export function releaseVerify(dir) {
|
|
186
|
+
return verifyRelease(resolve(dir));
|
|
187
|
+
}
|
|
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. */
|
|
189
|
+
export function exportOntology(ont, o) {
|
|
190
|
+
const fmt = o.format ?? (o.out?.endsWith(".cypher") || o.out?.endsWith(".cql") ? "cypher" : "json");
|
|
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 });
|
|
239
|
+
}
|
|
240
|
+
/** `okb instance set`: move to other classes, assign values, change the description, in that order. */
|
|
241
|
+
export function setInstance(ont, name, o) {
|
|
242
|
+
const notes = [
|
|
243
|
+
...(o.of?.length ? ops.setInstanceClasses(ont, name, o.of) : []),
|
|
244
|
+
...(o.assignments.length ? ops.assign(ont, ont.find(name, "Instance").id, o.assignments) : []),
|
|
245
|
+
];
|
|
246
|
+
if (o.desc !== undefined)
|
|
247
|
+
notes.push(...ops.setInstanceDescription(ont, name, o.desc));
|
|
248
|
+
return notes;
|
|
249
|
+
}
|
|
250
|
+
/** `okb quote list`: every quote, or the quotes from one source. */
|
|
251
|
+
export function quotes(ont, sourceRef) {
|
|
252
|
+
const locs = ont.ofType("SourceLocation").filter((l) => !sourceRef || ont.targets(l.id, "PART_OF").includes(ont.find(sourceRef, "Source").id));
|
|
253
|
+
return { locs, data: () => locs.map((l) => ({ ...l, citedBy: ont.sources(l.id, "CITES") })) };
|
|
254
|
+
}
|
|
255
|
+
/** `okb explain <topic>`: what matches, with the citations and rationale `--json` adds. */
|
|
256
|
+
export function explainData(hits) {
|
|
257
|
+
const meta = MetaKB.get();
|
|
258
|
+
return hits.map((h) => ({ ...h, citations: meta.citations(h.id), rationale: h.type === "Rule" ? meta.rationale(h) : undefined }));
|
|
259
|
+
}
|
|
260
|
+
/** `okb version`. */
|
|
261
|
+
export const versionLine = () => `okb ${PACKAGE_VERSION} · meta-KB ${MetaKB.get().version}`;
|
|
262
|
+
/** `okb skills install` and `okb skills status`, for the packaged skills and this meta-KB version. */
|
|
263
|
+
export function skillsInstallReport(o) {
|
|
264
|
+
return installSkills({ dir: o.dir, metaVersion: MetaKB.get().version, copy: o.copy, force: o.force, interactive: o.interactive, ask: o.ask });
|
|
265
|
+
}
|
|
266
|
+
export function skillsStatusReport(o) {
|
|
267
|
+
const metaVersion = MetaKB.get().version;
|
|
268
|
+
const { dir, skills } = skillsStatus({ dir: o.dir, metaVersion });
|
|
269
|
+
return { dir, skills, metaVersion, allCurrent: skills.every((s) => s.state === "current") };
|
|
270
|
+
}
|
package/meta-kb/data/edges.json
CHANGED
|
@@ -1989,6 +1989,21 @@
|
|
|
1989
1989
|
"type": "GOVERNS",
|
|
1990
1990
|
"to": "concept.competency-question"
|
|
1991
1991
|
},
|
|
1992
|
+
{
|
|
1993
|
+
"from": "rule.scope-cq-expected-answer",
|
|
1994
|
+
"type": "JUSTIFIED_BY",
|
|
1995
|
+
"to": "rat.scope-cq-expected-answer"
|
|
1996
|
+
},
|
|
1997
|
+
{
|
|
1998
|
+
"from": "rat.scope-cq-expected-answer",
|
|
1999
|
+
"type": "CITES",
|
|
2000
|
+
"to": "loc.o101.cq-litmus"
|
|
2001
|
+
},
|
|
2002
|
+
{
|
|
2003
|
+
"from": "rule.scope-cq-expected-answer",
|
|
2004
|
+
"type": "GOVERNS",
|
|
2005
|
+
"to": "concept.competency-question"
|
|
2006
|
+
},
|
|
1992
2007
|
{
|
|
1993
2008
|
"from": "rule.scope-no-unneeded",
|
|
1994
2009
|
"type": "JUSTIFIED_BY",
|
|
@@ -2144,6 +2159,16 @@
|
|
|
2144
2159
|
"type": "GOVERNS",
|
|
2145
2160
|
"to": "concept.lpg"
|
|
2146
2161
|
},
|
|
2162
|
+
{
|
|
2163
|
+
"from": "rule.struct-no-save-leftovers",
|
|
2164
|
+
"type": "JUSTIFIED_BY",
|
|
2165
|
+
"to": "rat.struct-no-save-leftovers"
|
|
2166
|
+
},
|
|
2167
|
+
{
|
|
2168
|
+
"from": "rule.struct-no-save-leftovers",
|
|
2169
|
+
"type": "GOVERNS",
|
|
2170
|
+
"to": "concept.lpg"
|
|
2171
|
+
},
|
|
2147
2172
|
{
|
|
2148
2173
|
"from": "rule.prov-verified",
|
|
2149
2174
|
"type": "JUSTIFIED_BY",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.8.1",
|
|
3
3
|
"formatVersion": "okb-lpg/3",
|
|
4
4
|
"nodeCounts": {
|
|
5
5
|
"MetaKB": 1,
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
"SourceLocation": 127,
|
|
8
8
|
"Principle": 7,
|
|
9
9
|
"Concept": 40,
|
|
10
|
-
"Rule":
|
|
11
|
-
"Rationale":
|
|
10
|
+
"Rule": 59,
|
|
11
|
+
"Rationale": 59,
|
|
12
12
|
"Decision": 10,
|
|
13
13
|
"Step": 8,
|
|
14
14
|
"NodeType": 11,
|
|
15
15
|
"EdgeType": 14
|
|
16
16
|
},
|
|
17
|
-
"edgeCount":
|
|
17
|
+
"edgeCount": 639,
|
|
18
18
|
"quotesVerified": true
|
|
19
19
|
}
|