@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
package/dist/render.d.ts CHANGED
@@ -1,6 +1,14 @@
1
+ import type { Note } from "./ops.js";
1
2
  import { type Explainable, type MetaStep } from "./metakb.js";
2
- import { type Ontology, type OkbNode } from "@ontology-kit/format";
3
+ import { type CompetencyQuestionNode, type DesignDecisionNode, type Ontology, type OkbNode, type SourceLocationNode, type SourceNode } from "@ontology-kit/reader";
3
4
  import { type Finding } from "./types.js";
5
+ import type { QueryResult } from "@ontology-kit/reader";
6
+ import type { CheckReport } from "./check.js";
7
+ import type { MdDoc } from "./markdown.js";
8
+ import type { ReviewItem } from "./review.js";
9
+ import type { SkillState } from "./skills.js";
10
+ import type { computeStatus } from "./status.js";
11
+ type Status = ReturnType<typeof computeStatus>;
4
12
  export declare const c: {
5
13
  bold: (s: string) => string;
6
14
  dim: (s: string) => string;
@@ -28,3 +36,82 @@ export declare function listExplainable(): string;
28
36
  export declare function tree(ont: Ontology, withInstances?: boolean): string;
29
37
  export declare function show(ont: Ontology, n: OkbNode): string;
30
38
  export declare function mermaid(ont: Ontology): string;
39
+ /** The `okb check` summary: one line per check, the problems under the ones that failed, and a verdict. */
40
+ export declare function formatCheck(report: CheckReport, name: string): string;
41
+ /** A tip teaches rather than reports, so it is shown dimmed and indented. */
42
+ export declare function formatNotes(notes: readonly Note[]): string[];
43
+ export declare function renderInit(name: string, root: string, folder: string, guide: string): string[];
44
+ export declare function renderScope(m: Ontology["meta"]): string[];
45
+ export declare function renderConvention(ont: Ontology): string;
46
+ export declare function renderQuestions(ont: Ontology, qs: readonly CompetencyQuestionNode[]): string[];
47
+ export declare function renderTerms(ont: Ontology): string[];
48
+ export declare function renderReuse(ont: Ontology): string[];
49
+ export declare function renderDecisions(ont: Ontology, ds: readonly DesignDecisionNode[]): string[];
50
+ export declare function renderFindings(findings: Finding[], hiddenLater: number, ont: Ontology, opts: {
51
+ all?: boolean;
52
+ verbose?: boolean;
53
+ }): string[];
54
+ export declare function renderStatus(ont: Ontology, findings: Finding[], st: Status): string[];
55
+ /** What `okb step <n>` prints after moving: a warning if the step you left isn't finished, then the new step's guide. */
56
+ export declare function renderStepMove(target: number, leaving: {
57
+ order: number;
58
+ complete: boolean;
59
+ items: {
60
+ done: boolean | null;
61
+ text: string;
62
+ }[];
63
+ }): string[];
64
+ export declare function renderExplainHits(hits: readonly Explainable[], q: string): string[];
65
+ export declare function renderSearchHits(hits: readonly Explainable[], query: string): string[];
66
+ export declare function renderReview(ont: Ontology, items: ReviewItem[], all: boolean): string[];
67
+ export declare function renderSources(ont: Ontology): string[];
68
+ export declare function renderOutline(src: SourceNode, doc: MdDoc, blocks: MdDoc["blocks"], quoted: ReadonlyMap<number, unknown>, onlyProblems: boolean): string[];
69
+ export declare function renderQuotes(ont: Ontology, locs: readonly SourceLocationNode[]): string[];
70
+ export declare function renderRules(ont: Ontology): string[];
71
+ export declare function renderDrift(hits: readonly {
72
+ message: string;
73
+ }[]): string[];
74
+ export declare function renderReleaseVerify(r: {
75
+ ok: boolean;
76
+ id: string;
77
+ version: string;
78
+ checked: number;
79
+ problems: string[];
80
+ }): string[];
81
+ export declare function renderPin(version: string): string;
82
+ export declare function renderSkillsInstall(dir: string, lines: readonly string[]): string[];
83
+ export declare function renderSkillsStatus(dir: string, metaVersion: string, skills: readonly {
84
+ name: string;
85
+ state: SkillState;
86
+ detail: string;
87
+ }[]): string[];
88
+ export declare function renderWrote(out: string, what: string, hint: string): string;
89
+ export declare function renderStepGuide(order: number): string;
90
+ export declare function renderDiagramWritten(out: string): string;
91
+ export declare function renderChangeSetWritten(out: string, s: {
92
+ nodesAdded: number;
93
+ nodesChanged: number;
94
+ nodesRemoved: number;
95
+ relationshipsAdded: number;
96
+ relationshipsChanged: number;
97
+ relationshipsRemoved: number;
98
+ }): string[];
99
+ export declare function renderExportWritten(out: string, g: {
100
+ nodes: unknown[];
101
+ relationships: unknown[];
102
+ notes: string[];
103
+ }, fmt: string, files?: string[]): string[];
104
+ /** `okb export --format eval-cases` written to a file. */
105
+ export declare function renderEvalCasesWritten(out: string, e: {
106
+ kb: {
107
+ version: string | null;
108
+ };
109
+ cases: unknown[];
110
+ skipped: {
111
+ number: number;
112
+ }[];
113
+ notes: string[];
114
+ }): string[];
115
+ /** `okb query` as text: one line per hit, the kind in a heading. */
116
+ export declare function renderQueryResult(ont: Ontology, r: QueryResult): string[];
117
+ export {};
package/dist/render.js CHANGED
@@ -1,7 +1,7 @@
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";
4
- import { edgeProps, nodeLabel } from "@ontology-kit/format";
3
+ import { MetaKB, explainName } from "./metakb.js";
4
+ import { edgeProps, nodeLabel } from "@ontology-kit/reader";
5
5
  import {} from "./types.js";
6
6
  import * as naming from "./naming.js";
7
7
  const useColor = process.stdout.isTTY && !process.env.NO_COLOR;
@@ -279,6 +279,10 @@ export function show(ont, n) {
279
279
  out.push(`${c.bold(nodeLabel(n))} ${c.dim(`${n.type} · ${n.id}`)}`);
280
280
  if ("description" in n && n.description)
281
281
  out.push(indent(n.description, " "));
282
+ if (n.createdAt)
283
+ line("created", n.createdAt);
284
+ if (n.updatedAt)
285
+ line("updated", n.updatedAt);
282
286
  if (n.type === "Class") {
283
287
  line("parents", ont.parents(n.id).map((p) => ont.label(p)).join(", ") || "(top level)");
284
288
  line("subclasses", ont.children(n.id).map((p) => ont.label(p)).join(", ") || "—");
@@ -339,7 +343,7 @@ export function show(ont, n) {
339
343
  }
340
344
  else {
341
345
  for (const [k, v] of Object.entries(n))
342
- if (!["id", "type", "name", "values", "authored"].includes(k))
346
+ if (!["id", "type", "name", "values", "authored", "createdAt", "updatedAt"].includes(k))
343
347
  line(k, typeof v === "string" ? v : JSON.stringify(v));
344
348
  if (n.type === "Rule") {
345
349
  if (n.authored)
@@ -411,3 +415,261 @@ export function mermaid(ont) {
411
415
  out.push("", `Disjoint: ${disj.join(" · ")}`);
412
416
  return out.join("\n");
413
417
  }
418
+ /** The `okb check` summary: one line per check, the problems under the ones that failed, and a verdict. */
419
+ export function formatCheck(report, name) {
420
+ const out = [c.bold(`okb check: ${name}`) + c.dim(` (okb ${report.installed}${report.pinned ? `, KB pins ${report.pinned}` : ""})`), ""];
421
+ const mark = { pass: SYMBOL.ok, warn: SYMBOL.warning, fail: SYMBOL.error };
422
+ for (const s of report.steps) {
423
+ out.push(`${mark[s.status]} ${c.bold(s.title)}: ${s.summary}`);
424
+ for (const p of s.problems)
425
+ out.push(` ${SYMBOL.error} ${p}`);
426
+ }
427
+ const failed = report.steps.filter((s) => s.status === "fail").length;
428
+ const warned = report.steps.filter((s) => s.status === "warn").length;
429
+ const safe = warned ? `no check failed, but ${warned} warned (marked ${SYMBOL.warning} above).` : "every check passed.";
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
+ return out.join("\n");
432
+ }
433
+ // ---- Terminal output for the command records (src/commands/). Each returns lines; the runner prints them. ----
434
+ /** A tip teaches rather than reports, so it is shown dimmed and indented. */
435
+ export function formatNotes(notes) {
436
+ return notes.map((n) => (typeof n === "string" ? n : c.dim(" " + n.text)));
437
+ }
438
+ export function renderInit(name, root, folder, guide) {
439
+ return [`${SYMBOL.ok} Created ontology '${name}' in ${root}\n`, guide, c.dim(`\nNext: cd ${folder} && okb scope --domain "..." --purpose "..." --users "..."`)];
440
+ }
441
+ export function renderScope(m) {
442
+ const row = (k, val) => ` ${c.dim(k.padEnd(13))} ${Array.isArray(val) ? val.join(", ") || c.yellow("—") : val || c.yellow("—")}`;
443
+ 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)];
444
+ }
445
+ export function renderConvention(ont) {
446
+ const cv = ont.conventions;
447
+ return `Naming convention: classes ${cv.classCase} (${cv.classNumber}) · slots ${cv.slotCase}${cv.slotAffix !== "none" ? ` (${cv.slotAffix})` : ""} · instances ${cv.instanceCase ?? "free text"}`;
448
+ }
449
+ export function renderQuestions(ont, qs) {
450
+ if (!qs.length)
451
+ return [c.dim('No competency questions yet. okb cq add "..."')];
452
+ const out = [];
453
+ for (const q of qs) {
454
+ const needs = ont.targets(q.id, "NEEDS").map((n) => ont.label(n));
455
+ const num = ont.displayNumber(q);
456
+ out.push(`${c.bold(String(num).padEnd(3))} ${q.text} ${c.dim(`[${q.status ?? "draft"}]`)}`);
457
+ out.push(c.dim(` needs: ${needs.length ? needs.join(", ") : "(not linked yet: okb cq link " + num + " <Class|slot>...)"}`));
458
+ out.push(c.dim(` answer: ${q.answer ? q.answer.expect.join(", ") + (q.answer.match === "includes" ? " (and maybe more)" : "") : "(none stored: okb cq answer " + num + " --query '...' --expect ...)"}`));
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 renderChangeSetWritten(out, s) {
649
+ return [`Wrote ${out}: a change set (cypher). Nodes: ${s.nodesAdded} added, ${s.nodesChanged} changed, ${s.nodesRemoved} removed. Relationships: ${s.relationshipsAdded} added, ${s.relationshipsChanged} changed, ${s.relationshipsRemoved} removed.`];
650
+ }
651
+ export function renderExportWritten(out, g, fmt, files) {
652
+ const where = files ? `${out}/ (${files.join(", ")})` : out;
653
+ return [`Wrote ${where}: ${g.nodes.length} nodes, ${g.relationships.length} relationships (${fmt}).`, ...g.notes.map((n) => c.dim(" " + n))];
654
+ }
655
+ /** `okb export --format eval-cases` written to a file. */
656
+ export function renderEvalCasesWritten(out, e) {
657
+ const skipped = e.skipped.length ? `, skipped ${e.skipped.length} with no stored answer (${e.skipped.map((s) => s.number).join(", ")})` : "";
658
+ return [`Wrote ${out}: ${e.cases.length} eval cases${e.kb.version ? ` from release ${e.kb.version}` : ""}${skipped}.`, ...e.notes.map((n) => c.dim(" " + n))];
659
+ }
660
+ /** `okb query` as text: one line per hit, the kind in a heading. */
661
+ export function renderQueryResult(ont, r) {
662
+ if (!r.hits.length)
663
+ return [c.dim(`No ${r.kind} results.`)];
664
+ const out = [];
665
+ if (r.kind === "find")
666
+ for (const h of r.hits)
667
+ out.push(h.name);
668
+ else if (r.kind === "slots")
669
+ for (const h of r.hits)
670
+ out.push(`${h.name} ${c.dim(`(${h.relationship ? "relationship" : "property"}${h.valueType ? `, ${h.valueType}` : ""})`)}`);
671
+ else
672
+ for (const h of r.hits)
673
+ out.push(`${h.name}${h.type ? " " + c.dim(`(${h.type})`) : ""} ${c.dim(`from ${ont.label(h.from)}${h.depth > 1 ? `, hop ${h.depth}` : ""}${h.inheritedFrom ? `, inherited from ${ont.label(h.inheritedFrom)}` : ""}`)}`);
674
+ return out;
675
+ }
@@ -0,0 +1,98 @@
1
+ import type { Ontology, SourceBlock } from "@ontology-kit/reader";
2
+ import { type MdDoc } from "./markdown.js";
3
+ /** Which block a baseline or current record describes, plus its hash. */
4
+ export type BlockRecord = SourceBlock;
5
+ export declare const RESYNC_SCHEMA = "okb-resync/1";
6
+ export declare const hashText: (text: string) => string;
7
+ /** The records for a document's quotable blocks, in document order. */
8
+ export declare function blockRecords(doc: MdDoc): BlockRecord[];
9
+ export type Change = "new" | "changed" | "removed";
10
+ export interface WorklistItem {
11
+ /** Stable across runs while the block's text is unchanged: `<source id>:<first 12 hex of the hash>`. */
12
+ id: string;
13
+ source: string;
14
+ change: Change;
15
+ headingPath: string[];
16
+ blockKind: string;
17
+ /** Line range in the current document; null for a removed block. */
18
+ lines: [number, number] | null;
19
+ /** Hash of the current text; null for a removed block. */
20
+ hash: string | null;
21
+ /** Hash of the text the baseline recorded; null for a new block. */
22
+ oldHash: string | null;
23
+ preview: string | null;
24
+ oldPreview: string | null;
25
+ }
26
+ export interface BlockDiff {
27
+ change: Change;
28
+ old?: BlockRecord;
29
+ /** The index into the current list. */
30
+ current?: number;
31
+ }
32
+ /**
33
+ * Compare a baseline with the current blocks. Pure. A block whose hash is still present is unchanged, wherever it
34
+ * moved. What's left is paired up as "changed" (same place, similar text), and the rest is "new" or "removed".
35
+ */
36
+ export declare function diffBlocks(baseline: BlockRecord[], current: BlockRecord[]): BlockDiff[];
37
+ export interface Citer {
38
+ id: string;
39
+ type: string;
40
+ label: string;
41
+ }
42
+ export interface QuoteIssue {
43
+ source: string;
44
+ /** The SourceLocation id. */
45
+ quote: string;
46
+ text: string;
47
+ was: {
48
+ locator?: string;
49
+ lines?: string;
50
+ };
51
+ /** Nodes that cite the quote: rules, facts, classes. */
52
+ citedBy: Citer[];
53
+ }
54
+ export interface MovedQuote extends QuoteIssue {
55
+ now: {
56
+ locator?: string;
57
+ lines?: string;
58
+ };
59
+ }
60
+ export interface SourceStatus {
61
+ id: string;
62
+ path: string | null;
63
+ format: string | null;
64
+ /** "checked", or why the source couldn't be (no local file, file missing). */
65
+ state: "checked" | "unreadable";
66
+ problem?: string;
67
+ /** Whether the Source has baseline hashes to compare against. Only markdown sources do. */
68
+ baseline: boolean;
69
+ quotes: number;
70
+ moved: number;
71
+ gone: number;
72
+ }
73
+ export interface ResyncReport {
74
+ schema: typeof RESYNC_SCHEMA;
75
+ /** False when a quote is gone or a source can't be read: the KB no longer matches its documents. */
76
+ ok: boolean;
77
+ /** True when the current blocks were stored as the new baseline (`--record`). */
78
+ recorded: boolean;
79
+ sources: SourceStatus[];
80
+ gone: QuoteIssue[];
81
+ moved: MovedQuote[];
82
+ worklist: WorklistItem[];
83
+ }
84
+ export interface ResyncOptions {
85
+ /** Update moved quotes in `ont` (the quote's own lines and links). Never touches a quote that can't be found. */
86
+ write: boolean;
87
+ /** Also store the current blocks as the baseline. Implies `write`. */
88
+ record: boolean;
89
+ }
90
+ /**
91
+ * Re-locate every quote in every source and compare each markdown source's blocks to its baseline. `pages` is
92
+ * `loadSourcePages(ont)`. With `write` false nothing in `ont` changes.
93
+ */
94
+ export declare function resync(ont: Ontology, pages: Map<string, string[] | MdDoc | Error>, o: ResyncOptions): ResyncReport;
95
+ /** The human-readable report, as lines. */
96
+ export declare function renderResync(r: ResyncReport, o: {
97
+ dryRun: boolean;
98
+ }): string[];