# operation

Derived additions: `facets.http.is.*`, `inputs[].is.*`, `input_groups.<kind>[]`, `path.effective` and `path.segments[]`. See [derived.md](/pack-builders/context/derived#http-views).

## Intent

A callable semantic behavior supporting service methods, controllers/routes, SDK calls, handlers, access controls, execution semantics, schedules, failures, and events.

Exact selection subject:

```yaml
subject: operation
```

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`                | `operation: OperationContext`        |
| `all`                 | `operations: OperationContext[]`     |
| 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                                                                                                                                                                                                                          |
| ------------------------------------------- | --------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `operation.id`                              | `string`                                                                          | Opaque stable semantic identity.                                                                                                                                                                                                                |
| `operation.name`                            | `NameContext`                                                                     | Stable semantic identity and finite naming variants.                                                                                                                                                                                            |
| `operation.description`                     | `string\|null`                                                                    | Human semantic description.                                                                                                                                                                                                                     |
| `operation.tags`                            | `string[]`                                                                        | Semantic classifiers; empty when none.                                                                                                                                                                                                          |
| `operation.explanations`                    | `ExplanationContext[]`                                                            | Advisory usage/security/implementation notes.                                                                                                                                                                                                   |
| `operation.group`                           | `SemanticLinkContext\|null`                                                       | Owning semantic group.                                                                                                                                                                                                                          |
| `operation.feature`                         | `SemanticLinkContext\|null`                                                       | Canonical owning feature.                                                                                                                                                                                                                       |     |
| `operation.role`                            | `create\|update\|delete\|detail\|list\|search\|validate\|transform\|action\|null` | Semantic role.                                                                                                                                                                                                                                  |
| `operation.input`                           | `OperationInputContext \| null`                                                   | The single input: `kind` (`fields` or `schema`), `value` (the schema, for a schema input), and `fields[]` with `name`, `value` (null for unknown/dynamic schema fields) and `optional`. Always named: a schema input lists the schema's fields. |     |
| `operation.output`                          | `OperationOutputContext \| null`                                                  | The single output: `value`.                                                                                                                                                                                                                     |     |
| `operation.failures`                        | `SemanticLinkContext[]`                                                           | Declared failure contracts.                                                                                                                                                                                                                     |
| `operation.emits`                           | `SemanticLinkContext[]`                                                           | Emitted events.                                                                                                                                                                                                                                 |
| `operation.access.authenticated`            | `boolean`                                                                         | Authentication requirement.                                                                                                                                                                                                                     |
| `operation.access.policies`                 | `SemanticLinkContext[]`                                                           | Required policies.                                                                                                                                                                                                                              |
| `operation.execution.mode`                  | `sync\|async`                                                                     | Execution mode.                                                                                                                                                                                                                                 |
| `operation.execution.timeout.seconds`       | `integer\|null`                                                                   | Timeout.                                                                                                                                                                                                                                        |
| `operation.execution.rate_limit`            | `RateLimitContext\|null`                                                          | Limit/window.                                                                                                                                                                                                                                   |
| `operation.execution.cache.ttl.seconds`     | `integer\|null`                                                                   | Cache lifetime.                                                                                                                                                                                                                                 |
| `operation.execution.transaction.required`  | `boolean\|null`                                                                   | Transaction requirement.                                                                                                                                                                                                                        |
| `operation.execution.retry`                 | `RetryContext\|null`                                                              | Attempts/backoff.                                                                                                                                                                                                                               |
| `operation.execution.idempotency.key`       | `OperationPortLinkContext\|null`                                                  | Named input port used as idempotency key.                                                                                                                                                                                                       |
| `operation.execution.audit.required`        | `boolean\|null`                                                                   | Audit requirement.                                                                                                                                                                                                                              |
| `operation.execution.invalidates`           | `SemanticLinkContext[]`                                                           | Invalidated operations.                                                                                                                                                                                                                         |
| `operation.facets.http.method`              | `HttpMethod\|null`                                                                | HTTP method.                                                                                                                                                                                                                                    |
| `operation.facets.http.path.local`          | `string\|null`                                                                    | Operation-declared path, unchanged from Runtime IR.                                                                                                                                                                                             |
| `operation.facets.http.path.effective`      | `string\|null`                                                                    | Derived full path: active application HTTP root + ordered owning-group HTTP roots + operation-local path.                                                                                                                                       |
| `operation.facets.http.inputs`              | `HttpInputBindingContext[]`                                                       | Input field (or whole schema input)→path/query/header/cookie/body/multipart/form bindings. `port.field` is the field name, or null for the whole input; `port.name` is the field name, or `input`.                                              |
| `operation.facets.http.outputs`             | `HttpOutputBindingContext[]`                                                      | Output→status/representation bindings.                                                                                                                                                                                                          |
| `operation.facets.http.failures`            | `HttpFailureBindingContext[]`                                                     | Failure→status/representation bindings.                                                                                                                                                                                                         |
| `operation.facets.websocket.path.local`     | `string\|null`                                                                    | Operation-declared WebSocket path.                                                                                                                                                                                                              |
| `operation.facets.websocket.path.effective` | `string\|null`                                                                    | Derived full WebSocket path using the same scope-root composition rule.                                                                                                                                                                         |
| `operation.facets.schedule`                 | `ScheduleFacetContext\|null`                                                      | Interval/daily schedule.                                                                                                                                                                                                                        |

## Usage rules

- Ports have stable indices and an optional canonical `name`; unnamed ports project as `input_0`, `output_0`.
- `path.local` preserves the authored operation path. `path.effective` is the Engine-composed route using the active application root, root-to-leaf owning-group HTTP roots, then the local path. Packs that mount routers beneath their own prefixes may still intentionally use `local`; external API descriptions and direct route registrations should normally use `effective`.

## Runtime IR implications to audit

Effective path resolution is derived from existing canonical scope facts; it does not add Runtime IR fields.

## Template example — Handlebars / controller method

The controller flattens the input into one parameter per HTTP binding, then passes the service one input object:

```hbs
@{{operation.facets.http.method}}("{{operation.facets.http.path.local}}") async
{{operation.name.camel}}(
{{#each operation.facets.http.inputs}}
  {{port.name.camel}}:
  {{renderValue port.value @root.file.dependencies}}{{#unless
    @last
  }},{{/unless}}
{{/each}}
) { return this.service.{{operation.name.camel}}({
{{#each operation.facets.http.inputs}}{{port.name.camel}}{{#unless @last}},
  {{/unless}}{{/each}}
}); }
```

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

- Are named ports the correct canonical improvement?

## Facet cardinality

Initial context cardinality is intentionally singular:

```text
operation.facets.http       0..1
operation.facets.websocket  0..1
operation.facets.schedule   0..1
```

If one behavior must be exposed through several independent HTTP bindings, model those as distinct operations that may share underlying semantic behavior rather than turning the context path into an array.
