@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.
Files changed (109) hide show
  1. package/README.md +1 -1
  2. package/dist/check.d.ts +43 -0
  3. package/dist/check.js +102 -0
  4. package/dist/checks.d.ts +1 -1
  5. package/dist/checks.js +27 -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 +144 -0
  11. package/dist/command-table.js +85 -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 +467 -0
  20. package/dist/commands/planning.d.ts +3 -0
  21. package/dist/commands/planning.js +251 -0
  22. package/dist/commands/reviewing.d.ts +3 -0
  23. package/dist/commands/reviewing.js +234 -0
  24. package/dist/commands/skills.d.ts +3 -0
  25. package/dist/commands/skills.js +53 -0
  26. package/dist/commands.d.ts +10 -22
  27. package/dist/commands.js +15 -622
  28. package/dist/cqanswer.d.ts +51 -0
  29. package/dist/cqanswer.js +76 -0
  30. package/dist/diff.d.ts +85 -0
  31. package/dist/diff.js +323 -0
  32. package/dist/export-changes.d.ts +40 -0
  33. package/dist/export-changes.js +115 -0
  34. package/dist/export-csv.d.ts +17 -0
  35. package/dist/export-csv.js +188 -0
  36. package/dist/export-eval-cases.d.ts +38 -0
  37. package/dist/export-eval-cases.js +40 -0
  38. package/dist/export.d.ts +34 -3
  39. package/dist/export.js +70 -12
  40. package/dist/families.d.ts +1 -1
  41. package/dist/families.js +1 -1
  42. package/dist/help.d.ts +11 -2
  43. package/dist/help.js +51 -57
  44. package/dist/kbdocs.d.ts +18 -0
  45. package/dist/kbdocs.js +393 -0
  46. package/dist/metakb.d.ts +1 -1
  47. package/dist/metakb.js +1 -1
  48. package/dist/naming.d.ts +2 -2
  49. package/dist/naming.js +2 -2
  50. package/dist/ontology-ref.d.ts +20 -0
  51. package/dist/ontology-ref.js +108 -0
  52. package/dist/ops/admin.d.ts +2 -2
  53. package/dist/ops/admin.js +26 -8
  54. package/dist/ops/classes.d.ts +1 -1
  55. package/dist/ops/classes.js +15 -7
  56. package/dist/ops/common.d.ts +12 -2
  57. package/dist/ops/common.js +3 -0
  58. package/dist/ops/instances.d.ts +2 -1
  59. package/dist/ops/instances.js +9 -3
  60. package/dist/ops/links.d.ts +2 -2
  61. package/dist/ops/links.js +3 -2
  62. package/dist/ops/naming.d.ts +1 -1
  63. package/dist/ops/naming.js +3 -1
  64. package/dist/ops/scope.d.ts +14 -3
  65. package/dist/ops/scope.js +38 -4
  66. package/dist/ops/slots.d.ts +1 -1
  67. package/dist/ops/slots.js +21 -8
  68. package/dist/ops/values.d.ts +1 -1
  69. package/dist/ops/values.js +5 -1
  70. package/dist/provenance.d.ts +5 -3
  71. package/dist/provenance.js +61 -19
  72. package/dist/release.d.ts +52 -0
  73. package/dist/release.js +337 -0
  74. package/dist/render.d.ts +88 -1
  75. package/dist/render.js +265 -3
  76. package/dist/resync.d.ts +98 -0
  77. package/dist/resync.js +234 -0
  78. package/dist/review.d.ts +1 -1
  79. package/dist/review.js +1 -1
  80. package/dist/reviewdocs.d.ts +42 -0
  81. package/dist/reviewdocs.js +263 -0
  82. package/dist/runner.d.ts +3 -0
  83. package/dist/runner.js +84 -0
  84. package/dist/skills.d.ts +19 -3
  85. package/dist/skills.js +130 -14
  86. package/dist/status.d.ts +1 -1
  87. package/dist/status.js +1 -1
  88. package/dist/types.d.ts +1 -1
  89. package/dist/types.js +1 -1
  90. package/dist/verifynote.d.ts +19 -0
  91. package/dist/verifynote.js +93 -0
  92. package/dist/workflows.d.ts +283 -0
  93. package/dist/workflows.js +270 -0
  94. package/meta-kb/data/edges.json +25 -0
  95. package/meta-kb/data/manifest.json +5 -5
  96. package/meta-kb/data/nodes.json +46 -9
  97. package/package.json +9 -4
  98. package/schema/edge.schema.json +68 -0
  99. package/schema/edges.schema.json +9 -0
  100. package/schema/node.schema.json +914 -0
  101. package/schema/nodes.schema.json +9 -0
  102. package/schema/okb.schema.json +41 -0
  103. package/skills/build-domain-kb-from-docs/SKILL.md +21 -3
  104. package/skills/ontology-coach/SKILL.md +8 -4
  105. package/skills/ontology-maintainer/SKILL.md +152 -0
  106. package/skills/ontology-review/SKILL.md +4 -2
  107. package/skills/ontology-signoff/SKILL.md +182 -0
  108. package/templates/okb-check.yml +148 -0
  109. package/templates/pull_request_template.md +16 -0
