Skip to main content
One procedure document can include others. A fragment node pastes another file’s sections in place: it is only a way to split a long document. A module node runs a reusable block of steps with its own declared inputs and outputs and its own private names, inside the same run. To start a separate run of another published procedure, use invoke.

Syntax

fragment id=intake-checks
module id=underwriting-gate

Fields

fragment

module

Both fences take no attributes after id, and their bodies take no other fields. Paths are static and relative to the including file. They may go up with ../, but must stay inside the procedure’s source folder. Every included file must exist when you compile. When you publish or start a draft, send the included files with the root source, in the request’s fragments and documents fields. See Publish a version.

Fragments

A fragment file starts with front matter that holds only its kind:
shared/intake-checks.procedure.fragment.md
A fragment has no inputs, outputs, ID or version. When the document is compiled:
  • The fragment’s H2 to H6 sections are placed under the heading that holds the fragment fence, one level deeper. Its H1 makes the file readable on its own and isn’t included.
  • Everything behaves as if written in the including document. Schemas and functions declared in either file can be used from the other. $inputs and every name mean the same thing.
  • Fence IDs and heading addresses must be unique across the combined document.
  • Under the heading that holds the fragment fence, other executable fences may come before it but not after it. Put later steps under a child heading or the next heading.
  • A fragment can include fragments and modules.
  • A fragment path can be included only once in a document. Cycles and missing files fail compilation.
  • Errors point at the line in the fragment file, together with the chain of fences that included it.
On a run page, the fragment fence shows the file’s path and opens the fragment as its own document. A fragment adds nothing at run time: the run behaves exactly as if the sections were written in place.

Modules

A module file declares typed inputs and outputs in its front matter:
modules/approval-gate.procedure.module.md
A module has no ID, version, triggers, permissions or lifecycle of its own. The root document’s version pins the exact module file.

Scope

  • Inside the module, $inputs is the module’s own input, set from the fence’s input. Values from the including document aren’t visible unless passed in. $run is available as usual.
  • The module’s step IDs, heading addresses, values, schemas, functions, effects and secrets are private to each inclusion. Two inclusions of the same module never share state or names.
  • Every path that finishes the module must bind each declared output. The fence’s outputs maps each one to a new name in the including document, such as $underwriting_decision. Nothing else comes out.
  • A module can’t end the run. complete, including a choice case that ends the run, isn’t allowed inside it. Return data and let the including document decide.
  • A module can include other modules and fragments. A fragment included by a module becomes part of that module and private to it.
Unlike a fragment, the same module can be included in several places, as the example below does. A module can also be included in a body of a choice, repeat, for-each or parallel.

Example

An endorsement request passes two approval gates that reuse one module. A fragment holds the shared intake step and its schemas. The three files sit in one folder: the fragment and module files above, and this root document.
endorsement-review.procedure.md
The root uses the endorsement schema and the $intake value from the fragment as if they were its own. Each gate creates its own task. The module’s approve step is identified as underwriting-gate:approve in the first gate and billing-gate:approve in the second.

On retry and resume

  • Fragments don’t exist at run time. They are combined into the document when it compiles.
  • Module input is fixed once. The fence’s input is evaluated once, when the run enters the module.
  • Outputs appear together. When the module finishes, its outputs are checked against their schemas and appear in the including document at once. If the module fails, no output appears.
  • Step identity follows the inclusion ID. Steps inside a module are identified by the inclusion’s fence ID and their own ID, such as underwriting-gate:approve. Moving the module file doesn’t change that identity; renaming the inclusion’s id does. Tests also address module steps by these names.

Common errors

See also