# `Spectre.GAM.Mind`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/gam/mind.ex#L1)

Capability-free boundary for application deliberation.

A mind may route, plan, call application code and construct Candidates.  It
receives no Grant, broker or ledger writer, and its result remains only a
proposal until each Candidate independently crosses the kernel boundary.

`use Spectre.GAM.Mind, ref: "mind:my-app:v1"` declares the behaviour and an
overridable `c:ref/0`. Implement `c:deliberate/2` yourself. When this stateless
implementation is used by an Instance, the existing runtime bridge preserves
its local state unchanged.

For a stateful implementation, opt into `stateful: true` and implement
`c:deliberate/3`. The generated, overridable `c:deliberate/2` calls it with `nil`
state and discards the returned state. A stateless call therefore starts
without local state; it never substitutes the options for that state. Your
callback must handle `nil` or you must override `c:deliberate/2` explicitly.

This helper does not choose an Agent, flow, router, pipeline or fallback,
record derived Evidence, or submit Candidates. Those remain application
decisions. Plain `@behaviour Spectre.GAM.Mind` implementations remain supported.

Without the helper, `c:deliberate/2` is always required; `c:deliberate/3` is an
optional, explicit stateful variant. Define both arities separately. Do not
write `def deliberate(turn, state, opts \ [])`: the generated `/2` would
receive stateless turn options as `state`. The two callbacks also have
intentionally different success shapes:

    def deliberate(turn, opts), do: {:ok, candidates(turn, opts)}

    def deliberate(turn, state, opts) do
      {:ok, candidates(turn, opts), next_state(state)}
    end

# `deliberate`

```elixir
@callback deliberate(
  Spectre.GAM.Mind.Turn.t(),
  keyword()
) ::
  {:ok,
   Spectre.GAM.Candidate.t()
   | map()
   | keyword()
   | [Spectre.GAM.Candidate.t() | map() | keyword()]}
  | {:error, term()}
```

# `deliberate`
*optional* 

```elixir
@callback deliberate(Spectre.GAM.Mind.Turn.t(), term(), keyword()) ::
  {:ok,
   Spectre.GAM.Candidate.t()
   | map()
   | keyword()
   | [Spectre.GAM.Candidate.t() | map() | keyword()], term()}
  | {:error, term()}
```

# `ref`

```elixir
@callback ref() :: String.t()
```

# `candidate`

```elixir
@spec candidate(Spectre.GAM.Mind.Turn.t(), map() | keyword()) ::
  {:ok, Spectre.GAM.Candidate.t()} | {:error, term()}
```

Builds a Candidate whose trusted proposer and Scope come from the sealed Turn.

# `candidate`

```elixir
@spec candidate(
  Spectre.GAM.Mind.Turn.t(),
  Spectre.GAM.Evidence.t() | [Spectre.GAM.Evidence.t()],
  map() | keyword()
) :: {:ok, Spectre.GAM.Candidate.t()} | {:error, term()}
```

Builds a Candidate that may also cite validated derivations produced from the same Turn.

# `deliberate`

```elixir
@spec deliberate(module(), Spectre.GAM.Mind.Turn.t(), keyword()) ::
  {:ok, [Spectre.GAM.Candidate.t()]} | {:error, term()}
```

Invokes a mind and normalizes its output to scope-bound Candidates.

# `deliberate`

```elixir
@spec deliberate(module(), Spectre.GAM.Mind.Turn.t(), term(), keyword()) ::
  {:ok, [Spectre.GAM.Candidate.t()], term()} | {:error, term()}
```

Invokes an optional stateful Mind callback without making its state authoritative.

# `evidence`

```elixir
@spec evidence(Spectre.GAM.Mind.Turn.t(), integer(), map() | keyword()) ::
  {:ok, Spectre.GAM.Evidence.t()} | {:error, term()}
```

Builds derived or generated Evidence bound to the exact sealed Turn context.

---

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