# š¤ PAMPA for AI Agents ā Complete Setup & Usage Guide
**If you're an AI agent reading this, you can set up PAMPA automatically and use it as your project memory!**
## š Auto-Setup Instructions
### Step 1: Tell your human to configure MCP
**Ask your human to add this to their MCP configuration:**
```json
{
"mcpServers": {
"pampa": {
"command": "npx",
"args": ["-y", "pampa", "mcp"],
"env": {
"OPENAI_API_KEY": "optional-but-recommended"
}
}
}
}
```
**Configuration locations:**
- **Claude Desktop**: `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS)
- **Cursor**: `mcp.json` in user configuration directory
### Step 2: Auto-install this rule in your system
**Copy this rule into your system instructions:**
```markdown
# PAMPA MCP Usage Rule
You have access to PAMPA, a code memory system that indexes and allows semantic search in projects.
## Basic Instructions
1. **ALWAYS at the start of a session:**
- Run `get_project_stats` to check if the project is indexed
- If no database exists, run `index_project`
- Run `update_project` to sync with recent changes
2. **BEFORE creating any function:**
- Use `search_code` with semantic queries like "user authentication", "validate email", "error handling"
- Review existing code with `get_code_chunk` before writing new code
3. **AFTER modifying code:**
- Run `update_project` to update the knowledge base
- This keeps the project memory synchronized
## Available Tools
- `search_code(query, limit, path, filters...)` - š Advanced semantic search with scoping
- `get_code_chunk(sha, path)` - Get complete code of a chunk
- `index_project(path, provider)` - Index project for the first time
- `update_project(path, provider)` - Update index after changes
- `get_project_stats(path)` - Get project statistics
- `use_context_pack(name, path)` - š Activate predefined search scopes
## Strategy
Use PAMPA as your project memory. Search before creating, keep updated after changes, and leverage existing knowledge to avoid code duplication.
```
## š§ Essential Workflow for AI Agents
### š ALWAYS Start Every Session With This
```
1. get_project_stats() ā Check if project is indexed
2. update_project() ā Sync with recent changes
3. search_code("main functionality") ā Understand project structure
```
### š Smart Search Strategies
**Be semantic, not literal:**
- ā
"user authentication logic"
- ā "login() function"
**Use context:**
- ā
"error handling for API calls"
- ā "error"
**Check variations:**
- ā
"create user", "add user", "register user", "new user"
**Explore related concepts:**
- After finding auth ā search "validation", "security", "permissions"
### ā” Complete Development Workflow
```mermaid
graph TD
A[Start Session] --> B[get_project_stats]
B --> C[update_project]
C --> D[search_code for task context]
D --> E[Review existing code with get_code_chunk]
E --> F{Code exists?}
F -->|Yes| G[Modify/Extend existing]
F -->|No| H[Create new code]
G --> I[update_project]
H --> I
I --> J[Verify with search_code]
```
## šÆ Advanced Usage Patterns
### Project Discovery
```
1. get_project_stats() ā Overview
2. search_code("main entry point") ā Find starting point
3. search_code("configuration") ā Find config files
4. search_code("API endpoints") ā Find interfaces
5. search_code("database") ā Find data layer
```
### Before Creating Any Function
```
1. search_code("similar functionality description")
2. search_code("related helper functions")
3. search_code("validation patterns")
4. get_code_chunk(interesting_results) ā Study patterns
5. Only create if nothing suitable exists
```
### After Making Changes
```
1. update_project() ā Index your changes
2. search_code("your new function name") ā Verify indexing
3. search_code("related functionality") ā Check integration
```
## š§ Available MCP Tools Reference
### `search_code(query, limit=10, path=".", ...filters)`
**Purpose**: Advanced semantic search with scoping and hybrid ranking
**Basic Parameters:**
- `query`: Natural language description ("user validation", "error handling")
- `limit`: Number of results (default: 10)
- `path`: Project root directory (usually current directory)
**š NEW: Advanced Filtering & Ranking:**
- `path_glob`: Filter by file patterns (e.g., "app/Services/**", "src/components/**")
- `tags`: Filter by semantic tags (e.g., ["stripe", "payment"])
- `lang`: Filter by languages (e.g., ["php", "typescript"])
- `provider`: Override embedding provider ("auto", "openai", "transformers")
- `hybrid`: Enable hybrid search ("on", "off") - combines semantic + keyword
- `bm25`: Enable BM25 keyword search ("on", "off")
- `reranker`: Use cross-encoder reranker ("off", "transformers")
- `symbol_boost`: Enable symbol-aware ranking ("on", "off")
**Returns**: Array of {file, symbol, line, similarity, sha, meta}
### `get_code_chunk(sha, path=".")`
**Purpose**: Retrieve complete source code of a specific chunk
- `sha`: SHA identifier from search results
- `path`: Project root directory
- **Returns**: Complete source code with context
### `index_project(path=".", provider="auto")`
**Purpose**: Create initial project index (first time setup)
- `path`: Directory to index
- `provider`: Embedding provider (auto/openai/transformers/ollama/cohere)
- **Creates**: `.pampa/` directory with database and chunks
### `update_project(path=".", provider="auto")`
**Purpose**: Update index after code changes (use frequently!)
- `path`: Directory to update
- `provider`: Embedding provider
- **Updates**: Adds new functions, removes deleted ones, updates modified
### `get_project_stats(path=".")`
**Purpose**: Get project overview and statistics
- `path`: Directory to analyze
- **Returns**: File counts, languages, function statistics
### `use_context_pack(name, path=".")` š
**Purpose**: Activate predefined search scopes and filters
- `name`: Context pack name (e.g., "stripe-backend", "react-components")
- `path`: Project root directory
- **Effect**: Sets default filters for subsequent `search_code` calls
- **Use case**: Focus searches on specific domains or technologies
## š Interpreting Results
### Search Results Quality
- **Similarity > 0.7**: Excellent match, highly relevant
- **Similarity > 0.5**: Good match, worth examining
- **Similarity > 0.3**: Moderate match, might be useful
- **Similarity < 0.3**: Poor match, probably not relevant
### Project Stats Insights
```json
{
"total_functions": 150, // How many functions are indexed
"languages": ["javascript", "python"], // What languages detected
"files_by_language": {
// Distribution of code
"javascript": 45,
"python": 12
}
}
```
## šÆ Sample Prompts for Common Tasks
### Understanding a New Project
```
š "Let me explore this codebase structure"
ā get_project_stats()
š "Show me the main application logic"
ā search_code("main application entry point")
š "Find authentication and security functions"
ā search_code("authentication security login")
```
### Before Coding
```
š "Does this project have user validation?"
ā search_code("user validation input validation")
š "How is error handling implemented?"
ā search_code("error handling exception handling")
š "Are there existing API endpoints?"
ā search_code("API endpoint route handler")
š "What database operations exist?"
ā search_code("database query CRUD operations")
```
### During Development
```
š "Find functions similar to what I'm building"
ā search_code("description of your planned function")
š "Check existing utility functions"
ā search_code("utility helper functions")
š "Look for validation patterns"
ā search_code("validation pattern schema")
š "Focus search on specific directories"
ā search_code("payment processing", path_glob=["app/Services/**"])
š "Search only backend PHP code"
ā search_code("user authentication", lang=["php"])
š "Use context packs for domain focus"
ā use_context_pack("stripe-backend")
ā search_code("create payment session") // Now scoped to Stripe backend
š "Get better results with hybrid search"
ā search_code("checkout flow", hybrid="on", reranker="transformers")
```
### After Coding
```
š "Update the project index with my changes"
ā update_project()
š "Verify my new function was indexed"
ā search_code("your new function name")
š "Check integration with existing code"
ā search_code("related functionality")
```
## šØ Critical Reminders
### DO THIS ALWAYS:
- ā
**Start sessions** with `get_project_stats()` and `update_project()`
- ā
**Search before creating** any new function
- ā
**Update after changes** with `update_project()`
- ā
**Use semantic queries** not exact function names
- š ā
**Use scoped searches** for better precision: `path_glob`, `lang`, `tags`
- š ā
**Leverage context packs** for domain-specific work
- š ā
**Enable hybrid search** for better recall (default in v1.12+)
### NEVER DO THIS:
- ā **Skip searching** before writing code
- ā **Forget to update** after making changes
- ā **Search with exact code** instead of descriptions
- ā **Ignore existing implementations** that could be extended
- š ā **Search entire codebase** when you can scope to relevant areas
- š ā **Ignore context packs** that match your current task domain
## š Success Stories
**Before PAMPA**: "I'll create a new validation function"
**With PAMPA**: "Let me search for existing validation ā Found 3 similar functions ā Extended the best one"
**Before PAMPA**: "I need an API endpoint for users"
**With PAMPA**: "Searched for API patterns ā Found consistent structure ā Followed same pattern"
**Before PAMPA**: "Where's the database connection code?"
**With PAMPA**: "search_code('database connection') ā Found in 2 seconds"
## š New in v1.12: Advanced Features
### šÆ Scoped Search Examples
```javascript
// Search only in service layer
search_code('payment processing', { path_glob: ['app/Services/**'] });
// Search PHP backend only
search_code('user authentication', { lang: ['php'] });
// Search with tags
search_code('create session', { tags: ['stripe', 'payment'] });
// Combine multiple scopes
search_code('validation', {
path_glob: ['app/Http/**'],
lang: ['php'],
tags: ['api'],
});
```
### š Hybrid Search Benefits
- **Better recall**: Finds functions even with different terminology
- **Keyword + semantic**: Combines exact matches with meaning-based search
- **Default enabled**: No configuration needed in v1.12+
### š¦ Context Packs Workflow
```javascript
// 1. Activate domain-specific context
use_context_pack('stripe-backend');
// 2. All searches now automatically scoped
search_code('create payment'); // ā Only Stripe backend results
search_code('handle webhook'); // ā Only Stripe webhook handlers
search_code('refund transaction'); // ā Only Stripe refund logic
```
### ā” Performance Tips
- **Use scoped searches** for faster, more relevant results
- **Enable file watching** (`pampa watch`) for real-time updates
- **Use reranker** for critical searches: `reranker: "transformers"`
- **Leverage symbol boost** for function-specific searches
## š Additional Resources
- **Human-readable docs**: [README.md](README.md)
- **Spanish docs**: [README_es.md](README_es.md)
- **MCP rule file**: [RULE_FOR_PAMPA_MCP.md](RULE_FOR_PAMPA_MCP.md)
- **š Migration guide**: [MIGRATION_GUIDE_v1.12.md](MIGRATION_GUIDE_v1.12.md)
- **š Multi-project demo**: [DEMO_MULTI_PROJECT.md](DEMO_MULTI_PROJECT.md)
- **Project repository**: https://github.com/tecnomanu/pampa
## šØ Troubleshooting for AI Agents
### If PAMPA tools are not available:
1. **Check MCP configuration**: Ensure your human configured the MCP server correctly
2. **Verify installation**: Ask them to run `npx pampa --version`
3. **Enable debug mode**: Add `--debug` to MCP args for detailed logs
4. **Check permissions**: Ensure write access to project directory
### If indexing fails:
1. **Check embedding provider**: Transformers.js (free) vs OpenAI (requires API key)
2. **Verify project structure**: Must be a valid code project with supported files
3. **Check disk space**: Indexing creates `.pampa/` directory with database
---
š¤ **Remember**: PAMPA is your project memory. Use it continuously to avoid duplicating work and to understand existing codebase architecture. It's like having perfect memory of every function ever written in the project!