Initial commit

This commit is contained in:
Zhongwei Li
2025-11-29 18:52:14 +08:00
commit 5aa901f301
16 changed files with 1105 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
# Assets
Bundled resources for api-error-handler skill
- [ ] error_response_template.json: A JSON template for consistent error responses.
- [ ] error_code_prefix_mapping.json: A mapping of error code prefixes to specific API modules or services.

View File

@@ -0,0 +1,32 @@
{
"skill": {
"name": "skill-name",
"version": "1.0.0",
"enabled": true,
"settings": {
"verbose": false,
"autoActivate": true,
"toolRestrictions": true
}
},
"triggers": {
"keywords": [
"example-trigger-1",
"example-trigger-2"
],
"patterns": []
},
"tools": {
"allowed": [
"Read",
"Grep",
"Bash"
],
"restricted": []
},
"metadata": {
"author": "Plugin Author",
"category": "general",
"tags": []
}
}

View File

@@ -0,0 +1,68 @@
{
"_comment": "Mapping of error code prefixes to API modules/services. Used for determining the origin and handling strategy for different error types.",
"mappings": {
"AUTH": {
"_comment": "Authentication-related errors",
"module": "AuthenticationService",
"http_status_code": 401,
"description": "Errors related to user authentication, authorization, or session management.",
"handling_strategy": "Retry with re-authentication if possible, otherwise log and return a 401 Unauthorized error."
},
"USER": {
"_comment": "User management errors",
"module": "UserService",
"http_status_code": 400,
"description": "Errors related to user creation, modification, or deletion.",
"handling_strategy": "Return a 400 Bad Request error with specific details about the invalid user data or operation."
},
"PROD": {
"_comment": "Product catalog errors",
"module": "ProductCatalogService",
"http_status_code": 500,
"description": "Errors related to retrieving or managing product information.",
"handling_strategy": "Retry a limited number of times. If still failing, log the error and return a 500 Internal Server Error with a generic message. Monitor for widespread issues."
},
"ORD": {
"_comment": "Order processing errors",
"module": "OrderProcessingService",
"http_status_code": 409,
"description": "Errors related to order placement, modification, or fulfillment.",
"handling_strategy": "Return a 409 Conflict error if the order is in an invalid state. For other errors, attempt to automatically correct the order if possible, otherwise notify support and return a 500 Internal Server Error."
},
"PAY": {
"_comment": "Payment processing errors",
"module": "PaymentGatewayService",
"http_status_code": 402,
"description": "Errors related to payment authorization, capture, or refund.",
"handling_strategy": "Return a 402 Payment Required error. Provide specific instructions to the user on how to resolve the payment issue."
},
"RATE": {
"_comment": "Rate limiting errors",
"module": "RateLimiter",
"http_status_code": 429,
"description": "Errors indicating that the client has exceeded their rate limit.",
"handling_strategy": "Return a 429 Too Many Requests error with a 'Retry-After' header indicating when the client can retry."
},
"DATA": {
"_comment": "Data validation or database errors",
"module": "DatabaseService",
"http_status_code": 503,
"description": "Errors related to accessing or manipulating data in the database. Includes validation failures.",
"handling_strategy": "Retry database operations with exponential backoff. If persistent, return a 503 Service Unavailable error, indicating a temporary issue. Alert the database administrators."
},
"INTEG": {
"_comment": "Integration errors with external services",
"module": "IntegrationService",
"http_status_code": 502,
"description": "Errors encountered when communicating with external APIs or services.",
"handling_strategy": "Implement circuit breaker pattern to prevent cascading failures. Return a 502 Bad Gateway error if the external service is unavailable."
},
"NOTF": {
"_comment": "Notification service errors",
"module": "NotificationService",
"http_status_code": 500,
"description": "Errors related to sending emails, SMS messages, or push notifications.",
"handling_strategy": "Queue failed notifications for retry. Log errors and monitor for persistent failures. Return a 500 Internal Server Error to the client, indicating a temporary issue with notifications."
}
}
}

View File

