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
//! Control protocol for bidirectional communication with Claude Code
//!
//! This module implements the control protocol that enables bidirectional
//! communication between the SDK and Claude Code CLI, including:
//! - Request/response routing
//! - Initialization handshake
//! - Control messages (interrupt, pause, resume)
//! - Hook invocations
//! - Permission requests
//!
//! # Architecture
//!
//! The control protocol operates over the same transport as regular messages,
//! using a special message format to distinguish control messages from data messages.
//!
//! ## Message Flow
//!
//! ```text
//! SDK CLI
//! | |
//! |--- Init Request ---------->|
//! |<-- Init Response -----------|
//! | |
//! |--- User Message ---------->|
//! |<-- Assistant Message ------|
//! |<-- Hook Event -------------|
//! |--- Hook Response --------->|
//! |<-- Permission Request -----|
//! |--- Permission Response --->|
//! |--- Interrupt ------------->|
//! |<-- Result Message ---------|
//! ```
//!
//! # Example: Using the Protocol Handler
//!
//! ```rust
//! use claude_agent_sdk::control::ProtocolHandler;
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! // Create a protocol handler
//! let mut handler = ProtocolHandler::new();
//!
//! // Initialize the protocol
//! let init_request = handler.create_init_request();
//! // ... send init_request to CLI and receive response ...
//!
//! // Mark as initialized after handshake
//! handler.set_initialized(true);
//!
//! // Create and send control requests
//! let interrupt = handler.create_interrupt_request();
//! let send_msg = handler.create_send_message_request("Hello".to_string());
//! # Ok(())
//! # }
//! ```
//!
//! # Protocol Version
//!
//! Current protocol version: `1.0`
//!
//! The protocol version is negotiated during initialization. If the CLI
//! supports a different version, the connection will fail with an error.
pub use ;