Initial commit
This commit is contained in:
228
skills/context-master/scripts/create_subagent.py
Normal file
228
skills/context-master/scripts/create_subagent.py
Normal file
@@ -0,0 +1,228 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Create a subagent configuration for Claude Code.
|
||||
|
||||
Usage:
|
||||
python create_subagent.py <agent_name> [--type TYPE] [--output DIR]
|
||||
|
||||
Types:
|
||||
- researcher: For documentation and code searches with deep analysis
|
||||
- tester: For running tests and validation with failure analysis
|
||||
- analyzer: For code analysis and architectural insights
|
||||
- builder: For build and deployment tasks
|
||||
- deep_analyzer: For complex decisions requiring extensive thinking
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
SUBAGENT_TEMPLATES = {
|
||||
"researcher": {
|
||||
"name": "{agent_name}",
|
||||
"description": "Research and documentation lookup agent with deep analysis",
|
||||
"instructions": """You are a research specialist. Your job is to:
|
||||
- Search through documentation efficiently
|
||||
- THINK DEEPLY about findings using extended thinking
|
||||
- Analyze patterns and implications
|
||||
- Synthesize insights with reasoning
|
||||
- Return concise, well-reasoned summaries
|
||||
|
||||
IMPORTANT: For complex research, use extended thinking before responding:
|
||||
- Use "think hard" for multi-source analysis
|
||||
- Use "ultrathink" for architecture pattern evaluation
|
||||
- Your thinking happens in YOUR isolated context
|
||||
- Return only the analysis summary to the main agent
|
||||
|
||||
The main agent needs your INSIGHTS, not raw data.""",
|
||||
"tools": ["read", "search", "web_search"],
|
||||
"autonomy": "medium"
|
||||
},
|
||||
|
||||
"tester": {
|
||||
"name": "{agent_name}",
|
||||
"description": "Testing and validation agent with analysis",
|
||||
"instructions": """You are a testing specialist. Your job is to:
|
||||
- Execute test suites
|
||||
- Validate code changes
|
||||
- ANALYZE test failures deeply
|
||||
- Identify root causes and patterns
|
||||
- Report clear, actionable results
|
||||
|
||||
IMPORTANT: When test failures occur, use extended thinking:
|
||||
- Use "think hard" to analyze failure patterns
|
||||
- Consider root causes and related issues
|
||||
- Your analysis happens in YOUR isolated context
|
||||
- Return actionable findings to the main agent
|
||||
|
||||
Focus on test execution and insightful result reporting.""",
|
||||
"tools": ["bash", "read", "write"],
|
||||
"autonomy": "high"
|
||||
},
|
||||
|
||||
"analyzer": {
|
||||
"name": "{agent_name}",
|
||||
"description": "Code analysis and deep architectural insight agent",
|
||||
"instructions": """You are a code analysis specialist. Your job is to:
|
||||
- Analyze code structure and patterns
|
||||
- THINK DEEPLY about implications and tradeoffs
|
||||
- Identify potential issues and opportunities
|
||||
- Compute complexity metrics
|
||||
- Find dependencies and relationships
|
||||
|
||||
IMPORTANT: Always use extended thinking for analysis:
|
||||
- Use "think harder" for architecture analysis
|
||||
- Use "ultrathink" for complex system evaluation
|
||||
- Consider multiple perspectives and edge cases
|
||||
- Your deep reasoning happens in YOUR isolated context
|
||||
- Return concise analysis with key insights to the main agent
|
||||
|
||||
Provide actionable insights backed by reasoning.""",
|
||||
"tools": ["read", "search", "bash"],
|
||||
"autonomy": "medium"
|
||||
},
|
||||
|
||||
"builder": {
|
||||
"name": "{agent_name}",
|
||||
"description": "Build and deployment agent",
|
||||
"instructions": """You are a build specialist. Your job is to:
|
||||
- Execute build processes
|
||||
- Run deployment scripts
|
||||
- Verify build outputs
|
||||
- Report build status and errors
|
||||
|
||||
Focus on build execution and clear status reporting. Return success/failure and any errors.""",
|
||||
"tools": ["bash", "read"],
|
||||
"autonomy": "high"
|
||||
},
|
||||
|
||||
"deep_analyzer": {
|
||||
"name": "{agent_name}",
|
||||
"description": "Deep analysis agent with mandatory extended thinking",
|
||||
"instructions": """You are a deep analysis specialist. Your PRIMARY function is to think deeply before responding.
|
||||
|
||||
MANDATORY WORKFLOW:
|
||||
1. Always start with "ultrathink" for complex analysis
|
||||
2. Consider multiple approaches and perspectives
|
||||
3. Evaluate tradeoffs, implications, and edge cases
|
||||
4. Reason through consequences and alternatives
|
||||
5. Synthesize findings into clear recommendations
|
||||
|
||||
Your extended thinking happens in YOUR isolated context - this is your superpower.
|
||||
The main agent only sees your conclusions, not your reasoning process.
|
||||
|
||||
RETURN FORMAT:
|
||||
- Brief conclusion (2-3 sentences)
|
||||
- Key reasoning points (3-5 bullets)
|
||||
- Recommendation with rationale
|
||||
- Any important caveats
|
||||
|
||||
The main agent trusts your deep analysis. Give them confidence through thorough thinking.""",
|
||||
"tools": ["read", "search", "bash", "web_search"],
|
||||
"autonomy": "high"
|
||||
}
|
||||
}
|
||||
|
||||
CLAUDE_CODE_FORMAT = """# {agent_name}
|
||||
|
||||
{description}
|
||||
|
||||
## Instructions
|
||||
|
||||
{instructions}
|
||||
|
||||
## Allowed Tools
|
||||
|
||||
{tools}
|
||||
|
||||
## Autonomy Level
|
||||
|
||||
{autonomy_description}
|
||||
"""
|
||||
|
||||
AUTONOMY_DESCRIPTIONS = {
|
||||
"low": "Ask for confirmation before taking actions. Provide recommendations.",
|
||||
"medium": "Take standard actions autonomously. Ask for confirmation on significant changes.",
|
||||
"high": "Execute tasks fully autonomously. Report results when complete."
|
||||
}
|
||||
|
||||
|
||||
def create_subagent(agent_name: str, agent_type: str, output_dir: str) -> None:
|
||||
"""Create a subagent configuration file."""
|
||||
if agent_type not in SUBAGENT_TEMPLATES:
|
||||
raise ValueError(
|
||||
f"Unknown agent type: {agent_type}. "
|
||||
f"Choose from: {', '.join(SUBAGENT_TEMPLATES.keys())}"
|
||||
)
|
||||
|
||||
template = SUBAGENT_TEMPLATES[agent_type].copy()
|
||||
template["name"] = agent_name
|
||||
|
||||
# Create output directory
|
||||
output_path = Path(output_dir)
|
||||
output_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Create .claude/agents directory structure
|
||||
agents_dir = output_path / ".claude" / "agents"
|
||||
agents_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Generate agent file in Claude Code format
|
||||
agent_file = agents_dir / f"{agent_name}.md"
|
||||
|
||||
tools_list = "\n".join(f"- {tool}" for tool in template["tools"])
|
||||
autonomy_desc = AUTONOMY_DESCRIPTIONS[template["autonomy"]]
|
||||
|
||||
content = CLAUDE_CODE_FORMAT.format(
|
||||
agent_name=agent_name,
|
||||
description=template["description"],
|
||||
instructions=template["instructions"],
|
||||
tools=tools_list,
|
||||
autonomy_description=autonomy_desc
|
||||
)
|
||||
|
||||
agent_file.write_text(content)
|
||||
|
||||
# Also create a JSON version for programmatic use
|
||||
json_file = agents_dir / f"{agent_name}.json"
|
||||
json_file.write_text(json.dumps(template, indent=2))
|
||||
|
||||
print(f"✅ Created subagent: {agent_name}")
|
||||
print(f" Type: {agent_type}")
|
||||
print(f" Location: {agent_file}")
|
||||
print(f"\n📝 Next steps:")
|
||||
print(f" 1. Review and customize {agent_file}")
|
||||
print(f" 2. Use in Claude Code with: /agent {agent_name}")
|
||||
print(f" 3. Commit to version control")
|
||||
|
||||
# Print usage example
|
||||
print(f"\n💡 Usage example:")
|
||||
print(f" /agent {agent_name} [your task description]")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Create a subagent configuration for Claude Code"
|
||||
)
|
||||
parser.add_argument(
|
||||
"agent_name",
|
||||
help="Name for the subagent (e.g., 'test-runner', 'doc-searcher')"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--type",
|
||||
choices=list(SUBAGENT_TEMPLATES.keys()),
|
||||
default="researcher",
|
||||
help="Type of subagent to create"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output",
|
||||
default=".",
|
||||
help="Output directory (default: current directory)"
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
create_subagent(args.agent_name, args.type, args.output)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
341
skills/context-master/scripts/generate_claude_md.py
Normal file
341
skills/context-master/scripts/generate_claude_md.py
Normal file
@@ -0,0 +1,341 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Generate a CLAUDE.md file for context-efficient Claude Code workflows.
|
||||
|
||||
Usage:
|
||||
python generate_claude_md.py [--type TYPE] [--output PATH]
|
||||
|
||||
Types:
|
||||
- general: General-purpose project (default)
|
||||
- backend: Backend API/service project
|
||||
- frontend: Frontend web application
|
||||
- fullstack: Full-stack application
|
||||
- data: Data science/ML project
|
||||
- library: Library/package project
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
TEMPLATES = {
|
||||
"general": """# Claude Code Configuration
|
||||
|
||||
## Project Overview
|
||||
<!-- Describe your project's purpose, architecture, and key components -->
|
||||
|
||||
## Context Management Strategy
|
||||
|
||||
### When to Use Subagents
|
||||
- **Code searches**: Use subagents to search through large codebases
|
||||
- **File analysis**: Delegate multi-file analysis to subagents
|
||||
- **Research tasks**: Use subagents for documentation lookups
|
||||
- **Testing**: Isolate test runs in subagents
|
||||
|
||||
### Context Commands
|
||||
- Use `/clear` between major tasks to reset context
|
||||
- Use `/compact` before complex multi-step work
|
||||
- Use `think` for planning complex changes
|
||||
|
||||
## Development Workflow
|
||||
|
||||
1. **Planning Phase**: Use "think" to analyze approach
|
||||
2. **Implementation**: Keep main context focused on current task
|
||||
3. **Verification**: Use subagents for testing and validation
|
||||
4. **Cleanup**: `/clear` before starting new features
|
||||
|
||||
## Allowed Tools
|
||||
- File operations (read, write, edit)
|
||||
- Git operations (commit, branch, status)
|
||||
- Shell commands for building and testing
|
||||
- Subagent delegation
|
||||
|
||||
## Code Style
|
||||
<!-- Add your project's code style guidelines -->
|
||||
|
||||
## Escalation Rules
|
||||
- Ask before making breaking changes
|
||||
- Confirm before deleting files
|
||||
- Verify test results before committing
|
||||
""",
|
||||
|
||||
"backend": """# Claude Code Configuration - Backend Project
|
||||
|
||||
## Project Overview
|
||||
<!-- Describe your API/service architecture -->
|
||||
|
||||
## Context Management Strategy
|
||||
|
||||
### When to Use Subagents
|
||||
- **Database queries**: Delegate schema exploration to subagents
|
||||
- **API documentation**: Use subagents to search through API docs
|
||||
- **Log analysis**: Isolate log file analysis in subagents
|
||||
- **Dependency analysis**: Check dependencies in isolated context
|
||||
- **Test runs**: Execute test suites in subagents
|
||||
|
||||
### Context Commands
|
||||
- `/clear` between feature implementations
|
||||
- `/compact` before multi-endpoint refactoring
|
||||
- `think hard` for API design decisions
|
||||
|
||||
## Development Workflow
|
||||
|
||||
1. **Schema Review**: Subagent explores DB schema
|
||||
2. **Planning**: Main context designs endpoint logic
|
||||
3. **Implementation**: Focus on current endpoint
|
||||
4. **Testing**: Subagent runs integration tests
|
||||
5. **Commit**: After test verification
|
||||
|
||||
## API Patterns
|
||||
<!-- Add your API conventions (REST, GraphQL, etc.) -->
|
||||
|
||||
## Database
|
||||
<!-- Add your schema info or reference documentation -->
|
||||
|
||||
## Testing Strategy
|
||||
- Unit tests required for business logic
|
||||
- Integration tests for API endpoints
|
||||
- Use subagents for test execution
|
||||
|
||||
## Escalation Rules
|
||||
- Confirm before database migrations
|
||||
- Ask before changing API contracts
|
||||
- Verify backward compatibility
|
||||
""",
|
||||
|
||||
"frontend": """# Claude Code Configuration - Frontend Project
|
||||
|
||||
## Project Overview
|
||||
<!-- Describe your frontend architecture (React, Vue, Angular, etc.) -->
|
||||
|
||||
## Context Management Strategy
|
||||
|
||||
### When to Use Subagents
|
||||
- **Component searches**: Find similar components across codebase
|
||||
- **Style analysis**: Isolate CSS/styling investigations
|
||||
- **Bundle analysis**: Check dependencies and imports
|
||||
- **Test runs**: Execute component tests in subagents
|
||||
- **Build verification**: Run builds in isolated context
|
||||
|
||||
### Context Commands
|
||||
- `/clear` between component implementations
|
||||
- `/compact` before large refactoring
|
||||
- `think` for component architecture decisions
|
||||
|
||||
## Development Workflow
|
||||
|
||||
1. **Component Planning**: Design component structure
|
||||
2. **Implementation**: Focus on current component
|
||||
3. **Styling**: Apply consistent design system
|
||||
4. **Testing**: Subagent runs component tests
|
||||
5. **Build Check**: Subagent verifies build
|
||||
|
||||
## Component Patterns
|
||||
<!-- Add your component conventions -->
|
||||
|
||||
## Styling Approach
|
||||
<!-- CSS-in-JS, Tailwind, CSS Modules, etc. -->
|
||||
|
||||
## State Management
|
||||
<!-- Redux, Context API, Zustand, etc. -->
|
||||
|
||||
## Testing Strategy
|
||||
- Component tests required
|
||||
- Use Testing Library best practices
|
||||
- Subagents handle test execution
|
||||
|
||||
## Escalation Rules
|
||||
- Confirm before major architectural changes
|
||||
- Ask before adding new dependencies
|
||||
- Verify accessibility requirements
|
||||
""",
|
||||
|
||||
"fullstack": """# Claude Code Configuration - Full-Stack Project
|
||||
|
||||
## Project Overview
|
||||
<!-- Describe your full-stack architecture -->
|
||||
|
||||
## Context Management Strategy
|
||||
|
||||
### When to Use Subagents
|
||||
- **Frontend searches**: Delegate component searches
|
||||
- **Backend analysis**: Isolate API endpoint analysis
|
||||
- **Database operations**: Schema exploration in subagents
|
||||
- **Build processes**: Run builds in isolated contexts
|
||||
- **Test suites**: Execute frontend and backend tests separately
|
||||
|
||||
### Context Commands
|
||||
- `/clear` between frontend/backend context switches
|
||||
- `/compact` before cross-stack refactoring
|
||||
- `think hard` for architectural decisions
|
||||
|
||||
## Development Workflow
|
||||
|
||||
1. **Planning**: Design full-stack feature flow
|
||||
2. **Backend First**: Implement API endpoints
|
||||
3. **Frontend**: Build UI components
|
||||
4. **Integration**: Connect frontend to backend
|
||||
5. **Testing**: Subagents test both layers
|
||||
|
||||
## Stack
|
||||
- **Frontend**: <!-- React, Vue, etc. -->
|
||||
- **Backend**: <!-- Node.js, Python, etc. -->
|
||||
- **Database**: <!-- PostgreSQL, MongoDB, etc. -->
|
||||
|
||||
## API Patterns
|
||||
<!-- REST, GraphQL, tRPC, etc. -->
|
||||
|
||||
## Testing Strategy
|
||||
- Unit tests for business logic
|
||||
- Integration tests for APIs
|
||||
- Component tests for UI
|
||||
- E2E tests for critical flows
|
||||
|
||||
## Escalation Rules
|
||||
- Confirm before database migrations
|
||||
- Ask before API contract changes
|
||||
- Verify cross-stack impacts
|
||||
""",
|
||||
|
||||
"data": """# Claude Code Configuration - Data Science Project
|
||||
|
||||
## Project Overview
|
||||
<!-- Describe your data pipeline and analysis goals -->
|
||||
|
||||
## Context Management Strategy
|
||||
|
||||
### When to Use Subagents
|
||||
- **Data exploration**: Delegate large dataset analysis
|
||||
- **Model searches**: Find similar models in codebase
|
||||
- **Documentation**: Research library documentation
|
||||
- **Experiment runs**: Execute training in subagents
|
||||
- **Result analysis**: Isolate metrics computation
|
||||
|
||||
### Context Commands
|
||||
- `/clear` between experiments
|
||||
- `/compact` before model refactoring
|
||||
- `think harder` for model architecture decisions
|
||||
|
||||
## Development Workflow
|
||||
|
||||
1. **Data Exploration**: Subagent analyzes dataset
|
||||
2. **Feature Engineering**: Design features in main context
|
||||
3. **Model Development**: Implement and iterate
|
||||
4. **Evaluation**: Subagent runs evaluation metrics
|
||||
5. **Documentation**: Record experiment results
|
||||
|
||||
## Data Pipeline
|
||||
<!-- Add your data sources and processing steps -->
|
||||
|
||||
## Model Architecture
|
||||
<!-- Add your model details -->
|
||||
|
||||
## Experiment Tracking
|
||||
<!-- MLflow, Weights & Biases, etc. -->
|
||||
|
||||
## Testing Strategy
|
||||
- Unit tests for data processing
|
||||
- Validation tests for model outputs
|
||||
- Subagents handle long-running tests
|
||||
|
||||
## Escalation Rules
|
||||
- Confirm before large dataset operations
|
||||
- Ask before changing data schemas
|
||||
- Verify model performance before deployment
|
||||
""",
|
||||
|
||||
"library": """# Claude Code Configuration - Library Project
|
||||
|
||||
## Project Overview
|
||||
<!-- Describe your library's purpose and API -->
|
||||
|
||||
## Context Management Strategy
|
||||
|
||||
### When to Use Subagents
|
||||
- **API searches**: Find similar functions across codebase
|
||||
- **Documentation**: Research upstream dependencies
|
||||
- **Example analysis**: Review usage examples
|
||||
- **Test execution**: Run test suites in subagents
|
||||
- **Build verification**: Check builds across versions
|
||||
|
||||
### Context Commands
|
||||
- `/clear` between feature implementations
|
||||
- `/compact` before API refactoring
|
||||
- `think` for public API design
|
||||
|
||||
## Development Workflow
|
||||
|
||||
1. **API Design**: Plan function signatures
|
||||
2. **Implementation**: Implement core logic
|
||||
3. **Documentation**: Write docstrings and examples
|
||||
4. **Testing**: Comprehensive test coverage
|
||||
5. **Verification**: Subagent runs full test suite
|
||||
|
||||
## API Principles
|
||||
- Maintain backward compatibility
|
||||
- Clear, consistent naming
|
||||
- Comprehensive documentation
|
||||
- Type hints/annotations
|
||||
|
||||
## Testing Strategy
|
||||
- Unit tests for all public APIs
|
||||
- Integration tests for workflows
|
||||
- Docstring examples as doctests
|
||||
- Subagents handle test execution
|
||||
|
||||
## Documentation
|
||||
- Docstrings required for all public APIs
|
||||
- Usage examples in docs/
|
||||
- Changelog maintenance
|
||||
|
||||
## Escalation Rules
|
||||
- Confirm before breaking API changes
|
||||
- Ask before adding dependencies
|
||||
- Verify semantic versioning
|
||||
"""
|
||||
}
|
||||
|
||||
|
||||
def generate_claude_md(project_type: str, output_path: str) -> None:
|
||||
"""Generate a CLAUDE.md file from a template."""
|
||||
if project_type not in TEMPLATES:
|
||||
raise ValueError(f"Unknown project type: {project_type}. Choose from: {', '.join(TEMPLATES.keys())}")
|
||||
|
||||
content = TEMPLATES[project_type]
|
||||
|
||||
# Create parent directory if it doesn't exist
|
||||
output_file = Path(output_path)
|
||||
output_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Write the file
|
||||
output_file.write_text(content)
|
||||
print(f"✅ Generated CLAUDE.md at {output_path}")
|
||||
print(f" Template: {project_type}")
|
||||
print(f"\n📝 Next steps:")
|
||||
print(f" 1. Review and customize the generated CLAUDE.md")
|
||||
print(f" 2. Fill in project-specific details")
|
||||
print(f" 3. Commit it to your repository")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Generate a CLAUDE.md file for context-efficient Claude Code workflows"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--type",
|
||||
choices=list(TEMPLATES.keys()),
|
||||
default="general",
|
||||
help="Project type template to use"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output",
|
||||
default="./CLAUDE.md",
|
||||
help="Output path for the CLAUDE.md file"
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
generate_claude_md(args.type, args.output)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user