Skip to main content

interlink/
lib.rs

1//! Agent-to-agent messaging for Claude Code.
2//!
3//! Two Claude Code agents converse by each running an MCP server: outbound is the
4//! `send_message` tool; inbound is delivered by default to a local inbox that a
5//! background `interlink-mcp wait` listener drains (plain `claude`, no flags), with
6//! native `notifications/claude/channel` push as an opt-in enhancement (`interlinked`
7//! / `INTERLINK_CHANNELS=1`). A small **bus** routes messages between agents and
8//! buffers for agents that are offline.
9//!
10//! ## Trust
11//!
12//! An agent's identity is its **Ed25519 public key** ([`identity`]); names are
13//! local petnames. Every message is signed, and the channel server verifies the
14//! signature and checks the sender against an allowlist *before* pushing —
15//! so an unverified message never reaches the model.
16//!
17//! Authority comes from the server's `instructions` string, which lands in
18//! Claude's system prompt. The peer's text is untrusted data that parameterises
19//! an action; it never authorises one. An ungated channel is a prompt-injection
20//! vector.
21//!
22//! ## Pieces (each behind a feature)
23//!
24//! - [`identity`] — keys, signing, verification, the peer allowlist.
25//! - [`bus`] — the broker: per-recipient queues with `POST /send`, `GET /recv`.
26
27#[cfg(feature = "agent")]
28pub mod agent;
29
30#[cfg(feature = "bus")]
31pub mod bus;
32
33#[cfg(feature = "identity")]
34pub mod identity;
35
36#[cfg(feature = "agent")]
37pub mod policy;
38
39pub mod route;
40
41#[cfg(feature = "persist")]
42pub mod store;
43
44/// Unix milliseconds.
45pub fn now_ms() -> u64 {
46    std::time::SystemTime::now()
47        .duration_since(std::time::UNIX_EPOCH)
48        .unwrap_or_default()
49        .as_millis() as u64
50}