|
| 1 | +# Code Simplifier |
| 2 | + |
| 3 | +> For an overview of all available workflows, see the [main README](../README.md). |
| 4 | +
|
| 5 | +The [Code Simplifier workflow](../workflows/code-simplifier.md?plain=1) automatically analyzes recently modified code and creates pull requests with simplifications that improve clarity, consistency, and maintainability while preserving functionality. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +Add the workflow to your repository: |
| 10 | + |
| 11 | +```bash |
| 12 | +gh aw add https://github.com/githubnext/agentics/blob/main/workflows/code-simplifier.md |
| 13 | +``` |
| 14 | + |
| 15 | +Then compile: |
| 16 | + |
| 17 | +```bash |
| 18 | +gh aw compile |
| 19 | +``` |
| 20 | + |
| 21 | +## What It Does |
| 22 | + |
| 23 | +The Code Simplifier workflow runs daily and: |
| 24 | + |
| 25 | +1. **Identifies Recent Changes** - Finds code modified in the last 24 hours from merged PRs and commits |
| 26 | +2. **Analyzes Code Quality** - Reviews changed files for opportunities to simplify without changing functionality |
| 27 | +3. **Applies Improvements** - Makes targeted edits to enhance clarity, reduce complexity, and apply project conventions |
| 28 | +4. **Validates Changes** - Runs tests, linters, and builds to ensure no functionality is broken |
| 29 | +5. **Creates Pull Requests** - Proposes simplifications for review when beneficial improvements are found |
| 30 | + |
| 31 | +## How It Works |
| 32 | + |
| 33 | +The workflow focuses exclusively on **recently modified code** (last 24 hours), making it a continuous cleanup process that trails behind active development: |
| 34 | + |
| 35 | +### Simplification Principles |
| 36 | + |
| 37 | +- **Preserves Functionality** - Never changes what code does, only how it does it |
| 38 | +- **Enhances Clarity** - Reduces nesting, eliminates redundancy, improves naming |
| 39 | +- **Applies Standards** - Follows project-specific conventions and established patterns |
| 40 | +- **Maintains Balance** - Avoids over-simplification that reduces maintainability |
| 41 | + |
| 42 | +### What It Simplifies |
| 43 | + |
| 44 | +Common improvements include: |
| 45 | +- Reducing nested conditionals and loops |
| 46 | +- Extracting repeated logic into helper functions |
| 47 | +- Improving variable and function names for clarity |
| 48 | +- Consolidating similar error handling patterns |
| 49 | +- Removing unnecessary comments |
| 50 | +- Converting complex expressions to more readable forms |
| 51 | +- Applying idiomatic language features |
| 52 | + |
| 53 | +## When to Use This Workflow |
| 54 | + |
| 55 | +The Code Simplifier is particularly valuable: |
| 56 | + |
| 57 | +- **After Rapid Development** - Cleans up code written during feature sprints |
| 58 | +- **With AI-Assisted Development** - Ensures speed doesn't sacrifice simplicity |
| 59 | +- **For Continuous Quality** - Maintains code quality as an ongoing practice, not periodic sprints |
| 60 | +- **In Active Codebases** - Works best in repositories with regular changes |
| 61 | + |
| 62 | +## Example Pull Requests |
| 63 | + |
| 64 | +From the original gh-aw repository (83% merge rate): |
| 65 | +- [Extract action mode helper to reduce duplication](https://github.com/github/gh-aw/pull/13982) |
| 66 | +- [Simplify validation config code for clarity](https://github.com/github/gh-aw/pull/13118) |
| 67 | + |
| 68 | +## Customization |
| 69 | + |
| 70 | +You can customize the workflow by editing the source file: |
| 71 | + |
| 72 | +```bash |
| 73 | +gh aw edit code-simplifier |
| 74 | +``` |
| 75 | + |
| 76 | +Common customizations: |
| 77 | +- **Change schedule** - Adjust how often it runs (default: daily) |
| 78 | +- **Modify scope** - Change the time window for recent changes (default: 24 hours) |
| 79 | +- **Add language-specific rules** - Include conventions specific to your project's languages |
| 80 | +- **Adjust validation** - Customize test, lint, and build commands for your build system |
| 81 | + |
| 82 | +## Configuration |
| 83 | + |
| 84 | +The workflow uses these default settings: |
| 85 | + |
| 86 | +- **Schedule**: Runs daily |
| 87 | +- **Scope**: Analyzes code changed in the last 24 hours |
| 88 | +- **PR Labels**: `refactoring`, `code-quality`, `automation` |
| 89 | +- **Timeout**: 30 minutes |
| 90 | +- **Expires**: PRs auto-close after 1 day if not merged |
| 91 | + |
| 92 | +## Tips for Success |
| 93 | + |
| 94 | +1. **Review Promptly** - The workflow creates PRs that expire in 1 day, so review them quickly |
| 95 | +2. **Trust the Tests** - The workflow validates all changes with your test suite |
| 96 | +3. **Provide Feedback** - Close PRs that miss the mark; the workflow learns from patterns |
| 97 | +4. **Set Clear Conventions** - Document coding standards in your repository for better results |
| 98 | +5. **Start Small** - Run it for a week to see the kinds of improvements it suggests |
| 99 | + |
| 100 | +## Source |
| 101 | + |
| 102 | +This workflow is adapted from [Peli's Agent Factory](https://github.github.io/gh-aw/blog/2026-01-13-meet-the-workflows-continuous-simplicity/), where it achieved an 83% merge rate across 6 PRs in the gh-aw repository. |
| 103 | + |
| 104 | +## Related Workflows |
| 105 | + |
| 106 | +- [Update Docs](update-docs.md) - Maintains documentation automatically |
| 107 | +- [Daily Test Coverage Improver](daily-test-improver.md) - Improves test coverage |
| 108 | +- [Daily Performance Improver](daily-perf-improver.md) - Optimizes code performance |
0 commit comments