Compile one Markdown article into one isolated, self-contained OKF Bundle (.okf.zip).
OKF Compiler follows a subtraction-first rule: every document starts fresh. A compile reads only the current Markdown file and its relative assets. It never reads or mutates a long-lived knowledge base, performs no global concept merge, and materializes no global backlinks.
article.okf.zip
├── okf.yaml
├── manifest.json
├── index.md
├── log.md
├── source_map.json
├── sources/
│ ├── original.md
│ └── article.md
├── sections/
├── assets/
│ ├── images/
│ └── media/
├── extracts/
│ ├── summary.md
│ ├── concepts/
│ ├── entities/
│ └── claims/
└── relations/
└── proposed_edges.jsonl
sources/original.mdpreserves the input verbatim.sources/article.mdis the portable source with local asset links rewritten into the bundle.- Referenced Markdown images and local HTML
img,video,audio, andsourceassets are copied. sections/*.mdare split conservatively from real ATX headings.- LLM output is document-local and evidence-anchored. It is proposed knowledge, not a global wiki mutation.
Basic compiler, without LLM extraction:
uv tool install git+https://github.com/FFFFFFpy/okf-compiler.gitWith optional LiteLLM extraction:
uv tool install "okf-compiler[llm] @ git+https://github.com/FFFFFFpy/okf-compiler.git"For development:
git clone https://github.com/FFFFFFpy/okf-compiler.git
cd okf-compiler
uv sync --extra dev --extra llmCopy-Item .env.example .envOKF_LLM_BASE_URL=https://api.example.com/v1
OKF_LLM_MODEL=your-model
OKF_LLM_API_KEY=your-key
OKF_LLM_TIMEOUT=120Configuration priority is:
CLI flags > process environment > .env > defaults
Dotenv discovery order is --env-file, OKF_ENV_FILE, .env in the current working directory, then .env beside the input.
uv run okf compile article.mdWithout LLM:
uv run okf compile article.md --no-llmBy default the output is article.okf.zip beside the source file.
Normal bundle logs stay compact. For structured sidecar diagnostics:
uv run okf compile article.md `
--debug-dir ".\okf-debug"The run directory contains:
okf-debug/<run>/
├── run.json
├── compiler.jsonl
├── traceback.log # only when an exception occurs
└── validation/
├── concepts.jsonl
├── entities.jsonl
└── relations.jsonl
To additionally save full LLM prompts, raw responses, and parsed JSON:
uv run okf compile article.md `
--debug-dir ".\okf-debug" `
--debug-llm-payloadsFull payload logs may contain the complete source article. API keys are not intentionally written, but debug directories should still be treated as private data.
Use strict mode when degraded extraction must fail CI or a batch job:
uv run okf compile article.md --strictThe bundle is still written for inspection, but the command returns a non-zero exit code when an extraction stage rejected output.
New LLM extraction uses quote-based evidence:
{
"section_id": "s0002",
"quote": "verbatim contiguous text copied from the document"
}The compiler locates the quote inside the selected section and calculates absolute line_start and line_end. This avoids asking an LLM to count Markdown lines. Legacy line-based evidence remains accepted for compatibility.
uv run okf compile-dir `
"D:\MyProjects\wxarticle2md\output" `
--out "D:\MyProjects\okf-bundles" `
--mode wechat `
--max-workers 3 `
--debug-dir "D:\MyProjects\okf-debug"Input selection priority in wechat mode:
- Main Markdown declared by
manifest.json. - Markdown whose stem matches the article directory.
document.md.- The only Markdown file in the directory.
- Otherwise the directory is reported as ambiguous and skipped.
- H1 is treated as the document title.
- The first ATX level from H2 to H6 with at least two headings becomes the section boundary.
- Lower headings and conservative pseudo-heading matches become section anchors, not extra top-level sections.
- If no suitable heading level exists, the document becomes one whole-document section.
from pathlib import Path
from okf_compiler import CompileOptions, compile_one
result = compile_one(
Path("article.md"),
Path("article.okf.zip"),
CompileOptions(no_llm=True),
)
if not result.successful:
raise RuntimeError(result.error)OKF Compiler is a producer, not a knowledge-base runtime. Consumers such as OpenViking, WeKnora, or OpenKB may index sections and extracts, resolve local concepts against global candidates, and accept or reject proposed edges. The compiler itself performs no global mutation.
Apache License 2.0. See NOTICE for extraction provenance and changes.