Spectre.Execution.Closure (Spectre v0.3.0)

Copy Markdown View Source

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.

Summary

Functions

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

Returns the canonical SHA-256 digest of the closure.

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

Builds one validated fingerprint entry for a trusted loaded module.

Restores a closure from decoded canonical data.

Builds a complete, validated execution closure.

Builds a closure or raises with its stable validation reason.

Observes every BEAM fingerprint through trusted loaded-code metadata.

Returns the Execution Closure schema version.

Returns the portable data sealed into a Definition Manifest.

Types

drift()

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

fingerprint()

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

t()

@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()
}

Functions

compare_builds(closure, observed)

@spec compare_builds(t(), %{optional(String.t()) => 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(closure)

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

Returns the canonical SHA-256 digest of the closure.

fingerprint(module)

@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(ref, module, policy \\ :block)

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

Builds one validated fingerprint entry for a trusted loaded module.

from_data(closure)

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

Restores a closure from decoded canonical data.

new(closure)

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

Builds a complete, validated execution closure.

new!(attrs)

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

Builds a closure or raises with its stable validation reason.

observe_builds(closure, opts \\ [])

@spec observe_builds(
  t(),
  keyword()
) :: {:ok, %{optional(String.t()) => String.t()}} | {:error, term()}

Observes every BEAM fingerprint through trusted loaded-code metadata.

schema_version()

@spec schema_version() :: pos_integer()

Returns the Execution Closure schema version.

to_data(closure)

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

Returns the portable data sealed into a Definition Manifest.