@ontology-kit/okb 0.2.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.
package/dist/clidocs.d.ts CHANGED
@@ -2,5 +2,3 @@
2
2
  export declare const cmdAnchor: (cmd: string, sub?: string) => string;
3
3
  export declare function renderCliDocs(): string;
4
4
  export declare function renderCheatSheet(): string;
5
- /** Flags the help text shows for a command that its reference entry doesn't document. */
6
- export declare function undocumentedFlags(help: string): string[];
package/dist/clidocs.js CHANGED
@@ -1,8 +1,4 @@
1
- /**
2
- * Renders docs/CLI.md from the command reference in src/commands.ts. The help text
3
- * (src/help.ts) stays the terminal summary; `undocumentedFlags` keeps the two from drifting.
4
- */
5
- import { CHEAT_SHEET, COMMANDS } from "./commands.js";
1
+ import { cheatSheet, documented } from "./commands.js";
6
2
  /** A stable anchor for a command or subcommand section: `cmd-class`, `cmd-class-add`. */
7
3
  export const cmdAnchor = (cmd, sub) => `cmd-${cmd}${sub ? `-${sub}` : ""}`;
8
4
  const cell = (s) => s.replace(/\|/g, "\\|");
@@ -24,7 +20,7 @@ function form(cmd, f, lines) {
24
20
  /** Commands in `COMMANDS` order, grouped by their `group`, each group once. */
25
21
  function groups() {
26
22
  const out = new Map();
27
- for (const c of COMMANDS)
23
+ for (const c of documented())
28
24
  out.set(c.group, [...(out.get(c.group) ?? []), c]);
29
25
  return [...out];
30
26
  }
@@ -46,7 +42,7 @@ export function renderCliDocs() {
46
42
  lines.push(`## ${group}`, "");
47
43
  for (const cmd of cmds) {
48
44
  lines.push(`<a id="${cmdAnchor(cmd.name)}"></a>`, `### okb ${cmd.name}`, "", cmd.description, "");
49
- for (const f of cmd.forms)
45
+ for (const f of cmd.forms.filter((f) => !f.hidden))
50
46
  form(cmd, f, lines);
51
47
  }
52
48
  }
@@ -59,9 +55,9 @@ export function renderCheatSheet() {
59
55
  "The `okb` commands you will use most, in the order you usually need them. For every command and argument, see the [full reference](CLI.md).",
60
56
  "",
61
57
  ];
62
- const rows = CHEAT_SHEET.map((c) => ({ ...c, group: COMMANDS.find((k) => k.name === c.example.split(" ")[1])?.group ?? "" }));
58
+ const rows = cheatSheet(documented());
63
59
  for (const [group] of groups()) {
64
- const mine = rows.filter((r) => r.group === group);
60
+ const mine = rows.filter((r) => r.command.group === group);
65
61
  if (!mine.length)
66
62
  continue;
67
63
  lines.push(`## ${group}`, "");
@@ -70,21 +66,3 @@ export function renderCheatSheet() {
70
66
  }
71
67
  return lines.join("\n");
72
68
  }
73
- /** Flags the help text shows for a command that its reference entry doesn't document. */
74
- export function undocumentedFlags(help) {
75
- const missing = [];
76
- const known = new Map(COMMANDS.map((c) => [c.name, new Set(c.forms.flatMap((f) => f.args.map((a) => a[0])))]));
77
- for (const line of help.split("\n")) {
78
- for (const piece of line.split(/\s+·\s+|\s{3,}(?=okb [a-z])/)) {
79
- const m = piece.trim().match(/^okb ([a-z]+)/);
80
- if (!m)
81
- continue;
82
- const doc = known.get(m[1]);
83
- for (const [, flag] of piece.matchAll(/(?<![\w-])(--[a-z][a-z-]*)/g)) {
84
- if (!doc?.has(flag) && !["--json", "--help"].includes(flag))
85
- missing.push(`okb ${m[1]} ${flag}`);
86
- }
87
- }
88
- }
89
- return missing;
90
- }
@@ -0,0 +1,134 @@
1
+ import { type Ontology } from "@ontology-kit/reader";
2
+ import type { Notes } from "./ops.js";
3
+ /** [name, value type, description] */
4
+ export type Arg = readonly [name: string, type: string, description: string];
5
+ /** What a form accepts for one `--option`, in the shape `node:util` `parseArgs` takes. */
6
+ export type OptionSpec = {
7
+ readonly type: "string" | "boolean";
8
+ readonly multiple?: boolean;
9
+ };
10
+ export type OptionSpecs = Readonly<Record<string, OptionSpec>>;
11
+ /** The `<name>` argument's description in most `add` forms. */
12
+ export declare const NAME_DESC = "The name, in the case your naming convention asks for.";
13
+ /** Shorthands for writing option tables: a text value, a repeatable text value, a flag. */
14
+ export declare const opt: {
15
+ str: {
16
+ readonly type: "string";
17
+ };
18
+ strs: {
19
+ readonly type: "string";
20
+ readonly multiple: true;
21
+ };
22
+ bool: {
23
+ readonly type: "boolean";
24
+ };
25
+ };
26
+ /** What a record's `run` sees: parsed values and the runners. It never sees the command line itself. */
27
+ export interface Ctx {
28
+ /** Parsed `--options`, by name without the dashes (`--add-parent` is `"add-parent"`). */
29
+ readonly opts: Record<string, any>;
30
+ /** Positional arguments after the command and form words. */
31
+ readonly args: string[];
32
+ /** `--json` was given. */
33
+ readonly json: boolean;
34
+ /** Every command, for the help text. */
35
+ readonly commands: readonly Command[];
36
+ /** A whole number option (`--min 2`), or undefined when absent. */
37
+ int(name: string): number | undefined;
38
+ /** Read the ontology folder (`-C`, default `.`). */
39
+ load(): Ontology;
40
+ /** Load the folder, change it, save it and print the notes, all with the folder's lock held. */
41
+ mutate(fn: (ont: Ontology) => Notes): void;
42
+ mutateAsync(fn: (ont: Ontology) => Promise<Notes>): Promise<void>;
43
+ /** Hold the folder's lock while `fn` runs; `fn` saves what it changed. */
44
+ edit<T>(fn: (ont: Ontology) => T): T;
45
+ editAsync<T>(fn: (ont: Ontology) => Promise<T>): Promise<T>;
46
+ /** The ontology folder as given by `-C` (default `.`). */
47
+ readonly dir: string;
48
+ /** Print `data` as JSON under --json, otherwise the lines the printer builds. Nothing prints for no lines. */
49
+ emit(data: () => unknown, lines: () => string | string[]): void;
50
+ /** Print notes (tips dimmed). */
51
+ say(notes: Notes): void;
52
+ /** Like `emit`, but prints the text exactly as given (no trailing newline added). */
53
+ emitRaw(data: () => unknown, text: () => string): void;
54
+ /** Print text or lines. */
55
+ print(lines: string | string[]): void;
56
+ /** Print without a trailing newline (for piping a whole file). */
57
+ printRaw(text: string): void;
58
+ /** Write a file (relative to the working folder). */
59
+ write(path: string, text: string): void;
60
+ /** Set the process exit code. */
61
+ exit(code: number): void;
62
+ }
63
+ export interface Form {
64
+ /** The subcommand word, if any: `add` for `okb cq add`. A form without one is the bare command. */
65
+ sub?: string;
66
+ description: string;
67
+ examples: string[];
68
+ /** The documented arguments and options, in the order the reference shows them. */
69
+ args: Arg[];
70
+ /** The options this form parses (global `-C` and `--json` are always accepted). */
71
+ options?: OptionSpecs;
72
+ /** The message when the arguments are wrong. Required wherever `min`, `max` or `require` is set. */
73
+ usage?: string;
74
+ /** Fewest and most positional arguments. */
75
+ min?: number;
76
+ max?: number;
77
+ /** Options that must be given. */
78
+ require?: string[];
79
+ /** Left out of the help text and docs/CLI.md (an internal or deprecated form). */
80
+ hidden?: boolean;
81
+ /** One card on docs/CLI-CHEAT-SHEET.md. */
82
+ cheat?: {
83
+ example: string;
84
+ description: string;
85
+ };
86
+ /** A form without `run` is documentation for a variant of another form (`docs --changed`). */
87
+ run?: (ctx: Ctx) => void | Promise<void>;
88
+ }
89
+ export interface Command {
90
+ name: string;
91
+ /** The heading it appears under, by what you are trying to do. Commands appear in the order listed, so keep a group together. */
92
+ group: string;
93
+ /** A few words for the help text's command list. */
94
+ summary?: string;
95
+ description: string;
96
+ forms: Form[];
97
+ /** Other words that run this command (`--version`). */
98
+ aliases?: string[];
99
+ /** Which subcommand a bare `okb <command>` runs when the command has no bare form of its own. */
100
+ bare?: string;
101
+ /** Overrides the "Usage: okb x add|set ..." message for an unknown subcommand. */
102
+ usage?: string;
103
+ /** Rewrites the command line to another command's (everyday names for slot kinds). */
104
+ rewrite?: (rest: string[]) => string[];
105
+ /** Left out of the help text and docs/CLI.md. */
106
+ hidden?: boolean;
107
+ }
108
+ /** Parsed global options plus where they came from. */
109
+ export interface Globals {
110
+ C?: string;
111
+ json: boolean;
112
+ }
113
+ /** The first thing on the command line: global options may come before the command. */
114
+ export declare function leadingGlobals(argv: readonly string[]): {
115
+ globals: Partial<Globals>;
116
+ rest: string[];
117
+ };
118
+ export interface Resolved {
119
+ cmd: Command;
120
+ form: Form;
121
+ /** The words after the command and form words. */
122
+ rest: string[];
123
+ }
124
+ /** Find the command and form for the words after global options; throws a usage error if there is none. */
125
+ export declare function resolve(commands: readonly Command[], argv: readonly string[]): Resolved;
126
+ /** Parse a form's words with its options; wrong arguments throw the form's usage message. */
127
+ export declare function parseForm(form: Form, rest: readonly string[]): {
128
+ opts: Record<string, any>;
129
+ args: string[];
130
+ };
131
+ /** True for a parse error from `parseArgs` (an unknown option, a missing value). */
132
+ export declare const isParseError: (e: unknown) => boolean;
133
+ /** "true", "yes" or "1" (any case) is true; anything else is false; absent stays undefined. */
134
+ export declare const tri: (x: string | undefined) => boolean | undefined;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * The command table: what a command record is, and how a command line finds its record.
3
+ *
4
+ * Each form of a command (`cq add`, `cq set`, or a bare `okb status`) is one record. A record is
5
+ * both the spec (description, examples, arguments, options) and the router (`run`), so the help
6
+ * text and docs/CLI.md are rendered from it and nothing else describes a command. A record only
7
+ * sees a typed `Ctx`, never the parser, so `parseArgs` could be swapped for another parser.
8
+ *
9
+ * Adding a command or a form is one record in a file under `src/commands/`.
10
+ */
11
+ import { parseArgs } from "node:util";
12
+ import { OkbError } from "@ontology-kit/reader";
13
+ const str = { type: "string" };
14
+ const strs = { type: "string", multiple: true };
15
+ const bool = { type: "boolean" };
16
+ /** The `<name>` argument's description in most `add` forms. */
17
+ export const NAME_DESC = "The name, in the case your naming convention asks for.";
18
+ /** Shorthands for writing option tables: a text value, a repeatable text value, a flag. */
19
+ export const opt = { str, strs, bool };
20
+ /** The first thing on the command line: global options may come before the command. */
21
+ export function leadingGlobals(argv) {
22
+ const globals = {};
23
+ const rest = [...argv];
24
+ for (;;) {
25
+ if (rest[0] === "-C" && rest.length > 2) {
26
+ // Same rule as the trailing form (parseArgs): an operand starting with a dash is a mistake, not a folder. `-C ./--json` is fine.
27
+ if (rest[1].length > 1 && rest[1].startsWith("-")) {
28
+ throw new OkbError(`Option '-C' argument is ambiguous.\nDid you forget to specify the option argument for '-C'?\nTo specify an option argument starting with a dash use '--C=-XYZ' or '-C-XYZ'.`);
29
+ }
30
+ globals.C = rest[1];
31
+ rest.splice(0, 2);
32
+ }
33
+ else if (rest[0] === "--json" && rest.length > 1) {
34
+ globals.json = true;
35
+ rest.splice(0, 1);
36
+ }
37
+ else
38
+ break;
39
+ }
40
+ return { globals, rest };
41
+ }
42
+ const runnable = (cmd) => cmd.forms.filter((f) => f.run);
43
+ const subWords = (cmd) => runnable(cmd).filter((f) => f.sub && !f.hidden).map((f) => f.sub);
44
+ /** Find the command and form for the words after global options; throws a usage error if there is none. */
45
+ export function resolve(commands, argv) {
46
+ let words = [...argv];
47
+ for (let hops = 0; hops < 3; hops++) {
48
+ const [name, ...rest] = words;
49
+ const cmd = commands.find((c) => c.name === name || c.aliases?.includes(name));
50
+ if (!cmd)
51
+ throw new OkbError(`Unknown command '${name}'. Run okb help.`);
52
+ if (cmd.rewrite) {
53
+ words = cmd.rewrite(rest);
54
+ continue;
55
+ }
56
+ const forms = runnable(cmd);
57
+ const named = rest[0] === undefined ? undefined : forms.find((f) => f.sub === rest[0]);
58
+ if (named)
59
+ return { cmd, form: named, rest: rest.slice(1) };
60
+ const bare = forms.find((f) => !f.sub) ?? forms.find((f) => f.sub === cmd.bare);
61
+ if (!bare)
62
+ throw new OkbError(cmd.usage ?? `Usage: okb ${cmd.name} ${subWords(cmd).join("|")} ... (okb help)`);
63
+ return { cmd, form: bare, rest };
64
+ }
65
+ throw new OkbError("Command rewrite loop.");
66
+ }
67
+ const GLOBAL_OPTIONS = { C: { type: "string", short: "C" }, json: bool };
68
+ /** Parse a form's words with its options; wrong arguments throw the form's usage message. */
69
+ export function parseForm(form, rest) {
70
+ const { values, positionals } = parseArgs({ args: [...rest], options: { ...GLOBAL_OPTIONS, ...form.options }, allowPositionals: true, strict: true });
71
+ const opts = values;
72
+ const bad = (form.min !== undefined && positionals.length < form.min) ||
73
+ (form.max !== undefined && positionals.length > form.max) ||
74
+ (form.require ?? []).some((k) => !opts[k]);
75
+ if (bad)
76
+ throw new OkbError(form.usage);
77
+ return { opts, args: positionals };
78
+ }
79
+ /** True for a parse error from `parseArgs` (an unknown option, a missing value). */
80
+ export const isParseError = (e) => String(e?.code ?? "").startsWith("ERR_PARSE_ARGS");
81
+ /** "true", "yes" or "1" (any case) is true; anything else is false; absent stays undefined. */
82
+ export const tri = (x) => (x === undefined ? undefined : ["true", "yes", "1"].includes(x.toLowerCase()));
@@ -0,0 +1,3 @@
1
+ /** Working from documents: sources, quotes, rules extracted from them, and verification. */
2
+ import { type Command } from "../command-table.js";
3
+ export declare const documents: Command[];
@@ -0,0 +1,250 @@
1
+ /** Working from documents: sources, quotes, rules extracted from them, and verification. */
2
+ import { opt } from "../command-table.js";
3
+ import { OkbError } from "@ontology-kit/reader";
4
+ import * as prov from "../provenance.js";
5
+ import { formatNotes, renderOutline, renderQuotes, renderRules, renderSources } from "../render.js";
6
+ import { renderResync } from "../resync.js";
7
+ import { outline, quotes, refreshAll } from "../workflows.js";
8
+ const { str, strs, bool } = opt;
9
+ export const documents = [
10
+ {
11
+ name: "source",
12
+ group: "Working from documents",
13
+ summary: "register documents to extract from",
14
+ description: "Registers documents you are extracting from, so quotes and rules can point back to them.",
15
+ bare: "list",
16
+ forms: [
17
+ {
18
+ sub: "add",
19
+ description: "Registers a Markdown or PDF file.",
20
+ examples: ["okb source add docs/button.md --repo-url https://github.com/acme/ds/blob/main/button.md"],
21
+ args: [
22
+ ["<file>", "path", "A Markdown or PDF file."],
23
+ ["--title", "text", "A title."],
24
+ ["--repo-url", "url", "The file's address on GitHub."],
25
+ ["--url", "url", "The address of the rendered page."],
26
+ ["--id", "text", "Your own id for it."],
27
+ ],
28
+ options: { title: str, url: str, "repo-url": str, id: str },
29
+ usage: "Usage: okb source add <file.md|file.pdf> [--title ...] [--repo-url <GitHub file URL>] [--url <rendered page URL>]",
30
+ min: 1,
31
+ cheat: { example: "okb source add docs/button.md", description: "Register a document to extract from" },
32
+ run: (ctx) => {
33
+ const o = ctx.opts;
34
+ ctx.mutate((ont) => prov.addSource(ont, ctx.args[0], { title: o.title, url: o.url, repoUrl: o["repo-url"], id: o.id }));
35
+ },
36
+ },
37
+ {
38
+ sub: "outline",
39
+ description: "Lists every block of a Markdown source with its heading path and line numbers, and shows which are already quoted.",
40
+ examples: ["okb source outline button --quotable"],
41
+ args: [
42
+ ["<source>", "name", "The source."],
43
+ ["--quotable", "flag", "Show only blocks you can quote."],
44
+ ["--problems", "flag", "Show only problems in the document."],
45
+ ],
46
+ options: { quotable: bool, problems: bool },
47
+ run: (ctx) => {
48
+ const o = outline(ctx.load(), ctx.args[0], { quotable: ctx.opts.quotable });
49
+ ctx.emit(o.data, () => renderOutline(o.src, o.doc, o.blocks, o.quoted, ctx.opts.problems));
50
+ },
51
+ },
52
+ {
53
+ sub: "refresh",
54
+ description: "Checks quotes again after the document changes. With `--all` it checks every source, reports quotes that are gone (with the rules and facts that cite them) or moved, and lists the new, changed and removed blocks as a worklist. With `--all` it exits with code 1 when a quote is gone or a source can't be read (a single source only reports).",
55
+ examples: ["okb source refresh button", "okb source refresh --all", "okb source refresh --all --json --dry-run"],
56
+ args: [
57
+ ["[<source>]", "name", "The source to check (leave it out with --all)."],
58
+ ["--all", "flag", "Check every source and list the worklist of new, changed and removed blocks."],
59
+ ["--dry-run", "flag", "With --all: write nothing, not even moved quotes."],
60
+ ["--record", "flag", "With --all: store the current blocks as the baseline once the worklist is dealt with."],
61
+ ["--strict", "flag", "With --all: also exit with code 1 when the worklist isn't empty."],
62
+ ],
63
+ options: { all: bool, record: bool, "dry-run": bool, strict: bool },
64
+ run: async (ctx) => {
65
+ const o = ctx.opts;
66
+ if (!o.all)
67
+ return ctx.mutate((ont) => prov.refreshSource(ont, ctx.args[0]));
68
+ if (ctx.args.length)
69
+ throw new OkbError("--all re-checks every source; leave out the source name (or drop --all).");
70
+ const { report, write } = await refreshAll(ctx.dir, { dryRun: o["dry-run"], record: o.record });
71
+ ctx.emit(() => report, () => formatNotes(renderResync(report, { dryRun: !write })));
72
+ // 1 when the KB no longer matches its documents (a quote is gone or a source can't be read); --strict also when blocks need work.
73
+ if (!report.ok || (o.strict && report.worklist.length))
74
+ ctx.exit(1);
75
+ },
76
+ },
77
+ {
78
+ sub: "list",
79
+ description: "Lists the sources. Bare `okb source` does the same.",
80
+ examples: ["okb source list"],
81
+ args: [],
82
+ run: (ctx) => ctx.print(renderSources(ctx.load())),
83
+ },
84
+ ],
85
+ },
86
+ {
87
+ name: "quote",
88
+ group: "Working from documents",
89
+ summary: "record a verbatim passage",
90
+ description: "Records a verbatim passage from a source. Okb finds it in the document for you.",
91
+ bare: "list",
92
+ forms: [
93
+ {
94
+ sub: "add",
95
+ description: "Records one quote.",
96
+ examples: ["okb quote add button \"Use a primary button for the main action.\" --cites Button"],
97
+ args: [
98
+ ["<source>", "name", "The source it comes from."],
99
+ ["<text>", "text", "The passage, word for word."],
100
+ ["--cites", "node", "A node the quote supports. Repeat it for more."],
101
+ ["--line", "number", "A line to look near, if the text appears more than once."],
102
+ ["--allow-code", "flag", "Allow a quote from a code block."],
103
+ ],
104
+ options: { cites: strs, line: str, "allow-code": bool },
105
+ usage: 'Usage: okb quote add <source> "verbatim text" [--cites <node>] [--line N]',
106
+ min: 2,
107
+ cheat: { example: "okb quote add button \"verbatim text\" --cites Button", description: "Record a quote" },
108
+ run: (ctx) => ctx.mutateAsync((ont) => prov.addQuote(ont, ctx.args[0], ctx.args.slice(1).join(" "), { cites: ctx.opts.cites, line: ctx.int("line"), allowCode: ctx.opts["allow-code"] })),
109
+ },
110
+ {
111
+ sub: "list",
112
+ description: "Lists the quotes. Bare `okb quote` does the same.",
113
+ examples: ["okb quote list"],
114
+ args: [],
115
+ run: (ctx) => {
116
+ const ont = ctx.load();
117
+ const q = quotes(ont, ctx.args[0]);
118
+ ctx.emit(q.data, () => renderQuotes(ont, q.locs));
119
+ },
120
+ },
121
+ ],
122
+ },
123
+ {
124
+ name: "rule",
125
+ group: "Working from documents",
126
+ summary: "record a rule a document states",
127
+ description: "Records a rule a document states, tied to the quote that supports it.",
128
+ bare: "list",
129
+ forms: [
130
+ {
131
+ sub: "add",
132
+ description: "Records one rule.",
133
+ examples: ["okb rule add --statement \"Buttons SHOULD have one primary per page.\" --modality SHOULD --governs Button --cites quote.1"],
134
+ args: [
135
+ ["--statement", "text", "The rule, in one sentence."],
136
+ ["--modality", "MUST, SHOULD, MAY, MUST_NOT or SHOULD_NOT", "How strong the document makes it."],
137
+ ["--cites", "quote id", "The quote that supports it. Repeat it for more."],
138
+ ["--governs", "class or slot", "What it applies to. Repeat it for more."],
139
+ ["--name", "text", "A short name."],
140
+ ["--authored", "flag", "You wrote it; the document doesn't state it."],
141
+ ["--value", "slot=value", "A value it sets. Repeat it for more."],
142
+ ["--refines", "rule id", "A broader rule this one narrows."],
143
+ ["--adds", "text", "What this rule adds to the one it refines."],
144
+ ],
145
+ options: { statement: str, modality: str, governs: strs, cites: strs, name: str, authored: bool, value: strs, refines: strs, adds: str },
146
+ usage: 'Usage: okb rule add --statement "..." --modality MUST|SHOULD|MAY|MUST_NOT|SHOULD_NOT --cites <quote id> [--governs <Class|slot>] [--authored] [--value slot=value ...] [--refines <rule> [--adds "..."]]',
147
+ require: ["statement", "modality"],
148
+ cheat: { example: "okb rule add --statement \"...\" --modality SHOULD --cites quote.1", description: "Record a rule a document states" },
149
+ run: (ctx) => {
150
+ const o = ctx.opts;
151
+ ctx.mutate((ont) => prov.addRule(ont, { statement: o.statement, modality: o.modality, governs: o.governs, cites: o.cites, name: o.name, authored: o.authored, values: o.value, refines: o.refines, adds: o.adds }));
152
+ },
153
+ },
154
+ {
155
+ sub: "refines",
156
+ description: "Says that one rule narrows another.",
157
+ examples: ["okb rule refines rule.2 rule.1 --adds \"Only inside dialogs\""],
158
+ args: [
159
+ ["<rule>", "rule id", "The narrower rule."],
160
+ ["<broader rule>", "rule id", "The rule it narrows."],
161
+ ["--adds", "text", "What it adds."],
162
+ ["--remove", "flag", "Remove the link."],
163
+ ],
164
+ options: { adds: str, remove: bool },
165
+ usage: 'Usage: okb rule refines <rule> <broader rule> [--adds "..."] [--remove]',
166
+ min: 2,
167
+ max: 2,
168
+ run: (ctx) => ctx.mutate((ont) => prov.refine(ont, ctx.args[0], ctx.args[1], { adds: ctx.opts.adds, remove: ctx.opts.remove })),
169
+ },
170
+ {
171
+ sub: "list",
172
+ description: "Lists the rules. Bare `okb rule` does the same.",
173
+ examples: ["okb rule list"],
174
+ args: [],
175
+ run: (ctx) => ctx.print(renderRules(ctx.load())),
176
+ },
177
+ ],
178
+ },
179
+ {
180
+ name: "fulfills",
181
+ group: "Working from documents",
182
+ summary: "say an instance follows a rule",
183
+ description: "Says that an instance follows a rule.",
184
+ forms: [
185
+ {
186
+ description: "Links the instance to the rule.",
187
+ examples: ["okb fulfills SaveButton rule.1"],
188
+ args: [
189
+ ["<instance>", "name", "The instance."],
190
+ ["<rule>", "rule id", "The rule."],
191
+ ["--remove", "flag", "Remove the link."],
192
+ ],
193
+ options: { remove: bool },
194
+ usage: "Usage: okb fulfills <instance> <rule> [--remove]",
195
+ min: 2,
196
+ max: 2,
197
+ run: (ctx) => ctx.mutate((ont) => prov.fulfill(ont, ctx.args[0], ctx.args[1], { remove: ctx.opts.remove })),
198
+ },
199
+ ],
200
+ },
201
+ {
202
+ name: "cite",
203
+ group: "Working from documents",
204
+ summary: "attach a quote to a node",
205
+ description: "Attaches a quote you already recorded to another node.",
206
+ forms: [
207
+ {
208
+ description: "Links the quote to the node.",
209
+ examples: ["okb cite Button quote.4"],
210
+ args: [
211
+ ["<node>", "name", "The class, slot, instance or rule."],
212
+ ["<quote id>", "quote id", "The quote. `okb quote list` shows them."],
213
+ ],
214
+ usage: "Usage: okb cite <node> <quote id> (attach an existing quote; see okb quote list)",
215
+ min: 2,
216
+ max: 2,
217
+ run: (ctx) => ctx.mutate((ont) => prov.cite(ont, ctx.args[0], ctx.args[1])),
218
+ },
219
+ ],
220
+ },
221
+ {
222
+ name: "verify",
223
+ group: "Working from documents",
224
+ summary: "record an independent check",
225
+ description: "Records the result of an independent check that a node matches what its quote says, or approves it.",
226
+ forms: [
227
+ {
228
+ description: "Sets a verification status, or approves the node.",
229
+ examples: ["okb verify rule.1 --status SUPPORTED", "okb verify rule.1 --approve"],
230
+ args: [
231
+ ["<node>", "name", "The node to verify."],
232
+ ["--status", "SUPPORTED, OVERREACH or UNSUPPORTED", "What the check found."],
233
+ ["--corrected", "text", "A corrected wording, for OVERREACH."],
234
+ ["--confidence", "verbatim or paraphrased", "How closely the node follows the quote."],
235
+ ["--note", "text", "One sentence on why: the word or number you changed, or the part of the statement the quote doesn't support. OVERREACH prints a suggestion."],
236
+ ["--ref", "url", "An http or https link to the PR comment, issue or review thread where the reasoning happened."],
237
+ ["--approve", "flag", "Approve it after review."],
238
+ ],
239
+ options: { status: str, corrected: str, confidence: str, note: str, ref: str, approve: bool },
240
+ usage: 'Usage: okb verify <node> --status SUPPORTED|OVERREACH|UNSUPPORTED [--corrected "..."] [--confidence verbatim|paraphrased] [--note "..."] [--ref <url>] · okb verify <node> --approve',
241
+ min: 1,
242
+ cheat: { example: "okb verify rule.1 --status SUPPORTED", description: "Record an independent check" },
243
+ run: (ctx) => {
244
+ const o = ctx.opts;
245
+ ctx.mutate((ont) => prov.verify(ont, ctx.args[0], { status: o.status, corrected: o.corrected, confidence: o.confidence, note: o.note, ref: o.ref, approve: o.approve }));
246
+ },
247
+ },
248
+ ],
249
+ },
250
+ ];
@@ -0,0 +1,3 @@
1
+ /** Getting started: create an ontology, see where you are, learn a concept, check your work. */
2
+ import { type Command } from "../command-table.js";
3
+ export declare const gettingStarted: Command[];