EcoLint
#codecarbon
The problem EcoLint solves
EcoLint ๐
AI-Powered FinOps Optimizer, Security Scanner, & VS Code Extension
EcoLint is a comprehensive suite of tools designed to drastically reduce the computational footprint of your code. By acting as an advanced FinOps engine, it intelligently analyzes your source code to optimize performance (speed, RAM, CPU cycles), calculate carbon and cost savings, and apply automated cybersecurity patches.
The EcoLint project is divided into two primary interfaces:
- The VS Code Extension (
/ecolint&/backend) - The Terminal CLI Tool (
/ecolint-cli)
๐ป 1. EcoLint for VS Code
The EcoLint VS Code extension brings our AI-powered code analysis, benchmarking, and optimization directly into your IDE. It communicates with a dedicated backend language server to provide real-time suggestions and automated refactoring.
โจ Extension Features
- Analyze (
ecolint.analyze): Analyzes the current code for performance bottlenecks and structural issues. - Benchmark (
ecolint.benchmark): Runs simulated performance benchmarks on the active file. - Optimize (
ecolint.optimize): Automatically optimizes the selected code inline. - Generate Pull Request (
ecolint.generatePullRequest): Generates a summary PR containing the analysis results and optimization justifications. - Interactive UI: Integrates directly into the VS Code Activity Bar with dedicated views for Analysis Results, Benchmarks, and Optimizations.
๐ ๏ธ Extension Setup
The VS Code extension requires the backend server to be running:
- Start the Backend:
cd EcoLint/backend npm install npm run start # (or equivalent dev script) - Install the Extension:
cd EcoLint/ecolint npm install # Press F5 in VS Code to launch the Extension Development Host
(Note: Ensure ecolint.apiEndpoint in your VS Code settings points to your running backend).
๐ 2. EcoLint CLI
The EcoLint CLI is a lightweight, terminal-based alternative for fast, pipeline-friendly optimizations.
โจ CLI Features
- ๐ง Multi-Mode AI Optimization:
- Maximum Performance: Strips formatting and readability to compress variables and maximize raw computational speed. (C/C++ Aware: Replaces heavy includes with lightweight forward declarations).
- Balanced Production: Achieves high performance while adhering strictly to clean architectural principles.
- Educational Mode: Provides a JSON-formatted technical breakdown explaining the complexity shifts (e.g., $O(N^2) \rightarrow O(N)$).
- ๐ Intelligent Security Scanner (SOLID Design): Scans entire files for severe vulnerabilities (SQL Injections, XSS) and offers 1-click automated security patches.
- ๐ Eco Metrics Telemetry: Simulates the real-world impact of your code optimizations (Latency, RAM, Carbon Reduction, Cost Savings).
- ๐ฌ Dynamic Custom Directives: Override the engine with natural language rules (e.g., "Do not remove comments").
๐ ๏ธ CLI Setup & Usage
- Installation:
cd EcoLint/ecolint-cli npm install - Configuration: Add your AI provider API Key to
ecolint-cli/.env:NVIDIA_API_KEY=your_api_key_here - Usage:
npm run build # Optimize and secure a specific file npm start -- --file ../test.c # Optimize a specific line range npm start -- --file ../test.c --lines 10-25
๐ Documentation
For more in-depth architectural details, API documentation, and contribution guidelines, please refer to the /docs directory.
๐งช Testing the Pipeline
You can test the core AI engine using the provided test files at the root of the repository:
vulnerable_test.py: ContainsO(N^2)loops and glaring security flaws (Hardcoded Secrets & SQL Injection). Tests both the FinOps optimizer and the Security Scanner.test.c: Contains standard C code. Tests the C/C++ specific include optimizations.
Challenges we ran into
Here are the major technical problems and roadblocks we encountered (and successfully solved!) while building the EcoLint project:
- The AST web-tree-sitter Module Crash
The Problem: When we first tried to implement Abstract Syntax Tree (AST) parsing to deeply analyze code structure, we hit a hard crash: SyntaxError: The requested module 'web-tree-sitter' does not provide an export named 'default'.
The Solution: This happened because our project uses modern ESM (ECMAScript Modules, type: "module"), but the library was built for older CommonJS environments. Since it blocked the build, we pivoted, ripped out the AST logic, and shifted our focus entirely to LLM-based parsing and optimization instead. - The AI Ignoring the "Don't Remove Comments" Rule
The Problem: You passed a custom directive saying "don't remove comments", but the AI kept deleting them anyway.
The Solution: The underlying Maximum Performance system prompt was so aggressive ("Ignore code readability, documentation... at all costs") that it overpowered your custom instruction. We solved this by wrapping your custom instructions in a CRITICAL USER DIRECTIVE block, explicitly telling the AI that your instructions strictly override its default system behavior. - DeepSeek Minifying and Squashing Code
The Problem: When you switched to the DeepSeek AI model and ran it on test.c, it output the code as a giant, unreadable block of text squashed onto a single line.
The Solution: The AI took our instruction to "optimize for token constraints at all costs" far too literally and deleted all spaces and line breaks to save tokens. I updated the system prompt to explicitly command it: "CRITICAL: You must preserve standard code formatting, indentation, and line breaks. Do not minify or squash the code." - Git Submodule & Push Failures
The Problem: When you tried to push the code to GitHub, Git threw warnings about an "embedded git repository" and later failed with fatal: 'ecolint_cli' does not appear to be a git repository.
The Solution: Because ecolint-cli had its own hidden .git folder inside it, Git treated it as a detached submodule, meaning it wasn't actually saving your files to the main EcoLint repo. We solved this by deleting the inner .git folder, clearing the cache, and re-adding it so the main repository could properly track all your code. - Architectural Bloat (SOLID Principles)
The Problem: When you asked to add a full-file Security Vulnerability Scanner on top of the FinOps optimizer, the main AI engine and orchestration file were at risk of becoming a massive, unmaintainable "spaghetti" script.
The Solution: We applied SOLID principles (specifically the Single Responsibility Principle) by entirely separating the cybersecurity logic into a brand new securityController.ts. This kept the optimization engine fast and clean, while allowing the security scanner to run as an independent layer just before saving the file.
Technologies used