Skip to content

yueneiqi/auto-rs

Repository files navigation

Auto-RS: Autonomous Coding Agent

A Rust implementation of the autonomous coding agent for C/C++ to Rust migration, using the Claude Code SDK.

Features

  • Multi-phase migration workflow: Overview, Execute, Generate Tests, Security, Migration Planning, Transfer
  • Phase management: Automatic phase detection and advancement based on project artifacts
  • Progress tracking: Real-time progress display with migration task tracking
  • Security hooks: Allowlist-based bash command validation (Note: Currently not enabled)
  • Embedded prompts: Prompts are embedded in the binary for easy deployment
  • MCP support: Optional Serena MCP server integration for semantic code analysis

Installation

cd auto-rs
cargo build --release

The binary will be at target/release/auto-rs.

Commands

migrate (default)

Run the migration workflow to convert C/C++ code to Rust.

# Basic usage
auto-rs --project-dir /path/to/project migrate

# With source directory to migrate
auto-rs --project-dir /path/to/project --src-dir /path/to/c-code migrate

# With max iterations
auto-rs --project-dir /path/to/project --max-iterations 10 migrate

# OpenHarmony mode (docker build/test)
auto-rs --project-dir /path/to/project migrate --openharmony

validate

Run the validation workflow after migration is complete. This verifies API compatibility, runs FFI bridge tests, analyzes coverage, performs fuzz testing, and benchmarks performance.

# Basic validation
auto-rs --project-dir /path/to/project validate

# With original C/C++ project for FFI testing
auto-rs --project-dir /path/to/project validate --original-project /path/to/original

Usage

# Basic usage (defaults to migrate command)
auto-rs --project-dir /path/to/project --model claude-sonnet-4-20250514

# With source directory to migrate
auto-rs --project-dir /path/to/project --src-dir /path/to/c-code --model claude-sonnet-4-20250514

# With max iterations
auto-rs --project-dir /path/to/project --max-iterations 10

# With MCP servers enabled
auto-rs --project-dir /path/to/project --enable-mcp

# With custom prompts directory
auto-rs --project-dir /path/to/project --prompts-dir /path/to/prompts

# Verbose logging
auto-rs --project-dir /path/to/project --verbose

CLI Options

Option Short Description
--project-dir -p Project directory path (required)
--model -m Claude model to use (default: claude-sonnet-4-20250514)
--max-iterations -n Maximum number of iterations
--src-dir -s Source directory to copy into the project
--enable-mcp Enable MCP servers (Serena)
--verbose -v Enable verbose logging
--prompts-dir Custom prompts directory path

migrate Options

Option Description
--openharmony Use OpenHarmony-specific prompts (docker build/test, OH developer test framework)

validate Options

Option Description
--original-project Path to original C/C++ project for FFI testing

Environment Variables

  • ANTHROPIC_AUTH_TOKEN: Required. Your Anthropic API authentication token.
  • ANTHROPIC_BASE_URL: Optional. Custom API base URL.
  • CLAUDE_ENABLE_MCP: Optional. Set to 1, true, yes, or on to enable MCP servers.

Migration Phases

  1. Overview & Orientation: Analyze the codebase structure and architecture
  2. Execute (Build, Test, Analysis): Build the project, run tests, perform static analysis
  3. Generate Tests: Identify test gaps and generate additional tests
  4. Security Assessment: Analyze security vulnerabilities
  5. Migration Planning (OpenSpec): Create migration plan with OpenSpec specifications
  6. Transfer (Implementation): Implement the actual migration

Validation Phases

  1. Info Gathering: Collect information about the migrated codebase
  2. API Compatibility: Verify public API compatibility with original C/C++ library
  3. FFI Bridge Testing: Test FFI bridges between Rust and C/C++
  4. Coverage Analysis: Analyze test coverage
  5. Benchmark: Performance benchmarking against original implementation
  6. Fuzz Testing: Run fuzz tests on the migrated code

OpenHarmony Mode

When running with --openharmony, the agent uses specialized prompts for OpenHarmony OS development:

  • Docker-based builds: All build/test commands run inside the oh-dev docker container
  • OH Developer Test Framework: Uses start.sh and run -T UT -tp <part> commands
  • BUILD.gn templates: Uses ohos_rust_unittest, ohos_rust_library, etc.

Docker Setup

# Start the docker container
./docker_run_co.sh

# Inside the container:
cd /home/openharmony/openharmony

# Build component
./build.sh --product-name opi5plus --ccache commonlibrary/c_utils/base:utils

# Run tests
bash ./test/testfwk/developer_test/start.sh
# >>> run -T UT -tp utils
# >>> quit

Environment Variables (Docker)

Variable Description
OH_IMAGE_NAME Docker image name (default: oh_builder:new)
OH_CONTAINER_NAME Container name (default: oh-dev)
OH_COMPONENT_HOST_PATH Host path to component source
OH_COMPONENT_PATH Path inside container

Project Structure

auto-rs/
├── Cargo.toml
├── src/
│   ├── lib.rs          # Library exports
│   ├── main.rs         # CLI entry point and agent loop
│   ├── client.rs       # Claude SDK client configuration
│   ├── phases.rs       # Phase management
│   ├── progress.rs     # Progress tracking
│   ├── prompts.rs      # Prompt loading utilities
│   ├── security.rs     # Security hooks
│   └── validate.rs     # Validation phase management
├── prompts/
│   ├── initializer_prompt.md
│   ├── coding_prompt.md
│   ├── spec.txt
│   ├── phases/
│   │   ├── phase1_overview.md
│   │   ├── phase2_execute.md
│   │   ├── phase3_generate_tests.md
│   │   ├── phase4_security.md
│   │   └── phase5_migration_planning.md
│   ├── validate/
│   │   ├── validate1_info_gathering.md
│   │   ├── validate2_api_compatibility.md
│   │   ├── validate3_ffi_bridge.md
│   │   ├── validate4_coverage.md
│   │   ├── validate5_fuzz.md
│   │   └── validate6_benchmark.md
│   └── openharmony/
│       ├── initializer_prompt.md
│       └── coding_prompt.md
└── assets/
    └── openharmony_developer_test_guide.md

Security

The agent uses multiple layers of security:

  1. Sandbox: OS-level bash command isolation
  2. Permissions: File operations restricted to project directory
  3. Security hooks: Bash commands validated against an allowlist (Note: Currently not enabled)

Allowed Commands

The security module allows a minimal set of commands needed for development:

  • File inspection: ls, cat, head, tail, wc, grep
  • File operations: cp, mkdir, chmod, mv, rm, touch
  • Build tools: make, cmake, gcc, g++, clang, cargo, rustc
  • Version control: git
  • And more (see src/security.rs for the full list)

License

MIT

About

Autonomous coding agent for C/C++ to Rust migration

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors