| name | Deep Context Generation with PMAT |
| description | Generates comprehensive, LLM-optimized codebase context using PMAT
(Pragmatic AI Labs MCP Agent Toolkit). Use this skill when:
- Starting work on unfamiliar codebases
- Onboarding to new projects or repositories
- Need quick understanding of project architecture
- Preparing for refactoring or feature implementation
- Creating documentation or technical specifications
Outputs highly compressed markdown (60-80% reduction) optimized for LLM consumption.
Supports 25+ languages with architecture visualization, complexity heatmaps, and dependency graphs.
|
| allowed-tools | Bash, Read, Write, Glob, Grep |
PMAT Deep Context Generation Skill
You are an expert at generating comprehensive codebase context using PMAT (Pragmatic AI Labs MCP Agent Toolkit).
When to Activate
This skill should automatically activate when:
- User asks for codebase overview, architecture, or "how does this work?"
- Starting work on unfamiliar code ("I'm new to this project")
- Need to understand project structure before making changes
- Onboarding scenarios ("walk me through this codebase")
- Creating technical documentation or specifications
Core Command: pmat context
pmat context --output context.md --format llm-optimized
What it does:
- Scans entire codebase (respects .gitignore)
- Generates highly compressed markdown (60-80% smaller than raw code)
- Includes architecture diagrams (ASCII art tree structure)
- Provides complexity heatmaps and hotspot identification
- Extracts key abstractions (classes, functions, modules)
- Maps dependencies and import relationships
Performance:
- Small projects (<100 files): <500ms
- Medium projects (100-1K files): <2s
- Large projects (10K+ files): 5-15s
Usage Workflow
Step 1: Generate Full Context
When user needs comprehensive understanding:
pmat context --output deep_context.md --format llm-optimized
Then read the generated file:
cat deep_context.md
Step 2: Analyze the Context
Look for these key sections in the generated context:
-
Project Overview
- Language distribution
- Total files/lines of code
- Main entry points
-
Architecture Tree
- Directory structure
- Module organization
- Key components
-
Complexity Heatmap
- Files sorted by complexity score
- Hotspots requiring attention
- Maintainability indicators
-
Dependency Graph
- Import relationships
- Cross-module dependencies
- External libraries
-
Key Abstractions
- Classes and interfaces
- Public APIs
- Core data structures
Step 3: Answer User Questions
Use the generated context to:
- Explain architecture decisions
- Identify where to make changes
- Suggest refactoring targets
- Map feature implementation paths
Example Usage
Example 1: Quick Codebase Tour
pmat context --output tour.md --format llm-optimized
cat tour.md
Example 2: Find Implementation Location
pmat context --output lang_context.md --format llm-optimized
grep -n "LanguageAnalyzer" lang_context.md
Example 3: Refactoring Guidance
pmat context --output refactor_context.md --format llm-optimized
grep -A 10 -B 2 "auth" refactor_context.md > auth_subset.md
Advanced Features
Incremental Context Updates
For large projects, generate context incrementally:
pmat context --path src/services --output services_context.md --format llm-optimized
Filter by Language
Focus on specific language files:
pmat context --language rust --output rust_context.md --format llm-optimized
Include/Exclude Patterns
Customize what gets analyzed:
pmat context --exclude "**/*test.rs" --output prod_context.md --format llm-optimized
Integration with Other Skills
Combine with pmat-quality:
- Generate context first (architecture understanding)
- Run quality analysis (identify issues)
- Provide comprehensive improvement plan
Combine with pmat-refactor:
- Generate context (current state)
- Run refactor analysis (opportunities)
- Context helps prioritize refactoring targets
Output Format Details
The generated context.md file includes:
Section 1: Metadata
# Project Context: <project_name>
Generated: 2025-10-22
Tool: PMAT v2.170.0
Total Files: 234
Total Lines: 45,678
Languages: Rust (85%), JavaScript (10%), Other (5%)
Section 2: Architecture Tree
## Architecture
āāā src/
ā āāā main.rs (85 LOC, complexity: 12)
ā āāā cli/ (12 files, 1,234 LOC)
ā āāā services/ (45 files, 8,976 LOC)
ā ā āāā deep_context.rs (complexity: 342)
ā ā āāā quality_gates.rs (complexity: 128)
ā āāā tdg/ (23 files, 3,456 LOC)
Section 3: Complexity Heatmap
## Complexity Hotspots
1. services/deep_context.rs - Score: 342 (REFACTOR URGENTLY)
2. tdg/analyzer.rs - Score: 128 (REVIEW)
3. cli/handlers.rs - Score: 95 (ACCEPTABLE)
Section 4: Key Abstractions
## Core Types
- `DeepContextAnalyzer`: Main analysis engine
- `QualityGate`: Quality enforcement system
- `TdgScore`: Technical debt grading
Section 5: Dependency Graph
## Dependencies
services/deep_context.rs imports from:
- services/file_discovery.rs
- services/language_analyzer.rs
- tdg/analyzer.rs
Performance Optimization Tips
For Very Large Codebases (100K+ files):
- Generate context for subdirectories separately
- Cache generated context files
- Use
--exclude to skip vendor/node_modules
- Generate once, reference multiple times in conversation
Context File Size:
- Typically 60-80% smaller than raw code
- Example: 10MB of source code ā 2-3MB context file
- Still very large - use grep/search to extract relevant sections
Caching Strategy
PMAT caches context generation:
- Cache location:
.pmat-cache/context/
- Invalidation: Automatic on file changes
- Manual refresh:
pmat context --refresh
Error Handling
If context generation fails:
- Check disk space (context files can be large)
- Verify pmat version:
pmat --version (requires v2.170.0+)
- Try smaller scope:
pmat context --path src/ --output src_context.md
- Check for binary files causing issues (PMAT should skip these)
Best Practices
- Generate Once Per Session: Cache and reuse context files
- Start Broad, Then Narrow: Full context first, then grep for specifics
- Update on Major Changes: Regenerate context after significant refactoring
- Combine Tools: Use context + quality + refactor for comprehensive analysis
- Share Context: Include context.md in issue reports for better bug triage
Scientific Foundation
Context generation implements:
- Halstead Metrics: Program vocabulary and volume
- Information Retrieval: TF-IDF for key term extraction
- Graph Theory: Dependency network analysis
- Compression Algorithms: Semantic deduplication (60-80% reduction)
Limitations
- Very Large Files: Files >10K LOC may be summarized rather than fully included
- Binary Files: Skipped (images, compiled code, etc.)
- Generated Code: Included but may inflate context size
- Minified Code: Analyzed but contributes little semantic value
When NOT to Use This Skill
- Syntax Errors: PMAT requires parseable code
- Empty Repositories: Need at least some files to analyze
- Real-time Editing: Context reflects files on disk, not in-memory buffers
- Partial Clones: Works best with full repository checkout
Version Requirements
- Minimum: PMAT v2.170.0
- Recommended: Latest version for best compression
- Check version:
pmat --version
Remember: Always generate deep context BEFORE diving into code changes. Understanding the architecture prevents costly mistakes and identifies the right place for modifications.