# `Spectre.Policy`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/runtime/policy.ex#L1)

Policy gate evaluator for pending effects.

A conversation-resolved policy is a temporary deterministic router for one
pending effect. Externally resolved policies keep normal flow routing active
and accept only an addressed trusted-host decision.

# `decision`

```elixir
@type decision() :: {:accept, atom()} | {:reject, atom()} | :no_match
```

# `resolution`

```elixir
@type resolution() ::
  {:accept, atom()} | {:reject, atom()} | Spectre.Policy.Resolution.t()
```

# `t`

```elixir
@type t() :: %Spectre.Policy{
  accepts: [map()],
  max_attempts: pos_integer() | nil,
  name: atom(),
  otherwise: {:ask, atom() | String.t()} | nil,
  owner: module() | nil,
  reference: term(),
  rejects: [map()],
  request: atom() | String.t() | nil,
  scope: Spectre.Definition.scope(),
  then: atom() | nil
}
```

# `awaiting?`

```elixir
@spec awaiting?(Spectre.State.t()) :: boolean()
```

Returns true when the state is waiting on a policy response.

# `decide`

```elixir
@spec decide(t(), String.t()) :: decision()
```

Decides whether policy text accepts, rejects, or misses all policy branches.

# `new`

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

Builds a policy struct from compiled DSL metadata.

# `resolve`

```elixir
@spec resolve(resolution(), Spectre.Input.t(), Spectre.Context.t() | map()) ::
  {:ok, Spectre.Result.t()} | {:error, term()}
```

Resolves the active policy from a trusted host decision without matching
synthetic user text.

The label must exist in the policy's corresponding accept/reject branches.
This is useful when an application already has durable proof that a policy is
satisfied. Callers should use `Spectre.resolve_policy/4` so the resulting
state is persisted before execution.

# `resume`

```elixir
@spec resume(Spectre.Input.t(), Spectre.Context.t()) ::
  {:ok, Spectre.Result.t()} | {:error, term()}
```

Resumes the active policy with the user's latest input.

---

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