Skip to content

Conversation

@mona-codes-x
Copy link

@mona-codes-x mona-codes-x commented Oct 17, 2025

User description

feat: Add enhanced Clean Code Agent

Qodo challenge category - Best agent for clean code description

PR Body

🚀 Introducing the Clean Code Agent: AI-Powered Code Quality Assistant

This PR introduces the Clean Code Agent, an advanced AI-powered tool designed to help developers maintain readable, maintainable, and well-structured codebases.

🔍 Key Features

  1. Automated Code Analysis and Refactoring

    • Comprehensive analysis of code for readability, maintainability, and structure issues.
    • Provides actionable diff-style refactoring previews for easy implementation of improvements.
    • Detects and suggests fixes for code smells, naming issues, and long parameter lists.
  2. Intelligent Code Generation

    • Automatic Docstring Generation: Identifies public functions without documentation and generates complete, accurate docstrings.
    • Unit Test Scaffolding: Creates full unit test files with proper structure for public functions.
    • Promotes better documentation and testing practices across teams.
  3. Advanced Integrations

    • Supports running command-line linters (ESLint, Pylint, etc.) and using their output for enhanced analysis.
    • Allows custom rule sets for team-specific coding standards.
    • Seamless CI/CD integration with configurable severity thresholds.
  4. CI/CD Ready for Automated Quality Gates

    • Includes pre-configured templates for GitHub Actions, GitLab CI, Jenkins, and Azure DevOps.
    • Enables automated pull request checks to ensure code quality standards are maintained.
    • Provides structured JSON output for easy integration with existing pipelines.

📁 Files Added

agents/clean-code-agent/
├── agent.toml                        # Main agent configuration
├── agent.yaml                        # YAML configuration (equivalent to agent.toml)
├── README.md                         # Comprehensive feature documentation
├── examples/
│   ├── usage.md                      # Detailed usage examples and options
│   ├── sample_code.py                # Before/after refactoring demonstration
│   ├── utils.py                      # Test file for docstring and test generation
│   ├── ci-configs/
│   │   ├── github-actions.yml        # GitHub Actions CI/CD template
│   │   ├── gitlab-ci.yml             # GitLab CI/CD template
│   │   ├── jenkins-pipeline.groovy   # Jenkins CI/CD template
│   │   └── azure-devops.yml          # Azure DevOps CI/CD template
│   └── tests/
│       └── test_utils.py             # Generated unit test scaffold example

🧪 Verification

The agent has been thoroughly tested, demonstrating:

  • Successful generation of high-quality docstrings
  • Creation of complete, runnable unit test scaffolds
  • Production of actionable code refactoring suggestions

🎯 Usage Examples

Basic Code Analysis:

qodo clean_code --set files="src/" --set language="python"

Generate Documentation and Tests:

qodo clean_code --set files="src/my_module.py" --set language="python" --set generate_docstrings=true --set generate_tests=true

Integrated with Existing Linters:

qodo clean_code --set files="src/" --set language="javascript" --set linter_command="eslint ."

🔒 Implementation Details

  • Compatible with Qodo Command ecosystem
  • No external dependencies introduced
  • Maintains backward compatibility
  • Structured output for machine-to-machine integration

This agent represents a significant advancement in AI-assisted code quality tools, making it easier for teams to maintain exceptional code standards and developer productivity.


PR Type

Enhancement


Description

  • Introduces Clean Code Agent for AI-powered code quality analysis

  • Provides automated code refactoring with diff-style previews

  • Generates missing docstrings and unit test scaffolds automatically

  • Includes CI/CD templates for GitHub Actions, GitLab, Jenkins, Azure DevOps

  • Supports linter integration and custom rule sets for team standards


Diagram Walkthrough

flowchart LR
  A["Source Code"] -->|"analyze"| B["Clean Code Agent"]
  B -->|"detect issues"| C["Code Smells & Naming"]
  B -->|"generate"| D["Docstrings & Tests"]
  B -->|"integrate"| E["CI/CD Pipelines"]
  C -->|"output"| F["Markdown/JSON Report"]
  D -->|"output"| F
  E -->|"output"| F
Loading

File Walkthrough

Relevant files
Configuration changes
6 files
agent.toml
Main agent configuration with command definition                 
+100/-0 
agent.yaml
YAML equivalent of agent configuration                                     
+120/-0 
github-actions.yml
GitHub Actions CI/CD integration template                               
+25/-0   
gitlab-ci.yml
GitLab CI/CD integration template                                               
+13/-0   
jenkins-pipeline.groovy
Jenkins pipeline CI/CD integration template                           
+16/-0   
azure-devops.yml
Azure DevOps CI/CD integration template                                   
+21/-0   
Documentation
2 files
README.md
Comprehensive documentation of agent features                       
+44/-0   
usage.md
Detailed usage examples and command options                           
+75/-0   
Enhancement
2 files
sample_code.py
Before/after refactoring demonstration code                           
+121/-0 
utils.py
Utility functions with docstrings and type hints                 
+32/-0   
Tests
1 files
test_utils.py
Generated unit test scaffold for utilities                             
+28/-0   

