Skip to content

API Reference parrot.knowledge.wiki.bookkeeper

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

parrot.knowledge.wiki.bookkeeper

View source

Wiki bookkeeper — index.md and log.md lifecycle management (FEAT-260).

Implements the bookkeeping layer of the LLM Wiki:

  • index.md — extends OKF's generate_index_md() output with a wiki-specific header that includes source counts, category breakdown, and a last-updated timestamp.
  • log.md — append-only operation chronicle. Every entry is prefixed with a parseable ISO-8601 UTC timestamp and an operation tag so that tools can grep the log without parsing free-form text.

Log entry format::

[2026-06-26T15:42:00Z] [INGEST] source: article.md, pages: 3
[2026-06-26T15:43:12Z] [QUERY] question: "what is a neural network"
[2026-06-26T15:50:00Z] [LINT] issues: 0

The bookkeeper does not hold any persistent state — all state lives on disk in the wiki directory passed to each method call. This keeps the class stateless and safe to construct cheaply.

Class WikiBookkeeper

Manages index.md and log.md bookkeeping files for a wiki.

This class is intentionally stateless — wiki directory paths are passed to each method so the same instance can service multiple wikis.

Example::

bk = WikiBookkeeper()
bk.log_operation(wiki_dir, "INGEST", "source: article.md, pages: 3")
print(bk.read_log(wiki_dir, last_n=10))

Attributes:

Attribute Type Description
INDEX_FILENAME str
LOG_FILENAME str
logger logging.Logger

Method WikiBookkeeper.generate_index

Generate index.md content, extending OKF's output with wiki metadata.

Calls generate_index_md(tree, tree_name) from the OKF projection module and prepends a wiki-specific summary block containing:

  • last-updated timestamp
  • number of tracked sources
  • category breakdown

Falls back to a minimal header when the tree is empty or generate_index_md raises.

generate_index(tree: dict, tree_name: str, sources: Optional[list] = None, categories: Optional[list] = None) -> str

Parameter Type Default Description
tree dict OKF-enriched PageIndex tree dictionary.
tree_name str PageIndex tree name used in OKF index links.
sources Optional[list] None Optional list of source entries (for the count).
categories Optional[list] None Optional list of category strings (for breakdown).

Returns: str — A Markdown string suitable for writing to index.md.

Method WikiBookkeeper.write_index

Write (or overwrite) index.md in the wiki directory.

write_index(wiki_dir: Path, tree: Optional[dict] = None, tree_name: str = 'wiki', sources: Optional[list] = None, categories: Optional[list] = None) -> None

Parameter Type Default Description
wiki_dir Path Root directory of the wiki instance.
tree Optional[dict] None OKF tree dict; may be None for an empty wiki.
tree_name str 'wiki' Tree name for OKF index links.
sources Optional[list] None Source entries for count reporting.
categories Optional[list] None Category strings for the breakdown section.

Method WikiBookkeeper.rebuild_index

Regenerate index.md from current state and return the content.

This is equivalent to write_index but also returns the content string so callers can inspect or log it.

rebuild_index(wiki_dir: Path, tree: Optional[dict] = None, tree_name: str = 'wiki', sources: Optional[list] = None) -> str

Parameter Type Default Description
wiki_dir Path Root directory of the wiki instance.
tree Optional[dict] None OKF tree dict; may be None for an empty wiki.
tree_name str 'wiki' Tree name for OKF index links.
sources Optional[list] None Source entries for count reporting.

Returns: str — The generated index.md content string.

Method WikiBookkeeper.log_operation

Append a single operation entry to log.md.

The entry format is::

[<ISO-8601-UTC>] [<OPERATION>] <details>

The log file is always opened in append mode and never truncated.

log_operation(wiki_dir: Path, operation: str, details: str, timestamp: Optional[str] = None) -> None

Parameter Type Default Description
wiki_dir Path Root directory of the wiki instance.
operation str Short uppercase operation tag (e.g. "INGEST", "QUERY", "LINT").
details str Human-readable details for this operation.
timestamp Optional[str] None Optional pre-formatted ISO-8601 UTC timestamp. If None, the current UTC time is used.

Method WikiBookkeeper.read_log

Return the last last_n lines from log.md.

read_log(wiki_dir: Path, last_n: int = 50) -> str

Parameter Type Default Description
wiki_dir Path Root directory of the wiki instance.
last_n int 50 Maximum number of trailing lines to return. Pass 0 or a negative value to return all lines.

Returns: str — A string containing up to last_n log lines. Returns an empty string when the log file does not yet exist.

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