Skip to content

Raishin/kiro-power-code-simplifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code Simplifier - Kiro Power

A comprehensive Kiro Power for simplifying and refining code across multiple programming languages and frameworks. Enhances code clarity, consistency, and maintainability while preserving all functionality.

Overview

Code Simplifier helps you write cleaner, more maintainable code by providing:

  • Framework-specific best practices for 9+ frameworks
  • Language-specific patterns for 8+ programming languages
  • Up-to-date documentation via Context7 MCP integration
  • Automated code review through agent hooks
  • Manual on-demand reviews when you need them

Supported Languages

  • C - Memory management, pointers, and best practices
  • C# - LINQ, async/await, and .NET conventions
  • Java - Modern Java 17+ features, streams, and design patterns
  • JavaScript - ES6+ features and modern patterns
  • Kotlin - Null safety, coroutines, and idiomatic patterns
  • Python - Pythonic patterns and best practices
  • Rust - Ownership, borrowing, and error handling
  • TypeScript - Type system, generics, and React patterns

Supported Frameworks

  • Spring Boot (Java) - Dependency injection, REST APIs, JPA patterns
  • Django (Python) - Models, views, QuerySet optimization
  • FastAPI (Python) - Async patterns, Pydantic, dependency injection
  • Flask (Python) - Blueprints, application factory, SQLAlchemy
  • FastMCP (Python) - MCP server patterns and tool definitions
  • Laravel (PHP) - Eloquent, routing, and Laravel conventions
  • Symfony (PHP) - Symfony best practices and standards
  • PHP - General PHP patterns and best practices

Features

🎯 Core Principles

  1. Preserve Functionality - Never change what code does, only how it does it
  2. Enhance Clarity - Make code easier to understand and maintain
  3. Apply Standards - Follow framework-specific conventions
  4. Maintain Balance - Avoid over-simplification
  5. Focus Scope - Prioritize recently modified code

📚 Steering Files

17 comprehensive guides covering:

  • Universal principles (core.md)
  • Language-specific patterns (8 files)
  • Framework-specific conventions (8 files)

Access guides on-demand based on your current work context.

🔌 MCP Integration

Uses Context7 MCP to provide up-to-date documentation:

  • Query latest framework best practices
  • Access current library documentation
  • Ensure recommendations follow latest conventions

🎣 Agent Hooks

Two hooks for automated code simplification:

1. Manual Trigger Hook

  • File: hooks/simplify-on-demand.json
  • Type: User-triggered
  • Status: Ready to use
  • Purpose: Click to get code review on-demand

2. Automatic Hook (Disabled by Default)

  • File: hooks/simplify-on-save.json
  • Type: File-edited (automatic)
  • Status: ⚠️ Disabled by default
  • Purpose: Auto-review on every file save
  • Note: Enable explicitly if you want continuous feedback

Installation

Via Kiro Powers UI

  1. Open Kiro Powers panel
  2. Search for "Code Simplifier"
  3. Click "Install"
  4. The power and hooks will be available immediately

Via Local Directory

  1. Clone this repository
  2. In Kiro Powers UI, click "Add Custom Power"
  3. Select "Local Directory"
  4. Browse to this directory
  5. Click "Add"

Usage

Quick Start

  1. Activate the power to read documentation:

    Call action "activate" with powerName="code-simplifier"
    
  2. Read a specific guide for your language/framework:

    Call action "readSteering" with powerName="code-simplifier", steeringFile="python-django.md"
    
  3. Query up-to-date docs via Context7:

    Use resolve-library-id to find library
    Use query-docs to get current best practices
    

Using Hooks

Manual Review

  1. Install hooks (if not auto-installed with power):

    # Linux/macOS
    cd hooks && ./install-hooks.sh
    
    # Windows
    cd hooks && install-hooks.bat
  2. Open Agent Hooks panel in Kiro

  3. Find "Simplify Code On-Demand"

  4. Click trigger when you want a review

For testing: See hooks/TESTING.md for comprehensive testing guide

Automatic Review (Optional)

  1. Open Agent Hooks panel
  2. Find "Simplify Code On Save (Disabled by Default)"
  3. Enable the hook
  4. Code will be reviewed automatically on every save

