behavior-contracts 0.8.10 → 0.8.12

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 (39) hide show
  1. package/README.md +22 -16
  2. package/cli-contract.yaml +46 -44
  3. package/dist/cli.js +16 -14
  4. package/dist/cli.js.map +1 -1
  5. package/dist/commands/codegen.d.ts +4 -3
  6. package/dist/commands/codegen.d.ts.map +1 -1
  7. package/dist/commands/codegen.js +8 -5
  8. package/dist/commands/codegen.js.map +1 -1
  9. package/dist/generated/commands.d.ts.map +1 -1
  10. package/dist/generated/commands.js +12 -16
  11. package/dist/generated/commands.js.map +1 -1
  12. package/dist/generated/contract.d.ts.map +1 -1
  13. package/dist/generated/contract.js +2 -2
  14. package/dist/generated/contract.js.map +1 -1
  15. package/dist/generated/program.d.ts +6 -8
  16. package/dist/generated/program.d.ts.map +1 -1
  17. package/dist/generated/program.js +6 -8
  18. package/dist/generated/program.js.map +1 -1
  19. package/dist/generated/types.d.ts +6 -8
  20. package/dist/generated/types.d.ts.map +1 -1
  21. package/dist/generator/core.d.ts +37 -20
  22. package/dist/generator/core.d.ts.map +1 -1
  23. package/dist/generator/core.js +2 -1
  24. package/dist/generator/core.js.map +1 -1
  25. package/dist/generator/emit-typed-native-go.d.ts +19 -7
  26. package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
  27. package/dist/generator/emit-typed-native-go.js +557 -408
  28. package/dist/generator/emit-typed-native-go.js.map +1 -1
  29. package/dist/generator/emit-typed-native-rust.d.ts +27 -22
  30. package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
  31. package/dist/generator/emit-typed-native-rust.js +430 -482
  32. package/dist/generator/emit-typed-native-rust.js.map +1 -1
  33. package/dist/generator/index.d.ts +2 -2
  34. package/dist/generator/index.d.ts.map +1 -1
  35. package/dist/generator/index.js +1 -1
  36. package/dist/generator/index.js.map +1 -1
  37. package/dist/index.d.ts +1 -1
  38. package/dist/index.d.ts.map +1 -1
  39. package/package.json +1 -1
