Instinct
Instinct is MyDeskBot's intelligent code awareness system that learns from your codebase and provides contextually relevant assistance.
What is Instinct?
Instinct is MyDeskBot's ability to understand your entire codebase beyond just the current file. It learns the structure, patterns, conventions, and relationships in your code to provide more accurate and relevant suggestions.
How Instinct Works
1. Codebase Indexing
MyDeskBot indexes your entire codebase:
- File structure: Understanding your project's organization
- Imports and dependencies: Tracking relationships between modules
- Function signatures: Knowing what functions exist and their parameters
- Type definitions: Understanding types and interfaces
- Documentation: Reading comments and docstrings
- Configuration: Analyzing config files
2. Pattern Learning
Instinct learns patterns in your code:
- Naming conventions: How you name variables, functions, classes
- Code structure: How you organize functions and classes
- Error handling: Your error handling patterns
- Testing style: How you structure tests
- Documentation style: Your comment and docstring formats
3. Context Understanding
Instinct understands context:
- Current file's role: What this file does in your project
- Related files: Files that are likely relevant
- Business logic: Understanding your domain-specific rules
- Architectural patterns: Your chosen patterns (MVC, Redux, etc.)
Instinct Features
1. Cross-file Suggestions
Get suggestions that understand your entire codebase:
# In utils/validation.py
def validate_email(email: str) -> bool:
return '@' in email
# In models/user.py
# Instinct knows about validate_email
# And can suggest using it
class User:
def __init__(self, email: str):
if not validate_email(email): # Suggestion: Use existing validator
raise ValueError("Invalid email")
self.email = email2. Consistent Style Enforcement
Instinct maintains consistency across your codebase:
// File A: Uses arrow functions
const fetchData = async () => {
const response = await fetch("/api/data");
return response.json();
};
// File B: Instinct suggests arrow functions to maintain consistency
// Instead of:
function processData() {
// ...
}
// Instinct suggests:
const processData = async () => {
// ...
};3. Automatic Imports
Instinct suggests the right imports:
# Type:
datetime.now()
# Instinct suggests:
from datetime import datetime
datetime.now()4. Pattern Completion
Complete patterns based on your codebase:
// If you have this pattern in your codebase:
public class Service {
private final Repository repository;
public Service(Repository repository) {
this.repository = repository;
}
public Entity getById(Long id) {
return repository.findById(id)
.orElseThrow(() -> new NotFoundException(id));
}
}
// Instinct can suggest similar for new services:
public class UserService {
private final UserRepository userRepository;
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
public User getById(Long id) {
return userRepository.findById(id)
.orElseThrow(() -> new UserNotFoundException(id));
}
}Enabling Instinct
Configuration
{
"mydeskbot.instinct": {
"enabled": true,
"indexing": {
"enabled": true,
"autoUpdate": true,
"includePatterns": ["**/*.{js,ts,py,java,go,rs}"],
"excludePatterns": [
"node_modules/**",
"**/*.min.js",
"dist/**",
"build/**"
]
},
"learning": {
"enabled": true,
"patternRecognition": true,
"styleLearning": true
}
}
}Initial Indexing
When you first enable Instinct:
- MyDeskBot indexes your entire codebase
- This may take a few minutes for large projects
- Index is stored locally for fast access
- Index is updated automatically as you code
Instinct Capabilities
1. Semantic Search
Search your codebase semantically:
User: Find the user authentication logic
MyDeskBot: Found in:
- src/auth/login.js: Handles user login
- src/middleware/auth.js: JWT authentication middleware
- src/services/auth.js: Authentication service2. Code Navigation
Navigate related code:
User: Take me to the user model definition
MyDeskBot: Opens src/models/user/User.ts3. Impact Analysis
Understand the impact of changes:
User: If I change the User interface, what will break?
MyDeskBot: These files will be affected:
- src/services/userService.ts (uses User)
- src/controllers/userController.ts (uses User)
- src/types/userTypes.ts (extends User)4. Documentation Generation
Generate documentation that matches your style:
# Instinct learns your docstring style:
def calculate_total(items):
"""Calculate total price of items.
Args:
items: List of items with price and quantity
Returns:
Total price as float
"""
# ...
# And generates consistent documentation:
def process_order(order):
"""Process an order and calculate totals.
Args:
order: Order object with items and customer info
Returns:
Processed order with calculated totals
Raises:
ValidationError: If order is invalid
"""
# ...Instinct Learning
What Instinct Learns
Instinct learns from your codebase:
Naming Conventions
- Variable naming: camelCase vs snake_case
- Function naming: verb prefixes (get, set, create, update)
- Class naming: PascalCase
Code Structure
- File organization
- Folder structure
- Module relationships
Error Handling
- Error types used
- Error message format
- Error propagation patterns
Testing Patterns
- Test file naming
- Test structure (AAA: Arrange, Act, Assert)
- Assertion style
Comment Style
- Comment frequency
- Comment format (JSDoc, docstrings)
- Comment content
Customizing Learning
You can customize what Instinct learns:
{
"mydeskbot.instinct.learning": {
"naming": true,
"structure": true,
"errorHandling": true,
"testing": true,
"documentation": true
}
}Instinct Commands
Available Commands
Query Instinct:
MyDeskBot: What patterns do you know about authentication in this project?Request Suggestions:
MyDeskBot: Suggest a function name following our conventionsFind Related Code:
MyDeskBot: Find all files that use the User classExplain Pattern:
MyDeskBot: Explain the error handling pattern in this codebaseBest Practices
1. Keep Code Consistent
Instinct works best with consistent code:
# Consistent naming
def get_user(id):
pass
def get_order(id):
pass
# Not consistent
def get_user(id):
pass
def fetch_order(id): # Different naming
pass2. Add Documentation
Help Instinct learn from documentation:
def process_payment(payment_data):
"""Process a payment with Stripe.
Args:
payment_data: Dictionary containing payment information
- amount: Payment amount in cents
- currency: Currency code (default: "usd")
- token: Stripe payment token
Returns:
Dictionary with payment result including:
- success: Boolean indicating payment status
- transaction_id: Stripe transaction ID
- error: Error message if failed
Raises:
PaymentError: If payment processing fails
Example:
>>> process_payment({
... "amount": 1000,
... "currency": "usd",
... "token": "tok_12345"
... })
{
"success": True,
"transaction_id": "pi_12345",
"error": None
}
"""
# Implementation3. Use Type Hints
Types help Instinct understand your code:
def create_user(
name: str,
email: str,
age: Optional[int] = None
) -> User:
"""Create a new user."""
return User(name=name, email=email, age=age)4. Follow Conventions
Instinct learns and reinforces conventions:
// Follow your framework's conventions
@RestController
@RequestMapping("/api/users")
public class UserController {
// ...
}Troubleshooting
Instinct Not Learning
Check:
- Instinct is enabled
- Project is indexed
- Files match include patterns
Solutions:
- Force re-index:
MyDeskBot: Re-index Project - Check exclude patterns
- Verify file types are supported
Poor Suggestions
Check:
- Code consistency
- Documentation quality
- Type hints
Solutions:
- Improve code consistency
- Add more documentation
- Use type hints
- Re-index project
Indexing Issues
Solutions:
- Clear cache:
MyDeskBot: Clear Cache - Re-index project
- Check available disk space
- Reduce indexing scope
Advanced Features
1. Multi-Project Awareness
Instinct can understand multiple related projects:
{
"mydeskbot.instinct.projects": {
"main": "/path/to/main/project",
"shared": "/path/to/shared/library"
}
}2. Custom Patterns
Define custom patterns for Instinct to learn:
{
"mydeskbot.instinct.patterns": {
"controller": {
"prefix": "",
"suffix": "Controller",
"methods": ["getById", "getAll", "create", "update", "delete"]
},
"service": {
"prefix": "",
"suffix": "Service",
"methods": ["findById", "findAll", "save", "delete"]
}
}
}3. Domain-Specific Learning
Train Instinct on your domain:
{
"mydeskbot.instinct.domain": {
"entities": ["User", "Order", "Product"],
"actions": ["create", "update", "delete", "get"],
"validators": ["validateEmail", "validatePhone"]
}
}