Inspiration

My software friends and me have been creating a lot of Github Repo projects lately and find myself manually trying to optimize code which is time consuming and confusing. I wanted to create an autonomous Agent that does this for me and break down each optimization step into its own workflow all deployable on Github. This is such a worldwide valuable project for any developer to use.

What it does

Refactor Bot is a fully functional prototype of an AI agent that:

🧠 Thinks: Analyzes code structure, dependencies, and history 🧹 Acts: Executes formatting, cleanup, and documentation tasks 📈 Improves: Enhances readability, maintainability, and transparency 🔁 Decides: Chooses what to fix, when to commit, and how to document

How we built it

Refactor Bot is composed of six autonomous workflows:

  1. Cleanup Unused Imports/Variables
    Uses Ruff and Autoflake to remove dead code

  2. License Header Injection
    Adds missing license blocks to source files

  3. Auto Formatting
    Applies consistent styling via Black, Ruff, and Prettier

  4. Dependency Manifest Generation
    Uses pipdeptree to create a visual/textual summary of dependencies

  5. Code Graph Visualization
    Parses Python AST to generate module and call graphs as SVGs

  6. Changelog Generation
    Analyzes git history and updates CHANGELOG.md with categorized commits

Each workflow runs on a schedule or manually, commits directly to main, and requires no pull requests or approvals — embodying true autonomy.

Challenges we ran into

  • GitHub Actions limitations
    We discovered that workflows cannot modify other workflows unless using a Personal Access Token (PAT). To stay fully autonomous, we excluded .github/workflows/ from formatting.

  • .gitignore conflicts
    Our diagrams were being ignored by Git until we explicitly removed diagrams/ from .gitignore.

  • Workflow timing and order
    We had to carefully orchestrate the order of workflows to avoid commit collisions and ensure logical progression:

    • Cleanup → License → Format → Manifest → Graph → Changelog
  • Balancing autonomy with safety
    Direct commits to main are powerful but risky. We implemented safeguards like conditional commits (|| echo "No changes") to avoid unnecessary pushes.

    Accomplishments that we're proud of

What we learned

  • Design modular autonomous workflows that act independently yet harmoniously
  • Use tools like Black, Ruff, Prettier, and Autoflake to enforce code hygiene
  • Generate AST-based visualizations using Python and Graphviz
  • Parse git history to build a Conventional Commits-style changelog
  • Handle GitHub Actions permissions, .gitignore conflicts, and direct commits to main

We also deepened our understanding of agentic behavior — how AI can make decisions, execute tasks, and collaborate with humans asynchronously.

What's next for Refactor Bot: Autonomous Code Maintenance Agent

What’s Next

Refactor Bot is just the beginning. Our vision is to evolve it from a passive maintainer into a fully collaborative AI developer assistant — capable of reasoning, refactoring, and even proposing architectural improvements.

Here’s what’s next on our roadmap:

🧠 Smarter Refactoring

  • Use AI models to detect code smells and suggest structural improvements
  • Auto-convert legacy patterns to modern idioms (e.g., class-based → functional)

🗣️ Conversational Interface

  • Integrate with GitHub Discussions or Issues to respond to developer queries
  • Enable natural language prompts like “Refactor this module for readability”

🧪 Test Intelligence

  • Auto-generate unit tests for uncovered code
  • Suggest missing edge cases based on function signatures and logic

🧭 Autonomous Planning

  • Schedule maintenance tasks based on repo activity and commit velocity
  • Prioritize workflows dynamically using a utility function

🌐 Multi-language Support

  • Extend formatting and cleanup to Java, Go, Rust, and more
  • Visualize architecture across polyglot codebases

Built With

Share this project:

Updates