Goal
Remove the direct dependency on pydantic-ai from src/tunacode/tools/.
Tools should raise domain-specific exceptions, not framework-specific exceptions.
Strategy
- Define Protocol: Create
ToolRetryErrorinsrc/tunacode/exceptions.py. - Adapter Layer: Update
src/tunacode/tools/decorators.pyto catchToolRetryErrorand re-raisepydantic_ai.ModelRetry. - Refactor Tools: Update all tools to raise
ToolRetryErrorinstead ofModelRetry.
Steps (Executed 2026-01-28)
Step 1: Define Exception
- Added
ToolRetryErrortosrc/tunacode/exceptions.py.
Step 2: Update Decorator
- Modified
src/tunacode/tools/decorators.pyto catchToolRetryErrorand re-raiseModelRetry. - This acts as the translation layer between our internal tool protocol and the Pydantic-AI framework.
Step 3: Migrate Tools
- Replaced
ModelRetrywithToolRetryErrorin:tools/bash.pytools/glob.pytools/grep.pytools/list_dir.pytools/update_file.pytools/web_fetch.pytools/write_file.py
Verification
grep -r "pydantic_ai" src/tunacode/tools/ returns only decorators.py.
Dependencies are now correctly directed: tools -> exceptions <- decorator -> pydantic-ai.