Skip to content

API Reference parrot.knowledge.pageindex.okf.projection

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

parrot.knowledge.pageindex.okf.projection

View source

Deterministic sidecar and index.md generation for OKF.

This module is the "single writer" that projects the authoritative JSON tree onto disk. It:

  • Generates frontmatter-enriched sidecars (<flattened_concept_id>.md) for every node in the tree.
  • Writes a root-level index.md listing of the JSON ToC.

Both outputs are pure functions of the JSON — regenerating from the same tree MUST produce byte-identical files. Single-writer; no hand-edits survive.

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

  • Sidecar filenames are <flattened_concept_id>.md. Slashes in concept_id are encoded as -- (double-dash) for filesystem compatibility, because _NODE_ID_RE only allows [A-Za-z0-9_-]{1,64}.
  • Body content is preserved verbatim; only the frontmatter header is prepended/replaced.
  • Legacy <node_id>.md sidecars are retained here and removed later by the content-store sweep after the generation grace period.

Alias NodeContentStore

Re-exported from parrot.knowledge.pageindex.content_store.NodeContentStore.

Class ProjectionReport

Report returned by project_sidecars().

Fields:

Field Type Default Description
tree_name str Name of the tree that was projected.
nodes_projected int 0 Number of nodes written.
files_written list[str] Concept_id-keyed filenames written.
old_files_removed list[str] Reserved compatibility field; projection leaves it empty.

Alias flatten_concept_id_for_filename

Re-exported from parrot.knowledge.okf.utils.flatten_concept_id_for_filename.

Function generate_index_md

Generate a deterministic root-level index.md view of the JSON ToC.

Lists top-level concepts only — children are intentionally omitted to keep the index concise (per OKF spec §6: "root index lists all top-level concepts with links"). Deeply nested sub-concepts are discoverable via their parent's sidecar body or get_related traversal.

No YAML frontmatter in index.md (per OKF §6). Entries are ordered by their position in the structure list (preserving JSON ToC order).

generate_index_md(tree: dict, tree_name: str) -> str

Parameter Type Default Description
tree dict OKF-enriched PageIndex tree dict.
tree_name str PageIndex tree name (used in links).

Returns: str — Deterministic Markdown string for the index.md file.

Alias project_frontmatter

Re-exported from parrot.knowledge.okf.frontmatter.project_frontmatter.

Function project_sidecar

Combine projected frontmatter and existing body into a sidecar string.

project_sidecar(node: dict, tree_name: str, body: str) -> str

Parameter Type Default Description
node dict OKF-enriched PageIndex node dict (must have concept_id).
tree_name str PageIndex tree name (used in resource URI).
body str Existing sidecar body content (preserved verbatim).

Returns: str — Complete sidecar string: frontmatter + blank line + body.

Function project_sidecars

Regenerate all sidecars from the authoritative JSON tree.

For each node in the tree:

  1. Derive the flat concept_id filename.
  2. Load the existing body (body_ref blob, then concept_id, then node_id).
  3. Combine frontmatter + body and write via content_store.save().

Legacy <node_id>.md files are retained for readers of older generations; NodeContentStore.sweep_unreferenced removes them after the grace period.

This function is byte-deterministic: two runs on the same tree JSON produce identical file contents.

project_sidecars(tree: dict, tree_name: str, content_store: NodeContentStore) -> ProjectionReport

Parameter Type Default Description
tree dict OKF-enriched PageIndex tree dict (all nodes must have concept_id).
tree_name str PageIndex tree name.
content_store NodeContentStore NodeContentStore instance for reading/writing sidecars.

Returns: ProjectionReport — ProjectionReport with counts and filenames of written files.

Alias structure_to_list

Re-exported from parrot.knowledge.pageindex.utils.structure_to_list.

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