Skip to content

API Reference parrot.knowledge.okf.frontmatter

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.knowledge.okf.frontmatter

View source

Frontmatter model and deterministic YAML projection for OKF sidecars.

The frontmatter is the deterministic mirror of the authoritative JSON node onto each sidecar .md file. The projection is:

  • Pure function: same JSON node → same YAML bytes every time.
  • Single-writer: only project_frontmatter writes frontmatter; no hand-edits to sidecar frontmatter are valid (they will be overwritten).
  • Byte-deterministic: field order is fixed, values are verbatim from JSON.

Moved from parrot.knowledge.pageindex.okf.frontmatter to the shared parrot.knowledge.okf package (FEAT-239) to allow GraphIndex to reuse the engine without an inverted dependency. The original module is now a thin re-export shim for backwards compatibility.

Design notes (from spec §2.2, D1, D11):

  • summary reuses the FEAT-199 embedding target text — one source, zero divergence.
  • tags are sorted alphabetically for determinism.
  • Optional fields (source, url) are omitted when None.
  • Frontmatter delimiters are ---\n (start) and ---\n (end).

Class ConceptFrontmatter

Pydantic v2 model for the deterministic frontmatter projection.

Field order here determines YAML output order (dict insertion order, Python 3.7+, preserved by model_dump()).

Fields:

Field Type Default Description
type ConceptType Ontological type (controlled vocabulary).
title str Human-readable concept title.
id str Stable concept_id (link target, filename stem).
node_id str Structural position in the tree (volatile, for debugging only).
resource str Canonical URI pageindex://<tree>/<concept_id>.
tags list[str] Alphabetically sorted free-namespace tags.
timestamp str '' ISO-8601 timestamp string from the node.
summary str Embedding target text (reuses FEAT-199 value, D11).
relates_to list[RelatesTo] Typed edge list.
source Optional[SourceProvenance] None Optional per-node provenance.

Function parse_frontmatter

Parse YAML frontmatter from a sidecar string back into a model.

The text must begin with --- and contain a closing ---. CRLF line-endings are normalised to LF before parsing.

parse_frontmatter(text: str) -> ConceptFrontmatter

Parameter Type Default Description
text str Sidecar file content starting with YAML frontmatter.

Returns: ConceptFrontmatter — Parsed ConceptFrontmatter instance.

Raises:

  • ValueError — If the frontmatter block cannot be found or parsed.

Function project_frontmatter

Produce a byte-deterministic YAML frontmatter string from a node dict.

The output starts with ---\n and ends with ---\n. Given the same node dict and tree_name, this function MUST return byte-identical output every time it is called (idempotency / determinism guarantee).

Fields extracted from node:

  • type (or "Section" as fallback)
  • title
  • concept_id
  • node_id
  • summary (or empty string)
  • categories → tags (sorted)
  • timestamp (or empty string)
  • relates_to list
  • source dict (optional)

project_frontmatter(node: dict, tree_name: str) -> str

Parameter Type Default Description
node dict PageIndex node dict (must have concept_id, title, node_id).
tree_name str Name of the PageIndex tree, used to build the resource URI.

Returns: str — YAML frontmatter string delimited by ---\n.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally