behavior-contracts 0.11.4 → 0.11.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/authoring.d.ts +16 -6
  2. package/dist/authoring.d.ts.map +1 -1
  3. package/dist/authoring.js +6 -2
  4. package/dist/authoring.js.map +1 -1
  5. package/dist/behavior.d.ts +37 -6
  6. package/dist/behavior.d.ts.map +1 -1
  7. package/dist/behavior.js +62 -13
  8. package/dist/behavior.js.map +1 -1
  9. package/dist/builder.d.ts.map +1 -1
  10. package/dist/builder.js +21 -8
  11. package/dist/builder.js.map +1 -1
  12. package/dist/cli.js +11 -2
  13. package/dist/cli.js.map +1 -1
  14. package/dist/commands/codegen.d.ts +11 -2
  15. package/dist/commands/codegen.d.ts.map +1 -1
  16. package/dist/commands/codegen.js +11 -14
  17. package/dist/commands/codegen.js.map +1 -1
  18. package/dist/commands/ts-compile.d.ts +1 -7
  19. package/dist/commands/ts-compile.d.ts.map +1 -1
  20. package/dist/commands/ts-compile.js +45 -14
  21. package/dist/commands/ts-compile.js.map +1 -1
  22. package/dist/commands/ts-extract.d.ts +0 -2
  23. package/dist/commands/ts-extract.d.ts.map +1 -1
  24. package/dist/commands/ts-extract.js +0 -4
  25. package/dist/commands/ts-extract.js.map +1 -1
  26. package/dist/generator/async-plan.d.ts.map +1 -1
  27. package/dist/generator/async-plan.js +2 -1
  28. package/dist/generator/async-plan.js.map +1 -1
  29. package/dist/generator/core.d.ts +35 -2
  30. package/dist/generator/core.d.ts.map +1 -1
  31. package/dist/generator/core.js +50 -2
  32. package/dist/generator/core.js.map +1 -1
  33. package/dist/generator/emit-php.d.ts.map +1 -1
  34. package/dist/generator/emit-php.js +4 -3
  35. package/dist/generator/emit-php.js.map +1 -1
  36. package/dist/generator/emit-python.d.ts.map +1 -1
  37. package/dist/generator/emit-python.js +4 -3
  38. package/dist/generator/emit-python.js.map +1 -1
  39. package/dist/generator/emit-shared-go.d.ts.map +1 -1
  40. package/dist/generator/emit-shared-go.js +23 -4
  41. package/dist/generator/emit-shared-go.js.map +1 -1
  42. package/dist/generator/emit-shared-rust.d.ts.map +1 -1
  43. package/dist/generator/emit-shared-rust.js +24 -6
  44. package/dist/generator/emit-shared-rust.js.map +1 -1
  45. package/dist/generator/emit-shared-typescript.d.ts.map +1 -1
  46. package/dist/generator/emit-shared-typescript.js +23 -8
  47. package/dist/generator/emit-shared-typescript.js.map +1 -1
  48. package/dist/generator/emit-typed-native-go.d.ts +2 -2
  49. package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
  50. package/dist/generator/emit-typed-native-go.js +118 -55
  51. package/dist/generator/emit-typed-native-go.js.map +1 -1
  52. package/dist/generator/emit-typed-native-rust.d.ts +2 -2
  53. package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
  54. package/dist/generator/emit-typed-native-rust.js +119 -70
  55. package/dist/generator/emit-typed-native-rust.js.map +1 -1
  56. package/dist/generator/index.d.ts +2 -2
  57. package/dist/generator/index.d.ts.map +1 -1
  58. package/dist/generator/index.js +1 -1
  59. package/dist/generator/index.js.map +1 -1
  60. package/dist/generator/straightline.d.ts +12 -2
  61. package/dist/generator/straightline.d.ts.map +1 -1
  62. package/dist/generator/straightline.js +47 -32
  63. package/dist/generator/straightline.js.map +1 -1
  64. package/dist/guard.js +26 -5
  65. package/dist/guard.js.map +1 -1
  66. package/dist/lowering.d.ts +47 -3
  67. package/dist/lowering.d.ts.map +1 -1
  68. package/dist/lowering.js +113 -8
  69. package/dist/lowering.js.map +1 -1
  70. package/dist/provenance.d.ts +26 -24
  71. package/dist/provenance.d.ts.map +1 -1
  72. package/dist/provenance.js +30 -59
  73. package/dist/provenance.js.map +1 -1
  74. package/dist/type-gate.d.ts.map +1 -1
  75. package/dist/type-gate.js +3 -1
  76. package/dist/type-gate.js.map +1 -1
  77. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
- import { GeneratorFailure } from "./core.js";
2
- import { isControlGate, mapNodeElemIsOpaqueWire, nodeWirePassthrough } from "../behavior.js";
1
+ import { entryPortOrder, GeneratorFailure } from "./core.js";
2
+ import { isControlGate, mapNodeElemIsOpaqueWire, mapTransformExpr, nodeWirePassthrough } from "../behavior.js";
3
3
  import { goStraightlineInternals } from "./emit-shared-go.js";
