Meet the Workflows: Continuous Refactoring
Welcome back to Peli’s Agent Factory!
In our previous post, we met automated agents that detect complexity and propose simpler solutions. These work tirelessly in the background, cleaning things up. Now let’s explore similar agents that take a deeper structural view, extending the automation to structural refactoring.
Continuous Refactoring
Section titled “Continuous Refactoring”Our next two agents continuously analyze code structure, suggesting systematic improvements:
- Semantic Function Refactor - Spots refactoring opportunities we might have missed
- Large File Simplifier - Monitors file sizes and proposes splitting oversized files
The Semantic Function Refactor workflow combines agentic AI with code analysis tools to analyze and address the structure of the entire codebase. It analyzes all Go source files in the pkg/ directory to identify functions that might be in the wrong place.
As codebases evolve, functions sometimes end up in files where they don’t quite belong. Humans struggle to notice these organizational issues because we work on one file at a time and focus on making code work rather than on where it lives.
The workflow performs comprehensive discovery by
- algorithmically collecting all function names from non-test Go files, then
- agentically grouping functions semantically by name and purpose.
It then identifies functions that don’t fit their current file’s theme as outliers, uses Serena-powered semantic code analysis to detect potential duplicates, and creates issues recommending consolidated refactoring. These issues can then be reviewed and addressed by coding agents.
The workflow follows a “one file per feature” principle: files should be named after their primary purpose, and functions within each file should align with that purpose. It closes existing open issues with the [refactor] prefix before creating new ones. This prevents issue accumulation and ensures recommendations stay current.
In our extended use of Semantic Function Refactoring, the workflow has driven 112 merged PRs out of 142 proposed (79% merge rate) through causal chains - creating 99 refactoring issues that downstream agents turn into code changes. For example, issue #12291 analyzing code organization opportunities led to PR #12363 splitting permissions.go into focused modules (928→133 lines).
An example PR from our own use of this workflow is Move misplaced extraction functions to frontmatter_extraction.go.
Large File Simplifier: The Size Monitor
Section titled “Large File Simplifier: The Size Monitor”Large files are a common code smell - they often indicate unclear boundaries, mixed responsibilities, or accumulated complexity. The Large File Simplifier workflow monitors file sizes daily and creates actionable issues when files grow too large.
The workflow runs on weekdays, analyzing all Go source files in the pkg/ directory. It identifies the largest file, checks if it exceeds healthy size thresholds, and creates a detailed issue proposing how to split it into smaller, more focused files.
What makes this workflow effective is its focus and prioritization. Instead of overwhelming developers with issues about every large file, it creates at most one issue, targeting the largest offender. The workflow also skips if an open [file-diet] issue already exists, preventing duplicate work.
In our extended use, Large File Simplifier (also known as “Daily File Diet”) has driven 26 merged PRs out of 33 proposed (79% merge rate) through causal chains - creating 37 file-diet issues targeting the largest files, which downstream agents turn into modular code changes. For example, issue #12535 targeting add_interactive.go led to PR #12545 refactoring it into 6 domain-focused modules.
The workflow uses Serena for semantic code analysis to understand function relationships and propose logical boundaries for splitting. It both counts lines and analyzes the code structure to suggest meaningful module boundaries that make sense.
The Power of Continuous Refactoring
Section titled “The Power of Continuous Refactoring”These workflows demonstrate how AI agents can continuously maintain institutional knowledge about code organization. The benefits compound over time: better organization makes code easier to find, consistent patterns reduce cognitive load, reduced duplication improves maintainability, and clean structure attracts further cleanliness. They’re particularly valuable in AI-assisted development, where code gets written quickly and organizational concerns can take a backseat to functionality.
Using These Workflows
Section titled “Using These Workflows”You can add these workflows to your own repository and remix them. Get going with our Quick Start, then run one of the following:
Semantic Function Refactor:
gh aw add-wizard https://github.com/github/gh-aw/blob/v0.45.5/.github/workflows/semantic-function-refactor.mdLarge File Simplifier:
gh aw add-wizard https://github.com/github/gh-aw/blob/v0.45.5/.github/workflows/daily-file-diet.mdThen edit and remix the workflow specifications to meet your needs, regenerate the lock file using gh aw compile, and push to your repository. See our Quick Start for further installation and setup instructions.
You can also create your own workflows.
Next Up: Continuous Style
Section titled “Next Up: Continuous Style”Beyond structure and organization, there’s another dimension of code quality: presentation and style. How do we maintain beautiful, consistent console output and formatting?
Continue reading: Meet the Workflows: Continuous Style →
Learn More
Section titled “Learn More”- GitHub Agentic Workflows - The technology behind the workflows
- Quick Start - How to write and compile workflows
This is part 3 of a 19-part series exploring the workflows in Peli’s Agent Factory.