# JSFE reference

This is the self-contained authoring reference for JSFE and the Flow Designer's backend CoPilot. Use the actual installed flow/tool registries and host instructions for available business services, approved functions, configuration and credentials. Do not invent a tool, shared flow, model role or business capability. This reference describes engine behavior; it does not activate or deploy definitions.

## 1. Runtime documents and ownership

A flow set is a JSON array, conventionally `tenant.flows`, accompanied by a JSON tool array, `tenant.tools`. These are the editable runtime sources. Include all tenant workers, catalogs, forms, action declarations and named JavaScript functions in those documents. They must not import tenant JavaScript modules or require a generator to reconstruct their definitions. The host may compose multiple matched pairs, such as system, Shopify and tenant sets. Reference installed shared workers by ID instead of copying them. Resolve conflicting IDs deliberately; never rely on a later duplicate silently shadowing a definition.

JSFE owns collection state, nested ownership, validation transitions, confirmation invalidation, action guards and recovery. The host owns approved transport functions, credentials, storage, turn serialization and model configuration. Tenant definitions own intent descriptions, business rules, API payloads and presentation. Keep generic collection/retrieval/action bookkeeping in JSFE.

There are four authoring concepts:

| Concept | JSON declaration | Purpose |
| --- | --- | --- |
| Form | `form` | Collect and validate a reentrant task, accepting independently valid inputs out of order. |
| Provider | `provides` | Retrieve declared facts or fact sets, with authentication where required. |
| Performer | `form` and `performs`, with `prepare` and `present` | Collect, prepare, confirm and execute a guarded action. |
| Worker | `steps`, or `call` | Perform a small explicit calculation or orchestration task. |

A versioned entry has `declarationVersion: 2` (new authoring) or `1` (earlier sets, unchanged). JSFE lowers it at engine construction, compiles contextual question workers, links installed child schemas and validates the new declarations. Ordinary executable entries without that marker retain their existing meaning; `functions` on such an entry is a compile error. Generated steps and schemas are execution output, not a second editable source.

**Version 2: one parameter contract.** A primary form's parameters are GENERATED, never written: one per input that has a profile or sub-form, and a sub-form input becomes an object parameter carrying every nested field (`card_info{card_number, card_expiration, …}`). An enum's values come from the input's choices, and each value's meaning from that choice's `description`; write the meaning there, once, next to its phrases. The input's own `description` is the rule read before the meanings (`rule: key: meaning; …`, plus `enumDescriptions`). A choice the form offers but extraction must never set carries `extract:false`; an input callers may set but extraction never fills carries `internal:true`. `parameters` holds only entry arguments: values a calling flow passes (`owner`, `question`) and values a caller may say up front that the form does not ask under that name. Authoring a name the form generates, at any depth, is a compile error. A FLOW step may pass only arguments its version 2 target declares.