@@ -0,0 +1,251 @@
1
+ /** Planning: scope, competency questions, reuse and terms (steps 1 to 3). */
2
+ import { opt } from "../command-table.js";
3
+ import { OkbError } from "@ontology-kit/reader";
4
+ import * as ops from "../ops.js";
5
+ import { checkQuestions, describeResult } from "../cqanswer.js";
6
+ import { renderQuestions, renderReuse, renderScope, renderTerms } from "../render.js";
7
+ const { str, strs } = opt;
8
+ const SCOPE_OPTIONS = { name: str, domain: str, purpose: str, users: strs, maintainers: strs, "out-of-scope": strs, kind: str };
9
+ export const planning = [
10
+ {
11
+ name: "scope",
12
+ group: "Planning",
13
+ summary: "record the domain, purpose and users",
14
+ description: "Records the domain, purpose, users and boundaries of the ontology. With no flags it shows what you have.",
15
+ forms: [
16
+ {
17
+ description: "Sets any of the fields you pass and prints the result.",
18
+ examples: ["okb scope --domain \"Wine and food pairing\" --purpose \"Recommend wines for a meal\" --users sommeliers,cooks"],
19
+ args: [
20
+ ["--domain", "text", "What the ontology covers."],
21
+ ["--purpose", "text", "What it is for."],
22
+ ["--users", "list", "Who will use it."],
23
+ ["--maintainers", "list", "Who keeps it up to date."],
24
+ ["--out-of-scope", "list", "What it deliberately leaves out."],
25
+ ["--kind", "text", "The kind of ontology, such as a domain ontology."],
26
+ ["--name", "text", "Rename the ontology."],
27
+ ],
28
+ options: SCOPE_OPTIONS,
29
+ cheat: { example: "okb scope --domain \"...\" --purpose \"...\"", description: "Record what the ontology is for" },
30
+ run: (ctx) => {
31
+ const o = ctx.opts;
32
+ const touched = Object.keys(SCOPE_OPTIONS).some((k) => o[k] !== undefined);
33
+ const ont = touched
34
+ ? ctx.edit((ont) => {
35
+ ops.setScope(ont, { name: o.name, domain: o.domain, purpose: o.purpose, users: o.users, maintainers: o.maintainers, outOfScope: o["out-of-scope"], kind: o.kind });
36
+ ont.save();
37
+ return ont;
38
+ })
39
+ : ctx.load();
40
+ ctx.emit(() => ont.meta, () => renderScope(ont.meta));
41
+ },
42
+ },
43
+ ],
44
+ },
45
+ {
46
+ name: "cq",
47
+ group: "Planning",
48
+ summary: "competency questions",
49
+ description: "Manages competency questions: the questions your ontology must be able to answer.",
50
+ bare: "list",
51
+ forms: [
52
+ {
53
+ sub: "add",
54
+ description: "Adds one or more questions.",
55
+ examples: ["okb cq add \"Which wines go with fish?\""],
56
+ args: [
57
+ ["<question>", "text", "The question. Quote it."],
58
+ ],
59
+ usage: 'Usage: okb cq add "Your question?"',
60
+ min: 1,
61
+ cheat: { example: "okb cq add \"Which wines go with fish?\"", description: "Add a competency question" },
62
+ run: (ctx) => ctx.mutate((ont) => ctx.args.flatMap((t) => ops.addCQ(ont, t))),
63
+ },
64
+ {
65
+ sub: "list",
66
+ description: "Lists the questions and what each one needs. Bare `okb cq` does the same.",
67
+ examples: ["okb cq list"],
68
+ args: [],
69
+ run: (ctx) => {
70
+ const ont = ctx.load();
71
+ const qs = ont.numbered("CompetencyQuestion");
72
+ ctx.emit(() => qs.map((q) => ({ ...q, needs: ont.targets(q.id, "NEEDS") })), () => renderQuestions(ont, qs));
73
+ },
74
+ },
75
+ {
76
+ sub: "link",
77
+ description: "Says which classes, slots or instances a question needs. Use `unlink` to undo it.",
78
+ examples: ["okb cq link 1 Wine Food goesWellWith"],
79
+ args: [
80
+ ["<number>", "number", "The question's number."],
81
+ ["<name>...", "names", "The classes, slots or instances it needs."],
82
+ ],
83
+ usage: "Usage: okb cq link <question number> <Class|slot|instance>...",
84
+ min: 2,
85
+ run: (ctx) => ctx.mutate((ont) => ops.linkCQ(ont, ctx.args[0], ctx.args.slice(1), false)),
86
+ },
87
+ {
88
+ sub: "set",
89
+ description: "Changes a question's text or marks it answerable.",
90
+ examples: ["okb cq set 1 --status answerable"],
91
+ args: [
92
+ ["<number>", "number", "The question's number."],
93
+ ["--text", "text", "New wording."],
94
+ ["--status", "draft or answerable", "Whether the ontology can answer it yet."],
95
+ ],
96
+ options: { text: str, status: str },
97
+ run: (ctx) => ctx.mutate((ont) => ops.setCQ(ont, ctx.args[0], { text: ctx.opts.text, status: ctx.opts.status })),
98
+ },
99
+ {
100
+ sub: "answer",
101
+ description: "Stores the answer a question should get: a query (one JSON object) and the names it must return. The query is `{\"find\": {\"class\": ..., \"where\": {slot: value}}}` (instances of a class), `{\"traverse\": {\"from\": ..., \"slot\": ...}}` (what a slot gives for one thing) or `{\"slots\": {\"of\": ...}}` (a thing's slots). `okb cq check` runs it later.",
102
+ examples: ["okb cq answer 6 --query '{\"traverse\":{\"from\":\"Chateau Morgon\",\"slot\":\"produces\"}}' --expect \"Chateau Morgon Beaujolais\""],
103
+ args: [
104
+ ["<number>", "number", "The question's number."],
105
+ ["--query", "JSON", "The query to run."],
106
+ ["--expect", "list", "The names it must return, separated by commas."],
107
+ ["--exact", "flag", "Fail on a name that isn't listed (the default)."],
108
+ ["--includes", "flag", "Pass as long as the listed names are there."],
109
+ ],
110
+ options: { query: str, expect: strs, exact: opt.bool, includes: opt.bool },
111
+ usage: "Usage: okb cq answer <question number> --query '<JSON>' --expect A,B,C [--exact|--includes]",
112
+ min: 1,
113
+ max: 1,
114
+ cheat: { example: "okb cq answer 1 --query '{...}' --expect A,B", description: "Store a question's expected answer" },
115
+ run: (ctx) => {
116
+ const o = ctx.opts;
117
+ if (o.query === undefined || o.expect === undefined)
118
+ throw new OkbError("cq answer needs --query and --expect.");
119
+ if (o.exact && o.includes)
120
+ throw new OkbError("Use --exact or --includes, not both.");
121
+ ctx.mutate((ont) => ops.answerCQ(ont, ctx.args[0], { query: o.query, expect: o.expect, match: o.includes ? "includes" : "exact" }));
122
+ },
123
+ },
124
+ {
125
+ sub: "check",
126
+ description: "Runs each question's stored query and compares the names with the expected answer. Prints pass, fail (with the missing and extra names) or no answer stored for each question, and exits non-zero when any fails. `okb check` includes it.",
127
+ examples: ["okb cq check", "okb cq check --json"],
128
+ args: [],
129
+ usage: "Usage: okb cq check [--json]",
130
+ max: 0,
131
+ run: (ctx) => {
132
+ const results = checkQuestions(ctx.load());
133
+ ctx.emit(() => results, () => (results.length ? results.map(describeResult) : ["No competency questions yet."]));
134
+ ctx.exit(results.some((r) => r.status === "fail") ? 1 : 0);
135
+ },
136
+ },
137
+ {
138
+ sub: "remove",
139
+ description: "Deletes a question.",
140
+ examples: ["okb cq remove 3"],
141
+ args: [
142
+ ["<number>", "number", "The question's number."],
143
+ ],
144
+ run: (ctx) => ctx.mutate((ont) => ops.remove(ont, ctx.args[0], ["CompetencyQuestion"])),
145
+ },
146
+ {
147
+ sub: "unlink",
148
+ description: "",
149
+ examples: [],
150
+ args: [],
151
+ usage: "Usage: okb cq unlink <question number> <Class|slot|instance>...",
152
+ min: 2,
153
+ hidden: true,
154
+ run: (ctx) => ctx.mutate((ont) => ops.linkCQ(ont, ctx.args[0], ctx.args.slice(1), true)),
155
+ },
156
+ ],
157
+ },
158
+ {
159
+ name: "reuse",
160
+ group: "Planning",
161
+ summary: "record existing ontologies you considered",
162
+ description: "Records which existing ontologies you looked at and what you decided about each.",
163
+ bare: "list",
164
+ forms: [
165
+ {
166
+ sub: "add",
167
+ description: "Records one ontology you considered.",
168
+ examples: ["okb reuse add --name FOAF --url http://xmlns.com/foaf/spec/ --decision reference"],
169
+ args: [
170
+ ["--name", "text", "The ontology's name."],
171
+ ["--decision", "reuse, adapt, reference or rejected", "What you decided."],
172
+ ["--url", "url", "Where it lives."],
173
+ ["--notes", "text", "Why."],
174
+ ],
175
+ options: { name: str, url: str, decision: str, notes: str },
176
+ usage: "Usage: okb reuse add --name ... --decision reuse|adapt|reference|rejected [--url ...] [--notes ...]",
177
+ require: ["name", "decision"],
178
+ run: (ctx) => ctx.mutate((ont) => ops.addReuse(ont, { name: ctx.opts.name, url: ctx.opts.url, decision: ctx.opts.decision, notes: ctx.opts.notes })),
179
+ },
180
+ {
181
+ sub: "none",
182
+ description: "Records that you looked and found nothing that fits.",
183
+ examples: ["okb reuse none --why \"Checked schema.org and FOAF; neither covers wine.\""],
184
+ args: [
185
+ ["--why", "text", "What you looked at and why nothing fit."],
186
+ ],
187
+ options: { why: str },
188
+ usage: 'Usage: okb reuse none --why "what you looked at and why nothing fit"',
189
+ require: ["why"],
190
+ cheat: { example: "okb reuse none --why \"...\"", description: "Record that nothing existing fits" },
191
+ run: (ctx) => ctx.mutate((ont) => ops.reuseNone(ont, ctx.opts.why)),
192
+ },
193
+ {
194
+ sub: "list",
195
+ description: "Lists what you recorded. Bare `okb reuse` does the same.",
196
+ examples: ["okb reuse list"],
197
+ args: [],
198
+ run: (ctx) => ctx.print(renderReuse(ctx.load())),
199
+ },
200
+ ],
201
+ },
202
+ {
203
+ name: "term",
204
+ group: "Planning",
205
+ summary: "collect the words of your domain",
206
+ description: "Collects the important words of your domain, then decides what each one becomes.",
207
+ bare: "list",
208
+ forms: [
209
+ {
210
+ sub: "add",
211
+ description: "Adds terms to the list.",
212
+ examples: ["okb term add wine grape winery color"],
213
+ args: [
214
+ ["<term>...", "text", "One or more terms. Quote multi-word terms."],
215
+ ["--note", "text", "A note to keep with them."],
216
+ ],
217
+ options: { note: str },
218
+ usage: "Usage: okb term add <term> [<term>...] (quote multi-word terms)",
219
+ min: 1,
220
+ cheat: { example: "okb term add wine grape winery", description: "Collect the words of your domain" },
221
+ run: (ctx) => ctx.mutate((ont) => ops.addTerms(ont, ctx.args, ctx.opts.note)),
222
+ },
223
+ {
224
+ sub: "list",
225
+ description: "Lists terms grouped by what you decided. Bare `okb term` does the same.",
226
+ examples: ["okb term list"],
227
+ args: [],
228
+ run: (ctx) => {
229
+ const ont = ctx.load();
230
+ ctx.emit(() => ont.ofType("Term"), () => renderTerms(ont));
231
+ },
232
+ },
233
+ {
234
+ sub: "set",
235
+ description: "Decides what a term becomes.",
236
+ examples: ["okb term set wine --as class", "okb term set vintage --as synonym --node Year"],
237
+ args: [
238
+ ["<term>", "text", "The term."],
239
+ ["--as", "class, slot, instance, value, synonym or out-of-scope", "What it becomes."],
240
+ ["--node", "name", "The class, slot or instance it became or points to."],
241
+ ["--note", "text", "A note about the decision."],
242
+ ],
243
+ options: { as: str, node: str, note: str },
244
+ usage: "Usage: okb term set <term> --as class|slot|instance|value|synonym|out-of-scope [--node Name]",
245
+ min: 1,
246
+ require: ["as"],
247
+ run: (ctx) => ctx.mutate((ont) => ops.setTerm(ont, ctx.args[0], ctx.opts.as, ctx.opts.node, ctx.opts.note)),
248
+ },
249
+ ],
250
+ },
251
+ ];
@@ -0,0 +1,3 @@
1
+ /** Reviewing and sharing: review questions, decisions, diagrams, exports and reference pages (step 8). */
2
+ import { type Command } from "../command-table.js";
3
+ export declare const reviewing: Command[];
@@ -0,0 +1,234 @@
1
+ /** Reviewing and sharing: review questions, decisions, diagrams, exports and reference pages (step 8). */
2
+ import { opt } from "../command-table.js";
3
+ import { OkbError, query } from "@ontology-kit/reader";
4
+ import * as ops from "../ops.js";
5
+ import { buildReview } from "../review.js";
6
+ import { mermaid, renderDecisions, renderQueryResult, renderChangeSetWritten, renderDiagramWritten, renderEvalCasesWritten, renderExportWritten, renderReview, renderWrote } from "../render.js";
7
+ import { exportEvalCases } from "../export-eval-cases.js";
8
+ import { docs, exportOntology, reviewData } from "../workflows.js";
9
+ const { str, strs, bool } = opt;
10
+ export const reviewing = [
11
+ {
12
+ name: "review",
13
+ group: "Reviewing and sharing",
14
+ summary: "questions only a person can judge",
15
+ description: "Turns the rules only a person can judge into questions about your ontology. The ontology-review skill uses it.",
16
+ forms: [
17
+ {
18
+ description: "Lists the questions for the steps you have reached.",
19
+ examples: ["okb review", "okb review --all --json"],
20
+ args: [
21
+ ["--all", "flag", "Include every rule, not only the visible ones."],
22
+ ["--json", "flag", "Print everything as JSON."],
23
+ ],
24
+ options: { all: bool },
25
+ cheat: { example: "okb review", description: "Get questions only a person can judge" },
26
+ run: (ctx) => {
27
+ const ont = ctx.load();
28
+ const items = buildReview(ont, ctx.opts.all);
29
+ ctx.emit(() => reviewData(ont, items), () => renderReview(ont, items, ctx.opts.all));
30
+ },
31
+ },
32
+ ],
33
+ },
34
+ {
35
+ name: "decision",
36
+ group: "Reviewing and sharing",
37
+ summary: "record a design decision",
38
+ description: "Records a design decision, with the reason, so you and others can see why the ontology is the way it is.",
39
+ bare: "list",
40
+ forms: [
41
+ {
42
+ sub: "add",
43
+ description: "Records a decision. A decision can waive a rule, which turns that rule's warning into a note.",
44
+ examples: ["okb decision add --title \"Wines are not foods\" --decision \"Keep them separate\" --why \"Pairing needs both\""],
45
+ args: [
46
+ ["--title", "text", "A short title."],
47
+ ["--decision", "text", "What you decided."],
48
+ ["--why", "text", "The reason."],
49
+ ["--question", "text", "The question it answers."],
50
+ ["--alt", "text", "An option you rejected. Repeat it for more."],
51
+ ["--about", "name", "A class, slot or instance it concerns. Repeat it for more."],
52
+ ["--waives", "rule key", "A rule it explains away. Repeat it for more."],
53
+ ],
54
+ options: { title: str, decision: str, question: str, why: str, alt: strs, about: strs, waives: strs },
55
+ usage: 'Usage: okb decision add --title "..." --decision "..." --why "..." [--about X] [--waives rule-id]',
56
+ require: ["title", "decision"],
57
+ cheat: { example: "okb decision add --title \"...\" --decision \"...\" --why \"...\"", description: "Record a design decision" },
58
+ run: (ctx) => {
59
+ const o = ctx.opts;
60
+ ctx.mutate((ont) => ops.addDecision(ont, { title: o.title, decision: o.decision, question: o.question, rationale: o.why, alternatives: o.alt, about: o.about, waives: o.waives }));
61
+ },
62
+ },
63
+ {
64
+ sub: "list",
65
+ description: "Lists the decisions. Bare `okb decision` does the same.",
66
+ examples: ["okb decision list"],
67
+ args: [],
68
+ run: (ctx) => {
69
+ const ont = ctx.load();
70
+ const ds = ont.numbered("DesignDecision");
71
+ ctx.emit(() => ds, () => renderDecisions(ont, ds));
72
+ },
73
+ },
74
+ ],
75
+ },
76
+ {
77
+ name: "diagram",
78
+ group: "Reviewing and sharing",
79
+ summary: "draw the ontology as Mermaid",
80
+ description: "Draws the ontology as a Mermaid diagram you can open in GitHub or VS Code.",
81
+ forms: [
82
+ {
83
+ description: "Prints the diagram, or writes it to a file.",
84
+ examples: ["okb diagram --out diagram.md"],
85
+ args: [
86
+ ["--out", "path", "Write the diagram here instead of printing it."],
87
+ ],
88
+ options: { out: str },
89
+ cheat: { example: "okb diagram --out diagram.md", description: "Draw the ontology" },
90
+ run: (ctx) => {
91
+ const md = mermaid(ctx.load());
92
+ const { out } = ctx.opts;
93
+ if (out) {
94
+ ctx.write(out, md + "\n");
95
+ ctx.print(renderDiagramWritten(out));
96
+ }
97
+ else
98
+ ctx.print(md);
99
+ },
100
+ },
101
+ ],
102
+ },
103
+ {
104
+ name: "export",
105
+ group: "Reviewing and sharing",
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.",
108
+ forms: [
109
+ {
110
+ description: "Prints the export, or writes it to a file.",
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"],
112
+ args: [
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."],
114
+ ["--out", "path", "Write to this file instead of printing. For neo4j-csv and neptune-csv it is a folder, which is required."],
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."],
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."],
117
+ ["--with-schema", "flag", "Include classes and slots, not only instances."],
118
+ ["--no-inherited", "flag", "Leave out values an instance inherits from its class."],
119
+ ["--no-rules", "flag", "Leave out extracted rules."],
120
+ ["--include-unverified", "flag", "Include rules and quotes that haven't been verified."],
121
+ ],
122
+ options: { format: str, out: str, style: str, since: str, "with-schema": bool, "no-inherited": bool, "no-rules": bool, "include-unverified": bool },
123
+ cheat: { example: "okb export --format cypher --out wine.cypher", description: "Export for a graph database" },
124
+ run: (ctx) => {
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
+ }
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"] });
141
+ if (o.out && files) {
142
+ for (const [name, body] of Object.entries(files))
143
+ ctx.write(`${o.out}/${name}`, body);
144
+ ctx.print(renderExportWritten(o.out, graph, fmt, Object.keys(files)));
145
+ }
146
+ else if (o.out && changes) {
147
+ ctx.write(o.out, text);
148
+ ctx.print(renderChangeSetWritten(o.out, changes));
149
+ }
150
+ else if (o.out) {
151
+ ctx.write(o.out, text);
152
+ ctx.print(renderExportWritten(o.out, graph, fmt));
153
+ }
154
+ else
155
+ ctx.printRaw(text);
156
+ },
157
+ },
158
+ ],
159
+ },
160
+ {
161
+ name: "query",
162
+ group: "Reviewing and sharing",
163
+ summary: "run one read-only query and print what it returns",
164
+ description: "Runs one query against the ontology and prints what it returns, the same every time, for a person or a script. The query is the one-key JSON object `okb cq answer` stores, so a query that works here can be stored with `okb cq answer` unchanged. It never changes the ontology. To look at one thing, use `okb show`.",
165
+ forms: [
166
+ {
167
+ description: "Runs the query. `{\"find\": {\"class\": ..., \"where\": {slot: value}}}` lists the instances of a class (and its subclasses) whose values match, `{\"traverse\": {\"from\": ..., \"slot\": ...}}` lists what a slot gives for one thing (or a list of things), and `{\"slots\": {\"of\": ...}}` lists a thing's slots. Quote the JSON so your shell passes it as one argument. With `--json` it prints `{kind, hits}`.",
168
+ examples: ["okb query '{\"find\":{\"class\":\"Drink\"}}'", "okb query '{\"slots\":{\"of\":\"Drink\"}}' --json"],
169
+ args: [
170
+ ["<json>", "JSON", "The query: an object with one key, `find`, `traverse` or `slots`."],
171
+ ],
172
+ usage: "Usage: okb query '<JSON>' [--json]",
173
+ min: 1,
174
+ max: 1,
175
+ cheat: { example: "okb query '{\"find\":{\"class\":\"Drink\"}}'", description: "Run a read-only query" },
176
+ run: (ctx) => {
177
+ let q;
178
+ try {
179
+ q = JSON.parse(ctx.args[0]);
180
+ }
181
+ catch {
182
+ throw new OkbError(`The query isn't valid JSON. Quote it as one argument. Example: okb query '{"find":{"class":"Wine","where":{"color":"red"}}}'`);
183
+ }
184
+ const ont = ctx.load();
185
+ const result = query(ont, q);
186
+ ctx.emit(() => result, () => renderQueryResult(ont, result));
187
+ },
188
+ },
189
+ ],
190
+ },
191
+ {
192
+ name: "docs",
193
+ group: "Reviewing and sharing",
194
+ summary: "write Markdown reference pages",
195
+ description: "Writes Markdown reference pages for the ontology, so people can read its structure and rules without okb: an index, one page per class, a rules page and a sources page.",
196
+ forms: [
197
+ {
198
+ description: "Writes `index.md` (scope, competency questions, class tree, decisions), `classes/<id>.md` (slots with allowed values, inherited and own rules with their quotes, instances, decisions), `rules.md` and `sources.md`. Every rule links to its quote on the sources page. Items have stable anchors made from their ids (`rule.breve` becomes `#rule-breve`), links are relative, and the output has no dates, so you can commit it and check it for drift. It replaces pages an earlier run wrote and leaves other files alone. It never changes the ontology.",
199
+ examples: ["okb docs --out docs/kb"],
200
+ args: [
201
+ ["--out", "folder", "Where to write the pages. Required; it is created if it doesn't exist."],
202
+ ],
203
+ options: { out: str, changed: str, hops: str, context: bool },
204
+ usage: "Usage: okb docs --out <folder> · okb docs --out <folder> --changed <ref> [--hops N] · okb docs --out <folder> --context",
205
+ max: 0,
206
+ require: ["out"],
207
+ run: async (ctx) => {
208
+ const o = ctx.opts;
209
+ const r = await docs(ctx.dir, o.out, { changed: o.changed, hops: o.hops, context: o.context });
210
+ ctx.emit(() => ({ out: o.out, files: r.files, ...r.extra }), () => renderWrote(o.out, r.what, r.hint));
211
+ },
212
+ },
213
+ {
214
+ sub: "--changed",
215
+ description: "A review view of a change: only the pages whose text differs from `<ref>` (a git ref or a folder, the same as `okb diff`). A rule changed on a class changes the page of every subclass that inherits it, so those pages come with it. It also writes `changes.md`, which lists the changed pages and the stale-quote worklist from `okb source refresh --all --dry-run` (quotes that are gone or moved, and blocks that are new or changed, each with the nodes that cite them), because a source edit that hasn't been re-synced yet changes no page. Pages are the same text as the full render, so links to pages that aren't in the folder point into the full output. It only adds and overwrites files, so write it to a scratch folder, not to the committed pages. It never changes the ontology.",
216
+ examples: ["okb docs --out review --changed main", "okb docs --out review --changed v1.0.0 --hops 1"],
217
+ args: [
218
+ ["--out", "folder", "Where to write the pages. Required."],
219
+ ["--changed", "ref", "The git ref (or folder) to compare the working folder with."],
220
+ ["--hops", "number", "Also write the class pages that link to or from a changed class page, this many links away. Default 0. It doesn't go through the index, rules or sources pages, which link to everything."],
221
+ ],
222
+ },
223
+ {
224
+ sub: "--context",
225
+ description: "A review view of every rule beside the source text around its quote: the statement, modality, verification status, the verifier's note (when `okb verify --note` stored one), the original draft of a corrected rule, the quote, and the lines around it with the quoted lines marked. Rules that need a person come first (UNSUPPORTED, OVERREACH not yet approved, not verified, no quote, quote no longer in the source), then the rest by name. It reads the source files, so it needs them on disk. A source that isn't Markdown shows the quote alone. It writes `rules-in-context.md` and never changes the ontology.",
226
+ examples: ["okb docs --out review --context"],
227
+ args: [
228
+ ["--out", "folder", "Where to write `rules-in-context.md`. Required."],
229
+ ["--context", "flag", "Write the rules-in-context page instead of the reference pages. It doesn't combine with `--changed`."],
230
+ ],
231
+ },
232
+ ],
233
+ },
234
+ ];
@@ -0,0 +1,3 @@
1
+ /** Skills: install the Claude skills that ship with okb. */
2
+ import { type Command } from "../command-table.js";
3
+ export declare const skills: Command[];
@@ -0,0 +1,53 @@
1
+ /** Skills: install the Claude skills that ship with okb. */
2
+ import { opt } from "../command-table.js";
3
+ import { renderSkillsInstall, renderSkillsStatus } from "../render.js";
4
+ import { skillsInstallReport, skillsStatusReport } from "../workflows.js";
5
+ const { str, bool } = opt;
6
+ const SKILLS_USAGE = "Usage: okb skills install [--copy] [--dir <folder>] [--force] · okb skills status [--dir <folder>]";
7
+ export const skills = [
8
+ {
9
+ name: "skills",
10
+ group: "Skills",
11
+ summary: "install the Claude skills that ship with okb",
12
+ description: "Puts the skills that come with okb where Claude Code and Cursor load them from, and checks that they match this okb.",
13
+ usage: SKILLS_USAGE,
14
+ forms: [
15
+ {
16
+ sub: "install",
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
+ examples: ["okb skills install", "okb skills install --copy", "okb skills install --dir ~/.cursor/skills"],
19
+ args: [
20
+ ["--copy", "flag", "Copy the skill folders instead of linking to them. Run it again after you update okb."],
21
+ ["--dir", "path", "The skills folder to use instead of `~/.claude/skills/`. The `OKB_SKILLS_DIR` environment variable sets it too."],
22
+ ["--force", "flag", "Replace without asking, for scripts and CI. The old folder is still kept in the backup folder."],
23
+ ],
24
+ options: { copy: bool, dir: str, force: bool },
25
+ usage: SKILLS_USAGE,
26
+ max: 0,
27
+ cheat: { example: "okb skills install", description: "Install the Claude skills that ship with okb" },
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));
32
+ },
33
+ },
34
+ {
35
+ sub: "status",
36
+ description: "Lists each skill with where it is installed and whether its version matches this okb. It exits with code 1 when any skill is missing or out of date.",
37
+ examples: ["okb skills status", "okb skills status --dir ~/.cursor/skills"],
38
+ args: [
39
+ ["--dir", "path", "The skills folder to check instead of `~/.claude/skills/`."],
40
+ ],
41
+ options: { dir: str },
42
+ usage: SKILLS_USAGE,
43
+ max: 0,
44
+ run: (ctx) => {
45
+ const r = skillsStatusReport({ dir: ctx.opts.dir });
46
+ ctx.emit(() => ({ dir: r.dir, metaKbVersion: r.metaVersion, skills: r.skills }), () => renderSkillsStatus(r.dir, r.metaVersion, r.skills));
47
+ if (!r.allCurrent)
48
+ ctx.exit(1);
49
+ },
50
+ },
51
+ ],
52
+ },
53
+ ];
@@ -1,28 +1,16 @@
1
1
  /**
2
- * The command reference behind docs/CLI.md: what each `okb` command does, an example,
3
- * and its arguments. `tests/misc.test.ts` checks that every command in the dispatch table
4
- * is here and that every flag the help text shows for a command is documented.
2
+ * Every `okb` command, as records (see `command-table.ts`): the one place a command is described,
3
+ * routed and run. `help.ts` and `clidocs.ts` render the help text and docs/CLI.md from this list.
4
+ * To add a command or a form, add a record to the file for its group in `src/commands/`.
5
5
  */
