@ontology-kit/okb 0.1.0 → 0.3.0-alpha.133
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/check.d.ts +43 -0
- package/dist/check.js +102 -0
- package/dist/checks.d.ts +1 -1
- package/dist/checks.js +27 -4
- package/dist/cli.js +11 -705
- package/dist/clidocs.d.ts +0 -2
- package/dist/clidocs.js +5 -27
- package/dist/clock.js +1 -1
- package/dist/command-table.d.ts +144 -0
- package/dist/command-table.js +85 -0
- package/dist/commands/documents.d.ts +3 -0
- package/dist/commands/documents.js +250 -0
- package/dist/commands/getting-started.d.ts +3 -0
- package/dist/commands/getting-started.js +135 -0
- package/dist/commands/housekeeping.d.ts +3 -0
- package/dist/commands/housekeeping.js +203 -0
- package/dist/commands/modeling.d.ts +3 -0
- package/dist/commands/modeling.js +467 -0
- package/dist/commands/planning.d.ts +3 -0
- package/dist/commands/planning.js +251 -0
- package/dist/commands/reviewing.d.ts +3 -0
- package/dist/commands/reviewing.js +234 -0
- package/dist/commands/skills.d.ts +3 -0
- package/dist/commands/skills.js +53 -0
- package/dist/commands.d.ts +10 -22
- package/dist/commands.js +15 -622
- package/dist/cqanswer.d.ts +51 -0
- package/dist/cqanswer.js +76 -0
- package/dist/diff.d.ts +85 -0
- package/dist/diff.js +323 -0
- package/dist/export-changes.d.ts +40 -0
- package/dist/export-changes.js +115 -0
- package/dist/export-csv.d.ts +17 -0
- package/dist/export-csv.js +188 -0
- package/dist/export-eval-cases.d.ts +38 -0
- package/dist/export-eval-cases.js +40 -0
- package/dist/export.d.ts +34 -3
- package/dist/export.js +70 -12
- package/dist/families.d.ts +1 -1
- package/dist/families.js +1 -1
- package/dist/help.d.ts +11 -2
- package/dist/help.js +51 -57
- package/dist/kbdocs.d.ts +18 -0
- package/dist/kbdocs.js +393 -0
- package/dist/metakb.d.ts +1 -1
- package/dist/metakb.js +1 -1
- package/dist/naming.d.ts +2 -2
- package/dist/naming.js +2 -2
- package/dist/ontology-ref.d.ts +20 -0
- package/dist/ontology-ref.js +108 -0
- package/dist/ops/admin.d.ts +2 -2
- package/dist/ops/admin.js +26 -8
- package/dist/ops/classes.d.ts +1 -1
- package/dist/ops/classes.js +15 -7
- package/dist/ops/common.d.ts +12 -2
- package/dist/ops/common.js +3 -0
- package/dist/ops/instances.d.ts +2 -1
- package/dist/ops/instances.js +9 -3
- package/dist/ops/links.d.ts +2 -2
- package/dist/ops/links.js +3 -2
- package/dist/ops/naming.d.ts +1 -1
- package/dist/ops/naming.js +3 -1
- package/dist/ops/scope.d.ts +14 -3
- package/dist/ops/scope.js +38 -4
- package/dist/ops/slots.d.ts +1 -1
- package/dist/ops/slots.js +21 -8
- package/dist/ops/values.d.ts +1 -1
- package/dist/ops/values.js +5 -1
- package/dist/provenance.d.ts +5 -3
- package/dist/provenance.js +61 -19
- package/dist/release.d.ts +52 -0
- package/dist/release.js +337 -0
- package/dist/render.d.ts +88 -1
- package/dist/render.js +265 -3
- package/dist/resync.d.ts +98 -0
- package/dist/resync.js +234 -0
- package/dist/review.d.ts +1 -1
- package/dist/review.js +1 -1
- package/dist/reviewdocs.d.ts +42 -0
- package/dist/reviewdocs.js +263 -0
- package/dist/runner.d.ts +3 -0
- package/dist/runner.js +84 -0
- package/dist/skills.d.ts +19 -3
- package/dist/skills.js +130 -14
- package/dist/status.d.ts +1 -1
- package/dist/status.js +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/dist/verifynote.d.ts +19 -0
- package/dist/verifynote.js +93 -0
- package/dist/workflows.d.ts +283 -0
- package/dist/workflows.js +270 -0
- package/meta-kb/data/edges.json +25 -0
- package/meta-kb/data/manifest.json +5 -5
- package/meta-kb/data/nodes.json +46 -9
- package/package.json +9 -4
- package/schema/edge.schema.json +68 -0
- package/schema/edges.schema.json +9 -0
- package/schema/node.schema.json +914 -0
- package/schema/nodes.schema.json +9 -0
- package/schema/okb.schema.json +41 -0
- package/skills/build-domain-kb-from-docs/SKILL.md +21 -3
- package/skills/ontology-coach/SKILL.md +8 -4
- package/skills/ontology-maintainer/SKILL.md +152 -0
- package/skills/ontology-review/SKILL.md +4 -2
- package/skills/ontology-signoff/SKILL.md +182 -0
- package/templates/okb-check.yml +148 -0
- package/templates/pull_request_template.md +16 -0
package/dist/skills.d.ts
CHANGED
|
@@ -37,16 +37,32 @@ export declare function skillsStatus(opts: SkillsOptions): {
|
|
|
37
37
|
dir: string;
|
|
38
38
|
skills: SkillReport[];
|
|
39
39
|
};
|
|
40
|
+
/** Gives the answer to a question, or `undefined` when the input ended. Tests pass their own. */
|
|
41
|
+
export type Ask = (question: string) => Promise<string | undefined>;
|
|
42
|
+
/** Asks on the terminal, with `node:readline`. */
|
|
43
|
+
export declare const terminalAsk: Ask;
|
|
40
44
|
export interface InstallOptions extends SkillsOptions {
|
|
41
45
|
/** Copy the folders instead of linking to them. */
|
|
42
46
|
copy?: boolean;
|
|
43
|
-
/** Replace
|
|
47
|
+
/** Replace without asking. */
|
|
44
48
|
force?: boolean;
|
|
49
|
+
/** Where answers come from. The default reads the terminal. */
|
|
50
|
+
ask?: Ask;
|
|
51
|
+
/** Whether there is a person to ask. The default is that both stdin and stdout are terminals. */
|
|
52
|
+
interactive?: boolean;
|
|
53
|
+
/** The clock for the backup folder's name. */
|
|
54
|
+
now?: () => Date;
|
|
45
55
|
}
|
|
46
56
|
export interface InstallResult {
|
|
47
57
|
dir: string;
|
|
48
58
|
/** What happened to each skill, one sentence each. */
|
|
49
59
|
lines: string[];
|
|
60
|
+
/** Where each replaced folder was kept. */
|
|
61
|
+
backups: string[];
|
|
50
62
|
}
|
|
51
|
-
/**
|
|
52
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Installs the packaged skills. Checks everything first, so a refusal or a "no" changes nothing. Something that would be replaced and might
|
|
65
|
+
* lose something (an older or edited copy, a folder that isn't this skill, a link to somewhere else) is shown and the person is asked,
|
|
66
|
+
* once per skill. Without a terminal it is refused unless `force`. A replaced folder is kept in `<dir>.backup/`.
|
|
67
|
+
*/
|
|
68
|
+
export declare function installSkills(opts: InstallOptions): Promise<InstallResult>;
|
package/dist/skills.js
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { cpSync, lstatSync, existsSync, mkdirSync, readdirSync, readFileSync, readlinkSync, realpathSync, renameSync, rmSync, symlinkSync } from "node:fs";
|
|
7
7
|
import { homedir } from "node:os";
|
|
8
|
+
import { createInterface } from "node:readline";
|
|
8
9
|
import { dirname, join, resolve } from "node:path";
|
|
9
10
|
import { fileURLToPath } from "node:url";
|
|
10
|
-
import { OkbError } from "@ontology-kit/
|
|
11
|
+
import { OkbError } from "@ontology-kit/reader";
|
|
11
12
|
/** The skills in this package. From src/ and from dist/ the package root is one folder up. */
|
|
12
13
|
export const PACKAGED_SKILLS_DIR = join(dirname(dirname(fileURLToPath(import.meta.url))), "skills");
|
|
13
14
|
/** Where skills go when `--dir` is not given: `$OKB_SKILLS_DIR`, else `~/.claude/skills` (Cursor reads that folder too). */
|
|
@@ -81,18 +82,111 @@ export function skillsStatus(opts) {
|
|
|
81
82
|
const dir = resolve(opts.dir ?? defaultSkillsDir());
|
|
82
83
|
return { dir, skills: packagedSkills().map((n) => inspect(n, dir, opts.metaVersion)) };
|
|
83
84
|
}
|
|
84
|
-
/**
|
|
85
|
-
export
|
|
85
|
+
/** Asks on the terminal, with `node:readline`. */
|
|
86
|
+
export const terminalAsk = (question) => new Promise((done) => {
|
|
87
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
88
|
+
let answered = false;
|
|
89
|
+
rl.on("close", () => {
|
|
90
|
+
if (!answered)
|
|
91
|
+
done(undefined);
|
|
92
|
+
});
|
|
93
|
+
rl.question(question, (answer) => {
|
|
94
|
+
answered = true;
|
|
95
|
+
rl.close();
|
|
96
|
+
done(answer);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
/** Whether install must ask before replacing this: anything that isn't missing, current, a link to this okb or a broken link. */
|
|
100
|
+
function needsAsk(r) {
|
|
101
|
+
if (r.state === "foreign" || r.state === "modified" || r.state === "other-install")
|
|
102
|
+
return true;
|
|
103
|
+
return r.state === "stale" && r.how === "copy"; // a stale link into this okb loses nothing
|
|
104
|
+
}
|
|
105
|
+
/** Files that differ, only in the installed folder, only in the packaged one. */
|
|
106
|
+
function compare(found, source) {
|
|
107
|
+
const old = files(found);
|
|
108
|
+
const now = files(source);
|
|
109
|
+
return {
|
|
110
|
+
differ: old.filter((f) => now.includes(f) && !readFileSync(join(found, f)).equals(readFileSync(join(source, f)))),
|
|
111
|
+
onlyOld: old.filter((f) => !now.includes(f)),
|
|
112
|
+
onlyNew: now.filter((f) => !old.includes(f)),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** Where a replaced folder is kept: a sibling of the skills folder, since a host loads every folder in it that has a SKILL.md. */
|
|
116
|
+
const backupRoot = (dir) => `${dir}.backup`;
|
|
117
|
+
const stamp = (d) => d.toISOString().replace(/\.\d+Z$/, "Z").replace(/[-:]/g, "");
|
|
118
|
+
/** Moves `from` to `to`, copying when they are on different filesystems. */
|
|
119
|
+
function moveTo(from, to) {
|
|
120
|
+
mkdirSync(dirname(to), { recursive: true });
|
|
121
|
+
try {
|
|
122
|
+
renameSync(from, to);
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
if (err.code !== "EXDEV")
|
|
126
|
+
throw err;
|
|
127
|
+
cpSync(from, to, { recursive: true, verbatimSymlinks: true });
|
|
128
|
+
rmSync(from, { recursive: true, force: true });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/** What the person sees before the question: what is there, how it differs, what would change and what is kept. */
|
|
132
|
+
function explain(r, source, want, backup) {
|
|
133
|
+
const lines = [`${r.name}: ${r.path} is ${r.detail}.`];
|
|
134
|
+
let looked;
|
|
135
|
+
try {
|
|
136
|
+
looked = lstatSync(r.path).isSymbolicLink() ? realpathSync(r.path) : r.path;
|
|
137
|
+
if (!lstatSync(looked).isDirectory())
|
|
138
|
+
looked = undefined;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
looked = undefined;
|
|
142
|
+
}
|
|
143
|
+
if (looked) {
|
|
144
|
+
const d = compare(looked, source);
|
|
145
|
+
if (d.differ.length)
|
|
146
|
+
lines.push(` Files that differ from the packaged skill: ${d.differ.join(", ")}`);
|
|
147
|
+
if (d.onlyOld.length)
|
|
148
|
+
lines.push(` Files only in the installed folder (the packaged skill doesn't have them): ${d.onlyOld.join(", ")}`);
|
|
149
|
+
if (d.onlyNew.length)
|
|
150
|
+
lines.push(` Files only in the packaged skill (missing from the installed one): ${d.onlyNew.join(", ")}`);
|
|
151
|
+
if (!d.differ.length && !d.onlyOld.length && !d.onlyNew.length)
|
|
152
|
+
lines.push(" Its files are the same as the packaged skill's.");
|
|
153
|
+
}
|
|
154
|
+
lines.push(` It would be replaced with ${want === "copy" ? "a copy of" : "a link to"} ${source}.`);
|
|
155
|
+
lines.push(backup ? ` The old one is moved, not deleted, and kept in ${backup}.` : " A link needs no backup: only the link is replaced, and what it points to isn't touched.");
|
|
156
|
+
return lines.join("\n");
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Installs the packaged skills. Checks everything first, so a refusal or a "no" changes nothing. Something that would be replaced and might
|
|
160
|
+
* lose something (an older or edited copy, a folder that isn't this skill, a link to somewhere else) is shown and the person is asked,
|
|
161
|
+
* once per skill. Without a terminal it is refused unless `force`. A replaced folder is kept in `<dir>.backup/`.
|
|
162
|
+
*/
|
|
163
|
+
export async function installSkills(opts) {
|
|
86
164
|
const dir = resolve(opts.dir ?? defaultSkillsDir());
|
|
87
165
|
const want = opts.copy ? "copy" : "link";
|
|
166
|
+
const interactive = opts.interactive ?? (Boolean(process.stdin.isTTY) && Boolean(process.stdout.isTTY));
|
|
167
|
+
const ask = opts.ask ?? terminalAsk;
|
|
168
|
+
const at = stamp((opts.now ?? (() => new Date()))());
|
|
88
169
|
const before = packagedSkills().map((n) => inspect(n, dir, opts.metaVersion));
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
170
|
+
const toAsk = before.filter(needsAsk);
|
|
171
|
+
const backups = new Map();
|
|
172
|
+
for (const r of toAsk)
|
|
173
|
+
if (!lstatSync(r.path).isSymbolicLink())
|
|
174
|
+
backups.set(r.name, join(backupRoot(dir), `${r.name}-${at}`));
|
|
175
|
+
if (toAsk.length && !opts.force) {
|
|
176
|
+
if (!interactive) {
|
|
177
|
+
const why = toAsk.map((r) => ` ${r.path}: ${r.detail}`).join("\n");
|
|
178
|
+
const them = toAsk.length === 1 ? "it" : "them";
|
|
179
|
+
throw new OkbError(`Not installing: ${toAsk.length === 1 ? "this isn't" : "these aren't"} this package's to replace.\n${why}\nNothing was changed. Move ${them} away, run okb skills install in a terminal to be asked, or pass --force to replace ${them} and put the ${want === "copy" ? "copies" : "links"} in place. A replaced folder is kept in ${backupRoot(dir)}.`);
|
|
180
|
+
}
|
|
181
|
+
for (const r of toAsk) {
|
|
182
|
+
const answer = await ask(`${explain(r, join(PACKAGED_SKILLS_DIR, r.name), want, backups.get(r.name))}\nReplace it? (y/N) `);
|
|
183
|
+
if (!/^\s*(y|yes)\s*$/i.test(answer ?? ""))
|
|
184
|
+
throw new OkbError(`Not installing: the answer for ${r.name} wasn't y. Nothing was changed.`);
|
|
185
|
+
}
|
|
93
186
|
}
|
|
94
187
|
mkdirSync(dir, { recursive: true });
|
|
95
188
|
const lines = [];
|
|
189
|
+
const kept = [];
|
|
96
190
|
for (const r of before) {
|
|
97
191
|
const source = join(PACKAGED_SKILLS_DIR, r.name);
|
|
98
192
|
if (r.state === "current" && r.how === want) {
|
|
@@ -105,16 +199,38 @@ export function installSkills(opts) {
|
|
|
105
199
|
cpSync(source, tmp, { recursive: true });
|
|
106
200
|
else
|
|
107
201
|
symlinkSync(source, tmp, "junction");
|
|
108
|
-
|
|
109
|
-
if (lstatOrUndefined(r.path))
|
|
110
|
-
|
|
111
|
-
|
|
202
|
+
let note = "";
|
|
203
|
+
if (lstatOrUndefined(r.path)) {
|
|
204
|
+
// Move the old one aside, activate the new one, then dispose of the old: an interruption leaves one of them in place, never neither.
|
|
205
|
+
// Renaming a link moves the link, not its target.
|
|
206
|
+
const old = join(dir, `.${r.name}.okb-old-${process.pid}`);
|
|
207
|
+
rmSync(old, { recursive: true, force: true });
|
|
208
|
+
renameSync(r.path, old);
|
|
209
|
+
try {
|
|
210
|
+
renameSync(tmp, r.path);
|
|
211
|
+
}
|
|
212
|
+
catch (err) {
|
|
213
|
+
renameSync(old, r.path);
|
|
214
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
215
|
+
throw err;
|
|
216
|
+
}
|
|
217
|
+
const backup = backups.get(r.name);
|
|
218
|
+
if (backup) {
|
|
219
|
+
moveTo(old, backup);
|
|
220
|
+
kept.push(backup);
|
|
221
|
+
note = `; the old one is kept in ${backup}`;
|
|
222
|
+
}
|
|
223
|
+
else
|
|
224
|
+
rmSync(old, { recursive: true, force: true }); // on a link this removes the link, not its target
|
|
225
|
+
}
|
|
226
|
+
else
|
|
227
|
+
renameSync(tmp, r.path);
|
|
112
228
|
const verb = want === "copy" ? "copied" : "linked";
|
|
113
229
|
const replaced = {
|
|
114
|
-
missing: "", current: ` (was ${r.how === "link" ? "a link" : "a copy"})`, stale: ` (replaced ${r.how === "link" ? "an old link" : `a copy at version ${r.version}`})`,
|
|
115
|
-
modified:
|
|
230
|
+
missing: "", current: ` (was ${r.how === "link" ? "a link" : "a copy"})`, stale: ` (replaced ${r.how === "link" ? "an old link" : `a copy at version ${r.version}`}${note})`,
|
|
231
|
+
modified: ` (replaced a modified copy${note})`, "other-install": " (replaced a link to a different okb)", "broken-link": " (replaced a broken link)", foreign: ` (replaced what was there${note})`,
|
|
116
232
|
};
|
|
117
233
|
lines.push(`${r.name}: ${verb}${replaced[r.state]}`);
|
|
118
234
|
}
|
|
119
|
-
return { dir, lines };
|
|
235
|
+
return { dir, lines, backups: kept };
|
|
120
236
|
}
|
package/dist/status.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Ontology } from "@ontology-kit/
|
|
1
|
+
import { type Ontology } from "@ontology-kit/reader";
|
|
2
2
|
import { type Finding } from "./types.js";
|
|
3
3
|
type StepCheck = (ont: Ontology, all: Finding[]) => boolean;
|
|
4
4
|
export declare const STEP_CHECKS: Record<string, StepCheck>;
|
package/dist/status.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { MIN_COMPETENCY_QUESTIONS, runChecks } from "./checks.js";
|
|
7
7
|
import { MetaKB } from "./metakb.js";
|
|
8
|
-
import {} from "@ontology-kit/
|
|
8
|
+
import {} from "@ontology-kit/reader";
|
|
9
9
|
import {} from "./types.js";
|
|
10
10
|
/** Step 3's brainstorm should reach this many terms before sorting them into classes and slots. */
|
|
11
11
|
const MIN_TERMS = 10;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Small types and guards that only okb needs (the file format's own types are in @ontology-kit/
|
|
1
|
+
/** Small types and guards that only okb needs (the file format's own types are in @ontology-kit/reader). */
|
|
2
2
|
/** Narrows a string from the command line or a file to one of a fixed set of values. */
|
|
3
3
|
export declare function isOneOf<T extends string>(values: readonly T[], v: string | undefined): v is T;
|
|
4
4
|
export type Severity = "error" | "warning" | "info";
|
package/dist/types.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Small types and guards that only okb needs (the file format's own types are in @ontology-kit/
|
|
1
|
+
/** Small types and guards that only okb needs (the file format's own types are in @ontology-kit/reader). */
|
|
2
2
|
/** Narrows a string from the command line or a file to one of a fixed set of values. */
|
|
3
3
|
export function isOneOf(values, v) {
|
|
4
4
|
return values.includes(v);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Modality } from "@ontology-kit/reader";
|
|
2
|
+
import { type Notes } from "./ops/common.js";
|
|
3
|
+
/**
|
|
4
|
+
* One sentence naming what changed: a modality, a number, or a few words. Null when the difference
|
|
5
|
+
* can't be named this way (a rewording, or a change too big to list), so the caller falls back to the
|
|
6
|
+
* generic tip.
|
|
7
|
+
*/
|
|
8
|
+
export declare function suggestNote(original: string, corrected: string): string | null;
|
|
9
|
+
/**
|
|
10
|
+
* The one modality a statement states in capitals (`... SHOULD be ...` is SHOULD, `MUST NOT` is MUST_NOT), or null
|
|
11
|
+
* when it states none or more than one. Lower-case "may" or "should" is ordinary prose and doesn't count.
|
|
12
|
+
*/
|
|
13
|
+
export declare function statedModality(statement: string): Modality | null;
|
|
14
|
+
/** A double-quoted shell argument. */
|
|
15
|
+
export declare const shellQuote: (s: string) => string;
|
|
16
|
+
export declare const GENERIC_NOTE_TIP: import("./ops/common.js").Tip;
|
|
17
|
+
export declare const UNSUPPORTED_NOTE_TIP: import("./ops/common.js").Tip;
|
|
18
|
+
/** Lines to print after OVERREACH with no --note. */
|
|
19
|
+
export declare function overreachNoteTips(id: string, original: string, corrected: string, extra: string): Notes;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { tip } from "./ops/common.js";
|
|
2
|
+
const MODALITY = /\b(MUST\s+NOT|SHOULD\s+NOT|MUST|SHOULD|MAY)\b/gi;
|
|
3
|
+
const keyword = (m) => m.toUpperCase().replace(/\s+/g, " ");
|
|
4
|
+
const NUMBER = /\d+(?:[.,]\d+)*/g;
|
|
5
|
+
const WORD = /[\p{L}'-]+/gu;
|
|
6
|
+
/** Strongest first, so a drop in rank reads as narrowing. */
|
|
7
|
+
const RANK = ["MUST NOT", "MUST", "SHOULD NOT", "SHOULD", "MAY"];
|
|
8
|
+
/** A diff longer than this is a rewrite, and a list of words wouldn't name it. */
|
|
9
|
+
const MAX_WORDS = 4;
|
|
10
|
+
const found = (text, re) => [...text.matchAll(re)].map((m) => m[0]);
|
|
11
|
+
const quote = (words) => words.map((w) => `"${w}"`).join(", ");
|
|
12
|
+
/** Items in `a` that `b` doesn't have, counting repeats. */
|
|
13
|
+
function without(a, b) {
|
|
14
|
+
const left = [...b];
|
|
15
|
+
return a.filter((x) => {
|
|
16
|
+
const i = left.indexOf(x);
|
|
17
|
+
if (i < 0)
|
|
18
|
+
return true;
|
|
19
|
+
left.splice(i, 1);
|
|
20
|
+
return false;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** Words minus the modality and number tokens, which the other parts of the suggestion name. */
|
|
24
|
+
function plainWords(text) {
|
|
25
|
+
return found(text.replace(MODALITY, " ").replace(NUMBER, " "), WORD).map((w) => w.toLowerCase());
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* One sentence naming what changed: a modality, a number, or a few words. Null when the difference
|
|
29
|
+
* can't be named this way (a rewording, or a change too big to list), so the caller falls back to the
|
|
30
|
+
* generic tip.
|
|
31
|
+
*/
|
|
32
|
+
export function suggestNote(original, corrected) {
|
|
33
|
+
const parts = [];
|
|
34
|
+
const m0 = found(original, MODALITY).map(keyword);
|
|
35
|
+
const m1 = found(corrected, MODALITY).map(keyword);
|
|
36
|
+
if (m0.length && m0.length === m1.length) {
|
|
37
|
+
const i = m0.findIndex((m, k) => m !== m1[k]);
|
|
38
|
+
if (i >= 0) {
|
|
39
|
+
const [r0, r1] = [RANK.indexOf(m0[i]), RANK.indexOf(m1[i])];
|
|
40
|
+
// MUST NOT to MUST (or the other way) flips the meaning; it is neither narrower nor stronger.
|
|
41
|
+
const flips = m0[i].endsWith("NOT") !== m1[i].endsWith("NOT");
|
|
42
|
+
parts.push(`${flips ? "changed" : r1 > r0 ? "narrowed" : "strengthened"} ${m0[i]} to ${m1[i]}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else if (m0.join() !== m1.join())
|
|
46
|
+
return null;
|
|
47
|
+
const n0 = found(original, NUMBER);
|
|
48
|
+
const n1 = found(corrected, NUMBER);
|
|
49
|
+
const goneN = without(n0, n1);
|
|
50
|
+
const newN = without(n1, n0);
|
|
51
|
+
if (goneN.length && goneN.length === newN.length)
|
|
52
|
+
parts.push(`changed ${goneN.join(", ")} to ${newN.join(", ")}`);
|
|
53
|
+
else {
|
|
54
|
+
if (goneN.length)
|
|
55
|
+
parts.push(`removed ${goneN.join(", ")}`);
|
|
56
|
+
if (newN.length)
|
|
57
|
+
parts.push(`added ${newN.join(", ")}`);
|
|
58
|
+
}
|
|
59
|
+
const w0 = plainWords(original);
|
|
60
|
+
const w1 = plainWords(corrected);
|
|
61
|
+
const goneW = without(w0, w1);
|
|
62
|
+
const newW = without(w1, w0);
|
|
63
|
+
if (goneW.length > MAX_WORDS || newW.length > MAX_WORDS)
|
|
64
|
+
return null;
|
|
65
|
+
if (goneW.length && newW.length && goneW.length === newW.length && goneW.length <= 2)
|
|
66
|
+
parts.push(`replaced ${quote(goneW)} with ${quote(newW)}`);
|
|
67
|
+
else {
|
|
68
|
+
if (goneW.length)
|
|
69
|
+
parts.push(`removed ${quote(goneW)}`);
|
|
70
|
+
if (newW.length)
|
|
71
|
+
parts.push(`added ${quote(newW)}`);
|
|
72
|
+
}
|
|
73
|
+
return parts.length ? parts.join("; ") : null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The one modality a statement states in capitals (`... SHOULD be ...` is SHOULD, `MUST NOT` is MUST_NOT), or null
|
|
77
|
+
* when it states none or more than one. Lower-case "may" or "should" is ordinary prose and doesn't count.
|
|
78
|
+
*/
|
|
79
|
+
export function statedModality(statement) {
|
|
80
|
+
const found = new Set([...statement.matchAll(/\b(MUST\s+NOT|SHOULD\s+NOT|MUST|SHOULD|MAY)\b/g)].map((m) => m[1].replace(/\s+/g, "_")));
|
|
81
|
+
return found.size === 1 ? [...found][0] : null;
|
|
82
|
+
}
|
|
83
|
+
/** A double-quoted shell argument. */
|
|
84
|
+
export const shellQuote = (s) => `"${s.replace(/(["\\$`])/g, "\\$1")}"`;
|
|
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.');
|
|
87
|
+
/** Lines to print after OVERREACH with no --note. */
|
|
88
|
+
export function overreachNoteTips(id, original, corrected, extra) {
|
|
89
|
+
const s = suggestNote(original, corrected);
|
|
90
|
+
if (!s)
|
|
91
|
+
return [GENERIC_NOTE_TIP];
|
|
92
|
+
return [`Suggested note: ${s}`, `To store it: okb verify ${id} --status OVERREACH --corrected ${shellQuote(corrected)} --note ${shellQuote(s)}${extra}`];
|
|
93
|
+
}
|
|
@@ -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
|
+
};
|