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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//! saorsa-agent: AI coding agent runtime.
//!
//! Provides the agent loop, built-in tools (bash, read, write, edit, grep, find, ls, web\_search),
//! event system for UI integration, and tool registry.
//!
//! # Architecture Overview
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────┐
//! │ UI Layer (saorsa) │
//! │ Sends user input, receives AgentEvent stream │
//! └─────────────────────────────────────────────────────────────┘
//! │
//! ▼
//! ┌─────────────────────────────────────────────────────────────┐
//! │ AgentLoop (async runtime) │
//! │ User message → Context → LLM request → Tool execution │
//! │ → Follow-up → ... → Final response → TurnEnd │
//! └─────────────────────────────────────────────────────────────┘
//! │ │ │
//! ▼ ▼ ▼
//! ┌──────────┐ ┌──────────────┐ ┌──────────────┐
//! │ Context │ │ Provider │ │ ToolRegistry │
//! │ Builder │ │ (saorsa-ai) │ │ │
//! └──────────┘ └──────────────┘ └──────────────┘
//! │ │ │
//! ▼ ▼ ▼
//! ┌────────────────┐ ┌────────────────┐ ┌────────────────┐
//! │ AGENTS.md │ │ Stream events │ │ Bash, Read, │
//! │ SYSTEM.md │ │ Tool calls │ │ Write, Edit, │
//! │ Project files │ │ Content delta │ │ Grep, Find, Ls │
//! └────────────────┘ └────────────────┘ └────────────────┘
//! │
//! ▼
//! ┌─────────────────────────────────────────────────────────────┐
//! │ SessionStorage (persistence) │
//! │ Messages, tool results, tree structure, bookmarks │
//! └─────────────────────────────────────────────────────────────┘
//! ```
//!
//! ## Core Subsystems
//!
//! - **AgentLoop**: Main async runtime coordinating LLM interaction and tool execution
//! - **Context Engineering**: Loads AGENTS.md, SYSTEM.md, project files into LLM context
//! - **Tool Registry**: Built-in tools (bash, file ops, search) + extension tools
//! - **Session Management**: Conversation history with tree-based branching and bookmarks
//! - **Event System**: Async channel for UI updates (thinking, tool execution, streaming)
//! - **Skills System**: On-demand capabilities loaded from `~/.claude/skills/`
//! - **Extension System**: Plugins for commands, keybindings, tools, and widgets
//!
//! ## Agent Execution Flow
//!
//! 1. **User Input** → ContextBuilder assembles prompt with context files
//! 2. **LLM Request** → Provider streams back content and tool calls
//! 3. **Tool Execution** → Tools run in parallel, results added to conversation
//! 4. **Follow-up** → If tools were called, LLM gets results and continues
//! 5. **Turn End** → Final response emitted, session persisted
//!
//! ## Key Types
//!
//! - `AgentLoop`: Main agent runtime (run_turn, execute_tools)
//! - `Tool`: Trait for executable tools with JSON schema parameters
//! - `ContextBuilder`: Assembles system prompt with AGENTS.md, project files
//! - `SessionStorage`: Persists conversation history and tree structure
//! - `AgentEvent`: UI update events (thinking, tool execution, streaming, turn end)
/// Context engineering (AGENTS.md, SYSTEM.md, compaction, skills, templates).
/// Cost tracking for LLM interactions.
/// Extension system for plugins and custom functionality.
/// Session management for conversation history and persistence.
/// Skills system for on-demand capabilities.
/// Prompt template system.
pub use ;
pub use AgentConfig;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;