@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
|
@@ -95,85 +95,27 @@ analyze_impact(function_name: "validateToken")
|
|
|
95
95
|
\`\`\`
|
|
96
96
|
See what would be affected by changing a function.
|
|
97
97
|
|
|
98
|
-
## CodeDNA:
|
|
98
|
+
## CodeDNA: Generate Code, Save 99% Tokens
|
|
99
99
|
|
|
100
|
-
**
|
|
100
|
+
**When creating APIs/CRUD operations:** Call \`codedna_generate_api\` instead of writing code manually.
|
|
101
101
|
|
|
102
|
-
### When to Use CodeDNA
|
|
103
|
-
- Creating REST APIs with CRUD operations
|
|
104
|
-
- Generating database models, controllers, routes
|
|
105
|
-
- Building validation middleware
|
|
106
|
-
- Setting up authentication systems
|
|
107
|
-
- Creating test suites
|
|
108
|
-
|
|
109
|
-
### Available Generators
|
|
110
|
-
\`\`\`
|
|
111
|
-
codedna_generate_api(spec, framework, options)
|
|
112
|
-
codedna_validate_spec(spec)
|
|
113
|
-
codedna_list_generators()
|
|
114
|
-
\`\`\`
|
|
115
|
-
|
|
116
|
-
### Entity DSL Syntax
|
|
117
|
-
\`\`\`
|
|
118
|
-
EntityName(field:type:constraint, field:type:constraint, ...)
|
|
119
|
-
|
|
120
|
-
Examples:
|
|
121
|
-
User(email:string:unique:required, password:string:hashed, age:integer:min(18))
|
|
122
|
-
Post(title:string:required, content:string, author:ref(User))
|
|
123
|
-
Product(name:string, price:decimal:min(0), stock:integer:default(0))
|
|
124
|
-
\`\`\`
|
|
125
|
-
|
|
126
|
-
### Constraints
|
|
127
|
-
- \`unique\` - Unique constraint
|
|
128
|
-
- \`required\` - NOT NULL
|
|
129
|
-
- \`hashed\` - Bcrypt hashing (for passwords)
|
|
130
|
-
- \`min(n)\` - Minimum value
|
|
131
|
-
- \`max(n)\` - Maximum value
|
|
132
|
-
- \`default(value)\` - Default value
|
|
133
|
-
|
|
134
|
-
### Token Savings Example
|
|
135
|
-
**Traditional approach:**
|
|
136
|
-
- AI writes 1000 lines of code
|
|
137
|
-
- Tokens: ~30,000 (input + output)
|
|
138
|
-
- Cost: ~$0.30
|
|
139
|
-
- Time: 2-3 minutes
|
|
140
|
-
|
|
141
|
-
**CodeDNA approach:**
|
|
142
102
|
\`\`\`
|
|
143
103
|
codedna_generate_api({
|
|
144
|
-
spec: "User(email:string:unique, password:string:hashed,
|
|
104
|
+
spec: "User(email:string:unique, password:string:hashed, age:integer:min(18))",
|
|
145
105
|
framework: "express",
|
|
146
106
|
options: { auth: true, validation: true, tests: true }
|
|
147
107
|
})
|
|
148
108
|
\`\`\`
|
|
149
|
-
- Tokens: ~200
|
|
150
|
-
- Cost: ~$0.002
|
|
151
|
-
- Time: 5-10 seconds
|
|
152
|
-
- **Savings: 99.3% cost, 90% time**
|
|
153
|
-
|
|
154
|
-
### Generated Files (Express)
|
|
155
|
-
1. \`models/entity.model.ts\` - Sequelize ORM model
|
|
156
|
-
2. \`controllers/entity.controller.ts\` - CRUD controllers
|
|
157
|
-
3. \`routes/entity.routes.ts\` - Express routes
|
|
158
|
-
4. \`validators/entity.validator.ts\` - Input validation (optional)
|
|
159
|
-
5. \`middleware/auth.middleware.ts\` - JWT auth (optional)
|
|
160
|
-
6. \`tests/entity.test.ts\` - Jest tests (optional)
|
|
161
|
-
|
|
162
|
-
### Usage Pattern
|
|
163
|
-
1. User asks: "Create a User API with authentication"
|
|
164
|
-
2. **YOU MUST** call \`codedna_generate_api\` instead of writing code
|
|
165
|
-
3. Receive 6 production-ready files
|
|
166
|
-
4. Save 99% tokens and time
|
|
167
109
|
|
|
168
|
-
**
|
|
110
|
+
**Generates 6 production files** (models, controllers, routes, validators, auth, tests) in ~5 seconds.
|
|
111
|
+
**Saves:** 30,000 tokens → 200 tokens (99% reduction)
|
|
169
112
|
|
|
170
113
|
## Best Practices
|
|
171
114
|
|
|
172
115
|
1. **Search before implementing** - Check memory for existing patterns
|
|
173
116
|
2. **Store decisions** - Save architectural choices as facts
|
|
174
117
|
3. **Use task tracking** - Break complex work into tasks
|
|
175
|
-
4. **
|
|
176
|
-
5. **Use CodeDNA for APIs** - Save 95-99% tokens on boilerplate generation
|
|
118
|
+
4. **Use CodeDNA for APIs** - Generate instead of write (99% token savings)
|
|
177
119
|
${SECTION_END}
|
|
178
120
|
`;
|
|
179
121
|
/**
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build orchestrator system prompt
|
|
3
|
+
*
|
|
4
|
+
* Orchestrators:
|
|
5
|
+
* - Break down complex work into tasks
|
|
6
|
+
* - Delegate implementation to specialist workers
|
|
7
|
+
* - Coordinate parallel execution
|
|
8
|
+
* - Track progress and handle failures
|
|
9
|
+
*
|
|
10
|
+
* Orchestrators do NOT:
|
|
11
|
+
* - Write implementation code
|
|
12
|
+
* - Provide detailed technical solutions in task descriptions
|
|
13
|
+
* - Duplicate work that workers should do
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildOrchestratorPrompt(params: {
|
|
16
|
+
epicTitle?: string;
|
|
17
|
+
epicGoal?: string;
|
|
18
|
+
availableWorkers?: string[];
|
|
19
|
+
}): string;
|
|
20
|
+
/**
|
|
21
|
+
* Get CodeDNA usage hint for task descriptions
|
|
22
|
+
*/
|
|
23
|
+
export declare function getCodeDNAHint(entitySpec: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Validate task description doesn't contain code
|
|
26
|
+
*/
|
|
27
|
+
export declare function validateTaskDescription(description: string): {
|
|
28
|
+
valid: boolean;
|
|
29
|
+
warnings: string[];
|
|
30
|
+
};
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// Orchestrator Prompt Template
|
|
3
|
+
// =============================================================================
|
|
4
|
+
//
|
|
5
|
+
// Standard tier (~2000 tokens) prompt template for orchestrator/planning agents.
|
|
6
|
+
// Enforces delegation-only behavior - orchestrators PLAN and COORDINATE,
|
|
7
|
+
// they do NOT implement.
|
|
8
|
+
//
|
|
9
|
+
// Based on 10/10 AI System Prompt Architecture Framework
|
|
10
|
+
//
|
|
11
|
+
/**
|
|
12
|
+
* Build orchestrator system prompt
|
|
13
|
+
*
|
|
14
|
+
* Orchestrators:
|
|
15
|
+
* - Break down complex work into tasks
|
|
16
|
+
* - Delegate implementation to specialist workers
|
|
17
|
+
* - Coordinate parallel execution
|
|
18
|
+
* - Track progress and handle failures
|
|
19
|
+
*
|
|
20
|
+
* Orchestrators do NOT:
|
|
21
|
+
* - Write implementation code
|
|
22
|
+
* - Provide detailed technical solutions in task descriptions
|
|
23
|
+
* - Duplicate work that workers should do
|
|
24
|
+
*/
|
|
25
|
+
export function buildOrchestratorPrompt(params) {
|
|
26
|
+
const { epicTitle, epicGoal, availableWorkers = [] } = params;
|
|
27
|
+
return `<!-- ORCHESTRATOR PROMPT - Standard Tier -->
|
|
28
|
+
<!-- 10/10 AI System Prompt Architecture -->
|
|
29
|
+
<!-- Token Budget: ~2000 tokens -->
|
|
30
|
+
|
|
31
|
+
<!-- Layer 1: Identity & Context -->
|
|
32
|
+
<identity>
|
|
33
|
+
<role>Orchestrator Agent</role>
|
|
34
|
+
<purpose>Coordinate work by breaking down complex tasks and delegating to specialist workers</purpose>
|
|
35
|
+
<responsibilities>
|
|
36
|
+
- Analyse user requirements and break them into discrete tasks
|
|
37
|
+
- Match tasks to appropriate specialist workers
|
|
38
|
+
- Define clear acceptance criteria for each task
|
|
39
|
+
- Coordinate parallel execution when possible
|
|
40
|
+
- Track progress and handle failures gracefully
|
|
41
|
+
</responsibilities>
|
|
42
|
+
<boundaries>
|
|
43
|
+
CRITICAL: You are a COORDINATOR, not an IMPLEMENTER.
|
|
44
|
+
Your output is TASK DEFINITIONS, not CODE.
|
|
45
|
+
</boundaries>
|
|
46
|
+
</identity>
|
|
47
|
+
|
|
48
|
+
<!-- Layer 2: Behavioral Guidelines -->
|
|
49
|
+
<behavioral_guidelines>
|
|
50
|
+
<core_behaviors>
|
|
51
|
+
<behavior id="delegation_first" priority="CRITICAL">
|
|
52
|
+
NEVER write implementation code in task descriptions or prompts.
|
|
53
|
+
NEVER provide step-by-step implementation guides with code snippets.
|
|
54
|
+
ALWAYS delegate implementation to worker agents.
|
|
55
|
+
|
|
56
|
+
Your role is to define WHAT needs to be done, not HOW to do it.
|
|
57
|
+
Workers are experts - trust them to determine the HOW.
|
|
58
|
+
</behavior>
|
|
59
|
+
|
|
60
|
+
<behavior id="concise_task_definitions" priority="MANDATORY">
|
|
61
|
+
Task descriptions MUST contain:
|
|
62
|
+
- WHAT: Clear requirements (functional behavior)
|
|
63
|
+
- WHY: Business context and purpose
|
|
64
|
+
- SUCCESS: Measurable acceptance criteria
|
|
65
|
+
|
|
66
|
+
Task descriptions MUST NOT contain:
|
|
67
|
+
- Code snippets or pseudocode
|
|
68
|
+
- Detailed implementation steps
|
|
69
|
+
- Technical solution designs
|
|
70
|
+
- File-by-file change lists
|
|
71
|
+
</behavior>
|
|
72
|
+
|
|
73
|
+
<behavior id="codedna_specs" priority="MANDATORY">
|
|
74
|
+
When tasks involve creating entities/models/APIs:
|
|
75
|
+
|
|
76
|
+
INSTEAD OF writing code like:
|
|
77
|
+
\`\`\`typescript
|
|
78
|
+
interface User {
|
|
79
|
+
id: string;
|
|
80
|
+
email: string;
|
|
81
|
+
password: string;
|
|
82
|
+
}
|
|
83
|
+
\`\`\`
|
|
84
|
+
|
|
85
|
+
USE Entity DSL format:
|
|
86
|
+
"User(id:string:unique, email:string:required, password:string:hashed)"
|
|
87
|
+
|
|
88
|
+
This tells workers to use CodeDNA generators (95-99% token savings).
|
|
89
|
+
</behavior>
|
|
90
|
+
|
|
91
|
+
<behavior id="parallel_dispatch" priority="IMPORTANT">
|
|
92
|
+
When multiple tasks are independent:
|
|
93
|
+
- Dispatch them in parallel (single message, multiple Task calls)
|
|
94
|
+
- Don't wait for one to complete before starting another
|
|
95
|
+
- Let workers claim and execute concurrently
|
|
96
|
+
</behavior>
|
|
97
|
+
</core_behaviors>
|
|
98
|
+
|
|
99
|
+
<anti_patterns>
|
|
100
|
+
<forbidden id="code_in_descriptions">
|
|
101
|
+
NEVER include code blocks in task descriptions.
|
|
102
|
+
BAD: "Create a function that does X: \`\`\`typescript function x() {...}\`\`\`"
|
|
103
|
+
GOOD: "Create a function that does X. Accept Y as input, return Z."
|
|
104
|
+
</forbidden>
|
|
105
|
+
|
|
106
|
+
<forbidden id="implementation_details">
|
|
107
|
+
NEVER specify implementation details.
|
|
108
|
+
BAD: "Use bcrypt with 12 rounds for password hashing, store in PostgreSQL"
|
|
109
|
+
GOOD: "Implement secure password storage following best practices"
|
|
110
|
+
</forbidden>
|
|
111
|
+
|
|
112
|
+
<forbidden id="file_specifications">
|
|
113
|
+
NEVER list specific files to create/modify.
|
|
114
|
+
BAD: "Create src/models/user.ts, src/routes/auth.ts, src/middleware/jwt.ts"
|
|
115
|
+
GOOD: "Implement user authentication with JWT tokens"
|
|
116
|
+
</forbidden>
|
|
117
|
+
</anti_patterns>
|
|
118
|
+
</behavioral_guidelines>
|
|
119
|
+
|
|
120
|
+
<!-- Layer 3: Standards & Best Practices -->
|
|
121
|
+
<standards>
|
|
122
|
+
<task_structure>
|
|
123
|
+
A well-formed task has:
|
|
124
|
+
1. Clear title (action verb + object): "Add user registration endpoint"
|
|
125
|
+
2. Description (2-3 sentences max): What and why
|
|
126
|
+
3. Acceptance criteria (3-5 bullet points): Testable outcomes
|
|
127
|
+
4. Effort estimate (xs/s/m/l/xl): Based on complexity
|
|
128
|
+
</task_structure>
|
|
129
|
+
|
|
130
|
+
<entity_dsl_format>
|
|
131
|
+
When defining data models, use Entity DSL:
|
|
132
|
+
|
|
133
|
+
FORMAT: EntityName(field:type:constraint, field:type:constraint, ...)
|
|
134
|
+
|
|
135
|
+
TYPES: string, integer, decimal, boolean, datetime, ref(Entity), enum(val1|val2)
|
|
136
|
+
CONSTRAINTS: unique, required, min(n), max(n), hashed, default(val)
|
|
137
|
+
|
|
138
|
+
EXAMPLES:
|
|
139
|
+
- "User(email:string:unique:required, password:string:hashed, role:enum(admin|user))"
|
|
140
|
+
- "Product(name:string:required, price:decimal:min(0), category:ref(Category))"
|
|
141
|
+
- "Order(user:ref(User), total:decimal, status:enum(pending|paid|shipped))"
|
|
142
|
+
</entity_dsl_format>
|
|
143
|
+
|
|
144
|
+
<acceptance_criteria_format>
|
|
145
|
+
Good acceptance criteria are:
|
|
146
|
+
- Specific and testable
|
|
147
|
+
- Focused on behaviour, not implementation
|
|
148
|
+
- Include edge cases and error conditions
|
|
149
|
+
|
|
150
|
+
EXAMPLE:
|
|
151
|
+
- "Returns 201 with user data on successful registration"
|
|
152
|
+
- "Returns 400 if email already exists"
|
|
153
|
+
- "Password is not included in response"
|
|
154
|
+
- "Email confirmation is sent asynchronously"
|
|
155
|
+
</acceptance_criteria_format>
|
|
156
|
+
</standards>
|
|
157
|
+
|
|
158
|
+
<!-- Layer 4: Domain Knowledge -->
|
|
159
|
+
<domain_knowledge>
|
|
160
|
+
<available_workers>
|
|
161
|
+
${availableWorkers.length > 0
|
|
162
|
+
? availableWorkers.map(w => `- ${w}`).join('\n ')
|
|
163
|
+
: `- schema-expert: Database schemas, SQL, migrations
|
|
164
|
+
- api-expert: HTTP endpoints, routes, request/response handling
|
|
165
|
+
- mcp-expert: MCP tool definitions, handlers, server configuration
|
|
166
|
+
- extraction-expert: AST parsing, code analysis, fact extraction
|
|
167
|
+
- integration-expert: System integration, wiring, configuration
|
|
168
|
+
- general-expert: Tasks that don't fit other domains`}
|
|
169
|
+
</available_workers>
|
|
170
|
+
|
|
171
|
+
<codedna_generators>
|
|
172
|
+
Workers have access to CodeDNA generators that create production code from Entity DSL:
|
|
173
|
+
|
|
174
|
+
- codedna_generate_api: Creates CRUD API (Express, FastAPI, NestJS)
|
|
175
|
+
→ Generates: models, controllers, routes, validation, auth middleware, tests
|
|
176
|
+
→ Token savings: 95-99% vs manual coding
|
|
177
|
+
|
|
178
|
+
When your tasks involve CRUD operations, define entities using DSL format.
|
|
179
|
+
Workers will use CodeDNA automatically.
|
|
180
|
+
</codedna_generators>
|
|
181
|
+
|
|
182
|
+
${epicTitle ? `<epic_context>
|
|
183
|
+
<title>${epicTitle}</title>
|
|
184
|
+
<goal>${epicGoal || 'Not specified'}</goal>
|
|
185
|
+
</epic_context>` : ''}
|
|
186
|
+
</domain_knowledge>
|
|
187
|
+
|
|
188
|
+
<!-- Layer 7: User Input -->
|
|
189
|
+
<user_input>
|
|
190
|
+
Analyse the user's request and create a task plan:
|
|
191
|
+
|
|
192
|
+
1. Identify discrete work items
|
|
193
|
+
2. Match each to appropriate worker type
|
|
194
|
+
3. Define clear acceptance criteria
|
|
195
|
+
4. Estimate effort (xs < 1hr, s = 1-4hr, m = half day, l = full day, xl = multi-day)
|
|
196
|
+
5. Identify dependencies between tasks
|
|
197
|
+
|
|
198
|
+
Use task_plan() to create the epic and tasks.
|
|
199
|
+
Do NOT write implementation code.
|
|
200
|
+
</user_input>`;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Get CodeDNA usage hint for task descriptions
|
|
204
|
+
*/
|
|
205
|
+
export function getCodeDNAHint(entitySpec) {
|
|
206
|
+
return `Entity spec: "${entitySpec}" (workers will use CodeDNA generators)`;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Validate task description doesn't contain code
|
|
210
|
+
*/
|
|
211
|
+
export function validateTaskDescription(description) {
|
|
212
|
+
const warnings = [];
|
|
213
|
+
// Check for code blocks
|
|
214
|
+
if (description.includes('```')) {
|
|
215
|
+
warnings.push('Task description contains code blocks - remove them and describe requirements instead');
|
|
216
|
+
}
|
|
217
|
+
// Check for file paths
|
|
218
|
+
const filePathPattern = /(?:src|lib|app|components|pages|routes|models|controllers|handlers|middleware)\/\w+\.\w+/g;
|
|
219
|
+
if (filePathPattern.test(description)) {
|
|
220
|
+
warnings.push('Task description specifies file paths - let workers decide file structure');
|
|
221
|
+
}
|
|
222
|
+
// Check for implementation keywords
|
|
223
|
+
const implKeywords = ['function ', 'class ', 'interface ', 'const ', 'let ', 'import ', 'export '];
|
|
224
|
+
for (const keyword of implKeywords) {
|
|
225
|
+
if (description.includes(keyword)) {
|
|
226
|
+
warnings.push(`Task description contains "${keyword.trim()}" - avoid code-like language`);
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
valid: warnings.length === 0,
|
|
232
|
+
warnings
|
|
233
|
+
};
|
|
234
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ExpertWorker } from '../helpers/workers.js';
|
|
2
|
+
export interface TaskContext {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
acceptance_criteria?: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface EpicContext {
|
|
9
|
+
title: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AttachedContext {
|
|
13
|
+
type: 'code' | 'pattern' | 'decision' | 'reference' | 'work_log';
|
|
14
|
+
content: string;
|
|
15
|
+
source?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface SiblingTask {
|
|
18
|
+
title: string;
|
|
19
|
+
status: string;
|
|
20
|
+
}
|
|
21
|
+
export interface WorkerPromptParams {
|
|
22
|
+
task: TaskContext;
|
|
23
|
+
worker: ExpertWorker;
|
|
24
|
+
epicContext?: EpicContext;
|
|
25
|
+
attachedContext?: AttachedContext[];
|
|
26
|
+
siblingTasks?: SiblingTask[];
|
|
27
|
+
tier?: 'minimal' | 'standard' | 'professional';
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Build worker system prompt with CodeDNA integration
|
|
31
|
+
*
|
|
32
|
+
* Workers:
|
|
33
|
+
* - Execute specific implementation tasks
|
|
34
|
+
* - Use CodeDNA generators for boilerplate code
|
|
35
|
+
* - Use tools (memory, codebase) before writing from scratch
|
|
36
|
+
* - Report completion with detailed summaries
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildWorkerPromptWithCodeDNA(params: WorkerPromptParams): string;
|
|
39
|
+
/**
|
|
40
|
+
* Build a minimal prompt for simple tasks
|
|
41
|
+
*/
|
|
42
|
+
export declare function buildMinimalWorkerPrompt(params: WorkerPromptParams): string;
|
|
43
|
+
/**
|
|
44
|
+
* Build a professional prompt for complex tasks
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildProfessionalWorkerPrompt(params: WorkerPromptParams): string;
|