a3s_code_core/lib.rs
1//! A3S Code Core Library
2//!
3//! Embeddable AI agent library with tool execution capabilities.
4//! This crate contains all business logic extracted from the A3S Code agent,
5//! enabling direct Rust API usage as an embedded library.
6//!
7//! ## Quick Start
8//!
9//! ```rust,no_run
10//! use a3s_code_core::{Agent, AgentEvent};
11//!
12//! # async fn run() -> anyhow::Result<()> {
13//! // From a config file path (.hcl or .json)
14//! let agent = Agent::new("agent.hcl").await?;
15//!
16//! // Create a workspace-bound session
17//! let session = agent.session("/my-project", None)?;
18//!
19//! // Non-streaming
20//! let result = session.send("What files handle auth?", None).await?;
21//! println!("{}", result.text);
22//!
23//! // Streaming (AgentEvent is #[non_exhaustive])
24//! let (mut rx, _handle) = session.stream("Refactor auth", None).await?;
25//! while let Some(event) = rx.recv().await {
26//! match event {
27//! AgentEvent::TextDelta { text } => print!("{text}"),
28//! AgentEvent::End { .. } => break,
29//! _ => {} // required: #[non_exhaustive]
30//! }
31//! }
32//! # Ok(())
33//! # }
34//! ```
35//!
36//! ## Architecture
37//!
38//! ```text
39//! Agent (facade — config-driven, workspace-independent)
40//! +-- LlmClient (Anthropic / OpenAI)
41//! +-- CodeConfig (HCL / JSON)
42//! +-- SessionManager (multi-session support)
43//! |
44//! +-- AgentSession (workspace-bound)
45//! +-- AgentLoop (core execution engine)
46//! | +-- ToolExecutor (14 tools: 11 builtin + 3 skill discovery)
47//! | +-- LlmPlanner (JSON-structured planning)
48//! | +-- HITL Confirmation
49//! +-- HookEngine (8 lifecycle events)
50//! +-- Security (sanitizer, taint, injection detection, audit)
51//! +-- Memory (episodic, semantic, procedural, working)
52//! +-- MCP (JSON-RPC 2.0, stdio + HTTP+SSE)
53//! +-- Cost Tracking / Telemetry
54//! ```
55
56pub mod agent;
57pub mod agent_api;
58pub mod agent_teams;
59pub mod commands;
60pub mod config;
61pub mod context;
62pub mod error;
63pub mod file_history;
64pub mod hitl;
65pub mod hooks;
66pub mod llm;
67pub mod mcp;
68pub mod memory;
69pub mod permissions;
70pub mod planning;
71pub(crate) mod prompts;
72pub mod queue;
73pub(crate) mod retry;
74pub mod sandbox;
75pub mod security;
76pub mod session;
77pub mod session_lane_queue;
78pub mod skills;
79pub mod store;
80pub(crate) mod subagent;
81pub mod telemetry;
82#[cfg(feature = "telemetry")]
83pub mod telemetry_otel;
84pub mod tool_search;
85pub mod tools;
86
87// Re-export key types at crate root for ergonomic usage
88pub use agent::{AgentConfig, AgentEvent, AgentLoop, AgentResult};
89pub use agent_api::{Agent, AgentSession, SessionOptions, ToolCallResult};
90pub use agent_teams::{AgentTeam, TeamConfig, TeamMember, TeamMessage, TeamRole, TeamTaskBoard};
91pub use commands::{CommandAction, CommandContext, CommandOutput, CommandRegistry, SlashCommand};
92pub use config::{CodeConfig, ModelConfig, ModelCost, ModelLimit, ModelModalities, ProviderConfig};
93pub use error::{CodeError, Result};
94pub use hooks::HookEngine;
95pub use llm::{
96 AnthropicClient, Attachment, ContentBlock, ImageSource, LlmClient, LlmResponse, Message,
97 OpenAiClient, TokenUsage,
98};
99pub use prompts::SystemPromptSlots;
100pub use queue::{
101 ExternalTask, ExternalTaskResult, LaneHandlerConfig, SessionLane, SessionQueueConfig,
102 SessionQueueStats, TaskHandlerMode,
103};
104pub use sandbox::SandboxConfig;
105pub use session::{SessionConfig, SessionManager, SessionState};
106pub use session_lane_queue::SessionLaneQueue;
107pub use skills::{builtin_skills, Skill, SkillKind};
108pub use tool_search::{ToolIndex, ToolMatch, ToolSearchConfig};
109pub use tools::{ToolContext, ToolExecutor, ToolResult};