**Shared data.** One reserved entry per flow set holds values several flows use: `{"id":"<set>-data","library":"data","declarationVersion":2,"data":{"services":{…},…}}`. Expressions read it at run time as `$data.<name>` (for example `Object.values($data.services).find(s=>s.key===service)`); it is frozen and never saved in the session, so never copy it into a variable or cargo. A declaration field that is not an expression (a choice's phrases or label) references it as `{"$data":"services.bc.phrases"}` (a dotted path), compiled to a copy. An unknown name or path, a name declared twice, or a reference cycle fails at load. Write a catalog, phrase list or label once there, never as copies.

**Shared functions.** One reserved entry per flow set: `{"id":"<set>-functions","library":"functions","declarationVersion":2,"functions":{…}}`. Every version 2 flow can call them as `fn.name(…)`; a flow redefining a shared name, or a name declared twice, is a compile error. Put a function used by more than one flow there, never in copies.

`compileFlowDeclarations(flows, {tools?, externalFlows?, validate?})` is the tooling accessor; validation defaults to true. External flow objects support child-schema linking; external IDs alone support reference checking. A runtime engine must receive the actual complete composed registry. Compilation/contract validation is not behavioral testing.

## 2. Common flow fields

| Field | Meaning |
| --- | --- |
| `id` | Stable unique identifier, conventionally kebab-case. |
| `name` | Activation name, conventionally PascalCase; derived from `id` for declarations when omitted. |
| `description` | Intent boundary: what should activate the primary and which neighboring requests belong elsewhere. Stage-one intent selection reads this description. |
| `primary` | Whether intent detection may activate this entry. Ordinary flows default false; Provider defaults true unless overridden. |
| `version` | Informational flow version; not a saved-session migration or hot-reload instruction. |
| `scope` | `isolated` or `shared`. Prefer isolated reusable workers. Versioned builders default isolated. |
| `parameters` | Entry arguments: what a caller passes, or what may be said up front that no input asks. On a version 2 form, input parameters are generated and may not be written. Declare meaning precisely; never infer consent from extraction. |
| `parameterInstructions` | Cross-parameter extraction guidance for stage two; not stage-one intent selection. |
| `variables` | Initial local variables, preferably `{ "name": {"type":"string","value":""} }`. Object/array defaults are cloned per activation. |
| `interruptable` | When it and every flow on the stack are true, intent detection may interrupt. |
| `loopBound` | A string naming the runtime limit that ends a loop this flow is on; the flow-trap check accepts the loop and a test must drive the limit. |
| `replaceTarget` | `true`: a `FLOW.replace` with `toParent:true` may return to this flow's waiting frame and take its place. |
| `functions` | Named ordinary JavaScript bodies, described below. |
| `contract` | Business summary, role, requirements, tool references and result metadata; builders supply normal protocol details. |
| `wraps` | Ordinary thin wrapper over an installed shared flow, by ID/name. The shared target becomes non-primary; omitted wrapper description, parameters, prompts and primary flag inherit from it (a primary wrapper needs no description of its own). |

For an ordinary executable flow, `prompt` / `prompt_es` are short UI labels, not intent instructions. For a Form/Performer declaration put them inside `form`. Other supported language variants use the corresponding language suffix.

A parameter descriptor has `name`, optional `type`, `description`, optional `enum`, `jsonSchema`, `internal`, and declaration-only `default`. Types are `string` (default), `boolean`, `number`, `integer`, `object`, `array`. A parameter map is also supported: a string value is a string parameter description; an object is its descriptor. `default` initializes its local variable and is omitted from extraction metadata. Preserve meaningful defaults such as an explicit confirmation-policy boolean. Do not copy generated `form_instance` bookkeeping into public parameters.

String `enum` values must be nonempty, trimmed and unique ignoring case. Extraction normalizes a case-insensitive match to the declared spelling and drops other values. An absent/invalid extracted parameter must still be collected. `internal:true` excludes a parameter from two-stage user extraction. `jsonSchema` supplies structured extraction shape; a form still validates its individual leaves. Public primary form fields with descriptions derive missing extraction parameters, including nested child schemas; declare aliases or narrower extraction enums explicitly.

Descriptions identify services and facts; caller-facing wording belongs in questions, SAY steps and fact renderers. Prefer focused handlers for distinct questions instead of one generic summary.

## 3. Expressions, variables and named JavaScript

Step expression strings are ordinary JavaScript expressions. `{{expression}}` interpolates a value into a message template. In a SET expression use the comma operator for multiple assignments, or call a named function; do not place bare semicolon-separated statements in an expression. Host-approved helpers and current flow variables are available in expressions. `cargo` is session-persistent state shared across flow boundaries, reboots and returns. It does not replace authentication or input validation.

An isolated flow receives its own declared variables/defaults and explicitly passed parameters, not arbitrary caller locals. Its local writes do not return to the caller; return domain results through declared cargo paths. Ordinary shared flow calls share the caller context by reference. Do not use `parameter || cargo.value` where false, zero or an empty value has a distinct business meaning; check the intended absence condition explicitly.

A function declaration is:

```json
{
  "declarationVersion": 1,
  "id": "calculate-total",
  "description": "Calculate the sum of the supplied item amounts.",
  "functions": {
    "total": {
      "description": "Sum the supplied item amounts without changing them",
      "parameters": [{"name":"items","type":"array"}],
      "body": [
        "let sum = 0;",
        "for (const item of items) sum += Number(item.amount);",
        "return sum;"
      ]
    }
  },
  "steps": [{
    "id":"calculate", "type":"SET", "variable":"noop",
    "value":"(cargo.total = fn.total(cargo.items), true)", "requireTrue":true
  }]
}
```

`functions` maps safe JavaScript identifiers to `{parameters, body}`. Each parameter has `name`, optional descriptive `type` / `description`, and optional `rest:true` on a rest parameter. `body` is an array of ordinary JavaScript source lines. Optional function `name` preserves its own recursion name when the registry key is an alias. Argument type annotations are descriptive; business validation remains explicit.

Use ordinary `if`, loops, local variables, arrays, objects, callbacks, `map`, `filter`, `reduce` and sibling function calls. This is not a restricted calculation DSL. Bodies are synchronous trusted developer code, compiled once for the loaded owner definition. Expressions call `fn.name(args)`; bodies can call siblings directly or through `fn`. Registered approved platform helpers are lexically available; callbacks may also be explicit parameters. Pass `cargo`, form state, request, result and other session values explicitly: functions do not capture a live session, caller variables or module imports. Function names are scoped to their declaring flow, plus the set's shared functions on version 2 flows. `fn` is reserved; do not declare a variable, parameter, global or approved helper with that name.

Use functions for pure business calculations and guarded session projections. External effects must use registered tools/action workers. Do not hide transport calls, new model selection or action authorization in a helper.

## 4. Ordinary executable steps

Each step has `type`, a stable `id`, and the applicable fields below. CASE/SWITCH branches and `onFail` contain one step object, never an array. Use a named worker when a branch needs several steps. Executing a branch does not terminate the following step sequence.

| Type | Fields and behavior |
| --- | --- |
| `SAY` | `value`, optional `value_es` etc.; append localized text until the next wait/return boundary. |
| `SAY-GET` | Same message fields plus `variable`; deliver accumulated text and wait for the next answer. Optional `digits`, `asSpoken`, `pii`. |
| `SET` | Evaluate `value`, assign to `variable`. `requireTrue:true` requires the result to be exactly true; expression failure must not be treated as success. |
| `CASE` | Ordered `branches` keys `condition: expression`, with optional `default`; first matching condition wins. |
| `SWITCH` | Evaluate `variable` once; select its value's branch, otherwise `default`. |
| `FLOW` | `value` target ID/name, `callType`, optional `parameters`; see control semantics below. |
| `CALL-TOOL` | Registered `tool`, `args`, result `variable`, and explicit `onFail`. |
| `END` | End only this flow; resume its caller after the FLOW call. A root simply finishes. |
| `RETURN` | End all stacks and return the evaluated `value` to the host. Empty string forwards this turn's original input to host AI/RAG. Queued SAY text is dropped unless `keepSay:true`. |
| `DISPATCH` | End all stacks, drop undelivered SAY text, and reroute this turn's input through primary intent detection. A match starts in the same turn; otherwise the host handles it with its conversation context. Optional `outcome`, `reason`, `recovery`. Contextual form: `onResponse:"continue"` with `responseContext`, `responseVariable` (a declared object), `responseParameters`, `responseChoices` (a declared array variable of `{key,label?,route?:"new_request",parameters?}`), `responseReasonFor` (a string; not with `responseChoices`), `responseConcern` (what the process does; offers the ranker `concern`), `responseConcernForm` (a form instance whose chain's `user_description` offers `concern`), `responseStay` (a declared boolean variable: while true, a new request is one more reply that picked nothing) and `onNoIntent:"stay"`. No other key is accepted. |

`FLOW.call` runs the child and returns to the next caller step. `FLOW.replace` replaces only the current frame; when the replacement ends, it returns to the original caller. A shared replace preserves existing variables; `initializeDefaults:true` fills declared target defaults only where a value is undefined. Versioned native builders set this explicitly. An isolated target always has its own declared context. `FLOW.reboot` clears all stacks and starts a new execution context with explicit parameters, preserving cargo. Queued SAY text normally travels with the reboot; `discardSay:true` drops it.

A `FLOW.replace` with `toParent: true` whose target flow declares `replaceTarget: true` returns to that flow's waiting frame and takes its place, dropping what ran above it. With either missing, or no such frame, it is a local replace. The validator refuses a loop holding a `call` (`stack_growth`) and a loop of replaces with no question in reach (`spin`); a flow on a loop that a runtime limit ends declares `loopBound: "<the limit>"`, and a test drives the loop to that limit. Use `call` for a closed sub-task and `DISPATCH` for anything the caller asked for.

A flow trap (a loop of flows with no question in reach, or a stack that grows with each answer) is a load-time validation error: it is listed in `state.errors`, and the engine still starts. Trap edges include form input form, validator, prepare, refresh, after, answer_precheck, answer_validator, on_no, on_declined; proposal prepare and on_declined; gate, source and action flow; parameters validate_flow, code_validator, answer_handler, failed_flow, cell_validator, email_validator, switch_reset (calls), restart (replace), retry_flow with retry_returns:true (replace). Not traps: a flow replacing itself, reboot, DISPATCH, loopBound, any path through a JSFE worker.

Every `FLOW.parameters`, `onFail.parameters` and `CALL-TOOL.args` value is interpolated by path only: `{{request.account}}` resolves, an expression resolves to ''. A value that is one whole `{{path}}` passes the value itself (object, array, number); a template mixed with text is a string. Compute expressions in a preceding SET or named worker. Provider `gateParameters` is an authoring convenience that lowers whole-expression templates to SET steps before the call.

`digits` on SAY-GET has `min`, `max`, optional `autoSubmitChars`, `autoSubmitMs`, and host-supported completion hints. A one-key answer must be exactly that key, not digits found inside a sentence. Direct `asSpoken:true` (or a condition string) preserves the original voice answer instead of digit reduction/AI cleanup. Use it for meaning-sensitive answers such as amounts; do not disable normal number/email cleanup indiscriminately. `pii:true` (or a condition) marks sensitive input for engine/host logging safeguards. FORM field spelling is `as_spoken`, not `asSpoken`.

