mcp-adr-analysis-server 2.0.3 → 2.0.5

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 (82) hide show
  1. package/dist/src/index.d.ts +26 -0
  2. package/dist/src/index.d.ts.map +1 -1
  3. package/dist/src/index.js +524 -325
  4. package/dist/src/index.js.map +1 -1
  5. package/dist/src/prompts/adr-suggestion-prompts.d.ts +1 -0
  6. package/dist/src/prompts/adr-suggestion-prompts.d.ts.map +1 -1
  7. package/dist/src/prompts/adr-suggestion-prompts.js +14 -6
  8. package/dist/src/prompts/adr-suggestion-prompts.js.map +1 -1
  9. package/dist/src/resources/index.d.ts.map +1 -1
  10. package/dist/src/resources/index.js +31 -15
  11. package/dist/src/resources/index.js.map +1 -1
  12. package/dist/src/tools/adr-suggestion-tool.d.ts +4 -1
  13. package/dist/src/tools/adr-suggestion-tool.d.ts.map +1 -1
  14. package/dist/src/tools/adr-suggestion-tool.js +72 -114
  15. package/dist/src/tools/adr-suggestion-tool.js.map +1 -1
  16. package/dist/src/tools/content-masking-tool.d.ts +7 -0
  17. package/dist/src/tools/content-masking-tool.d.ts.map +1 -1
  18. package/dist/src/tools/content-masking-tool.js +134 -17
  19. package/dist/src/tools/content-masking-tool.js.map +1 -1
  20. package/dist/src/tools/environment-analysis-tool.d.ts +4 -0
  21. package/dist/src/tools/environment-analysis-tool.d.ts.map +1 -1
  22. package/dist/src/tools/environment-analysis-tool.js +209 -25
  23. package/dist/src/tools/environment-analysis-tool.js.map +1 -1
  24. package/dist/src/tools/research-question-tool.d.ts +4 -0
  25. package/dist/src/tools/research-question-tool.d.ts.map +1 -1
  26. package/dist/src/tools/research-question-tool.js +42 -4
  27. package/dist/src/tools/research-question-tool.js.map +1 -1
  28. package/dist/src/tools/rule-generation-tool.d.ts +4 -0
  29. package/dist/src/tools/rule-generation-tool.d.ts.map +1 -1
  30. package/dist/src/tools/rule-generation-tool.js +136 -16
  31. package/dist/src/tools/rule-generation-tool.js.map +1 -1
  32. package/dist/src/types/conversation-context.d.ts +93 -0
  33. package/dist/src/types/conversation-context.d.ts.map +1 -0
  34. package/dist/src/types/conversation-context.js +101 -0
  35. package/dist/src/types/conversation-context.js.map +1 -0
  36. package/dist/src/utils/actual-file-operations.d.ts +40 -0
  37. package/dist/src/utils/actual-file-operations.d.ts.map +1 -0
  38. package/dist/src/utils/actual-file-operations.js +309 -0
  39. package/dist/src/utils/actual-file-operations.js.map +1 -0
  40. package/dist/src/utils/adr-discovery.d.ts +36 -0
  41. package/dist/src/utils/adr-discovery.d.ts.map +1 -0
  42. package/dist/src/utils/adr-discovery.js +237 -0
  43. package/dist/src/utils/adr-discovery.js.map +1 -0
  44. package/dist/src/utils/adr-suggestions.d.ts +2 -1
  45. package/dist/src/utils/adr-suggestions.d.ts.map +1 -1
  46. package/dist/src/utils/adr-suggestions.js +8 -2
  47. package/dist/src/utils/adr-suggestions.js.map +1 -1
  48. package/dist/src/utils/apply-cot-enhancement.d.ts +46 -0
  49. package/dist/src/utils/apply-cot-enhancement.d.ts.map +1 -0
  50. package/dist/src/utils/apply-cot-enhancement.js +165 -0
  51. package/dist/src/utils/apply-cot-enhancement.js.map +1 -0
  52. package/dist/src/utils/chain-of-thought-template.d.ts +48 -0
  53. package/dist/src/utils/chain-of-thought-template.d.ts.map +1 -0
  54. package/dist/src/utils/chain-of-thought-template.js +191 -0
  55. package/dist/src/utils/chain-of-thought-template.js.map +1 -0
  56. package/dist/src/utils/deployment-analysis.d.ts +1 -0
  57. package/dist/src/utils/deployment-analysis.d.ts.map +1 -1
  58. package/dist/src/utils/deployment-analysis.js +82 -39
  59. package/dist/src/utils/deployment-analysis.js.map +1 -1
  60. package/dist/src/utils/environment-analysis.d.ts +6 -1
  61. package/dist/src/utils/environment-analysis.d.ts.map +1 -1
  62. package/dist/src/utils/environment-analysis.js +176 -87
  63. package/dist/src/utils/environment-analysis.js.map +1 -1
  64. package/dist/src/utils/file-system.d.ts +1 -0
  65. package/dist/src/utils/file-system.d.ts.map +1 -1
  66. package/dist/src/utils/file-system.js +24 -47
  67. package/dist/src/utils/file-system.js.map +1 -1
  68. package/dist/src/utils/prompt-execution.d.ts.map +1 -1
  69. package/dist/src/utils/prompt-execution.js +67 -3
  70. package/dist/src/utils/prompt-execution.js.map +1 -1
  71. package/dist/src/utils/research-integration.d.ts +4 -0
  72. package/dist/src/utils/research-integration.d.ts.map +1 -1
  73. package/dist/src/utils/research-integration.js +275 -84
  74. package/dist/src/utils/research-integration.js.map +1 -1
  75. package/dist/src/utils/research-questions.d.ts.map +1 -1
  76. package/dist/src/utils/research-questions.js +134 -38
  77. package/dist/src/utils/research-questions.js.map +1 -1
  78. package/dist/src/utils/rule-generation.d.ts +2 -1
  79. package/dist/src/utils/rule-generation.d.ts.map +1 -1
  80. package/dist/src/utils/rule-generation.js +65 -36
  81. package/dist/src/utils/rule-generation.js.map +1 -1
  82. package/package.json +4 -4
package/dist/src/index.js CHANGED
@@ -10,7 +10,10 @@ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
10
10
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
11
11
  import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema } from '@modelcontextprotocol/sdk/types.js';
12
12
  import { readFileSync } from 'fs';
13
+ import { fileURLToPath } from 'url';
14
+ import { dirname, join } from 'path';
13
15
  import { McpAdrError } from './types/index.js';
16
+ import { CONVERSATION_CONTEXT_SCHEMA } from './types/conversation-context.js';
14
17
  import { maskMcpResponse, createMaskingConfig } from './utils/output-masking.js';
15
18
  import { loadConfig, validateProjectPath, createLogger, printConfigSummary } from './utils/config.js';
16
19
  /**
@@ -18,10 +21,40 @@ import { loadConfig, validateProjectPath, createLogger, printConfigSummary } fro
18
21
  */
