AI-powered Python code auditor for environmental efficiency
Project description
EcoCode: AI-Powered Python Code Auditor for Energy Efficiency
๐ Mastering the Kiro Platform
This project was built entirely using Kiro's spec-driven development workflow, demonstrating how AI-assisted development can produce high-quality, well-tested software with formal correctness guarantees.
How We Used Kiro
1. Spec-Driven Development
We leveraged Kiro's structured spec workflow to transform a rough idea into a complete implementation:
- Requirements Phase: Generated EARS-compliant requirements with INCOSE quality rules
- Design Phase: Created comprehensive design documents with architecture diagrams, component interfaces, and data models
- Tasks Phase: Broke down the design into incremental, actionable coding tasks
2. Property-Based Testing Integration
Kiro guided us through formal correctness properties:
- 14 Correctness Properties defined in the design document
- 21 Property-Based Tests using Hypothesis library
- Each property validates specific requirements traceability
3. Iterative Implementation
Using Kiro's task execution workflow:
- Tasks were implemented incrementally with checkpoints
- Each component was tested before integration
- Property tests caught edge cases that unit tests would miss
Project Structure
.kiro/
โโโ hooks/
โ โโโ ecocode-green-audit.kiro.hook # Auto-audit on file save
โโโ steering/
โ โโโ green-coding.md # Green coding best practices
โโโ specs/
โ โโโ ecocode/
โ โโโ requirements.md # EARS-compliant requirements
โ โโโ design.md # Architecture & correctness properties
โ โโโ tasks.md # Implementation checklist (all โ
)
src/
โโโ ecocode/
โโโ analysis.py # Pattern detection (AST-based)
โโโ auditor.py # Main orchestration
โโโ models.py # Data models
โโโ refactoring.py # Refactor plan generation
โโโ reporter.py # JSON/Console output
โโโ scoring.py # Green Score calculation
โโโ watcher.py # File monitoring
tests/
โโโ property/ # Property-based tests (Hypothesis)
โโโ unit/ # Unit tests
โโโ fixtures/ # Sample code for testing
Key Features Demonstrated
| Feature | Kiro Capability Used |
|---|---|
| Pattern Detection | Spec-driven design with AST analysis |
| Green Score | Property-based testing for score invariants |
| Refactoring Plans | Requirements traceability in tasks |
| JSON Serialization | Round-trip property testing |
| CLI Interface | Incremental task implementation |
๐ค Kiro Agent Integration
EcoCode is designed to be an agentic extension of the Kiro IDE:
-
Agent Hooks: Includes a pre-configured
on_file_savehook in the.kiro/hooks/folder. This triggers an automated audit every time a developer saves a Python file, delivering results directly to the Kiro Agent. -
MCP Integration: The Kiro Agent can utilize MCP servers when interpreting EcoCode's JSON reports. This allows the AI to provide real-world carbon and cost savings estimates during the refactoring conversation.
-
Steering Files: Custom steering rules in
.kiro/steering/guide the agent to prioritize energy efficiency suggestions and follow green coding best practices.
Running the Project
# Install dependencies
pip install -e .
# Analyze a Python file
python -m ecocode --analyze your_file.py
# Output as JSON
python -m ecocode --analyze your_file.py --json
# Run all tests (21 property-based tests)
python -m pytest tests/ -v
Correctness Properties Validated
- Python File Filtering - Only .py files trigger analysis
- Issue Structure Completeness - All issues have required fields
- Green Score Range Invariant - Score always in [0, 100]
- Perfect Score for Clean Code - Empty issues gives 100
- Score Determinism - Same issues produce same score
- Severity Impact Ordering - Higher severity = higher penalty
- Score Breakdown Consistency - Penalties + score = 100
- RefactorPlan Completeness - All plans have required fields
- RefactorPlan Priority Ordering - Plans sorted by priority
- JSON Round-Trip Consistency - Serialize/deserialize preserves data
- Nested Loop Detection - Nested array loops are detected
- Redundant Computation Detection - Loop-invariant code detected
- Model Loading in Loop Detection - ML model loads in loops detected
- One RefactorPlan Per Issue - Plan count equals issue count
What Makes This Special
- 100% Test Pass Rate: All 21 property-based tests pass
- Formal Correctness: Properties derived from EARS requirements
- Full Traceability: Every test maps to specific requirements
- Clean Architecture: Modular design following spec-driven patterns
Built with Kiro - Where AI meets formal software engineering
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ecocode-0.1.0.tar.gz.
File metadata
- Download URL: ecocode-0.1.0.tar.gz
- Upload date:
- Size: 28.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0094e05e0a13c8ff08e20d96de9a5569da7dd19dbac8d189ab7ed27fa5fe9652
|
|
| MD5 |
d53a322e6a1912273570f2051c443f20
|
|
| BLAKE2b-256 |
9e6d76a0d9bf433d40eba5188fb2136c256bcf42b68e7beecdeab55bd245764f
|
File details
Details for the file ecocode-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ecocode-0.1.0-py3-none-any.whl
- Upload date:
- Size: 29.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0de16820058076c6b96349d4033be9949bb225184ece0321d74703171f362b84
|
|
| MD5 |
bd0cbd9b7a121ff0025413bab4ceda36
|
|
| BLAKE2b-256 |
bffac8e162ad58a46f88b262eafa9e9e1ecf53f07c59ce4301d05007014d7cb8
|