# Workflows

## Meaning

A Workflow describes semantic orchestration across multiple pieces of behavior over time. It owns ordered/conditional/waiting execution that is larger than one Operation.

Workflow meaning remains declarative and implementation-neutral. Queue engines, workflow products, workers, schedulers, persistence products, and execution frameworks remain pack/runtime choices.

## Canonical shape

A Workflow may define:

- optional `group` and semantic metadata;
- ordered direct input value ports;
- ordered direct output value ports;
- explicit output bindings;
- a named start step;
- named steps;
- transitions between steps.

Example:

```yaml
workflows:
  users.Onboarding:
    inputs:
      - value:
          $ref: "#/schemas/users.User"
    outputs:
      - value:
          $ref: "#/schemas/users.User"
    start:
      $ref: "#/workflows/users.Onboarding"
      step: create
```

## Workflow ports

Workflow inputs/outputs use the same direct authored-value principle as Operations:

```yaml
inputs:
  - value:
      $ref: "#/schemas/users.User"
```

A port references one canonical `ValueRef`:

```text
PropertyRef | SchemaRef
```

Workflow I/O is ordered. It is not a keyed map of arbitrary `ValueUsage` contracts.

Typed Workflow port references use:

```yaml
$ref: "#/workflows/users.Onboarding"
direction: input
index: 0
```

## Step identity

A Workflow step is addressed through the Workflow identity plus an explicit step key:

```yaml
$ref: "#/workflows/users.Onboarding"
step: create
```

Do not use physical pointers such as:

```text
#/workflows/users.Onboarding/steps/create
```

## Step kinds

Canonical step kinds currently include:

- `operation` — invoke an Operation;
- `workflow` — invoke another Workflow;
- `wait` — wait for a semantic Event.

Operation and nested-Workflow steps do not redefine the target declaration's input/output meaning.

## Explicit value flow

Step input flow is explicit.

A binding identifies the target input index on the invoked Operation/Workflow and a typed semantic source:

```yaml
inputs:
  - target: 0
    source:
      kind: workflow-input
      port:
        $ref: "#/workflows/users.Onboarding"
        direction: input
        index: 0
```

Supported Workflow value sources are:

### Workflow input

```yaml
kind: workflow-input
port:
  $ref: "#/workflows/users.Onboarding"
  direction: input
  index: 0
```

### Step output

```yaml
kind: step-output
step:
  $ref: "#/workflows/users.Onboarding"
  step: create
index: 0
```

### Event payload

```yaml
kind: event-payload
step:
  $ref: "#/workflows/users.Onboarding"
  step: created
```

An Event-payload source is valid only for a wait step whose Event has a payload.

## Workflow outputs

Workflow output flow is also explicit:

```yaml
output_bindings:
  - target:
      $ref: "#/workflows/users.Onboarding"
      direction: output
      index: 0
    source:
      kind: step-output
      step:
        $ref: "#/workflows/users.Onboarding"
        step: create
      index: 0
```

The source value must be compatible with the target Workflow output value.

## Transitions

Transitions use typed Workflow-step references:

```yaml
transitions:
  - from:
      $ref: "#/workflows/users.Onboarding"
      step: create
    to:
      $ref: "#/workflows/users.Onboarding"
      step: waitForCreated
```

An optional Policy reference may guard a transition.

## Event relationships

A wait step may wait for an Event:

```yaml
waitForCreated:
  kind: wait
  event:
    $ref: "#/events/users.UserCreated"
```

This is different from an Event listener.

```text
Event.listeners
```

expresses consumers triggered by the Event.

```text
Workflow WaitStep
```

expresses orchestration that waits for an Event occurrence.

## Removed model

Do not emit keyed Workflow input/output maps, arbitrary canonical-value dictionaries, implicit type-based input inference, or physical step pointers.

The old patterns:

```text
#/workflows/<name>/inputs/<key>
#/workflows/<name>/steps/<key>
```

are not canonical behavior references.

## Boundaries

A Workflow may invoke Operations and nested Workflows and wait for Events, but it does not redefine those declarations.

Value flow must remain explicit, typed, deterministic, inspectable, and portable. Hidden transformations or string-path mapping conventions are not part of canonical Workflow meaning.