An `onFail` SAY alone continues into the next step; route to an explicit terminating/recovery worker when continuation would be unsafe. The same is true of a SAY-only CASE branch. Transport retries must not repeat a charge or cancellation merely because a response was lost.

## 5. Forms and inputs

A form declaration has top-level common fields and `form:{inputs:[...]}`. Do not combine `form` with top-level executable `steps`. Form-specific options belong inside `form`:

| Option | Meaning |
| --- | --- |
| `inputs` | Ordered field/group/sub-form declarations. Order controls which ready missing field is asked next, not which fields may be accepted. |
| `before`, `after` | Ordinary step arrays before collection and after completed collection/confirmation. |
| `validator` | Whole-form validation worker, called with `{form,values}`. |
| `confirm`, `before_confirm`, `declined` | Confirmation descriptor, preceding steps and declined step array. |
| `confirmation_condition` | JavaScript expression deciding whether declared confirmation applies; default true. |
| `stop` | Internal condition used by the collection loop to stop a context service. |
| `close_on_stop` | Close that stopped service without returning an incomplete child value. |
| `resume_on_parent_change` | Owner corrections unwind a stale opted-in context and resume the changed ancestor. |
| `done` | Default true: complete through the shared form-done transition. False leaves deliberate orchestration to the author. |
| `prompt`, `prompt_es` | UI labels. |
| `incomplete_outcome` | Explicit business outcome fallback for incomplete optional followups; see recovery. |
| `on_exhausted` | Bounded recovery worker after validation attempts are exhausted. |
| `on_no` | Worker (called with `{form}`) for a whole NO at one of the form's questions, or a sub-form's, that the question does not read itself (not a yes/no, confirmation or proposal question, and no choice of it reads NO); the form then continues. A payment declares one that starts its selection again. |

Top-level `variables` provides extra form locals. JSFE creates instance IDs, saved arguments, values, validation and confirmation state; do not author copies of these bookkeeping fields.

A minimal collecting flow is:

```json
{
  "declarationVersion":1, "id":"collect-postal-code", "primary":true,
  "description":"Collect the caller's postal code for the requested service.",
  "form":{"inputs":[{"name":"zip","field":"zip","description":"The caller's postal code"}]}
}
```

Use one of these input shapes:

| Shape | Fields |
| --- | --- |
| Preset field | `name`, `field`; optional overrides. Presets: `phone`, `email`, `zip`, `account_number`, `ssn_last4`, `amount`, `street_address`, `city`, `state`, `card_number`, `card_expiration`, `card_cvv`, `card_zip`. `card_cvv` takes its card brand's length (`validate-card-cvv`: 4 digits for American Express, 3 for every other brand). |
| Inline field | `name`, `profile`, questions and business validation. |
| Child form | `name`, `form:"installed-child-id"`, optional `parameters`. JSFE links its schema; do not copy the derived `schema` into editable source. |
| Alternative group | `name`, `any_of:[leaf-or-child declarations]`; optional `exclusive:true`. At least one applicable member satisfies the group; exclusive competing answers require clarification. A ranked pick at the group's question is read as the answer of the member that offers that choice. |
| Bound requirement | `name`, `bind:"cargo.someVerifiedValue"`; a nonempty, non-false bound value satisfies it. A bound requirement is not a general text collector. |

Field options:

| Fields | Meaning |
| --- | --- |
| `label`, `label_es`; `question`, `question_es`; `retry`, `retry_es` | Names, first prompt and explicit retry wording. Contextual question templates compile to workers automatically. |
| `question_text`, `question_text_es`; `retry_text`, `retry_text_es` | Optional written-channel wording, used instead when the conversation is not a call (`cargo.voice` false). |
| `description` | Public extraction guidance; `response.description`, when used, describes an open answer. |
| `when` | Map paths to desired scalar values or arrays; siblings use field names, session paths use `cargo.*`, owner data uses `form.*`. Values prefixed `!` exclude that value. |
| `unless` | Paths whose populated, non-false value makes the field inapplicable. |
| `required_when` | Same condition map; a false evaluated condition makes a relevant field optional but still recognizable. Unknown dependencies block completion. |
| `depends_on` | Committed prerequisites for validation/preparation; their changes invalidate dependents transitively. |
| `reset_on` | Invalidate when these fields change, without creating a validation prerequisite. |
| `validator`, `validate_always` | Field validation worker; true explicitly revalidates unchanged values. A validator declaration may use `revalidate:true`. |
| `prepare`, `refresh`, `after` | Worker before initial validation/prompt, before each prompt, and after acceptance. |
| `choices_from`, `question_from` | Read prepared choices/question from the owner's `data`; corresponding localized question storage is handled by shared workers. |
| `digits`, `pii`, `as_spoken` | Collection hints. FORM preserves original speech by default; false explicitly opts into cleanup. |
| `confirm_against` | Declare overlapping field interpretations that require clarification even when normal current-field priority applies. |
| `activate`, `activate_on` | Narrow dormant activation: proposed controller assignments plus, for a subform, nominated descendant entry paths (`activate_on`). A dormant plain input declares `activate` alone and is its own entry: an amount said at "NEW CARD, LINK, or a different amount" chooses the amount option (`revised_amount` with `when:{next:'amount'}`, `activate:{next:'amount'}`). Controller and entry validate atomically; a rejected entry must not flip a controller. |
| `silent` | An accepted answer is not acknowledged. For an input that hands its value on to another form's input (its `after` flow), whose own acceptance or rejection is what the caller hears. |
| `response` | `{description}` on a readable leaf; use existing contextual DISPATCH extraction before accepting an open-ended answer. |
| `proposal` | Optional approval of an inferred field candidate, independent of final action consent. |
| `max_misses`, `max_attempts`, `on_exhausted` | Bounds for unreadable responses (default 4), validator rejections (default 3) and deliberate branch recovery. |
| `answer_precheck` | Flow called with `{answer}` before the choices are matched; an `answer_key` it sets is the answer's key (an answer that must not be read as a choice, such as a question). |
| `answer_validator` | Flow called with `{answer}` when an answer picks no choice; an `answer_key` it sets becomes `cargo.choice`, none leaves the answer handled as before. Fail-closed; it ends by completion (a RETURN ends the turn). |
| `route_keys` | `[{prefix,flow}]`: an answer key starting with `prefix` is handed to that flow, which takes the answer. |
| `accumulate`, `accumulate_first` | Digit inputs: a number said in groups across turns is kept and joined; short of `digits.min` the next question is "Go on.", and anything that is not digits drops the partial. `accumulate_first` is a regex the first group must match to start one. |
| `own_identifiers` | `true`: identifier inputs of other forms in the chain are not offered to this input's reader. |
| `declinable` | `true` on a readable leaf (not a choice, a confirmation or a proposal): the field may be answered "there is none". The whole answer saying so, in English or Spanish (`none`, `no`, `n/a`, `I don't have one`, `no tengo…`, `no hay…`, `ninguno`; never with a digit), stores an explicit `null`: answered, with no value, so the form moves on, while an absent key stays unanswered. The reply ranker is offered `none` at its question, and a read-back with `named_fields` offers it for correction. On a card the field may be left blank. A field that is never asked uses `required_when` instead. |

