# `PtcRunner.Lisp.Prelude.PromptInventory`
[🔗](https://github.com/andreasronge/ptc_runner/blob/main/lib/ptc_runner/lisp/prelude/prompt_inventory.ex#L1)

Deterministic, bounded prompt-inventory renderer for a compiled prelude
(Capability Prelude V1, plan §9).

The renderer is fed by the SAME `%PtcRunner.Lisp.Prelude.Export{}` records the
analyzer, evaluator, and discovery forms consult — there is no separate
prompt/discovery registry. It produces a compact, domain-blind-at-the-core
block that a deployment-specific prelude fills with its own namespace and
export names. The block is inserted into the SubAgent system prompt through
dynamic context assembly, NOT by editing static core prompt templates.

## What it renders

  * a per-namespace summary (namespace name + docstring) for namespaces that
    have at least one `:prompt`-visible export;
  * for each such namespace, up to `per_namespace_cap/0` prompt-visible
    exports, each with its signature, short doc, and — only for an inferred
    `:read`/`:write` backing — an effect hint (`:unknown` is omitted as noise,
    but stays available via `(meta ...)` / `(ns-publics ...)`);
  * a "more via `(ns-publics 'ns)`" line when a namespace has more
    prompt-visible exports than the cap;
  * a discovery hint noting that additional `:discoverable` exports (omitted
    from the inventory by design) can be found through `doc`/`dir`/`apropos`/
    `ns-publics`, and that `source` renders an export's defining form;
  * a compact existing-ledger summary (`Tool calls made` / `Tool call
    errors`) when ledger data is supplied.

## Determinism + bounds

Output is fully determined by the export records and the supplied ledger
counts: namespaces and exports are sorted, and per-namespace export rendering
is capped at `per_namespace_cap/0`. `render/2` returns `nil` when there is no
prelude or no `:prompt`-visible export, so callers can filter the section out
of prompt assembly.

# `ledger`

```elixir
@type ledger() ::
  %{tool_calls: non_neg_integer(), tool_errors: non_neg_integer()} | [map()]
```

Ledger summary input. Either a precomputed `%{tool_calls: n, tool_errors: m}`
map or the raw `tool_calls` list (records carrying an `:error` field that is
`nil` on success), from which counts are derived.

# `per_namespace_cap`

```elixir
@spec per_namespace_cap() :: pos_integer()
```

The per-namespace cap on rendered prompt-visible exports.

# `render`

```elixir
@spec render(
  PtcRunner.Lisp.Prelude.t() | nil,
  keyword()
) :: String.t() | nil
```

Renders the prompt inventory for `prelude`.

## Options

  * `:ledger` — a `%{tool_calls: n, tool_errors: m}` map or a raw `tool_calls`
    list; when present, a compact ledger summary is appended.

Returns the rendered block string, or `nil` when there is no prelude or no
`:prompt`-visible export to show.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
