# `Spectre.Operation.Control.Command`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/operation/control/command.ex#L1)

Durable, idempotent command shared by operation and inference control lanes.

# `t`

```elixir
@type t() :: %Spectre.Operation.Control.Command{
  action: atom(),
  base_revision: non_neg_integer() | nil,
  causation_id: String.t() | nil,
  committed_at: non_neg_integer() | nil,
  completed_at: non_neg_integer() | nil,
  correlation_id: String.t(),
  desired_state: :active | :paused | :terminal | nil,
  id: String.t(),
  loop_id: String.t(),
  metadata: map(),
  mode: :safe | :immediate,
  payload: term(),
  provenance: map(),
  rejection: term(),
  requested_at: non_neg_integer(),
  status: :pending | :committed | :applied | :rejected
}
```

# `applied`

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

Marks the command as `:applied`, stamping `completed_at` with the current time.

# `committed`

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

Marks the command as `:committed`, stamping `committed_at` with the current time.

# `new`

```elixir
@spec new(String.t(), atom(), keyword()) :: t()
```

Builds a pending control command for `loop_id`.

Operational loops accept `:pause`, `:update`, `:resume`, `:stop`, `:renew`,
`:trigger` and `:update_and_resume`. Inference control accepts `:steer` and
`:cancel`. Each runtime rejects commands from the other domain. The desired
state is derived from the action unless `:desired_state` is given. Missing
ids and `requested_at` default to fresh UUIDv7s and the current time. Raises
`ArgumentError` on an invalid mode.

# `rejected`

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

Marks the command as `:rejected` with `reason`, stamping `completed_at` with
the current time.

# `validate`

```elixir
@spec validate(t()) :: :ok | {:error, term()}
```

Validates the command's identity, action, mode, timestamps and portability.

Returns `:ok`, or `{:error, reason}` naming the first invalid field or the
status whose timestamps are inconsistent.

---

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