# `Runic.Workflow.Step`
[🔗](https://github.com/zblanco/runic/blob/main/lib/workflow/step.ex#L1)

Step nodes transform input facts into output facts.

A Step receives a fact, applies its work function, and produces a new fact
with the result. Steps are the primary computation nodes in a workflow.

## Meta Expression Support

Steps can reference workflow state through meta expressions like `state_of(:component)`.
When a Step has meta references, the `:meta_refs` field is populated during
macro compilation, and `:meta_ref` edges are drawn during `Component.connect/3`.

During the prepare phase, these edges are traversed to populate `meta_context` in
the `CausalContext`, making the referenced state available during execution.

## Runtime Context

Steps can also reference external runtime values via `context/1` expressions:

    step = Runic.step(fn _x -> context(:api_key) end, name: :call_llm)
    step = Runic.step(fn x -> x + context(:offset) end, name: :compute)

When `context/1` is detected, the step's work function is rewritten to arity-2
`(input, meta_ctx)` and `meta_refs` are populated with `kind: :context` entries.
Values are resolved from the workflow's `run_context` during the prepare phase.

# `meta_ref`

```elixir
@type meta_ref() :: %{
  kind: atom(),
  target: atom() | integer() | {atom(), atom()},
  field_path: [atom()],
  context_key: atom()
}
```

# `t`

```elixir
@type t() :: %Runic.Workflow.Step{
  closure: Runic.Closure.t() | nil,
  hash: String.t() | nil,
  inputs: term(),
  meta_refs: [meta_ref()],
  name: String.t() | atom(),
  outputs: term(),
  work: function(),
  work_hash: String.t() | nil
}
```

# `has_meta_refs?`

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

Returns whether this step has meta references that need to be resolved
during the prepare phase.

# `new`

# `run`

Executes the work function of the Lambda step returning the raw unwrapped value.

# `run_with_meta_context`

```elixir
@spec run_with_meta_context(t(), term(), map()) :: term()
```

Runs the step work function with meta context available.

When a step has meta references, its work function is arity 2,
receiving `(input, meta_context)`.

---

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