# `Spectre.Stack.Contract.V2`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/stack/contract/v2.ex#L1)

Mandatory runtime Stack contract for reflective Definition Manifests.

Contract V2 seals two distinct objects: the effective Authority Envelope and
the Execution Closure. Existing compiled Stack V1 definitions are accepted
only through `from_v1/2`, which reads and conservatively lowers them without
mutating or retaining V1 as the native Manifest contract.

# `t`

```elixir
@type t() :: %Spectre.Stack.Contract.V2{
  authority: Spectre.Authority.Envelope.t(),
  contract_version: 2,
  execution_closure: Spectre.Execution.Closure.t(),
  source_contract: :native_v2 | :adapted_v1
}
```

# `from_compiled`

```elixir
@spec from_compiled(
  Spectre.Definition.t(),
  Spectre.Definition.Canonical.t(),
  keyword()
) ::
  {:ok, t()} | {:error, term()}
```

Builds Contract V2 for a compiled Agent/Skill and its canonical projection.

# `from_v1`

```elixir
@spec from_v1(
  Spectre.Stack.Definition.t() | module() | nil,
  keyword()
) :: {:ok, t()} | {:error, term()}
```

Conservatively adapts an immutable Stack Contract V1 definition.

V1 capability declarations are requests only. Effective grants are their
intersection with the explicit `:authority_ceiling`; omitting the ceiling
produces an empty envelope.

# `from_v1!`

```elixir
@spec from_v1!(
  Spectre.Stack.Definition.t() | module() | nil,
  keyword()
) :: t()
```

Adapts a V1 Stack or raises with its stable validation reason.

# `new`

```elixir
@spec new(Spectre.Authority.Envelope.t(), Spectre.Execution.Closure.t()) ::
  {:ok, t()} | {:error, term()}
```

Builds a native Contract V2 from reviewed authority and closure data.

# `new!`

```elixir
@spec new!(Spectre.Authority.Envelope.t(), Spectre.Execution.Closure.t()) :: t()
```

Builds a native Contract V2 or raises.

# `to_data`

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

Returns portable inspection data for the adapted contract.

# `version`

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

Returns the mandatory reflective Stack contract version.

---

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