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
69
70
71
//! par-term-acp: Agent Communication Protocol (ACP) implementation.
//!
//! This crate provides the core ACP protocol implementation for communicating
//! with AI coding agents (Claude Code, Codex CLI, Gemini CLI, etc.) via JSON-RPC.
//!
//! # Architecture
//!
//! The crate is organized into several modules:
//!
//! - [`agent`] - Agent lifecycle management (spawn, handshake, message routing dispatch)
//! - [`agents`] - Agent discovery and configuration loading
//! - [`message_handler`] - Background async task that routes incoming JSON-RPC messages to the UI
//! - [`protocol`] - ACP message types (initialize, session, permission, etc.)
//! - [`jsonrpc`] - JSON-RPC 2.0 client implementation
//! - [`fs_ops`] - Low-level filesystem operations (read, write, list, find)
//! - [`fs_tools`] - RPC handler functions for `fs/*` tool calls from the agent
//! - [`permissions`] - Permission request dispatch, auto-approval logic, `SafePaths`, and `is_safe_write_path`
//! - [`session`] - Session-new parameter builders (MCP server descriptor, Claude wrapper metadata)
//!
//! # Example
//!
//! ```ignore
//! use par_term_acp::{Agent, AgentConfig, AgentMessage, SafePaths, discover_agents};
//! use tokio::sync::mpsc;
//!
//! // Discover available agents
//! let agents = discover_agents(&config_dir);
//! let config = agents.into_iter().next().unwrap();
//!
//! // Create agent manager
//! let (tx, mut rx) = mpsc::unbounded_channel();
//! let safe_paths = SafePaths {
//! config_dir: PathBuf::from("/path/to/config"),
//! shaders_dir: PathBuf::from("/path/to/shaders"),
//! };
//! let mut agent = Agent::new(config, tx, safe_paths, PathBuf::from("par-term"));
//!
//! // Connect and handle messages
//! agent.connect("/working/dir", capabilities, &[]).await?;
//! while let Some(msg) = rx.recv().await {
//! match msg {
//! AgentMessage::SessionUpdate(update) => { /* handle */ }
//! AgentMessage::PermissionRequest { .. } => { /* handle */ }
//! _ => {}
//! }
//! }
//! ```
// Re-export the main public types at the crate root for convenience
pub use ;
pub use ;
pub use ;
pub use SafePaths;
pub use ;