@ontology-kit/okb 0.1.0 → 0.3.0-alpha.210

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.
Files changed (97) hide show
  1. package/README.md +1 -1
  2. package/dist/check.d.ts +43 -0
  3. package/dist/check.js +83 -0
  4. package/dist/checks.d.ts +1 -1
  5. package/dist/checks.js +4 -4
  6. package/dist/cli.js +11 -705
  7. package/dist/clidocs.d.ts +0 -2
  8. package/dist/clidocs.js +5 -27
  9. package/dist/clock.js +1 -1
  10. package/dist/command-table.d.ts +134 -0
  11. package/dist/command-table.js +82 -0
  12. package/dist/commands/documents.d.ts +3 -0
  13. package/dist/commands/documents.js +250 -0
  14. package/dist/commands/getting-started.d.ts +3 -0
  15. package/dist/commands/getting-started.js +135 -0
  16. package/dist/commands/housekeeping.d.ts +3 -0
  17. package/dist/commands/housekeeping.js +203 -0
  18. package/dist/commands/modeling.d.ts +3 -0
  19. package/dist/commands/modeling.js +433 -0
  20. package/dist/commands/planning.d.ts +3 -0
  21. package/dist/commands/planning.js +212 -0
  22. package/dist/commands/reviewing.d.ts +3 -0
  23. package/dist/commands/reviewing.js +177 -0
  24. package/dist/commands/skills.d.ts +3 -0
  25. package/dist/commands/skills.js +52 -0
  26. package/dist/commands.d.ts +10 -22
  27. package/dist/commands.js +15 -622
  28. package/dist/diff.d.ts +85 -0
  29. package/dist/diff.js +323 -0
  30. package/dist/export.d.ts +1 -1
  31. package/dist/export.js +1 -1
  32. package/dist/families.d.ts +1 -1
  33. package/dist/families.js +1 -1
  34. package/dist/help.d.ts +11 -2
  35. package/dist/help.js +51 -57
  36. package/dist/kbdocs.d.ts +18 -0
  37. package/dist/kbdocs.js +393 -0
  38. package/dist/metakb.d.ts +1 -1
  39. package/dist/metakb.js +1 -1
  40. package/dist/naming.d.ts +2 -2
  41. package/dist/naming.js +2 -2
  42. package/dist/ontology-ref.d.ts +20 -0
  43. package/dist/ontology-ref.js +108 -0
  44. package/dist/ops/admin.d.ts +1 -1
  45. package/dist/ops/admin.js +24 -7
  46. package/dist/ops/classes.d.ts +1 -1
  47. package/dist/ops/classes.js +13 -5
  48. package/dist/ops/instances.d.ts +2 -1
  49. package/dist/ops/instances.js +7 -1
  50. package/dist/ops/links.d.ts +1 -1
  51. package/dist/ops/links.js +1 -1
  52. package/dist/ops/naming.d.ts +1 -1
  53. package/dist/ops/naming.js +3 -1
  54. package/dist/ops/scope.d.ts +5 -1
  55. package/dist/ops/scope.js +19 -1
  56. package/dist/ops/slots.d.ts +1 -1
  57. package/dist/ops/slots.js +15 -2
  58. package/dist/ops/values.d.ts +1 -1
  59. package/dist/ops/values.js +5 -1
  60. package/dist/provenance.d.ts +4 -2
  61. package/dist/provenance.js +58 -17
  62. package/dist/release.d.ts +52 -0
  63. package/dist/release.js +337 -0
  64. package/dist/render.d.ts +64 -1
  65. package/dist/render.js +240 -3
  66. package/dist/resync.d.ts +98 -0
  67. package/dist/resync.js +234 -0
  68. package/dist/review.d.ts +1 -1
  69. package/dist/review.js +1 -1
  70. package/dist/reviewdocs.d.ts +42 -0
  71. package/dist/reviewdocs.js +263 -0
  72. package/dist/runner.d.ts +3 -0
  73. package/dist/runner.js +79 -0
  74. package/dist/skills.js +1 -1
  75. package/dist/status.d.ts +1 -1
  76. package/dist/status.js +1 -1
  77. package/dist/types.d.ts +1 -1
  78. package/dist/types.js +1 -1
  79. package/dist/verifynote.d.ts +18 -0
  80. package/dist/verifynote.js +92 -0
  81. package/dist/workflows.d.ts +256 -0
  82. package/dist/workflows.js +223 -0
  83. package/meta-kb/data/manifest.json +2 -2
  84. package/meta-kb/data/nodes.json +8 -8
  85. package/package.json +9 -4
  86. package/schema/edge.schema.json +68 -0
  87. package/schema/edges.schema.json +9 -0
  88. package/schema/node.schema.json +893 -0
  89. package/schema/nodes.schema.json +9 -0
  90. package/schema/okb.schema.json +41 -0
  91. package/skills/build-domain-kb-from-docs/SKILL.md +20 -2
  92. package/skills/ontology-coach/SKILL.md +6 -2
  93. package/skills/ontology-maintainer/SKILL.md +152 -0
  94. package/skills/ontology-review/SKILL.md +3 -1
  95. package/skills/ontology-signoff/SKILL.md +182 -0
  96. package/templates/okb-check.yml +132 -0
  97. package/templates/pull_request_template.md +16 -0
