1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2026 EvoRule Project
// This file is part of EvoRule, licensed under GNU Affero General Public License v3 or later.
//! Mechanism gateway: the single injection point for canonical mechanism
//! execution (meta-instruction evaluation) into plugin families.
//!
//! The plugin-kit crate deliberately carries **no** dependency on the
//! canonical repo (`evorule-tcb` / `evorule-reactor`). Mechanism-dependent
//! services (e.g. the inference family's forward simulation) obtain their
//! meta-instruction executor exclusively through this gateway, which the
//! host process registers at startup:
//!
//! - **Hosts** (the canonical consumer of the mechanism layer, e.g.
//! `evorule-server`) implement [`MechanismGateway`] and call
//! [`register_mechanism_gateway`] during plugin loading. This keeps the
//! service entry point (`evorule-server`) as the only legitimate consumer
//! of canonical mechanism capabilities.
//! - **Guests** (wasm32 family modules) ship **without** a gateway: their
//! compile graph contains no canonical crates at all, and any
//! mechanism-dependent call fails visibly with
//! [`GATEWAY_UNAVAILABLE_ERR`] (never a silent fallback, never a stub
//! impersonating the real mechanism).
//!
//! # Failure semantics (fail-visible)
//!
//! [`require_mechanism_gateway`] returns a self-describing error when no
//! gateway has been registered. Callers surface this error through their
//! regular business-error channel; nothing degrades silently.
//!
//! # Result mirroring
//!
//! [`MetaOutcome`] mirrors the canonical executor's result enum arm-for-arm
//! (state / io-required / halted). The host-side implementation performs a
//! mechanical three-arm mapping; no semantic reinterpretation happens on
//! either side of the boundary.
use ;
use crateJsonValue;
/// Canonical fail-visible error for mechanism calls without a registered
/// gateway. Byte-stable by design: host-side and guest-side runs must
/// produce the identical error text so downstream golden vectors and
/// parity comparisons stay deterministic.
pub const GATEWAY_UNAVAILABLE_ERR: &str = "mechanism gateway not available in this runtime \
(guest runtimes ship without a mechanism gateway by design; hosts must register one via \
register_mechanism_gateway at startup)";
/// Outcome of one meta-instruction execution, mirrored arm-for-arm from the
/// canonical executor's result type (state / io-required / halted).
///
/// This mirror lives in plugin-kit (not in the primitive-types layer) on
/// purpose: it carries mechanism semantics, which must not leak into the
/// base value-domain crate.
/// Host-side mechanism executor: synchronous pure-function view over the
/// canonical meta-instruction state machine.
static GATEWAY: = new;
/// Register the process-wide mechanism gateway (host startup / plugin
/// loading path).
///
/// # Errors
///
/// A gateway is already registered — fail-fast, no silent replacement (the
/// first registration wins for the lifetime of the process).
/// Registered gateway, if any. Hosts register at startup; guests never do.
/// Fail-visible accessor: the registered gateway or
/// [`GATEWAY_UNAVAILABLE_ERR`]. Mechanism-dependent services must go through
/// this accessor (never silently degrade when [`mechanism_gateway`] is
/// `None`).
///
/// # Errors
///
/// No gateway registered in this runtime (guest case, or a host that missed
/// its startup registration).