mcp-adr-analysis-server 1.1.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/LICENSE +21 -0
- package/README.md +608 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +1722 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/prompts/adr-suggestion-prompts.d.ts +24 -0
- package/dist/src/prompts/adr-suggestion-prompts.d.ts.map +1 -0
- package/dist/src/prompts/adr-suggestion-prompts.js +383 -0
- package/dist/src/prompts/adr-suggestion-prompts.js.map +1 -0
- package/dist/src/prompts/analysis-prompts.d.ts +24 -0
- package/dist/src/prompts/analysis-prompts.d.ts.map +1 -0
- package/dist/src/prompts/analysis-prompts.js +489 -0
- package/dist/src/prompts/analysis-prompts.js.map +1 -0
- package/dist/src/prompts/deployment-analysis-prompts.d.ts +54 -0
- package/dist/src/prompts/deployment-analysis-prompts.d.ts.map +1 -0
- package/dist/src/prompts/deployment-analysis-prompts.js +712 -0
- package/dist/src/prompts/deployment-analysis-prompts.js.map +1 -0
- package/dist/src/prompts/environment-analysis-prompts.d.ts +34 -0
- package/dist/src/prompts/environment-analysis-prompts.d.ts.map +1 -0
- package/dist/src/prompts/environment-analysis-prompts.js +724 -0
- package/dist/src/prompts/environment-analysis-prompts.js.map +1 -0
- package/dist/src/prompts/index.d.ts +43 -0
- package/dist/src/prompts/index.d.ts.map +1 -0
- package/dist/src/prompts/index.js +384 -0
- package/dist/src/prompts/index.js.map +1 -0
- package/dist/src/prompts/research-integration-prompts.d.ts +43 -0
- package/dist/src/prompts/research-integration-prompts.d.ts.map +1 -0
- package/dist/src/prompts/research-integration-prompts.js +398 -0
- package/dist/src/prompts/research-integration-prompts.js.map +1 -0
- package/dist/src/prompts/research-question-prompts.d.ts +75 -0
- package/dist/src/prompts/research-question-prompts.d.ts.map +1 -0
- package/dist/src/prompts/research-question-prompts.js +695 -0
- package/dist/src/prompts/research-question-prompts.js.map +1 -0
- package/dist/src/prompts/rule-generation-prompts.d.ts +63 -0
- package/dist/src/prompts/rule-generation-prompts.d.ts.map +1 -0
- package/dist/src/prompts/rule-generation-prompts.js +630 -0
- package/dist/src/prompts/rule-generation-prompts.js.map +1 -0
- package/dist/src/prompts/security-prompts.d.ts +23 -0
- package/dist/src/prompts/security-prompts.d.ts.map +1 -0
- package/dist/src/prompts/security-prompts.js +287 -0
- package/dist/src/prompts/security-prompts.js.map +1 -0
- package/dist/src/resources/index.d.ts +24 -0
- package/dist/src/resources/index.d.ts.map +1 -0
- package/dist/src/resources/index.js +458 -0
- package/dist/src/resources/index.js.map +1 -0
- package/dist/src/tools/adr-suggestion-tool.d.ts +40 -0
- package/dist/src/tools/adr-suggestion-tool.d.ts.map +1 -0
- package/dist/src/tools/adr-suggestion-tool.js +338 -0
- package/dist/src/tools/adr-suggestion-tool.js.map +1 -0
- package/dist/src/tools/content-masking-tool.d.ts +52 -0
- package/dist/src/tools/content-masking-tool.d.ts.map +1 -0
- package/dist/src/tools/content-masking-tool.js +206 -0
- package/dist/src/tools/content-masking-tool.js.map +1 -0
- package/dist/src/tools/deployment-analysis-tool.d.ts +39 -0
- package/dist/src/tools/deployment-analysis-tool.d.ts.map +1 -0
- package/dist/src/tools/deployment-analysis-tool.js +310 -0
- package/dist/src/tools/deployment-analysis-tool.js.map +1 -0
- package/dist/src/tools/environment-analysis-tool.d.ts +16 -0
- package/dist/src/tools/environment-analysis-tool.d.ts.map +1 -0
- package/dist/src/tools/environment-analysis-tool.js +298 -0
- package/dist/src/tools/environment-analysis-tool.js.map +1 -0
- package/dist/src/tools/research-integration-tool.d.ts +44 -0
- package/dist/src/tools/research-integration-tool.d.ts.map +1 -0
- package/dist/src/tools/research-integration-tool.js +429 -0
- package/dist/src/tools/research-integration-tool.js.map +1 -0
- package/dist/src/tools/research-question-tool.d.ts +55 -0
- package/dist/src/tools/research-question-tool.d.ts.map +1 -0
- package/dist/src/tools/research-question-tool.js +333 -0
- package/dist/src/tools/research-question-tool.js.map +1 -0
- package/dist/src/tools/rule-generation-tool.d.ts +49 -0
- package/dist/src/tools/rule-generation-tool.d.ts.map +1 -0
- package/dist/src/tools/rule-generation-tool.js +432 -0
- package/dist/src/tools/rule-generation-tool.js.map +1 -0
- package/dist/src/types/index.d.ts +531 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +129 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/utils/adr-suggestions.d.ts +104 -0
- package/dist/src/utils/adr-suggestions.d.ts.map +1 -0
- package/dist/src/utils/adr-suggestions.js +228 -0
- package/dist/src/utils/adr-suggestions.js.map +1 -0
- package/dist/src/utils/cache.d.ts +51 -0
- package/dist/src/utils/cache.d.ts.map +1 -0
- package/dist/src/utils/cache.js +243 -0
- package/dist/src/utils/cache.js.map +1 -0
- package/dist/src/utils/config.d.ts +65 -0
- package/dist/src/utils/config.d.ts.map +1 -0
- package/dist/src/utils/config.js +118 -0
- package/dist/src/utils/config.js.map +1 -0
- package/dist/src/utils/content-masking.d.ts +79 -0
- package/dist/src/utils/content-masking.d.ts.map +1 -0
- package/dist/src/utils/content-masking.js +203 -0
- package/dist/src/utils/content-masking.js.map +1 -0
- package/dist/src/utils/deployment-analysis.d.ts +67 -0
- package/dist/src/utils/deployment-analysis.d.ts.map +1 -0
- package/dist/src/utils/deployment-analysis.js +263 -0
- package/dist/src/utils/deployment-analysis.js.map +1 -0
- package/dist/src/utils/environment-analysis.d.ts +76 -0
- package/dist/src/utils/environment-analysis.d.ts.map +1 -0
- package/dist/src/utils/environment-analysis.js +329 -0
- package/dist/src/utils/environment-analysis.js.map +1 -0
- package/dist/src/utils/file-system.d.ts +63 -0
- package/dist/src/utils/file-system.d.ts.map +1 -0
- package/dist/src/utils/file-system.js +189 -0
- package/dist/src/utils/file-system.js.map +1 -0
- package/dist/src/utils/output-masking.d.ts +45 -0
- package/dist/src/utils/output-masking.d.ts.map +1 -0
- package/dist/src/utils/output-masking.js +200 -0
- package/dist/src/utils/output-masking.js.map +1 -0
- package/dist/src/utils/research-documentation.d.ts +58 -0
- package/dist/src/utils/research-documentation.d.ts.map +1 -0
- package/dist/src/utils/research-documentation.js +438 -0
- package/dist/src/utils/research-documentation.js.map +1 -0
- package/dist/src/utils/research-integration.d.ts +89 -0
- package/dist/src/utils/research-integration.d.ts.map +1 -0
- package/dist/src/utils/research-integration.js +432 -0
- package/dist/src/utils/research-integration.js.map +1 -0
- package/dist/src/utils/research-questions.d.ts +97 -0
- package/dist/src/utils/research-questions.d.ts.map +1 -0
- package/dist/src/utils/research-questions.js +319 -0
- package/dist/src/utils/research-questions.js.map +1 -0
- package/dist/src/utils/rule-format.d.ts +76 -0
- package/dist/src/utils/rule-format.d.ts.map +1 -0
- package/dist/src/utils/rule-format.js +257 -0
- package/dist/src/utils/rule-format.js.map +1 -0
- package/dist/src/utils/rule-generation.d.ts +86 -0
- package/dist/src/utils/rule-generation.d.ts.map +1 -0
- package/dist/src/utils/rule-generation.js +330 -0
- package/dist/src/utils/rule-generation.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Research question generation utilities using prompt-driven AI analysis
|
|
3
|
+
* Implements intelligent research question generation and task tracking
|
|
4
|
+
*/
|
|
5
|
+
import { McpAdrError } from '../types/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Correlate problems with knowledge graph
|
|
8
|
+
*/
|
|
9
|
+
export async function correlateProblemKnowledge(problems, knowledgeGraph) {
|
|
10
|
+
try {
|
|
11
|
+
const { generateProblemKnowledgeCorrelationPrompt } = await import('../prompts/research-question-prompts.js');
|
|
12
|
+
const correlationPrompt = generateProblemKnowledgeCorrelationPrompt(problems, knowledgeGraph);
|
|
13
|
+
const instructions = `
|
|
14
|
+
# Problem-Knowledge Correlation Instructions
|
|
15
|
+
|
|
16
|
+
This analysis will correlate identified problems with the architectural knowledge graph to identify research opportunities.
|
|
17
|
+
|
|
18
|
+
## Correlation Analysis
|
|
19
|
+
- **Problems**: ${problems.length} problems identified
|
|
20
|
+
- **Technologies**: ${knowledgeGraph.technologies.length} technologies in knowledge graph
|
|
21
|
+
- **Patterns**: ${knowledgeGraph.patterns.length} patterns in knowledge graph
|
|
22
|
+
- **ADRs**: ${knowledgeGraph.adrs.length} ADRs in knowledge graph
|
|
23
|
+
- **Relationships**: ${knowledgeGraph.relationships.length} relationships mapped
|
|
24
|
+
|
|
25
|
+
## Next Steps
|
|
26
|
+
1. **Submit the correlation prompt** to an AI agent for comprehensive analysis
|
|
27
|
+
2. **Parse the JSON response** to get correlation analysis and research opportunities
|
|
28
|
+
3. **Review knowledge gaps** and prioritize research areas
|
|
29
|
+
4. **Use findings** to generate targeted research questions
|
|
30
|
+
|
|
31
|
+
## Expected AI Response Format
|
|
32
|
+
The AI will return a JSON object with:
|
|
33
|
+
- \`correlationAnalysis\`: Overall correlation statistics and confidence
|
|
34
|
+
- \`problemCorrelations\`: Detailed problem-knowledge correlations
|
|
35
|
+
- \`knowledgeGaps\`: Identified gaps in the knowledge graph
|
|
36
|
+
- \`researchOpportunities\`: Prioritized research opportunities
|
|
37
|
+
- \`recommendations\`: Actionable recommendations for research planning
|
|
38
|
+
|
|
39
|
+
## Usage Example
|
|
40
|
+
\`\`\`typescript
|
|
41
|
+
const result = await correlateProblemKnowledge(problems, knowledgeGraph);
|
|
42
|
+
// Submit result.correlationPrompt to AI agent
|
|
43
|
+
// Parse AI response for correlation analysis
|
|
44
|
+
\`\`\`
|
|
45
|
+
`;
|
|
46
|
+
return {
|
|
47
|
+
correlationPrompt,
|
|
48
|
+
instructions,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
throw new McpAdrError(`Failed to correlate problems with knowledge: ${error instanceof Error ? error.message : String(error)}`, 'CORRELATION_ERROR');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Find relevant ADRs and patterns for research context
|
|
57
|
+
*/
|
|
58
|
+
export async function findRelevantAdrPatterns(researchContext, adrDirectory = 'docs/adrs') {
|
|
59
|
+
try {
|
|
60
|
+
const { findFiles } = await import('./file-system.js');
|
|
61
|
+
const { generateRelevantAdrPatternPrompt } = await import('../prompts/research-question-prompts.js');
|
|
62
|
+
// Find all ADR files
|
|
63
|
+
const adrFiles = await findFiles(process.cwd(), [`${adrDirectory}/**/*.md`], {
|
|
64
|
+
includeContent: true,
|
|
65
|
+
});
|
|
66
|
+
// Prepare ADR data
|
|
67
|
+
const availableAdrs = adrFiles.map(file => {
|
|
68
|
+
const titleMatch = file.content?.match(/^#\s+(.+)$/m);
|
|
69
|
+
const statusMatch = file.content?.match(/##\s+Status\s*\n\s*(.+)/i);
|
|
70
|
+
return {
|
|
71
|
+
id: file.name.replace(/\.md$/, ''),
|
|
72
|
+
title: titleMatch?.[1] || file.name.replace(/\.md$/, ''),
|
|
73
|
+
content: file.content || '',
|
|
74
|
+
status: statusMatch?.[1] || 'Unknown',
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
// Extract patterns from project (simplified for this implementation)
|
|
78
|
+
const availablePatterns = extractArchitecturalPatterns();
|
|
79
|
+
const relevancePrompt = generateRelevantAdrPatternPrompt(researchContext, availableAdrs, availablePatterns);
|
|
80
|
+
const instructions = `
|
|
81
|
+
# Relevant ADR and Pattern Discovery Instructions
|
|
82
|
+
|
|
83
|
+
This analysis will identify ADRs and patterns relevant to the research context.
|
|
84
|
+
|
|
85
|
+
## Discovery Scope
|
|
86
|
+
- **Research Topic**: ${researchContext.topic}
|
|
87
|
+
- **Research Category**: ${researchContext.category}
|
|
88
|
+
- **Available ADRs**: ${availableAdrs.length} ADRs
|
|
89
|
+
- **Available Patterns**: ${availablePatterns.length} patterns
|
|
90
|
+
- **Research Objectives**: ${researchContext.objectives.length} objectives
|
|
91
|
+
|
|
92
|
+
## Next Steps
|
|
93
|
+
1. **Submit the relevance prompt** to an AI agent for analysis
|
|
94
|
+
2. **Parse the JSON response** to get relevant ADRs and patterns
|
|
95
|
+
3. **Review research implications** and constraints
|
|
96
|
+
4. **Use findings** to inform research question generation
|
|
97
|
+
|
|
98
|
+
## Expected AI Response Format
|
|
99
|
+
The AI will return a JSON object with:
|
|
100
|
+
- \`relevanceAnalysis\`: Overall relevance statistics and confidence
|
|
101
|
+
- \`relevantAdrs\`: ADRs relevant to the research context
|
|
102
|
+
- \`relevantPatterns\`: Patterns applicable to the research
|
|
103
|
+
- \`researchImplications\`: Constraints, opportunities, dependencies, conflicts
|
|
104
|
+
- \`researchGuidance\`: Specific guidance for research approach
|
|
105
|
+
|
|
106
|
+
## Usage Example
|
|
107
|
+
\`\`\`typescript
|
|
108
|
+
const result = await findRelevantAdrPatterns(researchContext, adrDirectory);
|
|
109
|
+
// Submit result.relevancePrompt to AI agent
|
|
110
|
+
// Parse AI response for relevant knowledge
|
|
111
|
+
\`\`\`
|
|
112
|
+
`;
|
|
113
|
+
return {
|
|
114
|
+
relevancePrompt,
|
|
115
|
+
instructions,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw new McpAdrError(`Failed to find relevant ADRs and patterns: ${error instanceof Error ? error.message : String(error)}`, 'RELEVANCE_ANALYSIS_ERROR');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Generate context-aware research questions
|
|
124
|
+
*/
|
|
125
|
+
export async function generateContextAwareQuestions(researchContext, relevantKnowledge, projectPath = process.cwd()) {
|
|
126
|
+
try {
|
|
127
|
+
const { analyzeProjectStructure } = await import('./file-system.js');
|
|
128
|
+
const { generateContextAwareResearchQuestionsPrompt } = await import('../prompts/research-question-prompts.js');
|
|
129
|
+
// Analyze project context
|
|
130
|
+
const projectStructure = await analyzeProjectStructure(projectPath);
|
|
131
|
+
const projectContext = {
|
|
132
|
+
technologies: projectStructure.detectedTechnologies || [],
|
|
133
|
+
architecture: inferArchitectureType(projectStructure),
|
|
134
|
+
domain: inferDomainType(projectStructure),
|
|
135
|
+
scale: inferProjectScale(projectStructure),
|
|
136
|
+
};
|
|
137
|
+
const questionPrompt = generateContextAwareResearchQuestionsPrompt({
|
|
138
|
+
...researchContext,
|
|
139
|
+
constraints: researchContext.constraints || [],
|
|
140
|
+
timeline: researchContext.timeline || 'Not specified',
|
|
141
|
+
}, relevantKnowledge, projectContext);
|
|
142
|
+
const instructions = `
|
|
143
|
+
# Context-Aware Research Question Generation Instructions
|
|
144
|
+
|
|
145
|
+
This analysis will generate specific, actionable research questions based on comprehensive context analysis.
|
|
146
|
+
|
|
147
|
+
## Question Generation Context
|
|
148
|
+
- **Research Topic**: ${researchContext.topic}
|
|
149
|
+
- **Project Technologies**: ${projectContext.technologies.join(', ')}
|
|
150
|
+
- **Architecture Type**: ${projectContext.architecture}
|
|
151
|
+
- **Domain**: ${projectContext.domain}
|
|
152
|
+
- **Project Scale**: ${projectContext.scale}
|
|
153
|
+
- **Relevant ADRs**: ${relevantKnowledge.adrs.length}
|
|
154
|
+
- **Relevant Patterns**: ${relevantKnowledge.patterns.length}
|
|
155
|
+
- **Knowledge Gaps**: ${relevantKnowledge.gaps.length}
|
|
156
|
+
- **Research Opportunities**: ${relevantKnowledge.opportunities.length}
|
|
157
|
+
|
|
158
|
+
## Next Steps
|
|
159
|
+
1. **Submit the question prompt** to an AI agent for comprehensive question generation
|
|
160
|
+
2. **Parse the JSON response** to get structured research questions
|
|
161
|
+
3. **Review research plan** and prioritize questions
|
|
162
|
+
4. **Create research tasks** using the task tracking system
|
|
163
|
+
|
|
164
|
+
## Expected AI Response Format
|
|
165
|
+
The AI will return a JSON object with:
|
|
166
|
+
- \`researchQuestionGeneration\`: Generation metadata and quality metrics
|
|
167
|
+
- \`primaryQuestions\`: Core research questions with detailed specifications
|
|
168
|
+
- \`secondaryQuestions\`: Supporting questions for comprehensive coverage
|
|
169
|
+
- \`methodologicalQuestions\`: Questions about research approach and methodology
|
|
170
|
+
- \`researchPlan\`: Phased research plan with timelines and dependencies
|
|
171
|
+
- \`qualityAssurance\`: Quality assurance and validation approach
|
|
172
|
+
- \`expectedImpact\`: Expected impact and benefits of the research
|
|
173
|
+
|
|
174
|
+
## Usage Example
|
|
175
|
+
\`\`\`typescript
|
|
176
|
+
const result = await generateContextAwareQuestions(context, knowledge, projectPath);
|
|
177
|
+
// Submit result.questionPrompt to AI agent
|
|
178
|
+
// Parse AI response for research questions and plan
|
|
179
|
+
\`\`\`
|
|
180
|
+
`;
|
|
181
|
+
return {
|
|
182
|
+
questionPrompt,
|
|
183
|
+
instructions,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
throw new McpAdrError(`Failed to generate context-aware questions: ${error instanceof Error ? error.message : String(error)}`, 'QUESTION_GENERATION_ERROR');
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Create research task tracking system
|
|
192
|
+
*/
|
|
193
|
+
export async function createResearchTaskTracking(researchQuestions, currentProgress) {
|
|
194
|
+
try {
|
|
195
|
+
const { generateResearchTaskTrackingPrompt } = await import('../prompts/research-question-prompts.js');
|
|
196
|
+
const trackingPrompt = generateResearchTaskTrackingPrompt(researchQuestions, currentProgress);
|
|
197
|
+
const instructions = `
|
|
198
|
+
# Research Task Tracking Instructions
|
|
199
|
+
|
|
200
|
+
This analysis will create a comprehensive task tracking and management system for research execution.
|
|
201
|
+
|
|
202
|
+
## Tracking Scope
|
|
203
|
+
- **Research Questions**: ${researchQuestions.length} questions to track
|
|
204
|
+
- **Current Progress**: ${currentProgress?.length || 0} progress entries
|
|
205
|
+
- **Question Types**: ${Array.from(new Set(researchQuestions.map(q => q.type))).join(', ')}
|
|
206
|
+
- **Priority Levels**: ${Array.from(new Set(researchQuestions.map(q => q.priority))).join(', ')}
|
|
207
|
+
|
|
208
|
+
## Next Steps
|
|
209
|
+
1. **Submit the tracking prompt** to an AI agent for system creation
|
|
210
|
+
2. **Parse the JSON response** to get comprehensive tracking system
|
|
211
|
+
3. **Implement tracking** in project management tools
|
|
212
|
+
4. **Begin research execution** with regular progress updates
|
|
213
|
+
|
|
214
|
+
## Expected AI Response Format
|
|
215
|
+
The AI will return a JSON object with:
|
|
216
|
+
- \`researchTaskTracking\`: Overall tracking metadata and configuration
|
|
217
|
+
- \`researchTasks\`: Detailed tasks with progress tracking and dependencies
|
|
218
|
+
- \`milestones\`: Key milestones and checkpoints
|
|
219
|
+
- \`riskManagement\`: Risk identification and mitigation strategies
|
|
220
|
+
- \`progressMetrics\`: Quantitative progress measurements
|
|
221
|
+
- \`communicationPlan\`: Stakeholder communication and reporting
|
|
222
|
+
- \`qualityAssurance\`: Quality control and validation processes
|
|
223
|
+
- \`recommendations\`: Process and management recommendations
|
|
224
|
+
|
|
225
|
+
## Usage Example
|
|
226
|
+
\`\`\`typescript
|
|
227
|
+
const result = await createResearchTaskTracking(questions, progress);
|
|
228
|
+
// Submit result.trackingPrompt to AI agent
|
|
229
|
+
// Parse AI response for task tracking system
|
|
230
|
+
\`\`\`
|
|
231
|
+
`;
|
|
232
|
+
return {
|
|
233
|
+
trackingPrompt,
|
|
234
|
+
instructions,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
throw new McpAdrError(`Failed to create research task tracking: ${error instanceof Error ? error.message : String(error)}`, 'TASK_TRACKING_ERROR');
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Extract architectural patterns from project structure
|
|
243
|
+
*/
|
|
244
|
+
function extractArchitecturalPatterns() {
|
|
245
|
+
// Simplified pattern extraction - in a real implementation, this would be more sophisticated
|
|
246
|
+
return [
|
|
247
|
+
{
|
|
248
|
+
name: 'Microservices Architecture',
|
|
249
|
+
description: 'Distributed architecture with independent services',
|
|
250
|
+
category: 'architectural',
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
name: 'Layered Architecture',
|
|
254
|
+
description: 'Hierarchical organization of components',
|
|
255
|
+
category: 'architectural',
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
name: 'Event-Driven Architecture',
|
|
259
|
+
description: 'Asynchronous communication through events',
|
|
260
|
+
category: 'architectural',
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
name: 'Repository Pattern',
|
|
264
|
+
description: 'Data access abstraction pattern',
|
|
265
|
+
category: 'design',
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
name: 'Factory Pattern',
|
|
269
|
+
description: 'Object creation abstraction pattern',
|
|
270
|
+
category: 'design',
|
|
271
|
+
},
|
|
272
|
+
];
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Infer architecture type from project structure
|
|
276
|
+
*/
|
|
277
|
+
function inferArchitectureType(projectStructure) {
|
|
278
|
+
if (projectStructure.directories?.some((dir) => dir.includes('service'))) {
|
|
279
|
+
return 'microservices';
|
|
280
|
+
}
|
|
281
|
+
if (projectStructure.directories?.some((dir) => dir.includes('layer'))) {
|
|
282
|
+
return 'layered';
|
|
283
|
+
}
|
|
284
|
+
if (projectStructure.detectedTechnologies?.includes('kubernetes')) {
|
|
285
|
+
return 'cloud-native';
|
|
286
|
+
}
|
|
287
|
+
return 'monolithic';
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Infer domain type from project structure
|
|
291
|
+
*/
|
|
292
|
+
function inferDomainType(projectStructure) {
|
|
293
|
+
const technologies = projectStructure.detectedTechnologies || [];
|
|
294
|
+
if (technologies.some((tech) => tech.includes('react') || tech.includes('vue') || tech.includes('angular'))) {
|
|
295
|
+
return 'web-application';
|
|
296
|
+
}
|
|
297
|
+
if (technologies.some((tech) => tech.includes('api') || tech.includes('rest'))) {
|
|
298
|
+
return 'api-service';
|
|
299
|
+
}
|
|
300
|
+
if (technologies.some((tech) => tech.includes('data') || tech.includes('analytics'))) {
|
|
301
|
+
return 'data-platform';
|
|
302
|
+
}
|
|
303
|
+
return 'general-software';
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Infer project scale from project structure
|
|
307
|
+
*/
|
|
308
|
+
function inferProjectScale(projectStructure) {
|
|
309
|
+
const fileCount = projectStructure.totalFiles || 0;
|
|
310
|
+
const dirCount = projectStructure.totalDirectories || 0;
|
|
311
|
+
if (fileCount > 1000 || dirCount > 100) {
|
|
312
|
+
return 'enterprise';
|
|
313
|
+
}
|
|
314
|
+
if (fileCount > 100 || dirCount > 20) {
|
|
315
|
+
return 'medium';
|
|
316
|
+
}
|
|
317
|
+
return 'small';
|
|
318
|
+
}
|
|
319
|
+
//# sourceMappingURL=research-questions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"research-questions.js","sourceRoot":"","sources":["../../../src/utils/research-questions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA2DhD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,QAA2B,EAC3B,cAA8B;IAE9B,IAAI,CAAC;QACH,MAAM,EAAE,yCAAyC,EAAE,GAAG,MAAM,MAAM,CAChE,yCAAyC,CAC1C,CAAC;QAEF,MAAM,iBAAiB,GAAG,yCAAyC,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;QAE9F,MAAM,YAAY,GAAG;;;;;;kBAMP,QAAQ,CAAC,MAAM;sBACX,cAAc,CAAC,YAAY,CAAC,MAAM;kBACtC,cAAc,CAAC,QAAQ,CAAC,MAAM;cAClC,cAAc,CAAC,IAAI,CAAC,MAAM;uBACjB,cAAc,CAAC,aAAa,CAAC,MAAM;;;;;;;;;;;;;;;;;;;;;;CAsBzD,CAAC;QAEE,OAAO;YACL,iBAAiB;YACjB,YAAY;SACb,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,WAAW,CACnB,gDAAgD,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,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QAAQ,GAAG,gBAAgB,CAAC,gBAAgB,IAAI,CAAC,CAAC;IAExD,IAAI,SAAS,GAAG,IAAI,IAAI,QAAQ,GAAG,GAAG,EAAE,CAAC;QACvC,OAAO,YAAY,CAAC;IACtB,CAAC;IACD,IAAI,SAAS,GAAG,GAAG,IAAI,QAAQ,GAAG,EAAE,EAAE,CAAC;QACrC,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Machine-readable rule format utilities
|
|
3
|
+
* Implements JSON/YAML rule serialization and validation
|
|
4
|
+
*/
|
|
5
|
+
import { ArchitecturalRule, ValidationResult } from './rule-generation.js';
|
|
6
|
+
export interface RuleSet {
|
|
7
|
+
metadata: {
|
|
8
|
+
version: string;
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
created: string;
|
|
12
|
+
lastModified: string;
|
|
13
|
+
author: string;
|
|
14
|
+
tags: string[];
|
|
15
|
+
};
|
|
16
|
+
rules: ArchitecturalRule[];
|
|
17
|
+
categories: Array<{
|
|
18
|
+
name: string;
|
|
19
|
+
description: string;
|
|
20
|
+
priority: 'low' | 'medium' | 'high' | 'critical';
|
|
21
|
+
ruleCount: number;
|
|
22
|
+
}>;
|
|
23
|
+
dependencies: Array<{
|
|
24
|
+
ruleId: string;
|
|
25
|
+
dependsOn: string[];
|
|
26
|
+
conflictsWith: string[];
|
|
27
|
+
relationship: 'requires' | 'enhances' | 'conflicts' | 'supersedes';
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
30
|
+
export interface ComplianceReport {
|
|
31
|
+
metadata: {
|
|
32
|
+
reportId: string;
|
|
33
|
+
generatedAt: string;
|
|
34
|
+
projectName: string;
|
|
35
|
+
ruleSetVersion: string;
|
|
36
|
+
scope: string;
|
|
37
|
+
};
|
|
38
|
+
summary: {
|
|
39
|
+
overallCompliance: number;
|
|
40
|
+
totalFiles: number;
|
|
41
|
+
totalRules: number;
|
|
42
|
+
totalViolations: number;
|
|
43
|
+
riskLevel: 'low' | 'medium' | 'high' | 'critical';
|
|
44
|
+
};
|
|
45
|
+
results: ValidationResult[];
|
|
46
|
+
trends: Array<{
|
|
47
|
+
date: string;
|
|
48
|
+
compliance: number;
|
|
49
|
+
violations: number;
|
|
50
|
+
}>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Create a new rule set with metadata
|
|
54
|
+
*/
|
|
55
|
+
export declare function createRuleSet(name: string, description: string, rules: ArchitecturalRule[], author?: string): RuleSet;
|
|
56
|
+
/**
|
|
57
|
+
* Serialize rule set to JSON
|
|
58
|
+
*/
|
|
59
|
+
export declare function serializeRuleSetToJson(ruleSet: RuleSet): string;
|
|
60
|
+
/**
|
|
61
|
+
* Serialize rule set to YAML
|
|
62
|
+
*/
|
|
63
|
+
export declare function serializeRuleSetToYaml(ruleSet: RuleSet): string;
|
|
64
|
+
/**
|
|
65
|
+
* Parse rule set from JSON
|
|
66
|
+
*/
|
|
67
|
+
export declare function parseRuleSetFromJson(jsonContent: string): RuleSet;
|
|
68
|
+
/**
|
|
69
|
+
* Create compliance report
|
|
70
|
+
*/
|
|
71
|
+
export declare function createComplianceReport(projectName: string, ruleSetVersion: string, validationResults: ValidationResult[], scope?: string): ComplianceReport;
|
|
72
|
+
/**
|
|
73
|
+
* Serialize compliance report to JSON
|
|
74
|
+
*/
|
|
75
|
+
export declare function serializeComplianceReportToJson(report: ComplianceReport): string;
|
|
76
|
+
//# sourceMappingURL=rule-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-format.d.ts","sourceRoot":"","sources":["../../../src/utils/rule-format.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE3E,MAAM,WAAW,OAAO;IACtB,QAAQ,EAAE;QACR,OAAO,EAA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B,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC,CAAC;CACJ;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,iBAAiB,EAAE,EAC1B,MAAM,GAAE,MAAkC,GACzC,OAAO,CAsCT;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAS/D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAqE/D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAWjE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,EACtB,iBAAiB,EAAE,gBAAgB,EAAE,EACrC,KAAK,GAAE,MAAuB,GAC7B,gBAAgB,CAgDlB;AAED;;GAEG;AACH,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAShF"}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Machine-readable rule format utilities
|
|
3
|
+
* Implements JSON/YAML rule serialization and validation
|
|
4
|
+
*/
|
|
5
|
+
import { McpAdrError } from '../types/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Create a new rule set with metadata
|
|
8
|
+
*/
|
|
9
|
+
export function createRuleSet(name, description, rules, author = 'MCP ADR Analysis Server') {
|
|
10
|
+
const now = new Date().toISOString();
|
|
11
|
+
// Group rules by category
|
|
12
|
+
const categoryMap = new Map();
|
|
13
|
+
rules.forEach(rule => {
|
|
14
|
+
const category = rule.category;
|
|
15
|
+
if (!categoryMap.has(category)) {
|
|
16
|
+
categoryMap.set(category, []);
|
|
17
|
+
}
|
|
18
|
+
categoryMap.get(category).push(rule);
|
|
19
|
+
});
|
|
20
|
+
// Create category summaries
|
|
21
|
+
const categories = Array.from(categoryMap.entries()).map(([name, categoryRules]) => ({
|
|
22
|
+
name,
|
|
23
|
+
description: getCategoryDescription(name),
|
|
24
|
+
priority: getCategoryPriority(name),
|
|
25
|
+
ruleCount: categoryRules.length,
|
|
26
|
+
}));
|
|
27
|
+
// Extract rule dependencies
|
|
28
|
+
const dependencies = extractRuleDependencies(rules);
|
|
29
|
+
return {
|
|
30
|
+
metadata: {
|
|
31
|
+
version: '1.0.0',
|
|
32
|
+
name,
|
|
33
|
+
description,
|
|
34
|
+
created: now,
|
|
35
|
+
lastModified: now,
|
|
36
|
+
author,
|
|
37
|
+
tags: extractRuleTags(rules),
|
|
38
|
+
},
|
|
39
|
+
rules,
|
|
40
|
+
categories,
|
|
41
|
+
dependencies,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Serialize rule set to JSON
|
|
46
|
+
*/
|
|
47
|
+
export function serializeRuleSetToJson(ruleSet) {
|
|
48
|
+
try {
|
|
49
|
+
return JSON.stringify(ruleSet, null, 2);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
throw new McpAdrError(`Failed to serialize rule set to JSON: ${error instanceof Error ? error.message : String(error)}`, 'SERIALIZATION_ERROR');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Serialize rule set to YAML
|
|
57
|
+
*/
|
|
58
|
+
export function serializeRuleSetToYaml(ruleSet) {
|
|
59
|
+
try {
|
|
60
|
+
// Simple YAML serialization (for complex cases, use a proper YAML library)
|
|
61
|
+
const yamlLines = [];
|
|
62
|
+
// Metadata section
|
|
63
|
+
yamlLines.push('metadata:');
|
|
64
|
+
yamlLines.push(` version: "${ruleSet.metadata.version}"`);
|
|
65
|
+
yamlLines.push(` name: "${ruleSet.metadata.name}"`);
|
|
66
|
+
yamlLines.push(` description: "${ruleSet.metadata.description}"`);
|
|
67
|
+
yamlLines.push(` created: "${ruleSet.metadata.created}"`);
|
|
68
|
+
yamlLines.push(` lastModified: "${ruleSet.metadata.lastModified}"`);
|
|
69
|
+
yamlLines.push(` author: "${ruleSet.metadata.author}"`);
|
|
70
|
+
yamlLines.push(' tags:');
|
|
71
|
+
ruleSet.metadata.tags.forEach(tag => {
|
|
72
|
+
yamlLines.push(` - "${tag}"`);
|
|
73
|
+
});
|
|
74
|
+
// Categories section
|
|
75
|
+
yamlLines.push('');
|
|
76
|
+
yamlLines.push('categories:');
|
|
77
|
+
ruleSet.categories.forEach(category => {
|
|
78
|
+
yamlLines.push(` - name: "${category.name}"`);
|
|
79
|
+
yamlLines.push(` description: "${category.description}"`);
|
|
80
|
+
yamlLines.push(` priority: "${category.priority}"`);
|
|
81
|
+
yamlLines.push(` ruleCount: ${category.ruleCount}`);
|
|
82
|
+
});
|
|
83
|
+
// Rules section
|
|
84
|
+
yamlLines.push('');
|
|
85
|
+
yamlLines.push('rules:');
|
|
86
|
+
ruleSet.rules.forEach(rule => {
|
|
87
|
+
yamlLines.push(` - id: "${rule.id}"`);
|
|
88
|
+
yamlLines.push(` name: "${rule.name}"`);
|
|
89
|
+
yamlLines.push(` description: "${rule.description}"`);
|
|
90
|
+
yamlLines.push(` category: "${rule.category}"`);
|
|
91
|
+
yamlLines.push(` type: "${rule.type}"`);
|
|
92
|
+
yamlLines.push(` severity: "${rule.severity}"`);
|
|
93
|
+
yamlLines.push(` scope: "${rule.scope}"`);
|
|
94
|
+
yamlLines.push(` pattern: "${rule.pattern}"`);
|
|
95
|
+
yamlLines.push(` message: "${rule.message}"`);
|
|
96
|
+
yamlLines.push(` automatable: ${rule.automatable}`);
|
|
97
|
+
yamlLines.push(` confidence: ${rule.confidence}`);
|
|
98
|
+
yamlLines.push(' examples:');
|
|
99
|
+
yamlLines.push(' valid:');
|
|
100
|
+
rule.examples.valid.forEach(example => {
|
|
101
|
+
yamlLines.push(` - "${example}"`);
|
|
102
|
+
});
|
|
103
|
+
yamlLines.push(' invalid:');
|
|
104
|
+
rule.examples.invalid.forEach(example => {
|
|
105
|
+
yamlLines.push(` - "${example}"`);
|
|
106
|
+
});
|
|
107
|
+
yamlLines.push(' sourceAdrs:');
|
|
108
|
+
rule.sourceAdrs.forEach(adr => {
|
|
109
|
+
yamlLines.push(` - "${adr}"`);
|
|
110
|
+
});
|
|
111
|
+
yamlLines.push(' tags:');
|
|
112
|
+
rule.tags.forEach(tag => {
|
|
113
|
+
yamlLines.push(` - "${tag}"`);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
return yamlLines.join('\n');
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw new McpAdrError(`Failed to serialize rule set to YAML: ${error instanceof Error ? error.message : String(error)}`, 'SERIALIZATION_ERROR');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Parse rule set from JSON
|
|
124
|
+
*/
|
|
125
|
+
export function parseRuleSetFromJson(jsonContent) {
|
|
126
|
+
try {
|
|
127
|
+
const ruleSet = JSON.parse(jsonContent);
|
|
128
|
+
validateRuleSet(ruleSet);
|
|
129
|
+
return ruleSet;
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
throw new McpAdrError(`Failed to parse rule set from JSON: ${error instanceof Error ? error.message : String(error)}`, 'PARSING_ERROR');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Create compliance report
|
|
137
|
+
*/
|
|
138
|
+
export function createComplianceReport(projectName, ruleSetVersion, validationResults, scope = 'full_project') {
|
|
139
|
+
const now = new Date().toISOString();
|
|
140
|
+
const reportId = `compliance-${Date.now()}`;
|
|
141
|
+
// Calculate summary metrics
|
|
142
|
+
const totalFiles = validationResults.length;
|
|
143
|
+
const totalViolations = validationResults.reduce((sum, result) => sum + result.violations.length, 0);
|
|
144
|
+
const totalRules = validationResults.reduce((sum, result) => sum + result.totalRulesChecked, 0) / totalFiles;
|
|
145
|
+
const overallCompliance = validationResults.reduce((sum, result) => sum + result.overallCompliance, 0) / totalFiles;
|
|
146
|
+
// Determine risk level
|
|
147
|
+
const criticalViolations = validationResults.reduce((sum, result) => sum + result.violations.filter(v => v.severity === 'critical').length, 0);
|
|
148
|
+
const errorViolations = validationResults.reduce((sum, result) => sum + result.violations.filter(v => v.severity === 'error').length, 0);
|
|
149
|
+
let riskLevel = 'low';
|
|
150
|
+
if (criticalViolations > 0)
|
|
151
|
+
riskLevel = 'critical';
|
|
152
|
+
else if (errorViolations > 5)
|
|
153
|
+
riskLevel = 'high';
|
|
154
|
+
else if (overallCompliance < 0.8)
|
|
155
|
+
riskLevel = 'medium';
|
|
156
|
+
return {
|
|
157
|
+
metadata: {
|
|
158
|
+
reportId,
|
|
159
|
+
generatedAt: now,
|
|
160
|
+
projectName,
|
|
161
|
+
ruleSetVersion,
|
|
162
|
+
scope,
|
|
163
|
+
},
|
|
164
|
+
summary: {
|
|
165
|
+
overallCompliance,
|
|
166
|
+
totalFiles,
|
|
167
|
+
totalRules: Math.round(totalRules),
|
|
168
|
+
totalViolations,
|
|
169
|
+
riskLevel,
|
|
170
|
+
},
|
|
171
|
+
results: validationResults,
|
|
172
|
+
trends: [], // Would be populated with historical data
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Serialize compliance report to JSON
|
|
177
|
+
*/
|
|
178
|
+
export function serializeComplianceReportToJson(report) {
|
|
179
|
+
try {
|
|
180
|
+
return JSON.stringify(report, null, 2);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
throw new McpAdrError(`Failed to serialize compliance report: ${error instanceof Error ? error.message : String(error)}`, 'SERIALIZATION_ERROR');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Validate rule set structure
|
|
188
|
+
*/
|
|
189
|
+
function validateRuleSet(ruleSet) {
|
|
190
|
+
if (!ruleSet.metadata || !ruleSet.rules || !Array.isArray(ruleSet.rules)) {
|
|
191
|
+
throw new Error('Invalid rule set structure: missing metadata or rules');
|
|
192
|
+
}
|
|
193
|
+
if (!ruleSet.metadata.version || !ruleSet.metadata.name) {
|
|
194
|
+
throw new Error('Invalid rule set metadata: missing version or name');
|
|
195
|
+
}
|
|
196
|
+
// Validate each rule
|
|
197
|
+
ruleSet.rules.forEach((rule, index) => {
|
|
198
|
+
if (!rule.id || !rule.name || !rule.description) {
|
|
199
|
+
throw new Error(`Invalid rule at index ${index}: missing required fields`);
|
|
200
|
+
}
|
|
201
|
+
if (!['must', 'should', 'may', 'must_not', 'should_not'].includes(rule.type)) {
|
|
202
|
+
throw new Error(`Invalid rule type at index ${index}: ${rule.type}`);
|
|
203
|
+
}
|
|
204
|
+
if (!['info', 'warning', 'error', 'critical'].includes(rule.severity)) {
|
|
205
|
+
throw new Error(`Invalid rule severity at index ${index}: ${rule.severity}`);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Get category description
|
|
211
|
+
*/
|
|
212
|
+
function getCategoryDescription(category) {
|
|
213
|
+
const descriptions = {
|
|
214
|
+
architectural: 'Rules governing overall system architecture and design patterns',
|
|
215
|
+
technology: 'Rules about technology choices, frameworks, and libraries',
|
|
216
|
+
coding: 'Rules for code style, organization, and implementation practices',
|
|
217
|
+
process: 'Rules for development processes and workflows',
|
|
218
|
+
security: 'Rules for security implementation and best practices',
|
|
219
|
+
performance: 'Rules for performance optimization and efficiency',
|
|
220
|
+
};
|
|
221
|
+
return descriptions[category] || 'General architectural rules';
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Get category priority
|
|
225
|
+
*/
|
|
226
|
+
function getCategoryPriority(category) {
|
|
227
|
+
const priorities = {
|
|
228
|
+
security: 'critical',
|
|
229
|
+
architectural: 'high',
|
|
230
|
+
performance: 'high',
|
|
231
|
+
technology: 'medium',
|
|
232
|
+
coding: 'medium',
|
|
233
|
+
process: 'low',
|
|
234
|
+
};
|
|
235
|
+
return priorities[category] || 'medium';
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Extract rule dependencies
|
|
239
|
+
*/
|
|
240
|
+
function extractRuleDependencies(rules) {
|
|
241
|
+
// Simple dependency extraction based on rule content
|
|
242
|
+
// In a real implementation, this would be more sophisticated
|
|
243
|
+
return rules.map(rule => ({
|
|
244
|
+
ruleId: rule.id,
|
|
245
|
+
dependsOn: [],
|
|
246
|
+
conflictsWith: [],
|
|
247
|
+
relationship: 'enhances',
|
|
248
|
+
}));
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Extract tags from rules
|
|
252
|
+
*/
|
|
253
|
+
function extractRuleTags(rules) {
|
|
254
|
+
const allTags = rules.flatMap(rule => rule.tags);
|
|
255
|
+
return Array.from(new Set(allTags));
|
|
256
|
+
}
|
|
257
|
+
//# sourceMappingURL=rule-format.js.map
|