@@ -0,0 +1,56 @@
{
"_comment": "Template for a standardized error response.",
"error": {
"_comment": "Top-level key indicating an error occurred.",
"code": "ERR_INVALID_INPUT",
"_comment": "A unique error code for programmatic handling. Should be stable and not change even if the message changes.",
"message": "Invalid input provided.",
"_comment": "A human-readable error message. Should be helpful to the user.",
"status": 400,
"_comment": "The HTTP status code associated with the error.",
"details": {
"_comment": "Optional details about the error. Can be an object or an array.",
"field": "email",
"issue": "Email address is not valid."
},
"timestamp": "2024-10-27T10:00:00Z",
"_comment": "Timestamp of when the error occurred (ISO 8601 format)."
},
"_comment": "Example of a different error scenario (Internal Server Error)",
"example_internal_server_error": {
"error": {
"code": "ERR_INTERNAL_SERVER_ERROR",
"message": "An unexpected error occurred on the server.",
"status": 500,
"details": {
"_comment": "This can be omitted or contain sensitive information that should not be exposed to the client.",
"errorId": "a1b2c3d4e5f6g7h8"
},
"timestamp": "2024-10-27T10:01:00Z"
}
},
"_comment": "Example of a different error scenario (Unauthorized)",
"example_unauthorized": {
"error": {
"code": "ERR_UNAUTHORIZED",
"message": "Unauthorized: Invalid credentials.",
"status": 401,
"details": null,
"_comment": "Details are often omitted for unauthorized errors.",
"timestamp": "2024-10-27T10:02:00Z"
}
},
"_comment": "Example of a different error scenario (Not Found)",
"example_not_found": {
"error": {
"code": "ERR_NOT_FOUND",
"message": "Resource not found.",
"status": 404,
"details": {
"resource": "user",
"id": "123"
},
"timestamp": "2024-10-27T10:03:00Z"
}
}
}

View File

@@ -0,0 +1,28 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Claude Skill Configuration",
"type": "object",
"required": ["name", "description"],
"properties": {
"name": {
"type": "string",
"pattern": "^[a-z0-9-]+$",
"maxLength": 64,
"description": "Skill identifier (lowercase, hyphens only)"
},
"description": {
"type": "string",
"maxLength": 1024,
"description": "What the skill does and when to use it"
},
"allowed-tools": {
"type": "string",
"description": "Comma-separated list of allowed tools"
},
"version": {
"type": "string",
"pattern": "^\\d+\\.\\d+\\.\\d+$",
"description": "Semantic version (x.y.z)"
}
}
}

View File

@@ -0,0 +1,27 @@
{
"testCases": [
{
"name": "Basic activation test",
"input": "trigger phrase example",
"expected": {
"activated": true,
"toolsUsed": ["Read", "Grep"],
"success": true
}
},
{
"name": "Complex workflow test",
"input": "multi-step trigger example",
"expected": {
"activated": true,
"steps": 3,
"toolsUsed": ["Read", "Write", "Bash"],
"success": true
}
}
],
"fixtures": {
"sampleInput": "example data",
"expectedOutput": "processed result"
}
}

View File

@@ -0,0 +1,7 @@
# References
Bundled resources for api-error-handler skill
- [ ] http_status_codes.md: A comprehensive list of HTTP status codes with descriptions and when to use them.
- [ ] error_handling_best_practices.md: Best practices for API error handling, including security considerations.
- [ ] example_error_responses.json: Examples of well-structured error responses in JSON format.

View File

