diff --git a/.claude/settings.json b/.claude/settings.json index 13a4f51e..025b4655 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -14,7 +14,7 @@ ".vscode", ".claude", ".ai", - "~/amplifier" + "~/dev/amplifier" ] }, "enableAllProjectMcpServers": false, diff --git a/.gitignore b/.gitignore index dff640aa..3553f21b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,8 @@ __pycache__ .ruff_cache .cache *.egg-info -bin +# bin directory for build artifacts (but allow our global command) +# bin obj dist build diff --git a/Makefile b/Makefile index da372af1..9b091e49 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,7 @@ default: ## Show essential commands @echo "" @echo "Quick Start:" @echo " make install Install all dependencies" + @echo " make install-global Install global 'amplifier' command" @echo "" @echo "Knowledge Base:" @echo " make knowledge-update Full pipeline: extract & synthesize" @@ -54,6 +55,7 @@ help: ## Show ALL available commands @echo "" @echo "QUICK START:" @echo " make install Install all dependencies" + @echo " make install-global Install global 'amplifier' command" @echo "" @echo "KNOWLEDGE BASE:" @echo " make knowledge-update Full pipeline: extract & synthesize" @@ -140,6 +142,9 @@ install: ## Install all dependencies @echo "" @echo "✅ All dependencies installed!" @echo "" + @echo "💡 For global access to Amplifier from any directory:" + @echo " make install-global" + @echo "" @if [ -n "$$VIRTUAL_ENV" ]; then \ echo "✓ Virtual environment already active"; \ elif [ -f .venv/bin/activate ]; then \ @@ -148,6 +153,67 @@ install: ## Install all dependencies echo "✗ No virtual environment found. Run 'make install' first."; \ fi +# Global installation +install-global: ## Install global 'amplifier' command for system-wide access + @echo "Installing global Amplifier command..." + @if [ ! -f .venv/bin/activate ]; then \ + echo "❌ Please run 'make install' first to create the virtual environment"; \ + exit 1; \ + fi + @mkdir -p ~/bin + @cp bin/amplifier ~/bin/amplifier + @chmod +x ~/bin/amplifier + @echo "✅ Global 'amplifier' command installed to ~/bin/amplifier" + @echo "" + @if echo "$$PATH" | grep -q "$$HOME/bin"; then \ + echo "✓ ~/bin is already in your PATH"; \ + else \ + echo "💡 Add ~/bin to your PATH for global access:"; \ + if [ -n "$$ZSH_VERSION" ] || [ "$$SHELL" = "/bin/zsh" ] || [ -f ~/.zshrc ]; then \ + echo ' echo "export PATH="\$$HOME/bin:\$$PATH"" >> ~/.zshrc'; \ + echo " source ~/.zshrc"; \ + else \ + echo ' echo "export PATH="\$$HOME/bin:\$$PATH"" >> ~/.bashrc'; \ + echo " source ~/.bashrc"; \ + fi; \ + fi + @echo "" + @echo "Usage: amplifier [project-dir] [claude-options]" + @echo "Example: amplifier ~/my-project --model sonnet" + +install-global-system: ## Install global 'amplifier' command system-wide (requires sudo) + @echo "Installing system-wide Amplifier command..." + @if [ ! -f .venv/bin/activate ]; then \ + echo "❌ Please run 'make install' first to create the virtual environment"; \ + exit 1; \ + fi + @echo "This will install to /usr/local/bin and requires sudo privileges." + @read -p "Continue? [y/N] " -n 1 -r; echo; \ + if [[ $$REPLY =~ ^[Yy]$$ ]]; then \ + sudo cp bin/amplifier /usr/local/bin/amplifier; \ + sudo chmod +x /usr/local/bin/amplifier; \ + echo "✅ Global 'amplifier' command installed to /usr/local/bin/amplifier"; \ + else \ + echo "Installation cancelled."; \ + fi + +uninstall-global: ## Remove global 'amplifier' command + @echo "Removing global Amplifier command..." + @if [ -f ~/bin/amplifier ]; then \ + rm ~/bin/amplifier; \ + echo "✅ Removed ~/bin/amplifier"; \ + else \ + echo "✓ ~/bin/amplifier not found"; \ + fi + @if [ -f /usr/local/bin/amplifier ]; then \ + echo "System-wide installation found at /usr/local/bin/amplifier"; \ + read -p "Remove it? (requires sudo) [y/N] " -n 1 -r; echo; \ + if [[ $$REPLY =~ ^[Yy]$$ ]]; then \ + sudo rm /usr/local/bin/amplifier; \ + echo "✅ Removed /usr/local/bin/amplifier"; \ + fi; \ + fi + # Code quality check: ## Format, lint, and type-check all code @# Handle worktree virtual environment issues by unsetting mismatched VIRTUAL_ENV diff --git a/README.md b/README.md index c7cff594..eb9d7821 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,18 @@ Before starting, you'll need: .venv\Scripts\activate # Windows ``` +5. **Install global access** (Optional but recommended): + ```bash + make install-global + ``` + + This installs the `amplifier` command globally, letting you use Amplifier on any project from anywhere: + + ```bash + cd ~/my-other-project + amplifier # Starts Claude with Amplifier agents for this project + ``` + ## 📖 How to Use Amplifier ### Basic Usage @@ -95,28 +107,104 @@ cd amplifier claude # Everything is pre-configured and ready ``` -### Using with Your Own Projects +### Global Usage: Amplifier on Any Project 🌍 -Want Amplifier's power on your own code? Easy: +**The power of Amplifier is no longer confined to the Amplifier directory.** Use all 20+ specialized agents, knowledge extraction, and automation tools on any codebase, anywhere on your system. -1. **Start Claude with both directories**: +#### Method 1: Global Command (Recommended) - ```bash - claude --add-dir /path/to/your/project - ``` +After running `make install-global`, use Amplifier from any directory: -2. **Tell Claude where to work** (paste as first message): +```bash +# Work on any project +cd ~/my-web-app +amplifier - ``` - I'm working in /path/to/your/project which doesn't have Amplifier files. - Please cd to that directory and work there. - Do NOT update any issues or PRs in the Amplifier repo. - ``` +# Or specify a different project +amplifier ~/dev/my-python-api + +# Pass Claude options +amplifier ~/my-project --model sonnet +amplifier ~/my-app --print "Fix the authentication bug" +``` + +#### Method 2: From Amplifier Directory + +If you prefer not to install globally: + +```bash +cd ~/dev/amplifier +./amplifier-anywhere.sh ~/path/to/your/project + +# Or with Claude options +./amplifier-anywhere.sh ~/my-app --model sonnet +``` + +#### Method 3: Manual Setup + +For maximum control: + +```bash +cd ~/dev/amplifier +source .venv/bin/activate +claude --add-dir /path/to/your/project +``` + +#### Usage Template + +**Important**: When Claude starts, always begin with this message template: + +``` +I'm working in [YOUR_PROJECT_PATH] which doesn't have Amplifier files. +Please cd to that directory and work there. +Do NOT update any issues or PRs in the Amplifier repo. + +Use [AGENT_NAME] to [TASK_DESCRIPTION]. +``` + +**Examples**: +- `"Use zen-architect to design my application's caching layer"` +- `"Deploy bug-hunter to find why my login system is failing"` +- `"Have security-guardian review my API implementation for vulnerabilities"` +- `"Use modular-builder to implement the user profile feature"` + +#### Global Benefits + +✅ **All 20+ specialized agents** work on your projects +✅ **Shared knowledge base** - insights from one project help others +✅ **Same powerful automation** - quality checks, parallel development +✅ **Project isolation** - changes only affect your target project +✅ **Works anywhere** - no need to copy files or modify your projects -3. **Use Amplifier's agents on your code**: - - "Use the zen-architect agent to design my application's caching layer" - - "Deploy bug-hunter to find why my login system is failing" - - "Have security-guardian review my API implementation for vulnerabilities" +#### Troubleshooting Global Access + +**Command not found: `amplifier`** +```bash +# Check if ~/bin is in PATH +echo $PATH | grep $HOME/bin + +# Add to PATH if missing +echo 'export PATH="$HOME/bin:$PATH"' >> ~/.zshrc # or ~/.bashrc +source ~/.zshrc +``` + +**Cannot find Amplifier installation** +```bash +# The global command looks for Amplifier in these locations: +# - ~/dev/amplifier (most common) +# - ~/amplifier +# - ~/repos/amplifier +# - ~/code/amplifier + +# Create a symlink if needed +ln -s /path/to/your/amplifier ~/dev/amplifier +``` + +**Get help anytime** +```bash +amplifier --help # Show usage help +amplifier --version # Show version info +``` ### Parallel Development diff --git a/amplifier-anywhere.sh b/amplifier-anywhere.sh new file mode 100755 index 00000000..f33eb16c --- /dev/null +++ b/amplifier-anywhere.sh @@ -0,0 +1,152 @@ +#!/bin/bash + +# Amplifier Universal Script +# Use Amplifier's power on any project directory +# +# Usage: +# amplifier [project-dir] [claude-options] +# amplifier --help +# amplifier --version + +set -e # Exit on any error + +# Help function +show_help() { + cat << EOF +Amplifier Universal Access Script + +USAGE: + amplifier [PROJECT_DIR] [CLAUDE_OPTIONS...] + amplifier --help + amplifier --version + +EXAMPLES: + amplifier # Use current directory + amplifier ~/dev/my-project # Use specific directory + amplifier . --model sonnet # Pass options to Claude + amplifier ~/app --print "Fix bugs" # Non-interactive mode + +DESCRIPTION: + Starts Claude with Amplifier's specialized agents and tools, + configured to work on projects in any directory. + + All of Amplifier's 20+ agents become available: + - zen-architect (design with simplicity) + - bug-hunter (systematic debugging) + - security-guardian (security analysis) + - And many more... + +FIRST MESSAGE TEMPLATE: + I'm working in [YOUR_PROJECT_PATH] which doesn't have Amplifier files. + Please cd to that directory and work there. + Do NOT update any issues or PRs in the Amplifier repo. + +EOF +} + +# Handle help and version flags +if [[ "$1" == "--help" || "$1" == "-h" ]]; then + show_help + exit 0 +fi + +if [[ "$1" == "--version" ]]; then + echo "Amplifier Universal Access (part of Amplifier toolkit)" + exit 0 +fi + +# Auto-detect Amplifier directory +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +if [[ "$SCRIPT_DIR" == */bin ]]; then + # Global installation - find amplifier directory + AMPLIFIER_DIR="$(dirname "$SCRIPT_DIR")/dev/amplifier" + if [[ ! -d "$AMPLIFIER_DIR" ]]; then + # Fallback - common locations + for candidate in "$HOME/dev/amplifier" "$HOME/amplifier" "$HOME/repos/amplifier"; do + if [[ -d "$candidate" ]]; then + AMPLIFIER_DIR="$candidate" + break + fi + done + fi +else + # Local installation + AMPLIFIER_DIR="$SCRIPT_DIR" +fi + +# Validate Amplifier directory +if [[ ! -d "$AMPLIFIER_DIR" ]]; then + echo "❌ Cannot find Amplifier installation directory" + echo " Looked for: $AMPLIFIER_DIR" + echo " Please ensure Amplifier is properly installed" + exit 1 +fi + +if [[ ! -f "$AMPLIFIER_DIR/.venv/bin/activate" ]]; then + echo "❌ Amplifier virtual environment not found at: $AMPLIFIER_DIR/.venv" + echo " Run 'make install' in the Amplifier directory first" + exit 1 +fi + +# Parse arguments - use ORIGINAL_PWD if set (from global wrapper), otherwise current pwd +DEFAULT_DIR="${ORIGINAL_PWD:-$(pwd)}" +PROJECT_DIR="${1:-$DEFAULT_DIR}" + +# Check if first arg is a Claude flag (starts with --) +if [[ "$1" == --* ]] && [[ "$1" != "--help" ]] && [[ "$1" != "-h" ]] && [[ "$1" != "--version" ]]; then + # First argument is a Claude option, use default directory + PROJECT_DIR="$DEFAULT_DIR" + CLAUDE_ARGS="$@" +else + # First argument might be a directory + if [[ -n "$1" ]]; then + shift || true # Remove first argument, ignore error if no args + fi + CLAUDE_ARGS="$@" +fi + +# Validate project directory +if [[ ! -d "$PROJECT_DIR" ]]; then + echo "❌ Directory '$PROJECT_DIR' does not exist" + exit 1 +fi + +# Convert to absolute path +PROJECT_DIR="$(cd "$PROJECT_DIR" && pwd)" + +echo "🚀 Starting Amplifier for project: $PROJECT_DIR" +echo "📁 Amplifier location: $AMPLIFIER_DIR" + +# Set up pnpm paths +export PNPM_HOME="$HOME/.local/share/pnpm" +export PATH="$PNPM_HOME:$PATH" + +# Check Claude availability +if ! command -v claude >/dev/null 2>&1; then + echo "❌ Claude CLI not found. Please ensure it's installed and in PATH." + echo " Run 'make install' in Amplifier directory to install it." + exit 1 +fi + +# Activate amplifier's virtual environment +echo "🔄 Activating Amplifier environment..." +source "$AMPLIFIER_DIR/.venv/bin/activate" + +# Create necessary directories in amplifier +mkdir -p "$AMPLIFIER_DIR/.claude-trace" +mkdir -p "$AMPLIFIER_DIR/.data" + +echo "✅ Environment activated" +echo "🐍 Python: $(which python)" +echo "🤖 Claude: $(which claude)" +echo "📂 Project: $PROJECT_DIR" +echo "" +echo "💡 First message template:" +echo " I'm working in $PROJECT_DIR which doesn't have Amplifier files." +echo " Please cd to that directory and work there." +echo " Do NOT update any issues or PRs in the Amplifier repo." +echo "" + +# Start Claude with both directories +cd "$AMPLIFIER_DIR" +exec claude --add-dir "$PROJECT_DIR" $CLAUDE_ARGS diff --git a/amplifier/tools/aider_regenerator.py b/amplifier/tools/aider_regenerator.py new file mode 100644 index 00000000..d3d0318c --- /dev/null +++ b/amplifier/tools/aider_regenerator.py @@ -0,0 +1,256 @@ +#!/usr/bin/env python3 +""" +Aider Regenerator - AI-powered module regeneration tool. + +This tool provides AI-powered code regeneration capabilities using Aider, +enabling automated module regeneration based on specifications. +""" + +import logging +import subprocess +import sys +from pathlib import Path + +logger = logging.getLogger(__name__) + + +class AiderRegenerator: + """AI-powered module regeneration using Aider.""" + + def __init__(self, venv_path: Path = Path(".aider-venv")): + """Initialize the Aider regenerator. + + Args: + venv_path: Path to the Aider virtual environment + """ + self.venv_path = venv_path + self.aider_cmd = self.venv_path / "bin" / "aider" + + if not self.aider_cmd.exists(): + raise RuntimeError(f"Aider not found at {self.aider_cmd}. Please run scripts/setup-aider.sh first.") + + def regenerate_module( + self, + module_path: Path, + spec_path: Path | None = None, + philosophy: str = "fractalized", + auto_commit: bool = False, + model: str = "claude-3-5-sonnet-20241022", + ) -> bool: + """Regenerate a module using AI based on its specification. + + Args: + module_path: Path to the module to regenerate + spec_path: Optional path to specification file + philosophy: Philosophy to follow (fractalized, modular, zen) + auto_commit: Whether to auto-commit changes + model: AI model to use + + Returns: + True if regeneration succeeded + """ + if not module_path.exists(): + logger.error(f"Module not found: {module_path}") + return False + + # Build the prompt based on philosophy + prompt = self._build_prompt(module_path, spec_path, philosophy) + + # Prepare Aider command + cmd = [ + str(self.aider_cmd), + "--model", + model, + "--yes-always", # Auto-approve changes + "--no-auto-commits" if not auto_commit else "--auto-commits", + str(module_path), + ] + + if spec_path and spec_path.exists(): + cmd.append(str(spec_path)) + + # Add the prompt via stdin + logger.info(f"Regenerating {module_path.name} with {philosophy} philosophy...") + + try: + result = subprocess.run( + cmd, + input=prompt, + text=True, + capture_output=True, + timeout=300, # 5 minute timeout + ) + + if result.returncode == 0: + logger.info(f"Successfully regenerated {module_path.name}") + return True + logger.error(f"Aider failed: {result.stderr}") + return False + + except subprocess.TimeoutExpired: + logger.error("Aider timed out after 5 minutes") + return False + except Exception as e: + logger.error(f"Error running Aider: {e}") + return False + + def _build_prompt(self, module_path: Path, spec_path: Path | None, philosophy: str) -> str: + """Build the regeneration prompt based on philosophy. + + Args: + module_path: Path to the module + spec_path: Optional specification file + philosophy: Philosophy to follow + + Returns: + The prompt string for Aider + """ + prompts = { + "fractalized": ( + "Regenerate this module following the Fractalized Thinking philosophy:\n" + "1. Start with the smallest, simplest working piece\n" + "2. Patiently untangle complexity thread by thread\n" + "3. Build bridges between simple components\n" + "4. Let patterns emerge naturally\n\n" + ), + "modular": ( + "Regenerate this module following the Modular philosophy:\n" + "1. Create self-contained bricks with clear studs (interfaces)\n" + "2. Each brick has one clear responsibility\n" + "3. Contracts are stable, implementations can change\n" + "4. Prefer regeneration over patching\n\n" + ), + "zen": ( + "Regenerate this module following the Zen philosophy:\n" + "1. Ruthless simplicity - remove everything unnecessary\n" + "2. Direct solutions without unnecessary abstractions\n" + "3. Trust in emergence from simple components\n" + "4. Handle only what's needed now\n\n" + ), + } + + base_prompt = prompts.get(philosophy, prompts["fractalized"]) + + if spec_path and spec_path.exists(): + spec_content = spec_path.read_text() + base_prompt += f"Follow this specification:\n{spec_content}\n\n" + + base_prompt += f"Regenerate the module at {module_path} to be cleaner, simpler, and more maintainable." + + return base_prompt + + def batch_regenerate( + self, + modules: list[Path], + philosophy: str = "fractalized", + auto_commit: bool = False, + model: str = "claude-3-5-sonnet-20241022", + ) -> dict[str, bool]: + """Regenerate multiple modules in sequence. + + Args: + modules: List of module paths to regenerate + philosophy: Philosophy to follow + auto_commit: Whether to auto-commit changes + model: AI model to use + + Returns: + Dictionary mapping module paths to success status + """ + results = {} + + for module in modules: + logger.info(f"Processing {module}...") + success = self.regenerate_module( + module, + philosophy=philosophy, + auto_commit=auto_commit, + model=model, + ) + results[str(module)] = success + + if not success: + logger.warning(f"Failed to regenerate {module}, continuing...") + + # Summary + successful = sum(1 for s in results.values() if s) + logger.info(f"Regenerated {successful}/{len(modules)} modules successfully") + + return results + + +def main(): + """CLI entry point for direct usage.""" + import argparse + + parser = argparse.ArgumentParser(description="Regenerate modules using AI") + parser.add_argument("modules", nargs="+", help="Module files to regenerate") + parser.add_argument( + "--philosophy", + choices=["fractalized", "modular", "zen"], + default="fractalized", + help="Philosophy to follow", + ) + parser.add_argument( + "--spec", + help="Path to specification file", + ) + parser.add_argument( + "--auto-commit", + action="store_true", + help="Auto-commit changes", + ) + parser.add_argument( + "--model", + default="claude-3-5-sonnet-20241022", + help="AI model to use", + ) + parser.add_argument( + "--verbose", + action="store_true", + help="Enable verbose output", + ) + + args = parser.parse_args() + + # Setup logging + logging.basicConfig( + level=logging.DEBUG if args.verbose else logging.INFO, + format="%(levelname)s: %(message)s", + ) + + # Initialize regenerator + try: + regenerator = AiderRegenerator() + except RuntimeError as e: + logger.error(str(e)) + sys.exit(1) + + # Process modules + modules = [Path(m) for m in args.modules] + + if len(modules) == 1 and args.spec: + # Single module with spec + success = regenerator.regenerate_module( + modules[0], + spec_path=Path(args.spec) if args.spec else None, + philosophy=args.philosophy, + auto_commit=args.auto_commit, + model=args.model, + ) + sys.exit(0 if success else 1) + else: + # Batch regeneration + results = regenerator.batch_regenerate( + modules, + philosophy=args.philosophy, + auto_commit=args.auto_commit, + model=args.model, + ) + + # Exit with error if any failed + sys.exit(0 if all(results.values()) else 1) + + +if __name__ == "__main__": + main() diff --git a/bin/amplifier b/bin/amplifier new file mode 100755 index 00000000..cc92336b --- /dev/null +++ b/bin/amplifier @@ -0,0 +1,39 @@ +#!/bin/bash + +# Global Amplifier Command +# This is the version installed to ~/bin or /usr/local/bin + +# Auto-detect Amplifier directory from common locations +AMPLIFIER_DIRS=( + "$HOME/dev/amplifier" + "$HOME/amplifier" + "$HOME/repos/amplifier" + "$HOME/code/amplifier" + "/opt/amplifier" +) + +AMPLIFIER_DIR="" +for dir in "${AMPLIFIER_DIRS[@]}"; do + if [[ -d "$dir" && -f "$dir/.venv/bin/activate" ]]; then + AMPLIFIER_DIR="$dir" + break + fi +done + +if [[ -z "$AMPLIFIER_DIR" ]]; then + echo "❌ Cannot find Amplifier installation" + echo " Searched locations:" + for dir in "${AMPLIFIER_DIRS[@]}"; do + echo " - $dir" + done + echo "" + echo " Please ensure Amplifier is cloned and installed in one of these locations." + echo " Or create a symlink: ln -s /path/to/your/amplifier ~/dev/amplifier" + exit 1 +fi + +# Save original working directory +ORIGINAL_PWD="$(pwd)" + +# Execute the main script, passing the original working directory as an env variable +ORIGINAL_PWD="$ORIGINAL_PWD" exec "$AMPLIFIER_DIR/amplifier-anywhere.sh" "$@" diff --git a/docs/aider-tools.md b/docs/aider-tools.md new file mode 100644 index 00000000..c43ddd18 --- /dev/null +++ b/docs/aider-tools.md @@ -0,0 +1,136 @@ +# Aider Tools for Amplifier + +AI-powered code regeneration tools using [Aider](https://aider.chat/). + +## Overview + +The Aider tools provide AI-powered module regeneration capabilities, enabling automated code improvements based on different development philosophies. + +## Installation + +Run the setup script to install Aider in an isolated environment: + +```bash +bash scripts/setup-aider.sh +``` + +This creates a `.aider-venv` virtual environment with Aider installed. + +## Configuration + +Set your API key for the AI model: + +```bash +export ANTHROPIC_API_KEY='your-api-key' +``` + +## Usage + +### Command Line + +Regenerate a single module: + +```bash +python amplifier/tools/aider_regenerator.py amplifier/some_module.py --philosophy zen +``` + +Regenerate with a specification: + +```bash +python amplifier/tools/aider_regenerator.py amplifier/module.py --spec specs/module_spec.md +``` + +Batch regeneration: + +```bash +python amplifier/tools/aider_regenerator.py amplifier/*.py --philosophy modular +``` + +### Python API + +```python +from pathlib import Path +from amplifier.tools.aider_regenerator import AiderRegenerator + +# Initialize regenerator +regenerator = AiderRegenerator() + +# Regenerate a module +success = regenerator.regenerate_module( + module_path=Path("amplifier/my_module.py"), + philosophy="fractalized", + auto_commit=False +) + +# Batch regeneration +modules = list(Path("amplifier").glob("*.py")) +results = regenerator.batch_regenerate( + modules, + philosophy="zen" +) +``` + +## Development Philosophies + +The regenerator supports three philosophies: + +### Fractalized Thinking +- Start with the smallest, simplest working piece +- Patiently untangle complexity thread by thread +- Build bridges between simple components +- Let patterns emerge naturally + +### Modular Design +- Create self-contained bricks with clear interfaces +- Each brick has one clear responsibility +- Contracts are stable, implementations can change +- Prefer regeneration over patching + +### Zen Simplicity +- Ruthless simplicity - remove everything unnecessary +- Direct solutions without unnecessary abstractions +- Trust in emergence from simple components +- Handle only what's needed now + +## Options + +- `--philosophy`: Choose regeneration philosophy (fractalized, modular, zen) +- `--spec`: Path to specification file +- `--auto-commit`: Automatically commit changes +- `--model`: AI model to use (default: claude-3-5-sonnet) +- `--verbose`: Enable debug output + +## Pre-commit Hook (Optional) + +To automatically regenerate modified files before commits, create `.git/hooks/pre-commit`: + +```bash +#!/bin/bash +# Auto-regenerate modified Python files + +if [ "$AIDER_REGENERATE" = "true" ]; then + # Get modified Python files + files=$(git diff --cached --name-only --diff-filter=M | grep '\.py$') + + if [ -n "$files" ]; then + echo "Regenerating modified Python files..." + python amplifier/tools/aider_regenerator.py $files \ + --philosophy ${AIDER_PHILOSOPHY:-fractalized} \ + ${AIDER_AUTO_ADD:+--auto-commit} + fi +fi +``` + +Then enable with: + +```bash +export AIDER_REGENERATE=true +git commit -m "Your message" +``` + +## Notes + +- Aider requires an API key for the chosen AI model +- Regeneration typically takes 30-60 seconds per module +- The tool preserves file structure while improving code quality +- Always review regenerated code before committing \ No newline at end of file diff --git a/scripts/setup-aider.sh b/scripts/setup-aider.sh new file mode 100755 index 00000000..e710523b --- /dev/null +++ b/scripts/setup-aider.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# Setup script for Aider integration + +set -e + +echo "Setting up Aider for AI-powered code regeneration..." + +# Check if uv is available +if ! command -v uv &> /dev/null; then + echo "Error: uv is not installed. Please install it first." + echo "Run: curl -LsSf https://astral.sh/uv/install.sh | sh" + exit 1 +fi + +# Create isolated virtual environment for Aider +echo "Creating isolated environment for Aider..." +uv venv .aider-venv --python 3.11 + +# Install Aider in the isolated environment +echo "Installing Aider..." +source .aider-venv/bin/activate +uv pip install aider-chat + +echo "" +echo "✅ Aider setup complete!" +echo "" +echo "To use Aider directly:" +echo " source .aider-venv/bin/activate" +echo " aider --help" +echo "" +echo "To use the regeneration tool:" +echo " python amplifier/tools/aider_regenerator.py --help" +echo "" +echo "Note: You'll need to set your API key:" +echo " export ANTHROPIC_API_KEY='your-api-key'" +echo "" \ No newline at end of file diff --git a/start-claude.sh b/start-claude.sh new file mode 100755 index 00000000..f0f19903 --- /dev/null +++ b/start-claude.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Amplifier Claude Startup Script +# This script ensures all environment variables and paths are set correctly + +echo "🚀 Starting Claude with Amplifier environment..." + +# Set up pnpm paths +export PNPM_HOME="$HOME/.local/share/pnpm" +export PATH="$PNPM_HOME:$PATH" + +# Activate virtual environment +source .venv/bin/activate + +# Create necessary directories if they don't exist +mkdir -p .claude-trace +mkdir -p .data + +echo "✅ Environment activated" +echo "📁 Working directory: $(pwd)" +echo "🐍 Python: $(which python)" +echo "🤖 Claude: $(which claude)" +echo "" + +# Start Claude +claude "$@" \ No newline at end of file