# `Spectre.Skill.StateBinding`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/skill/state_binding.ex#L1)

Portable, generation-fenced state owned by one stable Skill and Definition.

A binding identifies one branch. Its schema, generation, parent branch and
owning Definition are immutable; state updates use revision CAS. Activation
may move a retained branch between `:active` and `:dormant`, while retention
transitions are monotonic and a purged binding keeps only its tombstone.

# `retention`

```elixir
@type retention() :: :retained | :gc_eligible | :abandoned | :purged
```

# `status`

```elixir
@type status() :: :active | :dormant
```

# `t`

```elixir
@type t() :: %Spectre.Skill.StateBinding{
  binding_receipt: String.t(),
  branch_id: String.t(),
  created_at: non_neg_integer(),
  fencing_token: pos_integer(),
  owning_definition_ref: Spectre.Definition.Ref.t(),
  parent_branch_id: String.t() | nil,
  provenance: map(),
  retention: retention(),
  revision: non_neg_integer(),
  schema_version: pos_integer(),
  skill_id: String.t(),
  state: term(),
  state_generation: pos_integer(),
  state_schema_ref: String.t(),
  status: status(),
  updated_at: non_neg_integer()
}
```

# `activation_pointer`

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

Returns the immutable pointer stored in an Activation snapshot.

# `activation_pointer?`

```elixir
@spec activation_pointer?(term()) :: boolean()
```

Returns true for an Activation Skill-state pointer.

# `decode`

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

Decodes and verifies portable binding bytes.

# `encode`

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

Encodes a binding into portable canonical bytes.

# `from_data`

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

Restores portable binding data without creating atoms.

# `new`

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

Builds and verifies one Skill-state branch binding.

# `new!`

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

Builds a binding or raises with its stable validation reason.

# `schema_version`

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

Returns the Skill-state binding schema version.

# `to_data`

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

Returns portable canonical data.

# `transition_retention`

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

Applies a monotonic retention transition and preserves a purged tombstone.

# `transition_status`

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

Moves a retained branch between active and dormant with revision CAS.

# `update`

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

Updates the active branch state through generation and revision CAS.

---

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