PtcRunner.SubAgent.KeyNormalizer (PtcRunner v0.9.0)

Copy Markdown View Source

Normalizes map keys from hyphens to underscores at the tool boundary.

PTC-Lisp uses Clojure conventions where LLMs naturally write hyphenated keywords (e.g., :was-improved). Elixir/JSON conventions use underscores. This module provides key normalization at the boundary between the two.

Summary

Functions

Normalize a single key from hyphen to underscore format.

Recursively normalize map keys from hyphens to underscores.

Functions

normalize_key(k)

@spec normalize_key(atom() | binary() | term()) :: binary() | term()

Normalize a single key from hyphen to underscore format.

Examples

iex> PtcRunner.SubAgent.KeyNormalizer.normalize_key(:"was-improved")
"was_improved"

iex> PtcRunner.SubAgent.KeyNormalizer.normalize_key("foo-bar")
"foo_bar"

iex> PtcRunner.SubAgent.KeyNormalizer.normalize_key(:no_hyphens)
"no_hyphens"

normalize_keys(value)

@spec normalize_keys(term()) :: term()

Recursively normalize map keys from hyphens to underscores.

Converts Clojure-style :was-improved to Elixir-style "was_improved". Works recursively on nested maps and lists.

Examples

iex> PtcRunner.SubAgent.KeyNormalizer.normalize_keys(%{"was-improved" => true})
%{"was_improved" => true}

iex> PtcRunner.SubAgent.KeyNormalizer.normalize_keys(%{nested: %{"foo-bar" => 1}})
%{"nested" => %{"foo_bar" => 1}}

iex> PtcRunner.SubAgent.KeyNormalizer.normalize_keys([%{"list-item" => 1}])
[%{"list_item" => 1}]