Skip to content

OKForest CLI

The OKForest CLI checks Open Knowledge Format (OKF) trees, lists their metadata, and starts new ones. Each tree is checked by the OKF version its root index.md declares (okf_version: 0.2 or 0.3). It is deterministic: no model calls and no network, and the same results on every machine. It is the same code that runs inside the OKForest service. The source is at github.com/okforest/cli (Apache 2.0).

It needs Node.js 22 or later. To try it without installing anything, run it with npx:

Terminal window
npx okforest validate .

To run okforest directly, as the examples on this page do, install it globally:

Terminal window
npm install --global okforest

In a repository, add it as a development dependency instead, so everyone and CI run the same version (then npx okforest runs that one):

Terminal window
npm install --save-dev okforest

Checks a tree against the OKF specification, by the version the tree declares, and OKForest’s conventions (see Rules), and prints each finding with its file and line. A tree on 0.2, or with no version, is told that 0.3 is current, to move when it’s ready.

Terminal window
okforest validate knowledge
okforest validate . --format json
  • Exits with 1 when there are errors, and 0 otherwise. Warnings and info never fail: a conformant bundle with, say, a broken link still passes, as the specification requires.
  • Exits with 2 on usage problems, such as a path that doesn’t exist.
  • --format json writes a versioned report (schemaVersion: 1) for CI and other tools. It is the same document the GitHub Action writes.
  • Every finding names its rule, and links to the rule’s page in these docs (Rules): the text output ends with a “Rule docs” list, and each finding in the JSON report carries docs, the page’s URL. okforest rule <rule> explains one in the terminal.

Explains a rule, the same as its page in these docs, offline: why it exists, an example that breaks it, what okforest validate reports for it, and the fix. Without a rule, it lists every rule with its severity.

Terminal window
okforest rule okf/type
okforest rule okforest/slug --format json
  • A coding agent that runs okforest validate can run okforest rule on each rule it reports, to learn the fix without fetching a page.
  • --format json gives the rule as data: its severity, description, why, and example.
  • A mistyped rule gets a suggestion: okforest rule okf/slug asks whether you meant okforest/slug.

The D2 and Mermaid syntax checks use optional packages, about 200 MB together, so the CLI stays small without them. Install them alongside the CLI to turn the checks on:

Terminal window
npx -p okforest -p @d2lang/d2 -p mermaid okforest validate .
npm install --save-dev okforest @d2lang/d2 mermaid # or in a repository

Without them, diagram blocks are reported as not checked (info). Some Mermaid diagram types (pie, gitGraph, and others) need a browser to parse and are also reported as not checked. The GitHub Action includes the diagram checks, with nothing to install.

Lists every type, tag, and frontmatter key in use, with counts, status and trust totals, and likely near-duplicates (e-commerce and ecommerce, Policy and Policies). Use it to settle on one vocabulary before a tree grows.

Terminal window
okforest inventory . --format json

Starts a repository for a tree, laid out as the company template is, with an empty tree that validates with no problems:

  • okf/, the tree: a root index.md declaring okf_version: "0.3", log.md, and .okforest/settings.yaml with the tree’s name (--name, defaulting to the folder’s name); see Settings for every setting;
  • README.md, with a setup checklist, and AGENTS.md, telling AI agents how to write the tree’s pages;
  • .github/workflows/ci.yaml, which scans every pull request for secrets with Betterleaks (its rules in .betterleaks.toml, including one for passwords written out in text), then runs the OKForest Validate action on okf/;
  • .github/dependabot.yaml, which keeps the workflow’s actions up to date, and .gitignore.
Terminal window
npx okforest init acme-knowledge --name "Acme Knowledge"
npx okforest validate acme-knowledge/okf

For a tree on OKF 0.2, start it with the last CLI that made one: npx okforest@0.15.0 init.

For a company’s tree, with its folders, types, and starter concepts, start from a template instead.

