behavior-contracts 0.12.1 → 0.13.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.
@@ -0,0 +1,139 @@
1
+ package coderuntime
2
+
3
+ import (
4
+ "fmt"
5
+ "strconv"
6
+ "strings"
7
+ )
8
+
9
+ // TemplateFailure is a template rendering Failure with a stable code.
10
+ type TemplateFailure struct {
11
+ Code string
12
+ Msg string
13
+ }
14
+
15
+ func (e *TemplateFailure) Error() string { return e.Code + ": " + e.Msg }
16
+
17
+ func tmplFail(code, msg string) *TemplateFailure { return &TemplateFailure{Code: code, Msg: msg} }
18
+
19
+ // RenderTemplate replaces {param} placeholders with bound values (strict).
20
+ // params is an ordered *Obj of bindings. {result.*}/{item.*} are out-of-scope
21
+ // Failures (resolved by a different layer). Placeholder = {non-empty non-brace}.
22
+ func RenderTemplate(template string, params *Obj) (string, error) {
23
+ if params == nil {
24
+ params = NewObj()
25
+ }
26
+ runes := []rune(template)
27
+ var out strings.Builder
28
+ i := 0
29
+ for i < len(runes) {
30
+ if runes[i] == '{' {
31
+ if close, name, ok := placeholderAt(runes, i); ok {
32
+ s, err := resolve(template, name, params)
33
+ if err != nil {
34
+ return "", err
35
+ }
36
+ out.WriteString(s)
37
+ i = close + 1
38
+ continue
39
+ }
40
+ }
41
+ out.WriteRune(runes[i])
42
+ i++
43
+ }
44
+ return out.String(), nil
45
+ }
46
+
47
+ // placeholderAt returns (closeIndex, name, ok) if runes[open]='{' begins a valid
48
+ // placeholder {name} where name is one-or-more non-brace runes (regex \{([^{}]+)\}).
49
+ func placeholderAt(runes []rune, open int) (int, string, bool) {
50
+ j := open + 1
51
+ count := 0
52
+ for j < len(runes) {
53
+ switch runes[j] {
54
+ case '{':
55
+ return 0, "", false // brace inside — not a placeholder
56
+ case '}':
57
+ if count == 0 {
58
+ return 0, "", false // empty name {}
59
+ }
60
+ return j, string(runes[open+1 : j]), true
61
+ default:
62
+ count++
63
+ j++
64
+ }
65
+ }
66
+ return 0, "", false
67
+ }
68
+
69
+ func resolve(template, name string, params *Obj) (string, error) {
70
+ if strings.HasPrefix(name, "result.") || strings.HasPrefix(name, "item.") {
71
+ return "", tmplFail("RESULT_SCOPE_IN_CORE",
72
+ fmt.Sprintf("template references '{%s}' resolved by a different layer, not core RenderTemplate", name))
73
+ }
74
+ v, ok := params.Get(name)
75
+ if !ok || v == nil {
76
+ return "", tmplFail("UNBOUND_PARAM",
77
+ fmt.Sprintf("template '%s' references unbound parameter '%s'", template, name))
78
+ }
79
+ return stringify(v)
80
+ }
81
+
82
+ // stringify renders a param value; parity SSoT = Python str(value).
83
+ func stringify(v Value) (string, error) {
84
+ switch t := v.(type) {
85
+ case string:
86
+ return t, nil
87
+ case bool:
88
+ if t {
89
+ return "True", nil
90
+ }
91
+ return "False", nil
92
+ case int64:
93
+ return strconv.FormatInt(t, 10), nil
94
+ case float64:
95
+ r, err := pyFloatRepr(t)
96
+ if err != nil {
97
+ return "", tmplFail("INVALID_STRINGIFY", fmt.Sprintf("cannot stringify non-finite float %v", t))
98
+ }
99
+ return r, nil
100
+ default:
101
+ return "", tmplFail("INVALID_STRINGIFY", fmt.Sprintf("cannot stringify %s into a template", typeName(v)))
102
+ }
103
+ }
104
+
105
+ // ResolvePartial is the explain/dry-run variant: substitutes {param}, leaves
106
+ // {result.*} and unbound params in place (template-rendering.md §3.3).
107
+ func ResolvePartial(template string, params *Obj) string {
108
+ if params == nil {
109
+ params = NewObj()
110
+ }
111
+ runes := []rune(template)
112
+ var out strings.Builder
113
+ i := 0
114
+ for i < len(runes) {
115
+ if runes[i] == '{' {
116
+ if close, name, ok := placeholderAt(runes, i); ok {
117
+ if strings.HasPrefix(name, "result.") || strings.HasPrefix(name, "item.") {
118
+ out.WriteString(string(runes[i : close+1]))
119
+ i = close + 1
120
+ continue
121
+ }
122
+ if v, present := params.Get(name); present && v != nil {
123
+ if s, err := stringify(v); err == nil {
124
+ out.WriteString(s)
125
+ } else {
126
+ out.WriteString(string(runes[i : close+1]))
127
+ }
128
+ } else {
129
+ out.WriteString(string(runes[i : close+1]))
130
+ }
131
+ i = close + 1
132
+ continue
133
+ }
134
+ }
135
+ out.WriteRune(runes[i])
136
+ i++
137
+ }
138
+ return out.String()
139
+ }
@@ -0,0 +1,138 @@
1
+ // Package coderuntime is the JSON-free codegen runtime of behavior-contracts:
2
+ // the exact runtime surface generated codegen modules (go-straightline /
3
+ // go-typed / go-typed-raw) and raw-ABI consumers link against. It contains the
4
+ // Value model, the native operator primitives (semantics SSoT value-core), the
5
+ // execution-plan skeleton (RunPlan), template rendering, canonical
6
+ // serialization, the handler seams (ComponentExec / RawComponentExec), and the
7
+ // coded Failure types.
8
+ //
9
+ // INVARIANT (owner order): this package MUST NOT import encoding/json (or any
10
+ // JSON-handling library) — generated codegen code must never pull JSON handling
11
+ // or IR data into a consumer's compile unit. The IR surface (expression IR
12
+ // walking, RunBehavior, codec/guard/fingerprint/conformance) lives in the
13
+ // parent package github.com/foo-ogawa/behavior-contracts/go, which imports and
14
+ // re-exports this package (never the reverse). This mirrors the Rust crate's
15
+ // `ir` cargo feature (default-on; the codegen surface builds with
16
+ // --no-default-features).
17
+ //
18
+ // Value model: int = checked int64, float = IEEE754 float64 (NaN/±Inf are Failures
19
+ // at the boundary), string, bool, null, arr, obj. The int/float distinction is
20
+ // normative: int 1 != float 1.0.
21
+ package coderuntime
22
+
23
+ // Value is a runtime value. The concrete dynamic types are:
24
+ //
25
+ // nil -> null
26
+ // bool -> bool
27
+ // int64 -> int
28
+ // float64 -> float
29
+ // string -> string
30
+ // []Value -> arr
31
+ // *Obj -> obj (insertion-ordered key/value pairs)
32
+ //
33
+ // *Obj preserves key insertion order because canonical key-identity semantics
34
+ // (canonicalValue: top-level sort only, nested = insertion order) depend on it.
35
+ type Value interface{}
36
+
37
+ // Obj is an insertion-ordered object value.
38
+ type Obj struct {
39
+ Keys []string
40
+ Vals map[string]Value
41
+ }
42
+
43
+ // NewObj returns an empty ordered object.
44
+ func NewObj() *Obj {
45
+ return &Obj{Keys: nil, Vals: map[string]Value{}}
46
+ }
47
+
48
+ // Set inserts or updates a key, preserving first-insertion order.
49
+ func (o *Obj) Set(k string, v Value) {
50
+ if _, ok := o.Vals[k]; !ok {
51
+ o.Keys = append(o.Keys, k)
52
+ }
53
+ o.Vals[k] = v
54
+ }
55
+
56
+ // Get returns the value for k and whether it is present.
57
+ func (o *Obj) Get(k string) (Value, bool) {
58
+ v, ok := o.Vals[k]
59
+ return v, ok
60
+ }
61
+
62
+ // Len returns the number of keys.
63
+ func (o *Obj) Len() int { return len(o.Keys) }
64
+
65
+ // typeName returns the normative type label of a runtime value.
66
+ func typeName(v Value) string {
67
+ switch v.(type) {
68
+ case nil:
69
+ return "null"
70
+ case bool:
71
+ return "bool"
72
+ case int64:
73
+ return "int"
74
+ case float64:
75
+ return "float"
76
+ case string:
77
+ return "string"
78
+ case []Value:
79
+ return "arr"
80
+ case *Obj:
81
+ return "obj"
82
+ default:
83
+ return "unknown"
84
+ }
85
+ }
86
+
87
+ // DeepEquals is deep structural equality with strict int/float type distinction
88
+ // (PROTOCOL §4.1): int64(1) != float64(1.0). NaN == NaN is treated as equal
89
+ // (used only for Failure-path fixtures). Objects compare by key-set + value
90
+ // (order-independent); arrays are ordered.
91
+ func DeepEquals(a, b Value) bool {
92
+ switch av := a.(type) {
93
+ case nil:
94
+ return b == nil
95
+ case bool:
96
+ bv, ok := b.(bool)
97
+ return ok && av == bv
98
+ case int64:
99
+ bv, ok := b.(int64)
100
+ return ok && av == bv
101
+ case float64:
102
+ bv, ok := b.(float64)
103
+ if !ok {
104
+ return false
105
+ }
106
+ return av == bv || (isNaN(av) && isNaN(bv))
107
+ case string:
108
+ bv, ok := b.(string)
109
+ return ok && av == bv
110
+ case []Value:
111
+ bv, ok := b.([]Value)
112
+ if !ok || len(av) != len(bv) {
113
+ return false
114
+ }
115
+ for i := range av {
116
+ if !DeepEquals(av[i], bv[i]) {
117
+ return false
118
+ }
119
+ }
120
+ return true
121
+ case *Obj:
122
+ bv, ok := b.(*Obj)
123
+ if !ok || av.Len() != bv.Len() {
124
+ return false
125
+ }
126
+ for _, k := range av.Keys {
127
+ w, present := bv.Get(k)
128
+ if !present || !DeepEquals(av.Vals[k], w) {
129
+ return false
130
+ }
131
+ }
132
+ return true
133
+ default:
134
+ return false
135
+ }
136
+ }
137
+
138
+ func isNaN(f float64) bool { return f != f }
@@ -0,0 +1,9 @@
1
+ package coderuntime
2
+
3
+ // Version is the dsl-contracts release version (library semver — distinct from
4
+ // the IR/vector SpecVersions in spec.go). Go modules are consumed by VCS tag, so
5
+ // this constant is kept in lockstep with the git tag `go/vX.Y.Z` (and with the
6
+ // npm / PyPI / crates packages) by scripts/sync-versions.mjs — the single source
7
+ // of truth is the repo-root VERSION file. Do not edit by hand; run
8
+ // `node scripts/sync-versions.mjs`.
9
+ const Version = "0.13.1"
package/go/compat.go ADDED
@@ -0,0 +1,289 @@
1
+ // Package dslcontracts is the Go port of the dsl-contracts language-neutral IR
2
+ // runtime COMMON core: expression evaluation, template rendering, execution-plan
3
+ // skeleton, and canonical serialization. It passes the shared conformance vectors
4
+ // byte-for-byte alongside the TypeScript, Python, and Rust implementations.
5
+ //
6
+ // Since 0.5.0 the JSON-free codegen runtime lives in the subpackage
7
+ // coderuntime (github.com/foo-ogawa/behavior-contracts/go/coderuntime): the
8
+ // surface generated codegen modules and raw-ABI consumers link against, with
9
+ // ZERO encoding/json in its dependency tree. This parent package keeps the IR
10
+ // surface (EvaluateExpression, RunBehavior, codec / envelope / guard /
11
+ // fingerprint / conformance — everything that consumes parsed JSON/IR) and
12
+ // re-exports the moved symbols below, so existing interpreter consumers keep
13
+ // compiling unchanged. This mirrors the Rust crate's default-on `ir` feature.
14
+ //
15
+ // Value model: int = checked int64, float = IEEE754 float64 (NaN/±Inf are Failures
16
+ // at the boundary), string, bool, null, arr, obj. The int/float distinction is
17
+ // normative: int 1 != float 1.0.
18
+ package dslcontracts
19
+
20
+ import (
21
+ "math"
22
+
23
+ "github.com/foo-ogawa/behavior-contracts/go/coderuntime"
24
+ )
25
+
26
+ // ── Back-compat re-exports (moved to coderuntime in 0.5.0) ────────────────────
27
+ // Type aliases keep assignability and method sets; func wrappers keep call sites.
28
+
29
+ // Value model (coderuntime/value.go).
30
+ type (
31
+ // Value is a runtime value. See coderuntime.Value.
32
+ Value = coderuntime.Value
33
+ // Obj is an insertion-ordered object value. See coderuntime.Obj.
34
+ Obj = coderuntime.Obj
35
+ )
36
+
37
+ // Expression value-core (coderuntime/exprcore.go).
38
+ type (
39
+ // ExprFailure is an expression evaluation Failure with a stable code.
40
+ ExprFailure = coderuntime.ExprFailure
41
+ )
42
+
43
+ // Behavior handler seams (coderuntime/behaviorcore.go).
44
+ type (
45
+ // BehaviorFailure is a RunBehavior failure with a stable code.
46
+ BehaviorFailure = coderuntime.BehaviorFailure
47
+ // ComponentExec is the boundary-injected handler registry seam (§7.1).
48
+ ComponentExec = coderuntime.ComponentExec
49
+ // ComponentCtxExec is the ctx-carrying extension of ComponentExec.
50
+ ComponentCtxExec = coderuntime.ComponentCtxExec
51
+ )
52
+
53
+ // Execution plan (coderuntime/plan.go).
54
+ type (
55
+ // ExecutionPlanSpec is the stage grouping for run_plan.
56
+ ExecutionPlanSpec = coderuntime.ExecutionPlanSpec
57
+ // OpSpec describes one operation.
58
+ OpSpec = coderuntime.OpSpec
59
+ // ExecOutcome is a consumer-supplied node execution result.
60
+ ExecOutcome = coderuntime.ExecOutcome
61
+ // ErrorDetail is the structured, recoverable payload a failure carries (scp-error.md).
62
+ ErrorDetail = coderuntime.ErrorDetail
63
+ // Exec is the consumer callback: exec(op, boundValue) -> outcome.
64
+ Exec = coderuntime.Exec
65
+ // OnSkip is the skip-time notification of RunPlan (see coderuntime.OnSkip).
66
+ OnSkip = coderuntime.OnSkip
67
+ // PlanFailure is a plan execution Failure with a stable code.
68
+ PlanFailure = coderuntime.PlanFailure
69
+ // RunResult holds the outcome of run_plan.
70
+ RunResult = coderuntime.RunResult
71
+ )
72
+
73
+ // Template / canonical (coderuntime/template.go, coderuntime/canonical.go).
74
+ type (
75
+ // TemplateFailure is a template rendering Failure with a stable code.
76
+ TemplateFailure = coderuntime.TemplateFailure
77
+ // CanonicalFailure is a canonical-serialization Failure with a stable code.
78
+ CanonicalFailure = coderuntime.CanonicalFailure
79
+ )
80
+
81
+ // RAW handler ABI (coderuntime/rawabi.go).
82
+ type (
83
+ // RawValue is a handler result on the RAW data plane.
84
+ RawValue = coderuntime.RawValue
85
+ // RawRow is the object accessor on the raw data plane.
86
+ RawRow = coderuntime.RawRow
87
+ // RawOutcome is a RAW handler execution result.
88
+ RawOutcome = coderuntime.RawOutcome
89
+ // RawComponentExec is the RAW handler registry seam.
90
+ RawComponentExec = coderuntime.RawComponentExec
91
+ // RawComponentCtxExec is the ctx-carrying extension of RawComponentExec.
92
+ RawComponentCtxExec = coderuntime.RawComponentCtxExec
93
+ // RawObj is bc's native map-backed RawRow used by the conformance harness.
94
+ RawObj = coderuntime.RawObj
95
+ )
96
+
97
+ // Native PORTS ABI (coderuntime/rawabi.go, 0.5.0).
98
+ type (
99
+ // NativePorts carries a generated per-node native ports struct (no map container).
100
+ NativePorts = coderuntime.NativePorts
101
+ // PortReader is the optional uniform read accessor a native ports struct implements.
102
+ PortReader = coderuntime.PortReader
103
+ // NativeComponentExec is the native-ports handler registry seam.
104
+ NativeComponentExec = coderuntime.NativeComponentExec
105
+ // NativeComponentCtxExec is the ctx-carrying extension of NativeComponentExec.
106
+ NativeComponentCtxExec = coderuntime.NativeComponentCtxExec
107
+ // NativeRawComponentExec is the combined native-ports-in + raw-result-out seam (bc#77; bc#94
108
+ // concretized the covered path: the generated runner is generic over the concrete handler type,
109
+ // so ExecNativeRaw is a DIRECT (devirtualized) call — no interface-dispatch shim. The single
110
+ // method always carries nodeID; the separate ctx interface + its resolution assert are gone).
111
+ NativeRawComponentExec = coderuntime.NativeRawComponentExec
112
+ )
113
+
114
+ // ExprFn は codegen が native primitive へ渡す被演算子 thunk(scope→評価済み Value)。
115
+ type ExprFn = coderuntime.ExprFn
116
+
117
+ // Version is the dsl-contracts release version (see coderuntime/version.go).
118
+ const Version = coderuntime.Version
119
+
120
+ // ForbiddenObjectKey is rejected fail-closed anywhere an object is built from
121
+ // IR/JSON-derived arbitrary string keys (expression-ir.md §2.3/§8).
122
+ const ForbiddenObjectKey = coderuntime.ForbiddenObjectKey
123
+
124
+ // EnvelopeSpecVersion is the default graphddb-shaped supported envelope version.
125
+ const EnvelopeSpecVersion = coderuntime.EnvelopeSpecVersion
126
+
127
+ // SpecVersions are the supported IR/vector spec versions (see coderuntime/spec.go).
128
+ var SpecVersions = coderuntime.SpecVersions
129
+
130
+ // NewObj returns an empty ordered object.
131
+ func NewObj() *Obj { return coderuntime.NewObj() }
132
+
133
+ // DeepEquals is deep structural equality with strict int/float type distinction.
134
+ func DeepEquals(a, b Value) bool { return coderuntime.DeepEquals(a, b) }
135
+
136
+ // OkOutcome / ErrOutcome are convenience constructors.
137
+ func OkOutcome(v Value) ExecOutcome { return coderuntime.OkOutcome(v) }
138
+ func ErrOutcome(e string) ExecOutcome { return coderuntime.ErrOutcome(e) }
139
+
140
+ // ErrOutcomeDetail — a failure outcome carrying a structured Error Value (scp-error.md).
141
+ func ErrOutcomeDetail(e string, d *ErrorDetail) ExecOutcome {
142
+ return coderuntime.ErrOutcomeDetail(e, d)
143
+ }
144
+
145
+ // RunPlan executes the plan. plan may be nil (1 op = 1 stage fallback). onSkip is
146
+ // optional (at most one) — see OnSkip.
147
+ func RunPlan(plan *ExecutionPlanSpec, ops []OpSpec, exec Exec, onSkip ...OnSkip) (*RunResult, error) {
148
+ return coderuntime.RunPlan(plan, ops, exec, onSkip...)
149
+ }
150
+
151
+ // RenderTemplate replaces {param} placeholders with bound values (strict).
152
+ func RenderTemplate(template string, params *Obj) (string, error) {
153
+ return coderuntime.RenderTemplate(template, params)
154
+ }
155
+
156
+ // ResolvePartial is the explain/dry-run variant of RenderTemplate.
157
+ func ResolvePartial(template string, params *Obj) string {
158
+ return coderuntime.ResolvePartial(template, params)
159
+ }
160
+
161
+ // PyFloatRepr renders f exactly as CPython repr(float) / json.dumps(float) would.
162
+ func PyFloatRepr(f float64) (string, error) { return coderuntime.PyFloatRepr(f) }
163
+
164
+ // CanonicalValue is key-identity canonical serialization.
165
+ func CanonicalValue(v Value) (string, error) { return coderuntime.CanonicalValue(v) }
166
+
167
+ // CanonicalJSON is fingerprint canonical serialization.
168
+ func CanonicalJSON(v Value) (string, error) { return coderuntime.CanonicalJSON(v) }
169
+
170
+ // ── RAW handler ABI wrappers ──────────────────────────────────────────────────
171
+
172
+ // OkRaw / ErrRaw are convenience constructors mirroring OkOutcome / ErrOutcome.
173
+ func OkRaw(v RawValue) RawOutcome { return coderuntime.OkRaw(v) }
174
+ func ErrRaw(e string) RawOutcome { return coderuntime.ErrRaw(e) }
175
+
176
+ // ExecRawHandler dispatches to ExecRawCtx when available, else ExecRaw.
177
+ func ExecRawHandler(handlers RawComponentExec, nodeID, component string, ports *Obj, bound Value) (RawOutcome, bool) {
178
+ return coderuntime.ExecRawHandler(handlers, nodeID, component, ports, bound)
179
+ }
180
+
181
+ // ExecNativeHandler dispatches to ExecNativeCtx when available, else ExecNative (native PORTS ABI).
182
+ func ExecNativeHandler(handlers NativeComponentExec, nodeID, component string, ports NativePorts, bound Value) (ExecOutcome, bool) {
183
+ return coderuntime.ExecNativeHandler(handlers, nodeID, component, ports, bound)
184
+ }
185
+
186
+ // RawFieldType returns the normative type label of a RawValue.
187
+ func RawFieldType(v RawValue) string { return coderuntime.RawFieldType(v) }
188
+
189
+ // NewRawObj returns an empty native-backed RawRow.
190
+ func NewRawObj() *RawObj { return coderuntime.NewRawObj() }
191
+
192
+ // RawFromValue lowers a dynamic Value into the equivalent native-backed RawValue.
193
+ func RawFromValue(v Value) RawValue { return coderuntime.RawFromValue(v) }
194
+
195
+ // ── Native primitives (codegen callable surface, coderuntime/primitives.go) ──
196
+
197
+ func AddNative(a, b ExprFn, scope *Obj) (Value, error) { return coderuntime.AddNative(a, b, scope) }
198
+ func SubNative(a, b ExprFn, scope *Obj) (Value, error) { return coderuntime.SubNative(a, b, scope) }
199
+ func MulNative(a, b ExprFn, scope *Obj) (Value, error) { return coderuntime.MulNative(a, b, scope) }
200
+ func NegNative(a ExprFn, scope *Obj) (Value, error) { return coderuntime.NegNative(a, scope) }
201
+ func DivNative(a, b ExprFn, scope *Obj) (Value, error) { return coderuntime.DivNative(a, b, scope) }
202
+ func ModNative(a, b ExprFn, scope *Obj) (Value, error) { return coderuntime.ModNative(a, b, scope) }
203
+ func EqNative(a, b ExprFn, scope *Obj) (Value, error) { return coderuntime.EqNative(a, b, scope) }
204
+ func NeNative(a, b ExprFn, scope *Obj) (Value, error) { return coderuntime.NeNative(a, b, scope) }
205
+ func LtNative(a, b ExprFn, scope *Obj) (Value, error) { return coderuntime.LtNative(a, b, scope) }
206
+ func LeNative(a, b ExprFn, scope *Obj) (Value, error) { return coderuntime.LeNative(a, b, scope) }
207
+ func GtNative(a, b ExprFn, scope *Obj) (Value, error) { return coderuntime.GtNative(a, b, scope) }
208
+ func GeNative(a, b ExprFn, scope *Obj) (Value, error) { return coderuntime.GeNative(a, b, scope) }
209
+ func NotNative(a ExprFn, scope *Obj) (Value, error) { return coderuntime.NotNative(a, scope) }
210
+ func AndNative(a, b ExprFn, scope *Obj) (Value, error) { return coderuntime.AndNative(a, b, scope) }
211
+ func OrNative(a, b ExprFn, scope *Obj) (Value, error) { return coderuntime.OrNative(a, b, scope) }
212
+ func CoalesceNative(a, b ExprFn, scope *Obj) (Value, error) {
213
+ return coderuntime.CoalesceNative(a, b, scope)
214
+ }
215
+ func CondNative(c, then, els ExprFn, scope *Obj) (Value, error) {
216
+ return coderuntime.CondNative(c, then, els, scope)
217
+ }
218
+ func LenNative(a ExprFn, scope *Obj) (Value, error) { return coderuntime.LenNative(a, scope) }
219
+ func ArrNative(elems []ExprFn, scope *Obj) (Value, error) {
220
+ return coderuntime.ArrNative(elems, scope)
221
+ }
222
+ func ObjNative(keys []string, vals []ExprFn, scope *Obj) (Value, error) {
223
+ return coderuntime.ObjNative(keys, vals, scope)
224
+ }
225
+ func IntLitNative(literal string) (Value, error) { return coderuntime.IntLitNative(literal) }
226
+ func FloatLitNative(n float64) (Value, error) { return coderuntime.FloatLitNative(n) }
227
+ func NumberLitNative(n float64) (Value, error) { return coderuntime.NumberLitNative(n) }
228
+ func NewBehaviorFailure(code, msg string) error { return coderuntime.NewBehaviorFailure(code, msg) }
229
+ func NewExprFailure(code, msg string) error { return coderuntime.NewExprFailure(code, msg) }
230
+ func NewPlanFailure(code, msg string) error { return coderuntime.NewPlanFailure(code, msg) }
231
+
232
+ // TypeName returns the normative type label of a runtime Value.
233
+ func TypeName(v Value) string { return coderuntime.TypeName(v) }
234
+
235
+ // ExecHandler dispatches to ExecCtx when available, else Exec.
236
+ func ExecHandler(handlers ComponentExec, nodeID, component string, ports *Obj, bound Value) (ExecOutcome, bool) {
237
+ return coderuntime.ExecHandler(handlers, nodeID, component, ports, bound)
238
+ }
239
+
240
+ // FirstExecErrInVisitOrder restores the sequential precedence of exec-internal
241
+ // failures (bc#23).
242
+ func FirstExecErrInVisitOrder(execErrs []error, plan *ExecutionPlanSpec, n int, planErr error) error {
243
+ return coderuntime.FirstExecErrInVisitOrder(execErrs, plan, n, planErr)
244
+ }
245
+
246
+ // MapWithConcurrency は入力順を保存し in-flight を concurrency で上限する bounded 並行 map。
247
+ func MapWithConcurrency[T any, U any](items []T, concurrency int64, worker func(item T, index int) U) []U {
248
+ return coderuntime.MapWithConcurrency(items, concurrency, worker)
249
+ }
250
+
251
+ // UnproducedValue は未生成 Port(Skip)の表現値。single→nil / connection→空 connection。
252
+ func UnproducedValue(kind string) Value { return coderuntime.UnproducedValue(kind) }
253
+
254
+ // SkipConnection は connection relation の未生成 = {items:[],cursor:nil}。
255
+ func SkipConnection() Value { return coderuntime.SkipConnection() }
256
+
257
+ // ── Internal bridges (unexported helpers this package's IR surface shares
258
+ // with the coderuntime SSoT — same names the pre-split files used) ───────────
259
+
260
+ func typeName(v Value) string { return coderuntime.TypeName(v) }
261
+
262
+ func exprFail(code, msg string) *ExprFailure { return &ExprFailure{Code: code, Msg: msg} }
263
+ func behaviorFail(code, msg string) *BehaviorFailure { return &BehaviorFailure{Code: code, Msg: msg} }
264
+ func canonFail(code, msg string) *CanonicalFailure { return &CanonicalFailure{Code: code, Msg: msg} }
265
+
266
+ func arithValues(op string, a, b Value) (Value, error) { return coderuntime.ArithValues(op, a, b) }
267
+ func negValue(a Value) (Value, error) { return coderuntime.NegValue(a) }
268
+ func divValues(a, b Value) (Value, error) { return coderuntime.DivValues(a, b) }
269
+ func modValues(a, b Value) (Value, error) { return coderuntime.ModValues(a, b) }
270
+ func eqNeValues(op string, a, b Value) (Value, error) { return coderuntime.EqNeValues(op, a, b) }
271
+ func compareOp(op string, a, b Value) (Value, error) { return coderuntime.CompareValues(op, a, b) }
272
+ func lenValue(a Value) (Value, error) { return coderuntime.LenValue(a) }
273
+ func intLitValue(s string) (Value, error) { return coderuntime.IntLitValue(s) }
274
+ func checkFinite(v float64) (Value, error) { return coderuntime.CheckFinite(v) }
275
+ func requireBool(v Value, ctx string) (bool, error) { return coderuntime.RequireBool(v, ctx) }
276
+
277
+ func execHandler(handlers ComponentExec, nodeID, component string, ports *Obj, bound Value) (ExecOutcome, bool) {
278
+ return coderuntime.ExecHandler(handlers, nodeID, component, ports, bound)
279
+ }
280
+ func firstExecErrInVisitOrder(execErrs []error, plan *ExecutionPlanSpec, n int, planErr error) error {
281
+ return coderuntime.FirstExecErrInVisitOrder(execErrs, plan, n, planErr)
282
+ }
283
+ func unproducedValue(kind string) Value { return coderuntime.UnproducedValue(kind) }
284
+
285
+ func pyFloatRepr(f float64) (string, error) { return coderuntime.PyFloatRepr(f) }
286
+ func nan() float64 { return math.NaN() }
287
+ func posInf() float64 { return math.Inf(1) }
288
+ func negInf() float64 { return math.Inf(-1) }
289
+ func isNaN(f float64) bool { return f != f }