# `Spectre.Execution.Closure`
[🔗](https://github.com/elchemista/spectre/blob/0.3.0/lib/spectre/execution/closure.ex#L1)

Portable execution dependencies sealed into a Definition Manifest.

The closure records exact data references and the fingerprints of compiled
implementations observed when a Definition was composed. A fingerprint is
evidence of one build, not a promise that BEAM code can be restored by
digest. `compare_builds/2` makes missing or changed code explicit so a
resolver can block before execution or report drift under a host policy.

# `drift`

```elixir
@type drift() :: %{
  ref: String.t(),
  expected: String.t(),
  observed: String.t() | nil,
  reason: :changed | :missing,
  policy: :block | :report
}
```

# `fingerprint`

```elixir
@type fingerprint() :: %{
  ref: String.t(),
  digest: String.t(),
  drift_policy: :block | :report
}
```

# `t`

```elixir
@type t() :: %Spectre.Execution.Closure{
  build_fingerprints: [fingerprint()],
  compatibility_mode: :native_v2 | :adapted_v1,
  contract_refs: [String.t()],
  evaluation_corpus_digest: String.t() | nil,
  model_profile_refs: [String.t()],
  package_refs: [String.t()],
  projection_generators: [map()],
  prompt_fragment_digests: [String.t()],
  recording_refs: [String.t()],
  schema_version: pos_integer(),
  stack_ref: String.t(),
  state_codec_ref: String.t(),
  state_schema_ref: String.t()
}
```

# `compare_builds`

```elixir
@spec compare_builds(t(), %{optional(String.t()) =&gt; String.t()}) ::
  {:ok, :matched} | {:drift, [drift()]} | {:error, term()}
```

Compares sealed build fingerprints with fingerprints observed by trusted host
code. The observed map is keyed by the closure's logical code Refs.

# `digest`

```elixir
@spec digest(t()) :: String.t()
```

Returns the canonical SHA-256 digest of the closure.

# `fingerprint`

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

Computes the SHA-256 fingerprint of the currently loaded BEAM object code.

This helper is intended for trusted composition and deployment registries;
canonical runtime data is never converted into a module to call it.

# `fingerprint_entry`

```elixir
@spec fingerprint_entry(String.t(), module(), :block | :report) ::
  {:ok, fingerprint()} | {:error, term()}
```

Builds one validated fingerprint entry for a trusted loaded module.

# `from_data`

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

Restores a closure from decoded canonical data.

# `new`

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

Builds a complete, validated execution closure.

# `new!`

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

Builds a closure or raises with its stable validation reason.

# `observe_builds`

```elixir
@spec observe_builds(
  t(),
  keyword()
) :: {:ok, %{optional(String.t()) =&gt; String.t()}} | {:error, term()}
```

Observes every BEAM fingerprint through trusted loaded-code metadata.

# `schema_version`

```elixir
@spec schema_version() :: pos_integer()
```

Returns the Execution Closure schema version.

# `to_data`

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

Returns the portable data sealed into a Definition Manifest.

---

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