@afterxleep/doc-bot 1.19.0 → 1.21.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 (2) hide show
  1. package/package.json +9 -9
  2. package/src/index.js +93 -140
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afterxleep/doc-bot",
3
- "version": "1.19.0",
3
+ "version": "1.21.0",
4
4
  "description": "Generic MCP server for intelligent documentation access in any project",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -43,14 +43,14 @@
43
43
  },
44
44
  "homepage": "https://github.com/afterxleep/doc-bot#readme",
45
45
  "dependencies": {
46
- "@modelcontextprotocol/sdk": "^0.7.0",
47
- "commander": "^12.0.0",
48
- "chokidar": "^3.5.3",
49
- "fs-extra": "^11.0.0",
50
- "glob": "^10.3.0",
51
- "yaml": "^2.3.0",
52
- "better-sqlite3": "^11.10.0",
53
- "axios": "^1.6.0",
46
+ "@modelcontextprotocol/sdk": "^1.18.0",
47
+ "commander": "^14.0.0",
48
+ "chokidar": "^4.0.3",
49
+ "fs-extra": "^11.3.2",
50
+ "glob": "^11.0.3",
51
+ "yaml": "^2.8.1",
52
+ "better-sqlite3": "^12.2.0",
53
+ "axios": "^1.12.2",
54
54
  "tar": "^7.4.0",
55
55
  "adm-zip": "^0.5.16",
56
56
  "plist": "^3.1.0"
package/src/index.js CHANGED
@@ -364,7 +364,7 @@ class DocsServer {
364
364
  },
365
365
  {
366
366
  name: 'doc_bot',
367
- description: 'Your intelligent project assistant. Analyzes ANY request and provides smart routing to the right tools. ALWAYS call this first - it understands coding, documentation, architecture questions, and more.',
367
+ description: 'ALWAYS call this first for any task. Returns mandatory project standards (alwaysApply rules) that must be followed, plus a catalog of available documentation tools. Provides intelligent guidance while trusting your judgment on what additional context you need based on your familiarity with the codebase.',
368
368
  inputSchema: {
369
369
  type: 'object',
370
370
  properties: {
@@ -700,14 +700,16 @@ class DocsServer {
700
700
  }]
701
701
  };
702
702
 
703
- case 'doc_bot':
703
+ case 'doc_bot': {
704
704
  const assistantTask = args?.task || '';
705
+ const docBotMandatoryRules = await this.docService.getGlobalRules();
705
706
  return {
706
707
  content: [{
707
708
  type: 'text',
708
- text: this.getDocBotGuidance(assistantTask)
709
+ text: this.getIntelligentGatekeeperResponse(assistantTask, docBotMandatoryRules)
709
710
  }]
710
711
  };
712
+ }
711
713
 
712
714
  default:
713
715
  throw new Error(`Unknown tool: ${name}`);
@@ -1247,172 +1249,123 @@ Try:
1247
1249
  return output;
1248
1250
  }
1249
1251
 
1250
- getDocBotGuidance(task) {
1251
- // This is the intelligent guidance that replaces the complex AGENT_INTEGRATION_RULE
1252
- const taskLower = task.toLowerCase();
1253
-
1254
- let guidance = `# 🤖 DOC-BOT INTELLIGENT ASSISTANT\n\n`;
1255
- guidance += `**Your Request**: ${task}\n\n`;
1256
-
1252
+ getIntelligentGatekeeperResponse(task, mandatoryRules) {
1257
1253
  // Check for administrative/management tasks first
1258
1254
  const isDocsetManagement = /add.*docset|remove.*docset|list.*docset|install.*docset/i.test(task);
1259
1255
  const isRuleManagement = /add.*rule|create.*rule|update.*rule|document.*pattern|capture.*pattern/i.test(task);
1260
1256
  const isDocumentManagement = /refresh.*doc|reload.*doc|index.*doc|get.*index/i.test(task);
1261
-
1262
- // Handle administrative tasks directly
1257
+
1258
+ // Handle administrative tasks with direct action guidance
1263
1259
  if (isDocsetManagement) {
1264
- guidance += `## 📦 DOCSET MANAGEMENT TASK DETECTED\n\n`;
1265
- guidance += `**Direct Actions Required**:\n`;
1266
-
1260
+ let guidance = `# 📦 Docset Management\n\n`;
1261
+
1267
1262
  if (/list/i.test(task)) {
1268
- guidance += `1. \`list_docsets()\` - Show all installed documentation sets\n\n`;
1263
+ guidance += `**Action**: \`list_docsets()\`\n\n`;
1264
+ guidance += `Shows all installed documentation sets with their IDs and metadata.\n`;
1269
1265
  } else if (/add|install/i.test(task)) {
1270
- guidance += `1. \`add_docset(source: "path/to/docset or URL")\` - Install new docset\n\n`;
1271
- guidance += `📝 **Examples**:\n`;
1266
+ guidance += `**Action**: \`add_docset(source: "path or URL")\`\n\n`;
1267
+ guidance += `**Examples**:\n`;
1272
1268
  guidance += `- Local: \`add_docset(source: "/Downloads/Swift.docset")\`\n`;
1273
- guidance += `- URL: \`add_docset(source: "https://example.com/React.docset.tgz")\`\n\n`;
1269
+ guidance += `- URL: \`add_docset(source: "https://example.com/React.docset.tgz")\`\n`;
1274
1270
  } else if (/remove/i.test(task)) {
1275
- guidance += `1. \`list_docsets()\` - First, get the docset ID\n`;
1276
- guidance += `2. \`remove_docset(docsetId: "the-id-from-step-1")\` - Remove the docset\n\n`;
1271
+ guidance += `**Steps**:\n`;
1272
+ guidance += `1. \`list_docsets()\` - Get the docset ID\n`;
1273
+ guidance += `2. \`remove_docset(docsetId: "id-from-step-1")\`\n`;
1277
1274
  }
1278
-
1279
- guidance += `💡 **Note**: This is an administrative task - no documentation search needed.\n`;
1275
+
1280
1276
  return guidance;
1281
1277
  }
1282
-
1278
+
1283
1279
  if (isRuleManagement) {
1284
- guidance += `## 📝 RULE/PATTERN MANAGEMENT TASK DETECTED\n\n`;
1285
- guidance += `**Direct Action Required**:\n`;
1286
- guidance += `1. \`create_or_update_rule(...)\` with these parameters:\n\n`;
1280
+ let guidance = `# 📝 Rule/Pattern Management\n\n`;
1281
+ guidance += `**Action**: \`create_or_update_rule(...)\`\n\n`;
1282
+ guidance += `**Parameters**:\n`;
1287
1283
  guidance += `\`\`\`javascript\n`;
1288
1284
  guidance += `{\n`;
1289
1285
  guidance += ` fileName: "descriptive-name.md",\n`;
1290
- guidance += ` title: "Clear title for the rule/pattern",\n`;
1286
+ guidance += ` title: "Clear title for the rule",\n`;
1291
1287
  guidance += ` content: "Full markdown documentation",\n`;
1292
- guidance += ` alwaysApply: true/false, // true = global, false = contextual\n`;
1293
- guidance += ` keywords: ["relevant", "search", "terms"],\n`;
1288
+ guidance += ` alwaysApply: true, // true = mandatory (like CLAUDE.md)\n`;
1289
+ guidance += ` // false = contextual (found via search)\n`;
1290
+ guidance += ` keywords: ["search", "terms"],\n`;
1294
1291
  guidance += ` description: "Brief summary" // optional\n`;
1295
1292
  guidance += `}\n`;
1296
- guidance += `\`\`\`\n\n`;
1297
- guidance += `💡 **Note**: This captures project knowledge permanently - no search needed.\n`;
1293
+ guidance += `\`\`\`\n`;
1298
1294
  return guidance;
1299
1295
  }
1300
-
1296
+
1301
1297
  if (isDocumentManagement) {
1302
- guidance += `## 🔄 DOCUMENTATION MANAGEMENT TASK DETECTED\n\n`;
1303
- guidance += `**Direct Action Required**:\n`;
1304
-
1298
+ let guidance = `# 🔄 Documentation Management\n\n`;
1299
+
1305
1300
  if (/refresh|reload/i.test(task)) {
1306
- guidance += `1. \`refresh_documentation()\` - Reload all docs from disk\n\n`;
1301
+ guidance += `**Action**: \`refresh_documentation()\`\n\n`;
1302
+ guidance += `Reloads all documentation from disk and rebuilds search indexes.\n`;
1307
1303
  } else {
1308
- guidance += `1. \`get_document_index()\` - List all available documentation\n\n`;
1304
+ guidance += `**Action**: \`get_document_index()\`\n\n`;
1305
+ guidance += `Lists all available documentation files with metadata.\n`;
1309
1306
  }
1310
-
1311
- guidance += `💡 **Note**: This is an administrative task - direct execution only.\n`;
1307
+
1312
1308
  return guidance;
1313
1309
  }
1314
-
1315
- // Analyze the task and provide intelligent routing for non-administrative tasks
1316
- if (taskLower.includes('create') || taskLower.includes('implement') || taskLower.includes('build') ||
1317
- taskLower.includes('write') || taskLower.includes('add') || taskLower.includes('code') ||
1318
- taskLower.includes('function') || taskLower.includes('class') || taskLower.includes('component')) {
1319
- guidance += `## 💻 CODE GENERATION TASK DETECTED\n\n`;
1320
- guidance += `**MANDATORY Steps (in order)**:\n`;
1321
- guidance += `1. ⚡ FIRST: \`check_project_rules("${task}")\` - Get critical coding standards\n`;
1322
- guidance += `2. 🔍 SEARCH for existing patterns:\n`;
1323
-
1324
- // Extract likely search terms
1325
- const searchTerms = this.extractSearchTerms(task);
1326
- searchTerms.forEach(term => {
1327
- guidance += ` - \`search_documentation("${term}")\`\n`;
1328
- });
1329
-
1330
- guidance += `3. 📚 EXPLORE: If APIs found, use \`explore_api()\` for complete details\n`;
1331
- guidance += `4. ✅ IMPLEMENT: Generate code following ALL discovered patterns\n\n`;
1332
- guidance += `⚠️ **CRITICAL**: Never skip step 1 - project rules are mandatory!\n\n`;
1333
- } else if (taskLower.includes('how') || taskLower.includes('what') || taskLower.includes('why') ||
1334
- taskLower.includes('understand') || taskLower.includes('explain') || taskLower.includes('architecture')) {
1335
- guidance += `## 🔍 KNOWLEDGE/UNDERSTANDING TASK DETECTED\n\n`;
1336
- guidance += `**Recommended Flow**:\n`;
1337
- guidance += `1. 📖 START with searches for technical terms:\n`;
1338
-
1339
- const searchTerms = this.extractSearchTerms(task);
1340
- searchTerms.forEach(term => {
1341
- guidance += ` - \`search_documentation("${term}")\`\n`;
1342
- });
1343
-
1344
- guidance += `2. 📋 CONTEXT: \`get_global_rules()\` for project philosophy\n`;
1345
- guidance += `3. 📄 DETAILS: Use \`read_specific_document()\` on relevant results\n`;
1346
- guidance += `4. 🔬 DEEP DIVE: \`explore_api()\` for framework/class details\n\n`;
1347
- } else if (taskLower.includes('document') || taskLower.includes('capture') || taskLower.includes('learned') ||
1348
- taskLower.includes('pattern') || taskLower.includes('convention')) {
1349
- guidance += `## 📝 DOCUMENTATION TASK DETECTED\n\n`;
1350
- guidance += `**To capture new knowledge**:\n`;
1351
- guidance += `Use \`create_or_update_rule()\` with:\n`;
1352
- guidance += `- fileName: descriptive-name.md\n`;
1353
- guidance += `- title: Clear, searchable title\n`;
1354
- guidance += `- content: Full markdown documentation\n`;
1355
- guidance += `- alwaysApply: true/false (is this a global rule?)\n\n`;
1356
- } else if (taskLower.includes('file') || taskLower.includes('working on') || taskLower.includes('modify')) {
1357
- guidance += `## 📁 FILE-SPECIFIC TASK DETECTED\n\n`;
1358
- guidance += `**File Context Flow**:\n`;
1359
- guidance += `1. 📂 GET CONTEXT: \`get_file_docs("${task}")\` for file-specific patterns\n`;
1360
- guidance += `2. 🔍 SEARCH: Look for related components/patterns\n`;
1361
- guidance += `3. ✅ CHECK: \`check_project_rules()\` before modifications\n\n`;
1310
+
1311
+ // For coding/general tasks: Return mandatory rules + tool catalog
1312
+ let response = `# Mandatory Project Standards\n\n`;
1313
+
1314
+ if (!mandatoryRules || mandatoryRules.length === 0) {
1315
+ response += `*No mandatory rules defined for this project.*\n\n`;
1362
1316
  } else {
1363
- guidance += `## 🎯 GENERAL TASK GUIDANCE\n\n`;
1364
- guidance += `**Intelligent Routing Based on Your Request**:\n`;
1365
- guidance += `1. 🏁 START: \`get_global_rules()\` - Understand the project\n`;
1366
- guidance += `2. 🔍 DISCOVER: \`search_documentation()\` with key terms from your request\n`;
1367
- guidance += `3. 📋 REQUIREMENTS: \`check_project_rules("${task}")\` if generating any output\n`;
1368
- guidance += `4. 📚 EXPLORE: \`explore_api()\` for any frameworks/APIs mentioned\n\n`;
1317
+ response += `These rules apply to ALL code in this project:\n\n`;
1318
+ mandatoryRules.forEach((rule, index) => {
1319
+ response += `## ${index + 1}. ${rule.metadata?.title || rule.fileName}\n\n`;
1320
+ response += `${rule.content}\n\n`;
1321
+ if (index < mandatoryRules.length - 1) {
1322
+ response += `---\n\n`;
1323
+ }
1324
+ });
1369
1325
  }
1370
-
1371
- guidance += `## 🔑 Search Tips for Maximum Effectiveness:\n\n`;
1372
- guidance += `✅ **DO**: Search for class names, API names, technical terms\n`;
1373
- guidance += ` Examples: "Widget", "URLSession", "Authentication", "CoreData"\n\n`;
1374
- guidance += `❌ **DON'T**: Search with questions or descriptions\n`;
1375
- guidance += ` Avoid: "how to create", "new features", "iOS 18 widgets"\n\n`;
1376
- guidance += `🎯 **Best Practice**: Think like you're searching an API index, not Google!\n\n`;
1377
- guidance += `## 💡 Remember:\n`;
1378
- guidance += `- Project documentation ALWAYS overrides general knowledge\n`;
1379
- guidance += `- When in doubt, search first\n`;
1380
- guidance += `- Use \`explore_api()\` after finding relevant APIs\n`;
1381
- guidance += `- Document new patterns with \`create_or_update_rule()\`\n`;
1382
-
1383
- return guidance;
1384
- }
1385
-
1386
- extractSearchTerms(task) {
1387
- // Extract potential API/class names from the task
1388
- const terms = [];
1389
-
1390
- // Common patterns to extract
1391
- const patterns = {
1392
- 'widget': ['Widget', 'WidgetKit'],
1393
- 'auth': ['Authentication', 'Auth', 'Login'],
1394
- 'database': ['Database', 'CoreData', 'SQLite'],
1395
- 'network': ['URLSession', 'Network', 'API'],
1396
- 'cache': ['Cache', 'Caching', 'Redis'],
1397
- 'ui': ['UIKit', 'SwiftUI', 'View'],
1398
- 'react': ['React', 'Component', 'Hook'],
1399
- 'api': ['API', 'REST', 'GraphQL'],
1400
- 'test': ['Test', 'Jest', 'XCTest']
1401
- };
1402
-
1403
- const taskLower = task.toLowerCase();
1404
- Object.keys(patterns).forEach(key => {
1405
- if (taskLower.includes(key)) {
1406
- terms.push(...patterns[key]);
1407
- }
1408
- });
1409
-
1410
- // Also extract capitalized words as potential class names
1411
- const capitalizedWords = task.match(/[A-Z][a-zA-Z]+/g) || [];
1412
- terms.push(...capitalizedWords);
1413
-
1414
- // Remove duplicates and limit to 3-4 terms
1415
- return [...new Set(terms)].slice(0, 4);
1326
+
1327
+ response += `---\n\n`;
1328
+ response += `## Additional Documentation Tools Available\n\n`;
1329
+ response += `You have access to these tools for finding contextual information:\n\n`;
1330
+
1331
+ response += `**\`search_documentation(query)\`**\n`;
1332
+ response += `- Search project docs for patterns, examples, conventions\n`;
1333
+ response += `- Use when: You need to understand how something is implemented in this codebase\n`;
1334
+ response += `- Examples: \`search_documentation("authentication")\`, \`search_documentation("validation")\`\n`;
1335
+ response += `- Tip: Use technical terms (class names, API names), not descriptions\n\n`;
1336
+
1337
+ response += `**\`get_file_docs(filePath)\`**\n`;
1338
+ response += `- Get file-specific or directory-specific documentation\n`;
1339
+ response += `- Use when: Working with specific files and need conventions for that area\n`;
1340
+ response += `- Examples: \`get_file_docs("src/components/Auth.tsx")\`, \`get_file_docs("services/**")\`\n\n`;
1341
+
1342
+ response += `**\`explore_api(apiName)\`**\n`;
1343
+ response += `- Deep-dive into framework/API documentation (all methods, properties, examples)\n`;
1344
+ response += `- Use when: Using frameworks or APIs you're unfamiliar with\n`;
1345
+ response += `- Examples: \`explore_api("URLSession")\`, \`explore_api("React.Component")\`\n\n`;
1346
+
1347
+ response += `**\`read_specific_document(fileName)\`**\n`;
1348
+ response += `- Read full content of a specific documentation file\n`;
1349
+ response += `- Use when: Search results show a relevant doc and you need complete details\n`;
1350
+ response += `- Examples: \`read_specific_document("api-patterns.md")\`\n\n`;
1351
+
1352
+ response += `**\`get_global_rules()\`**\n`;
1353
+ response += `- Get complete project philosophy and engineering principles\n`;
1354
+ response += `- Use when: Making architectural decisions or need comprehensive context\n\n`;
1355
+
1356
+ response += `---\n\n`;
1357
+ response += `## Your Task: "${task}"\n\n`;
1358
+ response += `**You now have:**\n`;
1359
+ response += `✅ Mandatory project standards (above)\n`;
1360
+ response += `✅ Tools to explore codebase-specific patterns (listed above)\n\n`;
1361
+
1362
+ response += `**Your decision:**\n`;
1363
+ response += `- If you understand how to implement this correctly with the standards above → proceed\n`;
1364
+ response += `- If you need to understand existing patterns in this codebase → use the tools above\n\n`;
1365
+
1366
+ response += `Remember: You know the codebase context best. Use additional tools only if you need them.\n`;
1367
+
1368
+ return response;
1416
1369
  }
1417
1370
 
1418
1371
  async createOrUpdateRule({ fileName, title, description, keywords, alwaysApply, content }) {