CommBus.Prompts (CommBus v0.1.0)

Copy Markdown View Source

Prompt catalog with optional overrides and cached runtime loading.

Summary

Functions

Returns the prompt body for the given key, checking the override store first, then falling back to the cached prompt's body.

Returns the configured prompt root directory, falling back to config/comm_bus/prompts relative to the project root.

Fetches a cached prompt by its key (slug, name, or path), raising if not found.

Returns all cached prompts as a list, loading from disk if not yet cached.

Loads all prompt files from the configured root directory, caches them in :persistent_term, and returns the prompt map.

Reloads all prompts from disk, refreshing the :persistent_term cache.

Renders a prompt by key with the given variables, applying any active override before rendering. Raises on failure.

Functions

body!(key, opts \\ [])

@spec body!(
  String.t(),
  keyword()
) :: String.t()

Returns the prompt body for the given key, checking the override store first, then falling back to the cached prompt's body.

Parameters

  • key — The prompt identifier string.
  • opts — Keyword options forwarded to the override store.

Returns

The prompt body as a String.t().

default_root()

@spec default_root() :: String.t()

Returns the configured prompt root directory, falling back to config/comm_bus/prompts relative to the project root.

Returns

A string path to the prompt directory.

get_prompt!(key)

@spec get_prompt!(String.t()) :: CommBus.Template.Prompt.t()

Fetches a cached prompt by its key (slug, name, or path), raising if not found.

Parameters

  • key — The prompt identifier string.

Returns

A %CommBus.Template.Prompt{} struct.

Raises

Raises if no prompt matches the given key.

list_prompts()

@spec list_prompts() :: [CommBus.Template.Prompt.t()]

Returns all cached prompts as a list, loading from disk if not yet cached.

Returns

A list of %CommBus.Template.Prompt{} structs.

load_from_disk!(opts \\ [])

@spec load_from_disk!(keyword()) :: map()

Loads all prompt files from the configured root directory, caches them in :persistent_term, and returns the prompt map.

Parameters

  • opts — Keyword options: :root (directory path), :schema (:devman, :human, :flex).

Returns

A map of prompt keys to %CommBus.Template.Prompt{} structs.

Raises

Raises if any prompt files fail validation.

reload!()

@spec reload!() :: map()

Reloads all prompts from disk, refreshing the :persistent_term cache.

Returns

A map of prompt keys to %CommBus.Template.Prompt{} structs.

render!(key, vars \\ %{}, opts \\ [])

@spec render!(String.t(), map(), keyword()) :: String.t()

Renders a prompt by key with the given variables, applying any active override before rendering. Raises on failure.

Parameters

  • key — The prompt identifier string.
  • vars — A map of template variable bindings.
  • opts — Keyword options forwarded to the template engine.

Returns

The rendered content as a String.t().