Profiles:

| `profile.kind` | Options |
| --- | --- |
| `choice` | `choices:[{key,phrases,label?,label_es?,keys?,exact?,neutral?,negative?,current_only?}]`; optional `accept_other`, `numeric_values`, `narrative`, `whole_phrases`, `template_words`. |
| `digits` | `min`, `max`: one unambiguous digit run of that length. |
| `identifier` | `pattern`: permitted account identifier shape. |
| `pattern` | `regex`, optional `flags`, `group`; optional `accept_other` for the current field only, `whole_phrases`, `template_words`; `spoken_digits` (`true`, or `'house_number'` when a numbered street can follow) reads a number said in pieces as one number ("5 0 9 Lazy Lane", "apt 2 0 4"), required on any pattern that reads digits. |
| `phone`, `email` | Typed readers; email `literal:true` preserves an explicit visible address token in surrounding prose. |
| `amount` | `min`, `max`, optional `marked:true` or `marked:"out_of_order"`; optional `money:{currency:"USD",cardinals:true,intent:"payment"}`. |
| `text` | Current-field text fallback; `narrative:true` retains a substantive answer alongside independent structured fields. |

`phrases` is the authoring name for matching aliases; `description` explains their meaning to parameter extraction only. For the reply ranker a choice is its `label`, or else its key and first six phrases, so write a `label` when the phrases do not convey the option; there is no rank attribute. Do not duplicate `words` / `gloss` aliases in new source. Historical executable definitions remain readable with those old keys; new names take precedence.

Matching depends on policy. With `exact:true`, a phrase must form the whole normalized answer, allowing the engine's bounded courtesy/affirmation wrappers; questions and additional substantive corrections do not consent. Thus exact `here` does not accept `pay here`. Without exact, ordinary positive named choices may match within an unnegated clause: do not assume whole-answer matching. Keypad aliases, YES and NO-type answers have stricter rules regardless. `keys` are current-field-only whole-answer keypad aliases; they must not steal a monetary answer or identify a different field. `neutral` is not consent. Use exact choices for sensitive finite decisions.

JSFE resolves valid current-field evidence first, then a unique match in the nearest owning form, then ancestors; genuine competing claims are clarified. Independent spans can fill independent fields. Typed evidence outranks arbitrary text. `confirm_against` deliberately retains ambiguity. A child result uses the same acceptance/invalidation transition as a leaf. Pending dependent candidates wait for valid prerequisites; invalid data cannot authorize an action. Narrative mode does not turn fragments or bare structured identifiers into business explanations.

### Context-aware acceptance

A caller answers out of order, often several fields at once. That ability is kept, and every out-of-order answer is
validated against its context: an answer fills another question's field only where it is relevant there. These are the
standard rules for every form; the declarations below tell the engine what each field is.

Declarations:

| Declaration | Meaning |
| --- | --- |
| `confirmation:"firm"` / `"soft"` (an input, a form's `confirm`, a proposal policy) | A yes/no decision; declared, it is definite; absent, firm only for a payment. Firm: YES only by `CONFIRM_WORDS` or the option's own exact phrases. Soft (an offer): the wider YES vocabulary. NO by the NO vocabulary or the option's own phrases. |
| input `invites:[names]`, `form.confirm.invites` | The other inputs this question (or the read-back) also asks for ("NEW CARD, LINK, or a different amount" invites `amount`), in its form or an enclosing one; read as in order while it is asked. |
| profile `out_of_order:{…}` | A narrower signature for out-of-order reading: the payment card takes a bare last four when asked, but out of order only a card word or "ending in 4242". |
| `authenticate-user` `other_whole_answer:true` | At the code question "another account" switches only as the whole answer; inside a sentence the reply ranker decides, offered `another_account` and `no_other_account` ("I understand. We still need to secure access to your account.", then the question). Default off. |
| input `confirm_out_of_order:{word,word_es,message,message_es}` | Out of order a number fills this input only beside its `word`, in either language. Alone, the caller hears `message` (`{value}` is the number, `{word}` the word) and the current question again, which counts as an attempt. `authenticate-user`'s `code_confirm` is the same declaration for a `code_validator`, whose flow reads it with `saysConfirmWord` and `confirmOutOfOrderLine`: an account number at the verification-code question, where it may be a code said with an extra digit. A pattern field's `asked_regex` also reads out of order beside the word; the field asked now wins over a refused number. Card presets: expiration, security code and billing ZIP. |
| profile `refuse_amount_shape:true` (digits) | Out of order, three digits then two ("119 19") fill nothing: they read as dollars and cents. At its own question they read as the field. The `zip` and `card_zip` presets declare it. |
| `digits: {min,max}` with `length_message` / `length_message_es` | At its own question (a `digits`, `phone` or `identifier` field; a pattern field reads only what it matches), one number of 3+ digits whose length is outside `digits`, read by no other field: a reading of the field, rejected with "{heard} digits; it has {lengths}", said with the re-ask. The declaration is the opt-in; the length presets declare messages. |
| input `choices_from` | The choice's values come from prepared data (the caller's saved cards), so its signature is those values. |

Rules, in order:

1. **The current question first.** The whole answer is read against the current input's signature and the inputs it
   invites (an invited input with its asked signature, not its out-of-order one). A match is that answer. A bare number
   whose length is the current input's keypad length (`digits`) is its answer even when its reader rejects it: its
   validation decides and the question is asked again, so an expiration "1320" (month 13) is never a security code.
   A choice keeps rule 4, and an amount is read by its own profile.
2. **A confirmation is answered only when it is asked.** Out of order it never makes sense, so no words, YES, NO or the
   option's own phrases, fill a confirmation that is not the current question.
