@afterxleep/doc-bot 1.2.0 ā 1.4.0
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/README.md +40 -5
- package/package.json +1 -1
- package/src/index.js +164 -14
package/README.md
CHANGED
|
@@ -111,13 +111,48 @@ Run tests with: `npm test`
|
|
|
111
111
|
|
|
112
112
|
## Rule Enforcement
|
|
113
113
|
|
|
114
|
-
Doc-bot ensures your rules are **always considered** through
|
|
114
|
+
Doc-bot ensures your rules are **always considered** through multiple enforcement mechanisms:
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
-
|
|
118
|
-
- **
|
|
116
|
+
### šØ Mandatory Rule Checking
|
|
117
|
+
- **`check_project_rules` tool**: Must be called before ANY code generation
|
|
118
|
+
- **Aggressive descriptions**: All tools emphasize mandatory rule compliance
|
|
119
|
+
- **Rule reminders**: Every tool response includes compliance warnings
|
|
119
120
|
|
|
120
|
-
|
|
121
|
+
### š Automatic Integration
|
|
122
|
+
- **Enhanced system prompt injection**: Comprehensive MCP usage protocol injected via `docs://system-prompt`
|
|
123
|
+
- **Documentation discovery**: Available topics automatically extracted and presented to agent
|
|
124
|
+
- **Tool usage instructions**: Explicit requirements for when and how to use each MCP tool
|
|
125
|
+
- **Contextual rules**: Applied when working with matching files/patterns
|
|
126
|
+
- **Multiple touchpoints**: Rules enforced at every interaction level
|
|
127
|
+
|
|
128
|
+
### ā ļø Compliance Warnings
|
|
129
|
+
All tool responses include explicit warnings that rules are:
|
|
130
|
+
- **NON-NEGOTIABLE**: Must be followed without exception
|
|
131
|
+
- **MANDATORY**: Violation will result in rejection
|
|
132
|
+
- **CRITICAL**: Require acknowledgment before proceeding
|
|
133
|
+
|
|
134
|
+
This multi-layered approach makes rule violations virtually impossible to ignore.
|
|
135
|
+
|
|
136
|
+
## System Prompt Integration
|
|
137
|
+
|
|
138
|
+
The `docs://system-prompt` resource automatically injects comprehensive instructions into the AI agent's system context:
|
|
139
|
+
|
|
140
|
+
### š MCP Usage Protocol
|
|
141
|
+
- Explicit instructions to **ALWAYS** call `check_project_rules` before code generation
|
|
142
|
+
- **NEVER generate code without checking documentation** requirement
|
|
143
|
+
- Mandatory acknowledgment of rule compliance
|
|
144
|
+
|
|
145
|
+
### š·ļø Automatic Topic Discovery
|
|
146
|
+
- Extracts available documentation topics from your project
|
|
147
|
+
- Presents them to the agent for context awareness
|
|
148
|
+
- Includes topics from metadata, filenames, and content analysis
|
|
149
|
+
|
|
150
|
+
### š ļø Tool Usage Requirements
|
|
151
|
+
- Specifies when and how to use each MCP tool
|
|
152
|
+
- Maps tools to specific use cases (file-specific docs, search, etc.)
|
|
153
|
+
- Ensures comprehensive documentation coverage
|
|
154
|
+
|
|
155
|
+
The system prompt is regenerated on each request to reflect current documentation state.
|
|
121
156
|
|
|
122
157
|
## The manifest file
|
|
123
158
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -133,6 +133,20 @@ class DocsServer {
|
|
|
133
133
|
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
134
134
|
return {
|
|
135
135
|
tools: [
|
|
136
|
+
{
|
|
137
|
+
name: 'check_project_rules',
|
|
138
|
+
description: 'ā ļø MANDATORY: Must be called before generating ANY code. Returns critical project rules and coding standards that MUST be followed.',
|
|
139
|
+
inputSchema: {
|
|
140
|
+
type: 'object',
|
|
141
|
+
properties: {
|
|
142
|
+
task: {
|
|
143
|
+
type: 'string',
|
|
144
|
+
description: 'Brief description of the coding task about to be performed'
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
required: ['task']
|
|
148
|
+
}
|
|
149
|
+
},
|
|
136
150
|
{
|
|
137
151
|
name: 'search_documentation',
|
|
138
152
|
description: 'Search documentation by query',
|
|
@@ -149,7 +163,7 @@ class DocsServer {
|
|
|
149
163
|
},
|
|
150
164
|
{
|
|
151
165
|
name: 'get_relevant_docs',
|
|
152
|
-
description: 'Get context-aware documentation suggestions',
|
|
166
|
+
description: 'Get context-aware documentation suggestions including project rules that must be followed',
|
|
153
167
|
inputSchema: {
|
|
154
168
|
type: 'object',
|
|
155
169
|
properties: {
|
|
@@ -168,7 +182,7 @@ class DocsServer {
|
|
|
168
182
|
},
|
|
169
183
|
{
|
|
170
184
|
name: 'get_global_rules',
|
|
171
|
-
description: 'Get
|
|
185
|
+
description: 'Get critical project rules that must ALWAYS be followed when writing code',
|
|
172
186
|
inputSchema: {
|
|
173
187
|
type: 'object',
|
|
174
188
|
properties: {}
|
|
@@ -198,6 +212,16 @@ class DocsServer {
|
|
|
198
212
|
|
|
199
213
|
try {
|
|
200
214
|
switch (name) {
|
|
215
|
+
case 'check_project_rules':
|
|
216
|
+
const task = args?.task || 'code generation';
|
|
217
|
+
const mandatoryRules = await this.getMandatoryRules(task);
|
|
218
|
+
return {
|
|
219
|
+
content: [{
|
|
220
|
+
type: 'text',
|
|
221
|
+
text: mandatoryRules
|
|
222
|
+
}]
|
|
223
|
+
};
|
|
224
|
+
|
|
201
225
|
case 'search_documentation':
|
|
202
226
|
const query = args?.query;
|
|
203
227
|
if (!query) {
|
|
@@ -300,6 +324,9 @@ class DocsServer {
|
|
|
300
324
|
output += `\n${doc.content}\n\n---\n\n`;
|
|
301
325
|
});
|
|
302
326
|
|
|
327
|
+
// Add rule reminder to all search results
|
|
328
|
+
output += '\nā ļø REMINDER: Before implementing any code, use the check_project_rules tool to ensure compliance.\n';
|
|
329
|
+
|
|
303
330
|
return output;
|
|
304
331
|
}
|
|
305
332
|
|
|
@@ -334,22 +361,29 @@ class DocsServer {
|
|
|
334
361
|
output += `**Confidence:** ${relevant.confidence.toFixed(2)}\n\n`;
|
|
335
362
|
}
|
|
336
363
|
|
|
364
|
+
// Add rule reminder for contextual docs
|
|
365
|
+
output += '\nā ļø CRITICAL: These rules are MANDATORY and must be followed before generating code.\n';
|
|
366
|
+
|
|
337
367
|
return output;
|
|
338
368
|
}
|
|
339
369
|
|
|
340
370
|
formatGlobalRules(globalRules) {
|
|
341
371
|
if (!globalRules || globalRules.length === 0) {
|
|
342
|
-
return 'No global rules defined.';
|
|
372
|
+
return 'ā WARNING: No global rules defined. Consider adding project rules for code consistency.';
|
|
343
373
|
}
|
|
344
374
|
|
|
345
|
-
let output = '
|
|
346
|
-
output += 'These rules
|
|
375
|
+
let output = 'šØ MANDATORY Global Rules (ALWAYS Apply) šØ\n\n';
|
|
376
|
+
output += 'ā ļø CRITICAL: These rules are NON-NEGOTIABLE and must be followed in ALL code generation:\n\n';
|
|
347
377
|
|
|
348
|
-
globalRules.forEach(rule => {
|
|
349
|
-
output += `## ${rule.metadata?.title || rule.fileName}\n`;
|
|
378
|
+
globalRules.forEach((rule, index) => {
|
|
379
|
+
output += `## ${index + 1}. ${rule.metadata?.title || rule.fileName}\n`;
|
|
350
380
|
output += `${rule.content}\n\n`;
|
|
381
|
+
output += '---\n\n';
|
|
351
382
|
});
|
|
352
383
|
|
|
384
|
+
output += 'ā
ACKNOWLEDGMENT REQUIRED: You must confirm compliance with these rules before proceeding.\n';
|
|
385
|
+
output += 'ā VIOLATION: Any code that violates these rules will be rejected.\n';
|
|
386
|
+
|
|
353
387
|
return output;
|
|
354
388
|
}
|
|
355
389
|
|
|
@@ -370,22 +404,138 @@ class DocsServer {
|
|
|
370
404
|
|
|
371
405
|
async generateSystemPrompt() {
|
|
372
406
|
const globalRules = await this.docService.getGlobalRules();
|
|
407
|
+
const allDocs = await this.docService.getAllDocuments();
|
|
408
|
+
|
|
409
|
+
let prompt = '# CRITICAL: Project Documentation and MCP Server Integration\n\n';
|
|
410
|
+
|
|
411
|
+
// Add MCP server usage instructions
|
|
412
|
+
prompt += '## š§ MANDATORY: MCP Server Usage Protocol\n\n';
|
|
413
|
+
prompt += 'You have access to a doc-bot MCP server with the following MANDATORY requirements:\n\n';
|
|
414
|
+
prompt += '### šØ BEFORE ANY CODE GENERATION:\n';
|
|
415
|
+
prompt += '1. **ALWAYS** call `check_project_rules` tool first to get critical project rules\n';
|
|
416
|
+
prompt += '2. **NEVER generate code without checking project documentation**\n';
|
|
417
|
+
prompt += '3. **REQUIRED** to acknowledge rule compliance before proceeding\n\n';
|
|
418
|
+
|
|
419
|
+
prompt += '### š Available Documentation Resources:\n';
|
|
420
|
+
if (allDocs && allDocs.length > 0) {
|
|
421
|
+
const docTopics = this.extractDocumentationTopics(allDocs);
|
|
422
|
+
prompt += 'This project has documentation covering:\n';
|
|
423
|
+
docTopics.forEach(topic => {
|
|
424
|
+
prompt += `- ${topic}\n`;
|
|
425
|
+
});
|
|
426
|
+
prompt += '\n';
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
prompt += '### š ļø Required MCP Tool Usage:\n';
|
|
430
|
+
prompt += '- Use `check_project_rules` before ANY code generation\n';
|
|
431
|
+
prompt += '- Use `get_relevant_docs` when working with specific files/patterns\n';
|
|
432
|
+
prompt += '- Use `search_documentation` to find specific guidance\n';
|
|
433
|
+
prompt += '- Use `get_global_rules` for comprehensive rule review\n\n';
|
|
434
|
+
|
|
435
|
+
// Add project-specific rules
|
|
436
|
+
if (globalRules && globalRules.length > 0) {
|
|
437
|
+
prompt += '## š Project-Specific Rules (NON-NEGOTIABLE)\n\n';
|
|
438
|
+
prompt += 'IMPORTANT: You MUST follow these rules before generating ANY code:\n\n';
|
|
439
|
+
|
|
440
|
+
globalRules.forEach((rule, index) => {
|
|
441
|
+
prompt += `### Rule ${index + 1}: ${rule.metadata?.title || rule.fileName}\n`;
|
|
442
|
+
prompt += `${rule.content}\n\n`;
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
prompt += '---\n\n';
|
|
447
|
+
prompt += 'ā ļø **CRITICAL COMPLIANCE REQUIREMENTS:**\n';
|
|
448
|
+
prompt += '- VIOLATION OF THESE RULES IS NOT ACCEPTABLE\n';
|
|
449
|
+
prompt += '- ALWAYS use MCP tools before coding\n';
|
|
450
|
+
prompt += '- ACKNOWLEDGE rule compliance before responding\n';
|
|
451
|
+
prompt += '- NEVER assume - always check documentation\n';
|
|
452
|
+
|
|
453
|
+
return prompt;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
extractDocumentationTopics(docs) {
|
|
457
|
+
const topics = new Set();
|
|
458
|
+
|
|
459
|
+
docs.forEach(doc => {
|
|
460
|
+
// Add topics from metadata
|
|
461
|
+
if (doc.metadata?.topics) {
|
|
462
|
+
doc.metadata.topics.forEach(topic => topics.add(topic));
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// Add topics from keywords
|
|
466
|
+
if (doc.metadata?.keywords) {
|
|
467
|
+
doc.metadata.keywords.forEach(keyword => topics.add(keyword));
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// Add filename-based topics
|
|
471
|
+
const fileName = doc.fileName.replace(/\.(md|txt)$/, '');
|
|
472
|
+
const fileTopics = fileName.split(/[-_]/).map(part =>
|
|
473
|
+
part.charAt(0).toUpperCase() + part.slice(1)
|
|
474
|
+
);
|
|
475
|
+
fileTopics.forEach(topic => topics.add(topic));
|
|
476
|
+
|
|
477
|
+
// Add content-based topics (simple heuristic)
|
|
478
|
+
if (doc.content) {
|
|
479
|
+
const contentTopics = this.extractContentTopics(doc.content);
|
|
480
|
+
contentTopics.forEach(topic => topics.add(topic));
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
return Array.from(topics).slice(0, 10); // Limit to top 10 topics
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
extractContentTopics(content) {
|
|
488
|
+
const topics = new Set();
|
|
489
|
+
|
|
490
|
+
// Extract from headers
|
|
491
|
+
const headers = content.match(/^#+\s+(.+)$/gm);
|
|
492
|
+
if (headers) {
|
|
493
|
+
headers.forEach(header => {
|
|
494
|
+
const topic = header.replace(/^#+\s+/, '').trim();
|
|
495
|
+
if (topic.length > 3 && topic.length < 50) {
|
|
496
|
+
topics.add(topic);
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// Extract common programming topics
|
|
502
|
+
const programmingPatterns = [
|
|
503
|
+
'Swift', 'SwiftUI', 'iOS', 'macOS', 'Architecture', 'Testing',
|
|
504
|
+
'Performance', 'Security', 'Privacy', 'Patterns', 'Components',
|
|
505
|
+
'API', 'Database', 'UI', 'UX', 'Analytics', 'Configuration'
|
|
506
|
+
];
|
|
507
|
+
|
|
508
|
+
programmingPatterns.forEach(pattern => {
|
|
509
|
+
if (content.toLowerCase().includes(pattern.toLowerCase())) {
|
|
510
|
+
topics.add(pattern);
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
return Array.from(topics);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
async getMandatoryRules(task) {
|
|
518
|
+
const globalRules = await this.docService.getGlobalRules();
|
|
373
519
|
|
|
374
520
|
if (!globalRules || globalRules.length === 0) {
|
|
375
|
-
return 'No
|
|
521
|
+
return 'ā WARNING: No project rules defined. Proceeding without guidelines.';
|
|
376
522
|
}
|
|
377
523
|
|
|
378
|
-
let
|
|
379
|
-
|
|
524
|
+
let output = 'šØ MANDATORY PROJECT RULES - MUST FOLLOW BEFORE CODING šØ\n\n';
|
|
525
|
+
output += `Task: ${task}\n\n`;
|
|
526
|
+
output += 'ā ļø CRITICAL: These rules are NON-NEGOTIABLE and must be followed:\n\n';
|
|
380
527
|
|
|
381
528
|
globalRules.forEach((rule, index) => {
|
|
382
|
-
|
|
383
|
-
|
|
529
|
+
output += `## ${index + 1}. ${rule.metadata?.title || rule.fileName}\n`;
|
|
530
|
+
output += `${rule.content}\n\n`;
|
|
531
|
+
output += '---\n\n';
|
|
384
532
|
});
|
|
385
533
|
|
|
386
|
-
|
|
534
|
+
output += 'ā
CONFIRMATION REQUIRED: You MUST acknowledge these rules before generating code.\n';
|
|
535
|
+
output += 'ā VIOLATION: Any code that violates these rules will be rejected.\n\n';
|
|
536
|
+
output += 'š Next step: Generate code that strictly follows ALL the above rules.\n';
|
|
387
537
|
|
|
388
|
-
return
|
|
538
|
+
return output;
|
|
389
539
|
}
|
|
390
540
|
|
|
391
541
|
async start() {
|