Observed since 21 Oct, 10:50 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Secure AI-assisted code refactoring with policy controls for 39+ programming languages
A universal CLI tool for secure AI-assisted code refactoring across 39+ programming languages with comprehensive security controls and audit logging.
This tool showcases how to safely integrate AI-powered code refactoring into development workflows by:
**/payment*, **/.env*, **/secrets/**The tool supports 39+ programming languages out of the box:
| Category | Languages |
|---|---|
| Web Development | JavaScript, TypeScript, HTML, CSS, SCSS, PHP |
| Systems Programming | C, C++, Rust, Go |
| JVM Languages | Java, Kotlin, Scala, Groovy |
| Scripting | Python, Ruby, Perl, Shell (Bash/Zsh/Fish), Lua |
| Functional | Haskell, OCaml, F#, Elixir, Erlang, Clojure |
| Mobile | Swift, Kotlin, Dart |
| Data & Config | SQL, YAML, JSON, XML, Markdown, Terraform |
| Other | R, MATLAB, PowerShell, Vim Script, Dockerfile, Makefile |
# List all supported languages
ai-governance bulk-refactor . --list-languages
# Refactor specific language(s)
ai-governance bulk-refactor src/ --lang python --target "add type hints"
ai-governance bulk-refactor src/ --lang java --lang kotlin --target "modernize"
# Refactor specific extensions
ai-governance bulk-refactor . --ext "js,jsx,ts,tsx" --target "convert to React hooks"
Java Spring Boot Project:
ai-governance bulk-refactor src/main/java --lang java --target "add comprehensive javadoc comments"
JavaScript/TypeScript React App:
ai-governance bulk-refactor src/components --lang typescript --target "convert class components to functional"
Go Microservice:
ai-governance bulk-refactor . --lang go --target "improve error handling and add context"
Multi-Language Monorepo:
ai-governance bulk-refactor backend/ --lang python --lang java --target "add logging"
Install globally using pipx for system-wide access:
# Install pipx if you don't have it
pip install pipx
pipx ensurepath
# Install ai-governance-tool from PyPI
pipx install ai-governance-tool
Now ai-governance is available from any directory, any project!
Note: The PyPI package is
ai-governance-toolbut the CLI command isai-governance.
pip install ai-governance-tool
git clone https://github.com/aunabdi93/ai-governance-tool
cd ai-governance-tool
pip install -e .
The tool will guide you through setup interactively. You have two options:
Option 1: Run init command (Recommended)
ai-governance init
This will:
Option 2: Just start using it
Simply run your first refactor command:
ai-governance refactor myfile.py --target "modernize code"
The tool will detect the missing API key and walk you through setup interactively!
Security-First Approach:
For maximum security, the tool does NOT save your API key to disk. You'll be prompted to enter it when starting each session (input is hidden).
If you prefer convenience over security, you can set an environment variable:
# Add to your shell profile (~/.zshrc, ~/.bashrc, etc.)
export ANTHROPIC_API_KEY='your_api_key_here'
This way, the key is managed by your system (not by the tool), and you won't be prompted each time.
Once installed with pipx, you can use ai-governance from any directory, with any project, in any language:
# Python project
cd ~/my-python-project
ai-governance refactor legacy.py --target "add type hints and modernize to Python 3.10+"
# Java Spring Boot project
cd ~/my-java-app
ai-governance bulk-refactor src/main/java --lang java --target "add comprehensive javadoc"
# JavaScript/TypeScript React project
cd ~/my-react-app
ai-governance refactor src/App.tsx --target "convert to functional components with hooks"
# Go microservice
cd ~/my-go-service
ai-governance bulk-refactor . --lang go --target "improve error handling with context"
# Rust project
cd ~/my-rust-project
ai-governance refactor src/main.rs --target "add better error handling and documentation"
The tool works seamlessly across all programming languages!
ai-governance refactor <filepath> --target "<description>"
Example:
ai-governance refactor demo/legacy_code/utils.py --target "modernize to Python 3.10+ with type hints"
First-time users: If you haven't configured an API key, the tool will:
Security Note: Your API key is NOT saved to disk. You'll be prompted again in the next session.
ai-governance bulk-refactor <paths...> --target "<description>" [options]
Examples:
# Refactor entire directory (all supported languages)
ai-governance bulk-refactor src/ --target "add comprehensive documentation"
# Refactor specific language
ai-governance bulk-refactor src/ --lang python --target "add type hints"
# Refactor multiple languages
ai-governance bulk-refactor . --lang java --lang kotlin --target "modernize code"
# Refactor specific file extensions
ai-governance bulk-refactor backend/ --ext "py,pyi" --target "update to Python 3.12"
# Refactor files matching a pattern
ai-governance bulk-refactor tests/ --pattern "test_*.py" --target "use pytest fixtures"
# Mix files and directories
ai-governance bulk-refactor src/api/ lib/utils.js main.py --target "improve error handling"
# Dry run to preview what would be refactored
ai-governance bulk-refactor src/ --lang typescript --target "..." --dry-run
# Auto-apply without confirmation (use with caution)
ai-governance bulk-refactor src/ --lang go --target "..." --apply
Multi-Language Project Examples:
# Java Spring Boot - refactor all service classes
ai-governance bulk-refactor src/main/java/com/company/services \
--lang java \
--target "add comprehensive javadoc and improve exception handling"
# React TypeScript - convert class components to functional
ai-governance bulk-refactor src/components \
--lang typescript \
--pattern "*.tsx" \
--target "convert class components to functional components with hooks"
# Go microservice - improve error handling
ai-governance bulk-refactor cmd/ internal/ \
--lang go \
--target "add context to errors and improve logging"
# Python data science - modernize notebooks
ai-governance bulk-refactor notebooks/ \
--lang python \
--pattern "*.py" \
--target "add type hints and use modern pandas methods"
ai-governance audit
ai-governance audit --status blocked
ai-governance audit --stats
ai-governance dashboard
ai-governance dashboard --port 8080
ai-governance dashboard --host 0.0.0.0 --port 3000
The web dashboard provides:
See AUDIT_DASHBOARD.md for complete dashboard documentation.
ai-governance init
This command lets you:
refactor command:--target, -t: Description of desired refactoring (required)--policy, -p: Path to custom policy YAML file--no-backup: Skip creating backup files--dry-run: Scan only, don't refactor--apply: Automatically apply changes without confirmationbulk-refactor command:--target, -t: Description of desired refactoring (required)--policy, -p: Path to custom policy YAML file--lang, --language: Filter by programming language (can specify multiple times)--ext, --extensions: Comma-separated file extensions (e.g., "py,js,ts")--pattern: Glob pattern to match files (e.g., "test_*.py")--recursive/--no-recursive: Search directories recursively (default: enabled)--no-backup: Skip creating backup files--dry-run: Scan only, don't refactor--apply: Automatically apply changes without confirmation--list-languages: Show all supported languages and exitaudit command:--limit, -l: Number of recent logs to show (default: 50)--status, -s: Filter by status (allowed/blocked/error/success)--stats: Show statistics onlyinit command:--project: Initialize project-level configuration (.ai-governance/policy.yaml)--user: Initialize user-level configuration (~/.config/ai-governance/policy.yaml)--template: Specify template to use (default-secure, permissive, strict)--force: Overwrite existing configuration fileconfig command:sessions command (for codebase-refactor):--list: Show all refactoring sessions with status--show SESSION_ID: Display details of a specific session--cleanup: Remove completed session checkpointsTry the tool immediately with any of your projects:
# Python - Add type hints
ai-governance refactor app.py --target "add comprehensive type hints"
# Java - Add javadoc
ai-governance refactor UserService.java --target "add javadoc to all public methods"
# JavaScript - Modernize
ai-governance refactor legacy.js --target "convert to ES6+ with async/await"
# TypeScript - Improve types
ai-governance refactor api.ts --target "use strict TypeScript types"
# Go - Add error handling
ai-governance refactor handler.go --target "improve error handling with wrapped errors"
# Rust - Add documentation
ai-governance refactor main.rs --target "add comprehensive documentation comments"
The demo/legacy_code/ directory contains example files demonstrating the tool's security controls:
user_service.py - Contains:
sk_live_51HxKj2eZvKYlo2C9x8rT3mN4pQ7wX6vU5yR8sA1bZsupersecretpassword123email_handler.py - Contains:
emailpass456payment_processor.py - Contains:
4532-1234-5678-9010**/payment* pattern)utils.py - Clean utility functions:
helper_functions.py - Clean helper functions:
Try refactoring the demo files to see the security controls in action:
# This will be BLOCKED - contains API key and password
ai-governance refactor demo/legacy_code/user_service.py --target "refactor to FastAPI async patterns"
# This will be BLOCKED - contains email password
ai-governance refactor demo/legacy_code/email_handler.py --target "modernize email handling"
# This will be BLOCKED - contains credit card data and matches payment* pattern
ai-governance refactor demo/legacy_code/payment_processor.py --target "update to use Stripe SDK"
# This will be ALLOWED - clean code, no sensitive data
ai-governance refactor demo/legacy_code/utils.py --target "modernize to Python 3.10+"
# This will be ALLOWED - clean code, no sensitive data
ai-governance refactor demo/legacy_code/helper_functions.py --target "use modern Python idioms"
# View audit logs to see what was blocked and why
ai-governance audit
ai-governance audit --status blocked
ai-governance audit --stats
Run the automated demo to see all features:
python demo.py
Or use the shell script:
bash demo.sh
Quick Start: See QUICKSTART_CONFIG.md for a 5-minute setup guide with examples!
The tool uses a flexible configuration hierarchy that allows project-specific security policies:
Configuration Priority (highest to lowest):
--policy custom.yaml) - Overrides all.ai-governance/policy.yaml) - Project-specific rules~/.config/ai-governance/policy.yaml) - Personal defaultsdefault-secure.yaml) - FallbackInitialize project-specific configuration:
# Create project config with default-secure template
ai-governance init --project
# Use permissive template for development
ai-governance init --project --template permissive
# Use strict template for production
ai-governance init --project --template strict
Initialize user-level configuration:
# Set default policy for all your projects
ai-governance init --user
Check configuration status:
ai-governance config
default-secure (recommended) - Balanced security for most projects
permissive - Relaxed rules for development/internal tools
strict - Enhanced security for production code
Different policies per project:
# Web app - use strict policy
cd ~/projects/webapp
ai-governance init --project --template strict
# Internal tool - use permissive policy
cd ~/projects/internal-tool
ai-governance init --project --template permissive
Team-shared configuration:
# Copy team policy to project (commit to git)
mkdir .ai-governance
cp /path/to/team-policy.yaml .ai-governance/policy.yaml
git add .ai-governance/policy.yaml
Temporary override:
# Use explicit policy for one-off refactoring
ai-governance refactor file.py --target "..." --policy /custom/policy.yaml
security:
# Which files are allowed to be sent to AI
allowed_patterns:
- "**/*.py"
- "**/*.js"
- "src/**/*.ts"
# Which files should never be sent
blocked_patterns:
- "**/.env*"
- "**/secrets/**"
- "**/node_modules/**"
# Sensitive content detection
detect_secrets:
enabled: true
patterns:
- 'api[_-]?key[_-]?=.{8,}'
- 'sk-[a-zA-Z0-9]{32,}' # OpenAI keys
# File size limits (bytes)
max_file_size: 1048576 # 1MB
For complete configuration documentation, see CONFIGURATION_GUIDE.md.
policy_engine.py): Loads and manages security policies from YAMLscanner.py): Scans files for policy violationsai_client.py): Interfaces with Claude API for refactoringaudit_logger.py): Records all actions to SQLite databasediff_manager.py): Manages diffs and backupscli.py): Click-based command-line interfaceUser Request
↓
Security Scanner (check file pattern & content)
↓
[BLOCKED] → Audit Log → Stop
↓
[ALLOWED]
↓
AI Client (Claude API)
↓
Diff Manager (show changes)
↓
User Confirmation
↓
Apply Changes + Backup
↓
Audit Log (success)
The tool tracks and displays:
Example output:
Estimated cost: $0.0125
Estimated tokens: ~1,250
✅ Refactoring completed!
Tokens used: 1,342
Input: 1,105
Output: 237
Actual cost: $0.006870
The audit log is stored in .ai-governance-audit.db with this schema:
CREATE TABLE audit_log (
id INTEGER PRIMARY KEY,
timestamp TEXT NOT NULL,
filepath TEXT NOT NULL,
action TEXT NOT NULL,
status TEXT NOT NULL,
reason TEXT,
tokens_used INTEGER DEFAULT 0,
cost REAL DEFAULT 0.0,
findings TEXT,
model TEXT,
target_description TEXT
);
--no-backup only when appropriateThis is a demonstration tool showcasing AI governance concepts. For production use, consider:
MIT License - See LICENSE file for details
For issues or questions:
ai-governance auditecho $ANTHROPIC_API_KEYai-governance init"API key not found" error:
export ANTHROPIC_API_KEY='your_key'Tool not found after installation:
~/.local/bin is in your PATHpipx ensurepath and restart your terminalUpgrade to the latest version:
pipx upgrade ai-governance-tool
# or
pip install --upgrade ai-governance-tool
Want to change API key:
Want to use different keys for different projects:
ANTHROPIC_API_KEY environment variable per-projectRefactor entire project by language:
ai-governance bulk-refactor . --lang <language> --target "<description>"
Refactor specific directory:
ai-governance bulk-refactor src/ --target "<description>"
List all supported languages:
ai-governance bulk-refactor . --list-languages
Dry run (preview without refactoring):
ai-governance bulk-refactor <path> --target "<description>" --dry-run
View what was changed:
ai-governance audit
ai-governance audit --stats
| Language | Command |
|---|---|
| Python | ai-governance bulk-refactor . --lang python --target "add type hints" |
| Java | ai-governance bulk-refactor src/main/java --lang java --target "add javadoc" |
| JavaScript | ai-governance bulk-refactor src --lang javascript --target "modernize to ES6+" |
| TypeScript | ai-governance bulk-refactor . --lang typescript --target "improve types" |
| Go | ai-governance bulk-refactor . --lang go --target "add context to errors" |
| Rust | ai-governance bulk-refactor src --lang rust --target "add documentation" |
| C++ | ai-governance bulk-refactor src --lang cpp --target "modernize to C++17" |
| Ruby | ai-governance bulk-refactor lib --lang ruby --target "add yard documentation" |
| Project Type | Command |
|---|---|
| Spring Boot | ai-governance bulk-refactor src/main/java --lang java --target "add logging and javadoc" |
| React App | ai-governance bulk-refactor src --ext "jsx,tsx" --target "convert to hooks" |
| Django | ai-governance bulk-refactor . --lang python --pattern "*.py" --target "add type hints" |
| Node.js API | ai-governance bulk-refactor src --lang javascript --target "add JSDoc and error handling" |
| Go CLI | ai-governance bulk-refactor cmd --lang go --target "improve error messages" |
| Rust Binary | ai-governance bulk-refactor src --lang rust --target "add better documentation" |
Built with:
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.2.3 | 18 Feb 2026 | 6 |
This describes our collected data; it is not a security assessment.
Shared repository data · GitHub
Observed since 21 Oct, 10:50 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:627a409eb317d7c1531bfbd37c4595ff034acbb921b19d7cccdf5ade3c897e03