6
- /** [name, value type, description] */
7
- export type Arg = readonly [name: string, type: string, description: string];
8
- /** One way to call a command (a subcommand such as `add`, or the bare command). */
9
- export interface Form {
10
- /** The subcommand word, if any: `add` for `okb cq add`. */
11
- sub?: string;
12
- description: string;
13
- examples: string[];
14
- args: Arg[];
15
- }
16
- export interface Command {
17
- name: string;
18
- /** The heading it appears under, by what you are trying to do. Commands appear in the order listed, so keep a group together. */
19
- group: string;
20
- description: string;
21
- forms: Form[];
22
- }
6
+ import type { Command } from "./command-table.js";
7
+ /** In the order the reference shows them: each group's commands stay together. */
23
8
  export declare const COMMANDS: Command[];
24
- /** The commands you need most, for the cheat sheet. Each example's command must exist above. */
25
- export declare const CHEAT_SHEET: {
9
+ /** Commands and forms that appear in the help text and docs/CLI.md. */
10
+ export declare const documented: (commands?: readonly Command[]) => Command[];
11
+ /** The cards on docs/CLI-CHEAT-SHEET.md: the forms that have a `cheat`, in record order. */
12
+ export declare function cheatSheet(commands?: readonly Command[]): {
26
13
  example: string;
27
14
  description: string;
15
+ command: Command;
28
16
  }[];