GenAI.Approval.Expr (GenAI Approval v0.1.0)

Copy Markdown View Source

Pure evaluator for script expressions against a string-keyed environment.

Call expressions are delegated to the call_fn callback (fn endpoint, command, args_map -> {:ok, result} | {:error, reason} end); pass :forbidden where calls are illegal (conditions, outputs) — statically prevented, defensively enforced here too.

Traversal is lenient: dotted access on nil or a non-map yields nil (approval scripts branch on presence, they don't crash on it).

Summary

Functions

Evaluate a [{name, expr}] arg list into a string-keyed map.

Handlebars-style truthiness: only false and nil are falsy.

Types

call_fn()

@type call_fn() ::
  (String.t(), String.t(), map() -> {:ok, term()} | {:error, term()})
  | :forbidden

env()

@type env() :: %{optional(String.t()) => term()}

Functions

eval(arg, env, cb)

@spec eval(term(), env(), call_fn()) :: {:ok, term()} | {:error, term()}

eval_args(args, env, cb)

@spec eval_args([{String.t(), term()}], env(), call_fn()) ::
  {:ok, map()} | {:error, term()}

Evaluate a [{name, expr}] arg list into a string-keyed map.

truthy?(arg1)

Handlebars-style truthiness: only false and nil are falsy.