# `Jidoka.Snapshot`
[🔗](https://github.com/agentjido/jidoka/blob/v0.9.0/lib/jidoka/snapshot.ex#L1)

Serializable semantic snapshot for hibernate/resume.

Durable snapshot strings are authenticated with an HMAC signing secret from
`:jidoka, :snapshot_signing_secret` or `JIDOKA_SNAPSHOT_SIGNING_SECRET`.

# `t`

```elixir
@type t() :: %Jidoka.Snapshot{
  agent_id: binary(),
  cursor: term(),
  metadata: map(),
  schema_version: integer(),
  snapshot_id: binary(),
  turn_state: term()
}
```

# `deserialize`

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

Restores a snapshot produced by `serialize/1`.

# `fork`

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

Copies a hibernation snapshot for a new session fork.

The copied snapshot keeps the exact turn state and effect journal. It gets a
new snapshot id and records the source in metadata. Only resumable phase
boundaries can be forked.

# `forkable_phases`

```elixir
@spec forkable_phases() :: [atom()]
```

Returns the phase boundaries that support safe session forks.

# `from_input`

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

Normalizes a snapshot struct or authenticated serialized snapshot.

# `from_turn_state`

```elixir
@spec from_turn_state(Jidoka.Turn.State.t(), Jidoka.Turn.Cursor.t(), keyword()) ::
  {:ok, t()} | {:error, term()}
```

Builds a phase-boundary snapshot from the current turn state.

# `from_turn_state!`

```elixir
@spec from_turn_state!(Jidoka.Turn.State.t(), Jidoka.Turn.Cursor.t(), keyword()) ::
  t()
```

Builds a phase-boundary snapshot and raises on invalid data.

# `new`

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

Builds a durable agent snapshot from keyword or map attributes.

# `new!`

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

Builds an agent snapshot and raises if the attributes are invalid.

# `schema`

```elixir
@spec schema() :: Zoi.schema()
```

Returns the Zoi schema for a durable agent snapshot.

# `schema_version`

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

Returns the current snapshot schema version.

# `serialize`

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

Serializes a snapshot into an opaque durable string.

The format is intentionally internal to Jidoka. It preserves Elixir data
fidelity across hibernate/resume while the schema version remains the public
compatibility boundary.

# `serialize!`

```elixir
@spec serialize!(t()) :: String.t()
```

Serializes and signs a snapshot, or raises if serialization fails.

---

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