@@ -0,0 +1,263 @@
1
+ /**
2
+ * Review aids built on `okb docs` (issue #133), for a subject matter expert or a PR reviewer.
3
+ *
4
+ * 1. The changed-only view (`okb docs --changed <ref>`): render the pages at `<ref>` and for the working
5
+ * folder, keep the pages whose text differs. A changed inherited rule changes every subclass page that
6
+ * shows it, so the ripple comes for free. `--hops N` adds the class pages that link to or from a changed
7
+ * class page, for context. `changes.md` lists what changed and adds the stale-quote worklist from
8
+ * `okb source refresh --all`, because a source edit that hasn't been re-synced changes no page.
9
+ * 2. The context view (`okb docs --context`): each rule beside the source text around its quote.
10
+ *
11
+ * Everything here is pure (loaded ontologies and parsed documents in, Markdown out). No clock, no disk,
12
+ * stable ordering, so the same inputs always give the same text.
13
+ */
14
+ import { posix } from "node:path";
15
+ import { nameOrText } from "@ontology-kit/reader";
16
+ import { BANNER } from "./kbdocs.js";
17
+ import { locate } from "./markdown.js";
18
+ const byText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
19
+ const oneLine = (s) => s.replace(/\s*\n\s*/g, " ").trim();
20
+ const plural = (n, w) => `${n} ${w}${n === 1 ? "" : "s"}`;
21
+ /** Compare two renderings page by page. Pure. */
22
+ export function diffPages(before, after) {
23
+ const names = (pred) => Object.keys({ ...before, ...after }).filter(pred).sort(byText);
24
+ return {
25
+ changed: names((n) => n in before && n in after && before[n] !== after[n]),
26
+ added: names((n) => !(n in before) && n in after),
27
+ removed: names((n) => n in before && !(n in after)),
28
+ };
29
+ }
30
+ const isClassPage = (name) => name.startsWith("classes/");
31
+ /** The class pages a page links to (`](c-x.md#anchor)`, resolved against its own folder). */
32
+ function classLinks(name, text) {
33
+ const out = new Set();
34
+ for (const m of text.matchAll(/\]\(([^)\s#]+\.md)(?:#[^)\s]*)?\)/g)) {
35
+ if (/^[a-z]+:/i.test(m[1]))
36
+ continue;
37
+ const target = posix.normalize(posix.join(posix.dirname(name), m[1]));
38
+ if (isClassPage(target))
39
+ out.add(target);
40
+ }
41
+ return [...out];
42
+ }
43
+ /**
44
+ * Class pages within `hops` links of the starting pages, in either direction. Only class pages are walked:
45
+ * the index, rules and sources pages link to everything, so going through them would pull in the whole KB.
46
+ * Returns the pages that are new to the set, sorted.
47
+ */
48
+ export function expandHops(files, start, hops) {
49
+ const links = new Map();
50
+ const touch = (a, b) => {
51
+ if (!links.has(a))
52
+ links.set(a, new Set());
53
+ links.get(a).add(b);
54
+ };
55
+ for (const [name, text] of Object.entries(files)) {
56
+ if (!isClassPage(name))
57
+ continue;
58
+ for (const t of classLinks(name, text))
59
+ if (t in files) {
60
+ touch(name, t);
61
+ touch(t, name);
62
+ }
63
+ }
64
+ const seen = new Set(start);
65
+ let edge = start.filter(isClassPage);
66
+ for (let i = 0; i < hops; i++) {
67
+ const next = [];
68
+ for (const p of edge)
69
+ for (const q of links.get(p) ?? [])
70
+ if (!seen.has(q)) {
71
+ seen.add(q);
72
+ next.push(q);
73
+ }
74
+ edge = next;
75
+ }
76
+ return [...seen].filter((p) => !start.includes(p)).sort(byText);
77
+ }
78
+ /** The pages to write for a changed-only view: changed and added ones, plus the `--hops` neighbors. */
79
+ export function changedPageSet(before, after, hops = 0) {
80
+ const d = diffPages(before, after);
81
+ const core = [...d.changed, ...d.added].sort(byText);
82
+ const context = hops > 0 ? expandHops(after, core, hops) : [];
83
+ return { pages: [...core, ...context].sort(byText), changes: { ...d, context } };
84
+ }
85
+ const pageLink = (name) => `[${name}](${name})`;
86
+ /** `changes.md`: what changed, which pages follow, and the quotes and source blocks the sources changed under the KB. */
87
+ export function changesPage(o) {
88
+ const { changes: c } = o;
89
+ const out = [BANNER, "", `# Changes in ${o.name} since ${o.against}`, ""];
90
+ out.push(`This folder holds only the reference pages whose text differs from \`${o.against}\`${o.hops ? `, plus the class pages within ${plural(o.hops, "link")} of one that changed` : ""}. Links to pages that aren't here point into the full \`okb docs\` output.`, "");
91
+ const section = (title, pages, none) => {
92
+ out.push(`## ${title}`, "");
93
+ if (pages.length)
94
+ out.push(...pages.map((p) => `- ${pageLink(p)}`));
95
+ else
96
+ out.push(none);
97
+ out.push("");
98
+ };
99
+ section("Pages that changed", [...c.changed, ...c.added].sort(byText), "No page's text changed.");
100
+ if (c.added.length)
101
+ out.push(`New pages: ${c.added.map((p) => `\`${p}\``).join(", ")}.`, "");
102
+ if (o.hops)
103
+ section(`Neighbors, for context (${plural(o.hops, "hop")})`, c.context, "No class page links to a changed one.");
104
+ if (c.removed.length)
105
+ out.push("## Pages that no longer exist", "", ...c.removed.map((p) => `- \`${p}\``), "");
106
+ out.push(...staleSection(o.resync));
107
+ return out.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
108
+ }
109
+ function staleSection(r) {
110
+ const out = ["## Source changes not yet in the knowledge base", ""];
111
+ if (!r)
112
+ return [...out, "Not checked.", ""];
113
+ out.push("A document that changed since the last `okb source refresh` changes no page until someone acts on it. This is what `okb source refresh --all --dry-run` finds now.", "");
114
+ const unreadable = r.sources.filter((s) => s.state === "unreadable");
115
+ for (const s of unreadable)
116
+ out.push(`- Can't read \`${s.id}\` (${s.problem}); its quotes weren't checked.`);
117
+ if (unreadable.length)
118
+ out.push("");
119
+ if (!r.gone.length && !r.moved.length && !r.worklist.length && !unreadable.length)
120
+ return [...out, "Nothing: every quote is still in its source, and no block changed since the baseline.", ""];
121
+ const cites = (cs) => (cs.length ? cs.map((x) => `${x.type.toLowerCase()} ${x.label} (\`${x.id}\`)`).join(", ") : "nothing");
122
+ if (r.gone.length) {
123
+ out.push(`### Quotes that are gone (${r.gone.length})`, "", "The text is no longer in the source. Whatever cites it needs a new quote or a decision.", "");
124
+ for (const g of [...r.gone].sort((a, b) => byText(a.quote, b.quote)))
125
+ out.push(`- \`${g.quote}\` in \`${g.source}\` (was ${g.was.locator ?? "?"}${g.was.lines ? `, line ${g.was.lines}` : ""}): "${oneLine(g.text)}"`, ` - Cited by ${cites(g.citedBy)}.`);
126
+ out.push("");
127
+ }
128
+ if (r.moved.length) {
129
+ out.push(`### Quotes that moved (${r.moved.length})`, "", "Still in the source, at other lines. `okb source refresh --all` updates them.", "");
130
+ for (const m of [...r.moved].sort((a, b) => byText(a.quote, b.quote)))
131
+ out.push(`- \`${m.quote}\`: line ${m.was.lines ?? "?"} → ${m.now.lines ?? "?"}${m.now.locator !== m.was.locator ? ` (now under ${m.now.locator})` : ""}. Cited by ${cites(m.citedBy)}.`);
132
+ out.push("");
133
+ }
134
+ if (r.worklist.length) {
135
+ out.push(`### Blocks to extract or re-check (${r.worklist.length})`, "");
136
+ for (const w of r.worklist) {
137
+ const where = w.lines ? `line ${w.lines[0]}${w.lines[1] > w.lines[0] ? `-${w.lines[1]}` : ""}` : "removed";
138
+ out.push(`- ${w.change}, \`${w.source}\`, ${where}, ${w.headingPath.join(" > ") || "(top)"}: ${oneLine((w.change === "removed" ? w.oldPreview : w.preview) ?? "")}`);
139
+ }
140
+ out.push("");
141
+ }
142
+ return out;
143
+ }
144
+ // ---------------------------------------------------------------------------
145
+ // The context view
146
+ // ---------------------------------------------------------------------------
147
+ /** Source lines shown above and below a quote. */
148
+ export const CONTEXT_LINES = 3;
149
+ const PROBLEM_ORDER = ["unsupported", "overreach", "unverified", "no quote", "quote gone"];
150
+ const PROBLEM_TEXT = {
151
+ unsupported: "UNSUPPORTED: the verifier found nothing in the quote that supports it",
152
+ overreach: "OVERREACH: corrected, and no person has approved the correction yet",
153
+ unverified: "Not verified yet",
154
+ "no quote": "Cites no quote",
155
+ "quote gone": "Its quote is no longer in the source",
156
+ };
157
+ function quoteContext(loc, doc, hasFile) {
158
+ if (doc === undefined)
159
+ return { note: hasFile ? "The source file wasn't loaded." : "This source has no local file, so there is no text around the quote to show." };
160
+ if (doc instanceof Error)
161
+ return { note: `Can't read the source (${doc.message}).` };
162
+ if (Array.isArray(doc))
163
+ return { note: `The source isn't markdown. The quote is on page ${loc.page ?? "?"}; open the document to read around it.` };
164
+ const hits = locate(doc, loc.quote);
165
+ if (!hits.length)
166
+ return { note: "The quote is no longer in the source (okb source refresh --all says more)." };
167
+ const want = loc.startLine ?? 0;
168
+ const hit = hits.reduce((a, b) => (Math.abs(b.startLine - want) < Math.abs(a.startLine - want) ? b : a));
169
+ const first = Math.max(1, hit.startLine - CONTEXT_LINES);
170
+ const last = Math.min(doc.lines.length, hit.endLine + CONTEXT_LINES);
171
+ return { lines: doc.lines.slice(first - 1, last), first, marked: [hit.startLine, hit.endLine] };
172
+ }
173
+ /** A fence longer than any run of backticks in the text, so source code samples can't close it early. */
174
+ function fenced(body) {
175
+ const longest = Math.max(0, ...body.map((l) => Math.max(0, ...(l.match(/`+/g) ?? []).map((r) => r.length))));
176
+ const fence = "`".repeat(Math.max(3, longest + 1));
177
+ return [`${fence}text`, ...body, fence];
178
+ }
179
+ /** Every reason the rule needs a person, most urgent first. */
180
+ function problemsOf(rule, shown) {
181
+ const v = rule.verification;
182
+ const out = [];
183
+ if (v?.status === "UNSUPPORTED")
184
+ out.push("unsupported");
185
+ if (v?.status === "OVERREACH")
186
+ out.push("overreach");
187
+ if (!v)
188
+ out.push("unverified");
189
+ if (!shown.length)
190
+ out.push("no quote");
191
+ if (shown.some((s) => "note" in s.context && s.context.note.startsWith("The quote is no longer")))
192
+ out.push("quote gone");
193
+ return out;
194
+ }
195
+ function ruleInContext(ont, rule, problems, shown) {
196
+ const out = [`### ${rule.name}`, "", `**${rule.modality.replace("_", " ")}.** ${rule.statement}`, ""];
197
+ const v = rule.verification;
198
+ const bullets = [];
199
+ for (const p of problems)
200
+ bullets.push(`- Needs a person: ${PROBLEM_TEXT[p]}.`);
201
+ bullets.push(`- Rule: \`${rule.id}\`${rule.authored ? " (written by the owner)" : ""}`);
202
+ const governs = ont.targets(rule.id, "GOVERNS").map((g) => nameOrText(ont.require(g)) ?? g).sort(byText);
203
+ if (governs.length)
204
+ bullets.push(`- Governs: ${governs.join(", ")}`);
205
+ bullets.push(`- Verification: ${v ? v.status.toLowerCase() : "not verified"}${v?.approvedAfter ? ` (a person approved it after ${v.approvedAfter.toLowerCase()})` : ""}${rule.extractionConfidence ? `, confidence ${rule.extractionConfidence}` : ""}`);
206
+ if (v?.note || v?.ref)
207
+ bullets.push(`- Verifier's note: ${[v.note ? oneLine(v.note) : "", v.ref ? `<${v.ref}>` : ""].filter(Boolean).join(" ")}`);
208
+ if (rule._originalDraft)
209
+ bullets.push(`- Original draft, before the correction: ${oneLine(rule._originalDraft)}`);
210
+ out.push(...bullets, "");
211
+ for (const { loc, context } of shown) {
212
+ const src = ont.targets(loc.id, "PART_OF").map((i) => ont.get(i)).find((n) => n?.type === "Source");
213
+ out.push(`**Quote** (${src && "title" in src ? `${src.title}, ` : ""}${loc.locator ?? loc.id}${loc.lines ? `, line ${loc.lines}` : ""}):`, "", `> ${oneLine(loc.quote)}`, "");
214
+ if ("note" in context) {
215
+ out.push(context.note, "");
216
+ continue;
217
+ }
218
+ const width = String(context.first + context.lines.length - 1).length;
219
+ out.push(`The source around it (the quoted lines are marked with \`>\`):`, "");
220
+ out.push(...fenced(context.lines.map((text, i) => {
221
+ const n = context.first + i;
222
+ const mark = n >= context.marked[0] && n <= context.marked[1] ? ">" : " ";
223
+ return `${mark} ${String(n).padStart(width)} | ${text}`.trimEnd();
224
+ })), "");
225
+ }
226
+ return out;
227
+ }
228
+ /**
229
+ * `rules-in-context.md`: every rule beside the source text around its quote, problem cases first (then by
230
+ * name). `pages` is `loadSourcePages(ont)`; sources that aren't there or aren't markdown show the quote alone.
231
+ */
232
+ export function contextPage(ont, pages) {
233
+ const rules = ont.ofType("Rule");
234
+ const rows = rules.map((rule) => {
235
+ const shown = ont.targets(rule.id, "CITES").map((id) => ont.get(id)).filter((n) => n?.type === "SourceLocation")
236
+ .sort((a, b) => byText(a.id, b.id)).map((loc) => {
237
+ const src = ont.targets(loc.id, "PART_OF").map((i) => ont.get(i)).find((n) => n?.type === "Source");
238
+ return { loc, context: quoteContext(loc, src ? pages.get(src.id) : undefined, !!(src && src.type === "Source" && src.localPath)) };
239
+ });
240
+ return { rule, shown, problems: problemsOf(rule, shown) };
241
+ });
242
+ const rank = (p) => (p.length ? PROBLEM_ORDER.indexOf(p[0]) : PROBLEM_ORDER.length);
243
+ rows.sort((a, b) => rank(a.problems) - rank(b.problems) || byText(a.rule.name.toLowerCase(), b.rule.name.toLowerCase()) || byText(a.rule.id, b.rule.id));
244
+ const problems = rows.filter((r) => r.problems.length);
245
+ const out = [BANNER, "", `# Rules in context: ${ont.meta.name}`, ""];
246
+ if (!rows.length)
247
+ return [...out, "This knowledge base has no rules yet.", ""].join("\n");
248
+ out.push(`${plural(rows.length, "rule")}, each beside the source text around its quote, so you can check the rule against what the document says nearby, not just the sentence it quotes. The verifier saw only the quote and the statement; this page is the first place the rule meets its surroundings.`, "");
249
+ out.push("## Needs a person", "");
250
+ if (!problems.length)
251
+ out.push("Nothing is flagged. Every rule is verified and its quote is in the source.", "");
252
+ else
253
+ out.push(`${plural(problems.length, "rule")}: ${PROBLEM_ORDER.map((p) => [p, problems.filter((r) => r.problems[0] === p).length]).filter(([, n]) => n).map(([p, n]) => `${n} ${p}`).join(", ")}.`, "");
254
+ for (const r of problems)
255
+ out.push(...ruleInContext(ont, r.rule, r.problems, r.shown));
256
+ const rest = rows.filter((r) => !r.problems.length);
257
+ if (rest.length) {
258
+ out.push("## Everything else", "");
259
+ for (const r of rest)
260
+ out.push(...ruleInContext(ont, r.rule, [], r.shown));
261
+ }
262
+ return out.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
263
+ }
@@ -0,0 +1,3 @@
1
+ import { type Command, type Globals } from "./command-table.js";
2
+ /** Run one command line (without the program name) against the table. */
3
+ export declare function runCommand(commands: readonly Command[], argv: readonly string[], globals: Partial<Globals>): Promise<void>;
package/dist/runner.js ADDED
@@ -0,0 +1,79 @@
1
+ /**
2
+ * The runners a command record uses through its `Ctx`: load the folder, change it under the
3
+ * lock, print. Records never touch the filesystem, the lock or `console` themselves.
4
+ */
5
+ import { writeFileSync } from "node:fs";
6
+ import { resolve as resolvePath } from "node:path";
7
+ import { OkbError, Ontology } from "@ontology-kit/reader";
8
+ import { formatNotes } from "./render.js";
9
+ import { resolve, parseForm } from "./command-table.js";
10
+ function lines(text) {
11
+ return Array.isArray(text) ? text : [text];
12
+ }
13
+ function makeCtx(commands, opts, args, globals) {
14
+ const dir = globals.C ?? opts.C ?? ".";
15
+ const print = (text) => {
16
+ for (const l of lines(text))
17
+ console.log(l);
18
+ };
19
+ const say = (notes) => print(formatNotes(notes));
20
+ const edit = (fn) => Ontology.edit(dir, fn);
21
+ return {
22
+ opts,
23
+ args,
24
+ json: globals.json ?? !!opts.json,
25
+ commands,
26
+ dir,
27
+ int(name) {
28
+ const x = opts[name];
29
+ if (x === undefined)
30
+ return undefined;
31
+ if (!/^\d+$/.test(x))
32
+ throw new OkbError(`--${name} needs a whole number (0 or more).`);
33
+ return Number(x);
34
+ },
35
+ load: () => Ontology.load(dir),
36
+ edit,
37
+ editAsync: (fn) => Ontology.edit(dir, fn),
38
+ mutate(fn) {
39
+ edit((ont) => {
40
+ const notes = ont.tick(() => fn(ont));
41
+ ont.save();
42
+ say(notes);
43
+ });
44
+ },
45
+ async mutateAsync(fn) {
46
+ await Ontology.edit(dir, async (ont) => {
47
+ const notes = await fn(ont);
48
+ ont.save();
49
+ say(notes);
50
+ });
51
+ },
52
+ emit(data, build) {
53
+ if (globals.json ?? opts.json)
54
+ console.log(JSON.stringify(data(), null, 2));
55
+ else {
56
+ const out = lines(build());
57
+ if (out.length)
58
+ print(out);
59
+ }
60
+ },
61
+ emitRaw(data, text) {
62
+ if (globals.json ?? opts.json)
63
+ console.log(JSON.stringify(data(), null, 2));
64
+ else
65
+ process.stdout.write(text());
66
+ },
67
+ say,
68
+ print,
69
+ printRaw: (text) => void process.stdout.write(text),
70
+ write: (path, text) => writeFileSync(resolvePath(path), text),
71
+ exit: (code) => void (process.exitCode = code),
72
+ };
73
+ }
74
+ /** Run one command line (without the program name) against the table. */
75
+ export async function runCommand(commands, argv, globals) {
76
+ const { form, rest } = resolve(commands, argv);
77
+ const { opts, args } = parseForm(form, rest);
78
+ await form.run(makeCtx(commands, opts, args, globals));
79
+ }
package/dist/skills.js CHANGED
@@ -7,7 +7,7 @@ import { cpSync, lstatSync, existsSync, mkdirSync, readdirSync, readFileSync, re
7
7
  import { homedir } from "node:os";
8
8
  import { dirname, join, resolve } from "node:path";
9
9
  import { fileURLToPath } from "node:url";
10
- import { OkbError } from "@ontology-kit/format";
10
+ import { OkbError } from "@ontology-kit/reader";
11
11
  /** The skills in this package. From src/ and from dist/ the package root is one folder up. */
12
12
  export const PACKAGED_SKILLS_DIR = join(dirname(dirname(fileURLToPath(import.meta.url))), "skills");
13
13
  /** Where skills go when `--dir` is not given: `$OKB_SKILLS_DIR`, else `~/.claude/skills` (Cursor reads that folder too). */
package/dist/status.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type Ontology } from "@ontology-kit/format";
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/format";
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/format). */
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/format). */
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,18 @@
1
+ import type { Modality } from "@ontology-kit/reader";
2
+ /**
3
+ * One sentence naming what changed: a modality, a number, or a few words. Null when the difference
4
+ * can't be named this way (a rewording, or a change too big to list), so the caller falls back to the
5
+ * generic tip.
6
+ */
7
+ export declare function suggestNote(original: string, corrected: string): string | null;
8
+ /**
9
+ * The one modality a statement states in capitals (`... SHOULD be ...` is SHOULD, `MUST NOT` is MUST_NOT), or null
10
+ * when it states none or more than one. Lower-case "may" or "should" is ordinary prose and doesn't count.
11
+ */
12
+ export declare function statedModality(statement: string): Modality | null;
13
+ /** A double-quoted shell argument. */
14
+ export declare const shellQuote: (s: string) => string;
15
+ export declare const GENERIC_NOTE_TIP = "Tip: add a note so a reviewer sees why, not just the verdict: --note \"<one sentence naming the word or number you changed>\". Skip it when the correction speaks for itself.";
16
+ export declare const UNSUPPORTED_NOTE_TIP = "Tip: add --note \"<which part of the statement the quote doesn't support>\". One sentence naming the word or claim; don't restate UNSUPPORTED.";
17
+ /** Lines to print after OVERREACH with no --note. */
18
+ export declare function overreachNoteTips(id: string, original: string, corrected: string, extra: string): string[];
@@ -0,0 +1,92 @@
1
+ const MODALITY = /\b(MUST\s+NOT|SHOULD\s+NOT|MUST|SHOULD|MAY)\b/gi;
2
+ const keyword = (m) => m.toUpperCase().replace(/\s+/g, " ");
3
+ const NUMBER = /\d+(?:[.,]\d+)*/g;
4
+ const WORD = /[\p{L}'-]+/gu;
5
+ /** Strongest first, so a drop in rank reads as narrowing. */
6
+ const RANK = ["MUST NOT", "MUST", "SHOULD NOT", "SHOULD", "MAY"];
7
+ /** A diff longer than this is a rewrite, and a list of words wouldn't name it. */
8
+ const MAX_WORDS = 4;
9
+ const found = (text, re) => [...text.matchAll(re)].map((m) => m[0]);
10
+ const quote = (words) => words.map((w) => `"${w}"`).join(", ");
11
+ /** Items in `a` that `b` doesn't have, counting repeats. */
12
+ function without(a, b) {
13
+ const left = [...b];
14
+ return a.filter((x) => {
15
+ const i = left.indexOf(x);
16
+ if (i < 0)
17
+ return true;
18
+ left.splice(i, 1);
19
+ return false;
20
+ });
21
+ }
22
+ /** Words minus the modality and number tokens, which the other parts of the suggestion name. */
23
+ function plainWords(text) {
24
+ return found(text.replace(MODALITY, " ").replace(NUMBER, " "), WORD).map((w) => w.toLowerCase());
25
+ }
26
+ /**
27
+ * One sentence naming what changed: a modality, a number, or a few words. Null when the difference
28
+ * can't be named this way (a rewording, or a change too big to list), so the caller falls back to the
29
+ * generic tip.
30
+ */
31
+ export function suggestNote(original, corrected) {
32
+ const parts = [];
33
+ const m0 = found(original, MODALITY).map(keyword);
34
+ const m1 = found(corrected, MODALITY).map(keyword);
35
+ if (m0.length && m0.length === m1.length) {
36
+ const i = m0.findIndex((m, k) => m !== m1[k]);
37
+ if (i >= 0) {
38
+ const [r0, r1] = [RANK.indexOf(m0[i]), RANK.indexOf(m1[i])];
39
+ // MUST NOT to MUST (or the other way) flips the meaning; it is neither narrower nor stronger.
40
+ const flips = m0[i].endsWith("NOT") !== m1[i].endsWith("NOT");
41
+ parts.push(`${flips ? "changed" : r1 > r0 ? "narrowed" : "strengthened"} ${m0[i]} to ${m1[i]}`);
42
+ }
43
+ }
44
+ else if (m0.join() !== m1.join())
45
+ return null;
46
+ const n0 = found(original, NUMBER);
47
+ const n1 = found(corrected, NUMBER);
48
+ const goneN = without(n0, n1);
49
+ const newN = without(n1, n0);
50
+ if (goneN.length && goneN.length === newN.length)
51
+ parts.push(`changed ${goneN.join(", ")} to ${newN.join(", ")}`);
52
+ else {
53
+ if (goneN.length)
54
+ parts.push(`removed ${goneN.join(", ")}`);
55
+ if (newN.length)
56
+ parts.push(`added ${newN.join(", ")}`);
57
+ }
58
+ const w0 = plainWords(original);
59
+ const w1 = plainWords(corrected);
60
+ const goneW = without(w0, w1);
61
+ const newW = without(w1, w0);
62
+ if (goneW.length > MAX_WORDS || newW.length > MAX_WORDS)
63
+ return null;
64
+ if (goneW.length && newW.length && goneW.length === newW.length && goneW.length <= 2)
65
+ parts.push(`replaced ${quote(goneW)} with ${quote(newW)}`);
66
+ else {
67
+ if (goneW.length)
68
+ parts.push(`removed ${quote(goneW)}`);
69
+ if (newW.length)
70
+ parts.push(`added ${quote(newW)}`);
71
+ }
72
+ return parts.length ? parts.join("; ") : null;
73
+ }
74
+ /**
75
+ * The one modality a statement states in capitals (`... SHOULD be ...` is SHOULD, `MUST NOT` is MUST_NOT), or null
76
+ * when it states none or more than one. Lower-case "may" or "should" is ordinary prose and doesn't count.
77
+ */
78
+ export function statedModality(statement) {
79
+ 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, "_")));
80
+ return found.size === 1 ? [...found][0] : null;
81
+ }
82
+ /** A double-quoted shell argument. */
83
+ export const shellQuote = (s) => `"${s.replace(/(["\\$`])/g, "\\$1")}"`;
84
+ export const GENERIC_NOTE_TIP = 'Tip: add a note so a reviewer sees why, not just the verdict: --note "<one sentence naming the word or number you changed>". Skip it when the correction speaks for itself.';
85
+ export const UNSUPPORTED_NOTE_TIP = 'Tip: add --note "<which part of the statement the quote doesn\'t support>". One sentence naming the word or claim; don\'t restate UNSUPPORTED.';
86
+ /** Lines to print after OVERREACH with no --note. */
87
+ export function overreachNoteTips(id, original, corrected, extra) {
88
+ const s = suggestNote(original, corrected);
89
+ if (!s)
90
+ return [GENERIC_NOTE_TIP];
91
+ return [`Suggested note: ${s}`, `To store it: okb verify ${id} --status OVERREACH --corrected ${shellQuote(corrected)} --note ${shellQuote(s)}${extra}`];
92
+ }