# `Planck.Agent.TurnState`
[🔗](https://github.com/alexdesousa/planck/blob/v0.2.2/lib/planck/agent/turn_state.ex#L1)

Tracks the agent's turn counter and checkpoint stack.

`:index` increments on every new LLM turn. `:checkpoints` is a
reversed list of message-list lengths recorded at the start of each
user prompt — used to detect messages appended mid-turn and to rebuild
state after a session reload.

# `t`

```elixir
@type t() :: %Planck.Agent.TurnState{
  checkpoints: [non_neg_integer()],
  index: non_neg_integer()
}
```

- `:index` — monotonically increasing turn counter
- `:checkpoints` — reversed stack of message-count checkpoints, one per user prompt

# `advance`

```elixir
@spec advance(t()) :: t()
```

Increment the turn counter.

# `new`

```elixir
@spec new() :: t()
```

Return a fresh turn state.

# `push_checkpoint`

```elixir
@spec push_checkpoint(t(), non_neg_integer()) :: t()
```

Push a checkpoint (current message-list length) onto the stack.

# `rebuild_checkpoints`

```elixir
@spec rebuild_checkpoints(t(), [term()]) :: t()
```

Rebuild checkpoints from a message list, preserving the current index.

---

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