# `Imp.Optimizer.Playbook`
[🔗](https://github.com/deepfates/imp/blob/v0.18.1/lib/imp/optimizer/playbook.ex#L1)

Bounded optimization for persistent `Imp.Playbook` parameters.

The proposer receives training trajectories only. Challenger promotion requires
improvement on source- and group-disjoint promotion and audit splits, bounded
retained growth, and a content/provenance leakage audit. Every callback runs
under a declared reservation and returns authoritative usage accounting.

This is an Elixir-native adaptation of the incremental context-learning loop
explored by Dynamic Cheatsheet and ACE. It uses Imp's normal program
parameter and trajectory contracts; it is not a second agent-memory runtime.

`compile/6` never mutates a serving process. It returns a `Result` containing
the baseline, challenger, decision, audit scores, usage, and exact rollback
state. Application code must review that result and explicitly install
`result.program` (or persist and restore its completed checkpoint).

# `row`

```elixir
@type row() :: %{required(String.t()) =&gt; term()}
```

# `t`

```elixir
@type t() :: %Imp.Optimizer.Playbook{
  authority_source_ids: term(),
  budget: term(),
  checkpoint_fn: term(),
  evaluator: term(),
  max_growth_bytes: term(),
  max_growth_ratio: term(),
  min_lift: term(),
  parameter: term(),
  proposer: term(),
  reservations: term()
}
```

# `compile`

```elixir
@spec compile(t(), struct(), [row()], [row()], [row()], keyword()) ::
  {:ok, struct()} | {:error, term()}
```

Proposes, evaluates, and transactionally promotes one playbook delta.

# `new`

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

Builds a validated optimizer configuration.

# `observed_weaknesses`

```elixir
@spec observed_weaknesses(map(), keyword()) :: [map()]
```

Returns low-scoring training observations from a proposer request.

The result stays grounded in the exact training rows and admitted trajectories
passed to the proposer. Observations are ordered from lowest score to highest;
use `below:` to set the exclusive score threshold (default `1.0`). Promotion
and audit rows are never present in the request produced by this optimizer.

# `read_checkpoint!`

```elixir
@spec read_checkpoint!(Path.t()) :: map()
```

Reads and verifies a completed playbook optimizer checkpoint.

# `restore`

```elixir
@spec restore(map(), struct(), Imp.ProgramParameters.name()) ::
  {:ok, struct()} | {:error, term()}
```

Restores a completed checkpoint against fresh runtime-bound program callbacks.

# `retained_bytes`

```elixir
@spec retained_bytes(Imp.Playbook.t()) :: non_neg_integer()
```

Returns active and historical retained semantic bytes.

# `review`

```elixir
@spec review(struct()) :: map()
```

Returns a compact, data-only challenger review before deployment.

# `rollback`

```elixir
@spec rollback(struct()) :: struct()
```

Returns the exact pre-promotion program preserved by a result.

# `write_checkpoint!`

```elixir
@spec write_checkpoint!(map(), Path.t()) :: :ok
```

Atomically writes a verified completed checkpoint as owner-readable JSON.

The checkpoint's trajectories were redacted when they were dumped. Its
playbooks are written as they are: a restore continues from them and the
checkpoint's hash covers them, so treat the file as sensitive.

---

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