# `Spectre.Effect`
[🔗](https://github.com/elchemista/spectre/blob/0.3.0/lib/spectre/types/effect.ex#L1)

Runtime or host work represented as data.

Effects generalize the old pending-action shape. An action is now one effect
kind; future capabilities such as retrieval or search can use the same
contract without changing turn decisions. Action effects carry their owning
module and mounted scope as first-class fields; payload data cannot override
that trusted runtime origin.

# `outcome`

```elixir
@type outcome() :: {:ok, term()} | {:error, term()} | {:cancelled, term()} | nil
```

# `status`

```elixir
@type status() ::
  :pending | :waiting_policy | :approved | :completed | :failed | :cancelled
```

# `t`

```elixir
@type t() :: %Spectre.Effect{
  args: map(),
  error: term(),
  id: term(),
  idempotency_key: String.t(),
  kind: atom(),
  metadata: map(),
  mode: atom() | nil,
  name: atom() | String.t() | nil,
  owner: module() | nil,
  payload: map(),
  policy: term(),
  result: term(),
  run_id: String.t() | nil,
  scope: Spectre.Definition.scope() | nil,
  status: status()
}
```

# `al`

```elixir
@spec al(t()) :: String.t() | nil
```

Returns the Action Language text encoded in an action effect payload.

# `approve`

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

Marks a policy-gated effect as approved without executing it.

Approval is a durable state transition. The host may execute the effect only
after the approved state has been persisted.

# `bind_run`

```elixir
@spec bind_run(t(), String.t() | nil) :: t()
```

Associates an Effect with its owning Instance Run.

Extension-owned Effect builders should use
`Spectre.Context.lifecycle_run_id/1` and bind the returned value before
staging. Passing `nil` preserves the stateless and Session compatibility
lifecycle.

# `cancel`

```elixir
@spec cancel(t(), term()) :: t()
```

Marks an effect as cancelled.

# `complete`

```elixir
@spec complete(t(), term()) :: t()
```

Marks an effect as completed with a result.

# `effect_key`

```elixir
@spec effect_key(t() | map() | atom() | String.t()) :: atom() | String.t() | nil
```

Returns the stable key used for protection and dispatch checks.

# `executable?`

```elixir
@spec executable?(t()) :: boolean()
```

Returns whether an effect is ready for its host capability boundary.

Policy-gated effects become executable only after their durable
`:waiting_policy -> :approved` transition.

# `fail`

```elixir
@spec fail(t(), term()) :: t()
```

Marks an effect as failed with an error.

# `hooks`

```elixir
@spec hooks(t()) :: [map()]
```

Returns hooks attached to an effect payload.

# `idempotency_key`

```elixir
@spec idempotency_key(t()) :: String.t()
```

Returns the stable key that an action adapter can use to deduplicate retries.

# `outcome`

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

Normalizes a terminal effect into a host-facing outcome.

Older adapters may have stored `{:ok, value}` or `{:error, reason}` inside
a completed effect. These shapes are flattened for backwards compatibility.
Non-terminal effects return `nil`.

# `owner`

```elixir
@spec owner(t()) :: module() | nil
```

Returns the module that owned the route which staged the effect.

Legacy persisted effects may not carry an owner and return `nil`.

# `planned_by`

```elixir
@spec planned_by(t()) :: module() | atom() | nil
```

Returns the planner that produced the action, when present.

# `restore`

```elixir
@spec restore(map() | struct()) :: t()
```

Restores a persisted effect without inventing a missing scope.

Durable codecs use this behavior for legacy state. An unscoped restored
effect remains observable but must be rejected by the execution boundary.

# `schema_hash`

```elixir
@spec schema_hash(t()) :: String.t() | nil
```

Returns the approved provider schema hash, when present.

# `scope`

```elixir
@spec scope(t()) :: Spectre.Definition.scope() | nil
```

Returns the Agent or mounted-Skill scope that staged the effect.

Older persisted effects may not carry a scope and return `nil`.

# `selected_tool`

```elixir
@spec selected_tool(t()) :: String.t() | nil
```

Returns the selected tool encoded in an action effect payload.

# `source`

```elixir
@spec source(t()) :: atom() | nil
```

Returns the source encoded in an effect payload.

# `stage`

```elixir
@spec stage(map() | struct()) :: t()
```

Builds a pending effect outside a routed Skill context.

Effects staged through this generic compatibility API default to Agent scope.
Routed actions should use `stage_action/3` so ownership cannot be omitted.

# `stage_action`

```elixir
@spec stage_action(map() | struct(), module(), Spectre.Definition.scope()) :: t()
```

Builds a pending action effect with a trusted owner and scope.

Explicit origin arguments replace any owner or scope supplied by the action
payload. Both deterministic DSL actions and model-planned actions use this
constructor.

# `terminal?`

```elixir
@spec terminal?(t()) :: boolean()
```

Returns whether an effect reached a terminal lifecycle state.

# `via`

```elixir
@spec via(t()) :: Spectre.Action.provider_ref()
```

Returns the provider identifier encoded in an action effect.

Effects written before provider separation default to the local Elixir
provider.

# `waiting_policy`

```elixir
@spec waiting_policy(t(), term()) :: t()
```

Marks an effect as waiting on a policy gate.

---

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