# `Spectre.Execution.Program`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/execution/program.ex#L1)

Immutable, data-only program for a precise Work.

A program is a finite graph of registered operation steps, pure decisions,
bounded repeats, inference steps and terminal nodes. The graph contains no
callback or module selected by authored data. It materializes an ordinary
`Spectre.Operation.Definition`, so execution, fencing, retry, recovery and
control-plane semantics remain those of the existing operational runtime.

# `program_node`

```elixir
@type program_node() :: map()
```

# `t`

```elixir
@type t() :: %Spectre.Execution.Program{
  budget: map(),
  digest: String.t(),
  entry: String.t(),
  id: String.t(),
  initial: Spectre.Execution.Expression.t(),
  input: atom(),
  metadata: map(),
  migrations: [map()],
  mutable_paths: [[String.t() | non_neg_integer()]],
  nodes: %{required(String.t()) =&gt; program_node()},
  operation_refs: [String.t()],
  prompt_refs: [String.t()],
  schema_version: pos_integer(),
  security: map(),
  state: atom(),
  update: atom(),
  version: pos_integer() | String.t()
}
```

# `fetch_node`

```elixir
@spec fetch_node(t(), term()) :: {:ok, program_node()} | {:error, term()}
```

Fetches one exact node by its stable id.

# `from_compiled`

```elixir
@spec from_compiled(module()) :: {:ok, t()} | {:error, term()}
```

Loads a compiled declarative Work module into the same program IR.

# `from_data`

```elixir
@spec from_data(map()) :: {:ok, t()} | {:error, term()}
```

Restores a program from canonical data and verifies its digest.

# `new`

```elixir
@spec new(t() | map() | keyword()) :: {:ok, t()} | {:error, term()}
```

Builds and fully validates a data-driven Work program.

# `new!`

```elixir
@spec new!(t() | map() | keyword()) :: t()
```

Builds a program or raises with its stable validation reason.

# `operation_definition`

```elixir
@spec operation_definition(t()) :: Spectre.Operation.Definition.t()
```

Builds the code-owned operational contract consumed by the shared runtime.

# `operation_refs`

```elixir
@spec operation_refs(t()) :: [String.t()]
```

Returns the registered operation IDs required by the program.

# `profile_refs`

```elixir
@spec profile_refs(t()) :: [String.t()]
```

Returns exact model-profile IDs pinned by inference nodes.

# `prompt_refs`

```elixir
@spec prompt_refs(t()) :: [String.t()]
```

Returns prompt fragment IDs required by inference nodes.

# `to_data`

```elixir
@spec to_data(t()) :: map()
```

Returns the complete portable program representation.

# `validate_bindings`

```elixir
@spec validate_bindings(t(), module()) :: :ok | {:error, term()}
```

Validates registered operation kinds and purity constraints for one Agent.

# `validate_state`

```elixir
@spec validate_state(t(), term()) :: :ok | {:error, term()}
```

Validates a user state value against the program's declared schema.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
