swarm-engine-core 0.1.6

Core types and orchestration for SwarmEngine
Documentation
//! Events - 行動イベントの定義と配信
//!
//! Worker が実行した行動を ActionEvent として記録・配信する。
//!
//! # Event → Record の流れ
//!
//! **全ての Record は Event から変換される。** Builder で直接 Record を作らない。
//!
//! ```text
//! [Production Runtime]
//!
//! ActionEvent ─────────────────────┐
//! LearningEvent::StrategyAdvice ───┼──▶ ActionEventSubscriber ──▶ Record::Action
//! LearningEvent::DependencyGraph ──┼──▶ (同上) ──▶ Record::DependencyGraph
//! LlmDebugEvent ───────────────────┘
//!//!                                  LearningDaemon ──▶ Episode ──▶ Learn
//! ```
//!
//! # Event 追加時の Checklist
//!
//! 1. `events/` に Event 型を定義(または既存 enum に variant 追加)
//! 2. `LearningEventChannel` で配信可能にする(該当する場合)
//! 3. `learn/record/` に対応する `*Record` 型を定義
//! 4. `From<&Event> for *Record` を record ファイルに実装
//! 5. `record/mod.rs` で `From<&Event> for Record` にルーティング追加
//! 6. Subscriber が新 Event を処理できることを確認
//!
//! # モジュール構成
//!
//! | モジュール | 責務 |
//! |-----------|------|
//! | `action` | ActionEvent の定義 |
//! | `learning_channel` | LearningEvent の定義と配信 |
//! | `publisher` | イベント配信(broadcast) |
//! | `persistence` | JSONL 永続化 |
//! | `lifecycle` | Orchestrator ライフサイクルフック |
//!
//! # Hook vs Sink の命名規則
//!
//! | 名前 | 実行モデル | 例 |
//! |------|----------|-----|
//! | **Hook** | 同期 callback | `LifecycleHook` - Orchestrator 終了時に呼ばれる |
//! | **Sink** | async trait | `EventSink` (pipeline) - 非同期でデータを消費 |
//!
//! # 使用例
//!
//! ```ignore
//! use swarm_engine_core::events::{
//!     ActionEventPublisher, ActionEventBuilder, ActionEventResult,
//!     JsonlWriter,
//! };
//!
//! // Publisher を作成
//! let (publisher, rx) = ActionEventPublisher::new(1024);
//!
//! // JSONL 永続化を起動
//! let writer = JsonlWriter::new(publisher.subscribe(), "events.jsonl");
//! tokio::spawn(writer.run());
//!
//! // イベントを配信
//! let event = ActionEventBuilder::new(tick, worker_id, "CheckStatus")
//!     .target("user-service")
//!     .result(ActionEventResult::success())
//!     .build();
//! publisher.publish(event);
//! ```

mod action;
mod learning_channel;
mod lifecycle;
mod persistence;
mod publisher;
mod trace;

pub use action::{
    ActionContext, ActionEvent, ActionEventBuilder, ActionEventId, ActionEventResult,
};
pub use learning_channel::{
    DependencyGraphInferenceBuilder, LearnStatsOutcome, LearnStatsSnapshotBuilder, LearningEvent,
    LearningEventChannel, StrategyAdviceBuilder,
};
pub use lifecycle::{
    CompositeLifecycleHook, LearningLifecycleHook, LifecycleEvent, LifecycleHook, TerminationStats,
};
pub use persistence::JsonlWriter;
pub use publisher::{create_action_event_publisher, ActionEventPublisher};
pub use trace::{
    InMemoryTraceSubscriber, JsonlTraceSubscriber, NoOpTraceSubscriber, TraceEvent, TraceSubscriber,
};