PtcRunner.SubAgent.TypeExtractor (PtcRunner v0.7.0)

Copy Markdown View Source

Extract signature and description from Elixir function @spec and @doc.

Converts Elixir type specifications to PTC signature format for automatic tool definition. Extraction requires compiled documentation and only works for named functions (not anonymous).

Limitations

  • Requires docs to be compiled (not available in releases without --docs)
  • Only works for named functions (not anonymous)
  • @spec conversion is best-effort; explicit signatures are more precise
  • Unsupported types fall back to :any with warning

Examples

# Anonymous function - cannot extract
iex> PtcRunner.SubAgent.TypeExtractor.extract(fn x -> x end)
{:ok, {nil, nil}}

Summary

Functions

Extract signature and description from a function reference.

Functions

extract(fun)

@spec extract(function()) :: {:ok, {String.t() | nil, String.t() | nil}}

Extract signature and description from a function reference.

Returns {:ok, {signature, description}} where both may be nil if extraction is not possible. Never returns an error - falls back to {nil, nil} when extraction fails.

Examples

iex> {:ok, {signature, _description}} = PtcRunner.SubAgent.TypeExtractor.extract(&String.upcase/1)
iex> is_binary(signature) or is_nil(signature)
true