Skip to main content

meerkat_comms/
lib.rs

1#![cfg_attr(test, allow(clippy::panic))]
2// meerkat-comms
3//! Inter-agent communication for Meerkat instances.
4
5// On wasm32, use tokio_with_wasm as a drop-in replacement for tokio.
6#[cfg(target_arch = "wasm32")]
7pub mod tokio {
8    pub use tokio_with_wasm::alias::*;
9}
10
11pub mod identity;
12pub mod inbox;
13pub mod inproc;
14pub mod peer_meta;
15pub mod transport;
16pub mod trust;
17pub mod types;
18
19// Network I/O modules — not available on wasm32
20#[cfg(not(target_arch = "wasm32"))]
21pub mod io_task;
22#[cfg(not(target_arch = "wasm32"))]
23pub mod plain_listener;
24
25pub mod agent;
26pub(crate) mod classify;
27pub mod event_injector;
28pub mod mcp;
29pub(crate) mod peer_types;
30pub mod router;
31pub mod runtime;
32
33pub use event_injector::CommsEventInjector;
34pub use identity::{IdentityError, Keypair, PubKey, Signature};
35pub use inbox::{AdmissionOutcome, DropReason, Inbox, InboxError, InboxSender};
36pub use inproc::{
37    InprocPeerInfo, InprocRegistry, InprocSendError, RegistrationOutcome, RegistrationRejection,
38};
39#[cfg(not(target_arch = "wasm32"))]
40pub use io_task::{IoTaskError, handle_connection};
41pub use peer_meta::PeerMeta;
42#[cfg(not(target_arch = "wasm32"))]
43pub use plain_listener::{PlainIngressFault, PlainIngressFaults, handle_plain_connection};
44pub use router::{CommsConfig, DEFAULT_MAX_MESSAGE_BYTES, Router, SendError};
45#[cfg(not(target_arch = "wasm32"))]
46pub use transport::codec::{EnvelopeFrame, TransportCodec};
47pub use transport::{PeerAddr, TransportError};
48pub use trust::{TrustEntry, TrustError, TrustResolveError, TrustStore, TrustedPeersView};
49pub use types::{Envelope, InboxItem, MessageKind, SenderContentTaint, Status};
50
51// Re-export high-level components
52pub use runtime::comms_bootstrap::{
53    CommsAdvertise, CommsBootstrap, CommsBootstrapError, CommsBootstrapMode, ParentCommsContext,
54    PreparedComms,
55};
56pub use runtime::comms_config::CoreCommsConfig;
57#[cfg(not(target_arch = "wasm32"))]
58pub use runtime::comms_config::ResolvedCommsConfig;
59pub use runtime::comms_runtime::{
60    CommsRuntime, CommsRuntimeError, CommsToolMaterial, PeerRequestResponseAuthority,
61};
62
63pub use agent::dispatcher::{
64    CommsToolDispatcher, DynCommsToolDispatcher, NoOpDispatcher, comms_tool_defs,
65};
66pub use mcp::tools::{
67    RuntimeCommsCommandHandle, ToolContext, comms_tool_unavailable_reason, handle_tools_call,
68    handle_tools_call_with_context, tools_list,
69};
70
71// Capability registration
72inventory::submit! {
73    meerkat_capabilities::CapabilityRegistration {
74        id: meerkat_capabilities::CapabilityId::Comms,
75        description: "Inter-agent communication: send, request, response, list peers + keep-alive",
76        scope: meerkat_capabilities::CapabilityScope::Universal,
77        requires_feature: Some("comms"),
78        prerequisites: &[],
79        status_resolver: None,
80    }
81}
82
83// Skill registration
84inventory::submit! {
85    meerkat_skills::SkillRegistration {
86        id: "multi-agent-comms",
87        name: "Multi-Agent Comms",
88        description: "Setting up keep-alive, peer trust, send vs request/response patterns",
89        scope: meerkat_core::skills::SkillScope::Builtin,
90        requires_capabilities: &["comms"],
91        body: include_str!("../skills/multi-agent-comms/SKILL.md"),
92        extensions: &[],
93    }
94}
95
96/// Confirm keep-alive mode availability when the comms crate is compiled in.
97///
98/// This function is intentionally a passthrough — its existence in the
99/// dependency graph *is* the validation. When `meerkat-comms` is linked,
100/// comms is available and keep-alive mode can be enabled. The feature-gate check
101/// lives in `meerkat::surface::resolve_keep_alive()`, which calls this
102/// function under `#[cfg(feature = "comms")]` and returns an error under
103/// `#[cfg(not(feature = "comms"))]`.
104///
105/// This two-layer design avoids duplicating the `cfg` check in every
106/// surface crate.
107pub fn validate_keep_alive(requested: bool) -> Result<bool, String> {
108    Ok(requested)
109}