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
// 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.
//! EvoRule 反应式执行器
//!
//! # 设计原则
//! - 事实驱动:所有交互通过 Fact 通道进行
//! - 单一串行通道:保证调度确定性
//! - 稳定检测:队列空 + 无待处理 I/O = 稳定
//! - 无状态泄漏:所有状态由反应器维护
//! - Append-Only 审计链:所有 Fact 追加到 FactsLog,支持审计重放
//!
//! # 架构
//! ```text
//! 用户/治理层 → FactSender → [command mpsc] → 反应器
//! ↓
//! 调用 TCB 核心
//! ↓
//! 产生新 Fact → event broadcast → 用户/I/O 订阅者/审计器
//! ↓
//! 所有 Fact → FactsLog(审计链)
//! ```
//!
//! # 模块结构
//! - `fact` — Fact 枚举、FactId、IoType
//! - `io_handler` — I/O Handler trait(H5: 从 evorule-governance 下沉,object-safe)
//! - `channel` — 双通道封装(command + event)
//! - `reactor` — 反应器核心引擎
//! - `state` — 反应器内部状态
//! - `facts_log` — Append-Only 审计链(含哈希链)
//! - `stable_detector` — 稳定检测逻辑
//! - `invariants` — 结构不变量检查
//! - `hash` — BLAKE3 哈希链算法(单一真相源)
//! - `wal` — WAL 读写(JSONL 格式,含哈希字段)
//! - `pure` — 纯逻辑模块,Kani 形式化验证准备
//! - `ffi` — C FFI 接口(feature = "ffi")
//! - `error` — 错误类型定义
//! - `phase` — 反应器阶段定义
//!
//! # 使用示例
//! ```ignore
//! use evorule_reactor::{Reactor, Fact, FactId};
//! use evorule_tcb::JsonValue;
//!
//! let core_eval = vec![]; // 从 core_eval.json 加载
//! let reactor = Reactor::builder(core_eval).max_rounds(1000).build();
//! let (tx, mut rx, _event_tx, _handle, _facts_log) = reactor.spawn();
//!
//! // 提交命令
//! tx.send(Fact::Command {
//! id: FactId(1),
//! instruction: JsonValue::object_from_pairs(&[
//! ("type", JsonValue::string("increment")),
//! ("params", JsonValue::object_from_pairs(&[
//! ("attr", JsonValue::string("x")),
//! ("delta", JsonValue::Integer(5)),
//! ])),
//! ]),
//! }).unwrap();
//!
//! // 等待 Stable 事实(broadcast recv 返回 Result)
//! while let Ok(fact) = rx.recv().await {
//! if let Fact::Stable { final_snapshot, .. } = fact {
//! println!("完成: {:?}", final_snapshot);
//! break;
//! }
//! }
//! ```
// 永不 panic 保障:禁止以下 panic-prone 模式(与 evorule-tcb 基线对齐)
// 测试/基准模块内可局部 #[allow(...)] 豁免
// ffi feature 必须暴露 extern "C" 接口,局部 allow unsafe_code 覆盖 deny
// 默认 feature (无 ffi) 下 ffi 模块不会被编译
// H5: IoHandler trait 下沉到 evorule-reactor(与 IoType 同层,object-safe)
pub use ;
pub use ReactorError;
pub use ;
// H5: IoHandler/IoResult 从 evorule-governance 下沉,供应用层 crate 使用
pub use ;
pub use ;
pub use InvariantViolation;
pub use ;
pub use ;
pub use ;
pub use ;
pub use StableDetector;
pub use ;