okforest/template-company-knowledge is a tree for what a company is and how it runs, kept as a GitHub template repository:

  • its folders: company/ (overview, mission, vision, values, history, brand, glossary), products/, market/, revenue/ (marketing, sales, customer support), people/ (roles, org chart, onboarding), operations/ (vendors, meetings, and operating policies), technology/ (architecture, security, and decisions), finance/, and legal/, with 44 draft starter concepts;
  • 18 types, each with a schema and a template: Organization, Statement, Guide, Term, Product, Pricing, Plan, Customer Profile, Persona, Competitor, Process, Policy, Role, Person, Vendor, Budget, Agreement, and Decision;
  • its conventions, in AGENTS.md: an x-owner is a role (/people/roles/cfo), not a person; a person’s job title is apart from the roles they hold; and secrets are never kept in the tree, only where they’re kept.

The tree is in okf/, beside the repository’s README.md and its workflows (OKForest Validate, and a secret scan). Start a copy with Use this template › Create a new repository on GitHub, or:

Terminal window
npx giget gh:okforest/template-company-knowledge acme-knowledge

Then follow its README’s setup checklist, which replaces the template’s two placeholders ({{company_name}} and {{password_manager}}); until then, validating it warns about them.

To start trees from your own template (your teams’ types, their schemas and templates, and your starter concepts), keep it as a repository of its own, laid out as the company template is and as okforest init starts one: the tree in okf/, with a README.md, an AGENTS.md, and .github/ for its workflows. One repository per template, so its CI runs, Dependabot keeps its workflows’ actions up to date, and each copy gets all of it.

On GitHub, mark it a template (the repository’s Settings, then Template repository). Each new tree is then Use this template › Create a new repository: a new repository with the template’s files and none of its history. Or copy it from a terminal with giget:

Terminal window
npx giget gh:acme/sales-knowledge-template sales-knowledge

Then set the new tree’s name in okf/.okforest/settings.yaml (a copy keeps the template’s own) and check it:

Terminal window
npx okforest validate sales-knowledge/okf

Creates a concept of a type at a path in the tree, from the type’s template when it has one, exactly as written, with the title and description given put in place; a type without a template starts with just its type, title, and description. When the file’s folder has an index.md, the new concept is listed in it. A folder it creates gets an index.md listing the new concept, and is listed in its parent’s: okforest new Persona market/personas/cfo.md writes market/personas/index.md and adds it to market/index.md. Then the new page is checked, so what’s left to fill in shows at once.

Terminal window
okforest new Metric metrics/churn.md --title "Monthly churn" \
--description "Customers who cancel in a month, as a share of those at its start."
okforest new Metric metrics/arr.md --root acme-okf # a tree that isn't the current folder

Drafts a type schema for each type in use that has none, in .okforest/types/, from what the type’s concepts hold:

  • each field they use beyond OKF’s own, typed by its values;
  • a format (a date, a date and time, an email address, a URI) when every value has it;
  • the allowed values, when a few short ones repeat;
  • required for the fields every concept has, when there are two or more.

Each concept it’s drafted from matches the draft, so okforest validate still passes; tighten it from there. It never overwrites a file: a type that has a schema is skipped.

Terminal window
okforest types init . --dry-run # print the drafts
okforest types init . --type Customer # only some types (repeatable)

Every .md file is a concept except index.md and log.md (reserved by OKF) and files under .okforest/ and .git/. That includes repository files such as README.md, and markdown under .github/. Leave out the ones that are not concepts with ignore: globs in .okforest/settings.yaml (glob syntax):

ignore:
- README.md
- drafts/

The CLI lists ignored files, so links to them still resolve, but doesn’t read them.

The CLI is built on two packages you can use directly, in Node, browsers, and Workers:

  • @okforest/okf reads a tree into a model: concepts, links, backlinks, trust tiers, staleness, and the metadata inventory.
  • @okforest/validate runs the rules and returns structured findings.