LlmCore.Config.Editor (llm_core v0.3.0)

Copy Markdown View Source

Helpers for reading and mutating llm_core.toml files.

The editor focuses on the project-level file but accepts custom paths so callers (mix tasks, tests) can operate on ad-hoc configs without touching user data.

Summary

Functions

Returns the default path to the project-level llm_core.toml file.

Removes the value at the given key path from config.

Sets a nested value in config at the given key path.

Reads and decodes the TOML configuration file at path.

Reads the config at path, applies the transformation function fun, and writes the result back.

Encodes map as TOML and writes it to path, creating parent directories as needed.

Functions

default_path()

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

Returns the default path to the project-level llm_core.toml file.

delete_path(config, list)

@spec delete_path(map(), [String.t()]) :: map()

Removes the value at the given key path from config.

put_path(config, list, value)

@spec put_path(map(), [String.t()], term()) :: map()

Sets a nested value in config at the given key path.

Creates intermediate maps as needed.

read(path \\ default_path())

@spec read(String.t() | nil) :: {:ok, map()} | {:error, term()}

Reads and decodes the TOML configuration file at path.

Returns {:ok, map()} with the parsed contents, or {:ok, %{}} if the file does not exist.

update(fun, path \\ default_path())

@spec update((map() -> map()), String.t() | nil) :: {:ok, map()} | {:error, term()}

Reads the config at path, applies the transformation function fun, and writes the result back.

Returns {:ok, new_config} on success.

write(map, path \\ default_path())

@spec write(map(), String.t() | nil) :: :ok | {:error, term()}

Encodes map as TOML and writes it to path, creating parent directories as needed.