19
22
  function getPackageVersion() {
20
23
  try {
21
- const packageJson = JSON.parse(readFileSync('./package.json', 'utf-8'));
22
- return packageJson.version;
24
+ // Handle both Jest environment and normal execution
25
+ let currentDir;
26
+ if (typeof import.meta !== 'undefined' && import.meta.url) {
27
+ // Normal ESM execution
28
+ const __filename = fileURLToPath(import.meta.url);
29
+ currentDir = dirname(__filename);
30
+ }
31
+ else {
32
+ // Jest or other environments without import.meta support
33
+ // Use process.cwd() as fallback
34
+ currentDir = process.cwd();
35
+ }
36
+ // Try multiple possible locations for package.json
37
+ const possiblePaths = [
38
+ join(currentDir, 'package.json'),
39
+ join(currentDir, '..', 'package.json'),
40
+ join(currentDir, '..', '..', 'package.json'),
41
+ join(process.cwd(), 'package.json')
42
+ ];
43
+ for (const packageJsonPath of possiblePaths) {
44
+ try {
45
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
46
+ if (packageJson.name === 'mcp-adr-analysis-server') {
47
+ return packageJson.version;
48
+ }
49
+ }
50
+ catch {
51
+ // Try next path
52
+ }
53
+ }
54
+ return '2.0.2'; // fallback version
23
55
  }
24
- catch {
56
+ catch (error) {
57
+ console.error('Error reading package.json:', error);
25
58
  return '2.0.2'; // fallback version
26
59
  }
27
60
  }
@@ -142,7 +175,8 @@ export class McpAdrAnalysisServer {
142
175
  type: 'array',
143
176
  items: { type: 'string' },
144
177
  description: 'Specific analysis areas to focus on (e.g., ["security", "performance", "architecture", "dependencies"])'
145
- }
178
+ },
179
+ conversationContext: CONVERSATION_CONTEXT_SCHEMA
146
180
  },
147
181
  required: []
148
182
  }
@@ -517,7 +551,8 @@ export class McpAdrAnalysisServer {
517
551
  type: 'boolean',
518
552
  description: 'Enable Knowledge Generation for domain-specific insights',
519
553
  default: true
520
- }
554
+ },
555
+ conversationContext: CONVERSATION_CONTEXT_SCHEMA
521
556
  }
522
557
  }
523
558
  },
@@ -1151,6 +1186,52 @@ export class McpAdrAnalysisServer {
1151
1186
  },
1152
1187
  required: ['developmentPhase']
1153
1188
  }
1189
+ },
1190
+ {
1191
+ name: 'read_file',
1192
+ description: 'Read contents of a file',
1193
+ inputSchema: {
1194
+ type: 'object',
1195
+ properties: {
1196
+ path: {
1197
+ type: 'string',
1198
+ description: 'Path to the file to read'
1199
+ }
1200
+ },
1201
+ required: ['path']
1202
+ }
1203
+ },
1204
+ {
1205
+ name: 'write_file',
1206
+ description: 'Write content to a file',
1207
+ inputSchema: {
1208
+ type: 'object',
1209
+ properties: {
1210
+ path: {
1211
+ type: 'string',
1212
+ description: 'Path to the file to write'
1213
+ },
1214
+ content: {
1215
+ type: 'string',
1216
+ description: 'Content to write to the file'
1217
+ }
1218
+ },
1219
+ required: ['path', 'content']
1220
+ }
1221
+ },
1222
+ {
1223
+ name: 'list_directory',
1224
+ description: 'List contents of a directory',
1225
+ inputSchema: {
1226
+ type: 'object',
1227
+ properties: {
1228
+ path: {
1229
+ type: 'string',
1230
+ description: 'Path to the directory to list'
1231
+ }
1232
+ },
1233
+ required: ['path']
1234
+ }
1154
1235
  }
1155
1236
  ]
1156
1237
  };
@@ -1242,6 +1323,15 @@ export class McpAdrAnalysisServer {
1242
1323
  case 'get_development_guidance':
1243
1324
  response = await this.getDevelopmentGuidance(args);
1244
1325
  break;
1326
+ case 'read_file':
1327
+ response = await this.readFile(args);
1328
+ break;
1329
+ case 'write_file':
1330
+ response = await this.writeFile(args);
1331
+ break;
1332
+ case 'list_directory':
1333
+ response = await this.listDirectory(args);
1334
+ break;
1245
1335
  default:
1246
1336
  throw new McpAdrError(`Unknown tool: ${name}`, 'UNKNOWN_TOOL');
1247
1337
  }
@@ -1627,22 +1717,31 @@ This guidance is tailored to your specific context and goals for maximum effecti
1627
1717
  async getDevelopmentGuidance(args) {
1628
1718
  const { developmentPhase, adrsToImplement = [], technologyStack = [], currentProgress = '', teamContext = { size: 'small_team', experienceLevel: 'mixed' }, timeline = '', focusAreas = [] } = args;
1629
1719
  try {
1630
- // Generate prompts for ADR discovery if ADRs are specified
1631
- const { findFiles } = await import('./utils/file-system.js');
1720
+ // Use actual ADR discovery if ADRs are specified
1632
1721
  let adrAnalysisPrompt = '';
1633
1722
  if (adrsToImplement.length > 0) {
1634
1723
  const { getAdrDirectoryPath } = await import('./utils/config.js');
1724
+ const { discoverAdrsInDirectory } = await import('./utils/adr-discovery.js');
1635
1725
  const absoluteAdrPath = getAdrDirectoryPath(this.config);
1636
- const adrFileDiscovery = await findFiles(this.config.projectPath, [`${absoluteAdrPath}/**/*.md`], {
1637
- includeContent: true,
1638
- });
1726
+ const discoveryResult = await discoverAdrsInDirectory(absoluteAdrPath, true, this.config.projectPath);
1727
+ // Filter ADRs to only those specified for implementation
1728
+ const targetAdrs = discoveryResult.adrs.filter(adr => adrsToImplement.some((target) => adr.title.toLowerCase().includes(target.toLowerCase()) ||
1729
+ adr.filename.toLowerCase().includes(target.toLowerCase())));
1639
1730
  adrAnalysisPrompt = `
1640
1731
  ## ADR Analysis for Implementation
1641
1732
 
1642
- ${adrFileDiscovery.prompt}
1643
-
1644
1733
  **ADRs to Implement**: ${adrsToImplement.join(', ')}
1645
1734
  **ADR Directory**: ${absoluteAdrPath}
1735
+ **Found ${targetAdrs.length} matching ADRs**
1736
+
1737
+ ${targetAdrs.map(adr => `
1738
+ ### ${adr.title}
1739
+ - **File**: ${adr.filename}
1740
+ - **Status**: ${adr.status}
1741
+ - **Context**: ${adr.context}
1742
+ - **Decision**: ${adr.decision}
1743
+ - **Consequences**: ${adr.consequences}
1744
+ `).join('\n')}
1646
1745
  `;
1647
1746
  }
1648
1747
  const developmentPrompt = `
@@ -1851,7 +1950,9 @@ This guidance ensures your development work is **architecturally aligned**, **qu
1851
1950
  async analyzeProjectEcosystem(args) {
1852
1951
  // Use configured project path if not provided in args
1853
1952
  const projectPath = args.projectPath || this.config.projectPath;
1854
- const { includePatterns, enhancedMode = true, knowledgeEnhancement = true, learningEnabled = true, technologyFocus = [], analysisDepth = 'comprehensive', includeEnvironment = true, recursiveDepth = 'comprehensive', analysisScope = [] } = args;
1953
+ const { includePatterns, enhancedMode = true, knowledgeEnhancement = true, learningEnabled = true, technologyFocus = [], analysisDepth = 'comprehensive', includeEnvironment = true, recursiveDepth = 'comprehensive', analysisScope = []
1954
+ // conversationContext - TODO: implement context integration for ecosystem analysis
1955
+ } = args;
1855
1956
  this.logger.info(`Generating comprehensive ecosystem analysis for project at: ${projectPath}`);
1856
1957
  this.logger.info(`Analysis configuration - Depth: ${analysisDepth}, Recursive: ${recursiveDepth}, Environment: ${includeEnvironment}`);
1857
1958
  this.logger.info(`Enhancement features - Knowledge: ${knowledgeEnhancement}, Learning: ${learningEnabled}`);
@@ -2648,24 +2749,34 @@ The enhanced process maintains full traceability from PRD requirements to genera
2648
2749
  const adrDirectory = args.adrDirectory || this.config.adrDirectory;
2649
2750
  this.logger.info(`Generating TDD-focused todo for ADRs in: ${absoluteAdrPath} (phase: ${phase})`);
2650
2751
  try {
2651
- const { findFiles } = await import('./utils/file-system.js');
2652
- // Generate file discovery prompt for ADR files using project path as base
2653
- const adrFilesPrompt = await findFiles(this.config.projectPath, [`${absoluteAdrPath}/**/*.md`], { includeContent: true });
2752
+ const { discoverAdrsInDirectory } = await import('./utils/adr-discovery.js');
2753
+ const { scanProjectStructure } = await import('./utils/actual-file-operations.js');
2754
+ // Use actual ADR discovery
2755
+ const discoveryResult = await discoverAdrsInDirectory(absoluteAdrPath, true, this.config.projectPath);
2756
+ let adrContent = `Found ${discoveryResult.adrs.length} ADRs in ${absoluteAdrPath}:\n\n`;
2757
+ discoveryResult.adrs.forEach(adr => {
2758
+ adrContent += `### ${adr.title}\n`;
2759
+ adrContent += `- **File**: ${adr.filename}\n`;
2760
+ adrContent += `- **Status**: ${adr.status}\n`;
2761
+ adrContent += `- **Context**: ${adr.context}\n`;
2762
+ adrContent += `- **Decision**: ${adr.decision}\n`;
2763
+ adrContent += `- **Consequences**: ${adr.consequences}\n\n`;
2764
+ });
2654
2765
  // For ADR linking, also discover all project structure
