TunaCode Root Module (src/tunacode)
Where
Located at the root of the src/tunacode package, serving as the top-level application module.
What
The root module contains foundational elements that support the entire TunaCode CLI application:
constants.py- Global constants, configuration values, UI themes, and magic numbersexceptions.py- Hierarchical exception system with enhanced error reportingpy.typed- Type hint marker for PEP 561 compliance__init__.py- Package initialization
How
The root module follows a centralized foundation pattern:
Constants System (constants.py)
- Numeric Constants: File size limits, timeouts, viewport dimensions
- String Constants: File paths, environment variables, configuration keys
- Enumerations: Tool names for type-safe tool references
- Theme Definitions: Two complete UI themes (default "TunaCode" and "NeXTSTEP")
- Error Messages: Centralized error message templates
- UI Constants: Color palettes, styling directives, message formats
Exception Hierarchy (exceptions.py)
TunaCodeError (base)
├── ConfigurationError
│ └── ModelConfigurationError
├── ValidationError
│ └── SetupValidationError
├── ToolExecutionError
│ ├── TooBroadPatternError
│ └── ToolBatchingJSONError
├── AgentError
├── StateError
├── ServiceError
│ └── GitOperationError
├── FileOperationError
├── UserAbortError
├── GlobalRequestTimeoutError
└── AggregateToolError
Each exception includes:
- Contextual Attributes:
original_error,suggested_fix,troubleshooting_steps - Enhanced Messages: Formatted with emojis and actionable guidance
- Recovery Commands: Suggested shell commands for error resolution
Why
Centralization Strategy: By collocating constants and exceptions at the root level:
- Maintainability: Single source of truth prevents duplication
- Consistency: All modules reference identical error messages and constants
- Type Safety: Enumerations prevent typos in tool names and configuration keys
- Developer Experience: Import errors show clear paths to root module
- Theme Consistency: UI styling is centralized for coherent visual design
Design Principles:
- Fail Fast, Fail Loud: Exceptions carry rich context and recovery guidance
- No Magic Numbers: All numeric constants have descriptive names
- Symbolic Constants: String literals are replaced with named constants
- Modular Enhancement: Exception attributes enable progressive disclosure of error details
Integration Points
- All submodules import from
tunacode.constantsfor configuration values - Tool implementations raise
ToolExecutionErrorfor consistent error handling - Configuration system raises
ConfigurationErrorfor setup issues - UI components use
UI_COLORSand theme builders for visual consistency
Code Quality Notes
- Type Hints: Full type annotation coverage throughout
- Enum Usage:
ToolNameenum prevents string-based tool reference errors - Documentation: Comprehensive docstrings explain constant purposes
- Theme Builders: Lazy import of
textual.themeprevents import cycles