3. **Out of order requires a ready field and the whole signature.** A bare number never fills, out of order, a field whose
   `depends_on` prerequisites are not filled yet (the sub-account before the account is known); a named answer ("50
   dollars") still waits as a pending value. **The whole signature:** A digit field takes a number only when the whole number fits its
   length; a pattern only when it covers the whole number; a choice only its declared or prepared values. A fragment of
   a longer number (the last four of "88 91 7112") fills nothing. **A perfect match:** a number read out of order accounts for every digit
   of the answer, alone or with the other fields a compound answer fills. "0 4 guion 31, 0 31" at the expiration fills no ZIP;
   "the line is 8185551234" fills the phone. Its validation decides too: a number its validator rejects fills nothing and says nothing, and the question
   is asked again.
4. **A bare number** (no money mark, no word naming a field) is an amount only at a question that is, invites or is
   declared `confirm_against` an amount. A single digit the question offers as a key is that key; one it does not offer reaches the invited amount,
   whose validation decides. The engine holds no amounts, so "only a known amount" is the amount validator's rule: a retail tenant's
   takes a bare number at the amount question, and at a question that only invites an amount only when it is an amount the
   caller can pay (else it asks for it in dollars). A bare number that does not fit the current question is
   read out of order under rule 3.
5. **Compound answers.** Several fields fill from one answer only through the form's compound parser, or when every
   part of the answer fits exactly one field. **One part of an answer never fills two fields**; the engine refuses that
   reading and records the refusal.
6. **Scope.** Across forms the nearest form wins; two fields of the same form that fit the same part are asked about,
   never ranked. A number that fits two fields out of order is asked about wherever they are.

Every result records why: `decisions` lists each field filled other than as the current answer with its rule (`invited`, `out_of_order`, `compound`), and every
refused reading is listed with its rule, so hosts can log what was filled out of order and what was refused.

## 6. Validation, reentry and contextual uncertainty

A field validator receives `{form,input,value,values,reading}` and writes `cargo.inputCheck={ok:true,value?}` or `{ok:false,message?,message_es?,quiet?}`. Missing/malformed results fail closed. Activation values and conversational answers use the same validation path. A rejection counts an attempt (`max_attempts`, default 3). Its message (default "That {label} doesn't look right." / "No pude usar eso como {label}.") is said only in front of the next question a form of the same task asks this turn; a form that gives up, yields, exhausts or leaves by DISPATCH never says it. `quiet:true` says nothing and still counts the attempt. A number read out of order that its validator rejects is ignored: no attempt, no line. `value` may normalize a valid input; never return success for a refusal to satisfy an effect's prerequisites.

A whole-form validator writes `cargo.formCheck={ok:true}` or `{ok:false,invalid:[{name,message?,message_es?}],message?,message_es?}`. Only declared fields may be rejected. The shared loop invalidates the affected branch and reasks; it does not discard independent valid fields. The form-level message is said once, in front of the first re-asked question; a per-input `invalid[].message` is shown only on a form card. A fourth invalid verdict exhausts the form (`on_exhausted`, else an optional incomplete outcome, else give-up) with no message.

State lives in `cargo.forms[opaqueInstance]`, owned by a root task or `(parent instance,input slot)`. JSFE maintains values, accepted proofs, pending candidates, dependencies, revisions, attempts, children and confirmation. `cargo.formTasks` identifies active root tasks. Internal `form_instance` resumes saved arguments and progress; context services use `parent_form` without a result slot. Do not write accepted values, approval tokens, revision counters or stack snapshots directly. Use business callback outputs and the shared acceptance path.

The loop skips accepted data and asks the first ready missing required field. Corrections invalidate dependent evidence and confirmation. With nested tasks, preserve the actual parent/slot rather than using a definition ID as an instance. Do not fabricate a completed child value when it stops, fails or yields.

### Retry, yield and recovery

An unreadable answer with any words goes to the reply ranker, offered the question's choices (`exact` ones too, since `exact` is how words match a choice; never the YES of a firm confirmation; a NO always) and a person (`__agent`), never text (the words and keypad key for text are read before it): a picked choice is the answer, a person is taken, a reply that picks none is asked again (counted against `max_attempts`); only `abort` or `new_request` leaves the form. `max_misses` (default four) bounds unreadable answers without words (symbols, an unexpected keypad entry): clarify each with explicit retry text or a localized “Sorry, I didn't catch that.” prefix; yield the fourth utterance to DISPATCH while preserving the draft. A form confirmation's unread answers are ranked the same way (offered NO always; YES only for a soft confirmation); after four, the `give-up` worker takes over. Validator failures use a separate `max_attempts` budget (default 3). An out-of-order accepted answer is not a miss. On exhaustion the nearest declared `on_exhausted` receives `{form,input,failed_form,failed_input,reason:"attempts_exhausted"}` and must deliberately recover that branch; it does not receive consent.

`user_description` / `user_description_es` on a form (jsfe 1.42.0): one sentence saying what the process does, written with the engine's own `{{...}}` expressions, every input of the form in scope ('' until answered) and its data ("This process allows you to change the delivery address or delivery date for your order.{{change === 'address' ? ' You chose to change the delivery address.' : change === 'date' ? ' You chose to change the delivery date.' : ''}}"). The nearest form in the chain declaring one is used. The form's readers then offer the reply ranker `concern`; a caller who expresses doubt that the process is what they need hears the sentence, "To cancel, press the asterisk key or say EXIT." (text: "To cancel, type EXIT."; Spanish SALIR) and the question again, with no attempt counted. Declare it where a caller may mistake what the flow is doing; it applies to every question of the form and its sub-forms, so word it for all of them.

**Global keys (jsfe 1.42.0).** A whole answer `*`, EXIT, QUIT or SALIR ends every flow at any question and starts `global-exit` (default: "cancelled at your request" and an offer of more help, thanks when resolved; a tenant overrides it with a flow that `wraps: "global-exit"`). On a call a whole answer `9` starts `switch-to-text` when the caller can be texted. Never write a local handler for these; to give a question its own meaning for one, declare it as a choice (key or phrase): a declared choice takes the answer. CANCEL is not an exit word.

**Yes/no keys.** Every yes/no question names 1 for YES and 2 for NO on a call; word it with `yesNoKeys(lang, cargo, yes?, no?)` rather than by hand: voice "Press 1 or say YES to submit it, or press 2 or say NO.", text "Type YES to submit it, or type NO." (Spanish SÍ, "Presione 1 o diga", "escriba"). `channelVerb(lang, cargo, capital?)` gives the verb alone: the host's `cargo.verb` / `cargo.verb_es`, else "say" on a call and "type" elsewhere. On a form confirmation, key 1 confirms and key 2 declines on every channel.

`must_complete:true` on a form (inherited by every field of it and of the forms nested in it) or on one field (`false` on a field opts out): an unreadable answer is never yielded to DISPATCH, however long, and neither is a confirmation miss or an unresolved ambiguity — the question is asked again, acknowledged. A worded reply always reaches the reply ranker, offered every choice the chain's reader accepts: a pick is taken, a clear withdrawal ends the flows, and any other verdict (a new request included) stays and says `first_task` / `first_task_es` from the nearest form declaring it, "I understand, first let's enter your new card details." / "Entiendo, primero vamos a ingresar los datos de su tarjeta nueva.", then the field's `retry` or its question. It uses no attempt. Use it where leaving would strand an effect in progress (a payment's card, its billing-ZIP correction). Other exits stay explicit: the form's stop words, `max_attempts` with `on_exhausted`, and whatever the host intercepts before the engine. The form runaway guard counts passes without a caller answer only.

`confirm.named_fields: true` lets a caller correct a read-back in their own words: each input of this form that declares `names` and holds a value is offered to the reply ranker, and a pick extracts the new value of every such input, so one reply can change several. `confirm.reply_context` tells the ranker and the extraction what a reply may contain (never spoken); an input's `argument_description` says what its value looks like ("apartment or unit number alone, such as 4 or 12B"). A reply the word readers only partly account for goes to the ranker, so none of it is lost.

`whole_phrases: true` on a `choice`, or on a `pattern` that reads words: a word reading picks only when the whole reply is accounted for by its phrase, another input's argument (digits, an amount, a card), courtesy, connecting words and the input's `template_words` ("pay $50 with my Visa card"). Anything else goes to the reply ranker, offered the choices as above. Keypad keys and digit readings are arguments and read as before. Off by default.

A choice marked `current_only` is read only at its own question: neither the word reader nor the reply ranker offers it while another question is asked (a route's `done` or `switch` is never picked for a NO or a sub account said at the amount question). Written cents (`72.45`, `$72.45`, `287,15`) are an amount by shape: out of order they fill an open amount, and beside another field's reading (`51:72.45` at a sub account question) they are that amount, never digits of a security code or ZIP code.

Use `response:{description}` for open descriptions that need a model's interpretation. The prepared question and field description become the contextual DISPATCH question, and the reply ranker decides what the reply does: an answer is extracted and still passes deterministic validation (missing usable data yields with progress saved); a withdrawal leaves for the host; a new request routes through intent detection. No separate field classifier/model role is needed. Do not attempt exhaustive conversational inference with keyword lists. A field that asks why the caller does not want something (a cancellation's reason) adds `reason_for` (the words) or `reason_for_from` (a form data key) to its `response`, so the ranker is offered no withdrawal there ("I don't use it" is the reason); the flow must confirm the request before acting.

Ordinary DISPATCH is the default uncertainty escape. An explicit contextual DISPATCH may additionally declare the following step fragment (its surrounding flow must declare the response object and supply its own input/recovery steps):

```json
{
  "id":"interpret-reply", "type":"DISPATCH", "onResponse":"continue",
  "responseContext":"Ask about the shown products or describe a different product.",
  "responseParameters":[{"name":"asked","type":"string","enum":["stock","price","search"],"description":"The requested operation"}],
  "responseVariable":"response"
}
```

Declare `response` as a local object variable. A single open string parameter whose words are the value (a reason, a description) may add `"verbatim":true`: a confident `answers` then keeps the reply as said when extraction finds nothing. Never mark a field that names something to look up (a product, a city). The reply ranker answers `answers`, `abort`, `new_request`, `irrelevant`, or `concern` when the step declares `responseConcern` (a string, interpolated: what the process does) or `responseConcernForm` (a form instance: its chain's `user_description`, rendered by the engine); the flow reads `{concern:true, concern_text}` and explains (a cleared `new_request` outranks it; nothing clear is `answers`; `irrelevant` extracts nothing and the question is asked again). `responseChoices` names a flow variable holding `[{key,label,route?,parameters?}]`: the ranker is also offered `choice:<key>`. A pick sets the response variable to `{key}`, plus `also` (other declared choices the reply clears at 0.6, by score) when there are any, plus `arguments` when the choice declares `parameters:[{name,type,description}]`. `route:"new_request"` makes a pick leave like a new request. `onNoIntent:"stay"`: a `new_request` that intent detection routes to no flow is an answer to this question, and the flow continues. `answers` retains the live continuation and runs the following recovery steps; an optional typed response writes a cloned normalized object before continuing. `new_request` routes the input through intent detection; `abort` ends every flow as a RETURN with the reply `cmd_request_aborted` and outcome `user_aborted` (no recovery stamp). Neither writes that response object. Typed contextual v1 permits primitive string/boolean/number/integer fields, not object/array/jsonSchema. Missing fields remain missing. Errors preserve the pending step and prior object. Context is supplied to that decision without overwriting saved conversation history. This is existing configured intent/extraction, not authorization and not a snapshot restore.

**A form question's values in a free-form sentence** (jsfe 1.36): declare `rank_parameters` on the input (extracted when the ranker says the reply answers), `parameters` on a choice (extracted when it is picked) or `confirm.rank_parameters` (at the form's confirmation), each `[{ name, description, type?, reads? }]`. Each value is read by the form's readers as if said alone: `reads` names the input it answers, else it answers the asked question. Never a DISPATCH of your own for this. Details and rules: architecture-guide.md, "Arguments in free-form answers".

## 7. Providers

Declare a catalog once in top-level `provides`, including on a Form/Performer that answers related questions. JSFE derives the public `asked` parameter and mid-form question catalog. Do not maintain a second vocabulary.

| Catalog field | Meaning |
| --- | --- |
| `subject`, `subject_es`, `name_path` | Human subject and optional cargo path for the person's display name. |
| `default` | Fact/set key when no explicit question was supplied. |
| `gate:{flow,verified:[paths]}` | Authentication worker and truthy verification paths required before private facts. |
| `source:{flow,result,subject?,refresh?}` | Retrieval worker, cargo result path, optional owner identity path; `refresh:"per_turn"` requests refresh on each turn. |
| `facts` | Nonempty list of fact definitions. |
| `sets` | `{key,description?,phrases?,facts:[factKeys]}` for related groups of facts. |
| `menu` | Optional post-answer menu with localized questions, choices and done policy. |

A fact has unique `key`, `description`, optional `phrases`, and a `path` within the loaded source or a dedicated `flow`. Optional `public:true` marks genuinely public data; private catalogs need an explicit gate. Presentation uses `label`/`label_es`, `say`/`say_es`, `missing`/`missing_es`, and `format`. Never invent a source value when absent. Money, date, digit and last-four renderers are presentation, not validation or permission.

Supported simple `format` names include `money`, `money_nonzero`, `date`, `date_no_year`, `last4`, `digits`. An object format maps result properties to format names. List format uses `{type:"list",item,item_es?,fields?,join?,join_es?}` with `{items}` / `{count}` in the outer template; optional `say_one` / `say_one_es` handles one item. Templates use `{value}`, named result properties and supplied `{name}` / `{label}`. Bracketed optional segments can provide alternatives separated by `|`.

`menu` supports `question`, `question_es`, optional voice variants, and `choices:[{key,phrases,exact?,flow?,set?}]`. `set` applies declared cargo assignments before an action route. `menu.unanswered: {asked:[catch-all keys],choice,question,question_es}` (off by default): a reply from this menu that intent detection sends back to this provider, when the ranker found no fact or `asked` is a listed catch-all, gets that question instead of the facts again, followed by `yesNoKeys` (so `question` must not word the keys); YES runs the named menu choice, NO returns to the menu, anything else is DISPATCHed. `menu.whole_phrases: true` (off by default): a fact's phrase answers only as the whole reply; a phrase inside a longer sentence goes to the reply ranker, offered every fact, action and `done` (each by its `label` or a fact's `description`, else its key and phrases) and a person. A pick is taken, and every other fact the reply clears at 0.6 is answered with it. A reply that picks nothing goes to the host, without intent detection, so the Guru answers from the account in its user context; `new_request` goes to intent detection. A reply with no phrase is a plain DISPATCH, as before. `done` supports `phrases`, `say`, `say_es`. Keep whole-answer terminal phrases such as “no thanks” separate from a neutral “no” that offers further help. Facts take priority; a declared terminal answer must not be shortened into a different action. Test following-turn choices and facts, not just direct `asked` activations.

