This document describes the architectural specifications for the TeaAgent codebase, including system architecture, component interactions, and design principles.
- Purpose: Main agent orchestration and task execution
- Dependencies: CodeAnalysis, WorkspaceTools, SubagentManager, HookRegistry, MemoryCatalog
- Interface:
ChatAgentConfig,run_chat_agent() - Current State: High coupling to backend systems
- Purpose: Permission management and approval workflow
- Components: ApprovalManager, ApprovalPolicy, ApprovalStore
- Current State: Circular dependencies, God class issue
- Purpose: File operations and shell command execution
- Components: File tools, Shell tools, Git tools
- Security: Safe command parsing, environment filtering
- Knowledge Search: Knowledge backends for context retrieval
- Code Parse: Code analysis backends for structure extraction
- Current State: Global state, no abstraction layer
- Purpose: Consistent error handling across modules
- Components: Error types, error handlers, error recovery
- Current State: Inconsistent patterns across modules
- Purpose: Configuration management and loading
- Components: ConfigLoader, configuration sources
- Current State: Hard-coded configuration keys
- Each component should have a single responsibility
- Components should be loosely coupled
- Dependencies should be explicit, not implicit
- Components should receive dependencies via constructor parameters
- Avoid direct instantiation of dependencies
- Use factories for complex object creation
- Use protocols/interfaces for component contracts
- Implement adapters for external systems
- Standardize interfaces across similar components
- Use specific exception types for different error categories
- Include error context and recovery hints
- Standardize error handling patterns
- Support dynamic configuration key registration
- Allow plugins to add their own configuration
- Use schema validation for configuration
User Input → ChatAgentConfig → run_chat_agent()
↓
CodeAnalysisConfig → LSPServerManager → SubagentManager
↓
WorkspaceToolConfig → ToolRegistry → Tool Execution
↓
HookRegistry → Audit Logging → Result
Tool Call → ApprovalManager → PermissionModeEnforcer
↓
JITApprovalManager → ApprovalStore → MultiSigQuorumManager
↓
ApprovalPolicy → Decision → Allow/Deny
Backend Request → BackendRegistry → BackendAdapter
↓
BackendFactory → Backend Instance → Result
↓
BackendHealthCheck → Health Status → Monitoring
Task → Intent Clarification → Plan Generation
↓
Tool Execution → Approval → Tool Result
↓
Context Update → Memory Catalog → Audit Log
File Request → Path Validation → Symlink Check
↓
Permission Check → File Operation → Atomic Write
↓
Audit Log → Result Return
Error Occurs → ErrorContext Capture → ErrorHandler
↓
Error Classification → Recovery Hint → Logging
↓
Error Propagation → User Notification
- Safe parsing with
shlex.split() - Environment variable allowlist
- Destructive command blocking
- Path traversal prevention
- Symlink validation
- Atomic file operations
- mtime validation
- Secure random generation with
secretsmodule - Strong token hashing with PBKDF2
- Salted hashing for new tokens
- Sensitive data redaction
- Audit trail integrity
- Secure secret storage
- Memory catalog caching for context retrieval
- Knowledge backend caching
- LSP server state caching
- Subagent execution in parallel
- Backend system async calls
- Non-blocking I/O operations
- Connection pooling for backend systems
- Thread pool for signature operations
- Memory limits for large files
- Subagent parallelization
- Backend system clustering
- Distributed audit storage
- Resource limits per run
- Memory limits for large contexts
- Timeout configurations
- Retry logic with exponential backoff
- Graceful degradation on backend failures
- Audit trail for debugging
- Externalized state (audit log, memory catalog)
- State snapshots for resumption
- State validation on load
- Health checks for backend systems
- Metrics for performance monitoring
- Alerting for critical failures
- ADR 0010 through ADR 0018 for detailed refactoring plans
- Component-specific documentation in respective modules
- Architecture decision records in docs/adr/