@claudetools/tools 0.3.9 → 0.5.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/README.md +60 -4
- package/dist/cli.js +0 -0
- package/dist/codedna/generators/base.d.ts +41 -0
- package/dist/codedna/generators/base.js +102 -0
- package/dist/codedna/generators/express-api.d.ts +12 -0
- package/dist/codedna/generators/express-api.js +61 -0
- package/dist/codedna/index.d.ts +4 -0
- package/dist/codedna/index.js +7 -0
- package/dist/codedna/parser.d.ts +117 -0
- package/dist/codedna/parser.js +233 -0
- package/dist/codedna/registry.d.ts +60 -0
- package/dist/codedna/registry.js +217 -0
- package/dist/codedna/template-engine.d.ts +17 -0
- package/dist/codedna/template-engine.js +183 -0
- package/dist/codedna/types.d.ts +64 -0
- package/dist/codedna/types.js +4 -0
- package/dist/handlers/codedna-handlers.d.ts +122 -0
- package/dist/handlers/codedna-handlers.js +194 -0
- package/dist/handlers/tool-handlers.js +593 -14
- package/dist/helpers/api-client.d.ts +37 -0
- package/dist/helpers/api-client.js +70 -0
- package/dist/helpers/codedna-monitoring.d.ts +34 -0
- package/dist/helpers/codedna-monitoring.js +159 -0
- package/dist/helpers/error-tracking.d.ts +73 -0
- package/dist/helpers/error-tracking.js +164 -0
- package/dist/helpers/library-detection.d.ts +26 -0
- package/dist/helpers/library-detection.js +145 -0
- package/dist/helpers/tasks-retry.d.ts +49 -0
- package/dist/helpers/tasks-retry.js +168 -0
- package/dist/helpers/tasks.d.ts +24 -1
- package/dist/helpers/tasks.js +146 -50
- package/dist/helpers/usage-analytics.d.ts +91 -0
- package/dist/helpers/usage-analytics.js +256 -0
- package/dist/helpers/workers.d.ts +25 -0
- package/dist/helpers/workers.js +80 -0
- package/dist/templates/claude-md.d.ts +1 -1
- package/dist/templates/claude-md.js +16 -5
- package/dist/tools.js +314 -0
- package/docs/AUTO-REGISTRATION.md +353 -0
- package/docs/CLAUDE4_PROMPT_ANALYSIS.md +589 -0
- package/docs/ENTITY_DSL_REFERENCE.md +685 -0
- package/docs/MODERN_STACK_COMPLETE_GUIDE.md +706 -0
- package/docs/PROMPT_STANDARDIZATION_RESULTS.md +324 -0
- package/docs/PROMPT_TIER_TEMPLATES.md +787 -0
- package/docs/RESEARCH_METHODOLOGY_EXTRACTION.md +336 -0
- package/package.json +14 -3
- package/scripts/verify-prompt-compliance.sh +197 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// CodeDNA MCP Tool Handlers
|
|
3
|
+
// =============================================================================
|
|
4
|
+
//
|
|
5
|
+
// Handlers for code generation tools that save 95-99% tokens by generating
|
|
6
|
+
// production code from compact Entity DSL specifications.
|
|
7
|
+
//
|
|
8
|
+
import { validateSpec } from '../codedna/parser.js';
|
|
9
|
+
import { TemplateRegistry } from '../codedna/registry.js';
|
|
10
|
+
import { ExpressApiGenerator } from '../codedna/generators/express-api.js';
|
|
11
|
+
import { errorTracker } from '../helpers/error-tracking.js';
|
|
12
|
+
import { analytics } from '../helpers/usage-analytics.js';
|
|
13
|
+
// Singleton registry instance
|
|
14
|
+
const registry = new TemplateRegistry();
|
|
15
|
+
/**
|
|
16
|
+
* Handle codedna_generate_api tool call
|
|
17
|
+
*/
|
|
18
|
+
export async function handleGenerateApi(args) {
|
|
19
|
+
const { spec, framework, options = {} } = args;
|
|
20
|
+
// Validate Entity DSL specification
|
|
21
|
+
const validation = validateSpec(spec);
|
|
22
|
+
if (!validation.valid) {
|
|
23
|
+
// Track validation error
|
|
24
|
+
await errorTracker.trackValidationError(spec, validation.errors || []);
|
|
25
|
+
return {
|
|
26
|
+
error: 'Invalid entity specification',
|
|
27
|
+
details: validation.errors,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
// Select generator based on framework
|
|
31
|
+
let generator;
|
|
32
|
+
if (framework === 'express') {
|
|
33
|
+
generator = new ExpressApiGenerator(registry);
|
|
34
|
+
}
|
|
35
|
+
else if (framework === 'fastapi') {
|
|
36
|
+
return {
|
|
37
|
+
error: 'FastAPI generator not yet implemented',
|
|
38
|
+
message: 'Currently only Express is supported. Coming soon: FastAPI, NestJS',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
else if (framework === 'nestjs') {
|
|
42
|
+
return {
|
|
43
|
+
error: 'NestJS generator not yet implemented',
|
|
44
|
+
message: 'Currently only Express is supported. Coming soon: FastAPI, NestJS',
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return {
|
|
49
|
+
error: `Unsupported framework: ${framework}`,
|
|
50
|
+
supported: ['express', 'fastapi', 'nestjs'],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const startTime = Date.now();
|
|
55
|
+
// Generate code
|
|
56
|
+
const result = await generator.generate(validation.parsed, options);
|
|
57
|
+
const executionTime = Date.now() - startTime;
|
|
58
|
+
// Track successful generation
|
|
59
|
+
await analytics.trackGeneration({
|
|
60
|
+
operation: 'generate_api',
|
|
61
|
+
generator: `${framework}-api`,
|
|
62
|
+
framework,
|
|
63
|
+
entityName: validation.parsed.name,
|
|
64
|
+
fieldCount: validation.parsed.fields.length,
|
|
65
|
+
specLength: spec.length,
|
|
66
|
+
filesGenerated: result.metadata.filesGenerated,
|
|
67
|
+
linesOfCode: result.metadata.linesOfCode,
|
|
68
|
+
tokensSaved: result.metadata.estimatedTokensSaved,
|
|
69
|
+
options: options,
|
|
70
|
+
executionTimeMs: executionTime,
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
success: true,
|
|
74
|
+
files: result.files,
|
|
75
|
+
metadata: result.metadata,
|
|
76
|
+
tokenSavings: {
|
|
77
|
+
traditional: result.metadata.linesOfCode * 25, // ~25 tokens per line
|
|
78
|
+
codedna: 150, // ~150 tokens for MCP call
|
|
79
|
+
saved: result.metadata.estimatedTokensSaved,
|
|
80
|
+
percentSaved: ((result.metadata.estimatedTokensSaved / (result.metadata.linesOfCode * 25)) * 100).toFixed(1) + '%',
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
// Track generation error
|
|
86
|
+
await errorTracker.trackGenerationError(framework, spec, error instanceof Error ? error : new Error(String(error)));
|
|
87
|
+
return {
|
|
88
|
+
error: 'Code generation failed',
|
|
89
|
+
message: error instanceof Error ? error.message : String(error),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Handle codedna_generate_frontend tool call
|
|
95
|
+
*/
|
|
96
|
+
export async function handleGenerateFrontend(args) {
|
|
97
|
+
const { spec, framework, options = {} } = args;
|
|
98
|
+
// Validate Entity DSL specification
|
|
99
|
+
const validation = validateSpec(spec);
|
|
100
|
+
if (!validation.valid) {
|
|
101
|
+
return {
|
|
102
|
+
error: 'Invalid entity specification',
|
|
103
|
+
details: validation.errors,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
// Frontend generators not yet implemented
|
|
107
|
+
return {
|
|
108
|
+
error: 'Frontend generators not yet implemented',
|
|
109
|
+
message: 'Coming soon: Next.js, React, Vue frontend generation',
|
|
110
|
+
frameworks: ['nextjs', 'react', 'vue'],
|
|
111
|
+
status: 'planned',
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Handle codedna_generate_component tool call
|
|
116
|
+
*/
|
|
117
|
+
export async function handleGenerateComponent(args) {
|
|
118
|
+
const { spec, type, framework, options = {} } = args;
|
|
119
|
+
// Validate Entity DSL specification
|
|
120
|
+
const validation = validateSpec(spec);
|
|
121
|
+
if (!validation.valid) {
|
|
122
|
+
return {
|
|
123
|
+
error: 'Invalid entity specification',
|
|
124
|
+
details: validation.errors,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
// Component generators not yet implemented
|
|
128
|
+
return {
|
|
129
|
+
error: 'Component generators not yet implemented',
|
|
130
|
+
message: 'Coming soon: Form, Table, Card, Modal components',
|
|
131
|
+
types: ['form', 'table', 'card', 'modal'],
|
|
132
|
+
frameworks: ['react', 'vue', 'svelte'],
|
|
133
|
+
status: 'planned',
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Handle codedna_list_generators tool call
|
|
138
|
+
*/
|
|
139
|
+
export async function handleListGenerators() {
|
|
140
|
+
try {
|
|
141
|
+
const generators = await registry.listGenerators();
|
|
142
|
+
return {
|
|
143
|
+
generators,
|
|
144
|
+
summary: {
|
|
145
|
+
total: generators.length,
|
|
146
|
+
byFramework: generators.reduce((acc, gen) => {
|
|
147
|
+
acc[gen.framework] = (acc[gen.framework] || 0) + 1;
|
|
148
|
+
return acc;
|
|
149
|
+
}, {}),
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
// Track network error for registry access
|
|
155
|
+
await errorTracker.trackNetworkError('list_generators', error instanceof Error ? error : new Error(String(error)));
|
|
156
|
+
return {
|
|
157
|
+
error: 'Failed to list generators',
|
|
158
|
+
message: error instanceof Error ? error.message : String(error),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Handle codedna_validate_spec tool call
|
|
164
|
+
*/
|
|
165
|
+
export async function handleValidateSpec(args) {
|
|
166
|
+
const { spec } = args;
|
|
167
|
+
const validation = validateSpec(spec);
|
|
168
|
+
// Track validation
|
|
169
|
+
if (validation.valid && validation.parsed) {
|
|
170
|
+
await analytics.trackValidation(spec, true, validation.parsed.name, validation.parsed.fields.length);
|
|
171
|
+
return {
|
|
172
|
+
valid: true,
|
|
173
|
+
entity: {
|
|
174
|
+
name: validation.parsed.name,
|
|
175
|
+
fields: validation.parsed.fields.map(f => ({
|
|
176
|
+
name: f.name,
|
|
177
|
+
type: f.type,
|
|
178
|
+
constraints: f.constraints.map(c => c.kind),
|
|
179
|
+
})),
|
|
180
|
+
},
|
|
181
|
+
summary: {
|
|
182
|
+
totalFields: validation.parsed.fields.length,
|
|
183
|
+
hasReferences: validation.parsed.fields.some(f => f.type.kind === 'reference'),
|
|
184
|
+
hasEnums: validation.parsed.fields.some(f => f.type.kind === 'enum'),
|
|
185
|
+
hasConstraints: validation.parsed.fields.some(f => f.constraints.length > 0),
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
await analytics.trackValidation(spec, false);
|
|
190
|
+
return {
|
|
191
|
+
valid: false,
|
|
192
|
+
errors: validation.errors,
|
|
193
|
+
};
|
|
194
|
+
}
|