@@ -0,0 +1,69 @@
# Skill Best Practices
Guidelines for optimal skill usage and development.
## For Users
### Activation Best Practices
1. **Use Clear Trigger Phrases**
- Match phrases from skill description
- Be specific about intent
- Provide necessary context
2. **Provide Sufficient Context**
- Include relevant file paths
- Specify scope of analysis
- Mention any constraints
3. **Understand Tool Permissions**
- Check allowed-tools in frontmatter
- Know what the skill can/cannot do
- Request appropriate actions
### Workflow Optimization
- Start with simple requests
- Build up to complex workflows
- Verify each step before proceeding
- Use skill consistently for related tasks
## For Developers
### Skill Development Guidelines
1. **Clear Descriptions**
- Include explicit trigger phrases
- Document all capabilities
- Specify limitations
2. **Proper Tool Permissions**
- Use minimal necessary tools
- Document security implications
- Test with restricted tools
3. **Comprehensive Documentation**
- Provide usage examples
- Document common pitfalls
- Include troubleshooting guide
### Maintenance
- Keep version updated
- Test after tool updates
- Monitor user feedback
- Iterate on descriptions
## Performance Tips
- Scope skills to specific domains
- Avoid overlapping trigger phrases
- Keep descriptions under 1024 chars
- Test activation reliability
## Security Considerations
- Never include secrets in skill files
- Validate all inputs
- Use read-only tools when possible
- Document security requirements

View File

@@ -0,0 +1,70 @@
# Skill Usage Examples
This document provides practical examples of how to use this skill effectively.
## Basic Usage
### Example 1: Simple Activation
**User Request:**
```
[Describe trigger phrase here]
```
**Skill Response:**
1. Analyzes the request
2. Performs the required action
3. Returns results
### Example 2: Complex Workflow
**User Request:**
```
[Describe complex scenario]
```
**Workflow:**
1. Step 1: Initial analysis
2. Step 2: Data processing
3. Step 3: Result generation
4. Step 4: Validation
## Advanced Patterns
### Pattern 1: Chaining Operations
Combine this skill with other tools:
```
Step 1: Use this skill for [purpose]
Step 2: Chain with [other tool]
Step 3: Finalize with [action]
```
### Pattern 2: Error Handling
If issues occur:
- Check trigger phrase matches
- Verify context is available
- Review allowed-tools permissions
## Tips & Best Practices
- ✅ Be specific with trigger phrases
- ✅ Provide necessary context
- ✅ Check tool permissions match needs
- ❌ Avoid vague requests
- ❌ Don't mix unrelated tasks
## Common Issues
**Issue:** Skill doesn't activate
**Solution:** Use exact trigger phrases from description
**Issue:** Unexpected results
**Solution:** Check input format and context
## See Also
- Main SKILL.md for full documentation
- scripts/ for automation helpers
- assets/ for configuration examples

View File

@@ -0,0 +1,7 @@
# Scripts
Bundled resources for api-error-handler skill
- [ ] validate_status_code.py: Validates if a given HTTP status code is valid according to standards.
- [ ] format_error_response.py: Formats an error response into a consistent JSON structure.
- [ ] generate_error_code.py: Generates a unique error code for internal tracking.

View File

@@ -0,0 +1,42 @@
#!/bin/bash
# Helper script template for skill automation
# Customize this for your skill's specific needs
set -e
function show_usage() {
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo " -v, --verbose Enable verbose output"
echo ""
}
# Parse arguments
VERBOSE=false
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_usage
exit 0
;;
-v|--verbose)
VERBOSE=true
shift
;;
*)
echo "Unknown option: $1"
show_usage
exit 1
;;
esac
done
# Your skill logic here
if [ "$VERBOSE" = true ]; then
echo "Running skill automation..."
fi
echo "✅ Complete"

View File

@@ -0,0 +1,32 @@
#!/bin/bash
# Skill validation helper
# Validates skill activation and functionality
set -e
echo "🔍 Validating skill..."
# Check if SKILL.md exists
if [ ! -f "../SKILL.md" ]; then
echo "❌ Error: SKILL.md not found"
exit 1
fi
# Validate frontmatter
if ! grep -q "^---$" "../SKILL.md"; then
echo "❌ Error: No frontmatter found"
exit 1
fi
# Check required fields
if ! grep -q "^name:" "../SKILL.md"; then
echo "❌ Error: Missing 'name' field"
exit 1
fi
if ! grep -q "^description:" "../SKILL.md"; then
echo "❌ Error: Missing 'description' field"
exit 1
fi
echo "✅ Skill validation passed"