@ontology-kit/okb 0.2.0 → 0.3.0-alpha.23
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/cli.js +11 -819
- package/dist/clidocs.d.ts +0 -2
- package/dist/clidocs.js +5 -27
- package/dist/command-table.d.ts +134 -0
- package/dist/command-table.js +82 -0
- package/dist/commands/documents.d.ts +3 -0
- package/dist/commands/documents.js +250 -0
- package/dist/commands/getting-started.d.ts +3 -0
- package/dist/commands/getting-started.js +135 -0
- package/dist/commands/housekeeping.d.ts +3 -0
- package/dist/commands/housekeeping.js +203 -0
- package/dist/commands/modeling.d.ts +3 -0
- package/dist/commands/modeling.js +433 -0
- package/dist/commands/planning.d.ts +3 -0
- package/dist/commands/planning.js +212 -0
- package/dist/commands/reviewing.d.ts +3 -0
- package/dist/commands/reviewing.js +177 -0
- package/dist/commands/skills.d.ts +3 -0
- package/dist/commands/skills.js +52 -0
- package/dist/commands.d.ts +10 -22
- package/dist/commands.js +15 -716
- package/dist/help.d.ts +11 -2
- package/dist/help.js +51 -64
- package/dist/release.d.ts +4 -0
- package/dist/release.js +22 -3
- package/dist/render.d.ts +61 -1
- package/dist/render.js +219 -1
- package/dist/runner.d.ts +3 -0
- package/dist/runner.js +79 -0
- package/dist/workflows.d.ts +256 -0
- package/dist/workflows.js +223 -0
- package/package.json +4 -3
package/dist/help.d.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The text of `okb help`, rendered from the command records so it can't drift from what the
|
|
3
|
+
* commands do. Its own module so the docs generator can read it without running the CLI.
|
|
4
|
+
*/
|
|
5
|
+
import type { Arg, Command } from "./command-table.js";
|
|
6
|
+
/** The first sentence of a description. */
|
|
7
|
+
export declare function summary(text: string): string;
|
|
8
|
+
/** A required option shows its operand without brackets (`--out <folder>`); an optional one stays in brackets. */
|
|
9
|
+
export declare function optionUsage([name, type]: Arg, required?: readonly string[]): string;
|
|
10
|
+
/** One line per command, grouped by what you are trying to do: its name, its subcommands, and what it does. */
|
|
11
|
+
export declare function renderHelp(commands: readonly Command[]): string;
|
package/dist/help.js
CHANGED
|
@@ -1,64 +1,51 @@
|
|
|
1
|
-
/** The
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
Skills okb skills install [--copy] [--dir <folder>] [--force] link (or copy) the packaged skills into ~/.claude/skills
|
|
53
|
-
okb skills status [--dir <folder>] which are installed, where, and whether they match this okb
|
|
54
|
-
|
|
55
|
-
Also: okb show <name> · okb rename <old> <new> · okb remove <name> · okb drift <folder>...
|
|
56
|
-
okb check [--json] is this KB safe to merge? (validation, quotes, verification; non-zero exit if not)
|
|
57
|
-
okb pin record this okb version in okb.json (CI installs it; okb check warns on older)
|
|
58
|
-
okb docs --out <folder> write Markdown reference pages: classes, slots, rules and the quotes behind them
|
|
59
|
-
--changed <ref> [--hops N] only the pages that differ from a git ref, plus the stale-quote worklist
|
|
60
|
-
--context every rule beside the source text around its quote, problem cases first
|
|
61
|
-
okb diff <old> [<new>] [--json] what changed in the knowledge between two folders or git refs (okb diff main)
|
|
62
|
-
okb release <version> · okb release verify cut a pinned release with a manifest and change log; check files against it
|
|
63
|
-
Names: when a class and a slot share a name, say which: class:Genre / slot:genre
|
|
64
|
-
Global options: -C <folder> (default: current folder) · --json (machine-readable output where supported)`;
|
|
1
|
+
/** The first sentence of a description. */
|
|
2
|
+
export function summary(text) {
|
|
3
|
+
return text.split(/(?<=\.)\s+(?=[A-Z`])/)[0].replace(/`/g, "").replace(/\.$/, "");
|
|
4
|
+
}
|
|
5
|
+
const MAX_FLAGS = 4;
|
|
6
|
+
/** A usage wider than this puts its summary on the next line. */
|
|
7
|
+
const MAX_USAGE = 48;
|
|
8
|
+
/** `okb init <folder> [--name]`: a single-form command shows its arguments, from the record; several forms show their subcommands. */
|
|
9
|
+
function usageOf(cmd) {
|
|
10
|
+
const forms = cmd.forms.filter((f) => !f.sub?.startsWith("--") && !f.hidden);
|
|
11
|
+
const subs = forms.filter((f) => f.sub).map((f) => f.sub);
|
|
12
|
+
const bare = forms.find((f) => !f.sub);
|
|
13
|
+
const rows = (bare?.args ?? []).filter((a) => a[0] !== "--json");
|
|
14
|
+
const words = rows.filter((a) => !a[0].startsWith("--")).map((a) => a[0]);
|
|
15
|
+
if (subs.length) {
|
|
16
|
+
// A bare form that needs an argument (`okb release <version>`) is not optional: show it as one of the alternatives.
|
|
17
|
+
if (bare && (bare.min ?? 0) > 0)
|
|
18
|
+
return `${cmd.name} ${[words.join(" "), ...subs].join("|")}`;
|
|
19
|
+
return `${cmd.name} ${bare ? `[${subs.join("|")}]` : subs.join("|")}`;
|
|
20
|
+
}
|
|
21
|
+
const flags = rows.filter((a) => a[0].startsWith("--"));
|
|
22
|
+
const shown = flags.length > MAX_FLAGS ? ["[options]"] : flags.map((a) => optionUsage(a, bare?.require));
|
|
23
|
+
return [cmd.name, ...words, ...shown].join(" ");
|
|
24
|
+
}
|
|
25
|
+
/** A required option shows its operand without brackets (`--out <folder>`); an optional one stays in brackets. */
|
|
26
|
+
export function optionUsage([name, type], required = []) {
|
|
27
|
+
if (!required.includes(name.replace(/^--/, "")))
|
|
28
|
+
return `[${name}]`;
|
|
29
|
+
return `${name} <${/^[\w-]+$/.test(type) ? type : "value"}>`;
|
|
30
|
+
}
|
|
31
|
+
/** One line per command, grouped by what you are trying to do: its name, its subcommands, and what it does. */
|
|
32
|
+
export function renderHelp(commands) {
|
|
33
|
+
const rows = [];
|
|
34
|
+
for (const cmd of commands) {
|
|
35
|
+
if (cmd.hidden)
|
|
36
|
+
continue;
|
|
37
|
+
rows.push({ group: cmd.group, usage: `okb ${usageOf(cmd)}`, what: cmd.summary ?? summary(cmd.description) });
|
|
38
|
+
}
|
|
39
|
+
const width = Math.max(...rows.filter((r) => r.usage.length <= MAX_USAGE).map((r) => r.usage.length)) + 3;
|
|
40
|
+
const lines = ["okb: build an ontology step by step (Ontology 101 method)"];
|
|
41
|
+
let group = "";
|
|
42
|
+
for (const r of rows) {
|
|
43
|
+
if (r.group !== group) {
|
|
44
|
+
lines.push("", r.group);
|
|
45
|
+
group = r.group;
|
|
46
|
+
}
|
|
47
|
+
lines.push(r.usage.length > MAX_USAGE ? ` ${r.usage}\n ${"".padEnd(width)}${r.what}` : ` ${r.usage.padEnd(width)}${r.what}`);
|
|
48
|
+
}
|
|
49
|
+
lines.push("", "Start with: okb init <folder> --name \"My Ontology\", then okb status and okb step.", "Learn a concept or rule: okb explain <topic>.", "Every command, with examples and options: docs/CLI.md, or https://ontology-kit.dev/reference/cli-reference/", "", "Names: when a class and a slot share a name, say which: class:Genre / slot:genre", "Global options: -C <folder> (default: current folder) · --json (machine-readable output where supported)");
|
|
50
|
+
return lines.join("\n");
|
|
51
|
+
}
|
package/dist/release.d.ts
CHANGED
|
@@ -25,6 +25,10 @@ export declare function compareVersions(a: string, b: string): number;
|
|
|
25
25
|
export declare const isVersion: (v: string) => boolean;
|
|
26
26
|
/** Read and check the shape of a manifest.json. Throws OkbError naming the problem. */
|
|
27
27
|
export declare function readReleaseManifest(file: string): ReleaseManifest;
|
|
28
|
+
/** The writer `writeFileAtomic` uses; tests swap `write` to simulate a failed write. */
|
|
29
|
+
export declare const releaseIo: {
|
|
30
|
+
write: (file: string, text: string) => void;
|
|
31
|
+
};
|
|
28
32
|
export interface ReleaseResult {
|
|
29
33
|
version: string;
|
|
30
34
|
previous?: string;
|
package/dist/release.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* says where it differs.
|
|
15
15
|
*/
|
|
16
16
|
import { createHash } from "node:crypto";
|
|
17
|
-
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
18
18
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
19
19
|
import { OkbError, Ontology, slug } from "@ontology-kit/reader";
|
|
20
20
|
import { today } from "./clock.js";
|
|
@@ -194,6 +194,25 @@ function writeReleasesMd(root, name) {
|
|
|
194
194
|
const sections = releasedVersions(root).map((v) => readFileSync(join(root, RELEASES_DIR, v, "CHANGES.md"), "utf8").trimEnd());
|
|
195
195
|
writeFileSync(join(root, "RELEASES.md"), `# Releases of ${name}\n\nEach release's changes, newest first. \`manifest.json\` pins the latest one; \`okb release verify\` checks the files against it.\n\n${sections.join("\n\n")}\n`);
|
|
196
196
|
}
|
|
197
|
+
/** The writer `writeFileAtomic` uses; tests swap `write` to simulate a failed write. */
|
|
198
|
+
export const releaseIo = {
|
|
199
|
+
write: (file, text) => writeFileSync(file, text, "utf8"),
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Write `text` to a temp file next to `file`, then rename it into place, so a failed write leaves the
|
|
203
|
+
* previous `file` whole. The temp file is removed if the write or the rename fails.
|
|
204
|
+
*/
|
|
205
|
+
function writeFileAtomic(file, text) {
|
|
206
|
+
const tmp = `${file}.tmp`;
|
|
207
|
+
try {
|
|
208
|
+
releaseIo.write(tmp, text);
|
|
209
|
+
renameSync(tmp, file);
|
|
210
|
+
}
|
|
211
|
+
catch (e) {
|
|
212
|
+
rmSync(tmp, { force: true });
|
|
213
|
+
throw e;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
197
216
|
/**
|
|
198
217
|
* Cut release `version` of the folder `ont` was loaded from. Call it inside `Ontology.edit` (it saves
|
|
199
218
|
* and writes files under the lock). `findings` are the validator's results; any open error stops the release.
|
|
@@ -261,8 +280,8 @@ export function cutRelease(ont, version, findings) {
|
|
|
261
280
|
// The manifests go last: they are what makes the release exist, so a failure above leaves nothing pinned.
|
|
262
281
|
// Dataset paths are relative to the manifest, so the snapshot's copy points at the sources from its own folder.
|
|
263
282
|
const snapManifest = { ...manifest, datasets: { ...manifest.datasets, ...(docs ? { docs: { ...docs, path: posix(relative(snap, resolve(root, docs.path))) || "." } } : {}) } };
|
|
264
|
-
|
|
265
|
-
|
|
283
|
+
writeFileAtomic(join(snap, MANIFEST_FILE), json(snapManifest));
|
|
284
|
+
writeFileAtomic(lastFile, json(manifest));
|
|
266
285
|
const notes = [`Released ${version}${last ? ` (was ${last.version})` : ""}: ${countsLine(ont)}`];
|
|
267
286
|
if (diff) {
|
|
268
287
|
const s = diff.summary;
|
package/dist/render.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { type Explainable, type MetaStep } from "./metakb.js";
|
|
2
|
-
import { type Ontology, type OkbNode } from "@ontology-kit/reader";
|
|
2
|
+
import { type CompetencyQuestionNode, type DesignDecisionNode, type Ontology, type OkbNode, type SourceLocationNode, type SourceNode } from "@ontology-kit/reader";
|
|
3
3
|
import { type Finding } from "./types.js";
|
|
4
4
|
import type { CheckReport } from "./check.js";
|
|
5
|
+
import type { MdDoc } from "./markdown.js";
|
|
6
|
+
import type { ReviewItem } from "./review.js";
|
|
7
|
+
import type { SkillState } from "./skills.js";
|
|
8
|
+
import type { computeStatus } from "./status.js";
|
|
9
|
+
type Status = ReturnType<typeof computeStatus>;
|
|
5
10
|
export declare const c: {
|
|
6
11
|
bold: (s: string) => string;
|
|
7
12
|
dim: (s: string) => string;
|
|
@@ -31,3 +36,58 @@ export declare function show(ont: Ontology, n: OkbNode): string;
|
|
|
31
36
|
export declare function mermaid(ont: Ontology): string;
|
|
32
37
|
/** The `okb check` summary: one line per check, the problems under the ones that failed, and a verdict. */
|
|
33
38
|
export declare function formatCheck(report: CheckReport, name: string): string;
|
|
39
|
+
export declare function formatNotes(notes: readonly string[]): string[];
|
|
40
|
+
export declare function renderInit(name: string, root: string, folder: string, guide: string): string[];
|
|
41
|
+
export declare function renderScope(m: Ontology["meta"]): string[];
|
|
42
|
+
export declare function renderConvention(ont: Ontology): string;
|
|
43
|
+
export declare function renderQuestions(ont: Ontology, qs: readonly CompetencyQuestionNode[]): string[];
|
|
44
|
+
export declare function renderTerms(ont: Ontology): string[];
|
|
45
|
+
export declare function renderReuse(ont: Ontology): string[];
|
|
46
|
+
export declare function renderDecisions(ont: Ontology, ds: readonly DesignDecisionNode[]): string[];
|
|
47
|
+
export declare function renderFindings(findings: Finding[], hiddenLater: number, ont: Ontology, opts: {
|
|
48
|
+
all?: boolean;
|
|
49
|
+
verbose?: boolean;
|
|
50
|
+
}): string[];
|
|
51
|
+
export declare function renderStatus(ont: Ontology, findings: Finding[], st: Status): string[];
|
|
52
|
+
/** What `okb step <n>` prints after moving: a warning if the step you left isn't finished, then the new step's guide. */
|
|
53
|
+
export declare function renderStepMove(target: number, leaving: {
|
|
54
|
+
order: number;
|
|
55
|
+
complete: boolean;
|
|
56
|
+
items: {
|
|
57
|
+
done: boolean | null;
|
|
58
|
+
text: string;
|
|
59
|
+
}[];
|
|
60
|
+
}): string[];
|
|
61
|
+
export declare function renderExplainHits(hits: readonly Explainable[], q: string): string[];
|
|
62
|
+
export declare function renderSearchHits(hits: readonly Explainable[], query: string): string[];
|
|
63
|
+
export declare function renderReview(ont: Ontology, items: ReviewItem[], all: boolean): string[];
|
|
64
|
+
export declare function renderSources(ont: Ontology): string[];
|
|
65
|
+
export declare function renderOutline(src: SourceNode, doc: MdDoc, blocks: MdDoc["blocks"], quoted: ReadonlyMap<number, unknown>, onlyProblems: boolean): string[];
|
|
66
|
+
export declare function renderQuotes(ont: Ontology, locs: readonly SourceLocationNode[]): string[];
|
|
67
|
+
export declare function renderRules(ont: Ontology): string[];
|
|
68
|
+
export declare function renderDrift(hits: readonly {
|
|
69
|
+
message: string;
|
|
70
|
+
}[]): string[];
|
|
71
|
+
export declare function renderReleaseVerify(r: {
|
|
72
|
+
ok: boolean;
|
|
73
|
+
id: string;
|
|
74
|
+
version: string;
|
|
75
|
+
checked: number;
|
|
76
|
+
problems: string[];
|
|
77
|
+
}): string[];
|
|
78
|
+
export declare function renderPin(version: string): string;
|
|
79
|
+
export declare function renderSkillsInstall(dir: string, lines: readonly string[]): string[];
|
|
80
|
+
export declare function renderSkillsStatus(dir: string, metaVersion: string, skills: readonly {
|
|
81
|
+
name: string;
|
|
82
|
+
state: SkillState;
|
|
83
|
+
detail: string;
|
|
84
|
+
}[]): string[];
|
|
85
|
+
export declare function renderWrote(out: string, what: string, hint: string): string;
|
|
86
|
+
export declare function renderStepGuide(order: number): string;
|
|
87
|
+
export declare function renderDiagramWritten(out: string): string;
|
|
88
|
+
export declare function renderExportWritten(out: string, g: {
|
|
89
|
+
nodes: unknown[];
|
|
90
|
+
relationships: unknown[];
|
|
91
|
+
notes: string[];
|
|
92
|
+
}, fmt: string): string[];
|
|
93
|
+
export {};
|
package/dist/render.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Human-readable output: findings, explanations, trees, node details, Mermaid diagrams. */
|
|
2
2
|
import { ruleUrl } from "./site.js";
|
|
3
|
-
import { MetaKB } from "./metakb.js";
|
|
3
|
+
import { MetaKB, explainName } from "./metakb.js";
|
|
4
4
|
import { edgeProps, nodeLabel } from "@ontology-kit/reader";
|
|
5
5
|
import {} from "./types.js";
|
|
6
6
|
import * as naming from "./naming.js";
|
|
@@ -430,3 +430,221 @@ export function formatCheck(report, name) {
|
|
|
430
430
|
out.push("", report.ok ? `${SYMBOL.ok} Safe to merge: ${safe}` : `${SYMBOL.error} Not safe to merge: ${failed} of ${report.steps.length} checks failed.`);
|
|
431
431
|
return out.join("\n");
|
|
432
432
|
}
|
|
433
|
+
// ---- Terminal output for the command records (src/commands/). Each returns lines; the runner prints them. ----
|
|
434
|
+
/** A note that teaches rather than reports is shown dimmed. */
|
|
435
|
+
const TIP = /^(Tip|Add a|Attach|Decide|Say which|List the)/;
|
|
436
|
+
export function formatNotes(notes) {
|
|
437
|
+
return notes.map((n) => (TIP.test(n) ? c.dim(" " + n) : n));
|
|
438
|
+
}
|
|
439
|
+
export function renderInit(name, root, folder, guide) {
|
|
440
|
+
return [`${SYMBOL.ok} Created ontology '${name}' in ${root}\n`, guide, c.dim(`\nNext: cd ${folder} && okb scope --domain "..." --purpose "..." --users "..."`)];
|
|
441
|
+
}
|
|
442
|
+
export function renderScope(m) {
|
|
443
|
+
const row = (k, val) => ` ${c.dim(k.padEnd(13))} ${Array.isArray(val) ? val.join(", ") || c.yellow("—") : val || c.yellow("—")}`;
|
|
444
|
+
return [c.bold(m.name), row("domain", m.domain), row("purpose", m.purpose), row("users", m.users), row("maintainers", m.maintainers), row("out of scope", m.outOfScope), row("kind", m.kind)];
|
|
445
|
+
}
|
|
446
|
+
export function renderConvention(ont) {
|
|
447
|
+
const cv = ont.conventions;
|
|
448
|
+
return `Naming convention: classes ${cv.classCase} (${cv.classNumber}) · slots ${cv.slotCase}${cv.slotAffix !== "none" ? ` (${cv.slotAffix})` : ""} · instances ${cv.instanceCase ?? "free text"}`;
|
|
449
|
+
}
|
|
450
|
+
export function renderQuestions(ont, qs) {
|
|
451
|
+
if (!qs.length)
|
|
452
|
+
return [c.dim('No competency questions yet. okb cq add "..."')];
|
|
453
|
+
const out = [];
|
|
454
|
+
for (const q of qs) {
|
|
455
|
+
const needs = ont.targets(q.id, "NEEDS").map((n) => ont.label(n));
|
|
456
|
+
const num = ont.displayNumber(q);
|
|
457
|
+
out.push(`${c.bold(String(num).padEnd(3))} ${q.text} ${c.dim(`[${q.status ?? "draft"}]`)}`);
|
|
458
|
+
out.push(c.dim(` needs: ${needs.length ? needs.join(", ") : "(not linked yet: okb cq link " + num + " <Class|slot>...)"}`));
|
|
459
|
+
}
|
|
460
|
+
return out;
|
|
461
|
+
}
|
|
462
|
+
export function renderTerms(ont) {
|
|
463
|
+
const ts = ont.ofType("Term");
|
|
464
|
+
const groups = new Map();
|
|
465
|
+
for (const t of ts) {
|
|
466
|
+
const d = t.disposition ?? "undecided";
|
|
467
|
+
const became = ont.targets(t.id, "BECAME").map((x) => ont.label(x));
|
|
468
|
+
groups.set(d, [...(groups.get(d) ?? []), t.text + (became.length ? c.dim(` → ${became.join(", ")}`) : "")]);
|
|
469
|
+
}
|
|
470
|
+
const out = [...groups].map(([d, items]) => `${c.bold(d.padEnd(13))} ${items.join(" · ")}`);
|
|
471
|
+
if (!ts.length)
|
|
472
|
+
out.push(c.dim("No terms yet. okb term add wine grape winery ..."));
|
|
473
|
+
return out;
|
|
474
|
+
}
|
|
475
|
+
export function renderReuse(ont) {
|
|
476
|
+
const rs = ont.ofType("ReusedOntology");
|
|
477
|
+
const out = rs.map((r) => `${c.bold(r.name)} ${c.dim(`[${r.decision}]`)} ${r.url ?? ""} ${r.notes ? "\n " + r.notes : ""}`);
|
|
478
|
+
if (!rs.length)
|
|
479
|
+
out.push(c.dim(ont.meta.reuseReviewed ? "Reviewed: nothing reused." : "Not reviewed yet."));
|
|
480
|
+
return out;
|
|
481
|
+
}
|
|
482
|
+
export function renderDecisions(ont, ds) {
|
|
483
|
+
const out = [];
|
|
484
|
+
for (const d of ds) {
|
|
485
|
+
out.push(`${c.bold(String(ont.displayNumber(d)).padEnd(3))} ${d.title}`);
|
|
486
|
+
out.push(` ${d.decision}${d.rationale ? c.dim(" · why: " + d.rationale) : ""}`);
|
|
487
|
+
const about = ont.targets(d.id, "ABOUT").map((x) => ont.label(x));
|
|
488
|
+
if (about.length || d.metaRules)
|
|
489
|
+
out.push(c.dim(` about: ${about.join(", ") || "—"}${d.metaRules ? " · explains: " + d.metaRules.join(", ") : ""}`));
|
|
490
|
+
}
|
|
491
|
+
if (!ds.length)
|
|
492
|
+
out.push(c.dim("No design decisions recorded yet."));
|
|
493
|
+
return out;
|
|
494
|
+
}
|
|
495
|
+
export function renderFindings(findings, hiddenLater, ont, opts) {
|
|
496
|
+
const out = [formatFindings(findings, ont, opts)];
|
|
497
|
+
if (hiddenLater)
|
|
498
|
+
out.push(c.dim(`(${hiddenLater} warning(s)/hint(s) from later steps are hidden until you get there; okb validate --all shows them. Errors are never hidden.)`));
|
|
499
|
+
return out;
|
|
500
|
+
}
|
|
501
|
+
export function renderStatus(ont, findings, st) {
|
|
502
|
+
const meta = MetaKB.get();
|
|
503
|
+
const shown = findings.filter((f) => !f.explainedBy && (f.severity === "error" || (meta.rule(f.rule).fromStep ?? 1) <= ont.step));
|
|
504
|
+
const count = (sev) => shown.filter((f) => f.severity === sev).length;
|
|
505
|
+
const out = [c.bold(ont.meta.name) + c.dim(` · ${ont.ofType("Class").length} classes · ${ont.ofType("Slot").length} slots · ${ont.ofType("Instance").length} instances · ${ont.ofType("CompetencyQuestion").length} questions`), ""];
|
|
506
|
+
for (const s of st.steps) {
|
|
507
|
+
const here = s.order === ont.step ? c.cyan(" ◀ you are here") : "";
|
|
508
|
+
const mark = s.complete ? SYMBOL.ok : s.order === ont.step ? c.cyan("▶") : SYMBOL.todo;
|
|
509
|
+
out.push(`${mark} ${c.bold(`${s.order}. ${s.name}`)}${here}`);
|
|
510
|
+
if (s.order === ont.step || (!s.complete && s.order < ont.step)) {
|
|
511
|
+
for (const it of s.items)
|
|
512
|
+
out.push(` ${it.done === null ? SYMBOL.ask : it.done ? SYMBOL.ok : SYMBOL.todo} ${it.text}`);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
out.push("");
|
|
516
|
+
out.push(`Validator (steps 1–${ont.step}): ${SYMBOL.error} ${count("error")} ${SYMBOL.warning} ${count("warning")} ${SYMBOL.info} ${count("info")} ${c.dim("okb validate for details")}`);
|
|
517
|
+
const cur = st.steps.find((s) => s.order === ont.step);
|
|
518
|
+
if (cur.complete && ont.step < st.steps.length)
|
|
519
|
+
out.push(c.green(`\nStep ${ont.step} looks done. When you're happy with it: okb step next`));
|
|
520
|
+
else if (st.suggested < ont.step)
|
|
521
|
+
out.push(c.yellow(`\nStep ${st.suggested} still has open items. It's fine to go back: okb step ${st.suggested}`));
|
|
522
|
+
else
|
|
523
|
+
out.push(c.dim(`\nSee the guide for this step: okb step`));
|
|
524
|
+
return out;
|
|
525
|
+
}
|
|
526
|
+
/** What `okb step <n>` prints after moving: a warning if the step you left isn't finished, then the new step's guide. */
|
|
527
|
+
export function renderStepMove(target, leaving) {
|
|
528
|
+
const out = [];
|
|
529
|
+
if (target > leaving.order && !leaving.complete) {
|
|
530
|
+
out.push(c.yellow(`Moving on with step ${leaving.order} unfinished (${leaving.items.filter((i) => i.done === false).map((i) => i.text).join("; ")}). That's allowed; the method is iterative.`));
|
|
531
|
+
}
|
|
532
|
+
out.push(c.cyan(`Now on step ${target}.`) + c.dim(` (To read a step's guide without moving: okb explain ${target})`) + "\n");
|
|
533
|
+
out.push(stepGuide(MetaKB.get().step(target)));
|
|
534
|
+
return out;
|
|
535
|
+
}
|
|
536
|
+
export function renderExplainHits(hits, q) {
|
|
537
|
+
if (!hits.length)
|
|
538
|
+
return [`Nothing called '${q}'. Try: okb explain --search ${q}`];
|
|
539
|
+
const out = [explain(hits[0])];
|
|
540
|
+
if (hits.length > 1)
|
|
541
|
+
out.push(c.dim(`\nAlso matches: ${hits.slice(1, 6).map(explainName).join(", ")}`));
|
|
542
|
+
return out;
|
|
543
|
+
}
|
|
544
|
+
export function renderSearchHits(hits, query) {
|
|
545
|
+
if (!hits.length)
|
|
546
|
+
return [`Nothing mentions '${query}'.`];
|
|
547
|
+
return hits.map((h) => `${(h.type === "Rule" ? h.key : h.id).padEnd(40)} ${c.dim(h.type)} ${h.type === "Rule" ? h.statement.slice(0, 60) : h.name}`);
|
|
548
|
+
}
|
|
549
|
+
/** `okb review` lists this many prompts per rule in the terminal; --json has them all. */
|
|
550
|
+
const REVIEW_PROMPTS_SHOWN = 12;
|
|
551
|
+
export function renderReview(ont, items, all) {
|
|
552
|
+
const out = [c.bold(all ? "Review: what only a person can judge (all rules)" : `Review: what only a person can judge (step ${ont.step} and anything already visible)`) + "\n"];
|
|
553
|
+
for (const it of items) {
|
|
554
|
+
out.push(`${SYMBOL.ask} ${c.bold(it.rule)} ${c.dim(`(${it.modality.replace("_", " ")})`)} ${it.question}`);
|
|
555
|
+
for (const f of it.flags)
|
|
556
|
+
out.push(` ${SYMBOL.warning} ${f}`);
|
|
557
|
+
for (const x of it.prompts.slice(0, REVIEW_PROMPTS_SHOWN))
|
|
558
|
+
out.push(` · ${x}`);
|
|
559
|
+
if (it.prompts.length > REVIEW_PROMPTS_SHOWN)
|
|
560
|
+
out.push(c.dim(` · ...and ${it.prompts.length - REVIEW_PROMPTS_SHOWN} more (okb review --json)`));
|
|
561
|
+
if (it.source)
|
|
562
|
+
out.push(c.dim(` ${it.source}`));
|
|
563
|
+
out.push("");
|
|
564
|
+
}
|
|
565
|
+
out.push(c.dim("Record answers that needed thought (or that someone might question later): okb decision add ..."));
|
|
566
|
+
return out;
|
|
567
|
+
}
|
|
568
|
+
export function renderSources(ont) {
|
|
569
|
+
const out = ont.ofType("Source").map((s) => `${c.bold(s.id)} ${s.title} ${c.dim(`(${s.format ?? "?"}, ${ont.sources(s.id, "PART_OF").length} quotes)`)} ${c.dim(s.localPath ?? s.url ?? "")}`);
|
|
570
|
+
if (!out.length)
|
|
571
|
+
out.push(c.dim("No sources yet. okb source add <file>"));
|
|
572
|
+
return out;
|
|
573
|
+
}
|
|
574
|
+
export function renderOutline(src, doc, blocks, quoted, onlyProblems) {
|
|
575
|
+
const out = [c.bold(`${doc.title ?? src.id}`) + c.dim(` ${src.localPath} · ${doc.blocks.length} blocks, ${doc.blocks.filter((b) => b.quotable).length} quotable`)];
|
|
576
|
+
if (doc.problems.length) {
|
|
577
|
+
out.push(c.yellow(`\n${doc.problems.length} problem(s) in the document:`));
|
|
578
|
+
for (const pr of doc.problems)
|
|
579
|
+
out.push(c.yellow(` line ${pr.line}: ${pr.message}`));
|
|
580
|
+
}
|
|
581
|
+
if (onlyProblems)
|
|
582
|
+
return out;
|
|
583
|
+
let lastPath = "";
|
|
584
|
+
for (const b of blocks) {
|
|
585
|
+
const pth = b.headingPath.join(" > ");
|
|
586
|
+
if (pth !== lastPath) {
|
|
587
|
+
out.push("\n" + c.bold(pth || "(top)"));
|
|
588
|
+
lastPath = pth;
|
|
589
|
+
}
|
|
590
|
+
const mark = !b.quotable ? c.dim("·") : quoted.has(b.startLine) ? SYMBOL.ok : SYMBOL.todo;
|
|
591
|
+
const where = `L${b.startLine}${b.endLine > b.startLine ? `-${b.endLine}` : ""}`.padEnd(9);
|
|
592
|
+
const label = b.kind === "code" ? c.dim(`code (${b.lang || "text"}), not quotable`) : b.kind === "comment" ? c.dim("comment") : b.kind === "frontmatter" ? c.dim("frontmatter") : (b.calloutType ? c.cyan(`[${b.calloutType}] `) : "") + b.text.slice(0, 110) + (b.text.length > 110 ? "…" : "");
|
|
593
|
+
out.push(` ${mark} ${c.dim(where)} ${c.dim(b.kind.padEnd(10))} ${label}${b.note?.startsWith("malformed") ? c.yellow(" ⚠ " + b.note) : ""}`);
|
|
594
|
+
}
|
|
595
|
+
out.push(c.dim(`\n${SYMBOL.ok} quoted ${SYMBOL.todo} not quoted yet · not quotable · okb quote add ${src.id} "..."`));
|
|
596
|
+
return out;
|
|
597
|
+
}
|
|
598
|
+
export function renderQuotes(ont, locs) {
|
|
599
|
+
return locs.map((l) => {
|
|
600
|
+
const by = ont.sources(l.id, "CITES").map((x) => ont.label(x));
|
|
601
|
+
return `${c.bold(l.id)} ${c.dim(`${l.locator}${l.lines ? `, line ${l.lines}` : ""}`)}\n "${l.quote}"${by.length ? c.dim(`\n cited by: ${by.join(", ")}`) : ""}`;
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
export function renderRules(ont) {
|
|
605
|
+
return ont.ofType("Rule").map((r) => {
|
|
606
|
+
const st = r.verification?.status ?? "unverified";
|
|
607
|
+
return `${c.bold(r.id)} ${c.dim(`[${r.modality} · ${r.authored ? "authored · " : ""}${st}${r.extractionConfidence ? " · " + r.extractionConfidence : ""}]`)}\n ${r.statement}${c.dim(`\n governs: ${ont.targets(r.id, "GOVERNS").map((x) => ont.label(x)).join(", ") || "—"} · cites: ${ont.targets(r.id, "CITES").join(", ")}`)}`;
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
export function renderDrift(hits) {
|
|
611
|
+
if (!hits.length)
|
|
612
|
+
return [`${SYMBOL.ok} No near-duplicate quotes across different sources.`];
|
|
613
|
+
return hits.map((h) => `${SYMBOL.info} ${h.message}`);
|
|
614
|
+
}
|
|
615
|
+
export function renderReleaseVerify(r) {
|
|
616
|
+
if (r.ok)
|
|
617
|
+
return [`${SYMBOL.ok} ${r.id} ${r.version} matches its manifest (${r.checked} files).`];
|
|
618
|
+
return [
|
|
619
|
+
`${SYMBOL.error} ${r.id} ${r.version} doesn't match its manifest:`,
|
|
620
|
+
...r.problems.map((pr) => ` - ${pr}`),
|
|
621
|
+
c.dim(" If the changes are intended, cut a new release: okb release <version>. If not, restore the files (git checkout)."),
|
|
622
|
+
];
|
|
623
|
+
}
|
|
624
|
+
export function renderPin(version) {
|
|
625
|
+
return `${SYMBOL.ok} Pinned okb ${version} in okb.json. okb check warns anyone with an older okb, and the CI workflow installs this version.`;
|
|
626
|
+
}
|
|
627
|
+
export function renderSkillsInstall(dir, lines) {
|
|
628
|
+
return [`${SYMBOL.ok} Skills in ${dir}`, ...lines.map((l) => ` ${l}`), c.dim("\n Start a new Claude Code or Cursor session to load them.")];
|
|
629
|
+
}
|
|
630
|
+
export function renderSkillsStatus(dir, metaVersion, skills) {
|
|
631
|
+
const good = (s) => s === "current";
|
|
632
|
+
const out = [c.bold(`Skills in ${dir}`) + c.dim(` (okb meta-KB ${metaVersion})`)];
|
|
633
|
+
for (const s of skills)
|
|
634
|
+
out.push(` ${good(s.state) ? SYMBOL.ok : s.state === "missing" ? SYMBOL.todo : SYMBOL.warning} ${s.name.padEnd(26)} ${s.detail}`);
|
|
635
|
+
if (!skills.every((s) => good(s.state)))
|
|
636
|
+
out.push(c.dim("\n Fix it with: okb skills install"));
|
|
637
|
+
return out;
|
|
638
|
+
}
|
|
639
|
+
export function renderWrote(out, what, hint) {
|
|
640
|
+
return `${SYMBOL.ok} Wrote ${what} to ${out}${hint}.`;
|
|
641
|
+
}
|
|
642
|
+
export function renderStepGuide(order) {
|
|
643
|
+
return stepGuide(MetaKB.get().step(order));
|
|
644
|
+
}
|
|
645
|
+
export function renderDiagramWritten(out) {
|
|
646
|
+
return `Wrote ${out}. Open it in GitHub, VS Code (Markdown preview), or mermaid.live.`;
|
|
647
|
+
}
|
|
648
|
+
export function renderExportWritten(out, g, fmt) {
|
|
649
|
+
return [`Wrote ${out}: ${g.nodes.length} nodes, ${g.relationships.length} relationships (${fmt}).`, ...g.notes.map((n) => c.dim(" " + n))];
|
|
650
|
+
}
|
package/dist/runner.d.ts
ADDED
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
|
+
}
|