Generating llms.txt

Generate llms.txt, companion llms-*.txt files, and docs_tree metadata from pkg/skill.py and project docs.

Run octavo-llms from the command line or call refresh_llms / update_llms_txt from Python to build llms.txt without importing the target package. Doc links default to Octavo's .md URLs (url_fn overrides this for legacy Quarto sites).

octavo-llms
octavo-llms --base-url https://example.com/docs/

Resolving project doc trees

Extract (title, description, order, has_body) from .ipynb, .qmd, .md, and .py files and resolve [tool.docs] + docs_dir into a structured docs tree.

doc_meta

def doc_meta(
    path:str | pathlib._local.Path, # Path to `.ipynb`, `.qmd`, `.md`, or `.py`
)->tuple[str, str, float, bool]: # `(title, desc, order, has_body)`

Extract (title, desc, order, has_body) from frontmatter, notebook headers, or Python docstrings.

docs_tree

def docs_tree(
    root:str | pathlib._local.Path, # Project root containing `pyproject.toml`
    docs_dir:str | pathlib._local.Path=None, # Docs/notebooks directory
    *, mod_urls:dict=None, # Optional `{module: rel_url}` map
    url_fn:<built-in function callable>=None, # Maps doc-relative `Path` to published URL (defaults to Octavo `.md` paths)
)->dict:

Resolve project docs into {section: items | {desc?, items?, Sub: ...}}.

Building and updating llms.txt

Parse skill.py via AST, render llms.txt and llms-*.txt companion files, and write them only when absent or generated.

parse_skill

def parse_skill(
    path:str | pathlib._local.Path, # Path to a `skill.py` file
)->fastcore.basics.AttrDict: # `AttrDict(summary, body, docs, base_url)`

Parse skill.py's docstring and literal __docs__ / __base_url__ via AST without importing it.

pkg_llms

def pkg_llms(
    path:str | pathlib._local.Path, # Package directory containing `skill.py`
    base_url:str='', # Published docs base URL (normalized to end with `/`)
    mod_urls:dict=None, # Optional `{module_name: rel_url}` for modules with web doc pages
    docs:dict=None, # Fallback docs dict (e.g. from `docs_tree`) used when `skill.py` omits `__docs__`
    summary:str='', # Fallback summary when `skill.py` is absent
    body:str='', # Fallback body (e.g. exported index markdown) when `skill.py` is absent
    marker:str=None, # Generator marker override when `skill.py` is absent
)->tuple[str, dict[str, str]]: # `(llms_txt, {companion_filename: content})`

Build llms.txt and pure-docstring companion files from path/skill.py (or summary/body fallback) without importing it.

update_llms_txt

def update_llms_txt(
    path:str | pathlib._local.Path, # Package directory containing `skill.py`
    fn:str | pathlib._local.Path=None, # Output `llms.txt` path (defaults to `<path>/../llms.txt`)
    base_url:str='', # Published docs base URL
    mod_urls:dict=None, # Optional `{module_name: rel_url}` map
    docs:dict=None, # Fallback docs dict (also synced to `pkg/_modidx.py` when `skill.py` exists)
    *, summary:str='', # Fallback summary when `skill.py` is absent
    body:str='', # Fallback body (e.g. exported index markdown) when `skill.py` is absent
    marker:str=None, # Generator marker override when `skill.py` is absent
)->list[pathlib._local.Path]: # Paths written or removed (empty when unchanged)

Write llms.txt and companion files when absent or generated; remove stale generated files.

refresh_llms

def refresh_llms(
    root:str | pathlib._local.Path, # Project root directory containing `pyproject.toml`
    data:dict=None, # Parsed `pyproject.toml` mapping (read from `root` when omitted)
    base_url:str=None, # Override published docs base URL (defaults to `docs_base_url` when a docs workflow exists)
    docs_dir:str | pathlib._local.Path=None, # Optional docs directory (defaults to `<root>/docs`)
)->list[pathlib._local.Path]: # Paths written or removed (empty when unchanged or skipped)

Generate or refresh repo-root llms.txt, llms-*.txt companions, and pkg/_modidx.py for non-nbdev projects.

llms_cli

def llms_cli(
    path:str=None, # Project directory or package directory containing `skill.py`
    out:str=None, # Output `llms.txt` path (used when `path` is a package directory)
    base_url:str=None, # Fallback base URL when `skill.py` omits `__base_url__`
)->None:

Generate or refresh llms.txt and companion files for a project or package directory.