behavior-contracts 0.10.1 → 0.11.1

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 (97) hide show
  1. package/README.md +246 -350
  2. package/cli-contract.yaml +49 -51
  3. package/dist/authoring.d.ts +80 -420
  4. package/dist/authoring.d.ts.map +1 -1
  5. package/dist/authoring.js +53 -1157
  6. package/dist/authoring.js.map +1 -1
  7. package/dist/behavior.d.ts +31 -15
  8. package/dist/behavior.d.ts.map +1 -1
  9. package/dist/behavior.js +55 -0
  10. package/dist/behavior.js.map +1 -1
  11. package/dist/builder.d.ts +4 -4
  12. package/dist/builder.d.ts.map +1 -1
  13. package/dist/builder.js +18 -16
  14. package/dist/builder.js.map +1 -1
  15. package/dist/cli.js +5 -5
  16. package/dist/cli.js.map +1 -1
  17. package/dist/commands/codegen.d.ts.map +1 -1
  18. package/dist/commands/codegen.js +12 -56
  19. package/dist/commands/codegen.js.map +1 -1
  20. package/dist/commands/ts-compile.d.ts +23 -0
  21. package/dist/commands/ts-compile.d.ts.map +1 -0
  22. package/dist/commands/ts-compile.js +693 -0
  23. package/dist/commands/ts-compile.js.map +1 -0
  24. package/dist/commands/ts-extract.d.ts +55 -7
  25. package/dist/commands/ts-extract.d.ts.map +1 -1
  26. package/dist/commands/ts-extract.js +177 -64
  27. package/dist/commands/ts-extract.js.map +1 -1
  28. package/dist/generated/contract.d.ts.map +1 -1
  29. package/dist/generated/contract.js +2 -2
  30. package/dist/generated/contract.js.map +1 -1
  31. package/dist/generated/program.js +4 -4
  32. package/dist/generated/program.js.map +1 -1
  33. package/dist/generator/core.d.ts +11 -1
  34. package/dist/generator/core.d.ts.map +1 -1
  35. package/dist/generator/core.js +5 -4
  36. package/dist/generator/core.js.map +1 -1
  37. package/dist/generator/emit-php.d.ts +0 -17
  38. package/dist/generator/emit-php.d.ts.map +1 -1
  39. package/dist/generator/emit-php.js +25 -1
  40. package/dist/generator/emit-php.js.map +1 -1
  41. package/dist/generator/emit-python.d.ts +0 -7
  42. package/dist/generator/emit-python.d.ts.map +1 -1
  43. package/dist/generator/emit-python.js +34 -1
  44. package/dist/generator/emit-python.js.map +1 -1
  45. package/dist/generator/emit-straightline-typed-typescript.js +1 -1
  46. package/dist/generator/emit-straightline-typed-typescript.js.map +1 -1
  47. package/dist/generator/emit-typed-native-go.d.ts +1 -1
  48. package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
  49. package/dist/generator/emit-typed-native-go.js +122 -112
  50. package/dist/generator/emit-typed-native-go.js.map +1 -1
  51. package/dist/generator/emit-typed-native-rust.d.ts +3 -2
  52. package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
  53. package/dist/generator/emit-typed-native-rust.js +61 -125
  54. package/dist/generator/emit-typed-native-rust.js.map +1 -1
  55. package/dist/generator/emit-typescript-native.js +1 -1
  56. package/dist/generator/emit-typescript-native.js.map +1 -1
  57. package/dist/generator/emit-typescript.js +1 -1
  58. package/dist/generator/emit-typescript.js.map +1 -1
  59. package/dist/generator/typed.d.ts +5 -1
  60. package/dist/generator/typed.d.ts.map +1 -1
  61. package/dist/generator/typed.js +40 -9
  62. package/dist/generator/typed.js.map +1 -1
  63. package/dist/guard.d.ts +11 -0
  64. package/dist/guard.d.ts.map +1 -1
  65. package/dist/guard.js +35 -8
  66. package/dist/guard.js.map +1 -1
  67. package/dist/index.d.ts +20 -57
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +25 -101
  70. package/dist/index.js.map +1 -1
  71. package/dist/lowering.d.ts +251 -0
  72. package/dist/lowering.d.ts.map +1 -0
  73. package/dist/lowering.js +682 -0
  74. package/dist/lowering.js.map +1 -0
  75. package/dist/provenance.js +4 -4
  76. package/dist/provenance.js.map +1 -1
  77. package/dist/runtime.d.ts +52 -0
  78. package/dist/runtime.d.ts.map +1 -0
  79. package/dist/runtime.js +77 -0
  80. package/dist/runtime.js.map +1 -0
  81. package/dist/spec-versions.d.ts +25 -0
  82. package/dist/spec-versions.d.ts.map +1 -0
  83. package/dist/spec-versions.js +26 -0
  84. package/dist/spec-versions.js.map +1 -0
  85. package/dist/type-gate.d.ts +12 -0
  86. package/dist/type-gate.d.ts.map +1 -1
  87. package/dist/type-gate.js +79 -3
  88. package/dist/type-gate.js.map +1 -1
  89. package/package.json +5 -1
  90. package/dist/bind.d.ts +0 -88
  91. package/dist/bind.d.ts.map +0 -1
  92. package/dist/bind.js +0 -155
  93. package/dist/bind.js.map +0 -1
  94. package/dist/lower.d.ts +0 -35
  95. package/dist/lower.d.ts.map +0 -1
  96. package/dist/lower.js +0 -118
  97. package/dist/lower.js.map +0 -1