4
4
  import { goTypedInternals } from "./emit-shared-go-typed.js";
5
5
  import { buildTypePlan, deriveTypeRef, findDecl, guardedMapIntoIsCoverable, inputPortIsOptional, inputPortTypeRef } from "./typed.js";
@@ -91,10 +91,16 @@ func leafFailure(message string) *BehaviorError {
91
91
  // leaf's structured detail through unchanged (the runner transports the Error Value, it does not
92
92
  // synthesize or re-interpret it).
93
93
  func opFailed(node string, policy string, e error) *BehaviorError {
94
+ // The Kind names itself in the message, and 'retry' says it gave up — the runtime owns the attempts
95
+ // (scp-error.md: tuning is Runtime-owned), so what the plan reports is the exhausted retry.
96
+ where := "operation '" + node + "' failed under '" + policy + "' policy"
97
+ if policy == "retry" {
98
+ where += " (exhausted)"
99
+ }
94
100
  if be, ok := e.(*BehaviorError); ok {
95
- return &BehaviorError{Code: "OP_FAILED", Message: "operation '" + node + "' failed under '" + policy + "' policy: " + be.Message, Detail: be.Detail}
101
+ return &BehaviorError{Code: "OP_FAILED", Message: where + ": " + be.Message, Detail: be.Detail}
96
102
  }
97
- return &BehaviorError{Code: "OP_FAILED", Message: "operation '" + node + "' failed under '" + policy + "' policy: " + e.Error()}
103
+ return &BehaviorError{Code: "OP_FAILED", Message: where + ": " + e.Error()}
98
104
  }
99
105
 
100
106
  // deTypeMismatch / deMissingField / deOverflow — the de-box mismatch failures the generated decode
@@ -804,7 +810,7 @@ function isNativeRaw(comp) {
804
810
  * - every element port is static (literal / ref into the element binding / concat / static arr),
805
811
  * - element outType is a NAMED struct (the augmented element type — over element + the into field),
806
812
  * - no `when` guard (guard+into => heterogeneous elements, not one []T — stays boxed),
807
- * - default 'fail' policy, relationKind single/connection or absent.
813
+ * - relationKind single/connection or absent (every Error Policy Kind is covered — goPolicyArm).
808
814
  * This is the struct-native de-box of a typed `map...into` element collection: build the per-element
809
815
  * native ports struct, dispatch the batched handler ONCE (RawValue out), and assemble each augmented
810
816
  * element struct by copying the over element's typed fields + materializing the into field from the
@@ -825,8 +831,6 @@ function coveredMapNode(n, bodyIds, comp) {
825
831
  // byte-equal. The skip value below (goZero of the into row type) yields nil / connection-struct-zero.
826
832
  if (m.when !== undefined && m.into !== undefined && !guardedMapIntoIsCoverable(n, comp))
827
833
  return false;
828
- if (m.policy !== undefined && m.policy !== "fail")
829
- return false;
830
834
  if (m.relationKind !== undefined && m.relationKind !== "single" && m.relationKind !== "connection")
831
835
  return false;
832
836
  // A map node must carry an outType (its ELEMENT type per the recorder SoT — authoring.ts recordMap
@@ -858,7 +862,9 @@ function coveredMapNode(n, bodyIds, comp) {
858
862
  if (schema === undefined || schema.elemType === undefined)
859
863
  return false;
860
864
  }
861
- const ports = m.ports;
865
+ // 純式 map(#222)は port を持たない: 被覆条件は「要素式が宣言された要素型へ native に materialize
866
+ // できること」で、それは compilePortNode(宣言型 materializer)が失敗したときに loud に落ちる。
867
+ const ports = (m.ports ?? {});
862
868
  const plan = planForComp(comp);
863
869
  const typedNodes = buildTypedNodes(comp, plan);
864
870
  const asBinding = mapAsBinding(comp, n, typedNodes, plan);
@@ -873,7 +879,7 @@ function coveredMapNode(n, bodyIds, comp) {
873
879
  * coveredFanoutNode (v3) — a FANOUT node (first-class `@refs` id-list fan-out) is covered when:
874
880
  * - over is a static ref to a PRIOR BODY NODE's typed arr field OR an INPUT array port with elemType,
875
881
  * - every element port is static (literal / ref into the $as binding / concat / static arr),
876
- * - default 'fail' policy, relationKind connection (guard-checked by the guard/builder).
882
+ * - relationKind connection (guard-checked by the guard/builder); every Error Policy Kind is covered.
877
883
  * The fanout de-boxes to: one deduped batched dispatch → first-seen dedupe (by the elem's dedupeKey
878
884
  * field) + dangling drop + implicitSource strip + connection wrap {items, cursor:nil} — NO boxed Value.
879
885
  */
@@ -881,8 +887,6 @@ function coveredFanoutNode(n, bodyIds, comp) {
881
887
  if (n === null || typeof n !== "object" || !("fanout" in n))
882
888
  return false;
883
889
  const f = n.fanout;
884
- if (f.policy !== undefined && f.policy !== "fail")
885
- return false;
886
890
  if (f.relationKind !== "connection")
887
891
  return false;
888
892
  const overE = classifyExpr(f.over);
@@ -996,13 +1000,11 @@ function coverageRejectReason(comp) {
996
1000
  if (!("component" in n))
997
1001
  return `node '${n.id}' is not a componentRef, map, or cond node (not native-covered)`;
998
1002
  const cr = n;
999
- // Only default 'fail' policy on covered reads: 'continue' (and any skip source, incl. bindField)
1000
- // makes a node UNPRODUCED at runtime, whose output ref must yield the unproduced rep — a
1001
- // produced-aware output lowering the struct-only path does not do yet (documented follow-up).
1002
- // Such components fall through to the boxed typed / straight-line path (correct, just not
1003
- // struct-de-plumbed). relationKind:single WITHOUT bindField (the #74/#323 core) IS covered.
1004
- if (cr.policy !== undefined && cr.policy !== "fail")
1005
- return `node '${n.id}' componentRef policy '${cr.policy}' (produced-aware output not yet native-covered)`;
1003
+ // Every Error Policy Kind IS covered on a componentRef: `continue` makes the node unproduced, which the
1004
+ // produced-aware output lowering (emitProducedAwareValue, driven by the same canSkip the bindField skip
1005
+ // uses) already renders, and `retry` shares `fail`'s control flow with the Kind named in the failure
1006
+ // (the attempts themselves are Runtime-owned — scp-error.md §Separating Policy Kind and Tuning, which
1007
+ // in native mode is the per-Component leaf transport). Proven by real go build + run, not by assertion.
1006
1008
  // #125: a when(...) control-gate child (`parent=gate, bindField:"ok"`). Its bindField is the gate's
1007
1009
  // skip signal, NOT a relation data key — so the relationKind constraint below (which governs a
1008
1010
  // relation bindField into a single|connection parent) does not apply. Its skip is driven by the
@@ -1347,8 +1349,8 @@ function inputScalarKind(schema) {
1347
1349
  * observe passes these decoded args positionally. A missing key leaves the zero value (every covered input
1348
1350
  * is required + always supplied by the corpus); a present-but-wrong-scalar is a fail-closed decode error.
1349
1351
  */
1350
- function emitInDecoder(comp, plan) {
1351
- const ports = Object.keys(comp.inputPorts ?? {});
1352
+ function emitInDecoder(comp, plan, declared) {
1353
+ const ports = entryPortOrder(comp, declared);
1352
1354
  if (ports.length === 0 || comp.inputPorts === undefined)
1353
1355
  return ""; // no input → observe calls the entry with no args.
1354
1356
  // #192: decode the generic *Obj test input into the entry's POSITIONAL args (named returns = the params,
@@ -1642,7 +1644,7 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
1642
1644
  * consumer (graphddb) drives it and keeps the struct native. A Value observation is produced ONLY
1643
1645
  * by the separate serialize wrapper (run_native_raw_<comp>, below), the single outer Value boundary.
1644
1646
  */
1645
- function emitNativeRawRunner(comp, plan, flags, wire, leaf) {
1647
+ function emitNativeRawRunner(comp, plan, flags, wire, leaf, declared) {
1646
1648
  const ep = execPlan(comp);
1647
1649
  const order = ep.order;
1648
1650
  const cplan = buildComponentPlan(comp, goStraightlineInternals.dialect, "scope");
@@ -1683,7 +1685,7 @@ function emitNativeRawRunner(comp, plan, flags, wire, leaf) {
1683
1685
  // output recursion) into the node's outType struct.
1684
1686
  // #192: 1:1 map of the authored signature — positional params (one per input port, box removed), not
1685
1687
  // an `In_<comp>` struct. Go allows unused function params, so no `_ = param` guard is needed.
1686
- const entryParams = Object.keys(comp.inputPorts ?? {})
1688
+ const entryParams = entryPortOrder(comp, declared)
1687
1689
  .map((p) => `${goParamName(p)} ${inputPortGoType(comp.inputPorts[p], plan, `input port '${p}' of component '${comp.name}'`)}`)
1688
1690
  .join(", ");
1689
1691
  lines.push(`func ${runnerName(comp.name)}(${entryParams}) (${outStructType}, error) {`);
@@ -1716,12 +1718,12 @@ function emitNativeRawRunner(comp, plan, flags, wire, leaf) {
1716
1718
  // v3: a covered fanout node — deduped batched dispatch + first-seen dedupe + dangling drop +
1717
1719
  // connection wrap (the SAME definition as run_behavior's fanoutDedupDrop).
1718
1720
  if ("fanout" in comp.body[i]) {
1719
- lines.push(emitFanoutArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, zeroOut, leaf, wire.selector));
1721
+ lines.push(emitFanoutArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, zeroOut, leaf, wire.selector, metas[i].policy));
1720
1722
  continue;
1721
1723
  }
1722
1724
  // #86 pt2: a covered batched map...into node — struct-native element collection + into enrichment.
1723
1725
  if ("map" in comp.body[i]) {
1724
- lines.push(emitMapArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, zeroOut, flags, leaf, wire.selector));
1726
+ lines.push(emitMapArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, zeroOut, flags, leaf, wire.selector, metas[i].policy));
1725
1727
  continue;
1726
1728
  }
1727
1729
  // #108: a cond node — pure Expression (no handler). Compile `if` to a native bool + materialize the
@@ -1786,22 +1788,14 @@ function emitNativeRawRunner(comp, plan, flags, wire, leaf) {
1786
1788
  // (renderResultDeBox) classifies it against the STATICALLY declared result type and produces the
1787
1789
  // structured Error Value on a mismatch (byte-equal codes to run_behavior's outType check, so ≡ holds).
1788
1790
  if (meta.policy === "continue") {
1789
- // continue: a failed node (leaf failure OR de-box mismatch) produces no Port — the downstream Skip
1790
- // propagation is what `continue` means. The inline de-box runs in a local closure so a mismatch is a
1791
- // LOCAL skip (not a runner-wide propagate); only a clean decode commits. (Covered componentRef nodes
1792
- // are always 'fail' policy today — this arm is defensive.)
1793
- const nodeGo = renderTypeRef(ref);
1794
- const nodeZeroFail = (e) => `return ${goZero(ref)}, ${e}`;
1791
+ // continue: a node whose COMPONENT failed produces no Port — the downstream Skip propagation is what
1792
+ // `continue` means (scp-error.md §Dependency rules for continue), so the leaf error leaves
1793
+ // produced_<s> false instead of propagating. A de-box mismatch is NOT a component failure: the
1794
+ // interpreter checks the declared outType in wrappedExec, OUTSIDE the policy interpretation, and
1795
+ // throws — so it must propagate here too, or the two surfaces disagree on the same IR.
1795
1796
  lines.push(`${indent}if wire_${s}, wire_${s}Err := ${call}; wire_${s}Err == nil {`);
1796
- lines.push(`${indent}\tdec_${s}, dec_${s}DErr := func() (${nodeGo}, error) {`);
1797
- lines.push(`${indent}\t\tvar out ${nodeGo}`);
1798
- lines.push(renderResultDeBox(ref, "out", `wire_${s}`, node.id, plan, `${indent}\t\t`, nodeZeroFail, nodeWirePassthrough(node), seqCtr));
1799
- lines.push(`${indent}\t\treturn out, nil`);
1800
- lines.push(`${indent}\t}()`);
1801
- lines.push(`${indent}\tif dec_${s}DErr == nil {`);
1802
- lines.push(`${indent}\t\t${typedLocal(node.id)} = dec_${s}`);
1803
- lines.push(`${indent}\t\tproduced_${s} = true`);
1804
- lines.push(`${indent}\t}`);
1797
+ lines.push(renderResultDeBox(ref, typedLocal(node.id), `wire_${s}`, node.id, plan, `${indent}\t`, returnZeroFail(zeroOut), nodeWirePassthrough(node), seqCtr));
1798
+ lines.push(`${indent}\tproduced_${s} = true`);
1805
1799
  lines.push(`${indent}}`);
1806
1800
  }
1807
1801
  else {
@@ -1863,9 +1857,15 @@ function emitNativeRawRunner(comp, plan, flags, wire, leaf) {
1863
1857
  * (direct field assignment; $as refs read the over element's typed fields), and the result is a
1864
1858
  * native []T with NO boxed Value on any plane. The map is under the parent's produced gate (inline).
1865
1859
  */
1866
- function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, flags, leaf, wireSel) {
1860
+ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, flags, leaf, wireSel, policy) {
1867
1861
  const m = node.map;
1868
1862
  const batched = m.batched === true;
1863
+ // Error Policy Kind of the map's Component (the unit is "a Component failed", and for a map that is this
1864
+ // node). The resolved Kind comes from the sequential analysis (the mirror of plan.ts preflight) — it is
1865
+ // never re-derived from the node here. `continue` → the node is unproduced (goPolicyArm wraps the body);
1866
+ // `fail`/`retry` → propagate, naming the Kind.
1867
+ const contPolicy = policy === "continue";
1868
+ const policyLit = JSON.stringify(policy === "retry" ? "retry" : "fail");
1869
1869
  const hasInto = m.into !== undefined;
1870
1870
  const hasGuard = m.when !== undefined;
1871
1871
  // #177 keep-with-null: a guarded map WITH `into` keeps guard-skipped elements with the (opt) into
@@ -1873,7 +1873,8 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
1873
1873
  // guarded NO-into map, which DROPs skipped elements. Byte-equal to run_behavior's applyInto keep-with-null.
1874
1874
  const keepWithNull = hasGuard && hasInto;
1875
1875
  const s = sanitize(node.id);
1876
- const leafSym = resolveLeafSymbol(m.component, leaf, m.leafSymbol);
1876
+ const transform = mapTransformExpr(m);
1877
+ const leafSym = transform === undefined ? resolveLeafSymbol(m.component, leaf, m.leafSymbol) : "";
1877
1878
  const arrRef = typedNodes.get(node.id);
1878
1879
  const elemGo = renderTypeRef(arrRef);
1879
1880
  const asName = m.as;
@@ -1883,7 +1884,7 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
1883
1884
  const overElemGo = renderTypeRef(overElemRef);
1884
1885
  const elemMat = mapElemMaterializerName(comp.name, node.id);
1885
1886
  const priorHere = (head) => priorNodeAt(head, atPos);
1886
- const portNames = Object.keys(m.ports);
1887
+ const portNames = Object.keys(m.ports ?? {});
1887
1888
  // #108 guard: compile the `when` expression to a native bool over an element-scoped resolveHead
1888
1889
  // ($as → the over element value `elemVar`; prior node → its typed local; input port → in.<Field>).
1889
1890
  // Returns the compiled {stmts, expr} or null (no guard). Mirrors run_behavior's per-element keep-gate
@@ -1911,7 +1912,7 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
1911
1912
  const buildPayloadElem = (il, elemVar) => [`${il}ep_${s} := ${goPayloadRow(portFields(elemVar), wireSel)}`];
1912
1913
  const lines = [];
1913
1914
  const closers = [];
1914
- lines.push(`\t// ── map '${node.id}' (${m.component}, ${batched ? "batched" : "per-element"}, into:${JSON.stringify(m.into ?? null)}${m.relationKind ? ", relationKind:" + m.relationKind : ""}${m.parent ? ", parent:" + m.parent : ""}) ──`);
1915
+ lines.push(`\t// ── map '${node.id}' (${m.component ?? "pure expression"}, ${batched ? "batched" : "per-element"}, into:${JSON.stringify(m.into ?? null)}${m.relationKind ? ", relationKind:" + m.relationKind : ""}${m.parent ? ", parent:" + m.parent : ""}) ──`);
1915
1916
  let indent = "\t";
1916
1917
  // the map is gated on the parent's produced flag (inline, like a relation child).
1917
1918
  if (m.parent !== undefined && priorNodeAt(m.parent, atPos)) {
@@ -1919,6 +1920,11 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
1919
1920
  closers.unshift(`${indent}}`);
1920
1921
  indent += "\t";
1921
1922
  }
1923
+ // the node's own statements start here: goPolicyArm wraps THIS range (not the parent gate) when the Kind
1924
+ // is `continue`, so a Component failure skips the rest of the node and leaves it unproduced.
1925
+ const bodyStart = lines.length;
1926
+ /** the map's Component failed (the transport returned an error) — what the Kind does about it. */
1927
+ const onComponentFailure = (errVar) => contPolicy ? [`skipped_${s} = true`, "break"] : [`return ${zeroOut}, opFailed(${JSON.stringify(node.id)}, ${policyLit}, ${errVar})`];
1922
1928
  // over collection (typed field access to the parent node's arr — no serialize; opt-arr → nil-safe deref).
1923
1929
  for (const l of goBindOver(indent, s, overExpr, overOptArr, overElemGo))
1924
1930
  lines.push(l);
@@ -1958,6 +1964,29 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
1958
1964
  out.push(`${il}}`);
1959
1965
  return out;
1960
1966
  };
1967
+ if (transform !== undefined) {
1968
+ // 純式 map(#222): transport 呼びもワイヤも de-box も無い。要素式を**宣言された要素型**へ native に
1969
+ // materialize して積むだけ(port 境界と同一の宣言型 materializer `compilePortNode` を通す — 要素種の
1970
+ // 推論は無い)。`when` guard は Component map と同一の keep-gate。
1971
+ lines.push(`${indent}for _, ${elemLocal(s)} := range over_${s} {`);
1972
+ for (const l of emitGuard(indent + "\t", elemLocal(s)))
1973
+ lines.push(l);
1974
+ const tc = compilePortNode(transform, comp, plan, typedNodes, priorHere, `map '${node.id}' transform`, arrRef.elem, {
1975
+ asBinding: { name: asName, ref: overElemRef, plan },
1976
+ asBase: elemLocal(s),
1977
+ narrowed: nodeNarrowedPaths(comp, node),
1978
+ wireSel,
1979
+ });
1980
+ for (const st of tc.stmts)
1981
+ lines.push(`${indent}\t${st}`);
1982
+ lines.push(`${indent}\t${typedLocal(node.id)} = append(${typedLocal(node.id)}, ${tc.expr})`);
1983
+ lines.push(`${indent}}`);
1984
+ lines.push(...goPolicyArm(s, indent, false, lines.splice(bodyStart)));
1985
+ for (const c of closers)
1986
+ lines.push(c);
1987
+ void overElemGo;
1988
+ return lines.join("\n");
1989
+ }
1961
1990
  if (batched && keepWithNull) {
1962
1991
  // #177 BATCHED keep-with-null (guarded map...into, opt into): first pass records, per over element in
1963
1992
  // ORDER, whether it is kept (guard true → build its ports, remember its over-index) or skipped (guard
@@ -1984,7 +2013,7 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
1984
2013
  // ONE op-agnostic transport call: the batch is a WireRow {items:[…]}; the result is a WireList whose
1985
2014
  // aligned elements are read via `.Items` (byte-equal to run_behavior's aligned batch result).
1986
2015
  lines.push(`${indent}\tmo_${s}, mo_${s}Err := ${leafSym}(${goPayloadBatch(`items_${s}`, wireSel)})`);
1987
- lines.push(`${indent}\tif mo_${s}Err != nil {`, `${indent}\t\treturn ${zeroOut}, opFailed(${JSON.stringify(node.id)}, "fail", mo_${s}Err)`, `${indent}\t}`);
2016
+ lines.push(`${indent}\tif mo_${s}Err != nil {`, ...onComponentFailure(`mo_${s}Err`).map((l) => `${indent}\t\t${l}`), `${indent}\t}`);
1988
2017
  lines.push(`${indent}\tmi_${s} := mo_${s}.Items`);
1989
2018
  lines.push(`${indent}\tif len(mi_${s}) != len(items_${s}) {`, `${indent}\t\treturn ${zeroOut}, ${goErr("MAP_BATCH_RESULT_MISMATCH", `fmt.Sprintf("map '${node.id}': batched handler must return a list aligned to items (want %d)", len(items_${s}))`)}`, `${indent}\t}`);
1990
2019
  lines.push(`${indent}\tfor mk_${s} := range items_${s} {`);
@@ -2015,7 +2044,7 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
2015
2044
  lines.push(`${indent}if len(items_${s}) > 0 {`);
2016
2045
  // ONE op-agnostic transport call: batch payload WireRow {items:[…]}; result WireList read via `.Items`.
2017
2046
  lines.push(`${indent}\tmo_${s}, mo_${s}Err := ${leafSym}(${goPayloadBatch(`items_${s}`, wireSel)})`);
2018
- lines.push(`${indent}\tif mo_${s}Err != nil {`, `${indent}\t\treturn ${zeroOut}, opFailed(${JSON.stringify(node.id)}, "fail", mo_${s}Err)`, `${indent}\t}`);
2047
+ lines.push(`${indent}\tif mo_${s}Err != nil {`, ...onComponentFailure(`mo_${s}Err`).map((l) => `${indent}\t\t${l}`), `${indent}\t}`);
2019
2048
  lines.push(`${indent}\tmi_${s} := mo_${s}.Items`);
2020
2049
  lines.push(`${indent}\tif len(mi_${s}) != len(items_${s}) {`, `${indent}\t\treturn ${zeroOut}, ${goErr("MAP_BATCH_RESULT_MISMATCH", `fmt.Sprintf("map '${node.id}': batched handler must return a list aligned to items (want %d)", len(items_${s}))`)}`, `${indent}\t}`);
2021
2050
  if (hasInto) {
@@ -2064,7 +2093,7 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
2064
2093
  lines.push(`${indent}\tif mo_${s}Err != nil {`, `${indent}\t\tcontinue`, `${indent}\t}`);
2065
2094
  }
2066
2095
  else {
2067
- lines.push(`${indent}\tif mo_${s}Err != nil {`, `${indent}\t\treturn ${zeroOut}, opFailed(${JSON.stringify(node.id)}, "fail", mo_${s}Err)`, `${indent}\t}`);
2096
+ lines.push(`${indent}\tif mo_${s}Err != nil {`, ...onComponentFailure(`mo_${s}Err`).map((l) => `${indent}\t\t${l}`), `${indent}\t}`);
2068
2097
  }
2069
2098
  // the element's wire is de-boxed strictly INLINE. A de-box mismatch fails closed regardless of
2070
2099
  // elementPolicy (≡ the interpreter's whole-node outType throw); elementPolicy governs the handler's
@@ -2081,12 +2110,38 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
2081
2110
  lines.push(`${indent}\t${typedLocal(node.id)} = append(${typedLocal(node.id)}, el_${s})`);
2082
2111
  lines.push(`${indent}}`);
2083
2112
  }
2084
- lines.push(`${indent}produced_${s} = true`);
2113
+ lines.push(...goPolicyArm(s, indent, contPolicy, lines.splice(bodyStart)));
2085
2114
  for (const c of closers)
2086
2115
  lines.push(c);
2087
2116
  void overElemGo;
2088
2117
  return lines.join("\n");
2089
2118
  }
2119
+ /**
2120
+ * goContinuePolicy — Error Policy Kind を 1 つのノード arm へ適用する共通形(map / fanout が共有)。
2121
+ *
2122
+ * `continue` は「Component が失敗 → その Port は未生成 → 下流は Skip」(scp-error.md §Dependency rules
2123
+ * for continue)なので、失敗した時点でそのノードの残りの処理を飛ばし `produced_<s>` を立てない。Go は
2124
+ * 宣言をまたぐ `goto` を禁じるので once-block(`for { … break }`)で囲む。この形なら de-box 不一致 /
2125
+ * 整列違反の `return` はそのまま関数を抜ける — interpreter も outType 検査を policy の外(wrappedExec)で
2126
+ * throw するので、そこが一致する。
2127
+ *
2128
+ * `fail` / `retry` は制御フローが同じで、違いは失敗が名乗る Kind だけ(試行そのものは Runtime 所有 =
2129
+ * native では per-Component の leaf transport)。
2130
+ */
2131
+ function goPolicyArm(s, indent, continuePolicy, body) {
2132
+ if (!continuePolicy)
2133
+ return [...body, `${indent}produced_${s} = true`];
2134
+ return [
2135
+ `${indent}skipped_${s} := false`,
2136
+ `${indent}for {`,
2137
+ ...body.map((l) => `\t${l}`.replace(/\n/g, "\n\t")),
2138
+ `${indent}\tbreak`,
2139
+ `${indent}}`,
2140
+ `${indent}if !skipped_${s} {`,
2141
+ `${indent}\tproduced_${s} = true`,
2142
+ `${indent}}`,
2143
+ ];
2144
+ }
2090
2145
  /** the map element loop variable (the over element, a typed struct). */
2091
2146
  function elemLocal(s) {
2092
2147
  return `oel_${s}`;
@@ -2100,9 +2155,12 @@ function elemLocal(s) {
2100
2155
  * (STRUCTURAL — the connection items elem type already omits the implicitSource field), and wrap into
2101
2156
  * the connection struct {items, cursor:nil}. NO boxed Value on any plane. Byte-equal to run_behavior.
2102
2157
  */
2103
- function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, leaf, wireSel) {
2158
+ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, leaf, wireSel, policy) {
2104
2159
  const f = node.fanout;
2105
2160
  const s = sanitize(node.id);
2161
+ // Error Policy Kind of the fanout's Component (same rule as the map arm — see goPolicyArm).
2162
+ const contPolicy = policy === "continue";
2163
+ const policyLit = JSON.stringify(policy === "retry" ? "retry" : "fail");
2106
2164
  const wvQ = goWireQ(wireSel);
2107
2165
  const leafSym = resolveLeafSymbol(f.component, leaf, f.leafSymbol);
2108
2166
  const connRef = typedNodes.get(node.id);
@@ -2137,6 +2195,8 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut
2137
2195
  closers.unshift(`${indent}}`);
2138
2196
  indent += "\t";
2139
2197
  }
2198
+ // the node's own statements start here (goPolicyArm wraps THIS range when the Kind is `continue`).
2199
+ const bodyStart = lines.length;
2140
2200
  // over id-list (typed field access — no serialize; opt-arr → nil-safe deref) → per-id ports (all ids).
2141
2201
  for (const l of goBindOver(indent, s, overExpr, overOptArr, overElemGo))
2142
2202
  lines.push(l);
@@ -2153,7 +2213,7 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut
2153
2213
  // per-id element wires (read via `.Items`). A DANGLING id is a WireNull element → the zero element (empty
2154
2214
  // dedupeKey), which the dangling drop below excludes. No `bound`.
2155
2215
  lines.push(`${indent}\tfo_${s}, fo_${s}Err := ${leafSym}(${goPayloadBatch(`pi_${s}`, wireSel)})`);
2156
- lines.push(`${indent}\tif fo_${s}Err != nil {`, `${indent}\t\treturn ${zeroOut}, opFailed(${JSON.stringify(node.id)}, "fail", fo_${s}Err)`, `${indent}\t}`);
2216
+ lines.push(`${indent}\tif fo_${s}Err != nil {`, ...(contPolicy ? [`${indent}\t\tskipped_${s} = true`, `${indent}\t\tbreak`] : [`${indent}\t\treturn ${zeroOut}, opFailed(${JSON.stringify(node.id)}, ${policyLit}, fo_${s}Err)`]), `${indent}\t}`);
2157
2217
  lines.push(`${indent}\tfw_${s} := fo_${s}.Items`);
2158
2218
  lines.push(`${indent}\tif len(fw_${s}) != len(pi_${s}) {`, `${indent}\t\treturn ${zeroOut}, ${goErr("FANOUT_BATCH_RESULT_MISMATCH", `fmt.Sprintf("fanout '${node.id}': batched handler must return a list aligned to the deduped id list (want %d)", len(pi_${s}))`)}`, `${indent}\t}`);
2159
2219
  // ── THE ONE dedupe/drop (mirrors fanoutDedupDrop verbatim): first-seen dedupe by dedupeKey field;
@@ -2179,7 +2239,7 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut
2179
2239
  // wrap into the connection struct {Items, Cursor:nil}. A nil items slice serializes to [] (the
2180
2240
  // connection serializer normalizes it) — matching {items:[],cursor:null} for an empty fan-out.
2181
2241
  lines.push(`${indent}${typedLocal(node.id)} = ${connRef.name}{${goFieldName("items")}: items_${s}}`);
2182
- lines.push(`${indent}produced_${s} = true`);
2242
+ lines.push(...goPolicyArm(s, indent, contPolicy, lines.splice(bodyStart)));
2183
2243
  for (const c of closers)
2184
2244
  lines.push(c);
2185
2245
  return lines.join("\n");
@@ -2815,7 +2875,7 @@ function emit(ctx) {
2815
2875
  const mm = emitMapElemMaterializers(c, typedNodes, plan);
2816
2876
  if (mm)
2817
2877
  elemCopiers.push(mm);
2818
- const r = emitNativeRawRunner(c, plan, flags, wire, leaf);
2878
+ const r = emitNativeRawRunner(c, plan, flags, wire, leaf, ctx.declaredEntryPortOrder);
2819
2879
  runnerCodes.push(r.code);
2820
2880
  }
2821
2881
  const structSurface = emitStructSurface(native);
@@ -2928,7 +2988,7 @@ ${emitGoWireTypes()}
2928
2988
  * whole-file zero (the ser_* NewObj is test glue, never on the consumer's read hot path). Emitted only for
2929
2989
  * the fully-covered case (the equivalence harness); production consumers never use it.
2930
2990
  */
2931
- export function goTypedNativeObserve(ir, runtimeImport, leaf, namespace) {
2991
+ export function goTypedNativeObserve(ir, runtimeImport, leaf, namespace, declared) {
2932
2992
  const components = ir.components;
2933
2993
  const native = components.filter(isNativeRaw);
2934
2994
  const plan = buildTypePlan(ir);
@@ -2945,7 +3005,7 @@ export function goTypedNativeObserve(ir, runtimeImport, leaf, namespace) {
2945
3005
  // #192: decode the generic *Obj test input into the entry's POSITIONAL args (test glue — ONE decode at
2946
3006
  // the top; a REQUIRED declared input absent is a fail-closed decode error here, never on the entry path),
2947
3007
  // then call the 1:1 entry positionally. A no-input entry is called with no args (no decoder).
2948
- const args = Object.keys(c.inputPorts ?? {}).map((p) => goParamName(p));
3008
+ const args = entryPortOrder(c, declared).map((p) => goParamName(p));
2949
3009
  const decode = args.length === 0
2950
3010
  ? ""
2951
3011
  : `\t\t${args.join(", ")}, ierr := decode_${sanitize(c.name)}(input)\n\t\tif ierr != nil {\n\t\t\treturn nil, ierr\n\t\t}\n`;
@@ -2955,7 +3015,7 @@ export function goTypedNativeObserve(ir, runtimeImport, leaf, namespace) {
2955
3015
  .join("\n");
2956
3016
  // input decoders (TEST glue): generic *Obj -> concrete In_<comp>. Scalar fields read the typed value
2957
3017
  // (a `.(T)` here is on the SDK/wire Value in the OBSERVE companion, never in the covered module).
2958
- const inDecoders = native.map((c) => emitInDecoder(c, plan)).join("\n\n");
3018
+ const inDecoders = native.map((c) => emitInDecoder(c, plan, declared)).join("\n\n");
2959
3019
  // every covered node returns a WireValue the inline de-box classifies — so the scripted wire adapter is
2960
3020
  // needed whenever any component has a handler node.
2961
3021
  const anyDeBox = native.some((c) => c.body.some((n) => !("cond" in n)));
@@ -3032,7 +3092,10 @@ func (e *BehaviorError) FailureDetail() (kind, model, field, expectedType, actua
3032
3092
  for (const n of c.body) {
3033
3093
  if ("cond" in n)
3034
3094
  continue; // #108: cond has no leaf (pure Expression) — no transport fn.
3035
- const catalog = "fanout" in n ? n.fanout.component : "map" in n ? n.map.component : n.component;
3095
+ // 純式 map(#222)も Component を呼ばないので transport は要らない(cond と同じ扱い)。
3096
+ if ("map" in n && mapTransformExpr(n.map) !== undefined)
3097
+ continue;
3098
+ const catalog = ("fanout" in n ? n.fanout.component : "map" in n ? n.map.component : n.component);
3036
3099
  const specSym = "fanout" in n ? n.fanout.leafSymbol : "map" in n ? n.map.leafSymbol : n.leafSymbol;
3037
3100
  const sym = leafSymbolBare(catalog, leaf, specSym);
3038
3101
  // echo branches (point/componentRef nodes only — a batched/fanout node returns a WireList, not a port).