feat(#154): Implement context estimator
Implements formula-based context estimation for predicting token usage before issue assignment. Formula: base = (files × 7000) + complexity + tests + docs total = base × 1.3 (30% safety buffer) Features: - EstimationInput/Result data models with validation - ComplexityLevel, TestLevel, DocLevel enums - Agent recommendation (haiku/sonnet/opus) based on tokens - Validation against actual usage with tolerance checking - Convenience function for quick estimations - JSON serialization support Implementation: - issue_estimator.py: Core estimator with formula - models.py: Data models and enums (100% coverage) - test_issue_estimator.py: 35 tests, 100% coverage - ESTIMATOR.md: Complete API documentation - requirements.txt: Python dependencies - .coveragerc: Coverage configuration Test Results: - 35 tests passing - 100% code coverage (excluding __main__) - Validates against historical issues - All edge cases covered Acceptance Criteria Met: ✅ Context estimation formula implemented ✅ Validation suite tests against historical issues ✅ Formula includes all components (files, complexity, tests, docs, buffer) ✅ Unit tests for estimator (100% coverage, exceeds 85% requirement) ✅ All components tested (low/medium/high levels) ✅ Agent recommendation logic validated Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,59 @@ The coordinator system automates issue assignment, tracking, and orchestration a
|
||||
|
||||
## Scripts
|
||||
|
||||
### create-gitea-bot.sh
|
||||
### Python Modules
|
||||
|
||||
#### issue_estimator.py
|
||||
|
||||
Formula-based context estimator for predicting token usage before issue assignment.
|
||||
|
||||
**Prerequisites:**
|
||||
|
||||
- Python 3.8+
|
||||
- Virtual environment with dependencies (see Installation below)
|
||||
|
||||
**Usage:**
|
||||
|
||||
```bash
|
||||
# Create virtual environment
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate # Windows: venv\Scripts\activate
|
||||
|
||||
# Install dependencies
|
||||
pip install -r requirements.txt
|
||||
|
||||
# Run examples
|
||||
python issue_estimator.py
|
||||
|
||||
# Run tests
|
||||
pytest test_issue_estimator.py -v
|
||||
|
||||
# Run with coverage
|
||||
pytest test_issue_estimator.py --cov=issue_estimator --cov=models --cov-report=term-missing
|
||||
```
|
||||
|
||||
**Python API:**
|
||||
|
||||
```python
|
||||
from issue_estimator import estimate_issue
|
||||
|
||||
# Quick estimation
|
||||
result = estimate_issue(
|
||||
files=2,
|
||||
complexity="medium",
|
||||
tests="medium",
|
||||
docs="light"
|
||||
)
|
||||
|
||||
print(f"Total estimate: {result.total_estimate:,} tokens")
|
||||
print(f"Recommended agent: {result.recommended_agent}")
|
||||
```
|
||||
|
||||
**Documentation:** See [ESTIMATOR.md](ESTIMATOR.md) for complete API reference and examples.
|
||||
|
||||
### Bash Scripts
|
||||
|
||||
#### create-gitea-bot.sh
|
||||
|
||||
Creates the `mosaic` bot user in Gitea for coordinator automation.
|
||||
|
||||
@@ -79,6 +131,37 @@ export TEST_ISSUE="156"
|
||||
**Output:**
|
||||
Success/failure for each test with detailed error messages.
|
||||
|
||||
## Installation
|
||||
|
||||
### Python Environment
|
||||
|
||||
For the context estimator and Python-based coordinator components:
|
||||
|
||||
```bash
|
||||
# Navigate to coordinator directory
|
||||
cd scripts/coordinator
|
||||
|
||||
# Create virtual environment
|
||||
python3 -m venv venv
|
||||
|
||||
# Activate virtual environment
|
||||
source venv/bin/activate # Windows: venv\Scripts\activate
|
||||
|
||||
# Install dependencies
|
||||
pip install -r requirements.txt
|
||||
|
||||
# Verify installation
|
||||
pytest test_issue_estimator.py -v
|
||||
```
|
||||
|
||||
### Bash Scripts
|
||||
|
||||
No installation needed for bash scripts. Just ensure they're executable:
|
||||
|
||||
```bash
|
||||
chmod +x scripts/coordinator/*.sh
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
### Environment Variables
|
||||
@@ -258,9 +341,24 @@ For complete documentation on the coordinator bot:
|
||||
- [Issue #156 - Create coordinator bot user](https://git.mosaicstack.dev/mosaic/stack/issues/156)
|
||||
- [Coordinator Architecture](../../docs/3-architecture/non-ai-coordinator-comprehensive.md)
|
||||
|
||||
## Files
|
||||
|
||||
| File | Purpose |
|
||||
| ------------------------- | ------------------------------------ |
|
||||
| `issue_estimator.py` | Context estimator implementation |
|
||||
| `models.py` | Data models and enums for estimator |
|
||||
| `test_issue_estimator.py` | Test suite (35 tests, 100% coverage) |
|
||||
| `ESTIMATOR.md` | Complete estimator documentation |
|
||||
| `requirements.txt` | Python dependencies |
|
||||
| `.coveragerc` | Coverage configuration |
|
||||
| `create-gitea-bot.sh` | Bot user creation script |
|
||||
| `test-gitea-bot.sh` | Bot functionality tests |
|
||||
| `README.md` | This file |
|
||||
|
||||
## Related Issues
|
||||
|
||||
- #156 - Create coordinator bot user in Gitea
|
||||
- #154 - Implement context estimator ✅ **COMPLETED**
|
||||
- #156 - Create coordinator bot user in Gitea ✅ **COMPLETED**
|
||||
- #157 - Configure coordinator webhook in Gitea
|
||||
- #158 - Implement coordinator task assignment engine
|
||||
- #140 - Coordinator integration architecture
|
||||
|
||||
Reference in New Issue
Block a user