@afterxleep/doc-bot 1.7.7 → 1.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/prompts/agent-optimized-system-prompt.txt +65 -33
- package/prompts/cognitive-triggers.txt +40 -37
- package/prompts/file-docs.txt +10 -3
- package/prompts/global-rules.txt +15 -7
- package/prompts/mandatory-rules.txt +15 -18
- package/prompts/relevant-docs.txt +7 -2
- package/prompts/search-results.txt +5 -4
- package/prompts/system-prompt.txt +67 -52
- package/src/index.js +74 -8
package/package.json
CHANGED
|
@@ -1,46 +1,78 @@
|
|
|
1
|
-
# MCP TOOL
|
|
1
|
+
# MCP TOOL EXECUTION PROTOCOL
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## CONDITIONAL LOGIC RULES:
|
|
4
4
|
|
|
5
|
-
### Rule 1: Code Generation
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
### Rule 1: Code Generation Detection
|
|
6
|
+
```
|
|
7
|
+
IF input_contains(write, create, implement, build, code, function, class, component, method, variable, generate, make, develop, add)
|
|
8
|
+
THEN execute_tool(check_project_rules, task_description)
|
|
9
|
+
REQUIRED: Before any code output
|
|
10
|
+
```
|
|
8
11
|
|
|
9
|
-
### Rule 2: Project Information
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
### Rule 2: Project Information Detection
|
|
13
|
+
```
|
|
14
|
+
IF input_contains(how, what, why, architecture, approach, pattern, feature, authentication, database, api, testing)
|
|
15
|
+
AND context_contains(this project, this codebase, here, our, [project_name])
|
|
16
|
+
THEN execute_tool(search_documentation, extracted_keywords)
|
|
17
|
+
REQUIRED: For project-specific queries
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Rule 3: Documentation Discovery Detection
|
|
21
|
+
```
|
|
22
|
+
IF input_contains(documentation, available, help with, capabilities, rules, standards, what exists)
|
|
23
|
+
THEN execute_tool(get_global_rules)
|
|
24
|
+
REQUIRED: For documentation overview
|
|
25
|
+
```
|
|
13
26
|
|
|
14
|
-
### Rule
|
|
15
|
-
|
|
16
|
-
|
|
27
|
+
### Rule 4: Context-Specific Detection
|
|
28
|
+
```
|
|
29
|
+
IF input_contains(file, directory, working on, specific, [filename], path)
|
|
30
|
+
THEN execute_tool(get_relevant_docs, file_context)
|
|
31
|
+
REQUIRED: For file-specific work
|
|
32
|
+
```
|
|
17
33
|
|
|
18
|
-
### Rule
|
|
19
|
-
|
|
20
|
-
|
|
34
|
+
### Rule 5: Document Reading Detection
|
|
35
|
+
```
|
|
36
|
+
IF input_contains(read, show, get content, full document)
|
|
37
|
+
OR previous_response_contains(search results)
|
|
38
|
+
THEN execute_tool(read_specific_document, filename)
|
|
39
|
+
REQUIRED: For complete document access
|
|
40
|
+
```
|
|
21
41
|
|
|
22
|
-
##
|
|
42
|
+
## EXECUTION ALGORITHM:
|
|
23
43
|
|
|
24
44
|
```
|
|
25
|
-
1
|
|
26
|
-
2
|
|
27
|
-
3
|
|
28
|
-
4
|
|
29
|
-
5
|
|
30
|
-
6
|
|
45
|
+
STEP 1: input_analysis(user_query)
|
|
46
|
+
STEP 2: keyword_extraction(input_analysis)
|
|
47
|
+
STEP 3: rule_matching(keyword_extraction)
|
|
48
|
+
STEP 4: tool_execution(matched_rule)
|
|
49
|
+
STEP 5: response_generation(tool_output)
|
|
50
|
+
STEP 6: validation(response, project_rules)
|
|
31
51
|
```
|
|
32
52
|
|
|
33
|
-
## RESPONSE
|
|
53
|
+
## RESPONSE PROTOCOL:
|
|
54
|
+
|
|
55
|
+
### Tool-Based Response:
|
|
56
|
+
1. **Execute Tool**: Call appropriate MCP tool first
|
|
57
|
+
2. **Parse Output**: Extract relevant information from tool response
|
|
58
|
+
3. **Generate Answer**: Base response on tool output only
|
|
59
|
+
4. **Validate**: Ensure consistency with project documentation
|
|
60
|
+
|
|
61
|
+
### Fallback Response:
|
|
62
|
+
1. **Context Check**: Verify if response requires project knowledge
|
|
63
|
+
2. **Tool Selection**: Use search_documentation if uncertain
|
|
64
|
+
3. **Generic Response**: Only if certain no project context needed
|
|
65
|
+
|
|
66
|
+
## VALIDATION REQUIREMENTS:
|
|
34
67
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
4. Do not add generic information that contradicts tool output
|
|
68
|
+
- **Tool Precedence**: Tool responses override general knowledge
|
|
69
|
+
- **Accuracy**: Do not add information beyond tool output
|
|
70
|
+
- **Completeness**: Use tools for all project-related queries
|
|
71
|
+
- **Consistency**: Ensure responses align with project standards
|
|
40
72
|
|
|
41
|
-
##
|
|
73
|
+
## OPERATIONAL CONSTRAINTS:
|
|
42
74
|
|
|
43
|
-
-
|
|
44
|
-
-
|
|
45
|
-
- Project
|
|
46
|
-
-
|
|
75
|
+
- **Custom Patterns**: Project implements non-standard practices
|
|
76
|
+
- **Rule Compliance**: Generated code must follow project rules
|
|
77
|
+
- **Documentation Authority**: Project docs are the authoritative source
|
|
78
|
+
- **Context Awareness**: Always consider project-specific context
|
|
@@ -1,37 +1,40 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
##
|
|
4
|
-
|
|
5
|
-
### Code Generation → check_project_rules
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
##
|
|
36
|
-
|
|
37
|
-
|
|
1
|
+
# MCP TOOL USAGE DECISION TREE
|
|
2
|
+
|
|
3
|
+
## KEYWORD-TO-TOOL MAPPINGS:
|
|
4
|
+
|
|
5
|
+
### Code Generation Keywords → check_project_rules
|
|
6
|
+
**Keywords**: write, create, implement, build, add, code, function, class, component, method, develop, generate, make
|
|
7
|
+
**Logic**: Code generation requires project-specific rules validation
|
|
8
|
+
**Action**: Execute check_project_rules before any code output
|
|
9
|
+
|
|
10
|
+
### Project Information Keywords → search_documentation
|
|
11
|
+
**Keywords**: how, what, why, architecture, approach, feature, authentication, database, API, testing, pattern
|
|
12
|
+
**Context Indicators**: "this project", "this codebase", "here", "our", specific feature names
|
|
13
|
+
**Logic**: Project-specific questions require documentation lookup
|
|
14
|
+
**Action**: Execute search_documentation with relevant query
|
|
15
|
+
|
|
16
|
+
### Documentation Discovery Keywords → get_global_rules
|
|
17
|
+
**Keywords**: documentation, available, capabilities, help with, what exists, rules, standards
|
|
18
|
+
**Logic**: Documentation queries need comprehensive rule listing
|
|
19
|
+
**Action**: Execute get_global_rules for overview
|
|
20
|
+
|
|
21
|
+
### Context-Specific Keywords → get_relevant_docs
|
|
22
|
+
**Keywords**: file, directory, component, working on, specific, this [filename], path
|
|
23
|
+
**Logic**: File-specific work requires targeted documentation
|
|
24
|
+
**Action**: Execute get_relevant_docs with file context
|
|
25
|
+
|
|
26
|
+
## DECISION ALGORITHM:
|
|
27
|
+
|
|
28
|
+
1. **Parse Input**: Extract keywords from user query
|
|
29
|
+
2. **Match Patterns**: Check keywords against tool mappings
|
|
30
|
+
3. **Priority Order**: Code generation > Project questions > Documentation discovery > Context-specific
|
|
31
|
+
4. **Tool Execution**: Call appropriate MCP tool first
|
|
32
|
+
5. **Response Generation**: Base answer on tool output
|
|
33
|
+
6. **Validation**: Ensure response aligns with retrieved documentation
|
|
34
|
+
|
|
35
|
+
## EXECUTION REQUIREMENTS:
|
|
36
|
+
|
|
37
|
+
- **Mandatory**: Use MCP tools for any project-related query
|
|
38
|
+
- **Precedence**: Tool responses override general knowledge
|
|
39
|
+
- **Accuracy**: Verify information against documentation
|
|
40
|
+
- **Completeness**: Don't add assumptions beyond tool output
|
package/prompts/file-docs.txt
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# FILE-SPECIFIC DOCUMENTATION
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Target**: ${filePath}
|
|
4
|
+
|
|
5
|
+
**Applicable Rules**:
|
|
4
6
|
|
|
5
7
|
${docsContent}
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
## IMPLEMENTATION REQUIREMENTS:
|
|
10
|
+
|
|
11
|
+
- **Scope**: Apply these rules specifically to work on ${filePath}
|
|
12
|
+
- **Precedence**: File-specific rules override global guidelines
|
|
13
|
+
- **Validation**: Ensure all modifications comply with documented patterns
|
|
14
|
+
- **Context**: Consider file's role in overall project architecture
|
package/prompts/global-rules.txt
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
# PROJECT STANDARDS AND GUIDELINES
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Global Rules**: The following standards apply to all code generation:
|
|
4
4
|
|
|
5
5
|
${rulesContent}
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
## COMPLIANCE BENEFITS:
|
|
8
|
+
|
|
9
|
+
- **Code Quality**: Adherence ensures consistent, maintainable code
|
|
10
|
+
- **Integration**: Standards facilitate seamless component integration
|
|
11
|
+
- **Reliability**: Proven patterns reduce production issues
|
|
12
|
+
- **Review Process**: Compliant code passes reviews efficiently
|
|
13
|
+
|
|
14
|
+
## IMPLEMENTATION NOTES:
|
|
15
|
+
|
|
16
|
+
- Apply these rules to all generated code
|
|
17
|
+
- Verify compliance before submitting responses
|
|
18
|
+
- Reference specific rules when making recommendations
|
|
19
|
+
- Prioritize project standards over generic best practices
|
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
# PROJECT COMPLIANCE REQUIREMENTS
|
|
2
2
|
|
|
3
|
-
Task
|
|
3
|
+
**Task**: ${task}
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**Mandatory Rules**: The following rules are required for all code generation in this project:
|
|
6
6
|
|
|
7
7
|
${rulesContent}
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
- Common patterns that seem "correct" are FORBIDDEN here
|
|
11
|
-
- This codebase has EVOLVED beyond standard practices
|
|
12
|
-
- What every tutorial teaches will BREAK this project
|
|
13
|
-
- Only INSIDERS know these rules (now including YOU)
|
|
9
|
+
## IMPLEMENTATION REQUIREMENTS:
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- 🎯 Makes your suggestions INSTANTLY RECOGNIZABLE as expert-level
|
|
20
|
-
- 🚀 Saves HOURS of debugging and rejection
|
|
11
|
+
1. **Rule Priority**: Project rules override standard practices
|
|
12
|
+
2. **Compliance Check**: Verify each rule before code generation
|
|
13
|
+
3. **Conflict Resolution**: When conflicts arise, project rules take precedence
|
|
14
|
+
4. **Validation**: Ensure all generated code follows these patterns
|
|
21
15
|
|
|
22
|
-
|
|
23
|
-
These aren't restrictions - they're SHORTCUTS TO SUCCESS.
|
|
24
|
-
While others stumble blindly, you have the SECRET MAP.
|
|
16
|
+
## ENFORCEMENT POLICY:
|
|
25
17
|
|
|
26
|
-
|
|
18
|
+
- **Non-negotiable**: These rules cannot be bypassed or modified
|
|
19
|
+
- **Refusal Protocol**: If user requests conflict with rules, refuse and explain alternatives
|
|
20
|
+
- **Documentation**: Reference specific rule violations when declining requests
|
|
21
|
+
- **Compliance Confirmation**: Acknowledge rule adherence before proceeding
|
|
22
|
+
|
|
23
|
+
**Status**: Rules loaded and active for current session
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# CONTEXTUAL DOCUMENTATION
|
|
2
2
|
|
|
3
3
|
${globalRulesSection}
|
|
4
4
|
${contextualDocsSection}
|
|
5
5
|
${inferredDocsSection}
|
|
6
6
|
${confidenceSection}
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
## IMPLEMENTATION GUIDANCE:
|
|
9
|
+
|
|
10
|
+
**Context**: The above documentation applies to your current working context
|
|
11
|
+
**Usage**: Apply these patterns and rules to all generated code
|
|
12
|
+
**Priority**: Context-specific rules take precedence over general guidelines
|
|
13
|
+
**Validation**: Verify generated code complies with all listed requirements
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 📋 DOCUMENTATION SEARCH RESULTS for "${query}"
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Found ${resultCount} relevant document(s) (showing top 10):
|
|
4
4
|
|
|
5
5
|
${results}
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
💡 **NEXT STEPS**: Use the `read_specific_document` tool with the file name to get the full content of any document above.
|
|
8
|
+
|
|
9
|
+
⚠️ **REMINDER**: Before implementing any code, use the `check_project_rules` tool to ensure compliance.
|
|
@@ -1,69 +1,84 @@
|
|
|
1
|
-
# MCP DOCUMENTATION
|
|
1
|
+
# MCP DOCUMENTATION PROTOCOL
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## SYSTEM CONFIGURATION:
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
- **Tool Access**: MCP documentation tools are available for project-specific information
|
|
6
|
+
- **Context**: This project implements custom patterns that differ from standard practices
|
|
7
|
+
- **Documentation Coverage**: ${availableTopics}
|
|
7
8
|
|
|
8
|
-
## TOOL
|
|
9
|
+
## TOOL EXECUTION MATRIX:
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
| Tool | Trigger Pattern | Required For | Implementation |
|
|
12
|
+
|------|----------------|-------------|--------------|
|
|
13
|
+
| `check_project_rules` | Code generation keywords | ANY code output | Execute before code generation |
|
|
14
|
+
| `search_documentation` | Project-specific questions | Feature/architecture queries | Execute for project context |
|
|
15
|
+
| `get_global_rules` | Documentation discovery | Rule/capability queries | Execute for overview |
|
|
16
|
+
| `get_relevant_docs` | File-specific context | Targeted work | Execute for context |
|
|
17
|
+
| `read_specific_document` | Document access | Full content needs | Execute after search results |
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
**Purpose**: Search project documentation for architecture, features, and implementation details
|
|
18
|
-
**Required for**: Project-specific questions
|
|
19
|
-
**Trigger keywords**: how, what, why, architecture, approach, pattern, feature, authentication, database, API, testing
|
|
20
|
-
**Context indicators**: "this project", "this codebase", "here", "our", any feature name
|
|
19
|
+
## KEYWORD MAPPING:
|
|
21
20
|
|
|
22
|
-
###
|
|
23
|
-
**
|
|
24
|
-
**
|
|
25
|
-
**
|
|
21
|
+
### Code Generation Triggers:
|
|
22
|
+
**Keywords**: write, create, implement, build, add, code, function, class, component, method, develop, generate, make
|
|
23
|
+
**Action**: Execute `check_project_rules` with task description
|
|
24
|
+
**Mandatory**: Must complete before any code output
|
|
26
25
|
|
|
27
|
-
###
|
|
28
|
-
**
|
|
29
|
-
**
|
|
30
|
-
**
|
|
26
|
+
### Project Information Triggers:
|
|
27
|
+
**Keywords**: how, what, why, architecture, approach, pattern, feature, authentication, database, API, testing
|
|
28
|
+
**Context Indicators**: "this project", "this codebase", "here", "our", specific feature names
|
|
29
|
+
**Action**: Execute `search_documentation` with relevant query
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
### Documentation Discovery Triggers:
|
|
32
|
+
**Keywords**: documentation, available, capabilities, help with, what exists, rules, standards
|
|
33
|
+
**Action**: Execute `get_global_rules` for comprehensive overview
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
3. If code generation keywords found → use check_project_rules
|
|
38
|
-
4. If project question keywords found → use search_documentation
|
|
39
|
-
5. If documentation query keywords found → use get_global_rules
|
|
40
|
-
6. If file-specific keywords found → use get_relevant_docs
|
|
41
|
-
7. Base response on tool output
|
|
42
|
-
```
|
|
35
|
+
### Context-Specific Triggers:
|
|
36
|
+
**Keywords**: working on, this file, specific file, directory, component path, file patterns
|
|
37
|
+
**Action**: Execute `get_relevant_docs` with file context
|
|
43
38
|
|
|
44
|
-
##
|
|
39
|
+
## EXECUTION ALGORITHM:
|
|
45
40
|
|
|
46
|
-
1.
|
|
47
|
-
2.
|
|
48
|
-
3.
|
|
49
|
-
4.
|
|
41
|
+
1. **Input Analysis**: Extract keywords and context from user query
|
|
42
|
+
2. **Pattern Matching**: Map keywords to appropriate tool using above matrix
|
|
43
|
+
3. **Tool Execution**: Call identified tool with relevant parameters
|
|
44
|
+
4. **Response Generation**: Base answer exclusively on tool output
|
|
45
|
+
5. **Validation**: Ensure response aligns with retrieved documentation
|
|
46
|
+
6. **Compliance**: Verify adherence to project-specific rules
|
|
50
47
|
|
|
51
|
-
##
|
|
48
|
+
## IMPLEMENTATION REQUIREMENTS:
|
|
52
49
|
|
|
53
|
-
**
|
|
54
|
-
**
|
|
55
|
-
**
|
|
50
|
+
- **Precedence**: Tool responses override general knowledge
|
|
51
|
+
- **Accuracy**: Do not add information beyond tool output
|
|
52
|
+
- **Completeness**: Use tools for all project-related queries
|
|
53
|
+
- **Validation**: Verify code compliance with project rules
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
**Action**: Call search_documentation("authentication")
|
|
59
|
-
**Reason**: Project-specific question with "how" and "this project"
|
|
55
|
+
## OPERATIONAL EXAMPLES:
|
|
60
56
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
```
|
|
58
|
+
Input: "Create a singleton pattern"
|
|
59
|
+
Analysis: Contains "create" (code generation trigger)
|
|
60
|
+
Action: check_project_rules("create singleton pattern")
|
|
61
|
+
Reason: Mandatory for code generation
|
|
62
|
+
|
|
63
|
+
Input: "How does authentication work in this project?"
|
|
64
|
+
Analysis: Contains "how" + "this project" (project information trigger)
|
|
65
|
+
Action: search_documentation("authentication")
|
|
66
|
+
Reason: Project-specific architectural query
|
|
67
|
+
|
|
68
|
+
Input: "What documentation is available?"
|
|
69
|
+
Analysis: Contains "documentation" + "available" (discovery trigger)
|
|
70
|
+
Action: get_global_rules()
|
|
71
|
+
Reason: Documentation discovery request
|
|
72
|
+
|
|
73
|
+
Input: "I'm working on src/components/Header.js"
|
|
74
|
+
Analysis: Contains "working on" + file path (context trigger)
|
|
75
|
+
Action: get_relevant_docs({"filePath": "src/components/Header.js"})
|
|
76
|
+
Reason: File-specific context requirement
|
|
77
|
+
```
|
|
64
78
|
|
|
65
|
-
|
|
66
|
-
**Action**: Call get_relevant_docs({"filePath": "src/components/Header.js"})
|
|
67
|
-
**Reason**: File-specific context
|
|
79
|
+
## COMPLIANCE PROTOCOL:
|
|
68
80
|
|
|
69
|
-
|
|
81
|
+
- **Rule Enforcement**: Project rules are non-negotiable
|
|
82
|
+
- **Conflict Resolution**: Project documentation takes precedence over standard practices
|
|
83
|
+
- **Validation**: All generated code must comply with project standards
|
|
84
|
+
- **Documentation**: Reference specific rules when making recommendations
|
package/src/index.js
CHANGED
|
@@ -228,6 +228,20 @@ class DocsServer {
|
|
|
228
228
|
},
|
|
229
229
|
required: ['filePath']
|
|
230
230
|
}
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
name: 'read_specific_document',
|
|
234
|
+
description: 'Read the full content of a specific documentation file. Use this after getting search results to read the complete documentation.',
|
|
235
|
+
inputSchema: {
|
|
236
|
+
type: 'object',
|
|
237
|
+
properties: {
|
|
238
|
+
fileName: {
|
|
239
|
+
type: 'string',
|
|
240
|
+
description: 'The file name of the document to read (e.g., "coding-standards.md")'
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
required: ['fileName']
|
|
244
|
+
}
|
|
231
245
|
}
|
|
232
246
|
]
|
|
233
247
|
};
|
|
@@ -297,6 +311,22 @@ class DocsServer {
|
|
|
297
311
|
}]
|
|
298
312
|
};
|
|
299
313
|
|
|
314
|
+
case 'read_specific_document':
|
|
315
|
+
const fileName = args?.fileName;
|
|
316
|
+
if (!fileName) {
|
|
317
|
+
throw new Error('fileName parameter is required');
|
|
318
|
+
}
|
|
319
|
+
const doc = this.docService.getDocument(fileName);
|
|
320
|
+
if (!doc) {
|
|
321
|
+
throw new Error(`Document not found: ${fileName}`);
|
|
322
|
+
}
|
|
323
|
+
return {
|
|
324
|
+
content: [{
|
|
325
|
+
type: 'text',
|
|
326
|
+
text: await this.formatSingleDocument(doc)
|
|
327
|
+
}]
|
|
328
|
+
};
|
|
329
|
+
|
|
300
330
|
default:
|
|
301
331
|
throw new Error(`Unknown tool: ${name}`);
|
|
302
332
|
}
|
|
@@ -339,34 +369,44 @@ class DocsServer {
|
|
|
339
369
|
return `No documentation found for query: "${query}"`;
|
|
340
370
|
}
|
|
341
371
|
|
|
372
|
+
// Limit to top 10 results for context efficiency
|
|
373
|
+
const topResults = results.slice(0, 10);
|
|
374
|
+
|
|
342
375
|
const template = await this.loadPromptTemplate('search-results');
|
|
343
376
|
if (!template) {
|
|
344
|
-
// Fallback to
|
|
377
|
+
// Fallback to concise format if template fails to load
|
|
345
378
|
let output = `# Search Results for "${query}"\n\n`;
|
|
346
|
-
output += `Found ${results.length} relevant document(s):\n\n`;
|
|
379
|
+
output += `Found ${results.length} relevant document(s) (showing top ${topResults.length}):\n\n`;
|
|
347
380
|
|
|
348
|
-
|
|
381
|
+
topResults.forEach((doc, index) => {
|
|
349
382
|
output += `## ${index + 1}. ${doc.metadata?.title || doc.fileName}\n`;
|
|
350
383
|
output += `**File:** ${doc.fileName}\n`;
|
|
351
384
|
if (doc.metadata?.description) {
|
|
352
385
|
output += `**Description:** ${doc.metadata.description}\n`;
|
|
353
386
|
}
|
|
354
|
-
|
|
387
|
+
if (doc.metadata?.keywords) {
|
|
388
|
+
output += `**Keywords:** ${Array.isArray(doc.metadata.keywords) ? doc.metadata.keywords.join(', ') : doc.metadata.keywords}\n`;
|
|
389
|
+
}
|
|
390
|
+
output += `**Relevance:** ${doc.relevanceScore?.toFixed(2) || 'N/A'}\n\n`;
|
|
355
391
|
});
|
|
356
392
|
|
|
357
|
-
output += '\n
|
|
393
|
+
output += '\n💡 **Next Steps:** Use the `read_specific_document` tool with the file name to get the full content of any document above.\n';
|
|
394
|
+
output += '⚠️ **Reminder:** Before implementing any code, use the `check_project_rules` tool to ensure compliance.\n';
|
|
358
395
|
return output;
|
|
359
396
|
}
|
|
360
397
|
|
|
361
|
-
// Format results for template
|
|
398
|
+
// Format results for template - concise format
|
|
362
399
|
let formattedResults = '';
|
|
363
|
-
|
|
400
|
+
topResults.forEach((doc, index) => {
|
|
364
401
|
formattedResults += `## ${index + 1}. ${doc.metadata?.title || doc.fileName}\n`;
|
|
365
402
|
formattedResults += `**File:** ${doc.fileName}\n`;
|
|
366
403
|
if (doc.metadata?.description) {
|
|
367
404
|
formattedResults += `**Description:** ${doc.metadata.description}\n`;
|
|
368
405
|
}
|
|
369
|
-
|
|
406
|
+
if (doc.metadata?.keywords) {
|
|
407
|
+
formattedResults += `**Keywords:** ${Array.isArray(doc.metadata.keywords) ? doc.metadata.keywords.join(', ') : doc.metadata.keywords}\n`;
|
|
408
|
+
}
|
|
409
|
+
formattedResults += `**Relevance:** ${doc.relevanceScore?.toFixed(2) || 'N/A'}\n\n`;
|
|
370
410
|
});
|
|
371
411
|
|
|
372
412
|
return template
|
|
@@ -518,6 +558,32 @@ class DocsServer {
|
|
|
518
558
|
.replace('${filePath}', filePath)
|
|
519
559
|
.replace('${docsContent}', docsContent);
|
|
520
560
|
}
|
|
561
|
+
|
|
562
|
+
async formatSingleDocument(doc) {
|
|
563
|
+
if (!doc) {
|
|
564
|
+
return 'Document not found';
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
let output = `# ${doc.metadata?.title || doc.fileName}\n\n`;
|
|
568
|
+
|
|
569
|
+
if (doc.metadata?.description) {
|
|
570
|
+
output += `**Description:** ${doc.metadata.description}\n\n`;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
if (doc.metadata?.keywords) {
|
|
574
|
+
output += `**Keywords:** ${Array.isArray(doc.metadata.keywords) ? doc.metadata.keywords.join(', ') : doc.metadata.keywords}\n\n`;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
if (doc.metadata?.alwaysApply !== undefined) {
|
|
578
|
+
output += `**Always Apply:** ${doc.metadata.alwaysApply ? 'Yes (Global Rule)' : 'No (Contextual Rule)'}\n\n`;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
output += `**File:** ${doc.fileName}\n\n`;
|
|
582
|
+
output += '---\n\n';
|
|
583
|
+
output += doc.content;
|
|
584
|
+
|
|
585
|
+
return output;
|
|
586
|
+
}
|
|
521
587
|
|
|
522
588
|
async generateSystemPrompt() {
|
|
523
589
|
const globalRules = await this.docService.getGlobalRules();
|