Skip to main content

Module behavior

Module behavior 

Source
Expand description

behavior — component-graph IR + run_behavior unified execution IF.

Ports the TS reference ts/src/behavior.ts (scp-ir-architecture.md §5-§7).

A portable component-graph IR (components[]{name, inputPorts, body[], output, plan}) is executed on top of the existing COMMON primitives: run_plan (stage exec / Skip propagation / Policy Kind) + evaluate (Expression IR). The concrete per-component (leaf) implementation is resolved by name through a ComponentExec seam — the boundary-injected handler registry (IR + {effects,config,hooks}).

Body node kinds:

  • componentRef: {id, component, ports, parent?, bindField?, relationKind?, policy?}
  • map: {id, map:{over, as, component, ports, when?, into?, batched?, parent?, relationKind?, policy?}} (when/into/batched are behaviorVersion 2)
  • cond: {id, cond:{if, then, else, parent?}} (pure Expression; no handler)

behaviorVersion 2 (bc#22):

  • map.when — per-element guard, lowered to {cond:[when,true,false]} (strict bool; non-bool fails closed with TYPE_MISMATCH). Falsy elements are skipped (handler not called, excluded from the result list; order preserved).
  • map.into — zip-attach: the node result becomes the over list with each guard-passing element shallow-copied and augmented with into: <handler result> (same length/order as over; skipped elements pass through unchanged). Parent results are never mutated. Non-object kept elements fail closed (MAP_INTO_ELEMENT_NOT_OBJECT).
  • map.batched — evaluates the ports of all guard-passing elements first, then calls the handler ONCE with {items:[<ports>...]}; the handler must return a list aligned to items (violations fail closed with MAP_BATCH_RESULT_MISMATCH). Zero kept elements means the handler is not called and the result is the empty list.
  • handler ctx — every handler call carries the node identity (nodeId + component) via the ComponentExec::exec_ctx seam (additive; default forwards to exec).

Structs§

BehaviorError
A unified failure for run_behavior, carrying a stable string code so the conformance runner can compare against expression / plan / behavior codes alike.

Enums§

BehaviorFailureCode
Stable behavior-execution failure codes (in addition to plan/expr codes).

Traits§

ComponentExec
The boundary-injected handler registry seam (§7.1). Resolves a catalog name to a leaf implementation and executes it with evaluated ports (+ the map element bound value, if any). Returns None when the name is unknown so run_behavior can fail closed with UNKNOWN_COMPONENT.

Functions§

run_behavior
Run a component-graph IR (scp-ir-architecture.md §7).