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