The shared `provide-data`, `load-source`, `answer-facts` and provider-menu workers gate, load and answer only the requested facts. Top-level `gateParameters` may pass literal data or whole-expression templates to the gate. Refresh clears old results before loading and records freshness only on success. `no_gate` may avoid rerunning a gate only while all declared verification paths still hold. It cannot grant access. Mid-form provider questions preserve the owner and pending verification instead of stacking repeated authentication tasks.

### Provider example: account-info

This reduced **composed-registry fragment** uses the existing account-info worker contract: the source produces `cargo.accountInfo.due.amount`. It is not a standalone flow set. Include the real `account-info-gate` and `account-info-load` definitions and their tool dependencies in the installed sets or final output; use a different source path only when its actual output contract declares it.

```json
{
  "declarationVersion":1, "id":"account-info", "name":"AccountInfo", "primary":true,
  "description":"Answer questions about the verified account amount due; not an instruction to make a payment.",
  "provides":{
    "subject":"account", "default":"due",
    "gate":{"flow":"account-info-gate","verified":["cargo.otpVerified","cargo.authenticatedAccount"]},
    "source":{"flow":"account-info-load","result":"cargo.accountInfo","subject":"cargo.accountNumber","refresh":"per_turn"},
    "facts":[{
      "key":"due", "description":"The payment currently required, not the entire remaining balance",
      "phrases":["amount due","monto por pagar"], "path":"due", "format":{"amount":"money"},
      "say":"The amount due is {amount}.", "say_es":"Lo que tiene por pagar es {amount}."
    }]
  }
}
```

