Expand description
§okf-core: the Open Knowledge Format, in pure Rust
A pure-Rust implementation of the Open Knowledge Format (OKF) v0.2, Google’s open, human- and agent-friendly format for representing knowledge as a directory of markdown files with YAML frontmatter.
OKF is intentionally minimal (“if you can cat a file, you can read OKF; if
you can git clone a repo, you can ship it”), so this crate implements it
with the standard library alone: its own YAML-subset parser, a
markdown link scanner, and a directory walker. The companion okf crate re-exports this
entire library and ships the okf command-line tool.
§Model
- A
Bundleis a directory tree of markdown files. - A
Conceptis one markdownDocument= YAMLFrontmatter+ body. - A
ConceptIdis a concept’s path within the bundle, minus.md. - Concepts relate via markdown
links; the bundle exposes the resulting graph and backlinks. index.mddirectory listings are generated byindex.log.mdhistories are parsed bylog.- Conformance checking and linting live in the companion
okf-validatorcrate.
§What v0.2 adds
v0.2 makes provenance, trust, lifecycle, and attestation first-class. Every one of the new keys is optional, and absence is meaningful rather than invalid, so a v0.1 document is still a conformant v0.2 document.
| Concern | Frontmatter | Module |
|---|---|---|
| Provenance | sources, usage_window | provenance |
| Trust | generated, verified, trust tiers | trust |
| Lifecycle | status, stale_after | trust |
| Identity | the actor convention | actor |
| Attestation | runtime, parameters, computation, executor, attester | computation |
| Attribution | [^label] footnotes keyed to sources[].id | footnotes |
Two v0.1 constructs are superseded but still readable, since a v0.2
consumer is expected to handle v0.1 bundles: timestamp gives way to
generated.at (see Frontmatter::content_changed_at), and the body
# Citations list gives way to sources (see Document::citations).
§Example
use okf_core::{Bundle, ConceptId};
let bundle = Bundle::load("./my_bundle")?;
println!("{} concepts", bundle.len());
let id = ConceptId::parse("tables/orders")?;
for link in bundle.links_from(&id) {
println!("{} -> {} (exists: {})", id, link.target, link.exists);
}Reading a concept’s trust signals:
use okf_core::{Document, TrustTier};
let doc = Document::parse(
"---\n\
type: Metric\n\
title: Revenue\n\
status: stable\n\
generated: { by: reference_agent/gemini-2.5-pro, at: 2026-06-20T22:53:05Z }\n\
verified: { by: human:walter, at: 2026-06-25T09:00:00Z }\n\
stale_after: 2026-12-31\n\
---\n\n\
)
.unwrap();
// A bare `verified` mapping counts as a one-element list.
assert_eq!(doc.frontmatter.verified().len(), 1);
assert_eq!(doc.frontmatter.trust_tier(), TrustTier::HumanReviewed);
assert_eq!(doc.frontmatter.status().to_string(), "stable");Modules§
- actor
- The actor convention: who or what performed an action.
- bundle
- Loading and traversing an OKF bundle: a directory tree of markdown files.
- computation
- Attested Computation concepts.
- concept_
id - Concept identifiers and their mapping to/from file paths.
- date
- Calendar dates and ISO-8601 datetimes for the trust and lifecycle families.
- diff
- Bundle-level diff: an OKF-semantics diff between two
Bundles. - document
- The OKF concept document: YAML frontmatter + markdown body.
- error
- Error types for the crate.
- fix
- Automated remediation and migrations for OKF concepts, bundles, and logs.
- footnotes
- Markdown footnotes, the carrier for per-claim attribution.
- frontmatter
- Typed, order-preserving access to a concept’s YAML frontmatter.
- index
- Generation of
index.mddirectory listings. - links
- Markdown link extraction, classification, and path-valued fields.
- log
- Parsing, building, and updating
log.mdupdate histories. - markdown
- Markdown scanning, link rewriting, heading extraction, and anchor slugs.
- provenance
- Provenance: the
sourcesfrontmatter family and per-claim attribution. - refactor
- Knowledge refactoring, concept relocation, deletion, splitting, and merging.
- scaffold
- Scaffolding and initialization utilities for OKF bundles and concept documents.
- trust
- Trust and lifecycle frontmatter:
generated,verified,status, andstale_after. - yaml
- A small YAML subset parser used for OKF frontmatter.
Structs§
- Actor
- A parsed actor string, retaining the text exactly as written.
- Attested
Computation - The contract of an
Attested Computationconcept: its top-level frontmatter plus the computation itself. - Attester
- The deterministic check.
- Attribution
- A body claim attributed to a source, produced by joining footnote labels to
sources[].id. - Bundle
- A loaded OKF bundle.
- Bundle
Diff - A bundle-level diff.
- Bundle
FixReport - Remediation report for a whole bundle.
- Bundle
Init Options - Options for initializing a new OKF bundle.
- Citation
- A numbered entry under a legacy v0.1
# Citationsheading. - Concept
- A single concept within a bundle (one markdown document).
- Concept
Id - A concept identifier: an ordered list of path segments (e.g.
["tables", "users"]fortables/users). - Concept
IdError - Error returned when a concept-id segment is malformed.
- Concept
Options - Options for creating a new concept document.
- Date
- A proleptic-Gregorian calendar date (
YYYY-MM-DD). - Date
Field - A frontmatter date field: the scalar exactly as written, plus its parse.
- Date
Time - An ISO-8601 datetime: a
Date, an optional time of day, and an optional UTC offset. - Date
Time Field - A frontmatter datetime field: the scalar exactly as written, plus its parse.
- Document
- A parsed OKF concept document.
- Executor
- How the computation is run.
- File
FixReport - Remediation report for a single file.
- FixOptions
- Options controlling automated remediation and migration.
- Footnote
Def - A
[^label]: textdefinition line. - Footnote
Ref - A
[^label]reference in the body prose. - Frontmatter
- A concept’s frontmatter: an ordered key/value mapping with typed accessors for the well-known OKF fields.
- Frontmatter
Change - Frontmatter key changes for a concept present in both bundles.
- Generated
- How the current content was produced:
generated: { by, at }. - Inline
Computation - A computation held in the body under
# Computation. - Link
- A markdown link found in a concept body.
- Log
- A parsed
log.md. - LogDay
- All entries recorded under a single date heading.
- LogEntry
- A single log bullet.
- Mapping
- An ordered YAML mapping (preserves insertion / source order, like the
reference implementation which dumps with
sort_keys=False). - Markdown
Heading - A parsed markdown heading.
- Merge
Options - Options for merging one concept into another.
- Merge
Report - Summary report of a merge operation.
- Move
Options - Options for moving or renaming a concept.
- Move
Report - Summary report of a move/rename operation.
- Parameter
- One typed, named hole an agent may fill.
- Parse
Actor Kind Error - Error returned when a string cannot be parsed into an
ActorKind. - Parse
Link Kind Error - Error returned when a string cannot be parsed into a
LinkKind. - Parse
Trust Tier Error - Error returned when a string cannot be parsed into a
TrustTier. - Remediation
- A single remediation action applied to a document or file.
- Remove
Options - Options for removing a concept.
- Remove
Report - Summary report of a removal operation.
- Rename
- A rename detected by matching content hash between a removed and an added concept.
- Rename
Section Options - Options for renaming a section heading within a concept.
- Rename
Section Report - Summary report of a section rename operation.
- Resolved
Link - A cross-link from one concept to another, after resolution.
- Resolved
Source - A
sourcesentry resolved against the bundle. - Source
- One entry in the
sourceslist: a material the concept derives from. - Split
Options - Options for splitting a concept section into a new concept.
- Split
Report - Summary report of a split operation.
- Trust
Change - A trust tier or status change for a concept present in both bundles.
- Usage
Window - The date/time range that frames
usage_count. - Verification
- A single verification event:
{ by, at }.
Enums§
- Actor
Kind - The category an actor string falls into.
- Bundle
Error - Errors raised when loading or operating on a bundle on disk.
- Computation
Source - Where the sanctioned computation lives.
- Document
Error - Errors raised when parsing or validating a single OKF concept document.
- Link
Kind - How a link target is interpreted.
- Link
Rewrite Action - Action to perform on a detected markdown link during rewrite.
- Refactor
Error - Error returned when a refactoring operation fails.
- Remediation
Kind - What kind of remediation or migration was applied.
- Resource
Kind - What kind of thing a
sources[].resourcenames. - Status
- A concept’s lifecycle
status. An absent key meansStatus::Stable. - Trust
Tier - A concept’s trust tier, derived from
verified. - Value
- A parsed YAML value.
Constants§
- ATTESTED_
COMPUTATION_ TYPE - The
typevalue that marks a concept as an Attested Computation. - KNOWN_
FRONTMATTER_ KEYS - Every frontmatter key the specification gives a meaning to, across all families. Anything else is a producer extension.
- LEGACY_
FRONTMATTER_ KEYS - Keys v0.2 retired but consumers may still encounter in v0.1 documents.
timestampis superseded bygenerated.at. - OKF_
VERSION - The OKF specification version this crate implements.
- PREFERRED_
KEY_ ORDER - The key order the reference implementation writes documents in (its
_PREFERRED_KEY_ORDER): identity first, then lifecycle, trust, and provenance. - RECOMMENDED_
FRONTMATTER_ KEYS - Keys a producer should fill in before publishing, in the order
Document::missing_recommendedreports them. - REQUIRED_
FRONTMATTER_ KEYS - The only frontmatter key OKF always requires: a concept carrying
nothing but
typeis fully conformant. - RESERVED_
FILENAMES - Reserved filenames with defined meaning at any level.
- SUPPORTED_
OKF_ VERSIONS - Specification versions this crate can consume.
Functions§
- append_
log_ entry - Appends an entry to
log.mdin the bundle root, creating the file if needed. - bundle_
diff - Computes the OKF-semantics diff between two bundles.
- compute_
relative_ path - Computes the relative markdown link path from
from_concepttoto_concept. - create_
concept - Creates a new concept markdown file with proper frontmatter and heading.
- default_
author - Returns a default author actor string based on system user environment
variables or
"human:author". - extract_
headings - Extracts all markdown headings in document order, ignoring headings inside fenced code blocks.
- field_
path_ candidates - Normalizes a path-valued frontmatter field into the bundle-relative paths it might name, most likely first.
- heading_
slug - Derives a standard Markdown anchor slug from a heading text.
- init_
bundle - Initializes a new OKF bundle at
rootwithindex.md,log.md, and optionally an initial concept. - matches_
heading - Checks whether a heading text matches a search query by title, slug, or normalized spacing.
- merge_
concepts - Merges
sourceconcept intotargetconcept and deletessource. - move_
concept - Moves or renames a concept, rewriting all incoming links and rebasing outgoing links.
- parse_
heading_ line - Parses a single line as an ATX heading (
#through######). - rebase_
relative_ path - Rebases a relative file/resource path from
old_dirtonew_dir. - remediate_
bundle - Remediates an entire bundle directory tree.
- remediate_
document - Remediates and migrates a single
Document. - remediate_
file - Remediates a single file on disk.
- remediate_
log - Remediates a parsed
log.mdfile (consolidating duplicate date headings). - remove_
concept - Safely removes a concept from the bundle.
- rename_
section - Renames a section heading within a concept and updates all internal and external anchor links.
- rewrite_
markdown_ links - Rewrites inline markdown links in a document body using a callback function.
- split_
concept - Splits a section from an existing concept into a new concept.