Skip to main content

meerkat_session/
lib.rs

1//! meerkat-session — Session service orchestration for Meerkat.
2//!
3//! This crate provides `EphemeralSessionService` (always available) and,
4//! behind feature gates, `PersistentSessionService` and `DefaultCompactor`.
5//!
6//! # Features
7//!
8//! - `session-store`: Enables `PersistentSessionService`.
9//! - `session-compaction`: Enables `DefaultCompactor` and `CompactionConfig`.
10
11// On wasm32, use tokio_with_wasm as a drop-in replacement for tokio.
12#[cfg(target_arch = "wasm32")]
13pub mod tokio {
14    pub use tokio_with_wasm::alias::*;
15}
16
17pub mod ephemeral;
18pub(crate) mod turn_admission;
19
20/// Session persistence migration entry points.
21///
22/// Canonical module path is `meerkat_session::persistent::migrations`;
23/// the implementation lives in `meerkat_core::session_migrations` so
24/// `meerkat-store` (which depends on `meerkat-core` but not on
25/// `meerkat-session`) can call the same transforms from its own
26/// deserialize path. This re-export keeps the wave-c plan's public
27/// path stable while making the functions dependency-reachable from
28/// below.
29pub use meerkat_core::session_migrations as migrations;
30
31#[cfg(feature = "session-compaction")]
32pub mod compactor;
33
34#[cfg(all(feature = "session-store", not(target_arch = "wasm32")))]
35pub mod event_store;
36
37#[cfg(all(feature = "session-store", not(target_arch = "wasm32")))]
38pub mod persistent;
39
40#[cfg(all(feature = "session-store", not(target_arch = "wasm32")))]
41pub mod projector;
42
43pub use ephemeral::{
44    EphemeralSessionService, RuntimeContextAdmissionGuard, SessionAgent, SessionAgentBuilder,
45    SessionSnapshot,
46};
47
48/// Metadata key used to store session labels in the `Session.metadata` map.
49///
50/// This is a persistence implementation detail — the ephemeral service stores
51/// labels directly on its in-memory handle; the persistent service reads/writes
52/// this key in the session snapshot for durable storage.
53pub const SESSION_LABELS_KEY: &str = "session_labels";
54
55/// Type alias for the raw broadcast receiver used by event subscriptions.
56/// Exported for WASM surface which needs synchronous `try_recv()`.
57pub type BroadcastEventReceiver =
58    tokio::sync::broadcast::Receiver<meerkat_core::EventEnvelope<meerkat_core::AgentEvent>>;
59
60#[cfg(feature = "session-compaction")]
61pub use compactor::DefaultCompactor;
62
63#[cfg(all(feature = "session-store", not(target_arch = "wasm32")))]
64pub use persistent::{
65    MachineServiceTurnCommitProtocol, MachineSessionArchiveProtocol, PersistentSessionService,
66};
67
68// Skill registration (inventory + meerkat-skills not available on wasm32)
69#[cfg(all(feature = "session-store", not(target_arch = "wasm32")))]
70inventory::submit! {
71    meerkat_skills::SkillRegistration {
72        id: "session-management",
73        name: "Session Management",
74        description: "Session persistence, resume patterns, event store replay, compaction tuning",
75        scope: meerkat_core::skills::SkillScope::Builtin,
76        requires_capabilities: &["session_store"],
77        body: include_str!("../skills/session-management/SKILL.md"),
78        extensions: &[],
79    }
80}
81
82// Capability registrations (inventory not available on wasm32)
83#[cfg(all(feature = "session-store", not(target_arch = "wasm32")))]
84inventory::submit! {
85    meerkat_capabilities::CapabilityRegistration {
86        id: meerkat_capabilities::CapabilityId::SessionStore,
87        description: "PersistentSessionService, SessionProjector",
88        scope: meerkat_capabilities::CapabilityScope::Universal,
89        requires_feature: Some("session-store"),
90        prerequisites: &[],
91        status_resolver: None,
92    }
93}
94
95#[cfg(all(feature = "session-compaction", not(target_arch = "wasm32")))]
96inventory::submit! {
97    meerkat_capabilities::CapabilityRegistration {
98        id: meerkat_capabilities::CapabilityId::SessionCompaction,
99        description: "DefaultCompactor: auto-compact at token threshold, LLM summary, history rebuild",
100        scope: meerkat_capabilities::CapabilityScope::Universal,
101        requires_feature: Some("session-compaction"),
102        prerequisites: &[],
103        status_resolver: None,
104    }
105}