## 8. Performers, confirmation and results

A Performer requires `form`, nonempty `performs`, `prepare` worker and `present` worker; optional `project` is a SET-step array. Each action declaration supports:

| Action field | Meaning |
| --- | --- |
| `action` | Stable business operation name. |
| `effect` | `read`, `send`, `write`, `charge`, `cancel`, `handoff`. |
| `when`, `unless` | Applicable action conditions; more than one selected action is an error. |
| `subject` | Ownership path such as `form.data.account` or `form.data.subject`; bind account/service identity, not an unrelated session flag. |
| `gate:{flow?,verified:[paths]}` | Execution-time verification; rerun the declared flow before each fresh effect. |
| `flow`, `tool` | Installed executor worker and/or registered tool identity. |
| `confirm:{exact:true}` | Binding, not firmness. Required for charge, cancel or `reversible:false`, and it requires a real form confirmation question. At execution the action runs only if the recorded confirmation matches the form's current revision, its current values and this action's proposal (request and subject); any change after the YES refuses the action until it is confirmed again. It does not change how the YES is read: that is the form confirmation's `confirmation` (`confirm.confirmation`, see the row on `confirmation` above), which, when not declared, is firm only when an action the form performs has `effect:"charge"` and soft otherwise (a cancellation included). |
| `outcomes` | Map declared executor statuses to business outcomes, including unknown results. |
| `retry` | Explicit policies: `after:[knownStatuses]`; unknown retry only for SEND with `unknown:"explicit"` and a new accepted recovery choice. |

The prepare worker receives `{form}` and writes `cargo.actionRequest` with the exact request. JSFE selects the applicable action, binds request/subject/current input revision, obtains required confirmation and guards execution. An executor returns its normalized business result through `cargo.operationResult`; transport adapters use `{transport:"ok",value}` or the declared failure path. Native execution must distinguish success, explicit refusal/failure and unknown completion. Do not claim success from a timeout, a missing status or a later balance change.

`form.confirm` contains localized `question`, `question_es`, an optional `confirmation` (`"firm"` or `"soft"`; absent, firm only when an action has `effect:"charge"`), optional additional affirmative `phrases`, `clarifications`, `no_keys`, and `interrupts:[{key,phrases,flow,exact?}]`. The default NO key is `2`; override only for a deliberately declared menu. Clarifications ask for explanation without consenting. Interrupt workers receive `{form,event,text}` and must reenter ordinary validation after corrections. An answer containing YES plus a correction or unrelated request is not approval of the old request.

An input `proposal` separately asks whether an inferred field value is correct. It is legal only on readable leaves, not group/child/bind nodes. Options are static confirmation fields, `prepare`, `origins:["activation","answer"]`, `when`, `unless`. Its prepare worker receives `{form,input,value,values,reading}` and writes `cargo.proposalCheck` to a confirmation descriptor or explicitly null. A validator may instead return `proposal` inside a successful input check. A descriptor supports question(s), `binding`, affirmative `phrases`, NO keys, clarifications, interrupts and `on_declined`. Missing or malformed decisions fail closed. Field approval is bound to owner, revision, value and business binding; validation reruns before acceptance. It never authorizes the final action. NO cannot commit the candidate; yield cannot be treated as NO.

Projectors update session facts/ledgers after execution and during late-result recovery. `project` allows only SET expressions with local temporary destinations; no tool, FLOW or message steps. Available expression locals are `form` (instance ID), `formSnapshot`, `request`, `result`, `key` and current `cargo`. Use named functions, preserve ownership, return true where your projection wrapper requires it, and make ledger changes idempotent by action key. A detached recovery projector receives the recorded snapshot but writes current cargo; it must not replace newer tasks with old state. Projection failure prevents receipt consumption. The presenter receives `{form,request,result}` and owns customer wording and optional next steps. Do not reread an unrelated nested performer's shared last result.

Use the same generic registered execution adapters across performers. Generated `operation:<tool-id>` workers are ordinary executable definitions: include them in the tenant/shared JSON set when referenced. Do not generate missing executors from a guessed tool name at runtime.

### Performer example: make-payment

This reduced **composed-registry fragment** illustrates action authoring, not a replacement payment implementation. Its real `payment-prepare` worker must set `form.data.account`, build the validated complete request in `cargo.actionRequest`, and prepare the confirmation question. `payment-execute` and `payment-present` must be supplied with their actual registered payment tools and normalized outcome contracts. A complete payment form also declares its account, method, card and other required inputs; do not infer those values or tool result paths from this example. `get-account` is the existing verification worker.

```json
{
  "declarationVersion":1, "id":"make-payment", "name":"MakePayment", "primary":true,
  "description":"Make a requested account payment after verification and exact confirmation; not a report of an earlier payment.",
  "form":{
    "inputs":[{"name":"amount","profile":{"kind":"amount","min":0.5,"money":{"currency":"USD","cardinals":true,"intent":"payment"}},"question":"How much would you like to pay?"}],
    "confirm":{"question":"{{cargo.paymentConfirmation.question}}","question_es":"{{cargo.paymentConfirmation.question_es}}"}
  },
  "performs":[{
    "action":"tenant_payment", "effect":"charge", "subject":"form.data.account",
    "gate":{"flow":"get-account","verified":["cargo.otpVerified","cargo.authenticatedAccount"]},
    "flow":"payment-execute", "confirm":{"exact":true},
    "outcomes":{"ok":"resolved","failed":"unresolved","unknown":"unresolved"}
  }],
  "prepare":"payment-prepare", "present":"payment-present",
  "functions":{
    "recordOutcome":{
      "parameters":[{"name":"cargo"},{"name":"result"},{"name":"key"}],
      "body":[
        "if (!key) throw new Error('Missing action key');",
        "cargo.paymentOutcomes ||= {};",
        "if (!Object.hasOwn(cargo.paymentOutcomes, key)) cargo.paymentOutcomes[key] = result.status;",
        "return true;"
      ]
    }
  },
  "project":[{"id":"record-outcome","type":"SET","variable":"noop","value":"fn.recordOutcome(cargo,result,key)","requireTrue":true}]
}
```

