317 lines
8.5 KiB
Markdown
317 lines
8.5 KiB
Markdown
# Config Auditor CLI
|
|
|
|
A powerful CLI tool that scans project configuration files, detects issues and vulnerabilities, suggests intelligent fixes using local LLMs, and can automatically fix common problems. Supports `package.json`, `tsconfig.json`, `.eslintrc`, `pyproject.toml`, and other common config formats.
|
|
|
|

|
|

|
|

|
|
|
|
## Features
|
|
|
|
- **Config File Discovery** - Automatically discover and collect configuration files in project directories
|
|
- **Multi-format Parser** - Parse JSON, YAML, TOML configuration files with ease
|
|
- **Issue Detection Engine** - Analyze configs for common issues like outdated dependencies, security vulnerabilities, and incorrect settings
|
|
- **Auto-fix Capability** - Automatically fix common configuration problems with backup support
|
|
- **Local LLM Integration** - Integrate with local LLMs (Ollama) for intelligent recommendations with explanations
|
|
- **Optimal Config Generation** - Generate optimized configurations based on project patterns
|
|
- **Report Generation** - Generate detailed audit reports in JSON, YAML, or pretty-printed text formats
|
|
|
|
## Installation
|
|
|
|
### From Source
|
|
|
|
```bash
|
|
pip install -e .
|
|
```
|
|
|
|
### Dependencies
|
|
|
|
- Python 3.9+
|
|
- Click 8.1.7+
|
|
- PyYAML 6.0.1+
|
|
- toml 0.10.2+
|
|
- requests 2.31.0+
|
|
- semver 3.0.2+
|
|
- packaging 23.2+
|
|
- ollama 0.1.41+ (optional, for LLM features)
|
|
|
|
## Quick Start
|
|
|
|
```bash
|
|
# Scan a directory for configuration files
|
|
config-auditor scan /path/to/project
|
|
|
|
# Audit configuration files for issues
|
|
config-auditor audit /path/to/project
|
|
|
|
# Automatically fix detected issues
|
|
config-auditor fix /path/to/project
|
|
|
|
# Generate optimal configurations
|
|
config-auditor generate --template node /path/to/project
|
|
```
|
|
|
|
## Commands
|
|
|
|
### scan
|
|
|
|
Scan a directory for configuration files.
|
|
|
|
```bash
|
|
config-auditor scan [OPTIONS] [PATH]
|
|
|
|
Options:
|
|
-p, --path PATH Path to scan (default: current directory)
|
|
-f, --format FORMAT Output format: json, yaml, text (default: text)
|
|
-v, --verbose Enable verbose output
|
|
```
|
|
|
|
**Example:**
|
|
|
|
```bash
|
|
config-auditor scan /my/project -v
|
|
# Found 5 configuration files
|
|
# Found: /my/project/package.json (json)
|
|
# Found: /my/project/tsconfig.json (json)
|
|
# Found: /my/project/.eslintrc.json (json)
|
|
# Found: /my/project/pyproject.toml (toml)
|
|
# Found: /my/project/.prettierrc (json)
|
|
```
|
|
|
|
### audit
|
|
|
|
Audit configuration files for issues and vulnerabilities.
|
|
|
|
```bash
|
|
config-auditor audit [OPTIONS] [PATH]
|
|
|
|
Options:
|
|
-p, --path PATH Path to scan (default: current directory)
|
|
-f, --format FORMAT Output format: json, yaml, text (default: text)
|
|
-v, --verbose Enable verbose output
|
|
```
|
|
|
|
**Example:**
|
|
|
|
```bash
|
|
config-auditor audit /my/project --format json
|
|
# Returns detailed JSON report with all issues found
|
|
```
|
|
|
|
### fix
|
|
|
|
Automatically fix detected issues.
|
|
|
|
```bash
|
|
config-auditor fix [OPTIONS] [PATH]
|
|
|
|
Options:
|
|
-p, --path PATH Path to scan (default: current directory)
|
|
--dry-run Preview changes without applying them
|
|
--force Skip confirmation
|
|
-v, --verbose Enable verbose output
|
|
```
|
|
|
|
**Example:**
|
|
|
|
```bash
|
|
# Preview fixes without applying
|
|
config-auditor fix /my/project --dry-run
|
|
|
|
# Apply fixes automatically
|
|
config-auditor fix /my/project --force
|
|
```
|
|
|
|
### generate
|
|
|
|
Generate optimal configurations based on project type.
|
|
|
|
```bash
|
|
config-auditor generate [OPTIONS] [PATH]
|
|
|
|
Options:
|
|
-p, --path PATH Path to scan (default: current directory)
|
|
-t, --template TYPE Template type: node, python, typescript
|
|
-f, --format FORMAT Output format: json, yaml, text (default: json)
|
|
```
|
|
|
|
**Example:**
|
|
|
|
```bash
|
|
# Auto-detect project type and generate config
|
|
config-auditor generate /my/project
|
|
|
|
# Generate Node.js config
|
|
config-auditor generate /my/project --template node
|
|
|
|
# Generate Python config
|
|
config-auditor generate /my/project --template python
|
|
```
|
|
|
|
### config
|
|
|
|
Show current configuration.
|
|
|
|
```bash
|
|
config-auditor config
|
|
```
|
|
|
|
## Supported Configuration Formats
|
|
|
|
| Format | Extensions | Parser |
|
|
|--------|------------|--------|
|
|
| JSON | `.json` | stdlib json |
|
|
| YAML | `.yaml`, `.yml` | PyYAML |
|
|
| TOML | `.toml` | toml library |
|
|
|
|
### Supported Configuration Files
|
|
|
|
- `package.json` - Node.js package configuration
|
|
- `tsconfig.json` - TypeScript configuration
|
|
- `.eslintrc.json`, `.eslintrc.js`, `.eslintrc.yaml` - ESLint configuration
|
|
- `.prettierrc`, `.prettierrc.json`, `.prettierrc.yaml` - Prettier configuration
|
|
- `pyproject.toml` - Python project configuration
|
|
- `setup.py`, `setup.cfg` - Python setup configuration
|
|
- `.babelrc`, `babel.config.js` - Babel configuration
|
|
- `next.config.js`, `next.config.mjs` - Next.js configuration
|
|
- And many more...
|
|
|
|
## Exit Codes
|
|
|
|
| Code | Description |
|
|
|------|-------------|
|
|
| 0 | Success - no issues found |
|
|
| 1 | General error |
|
|
| 2 | Configuration error |
|
|
| 3 | No config files found |
|
|
| 4 | Issues detected but not fixed |
|
|
| 5 | Fixes applied successfully |
|
|
| 6 | LLM unavailable |
|
|
|
|
## Configuration
|
|
|
|
Create a `config.yaml` file in your project root to customize behavior:
|
|
|
|
```yaml
|
|
llm:
|
|
endpoint: "http://localhost:11434" # Ollama endpoint
|
|
model: "llama3" # Model name
|
|
temperature: 0.7 # Sampling temperature
|
|
timeout: 30 # Request timeout in seconds
|
|
|
|
audit:
|
|
max_depth: 3 # Directory scan depth
|
|
severity_levels:
|
|
- critical
|
|
- warning
|
|
- info
|
|
|
|
fix:
|
|
create_backup: true # Create backups before fixing
|
|
backup_dir: ".config_auditor_backup" # Backup directory
|
|
dry_run_default: false # Default dry-run mode
|
|
```
|
|
|
|
## LLM Integration
|
|
|
|
Config Auditor can use local LLMs (via Ollama) for intelligent recommendations:
|
|
|
|
```bash
|
|
# Ensure Ollama is running
|
|
ollama serve
|
|
|
|
# Install a model
|
|
ollama pull llama3
|
|
|
|
# Run audit with LLM recommendations
|
|
config-auditor audit /my/project
|
|
```
|
|
|
|
The LLM provides:
|
|
- Context-aware explanations for detected issues
|
|
- Suggestions for optimal configuration values
|
|
- Best practices recommendations for your specific project type
|
|
|
|
## Development
|
|
|
|
### Setup
|
|
|
|
```bash
|
|
# Clone the repository
|
|
git clone https://7000pct.gitea.bloupla.net/7000pctAUTO/config-auditor-cli.git
|
|
cd config-auditor-cli
|
|
|
|
# Create virtual environment
|
|
python -m venv venv
|
|
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
|
|
# Install dependencies
|
|
pip install -e ".[dev]"
|
|
|
|
# Run tests
|
|
pytest tests/ -v --cov=config_auditor
|
|
|
|
# Run linting
|
|
ruff check config_auditor/ tests/
|
|
```
|
|
|
|
### Project Structure
|
|
|
|
```
|
|
config-auditor-cli/
|
|
├── config_auditor/
|
|
│ ├── __init__.py # Package marker
|
|
│ ├── cli.py # CLI commands and entry point
|
|
│ ├── discovery.py # Config file discovery engine
|
|
│ ├── parsers.py # Format-specific parsers
|
|
│ ├── rules.py # Issue detection rules
|
|
│ ├── fixes.py # Auto-fix functionality
|
|
│ ├── llm.py # Local LLM integration
|
|
│ ├── generate.py # Config generation
|
|
│ ├── report.py # Report generation
|
|
│ └── utils.py # Utility functions
|
|
├── tests/
|
|
│ ├── conftest.py # Test fixtures
|
|
│ ├── test_cli.py # CLI tests
|
|
│ ├── test_parsers.py # Parser tests
|
|
│ ├── test_rules.py # Rule tests
|
|
│ ├── test_fixes.py # Fixer tests
|
|
│ ├── test_llm.py # LLM client tests
|
|
│ ├── test_generate.py # Generator tests
|
|
│ ├── test_report.py # Report tests
|
|
│ └── test_utils.py # Utility tests
|
|
├── config_auditor.py # Entry point
|
|
├── requirements.txt # Dependencies
|
|
├── setup.py # Package setup
|
|
├── config.yaml # Default configuration
|
|
└── README.md # This file
|
|
```
|
|
|
|
### Running Tests
|
|
|
|
```bash
|
|
# Run all tests
|
|
pytest tests/ -v
|
|
|
|
# Run with coverage
|
|
pytest tests/ -v --cov=config_auditor --cov-report=term-missing
|
|
|
|
# Run specific test file
|
|
pytest tests/test_cli.py -v
|
|
```
|
|
|
|
## Contributing
|
|
|
|
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
|
|
## License
|
|
|
|
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
|
|
## Acknowledgments
|
|
|
|
- [Click](https://click.palletsprojects.com/) - CLI framework
|
|
- [Ollama](https://ollama.com/) - Local LLM runtime
|
|
- [PyYAML](https://pyyaml.org/) - YAML parsing
|
|
- [toml](https://github.com/uiri/toml) - TOML parsing
|