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).
Install
Section titled “Install”It needs Node.js 22 or later. To try it without installing anything, run it
with npx:
npx okforest validate .To run okforest directly, as the examples on this page do, install it
globally:
npm install --global okforestIn a repository, add it as a development dependency instead, so everyone and
CI run the same version (then npx okforest runs that one):
npm install --save-dev okforestokforest validate [path]
Section titled “okforest validate [path]”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.
okforest validate knowledgeokforest 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 jsonwrites 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.
okforest rule [rule]
Section titled “okforest rule [rule]”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.
okforest rule okf/typeokforest rule okforest/slug --format json- A coding agent that runs
okforest validatecan runokforest ruleon each rule it reports, to learn the fix without fetching a page. --format jsongives the rule as data: its severity, description,why, andexample.- A mistyped rule gets a suggestion:
okforest rule okf/slugasks whether you meantokforest/slug.
Diagram checks
Section titled “Diagram checks”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:
npx -p okforest -p @d2lang/d2 -p mermaid okforest validate .npm install --save-dev okforest @d2lang/d2 mermaid # or in a repositoryWithout 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.
okforest inventory [path]
Section titled “okforest inventory [path]”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.
okforest inventory . --format jsonokforest init [path]
Section titled “okforest init [path]”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 rootindex.mddeclaringokf_version: "0.3",log.md, and.okforest/settings.yamlwith the tree’s name (--name, defaulting to the folder’s name); see Settings for every setting;README.md, with a setup checklist, andAGENTS.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 onokf/;.github/dependabot.yaml, which keeps the workflow’s actions up to date, and.gitignore.
npx okforest init acme-knowledge --name "Acme Knowledge"npx okforest validate acme-knowledge/okfFor 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.
The company template
Section titled “The company template”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/, andlegal/, 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: anx-owneris 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:
npx giget gh:okforest/template-company-knowledge acme-knowledgeThen 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.
Your own template
Section titled “Your own template”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:
npx giget gh:acme/sales-knowledge-template sales-knowledgeThen set the new tree’s name in okf/.okforest/settings.yaml (a copy
keeps the template’s own) and check it:
npx okforest validate sales-knowledge/okfokforest new <type> <file>
Section titled “okforest new <type> <file>”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.
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 folderokforest types init [path]
Section titled “okforest types init [path]”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;
requiredfor 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.
okforest types init . --dry-run # print the draftsokforest types init . --type Customer # only some types (repeatable)What counts as a concept
Section titled “What counts as a concept”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.
As a library
Section titled “As a library”The CLI is built on two packages you can use directly, in Node, browsers, and Workers:
@okforest/okfreads a tree into a model: concepts, links, backlinks, trust tiers, staleness, and the metadata inventory.@okforest/validateruns the rules and returns structured findings.