Supported file types: .js, .ts, .jsx, .tsx, .py, .java, .kt, .rs, .c, .cpp, .cs, .php

Common Workflows

Workflow 1: Manual Code Review

  • Modify your code
  • Trigger the on-demand hook
  • Review suggestions
  • Apply improvements

Workflow 2: Framework-Specific Refactoring

  • Identify the framework being used
  • Load the appropriate steering file
  • Query Context7 for current best practices
  • Apply framework-specific patterns

Workflow 3: Continuous Feedback

  • Enable the automatic hook
  • Write code normally
  • Get feedback on every save
  • Disable when you want uninterrupted flow

Configuration

Context7 API Key

This power requires a Context7 API key for accessing up-to-date documentation.

  1. Get your API key from https://context7.com
  2. Update mcp.json with your key:
    {
    	"mcpServers": {
    		"context7": {
    			"command": "npx",
    			"args": [
    				"-y",
    				"@upstash/context7-mcp",
    				"--api-key",
    				"YOUR_KEY_HERE"
    			]
    		}
    	}
    }

Customizing Hooks

You can customize the hooks by editing the JSON files in the hooks/ directory:

  • Modify file patterns to watch different file types
  • Adjust prompts to focus on specific aspects
  • Change trigger conditions

See hooks/README.md for more details.

Best Practices

When to Simplify

Do simplify when:

  • Code has unnecessary nesting or complexity
  • Variable/function names are unclear
  • Logic is duplicated
  • Framework conventions aren't followed
  • Code is harder to understand than necessary

Don't simplify when:

  • Code is already clear and maintainable
  • Simplification would reduce readability
  • Complexity is inherent to the problem
  • Existing abstractions serve a clear purpose

Simplification Patterns

Common patterns across all languages:

  • Reduce nesting with early returns
  • Use clear, descriptive names
  • Eliminate code duplication
  • Follow framework conventions
  • Avoid nested ternary operators
  • Prefer explicit over clever code

Directory Structure

code-simplifier/
├── README.md                    # This file
├── POWER.md                     # Power documentation
├── LICENSE                      # License file
├── mcp.json                     # MCP server configuration
├── hooks/                       # Agent hooks
│   ├── README.md               # Hooks documentation
│   ├── simplify-on-demand.json # Manual trigger hook
│   └── simplify-on-save.json   # Automatic hook (disabled)
└── steering/                    # Language/framework guides
    ├── core.md                 # Universal principles
    ├── c.md                    # C language guide
    ├── csharp.md               # C# language guide
    ├── java.md                 # Java language guide
    ├── java-spring.md          # Spring Boot framework guide
    ├── js.md                   # JavaScript guide
    ├── kotlin.md               # Kotlin language guide
    ├── python.md               # Python language guide
    ├── python-django.md        # Django framework guide
    ├── python-fastapi.md       # FastAPI framework guide
    ├── python-fastmcp.md       # FastMCP framework guide
    ├── python-flask.md         # Flask framework guide
    ├── rust.md                 # Rust language guide
    ├── typescript.md           # TypeScript guide
    ├── php.md                  # PHP language guide
    ├── php-laravel.md          # Laravel framework guide
    └── php-symfony.md          # Symfony framework guide

Contributing

Contributions are welcome! To add support for a new language or framework:

  1. Create a new steering file in steering/
  2. Follow the existing structure and style
  3. Include:
    • Naming conventions
    • Language/framework-specific patterns
    • Bad vs good code examples
    • Simplification checklist
    • Additional resources
  4. Update POWER.md to list the new guide
  5. Submit a pull request

Troubleshooting

Context7 MCP Connection Issues

  • Verify API key is set correctly in mcp.json
  • Check internet connection
  • Restart Kiro to reconnect MCP server

Hooks Not Appearing

  • Ensure hooks are in the hooks/ directory
  • Check JSON syntax is valid
  • Restart Kiro if needed

Over-Simplification

  • Review the "Maintain Balance" principle in core.md
  • Provide feedback: "Keep it more explicit"
  • Request specific aspects to preserve

License

See LICENSE file for details.

Resources

Version

1.0.0 - Initial release with support for 8 languages and 9 frameworks

Author

Raishin


Keywords: code-simplification, refactoring, code-quality, maintainability, clean-code, code-review

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors