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;
17pub mod codec;
18pub mod envelope;
19pub mod expr;
20pub mod fingerprint;
21pub mod guard;
22pub mod plan;
23pub mod primitives;
24pub mod template;
25pub mod value;
26
27/// Supported spec versions (IR/vector versions; distinct from the crate semver).
28pub struct SpecVersions;
29impl SpecVersions {
30    pub const EXPRESSION: i64 = 2; // v2: obj __proto__ own key -> FORBIDDEN_KEY (fail-closed)
31    pub const TEMPLATE: i64 = 1;
32    pub const PLAN: i64 = 1;
33    pub const CANONICAL: i64 = 2; // v2: obj value __proto__ own key -> FORBIDDEN_KEY (fail-closed)
34    pub const BEHAVIOR: i64 = 2; // v2: map.when / map.into / map.batched / handler ctx (bc#22; v1 IR semantics unchanged)
35    pub const GUARD: i64 = 1; // v1 (bc#25: vector-pin assert_portable_component_graph accept/reject)
36    pub const C2: i64 = 1; // v1 (bc#28: c2-catalog-swap — catalog-swap execution + IR structural identity)
37}
38
39/// Default graphddb-shaped supported envelope version (`"<major>.<minor>"`).
40pub const ENVELOPE_SPEC_VERSION: &str = "1.1";
41
42// ── re-exports (public surface) ──────────────────────────────────────────────
43pub use value::{deep_equals, Value};
44
45pub use expr::{cmp_code_points, evaluate as evaluate_expression, ExprFailure, ExprFailureCode};
46
47pub use template::{render_template, resolve_partial, TemplateFailure, TemplateFailureCode};
48
49pub use plan::{
50    run_plan, run_plan_parallel, ExecOutcome, ExecutionPlanSpec, OpSpec, PlanFailure,
51    PlanFailureCode, PolicyKind, RelationKind, RunResult,
52};
53
54pub use canonical::{
55    canonical_json, canonical_value, py_float_repr, CanonicalFailure, CanonicalFailureCode,
56};
57
58pub use envelope::{validate_envelope, EnvelopeFailure, EnvelopeFailureCode};
59
60pub use guard::{
61    assert_portable, assert_portable_component_graph, PortabilityError, PORTABLE_EXPR_OPERATORS,
62};
63
64pub use behavior::{run_behavior, BehaviorError, BehaviorFailureCode, ComponentExec};
65
66pub use fingerprint::{fingerprint_component_graph, FingerprintFailure, FingerprintFailureCode};
67
68pub use codec::{decode_value, encode_value, DecodeError};
69
70// ── codegen primitive surface (bc#36 / typed-codegen.md §3.4) ─────────────────
71// 生成コードが直呼びできる安定 primitive 公開面。式演算子は `primitives` モジュールで
72// 個別関数として公開する(意味論は SSoT `evaluate_expression` へ委譲する薄いラッパ)。
73// bounded 並行 / skip・unproduced / hydration helper も同モジュールに含める。
74pub use primitives::{
75    concat_native, hydrate_into, map_with_concurrency, ref_native, ref_opt_native, skip_connection,
76    skip_single, unproduced_value,
77};