# workflow

## Intent

A named orchestration graph connecting operation/workflow calls, event waits, data bindings, policies, transitions, and outputs.

Exact selection subject:

```yaml
subject: workflow
```

The current Runtime IR is evidence, not authority. Target improvements needed for a usable template contract are called out explicitly.

## Scope envelope

| Scope                 | Context                              |
| --------------------- | ------------------------------------ |
| `each`                | `workflow: WorkflowContext`          |
| `all`                 | `workflows: WorkflowContext[]`       |
| collection candidates | `collects.group`, `collects.feature` |

For `collects.<dimension>`, the singular collector is added beside the plural selected-subject array. A collector is valid only when ownership is semantically provable.

## Context tree

| Context path                       | Type                             | Meaning / template use                                            |
| ---------------------------------- | -------------------------------- | ----------------------------------------------------------------- |
| `workflow.id`                      | `string`                         | Opaque stable semantic identity.                                  |
| `workflow.name`                    | `NameContext`                    | Stable semantic identity and finite naming variants.              |
| `workflow.description`             | `string\|null`                   | Human semantic description.                                       |
| `workflow.tags`                    | `string[]`                       | Semantic classifiers; empty when none.                            |
| `workflow.explanations`            | `ExplanationContext[]`           | Advisory usage/security/implementation notes.                     |
| `workflow.group`                   | `SemanticLinkContext\|null`      | Owning semantic group.                                            |
| `workflow.feature`                 | `SemanticLinkContext\|null`      | Canonical owning feature.                                         |     |
| `workflow.inputs`                  | `ValuePortContext[]`             | Named ordered inputs; each port.value uses SemanticValueContext.  |     |
| `workflow.outputs`                 | `ValuePortContext[]`             | Named ordered outputs; each port.value uses SemanticValueContext. |     |
| `workflow.start`                   | `WorkflowStepLinkContext`        | Starting step.                                                    |
| `workflow.steps`                   | `WorkflowStepContext[]`          | Named deterministic steps.                                        |
| `workflow.steps[].name`            | `NameContext`                    | Step identity.                                                    |
| `workflow.steps[].kind`            | `operation\|workflow\|wait`      | Structural variant.                                               |
| `workflow.steps[].operation`       | `SemanticLinkContext\|null`      | Operation target.                                                 |
| `workflow.steps[].workflow`        | `SemanticLinkContext\|null`      | Nested workflow target.                                           |
| `workflow.steps[].event`           | `SemanticLinkContext\|null`      | Waited event.                                                     |
| `workflow.steps[].timeout.seconds` | `integer\|null`                  | Wait timeout.                                                     |
| `workflow.steps[].inputs`          | `StepInputBindingContext[]`      | Target input ← workflow/step/event source.                        |
| `workflow.transitions`             | `WorkflowTransitionContext[]`    | From/to step links plus optional policy.                          |
| `workflow.output_bindings`         | `WorkflowOutputBindingContext[]` | Workflow output ← semantic source.                                |

## Usage rules

- Step maps become arrays with explicit names.
- All source/target refs resolve to bounded port/step/link objects.
- Workflow ports need semantic names for generated APIs.

## Runtime IR implications to audit

- Add stable names to workflow ports.
- Ensure step identities are explicit, not map-key-only.
- Promote workflow.step to a subject only if proof packs generate artifacts per step.

## Template example — Jinja / orchestration skeleton

```jinja
async def {{ file.symbol }}({% for p in workflow.inputs %}{{ p.name.snake }}{% if not loop.last %}, {% endif %}{% endfor %}):
{% for step in workflow.steps %}
    # {{ step.name.local }} — {{ step.kind }}
{% if step.kind == "operation" %}
    await {{ step.operation.name.snake }}(...)
{% endif %}
{% endfor %}
```

The example uses semantic context only. Any `renderType`/`render_type` helper shown is a pack-owned macro/partial consuming the documented `TypeContext`, not hidden Dryv context.

## Audit questions

- Can a real workflow pack generate code without parsing raw IR storage conventions?
- Is any field here present only because the current IR happens to store it?
- Does any nested item need first-class selection of its own?
