mirror of
https://github.com/leonvanzyl/autocoder.git
synced 2026-01-29 22:02:05 +00:00
This major update replaces the fixed `generations/` directory with support for storing projects in any directory on the filesystem. Projects are now tracked via a cross-platform registry system. ## New Features ### Project Registry (`registry.py`) - Cross-platform registry storing project name-to-path mappings - Platform-specific config locations: - Windows: %APPDATA%\autonomous-coder\projects.json - macOS: ~/Library/Application Support/autonomous-coder/projects.json - Linux: ~/.config/autonomous-coder/projects.json - POSIX path format for cross-platform compatibility - File locking for concurrent access safety (fcntl/msvcrt) - Atomic writes via temp file + rename to prevent corruption - Fixed Windows file locking issue with tempfile.mkstemp() ### Filesystem Browser API (`server/routers/filesystem.py`) - REST endpoints for browsing directories server-side - Cross-platform support with blocked system paths: - Windows: C:\Windows, Program Files, ProgramData, etc. - macOS: /System, /Library, /private, etc. - Linux: /etc, /var, /usr, /bin, etc. - Universal blocked paths: .ssh, .aws, .gnupg, .docker, etc. - Hidden file detection (Unix dot-prefix + Windows attributes) - UNC path blocking for security - Windows drive enumeration via ctypes - Directory creation with validation - Added `has_children` field to DirectoryEntry schema ### UI Folder Browser (`ui/src/components/FolderBrowser.tsx`) - React component for selecting project directories - Breadcrumb navigation with clickable segments - Windows drive selector - New folder creation inline - Fixed text visibility with explicit color values ## Updated Components ### Server Routers - `projects.py`: Uses registry instead of fixed generations/ directory - `agent.py`: Uses registry for project path lookups - `features.py`: Uses registry for database path resolution - `spec_creation.py`: Uses registry for WebSocket project resolution ### Process Manager (`server/services/process_manager.py`) - Fixed sandbox issue: subprocess now uses project_dir as cwd - This allows the Claude SDK sandbox to access external project directories ### Schemas (`server/schemas.py`) - Added `has_children` to DirectoryEntry - Added `in_progress` to ProjectStats - Added path field to ProjectSummary and ProjectDetail ### UI Components - `NewProjectModal.tsx`: Multi-step wizard with folder selection - Added clarifying text about subfolder creation - Fixed text color visibility issues ### API Client (`ui/src/lib/api.ts`) - Added filesystem API functions (listDirectory, createDirectory) - Fixed Windows path splitting for directory creation ### Documentation - Updated CLAUDE.md with registry system details - Updated command examples for absolute paths ## Security Improvements - Blocked `.` and `..` in directory names to prevent traversal - Added path blocking check in project creation - UNC path blocking throughout filesystem API 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
137 lines
4.0 KiB
Python
137 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Autonomous Coding Agent Demo
|
|
============================
|
|
|
|
A minimal harness demonstrating long-running autonomous coding with Claude.
|
|
This script implements the two-agent pattern (initializer + coding agent) and
|
|
incorporates all the strategies from the long-running agents guide.
|
|
|
|
Example Usage:
|
|
# Using absolute path directly
|
|
python autonomous_agent_demo.py --project-dir C:/Projects/my-app
|
|
|
|
# Using registered project name (looked up from registry)
|
|
python autonomous_agent_demo.py --project-dir my-app
|
|
|
|
# Limit iterations for testing
|
|
python autonomous_agent_demo.py --project-dir my-app --max-iterations 5
|
|
"""
|
|
|
|
import argparse
|
|
import asyncio
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
# Load environment variables from .env file (if it exists)
|
|
# IMPORTANT: Must be called BEFORE importing other modules that read env vars at load time
|
|
load_dotenv()
|
|
|
|
from agent import run_autonomous_agent
|
|
from registry import get_project_path
|
|
|
|
|
|
# Configuration
|
|
# DEFAULT_MODEL = "claude-sonnet-4-5-20250929"
|
|
DEFAULT_MODEL = "claude-opus-4-5-20251101"
|
|
|
|
|
|
def parse_args() -> argparse.Namespace:
|
|
"""Parse command line arguments."""
|
|
parser = argparse.ArgumentParser(
|
|
description="Autonomous Coding Agent Demo - Long-running agent harness",
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
epilog="""
|
|
Examples:
|
|
# Use absolute path directly
|
|
python autonomous_agent_demo.py --project-dir C:/Projects/my-app
|
|
|
|
# Use registered project name (looked up from registry)
|
|
python autonomous_agent_demo.py --project-dir my-app
|
|
|
|
# Use a specific model
|
|
python autonomous_agent_demo.py --project-dir my-app --model claude-sonnet-4-5-20250929
|
|
|
|
# Limit iterations for testing
|
|
python autonomous_agent_demo.py --project-dir my-app --max-iterations 5
|
|
|
|
Authentication:
|
|
Uses Claude CLI credentials from ~/.claude/.credentials.json
|
|
Run 'claude login' to authenticate (handled by start.bat/start.sh)
|
|
""",
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--project-dir",
|
|
type=str,
|
|
required=True,
|
|
help="Project directory path (absolute) or registered project name",
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--max-iterations",
|
|
type=int,
|
|
default=None,
|
|
help="Maximum number of agent iterations (default: unlimited)",
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--model",
|
|
type=str,
|
|
default=DEFAULT_MODEL,
|
|
help=f"Claude model to use (default: {DEFAULT_MODEL})",
|
|
)
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
def main() -> None:
|
|
"""Main entry point."""
|
|
args = parse_args()
|
|
|
|
# Note: Authentication is handled by start.bat/start.sh before this script runs.
|
|
# The Claude SDK auto-detects credentials from ~/.claude/.credentials.json
|
|
|
|
# Resolve project directory:
|
|
# 1. If absolute path, use as-is
|
|
# 2. Otherwise, look up from registry by name
|
|
project_dir_input = args.project_dir
|
|
project_dir = Path(project_dir_input)
|
|
|
|
if project_dir.is_absolute():
|
|
# Absolute path provided - use directly
|
|
if not project_dir.exists():
|
|
print(f"Error: Project directory does not exist: {project_dir}")
|
|
return
|
|
else:
|
|
# Treat as a project name - look up from registry
|
|
registered_path = get_project_path(project_dir_input)
|
|
if registered_path:
|
|
project_dir = registered_path
|
|
else:
|
|
print(f"Error: Project '{project_dir_input}' not found in registry")
|
|
print("Use an absolute path or register the project first.")
|
|
return
|
|
|
|
try:
|
|
# Run the agent (MCP server handles feature database)
|
|
asyncio.run(
|
|
run_autonomous_agent(
|
|
project_dir=project_dir,
|
|
model=args.model,
|
|
max_iterations=args.max_iterations,
|
|
)
|
|
)
|
|
except KeyboardInterrupt:
|
|
print("\n\nInterrupted by user")
|
|
print("To resume, run the same command again")
|
|
except Exception as e:
|
|
print(f"\nFatal error: {e}")
|
|
raise
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|