Skip to main content

behavior_contracts/
lib.rs

1//! behavior-contracts — language-neutral IR runtime COMMON core (Rust).
2//!
3//! Ports the same thin COMMON primitives as the TS/Python references. No backend,
4//! key-resolution, retry-tuning, or DSL-specific concepts — those live in consumers.
5//!
6//! Public COMMON primitives (runtime-boundary.md §2.1):
7//!   - [`validate_envelope`] — spec-version fail-closed check
8//!   - [`evaluate_expression`] — expression-ir.md normative evaluation
9//!   - [`render_template`] — `{param}` strict rendering
10//!   - [`run_plan`] — execution-plan skeleton (stage / Skip propagation / Policy Kind)
11//!   - [`canonical_value`] / [`canonical_json`] / [`py_float_repr`] — canonical serialization
12//!   - [`assert_portable`] — Portability Guard
13//!   - [`decode_value`] / [`deep_equals`] — conformance runner adapter COMMON part
14
15pub mod behavior;
16pub mod canonical;
17#[cfg(feature = "ir")]
18pub mod codec;
19#[cfg(feature = "ir")]
20pub mod envelope;
21pub mod expr;
22#[cfg(feature = "ir")]
23pub mod fingerprint;
24#[cfg(feature = "ir")]
25pub mod guard;
26pub mod plan;
27pub mod primitives;
28pub mod rawabi;
29pub mod template;
30pub mod value;
31
32/// Supported spec versions (IR/vector versions; distinct from the crate semver).
33pub struct SpecVersions;
34impl SpecVersions {
35    pub const EXPRESSION: i64 = 2; // v2: obj __proto__ own key -> FORBIDDEN_KEY (fail-closed)
36    pub const TEMPLATE: i64 = 1;
37    pub const PLAN: i64 = 1;
38    pub const CANONICAL: i64 = 2; // v2: obj value __proto__ own key -> FORBIDDEN_KEY (fail-closed)
39    pub const BEHAVIOR: i64 = 5; // v5 carries two changes: (a) a map node's Element Error Policy Kind (error|skip) + the structured detail a Failure carries (scp-error.md) — elementPolicy:skip changes which elements are present; (b) an OMITTED input key for a port DECLARED optional (inputPorts[name].required === false, the opt portable-type constructor) binds to null, the runner reading the component's own inputPorts declaration when building the entry scope. A required / undeclared name is unaffected (still UNKNOWN_BINDING). An old runtime (behavior<=4) loud-rejects a v5 IR via the baked-spec-skew gate + conformance pre-flight version fail-closed.
40    pub const GUARD: i64 = 3; // Vector-pin the map elementPolicy closed set (error|skip) and the reject of a skip declared where no per-element Failure exists (a batched map). (v2 = assert_compiled + UNTYPED_NODE + operator-type-signature SSoT accept/reject.)
41    pub const C2: i64 = 1; // v1 (bc#28: c2-catalog-swap — catalog-swap execution + IR structural identity)
42    pub const PROVENANCE: i64 = 1; // v1 (#128/A6): serialization-boundary canonical fingerprint match (5-language loud reject of tampered/stale) + non-vacuity (CONFORMANCE_MUTATE)
43}
44
45/// Default graphddb-shaped supported envelope version (`"<major>.<minor>"`).
46pub const ENVELOPE_SPEC_VERSION: &str = "1.1";
47
48// ── re-exports (public surface) ──────────────────────────────────────────────
49pub use value::{deep_equals, Value};
50
51#[cfg(feature = "ir")]
52pub use expr::evaluate as evaluate_expression;
53pub use expr::{cmp_code_points, ExprFailure, ExprFailureCode};
54
55pub use template::{render_template, resolve_partial, TemplateFailure, TemplateFailureCode};
56
57pub use plan::{
58    run_plan, run_plan_parallel, ElementPolicyKind, ErrorDetail, ErrorKind, ExecOutcome,
59    ExecutionPlanSpec, OpSpec, PlanFailure, PlanFailureCode, PolicyKind, RelationKind, RunResult,
60};
61
62pub use canonical::{
63    canonical_json, canonical_value, py_float_repr, CanonicalFailure, CanonicalFailureCode,
64};
65
66#[cfg(feature = "ir")]
67pub use envelope::{validate_envelope, EnvelopeFailure, EnvelopeFailureCode};
68
69#[cfg(feature = "ir")]
70pub use guard::{
71    assert_portable, assert_portable_component_graph, PortabilityError, PORTABLE_EXPR_OPERATORS,
72};
73
74#[cfg(feature = "ir")]
75pub use behavior::run_behavior;
76pub use behavior::{BehaviorError, BehaviorFailureCode, ComponentExec};
77
78// bc#76: RAW handler ABI — the de-boxed handler boundary (RawValue/RawRow, NOT Value).
79pub use rawabi::{
80    raw_from_value, raw_missing_prop, raw_type_mismatch, RawComponentExec, RawOutcome, RawRow,
81    RawValue,
82};
83
84// bc 0.5.0: native PORTS ABI — the de-plumbed port container (native struct behind PortReader,
85// NOT a Vec<(String, Value)>).
86pub use rawabi::{NativeComponentExec, PortReader};
87
88// bc#77: combined native-ports-in + raw-result-out ABI — the 1.0 read de-box (zero boxed Value
89// on both the port AND row plane; inline sequential exec, no run_plan skip-gate).
90// bc#94: the seam is nativized — the concrete ports struct flows to the handler by monomorphized
91// generic instantiation (`PortReaderT`, no `&dyn`/`as_any`/`downcast`; `&self` so a `Sync` handler
92// parallelizes without a forced `Mutex`).
93pub use rawabi::{NativeRawComponentExec, PortReaderT};
94
95#[cfg(feature = "ir")]
96pub use fingerprint::{fingerprint_component_graph, FingerprintFailure, FingerprintFailureCode};
97
98#[cfg(feature = "ir")]
99pub use codec::{decode_value, encode_value, DecodeError};
100
101// ── codegen primitive surface (bc#36 / typed-codegen.md §3.4) ─────────────────
102// 生成コードが直呼びできる安定 primitive 公開面。式演算子は `primitives` モジュールで
103// 個別関数として公開する(意味論は SSoT `evaluate_expression` へ委譲する薄いラッパ)。
104// bounded 並行 / skip・unproduced / hydration helper も同モジュールに含める。
105pub use primitives::{
106    concat_native, hydrate_into, map_with_concurrency, ref_native, ref_opt_native, skip_connection,
107    skip_single, unproduced_value,
108};