@@ -7,17 +7,18 @@ import { concurrencyPlan, execPlan, analyzeSequentialOps, classifyExpr, buildCom
7
7
  import { NativeExprCompiler } from "./native-expr.js";
8
8
  import { buildDeBoxPlan, notationOfRef } from "./emit-shared-debox.js";
9
9
  const PKG = "dslcontracts";
10
- /** resolveGoWire — the CONCRETE consumer wire type names the de-box classifies a node result against
11
- * (bc#141). Default (no option) → the in-package convention names, unqualified. A configured `import`
12
- * qualifies the names with the imported package's selector so a consumer can keep its wire types in its
13
- * own package. `value`/`row`/`list` name the WireValue / WireRow / WireList concrete types; the covered
14
- * runner + the generated Probe result structs reference them by these names. */
10
+ /** resolveGoWire — the BC-OWNED wire type names the de-box classifies a node result against. bc OWNS +
11
+ * GENERATES `WireValue`/`WireRow`/`WireList` (emitGoWireTypes); the consumer supplies none. A configured
12
+ * `sharedTypesImport` (Task A cross-package) qualifies the names with the shared BC-generated package's
13
+ * selector and moves the type definitions there (so a separate transport package can return them without an
14
+ * import cycle); absent → in-package (the covered module defines + references them unqualified). */
15
15
  function resolveGoWire(ctx) {
16
- const w = ctx.goWire;
17
- if (w === undefined)
16
+ const imp = ctx.sharedTypesImport;
17
+ if (imp === undefined)
18
18
  return { value: "WireValue", row: "WireRow", list: "WireList" };
19
- const sel = w.import !== undefined ? `${w.import.split("/").pop().replace(/[^A-Za-z0-9_]/g, "_")}.` : "";
20
- return { value: `${sel}${w.value}`, row: `${sel}${w.row}`, list: `${sel}${w.list}`, import: w.import };
19
+ const bare = imp.split("/").pop().replace(/[^A-Za-z0-9_]/g, "_");
20
+ const sel = `${bare}.`;
21
+ return { value: `${sel}WireValue`, row: `${sel}WireRow`, list: `${sel}WireList`, import: imp, selector: bare };
21
22
  }
22
23
  /** goErr — build the LOCAL concrete error value for a behavior/plan failure on the covered read
23
24
  * plane (runtime-free). The covered module declares `type BehaviorError struct { Code, Message string }`
@@ -290,14 +291,22 @@ function renderResultDeBox(ref, target, srcExpr, nodeId, plan, indent, fail, ctr
290
291
  * WireList seam types (that would own the wire format, and a Go interface is vtable dynamic dispatch); it
291
292
  * REFERENCES the consumer's CONCRETE types by name (RowProbe.Got is a `${wire.row}`, ListProbe.Got a
292
293
  * `${wire.list}`) and the runner calls their methods directly (zero dynamic dispatch, zero dictionary). */
293
- function emitProbeWireTypes(wire) {
294
+ /** emitGoProbeKinds — the probe kind consts. Emitted in the COVERED module ALWAYS (the inline de-box
295
+ * compares against them) AND in the shared wire package (its classifiers set them). Both packages carry an
296
+ * identical copy (values 0..3), so a probe struct built in one package compares equal in the other — no
297
+ * cross-package const reference, no export needed. */
298
+ function emitGoProbeKinds() {
294
299
  return `// Probe kinds — the outcome of classifying one wire attribute against a declared field type.
295
300
  const (
296
301
  probeGot uint8 = 0 // present; the wire variant matches the declared type
297
302
  probeWrong uint8 = 1 // present but a different wire variant (carries ActualWireType + Raw)
298
303
  probeAbsent uint8 = 2 // no attribute for this field
299
304
  probeNull uint8 = 3 // present as the producer's null variant (opt → None; required → mismatch)
300
- )
305
+ )`;
306
+ }
307
+ function emitProbeWireTypes(wire) {
308
+ return `// Probe RESULT structs — concrete data the WireValue classifiers hand back; the de-box reads .Kind /
309
+ // .Got / .ActualWireType / .Raw (exported fields).
301
310
 
302
311
  // StringProbe / NumberProbe / BoolProbe — a scalar probe result. Got holds the matched value (a
303
312
  // NumberProbe's Got is the raw numeric text; the de-box parses + range-checks it). ActualWireType is the
@@ -341,6 +350,198 @@ type ListProbe struct {
341
350
  Raw string
342
351
  }`;
343
352
  }
353
+ /** emitGoWireTypes — the BC-OWNED, BC-GENERATED, self-contained (runtime-free) concrete wire types + their
354
+ * classification. bc GENERATES the whole seam: `WireValue` is the generic result the consumer's SINGLE
355
+ * op-agnostic transport builds + returns (implementing NOTHING over it); numbers ride as raw text so BC
356
+ * owns overflow. The generated inline de-box reads it via the As.../Probe.../Elem... methods — static
357
+ * extraction lowers it to the covered plane's typed values immediately (no dynamic value crosses the covered
358
+ * plane). WireRow/WireList probes hand out a value wrapper over a SHARED slice backing (no deep copy). NO
359
+ * consumer classification. */
360
+ function emitGoWireTypes() {
361
+ return `// WireValue — the BC-OWNED generic result the consumer's single op-agnostic transport builds + returns
362
+ // (WireStr/WireNum/WireInt/WireFloat/WireBool/WireNull/WireRowOf/WireListOf) and implements NOTHING over.
363
+ // A self-contained tagged union (no untyped box, no bc-runtime Value); numbers carry raw text (BC parses +
364
+ // range-checks → overflow is BC's to detect). Composite = nested Entries (row) / Items (list).
365
+ type WireValue struct {
366
+ kind uint8
367
+ str string
368
+ num string
369
+ bl bool
370
+ Entries []WireField
371
+ Items []WireValue
372
+ }
373
+
374
+ type WireField struct {
375
+ Key string
376
+ Val WireValue
377
+ }
378
+
379
+ // WireRow / WireList — a wire map / array handle over a SHARED slice backing (value type; probes return the
380
+ // bc probe RESULT structs). The generated de-box probes them by declared field / element.
381
+ type WireRow struct {
382
+ entries []WireField
383
+ }
384
+
385
+ type WireList struct {
386
+ items []WireValue
387
+ }
388
+
389
+ const (
390
+ wireNull uint8 = 0
391
+ wireStr uint8 = 1
392
+ wireNum uint8 = 2
393
+ wireBool uint8 = 3
394
+ wireRow uint8 = 4
395
+ wireList uint8 = 5
396
+ )
397
+
398
+ // constructors the consumer's transport uses to build the result (numbers ride as raw text).
399
+ func WireStr(s string) WireValue { return WireValue{kind: wireStr, str: s} }
400
+ func WireNum(s string) WireValue { return WireValue{kind: wireNum, num: s} }
401
+ func WireInt(n int64) WireValue { return WireValue{kind: wireNum, num: strconv.FormatInt(n, 10)} }
402
+ func WireFloat(f float64) WireValue { return WireValue{kind: wireNum, num: strconv.FormatFloat(f, 'g', -1, 64)} }
403
+ func WireBool(b bool) WireValue { return WireValue{kind: wireBool, bl: b} }
404
+ func WireNull() WireValue { return WireValue{kind: wireNull} }
405
+ func WireRowOf(fields []WireField) WireValue { return WireValue{kind: wireRow, Entries: fields} }
406
+ func WireListOf(items []WireValue) WireValue { return WireValue{kind: wireList, Items: items} }
407
+
408
+ func (w *WireValue) wireTag() string {
409
+ switch w.kind {
410
+ case wireStr:
411
+ return "S"
412
+ case wireNum:
413
+ return "N"
414
+ case wireBool:
415
+ return "BOOL"
416
+ case wireRow:
417
+ return "M"
418
+ case wireList:
419
+ return "L"
420
+ default:
421
+ return "NULL"
422
+ }
423
+ }
424
+ func (w *WireValue) wireRaw() string {
425
+ switch w.kind {
426
+ case wireStr:
427
+ return w.str
428
+ case wireNum:
429
+ return w.num
430
+ case wireBool:
431
+ if w.bl {
432
+ return "true"
433
+ }
434
+ return "false"
435
+ case wireNull:
436
+ return "null"
437
+ default:
438
+ return "[composite]"
439
+ }
440
+ }
441
+
442
+ // the top result is always present; field/elem probes share the same classifiers over *WireValue (nil = absent).
443
+ func (w WireValue) AsString() StringProbe { return probeStringOf(&w) }
444
+ func (w WireValue) AsNumber() NumberProbe { return probeNumberOf(&w) }
445
+ func (w WireValue) AsBool() BoolProbe { return probeBoolOf(&w) }
446
+ func (w WireValue) AsRow() RowProbe { return probeRowOf(&w) }
447
+ func (w WireValue) AsList() ListProbe { return probeListOf(&w) }
448
+
449
+ func (r WireRow) get(field string) *WireValue {
450
+ for i := range r.entries {
451
+ if r.entries[i].Key == field {
452
+ return &r.entries[i].Val
453
+ }
454
+ }
455
+ return nil
456
+ }
457
+ func (r WireRow) Keys() []string {
458
+ ks := make([]string, len(r.entries))
459
+ for i := range r.entries {
460
+ ks[i] = r.entries[i].Key
461
+ }
462
+ return ks
463
+ }
464
+ func (r WireRow) ProbeString(field string) StringProbe { return probeStringOf(r.get(field)) }
465
+ func (r WireRow) ProbeNumber(field string) NumberProbe { return probeNumberOf(r.get(field)) }
466
+ func (r WireRow) ProbeBool(field string) BoolProbe { return probeBoolOf(r.get(field)) }
467
+ func (r WireRow) ProbeRow(field string) RowProbe { return probeRowOf(r.get(field)) }
468
+ func (r WireRow) ProbeList(field string) ListProbe { return probeListOf(r.get(field)) }
469
+
470
+ func (l WireList) Len() int { return len(l.items) }
471
+ func (l WireList) ElemString(i int) StringProbe { return probeStringOf(&l.items[i]) }
472
+ func (l WireList) ElemNumber(i int) NumberProbe { return probeNumberOf(&l.items[i]) }
473
+ func (l WireList) ElemBool(i int) BoolProbe { return probeBoolOf(&l.items[i]) }
474
+ func (l WireList) ElemRow(i int) RowProbe { return probeRowOf(&l.items[i]) }
475
+ func (l WireList) ElemList(i int) ListProbe { return probeListOf(&l.items[i]) }
476
+
477
+ // the ONE classifier per kind, over *WireValue (nil = absent attribute/element). The BC-owned variant IS
478
+ // the wire tag — no consumer classification.
479
+ func probeStringOf(w *WireValue) StringProbe {
480
+ if w == nil {
481
+ return StringProbe{Kind: probeAbsent}
482
+ }
483
+ switch w.kind {
484
+ case wireStr:
485
+ return StringProbe{Kind: probeGot, Got: w.str, ActualWireType: "S", Raw: w.str}
486
+ case wireNull:
487
+ return StringProbe{Kind: probeNull, ActualWireType: "NULL", Raw: "null"}
488
+ default:
489
+ return StringProbe{Kind: probeWrong, ActualWireType: w.wireTag(), Raw: w.wireRaw()}
490
+ }
491
+ }
492
+ func probeNumberOf(w *WireValue) NumberProbe {
493
+ if w == nil {
494
+ return NumberProbe{Kind: probeAbsent}
495
+ }
496
+ switch w.kind {
497
+ case wireNum:
498
+ return NumberProbe{Kind: probeGot, Got: w.num, ActualWireType: "N", Raw: w.num}
499
+ case wireNull:
500
+ return NumberProbe{Kind: probeNull, ActualWireType: "NULL", Raw: "null"}
501
+ default:
502
+ return NumberProbe{Kind: probeWrong, ActualWireType: w.wireTag(), Raw: w.wireRaw()}
503
+ }
504
+ }
505
+ func probeBoolOf(w *WireValue) BoolProbe {
506
+ if w == nil {
507
+ return BoolProbe{Kind: probeAbsent}
508
+ }
509
+ switch w.kind {
510
+ case wireBool:
511
+ return BoolProbe{Kind: probeGot, Got: w.bl, ActualWireType: "BOOL", Raw: w.wireRaw()}
512
+ case wireNull:
513
+ return BoolProbe{Kind: probeNull, ActualWireType: "NULL", Raw: "null"}
514
+ default:
515
+ return BoolProbe{Kind: probeWrong, ActualWireType: w.wireTag(), Raw: w.wireRaw()}
516
+ }
517
+ }
518
+ func probeRowOf(w *WireValue) RowProbe {
519
+ if w == nil {
520
+ return RowProbe{Kind: probeAbsent}
521
+ }
522
+ switch w.kind {
523
+ case wireRow:
524
+ return RowProbe{Kind: probeGot, Got: WireRow{entries: w.Entries}, ActualWireType: "M"}
525
+ case wireNull:
526
+ return RowProbe{Kind: probeNull, ActualWireType: "NULL", Raw: "null"}
527
+ default:
528
+ return RowProbe{Kind: probeWrong, ActualWireType: w.wireTag(), Raw: w.wireRaw()}
529
+ }
530
+ }
531
+ func probeListOf(w *WireValue) ListProbe {
532
+ if w == nil {
533
+ return ListProbe{Kind: probeAbsent}
534
+ }
535
+ switch w.kind {
536
+ case wireList:
537
+ return ListProbe{Kind: probeGot, Got: WireList{items: w.Items}, ActualWireType: "L"}
538
+ case wireNull:
539
+ return ListProbe{Kind: probeNull, ActualWireType: "NULL", Raw: "null"}
540
+ default:
541
+ return ListProbe{Kind: probeWrong, ActualWireType: w.wireTag(), Raw: w.wireRaw()}
542
+ }
543
+ }`;
544
+ }
344
545
  /** mapFanoutElemRef — the element ROW TypeRef a map/fanout node decodes (the per-element record). */
345
546
  function mapFanoutElemRef(node, typedNodes, plan) {
346
547
  const ref = typedNodes.get(node.id);
@@ -354,8 +555,8 @@ function goPortFieldName(wire) {
354
555
  return /[a-z]/.test(head) ? head.toUpperCase() + safe.slice(1) : "F_" + safe;
355
556
  }
356
557
  function portsStructName(compName, nodeId) {
357
- // EXPORTED so a consumer (and the test bench, both in a DIFFERENT Go package) can name the ports
358
- // type to implement the per-component Handler_<comp> interface's concrete Node_* method signatures.
558
+ // EXPORTED so a consumer (and the test bench, both in a DIFFERENT Go package) can name the ports type
559
+ // in their leaf transport symbols (the batched/fanout transport takes the batch ports struct).
359
560
  return `PortsNR_${sanitize(compName)}_${nodeId.replace(/[^A-Za-z0-9_]/g, "_")}`;
360
561
  }
361
562
  /** scalar TypeRef → PortFieldType (native go scalar kind). */
@@ -794,12 +995,42 @@ type ${structName} struct {
794
995
  ${fields}
795
996
  }`;
796
997
  }
797
- /** handlerTypeName — the per-component CONCRETE handler type name the runner takes by value (one Node_*
798
- * method per node). It is NOT a bc-declared interface (a Go interface is vtable dynamic dispatch): the
799
- * consumer supplies a concrete type of this name (default `Handler_<comp>`) and the runner calls
800
- * `h.Node_*(...)` directly (zero dynamic dispatch, zero dictionary). */
801
- function handlerTypeName(compName) {
802
- return `Handler_${sanitize(compName)}`;
998
+ /**
999
+ * resolveLeafSymbol — the op-agnostic transport symbol a covered leaf (= catalog component) is called
1000
+ * through at its execution point. A consumer-supplied override (`leafTransport.symbols[component]`) wins;
1001
+ * else the in-package DEFAULT convention `Leaf_<sanitizedComponent>`. This is the ONE place leaf→symbol
1002
+ * resolution lives (SSoT) — the runner call sites, the import block, and the test observe transport fns all
1003
+ * read it. There is no per-node handler indirection: a leaf is ONE transport, not one method per node.
1004
+ */
1005
+ function goLeafSel(leaf) {
1006
+ return leaf?.import !== undefined ? `${leaf.import.split("/").pop().replace(/[^A-Za-z0-9_]/g, "_")}.` : "";
1007
+ }
1008
+ /** leafSymbolBare — the UNQUALIFIED transport symbol name (consumer override or the default Leaf_<comp>).
1009
+ * The ONE source for the name: call sites qualify it with the package selector (resolveLeafSymbol); the
1010
+ * observe companion DEFINES the fn under this bare name (a definition carries no selector). */
1011
+ function leafSymbolBare(component, leaf) {
1012
+ return leaf?.symbols[component] ?? `Leaf_${sanitize(component)}`;
1013
+ }
1014
+ function resolveLeafSymbol(component, leaf) {
1015
+ return `${goLeafSel(leaf)}${leafSymbolBare(component, leaf)}`;
1016
+ }
1017
+ /**
1018
+ * portFieldSpread — the covered node's port fields, in declared `Object.keys(ports)` order, each carrying
1019
+ * its native ports-struct field name + Go type. The ONE place the transport-call port spread is derived
1020
+ * (SSoT): a runner call site spreads `<var>.<F>`; the test observe transport fn declares matching params.
1021
+ * Types come from the SAME `portFieldGoType` lowering `emitPortsStruct` uses, so the spread can never
1022
+ * disagree with the ports struct field types. (Go has no borrow — every field is passed by value.)
1023
+ */
1024
+ function portFieldSpread(ports, comp, plan, typedNodes, asBinding) {
1025
+ const opts = asBinding !== undefined ? { asBinding, asBase: asBinding.name } : undefined;
1026
+ return Object.keys(ports).map((pn) => ({
1027
+ field: goPortFieldName(pn),
1028
+ goType: portFieldGoType(ports[pn], comp, plan, typedNodes, `port '${pn}' of node '${comp.name}'`, opts),
1029
+ }));
1030
+ }
1031
+ /** leafCallArgs — the spread transport-call arguments for a ports-struct var (Go: by value, no borrow). */
1032
+ function leafCallArgs(varExpr, spread) {
1033
+ return spread.map((p) => `${varExpr}.${p.field}`).join(", ");
803
1034
  }
804
1035
  /** RunNativeRawStruct_<comp> — the EXPORTED name of the per-component struct-returning combined runner
805
1036
  * (bc#102). It MUST be an exported Go identifier so a consumer in a DIFFERENT package can call it (a
@@ -809,39 +1040,6 @@ function handlerTypeName(compName) {
809
1040
  function runnerName(compName) {
810
1041
  return `RunNativeRawStruct_${sanitize(compName)}`;
811
1042
  }
812
- /** Node_<comp>_<nodeId> — the concrete per-node handler method name. */
813
- function nodeMethodName(compName, nodeId) {
814
- return `Node_${sanitize(compName)}_${nodeId.replace(/[^A-Za-z0-9_]/g, "_")}`;
815
- }
816
- /**
817
- * boundGoType (change #3 — typed `bound`) — the CONCRETE Go type of a covered node's `bound` handler
818
- * param (bc#90 / runtime-free). `bound` is the parent-produced key (the bindField value); it replaces
819
- * the old boxed `dslcontracts.Value`. We represent PRODUCED-vs-UNPRODUCED with a POINTER: a non-nil
820
- * `*T` means the parent value was produced/present (an empty string is a VALID produced value — a
821
- * non-nil `*string` to ""); a nil pointer means UNPRODUCED/skip (exactly the old `!= nil` guard ≡
822
- * run_behavior). The pointed-to type is the bindField's concrete Go type (a string key here). A node
823
- * WITHOUT a bindField never receives a bound value — its param is a `*string` placeholder always
824
- * passed `nil` (a typed nil, so the ABI stays uniform and carries NO dslcontracts.Value).
825
- */
826
- function boundGoType(node, comp, typedNodes, plan) {
827
- if (node.bindField === undefined || node.parent === undefined)
828
- return "*string";
829
- const parentRef = typedNodes.get(node.parent);
830
- if (parentRef === undefined)
831
- return "*string";
832
- let bfRef;
833
- try {
834
- bfRef = goTypedInternals.typedFieldAccess(typedLocal(node.parent), parentRef, [node.bindField], plan).ref;
835
- }
836
- catch {
837
- return "*string";
838
- }
839
- // opt bindField: the field is already a *T — the bound pointed-to type is the inner. A required
840
- // scalar bindField: the bound pointed-to type is that scalar's Go type.
841
- if (bfRef.kind === "opt")
842
- return `*${renderTypeRef(bfRef.inner)}`;
843
- return `*${renderTypeRef(bfRef)}`;
844
- }
845
1043
  /** mapElemMaterializerName — the augmented-element copier for a covered map...into node. */
846
1044
  function mapElemMaterializerName(compName, nodeId) {
847
1045
  return `materializeMapElemNR_${sanitize(compName)}_${nodeId.replace(/[^A-Za-z0-9_]/g, "_")}`;
@@ -1235,7 +1433,7 @@ function emitPortInit(pn, expr, comp, plan, typedNodes, isPrior, opts) {
1235
1433
  *
1236
1434
  * NO RunPlan / []OpSpec / planSpec walk: the staging, the bound, and which ops are parallel are baked.
1237
1435
  */
1238
- function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes, plan, priorNodeAt, zeroOut, flags, wire) {
1436
+ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes, plan, priorNodeAt, zeroOut, flags, wire, leaf) {
1239
1437
  const lines = [];
1240
1438
  const ids = stage.map((i) => comp.body[i].id);
1241
1439
  lines.push(`\t// ── bc#87 real-concurrency stage {${ids.map((x) => JSON.stringify(x)).join(", ")}} — static parallel`);
@@ -1279,12 +1477,6 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
1279
1477
  lines.push(`\t\trun_${s} := false`);
1280
1478
  lines.push(`\t\tvar ps_${s} ${structName}`);
1281
1479
  lines.push(`\t\t_ = ps_${s}`);
1282
- // #114: a bindField relation child member carries its produced-aware bound key (a typed pointer,
1283
- // nil => UNPRODUCED/skip) into the goroutine — declared at stage scope, assigned in preflight.
1284
- if (node.bindField !== undefined) {
1285
- lines.push(`\t\tvar bound_${s} ${boundGoType(node, comp, typedNodes, plan)}`);
1286
- lines.push(`\t\t_ = bound_${s}`);
1287
- }
1288
1480
  }
1289
1481
  // 1) PREFLIGHT (ascending): parent-produced gate (+ #114 bindField bound-key gate) + ports build,
1290
1482
  // per member (BEFORE dispatch). For a bindField relation child the bound key is read from the SETTLED
@@ -1306,18 +1498,19 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
1306
1498
  closers.unshift(`${ind}}`);
1307
1499
  ind += "\t";
1308
1500
  if (node.bindField !== undefined && parentIsGate) {
1309
- lines.push(`${ind}gateOK_${s} := "ok"`);
1310
- lines.push(`${ind}bound_${s} = &gateOK_${s}`);
1501
+ // #125: a control-gate parent — produced_<gate> already carries the skip; no bound needed here
1502
+ // (the leaf transport no longer receives it, the child ports read the real data parent).
1311
1503
  }
1312
1504
  else if (node.bindField !== undefined) {
1505
+ // bound is the preflight skip-gate condition only (a local — the goroutine no longer captures it).
1313
1506
  const parentRef = typedNodes.get(node.parent);
1314
1507
  const { expr: bfExpr, ref: bfRef } = goTypedInternals.typedFieldAccess(typedLocal(node.parent), parentRef, [node.bindField], plan);
1315
1508
  if (bfRef.kind === "opt") {
1316
- lines.push(`${ind}bound_${s} = ${bfExpr}`);
1509
+ lines.push(`${ind}bound_${s} := ${bfExpr}`);
1317
1510
  }
1318
1511
  else {
1319
1512
  lines.push(`${ind}boundV_${s} := ${bfExpr}`);
1320
- lines.push(`${ind}bound_${s} = &boundV_${s}`);
1513
+ lines.push(`${ind}bound_${s} := &boundV_${s}`);
1321
1514
  }
1322
1515
  lines.push(`${ind}if bound_${s} != nil {`);
1323
1516
  closers.unshift(`${ind}}`);
@@ -1346,8 +1539,10 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
1346
1539
  lines.push(`\t\t\tgo func() {`);
1347
1540
  lines.push(`\t\t\t\tdefer wg.Done()`);
1348
1541
  lines.push(`\t\t\t\tdefer func() { <-sem }()`);
1349
- const boundArg = node.bindField !== undefined ? `bound_${s}` : "nil";
1350
- lines.push(`\t\t\t\twire_${s}, row_${s}Err = handlers.${nodeMethodName(comp.name, node.id)}(ps_${s}, ${boundArg})`);
1542
+ // DIRECT leaf transport call — the node's port fields spread off the preflight-built ports struct. No
1543
+ // `bound` (BC's internal produced/skip gate is already applied in preflight — the leaf never sees it).
1544
+ const call = `${resolveLeafSymbol(node.component, leaf)}(${leafCallArgs(`ps_${s}`, portFieldSpread(node.ports, comp, plan, typedNodes))})`;
1545
+ lines.push(`\t\t\t\twire_${s}, row_${s}Err = ${call}`);
1351
1546
  lines.push(`\t\t\t}()`);
1352
1547
  lines.push(`\t\t}`);
1353
1548
  }
@@ -1404,18 +1599,24 @@ function emitParallelStageArm(comp, stage, atPos, concurrency, metas, typedNodes
1404
1599
  * consumer (graphddb) drives it and keeps the struct native. A Value observation is produced ONLY
1405
1600
  * by the separate serialize wrapper (run_native_raw_<comp>, below), the single outer Value boundary.
1406
1601
  */
1407
- function emitNativeRawRunner(comp, plan, flags, wire) {
1602
+ /** isCrossPackageSharedNode — a node whose ports struct CROSSES the leaf-transport boundary as a whole
1603
+ * value (the batch ports struct passed to the transport), so under --shared-types-import it must live in
1604
+ * the shared package (else the transport package → covered package import cycle). Batched maps + fanouts
1605
+ * pass `${struct}_batch{Items: []${struct}}`; every other node passes only primitive port fields, so its
1606
+ * ports struct stays local. The SINGLE predicate emit() (skip-local) and the shared package (emit-there)
1607
+ * both use — they never disagree. */
1608
+ function isCrossPackageSharedNode(n) {
1609
+ return "fanout" in n || ("map" in n && n.map.batched === true);
1610
+ }
1611
+ function emitNativeRawRunner(comp, plan, flags, wire, leaf) {
1408
1612
  const ep = execPlan(comp);
1409
1613
  const order = ep.order;
1410
1614
  const cplan = buildComponentPlan(comp, goStraightlineInternals.dialect, "scope");
1411
1615
  const metas = analyzeSequentialOps(cplan.opsLiteral, order);
1412
1616
  const fn = sanitize(comp.name);
1413
- const typedNodes = new Map();
1414
1617
  // #125: a control-gate cond has NO outType (skip marker) — it never yields a typed data cell, so it
1415
1618
  // carries no typedNodes entry. Its skip is expressed purely via produced_<gate> (children gate on it).
1416
- for (const n of comp.body)
1417
- if (!isControlGate(n))
1418
- typedNodes.set(n.id, "map" in n ? mapNodeArrRef(n, plan) : deriveTypeRef(n.outType, plan));
1619
+ const typedNodes = buildTypedNodes(comp, plan);
1419
1620
  const idToPos = new Map();
1420
1621
  order.forEach((opIdx, k) => idToPos.set(comp.body[opIdx].id, k));
1421
1622
  const priorNodeAt = (head, atPos) => {
@@ -1441,12 +1642,12 @@ function emitNativeRawRunner(comp, plan, flags, wire) {
1441
1642
  lines.push(`// index order so the observed value / op multiset / failure precedence byte-match run_behavior`);
1442
1643
  lines.push(`// (the goroutine spawn is the ONLY runtime element — the WHAT is baked). The output is a typed`);
1443
1644
  lines.push(`// struct/value assembled by struct literal + field access — the consumer keeps it native.`);
1444
- // FULLY CONCRETE + NON-GENERIC: the runner takes the consumer's CONCRETE ${handlerTypeName(comp.name)}
1445
- // handler by value and calls h.Node_*(...) DIRECTLY (a Go generic method call goes through a dictionary,
1446
- // a Go interface through a vtable — BOTH are dynamic dispatch, so the covered plane uses neither). Each
1447
- // Node_* returns the node's result WIRE (a single ${wire.value}); the runner de-boxes it INLINE
1448
- // (fully-unrolled probe/match — no decode helper, no output recursion) into the node's outType struct.
1449
- lines.push(`func ${runnerName(comp.name)}(handlers ${handlerTypeName(comp.name)}, in ${inStructName(comp.name)}) (${outStructType}, error) {`);
1645
+ // At each covered node's execution point the runner calls the op-agnostic leaf TRANSPORT symbol
1646
+ // (default Leaf_<comp>) DIRECTLY with the node's port fields spread — no per-node handler indirection, no
1647
+ // interface, no generics (both are dynamic dispatch). Each transport returns the node's result WIRE (a
1648
+ // single ${wire.value}); the runner de-boxes it INLINE (fully-unrolled probe/match — no decode helper, no
1649
+ // output recursion) into the node's outType struct.
1650
+ lines.push(`func ${runnerName(comp.name)}(in ${inStructName(comp.name)}) (${outStructType}, error) {`);
1450
1651
  lines.push(`\t_ = in`);
1451
1652
  for (const k of order.keys()) {
1452
1653
  const node = comp.body[order[k]];
@@ -1470,19 +1671,19 @@ function emitNativeRawRunner(comp, plan, flags, wire) {
1470
1671
  // ascending-sorted stages), so we emit the block at the first member and skip the rest.
1471
1672
  const stage = ep.parallelStageOf.get(i);
1472
1673
  if (stage !== undefined && stage[0] === i) {
1473
- lines.push(emitParallelStageArm(comp, stage, k, ep.concurrency, metas, typedNodes, plan, priorNodeAt, zeroOut, flags, wire));
1674
+ lines.push(emitParallelStageArm(comp, stage, k, ep.concurrency, metas, typedNodes, plan, priorNodeAt, zeroOut, flags, wire, leaf));
1474
1675
  k += stage.length - 1;
1475
1676
  continue;
1476
1677
  }
1477
1678
  // v3: a covered fanout node — deduped batched dispatch + first-seen dedupe + dangling drop +
1478
1679
  // connection wrap (the SAME definition as run_behavior's fanoutDedupDrop).
1479
1680
  if ("fanout" in comp.body[i]) {
1480
- lines.push(emitFanoutArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, zeroOut));
1681
+ lines.push(emitFanoutArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, zeroOut, leaf, wire.selector));
1481
1682
  continue;
1482
1683
  }
1483
1684
  // #86 pt2: a covered batched map...into node — struct-native element collection + into enrichment.
1484
1685
  if ("map" in comp.body[i]) {
1485
- lines.push(emitMapArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, zeroOut, flags));
1686
+ lines.push(emitMapArm(comp, comp.body[i], k, typedNodes, plan, priorNodeAt, zeroOut, flags, leaf, wire.selector));
1486
1687
  continue;
1487
1688
  }
1488
1689
  // #108: a cond node — pure Expression (no handler). Compile `if` to a native bool + materialize the
@@ -1507,12 +1708,10 @@ function emitNativeRawRunner(comp, plan, flags, wire) {
1507
1708
  closers.unshift(`${indent}}`);
1508
1709
  indent += "\t";
1509
1710
  if (node.bindField !== undefined && parentIsGate) {
1510
- // #125: a when(...) control-gate parent. gate の bindField:"ok" は run_behavior では成立時
1511
- // `true` / 不成立時 `null`(→ null-binding skip)。native では produced_<gate>(= gate の `if`)
1512
- // が既にその skip を担うので、ここに来た時点で gate は成立。bound は skip の sentinel(データ
1513
- // キーではない — 子の ports は実データ親を参照する)として、非 nil の `*string` を渡す。
1514
- lines.push(`${indent}gateOK_${s} := "ok"`);
1515
- lines.push(`${indent}bound_${s} := &gateOK_${s}`);
1711
+ // #125: a when(...) control-gate parent. produced_<gate> (= the gate's `if`) ALREADY carries the
1712
+ // skip, so past it the gate held — there is no further skip to gate here. The bindField:"ok" was
1713
+ // only a sentinel formerly passed to the handler; the leaf transport no longer receives `bound`, so
1714
+ // NO bound local is emitted (the child ports read the real data parent, not the gate).
1516
1715
  }
1517
1716
  else if (node.bindField !== undefined) {
1518
1717
  // bind (change #3 — typed produced-aware bound): read the parent struct field DIRECTLY (typed
@@ -1541,12 +1740,15 @@ function emitNativeRawRunner(comp, plan, flags, wire) {
1541
1740
  // static string array / number literal) assigned straight into the ports field — ZERO
1542
1741
  // dslcontracts.Value, ZERO nvVE helper, ZERO `.(T)`. A genuinely-dynamic port FAILS CLOSED.
1543
1742
  const inits = [];
1544
- const boundArg = node.bindField !== undefined ? `bound_${s}` : "nil";
1545
1743
  for (const pn of portNames) {
1546
1744
  inits.push(emitPortInit(pn, node.ports[pn], comp, plan, typedNodes, (h) => priorNodeAt(h, k)));
1547
1745
  }
1746
+ // DIRECT leaf transport call: the resolved op-agnostic symbol, the node's port fields spread. `bound` is
1747
+ // NOT passed — it is BC's internal produced/skip gate, already enforced by the surrounding
1748
+ // `if bound_<s> != nil` / `if produced_<parent>` guards; the leaf never receives it.
1749
+ const call = `${resolveLeafSymbol(node.component, leaf)}(${leafCallArgs(`ports_${s}`, portFieldSpread(node.ports, comp, plan, typedNodes))})`;
1548
1750
  lines.push(`${indent}ports_${s} := ${structName}{${inits.join(", ")}}`);
1549
- // uniform seam: the handler returns a single result WIRE (${wire.value}); the inline de-box
1751
+ // uniform seam: the transport returns a single result WIRE (${wire.value}); the inline de-box
1550
1752
  // (renderResultDeBox) classifies it against the STATICALLY declared result type and produces the
1551
1753
  // structured Error Value on a mismatch (byte-equal codes to run_behavior's outType check, so ≡ holds).
1552
1754
  if (meta.policy === "continue") {
@@ -1556,7 +1758,7 @@ function emitNativeRawRunner(comp, plan, flags, wire) {
1556
1758
  // are always 'fail' policy today — this arm is defensive.)
1557
1759
  const nodeGo = renderTypeRef(ref);
1558
1760
  const nodeZeroFail = (e) => `return ${goZero(ref)}, ${e}`;
1559
- lines.push(`${indent}if wire_${s}, wire_${s}Err := handlers.${nodeMethodName(comp.name, node.id)}(ports_${s}, ${boundArg}); wire_${s}Err == nil {`);
1761
+ lines.push(`${indent}if wire_${s}, wire_${s}Err := ${call}; wire_${s}Err == nil {`);
1560
1762
  lines.push(`${indent}\tdec_${s}, dec_${s}DErr := func() (${nodeGo}, error) {`);
1561
1763
  lines.push(`${indent}\t\tvar out ${nodeGo}`);
1562
1764
  lines.push(renderResultDeBox(ref, "out", `wire_${s}`, node.id, plan, `${indent}\t\t`, nodeZeroFail, seqCtr));
@@ -1570,7 +1772,7 @@ function emitNativeRawRunner(comp, plan, flags, wire) {
1570
1772
  }
1571
1773
  else {
1572
1774
  const policyLit = JSON.stringify(meta.policy === "retry" ? "retry" : "fail");
1573
- lines.push(`${indent}wire_${s}, wire_${s}Err := handlers.${nodeMethodName(comp.name, node.id)}(ports_${s}, ${boundArg})`);
1775
+ lines.push(`${indent}wire_${s}, wire_${s}Err := ${call}`);
1574
1776
  lines.push(`${indent}if wire_${s}Err != nil {`);
1575
1777
  lines.push(`${indent}\treturn ${zeroOut}, opFailed(${JSON.stringify(node.id)}, ${policyLit}, wire_${s}Err)`);
1576
1778
  lines.push(`${indent}}`);
@@ -1627,14 +1829,19 @@ function emitNativeRawRunner(comp, plan, flags, wire) {
1627
1829
  * (direct field assignment; $as refs read the over element's typed fields), and the result is a
1628
1830
  * native []T with NO boxed Value on any plane. The map is under the parent's produced gate (inline).
1629
1831
  */
1630
- function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, flags) {
1832
+ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, flags, leaf, wireSel) {
1631
1833
  const m = node.map;
1632
1834
  const batched = m.batched === true;
1633
1835
  const hasInto = m.into !== undefined;
1634
1836
  const hasGuard = m.when !== undefined;
1635
1837
  const s = sanitize(node.id);
1636
- const structName = portsStructName(comp.name, node.id);
1838
+ // #154 cross-package: a BATCHED map's element + batch ports structs live in the shared package (they
1839
+ // cross the transport boundary as a whole value), so reference them selector-qualified here. A
1840
+ // non-batched map passes only primitive fields, so its ports struct stays local (unqualified).
1841
+ const q = wireSel !== undefined && batched ? `${wireSel}.` : "";
1842
+ const structName = `${q}${portsStructName(comp.name, node.id)}`;
1637
1843
  const batchStruct = `${structName}_batch`;
1844
+ const leafSym = resolveLeafSymbol(m.component, leaf);
1638
1845
  const arrRef = typedNodes.get(node.id);
1639
1846
  const elemGo = renderTypeRef(arrRef);
1640
1847
  const asName = m.as;
@@ -1717,7 +1924,9 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
1717
1924
  // empty items => empty result (handler not called), matching run_behavior.
1718
1925
  lines.push(`${indent}if len(items_${s}) > 0 {`);
1719
1926
  lines.push(`${indent}\tbp_${s} := ${batchStruct}{Items: items_${s}}`);
1720
- lines.push(`${indent}\tmo_${s}, mo_${s}Err := handlers.${nodeMethodName(comp.name, node.id)}(bp_${s}, nil)`);
1927
+ // DIRECT transport call — the batched dispatch takes the CONCRETE batch ports struct (shape unchanged;
1928
+ // only the call target changes). Returns the aligned per-element wires ([]WireValue). No `bound`.
1929
+ lines.push(`${indent}\tmo_${s}, mo_${s}Err := ${leafSym}(bp_${s})`);
1721
1930
  lines.push(`${indent}\tif mo_${s}Err != nil {`, `${indent}\t\treturn ${zeroOut}, opFailed(${JSON.stringify(node.id)}, "fail", mo_${s}Err)`, `${indent}\t}`);
1722
1931
  lines.push(`${indent}\tif len(mo_${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}`);
1723
1932
  if (hasInto) {
@@ -1756,7 +1965,7 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
1756
1965
  // Element Error Policy (scp-error.md): `skip` drops the failing element and proceeds (order is
1757
1966
  // preserved; the leaf keeps the Error Value it produced). `error` (default) promotes the element
1758
1967
  // Failure to the map's Component Failure, carrying the leaf's detail through.
1759
- lines.push(`${indent}\tmo_${s}, mo_${s}Err := handlers.${nodeMethodName(comp.name, node.id)}(ep_${s}, nil)`);
1968
+ lines.push(`${indent}\tmo_${s}, mo_${s}Err := ${leafSym}(${leafCallArgs(`ep_${s}`, portFieldSpread(m.ports, comp, plan, typedNodes, { name: asName, ref: overElemRef, plan }))})`);
1760
1969
  if (m.elementPolicy === "skip") {
1761
1970
  lines.push(`${indent}\tif mo_${s}Err != nil {`, `${indent}\t\tcontinue`, `${indent}\t}`);
1762
1971
  }
@@ -1797,11 +2006,15 @@ function elemLocal(s) {
1797
2006
  * (STRUCTURAL — the connection items elem type already omits the implicitSource field), and wrap into
1798
2007
  * the connection struct {items, cursor:nil}. NO boxed Value on any plane. Byte-equal to run_behavior.
1799
2008
  */
1800
- function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut) {
2009
+ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, leaf, wireSel) {
1801
2010
  const f = node.fanout;
1802
2011
  const s = sanitize(node.id);
1803
- const structName = portsStructName(comp.name, node.id);
2012
+ // #154 cross-package: a fanout's element + batch ports structs cross the transport boundary as a whole
2013
+ // value, so they live in the shared package — reference them selector-qualified here (else in-package).
2014
+ const q = wireSel !== undefined ? `${wireSel}.` : "";
2015
+ const structName = `${q}${portsStructName(comp.name, node.id)}`;
1804
2016
  const batchStruct = `${structName}_batch`;
2017
+ const leafSym = resolveLeafSymbol(f.component, leaf);
1805
2018
  const connRef = typedNodes.get(node.id);
1806
2019
  const elemRef = fanoutItemsElemRef(node, connRef, plan);
1807
2020
  const elemGo = renderTypeRef(elemRef);
@@ -1847,7 +2060,9 @@ function emitFanoutArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut
1847
2060
  // the handler returns the aligned per-id element WIRES (one nilable WireValue per id); each present
1848
2061
  // body is de-boxed strictly INLINE (a de-box mismatch fails closed). A DANGLING id is a nil wire → the
1849
2062
  // zero element (empty dedupeKey), which the dangling drop below excludes.
1850
- lines.push(`${indent}\tfo_${s}, fo_${s}Err := handlers.${nodeMethodName(comp.name, node.id)}(bp_${s}, nil)`);
2063
+ // DIRECT transport call — the batched fanout dispatch takes the CONCRETE batch ports struct (shape
2064
+ // unchanged; only the call target changes). Returns the aligned per-id element wires. No `bound`.
2065
+ lines.push(`${indent}\tfo_${s}, fo_${s}Err := ${leafSym}(bp_${s})`);
1851
2066
  lines.push(`${indent}\tif fo_${s}Err != nil {`, `${indent}\t\treturn ${zeroOut}, opFailed(${JSON.stringify(node.id)}, "fail", fo_${s}Err)`, `${indent}\t}`);
1852
2067
  lines.push(`${indent}\tif len(fo_${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}`);
1853
2068
  // ── THE ONE dedupe/drop (mirrors fanoutDedupDrop verbatim): first-seen dedupe by dedupeKey field;
@@ -2306,9 +2521,9 @@ func bcExpr_strGe(a, b string) bool { return bcExpr_cmpCP(a, b) >= 0 }`;
2306
2521
  * which lives OUTSIDE this module so the covered module stays literal whole-file zero. */
2307
2522
  function emitStructSurface(native) {
2308
2523
  return `// ComponentNamesNativeRaw — covered reads exposed on the combined struct-native path (declaration
2309
- // order). Each is driven via RunNativeRawStruct_<comp>(handlers, input) -> (T, error): a STRUCT
2310
- // return; the consumer keeps the model native (no Value serialization on the read hot path — the
2311
- // boxing residue bc#77 removes). See INTEGRATION.md §6.
2524
+ // order). Each is driven via RunNativeRawStruct_<comp>(input) -> (T, error): a STRUCT return; the consumer
2525
+ // keeps the model native (no Value serialization on the read hot path — the boxing residue bc#77 removes)
2526
+ // and supplies the op-agnostic leaf transport symbols the runner calls. See INTEGRATION.md §6.
2312
2527
  var ComponentNamesNativeRaw = []string{${native.map((c) => JSON.stringify(c.name)).join(", ")}}`;
2313
2528
  }
2314
2529
  /** Minimal module header for a FULLY-covered module (bc#90 / runtime-free). A fully-covered module
@@ -2316,7 +2531,7 @@ var ComponentNamesNativeRaw = []string{${native.map((c) => JSON.stringify(c.name
2316
2531
  * mismatch Sprintf, `strings` for a concat builder, `sync` for a parallel stage). ExpectedSpecVersions
2317
2532
  * stays as a local `var` for provenance, but the old `dslcontracts.SpecVersions` skew `init()` is GONE
2318
2533
  * (change #5 — there is no runtime to skew against once the module is runtime-free). */
2319
- function emitMinimalHeader(ctx, needStrings, needSync, needFmt, needMath, needStrconv = false, wireImport) {
2534
+ function emitMinimalHeader(ctx, needStrings, needSync, needFmt, needMath, needStrconv = false, wireImport, leafImport) {
2320
2535
  const sv = ctx.specVersions;
2321
2536
  const imports = [];
2322
2537
  if (needFmt)
@@ -2329,10 +2544,15 @@ function emitMinimalHeader(ctx, needStrings, needSync, needFmt, needMath, needSt
2329
2544
  imports.push(`\t"strings"`);
2330
2545
  if (needSync)
2331
2546
  imports.push(`\t"sync"`);
2332
- // a configured consumer wire package (goWire.import) — the covered module references its CONCRETE
2333
- // WireValue/WireRow/WireList types (default: in-package, no import).
2547
+ // the BC-generated shared wire package (sharedTypesImport) — the covered module references its
2548
+ // BC-OWNED WireValue/WireRow/WireList (+ batched/fanout batch ports structs) qualified by the
2549
+ // package selector (default: in-package, no import).
2334
2550
  if (wireImport !== undefined)
2335
2551
  imports.push(`\t${JSON.stringify(wireImport)}`);
2552
+ // a configured leaf-transport package (leafTransport.import) — the covered module calls the op-agnostic
2553
+ // transport symbols qualified by its selector (default: in-package / same package, no import).
2554
+ if (leafImport !== undefined && leafImport !== wireImport)
2555
+ imports.push(`\t${JSON.stringify(leafImport)}`);
2336
2556
  const importBlock = imports.length > 0 ? `\nimport (\n${imports.join("\n")}\n)\n` : "";
2337
2557
  return `// GENERATED by behavior-contracts (bc#90, go-typed-native — the RUNTIME-FREE covered read de-box) — DO NOT EDIT.
2338
2558
  // Input: portable component-graph IR only. Every component here is a COVERED READ (sequential typed
@@ -2359,6 +2579,7 @@ function emit(ctx) {
2359
2579
  // a fallible checked-arith helper call — determines whether the helper library + `math` import ship).
2360
2580
  goExprUsed.helpers = false;
2361
2581
  const wire = resolveGoWire(ctx);
2582
+ const leaf = ctx.leafTransport;
2362
2583
  // Emit the runners first so the nv* helper usage flags are known.
2363
2584
  const flags = { bind: false, field: false, cat: false, arr: false };
2364
2585
  const structs = [];
@@ -2368,15 +2589,20 @@ function emit(ctx) {
2368
2589
  // every covered node returns a WireValue the inline de-box classifies — the wire seam (probe kind
2369
2590
  // consts + probe RESULT structs) is emitted once whenever any handler node exists.
2370
2591
  const anyWire = native.some((c) => c.body.some((n) => !("cond" in n)));
2592
+ // #154 cross-package (--shared-types-import): a batched-map / fanout batch ports struct crosses the
2593
+ // transport boundary as a whole value, so it lives in the SHARED package (goSharedWireTypesPackage),
2594
+ // NOT the covered module — else the transport package would import the covered package (cycle). Every
2595
+ // other ports struct passes only primitive fields and stays local.
2596
+ const crossPackage = wire.import !== undefined;
2371
2597
  for (const c of native) {
2372
2598
  inStructs.push(emitInStruct(c, plan));
2373
- const typedNodes = new Map();
2374
2599
  // build the full typed-node map FIRST so a map's over-element resolution can see every node.
2375
- for (const n of c.body)
2376
- if (!isControlGate(n))
2377
- typedNodes.set(n.id, "map" in n ? mapNodeArrRef(n, plan) : deriveTypeRef(n.outType, plan)); // #125: control-gate typeless; map は produced-array ref に正規化
2600
+ const typedNodes = buildTypedNodes(c, plan);
2378
2601
  for (const n of c.body) {
2379
- if ("fanout" in n) {
2602
+ if (crossPackage && isCrossPackageSharedNode(n)) {
2603
+ // emitted in the shared package instead (goSharedWireTypesPackage), referenced here as <sel>.<T>.
2604
+ }
2605
+ else if ("fanout" in n) {
2380
2606
  // v3: a fanout node emits a per-id element ports struct + a batch struct (like a batched map).
2381
2607
  structs.push(emitFanoutPortsStructs(c, n, typedNodes, plan));
2382
2608
  }
@@ -2397,7 +2623,7 @@ function emit(ctx) {
2397
2623
  const mm = emitMapElemMaterializers(c, typedNodes, plan);
2398
2624
  if (mm)
2399
2625
  elemCopiers.push(mm);
2400
- const r = emitNativeRawRunner(c, plan, flags, wire);
2626
+ const r = emitNativeRawRunner(c, plan, flags, wire, leaf);
2401
2627
  runnerCodes.push(r.code);
2402
2628
  }
2403
2629
  const structSurface = emitStructSurface(native);
@@ -2426,31 +2652,43 @@ function emit(ctx) {
2426
2652
  // #108: `math` is imported iff the native-expr compiler emitted a fallible helper (bcExpr_modF uses
2427
2653
  // math.Mod). The helper library itself is baked into the module only when used (goExprUsed.helpers).
2428
2654
  const needMath = goExprUsed.helpers;
2429
- // `strconv` is imported iff a generated inline de-box parses a numeric field (int/float range check).
2430
- const needStrconv = runnerCodes.some((c) => c.includes("strconv."));
2431
- const header = emitMinimalHeader(ctx, false, needSync, needFmt, needMath, needStrconv, wire.import);
2655
+ // `strconv` is imported iff a generated inline de-box parses a numeric field (int/float range check) OR
2656
+ // the BC-owned wire types are emitted in-package (their WireInt/WireFloat constructors use strconv).
2657
+ const emitsWireTypes = anyWire && wire.import === undefined;
2658
+ const needStrconv = runnerCodes.some((c) => c.includes("strconv.")) || emitsWireTypes;
2659
+ // the covered module imports the shared wire package ONLY when it NAMES a qualified shared symbol — a
2660
+ // `var wire_s <pkg>.WireValue` (bc#87 parallel stage) OR a `<pkg>.PortsNR_*` batched/fanout ports struct
2661
+ // (#154 cross-package). A point/relation read holds the transport's return by inference + uses its LOCAL
2662
+ // probe consts, so it references nothing from the shared package and must NOT import it (an unused import
2663
+ // is a Go compile error). The `<sel>.` prefix covers both (wire.value is `<sel>.WireValue`).
2664
+ const needWireImport = wire.import !== undefined && wire.selector !== undefined && runnerCodes.some((c) => c.includes(`${wire.selector}.`));
2665
+ const header = emitMinimalHeader(ctx, false, needSync, needFmt, needMath, needStrconv, needWireImport ? wire.import : undefined, leaf?.import);
2432
2666
  const banner = `// COMBINED READ layer (bc#90 — the RUNTIME-FREE read de-box; STRUCT-ONLY, FULLY-NATIVE surface). A
2433
2667
  // covered read is a strictly-sequential typed componentRef chain (point reads + relationKind:single
2434
2668
  // children), emitted ONLY here: each node builds a native ports struct by direct field assignment (every
2435
2669
  // port is a CONCRETE Go value — string / bool / []string projection / int64 limit — NO boxed Value, NO
2436
- // PortReader accessor); the runner takes the consumer's CONCRETE Handler_<comp> handler by
2437
- // value and calls h.Node_*(...) DIRECTLY (no interface, no generics — zero dynamic dispatch). Each Node_*
2438
- // takes a typed produced-aware 'bound' pointer and returns the node's result WIRE (a single ${wire.value});
2439
- // the runner de-boxes it INLINE (fully-unrolled probe/match — no decode helper, no output recursion) into
2440
- // the node's outType struct. The covered plane carries NO bc-runtime reference at all — failures use the
2441
- // LOCAL *BehaviorError (same codes, byte-equal to run_behavior). Exec is INLINE sequential (no plan driver)
2442
- // so a relation child reads the parent's REAL struct result via direct field access and the child-present
2443
- // decision is made from the real parent value — relationSingle / connection converge with run_behavior
2444
- // (fixes #323/#74). The exposed API is the STRUCT-returning RunNativeRawStruct_<comp> (the consumer keeps
2445
- // the model native — no serialization on the read hot path). This module is FULLY NATIVE: a naive grep for
2670
+ // PortReader accessor); the runner calls the op-agnostic leaf TRANSPORT symbol (default Leaf_<comp>)
2671
+ // DIRECTLY with the node's port fields spread (no per-node handler indirection, no interface, no generics —
2672
+ // zero dynamic dispatch). A leaf is ONE transport, not one method per authored node. The transport returns
2673
+ // the node's result WIRE (a single ${wire.value}); the runner de-boxes it INLINE (fully-unrolled
2674
+ // probe/match — no decode helper, no output recursion) into the node's outType struct. The covered plane
2675
+ // carries NO bc-runtime reference at all — failures use the LOCAL *BehaviorError (same codes, byte-equal to
2676
+ // run_behavior). Exec is INLINE sequential (no plan driver) so a relation child reads the parent's REAL
2677
+ // struct result via direct field access and the child-present decision is made from the real parent value —
2678
+ // relationSingle / connection converge with run_behavior (fixes #323/#74). The exposed API is the
2679
+ // STRUCT-returning RunNativeRawStruct_<comp>; the consumer supplies the leaf transport symbols (default
2680
+ // same-package Leaf_<comp>, or a leafTransport import). This module is FULLY NATIVE: a naive grep for
2446
2681
  // boxing primitives OR for the bc-runtime package finds nothing, by design (bc#90/runtime-free).`;
2447
2682
  const sections = [
2448
2683
  banner,
2449
2684
  `// Local concrete failure type (runtime-free) — a covered runner returns *BehaviorError (satisfies\n// error) instead of a bc-runtime failure, so the fully-covered module imports ZERO bc runtime.\n${behaviorErrorType}`,
2450
2685
  decls ? `// Typed struct declarations (outType-derived; hash-dedup — shared type plan).\n${decls}` : undefined,
2451
2686
  `// Per-component CONCRETE input structs (fields = inputPorts; the consumer builds them natively —\n// no generic *Obj crosses the covered read boundary).\n${inStructs.join("\n\n")}`,
2452
- anyWire
2453
- ? `// strict de-box wire seam — the consumer supplies CONCRETE ${wire.value} / ${wire.row} / ${wire.list}\n// types (variant classification) and the runner classifies each node result against the STATICALLY\n// declared type via their methods; the generated INLINE de-box owns strictness (required/optional,\n// present/absent, error assembly, fail-closed). bc emits only the probe RESULT structs — concrete data,\n// no boxed Value, no interface, no dictionary crosses the seam.\n${emitProbeWireTypes(wire)}`
2687
+ // the probe kind consts live in the covered module ALWAYS (the inline de-box compares against them); the
2688
+ // shared wire package carries its own identical copy when the types are hoisted there (cross-package).
2689
+ anyWire ? `// Probe kind consts (the inline de-box compares against these).\n${emitGoProbeKinds()}` : undefined,
2690
+ emitsWireTypes
2691
+ ? `// strict de-box wire seam — the BC-OWNED, BC-GENERATED concrete WireValue (+ WireRow/WireList) the\n// consumer's single transport builds + returns (implementing NOTHING over it), plus the probe RESULT\n// structs. The generated INLINE de-box classifies it against the STATICALLY declared type and owns\n// strictness (required/optional, present/absent, error assembly, fail-closed). Self-contained concrete\n// types — no interface, no boxed runtime value.\n${emitProbeWireTypes(wire)}\n\n${emitGoWireTypes()}`
2454
2692
  : undefined,
2455
2693
  elemCopiers.length
2456
2694
  ? `// Augmented map-element copiers (over element fields + the concrete into row — pure assignment).\n${elemCopiers.join("\n\n")}`
@@ -2466,15 +2704,59 @@ function emit(ctx) {
2466
2704
  ].filter((s) => !!s);
2467
2705
  return `${header}\n\n${sections.join("\n\n")}\n`;
2468
2706
  }
2707
+ /**
2708
+ * goSharedWireTypesPackage — the BC-GENERATED shared package (Task A cross-package). Emits the SAME seam the
2709
+ * covered module emits in-package (emitGoProbeKinds + emitProbeWireTypes + emitGoWireTypes) into a standalone
2710
+ * package, so a separate leaf-transport package can return `WireValue` (and the covered module reference it)
2711
+ * without an import cycle. When `ir` is given, ALSO emits the batched-map / fanout batch ports structs (the
2712
+ * ONLY covered-module types that cross the transport boundary as a whole value) — same `emitMapPortsStructs`
2713
+ * / `emitFanoutPortsStructs` + same `isCrossPackageSharedNode` predicate `emit()` uses to skip them locally,
2714
+ * so the two never disagree (SSoT). Self-contained (only `strconv` for the numeric constructors). `pkgName`
2715
+ * is the package's Go identifier (the last path segment of `sharedTypesImport`). */
2716
+ export function goSharedWireTypesPackage(pkgName, ir) {
2717
+ const portsStructs = [];
2718
+ if (ir !== undefined) {
2719
+ const components = ir.components;
2720
+ const plan = buildTypePlan(ir);
2721
+ for (const c of components.filter(isNativeRaw)) {
2722
+ const typedNodes = buildTypedNodes(c, plan);
2723
+ for (const n of c.body) {
2724
+ if (!isCrossPackageSharedNode(n))
2725
+ continue;
2726
+ portsStructs.push("fanout" in n
2727
+ ? emitFanoutPortsStructs(c, n, typedNodes, plan)
2728
+ : emitMapPortsStructs(c, n, typedNodes, plan));
2729
+ }
2730
+ }
2731
+ }
2732
+ const portsSection = portsStructs.length
2733
+ ? `\n\n// #154 cross-package batched/fanout ports structs — the batch ports the covered module's runner\n// passes to the leaf transport as a whole value. Here (not the covered module) so the transport package\n// can name them without importing the covered package (cycle-free). Native fields — no boxed Value.\n${portsStructs.join("\n\n")}`
2734
+ : "";
2735
+ return `// GENERATED by behavior-contracts (go-typed-native) — the BC-OWNED shared wire types. A covered module
2736
+ // generated with --shared-types-import imports this; a separate leaf-transport package returns its
2737
+ // WireValue. Self-contained + runtime-free.
2738
+ package ${pkgName}
2739
+
2740
+ import "strconv"
2741
+
2742
+ ${emitGoProbeKinds()}
2743
+
2744
+ ${emitProbeWireTypes({ row: "WireRow", list: "WireList" })}
2745
+
2746
+ ${emitGoWireTypes()}${portsSection}
2747
+ `;
2748
+ }
2469
2749
  /**
2470
2750
  * goTypedNativeObserve — the TEST-ONLY observe companion (a SEPARATE file in the SAME package as the
2471
- * covered module). It carries the typed->Value serializers (ser_*) + an ObserveNativeRaw dispatch
2472
- * that drives the module-private struct runner and serializes its result to a canonical Value for
2473
- * the equivalence pin. This lives OUTSIDE the covered module so the module stays literal whole-file
2474
- * zero (the ser_* NewObj is test glue, never on the consumer's read hot path). Emitted only for the
2475
- * fully-covered case (the equivalence harness); production consumers never use it.
2751
+ * covered module). It carries the typed->Value serializers (ser_*) + the SCRIPTED analog of the consumer's
2752
+ * leaf transport symbols: free Leaf_<comp> funcs (same package, so the covered module's transport calls
2753
+ * resolve) that drain a shared package-level scripted queue, + an ObserveNativeRaw dispatch that fills the
2754
+ * queue from the per-case spec, drives the module-private struct runner, and serializes its result to a
2755
+ * canonical Value for the equivalence pin. This lives OUTSIDE the covered module so the module stays literal
2756
+ * whole-file zero (the ser_* NewObj is test glue, never on the consumer's read hot path). Emitted only for
2757
+ * the fully-covered case (the equivalence harness); production consumers never use it.
2476
2758
  */
2477
- export function goTypedNativeObserve(ir, runtimeImport) {
2759
+ export function goTypedNativeObserve(ir, runtimeImport, leaf) {
2478
2760
  const components = ir.components;
2479
2761
  const native = components.filter(isNativeRaw);
2480
2762
  const plan = buildTypePlan(ir);
@@ -2491,7 +2773,7 @@ export function goTypedNativeObserve(ir, runtimeImport) {
2491
2773
  // decode the generic *Obj input into the CONCRETE In_<comp> struct (test glue — ONE decode at the
2492
2774
  // top, OUTSIDE the covered hot path; a REQUIRED declared input is present so an absent key is a
2493
2775
  // fail-closed decode error surfaced here, never on the native runner path).
2494
- return `\tif name == ${JSON.stringify(c.name)} {\n\t\tin, ierr := decode_${inStructName(c.name)}(input)\n\t\tif ierr != nil {\n\t\t\treturn nil, ierr\n\t\t}\n\t\ttv, err := ${runnerName(c.name)}(${handlerTypeName(c.name)}{handlers}, in)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn ${ser}, nil\n\t}`;
2776
+ return `\tif name == ${JSON.stringify(c.name)} {\n\t\tin, ierr := decode_${inStructName(c.name)}(input)\n\t\tif ierr != nil {\n\t\t\treturn nil, ierr\n\t\t}\n\t\ttv, err := ${runnerName(c.name)}(in)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn ${ser}, nil\n\t}`;
2495
2777
  })
2496
2778
  .join("\n");
2497
2779
  // input decoders (TEST glue): generic *Obj -> concrete In_<comp>. Scalar fields read the typed value
@@ -2507,177 +2789,42 @@ export function goTypedNativeObserve(ir, runtimeImport) {
2507
2789
  // generated inline de-box from the same scripted vectors run_behavior uses — so actualWireType observed
2508
2790
  // in a mismatch is the PRODUCER tag (e.g. "N"), not the collapsed native type.
2509
2791
  const wireAdapter = anyDeBox
2510
- ? `// ── scripted wire adapter (TEST glue) ──
2511
- func scriptedWireTag(v ${PKG}.Value) string {
2512
- switch v.(type) {
2513
- case nil:
2514
- return "NULL"
2515
- case bool:
2516
- return "BOOL"
2517
- case int64, float64:
2518
- return "N"
2519
- case string:
2520
- return "S"
2521
- case []${PKG}.Value:
2522
- return "L"
2523
- case *${PKG}.Obj:
2524
- return "M"
2525
- default:
2526
- return "UNKNOWN"
2527
- }
2528
- }
2529
-
2530
- func scriptedWireRaw(v ${PKG}.Value) string {
2792
+ ? `// valueToWire (TEST glue): builds the covered module's BC-OWNED concrete WireValue from a scripted bc
2793
+ // Value — the harness analog of the consumer's real transport (which builds WireValue as it reads the
2794
+ // producer). Numbers ride as raw text (WireNum); floats use the SAME repr as run_behavior (PyFloatRepr) so
2795
+ // the raw text is byte-identical. The wire tags + classification live ONCE in the covered module's
2796
+ // WireValue (probeStringOf etc.), so this only CONSTRUCTS.
2797
+ func valueToWire(v ${PKG}.Value) WireValue {
2531
2798
  switch t := v.(type) {
2532
2799
  case nil:
2533
- return "null"
2800
+ return WireNull()
2534
2801
  case bool:
2535
- if t {
2536
- return "true"
2537
- }
2538
- return "false"
2802
+ return WireBool(t)
2539
2803
  case int64:
2540
- return strconv.FormatInt(t, 10)
2804
+ return WireInt(t)
2541
2805
  case float64:
2542
2806
  s, _ := ${PKG}.PyFloatRepr(t)
2543
- return s
2807
+ return WireNum(s)
2544
2808
  case string:
2545
- return t
2809
+ return WireStr(t)
2810
+ case []${PKG}.Value:
2811
+ items := make([]WireValue, len(t))
2812
+ for i := range t {
2813
+ items[i] = valueToWire(t[i])
2814
+ }
2815
+ return WireListOf(items)
2816
+ case *${PKG}.Obj:
2817
+ fields := make([]WireField, len(t.Keys))
2818
+ for i, k := range t.Keys {
2819
+ vv, _ := t.Get(k)
2820
+ fields[i] = WireField{Key: k, Val: valueToWire(vv)}
2821
+ }
2822
+ return WireRowOf(fields)
2546
2823
  default:
2547
- return ${PKG}.EncodeValue(v)
2548
- }
2549
- }
2550
-
2551
- func probeStringVal(v ${PKG}.Value) StringProbe {
2552
- if v == nil {
2553
- return StringProbe{Kind: probeNull, ActualWireType: "NULL", Raw: "null"}
2554
- }
2555
- if s, ok := v.(string); ok {
2556
- return StringProbe{Kind: probeGot, Got: s, ActualWireType: "S", Raw: s}
2557
- }
2558
- return StringProbe{Kind: probeWrong, ActualWireType: scriptedWireTag(v), Raw: scriptedWireRaw(v)}
2559
- }
2560
-
2561
- func probeNumberVal(v ${PKG}.Value) NumberProbe {
2562
- if v == nil {
2563
- return NumberProbe{Kind: probeNull, ActualWireType: "NULL", Raw: "null"}
2564
- }
2565
- switch v.(type) {
2566
- case int64, float64:
2567
- return NumberProbe{Kind: probeGot, Got: scriptedWireRaw(v), ActualWireType: "N", Raw: scriptedWireRaw(v)}
2568
- }
2569
- return NumberProbe{Kind: probeWrong, ActualWireType: scriptedWireTag(v), Raw: scriptedWireRaw(v)}
2570
- }
2571
-
2572
- func probeBoolVal(v ${PKG}.Value) BoolProbe {
2573
- if v == nil {
2574
- return BoolProbe{Kind: probeNull, ActualWireType: "NULL", Raw: "null"}
2575
- }
2576
- if b, ok := v.(bool); ok {
2577
- return BoolProbe{Kind: probeGot, Got: b, ActualWireType: "BOOL", Raw: scriptedWireRaw(v)}
2578
- }
2579
- return BoolProbe{Kind: probeWrong, ActualWireType: scriptedWireTag(v), Raw: scriptedWireRaw(v)}
2580
- }
2581
-
2582
- func probeRowVal(v ${PKG}.Value) RowProbe {
2583
- if v == nil {
2584
- return RowProbe{Kind: probeNull, ActualWireType: "NULL", Raw: "null"}
2585
- }
2586
- if o, ok := v.(*${PKG}.Obj); ok {
2587
- return RowProbe{Kind: probeGot, Got: WireRow{obj: o}, ActualWireType: "M"}
2824
+ return WireNull()
2588
2825
  }
2589
- return RowProbe{Kind: probeWrong, ActualWireType: scriptedWireTag(v), Raw: scriptedWireRaw(v)}
2590
2826
  }
2591
2827
 
2592
- func probeListVal(v ${PKG}.Value) ListProbe {
2593
- if v == nil {
2594
- return ListProbe{Kind: probeNull, ActualWireType: "NULL", Raw: "null"}
2595
- }
2596
- if a, ok := v.([]${PKG}.Value); ok {
2597
- return ListProbe{Kind: probeGot, Got: WireList{items: a}, ActualWireType: "L"}
2598
- }
2599
- return ListProbe{Kind: probeWrong, ActualWireType: scriptedWireTag(v), Raw: scriptedWireRaw(v)}
2600
- }
2601
-
2602
- // WireValue — the CONCRETE scripted node-result wire (the in-package default seam type the covered runner
2603
- // classifies via As*). A top value is always present, so As* never observes Absent; a scripted null is a
2604
- // nil Value → Null. A real consumer supplies its own concrete WireValue over its AttributeValue payload.
2605
- type WireValue struct {
2606
- v ${PKG}.Value
2607
- }
2608
-
2609
- func (w WireValue) AsString() StringProbe { return probeStringVal(w.v) }
2610
- func (w WireValue) AsNumber() NumberProbe { return probeNumberVal(w.v) }
2611
- func (w WireValue) AsBool() BoolProbe { return probeBoolVal(w.v) }
2612
- func (w WireValue) AsRow() RowProbe { return probeRowVal(w.v) }
2613
- func (w WireValue) AsList() ListProbe { return probeListVal(w.v) }
2614
-
2615
- // WireRow / WireList — the CONCRETE scripted wire map / array (the in-package default seam types), probed
2616
- // per declared field / element by the generated inline de-box (their methods return bc's probe structs).
2617
- type WireRow struct {
2618
- obj *${PKG}.Obj
2619
- }
2620
-
2621
- func (w WireRow) field(name string) (${PKG}.Value, bool) {
2622
- if w.obj == nil {
2623
- return nil, false
2624
- }
2625
- return w.obj.Get(name)
2626
- }
2627
-
2628
- func (w WireRow) Keys() []string {
2629
- if w.obj == nil {
2630
- return nil
2631
- }
2632
- return w.obj.Keys
2633
- }
2634
-
2635
- func (w WireRow) ProbeString(field string) StringProbe {
2636
- if v, ok := w.field(field); ok {
2637
- return probeStringVal(v)
2638
- }
2639
- return StringProbe{Kind: probeAbsent}
2640
- }
2641
-
2642
- func (w WireRow) ProbeNumber(field string) NumberProbe {
2643
- if v, ok := w.field(field); ok {
2644
- return probeNumberVal(v)
2645
- }
2646
- return NumberProbe{Kind: probeAbsent}
2647
- }
2648
-
2649
- func (w WireRow) ProbeBool(field string) BoolProbe {
2650
- if v, ok := w.field(field); ok {
2651
- return probeBoolVal(v)
2652
- }
2653
- return BoolProbe{Kind: probeAbsent}
2654
- }
2655
-
2656
- func (w WireRow) ProbeRow(field string) RowProbe {
2657
- if v, ok := w.field(field); ok {
2658
- return probeRowVal(v)
2659
- }
2660
- return RowProbe{Kind: probeAbsent}
2661
- }
2662
-
2663
- func (w WireRow) ProbeList(field string) ListProbe {
2664
- if v, ok := w.field(field); ok {
2665
- return probeListVal(v)
2666
- }
2667
- return ListProbe{Kind: probeAbsent}
2668
- }
2669
-
2670
- type WireList struct {
2671
- items []${PKG}.Value
2672
- }
2673
-
2674
- func (l WireList) Len() int { return len(l.items) }
2675
- func (l WireList) ElemString(i int) StringProbe { return probeStringVal(l.items[i]) }
2676
- func (l WireList) ElemNumber(i int) NumberProbe { return probeNumberVal(l.items[i]) }
2677
- func (l WireList) ElemBool(i int) BoolProbe { return probeBoolVal(l.items[i]) }
2678
- func (l WireList) ElemRow(i int) RowProbe { return probeRowVal(l.items[i]) }
2679
- func (l WireList) ElemList(i int) ListProbe { return probeListVal(l.items[i]) }
2680
-
2681
2828
  // FailureDetail exposes the structured Error Value fields WITHOUT naming the local ErrorDetail type, so
2682
2829
  // the harness can assert the de-box's kind / field / expectedType / actualWireType / rawValue (TEST
2683
2830
  // glue — same package as the covered module, so it may read the fields directly).
@@ -2689,17 +2836,14 @@ func (e *BehaviorError) FailureDetail() (kind, model, field, expectedType, actua
2689
2836
  return d.Kind, d.Model, d.Field, d.ExpectedType, d.ActualWireType, d.RawValue, true
2690
2837
  }`
2691
2838
  : "";
2692
- // Handler_<comp> wrapper types: the covered runner takes the CONCRETE per-component handler by value
2693
- // (non-generic). One scripted queue backs every component, so each Handler_<comp> embeds the shared
2694
- // *ScriptedNativeRaw — the Node_* methods (on *ScriptedNativeRaw) are promoted, so the runner's direct
2695
- // h.Node_*(...) call resolves to a concrete method (no interface, no dictionary). Test glue only.
2696
- const handlerWrappers = native
2697
- .map((c) => `// ${handlerTypeName(c.name)} — the CONCRETE handler the '${c.name}' runner takes by value (embeds the\n// shared scripted queue; the Node_* methods are promoted).\ntype ${handlerTypeName(c.name)} struct {\n\t*ScriptedNativeRaw\n}`)
2698
- .join("\n\n");
2699
- // ── concrete scripted adapter (TEST glue): implements every Node_* method by draining a per-COMPONENT
2700
- // scripted-outcome queue and returning the scripted ok Value wrapped as a WireValue (the generic
2701
- // scripted source — a Value queue — meets the uniform CONCRETE wire seam). ──
2702
- const methodImpls = [];
2839
+ // ── op-agnostic leaf TRANSPORT funcs (TEST glue) — the scripted analog of the consumer's transport
2840
+ // symbols. ONE free `Leaf_<component>` per DISTINCT covered leaf (catalog component) in the IR (a
2841
+ // per-module leaf has one consistent shape — verified), draining the shared package-level scripted queue
2842
+ // and returning the scripted wire in EXACTLY the shape the removed per-node method returned. bc#87
2843
+ // parallel goroutines share the queue (mutex-guarded); cases run sequentially so a shared package var is
2844
+ // fine. Echo (#129/#141) reads the spread port params directly. ──
2845
+ const transportFns = [];
2846
+ const emittedLeaf = new Set();
2703
2847
  for (const c of native) {
2704
2848
  const typedNodes = new Map();
2705
2849
  for (const n of c.body)
@@ -2707,18 +2851,20 @@ func (e *BehaviorError) FailureDetail() (kind, model, field, expectedType, actua
2707
2851
  typedNodes.set(n.id, "map" in n ? mapNodeArrRef(n, plan) : deriveTypeRef(n.outType, plan)); // #125: control-gate typeless; map は produced-array ref に正規化
2708
2852
  for (const n of c.body) {
2709
2853
  if ("cond" in n)
2710
- continue; // #108: cond has no handler method (pure Expression) — no scripted impl.
2711
- const ref = typedNodes.get(n.id);
2854
+ continue; // #108: cond has no leaf (pure Expression) — no transport fn.
2855
+ const catalog = "fanout" in n ? n.fanout.component : "map" in n ? n.map.component : n.component;
2856
+ if (emittedLeaf.has(catalog))
2857
+ continue; // per-module a leaf has ONE consistent shape — emit once.
2858
+ emittedLeaf.add(catalog);
2859
+ const sym = leafSymbolBare(catalog, leaf);
2712
2860
  if ("fanout" in n) {
2713
2861
  // fanout: return the aligned per-id element WIRES ([]*WireValue); a null aligned body is a
2714
2862
  // DANGLING id → nil (the covered runner maps it to the zero element).
2715
- const f = n.fanout;
2716
2863
  const portsT = `${portsStructName(c.name, n.id)}_batch`;
2717
- const foBoundT = boundGoType(n, c, typedNodes, plan);
2718
- methodImpls.push(`func (s *ScriptedNativeRaw) ${nodeMethodName(c.name, n.id)}(_ ${portsT}, _ ${foBoundT}) ([]*WireValue, error) {
2719
- src, ok := s.next(${JSON.stringify(f.component)})
2864
+ transportFns.push(`func ${sym}(_ ${portsT}) ([]*WireValue, error) {
2865
+ src, ok := nextScripted(${JSON.stringify(catalog)})
2720
2866
  if !ok {
2721
- return nil, unknownComponent(${JSON.stringify(f.component)})
2867
+ return nil, unknownComponent(${JSON.stringify(catalog)})
2722
2868
  }
2723
2869
  if src.isErr {
2724
2870
  return nil, leafFailure(src.err)
@@ -2730,7 +2876,7 @@ func (e *BehaviorError) FailureDetail() (kind, model, field, expectedType, actua
2730
2876
  wires = append(wires, nil)
2731
2877
  continue
2732
2878
  }
2733
- wv := WireValue{v: ev}
2879
+ wv := valueToWire(ev)
2734
2880
  wires = append(wires, &wv)
2735
2881
  }
2736
2882
  return wires, nil
@@ -2740,14 +2886,12 @@ func (e *BehaviorError) FailureDetail() (kind, model, field, expectedType, actua
2740
2886
  if ("map" in n) {
2741
2887
  // map: batched → one WIRE per element ([]WireValue); non-batched → one element WIRE (WireValue).
2742
2888
  const m = n.map;
2743
- const batched = m.batched === true;
2744
- const portsT = batched ? `${portsStructName(c.name, n.id)}_batch` : portsStructName(c.name, n.id);
2745
- const mapBoundT = boundGoType(n, c, typedNodes, plan);
2746
- if (batched) {
2747
- methodImpls.push(`func (s *ScriptedNativeRaw) ${nodeMethodName(c.name, n.id)}(_ ${portsT}, _ ${mapBoundT}) ([]WireValue, error) {
2748
- src, ok := s.next(${JSON.stringify(m.component)})
2889
+ if (m.batched === true) {
2890
+ const portsT = `${portsStructName(c.name, n.id)}_batch`;
2891
+ transportFns.push(`func ${sym}(_ ${portsT}) ([]WireValue, error) {
2892
+ src, ok := nextScripted(${JSON.stringify(catalog)})
2749
2893
  if !ok {
2750
- return nil, unknownComponent(${JSON.stringify(m.component)})
2894
+ return nil, unknownComponent(${JSON.stringify(catalog)})
2751
2895
  }
2752
2896
  if src.isErr {
2753
2897
  return nil, leafFailure(src.err)
@@ -2755,31 +2899,32 @@ func (e *BehaviorError) FailureDetail() (kind, model, field, expectedType, actua
2755
2899
  arr, _ := src.ok.([]${PKG}.Value)
2756
2900
  wires := make([]WireValue, 0, len(arr))
2757
2901
  for _, ev := range arr {
2758
- wires = append(wires, WireValue{v: ev})
2902
+ wires = append(wires, valueToWire(ev))
2759
2903
  }
2760
2904
  return wires, nil
2761
2905
  }`);
2762
2906
  }
2763
2907
  else {
2764
- methodImpls.push(`func (s *ScriptedNativeRaw) ${nodeMethodName(c.name, n.id)}(_ ${portsT}, _ ${mapBoundT}) (WireValue, error) {
2765
- src, ok := s.next(${JSON.stringify(m.component)})
2908
+ const { elemRef: overElemRef } = mapOverElemInfo(c, n, typedNodes, plan);
2909
+ const spread = portFieldSpread(m.ports, c, plan, typedNodes, { name: m.as, ref: overElemRef, plan });
2910
+ const params = spread.map((pf) => `_${pf.field} ${pf.goType}`).join(", ");
2911
+ transportFns.push(`func ${sym}(${params}) (WireValue, error) {
2912
+ src, ok := nextScripted(${JSON.stringify(catalog)})
2766
2913
  if !ok {
2767
- return WireValue{}, unknownComponent(${JSON.stringify(m.component)})
2914
+ return WireValue{}, unknownComponent(${JSON.stringify(catalog)})
2768
2915
  }
2769
2916
  if src.isErr {
2770
2917
  return WireValue{}, leafFailure(src.err)
2771
2918
  }
2772
- return WireValue{v: src.ok}, nil
2919
+ return valueToWire(src.ok), nil
2773
2920
  }`);
2774
2921
  }
2775
2922
  continue;
2776
2923
  }
2777
- // componentRef: return the whole result WIRE (one WireValue wrapping the scripted ok Value); the
2778
- // covered runner's INLINE de-box classifies it. A real consumer returns its own wire payload.
2924
+ // componentRef (point read): spread port fields; supports echo (#129/#141) reading the port params.
2779
2925
  const node = n;
2780
- const nodeBoundT = boundGoType(node, c, typedNodes, plan);
2781
- // echo (#129/#141 fixtures): the scripted leaf can ECHO an input PORT back as its result wire, so the
2782
- // input-port value flows into the de-boxed result and the runtime non-vacuity asserts survive.
2926
+ const ref = typedNodes.get(n.id);
2927
+ const spread = portFieldSpread(node.ports, c, plan, typedNodes);
2783
2928
  const echoBranches = [];
2784
2929
  if (ref.kind === "named") {
2785
2930
  const decl = findDecl(plan, ref.name);
@@ -2796,31 +2941,32 @@ func (e *BehaviorError) FailureDetail() (kind, model, field, expectedType, actua
2796
2941
  }
2797
2942
  if (portGo === recordGo) {
2798
2943
  // the port IS the whole record → echo it DIRECTLY (matching run_behavior's plain echo:port).
2799
- echoBranches.push(`\tif src.echo == ${JSON.stringify(pn)} {\n\t\treturn WireValue{v: ${serializeTyped(`ports.${goPortFieldName(pn)}`, ref, plan)}}, nil\n\t}`);
2944
+ echoBranches.push(`\tif src.echo == ${JSON.stringify(pn)} {\n\t\treturn valueToWire(${serializeTyped(goPortFieldName(pn), ref, plan)}), nil\n\t}`);
2800
2945
  }
2801
2946
  else if (fieldGo !== null && field !== undefined && portGo === fieldGo) {
2802
2947
  // a scalar port wraps into the record's single field ({v: ports.X}).
2803
- echoBranches.push(`\tif src.echo == ${JSON.stringify(pn)} {\n\t\treturn WireValue{v: ${serializeTyped(`${recordGo}{${goFieldName(field.name)}: ports.${goPortFieldName(pn)}}`, ref, plan)}}, nil\n\t}`);
2948
+ echoBranches.push(`\tif src.echo == ${JSON.stringify(pn)} {\n\t\treturn valueToWire(${serializeTyped(`${recordGo}{${goFieldName(field.name)}: ${goPortFieldName(pn)}}`, ref, plan)}), nil\n\t}`);
2804
2949
  }
2805
2950
  }
2806
2951
  }
2807
2952
  else if (ref.kind === "arr" && Object.prototype.hasOwnProperty.call(node.ports, "items")) {
2808
2953
  // #129: an arr node with an `items` port echoes the NATIVE port array (serialized to a Value array)
2809
2954
  // so the node→leaf array dataflow test is non-vacuous.
2810
- echoBranches.push(`\tif src.echo == "items" {\n\t\treturn WireValue{v: ${serializeTyped(`ports.${goPortFieldName("items")}`, ref, plan)}}, nil\n\t}`);
2955
+ echoBranches.push(`\tif src.echo == "items" {\n\t\treturn valueToWire(${serializeTyped(goPortFieldName("items"), ref, plan)}), nil\n\t}`);
2811
2956
  }
2812
2957
  const canEcho = echoBranches.length > 0;
2813
- const portsParam = canEcho ? "ports" : "_";
2958
+ // params keep their field names (echo reads them); Go allows unused params, so no underscore needed.
2959
+ const params = spread.map((pf) => `${pf.field} ${pf.goType}`).join(", ");
2814
2960
  const echoBlock = canEcho ? `${echoBranches.join("\n")}\n` : "";
2815
- methodImpls.push(`func (s *ScriptedNativeRaw) ${nodeMethodName(c.name, node.id)}(${portsParam} ${portsStructName(c.name, node.id)}, _ ${nodeBoundT}) (WireValue, error) {
2816
- src, ok := s.next(${JSON.stringify(node.component)})
2961
+ transportFns.push(`func ${sym}(${params}) (WireValue, error) {
2962
+ src, ok := nextScripted(${JSON.stringify(catalog)})
2817
2963
  if !ok {
2818
- return WireValue{}, unknownComponent(${JSON.stringify(node.component)})
2964
+ return WireValue{}, unknownComponent(${JSON.stringify(catalog)})
2819
2965
  }
2820
2966
  if src.isErr {
2821
2967
  return WireValue{}, leafFailure(src.err)
2822
2968
  }
2823
- ${echoBlock} return WireValue{v: src.ok}, nil
2969
+ ${echoBlock} return valueToWire(src.ok), nil
2824
2970
  }`);
2825
2971
  }
2826
2972
  }
@@ -2835,96 +2981,99 @@ type scriptSrc struct {
2835
2981
  ok ${PKG}.Value
2836
2982
  }
2837
2983
 
2838
- // ScriptedNativeRaw — the CONCRETE test handler: its Node_* methods drain a per-COMPONENT scripted queue
2839
- // and return the ok Value wrapped as a WireValue (the covered runner de-boxes it inline). Each runner
2840
- // takes a Handler_<comp> value that embeds this, so the Node_* calls stay fully concrete (no interface).
2841
- // EXPORTED so the runner glue (a separate package) can name it.
2842
- type ScriptedNativeRaw struct {
2843
- mu sync.Mutex
2844
- queues map[string][]scriptSrc
2845
- seen int
2846
- }
2984
+ // the shared scripted-outcome source the free Leaf_<comp> transport funcs drain (TEST glue). A package var
2985
+ // (not a per-call handler object) so the bc#87 parallel goroutines share it (mutex-guarded); reset+filled
2986
+ // per case by ObserveNativeRaw. Cases run sequentially in the harness, so one shared queue per case is fine.
2987
+ var (
2988
+ scriptedMu sync.Mutex
2989
+ scriptedQueues = map[string][]scriptSrc{}
2990
+ scriptedSeen int
2991
+ )
2847
2992
 
2848
- // NewScriptedNativeRaw builds the concrete test handler from the JSON handlers spec (the SAME shape
2849
- // the reference scriptedHandlers reads): { "<component>": {ok|error} | [ {ok|error}, … ] }. Each
2850
- // component's ok Value is DecodeValue'd once here (test glue); the per-node method decodes it into the
2851
- // concrete row. Returns the handler + any decode error (surfaced by the runner as a fatal).
2852
- func NewScriptedNativeRaw(spec *${PKG}.JObj) (*ScriptedNativeRaw, error) {
2853
- queues := map[string][]scriptSrc{}
2854
- if spec != nil {
2855
- for _, comp := range spec.Keys {
2856
- var entries []${PKG}.JNode
2857
- switch t := spec.Vals[comp].(type) {
2858
- case []${PKG}.JNode:
2859
- entries = t
2860
- default:
2861
- entries = []${PKG}.JNode{t}
2862
- }
2863
- for _, e := range entries {
2864
- eo, _ := e.(*${PKG}.JObj)
2865
- // #129: an \`echo\` directive names an input port to echo back (mirrors the reference
2866
- // scriptedHandlers' \`echo === "items"\`). It is drained together with the ok payload.
2867
- echo := ""
2868
- if echoNode, has := eo.Get("echo"); has {
2869
- echo, _ = echoNode.(string)
2870
- // normalize echo:port to the port NAME X so a de-box handler's echo comparison fires;
2871
- // echo:items already names the port directly.
2872
- if echo == "port" {
2873
- if portNode, hasPort := eo.Get("port"); hasPort {
2874
- echo, _ = portNode.(string)
2875
- }
2993
+ // fillScripted resets + loads the shared queue from the JSON handlers spec (the SAME shape the reference
2994
+ // scriptedHandlers reads): { "<component>": {ok|error} | [ {ok|error}, … ] }. Each ok Value is
2995
+ // DecodeValue'd once here (test glue). Returns any decode error (surfaced by the runner as a fatal).
2996
+ func fillScripted(spec *${PKG}.JObj) error {
2997
+ scriptedMu.Lock()
2998
+ defer scriptedMu.Unlock()
2999
+ scriptedQueues = map[string][]scriptSrc{}
3000
+ scriptedSeen = 0
3001
+ if spec == nil {
3002
+ return nil
3003
+ }
3004
+ for _, comp := range spec.Keys {
3005
+ var entries []${PKG}.JNode
3006
+ switch t := spec.Vals[comp].(type) {
3007
+ case []${PKG}.JNode:
3008
+ entries = t
3009
+ default:
3010
+ entries = []${PKG}.JNode{t}
3011
+ }
3012
+ for _, e := range entries {
3013
+ eo, _ := e.(*${PKG}.JObj)
3014
+ // #129: an \`echo\` directive names an input port to echo back (mirrors the reference
3015
+ // scriptedHandlers' \`echo === "items"\`). It is drained together with the ok payload.
3016
+ echo := ""
3017
+ if echoNode, has := eo.Get("echo"); has {
3018
+ echo, _ = echoNode.(string)
3019
+ // normalize echo:port to the port NAME X so a de-box handler's echo comparison fires;
3020
+ // echo:items already names the port directly.
3021
+ if echo == "port" {
3022
+ if portNode, hasPort := eo.Get("port"); hasPort {
3023
+ echo, _ = portNode.(string)
2876
3024
  }
2877
3025
  }
2878
- if okNode, has := eo.Get("ok"); has {
2879
- val, derr := ${PKG}.DecodeValue(okNode)
2880
- if derr != nil {
2881
- return nil, derr
2882
- }
2883
- queues[comp] = append(queues[comp], scriptSrc{ok: val, echo: echo})
2884
- continue
3026
+ }
3027
+ if okNode, has := eo.Get("ok"); has {
3028
+ val, derr := ${PKG}.DecodeValue(okNode)
3029
+ if derr != nil {
3030
+ return derr
2885
3031
  }
2886
- ev, _ := eo.Get("error")
2887
- es, _ := ev.(string)
2888
- queues[comp] = append(queues[comp], scriptSrc{isErr: true, err: es})
3032
+ scriptedQueues[comp] = append(scriptedQueues[comp], scriptSrc{ok: val, echo: echo})
3033
+ continue
2889
3034
  }
3035
+ ev, _ := eo.Get("error")
3036
+ es, _ := ev.(string)
3037
+ scriptedQueues[comp] = append(scriptedQueues[comp], scriptSrc{isErr: true, err: es})
2890
3038
  }
2891
3039
  }
2892
- return &ScriptedNativeRaw{queues: queues}, nil
3040
+ return nil
2893
3041
  }
2894
3042
 
2895
- // next drains one scripted outcome for a component (last entry repeats — mirrors the reference
2896
- // scriptedHandlers), returns ok=false when the component has no scripted queue (fail-closed). The
2897
- // bc#87 parallel-stage runner calls Node_* from multiple goroutines, so the drain is mutex-guarded.
2898
- func (s *ScriptedNativeRaw) next(component string) (scriptSrc, bool) {
2899
- s.mu.Lock()
2900
- defer s.mu.Unlock()
2901
- s.seen++
2902
- q, ok := s.queues[component]
3043
+ // nextScripted drains one scripted outcome for a component (last entry repeats — mirrors the reference
3044
+ // scriptedHandlers), returns ok=false when the component has no scripted queue (fail-closed). The bc#87
3045
+ // parallel-stage runner calls the transport funcs from multiple goroutines, so the drain is mutex-guarded.
3046
+ func nextScripted(component string) (scriptSrc, bool) {
3047
+ scriptedMu.Lock()
3048
+ defer scriptedMu.Unlock()
3049
+ scriptedSeen++
3050
+ q, ok := scriptedQueues[component]
2903
3051
  if !ok || len(q) == 0 {
2904
3052
  return scriptSrc{}, false
2905
3053
  }
2906
3054
  if len(q) > 1 {
2907
3055
  v := q[0]
2908
- s.queues[component] = q[1:]
3056
+ scriptedQueues[component] = q[1:]
2909
3057
  return v, true
2910
3058
  }
2911
3059
  return q[0], true
2912
3060
  }`;
2913
3061
  return `// GENERATED test-only observe companion (bc#77) — NOT part of the covered module. Serializes the
2914
- // struct-native runner's result to a canonical Value for the equivalence pin, and carries the CONCRETE
2915
- // scripted test handler (ScriptedNativeRaw) + the CONCRETE WireValue/WireRow/WireList seam types +
2916
- // per-component Handler_<comp> wrappers the runner takes. The consumer never uses this (it keeps the
2917
- // model native + supplies its own concrete WireValue + Handler_<comp>); it exists only so the test
2918
- // harness can byte-compare the STRUCT-only covered read against run_behavior. Same package as the module.
3062
+ // struct-native runner's result to a canonical Value for the equivalence pin, and carries the SCRIPTED
3063
+ // analog of the consumer's leaf transport symbols: free Leaf_<comp> funcs (same package as the covered
3064
+ // module, so its transport calls resolve) that drain a shared package-level scripted queue + the CONCRETE
3065
+ // WireValue/WireRow/WireList seam types. The consumer never uses this (it keeps the model native + supplies
3066
+ // its own concrete WireValue + transport funcs); it exists only so the test harness can byte-compare the
3067
+ // STRUCT-only covered read against run_behavior. Same package as the module.
2919
3068
  package behaviors
2920
3069
 
2921
3070
  import (
2922
- ${anyDeBox ? '\t"strconv"\n\n' : ""} "sync"
3071
+ "sync"
2923
3072
 
2924
3073
  ${PKG} "${runtimeImport ?? "github.com/foo-ogawa/behavior-contracts/go"}"
2925
3074
  )
2926
3075
 
2927
- // scripted wire adapter (TEST glue) — the CONCRETE WireValue/WireRow/WireList the covered module references.
3076
+ // valueToWire (TEST glue) — builds the covered module's BC-owned WireValue from a scripted bc Value.
2928
3077
  ${wireAdapter}
2929
3078
 
2930
3079
  // typed -> Value serializers (TEST glue only — the covered module has none).
@@ -2942,17 +3091,17 @@ ${inDecoders}
2942
3091
 
2943
3092
  ${adapter}
2944
3093
 
2945
- // per-component CONCRETE handler wrappers (the runner takes one by value — embeds the shared queue).
2946
- ${handlerWrappers}
2947
-
2948
- // ScriptedNativeRaw method impls (one per covered node — the concrete Node_* seam returning WireValue).
2949
- ${methodImpls.join("\n\n")}
3094
+ // scripted leaf transport funcs (one per covered leaf — the free op-agnostic transport the covered runner
3095
+ // calls directly; test glue draining the shared package queue).
3096
+ ${transportFns.join("\n\n")}
2950
3097
 
2951
- // ObserveNativeRaw drives the struct-native runner and serializes to a canonical Value (test only). It
2952
- // takes the CONCRETE *ScriptedNativeRaw and wraps it per component in the runner's Handler_<comp> value —
2953
- // each enclosed RunNativeRawStruct_* call is a NON-generic call over a concrete handler (direct,
2954
- // devirtualized per-node method calls), never an interface or a generic dictionary.
2955
- func ObserveNativeRaw(name string, handlers *ScriptedNativeRaw, input *${PKG}.Obj) (${PKG}.Value, error) {
3098
+ // ObserveNativeRaw resets+fills the shared scripted queue from the per-case spec, then drives the covered
3099
+ // struct-native runner and serializes to a canonical Value (test only). No handler object is passed — the
3100
+ // runner calls the free Leaf_<comp> transport funcs above directly (same package).
3101
+ func ObserveNativeRaw(name string, spec *${PKG}.JObj, input *${PKG}.Obj) (${PKG}.Value, error) {
3102
+ if ferr := fillScripted(spec); ferr != nil {
3103
+ return nil, ferr
3104
+ }
2956
3105
  ${arms}
2957
3106
  return nil, ${PKG}.NewBehaviorFailure("UNKNOWN_ENTRY", "component '"+name+"' is not a covered read (fail-closed)")
2958
3107
  }