The action key makes this session projection idempotent; it does not make the payment API idempotent. Where the API accepts an idempotency key, pass one as a tool argument. Either way an unknown result is held, never repeated: the engine claims each confirmed action once, treats a status outside `outcomes` as unknown, and never retries an unknown charge or cancellation. A recorded ledger entry does not prove a charge succeeded.

## 9. Outcomes, recovery and persistence

A terminating step may declare interpolated `outcome` / `reason`: `resolved`, `unresolved`, `deflected`; shared contextual yields use `pending`. Empty interpolation declares nothing. Outcome is business status, not automatic permission or proof of an external effect. Ordinary uncertainty must not be falsely declared “failed; start over.” Optional post-completion forms can retain completion with `incomplete_outcome:{outcome:"resolved",reason:"payment_made"}` or `{from:"declaredObjectParameter"}`. This cannot complete required inputs or authorize effects.

Optional step `recovery:{version:1,mode,reason,form?,flow?}` gives host guidance. Modes are `resume`, `restart`, `hold`, `none`; resume requires a real retained owned form and its definition. The engine validates it and exposes a one-turn `lastFlowRecovery`. A matched DISPATCH consumes the old outcome/recovery; a no-match handoff preserves it. Only explicit restart promises starting over. An attempted/unknown effect needs hold, never retry advice. Metadata does not execute recovery by itself.

### Action persistence

Durable is the default native action persistence mode. The host must provide its journal/storage and pass `assertFlowHostCapabilities`. A host may explicitly choose `engine.actionPersistence="session-only"`; both modes retain confirmation, ownership, revision, subject and session action guards. A separate `durableActions` requirement cannot be satisfied by session-only. Missing required support rejects activation; intrinsic `jsfe:*` protocols cannot be enabled by arbitrary host booleans.

Session-only protects persisted, serialized session progress from reentry/repetition. It does not protect against a successful external effect followed by loss of the updated session, or concurrent forks of an older snapshot. Durable storage and/or recoverable backend idempotency is needed for that failure boundary. Unknown charges/cancellations must never be automatically repeated in either mode.

With a durable journal, the host saves the returned full session before acknowledging exact versioned action receipts with `checkpointActionSession`. Failed saves do not release scopes. Compatible late results project into current state without replaying presenters or restoring an old workflow merely because their storage sequence is larger. Recovery identity binds verified runtime bytes and actual flow/tool contracts; a version string alone is insufficient. Identity mismatch, unresolved effects or failed projections preserve holds. Do not change persistence mode for a live conversation or clear holds to manufacture compatibility.

For versioned JSON, JSFE generates each declaration's continuation revision from its `version` major, plus the `version` major of each shared data or functions entry it uses (`$data`, `fn.`). Do not author `safetyRevision`. A minor or patch change keeps the revision: a saved session continues on its saved steps. **A change that can break a saved session bumps the major** (a removed or renamed input, entry argument, shared data or function name, or a changed meaning under the same name); the next turn of a session saved under the old major retires its unexecuted continuation before new input, and uncertain effects remain preserved/quarantined. `continuationBreaks(previousFlows, nextFlows)` (`jsfe/forms`) lists the removed names that need a major bump; run it against the deployed set before every deploy. A session saved under the earlier fingerprint revision (the whole declaration) continues while its declaration is unchanged. This is change detection, not authentication or automatic hot reload. Ordinary executable flows can explicitly use the SDK's revision helper when their host owns that policy.

## 10. Matching tools JSON

Every CALL-TOOL/action tool ID must exist in the composed tools array. A tool declares `id`, `name`, `description`, its input `parameters` JSON Schema (or supported `schema` form), and `implementation`.

| Tool field | Meaning |
| --- | --- |
| `parameters` | `{type:"object",properties,required?,additionalProperties?}`; properties describe actual arguments. |
| `implementation.type:"local"` | `function` names a host-approved function; no arbitrary function imports. |
| `implementation.type:"http"` | `url`, `method`, optional `headers`, `contentType`, `pathParams`, `queryParams`, `authentication`, `timeout`, `retries`, `responseMapping`. Credentials belong to approved host configuration. |
| `implementation.acceptStatus` | Listed non-2xx statuses are business answers: parse/map their body and let the flow inspect it. Other failed statuses follow onFail. |
| `returns` | JSON Schema of the value delivered after responseMapping. Read it to use real result paths. Optional host validation warns on mismatch without rewriting the result. |
| `security.rateLimit` | `{requests,window}` when supplied by the host contract. |

`responseMapping` supports `jsonPath` (`mappings` of target names to `{path,transform?,fallback?}`), `object` (`mappings`), `array` (`source`, optional `filter`, `itemMapping`, `sort`, `offset`, `limit`, `fallback`), `template` (`template`, optional `dataPath`) and `conditional` (`conditions:[{if,then}]`, optional `else`). Use the actual tool schema/mapping supplied by the host; do not guess backend result fields or invent transform functions. Preserve explicit failure and unknown-result behavior. Native contract validation requires CALL-TOOL to have an onFail route.

## Reference delivery

The canonical package file is `jsfe/docs/copilot-reference.md`. In hy-rag-lambdas, `foundation/copilot-reference.js` caches the reference for ten minutes, resolves the latest published JSFE version through npm, retrieves that version's immutable jsDelivr file, and retains the last successful copy in S3 as fallback. A local documentation edit is not active in the backend until JSFE is published and the loader retrieves it. Changes to the backend CoPilot output schema separately require a host deployment. Match generated definitions to the runtime and shared sets actually installed; publication of this reference does not upgrade them.

## 11. Authoring and debugging checklist

1. Specify the primary's intent boundary and extraction semantics, using supplied host/tool contracts. Keep authentication distinct from website login and requested facts distinct from actions.
2. Compose an existing shared field/sub-form/provider/executor before adding a tenant copy. Put the complete new tenant definitions and functions in its JSON pair.
3. Declare dependencies, ownership, business validators, refusal handling and exact action consent. Keep uncertain conversation with DISPATCH and the host's full context.
4. Test actual loaded JSON: happy path, following-turn menus, out-of-order fields, corrections, wrong input, decline, provider/authentication detours, duplicate requests and unknown effects. Assert tool calls and zero unintended effects, not just wording or inventory counts. Use focused tests for a scoped change; broader acceptance must be explicit and source-bound.
5. Validate composed references/tools and execute with matching runtime/helpers/shared sets. A successful compiler or exported function unit test does not prove the deployed prompt or journey uses that definition.

For debugging, `explainSession(session,{flows,previous?})` reads existing state and identifies the author component, active worker/step, missing input, confirmation, handoff and action hold. An optional previous snapshot adds changed field names without collected values. It is a snapshot/difference, not an event log, authorization decision or extra model role. An empty stack does not prove success. Keep source definitions editable, loaded definitions immutable, and session bookkeeping inside JSFE.
