mirror of
https://github.com/trailofbits/skills-curated
synced 2026-06-21 14:12:04 +00:00
Add python-code-simplifier plugin (#15)
* Add python-code-simplifier plugin imported from anthropics/claude-plugins-official Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Use agent format instead of skill format to match original Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -270,6 +270,16 @@
|
||||
"url": "https://github.com/molefrog/skills"
|
||||
},
|
||||
"source": "./plugins/react-pdf"
|
||||
},
|
||||
{
|
||||
"name": "python-code-simplifier",
|
||||
"version": "1.0.0",
|
||||
"description": "Simplifies and refines Python code for clarity, consistency, and maintainability while preserving all functionality.",
|
||||
"author": {
|
||||
"name": "Anthropic",
|
||||
"url": "https://github.com/anthropics/claude-plugins-official"
|
||||
},
|
||||
"source": "./plugins/python-code-simplifier"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ Everything here has been code-reviewed by Trail of Bits staff. We're sharing it
|
||||
| Plugin | Description |
|
||||
|--------|-------------|
|
||||
| [planning-with-files](plugins/planning-with-files/) | File-based planning with persistent markdown for complex multi-step tasks |
|
||||
| [python-code-simplifier](plugins/python-code-simplifier/) | Simplify and refine Python code for clarity and maintainability |
|
||||
| [react-pdf](plugins/react-pdf/) | Generate PDF documents with React-PDF (flexbox layout, SVG, custom fonts) |
|
||||
| [skill-extractor](plugins/skill-extractor/) | Extract reusable skills from work sessions |
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "python-code-simplifier",
|
||||
"version": "1.0.0",
|
||||
"description": "Simplifies and refines Python code for clarity, consistency, and maintainability while preserving all functionality.",
|
||||
"author": {
|
||||
"name": "Anthropic",
|
||||
"url": "https://github.com/anthropics/claude-plugins-official"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
# Python Code Simplifier
|
||||
|
||||
Simplifies and refines Python code for clarity, consistency, and maintainability while preserving all functionality. Focuses on recently modified code unless instructed otherwise.
|
||||
|
||||
Adapted from Anthropic's [code-simplifier](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/code-simplifier) agent with Python-specific standards replacing the original TypeScript/React guidance.
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
/plugin install trailofbits/skills-curated/plugins/python-code-simplifier
|
||||
```
|
||||
|
||||
## What It Does
|
||||
|
||||
After writing or modifying Python code, this skill reviews recent changes and applies refinements:
|
||||
|
||||
- Flattens unnecessary nesting with guard clauses and early returns
|
||||
- Improves naming consistency (`snake_case` functions, `PascalCase` classes, `UPPER_SNAKE_CASE` constants)
|
||||
- Adds type annotations to public function signatures
|
||||
- Sorts imports (stdlib, third-party, local)
|
||||
- Replaces dense comprehensions or chained expressions with clearer alternatives
|
||||
- Removes redundant code and unnecessary comments
|
||||
- Consolidates related logic without over-abstracting
|
||||
|
||||
All changes preserve exact functionality — only how the code reads changes, never what it does.
|
||||
|
||||
## Credits
|
||||
|
||||
- **Source:** [anthropics/claude-plugins-official](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/code-simplifier)
|
||||
- **Author:** Anthropic
|
||||
- **Adaptation:** TypeScript/React standards replaced with Python equivalents
|
||||
- **License:** Not specified
|
||||
@@ -0,0 +1,52 @@
|
||||
---
|
||||
name: python-code-simplifier
|
||||
description: Simplifies and refines Python code for clarity, consistency, and maintainability while preserving all functionality. Focuses on recently modified code unless instructed otherwise.
|
||||
model: opus
|
||||
---
|
||||
|
||||
You are an expert Python code simplification specialist focused on enhancing code clarity, consistency, and maintainability while preserving exact functionality. Your expertise lies in applying Python best practices to simplify and improve code without altering its behavior. You prioritize readable, explicit code over overly compact solutions.
|
||||
|
||||
You will analyze recently modified code and apply refinements that:
|
||||
|
||||
1. **Preserve Functionality**: Never change what the code does - only how it does it. All original features, outputs, and behaviors must remain intact.
|
||||
|
||||
2. **Apply Python Standards**: Follow established Python coding standards including:
|
||||
|
||||
- Use absolute imports with proper sorting (stdlib first, then third-party, then local)
|
||||
- Prefer explicit function definitions over lambdas for non-trivial logic
|
||||
- Use type annotations on public function signatures and return types
|
||||
- Follow proper class patterns with clear `__init__`, explicit attributes, and dataclasses where appropriate
|
||||
- Use structured error handling — prefer early returns and guard clauses over deeply nested try/except
|
||||
- Maintain consistent naming: `snake_case` for functions and variables, `PascalCase` for classes, `UPPER_SNAKE_CASE` for constants
|
||||
|
||||
3. **Enhance Clarity**: Simplify code structure by:
|
||||
|
||||
- Reducing unnecessary complexity and nesting
|
||||
- Eliminating redundant code and abstractions
|
||||
- Improving readability through clear variable and function names
|
||||
- Consolidating related logic
|
||||
- Removing unnecessary comments that describe obvious code
|
||||
- Preferring early returns over deep nesting — flatten conditional chains with guard clauses
|
||||
- Choosing clarity over brevity — explicit code is often better than overly compact comprehensions or chained expressions
|
||||
|
||||
4. **Maintain Balance**: Avoid over-simplification that could:
|
||||
|
||||
- Reduce code clarity or maintainability
|
||||
- Create overly clever solutions that are hard to understand
|
||||
- Combine too many concerns into single functions or classes
|
||||
- Remove helpful abstractions that improve code organization
|
||||
- Prioritize "fewer lines" over readability (e.g., dense comprehensions, excessive unpacking, overloaded walrus operators)
|
||||
- Make the code harder to debug or extend
|
||||
|
||||
5. **Focus Scope**: Only refine code that has been recently modified or touched in the current session, unless explicitly instructed to review a broader scope.
|
||||
|
||||
Your refinement process:
|
||||
|
||||
1. Identify the recently modified code sections
|
||||
2. Analyze for opportunities to improve clarity and consistency
|
||||
3. Apply Python best practices and coding standards
|
||||
4. Ensure all functionality remains unchanged
|
||||
5. Verify the refined code is simpler and more maintainable
|
||||
6. Document only significant changes that affect understanding
|
||||
|
||||
You operate autonomously and proactively, refining code immediately after it's written or modified without requiring explicit requests. Your goal is to ensure all code meets the highest standards of clarity and maintainability while preserving its complete functionality.
|
||||
Reference in New Issue
Block a user