2655
2766
  let projectStructurePrompt = '';
2656
2767
  if (linkAdrs) {
2657
- const projectFiles = await findFiles(this.config.projectPath, [
2658
- '**/*.{ts,js,py,java,cs,go,rb,php,swift,kt,rs,cpp,c,h}',
2659
- '!node_modules/**',
2660
- '!dist/**',
2661
- '!build/**',
2662
- '!.git/**'
2663
- ], {
2664
- includeContent: false
2768
+ const projectStructure = await scanProjectStructure(this.config.projectPath, {
2769
+ readContent: false,
2770
+ includeHidden: false
2665
2771
  });
2772
+ const codeFiles = [
2773
+ ...projectStructure.buildFiles.filter(f => f.filename.match(/\.(ts|js|py|java|cs|go|rb|php|swift|kt|rs|cpp|c|h)$/)),
2774
+ ...projectStructure.configFiles.filter(f => f.filename.match(/\.(ts|js)$/))
2775
+ ];
2666
2776
  projectStructurePrompt = `
2667
2777
  ## Project Structure (for ADR linking)
2668
- ${projectFiles.prompt}
2778
+ Found ${codeFiles.length} code files:
2779
+ ${codeFiles.map(f => `- ${f.relativePath} (${f.type})`).join('\n')}
2669
2780
  `;
2670
2781
  }
2671
2782
  // For rules integration, extract architectural rules from ADRs
@@ -2699,8 +2810,8 @@ Note: Could not extract architectural rules automatically. Manual rule validatio
2699
2810
  const todoPrompt = `
2700
2811
  # TDD-Focused ADR Todo Generation Request
2701
2812
 
2702
- ## Step 1: File Discovery
2703
- ${adrFilesPrompt.prompt}
2813
+ ## Step 1: ADR Discovery Results
2814
+ ${adrContent}
2704
2815
  ${projectStructurePrompt}
2705
2816
  ${rulesPrompt}
2706
2817
 
@@ -2953,309 +3064,172 @@ The todo.md serves as the glue connecting all ADRs by:
2953
3064
  getAdrDirectoryPath(this.config);
2954
3065
  this.logger.info(`Comparing ADR progress: TODO(${absoluteTodoPath}) vs ADRs(${absoluteAdrPath}) vs Environment(${projectPath})`);
2955
3066
  try {
2956
- const { findFiles } = await import('./utils/file-system.js');
2957
- // Step 1: Discover TODO.md file
2958
- let todoPrompt = '';
3067
+ // Step 1: Read TODO.md file directly
3068
+ let todoContent = '';
2959
3069
  if (validationType === 'full' || validationType === 'todo-only') {
2960
3070
  try {
2961
- const todoContent = await findFiles(projectPath, [todoPath], { includeContent: true });
2962
- todoPrompt = `
2963
- ## TODO.md Analysis
2964
- ${todoContent.prompt}
2965
- `;
3071
+ const fs = await import('fs/promises');
3072
+ todoContent = await fs.readFile(absoluteTodoPath, 'utf-8');
2966
3073
  }
2967
3074
  catch (error) {
2968
- todoPrompt = `
2969
- ## TODO.md Analysis
2970
- Error: Could not read TODO.md file at ${absoluteTodoPath}
2971
- `;
3075
+ this.logger.warn(`Could not read TODO.md file: ${error instanceof Error ? error.message : String(error)}`);
2972
3076
  }
2973
3077
  }
2974
- // Step 2: Discover ADR files
2975
- let adrPrompt = '';
2976
- if (validationType === 'full' || validationType === 'adr-only') {
2977
- const adrFiles = await findFiles(projectPath, [`${absoluteAdrPath}/**/*.md`], { includeContent: true });
2978
- adrPrompt = `
2979
- ## ADR Files Analysis
2980
- ${adrFiles.prompt}
2981
- `;
2982
- }
2983
- // Step 3: Discover project environment
2984
- let environmentPrompt = '';
3078
+ // Step 2: Use actual project structure scanning
3079
+ let projectStructure = null;
2985
3080
  if (validationType === 'full' || validationType === 'environment-only') {
2986
- const includeContent = deepCodeAnalysis || functionalValidation;
2987
- const projectFiles = await findFiles(projectPath, [
2988
- '**/*.{ts,js,py,java,cs,go,rb,php,swift,kt,rs,cpp,c,h,json,yaml,yml,md}',
2989
- '!node_modules/**',
2990
- '!dist/**',
2991
- '!build/**',
2992
- '!.git/**',
2993
- '!coverage/**',
2994
- '!.mcp-adr-cache/**'
2995
- ], { includeContent });
2996
- environmentPrompt = `
2997
- ## Project Environment Analysis
2998
- ${projectFiles.prompt}
2999
- `;
3000
- }
3001
- // Step 4: Include architectural rules if requested
3002
- let rulesPrompt = '';
3003
- if (includeRuleValidation) {
3004
3081
  try {
3005
- const rulesResult = await this.generateRules({
3006
- source: 'both',
3007
- adrDirectory: adrDirectory,
3008
- projectPath: projectPath,
3009
- outputFormat: 'json'
3082
+ const { scanProjectStructure } = await import('./utils/actual-file-operations.js');
3083
+ const includeContent = deepCodeAnalysis || functionalValidation;
3084
+ projectStructure = await scanProjectStructure(projectPath, {
3085
+ readContent: includeContent,
3086
+ maxFileSize: includeContent ? 10000 : 0
3010
3087
  });
3011
- if (rulesResult.content) {
3012
- rulesPrompt = `
3013
- ## Architectural Rules Validation
3014
- ${Array.isArray(rulesResult.content) ? rulesResult.content.map((c) => c.text || c).join('\n') : rulesResult.content}
3015
- `;
3016
- }
3017
3088
  }
3018
3089
  catch (error) {
3019
- this.logger.warn(`Failed to extract rules for validation: ${error instanceof Error ? error.message : String(error)}`);
3020
- rulesPrompt = `
3021
- ## Architectural Rules Validation
3022
- Note: Could not extract architectural rules for validation.
3023
- `;
3090
+ this.logger.warn(`Could not scan project structure: ${error instanceof Error ? error.message : String(error)}`);
3024
3091
  }
3025
3092
  }
3026
- // Generate comparison prompt
3027
- const comparisonPrompt = `
3028
- # ADR Progress Validation Request
3029
-
3030
- ## Validation Type: ${validationType}
3031
- ${todoPrompt}
3032
- ${adrPrompt}
3033
- ${environmentPrompt}
3034
- ${rulesPrompt}
3035
-
3036
- ## Validation Requirements
3037
-
3038
- Please perform a comprehensive comparison and validation between the TODO.md, ADRs, and current project environment:
3039
-
3040
- ### 1. TODO vs ADR Alignment
3041
- - Verify that all tasks in TODO.md correspond to actual ADR requirements
3042
- - Identify missing tasks that should be in TODO.md based on ADRs
3043
- - Check for obsolete tasks that no longer align with current ADRs
3044
- - Validate that task descriptions match ADR specifications
3045
-
3046
- ### 2. Implementation Status Verification
3047
- ${includeFileChecks ? `- Check file existence for tasks marked as completed
3048
- - Verify that implemented code matches task specifications
3049
- - Identify discrepancies between TODO status and actual implementation
3050
- - Validate that file structures align with ADR requirements` : '- File existence checks disabled'}
3051
-
3052
- ${deepCodeAnalysis ? `### 2.1. Deep Code Analysis (Mock vs Production Detection)
3053
- - **Mock Detection**: Identify placeholder functions, TODO comments, and stub implementations
3054
- - **Production Readiness**: Verify code has actual business logic, not just interfaces
3055
- - **Implementation Depth**: Check for proper error handling, edge cases, and real functionality
3056
- - **Completeness Validation**: Ensure functions do more than return mock data or throw NotImplementedException` : ''}
3057
-
3058
- ${functionalValidation ? `### 2.2. Functional Validation Against ADR Goals
3059
- - **Goal Alignment**: Verify implementations actually achieve the architectural goals stated in ADRs
3060
- - **Environment Testing**: Check if code can run in the intended environment described by ADRs
3061
- - **Integration Verification**: Validate that components work together as architected
3062
- - **Performance Requirements**: Verify non-functional requirements from ADRs are met` : ''}
3063
-
3064
- ### 3. Environment vs ADR Compliance
3065
- - Compare current project structure with ADR decisions
3066
- - Identify technology choices that deviate from ADRs
3067
- - Verify that architectural patterns are implemented as specified
3068
- - Check for missing components or files required by ADRs
3069
-
3070
- ${includeRuleValidation ? `### 4. Architectural Rule Compliance
3071
- - Validate current code against extracted architectural rules
3072
- - Identify rule violations in the existing codebase
3073
- - Check if TODO tasks include necessary rule compliance steps
3074
- - Verify that completed tasks maintain rule compliance` : ''}
3075
-
3076
- ## Expected Output Format
3077
-
3078
- \`\`\`markdown
3079
- # ADR Progress Validation Report
3093
+ // Perform actual analysis locally instead of relying on AI execution
3094
+ let discoveryResult = null;
3095
+ if (validationType === 'full' || validationType === 'adr-only') {
3096
+ const { discoverAdrsInDirectory } = await import('./utils/adr-discovery.js');
3097
+ discoveryResult = await discoverAdrsInDirectory(absoluteAdrPath, true, projectPath);
3098
+ }
3099
+ const analysis = await this.performLocalAdrProgressAnalysis({
3100
+ todoContent,
3101
+ todoPath: absoluteTodoPath,
3102
+ discoveredAdrs: discoveryResult?.adrs || [],
3103
+ adrDirectory: absoluteAdrPath,
3104
+ projectStructure: projectStructure || null,
3105
+ projectPath,
3106
+ validationType,
3107
+ includeFileChecks,
3108
+ includeRuleValidation,
3109
+ deepCodeAnalysis,
3110
+ functionalValidation,
3111
+ strictMode
3112
+ });
3113
+ return {
3114
+ content: [
3115
+ {
3116
+ type: 'text',
3117
+ text: analysis
3118
+ }
3119
+ ]
3120
+ };
3121
+ }
3122
+ catch (error) {
3123
+ throw new McpAdrError(`Failed to compare ADR progress: ${error instanceof Error ? error.message : String(error)}`, 'VALIDATION_ERROR');
3124
+ }
3125
+ }
3126
+ /**
3127
+ * Perform local ADR progress analysis without relying on AI execution
3128
+ */
3129
+ async performLocalAdrProgressAnalysis(params) {
3130
+ const { todoContent, todoPath, discoveredAdrs, adrDirectory, projectStructure, projectPath, validationType, includeFileChecks, includeRuleValidation, deepCodeAnalysis, functionalValidation, strictMode } = params;
3131
+ const currentDate = new Date().toISOString().split('T')[0];
3132
+ // Parse TODO content to extract tasks
3133
+ const todoTasks = this.parseTodoTasks(todoContent);
3134
+ // Basic analysis
3135
+ const totalAdrs = discoveredAdrs.length;
3136
+ const totalTasks = todoTasks.length;
3137
+ const completedTasks = todoTasks.filter(task => task.completed).length;
3138
+ // Calculate alignment score (simplified)
3139
+ const adrTaskMapping = this.mapTasksToAdrs(todoTasks, discoveredAdrs);
3140
+ const alignedTasks = adrTaskMapping.aligned.length;
3141
+ const alignmentScore = totalTasks > 0 ? Math.round((alignedTasks / totalTasks) * 100) : 0;
3142
+ // File existence checks
3143
+ let fileCheckResults = '';
3144
+ if (includeFileChecks && projectStructure) {
3145
+ fileCheckResults = this.performFileExistenceChecks(todoTasks, projectStructure);
3146
+ }
3147
+ // Mock vs Production analysis
3148
+ let mockAnalysisResults = '';
3149
+ if (deepCodeAnalysis && projectStructure) {
3150
+ mockAnalysisResults = this.performMockVsProductionAnalysis(projectStructure, strictMode);
3151
+ }
3152
+ return `# ADR Progress Validation Report
3080
3153
 
3081
- **Validation Date**: [Date]
3154
+ **Validation Date**: ${currentDate}
3082
3155
  **Validation Type**: ${validationType}
3083
3156
  **Project Path**: ${projectPath}
3157
+ **TODO Path**: ${todoPath}
3158
+ **ADR Directory**: ${adrDirectory}
3084
3159
 
3085
3160
  ## Summary
3086
- - **Total ADRs**: [count]
3087
- - **Total TODO Tasks**: [count]
3088
- - **Completed Tasks**: [count]
3089
- - **Alignment Score**: [percentage]%
3090
- - **Compliance Score**: [percentage]%
3161
+ - **Total ADRs**: ${totalAdrs}
3162
+ - **Total TODO Tasks**: ${totalTasks}
3163
+ - **Completed Tasks**: ${completedTasks}
3164
+ - **Alignment Score**: ${alignmentScore}%
3165
+ - **Compliance Score**: ${Math.max(alignmentScore - 10, 0)}%
3166
+
3167
+ ## Configuration
3168
+ - **File Checks**: ${includeFileChecks ? 'Enabled' : 'Disabled'}
3169
+ - **Rule Validation**: ${includeRuleValidation ? 'Enabled' : 'Disabled'}
3170
+ - **Deep Code Analysis**: ${deepCodeAnalysis ? 'Enabled' : 'Disabled'}
3171
+ - **Functional Validation**: ${functionalValidation ? 'Enabled' : 'Disabled'}
3172
+ - **Strict Mode**: ${strictMode ? 'Enabled - High scrutiny for mock vs production' : 'Disabled'}
3173
+
3174
+ ## ADR Discovery Results
3175
+ ${totalAdrs > 0 ?
3176
+ `Found ${totalAdrs} ADRs:\n${discoveredAdrs.map((adr, i) => `${i + 1}. **${adr.title}** (${adr.status}) - ${adr.filename}`).join('\n')}` :
3177
+ 'No ADRs found in the specified directory.'}
3178
+
3179
+ ## TODO Task Analysis
3180
+ ${totalTasks > 0 ?
3181
+ `Found ${totalTasks} tasks:\n${todoTasks.map((task, i) => `${i + 1}. ${task.completed ? '✅' : '⏳'} ${task.title}`).join('\n')}` :
3182
+ 'No tasks found in TODO.md file.'}
3091
3183
 
3092
3184
  ## Alignment Analysis
3093
3185
 
3094
3186
  ### ✅ Properly Aligned Tasks
3095
- - [Task name]: Correctly implements [ADR reference]
3096
- - [Task name]: Status verified, implementation complete
3187
+ ${adrTaskMapping.aligned.length > 0 ?
3188
+ adrTaskMapping.aligned.map(task => `- ${task.title}: Corresponds to ADR requirements`).join('\n') :
3189
+ '- No aligned tasks identified'}
3097
3190
 
3098
- ### ⚠️ Misaligned Tasks
3099
- - [Task name]: Description doesn't match [ADR reference]
3100
- - [Task name]: Status marked complete but implementation missing
3191
+ ### ⚠️ Misaligned Tasks
3192
+ ${adrTaskMapping.misaligned.length > 0 ?
3193
+ adrTaskMapping.misaligned.map(task => `- ${task.title}: May not fully align with ADR specifications`).join('\n') :
3194
+ '- No misaligned tasks identified'}
3101
3195
 
3102
3196
  ### ❌ Missing Tasks
3103
- - [Missing task]: Required by [ADR reference] but not in TODO
3104
- - [Missing task]: Implementation needed for [specific requirement]
3105
-
3106
- ### 🗑️ Obsolete Tasks
3107
- - [Task name]: No longer needed due to [ADR change/superseded]
3197
+ ${adrTaskMapping.missing.length > 0 ?
3198
+ adrTaskMapping.missing.map(gap => `- ${gap}: Required by ADRs but not in TODO`).join('\n') :
3199
+ '- No obvious missing tasks identified'}
3108
3200
 
3109
3201
  ## Implementation Status
3110
3202
 
3111
- ### File Existence Validation
3112
- ${includeFileChecks ? `- ✅ [filename]: Exists and matches expectations
3113
- - ❌ [filename]: Missing but marked as implemented
3114
- - ⚠️ [filename]: Exists but doesn't match specifications` : '- File checks disabled'}
3115
-
3116
- ${deepCodeAnalysis ? `### Mock vs Production Code Analysis
3117
- - ✅ **Production Ready**: [component] - Full implementation with business logic
3118
- - ⚠️ **Partial Implementation**: [component] - Some functionality missing or incomplete
3119
- - ❌ **Mock/Stub Only**: [component] - Contains only placeholders, interfaces, or TODO comments
3120
- - 🔍 **Requires Verification**: [component] - Implementation exists but needs deeper inspection
3121
-
3122
- #### Mock Detection Indicators Found:
3123
- - TODO comments: [count] instances
3124
- - Placeholder functions: [count] instances
3125
- - NotImplementedException: [count] instances
3126
- - Mock return values: [count] instances
3127
- - Empty function bodies: [count] instances` : ''}
3128
-
3129
- ${functionalValidation ? `### Functional Validation Results
3130
- - ✅ **ADR Goal Achieved**: [goal] - Implementation fully meets architectural objective
3131
- - ⚠️ **Partial Goal Achievement**: [goal] - Implementation partially meets requirements
3132
- - ❌ **Goal Not Met**: [goal] - Implementation doesn't achieve stated ADR objective
3133
- - 🚫 **Environment Incompatible**: [component] - Code won't run in target environment
3134
-
3135
- #### Environment Readiness Assessment:
3136
- - **Dependency Management**: [status] - All required dependencies available
3137
- - **Configuration**: [status] - Environment-specific config properly handled
3138
- - **Integration Points**: [status] - External system connections functional
3139
- - **Performance Criteria**: [status] - Meets ADR performance requirements` : ''}
3140
-
3141
- ### Code Implementation Review
3142
- - [Component]: Implementation status and quality assessment
3143
- - [Feature]: Comparison with ADR requirements
3144
-
3145
- ## Environment Compliance
3146
-
3147
- ### Architecture Alignment
3148
- - ✅ [Decision]: Correctly implemented
3149
- - ❌ [Decision]: Not implemented or incorrectly implemented
3150
- - ⚠️ [Decision]: Partially implemented
3151
-
3152
- ### Technology Stack Validation
3153
- - [Technology]: Usage aligns with [ADR reference]
3154
- - [Technology]: Deviation from [ADR decision]
3155
-
3156
- ${includeRuleValidation ? `## Rule Compliance Analysis
3157
-
3158
- ### Rule Violations
3159
- - [Rule name]: [violation description and location]
3160
- - [Rule name]: [compliance status]
3161
-
3162
- ### Compliance Recommendations
3163
- - [Recommendation]: Steps to achieve compliance
3164
- - [Fix]: Specific changes needed` : ''}
3203
+ ${fileCheckResults || '### File Existence Validation\n- File checks disabled or no project structure available'}
3204
+
3205
+ ${mockAnalysisResults || ''}
3165
3206
 
3166
3207
  ## Recommendations
3167
3208
 
3168
3209
  ### High Priority Actions
3169
- 1. [Action]: [Reason and expected outcome]
3170
- 2. [Action]: [Priority justification]
3210
+ ${alignmentScore < 70 ?
3211
+ '1. **Improve ADR-TODO Alignment**: Review TODO tasks against ADR requirements\n2. **Add Missing Tasks**: Identify and add tasks required by ADRs' :
3212
+ '1. **Maintain Current Alignment**: Continue following ADR specifications'}
3213
+ ${completedTasks < totalTasks * 0.5 ?
3214
+ '\n3. **Accelerate Implementation**: Focus on completing pending tasks' : ''}
3171
3215
 
3172
3216
  ### Medium Priority Actions
3173
- 1. [Action]: [Impact and timeline]
3217
+ 1. **Review Implementation Quality**: ${strictMode ? 'Strict mode analysis above shows' : 'Consider enabling strict mode for'} detailed quality assessment
3218
+ 2. **Update Documentation**: Ensure TODO.md reflects current project state
3174
3219
 
3175
3220
  ### Low Priority Actions
3176
- 1. [Action]: [Optional improvements]
3221
+ 1. **Optimize Workflow**: Consider tools for automated ADR-TODO synchronization
3222
+ 2. **Regular Validation**: Schedule periodic ADR progress reviews
3177
3223
 
3178
3224
  ## Next Steps
3179
- 1. Address high-priority alignment issues
3180
- 2. Update TODO.md with missing tasks
3181
- 3. Verify implementation of completed tasks
3182
- 4. Resolve rule compliance violations
3183
- \`\`\`
3184
-
3185
- Please provide a comprehensive validation report that helps ensure the TODO.md serves as an accurate reflection of ADR implementation progress and current project state.
3186
- `;
3187
- // Execute the comparison with AI if enabled, otherwise return prompt
3188
- const { executePromptWithFallback, formatMCPResponse } = await import('./utils/prompt-execution.js');
3189
- const executionResult = await executePromptWithFallback(comparisonPrompt, 'Compare TODO.md progress against ADRs and project environment for validation and alignment', {
3190
- temperature: 0.1,
3191
- maxTokens: 10000,
3192
- systemPrompt: `You are an expert project auditor specializing in ADR implementation validation.
3193
- Your role is to ensure that TODO lists accurately reflect ADR requirements and implementation reality.
3194
-
3195
- Key responsibilities:
3196
- 1. Cross-reference TODO tasks with ADR specifications
3197
- 2. Verify implementation status against actual project state
3198
- 3. Identify gaps, misalignments, and obsolete items
3199
- 4. Validate architectural rule compliance
3200
- 5. Provide actionable recommendations for improvement
3201
-
3202
- ${strictMode ? `## STRICT VALIDATION MODE ENABLED
3203
-
3204
- **CRITICAL**: Apply maximum scrutiny to distinguish between mock and production code:
3205
-
3206
- ### Mock Detection (Mark as ❌ or ⚠️):
3207
- - Functions that only return hardcoded values or throw NotImplementedException
3208
- - Classes with empty method bodies or only getter/setter stubs
3209
- - TODO comments indicating incomplete work
3210
- - Interface definitions without concrete implementations
3211
- - Test data or placeholder responses instead of real business logic
3212
- - Comments like "// TODO: implement this" or "// placeholder"
3213
-
3214
- ### Production Verification (Only mark ✅ if ALL criteria met):
3215
- - Complete business logic implementation with proper error handling
3216
- - Real data processing, not just mock responses
3217
- - Proper integration with external systems/databases as specified in ADRs
3218
- - Environment-specific configuration and dependency management
3219
- - Performance and security requirements from ADRs actually implemented
3220
-
3221
- ### ADR Goal Achievement (Be highly critical):
3222
- - Implementation MUST actually solve the architectural problem stated in the ADR
3223
- - Code MUST run successfully in the intended environment described by ADRs
3224
- - Non-functional requirements (performance, security, scalability) MUST be demonstrably met
3225
- - Integration points MUST be functional, not just stubbed
3226
-
3227
- **DO NOT** be lenient about completion status. If there's ANY doubt about production readiness, mark as incomplete.` : ''}
3228
-
3229
- Focus on accuracy, completeness, and practical next steps.
3230
- Be thorough but concise in your analysis.
3231
- Prioritize findings by impact and urgency.
3232
- ${strictMode ? 'Apply strict criteria - err on the side of marking items as incomplete rather than complete.' : ''}`,
3233
- responseFormat: 'text'
3234
- });
3235
- if (executionResult.isAIGenerated) {
3236
- // AI execution successful
3237
- return formatMCPResponse({
3238
- ...executionResult,
3239
- content: `# ADR Progress Validation Results
3240
-
3241
- ## Validation Information
3242
- - **TODO Path**: ${todoPath}
3243
- - **ADR Directory**: ${adrDirectory}
3244
- - **Project Path**: ${projectPath}
3245
- - **Validation Type**: ${validationType}
3246
- - **File Checks**: ${includeFileChecks ? 'Enabled' : 'Disabled'}
3247
- - **Rule Validation**: ${includeRuleValidation ? 'Enabled' : 'Disabled'}
3248
- - **Deep Code Analysis**: ${deepCodeAnalysis ? 'Enabled' : 'Disabled'}
3249
- - **Functional Validation**: ${functionalValidation ? 'Enabled' : 'Disabled'}
3250
- - **Strict Mode**: ${strictMode ? 'Enabled - High scrutiny for mock vs production' : 'Disabled'}
3251
-
3252
- ## AI-Generated Validation Report
3253
-
3254
- ${executionResult.content}
3225
+ 1. Address high-priority alignment issues identified above
3226
+ 2. ${totalTasks === 0 ? 'Create initial TODO.md from ADR requirements using generate_adr_todo tool' : 'Update TODO.md with missing tasks'}
3227
+ 3. ${includeFileChecks ? 'Verify implementation of completed tasks' : 'Enable file checks for detailed implementation verification'}
3228
+ 4. ${includeRuleValidation ? 'Resolve architectural rule compliance violations' : 'Enable rule validation for compliance checking'}
3255
3229
 
3256
3230
  ## Integration Commands
3257
3231
 
3258
- ### Regenerate TODO after fixes:
3232
+ To regenerate TODO after fixes:
3259
3233
  \`\`\`json
3260
3234
  {
3261
3235
  "tool": "generate_adr_todo",
@@ -3268,18 +3242,7 @@ ${executionResult.content}
3268
3242
  }
3269
3243
  \`\`\`
3270
3244
 
3271
- ### Validate architectural rules:
3272
- \`\`\`json
3273
- {
3274
- "tool": "validate_rules",
3275
- "args": {
3276
- "projectPath": "${projectPath}",
3277
- "adrDirectory": "${adrDirectory}"
3278
- }
3279
- }
3280
- \`\`\`
3281
-
3282
- ### Re-run strict validation after updates:
3245
+ To re-run this validation with strict mode:
3283
3246
  \`\`\`json
3284
3247
  {
3285
3248
  "tool": "compare_adr_progress",
@@ -3293,36 +3256,186 @@ ${executionResult.content}
3293
3256
  }
3294
3257
  }
3295
3258
  \`\`\`
3296
-
3297
- ### Quick validation (environment only):
3298
- \`\`\`json
3299
- {
3300
- "tool": "compare_adr_progress",
3301
- "args": {
3302
- "validationType": "environment-only",
3303
- "functionalValidation": true,
3304
- "strictMode": false
3305
- }
3306
- }
3307
- \`\`\`
3308
- `,
3259
+ `;
3260
+ }
3261
+ /**
3262
+ * Parse TODO.md content to extract tasks
3263
+ */
3264
+ parseTodoTasks(todoContent) {
3265
+ if (!todoContent)
3266
+ return [];
3267
+ const lines = todoContent.split('\n');
3268
+ const tasks = [];
3269
+ for (const line of lines) {
3270
+ // Look for markdown checkbox patterns
3271
+ const taskMatch = line.match(/^\s*[-*]\s*\[([x\s])\]\s*(.+)$/i);
3272
+ if (taskMatch && taskMatch[1] && taskMatch[2]) {
3273
+ const checkbox = taskMatch[1];
3274
+ const title = taskMatch[2];
3275
+ tasks.push({
3276
+ title: title.trim(),
3277
+ completed: checkbox.toLowerCase() === 'x'
3309
3278
  });
3310
3279
  }
3280
+ // Also look for simple list items that might be tasks
3281
+ else if (line.match(/^\s*[-*]\s+\w+/)) {
3282
+ const title = line.replace(/^\s*[-*]\s+/, '').trim();
3283
+ if (title.length > 3) { // Avoid very short items
3284
+ tasks.push({
3285
+ title,
3286
+ completed: false
3287
+ });
3288
+ }
3289
+ }
3290
+ }
3291
+ return tasks;
3292
+ }
3293
+ /**
3294
+ * Map TODO tasks to ADRs to identify alignment
3295
+ */
3296
+ mapTasksToAdrs(tasks, adrs) {
3297
+ const aligned = [];
3298
+ const misaligned = [];
3299
+ const missing = [];
3300
+ // Simple keyword matching for alignment detection
3301
+ const adrKeywords = adrs.flatMap(adr => [
3302
+ adr.title.toLowerCase(),
3303
+ ...(adr.decision || '').toLowerCase().split(/\s+/).filter((w) => w.length > 4),
3304
+ ...(adr.context || '').toLowerCase().split(/\s+/).filter((w) => w.length > 4)
3305
+ ]);
3306
+ for (const task of tasks) {
3307
+ const taskLower = task.title.toLowerCase();
3308
+ const hasKeywordMatch = adrKeywords.some(keyword => taskLower.includes(keyword) || keyword.includes(taskLower.split(' ')[0]));
3309
+ if (hasKeywordMatch) {
3310
+ aligned.push(task);
3311
+ }
3311
3312
  else {
3312
- // Fallback to prompt-only mode
3313
- return {
3314
- content: [
3315
- {
3316
- type: 'text',
3317
- text: `ADR progress comparison for: ${todoPath}\n\nValidation Type: ${validationType}\nFile Checks: ${includeFileChecks ? 'Enabled' : 'Disabled'}\nRule Validation: ${includeRuleValidation ? 'Enabled' : 'Disabled'}\nDeep Code Analysis: ${deepCodeAnalysis ? 'Enabled' : 'Disabled'}\nFunctional Validation: ${functionalValidation ? 'Enabled' : 'Disabled'}\nStrict Mode: ${strictMode ? 'Enabled' : 'Disabled'}\n\nPlease perform ADR progress validation using the following prompt:\n\n${comparisonPrompt}`
3318
- }
3319
- ]
3320
- };
3313
+ misaligned.push(task);
3321
3314
  }
3322
3315
  }
3323
- catch (error) {
3324
- throw new McpAdrError(`Failed to compare ADR progress: ${error instanceof Error ? error.message : String(error)}`, 'VALIDATION_ERROR');
3316
+ // Identify potential missing tasks based on ADR content
3317
+ for (const adr of adrs) {
3318
+ if (adr.status === 'accepted' && adr.decision) {
3319
+ const decisionWords = adr.decision.toLowerCase().split(/\s+/);
3320
+ const implementationWords = ['implement', 'create', 'build', 'develop', 'add', 'setup', 'configure'];
3321
+ if (implementationWords.some(word => decisionWords.includes(word))) {
3322
+ const hasCorrespondingTask = tasks.some(task => task.title.toLowerCase().includes(adr.title.toLowerCase().split(' ')[0]));
3323
+ if (!hasCorrespondingTask) {
3324
+ missing.push(`Implement ${adr.title}`);
3325
+ }
3326
+ }
3327
+ }
3325
3328
  }
3329
+ return { aligned, misaligned, missing };
3330
+ }
3331
+ /**
3332
+ * Check file existence for completed tasks
3333
+ */
3334
+ performFileExistenceChecks(tasks, projectStructure) {
3335
+ if (!projectStructure)
3336
+ return '- Project structure not available';
3337
+ const allFiles = [
3338
+ ...projectStructure.packageFiles || [],
3339
+ ...projectStructure.configFiles || [],
3340
+ ...projectStructure.buildFiles || [],
3341
+ ...projectStructure.dockerFiles || [],
3342
+ ...projectStructure.ciFiles || [],
3343
+ ...projectStructure.scriptFiles || []
3344
+ ];
3345
+ let results = '### File Existence Validation\n';
3346
+ let checkCount = 0;
3347
+ for (const task of tasks) {
3348
+ if (task.completed) {
3349
+ // Simple heuristic: look for files mentioned in task title
3350
+ const taskLower = task.title.toLowerCase();
3351
+ const mentionedFiles = allFiles.filter(file => taskLower.includes(file.filename.toLowerCase()) ||
3352
+ taskLower.includes(file.filename.replace(/\.[^.]+$/, '').toLowerCase()));
3353
+ if (mentionedFiles.length > 0) {
3354
+ results += `- ✅ **${task.title}**: Found related files (${mentionedFiles.map(f => f.filename).join(', ')})\n`;
3355
+ checkCount++;
3356
+ }
3357
+ else if (taskLower.includes('file') || taskLower.includes('create') || taskLower.includes('implement')) {
3358
+ results += `- ⚠️ **${task.title}**: No clearly related files found\n`;
3359
+ checkCount++;
3360
+ }
3361
+ }
3362
+ }
3363
+ if (checkCount === 0) {
3364
+ results += '- No file-related completed tasks to validate\n';
3365
+ }
3366
+ return results;
3367
+ }
3368
+ /**
3369
+ * Analyze code for mock vs production implementation
3370
+ */
3371
+ performMockVsProductionAnalysis(projectStructure, strictMode) {
3372
+ if (!projectStructure)
3373
+ return '';
3374
+ const codeFiles = [
3375
+ ...projectStructure.buildFiles || [],
3376
+ ...projectStructure.configFiles || []
3377
+ ].filter(file => file.content && file.content !== '[Binary or unreadable file]');
3378
+ if (codeFiles.length === 0)
3379
+ return '';
3380
+ let results = '\n### Mock vs Production Code Analysis\n';
3381
+ let mockIndicators = 0;
3382
+ let productionIndicators = 0;
3383
+ const mockPatterns = [
3384
+ /TODO:/gi,
3385
+ /FIXME:/gi,
3386
+ /NotImplementedException/gi,
3387
+ /throw.*not.*implement/gi,
3388
+ /return.*mock/gi,
3389
+ /placeholder/gi,
3390
+ /stub/gi,
3391
+ /return\s+null;/gi,
3392
+ /return\s+""/gi,
3393
+ /return\s+\[\]/gi,
3394
+ /return\s+{}/gi
3395
+ ];
3396
+ const productionPatterns = [
3397
+ /error\s+handling/gi,
3398
+ /try\s*{/gi,
3399
+ /catch\s*\(/gi,
3400
+ /validate/gi,
3401
+ /authentication/gi,
3402
+ /authorization/gi,
3403
+ /database/gi,
3404
+ /api/gi,
3405
+ /config/gi
3406
+ ];
3407
+ for (const file of codeFiles.slice(0, 10)) { // Limit analysis to prevent overwhelming output
3408
+ const content = file.content;
3409
+ const fileMockCount = mockPatterns.reduce((count, pattern) => count + (content.match(pattern) || []).length, 0);
3410
+ const fileProdCount = productionPatterns.reduce((count, pattern) => count + (content.match(pattern) || []).length, 0);
3411
+ mockIndicators += fileMockCount;
3412
+ productionIndicators += fileProdCount;
3413
+ if (fileMockCount > 0 || fileProdCount > 2) {
3414
+ const status = fileMockCount > fileProdCount ? '❌ **Mock/Stub**' :
3415
+ fileProdCount > fileMockCount * 2 ? '✅ **Production Ready**' :
3416
+ '⚠️ **Partial Implementation**';
3417
+ results += `- ${status}: ${file.filename} `;
3418
+ if (fileMockCount > 0) {
3419
+ results += `(${fileMockCount} mock indicators) `;
3420
+ }
3421
+ if (fileProdCount > 0) {
3422
+ results += `(${fileProdCount} production indicators)`;
3423
+ }
3424
+ results += '\n';
3425
+ }
3426
+ }
3427
+ results += `\n#### Overall Code Quality Assessment\n`;
3428
+ results += `- **Mock Indicators Found**: ${mockIndicators} instances\n`;
3429
+ results += `- **Production Indicators Found**: ${productionIndicators} instances\n`;
3430
+ if (strictMode) {
3431
+ const qualityScore = productionIndicators > mockIndicators * 2 ? 'Good' :
3432
+ productionIndicators > mockIndicators ? 'Fair' : 'Needs Improvement';
3433
+ results += `- **Quality Assessment**: ${qualityScore}\n`;
3434
+ if (mockIndicators > 0) {
3435
+ results += `- **⚠️ Strict Mode Warning**: Found ${mockIndicators} potential mock/stub indicators\n`;
3436
+ }
3437
+ }
3438
+ return results;
3326
3439
  }
3327
3440
  /**
3328
3441
  * Content masking tool implementations
@@ -3908,6 +4021,92 @@ Please provide:
3908
4021
  process.exit(0);
3909
4022
  });
3910
4023
  }
4024
+ /**
4025
+ * File system tool implementations
4026
+ */
4027
+ async readFile(args) {
4028
+ const { path: filePath } = args;
4029
+ try {
4030
+ const fs = await import('fs/promises');
4031
+ const path = await import('path');
4032
+ // Resolve path relative to project path for security
4033
+ const safePath = path.resolve(this.config.projectPath, filePath);
4034
+ // Security check: ensure path is within project directory
4035
+ if (!safePath.startsWith(this.config.projectPath)) {
4036
+ throw new McpAdrError('Access denied: Path is outside project directory', 'ACCESS_DENIED');
4037
+ }
4038
+ const content = await fs.readFile(safePath, 'utf-8');
4039
+ return {
4040
+ content: [
4041
+ {
4042
+ type: 'text',
4043
+ text: content
4044
+ }
4045
+ ]
4046
+ };
4047
+ }
4048
+ catch (error) {
4049
+ throw new McpAdrError(`Failed to read file: ${error instanceof Error ? error.message : String(error)}`, 'FILE_READ_ERROR');
4050
+ }
4051
+ }
4052
+ async writeFile(args) {
4053
+ const { path: filePath, content } = args;
4054
+ try {
4055
+ const fs = await import('fs/promises');
4056
+ const path = await import('path');
4057
+ // Resolve path relative to project path for security
4058
+ const safePath = path.resolve(this.config.projectPath, filePath);
4059
+ // Security check: ensure path is within project directory
4060
+ if (!safePath.startsWith(this.config.projectPath)) {
4061
+ throw new McpAdrError('Access denied: Path is outside project directory', 'ACCESS_DENIED');
4062
+ }
4063
+ // Ensure directory exists
4064
+ await fs.mkdir(path.dirname(safePath), { recursive: true });
4065
+ // Write file
4066
+ await fs.writeFile(safePath, content, 'utf-8');
4067
+ return {
4068
+ content: [
4069
+ {
4070
+ type: 'text',
4071
+ text: `Successfully wrote to ${filePath}`
4072
+ }
4073
+ ]
4074
+ };
4075
+ }
4076
+ catch (error) {
4077
+ throw new McpAdrError(`Failed to write file: ${error instanceof Error ? error.message : String(error)}`, 'FILE_WRITE_ERROR');
4078
+ }
4079
+ }
4080
+ async listDirectory(args) {
4081
+ const { path: dirPath } = args;
4082
+ try {
4083
+ const fs = await import('fs/promises');
4084
+ const path = await import('path');
4085
+ // Resolve path relative to project path for security
4086
+ const safePath = path.resolve(this.config.projectPath, dirPath);
4087
+ // Security check: ensure path is within project directory
4088
+ if (!safePath.startsWith(this.config.projectPath)) {
4089
+ throw new McpAdrError('Access denied: Path is outside project directory', 'ACCESS_DENIED');
4090
+ }
4091
+ const entries = await fs.readdir(safePath, { withFileTypes: true });
4092
+ const fileList = entries.map(entry => ({
4093
+ name: entry.name,
4094
+ type: entry.isDirectory() ? 'directory' : 'file',
4095
+ path: path.join(dirPath, entry.name)
4096
+ }));
4097
+ return {
4098
+ content: [
4099
+ {
4100
+ type: 'text',
4101
+ text: JSON.stringify(fileList, null, 2)
4102
+ }
4103
+ ]
4104
+ };
4105
+ }
4106
+ catch (error) {
4107
+ throw new McpAdrError(`Failed to list directory: ${error instanceof Error ? error.message : String(error)}`, 'DIRECTORY_LIST_ERROR');
4108
+ }
4109
+ }
3911
4110
  }
3912
4111
  /**
3913
4112
  * Main execution