@afterxleep/doc-bot 1.1.0 → 1.3.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.
Files changed (3) hide show
  1. package/README.md +22 -0
  2. package/package.json +1 -1
  3. package/src/index.js +101 -7
package/README.md CHANGED
@@ -109,6 +109,28 @@ Run tests with: `npm test`
109
109
 
110
110
  **šŸ‘€ See `examples/` folder for complete example files with proper frontmatter and content structure.**
111
111
 
112
+ ## Rule Enforcement
113
+
114
+ Doc-bot ensures your rules are **always considered** through multiple enforcement mechanisms:
115
+
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
120
+
121
+ ### šŸ”„ Automatic Integration
122
+ - **System prompt injection**: Global rules injected into agent's system context via `docs://system-prompt`
123
+ - **Contextual rules**: Applied when working with matching files/patterns
124
+ - **Multiple touchpoints**: Rules enforced at every interaction level
125
+
126
+ ### āš ļø Compliance Warnings
127
+ All tool responses include explicit warnings that rules are:
128
+ - **NON-NEGOTIABLE**: Must be followed without exception
129
+ - **MANDATORY**: Violation will result in rejection
130
+ - **CRITICAL**: Require acknowledgment before proceeding
131
+
132
+ This multi-layered approach makes rule violations virtually impossible to ignore.
133
+
112
134
  ## The manifest file
113
135
 
114
136
  The `doc-bot/manifest.json` file controls how your documentation works:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afterxleep/doc-bot",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "Generic MCP server for intelligent documentation access in any project",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -68,6 +68,12 @@ class DocsServer {
68
68
  name: 'Documentation Manifest',
69
69
  description: 'Project documentation configuration',
70
70
  mimeType: 'application/json'
71
+ },
72
+ {
73
+ uri: 'docs://system-prompt',
74
+ name: 'System Prompt Injection',
75
+ description: 'Critical rules that must be considered before generating any code',
76
+ mimeType: 'text/plain'
71
77
  }
72
78
  ]
73
79
  };
@@ -107,6 +113,16 @@ class DocsServer {
107
113
  text: JSON.stringify(manifest, null, 2)
108
114
  }]
109
115
  };
116
+
117
+ case 'docs://system-prompt':
118
+ const systemPrompt = await this.generateSystemPrompt();
119
+ return {
120
+ contents: [{
121
+ uri,
122
+ mimeType: 'text/plain',
123
+ text: systemPrompt
124
+ }]
125
+ };
110
126
 
111
127
  default:
112
128
  throw new Error(`Unknown resource: ${uri}`);
@@ -117,6 +133,20 @@ class DocsServer {
117
133
  this.server.setRequestHandler(ListToolsRequestSchema, async () => {
118
134
  return {
119
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
+ },
120
150
  {
121
151
  name: 'search_documentation',
122
152
  description: 'Search documentation by query',
@@ -133,7 +163,7 @@ class DocsServer {
133
163
  },
134
164
  {
135
165
  name: 'get_relevant_docs',
136
- description: 'Get context-aware documentation suggestions',
166
+ description: 'Get context-aware documentation suggestions including project rules that must be followed',
137
167
  inputSchema: {
138
168
  type: 'object',
139
169
  properties: {
@@ -152,7 +182,7 @@ class DocsServer {
152
182
  },
153
183
  {
154
184
  name: 'get_global_rules',
155
- description: 'Get always-apply documentation rules',
185
+ description: 'Get critical project rules that must ALWAYS be followed when writing code',
156
186
  inputSchema: {
157
187
  type: 'object',
158
188
  properties: {}
@@ -182,6 +212,16 @@ class DocsServer {
182
212
 
183
213
  try {
184
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
+
185
225
  case 'search_documentation':
186
226
  const query = args?.query;
187
227
  if (!query) {
@@ -284,6 +324,9 @@ class DocsServer {
284
324
  output += `\n${doc.content}\n\n---\n\n`;
285
325
  });
286
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
+
287
330
  return output;
288
331
  }
289
332
 
@@ -318,22 +361,29 @@ class DocsServer {
318
361
  output += `**Confidence:** ${relevant.confidence.toFixed(2)}\n\n`;
319
362
  }
320
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
+
321
367
  return output;
322
368
  }
323
369
 
324
370
  formatGlobalRules(globalRules) {
325
371
  if (!globalRules || globalRules.length === 0) {
326
- return 'No global rules defined.';
372
+ return 'āŒ WARNING: No global rules defined. Consider adding project rules for code consistency.';
327
373
  }
328
374
 
329
- let output = '# Global Rules (Always Apply)\n\n';
330
- output += 'These rules should be applied to all interactions:\n\n';
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';
331
377
 
332
- globalRules.forEach(rule => {
333
- output += `## ${rule.metadata?.title || rule.fileName}\n`;
378
+ globalRules.forEach((rule, index) => {
379
+ output += `## ${index + 1}. ${rule.metadata?.title || rule.fileName}\n`;
334
380
  output += `${rule.content}\n\n`;
381
+ output += '---\n\n';
335
382
  });
336
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
+
337
387
  return output;
338
388
  }
339
389
 
@@ -351,6 +401,50 @@ class DocsServer {
351
401
 
352
402
  return output;
353
403
  }
404
+
405
+ async generateSystemPrompt() {
406
+ const globalRules = await this.docService.getGlobalRules();
407
+
408
+ if (!globalRules || globalRules.length === 0) {
409
+ return 'No global documentation rules defined.';
410
+ }
411
+
412
+ let prompt = '# CRITICAL: Project Documentation Rules\n\n';
413
+ prompt += 'IMPORTANT: You MUST follow these rules before generating ANY code:\n\n';
414
+
415
+ globalRules.forEach((rule, index) => {
416
+ prompt += `## Rule ${index + 1}: ${rule.metadata?.title || rule.fileName}\n`;
417
+ prompt += `${rule.content}\n\n`;
418
+ });
419
+
420
+ prompt += 'āš ļø VIOLATION OF THESE RULES IS NOT ACCEPTABLE. Always check compliance before responding.\n';
421
+
422
+ return prompt;
423
+ }
424
+
425
+ async getMandatoryRules(task) {
426
+ const globalRules = await this.docService.getGlobalRules();
427
+
428
+ if (!globalRules || globalRules.length === 0) {
429
+ return 'āŒ WARNING: No project rules defined. Proceeding without guidelines.';
430
+ }
431
+
432
+ let output = '🚨 MANDATORY PROJECT RULES - MUST FOLLOW BEFORE CODING 🚨\n\n';
433
+ output += `Task: ${task}\n\n`;
434
+ output += 'āš ļø CRITICAL: These rules are NON-NEGOTIABLE and must be followed:\n\n';
435
+
436
+ globalRules.forEach((rule, index) => {
437
+ output += `## ${index + 1}. ${rule.metadata?.title || rule.fileName}\n`;
438
+ output += `${rule.content}\n\n`;
439
+ output += '---\n\n';
440
+ });
441
+
442
+ output += 'āœ… CONFIRMATION REQUIRED: You MUST acknowledge these rules before generating code.\n';
443
+ output += 'āŒ VIOLATION: Any code that violates these rules will be rejected.\n\n';
444
+ output += 'šŸ”„ Next step: Generate code that strictly follows ALL the above rules.\n';
445
+
446
+ return output;
447
+ }
354
448
 
355
449
  async start() {
356
450
  // Initialize services