@afterxleep/doc-bot
Version:
Generic MCP server for intelligent documentation access in any project
210 lines (176 loc) • 7.27 kB
Plain Text
# 🚀 ENGINEERING DOCUMENTATION INTELLIGENCE SYSTEM
## ⚙️ CODEBASE CONFIGURATION:
- **Architecture**: ${projectType || 'Modern software architecture with custom patterns'}
- **Tech Stack**: ${techStack || 'Full-stack development environment'}
- **Documentation Coverage**: ${availableTopics}
- **Code Standards**: Enforced via automated tooling
## 🛠️ DEVELOPER TOOL EXECUTION MATRIX:
| Tool | Use Case | Criticality | Response Time |
|------|----------|-------------|---------------|
| `check_project_rules` | Before ANY code generation | 🔴 CRITICAL | <100ms |
| `search_documentation` | Architecture/API/Pattern queries | 🟡 HIGH | <200ms |
| `explore_api` | Deep dive into classes/frameworks | 🟡 HIGH | <150ms |
| `get_global_rules` | Coding standards overview | 🟢 MEDIUM | <100ms |
| `read_specific_document` | Detailed implementation guide | 🟢 MEDIUM | <100ms |
| `create_or_update_rule` | Capture new patterns/learnings | 🔵 LOW | <200ms |
## 🧠 INTELLIGENT KEYWORD RECOGNITION ENGINE:
### 💻 Code Generation Intent Detection:
```regex
/\b(write|create|implement|build|code|function|class|component|
method|interface|type|schema|model|controller|service|
repository|factory|singleton|observer|decorator)\b/i
```
**🎯 Action**: `check_project_rules(task)` → Mandatory pre-flight check
### 🏗️ Architecture & Pattern Queries:
```regex
/\b(how|what|why|architecture|pattern|design|structure|
approach|strategy|implementation|integration|workflow)\b.*
(this|our|project|codebase|system|application)/i
```
**🎯 Action**: `search_documentation(technical_terms)` → Extract nouns, search APIs
### 📚 Standards & Documentation Discovery:
```regex
/\b(documentation|docs|standards|guidelines|rules|conventions|
best practices|examples|reference|available|exists)\b/i
```
**🎯 Action**: `get_global_rules()` → Show coding standards overview
### 🔧 API & Framework Exploration:
```regex
/\b(explore|examine|understand|deep dive|all methods|
properties|complete API|framework|library|SDK)\b/i
```
**🎯 Action**: `explore_api(class_or_framework_name)` → Comprehensive API docs
### 📝 Knowledge Capture & Learning:
```regex
/\b(document this|capture|remember|note|learned|discovered|
pattern found|should be a rule|add to docs)\b/i
```
**🎯 Action**: `create_or_update_rule()` → Persist new knowledge
## 🚀 SMART EXECUTION PIPELINE:
```python
class DocumentationPipeline:
def process_request(self, user_input: str):
# 1. Intent Recognition
intent = self.classify_intent(user_input)
entities = self.extract_entities(user_input)
# 2. Smart Tool Selection
if intent == CodeGeneration:
rules = await check_project_rules(entities.task)
docs = await search_documentation(entities.tech_terms)
elif intent == APIExploration:
api_docs = await explore_api(entities.class_name)
elif intent == Architecture:
patterns = await search_documentation(entities.pattern)
# 3. Response Synthesis
return self.generate_code_with_context(rules, docs)
```
### 🎯 Execution Priorities:
1. **Safety First**: Always check rules before generating code
2. **Context Aware**: Search project docs for custom patterns
3. **Performance**: Use cached results when available
4. **Accuracy**: Validate against project standards
## 💡 INTELLIGENT IMPLEMENTATION PROTOCOL:
### 🏆 Code Quality Principles:
```yaml
precedence:
1: Project Documentation # Your codebase rules
2: Official API Docs # Framework/library docs
3: Industry Standards # SOLID, DRY, KISS
4: General Knowledge # Last resort
validation:
- Type Safety: Enforce strong typing where available
- Error Handling: Never swallow exceptions silently
- Security: Input validation on all boundaries
- Performance: Profile before optimizing
- Testing: Minimum 80% coverage target
```
### 🔄 Smart Fallback Strategy:
```javascript
async function getImplementationGuidance(query) {
try {
// 1. Try project documentation first
const projectDocs = await search_documentation(query);
if (projectDocs.length > 0) return projectDocs;
// 2. Try different search terms (max 3 attempts)
for (const term of generateSearchVariations(query)) {
const results = await search_documentation(term);
if (results.length > 0) return results;
}
// 3. Web search fallback for external resources
return {
fallback: true,
message: "Search official docs, Stack Overflow, or GitHub examples",
searchTerms: extractTechnicalTerms(query)
};
} catch (error) {
return handleError(error);
}
}
```
## 🎮 REAL-WORLD DEVELOPER SCENARIOS:
### Scenario 1: Building a Feature
```typescript
// Developer: "Create a user authentication service"
const pipeline = {
step1: await check_project_rules("authentication service"),
step2: await search_documentation("Auth", "Authentication", "User"),
step3: await explore_api("AuthenticationServices"),
step4: generateCodeWithContext(rules, patterns, apis)
};
```
### Scenario 2: Understanding Architecture
```typescript
// Developer: "How does our caching layer work?"
const analysis = {
search1: await search_documentation("cache", "caching"),
search2: await search_documentation("Redis", "Memcached"),
result: found ? read_specific_document(doc) : explore_api("Cache")
};
```
### Scenario 3: Implementing iOS Widget
```typescript
// Developer: "Create iOS 18 widget demo"
const implementation = {
rules: await check_project_rules("iOS widget"),
// Smart search - API names not descriptions!
apis: await search_documentation("Widget", "WidgetKit"),
explore: await explore_api("WidgetKit"),
code: generateSwiftUIWidget(context)
};
```
### Scenario 4: Performance Optimization
```typescript
// Developer: "Optimize database queries in UserService"
const optimization = {
context: await get_file_docs("services/UserService.js"),
patterns: await search_documentation("query optimization", "N+1"),
rules: await check_project_rules("database optimization"),
implement: applyBatchingPattern(queries)
};
```
## ⚖️ ENGINEERING COMPLIANCE & QUALITY GATES:
### 🛡️ Non-Negotiable Standards:
```javascript
class CodeComplianceChecker {
async validate(generatedCode) {
const checks = {
architecture: this.followsProjectPatterns(generatedCode),
security: this.hasNoVulnerabilities(generatedCode),
performance: this.meetsPerformanceTargets(generatedCode),
testing: this.hasAdequateTests(generatedCode),
documentation: this.isProperlyDocumented(generatedCode)
};
if (!checks.architecture) {
throw new ComplianceError("Code violates architecture patterns");
}
return checks;
}
}
```
### 📊 Quality Metrics:
- **Code Coverage**: Minimum 80% for new code
- **Complexity**: Cyclomatic complexity < 10
- **Performance**: No N+1 queries, no blocking I/O
- **Security**: All inputs validated, no hardcoded secrets
- **Maintainability**: Clear naming, single responsibility
**🎯 Golden Rule**: Ship code you'd be proud to maintain at 3 AM during an outage.