@qodo-merge-for-open-source
Copy link
Contributor

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
Sensitive information exposure

Description: Printing PII-like fields (user name and country) to stdout can lead to sensitive
information exposure in logs; consider structured logging with redaction or omit sensitive
fields.
sample_code.py [81-82]

Referred Code
print(f"Creating user {profile.name} from {profile.country}")
return {"name": profile.name, "email": profile.email}
Secret handling in CI

Description: Use of pipeline environment variable for API key may expose secrets in logs if downstream
commands echo env; ensure commands do not print the token and mask logs.
jenkins-pipeline.groovy [3-15]

Referred Code
environment {
    QODO_API_KEY = credentials('qodo-api-key')
}
stages {
    stage('Clean Code Check') {
        steps {
            script {
                sh 'npm install -g @qodo-ai/command'
                sh 'qodo clean_code --set files="." --set language="python" --set report_format="json"'
            }
        }
    }
}
Secret handling in CI

Description: GitHub Actions job passes an API key via environment; ensure steps and the agent avoid
printing the secret and that repository has secrets masking enabled.
github-actions.yml [14-25]

Referred Code
- name: Install Qodo
  run: npm install -g @qodo-ai/command

- name: Run Clean Code Agent
  run: |
    qodo clean_code \
      --set files="." \
      --set language="python" \
      --set report_format="json" \
      --set generate_docstrings=true
  env:
    QODO_API_KEY: ${{ secrets.QODO_API_KEY }}
Secret handling in CI

Description: GitLab CI exposes API key via variable; verify mask/protect flags are set and that command
outputs do not leak the secret.
gitlab-ci.yml [8-12]

Referred Code
  - npm install -g @qodo-ai/command
  - qodo clean_code --set files="." --set language="python" --set report_format="json"
variables:
  QODO_API_KEY: $QODO_API_KEY
rules:
Secret handling in CI

Description: Azure DevOps pipeline passes API key env; ensure variable is marked secret and outputs are
masked to prevent leakage in logs.
azure-devops.yml [17-21]

Referred Code
- script: |
    qodo clean_code --set files="." --set language="python" --set report_format="json"
  displayName: 'Run Clean Code Agent'
  env:
    QODO_API_KEY: $(QODO_API_KEY)
Ticket Compliance
🎫 No ticket provided
- [ ] Create ticket/issue <!-- /create_ticket --create_ticket=true -->

</details></td></tr>
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
No custom compliance provided

Follow the guide to enable custom compliance check.

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-merge-for-open-source
Copy link
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
High-level
Agent duplicates existing mature tooling

The agent's functionality, such as checking for code smells and naming
conventions, duplicates existing deterministic tools like linters. This
introduces unpredictability into CI/CD pipelines. The agent should instead focus
on unique capabilities like identifying architectural flaws or complex logic
issues.

Examples:

agents/clean-code-agent/agent.toml [9-16]
**Core Analysis Task:**
Analyze the provided source code files for readability, maintainability, and structure. For each issue, provide the file path, line number, a clear description, and a 'diff-style' refactoring preview.

You should look for:
- **Meaningful Naming:** Unclear variable, function, or class names.
- **Function Complexity:** Functions that are too long or have too many responsibilities.
- **Code Smells:** Duplicated code, dead code, long parameter lists.
- **Documentation Quality:** Unclear, outdated, or redundant comments.

Solution Walkthrough:

Before:

# agent.toml
instructions = """
You are an expert AI assistant...
Analyze the provided source code files for readability, maintainability, and structure.

You should look for:
- **Meaningful Naming:** Unclear variable, function, or class names.
- **Function Complexity:** Functions that are too long...
- **Code Smells:** Duplicated code, dead code, long parameter lists.
- **Documentation Quality:** Unclear, outdated, or redundant comments.
...
"""

After:

# agent.toml
instructions = """
You are an expert AI assistant specializing in advanced code analysis.
Your goal is to identify issues that traditional linters and static analysis tools often miss.

You should look for:
- **Architectural Smells:** Poor separation of concerns, cyclic dependencies.
- **Complex Logical Flaws:** Potential race conditions, inefficient algorithms.
- **API Design Issues:** Inconsistent API patterns, non-intuitive function signatures.
...
Assume basic linting has already been performed. Focus your analysis on higher-level conceptual and structural problems.
"""
Suggestion importance[1-10]: 9

__

Why: This is a critical high-level suggestion that correctly identifies a fundamental design weakness—the agent's core tasks overlap with mature, deterministic tools, making it potentially unreliable for CI/CD—and proposes a valuable strategic pivot.

High
Possible issue
Fix invalid character in import

Fix the invalid import path in test_utils.py. The path
agents.clean-code-agent.examples.utils contains a hyphen, which is a SyntaxError
in Python, and should be replaced with an underscore.

agents/clean-code-agent/examples/tests/test_utils.py [4]

-from agents.clean-code-agent.examples.utils import add_numbers, subtract_numbers
+from agents.clean_code_agent.examples.utils import add_numbers, subtract_numbers
  • Apply / Chat
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a SyntaxError in the Python import statement due to a hyphen in the module path, which makes the example test code non-functional as written.

High
  • More

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants