@claudetools/tools 0.5.1 → 0.6.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/dist/codedna/generators/fastapi-api.d.ts +12 -0
- package/dist/codedna/generators/fastapi-api.js +55 -0
- package/dist/codedna/generators/nestjs-api.d.ts +12 -0
- package/dist/codedna/generators/nestjs-api.js +57 -0
- package/dist/codedna/generators/react-frontend.d.ts +12 -0
- package/dist/codedna/generators/react-frontend.js +59 -0
- package/dist/codedna/generators/ui-component.d.ts +14 -0
- package/dist/codedna/generators/ui-component.js +52 -0
- package/dist/codedna/generators/vue-frontend.d.ts +12 -0
- package/dist/codedna/generators/vue-frontend.js +55 -0
- package/dist/codedna/registry.js +186 -0
- package/dist/handlers/codedna-handlers.d.ts +76 -20
- package/dist/handlers/codedna-handlers.js +112 -23
- package/dist/handlers/tool-handlers.js +62 -10
- package/dist/helpers/workers.d.ts +38 -1
- package/dist/helpers/workers.js +72 -5
- package/dist/templates/claude-md.d.ts +1 -1
- package/dist/templates/claude-md.js +6 -64
- package/dist/templates/orchestrator-prompt.d.ts +30 -0
- package/dist/templates/orchestrator-prompt.js +234 -0
- package/dist/templates/worker-prompt.d.ts +46 -0
- package/dist/templates/worker-prompt.js +322 -0
- package/package.json +1 -1
|
@@ -4,12 +4,35 @@
|
|
|
4
4
|
export declare function handleGenerateApi(args: any): Promise<{
|
|
5
5
|
error: string;
|
|
6
6
|
details: string[] | undefined;
|
|
7
|
-
message?: undefined;
|
|
8
7
|
supported?: undefined;
|
|
9
8
|
success?: undefined;
|
|
10
9
|
files?: undefined;
|
|
11
10
|
metadata?: undefined;
|
|
12
11
|
tokenSavings?: undefined;
|
|
12
|
+
message?: undefined;
|
|
13
|
+
} | {
|
|
14
|
+
error: string;
|
|
15
|
+
supported: string[];
|
|
16
|
+
details?: undefined;
|
|
17
|
+
success?: undefined;
|
|
18
|
+
files?: undefined;
|
|
19
|
+
metadata?: undefined;
|
|
20
|
+
tokenSavings?: undefined;
|
|
21
|
+
message?: undefined;
|
|
22
|
+
} | {
|
|
23
|
+
success: boolean;
|
|
24
|
+
files: Record<string, string>;
|
|
25
|
+
metadata: import("../codedna/types.js").GenerationMetadata;
|
|
26
|
+
tokenSavings: {
|
|
27
|
+
traditional: number;
|
|
28
|
+
codedna: number;
|
|
29
|
+
saved: number;
|
|
30
|
+
percentSaved: string;
|
|
31
|
+
};
|
|
32
|
+
error?: undefined;
|
|
33
|
+
details?: undefined;
|
|
34
|
+
supported?: undefined;
|
|
35
|
+
message?: undefined;
|
|
13
36
|
} | {
|
|
14
37
|
error: string;
|
|
15
38
|
message: string;
|
|
@@ -19,15 +42,28 @@ export declare function handleGenerateApi(args: any): Promise<{
|
|
|
19
42
|
files?: undefined;
|
|
20
43
|
metadata?: undefined;
|
|
21
44
|
tokenSavings?: undefined;
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* Handle codedna_generate_frontend tool call
|
|
48
|
+
*/
|
|
49
|
+
export declare function handleGenerateFrontend(args: any): Promise<{
|
|
50
|
+
error: string;
|
|
51
|
+
details: string[] | undefined;
|
|
52
|
+
supported?: undefined;
|
|
53
|
+
success?: undefined;
|
|
54
|
+
files?: undefined;
|
|
55
|
+
metadata?: undefined;
|
|
56
|
+
tokenSavings?: undefined;
|
|
57
|
+
message?: undefined;
|
|
22
58
|
} | {
|
|
23
59
|
error: string;
|
|
24
60
|
supported: string[];
|
|
25
61
|
details?: undefined;
|
|
26
|
-
message?: undefined;
|
|
27
62
|
success?: undefined;
|
|
28
63
|
files?: undefined;
|
|
29
64
|
metadata?: undefined;
|
|
30
65
|
tokenSavings?: undefined;
|
|
66
|
+
message?: undefined;
|
|
31
67
|
} | {
|
|
32
68
|
success: boolean;
|
|
33
69
|
files: Record<string, string>;
|
|
@@ -40,24 +76,17 @@ export declare function handleGenerateApi(args: any): Promise<{
|
|
|
40
76
|
};
|
|
41
77
|
error?: undefined;
|
|
42
78
|
details?: undefined;
|
|
43
|
-
message?: undefined;
|
|
44
79
|
supported?: undefined;
|
|
45
|
-
}>;
|
|
46
|
-
/**
|
|
47
|
-
* Handle codedna_generate_frontend tool call
|
|
48
|
-
*/
|
|
49
|
-
export declare function handleGenerateFrontend(args: any): Promise<{
|
|
50
|
-
error: string;
|
|
51
|
-
details: string[] | undefined;
|
|
52
80
|
message?: undefined;
|
|
53
|
-
frameworks?: undefined;
|
|
54
|
-
status?: undefined;
|
|
55
81
|
} | {
|
|
56
82
|
error: string;
|
|
57
83
|
message: string;
|
|
58
|
-
frameworks: string[];
|
|
59
|
-
status: string;
|
|
60
84
|
details?: undefined;
|
|
85
|
+
supported?: undefined;
|
|
86
|
+
success?: undefined;
|
|
87
|
+
files?: undefined;
|
|
88
|
+
metadata?: undefined;
|
|
89
|
+
tokenSavings?: undefined;
|
|
61
90
|
}>;
|
|
62
91
|
/**
|
|
63
92
|
* Handle codedna_generate_component tool call
|
|
@@ -65,17 +94,44 @@ export declare function handleGenerateFrontend(args: any): Promise<{
|
|
|
65
94
|
export declare function handleGenerateComponent(args: any): Promise<{
|
|
66
95
|
error: string;
|
|
67
96
|
details: string[] | undefined;
|
|
97
|
+
supported?: undefined;
|
|
98
|
+
success?: undefined;
|
|
99
|
+
files?: undefined;
|
|
100
|
+
metadata?: undefined;
|
|
101
|
+
tokenSavings?: undefined;
|
|
102
|
+
message?: undefined;
|
|
103
|
+
} | {
|
|
104
|
+
error: string;
|
|
105
|
+
supported: string[];
|
|
106
|
+
details?: undefined;
|
|
107
|
+
success?: undefined;
|
|
108
|
+
files?: undefined;
|
|
109
|
+
metadata?: undefined;
|
|
110
|
+
tokenSavings?: undefined;
|
|
111
|
+
message?: undefined;
|
|
112
|
+
} | {
|
|
113
|
+
success: boolean;
|
|
114
|
+
files: Record<string, string>;
|
|
115
|
+
metadata: import("../codedna/types.js").GenerationMetadata;
|
|
116
|
+
tokenSavings: {
|
|
117
|
+
traditional: number;
|
|
118
|
+
codedna: number;
|
|
119
|
+
saved: number;
|
|
120
|
+
percentSaved: string;
|
|
121
|
+
};
|
|
122
|
+
error?: undefined;
|
|
123
|
+
details?: undefined;
|
|
124
|
+
supported?: undefined;
|
|
68
125
|
message?: undefined;
|
|
69
|
-
types?: undefined;
|
|
70
|
-
frameworks?: undefined;
|
|
71
|
-
status?: undefined;
|
|
72
126
|
} | {
|
|
73
127
|
error: string;
|
|
74
128
|
message: string;
|
|
75
|
-
types: string[];
|
|
76
|
-
frameworks: string[];
|
|
77
|
-
status: string;
|
|
78
129
|
details?: undefined;
|
|
130
|
+
supported?: undefined;
|
|
131
|
+
success?: undefined;
|
|
132
|
+
files?: undefined;
|
|
133
|
+
metadata?: undefined;
|
|
134
|
+
tokenSavings?: undefined;
|
|
79
135
|
}>;
|
|
80
136
|
/**
|
|
81
137
|
* Handle codedna_list_generators tool call
|
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
import { validateSpec } from '../codedna/parser.js';
|
|
9
9
|
import { TemplateRegistry } from '../codedna/registry.js';
|
|
10
10
|
import { ExpressApiGenerator } from '../codedna/generators/express-api.js';
|
|
11
|
+
import { FastAPIGenerator } from '../codedna/generators/fastapi-api.js';
|
|
12
|
+
import { NestJSGenerator } from '../codedna/generators/nestjs-api.js';
|
|
13
|
+
import { ReactFrontendGenerator } from '../codedna/generators/react-frontend.js';
|
|
14
|
+
import { VueFrontendGenerator } from '../codedna/generators/vue-frontend.js';
|
|
15
|
+
import { UIComponentGenerator } from '../codedna/generators/ui-component.js';
|
|
11
16
|
import { errorTracker } from '../helpers/error-tracking.js';
|
|
12
17
|
import { analytics } from '../helpers/usage-analytics.js';
|
|
13
18
|
// Singleton registry instance
|
|
@@ -33,16 +38,10 @@ export async function handleGenerateApi(args) {
|
|
|
33
38
|
generator = new ExpressApiGenerator(registry);
|
|
34
39
|
}
|
|
35
40
|
else if (framework === 'fastapi') {
|
|
36
|
-
|
|
37
|
-
error: 'FastAPI generator not yet implemented',
|
|
38
|
-
message: 'Currently only Express is supported. Coming soon: FastAPI, NestJS',
|
|
39
|
-
};
|
|
41
|
+
generator = new FastAPIGenerator(registry);
|
|
40
42
|
}
|
|
41
43
|
else if (framework === 'nestjs') {
|
|
42
|
-
|
|
43
|
-
error: 'NestJS generator not yet implemented',
|
|
44
|
-
message: 'Currently only Express is supported. Coming soon: FastAPI, NestJS',
|
|
45
|
-
};
|
|
44
|
+
generator = new NestJSGenerator(registry);
|
|
46
45
|
}
|
|
47
46
|
else {
|
|
48
47
|
return {
|
|
@@ -103,13 +102,58 @@ export async function handleGenerateFrontend(args) {
|
|
|
103
102
|
details: validation.errors,
|
|
104
103
|
};
|
|
105
104
|
}
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
// Select generator based on framework
|
|
106
|
+
let generator;
|
|
107
|
+
if (framework === 'nextjs' || framework === 'react') {
|
|
108
|
+
generator = new ReactFrontendGenerator(registry);
|
|
109
|
+
}
|
|
110
|
+
else if (framework === 'vue') {
|
|
111
|
+
generator = new VueFrontendGenerator(registry);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
return {
|
|
115
|
+
error: `Unsupported framework: ${framework}`,
|
|
116
|
+
supported: ['nextjs', 'react', 'vue'],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const startTime = Date.now();
|
|
121
|
+
// Generate code
|
|
122
|
+
const result = await generator.generate(validation.parsed, options);
|
|
123
|
+
const executionTime = Date.now() - startTime;
|
|
124
|
+
// Track successful generation
|
|
125
|
+
await analytics.trackGeneration({
|
|
126
|
+
operation: 'generate_frontend',
|
|
127
|
+
generator: `${framework}-frontend`,
|
|
128
|
+
framework,
|
|
129
|
+
entityName: validation.parsed.name,
|
|
130
|
+
fieldCount: validation.parsed.fields.length,
|
|
131
|
+
specLength: spec.length,
|
|
132
|
+
filesGenerated: result.metadata.filesGenerated,
|
|
133
|
+
linesOfCode: result.metadata.linesOfCode,
|
|
134
|
+
tokensSaved: result.metadata.estimatedTokensSaved,
|
|
135
|
+
options: options,
|
|
136
|
+
executionTimeMs: executionTime,
|
|
137
|
+
});
|
|
138
|
+
return {
|
|
139
|
+
success: true,
|
|
140
|
+
files: result.files,
|
|
141
|
+
metadata: result.metadata,
|
|
142
|
+
tokenSavings: {
|
|
143
|
+
traditional: result.metadata.linesOfCode * 25,
|
|
144
|
+
codedna: 150,
|
|
145
|
+
saved: result.metadata.estimatedTokensSaved,
|
|
146
|
+
percentSaved: ((result.metadata.estimatedTokensSaved / (result.metadata.linesOfCode * 25)) * 100).toFixed(1) + '%',
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
await errorTracker.trackGenerationError(framework, spec, error instanceof Error ? error : new Error(String(error)));
|
|
152
|
+
return {
|
|
153
|
+
error: 'Code generation failed',
|
|
154
|
+
message: error instanceof Error ? error.message : String(error),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
113
157
|
}
|
|
114
158
|
/**
|
|
115
159
|
* Handle codedna_generate_component tool call
|
|
@@ -124,14 +168,59 @@ export async function handleGenerateComponent(args) {
|
|
|
124
168
|
details: validation.errors,
|
|
125
169
|
};
|
|
126
170
|
}
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
171
|
+
// Validate component type
|
|
172
|
+
const validTypes = ['form', 'table', 'card', 'modal'];
|
|
173
|
+
if (!validTypes.includes(type)) {
|
|
174
|
+
return {
|
|
175
|
+
error: `Invalid component type: ${type}`,
|
|
176
|
+
supported: validTypes,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
// Validate framework
|
|
180
|
+
const validFrameworks = ['react', 'vue', 'svelte'];
|
|
181
|
+
if (!validFrameworks.includes(framework)) {
|
|
182
|
+
return {
|
|
183
|
+
error: `Invalid framework: ${framework}`,
|
|
184
|
+
supported: validFrameworks,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
const startTime = Date.now();
|
|
189
|
+
const generator = new UIComponentGenerator(registry, type, framework);
|
|
190
|
+
const result = await generator.generate(validation.parsed, options);
|
|
191
|
+
const executionTime = Date.now() - startTime;
|
|
192
|
+
await analytics.trackGeneration({
|
|
193
|
+
operation: 'generate_component',
|
|
194
|
+
generator: `${framework}-${type}`,
|
|
195
|
+
framework,
|
|
196
|
+
entityName: validation.parsed.name,
|
|
197
|
+
fieldCount: validation.parsed.fields.length,
|
|
198
|
+
specLength: spec.length,
|
|
199
|
+
filesGenerated: result.metadata.filesGenerated,
|
|
200
|
+
linesOfCode: result.metadata.linesOfCode,
|
|
201
|
+
tokensSaved: result.metadata.estimatedTokensSaved,
|
|
202
|
+
options: options,
|
|
203
|
+
executionTimeMs: executionTime,
|
|
204
|
+
});
|
|
205
|
+
return {
|
|
206
|
+
success: true,
|
|
207
|
+
files: result.files,
|
|
208
|
+
metadata: result.metadata,
|
|
209
|
+
tokenSavings: {
|
|
210
|
+
traditional: result.metadata.linesOfCode * 25,
|
|
211
|
+
codedna: 100,
|
|
212
|
+
saved: result.metadata.estimatedTokensSaved,
|
|
213
|
+
percentSaved: ((result.metadata.estimatedTokensSaved / (result.metadata.linesOfCode * 25)) * 100).toFixed(1) + '%',
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
await errorTracker.trackGenerationError(`${framework}-${type}`, spec, error instanceof Error ? error : new Error(String(error)));
|
|
219
|
+
return {
|
|
220
|
+
error: 'Component generation failed',
|
|
221
|
+
message: error instanceof Error ? error.message : String(error),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
135
224
|
}
|
|
136
225
|
/**
|
|
137
226
|
* Handle codedna_list_generators tool call
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
import { CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
5
5
|
import { mcpLogger } from '../logger.js';
|
|
6
6
|
import { getDefaultProjectId, DEFAULT_USER_ID, lastContextUsed, setLastContextUsed, API_BASE_URL } from '../helpers/config.js';
|
|
7
|
-
import { EXPERT_WORKERS, matchTaskToWorker } from '../helpers/workers.js';
|
|
7
|
+
import { EXPERT_WORKERS, matchTaskToWorker, buildWorkerPrompt } from '../helpers/workers.js';
|
|
8
|
+
import { validateTaskDescription } from '../templates/orchestrator-prompt.js';
|
|
8
9
|
import { searchMemory, addMemory, storeFact, getContext, getSummary, getEntities, injectContext, apiRequest, listCachedDocs, getCachedDocs, cacheDocs } from '../helpers/api-client.js';
|
|
9
10
|
import { queryDependencies, analyzeImpact } from '../helpers/dependencies.js';
|
|
10
11
|
import { checkPatterns } from '../helpers/patterns.js';
|
|
@@ -432,8 +433,20 @@ export function registerToolHandlers(server) {
|
|
|
432
433
|
});
|
|
433
434
|
const epic = epicResult.data;
|
|
434
435
|
const createdTasks = [];
|
|
436
|
+
// Track description validation warnings
|
|
437
|
+
const descriptionWarnings = [];
|
|
435
438
|
// Create each task under the epic with worker assignment
|
|
436
439
|
for (const taskDef of tasks) {
|
|
440
|
+
// Validate task description doesn't contain code (orchestrators should delegate, not implement)
|
|
441
|
+
if (taskDef.description) {
|
|
442
|
+
const validation = validateTaskDescription(taskDef.description);
|
|
443
|
+
if (!validation.valid) {
|
|
444
|
+
descriptionWarnings.push({
|
|
445
|
+
task: taskDef.title,
|
|
446
|
+
warnings: validation.warnings,
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
}
|
|
437
450
|
// Match task to expert worker
|
|
438
451
|
const worker = matchTaskToWorker({
|
|
439
452
|
title: taskDef.title,
|
|
@@ -541,21 +554,60 @@ export function registerToolHandlers(server) {
|
|
|
541
554
|
const worker = EXPERT_WORKERS[workerId];
|
|
542
555
|
output += `- **${worker.name}**: ${items.length} task(s)\n`;
|
|
543
556
|
}
|
|
557
|
+
// Show warnings if task descriptions contained code (orchestrator anti-pattern)
|
|
558
|
+
if (descriptionWarnings.length > 0) {
|
|
559
|
+
output += `\n## ⚠️ Task Description Warnings\n\n`;
|
|
560
|
+
output += `**Best Practice:** Task descriptions should define WHAT and WHY, not HOW.\n`;
|
|
561
|
+
output += `Orchestrators should delegate implementation details to worker agents.\n\n`;
|
|
562
|
+
for (const warning of descriptionWarnings) {
|
|
563
|
+
output += `**${warning.task}:**\n`;
|
|
564
|
+
for (const w of warning.warnings) {
|
|
565
|
+
output += ` - ${w}\n`;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
output += `\n**Tip:** For entities, use DSL format: "User(email:string:unique, password:string:hashed)"\n`;
|
|
569
|
+
output += `Workers will use CodeDNA to generate code automatically.\n`;
|
|
570
|
+
}
|
|
544
571
|
// Auto-dispatch section with exact Task tool invocations
|
|
545
572
|
output += `\n---\n\n`;
|
|
546
573
|
output += `## Auto-Dispatch: Spawn Parallel Agents Now\n\n`;
|
|
547
574
|
output += `**IMPORTANT:** Execute these Task tool calls in a SINGLE message to spawn parallel workers:\n\n`;
|
|
548
575
|
output += `\`\`\`\n`;
|
|
549
576
|
for (const dt of dispatchable) {
|
|
550
|
-
// Build a
|
|
551
|
-
const
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
577
|
+
// Build a comprehensive prompt using 10/10 template with CodeDNA instructions
|
|
578
|
+
const workerPrompt = buildWorkerPrompt({
|
|
579
|
+
task: {
|
|
580
|
+
id: dt.task.id,
|
|
581
|
+
title: dt.task.title,
|
|
582
|
+
description: dt.task.description,
|
|
583
|
+
acceptance_criteria: parseJsonArray(dt.task.acceptance_criteria),
|
|
584
|
+
},
|
|
585
|
+
worker: dt.worker,
|
|
586
|
+
epicContext: {
|
|
587
|
+
title: epic.title,
|
|
588
|
+
description: goal,
|
|
589
|
+
},
|
|
590
|
+
}, 'standard'); // Use standard tier for dispatched tasks
|
|
591
|
+
// Escape the prompt for embedding in Task() call
|
|
592
|
+
// Use a simplified version for the dispatch call that references the full context
|
|
593
|
+
const dispatchPrompt = [
|
|
594
|
+
`# Task: ${dt.task.title}`,
|
|
595
|
+
`**Task ID:** ${dt.task.id}`,
|
|
596
|
+
`**Epic:** ${epic.title}`,
|
|
597
|
+
``,
|
|
598
|
+
dt.task.description || '',
|
|
599
|
+
``,
|
|
600
|
+
`## CodeDNA Priority`,
|
|
601
|
+
`If this task involves CRUD/API operations, use codedna_generate_api FIRST.`,
|
|
602
|
+
`Look for Entity DSL in description (e.g., "User(email:string:unique)").`,
|
|
603
|
+
``,
|
|
604
|
+
`## Protocol`,
|
|
605
|
+
`1. Call task_start(task_id="${dt.task.id}")`,
|
|
606
|
+
`2. Use memory_search and codebase_find before writing code`,
|
|
607
|
+
`3. Implement requirements`,
|
|
608
|
+
`4. Call task_complete(task_id="${dt.task.id}", summary="...")`,
|
|
609
|
+
].join('\n');
|
|
610
|
+
output += `Task(subagent_type="general-purpose", prompt="${dispatchPrompt.replace(/"/g, '\\"').replace(/\n/g, '\\n')}")\n`;
|
|
559
611
|
}
|
|
560
612
|
output += `\`\`\`\n\n`;
|
|
561
613
|
output += `**Note:** All ${dispatchable.length} tasks are ready for parallel execution. `;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type WorkerPromptParams, type TaskContext, type EpicContext, type AttachedContext, type SiblingTask } from '../templates/worker-prompt.js';
|
|
1
2
|
export interface ExpertWorker {
|
|
2
3
|
id: string;
|
|
3
4
|
name: string;
|
|
@@ -6,9 +7,19 @@ export interface ExpertWorker {
|
|
|
6
7
|
capabilities: string[];
|
|
7
8
|
promptTemplate: string;
|
|
8
9
|
}
|
|
10
|
+
export type { WorkerPromptParams, TaskContext, EpicContext, AttachedContext, SiblingTask };
|
|
9
11
|
export declare const EXPERT_WORKERS: Record<string, ExpertWorker>;
|
|
10
12
|
/**
|
|
11
|
-
* Build a structured worker prompt
|
|
13
|
+
* Build a structured worker prompt using the 10/10 AI System Prompt Architecture
|
|
14
|
+
*
|
|
15
|
+
* This function uses the new template system that includes:
|
|
16
|
+
* - XML semantic boundaries for machine-parseable structure
|
|
17
|
+
* - CodeDNA integration instructions (95-99% token savings for CRUD)
|
|
18
|
+
* - Tool usage priorities (memory_search, codebase_find before writing)
|
|
19
|
+
* - Tier-based complexity (minimal/standard/professional)
|
|
20
|
+
*
|
|
21
|
+
* @param params - Task, worker, and context information
|
|
22
|
+
* @param tier - Prompt complexity tier (default: 'standard')
|
|
12
23
|
*/
|
|
13
24
|
export declare function buildWorkerPrompt(params: {
|
|
14
25
|
task: {
|
|
@@ -31,6 +42,32 @@ export declare function buildWorkerPrompt(params: {
|
|
|
31
42
|
title: string;
|
|
32
43
|
status: string;
|
|
33
44
|
}>;
|
|
45
|
+
}, tier?: 'minimal' | 'standard' | 'professional'): string;
|
|
46
|
+
/**
|
|
47
|
+
* Legacy buildWorkerPrompt for backwards compatibility
|
|
48
|
+
* @deprecated Use buildWorkerPrompt with tier parameter instead
|
|
49
|
+
*/
|
|
50
|
+
export declare function buildWorkerPromptLegacy(params: {
|
|
51
|
+
task: {
|
|
52
|
+
id: string;
|
|
53
|
+
title: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
acceptance_criteria?: string | string[];
|
|
56
|
+
};
|
|
57
|
+
worker: ExpertWorker;
|
|
58
|
+
epicContext?: {
|
|
59
|
+
title: string;
|
|
60
|
+
description?: string;
|
|
61
|
+
};
|
|
62
|
+
attachedContext?: Array<{
|
|
63
|
+
type: string;
|
|
64
|
+
content: string;
|
|
65
|
+
source?: string;
|
|
66
|
+
}>;
|
|
67
|
+
siblingTasks?: Array<{
|
|
68
|
+
title: string;
|
|
69
|
+
status: string;
|
|
70
|
+
}>;
|
|
34
71
|
}): string;
|
|
35
72
|
/**
|
|
36
73
|
* Match a task to the best expert worker based on domain patterns
|
package/dist/helpers/workers.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
// =============================================================================
|
|
2
2
|
// Expert Worker Definitions (Orchestration System)
|
|
3
3
|
// =============================================================================
|
|
4
|
+
//
|
|
5
|
+
// Updated with 10/10 AI System Prompt Architecture and CodeDNA integration.
|
|
6
|
+
// Workers now know to use CodeDNA generators before writing boilerplate code.
|
|
7
|
+
//
|
|
8
|
+
import { buildWorkerPromptWithCodeDNA, } from '../templates/worker-prompt.js';
|
|
4
9
|
export const EXPERT_WORKERS = {
|
|
5
10
|
'schema-expert': {
|
|
6
11
|
id: 'schema-expert',
|
|
@@ -14,7 +19,10 @@ export const EXPERT_WORKERS = {
|
|
|
14
19
|
- Index optimisation
|
|
15
20
|
- Data modelling decisions
|
|
16
21
|
|
|
17
|
-
|
|
22
|
+
CODEDNA: If task includes Entity DSL (e.g., "User(email:string:unique)"),
|
|
23
|
+
the API layer will be generated automatically. Focus only on SQL schema.
|
|
24
|
+
|
|
25
|
+
Focus only on schema-related changes. Do not modify application code.
|
|
18
26
|
When complete, provide a concise summary of changes made.`,
|
|
19
27
|
},
|
|
20
28
|
'api-expert': {
|
|
@@ -28,7 +36,12 @@ When complete, provide a concise summary of changes made.`,
|
|
|
28
36
|
- Request validation and parsing
|
|
29
37
|
- Response formatting
|
|
30
38
|
- Error handling for endpoints
|
|
31
|
-
|
|
39
|
+
|
|
40
|
+
CODEDNA PRIORITY: Before writing CRUD code manually, check if CodeDNA can generate it:
|
|
41
|
+
- Look for Entity DSL in task (e.g., "User(email:string:unique, password:string:hashed)")
|
|
42
|
+
- Call codedna_generate_api(spec, framework="express", options={...})
|
|
43
|
+
- This generates models, controllers, routes, validation in seconds
|
|
44
|
+
- Only write manually for complex business logic that can't be generated
|
|
32
45
|
|
|
33
46
|
Focus only on API-related changes. Do not modify schema or extraction code.
|
|
34
47
|
When complete, provide a concise summary of endpoints created or modified.`,
|
|
@@ -45,6 +58,9 @@ When complete, provide a concise summary of endpoints created or modified.`,
|
|
|
45
58
|
- MCP resources and prompts
|
|
46
59
|
- Server configuration
|
|
47
60
|
|
|
61
|
+
TOOLS: Use memory_search to find existing MCP patterns before implementing.
|
|
62
|
+
TOOLS: Use codebase_find to locate similar tool definitions.
|
|
63
|
+
|
|
48
64
|
Focus only on MCP-related changes. Follow MCP SDK patterns exactly.
|
|
49
65
|
When complete, provide a concise summary of tools added or modified.`,
|
|
50
66
|
},
|
|
@@ -60,6 +76,9 @@ When complete, provide a concise summary of tools added or modified.`,
|
|
|
60
76
|
- Fact and relationship extraction
|
|
61
77
|
- Multi-language support
|
|
62
78
|
|
|
79
|
+
TOOLS: Use codebase_context to understand file dependencies before changes.
|
|
80
|
+
TOOLS: Use memory_search for existing extraction patterns.
|
|
81
|
+
|
|
63
82
|
Focus only on extraction logic. Follow the BaseExtractor pattern.
|
|
64
83
|
When complete, provide a concise summary of extraction capabilities added.`,
|
|
65
84
|
},
|
|
@@ -75,6 +94,9 @@ When complete, provide a concise summary of extraction capabilities added.`,
|
|
|
75
94
|
- Import/export wiring
|
|
76
95
|
- Dependency management
|
|
77
96
|
|
|
97
|
+
TOOLS: Use codebase_map to understand project structure before changes.
|
|
98
|
+
TOOLS: Use codebase_context to see file dependencies.
|
|
99
|
+
|
|
78
100
|
Focus on integration without modifying core implementation logic.
|
|
79
101
|
When complete, provide a concise summary of integrations configured.`,
|
|
80
102
|
},
|
|
@@ -84,7 +106,12 @@ When complete, provide a concise summary of integrations configured.`,
|
|
|
84
106
|
description: 'Handles tasks that do not fit other expert domains',
|
|
85
107
|
domains: ['**/*'],
|
|
86
108
|
capabilities: ['general-development', 'refactoring', 'documentation', 'testing'],
|
|
87
|
-
promptTemplate: `You are a general purpose development expert.
|
|
109
|
+
promptTemplate: `You are a general purpose development expert.
|
|
110
|
+
|
|
111
|
+
CODEDNA: For CRUD/API tasks, use codedna_generate_api before writing code manually.
|
|
112
|
+
TOOLS: Use memory_search and codebase_find before implementing from scratch.
|
|
113
|
+
|
|
114
|
+
Handle this task with care:
|
|
88
115
|
- Follow existing code patterns
|
|
89
116
|
- Make minimal necessary changes
|
|
90
117
|
- Document your reasoning
|
|
@@ -93,9 +120,49 @@ When complete, provide a concise summary of work done.`,
|
|
|
93
120
|
},
|
|
94
121
|
};
|
|
95
122
|
/**
|
|
96
|
-
* Build a structured worker prompt
|
|
123
|
+
* Build a structured worker prompt using the 10/10 AI System Prompt Architecture
|
|
124
|
+
*
|
|
125
|
+
* This function uses the new template system that includes:
|
|
126
|
+
* - XML semantic boundaries for machine-parseable structure
|
|
127
|
+
* - CodeDNA integration instructions (95-99% token savings for CRUD)
|
|
128
|
+
* - Tool usage priorities (memory_search, codebase_find before writing)
|
|
129
|
+
* - Tier-based complexity (minimal/standard/professional)
|
|
130
|
+
*
|
|
131
|
+
* @param params - Task, worker, and context information
|
|
132
|
+
* @param tier - Prompt complexity tier (default: 'standard')
|
|
133
|
+
*/
|
|
134
|
+
export function buildWorkerPrompt(params, tier = 'standard') {
|
|
135
|
+
const { task, worker, epicContext, attachedContext, siblingTasks } = params;
|
|
136
|
+
// Normalize acceptance_criteria to array
|
|
137
|
+
const criteria = Array.isArray(task.acceptance_criteria)
|
|
138
|
+
? task.acceptance_criteria
|
|
139
|
+
: (task.acceptance_criteria ? [task.acceptance_criteria] : []);
|
|
140
|
+
// Normalize attached context to proper type
|
|
141
|
+
const normalizedContext = (attachedContext || []).map(ctx => ({
|
|
142
|
+
type: ctx.type,
|
|
143
|
+
content: ctx.content,
|
|
144
|
+
source: ctx.source,
|
|
145
|
+
}));
|
|
146
|
+
// Use the new 10/10 template system
|
|
147
|
+
return buildWorkerPromptWithCodeDNA({
|
|
148
|
+
task: {
|
|
149
|
+
id: task.id,
|
|
150
|
+
title: task.title,
|
|
151
|
+
description: task.description,
|
|
152
|
+
acceptance_criteria: criteria,
|
|
153
|
+
},
|
|
154
|
+
worker,
|
|
155
|
+
epicContext,
|
|
156
|
+
attachedContext: normalizedContext,
|
|
157
|
+
siblingTasks,
|
|
158
|
+
tier,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Legacy buildWorkerPrompt for backwards compatibility
|
|
163
|
+
* @deprecated Use buildWorkerPrompt with tier parameter instead
|
|
97
164
|
*/
|
|
98
|
-
export function
|
|
165
|
+
export function buildWorkerPromptLegacy(params) {
|
|
99
166
|
const { task, worker, epicContext, attachedContext, siblingTasks } = params;
|
|
100
167
|
let prompt = '';
|
|
101
168
|
// Worker domain introduction
|
|
@@ -5,7 +5,7 @@ export declare const PROJECT_SECTION_END = "<!-- CLAUDETOOLS:PROJECT:END -->";
|
|
|
5
5
|
/**
|
|
6
6
|
* Global CLAUDE.md content - added to ~/.claude/CLAUDE.md
|
|
7
7
|
*/
|
|
8
|
-
export declare const GLOBAL_TEMPLATE = "\n<!-- CLAUDETOOLS:START -->\n# ClaudeTools Memory System\n\nYou have access to a persistent memory system via the `claudetools_memory` MCP server. Use it to remember context across sessions.\n\n## Memory Tools\n\n### Searching Memory\n```\nmemory_search(query: \"authentication patterns\")\n```\nSearch for relevant facts, entities, and past context. Use this when:\n- Starting work on a feature to recall past decisions\n- Looking for patterns or conventions used before\n- Finding related code or architectural context\n\n### Storing Facts\n```\nmemory_store_fact(\n entity1: \"UserService\",\n relationship: \"USES\",\n entity2: \"bcrypt\",\n context: \"Password hashing uses bcrypt with 12 rounds\"\n)\n```\nStore important facts as relationships between entities. Use for:\n- Architectural decisions\n- Code patterns and conventions\n- Dependencies and relationships\n- User preferences learned during conversation\n\n### Context Injection\nContext is automatically injected at the start of each session based on the current project. Check `~/.claudetools/session-context.md` for project-specific context.\n\n## Task Management\n\n### Creating Work Plans with Auto-Dispatch\n```\ntask_plan(\n goal: \"Add user authentication\",\n epic_title: \"User Auth System\",\n tasks: [...]\n)\n```\nBreak down complex work into tracked tasks. **Tasks are automatically set to `ready` status.**\n\nAfter `task_plan` completes, you will receive Task tool invocations to spawn parallel agents.\n**Execute ALL Task tool calls in a SINGLE message** to enable parallel execution.\n\n### Parallel Agent Workflow\n1. User describes work needed\n2. Call `task_plan_draft` to present the plan\n3. User says \"go\" to approve\n4. Call `task_plan` - tasks created in `ready` status\n5. Execute the provided Task tool calls in ONE message\n6. Agents work in parallel, each calling `task_complete` when done\n\n### Manual Task Start (Sequential)\n```\ntask_start(task_id: \"task_xxx\")\n```\nClaim a task before working on it. Use for sequential execution.\n\n### Completing Tasks\n```\ntask_complete(task_id: \"task_xxx\", summary: \"Implemented JWT auth with refresh tokens\")\n```\nMark tasks done with a summary of work completed. **Always call this when a task is finished.**\n\n## Codebase Intelligence\n\n### Finding Code\n```\ncodebase_map() # Get overview of project structure\ncodebase_find(\"UserService\") # Find symbols/files\ncodebase_context(\"src/auth.ts\") # Get file dependencies\n```\n\n### Impact Analysis\n```\nanalyze_impact(function_name: \"validateToken\")\n```\nSee what would be affected by changing a function.\n\n## CodeDNA:
|
|
8
|
+
export declare const GLOBAL_TEMPLATE = "\n<!-- CLAUDETOOLS:START -->\n# ClaudeTools Memory System\n\nYou have access to a persistent memory system via the `claudetools_memory` MCP server. Use it to remember context across sessions.\n\n## Memory Tools\n\n### Searching Memory\n```\nmemory_search(query: \"authentication patterns\")\n```\nSearch for relevant facts, entities, and past context. Use this when:\n- Starting work on a feature to recall past decisions\n- Looking for patterns or conventions used before\n- Finding related code or architectural context\n\n### Storing Facts\n```\nmemory_store_fact(\n entity1: \"UserService\",\n relationship: \"USES\",\n entity2: \"bcrypt\",\n context: \"Password hashing uses bcrypt with 12 rounds\"\n)\n```\nStore important facts as relationships between entities. Use for:\n- Architectural decisions\n- Code patterns and conventions\n- Dependencies and relationships\n- User preferences learned during conversation\n\n### Context Injection\nContext is automatically injected at the start of each session based on the current project. Check `~/.claudetools/session-context.md` for project-specific context.\n\n## Task Management\n\n### Creating Work Plans with Auto-Dispatch\n```\ntask_plan(\n goal: \"Add user authentication\",\n epic_title: \"User Auth System\",\n tasks: [...]\n)\n```\nBreak down complex work into tracked tasks. **Tasks are automatically set to `ready` status.**\n\nAfter `task_plan` completes, you will receive Task tool invocations to spawn parallel agents.\n**Execute ALL Task tool calls in a SINGLE message** to enable parallel execution.\n\n### Parallel Agent Workflow\n1. User describes work needed\n2. Call `task_plan_draft` to present the plan\n3. User says \"go\" to approve\n4. Call `task_plan` - tasks created in `ready` status\n5. Execute the provided Task tool calls in ONE message\n6. Agents work in parallel, each calling `task_complete` when done\n\n### Manual Task Start (Sequential)\n```\ntask_start(task_id: \"task_xxx\")\n```\nClaim a task before working on it. Use for sequential execution.\n\n### Completing Tasks\n```\ntask_complete(task_id: \"task_xxx\", summary: \"Implemented JWT auth with refresh tokens\")\n```\nMark tasks done with a summary of work completed. **Always call this when a task is finished.**\n\n## Codebase Intelligence\n\n### Finding Code\n```\ncodebase_map() # Get overview of project structure\ncodebase_find(\"UserService\") # Find symbols/files\ncodebase_context(\"src/auth.ts\") # Get file dependencies\n```\n\n### Impact Analysis\n```\nanalyze_impact(function_name: \"validateToken\")\n```\nSee what would be affected by changing a function.\n\n## CodeDNA: Generate Code, Save 99% Tokens\n\n**When creating APIs/CRUD operations:** Call `codedna_generate_api` instead of writing code manually.\n\n```\ncodedna_generate_api({\n spec: \"User(email:string:unique, password:string:hashed, age:integer:min(18))\",\n framework: \"express\",\n options: { auth: true, validation: true, tests: true }\n})\n```\n\n**Generates 6 production files** (models, controllers, routes, validators, auth, tests) in ~5 seconds.\n**Saves:** 30,000 tokens \u2192 200 tokens (99% reduction)\n\n## Best Practices\n\n1. **Search before implementing** - Check memory for existing patterns\n2. **Store decisions** - Save architectural choices as facts\n3. **Use task tracking** - Break complex work into tasks\n4. **Use CodeDNA for APIs** - Generate instead of write (99% token savings)\n<!-- CLAUDETOOLS:END -->\n";
|
|
9
9
|
/**
|
|
10
10
|
* Project-level CLAUDE.md content - added to .claude/CLAUDE.md
|
|
11
11
|
*/
|