> ## Documentation Index
> Fetch the complete documentation index at: https://ladygraph.io.vn/llms.txt
> Use this file to discover all available pages before exploring further.

# authoring

> Tools that write config files for a deployment.

Authoring tools: they WRITE the config files a deployment injects; the runtime never imports them.

## `authoring.build`

Build a proposed glossary: texts -> candidate terms -> agent -> repaired, validated, confidence-capped proposals -> glossary.proposed.yaml.

#### `BuildReport`

| Field | Type | Default |
| - | - | - |
| `candidates` | `int` | required |
| `proposed` | `int` | required |
| `unresolved` | `int` | required |
| `quoted_values` | `int` | required |
| `dropped_not_asked` | `int` | required |
| `capped_high` | `int` | required |
| `searches` | `int` | required |
| `turns` | `int \| None` | required |
| `seconds` | `float` | required |
| `timed_out` | `bool` | required |
| `output` | `pathlib.Path` | required |

#### `build_glossary`

```python theme={null}
build_glossary(cfg: GlossaryBuilderConfig, texts: Iterable[str], *, workdir: pathlib.Path, out: pathlib.Path, domain: str = 'documents', known: Iterable[str] = (), runner=None) -> BuildReport
```

## `authoring.candidates`

Candidate terms: what the builder is asked to decide. Found by patterns over the passage texts, counted, and capped.

#### `Candidate`

| Field | Type | Default |
| - | - | - |
| `term` | `str` | required |
| `count` | `int` | required |
| `context` | `str` | required |

#### `find_candidates`

```python theme={null}
find_candidates(texts: Iterable[str], cfg: Candidates, known: Iterable[str] = ()) -> list[Candidate]
```

## `authoring.cli`

python -m ladygraph.authoring \<build | doctor | approve> ... (see docs/glossary\_builder.example.yaml)

#### `main`

```python theme={null}
main(argv: list[str] | None = None) -> int
```

## `authoring.config`

The `glossary_builder:` section of ladygraph.yaml: how the term-list builder runs (docs/glossary\_builder.example.yaml).

#### `Candidates`

| Field | Type | Default |
| - | - | - |
| `patterns` | `list[str]` | factory |
| `ignore` | `list[str]` | `[]` |
| `min_count` | `int` | `2` |
| `max_terms` | `int` | `90` |

#### `Gateway`

The model endpoint the agent talks to: an Anthropic-compatible gateway you run yourself (LiteLLM is one).

| Field | Type | Default |
| - | - | - |
| `base_url` | `str` | `'http://127.0.0.1:4000'` |
| `api_key_env` | `str \| None` | `None` |

#### `GlossaryBuilderConfig`

| Field | Type | Default |
| - | - | - |
| `runner` | `Literal['claude_code']` | `'claude_code'` |
| `engine` | `str` | required |
| `gateway` | `Gateway` | factory |
| `source_language` | `str` | `"the documents' language"` |
| `target_language` | `str` | `'English'` |
| `search` | `Search` | factory |
| `candidates` | `Candidates` | factory |
| `limits` | `Limits` | factory |
| `output` | `str` | `'glossary.proposed.yaml'` |

#### `Limits`

| Field | Type | Default |
| - | - | - |
| `max_turns` | `int` | `160` |
| `timeout_s` | `int` | `3600` |
| `max_document_chars` | `int` | `120000` |

#### `Search`

Web search for PUBLIC terms.

| Field | Type | Default |
| - | - | - |
| `provider` | `Literal['none', 'tavily']` | `'none'` |
| `api_key_env` | `str` | `'TAVILY_SEARCH_API'` |
| `max_words` | `int` | `4` |
| `max_chars` | `int` | `40` |

#### `load_builder_config`

```python theme={null}
load_builder_config(path: pathlib.Path | str) -> GlossaryBuilderConfig
```

## `authoring.proposals`

What the agent wrote, made safe: repaired YAML, validated entries, confidence capped by evidence, glossary-format output.

#### `Proposal`

| Field | Type | Default |
| - | - | - |
| `en` | `str \| None` | `None` |
| `keep_original` | `bool` | `False` |
| `kind` | `Literal['public', 'internal']` | `'internal'` |
| `source` | `str` | `''` |
| `confidence` | `Literal['high', 'medium', 'low']` | `'low'` |

#### `cap_confidence`

```python theme={null}
cap_confidence(props: dict[str, Proposal], queries: list[str], texts: list[str]) -> int
```

`high` stays only with a logged search that names the term or an expansion in the documents; else it becomes `medium`.

