sdd-mcp-server 1.3.11 → 1.4.1

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.
@@ -0,0 +1,263 @@
1
+ import { analyzeProject } from './documentGenerator.js';
2
+
3
+ export async function generateRequirementsDocument(projectPath, featureName) {
4
+ const analysis = await analyzeProject(projectPath);
5
+ const desc = analysis.description || 'Feature requirements specification';
6
+ const obj = generateCoreObjective(analysis);
7
+ const acceptance = generateAcceptanceCriteria(analysis)
8
+ .map((c, i) => `${i + 1}. ${c}`)
9
+ .join('\n');
10
+
11
+ return `# Requirements Document
12
+
13
+ ## Introduction
14
+ ${featureName} - Requirements derived from codebase analysis.
15
+
16
+ **Project**: ${analysis.name}
17
+ **Description**: ${desc}
18
+
19
+ Generated on: ${new Date().toISOString()}
20
+
21
+ ## Functional Requirements
22
+
23
+ ### FR-1: Core Functionality
24
+ **Objective:** ${obj}
25
+
26
+ #### Acceptance Criteria
27
+ ${acceptance}
28
+
29
+ ### FR-2: Technology Integration
30
+ **Objective:** Integrate with the detected technology stack
31
+
32
+ #### Acceptance Criteria
33
+ ${generateTechRequirements(analysis).map((r, i) => `${i + 1}. ${r}`).join('\n')}
34
+
35
+ ### FR-3: Quality Standards
36
+ **Objective:** Meet quality, testing, and review standards
37
+
38
+ #### Acceptance Criteria
39
+ ${generateQualityRequirements(analysis).map((r, i) => `${i + 1}. ${r}`).join('\n')}
40
+
41
+ ## Non-Functional Requirements
42
+
43
+ ### NFR-1: Performance
44
+ - System SHALL respond within acceptable time limits
45
+ - Memory usage SHALL remain within reasonable bounds
46
+
47
+ ### NFR-2: Reliability
48
+ - System SHALL handle errors gracefully
49
+ - System SHALL maintain data integrity
50
+
51
+ ### NFR-3: Maintainability
52
+ - Code SHALL follow established conventions
53
+ - System SHALL be well-documented
54
+ `;
55
+ }
56
+
57
+ export async function generateDesignDocument(projectPath, featureName) {
58
+ const analysis = await analyzeProject(projectPath);
59
+ const arch = describeArchitecture(analysis);
60
+ const components = generateComponentList(analysis).map(c => `- **${c.name}**: ${c.description}`).join('\n');
61
+ const dataModels = generateDataModels(analysis).map(m => `- **${m}**: Data structure definition`).join('\n');
62
+ const techStack = generateDetailedTechStack(analysis);
63
+
64
+ return `# Technical Design Document
65
+
66
+ ## Project: ${featureName}
67
+
68
+ **Project Name:** ${analysis.name}
69
+ **Architecture:** ${analysis.architecture}
70
+ **Language:** ${analysis.language}
71
+
72
+ Generated on: ${new Date().toISOString()}
73
+
74
+ ## Architecture Overview
75
+
76
+ ### System Architecture
77
+ ${arch}
78
+
79
+ ### Key Components
80
+ ${components}
81
+
82
+ ### Data Models
83
+ ${dataModels}
84
+
85
+ ## Implementation Details
86
+
87
+ ### Technology Stack
88
+ ${techStack}
89
+
90
+ ### Dependencies
91
+ ${generateDependencySummary(analysis)}
92
+
93
+ ## Interface Specifications
94
+
95
+ ### Module Interfaces
96
+ ${generateModuleInterfaces(analysis)}
97
+
98
+ ## Configuration
99
+
100
+ ### Environment Variables
101
+ ${generateEnvVars(analysis)}
102
+
103
+ ### Build Configuration
104
+ ${generateBuildConfig(analysis)}
105
+ `;
106
+ }
107
+
108
+ export async function generateTasksDocument(projectPath, featureName) {
109
+ const analysis = await analyzeProject(projectPath);
110
+ const tasks = generateImplementationTasks(analysis);
111
+
112
+ const section = (title, list) =>
113
+ list.map((task, idx) => `- [ ] ${idx + 1}. ${task.title}
114
+ ${task.subtasks.map(s => ` - ${s}`).join('\n')}
115
+ - _Requirements: ${task.requirements}_`).join('\n\n');
116
+
117
+ return `# Implementation Plan
118
+
119
+ ## Project: ${featureName}
120
+
121
+ **Project Name:** ${analysis.name}
122
+ **Detected Stack:** ${[analysis.language, analysis.framework || '', analysis.buildTool || ''].filter(Boolean).join(' / ')}
123
+
124
+ Generated on: ${new Date().toISOString()}
125
+
126
+ ## Development Phase Tasks
127
+
128
+ ${section('Development', tasks.development)}
129
+
130
+ ## Integration Phase Tasks
131
+
132
+ ${section('Integration', tasks.integration)}
133
+
134
+ ## Quality & Testing Tasks
135
+
136
+ ${section('Quality', tasks.quality)}
137
+ `;
138
+ }
139
+
140
+ // Helper functions
141
+ function generateCoreObjective(analysis) {
142
+ if (analysis.dependencies?.includes('@modelcontextprotocol/sdk')) return 'Provide MCP tools for spec-driven development workflows';
143
+ if (analysis.framework === 'Express.js') return 'Expose REST endpoints and middleware for business logic';
144
+ if (analysis.framework === 'React') return 'Render interactive UI components with state management';
145
+ return 'Deliver feature-aligned functionality integrated with existing architecture';
146
+ }
147
+
148
+ function generateAcceptanceCriteria(analysis) {
149
+ const criteria = [
150
+ 'WHEN invoked THEN it SHALL execute without runtime errors',
151
+ 'IF input is invalid THEN it SHALL return meaningful errors',
152
+ 'WHILE under typical load IT SHALL meet performance targets'
153
+ ];
154
+ if (analysis.testFramework) criteria.push('WHERE tests exist THEY SHALL pass with adequate coverage');
155
+ if (analysis.language === 'typescript') criteria.push('WHEN type-checking THEN no TypeScript errors SHALL occur');
156
+ return criteria;
157
+ }
158
+
159
+ function generateTechRequirements(analysis) {
160
+ const out = ['Integrate with existing build and run scripts'];
161
+ if (analysis.dependencies?.includes('@modelcontextprotocol/sdk')) out.push('Expose MCP-compliant tools over stdio');
162
+ if (analysis.buildTool) out.push(`Provide build artifacts using ${analysis.buildTool}`);
163
+ return out;
164
+ }
165
+
166
+ function generateQualityRequirements(analysis) {
167
+ const out = ['Follow project coding conventions', 'Apply error handling and logging'];
168
+ if (analysis.testFramework) out.push(`Include ${analysis.testFramework} tests for new code`);
169
+ return out;
170
+ }
171
+
172
+ function describeArchitecture(analysis) {
173
+ if (analysis.architecture === 'Domain-Driven Design (DDD)') return 'Layered DDD: Domain, Application, Infrastructure, Presentation';
174
+ if (analysis.architecture.includes('API')) return 'REST API with routing, middleware, services, and data access layers';
175
+ if (analysis.framework === 'MCP SDK') return 'MCP server exposing development tools via stdio protocol';
176
+ return analysis.architecture || 'Modular architecture with clear separation of concerns';
177
+ }
178
+
179
+ function generateComponentList(analysis) {
180
+ const comps = [];
181
+ if (analysis.framework === 'MCP SDK') {
182
+ comps.push({ name: 'MCPServer', description: 'Handles stdio transport and tool registry' });
183
+ comps.push({ name: 'ToolHandlers', description: 'Implement SDD tools (init, requirements, design, tasks, etc.)' });
184
+ }
185
+ if (analysis.architecture.includes('API')) {
186
+ comps.push({ name: 'Controllers', description: 'HTTP route handlers' });
187
+ comps.push({ name: 'Services', description: 'Business logic orchestration' });
188
+ }
189
+ if (comps.length === 0) comps.push({ name: 'CoreModule', description: 'Primary feature implementation module' });
190
+ return comps;
191
+ }
192
+
193
+ function generateDataModels(analysis) {
194
+ if (analysis.framework === 'MCP SDK') return ['Tool', 'Request', 'Response'];
195
+ if (analysis.architecture.includes('API')) return ['RequestDTO', 'ResponseDTO'];
196
+ return ['Entity', 'ValueObject'];
197
+ }
198
+
199
+ function generateDetailedTechStack(analysis) {
200
+ const parts = [];
201
+ parts.push(`- Runtime: ${analysis.language === 'typescript' ? 'Node.js (TypeScript)' : 'Node.js (JavaScript)'}`);
202
+ if (analysis.framework) parts.push(`- Framework: ${analysis.framework}`);
203
+ if (analysis.buildTool) parts.push(`- Build: ${analysis.buildTool}`);
204
+ if (analysis.testFramework) parts.push(`- Testing: ${analysis.testFramework}`);
205
+ return parts.join('\n');
206
+ }
207
+
208
+ function generateDependencySummary(analysis) {
209
+ const deps = (analysis.dependencies || []).slice(0, 10).map(d => `- ${d}`).join('\n');
210
+ const dev = (analysis.devDependencies || []).slice(0, 10).map(d => `- ${d}`).join('\n');
211
+ return `#### Production\n${deps || '- (none)'}\n\n#### Development\n${dev || '- (none)'}`;
212
+ }
213
+
214
+ function generateModuleInterfaces(analysis) {
215
+ if (analysis.framework === 'MCP SDK') {
216
+ return `- registerTool(name: string, handler: (args) => Promise<unknown>)\n- connect(transport): Promise<void>`;
217
+ }
218
+ if (analysis.architecture.includes('API')) {
219
+ return `- handle(request): Response\n- service.process(input): Result`;
220
+ }
221
+ return `- execute(input): Output`;
222
+ }
223
+
224
+ function generateEnvVars(analysis) {
225
+ const envs = ['NODE_ENV', 'LOG_LEVEL'];
226
+ if (analysis.framework === 'MCP SDK') envs.push('MCP_MODE');
227
+ return envs.map(e => `- ${e}`).join('\n');
228
+ }
229
+
230
+ function generateBuildConfig(analysis) {
231
+ if (analysis.buildTool) return `Use ${analysis.buildTool} to emit production artifacts`;
232
+ return 'Use npm scripts (build/test/lint) defined in package.json';
233
+ }
234
+
235
+ function generateImplementationTasks(analysis) {
236
+ const dev = [
237
+ { title: 'Set up project scaffolding', subtasks: ['Initialize directories', 'Configure scripts'], requirements: 'FR-1' },
238
+ { title: 'Implement core feature logic', subtasks: ['Add modules', 'Wire integrations'], requirements: 'FR-1' }
239
+ ];
240
+ const integ = [
241
+ { title: 'Integrate with stack', subtasks: ['Validate build', 'Run dev server'], requirements: 'FR-2' }
242
+ ];
243
+ const quality = [
244
+ { title: 'Add tests and quality checks', subtasks: ['Unit tests', 'Lint/typecheck', 'Quality review'], requirements: 'FR-3' }
245
+ ];
246
+
247
+ if (analysis.framework === 'MCP SDK') {
248
+ dev.unshift({ title: 'Expose MCP tools', subtasks: ['Register tools', 'Handle stdio transport'], requirements: 'FR-2' });
249
+ }
250
+ if (analysis.architecture.includes('API')) {
251
+ dev.unshift({ title: 'Add HTTP endpoints', subtasks: ['Define routes', 'Implement handlers'], requirements: 'FR-1' });
252
+ }
253
+
254
+ if (analysis.testFramework) {
255
+ quality[0].subtasks.unshift(`Set up ${analysis.testFramework}`);
256
+ }
257
+ if (analysis.language === 'typescript') {
258
+ quality[0].subtasks.push('Ensure type safety (tsc)');
259
+ }
260
+
261
+ return { development: dev, integration: integ, quality };
262
+ }
263
+