High-level host-facing turn result.
A turn wraps the raw %Spectre.Result{} and a lifecycle decision that tells
the host what to do next without encoding capability-specific branches in the
decision vocabulary. This is Spectre's canonical local host result whether
the input was routed normally or claimed by a pre-route
Spectre.Turn.Handler.
Transport protocols should map their envelope into Spectre.turn/3 and map
this result back out. Addressing, correlation, remote task state, retries,
and delivery guarantees remain transport concerns.
Summary
Functions
Builds a turn from an already available result.
Projects one closed Runtime step into the stable host-facing Turn.
Resolves this turn's active policy from a trusted host decision and returns the next lifecycle decision.
Starts a Run and advances it to its first observable boundary.
Types
@type decision() :: {:awaiting, Spectre.Awaitable.t(), Spectre.Result.t()} | {:needs, Spectre.Effect.t(), Spectre.Result.t()} | {:completed, Spectre.Effect.t() | Spectre.Awaitable.t(), Spectre.Result.t()} | {:reply, Spectre.Result.t()} | {:no_response, Spectre.Result.t()}
@type observable() :: {:reply, term(), Spectre.Run.Ref.t()} | {:awaiting, Spectre.Run.Ref.t()} | {:needs, Spectre.Run.Boundary.t()}
@type t() :: %Spectre.Turn{ agent: module() | GenServer.server(), boundary: Spectre.Run.Boundary.t() | Spectre.Invocation.t() | nil, decision: decision(), input: Spectre.Input.t() | String.t() | map(), metadata: map(), observable: observable(), opts: keyword(), ref: Spectre.Run.Ref.t(), result: Spectre.Result.t() }
Functions
@spec from_result( module() | GenServer.server(), term(), keyword(), Spectre.Result.t() ) :: t()
Builds a turn from an already available result.
@spec from_step( module() | GenServer.server(), term(), keyword(), Spectre.Runtime.step_result() ) :: t()
Projects one closed Runtime step into the stable host-facing Turn.
The continuation itself remains owned by the runtime/actor. The Turn exposes only a revision-fenced reference and the first observable request or reply.
@spec resolve_policy(t(), Spectre.Policy.resolution(), keyword()) :: {:ok, t()} | {:error, term()}
Resolves this turn's active policy from a trusted host decision and returns the next lifecycle decision.
This keeps application adapters from synthesizing user text or manually rebuilding approved effects.
@spec run(module(), Spectre.Input.t() | String.t() | map(), keyword()) :: {:ok, t()} | {:error, term()}
Starts a Run and advances it to its first observable boundary.