#### `explicit_expansion`

```python theme={null}
explicit_expansion(term: str, texts: Iterable[str]) -> bool
```

True when some text spells the term out: the words just before "(TERM)" start with its letters.

#### `parse_proposals`

```python theme={null}
parse_proposals(text: str, candidates: Iterable[str]) -> tuple[dict[str, Proposal], dict[str, int]]
```

\{term: Proposal} for the terms that were asked about, plus counts of what was repaired or dropped.

#### `repair_yaml`

```python theme={null}
repair_yaml(text: str) -> tuple[str, int]
```

Quote every field value that is not already a plain scalar (harmless).

#### `searched_terms`

```python theme={null}
searched_terms(log: pathlib.Path) -> list[str]
```

The queries the guarded search tool ran (one JSON line each).

#### `to_glossary_yaml`

```python theme={null}
to_glossary_yaml(props: dict[str, Proposal], header: str) -> tuple[str, list[str]]
```

Text in the llm/glossary.yaml format (every entry `status: proposed`), and the terms left unresolved (no English).

## `authoring.runner`

The agent runner: Claude Code (headless, `--bare`) whose ENGINE is a model served by a gateway (LiteLLM or any Anthropic-compatible endpoint). The harness is the sandbox: `--bare` skips user settings and hooks, `--tools Read,Edit` leaves it no shell, no write-anywhere and no web, and the only extra tool is the guarded `search_term` (authoring/search\_guard.py). It reads a work folder and appends en

#### `ClaudeCodeRunner`

Construct with `ClaudeCodeRunner(cfg: GlossaryBuilderConfig, domain: str = 'documents', on_event: Optional[Callable[[dict], NoneType]] = None)`.

| Method | What it does |
| - | - |
| `prompt(self) -> str` | — |
| `command(self, workdir: pathlib.Path) -> tuple[list[str], dict[str, str]]` | The command line and the environment. |
| `run(self, workdir: pathlib.Path) -> RunResult` | Start the agent and read its `stream-json` output as it arrives: each line goes to harness.jsonl and, parsed, to `on_event` (a live view, see authoring/trace.py). |

#### `RunnerError`

#### `RunResult`

| Field | Type | Default |
| - | - | - |
| `returncode` | `int` | required |
| `turns` | `int \| None` | required |
| `seconds` | `float` | required |
| `timed_out` | `bool` | required |
| `log` | `pathlib.Path` | required |

#### `gateway_key`

```python theme={null}
gateway_key(cfg: GlossaryBuilderConfig) -> str
```

The key sent to the gateway: the environment variable the config names, else the local default (a localhost gateway).

## `authoring.search_guard`

A minimal MCP server (stdlib JSON-RPC over stdio) with ONE tool, `search_term`. The privacy rule is enforced here, in code: the query must be a term (few words, one line), so no sentence of the documents can leave. Every query is logged. Usage (written into the harness's mcp config by the runner): python -m ladygraph.authoring.search\_guard --env TAVILY\_SEARCH\_API --log queries.jsonl The key is rea

#### `refusal`

```python theme={null}
refusal(term: str, max_words: int, max_chars: int) -> str | None
```

#### `search`

```python theme={null}
search(term: str, key: str, log: pathlib.Path | None, max_words: int = 4, max_chars: int = 40) -> str
```

#### `serve`

```python theme={null}
serve(env: str, log: pathlib.Path | None, max_words: int, max_chars: int) -> None
```

## `authoring.trace`

Live view of what the agent does while `build` runs: its tool calls, its words and (with `--trace`) its thinking and tool results.

#### `Tracer`

`on_event` for ClaudeCodeRunner.

Construct with `Tracer(level: str = 'actions', stream: typing.TextIO \| None = None, workdir: pathlib.Path \| None = None)`.

| Method | What it does |
| - | - |
| `note(self, message: str) -> None` | A line of our own (not from the agent), such as which gateway is being used. |

#### `lines_for`

```python theme={null}
lines_for(event: dict, level: str = 'actions', width: int = 110, workdir: pathlib.Path | None = None) -> list[str]
```

The lines to show for one stream-json event (pure: no printing, no clock).

#### `parse_line`

```python theme={null}
parse_line(line: str) -> dict | None
```

One line of the harness log as an event, or None for a line that is not JSON.

#### `work_folder_intro`

```python theme={null}
work_folder_intro(workdir: pathlib.Path) -> list[str]
```

What the lines below refer to: the agent runs INSIDE this folder, and these are the files it reads and writes.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.