@ontology-kit/okb 0.0.0-stage → 0.1.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/LICENSE +9 -0
- package/README.md +26 -2
- package/bin/okb.js +8 -0
- package/dist/checks.d.ts +33 -0
- package/dist/checks.js +966 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +718 -0
- package/dist/clidocs.d.ts +6 -0
- package/dist/clidocs.js +90 -0
- package/dist/clock.d.ts +2 -0
- package/dist/clock.js +16 -0
- package/dist/commands.d.ts +28 -0
- package/dist/commands.js +622 -0
- package/dist/export.d.ts +54 -0
- package/dist/export.js +290 -0
- package/dist/families.d.ts +20 -0
- package/dist/families.js +51 -0
- package/dist/help.d.ts +2 -0
- package/dist/help.js +57 -0
- package/dist/markdown.d.ts +60 -0
- package/dist/markdown.js +310 -0
- package/dist/metakb.d.ts +164 -0
- package/dist/metakb.js +130 -0
- package/dist/naming.d.ts +20 -0
- package/dist/naming.js +140 -0
- package/dist/ops/admin.d.ts +16 -0
- package/dist/ops/admin.js +119 -0
- package/dist/ops/classes.d.ts +21 -0
- package/dist/ops/classes.js +105 -0
- package/dist/ops/common.d.ts +6 -0
- package/dist/ops/common.js +4 -0
- package/dist/ops/instances.d.ts +8 -0
- package/dist/ops/instances.js +70 -0
- package/dist/ops/links.d.ts +9 -0
- package/dist/ops/links.js +85 -0
- package/dist/ops/naming.d.ts +4 -0
- package/dist/ops/naming.js +70 -0
- package/dist/ops/scope.d.ts +29 -0
- package/dist/ops/scope.js +124 -0
- package/dist/ops/slots.d.ts +31 -0
- package/dist/ops/slots.js +186 -0
- package/dist/ops/values.d.ts +20 -0
- package/dist/ops/values.js +151 -0
- package/dist/ops.d.ts +14 -0
- package/dist/ops.js +14 -0
- package/dist/provenance.d.ts +53 -0
- package/dist/provenance.js +296 -0
- package/dist/quotes.d.ts +14 -0
- package/dist/quotes.js +104 -0
- package/dist/render.d.ts +30 -0
- package/dist/render.js +413 -0
- package/dist/review.d.ts +10 -0
- package/dist/review.js +145 -0
- package/dist/site.d.ts +6 -0
- package/dist/site.js +6 -0
- package/dist/skills.d.ts +52 -0
- package/dist/skills.js +120 -0
- package/dist/status.d.ts +18 -0
- package/dist/status.js +59 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +5 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +7 -0
- package/meta-kb/data/edges.json +3172 -0
- package/meta-kb/data/manifest.json +19 -0
- package/meta-kb/data/nodes.json +3546 -0
- package/package.json +71 -3
- package/skills/build-domain-kb-from-docs/SKILL.md +87 -0
- package/skills/ontology-coach/SKILL.md +100 -0
- package/skills/ontology-review/SKILL.md +66 -0
package/dist/skills.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `okb skills install` and `okb skills status`: put the skills that ship in this package where Claude
|
|
3
|
+
* Code and Cursor load them from (`~/.claude/skills/`), so they always match the okb that installed them.
|
|
4
|
+
* Nothing here touches an ontology, so it is not one of the `ops`.
|
|
5
|
+
*/
|
|
6
|
+
import { cpSync, lstatSync, existsSync, mkdirSync, readdirSync, readFileSync, readlinkSync, realpathSync, renameSync, rmSync, symlinkSync } from "node:fs";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
import { dirname, join, resolve } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { OkbError } from "@ontology-kit/format";
|
|
11
|
+
/** The skills in this package. From src/ and from dist/ the package root is one folder up. */
|
|
12
|
+
export const PACKAGED_SKILLS_DIR = join(dirname(dirname(fileURLToPath(import.meta.url))), "skills");
|
|
13
|
+
/** Where skills go when `--dir` is not given: `$OKB_SKILLS_DIR`, else `~/.claude/skills` (Cursor reads that folder too). */
|
|
14
|
+
export function defaultSkillsDir(env = process.env) {
|
|
15
|
+
return env.OKB_SKILLS_DIR || join(homedir(), ".claude", "skills");
|
|
16
|
+
}
|
|
17
|
+
/** The skill's name and the version it says it is, read from its SKILL.md; undefined when there is no readable SKILL.md. */
|
|
18
|
+
function readSkill(dir) {
|
|
19
|
+
let text;
|
|
20
|
+
try {
|
|
21
|
+
text = readFileSync(join(dir, "SKILL.md"), "utf8");
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
return { name: /^---\n(?:.*\n)*?name:\s*(\S+)/.exec(text)?.[1], version: /^\*\*Version ([^\s*]+?)\.\*\*/m.exec(text)?.[1] };
|
|
27
|
+
}
|
|
28
|
+
function files(dir, base = "") {
|
|
29
|
+
return readdirSync(join(dir, base), { withFileTypes: true }).flatMap((e) => (e.isDirectory() ? files(dir, join(base, e.name)) : [join(base, e.name)])).sort();
|
|
30
|
+
}
|
|
31
|
+
function sameTree(a, b) {
|
|
32
|
+
const fa = files(a);
|
|
33
|
+
const fb = files(b);
|
|
34
|
+
return fa.length === fb.length && fa.every((f, i) => f === fb[i] && readFileSync(join(a, f)).equals(readFileSync(join(b, f))));
|
|
35
|
+
}
|
|
36
|
+
/** The names of the skills this package carries. */
|
|
37
|
+
export function packagedSkills() {
|
|
38
|
+
if (!existsSync(PACKAGED_SKILLS_DIR))
|
|
39
|
+
throw new OkbError(`This okb has no skills folder (looked in ${PACKAGED_SKILLS_DIR}). Reinstall @ontology-kit/okb.`);
|
|
40
|
+
return readdirSync(PACKAGED_SKILLS_DIR, { withFileTypes: true }).filter((e) => e.isDirectory() && existsSync(join(PACKAGED_SKILLS_DIR, e.name, "SKILL.md"))).map((e) => e.name).sort();
|
|
41
|
+
}
|
|
42
|
+
function lstatOrUndefined(path) {
|
|
43
|
+
try {
|
|
44
|
+
return lstatSync(path);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function inspect(name, dir, metaVersion) {
|
|
51
|
+
const path = join(dir, name);
|
|
52
|
+
const source = join(PACKAGED_SKILLS_DIR, name);
|
|
53
|
+
const st = lstatOrUndefined(path);
|
|
54
|
+
if (!st)
|
|
55
|
+
return { name, path, state: "missing", detail: "not installed" };
|
|
56
|
+
const versionNote = (v) => (v ? `version ${v}, this okb is ${metaVersion}` : `no version line, this okb is ${metaVersion}`);
|
|
57
|
+
if (st.isSymbolicLink()) {
|
|
58
|
+
const linkTo = resolve(dir, readlinkSync(path));
|
|
59
|
+
if (!existsSync(path))
|
|
60
|
+
return { name, path, state: "broken-link", how: "link", linkTo, detail: `a link to ${linkTo}, which no longer exists (an update moved the package?)` };
|
|
61
|
+
const found = readSkill(path);
|
|
62
|
+
if (realpathSync(path) === realpathSync(source)) {
|
|
63
|
+
const ok = found?.version === metaVersion;
|
|
64
|
+
return { name, path, state: ok ? "current" : "stale", how: "link", version: found?.version, linkTo, detail: ok ? `linked to this okb, version ${metaVersion}` : `linked to this okb, but ${versionNote(found?.version)}` };
|
|
65
|
+
}
|
|
66
|
+
if (found?.name !== name)
|
|
67
|
+
return { name, path, state: "foreign", how: "link", linkTo, detail: `a link to ${linkTo}, which is not the ${name} skill` };
|
|
68
|
+
return { name, path, state: "other-install", how: "link", version: found.version, linkTo, detail: `linked to a different okb at ${linkTo} (${versionNote(found.version)})` };
|
|
69
|
+
}
|
|
70
|
+
const found = st.isDirectory() ? readSkill(path) : undefined;
|
|
71
|
+
if (!found || found.name !== name || !found.version)
|
|
72
|
+
return { name, path, state: "foreign", detail: st.isDirectory() ? "a folder that is not an okb skill" : "a file, not an okb skill folder" };
|
|
73
|
+
if (found.version !== metaVersion)
|
|
74
|
+
return { name, path, state: "stale", how: "copy", version: found.version, detail: `a copy at ${versionNote(found.version)}` };
|
|
75
|
+
if (!sameTree(path, source))
|
|
76
|
+
return { name, path, state: "modified", how: "copy", version: found.version, detail: `a copy at version ${found.version} whose files differ from this okb's` };
|
|
77
|
+
return { name, path, state: "current", how: "copy", version: found.version, detail: `a copy of this okb's skill, version ${metaVersion}` };
|
|
78
|
+
}
|
|
79
|
+
/** What is installed in the skills folder, for each skill this package carries. */
|
|
80
|
+
export function skillsStatus(opts) {
|
|
81
|
+
const dir = resolve(opts.dir ?? defaultSkillsDir());
|
|
82
|
+
return { dir, skills: packagedSkills().map((n) => inspect(n, dir, opts.metaVersion)) };
|
|
83
|
+
}
|
|
84
|
+
/** Installs the packaged skills. Checks everything first, so a refusal changes nothing. */
|
|
85
|
+
export function installSkills(opts) {
|
|
86
|
+
const dir = resolve(opts.dir ?? defaultSkillsDir());
|
|
87
|
+
const want = opts.copy ? "copy" : "link";
|
|
88
|
+
const before = packagedSkills().map((n) => inspect(n, dir, opts.metaVersion));
|
|
89
|
+
const refused = before.filter((r) => (r.state === "foreign" || r.state === "modified") && !opts.force);
|
|
90
|
+
if (refused.length) {
|
|
91
|
+
const why = refused.map((r) => ` ${r.path}: ${r.detail}`).join("\n");
|
|
92
|
+
throw new OkbError(`Not installing: ${refused.length === 1 ? "this is" : "these are"} not okb's to replace.\n${why}\nNothing was changed. Move ${refused.length === 1 ? "it" : "them"} away, or run okb skills install --force to delete ${refused.length === 1 ? "it" : "them"} and put the ${want === "copy" ? "copies" : "links"} in place.`);
|
|
93
|
+
}
|
|
94
|
+
mkdirSync(dir, { recursive: true });
|
|
95
|
+
const lines = [];
|
|
96
|
+
for (const r of before) {
|
|
97
|
+
const source = join(PACKAGED_SKILLS_DIR, r.name);
|
|
98
|
+
if (r.state === "current" && r.how === want) {
|
|
99
|
+
lines.push(`${r.name}: already ${want === "copy" ? "copied" : "linked"}, version ${opts.metaVersion}`);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const tmp = join(dir, `.${r.name}.okb-${process.pid}`);
|
|
103
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
104
|
+
if (want === "copy")
|
|
105
|
+
cpSync(source, tmp, { recursive: true });
|
|
106
|
+
else
|
|
107
|
+
symlinkSync(source, tmp, "junction");
|
|
108
|
+
// rm on a link removes the link, never the folder it points to.
|
|
109
|
+
if (lstatOrUndefined(r.path))
|
|
110
|
+
rmSync(r.path, { recursive: true, force: true });
|
|
111
|
+
renameSync(tmp, r.path);
|
|
112
|
+
const verb = want === "copy" ? "copied" : "linked";
|
|
113
|
+
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: " (replaced a modified copy)", "other-install": " (replaced a link to a different okb)", "broken-link": " (replaced a broken link)", foreign: " (replaced what was there, because of --force)",
|
|
116
|
+
};
|
|
117
|
+
lines.push(`${r.name}: ${verb}${replaced[r.state]}`);
|
|
118
|
+
}
|
|
119
|
+
return { dir, lines };
|
|
120
|
+
}
|
package/dist/status.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Ontology } from "@ontology-kit/format";
|
|
2
|
+
import { type Finding } from "./types.js";
|
|
3
|
+
type StepCheck = (ont: Ontology, all: Finding[]) => boolean;
|
|
4
|
+
export declare const STEP_CHECKS: Record<string, StepCheck>;
|
|
5
|
+
export interface StepStatus {
|
|
6
|
+
order: number;
|
|
7
|
+
name: string;
|
|
8
|
+
items: {
|
|
9
|
+
text: string;
|
|
10
|
+
done: boolean | null;
|
|
11
|
+
}[];
|
|
12
|
+
complete: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function computeStatus(ont: Ontology, all?: Finding[]): {
|
|
15
|
+
steps: StepStatus[];
|
|
16
|
+
suggested: number;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
package/dist/status.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Progress through the method. Each Step in the meta-KB lists `doneWhen` items;
|
|
3
|
+
* the ones with a `check` key are evaluated here (meta-kb/build.ts verifies every
|
|
4
|
+
* key exists). Items without a check are judgment calls, shown as "ask yourself".
|
|
5
|
+
*/
|
|
6
|
+
import { MIN_COMPETENCY_QUESTIONS, runChecks } from "./checks.js";
|
|
7
|
+
import { MetaKB } from "./metakb.js";
|
|
8
|
+
import {} from "@ontology-kit/format";
|
|
9
|
+
import {} from "./types.js";
|
|
10
|
+
/** Step 3's brainstorm should reach this many terms before sorting them into classes and slots. */
|
|
11
|
+
const MIN_TERMS = 10;
|
|
12
|
+
const noErrors = (all) => !all.some((f) => f.severity === "error");
|
|
13
|
+
/**
|
|
14
|
+
* "No errors in this part yet": no errors from the rules the meta-KB applies at
|
|
15
|
+
* these steps, or from the file's structure (struct-well-formed breaks every step).
|
|
16
|
+
*/
|
|
17
|
+
function noErrorsFrom(steps) {
|
|
18
|
+
return (_o, all) => {
|
|
19
|
+
const meta = MetaKB.get();
|
|
20
|
+
const rules = new Set(["struct-well-formed", ...steps.flatMap((s) => meta.stepRules(s).map((r) => r.key))]);
|
|
21
|
+
return noErrors(all.filter((f) => rules.has(f.rule)));
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export const STEP_CHECKS = {
|
|
25
|
+
scope_domain_purpose: (o) => Boolean(o.meta.domain && o.meta.purpose),
|
|
26
|
+
scope_users: (o) => (o.meta.users ?? []).length > 0,
|
|
27
|
+
cq_min3: (o) => o.ofType("CompetencyQuestion").length >= MIN_COMPETENCY_QUESTIONS,
|
|
28
|
+
scope_out: (o) => (o.meta.outOfScope ?? []).length > 0,
|
|
29
|
+
reuse_reviewed: (o) => Boolean(o.meta.reuseReviewed) || o.ofType("ReusedOntology").length > 0,
|
|
30
|
+
terms_min10: (o) => o.ofType("Term").length >= MIN_TERMS,
|
|
31
|
+
convention_set: (o) => Boolean(o.conventions),
|
|
32
|
+
classes_min2_with_isa: (o) => o.ofType("Class").length >= 2 && o.edgesOf("IS_A").length >= 1,
|
|
33
|
+
no_errors_hierarchy: noErrorsFrom([4]),
|
|
34
|
+
slots_min1: (o) => o.ofType("Slot").length >= 1,
|
|
35
|
+
slots_attached: (o) => o.ofType("Slot").every((s) => o.isAttached(s.id)),
|
|
36
|
+
slots_faceted: (o) => o.ofType("Slot").length > 0 && o.ofType("Slot").every((s) => s.valueType && s.cardinality),
|
|
37
|
+
no_errors_slots: noErrorsFrom([5, 6]),
|
|
38
|
+
instances_min3: (o) => o.ofType("Instance").length >= 3,
|
|
39
|
+
no_errors_instances: noErrorsFrom([7]),
|
|
40
|
+
cq_all_linked: (o) => {
|
|
41
|
+
const qs = o.ofType("CompetencyQuestion");
|
|
42
|
+
return qs.length > 0 && qs.every((q) => o.targets(q.id, "NEEDS").length > 0);
|
|
43
|
+
},
|
|
44
|
+
no_errors: (_o, all) => noErrors(all),
|
|
45
|
+
warnings_explained: (_o, all) => !all.some((f) => f.severity === "warning" && !f.explainedBy),
|
|
46
|
+
};
|
|
47
|
+
export function computeStatus(ont, all) {
|
|
48
|
+
const meta = MetaKB.get();
|
|
49
|
+
const findings = all ?? runChecks(ont, { all: true }).findings;
|
|
50
|
+
const steps = meta.steps.map((s) => {
|
|
51
|
+
const items = s.doneWhen.map((d) => ({
|
|
52
|
+
text: d.text,
|
|
53
|
+
done: d.check ? STEP_CHECKS[d.check](ont, findings) : null,
|
|
54
|
+
}));
|
|
55
|
+
return { order: s.order, name: s.name, items, complete: items.every((i) => i.done !== false) };
|
|
56
|
+
});
|
|
57
|
+
const firstOpen = steps.find((s) => !s.complete);
|
|
58
|
+
return { steps, suggested: firstOpen ? firstOpen.order : steps.length };
|
|
59
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Small types and guards that only okb needs (the file format's own types are in @ontology-kit/format). */
|
|
2
|
+
/** Narrows a string from the command line or a file to one of a fixed set of values. */
|
|
3
|
+
export declare function isOneOf<T extends string>(values: readonly T[], v: string | undefined): v is T;
|
|
4
|
+
export type Severity = "error" | "warning" | "info";
|
|
5
|
+
export interface Finding {
|
|
6
|
+
rule: string;
|
|
7
|
+
severity: Severity;
|
|
8
|
+
message: string;
|
|
9
|
+
nodes: string[];
|
|
10
|
+
/** Set when a DesignDecision waives this finding (warnings/info only). */
|
|
11
|
+
explainedBy?: string;
|
|
12
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PACKAGE_VERSION: string;
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The package version, read from package.json so it never drifts from what gets published. */
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
// src/ and dist/ both sit one level below the package root, as does an installed copy's dist/.
|
|
6
|
+
const PACKAGE_JSON = join(dirname(dirname(fileURLToPath(import.meta.url))), "package.json");
|
|
7
|
+
export const PACKAGE_VERSION = JSON.parse(readFileSync(PACKAGE_JSON, "utf8")).version;
|