JSON save/load helpers for portable program state.
Saved programs are treated as an external trust boundary. Loading validates the artifact shape, allowlists adapters and provider clients, and never restores credentials from disk.
Summary
Functions
Same as dump(program, []).
Returns program as a JSON-safe map that load/2 turns back into it.
Loads a program from the portable map dump/2 returns.
Loads a program from the portable map dump/2 returns, raising
ArgumentError where load/2 returns an error.
Reads a program artifact written by save!/3 and returns the program.
Functions
Same as dump(program, []).
Returns program as a JSON-safe map that load/2 turns back into it.
Credentials are left out. A program that holds callbacks (metrics, tool
runners, policies) is dumped by their names in the :registry, an
Imp.Saving.Registry.
@spec load(map(), keyword()) :: {:ok, struct()} | {:error, Exception.t()}
Loads a program from the portable map dump/2 returns.
Returns {:ok, program}, or {:error, %ArgumentError{}} when state is not
a program Imp can load: a missing or unknown "type", a malformed field, an
adapter or client outside the allowlist, or a callback name the :registry
does not hold. Nothing in state is turned into an atom that does not
already exist, and no credential is read from it.
Options:
:registry- anImp.Saving.Registrynaming the callbacks a saved program refers to (metrics, tool runners, policies).
Loads a program from the portable map dump/2 returns, raising
ArgumentError where load/2 returns an error.
Reads a program artifact written by save!/3 and returns the program.
The artifact's checksum is verified before anything in it is loaded. Raises
File.Error when the file cannot be read and ArgumentError when it is not
a checksummed Imp artifact or its program cannot be loaded. Takes the same
:registry option as load/2.
Writes program to path as a checksummed JSON artifact, readable with
read!/2. The file is written atomically with mode 0600 and carries no
credentials. Takes the same :registry option as dump/2.