|
1 | 1 | # CLAUDE.md |
2 | 2 |
|
3 | | -This file provides guidance to Claude Code when working with code in this repository. |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
4 | 4 |
|
5 | | -**Refer to `PROJECT_GUIDELINES.md` for detailed project information (Overview, Structure, Workflow, Code Style, Patterns, User Lessons).** |
| 5 | +## Repository Overview |
6 | 6 |
|
7 | | -## Common Tasks and Examples |
| 7 | +This monorepo contains: |
| 8 | +- **edda/** - Rust-based event-sourced AI agent orchestration system (primary focus) |
| 9 | +- **klaudbiusz/** - Python wrapper around Claude Agent SDK using edda MCP (secondary focus) |
| 10 | +- **agent/** - Legacy Python implementation (no longer maintained, mentioned for context only) |
8 | 11 |
|
9 | | -*[Add examples of common development tasks, like adding a new agent, extending the API, etc.]* |
| 12 | +Active development happens in **edda/** with occasional work in **klaudbiusz/**. |
10 | 13 |
|
11 | | -## Known Issues and Workarounds |
| 14 | +## Edda - Event-Sourced Agent Orchestration (Rust) |
12 | 15 |
|
13 | | -*[Document any known issues or quirks in the codebase that Claude should be aware of]* |
| 16 | +### Architecture |
14 | 17 |
|
15 | | -## Contributing Guidelines |
| 18 | +Edda is a modular event-sourced AI agent system primarily exposed as an **MCP server** for existing agents (like Claude Code). Originally designed as a standalone agent, it was redesigned to focus on MCP integration. The standalone agent (edda_agent/edda_cli) is in early stage and postponed. |
16 | 19 |
|
17 | | -*[Add any specific guidelines for contributing to the project]* |
| 20 | +Core capabilities: |
| 21 | +- **Event-Sourced Architecture**: Full event history with aggregate state reconstruction (edda_mq - stable) |
| 22 | +- **Multi-Agent Coordination**: Link agents with bidirectional communication via `Link` trait |
| 23 | +- **Pluggable LLM Support**: Provider-agnostic (Anthropic, Gemini via Rig) |
| 24 | +- **Sandboxed Execution**: Dagger-based containerized tool execution |
| 25 | +- **Type-Safe Event Handling**: Strongly-typed events, commands, responses |
| 26 | + |
| 27 | +### Workspace Structure |
| 28 | + |
| 29 | +| Crate | Purpose | Status | |
| 30 | +|-------|---------|--------| |
| 31 | +| **edda_mcp** | MCP server exposing scaffolding + Databricks tools | **Active (primary focus)** | |
| 32 | +| **edda_sandbox** | Dagger-based containerized tool execution | **Active** | |
| 33 | +| **edda_integrations** | External service integrations (Databricks, Google Sheets) | **Active** | |
| 34 | +| **edda_templates** | Embedded application templates | **Active** | |
| 35 | +| **edda_screenshot** | Browser automation for UI validation | **Active** | |
| 36 | +| **edda_mq** | Event sourcing, aggregate management, persistence (SQLite/PostgreSQL) | Stable (infra for edda_agent) | |
| 37 | +| **edda_agent** | Agent orchestration, event handling, coordination, toolbox | Early stage, postponed | |
| 38 | +| **edda_cli** | CLI for agent execution | Early stage, postponed | |
| 39 | + |
| 40 | +### Common Commands |
| 41 | + |
| 42 | +```bash |
| 43 | +cd edda |
| 44 | + |
| 45 | +# Check all crates compile |
| 46 | +cargo check |
| 47 | + |
| 48 | +# Run examples (also serve as integration tests) |
| 49 | +cargo run --example basic |
| 50 | +cargo run --example planner_worker |
| 51 | +cargo run --example multi_agent |
| 52 | + |
| 53 | +# Build MCP server |
| 54 | +cargo build --release --package edda_mcp |
| 55 | + |
| 56 | +# Run MCP server (for development) |
| 57 | +cargo run --manifest-path edda_mcp/Cargo.toml |
| 58 | + |
| 59 | +# Run tests |
| 60 | +cargo test |
| 61 | + |
| 62 | +# Install MCP server locally |
| 63 | +curl -LsSf https://raw.githubusercontent.com/appdotbuild/agent/refs/heads/main/edda/install.sh | sh |
| 64 | +``` |
| 65 | + |
| 66 | +### Core Patterns |
| 67 | + |
| 68 | +#### Agent Trait |
| 69 | + |
| 70 | +All agents implement: |
| 71 | +```rust |
| 72 | +pub trait Agent: Default + Send + Sync + Clone { |
| 73 | + const TYPE: &'static str; |
| 74 | + type AgentCommand: Send; |
| 75 | + type AgentEvent: MQEvent; |
| 76 | + type AgentError: std::error::Error + Send + Sync + 'static; |
| 77 | + type Services: Send + Sync; |
| 78 | + |
| 79 | + async fn handle_tool_results( |
| 80 | + state: &AgentState<Self>, |
| 81 | + services: &Self::Services, |
| 82 | + incoming: Vec<ToolResult>, |
| 83 | + ) -> Result<Vec<Event<Self::AgentEvent>>, Self::AgentError>; |
| 84 | + |
| 85 | + async fn handle_command( |
| 86 | + state: &AgentState<Self>, |
| 87 | + cmd: Self::AgentCommand, |
| 88 | + services: &Self::Services, |
| 89 | + ) -> Result<Vec<Event<Self::AgentEvent>>, Self::AgentError>; |
| 90 | + |
| 91 | + fn apply_event(state: &mut AgentState<Self>, event: Event<Self::AgentEvent>); |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +#### Event Sourcing Pattern |
| 96 | + |
| 97 | +Commands → Events → State: |
| 98 | +1. Command received (e.g., `SendRequest`) |
| 99 | +2. Handler validates and emits events |
| 100 | +3. Events persisted to event store |
| 101 | +4. State updated via `apply_event` |
| 102 | +5. Listeners dispatch events to handlers |
| 103 | + |
| 104 | +#### Multi-Agent Coordination |
| 105 | + |
| 106 | +Use `Link` trait for agent-to-agent communication: |
| 107 | +```rust |
| 108 | +link_runtimes(&mut main_runtime, &mut specialist_runtime, CustomLink); |
| 109 | +``` |
| 110 | + |
| 111 | +Example: Main agent delegates Databricks exploration to specialist agent with haiku model for cost optimization. |
| 112 | + |
| 113 | +#### Tool Execution |
| 114 | + |
| 115 | +All tools run in Dagger sandbox with isolated filesystem. Tools implement: |
| 116 | +```rust |
| 117 | +pub trait Tool: Send + Sync { |
| 118 | + fn name(&self) -> String; |
| 119 | + fn definition(&self) -> ToolDefinition; |
| 120 | + async fn call(&self, args: Value, sandbox: &mut impl Sandbox) -> Result<String>; |
| 121 | +} |
| 122 | +``` |
| 123 | + |
| 124 | +### Key Files |
| 125 | + |
| 126 | +- **edda/docs/DESIGN.md** - Complete system design with diagrams |
| 127 | +- **edda/CLAUDE.md** - Edda-specific development guidance |
| 128 | +- **edda_agent/src/processor/agent.rs** - Agent trait and runtime |
| 129 | +- **edda_agent/src/processor/link.rs** - Multi-agent coordination |
| 130 | +- **edda_agent/src/toolbox/basic.rs** - Core tools (ReadFile, WriteFile, Bash, etc.) |
| 131 | +- **edda_mq/src/aggregate.rs** - Event sourcing primitives |
| 132 | +- **edda_mcp/src/main.rs** - MCP server implementation |
| 133 | + |
| 134 | +### Environment Variables |
| 135 | + |
| 136 | +```bash |
| 137 | +# LLM providers |
| 138 | +ANTHROPIC_API_KEY=sk-ant-... |
| 139 | +GEMINI_API_KEY=... |
| 140 | + |
| 141 | +# Databricks (if using) |
| 142 | +DATABRICKS_HOST=https://your-workspace.databricks.com |
| 143 | +DATABRICKS_TOKEN=dapi... |
| 144 | + |
| 145 | +# Logging |
| 146 | +RUST_LOG=edda=debug,edda_agent=trace |
| 147 | +``` |
| 148 | + |
| 149 | +### Adding New Components |
| 150 | + |
| 151 | +**New Agent:** |
| 152 | +1. Implement `Agent` trait with custom command/event types |
| 153 | +2. Define `handle_tool_results` and `handle_command` methods |
| 154 | +3. Implement `apply_event` for state reconstruction |
| 155 | +4. Create `Runtime` with handlers (LLM, Tool, Log) |
| 156 | + |
| 157 | +**New Tool:** |
| 158 | +1. Implement `Tool` trait in `edda_agent/src/toolbox/` |
| 159 | +2. Define tool name and schema via `definition()` |
| 160 | +3. Implement `call()` method with sandbox execution |
| 161 | +4. Register in tool handler |
| 162 | + |
| 163 | +**New Integration:** |
| 164 | +1. Add client in `edda_integrations/` |
| 165 | +2. Create tools wrapping integration API |
| 166 | +3. Add MCP tools in `edda_mcp/src/tools/` if needed |
| 167 | + |
| 168 | +## Klaudbiusz - Databricks App Generator (Python) |
| 169 | + |
| 170 | +AI-powered Databricks application generator achieving **90% success rate** (18/20 apps deployable). |
| 171 | + |
| 172 | +### Structure |
| 173 | + |
| 174 | +- **cli/** - Generation (`main.py`, `codegen.py`) and evaluation (`evaluate_all.py`) scripts |
| 175 | +- **agents/** - Claude Agent definitions (markdown format with YAML frontmatter) |
| 176 | +- **app/** - Generated TypeScript full-stack applications (gitignored) |
| 177 | +- **eval-docs/** - 9-metric evaluation framework documentation |
| 178 | + |
| 179 | +### Common Commands |
| 180 | + |
| 181 | +```bash |
| 182 | +cd klaudbiusz |
| 183 | + |
| 184 | +# Generate single app |
| 185 | +uv run cli/main.py "Create customer churn analysis dashboard" |
| 186 | + |
| 187 | +# Batch generate from prompts |
| 188 | +uv run cli/bulk_run.py |
| 189 | + |
| 190 | +# Evaluate all apps |
| 191 | +python3 cli/evaluate_all.py |
| 192 | + |
| 193 | +# Archive evaluation results |
| 194 | +./cli/archive_evaluation.sh |
| 195 | +``` |
| 196 | + |
| 197 | +### Integration with Edda |
| 198 | + |
| 199 | +Klaudbiusz uses edda's MCP server via Claude Agent SDK: |
| 200 | +- `AppBuilder` class spawns `edda_mcp` binary |
| 201 | +- Agents use tools: `scaffold_data_app`, `validate_data_app`, `databricks_*` |
| 202 | +- Subagent pattern: main agent delegates to `dataresearch` agent for Databricks exploration |
| 203 | + |
| 204 | +## General Development Guidelines |
| 205 | + |
| 206 | +### Rust (edda) |
| 207 | + |
| 208 | +- Always run `cargo check` after changes |
| 209 | +- Leverage Rust type system: match by type, not string conditions |
| 210 | +- Rust chosen for correctness: avoid implicit fallbacks |
| 211 | +- Use async/await with Tokio runtime |
| 212 | +- Event sourcing: Commands → Events → State (never modify state directly) |
| 213 | +- Handlers should be idempotent |
| 214 | +- Use `tracing` crate for instrumentation |
| 215 | +- Examples double as integration tests |
| 216 | + |
| 217 | +### Python (klaudbiusz) |
| 218 | + |
| 219 | +- Use `uv` for package management: `uv run python ...` |
| 220 | +- Type safety is mandatory: run `uv run pyright .` after changes |
| 221 | +- Run `uv run ruff check . --fix` for linting |
| 222 | +- No silent failures: explicit error handling |
| 223 | +- Prefer modern patterns (match over if) |
| 224 | +- Never use lazy imports |
| 225 | + |
| 226 | +### Git Workflow |
| 227 | + |
| 228 | +- Short commit messages (no Claude Code mentions) |
| 229 | +- Use `gh` CLI for GitHub operations |
| 230 | +- Check `.dabgent_state` in klaudbiusz apps before committing |
| 231 | + |
| 232 | +### Testing |
| 233 | + |
| 234 | +**Edda:** |
| 235 | +- In-memory SQLite for fast tests |
| 236 | +- Run examples as integration tests |
| 237 | +- Test event replay and state reconstruction |
| 238 | + |
| 239 | +**Klaudbiusz:** |
| 240 | +- 9 objective metrics (build, runtime, type safety, tests, DB connectivity, data returned, UI renders, runability, deployability) |
| 241 | +- See `eval-docs/evals.md` for metric definitions |
| 242 | + |
| 243 | +## Documentation |
| 244 | + |
| 245 | +- **edda/docs/DESIGN.md** - Complete Edda architecture with diagrams |
| 246 | +- **edda/CLAUDE.md** - Edda-specific development guidance |
| 247 | +- **klaudbiusz/README.md** - Klaudbiusz overview and usage |
| 248 | +- **klaudbiusz/eval-docs/** - Evaluation framework documentation |
0 commit comments