@ontology-kit/okb 0.3.0-alpha.66 → 0.3.0
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/commands/reviewing.js +20 -5
- package/dist/commands/skills.js +6 -5
- package/dist/export-eval-cases.d.ts +38 -0
- package/dist/export-eval-cases.js +40 -0
- package/dist/render.d.ts +11 -0
- package/dist/render.js +5 -0
- package/dist/skills.d.ts +19 -3
- package/dist/skills.js +129 -13
- package/dist/workflows.d.ts +4 -1
- package/dist/workflows.js +1 -1
- package/meta-kb/data/manifest.json +1 -1
- package/meta-kb/data/nodes.json +1 -1
- package/package.json +2 -2
- package/skills/build-domain-kb-from-docs/SKILL.md +2 -2
- package/skills/ontology-coach/SKILL.md +2 -2
- 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
|
@@ -3,7 +3,8 @@ import { opt } from "../command-table.js";
|
|
|
3
3
|
import { OkbError, query } from "@ontology-kit/reader";
|
|
4
4
|
import * as ops from "../ops.js";
|
|
5
5
|
import { buildReview } from "../review.js";
|
|
6
|
-
import { mermaid, renderDecisions, renderQueryResult, renderChangeSetWritten, renderDiagramWritten, renderExportWritten, renderReview, renderWrote } from "../render.js";
|
|
6
|
+
import { mermaid, renderDecisions, renderQueryResult, renderChangeSetWritten, renderDiagramWritten, renderEvalCasesWritten, renderExportWritten, renderReview, renderWrote } from "../render.js";
|
|
7
|
+
import { exportEvalCases } from "../export-eval-cases.js";
|
|
7
8
|
import { docs, exportOntology, reviewData } from "../workflows.js";
|
|
8
9
|
const { str, strs, bool } = opt;
|
|
9
10
|
export const reviewing = [
|
|
@@ -102,14 +103,14 @@ export const reviewing = [
|
|
|
102
103
|
{
|
|
103
104
|
name: "export",
|
|
104
105
|
group: "Reviewing and sharing",
|
|
105
|
-
summary: "write JSON, openCypher or
|
|
106
|
-
description: "Writes the ontology as JSON, as openCypher, or as CSV files for the Neo4j and Neptune bulk loaders (okb writes files and never connects to a database). Instances become nodes labeled with their classes.",
|
|
106
|
+
summary: "write JSON, openCypher, CSV or eval cases",
|
|
107
|
+
description: "Writes the ontology as JSON, as openCypher, or as CSV files for the Neo4j and Neptune bulk loaders (okb writes files and never connects to a database). Instances become nodes labeled with their classes. `--format eval-cases` writes the competency questions as cases for an evaluation runner instead.",
|
|
107
108
|
forms: [
|
|
108
109
|
{
|
|
109
110
|
description: "Prints the export, or writes it to a file.",
|
|
110
|
-
examples: ["okb export --format cypher --out wine.cypher", "okb export --format neo4j-csv --out wine-neo4j", "okb export --format cypher --since 1.0.0 --out wine-1.1.0.cypher"],
|
|
111
|
+
examples: ["okb export --format cypher --out wine.cypher", "okb export --format neo4j-csv --out wine-neo4j", "okb export --format cypher --since 1.0.0 --out wine-1.1.0.cypher", "okb export --format eval-cases --out eval-cases.json"],
|
|
111
112
|
args: [
|
|
112
|
-
["--format", "json, cypher, neo4j-csv or
|
|
113
|
+
["--format", "json, cypher, neo4j-csv, neptune-csv or eval-cases", "The output format. Defaults to json. `eval-cases` writes one JSON file of cases, one per competency question that has a stored answer (`okb cq answer`), with the question, the expected names, the nodes it needs, the stored query and the released version (`okb release`) the cases came from; questions with no stored answer are listed under `skipped`, and no other flag applies. The two CSV formats are bulk-loader files (`neo4j-admin database import`, Neptune bulk loader) and write several files into the folder --out names."],
|
|
113
114
|
["--out", "path", "Write to this file instead of printing. For neo4j-csv and neptune-csv it is a folder, which is required."],
|
|
114
115
|
["--style", "batched or simple", "For cypher: batched (default) is a constraint plus UNWIND/MERGE batches you can load again; simple is one readable CREATE per node and edge, for an empty database."],
|
|
115
116
|
["--since", "release or git ref", "For cypher: write a change set instead of a full load. It moves a database loaded from that earlier release to this folder's release: MERGE for what was added or changed, removed properties, DETACH DELETE for removed nodes and deletes for removed relationships, behind a guard that stops before changing anything unless the database's (:OkbRelease) node holds that version. The folder must be at its latest release (`okb release`). Use the same flags as the full export."],
|
|
@@ -122,6 +123,20 @@ export const reviewing = [
|
|
|
122
123
|
cheat: { example: "okb export --format cypher --out wine.cypher", description: "Export for a graph database" },
|
|
123
124
|
run: (ctx) => {
|
|
124
125
|
const o = ctx.opts;
|
|
126
|
+
if (o.format === "eval-cases") {
|
|
127
|
+
const extra = ["style", "since", "with-schema", "no-inherited", "no-rules", "include-unverified"].filter((k) => o[k] !== undefined && o[k] !== false);
|
|
128
|
+
if (extra.length)
|
|
129
|
+
throw new OkbError(`--format eval-cases doesn't take ${extra.map((k) => "--" + k).join(", ")}.`);
|
|
130
|
+
const cases = exportEvalCases(ctx.load());
|
|
131
|
+
const text = JSON.stringify(cases, null, 2) + "\n";
|
|
132
|
+
if (o.out) {
|
|
133
|
+
ctx.write(o.out, text);
|
|
134
|
+
ctx.print(renderEvalCasesWritten(o.out, cases));
|
|
135
|
+
}
|
|
136
|
+
else
|
|
137
|
+
ctx.printRaw(text);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
125
140
|
const { fmt, graph, text, files, changes } = exportOntology(ctx.load(), { format: o.format, out: o.out, style: o.style, since: o.since, schema: o["with-schema"], noInherited: o["no-inherited"], noRules: o["no-rules"], includeUnverified: o["include-unverified"] });
|
|
126
141
|
if (o.out && files) {
|
|
127
142
|
for (const [name, body] of Object.entries(files))
|
package/dist/commands/skills.js
CHANGED
|
@@ -14,20 +14,21 @@ export const skills = [
|
|
|
14
14
|
forms: [
|
|
15
15
|
{
|
|
16
16
|
sub: "install",
|
|
17
|
-
description: "Links the
|
|
17
|
+
description: "Links the skills into `~/.claude/skills/` (a link keeps them current when the package updates), or copies them. A skill that isn't there, a copy identical to okb's, a link to this okb and a broken link are handled without a question. For anything else that is there (an older or edited copy, a folder that isn't one of okb's skills, a link to somewhere else) it shows what it found and which files differ, and asks `Replace it? (y/N)`. Only `y` or `yes` continues; anything else leaves everything untouched and exits with code 2. The old folder is kept in `<skills folder>.backup/<skill>-<UTC time>/` (a link needs no backup). It asks only in a terminal; in a script, CI or an agent it refuses and changes nothing unless you pass `--force`. Every check runs before anything changes, so a no for one skill stops the whole run.",
|
|
18
18
|
examples: ["okb skills install", "okb skills install --copy", "okb skills install --dir ~/.cursor/skills"],
|
|
19
19
|
args: [
|
|
20
20
|
["--copy", "flag", "Copy the skill folders instead of linking to them. Run it again after you update okb."],
|
|
21
21
|
["--dir", "path", "The skills folder to use instead of `~/.claude/skills/`. The `OKB_SKILLS_DIR` environment variable sets it too."],
|
|
22
|
-
["--force", "flag", "
|
|
22
|
+
["--force", "flag", "Replace without asking, for scripts and CI. The old folder is still kept in the backup folder."],
|
|
23
23
|
],
|
|
24
24
|
options: { copy: bool, dir: str, force: bool },
|
|
25
25
|
usage: SKILLS_USAGE,
|
|
26
26
|
max: 0,
|
|
27
27
|
cheat: { example: "okb skills install", description: "Install the Claude skills that ship with okb" },
|
|
28
|
-
run: (ctx) => {
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
run: async (ctx) => {
|
|
29
|
+
// --json output can't carry a question, so it behaves as if there were no terminal.
|
|
30
|
+
const { dir, lines, backups } = await skillsInstallReport({ dir: ctx.opts.dir, copy: ctx.opts.copy, force: ctx.opts.force, interactive: ctx.json ? false : undefined });
|
|
31
|
+
ctx.emit(() => ({ dir, lines, backups }), () => renderSkillsInstall(dir, lines));
|
|
31
32
|
},
|
|
32
33
|
},
|
|
33
34
|
{
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Ontology } from "@ontology-kit/reader";
|
|
2
|
+
export declare const EVAL_CASES_FORMAT = "okb-eval-cases/1";
|
|
3
|
+
export interface EvalNeed {
|
|
4
|
+
id: string;
|
|
5
|
+
type: string;
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
8
|
+
export interface EvalCase {
|
|
9
|
+
id: string;
|
|
10
|
+
number: number;
|
|
11
|
+
question: string;
|
|
12
|
+
/** The stored query (see "Expected answers" in docs/FORMAT.md). */
|
|
13
|
+
query: Record<string, unknown>;
|
|
14
|
+
/** The names a correct answer holds. */
|
|
15
|
+
expect: string[];
|
|
16
|
+
match: "exact" | "includes";
|
|
17
|
+
/** The classes, slots and instances the question needs: what a correct answer should retrieve. */
|
|
18
|
+
needs: EvalNeed[];
|
|
19
|
+
}
|
|
20
|
+
export interface EvalCases {
|
|
21
|
+
format: typeof EVAL_CASES_FORMAT;
|
|
22
|
+
kb: {
|
|
23
|
+
name: string;
|
|
24
|
+
/** The release's id (from manifest.json), or null before the first release. */
|
|
25
|
+
id: string | null;
|
|
26
|
+
/** The released version these cases were exported from, or null before the first release. */
|
|
27
|
+
version: string | null;
|
|
28
|
+
};
|
|
29
|
+
cases: EvalCase[];
|
|
30
|
+
skipped: {
|
|
31
|
+
id: string;
|
|
32
|
+
number: number;
|
|
33
|
+
question: string;
|
|
34
|
+
reason: string;
|
|
35
|
+
}[];
|
|
36
|
+
notes: string[];
|
|
37
|
+
}
|
|
38
|
+
export declare function exportEvalCases(ont: Ontology): EvalCases;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `okb export --format eval-cases`: the competency questions as cases an evaluation runner can load
|
|
3
|
+
* (decision 0036). A case is a question, the names a correct answer holds, the nodes the question needs
|
|
4
|
+
* (the facts a correct answer should retrieve) and the stored query that produces the names. A question
|
|
5
|
+
* with no stored answer isn't a case: it is listed under `skipped`, so a runner never scores a question
|
|
6
|
+
* that has no answer to compare with. The file names the KB and its released version, so a runner can
|
|
7
|
+
* serve that release and check it served the right one. It reads the ontology and never writes it.
|
|
8
|
+
*/
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { OkbError } from "@ontology-kit/reader";
|
|
11
|
+
import { MANIFEST_FILE, readReleaseManifest, verifyRelease } from "./release.js";
|
|
12
|
+
export const EVAL_CASES_FORMAT = "okb-eval-cases/1";
|
|
13
|
+
export function exportEvalCases(ont) {
|
|
14
|
+
const version = ont.manifest.version ?? null;
|
|
15
|
+
const manifestFile = join(ont.root, MANIFEST_FILE);
|
|
16
|
+
let id = null;
|
|
17
|
+
if (version) {
|
|
18
|
+
// A KB that names a version must have the release's manifest: verifyRelease throws when it is missing.
|
|
19
|
+
const v = verifyRelease(ont.root);
|
|
20
|
+
if (!v.ok)
|
|
21
|
+
throw new OkbError(`The folder has changed since release ${version} (${v.problems[0]}), so cases exported now would name a version the files don't match. Cut a release first (okb release <version>), then export.`);
|
|
22
|
+
id = readReleaseManifest(manifestFile).id;
|
|
23
|
+
}
|
|
24
|
+
const notes = version ? [] : ["This KB has no release yet, so the cases name no version. Cut one with `okb release <version>` so a runner can pin what it queries."];
|
|
25
|
+
const cases = [];
|
|
26
|
+
const skipped = [];
|
|
27
|
+
for (const q of ont.numbered("CompetencyQuestion")) {
|
|
28
|
+
const number = ont.displayNumber(q);
|
|
29
|
+
if (!q.answer) {
|
|
30
|
+
skipped.push({ id: q.id, number, question: q.text, reason: "no stored answer (okb cq answer)" });
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const needs = ont.targets(q.id, "NEEDS").map((t) => {
|
|
34
|
+
const n = ont.require(t);
|
|
35
|
+
return { id: n.id, type: n.type, name: ont.label(t) };
|
|
36
|
+
});
|
|
37
|
+
cases.push({ id: q.id, number, question: q.text, query: q.answer.query, expect: q.answer.expect, match: q.answer.match ?? "exact", needs });
|
|
38
|
+
}
|
|
39
|
+
return { format: EVAL_CASES_FORMAT, kb: { name: ont.meta.name || ont.manifest.name || "", id, version }, cases, skipped, notes };
|
|
40
|
+
}
|
package/dist/render.d.ts
CHANGED
|
@@ -101,6 +101,17 @@ export declare function renderExportWritten(out: string, g: {
|
|
|
101
101
|
relationships: unknown[];
|
|
102
102
|
notes: string[];
|
|
103
103
|
}, fmt: string, files?: string[]): string[];
|
|
104
|
+
/** `okb export --format eval-cases` written to a file. */
|
|
105
|
+
export declare function renderEvalCasesWritten(out: string, e: {
|
|
106
|
+
kb: {
|
|
107
|
+
version: string | null;
|
|
108
|
+
};
|
|
109
|
+
cases: unknown[];
|
|
110
|
+
skipped: {
|
|
111
|
+
number: number;
|
|
112
|
+
}[];
|
|
113
|
+
notes: string[];
|
|
114
|
+
}): string[];
|
|
104
115
|
/** `okb query` as text: one line per hit, the kind in a heading. */
|
|
105
116
|
export declare function renderQueryResult(ont: Ontology, r: QueryResult): string[];
|
|
106
117
|
export {};
|
package/dist/render.js
CHANGED
|
@@ -652,6 +652,11 @@ export function renderExportWritten(out, g, fmt, files) {
|
|
|
652
652
|
const where = files ? `${out}/ (${files.join(", ")})` : out;
|
|
653
653
|
return [`Wrote ${where}: ${g.nodes.length} nodes, ${g.relationships.length} relationships (${fmt}).`, ...g.notes.map((n) => c.dim(" " + n))];
|
|
654
654
|
}
|
|
655
|
+
/** `okb export --format eval-cases` written to a file. */
|
|
656
|
+
export function renderEvalCasesWritten(out, e) {
|
|
657
|
+
const skipped = e.skipped.length ? `, skipped ${e.skipped.length} with no stored answer (${e.skipped.map((s) => s.number).join(", ")})` : "";
|
|
658
|
+
return [`Wrote ${out}: ${e.cases.length} eval cases${e.kb.version ? ` from release ${e.kb.version}` : ""}${skipped}.`, ...e.notes.map((n) => c.dim(" " + n))];
|
|
659
|
+
}
|
|
655
660
|
/** `okb query` as text: one line per hit, the kind in a heading. */
|
|
656
661
|
export function renderQueryResult(ont, r) {
|
|
657
662
|
if (!r.hits.length)
|
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,6 +5,7 @@
|
|
|
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
11
|
import { OkbError } from "@ontology-kit/reader";
|
|
@@ -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/workflows.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Ontology, type OkbNode } from "@ontology-kit/reader";
|
|
2
2
|
import { type Explainable } from "./metakb.js";
|
|
3
3
|
import { type CsvFiles } from "./export-csv.js";
|
|
4
|
+
import { type Ask } from "./skills.js";
|
|
4
5
|
import * as ops from "./ops.js";
|
|
5
6
|
import { type ResyncReport } from "./resync.js";
|
|
6
7
|
import type { ReviewItem } from "./review.js";
|
|
@@ -269,7 +270,9 @@ export declare function skillsInstallReport(o: {
|
|
|
269
270
|
dir?: string;
|
|
270
271
|
copy?: boolean;
|
|
271
272
|
force?: boolean;
|
|
272
|
-
|
|
273
|
+
interactive?: boolean;
|
|
274
|
+
ask?: Ask;
|
|
275
|
+
}): Promise<import("./skills.js").InstallResult>;
|
|
273
276
|
export declare function skillsStatusReport(o: {
|
|
274
277
|
dir?: string;
|
|
275
278
|
}): {
|
package/dist/workflows.js
CHANGED
|
@@ -261,7 +261,7 @@ export function explainData(hits) {
|
|
|
261
261
|
export const versionLine = () => `okb ${PACKAGE_VERSION} · meta-KB ${MetaKB.get().version}`;
|
|
262
262
|
/** `okb skills install` and `okb skills status`, for the packaged skills and this meta-KB version. */
|
|
263
263
|
export function skillsInstallReport(o) {
|
|
264
|
-
return installSkills({ dir: o.dir, metaVersion: MetaKB.get().version, copy: o.copy, force: o.force });
|
|
264
|
+
return installSkills({ dir: o.dir, metaVersion: MetaKB.get().version, copy: o.copy, force: o.force, interactive: o.interactive, ask: o.ask });
|
|
265
265
|
}
|
|
266
266
|
export function skillsStatusReport(o) {
|
|
267
267
|
const metaVersion = MetaKB.get().version;
|
package/meta-kb/data/nodes.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ontology-kit/okb",
|
|
3
|
-
"version": "0.3.0
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"pdfjs-dist": "^6.3.289"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@ontology-kit/reader": "0.3.0
|
|
65
|
+
"@ontology-kit/reader": "0.3.0",
|
|
66
66
|
"yaml": "^2.8.0"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
@@ -5,7 +5,7 @@ description: Use when extracting design-system (or other) documentation, usually
|
|
|
5
5
|
|
|
6
6
|
# Build a domain KB from docs
|
|
7
7
|
|
|
8
|
-
**Version 2.8.
|
|
8
|
+
**Version 2.8.1.** It should match the meta-KB version that `okb version` prints.
|
|
9
9
|
|
|
10
10
|
Turns a documentation source (usually a markdown component doc, sometimes a PDF) into an okb ontology: Class, Slot and Instance nodes plus domain Rule nodes, each tied to a verbatim quote with its heading path and line numbers. It follows the meta-KB's rules in `packages/okb/meta-kb/` and the pipeline in `docs/EXTRACTION-PIPELINE.md` (both in the ontology-kit repository, usually `~/Projects/ontology-kit`).
|
|
11
11
|
|
|
@@ -13,7 +13,7 @@ The point of this skill is to be deterministic where possible and to stop for hu
|
|
|
13
13
|
|
|
14
14
|
## Step 0: Set up
|
|
15
15
|
|
|
16
|
-
1. Find okb: `okb version` (Node 24+; if it isn't installed, `npm install --global @ontology-kit/okb`, or from a clone of the repo `node <ontology-kit>/packages/okb/src/cli.ts`). Compare the meta-KB version it prints with this skill's version (top of this file). If they differ, tell the user that the skill or okb is out of date and offer to run `okb skills status`, then `okb skills install` to refresh the skills from this okb (the Installation page, <https://ontology-kit.dev/getting-started/installation/>, covers updating okb itself), before going on. The docs are readable as plain markdown: <https://ontology-kit.dev/llms.txt> lists every page with a one-line summary, and each page has a `.md` version.
|
|
16
|
+
1. Find okb: `okb version` (Node 24+; if it isn't installed, `npm install --global @ontology-kit/okb`, or from a clone of the repo `node <ontology-kit>/packages/okb/src/cli.ts`). Compare the meta-KB version it prints with this skill's version (top of this file). If they differ, tell the user that the skill or okb is out of date and offer to run `okb skills status`, then `okb skills install` to refresh the skills from this okb (the Installation page, <https://ontology-kit.dev/getting-started/installation/>, covers updating okb itself), before going on. `okb skills install` asks before it replaces a skill folder that is older or edited. You have no terminal to answer it, so it refuses and says what it found: show that to the user, and run it again with `--force` only after they agree (it keeps the old folder in a backup). The docs are readable as plain markdown: <https://ontology-kit.dev/llms.txt> lists every page with a one-line summary, and each page has a `.md` version.
|
|
17
17
|
2. The target ontology must exist and have a **scope and at least three competency questions** (`okb status`). If it doesn't, stop and do Step 1 of the method first, or hand off to the **ontology-coach** skill. Competency questions decide what's worth extracting; without them, extraction turns into copying the docs.
|
|
18
18
|
3. Load the modeling rules: `okb explain` (list), and `okb explain <rule-id>` for any you're unsure of. Don't invent structural rules beyond the meta-KB. If a modeling question isn't answered by a meta-KB rule or decision guide, raise it as an open question in the output rather than deciding silently.
|
|
19
19
|
4. Register the document, from a local copy (the markdown source, not the rendered website):
|
|
@@ -5,7 +5,7 @@ description: Coach someone who has never built an ontology or knowledge base thr
|
|
|
5
5
|
|
|
6
6
|
# Ontology coach
|
|
7
7
|
|
|
8
|
-
**Version 2.8.
|
|
8
|
+
**Version 2.8.1.** It should match the meta-KB version that `okb version` prints.
|
|
9
9
|
|
|
10
10
|
You are coaching a beginner through building an ontology with the **ontology-kit** toolkit. They have probably never built one. Your job is to make each decision small, explain each idea just before it's needed, do the typing for them, and leave behind an ontology that passes `okb validate` plus a record of _why_ it looks the way it does.
|
|
11
11
|
|
|
@@ -13,7 +13,7 @@ The toolkit's meta-KB is the authority on method, vocabulary and rules. **Don't
|
|
|
13
13
|
|
|
14
14
|
## 0. Setup (every session)
|
|
15
15
|
|
|
16
|
-
1. **Find the toolkit.** Try `okb version`. If that fails, okb isn't installed: ask the user to run `npm install --global @ontology-kit/okb` (it needs Node 24+, check with `node --version`). Only if they are working from a clone of the repo, look for the `ontology-kit` folder (usually `~/Projects/ontology-kit`) and run okb as `node <kit>/packages/okb/src/cli.ts ...`; if that folder isn't reachable from this session, ask the user to connect it, and don't try to rebuild the toolkit. Compare the meta-KB version it prints with this skill's version (top of this file). If they differ, tell the user that the skill or okb is out of date and offer to run `okb skills status`, then `okb skills install` to refresh the skills from this okb (the Installation page, <https://ontology-kit.dev/getting-started/installation/>, covers updating okb itself), before going on. The docs are readable as plain markdown: <https://ontology-kit.dev/llms.txt> lists every page with a one-line summary, and each page has a `.md` version.
|
|
16
|
+
1. **Find the toolkit.** Try `okb version`. If that fails, okb isn't installed: ask the user to run `npm install --global @ontology-kit/okb` (it needs Node 24+, check with `node --version`). Only if they are working from a clone of the repo, look for the `ontology-kit` folder (usually `~/Projects/ontology-kit`) and run okb as `node <kit>/packages/okb/src/cli.ts ...`; if that folder isn't reachable from this session, ask the user to connect it, and don't try to rebuild the toolkit. Compare the meta-KB version it prints with this skill's version (top of this file). If they differ, tell the user that the skill or okb is out of date and offer to run `okb skills status`, then `okb skills install` to refresh the skills from this okb (the Installation page, <https://ontology-kit.dev/getting-started/installation/>, covers updating okb itself), before going on. `okb skills install` asks before it replaces a skill folder that is older or edited. You have no terminal to answer it, so it refuses and says what it found: show that to the user, and run it again with `--force` only after they agree (it keeps the old folder in a backup). The docs are readable as plain markdown: <https://ontology-kit.dev/llms.txt> lists every page with a one-line summary, and each page has a `.md` version.
|
|
17
17
|
2. **Find or create their ontology.**
|
|
18
18
|
- Resuming: run `okb status` in their ontology folder and pick up where they are. Briefly recap their scope and the step they're on.
|
|
19
19
|
- New: ask what they want to model and what they'll use it for (one question), then `okb init <folder> --name "<Name>"`.
|
|
@@ -5,7 +5,7 @@ description: Use when someone looks after an existing okb knowledge base that is
|
|
|
5
5
|
|
|
6
6
|
# Maintain an existing KB
|
|
7
7
|
|
|
8
|
-
**Version 2.8.
|
|
8
|
+
**Version 2.8.1.** It should match the meta-KB version that `okb version` prints.
|
|
9
9
|
|
|
10
10
|
For the person (or the agent working for them) who looks after a KB that was built once and is now kept in git with `okb check` in CI. It works out what is open, does the routine update, and finishes with the pull request text. It adds no commands of its own: everything goes through `okb`. The same sequences, with their output, are in the maintainer guide (<https://ontology-kit.dev/build/maintaining/>) and the CI guide (<https://ontology-kit.dev/build/check-in-ci/>); read those when a step here is not enough.
|
|
11
11
|
|
|
@@ -20,7 +20,7 @@ For the person (or the agent working for them) who looks after a KB that was bui
|
|
|
20
20
|
|
|
21
21
|
## Step 0: Set up and triage
|
|
22
22
|
|
|
23
|
-
1. Find okb with `okb version`. Compare the meta-KB version it prints with this skill's version. If they differ, tell the user the skill or okb is out of date and offer `okb skills status`, then `okb skills install`, before going on.
|
|
23
|
+
1. Find okb with `okb version`. Compare the meta-KB version it prints with this skill's version. If they differ, tell the user the skill or okb is out of date and offer `okb skills status`, then `okb skills install`, before going on. `okb skills install` asks before it replaces a skill folder that is older or edited. You have no terminal to answer it, so it refuses and says what it found: show that to the user, and run it again with `--force` only after they agree (it keeps the old folder in a backup).
|
|
24
24
|
2. Make sure you're on a branch cut from the KB's main branch (`git fetch origin`, `git branch --show-current`, `git status --short`). Don't work on `main`.
|
|
25
25
|
3. Record what is already failing, before you touch anything, so the PR neither inherits nor hides it:
|
|
26
26
|
|
|
@@ -5,13 +5,13 @@ description: Review an ontology built with ontology-kit (okb) against the Ontolo
|
|
|
5
5
|
|
|
6
6
|
# Ontology review
|
|
7
7
|
|
|
8
|
-
**Version 2.8.
|
|
8
|
+
**Version 2.8.1.** It should match the meta-KB version that `okb version` prints.
|
|
9
9
|
|
|
10
10
|
Give an okb ontology a second opinion. `okb validate` already covers the mechanical rules. The value of this review is in the rules **only a person can judge** (is this really a kind-of? are these siblings equally general? should this class be a slot value?) and in **double-checking heuristic findings**, which can be false positives. The reader may be a beginner, so every finding must be understandable without prior ontology knowledge.
|
|
11
11
|
|
|
12
12
|
## 1. Gather
|
|
13
13
|
|
|
14
|
-
1. Find okb: `okb version` (Node 24+; if it isn't installed, `npm install --global @ontology-kit/okb`, or from a clone of the repo `node <ontology-kit>/packages/okb/src/cli.ts`). Compare the meta-KB version it prints with this skill's version (top of this file). If they differ, tell the user that the skill or okb is out of date and offer to run `okb skills status`, then `okb skills install` to refresh the skills from this okb (the Installation page, <https://ontology-kit.dev/getting-started/installation/>, covers updating okb itself), before going on. The docs are readable as plain markdown: <https://ontology-kit.dev/llms.txt> lists every page with a one-line summary, and each page has a `.md` version.
|
|
14
|
+
1. Find okb: `okb version` (Node 24+; if it isn't installed, `npm install --global @ontology-kit/okb`, or from a clone of the repo `node <ontology-kit>/packages/okb/src/cli.ts`). Compare the meta-KB version it prints with this skill's version (top of this file). If they differ, tell the user that the skill or okb is out of date and offer to run `okb skills status`, then `okb skills install` to refresh the skills from this okb (the Installation page, <https://ontology-kit.dev/getting-started/installation/>, covers updating okb itself), before going on. `okb skills install` asks before it replaces a skill folder that is older or edited. You have no terminal to answer it, so it refuses and says what it found: show that to the user, and run it again with `--force` only after they agree (it keeps the old folder in a backup). The docs are readable as plain markdown: <https://ontology-kit.dev/llms.txt> lists every page with a one-line summary, and each page has a `.md` version.
|
|
15
15
|
2. In the ontology folder, collect:
|
|
16
16
|
- `okb status --json`: the step they're on and what's complete
|
|
17
17
|
- `okb validate --all --json`: mechanical and heuristic findings
|
|
@@ -5,7 +5,7 @@ description: Use when a subject-matter expert or a pull request reviewer has to
|
|
|
5
5
|
|
|
6
6
|
# Sign off on a KB
|
|
7
7
|
|
|
8
|
-
**Version 2.8.
|
|
8
|
+
**Version 2.8.1.** It should match the meta-KB version that `okb version` prints.
|
|
9
9
|
|
|
10
10
|
For the person who knows the subject but may not know git, JSON or the `okb` command: a subject-matter expert (SME) whose documents an agent turned into rules, or a teammate reviewing a pull request that changes a KB. The job is to put each rule in front of them with the words it came from, get a decision, and keep a record. You run the commands. They answer questions.
|
|
11
11
|
|
|
@@ -22,7 +22,7 @@ This is a check on facts: is this rule true, and does the source say it? It is n
|
|
|
22
22
|
|
|
23
23
|
## Step 0: Set up
|
|
24
24
|
|
|
25
|
-
1. Run `okb version`. Compare the meta-KB version with this skill's version (top of this file). If they differ, tell the person the skill or okb is out of date and offer `okb skills status`, then `okb skills install`, before going on.
|
|
25
|
+
1. Run `okb version`. Compare the meta-KB version with this skill's version (top of this file). If they differ, tell the person the skill or okb is out of date and offer `okb skills status`, then `okb skills install`, before going on. `okb skills install` asks before it replaces a skill folder that is older or edited. You have no terminal to answer it, so it refuses and says what it found: show that to the user, and run it again with `--force` only after they agree (it keeps the old folder in a backup).
|
|
26
26
|
2. Find the KB folder (the one with `okb.json`). Make sure you are in it and that the source documents are on disk beside it: the context views read them.
|
|
27
27
|
3. Pick a scratch folder for the review pages, outside the KB folder (for example a new folder under the system temp directory). Use the same one for the whole session. Never write review pages into the KB's own `docs` folder.
|
|
28
28
|
4. Ask what they are here to do, in one question: "Is this the first time you're reading what was pulled out of your documents, or are you reviewing a change someone made?" First time: Story 1. A change: Story 2. If they say they have little time, run the story and use Story 3's order.
|
package/templates/okb-check.yml
CHANGED
|
@@ -65,6 +65,16 @@ jobs:
|
|
|
65
65
|
cat "$RUNNER_TEMP/check.txt"
|
|
66
66
|
exit "$status"
|
|
67
67
|
|
|
68
|
+
# Optional: ask the competency questions through the MCP server's tools, as an agent would, and not
|
|
69
|
+
# only against the files. Uncomment it if the KB is served with @ontology-kit/mcp. It needs the
|
|
70
|
+
# questions' answers stored (`okb cq answer`) and exits 1 when one fails. Add `continue-on-error: true`
|
|
71
|
+
# to report it without blocking the merge. The comment below reads this step's outcome through its `id`, and
|
|
72
|
+
# says "not safe to merge" when it failed, even if `continue-on-error` lets the job pass.
|
|
73
|
+
# - name: Run the competency questions through the MCP server
|
|
74
|
+
# id: mcp
|
|
75
|
+
# shell: bash
|
|
76
|
+
# run: npx --yes @ontology-kit/mcp check "$KB_DIR"
|
|
77
|
+
|
|
68
78
|
- name: Run okb diff against the base branch
|
|
69
79
|
if: always()
|
|
70
80
|
env:
|
|
@@ -81,13 +91,19 @@ jobs:
|
|
|
81
91
|
if: always()
|
|
82
92
|
env:
|
|
83
93
|
RESULT: ${{ steps.check.outcome }}
|
|
94
|
+
# Empty while the optional MCP step above is commented out, which counts as "not run".
|
|
95
|
+
MCP_RESULT: ${{ steps.mcp.outcome }}
|
|
84
96
|
shell: bash
|
|
85
97
|
run: |
|
|
86
98
|
# The backticks are Markdown, not command substitution.
|
|
87
99
|
# shellcheck disable=SC2016
|
|
88
100
|
{
|
|
89
101
|
echo '<!-- okb-check -->'
|
|
90
|
-
if [ "$RESULT" = success ]; then echo '## okb check: safe to merge'; else echo '## okb check: not safe to merge'; fi
|
|
102
|
+
if [ "$RESULT" = success ] && [ "$MCP_RESULT" != failure ]; then echo '## okb check: safe to merge'; else echo '## okb check: not safe to merge'; fi
|
|
103
|
+
if [ "$MCP_RESULT" = failure ]; then
|
|
104
|
+
echo
|
|
105
|
+
echo 'The competency questions asked through the MCP server failed (see the step in the run log).'
|
|
106
|
+
fi
|
|
91
107
|
echo
|
|
92
108
|
echo '~~~~text'
|
|
93
109
|
sed 's/\x1b\[[0-9;]*m//g' "$RUNNER_TEMP/check.txt"
|