# Code Style and Conventions

## Rust Style Guidelines

### Naming Conventions
- **Structs/Enums/Traits**: PascalCase (`DynamicToolManager`, `McpConfig`)
- **Functions/Methods**: snake_case (`execute_cli`, `get_provider_env`)
- **Constants**: UPPER_SNAKE_CASE (`DEFAULT_MAX_TOOLS_PER_REQUEST`)
- **Modules**: snake_case (`mcp_routing`, `auto_mode`)
- **Files**: snake_case (`cli_manager.rs`, `task_record.rs`)

### Error Handling
- Use `thiserror` for custom error types
- Use `anyhow` for application-level errors
- Always propagate errors with context using `.context()` or `.map_err()`

### Async Code
- Use Tokio runtime (`#[tokio::main]`)
- Use `async-trait` for async traits
- Prefer `.await` over blocking calls

### Documentation
- Use `///` for doc comments on public items
- Include examples in doc comments where appropriate
- Use `#![warn(missing_docs)]` for public APIs

## Project-Specific Conventions

### CLI Commands
- Located in `src/commands/`
- Each command has its own module or file
- Use `clap` derive macros for argument parsing

### MCP Tools
- Tool implementations in `src/mcp/`
- Use `rmcp` macros for tool definitions
- Follow MCP protocol specification

### TUI Components
- Located in `src/tui/`
- Use `ratatui` widgets
- Implement the `Screen` trait for screens

### Configuration
- Config files in `~/.aiw/`
- Use JSON format (`mcp.json`, `config.json`, `providers.json`)
- Config file permissions: 0600 (user read/write only)

### SPEC-Driven Development
- All features must have corresponding SPEC entries
- SPEC files in `SPEC/` directory
- Use REQ-XXX, ARCH-XXX, DATA-XXX, API-XXX naming

## Testing Conventions
- Unit tests in `tests/` directory
- Use `#[test]` attribute for tests
- Use `mockall` for mocking external dependencies
- Use `wiremock` for HTTP mocking
- Use `pretty_assertions` for test output

## Code Quality
- **No TODO/FIXME**: Implement fully or don't implement
- **No unwrap()**: Use proper error handling
- **No panics**: Return Result types
- **Maximum file size**: ~300 lines
- **Maximum function size**: ~50 lines