@@ -68,7 +68,7 @@ export declare function goSharedWireTypesPackage(pkgName: string): string;
68
68
  * whole-file zero (the ser_* NewObj is test glue, never on the consumer's read hot path). Emitted only for
69
69
  * the fully-covered case (the equivalence harness); production consumers never use it.
70
70
  */
71
- export declare function goTypedNativeObserve(ir: unknown, runtimeImport?: string, leaf?: LeafTransportOptions): string;
71
+ export declare function goTypedNativeObserve(ir: unknown, runtimeImport?: string, leaf?: LeafTransportOptions, namespace?: string): string;
72
72
  /**
73
73
  * goTypedNativeEmitter — language id `go-typed-native` (bc#77). Emits the generic straight-line
74
74
  * body (for non-covered components / helpers) plus the COMBINED READ layer (native ports struct
@@ -1 +1 @@
1
- {"version":3,"file":"emit-typed-native-go.d.ts","sourceRoot":"","sources":["../../src/generator/emit-typed-native-go.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,OAAO,KAAK,EAAe,aAAa,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAiClF;;;;+GAI+G;AAC/G,wBAAgB,wBAAwB,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM,CAE1E;AAo9FD;;;;;;6GAM6G;AAC7G,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAchE;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,oBAAoB,GAAG,MAAM,CAqT7G;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,aAOlC,CAAC"}
1
+ {"version":3,"file":"emit-typed-native-go.d.ts","sourceRoot":"","sources":["../../src/generator/emit-typed-native-go.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,OAAO,KAAK,EAAe,aAAa,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAiClF;;;;+GAI+G;AAC/G,wBAAgB,wBAAwB,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM,CAE1E;AAy9FD;;;;;;6GAM6G;AAC7G,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAchE;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,oBAAoB,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CA2TjI;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,aAOlC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { GeneratorFailure } from "./core.js";
2
- import { isControlGate, nodeWirePassthrough } from "../behavior.js";
2
+ import { isControlGate, mapNodeElemIsOpaqueWire, 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";
@@ -833,8 +833,12 @@ function coveredMapNode(n, bodyIds, comp) {
833
833
  // holds `node.outType = mapElem`, the PRE-array-wrap element; the emitter synthesizes the produced
834
834
  // `[]element`). A map WITHOUT outType is uncovered. Legacy hand-built IR that already carries the
835
835
  // The map node's outType is the ELEMENT type; mapNodeArrRef wraps it to the produced array ref.
836
+ // bc#164: an OPAQUE ELEMENT (`outType:"value"` on an output-passthrough map — mapNodeElemIsOpaqueWire,
837
+ // the shared rule) IS covered: each element wire is stored AS-IS in the produced list (no de-box, no
838
+ // per-op re-box), exactly as the componentRef path treats a passthrough result. Any other non-compound
839
+ // element type stays uncovered (loud), as before.
836
840
  const outT = n.outType;
837
- if (outT === undefined || typeof outT !== "object")
841
+ if (outT === undefined || (typeof outT !== "object" && !mapNodeElemIsOpaqueWire(n)))
838
842
  return false;
839
843
  // `over` element type must be STATICALLY resolvable: a ref to a PRIOR BODY NODE's typed arr field
840
844
  // (mapOverElemType) OR a ref to an INPUT array port that carries `elemType` (#108 — the C3 "BC does
@@ -1079,13 +1083,36 @@ function goPayloadBatch(itemsExpr, wireSel) {
1079
1083
  const q = goWireQ(wireSel);
1080
1084
  return `${q}WireRowOfFields([]${q}WireField{{Key: "items", Val: ${q}WireListOf(${itemsExpr})}})`;
1081
1085
  }
1082
- /** RunNativeRawStruct_<comp> — the EXPORTED name of the per-component struct-returning combined runner
1083
- * (bc#102). It MUST be an exported Go identifier so a consumer in a DIFFERENT package can call it (a
1084
- * leading-lowercase name is unexported / uncallable cross-package). The `RunNativeRawStruct_` prefix
1085
- * guarantees the leading char is uppercase regardless of how the component name sanitizes, and the
1086
- * sanitized component suffix keeps it unique per covered component. */
1086
+ /** #192: the generated entry is a 1:1 map of the authored method — its name is the EXPORTED Go form of
1087
+ * the component (method) name (`findByEmail` → `FindByEmail`), callable cross-package. No `In_<comp>`
1088
+ * box, no `RunNativeRawStruct_` prefix. `goFieldName` capitalizes the leading char (export) and safes
1089
+ * non-identifier chars; unique per covered component (one entry per method). */
1087
1090
  function runnerName(compName) {
1088
- return `RunNativeRawStruct_${sanitize(compName)}`;
1091
+ return goFieldName(compName);
1092
+ }
1093
+ /** #192: the Go package name = the namespace (declaring class), lower-cased (`UserQueries` → `userqueries`);
1094
+ * default `behaviors` when unset. Physical placement / namespace is set in ONE place (GenerateOptions.namespace).
1095
+ * The covered module and its test-only observe companion MUST share this package (same-package transport calls). */
1096
+ function goPackageName(ns) {
1097
+ if (ns === undefined)
1098
+ return "behaviors";
1099
+ const safe = ns.replace(/[^A-Za-z0-9]/g, "").toLowerCase();
1100
+ return safe.length > 0 && /[a-z_]/.test(safe[0]) ? safe : "behaviors";
1101
+ }
1102
+ /** Go keywords that a positional-parameter name must not collide with (prefixed with `p_` if it does). */
1103
+ const GO_KEYWORDS = /* @__PURE__ */ new Set([
1104
+ "break", "case", "chan", "const", "continue", "default", "defer", "else", "fallthrough", "for", "func",
1105
+ "go", "goto", "if", "import", "interface", "map", "package", "range", "return", "select", "struct",
1106
+ "switch", "type", "var", "nil", "true", "false", "iota", "in",
1107
+ ]);
1108
+ /** #192: an input port's positional PARAMETER name — a valid, unexported (lower-first) Go identifier
1109
+ * from the port name. The single naming for a port's param at both the entry signature and every input
1110
+ * ref (goInputHeadRef seam). Digit/underscore-leading or keyword names are `p_`-prefixed. */
1111
+ function goParamName(port) {
1112
+ const safe = port.replace(/[^A-Za-z0-9_]/g, "_");
1113
+ const head = safe.charAt(0);
1114
+ const name = /[A-Za-z]/.test(head) ? head.toLowerCase() + safe.slice(1) : "p_" + safe;
1115
+ return GO_KEYWORDS.has(name) ? "p_" + name : name;
1089
1116
  }
1090
1117
  /** mapElemMaterializerName — the augmented-element copier for a covered map...into node. */
1091
1118
  function mapElemMaterializerName(compName, nodeId) {
@@ -1131,8 +1158,10 @@ function goOverElemInfo(comp, over, typedNodes, plan, nodeId, label) {
1131
1158
  if (e.kind === "ref" && e.path.length === 1) {
1132
1159
  const schema = comp.inputPorts?.[e.path[0]];
1133
1160
  const et = schema?.elemType;
1134
- if (et !== undefined)
1135
- return { elemRef: deriveTypeRef(et, plan), overExpr: `in.${goFieldName(e.path[0])}`, optArr: inputPortIsOptional(schema) };
1161
+ // #192: read the input port via the goInputHeadRef seam (single input-ref path) — not a parallel `in.<Field>`.
1162
+ const head = goInputHeadRef(e.path[0], comp, plan);
1163
+ if (et !== undefined && head !== null)
1164
+ return { elemRef: deriveTypeRef(et, plan), overExpr: head.expr, optArr: inputPortIsOptional(schema) };
1136
1165
  }
1137
1166
  throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `go ${label}: '${nodeId}' 'over' must be a ref to a prior node's typed arr field OR an input array port with a declared elemType (got ${JSON.stringify(over)}). BC does not infer input-array element types (consumer-interface C3).`);
1138
1167
  }
@@ -1272,23 +1301,18 @@ function reconstructG(e) {
1272
1301
  // `dslcontracts.Value` leaves via the nv* helpers) is REMOVED — every covered port now lowers to a
1273
1302
  // FULLY NATIVE Go value in emitPortInit (string / bool / static-string-array / number literal), and a
1274
1303
  // genuinely-dynamic port fails closed. There is no boxed-Value fallback on the covered read plane.
1275
- // ── typed input struct (In_<comp>) + NATIVE scalar port lowering ─────────────────────────────
1304
+ // ── positional input params + NATIVE scalar port lowering (#192) ─────────────────────────────
1276
1305
  //
1277
- // A covered runner takes a CONCRETE per-component input struct `In_<comp>` (fields = the component's
1278
- // inputPorts with their declared Go types) instead of a generic *Obj. A simple string/scalar port —
1279
- // a literal, a ref to a typed input field (`in.UserId`), a ref to a prior node's typed struct scalar
1280
- // field, or a concat of statically-string parts — then lowers DIRECTLY to a native Go expression
1281
- // (`"USER#" + in.UserId`) assigned straight into the concrete ports-struct field: NO dslcontracts.Value,
1282
- // NO nvVE/nvBindVE helper, NO `.(string)` type-assert. The value is statically the concrete type (the
1283
- // input schema / prior-node outType guarantee it, and literals are self-evidently typed), so dropping
1284
- // the runtime TYPE_MISMATCH check is semantics-preserving. A port that CANNOT be statically proven the
1285
- // concrete type (a ref to a non-matching-typed input, a refOpt / opt field, or a dynamic operator)
1286
- // falls back to the nvVE Value path (documented — the only place a `.(T)` could survive; the covered
1287
- // string key/table/projection ports never hit it).
1288
- /** In_<comp> — the concrete per-component input struct name (fields = inputPorts). */
1289
- function inStructName(compName) {
1290
- return `In_${sanitize(compName)}`;
1291
- }
1306
+ // The entry takes POSITIONAL params (one per input port, box removed — `goParamName(port)`), not a
1307
+ // generic *Obj nor an `In_<comp>` struct. A simple string/scalar port — a literal, a ref to a typed
1308
+ // input param (`userId`), a ref to a prior node's typed struct scalar field, or a concat of
1309
+ // statically-string parts — lowers DIRECTLY to a native Go expression (`"USER#" + userId`): NO
1310
+ // dslcontracts.Value, NO nvVE/nvBindVE helper, NO `.(string)` type-assert. The value is statically the
1311
+ // concrete type (the input schema / prior-node outType guarantee it, and literals are self-evidently
1312
+ // typed), so dropping the runtime TYPE_MISMATCH check is semantics-preserving. A port that CANNOT be
1313
+ // statically proven the concrete type (a ref to a non-matching-typed input, a refOpt / opt field, or a
1314
+ // dynamic operator) falls back to the nvVE Value path (documented — the only place a `.(T)` could
1315
+ // survive; the covered string key/table/projection ports never hit it).
1292
1316
  /** Go type for an input port's declared type (scalar → concrete; array+elemType → []ElemT; else Value). */
1293
1317
  function inputPortGoType(schema, plan, where = "input port") {
1294
1318
  const ref = inputPortTypeRef(schema, plan);
@@ -1315,54 +1339,31 @@ function inputScalarKind(schema) {
1315
1339
  return undefined;
1316
1340
  }
1317
1341
  }
1318
- /** emitInStruct — the concrete input struct declaration for a covered component (fields = inputPorts,
1319
- * declaration order = Object key order; gofmt-aligned). Empty inputPorts => empty struct. */
1320
- function emitInStruct(comp, plan) {
1321
- const name = inStructName(comp.name);
1322
- const ports = Object.keys(comp.inputPorts ?? {});
1323
- if (ports.length === 0) {
1324
- return `// ${name} — the CONCRETE input for '${comp.name}' (no input ports).\ntype ${name} struct{}`;
1325
- }
1326
- const names = ports.map((p) => goFieldName(p));
1327
- // #139: inputPortGoType reads the inputPortTypeRef SSoT — an OPTIONAL port is `*T` (absent → nil); an
1328
- // optional whose inner type has no native lowering FAILS CLOSED (never a boxed Value escape).
1329
- const types = ports.map((p) => inputPortGoType(comp.inputPorts[p], plan, `input port '${p}' of component '${comp.name}'`));
1330
- const nameW = Math.max(0, ...names.map((n) => n.length));
1331
- const typeW = Math.max(0, ...types.map((t) => t.length));
1332
- const fields = ports
1333
- .map((p, i) => `\t${names[i].padEnd(nameW)} ${types[i].padEnd(typeW)} // ${JSON.stringify(p)}`)
1334
- .join("\n");
1335
- return `// ${name} — the CONCRETE input for '${comp.name}' (fields = inputPorts; typed, consumer-built —
1336
- // NO generic *Obj, NO per-field boxing crosses the covered read boundary).
1337
- type ${name} struct {
1338
- ${fields}
1339
- }`;
1340
- }
1341
1342
  /**
1342
- * emitInDecoder — the TEST-glue decoder `decode_In_<comp>(input *Obj) (In_<comp>, error)`. It reads
1343
- * each declared input port from the generic *Obj into the concrete In_<comp> field (scalar → typed
1344
- * read with a `.(T)` on the SDK/wire Value; Value-typed field → the raw Value). Lives ONLY in the
1345
- * observe companion (test harness), never in the covered module — the covered runner takes In_<comp>
1346
- * pre-built by the consumer. A missing key leaves the zero value (every covered input is required +
1347
- * always supplied by the corpus); a present-but-wrong-scalar is a fail-closed decode error.
1343
+ * emitInDecoder — the TEST-glue decoder `decode_<comp>(input *Obj) (<positional args...>, err error)`. It reads
1344
+ * each declared input port from the generic *Obj into the entry's POSITIONAL arg (named return; scalar →
1345
+ * typed read on the SDK/wire Value; value-typed → the raw wire). Lives ONLY in the observe companion (test
1346
+ * harness), never in the covered module — the entry takes positional params (#192, box removed) and the
1347
+ * observe passes these decoded args positionally. A missing key leaves the zero value (every covered input
1348
+ * is required + always supplied by the corpus); a present-but-wrong-scalar is a fail-closed decode error.
1348
1349
  */
1349
1350
  function emitInDecoder(comp, plan) {
1350
- const name = inStructName(comp.name);
1351
1351
  const ports = Object.keys(comp.inputPorts ?? {});
1352
+ if (ports.length === 0 || comp.inputPorts === undefined)
1353
+ return ""; // no input → observe calls the entry with no args.
1354
+ // #192: decode the generic *Obj test input into the entry's POSITIONAL args (named returns = the params,
1355
+ // in inputPorts order; a decode mismatch sets `err` and returns). The `In_<comp>` box is gone — this
1356
+ // test-glue decoder produces the values the observe companion passes positionally to the entry.
1357
+ const rets = ports
1358
+ .map((p) => `${goParamName(p)} ${inputPortGoType(comp.inputPorts[p], plan, `input port '${p}' of component '${comp.name}'`)}`)
1359
+ .join(", ");
1352
1360
  const lines = [];
1353
- lines.push(`func decode_${name}(input *${PKG}.Obj) (${name}, error) {`);
1354
- lines.push(`\tvar in ${name}`);
1355
- if (ports.length === 0 || comp.inputPorts === undefined) {
1356
- lines.push(`\t_ = input`);
1357
- lines.push(`\treturn in, nil`);
1358
- lines.push(`}`);
1359
- return lines.join("\n");
1360
- }
1361
+ lines.push(`func decode_${sanitize(comp.name)}(input *${PKG}.Obj) (${rets}, err error) {`);
1361
1362
  lines.push(`\tif input == nil {`);
1362
- lines.push(`\t\treturn in, nil`);
1363
+ lines.push(`\t\treturn`);
1363
1364
  lines.push(`\t}`);
1364
1365
  for (const p of ports) {
1365
- const field = goFieldName(p);
1366
+ const arg = goParamName(p);
1366
1367
  const schema = comp.inputPorts[p];
1367
1368
  const scalar = inputScalarKind(schema);
1368
1369
  const et = schema.elemType;
@@ -1371,50 +1372,46 @@ function emitInDecoder(comp, plan) {
1371
1372
  // #108: decode the boxed Value array into the native []ElemT (test glue — materialize each element
1372
1373
  // via the typed materializer; a non-array or non-conforming element is a fail-closed decode error).
1373
1374
  // bc#156: a `value[]` element is BC's opaque wire — decode it with the BC-owned valueToWire (the SAME
1374
- // wire the output de-box uses), NOT the typed materializer (WireValue is not a de-box target). This is
1375
- // the generic bound-value list built from a heterogeneous / empty input array.
1375
+ // wire the output de-box uses), NOT the typed materializer (WireValue is not a de-box target).
1376
1376
  const elemRef = deriveTypeRef(et, plan);
1377
1377
  const elemGo = renderTypeRef(elemRef);
1378
1378
  const mat = elemRef.kind === "value" ? "valueToWire(ev)" : goTypedInternals.materializeExpr("ev", elemRef, plan);
1379
1379
  lines.push(`\t\tarr, isArr := v.([]${PKG}.Value)`);
1380
1380
  lines.push(`\t\tif !isArr {`);
1381
- lines.push(`\t\t\treturn in, ${PKG}.NewExprFailure("TYPE_MISMATCH", "input ${p}: expected array, got "+${PKG}.TypeName(v))`);
1381
+ lines.push(`\t\t\terr = ${PKG}.NewExprFailure("TYPE_MISMATCH", "input ${p}: expected array, got "+${PKG}.TypeName(v))`);
1382
+ lines.push(`\t\t\treturn`);
1382
1383
  lines.push(`\t\t}`);
1383
1384
  lines.push(`\t\tdec := make([]${elemGo}, 0, len(arr))`);
1384
1385
  lines.push(`\t\tfor _, ev := range arr {`);
1385
- // materializeExpr returns the must*-based decode (panics on a malformed corpus element — test glue).
1386
1386
  lines.push(`\t\t\tdec = append(dec, ${mat})`);
1387
1387
  lines.push(`\t\t}`);
1388
- // #177 (A): an OPTIONAL array port field is `*[]E` (inputPortTypeRef opt → pointer), so take its address.
1389
- lines.push(`\t\tin.${field} = ${inputPortIsOptional(schema) ? "&dec" : "dec"}`);
1388
+ // #177 (A): an OPTIONAL array port param is `*[]E` (inputPortTypeRef opt → pointer), so take its address.
1389
+ lines.push(`\t\t${arg} = ${inputPortIsOptional(schema) ? "&dec" : "dec"}`);
1390
1390
  lines.push(`\t}`);
1391
1391
  continue;
1392
1392
  }
1393
1393
  if (schema?.type === "value") {
1394
- // bc#156: a scalar `value` port — the raw bound value as BC's opaque wire (valueToWire).
1395
- lines.push(`\t\tin.${field} = valueToWire(v)`);
1394
+ lines.push(`\t\t${arg} = valueToWire(v)`);
1396
1395
  lines.push(`\t}`);
1397
1396
  continue;
1398
1397
  }
1399
1398
  if (schema?.type === "map" && et !== undefined) {
1400
- // #108-map: decode the boxed *Obj into the native map[string]V (test glue — the input map port
1401
- // carries a declared elemType). materializeExpr covers the map de-box (Obj → map[string]V).
1402
1399
  const mapRef = { kind: "map", value: deriveTypeRef(et, plan) };
1403
- lines.push(`\t\tin.${field} = ${goTypedInternals.materializeExpr("v", mapRef, plan)}`);
1400
+ lines.push(`\t\t${arg} = ${goTypedInternals.materializeExpr("v", mapRef, plan)}`);
1404
1401
  lines.push(`\t}`);
1405
1402
  continue;
1406
1403
  }
1407
1404
  if (scalar === undefined) {
1408
- lines.push(`\t\tin.${field} = v`);
1405
+ lines.push(`\t\t${arg} = v`);
1409
1406
  }
1410
1407
  else {
1411
1408
  // #139: materialize via the inputPortTypeRef SSoT so an OPTIONAL scalar reads as *T (present → &v);
1412
- // an absent optional never enters this block (Get !ok), leaving the field nil (not a required zero).
1413
- lines.push(`\t\tin.${field} = ${goTypedInternals.materializeExpr("v", inputPortTypeRef(schema, plan), plan)}`);
1409
+ // an absent optional never enters this block (Get !ok), leaving the param nil (not a required zero).
1410
+ lines.push(`\t\t${arg} = ${goTypedInternals.materializeExpr("v", inputPortTypeRef(schema, plan), plan)}`);
1414
1411
  }
1415
1412
  lines.push(`\t}`);
1416
1413
  }
1417
- lines.push(`\treturn in, nil`);
1414
+ lines.push(`\treturn`);
1418
1415
  lines.push(`}`);
1419
1416
  return lines.join("\n");
1420
1417
  }
@@ -1668,8 +1665,12 @@ function emitNativeRawRunner(comp, plan, flags, wire, leaf) {
1668
1665
  // interface, no generics (both are dynamic dispatch). Each transport returns the node's result WIRE (a
1669
1666
  // single ${wire.value}); the runner de-boxes it INLINE (fully-unrolled probe/match — no decode helper, no
1670
1667
  // output recursion) into the node's outType struct.
1671
- lines.push(`func ${runnerName(comp.name)}(in ${inStructName(comp.name)}) (${outStructType}, error) {`);
1672
- lines.push(`\t_ = in`);
1668
+ // #192: 1:1 map of the authored signature — positional params (one per input port, box removed), not
1669
+ // an `In_<comp>` struct. Go allows unused function params, so no `_ = param` guard is needed.
1670
+ const entryParams = Object.keys(comp.inputPorts ?? {})
1671
+ .map((p) => `${goParamName(p)} ${inputPortGoType(comp.inputPorts[p], plan, `input port '${p}' of component '${comp.name}'`)}`)
1672
+ .join(", ");
1673
+ lines.push(`func ${runnerName(comp.name)}(${entryParams}) (${outStructType}, error) {`);
1673
1674
  for (const k of order.keys()) {
1674
1675
  const node = comp.body[order[k]];
1675
1676
  const id = node.id;
@@ -1922,7 +1923,10 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
1922
1923
  // `Conn` field → `Tn{}`, an OPT `*Conn` field → a non-nil `&Tn{}` (Some(empty connection), NOT nil).
1923
1924
  // `Tn{}`'s serializer normalizes nil items to [] → {items:[],cursor:null} (#182).
1924
1925
  // - non-connection into → the go zero (opt → nil = null, #177 keep-with-null; unchanged).
1925
- const intoSkipZero = m.relationKind === "connection" ? goConnectionUnproduced(elemRowRef, elemRowRef) : goZero(elemRowRef);
1926
+ // LAZY: the skip value exists only for a GUARDED map...into (the two call sites below). An opaque-wire
1927
+ // element (bc#164) has no zero — and no `into` either (mapElemRowRef requires a named struct for into),
1928
+ // so computing it eagerly would fail-close a shape that never uses it.
1929
+ const intoSkipZero = () => (m.relationKind === "connection" ? goConnectionUnproduced(elemRowRef, elemRowRef) : goZero(elemRowRef));
1926
1930
  // emit the per-element guard keep-gate (#108). `il` = indent, `elemVar` = the over element loop var.
1927
1931
  // On skip: batched → `continue` (element excluded from items + keptOver); non-batched → `continue`.
1928
1932
  const emitGuard = (il, elemVar, onSkip = ["continue"]) => {
@@ -1957,7 +1961,7 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
1957
1961
  lines.push(`${indent}\t\titems_${s} = append(items_${s}, ep_${s})`);
1958
1962
  lines.push(`${indent}\t\tkeptIdx_${s} = append(keptIdx_${s}, oi_${s})`);
1959
1963
  lines.push(`${indent}\t} else {`);
1960
- lines.push(`${indent}\t\t${typedLocal(node.id)}[oi_${s}] = ${elemMat}(${elemLocal(s)}, ${intoSkipZero})`);
1964
+ lines.push(`${indent}\t\t${typedLocal(node.id)}[oi_${s}] = ${elemMat}(${elemLocal(s)}, ${intoSkipZero()})`);
1961
1965
  lines.push(`${indent}\t}`);
1962
1966
  lines.push(`${indent}}`);
1963
1967
  lines.push(`${indent}if len(items_${s}) > 0 {`);
@@ -2028,7 +2032,7 @@ function emitMapArm(comp, node, atPos, typedNodes, plan, priorNodeAt, zeroOut, f
2028
2032
  // (elemMat(over, nil | connZero)) instead of dropped — byte-equal to run_behavior's applyInto
2029
2033
  // (opt-into → null / connection-into → empty connection).
2030
2034
  const nonBatchedSkip = keepWithNull
2031
- ? [`${typedLocal(node.id)} = append(${typedLocal(node.id)}, ${elemMat}(${elemLocal(s)}, ${intoSkipZero}))`, "continue"]
2035
+ ? [`${typedLocal(node.id)} = append(${typedLocal(node.id)}, ${elemMat}(${elemLocal(s)}, ${intoSkipZero()}))`, "continue"]
2032
2036
  : ["continue"];
2033
2037
  for (const l of emitGuard(indent + "\t", elemLocal(s), nonBatchedSkip))
2034
2038
  lines.push(l);
@@ -2173,7 +2177,8 @@ function goInputHeadRef(head, comp, plan) {
2173
2177
  const ref = inputPortTypeRef(comp.inputPorts?.[head], plan);
2174
2178
  if (ref === undefined)
2175
2179
  return null;
2176
- return { expr: `in.${goFieldName(head)}`, ref };
2180
+ // #192: the input port is a positional PARAMETER of the entry (box removed) — read it by param name.
2181
+ return { expr: goParamName(head), ref };
2177
2182
  }
2178
2183
  /**
2179
2184
  * emitCondArm — the struct-native exec of a covered cond node (#108). Mirrors run_behavior's cond
@@ -2690,18 +2695,18 @@ func bcExpr_strGt(a, b string) bool { return bcExpr_cmpCP(a, b) > 0 }
2690
2695
  func bcExpr_strGe(a, b string) bool { return bcExpr_cmpCP(a, b) >= 0 }`;
2691
2696
  }
2692
2697
  // ── BindNativeRaw dispatch surface ──────────────────────────────────────────────────────
2693
- /** The struct dispatch surface: ComponentNamesNativeRaw + the per-component struct runners
2694
- * (RunNativeRawStruct_<comp>) ARE the exposed API. The consumer calls the struct runner directly
2695
- * (it returns the typed model — NO Value serialization on the read hot path, matching how graphddb
2696
- * reads: a model, never a boxed Value). There is deliberately NO Value dispatch map — that would
2697
- * require a Value serializer (the boxing residue bc#77 eliminates). A canonical Value observation
2698
- * (equivalence pin) is produced by the SEPARATE test-only observe companion (goTypedNativeObserve),
2699
- * which lives OUTSIDE this module so the covered module stays literal whole-file zero. */
2698
+ /** The dispatch surface: ComponentNamesNativeRaw + the per-component entries (#192: the exported method
2699
+ * `<Method>(<positional params>) (T, error)`) ARE the exposed API. The consumer calls the entry directly
2700
+ * (it returns the typed model — NO Value serialization on the read hot path, matching how graphddb reads:
2701
+ * a model, never a boxed Value). There is deliberately NO Value dispatch map — that would require a Value
2702
+ * serializer (the boxing residue bc#77 eliminates). A canonical Value observation (equivalence pin) is
2703
+ * produced by the SEPARATE test-only observe companion (goTypedNativeObserve), which lives OUTSIDE this
2704
+ * module so the covered module stays literal whole-file zero. */
2700
2705
  function emitStructSurface(native) {
2701
- return `// ComponentNamesNativeRaw — covered reads exposed on the combined struct-native path (declaration
2702
- // order). Each is driven via RunNativeRawStruct_<comp>(input) -> (T, error): a STRUCT return; the consumer
2703
- // keeps the model native (no Value serialization on the read hot path — the boxing residue bc#77 removes)
2704
- // and supplies the op-agnostic leaf transport symbols the runner calls. See INTEGRATION.md §6.
2706
+ return `// ComponentNamesNativeRaw — covered reads exposed on the combined native path (declaration order).
2707
+ // Each is a 1:1 entry <Method>(<positional params>) -> (T, error): a native return; the consumer keeps the
2708
+ // model native (no Value serialization on the read hot path — the boxing residue bc#77 removes) and
2709
+ // supplies the op-agnostic leaf transport symbols the entry calls. See INTEGRATION.md §6.
2705
2710
  var ComponentNamesNativeRaw = []string{${native.map((c) => JSON.stringify(c.name)).join(", ")}}`;
2706
2711
  }
2707
2712
  /** Minimal module header for a FULLY-covered module (bc#90 / runtime-free). A fully-covered module
@@ -2742,7 +2747,7 @@ function emitMinimalHeader(ctx, needStrings, needSync, needFmt, needMath, needSt
2742
2747
  // sequential runner below. There is NO generic Bind/dispatch/plan scaffolding AND NO bc-runtime import —
2743
2748
  // a fully-covered module is FULLY NATIVE (zero bc-runtime reference; only the std-lib it uses).
2744
2749
 
2745
- package behaviors
2750
+ package ${goPackageName(ctx.namespace)}
2746
2751
  ${importBlock}
2747
2752
  // ExpectedSpecVersions are the spec versions baked at generation time (provenance only — the module
2748
2753
  // is runtime-free, so there is no runtime SpecVersions to skew-check against, bc#90 / change #5).
@@ -2768,7 +2773,6 @@ function emit(ctx) {
2768
2773
  const leaf = ctx.leafTransport;
2769
2774
  // Emit the runners first so the nv* helper usage flags are known.
2770
2775
  const flags = { bind: false, field: false, cat: false, arr: false };
2771
- const inStructs = [];
2772
2776
  const elemCopiers = [];
2773
2777
  const runnerCodes = [];
2774
2778
  // every covered node returns a WireValue the inline de-box classifies — the wire seam (probe kind
@@ -2778,7 +2782,7 @@ function emit(ctx) {
2778
2782
  // inline at the call site), so there are NO per-node ports structs on either the covered plane or the
2779
2783
  // shared package — the transport ABI is the generic WireRow, not a per-node/per-role concrete struct.
2780
2784
  for (const c of native) {
2781
- inStructs.push(emitInStruct(c, plan));
2785
+ // #192: no `In_<comp>` box — the entry takes positional params, so nothing is pushed to inStructs.
2782
2786
  // build the full typed-node map FIRST so a map's over-element resolution can see every node.
2783
2787
  const typedNodes = buildTypedNodes(c, plan);
2784
2788
  // augmented-element copiers for covered map...into nodes (over fields + the de-boxed into value).
@@ -2839,15 +2843,16 @@ function emit(ctx) {
2839
2843
  // carries NO bc-runtime reference at all — failures use the LOCAL *BehaviorError (same codes, byte-equal to
2840
2844
  // run_behavior). Exec is INLINE sequential (no plan driver) so a relation child reads the parent's REAL
2841
2845
  // struct result via direct field access and the child-present decision is made from the real parent value —
2842
- // relationSingle / connection converge with run_behavior (fixes #323/#74). The exposed API is the
2843
- // STRUCT-returning RunNativeRawStruct_<comp>; the consumer supplies the leaf transport symbols (default
2844
- // same-package Leaf_<comp>, or a leafTransport import). This module is FULLY NATIVE: a naive grep for
2846
+ // relationSingle / connection converge with run_behavior (fixes #323/#74). The exposed API is the 1:1
2847
+ // STRUCT-returning entry <Method>(<positional params>) (the In_<comp> box removed); the consumer supplies
2848
+ // the leaf transport symbols (default same-package Leaf_<comp>, or a leafTransport import). This module is
2849
+ // FULLY NATIVE: a naive grep for
2845
2850
  // boxing primitives OR for the bc-runtime package finds nothing, by design (bc#90/runtime-free).`;
2846
2851
  const sections = [
2847
2852
  banner,
2848
2853
  `// 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}`,
2849
2854
  decls ? `// Typed struct declarations (outType-derived; hash-dedup — shared type plan).\n${decls}` : undefined,
2850
- `// 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")}`,
2855
+ // #192: no per-component `In_<comp>` input structs — the entry takes positional params (box removed).
2851
2856
  // the probe kind consts live in the covered module ALWAYS (the inline de-box compares against them); the
2852
2857
  // shared wire package carries its own identical copy when the types are hoisted there (cross-package).
2853
2858
  anyWire ? `// Probe kind consts (the inline de-box compares against these).\n${emitGoProbeKinds()}` : undefined,
@@ -2897,7 +2902,7 @@ ${emitGoWireTypes()}
2897
2902
  * whole-file zero (the ser_* NewObj is test glue, never on the consumer's read hot path). Emitted only for
2898
2903
  * the fully-covered case (the equivalence harness); production consumers never use it.
2899
2904
  */
2900
- export function goTypedNativeObserve(ir, runtimeImport, leaf) {
2905
+ export function goTypedNativeObserve(ir, runtimeImport, leaf, namespace) {
2901
2906
  const components = ir.components;
2902
2907
  const native = components.filter(isNativeRaw);
2903
2908
  const plan = buildTypePlan(ir);
@@ -2911,10 +2916,15 @@ export function goTypedNativeObserve(ir, runtimeImport, leaf) {
2911
2916
  .map((c) => {
2912
2917
  const outRef = c.outputType !== undefined ? deriveTypeRef(c.outputType, plan) : undefined;
2913
2918
  const ser = outRef ? serializeTyped("tv", outRef, plan) : "tv";
2914
- // decode the generic *Obj input into the CONCRETE In_<comp> struct (test glue — ONE decode at the
2915
- // top, OUTSIDE the covered hot path; a REQUIRED declared input is present so an absent key is a
2916
- // fail-closed decode error surfaced here, never on the native runner path).
2917
- 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}`;
2919
+ // #192: decode the generic *Obj test input into the entry's POSITIONAL args (test glue — ONE decode at
2920
+ // the top; a REQUIRED declared input absent is a fail-closed decode error here, never on the entry path),
2921
+ // then call the 1:1 entry positionally. A no-input entry is called with no args (no decoder).
2922
+ const args = Object.keys(c.inputPorts ?? {}).map((p) => goParamName(p));
2923
+ const decode = args.length === 0
2924
+ ? ""
2925
+ : `\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`;
2926
+ const unusedInput = args.length === 0 ? "\t\t_ = input\n" : "";
2927
+ return `\tif name == ${JSON.stringify(c.name)} {\n${decode}${unusedInput}\t\ttv, err := ${runnerName(c.name)}(${args.join(", ")})\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn ${ser}, nil\n\t}`;
2918
2928
  })
2919
2929
  .join("\n");
2920
2930
  // input decoders (TEST glue): generic *Obj -> concrete In_<comp>. Scalar fields read the typed value
@@ -3160,8 +3170,8 @@ func nextScripted(component string) (scriptSrc, bool) {
3160
3170
  // module, so its transport calls resolve) that drain a shared package-level scripted queue + the CONCRETE
3161
3171
  // WireValue/WireRow/WireList seam types. The consumer never uses this (it keeps the model native + supplies
3162
3172
  // its own concrete WireValue + transport funcs); it exists only so the test harness can byte-compare the
3163
- // STRUCT-only covered read against run_behavior. Same package as the module.
3164
- package behaviors
3173
+ // STRUCT-only covered read against run_behavior. Same package as the module (#192: shared namespace).
3174
+ package ${goPackageName(namespace)}
3165
3175
 
3166
3176
  import (
3167
3177
  "sync"