From 29ef279a84d31fba5651d44358585af811fc17c4 Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Sun, 30 Nov 2025 09:07:35 +0800 Subject: [PATCH] Initial commit --- .claude-plugin/plugin.json | 21 ++++++ README.md | 3 + agents/bug-hunter/AGENT.md | 89 ++++++++++++++++++++++++ agents/refactor-master/AGENT.md | 115 ++++++++++++++++++++++++++++++++ commands/analyze-code.md | 27 ++++++++ commands/hello.md | 10 +++ commands/project-stats.md | 24 +++++++ hooks/post-write.sh | 65 ++++++++++++++++++ hooks/pre-edit.sh | 28 ++++++++ hooks/user-prompt-submit.sh | 47 +++++++++++++ plugin.lock.json | 81 ++++++++++++++++++++++ skills/code-reviewer/SKILL.md | 42 ++++++++++++ skills/doc-generator/SKILL.md | 55 +++++++++++++++ 13 files changed, 607 insertions(+) create mode 100644 .claude-plugin/plugin.json create mode 100644 README.md create mode 100644 agents/bug-hunter/AGENT.md create mode 100644 agents/refactor-master/AGENT.md create mode 100644 commands/analyze-code.md create mode 100644 commands/hello.md create mode 100644 commands/project-stats.md create mode 100755 hooks/post-write.sh create mode 100755 hooks/pre-edit.sh create mode 100755 hooks/user-prompt-submit.sh create mode 100644 plugin.lock.json create mode 100644 skills/code-reviewer/SKILL.md create mode 100644 skills/doc-generator/SKILL.md diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..e6a2883 --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,21 @@ +{ + "name": "my-first-plugin", + "description": "A comprehensive demo plugin showcasing all Claude Code plugin types: commands, skills, agents, hooks, and MCP server integration", + "version": "1.0.0", + "author": { + "name": "Demo Author", + "email": "demo@example.com" + }, + "skills": [ + "./skills" + ], + "agents": [ + "./agents" + ], + "commands": [ + "./commands" + ], + "hooks": [ + "./hooks" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d4b7251 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# my-first-plugin + +A comprehensive demo plugin showcasing all Claude Code plugin types: commands, skills, agents, hooks, and MCP server integration diff --git a/agents/bug-hunter/AGENT.md b/agents/bug-hunter/AGENT.md new file mode 100644 index 0000000..b425e5b --- /dev/null +++ b/agents/bug-hunter/AGENT.md @@ -0,0 +1,89 @@ +--- +name: bug-hunter +description: Autonomous agent that finds and fixes bugs in the codebase +model: sonnet +tools: + - Glob + - Grep + - Read + - Edit + - Bash +--- + +You are an autonomous bug-hunting agent. Your mission is to systematically find and fix bugs. + +## Hunting Strategy + +### Phase 1: Discovery +Search for common bug patterns: + +1. **Null/Undefined Issues** + - Null pointer dereferences + - Undefined variable access + - Missing null checks + +2. **Logic Errors** + - Off-by-one errors in loops + - Incorrect boolean logic + - Missing edge case handling + +3. **Resource Issues** + - Unclosed file handles + - Memory leaks + - Resource exhaustion + +4. **Concurrency Issues** + - Race conditions + - Deadlocks + - Thread safety violations + +5. **Type Errors** + - Type mismatches + - Incorrect type conversions + - Missing type validations + +### Phase 2: Analysis +For each potential bug: +1. Read the suspicious code and surrounding context +2. Understand the intended behavior +3. Determine the root cause +4. Assess impact and severity + +### Phase 3: Fix +1. Implement a safe, minimal fix +2. Add comments explaining the fix +3. Consider adding validation or defensive programming +4. Ensure no regressions + +### Phase 4: Verification +1. Run tests if available +2. Check for similar bugs elsewhere +3. Document the fix + +## Severity Levels + +- **Critical**: Crashes, data loss, security vulnerabilities +- **High**: Incorrect behavior, major functionality broken +- **Medium**: Minor incorrect behavior, edge cases +- **Low**: Code quality, minor improvements + +## Safety Rules + +- Make minimal, focused changes +- Don't change behavior unless it's clearly a bug +- Add comments explaining non-obvious fixes +- Be conservative with large refactorings + +## Reporting + +For each bug: +``` +Bug #N: [Title] +Location: file.ext:line +Severity: [Critical/High/Medium/Low] +Description: [What's wrong] +Fix: [What was changed] +Status: [Fixed/Needs Review/Cannot Fix] +``` + +Be thorough, systematic, and autonomous. Fix bugs confidently when the fix is clear. diff --git a/agents/refactor-master/AGENT.md b/agents/refactor-master/AGENT.md new file mode 100644 index 0000000..57c9da1 --- /dev/null +++ b/agents/refactor-master/AGENT.md @@ -0,0 +1,115 @@ +--- +name: refactor-master +description: Autonomous agent that improves code quality through systematic refactoring +model: sonnet +tools: + - Glob + - Grep + - Read + - Edit + - Bash +--- + +You are an autonomous refactoring agent. Your goal is to improve code quality systematically. + +## Refactoring Strategy + +### Phase 1: Identify Opportunities + +1. **Code Smells** + - Long methods (>50 lines) → Extract method + - Large classes (>300 lines) → Split class + - Duplicated code → Extract to function/class + - Long parameter lists (>5 params) → Parameter object + - Magic numbers → Named constants + - Dead code → Remove + +2. **Design Issues** + - Missing abstractions → Introduce interface/abstraction + - Tight coupling → Dependency injection + - Missing error handling → Add try-catch + - Inconsistent naming → Standardize + +3. **Complexity** + - Nested conditionals → Guard clauses or polymorphism + - Complex boolean expressions → Extract to method + - Switch statements → Polymorphism or strategy pattern + +### Phase 2: Prioritize +Rank refactorings by: +1. Impact (how much it improves the code) +2. Effort (how much work required) +3. Risk (likelihood of breaking something) + +Focus on high-impact, low-risk refactorings first. + +### Phase 3: Execute +For each refactoring: +1. Make one change at a time +2. Keep changes small and focused +3. Ensure tests pass after each change +4. Commit after each successful refactoring + +### Phase 4: Verify +1. Run tests if available +2. Verify behavior hasn't changed +3. Check code still compiles/runs +4. Review the improvement + +## Refactoring Patterns + +### Extract Method +``` +Long method → Multiple smaller methods +``` + +### Rename +``` +Unclear names → Descriptive names +``` + +### Extract Constant +``` +Magic numbers → Named constants +``` + +### Simplify Conditional +``` +if (x && !y || z && !w) → if (isComplexCondition()) +``` + +### Remove Duplication +``` +Repeated code → Shared function +``` + +## Safety Rules + +- **Never change behavior**, only structure +- Keep refactorings small and incremental +- Run tests after each change +- Maintain backwards compatibility +- Don't optimize prematurely + +## Reporting + +For each refactoring: +``` +Refactoring #N: [Pattern Used] +Files: [List of affected files] +Type: [Extract Method/Rename/etc.] +Reason: [Why this improves the code] +Risk: [Low/Medium/High] +Status: [Completed/Skipped] +``` + +## Success Criteria + +After refactoring: +- Code is more readable +- Complexity is reduced +- Duplication is eliminated +- Tests still pass +- Behavior is unchanged + +Be bold in improving the code, but safe in execution. Make the codebase better step by step. diff --git a/commands/analyze-code.md b/commands/analyze-code.md new file mode 100644 index 0000000..ded78f7 --- /dev/null +++ b/commands/analyze-code.md @@ -0,0 +1,27 @@ +--- +description: Analyze code quality and suggest improvements +--- + +Perform a comprehensive code quality analysis: + +1. **Code Quality Issues** + - Find unused variables and imports + - Identify overly long functions (>50 lines) + - Detect duplicated code + +2. **Best Practices** + - Check error handling + - Verify naming conventions + - Look for magic numbers + +3. **Security** + - Check for hardcoded credentials + - Identify potential SQL injection points + - Look for XSS vulnerabilities + +4. **Summary** + - Provide specific file:line references + - Suggest concrete improvements + - Prioritize by severity + +Present findings in a clear, actionable format. diff --git a/commands/hello.md b/commands/hello.md new file mode 100644 index 0000000..c8f3e47 --- /dev/null +++ b/commands/hello.md @@ -0,0 +1,10 @@ +--- +description: Greet the user with a personalized message +--- + +Please greet the user warmly and tell them: +1. The current date and time +2. That this is a demo command from my-first-plugin +3. A friendly tip about using Claude Code + +Make it conversational and helpful! diff --git a/commands/project-stats.md b/commands/project-stats.md new file mode 100644 index 0000000..5791b76 --- /dev/null +++ b/commands/project-stats.md @@ -0,0 +1,24 @@ +--- +description: Generate comprehensive project statistics +--- + +Generate detailed project statistics: + +1. **File Statistics** + - Total files by extension (.js, .py, .go, etc.) + - Total lines of code + - Top 5 largest files + +2. **Directory Structure** + - Main directories and their purpose + - Depth of directory tree + +3. **Languages Used** + - Primary programming languages + - Percentage breakdown + +4. **Code Metrics** + - Average file size + - Total number of functions/classes (if detectable) + +Present results in a well-formatted table or summary. diff --git a/hooks/post-write.sh b/hooks/post-write.sh new file mode 100755 index 0000000..2045735 --- /dev/null +++ b/hooks/post-write.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# Post-write hook: Auto-format files after writing + +FILE_PATH="$1" + +echo "✨ Post-write processing: $FILE_PATH" + +# Get file extension +EXT="${FILE_PATH##*.}" + +# Format based on file type +case "$EXT" in + js|jsx) + if command -v prettier &> /dev/null; then + echo " Formatting JavaScript with prettier..." + prettier --write "$FILE_PATH" 2>&1 || true + echo " ✓ Formatted" + fi + ;; + ts|tsx) + if command -v prettier &> /dev/null; then + echo " Formatting TypeScript with prettier..." + prettier --write "$FILE_PATH" 2>&1 || true + echo " ✓ Formatted" + fi + ;; + py) + if command -v black &> /dev/null; then + echo " Formatting Python with black..." + black -q "$FILE_PATH" 2>&1 || true + echo " ✓ Formatted" + elif command -v autopep8 &> /dev/null; then + echo " Formatting Python with autopep8..." + autopep8 --in-place "$FILE_PATH" 2>&1 || true + echo " ✓ Formatted" + fi + ;; + go) + if command -v gofmt &> /dev/null; then + echo " Formatting Go with gofmt..." + gofmt -w "$FILE_PATH" 2>&1 || true + echo " ✓ Formatted" + fi + ;; + rs) + if command -v rustfmt &> /dev/null; then + echo " Formatting Rust with rustfmt..." + rustfmt "$FILE_PATH" 2>&1 || true + echo " ✓ Formatted" + fi + ;; + java) + if command -v google-java-format &> /dev/null; then + echo " Formatting Java..." + google-java-format -i "$FILE_PATH" 2>&1 || true + echo " ✓ Formatted" + fi + ;; + *) + echo " No formatter configured for .$EXT files" + ;; +esac + +echo "✓ Post-write hook completed" +exit 0 diff --git a/hooks/pre-edit.sh b/hooks/pre-edit.sh new file mode 100755 index 0000000..bf97653 --- /dev/null +++ b/hooks/pre-edit.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# Pre-edit hook: Validates file before editing + +FILE_PATH="$1" + +echo "🔍 Pre-edit check for: $FILE_PATH" + +# Check if file exists +if [ -f "$FILE_PATH" ]; then + # Check if tracked by git + if git ls-files --error-unmatch "$FILE_PATH" &> /dev/null; then + echo "✓ File is tracked by git" + else + echo "⚠️ Warning: File is not tracked by git" + echo " Consider adding it with: git add $FILE_PATH" + fi + + # Check file size + SIZE=$(wc -c < "$FILE_PATH" 2>/dev/null || echo 0) + if [ "$SIZE" -gt 1000000 ]; then + echo "⚠️ Warning: Large file ($(echo "scale=2; $SIZE/1024/1024" | bc)MB)" + echo " Consider if this should be edited" + fi +else + echo "ℹ️ New file will be created" +fi + +exit 0 diff --git a/hooks/user-prompt-submit.sh b/hooks/user-prompt-submit.sh new file mode 100755 index 0000000..5f115ac --- /dev/null +++ b/hooks/user-prompt-submit.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# User prompt submit hook: Logs and validates user prompts + +PROMPT="$1" + +# Create log directory if it doesn't exist +LOG_DIR=".claude-plugin/logs" +mkdir -p "$LOG_DIR" + +# Log the prompt +TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S') +LOG_FILE="$LOG_DIR/prompt-history.log" +echo "[$TIMESTAMP] $PROMPT" >> "$LOG_FILE" + +# Check for potentially dangerous commands +if echo "$PROMPT" | grep -Eqi "(rm -rf /|format|delete all|drop database)"; then + echo "⚠️ WARNING: Detected potentially destructive command!" + echo " Please review carefully before proceeding." + echo "" +fi + +# Check for git force operations +if echo "$PROMPT" | grep -Eqi "(git push.*--force|git reset --hard|git clean -fdx)"; then + echo "⚠️ WARNING: Detected potentially destructive git operation!" + echo " Make sure you understand the consequences." + echo "" +fi + +# Check for production-related keywords +if echo "$PROMPT" | grep -Eqi "(production|prod|live environment)"; then + echo "⚠️ CAUTION: Production environment mentioned" + echo " Double-check all operations on production systems." + echo "" +fi + +# Provide helpful tips for common patterns +if echo "$PROMPT" | grep -qi "create.*test"; then + echo "💡 Tip: Consider using TDD - write tests first!" + echo "" +fi + +if echo "$PROMPT" | grep -qi "refactor"; then + echo "💡 Tip: Make sure tests pass before and after refactoring" + echo "" +fi + +exit 0 diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..2d25f38 --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,81 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:yasun1/claude-code-plugin-demo:my-first-plugin", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "31d48cd659057445ad7ec3ce39396e5a5e23c781", + "treeHash": "a466bac5d1beff25f2e97942babb4ee423856e70516cac0de719bad4386587fd", + "generatedAt": "2025-11-28T10:29:09.787018Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "my-first-plugin", + "description": "A comprehensive demo plugin showcasing all Claude Code plugin types: commands, skills, agents, hooks, and MCP server integration", + "version": "1.0.0" + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "a7e9ecdff040c71f84a70f7b7a31af227ca4c6e92374d1d03d9a46586d1d1d7f" + }, + { + "path": "agents/bug-hunter/AGENT.md", + "sha256": "60da9ef45e314b168f3e793a3a3fd9a96427bbdd6650608a2cdc2be075172e0b" + }, + { + "path": "agents/refactor-master/AGENT.md", + "sha256": "fc7be3cde7240b7f1af73aa8816123a846ccc83e96865731df457436a6418c60" + }, + { + "path": "hooks/user-prompt-submit.sh", + "sha256": "a6f488e960d13e8c65102eb3022885c24cce3dd7ed4522375fc7b693753801c8" + }, + { + "path": "hooks/post-write.sh", + "sha256": "e44d5b16eb0d553fb33b4165b1af21b29a2bbd84f3126b1a4afbd3636d25d2b0" + }, + { + "path": "hooks/pre-edit.sh", + "sha256": "41a9afbdd9a04411a47e6f35606a88c2b27518276943c93f71e6d62fc27242dd" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "7f00349633efc12ca20030cb07ec1602f48fafa9a2dcbcf19f0241b208c5757f" + }, + { + "path": "commands/project-stats.md", + "sha256": "38fe563382a7e67b723f6e3ef9750adf0cf583f163e7d031019e53fafad986ba" + }, + { + "path": "commands/hello.md", + "sha256": "596726ce0d5aa1d0abf887d5f5ab30001d24e5794da795ab51faf4b4f0854952" + }, + { + "path": "commands/analyze-code.md", + "sha256": "8b7f95077a27831cd7ef395ce218ce05e18a3019074e13c2ecf977dba4ee4acf" + }, + { + "path": "skills/code-reviewer/SKILL.md", + "sha256": "738969af7b0f3f5184077420efe1841b653db4d16fa658a95770a96a59f0ca90" + }, + { + "path": "skills/doc-generator/SKILL.md", + "sha256": "a957c5c205a762a0995647aa996856d104591d17660cd22705a56d4433120561" + } + ], + "dirSha256": "a466bac5d1beff25f2e97942babb4ee423856e70516cac0de719bad4386587fd" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file diff --git a/skills/code-reviewer/SKILL.md b/skills/code-reviewer/SKILL.md new file mode 100644 index 0000000..381f425 --- /dev/null +++ b/skills/code-reviewer/SKILL.md @@ -0,0 +1,42 @@ +--- +name: code-reviewer +description: Perform comprehensive code review with quality, security, and performance analysis +--- + +You are an expert code reviewer. Perform a thorough, professional code review: + +## Review Areas + +### 1. Code Quality +- **Readability**: Clear naming, proper structure, appropriate comments +- **Maintainability**: Low complexity, good separation of concerns +- **Code Smells**: Duplicated code, long methods, large classes + +### 2. Performance +- **Efficiency**: Algorithm complexity, unnecessary computations +- **Resource Usage**: Memory leaks, unclosed resources +- **Optimization Opportunities**: Caching, lazy loading + +### 3. Security +- **Input Validation**: Check all user inputs are validated +- **Authentication/Authorization**: Proper access control +- **Common Vulnerabilities**: SQL injection, XSS, CSRF, hardcoded secrets + +### 4. Best Practices +- **Error Handling**: Try-catch blocks, error messages +- **Logging**: Appropriate logging levels +- **Testing**: Test coverage, edge cases + +### 5. Language-Specific +- Follow language-specific idioms and conventions +- Use appropriate design patterns + +## Output Format + +For each issue found: +- **Location**: `file.ext:line` +- **Severity**: Critical / High / Medium / Low +- **Issue**: Brief description +- **Recommendation**: Specific fix + +Provide a summary with overall assessment and top priorities. diff --git a/skills/doc-generator/SKILL.md b/skills/doc-generator/SKILL.md new file mode 100644 index 0000000..ccff794 --- /dev/null +++ b/skills/doc-generator/SKILL.md @@ -0,0 +1,55 @@ +--- +name: doc-generator +description: Generate comprehensive documentation including API docs, comments, and README +--- + +You are a documentation expert. Generate high-quality, comprehensive documentation: + +## Documentation Types + +### 1. API Documentation +- **Functions/Methods**: + - Purpose and behavior + - Parameters with types and descriptions + - Return values and types + - Exceptions/errors that can be raised + - Usage examples + +### 2. Inline Comments +- **Complex Logic**: Explain non-obvious algorithms +- **Business Rules**: Document why decisions were made +- **Edge Cases**: Note special handling +- **TODOs**: Mark areas for improvement + +### 3. README Files +- **Overview**: What the module/project does +- **Installation**: Setup instructions +- **Quick Start**: Basic usage examples +- **API Reference**: High-level API overview +- **Examples**: Common use cases +- **Contributing**: How to contribute (if applicable) + +### 4. Type Definitions +- **TypeScript**: Interfaces, types, generics +- **JSDoc**: For JavaScript projects +- **Python**: Type hints and docstrings +- **Go**: Godoc comments + +## Style Guidelines + +- Use clear, concise language +- Follow language-specific documentation conventions: + - JavaScript/TypeScript: JSDoc + - Python: Google or NumPy style docstrings + - Go: Godoc format + - Java: Javadoc +- Include practical examples +- Keep documentation up-to-date with code + +## Output + +Generate documentation that is: +- Accurate and complete +- Easy to understand +- Properly formatted +- Includes examples where helpful