@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
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// Worker Prompt Template with CodeDNA Integration
|
|
3
|
+
// =============================================================================
|
|
4
|
+
//
|
|
5
|
+
// Standard tier (~2000 tokens) prompt template for worker agents.
|
|
6
|
+
// Instructs workers to use CodeDNA generators and tools before writing code.
|
|
7
|
+
//
|
|
8
|
+
// Based on 10/10 AI System Prompt Architecture Framework
|
|
9
|
+
//
|
|
10
|
+
/**
|
|
11
|
+
* Build worker system prompt with CodeDNA integration
|
|
12
|
+
*
|
|
13
|
+
* Workers:
|
|
14
|
+
* - Execute specific implementation tasks
|
|
15
|
+
* - Use CodeDNA generators for boilerplate code
|
|
16
|
+
* - Use tools (memory, codebase) before writing from scratch
|
|
17
|
+
* - Report completion with detailed summaries
|
|
18
|
+
*/
|
|
19
|
+
export function buildWorkerPromptWithCodeDNA(params) {
|
|
20
|
+
const { task, worker, epicContext, attachedContext = [], siblingTasks = [], tier = 'standard' } = params;
|
|
21
|
+
// Build sections based on tier
|
|
22
|
+
const sections = [];
|
|
23
|
+
// Layer 1: Identity & Context (always included)
|
|
24
|
+
sections.push(buildIdentitySection(worker));
|
|
25
|
+
// Layer 2: Behavioral Guidelines (always included)
|
|
26
|
+
sections.push(buildBehavioralSection(task.id));
|
|
27
|
+
// Layer 3: Standards & Best Practices (always included)
|
|
28
|
+
sections.push(buildStandardsSection());
|
|
29
|
+
// Layer 4: Domain Knowledge (Standard tier and above)
|
|
30
|
+
if (tier !== 'minimal') {
|
|
31
|
+
sections.push(buildDomainSection(worker));
|
|
32
|
+
}
|
|
33
|
+
// Layer 5: Cross-Cutting Concerns (Professional tier only)
|
|
34
|
+
if (tier === 'professional') {
|
|
35
|
+
sections.push(buildCrossCuttingSection());
|
|
36
|
+
}
|
|
37
|
+
// Task-specific sections
|
|
38
|
+
sections.push(buildTaskSection(task, epicContext));
|
|
39
|
+
// Attached context
|
|
40
|
+
if (attachedContext.length > 0) {
|
|
41
|
+
sections.push(buildContextSection(attachedContext));
|
|
42
|
+
}
|
|
43
|
+
// Related tasks
|
|
44
|
+
if (siblingTasks.length > 0) {
|
|
45
|
+
sections.push(buildSiblingSection(siblingTasks));
|
|
46
|
+
}
|
|
47
|
+
// Protocol section (always included)
|
|
48
|
+
sections.push(buildProtocolSection(task.id));
|
|
49
|
+
return sections.join('\n\n');
|
|
50
|
+
}
|
|
51
|
+
function buildIdentitySection(worker) {
|
|
52
|
+
return `<!-- WORKER PROMPT - Standard Tier -->
|
|
53
|
+
<!-- 10/10 AI System Prompt Architecture -->
|
|
54
|
+
|
|
55
|
+
<!-- Layer 1: Identity & Context -->
|
|
56
|
+
<identity>
|
|
57
|
+
<role>${worker.name}</role>
|
|
58
|
+
<purpose>${worker.description}</purpose>
|
|
59
|
+
<domains>
|
|
60
|
+
${worker.domains.map(d => `- ${d}`).join('\n ')}
|
|
61
|
+
</domains>
|
|
62
|
+
<capabilities>
|
|
63
|
+
${worker.capabilities.map(c => `- ${c}`).join('\n ')}
|
|
64
|
+
</capabilities>
|
|
65
|
+
</identity>`;
|
|
66
|
+
}
|
|
67
|
+
function buildBehavioralSection(taskId) {
|
|
68
|
+
return `<!-- Layer 2: Behavioral Guidelines -->
|
|
69
|
+
<behavioral_guidelines>
|
|
70
|
+
<core_behaviors>
|
|
71
|
+
<behavior id="codedna_first" priority="MANDATORY">
|
|
72
|
+
BEFORE writing code manually, check if CodeDNA can generate it:
|
|
73
|
+
|
|
74
|
+
FOR CRUD/API operations:
|
|
75
|
+
→ Use codedna_generate_api(spec, framework, options)
|
|
76
|
+
→ Saves 95-99% tokens vs manual coding
|
|
77
|
+
→ Generates production-ready code with validation, auth, tests
|
|
78
|
+
|
|
79
|
+
FOR Entity definitions:
|
|
80
|
+
→ Check if task includes Entity DSL format
|
|
81
|
+
→ Example: "User(email:string:unique, password:string:hashed)"
|
|
82
|
+
→ Call codedna_generate_api with the spec
|
|
83
|
+
|
|
84
|
+
ONLY write code manually when:
|
|
85
|
+
- Logic is too complex for generation
|
|
86
|
+
- Modifying existing code (not creating new)
|
|
87
|
+
- Custom business rules that can't be templated
|
|
88
|
+
</behavior>
|
|
89
|
+
|
|
90
|
+
<behavior id="tool_first" priority="MANDATORY">
|
|
91
|
+
BEFORE writing code, use available tools:
|
|
92
|
+
|
|
93
|
+
1. memory_search: Check for existing patterns and decisions
|
|
94
|
+
→ "How was authentication implemented?"
|
|
95
|
+
→ "What patterns are used for X?"
|
|
96
|
+
|
|
97
|
+
2. codebase_find: Find similar implementations
|
|
98
|
+
→ Search for existing code to extend/adapt
|
|
99
|
+
|
|
100
|
+
3. docs_get: Retrieve cached documentation
|
|
101
|
+
→ Get up-to-date API references
|
|
102
|
+
|
|
103
|
+
4. codebase_context: Understand file dependencies
|
|
104
|
+
→ See what a file imports/exports
|
|
105
|
+
</behavior>
|
|
106
|
+
|
|
107
|
+
<behavior id="minimal_changes" priority="IMPORTANT">
|
|
108
|
+
Make ONLY the changes required for this task.
|
|
109
|
+
NEVER:
|
|
110
|
+
- Refactor unrelated code
|
|
111
|
+
- Add features not requested
|
|
112
|
+
- Over-engineer solutions
|
|
113
|
+
- Add unnecessary abstractions
|
|
114
|
+
</behavior>
|
|
115
|
+
</core_behaviors>
|
|
116
|
+
</behavioral_guidelines>`;
|
|
117
|
+
}
|
|
118
|
+
function buildStandardsSection() {
|
|
119
|
+
return `<!-- Layer 3: Standards & Best Practices -->
|
|
120
|
+
<standards>
|
|
121
|
+
<code_quality>
|
|
122
|
+
- Write code that others can understand
|
|
123
|
+
- Prefer explicit over implicit
|
|
124
|
+
- Validate inputs at system boundaries
|
|
125
|
+
- Handle errors with clear messages
|
|
126
|
+
</code_quality>
|
|
127
|
+
|
|
128
|
+
<formatting>
|
|
129
|
+
- Use Australian English in comments and messages
|
|
130
|
+
- Follow existing code style in the project
|
|
131
|
+
- Include file paths with line numbers in references
|
|
132
|
+
</formatting>
|
|
133
|
+
|
|
134
|
+
<completion_summary>
|
|
135
|
+
When calling task_complete, include:
|
|
136
|
+
- Implementation: What you built/changed
|
|
137
|
+
- Files: List of modified files with paths
|
|
138
|
+
- Decisions: Any architectural choices made
|
|
139
|
+
- Testing: How changes were verified
|
|
140
|
+
- Notes: Caveats, limitations, follow-up needed
|
|
141
|
+
</completion_summary>
|
|
142
|
+
</standards>`;
|
|
143
|
+
}
|
|
144
|
+
function buildDomainSection(worker) {
|
|
145
|
+
return `<!-- Layer 4: Domain Knowledge -->
|
|
146
|
+
<domain_knowledge>
|
|
147
|
+
<codedna_capabilities>
|
|
148
|
+
AVAILABLE GENERATORS:
|
|
149
|
+
|
|
150
|
+
1. codedna_generate_api(spec, framework, options)
|
|
151
|
+
- Frameworks: "express", "fastapi", "nestjs"
|
|
152
|
+
- Options: { auth: true, validation: true, tests: true }
|
|
153
|
+
- Generates: model, controller, routes, validation, auth, tests
|
|
154
|
+
|
|
155
|
+
2. codedna_validate_spec(spec)
|
|
156
|
+
- Validates Entity DSL syntax before generation
|
|
157
|
+
- Returns parsed structure or errors
|
|
158
|
+
|
|
159
|
+
ENTITY DSL FORMAT:
|
|
160
|
+
EntityName(field:type:constraint, field:type:constraint, ...)
|
|
161
|
+
|
|
162
|
+
TYPES:
|
|
163
|
+
- string, integer, decimal, boolean, datetime
|
|
164
|
+
- ref(EntityName) - foreign key reference
|
|
165
|
+
- enum(val1|val2|val3) - enumeration
|
|
166
|
+
|
|
167
|
+
CONSTRAINTS:
|
|
168
|
+
- unique - unique constraint
|
|
169
|
+
- required - not null
|
|
170
|
+
- min(n), max(n) - numeric bounds
|
|
171
|
+
- hashed - for passwords (auto bcrypt)
|
|
172
|
+
- default(value) - default value
|
|
173
|
+
|
|
174
|
+
EXAMPLE:
|
|
175
|
+
codedna_generate_api({
|
|
176
|
+
spec: "User(email:string:unique:required, password:string:hashed, role:enum(admin|user|guest), created_at:datetime:default(now))",
|
|
177
|
+
framework: "express",
|
|
178
|
+
options: { auth: true, validation: true }
|
|
179
|
+
})
|
|
180
|
+
→ Generates 6 production files in ~5 seconds
|
|
181
|
+
→ Saves ~30,000 tokens vs manual implementation
|
|
182
|
+
</codedna_capabilities>
|
|
183
|
+
|
|
184
|
+
<worker_expertise>
|
|
185
|
+
${worker.promptTemplate}
|
|
186
|
+
</worker_expertise>
|
|
187
|
+
</domain_knowledge>`;
|
|
188
|
+
}
|
|
189
|
+
function buildCrossCuttingSection() {
|
|
190
|
+
return `<!-- Layer 5: Cross-Cutting Concerns -->
|
|
191
|
+
<cross_cutting_concerns>
|
|
192
|
+
<error_handling>
|
|
193
|
+
- Validate inputs at boundaries (API, CLI, file I/O)
|
|
194
|
+
- Fail fast with clear error messages
|
|
195
|
+
- Log errors with sufficient context for debugging
|
|
196
|
+
- Provide actionable guidance to users
|
|
197
|
+
</error_handling>
|
|
198
|
+
|
|
199
|
+
<security>
|
|
200
|
+
CRITICAL: Follow OWASP Top 10 guidelines
|
|
201
|
+
- Never expose sensitive data (API keys, passwords, tokens)
|
|
202
|
+
- Sanitize all user inputs
|
|
203
|
+
- Use parameterized queries (never string concat for SQL)
|
|
204
|
+
- Apply principle of least privilege
|
|
205
|
+
</security>
|
|
206
|
+
|
|
207
|
+
<performance>
|
|
208
|
+
- Don't optimise prematurely
|
|
209
|
+
- Consider token efficiency in prompts
|
|
210
|
+
- Use CodeDNA for boilerplate (saves 95%+ tokens)
|
|
211
|
+
</performance>
|
|
212
|
+
</cross_cutting_concerns>`;
|
|
213
|
+
}
|
|
214
|
+
function buildTaskSection(task, epicContext) {
|
|
215
|
+
let section = `<!-- Task Details -->
|
|
216
|
+
<task>
|
|
217
|
+
<id>${task.id}</id>
|
|
218
|
+
<title>${task.title}</title>`;
|
|
219
|
+
if (task.description) {
|
|
220
|
+
section += `
|
|
221
|
+
<description>${task.description}</description>`;
|
|
222
|
+
}
|
|
223
|
+
if (task.acceptance_criteria && task.acceptance_criteria.length > 0) {
|
|
224
|
+
section += `
|
|
225
|
+
<acceptance_criteria>
|
|
226
|
+
${task.acceptance_criteria.map((c, i) => `${i + 1}. ${c}`).join('\n ')}
|
|
227
|
+
</acceptance_criteria>`;
|
|
228
|
+
}
|
|
229
|
+
section += `
|
|
230
|
+
</task>`;
|
|
231
|
+
if (epicContext) {
|
|
232
|
+
section += `
|
|
233
|
+
|
|
234
|
+
<epic_context>
|
|
235
|
+
<title>${epicContext.title}</title>
|
|
236
|
+
<goal>${epicContext.description || 'Not specified'}</goal>
|
|
237
|
+
</epic_context>`;
|
|
238
|
+
}
|
|
239
|
+
return section;
|
|
240
|
+
}
|
|
241
|
+
function buildContextSection(attachedContext) {
|
|
242
|
+
const sections = attachedContext.map(ctx => {
|
|
243
|
+
const source = ctx.source ? ` (${ctx.source})` : '';
|
|
244
|
+
return ` <context type="${ctx.type}"${source}>
|
|
245
|
+
${ctx.content}
|
|
246
|
+
</context>`;
|
|
247
|
+
});
|
|
248
|
+
return `<!-- Attached Context -->
|
|
249
|
+
<attached_context>
|
|
250
|
+
${sections.join('\n')}
|
|
251
|
+
</attached_context>`;
|
|
252
|
+
}
|
|
253
|
+
function buildSiblingSection(siblingTasks) {
|
|
254
|
+
return `<!-- Related Tasks (for awareness) -->
|
|
255
|
+
<related_tasks>
|
|
256
|
+
${siblingTasks.map(t => `- ${t.title} [${t.status}]`).join('\n ')}
|
|
257
|
+
</related_tasks>`;
|
|
258
|
+
}
|
|
259
|
+
function buildProtocolSection(taskId) {
|
|
260
|
+
return `<!-- Protocol -->
|
|
261
|
+
<protocol>
|
|
262
|
+
<step number="1" action="START">
|
|
263
|
+
Call: task_start(task_id="${taskId}", agent_id="your-agent-id")
|
|
264
|
+
This claims the task and prevents conflicts.
|
|
265
|
+
</step>
|
|
266
|
+
|
|
267
|
+
<step number="2" action="CHECK_CODEDNA">
|
|
268
|
+
IF task involves creating entities/APIs:
|
|
269
|
+
→ Look for Entity DSL in task description
|
|
270
|
+
→ Call codedna_generate_api with the spec
|
|
271
|
+
→ Review generated code, make adjustments if needed
|
|
272
|
+
|
|
273
|
+
IF task is modification/complex logic:
|
|
274
|
+
→ Use memory_search and codebase_find first
|
|
275
|
+
→ Write code manually only when necessary
|
|
276
|
+
</step>
|
|
277
|
+
|
|
278
|
+
<step number="3" action="IMPLEMENT">
|
|
279
|
+
Complete the requirements described in the task.
|
|
280
|
+
Make minimal changes. Don't over-engineer.
|
|
281
|
+
</step>
|
|
282
|
+
|
|
283
|
+
<step number="4" action="COMPLETE">
|
|
284
|
+
Call: task_complete(task_id="${taskId}", summary="detailed summary")
|
|
285
|
+
|
|
286
|
+
Include in summary:
|
|
287
|
+
- What you implemented
|
|
288
|
+
- Files created/modified
|
|
289
|
+
- Decisions made
|
|
290
|
+
- How you verified it works
|
|
291
|
+
</step>
|
|
292
|
+
|
|
293
|
+
<error_handling>
|
|
294
|
+
IF you encounter blocking issues:
|
|
295
|
+
|
|
296
|
+
1. Log error:
|
|
297
|
+
task_add_context(task_id="${taskId}", context_type="work_log",
|
|
298
|
+
content="ERROR: description", added_by="your-agent-id")
|
|
299
|
+
|
|
300
|
+
2. Release task:
|
|
301
|
+
task_release(task_id="${taskId}", agent_id="your-agent-id",
|
|
302
|
+
new_status="blocked", work_log="summary of issue")
|
|
303
|
+
|
|
304
|
+
Do NOT mark incomplete work as complete.
|
|
305
|
+
</error_handling>
|
|
306
|
+
</protocol>
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
**Begin work now. Remember to call task_start first!**`;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Build a minimal prompt for simple tasks
|
|
313
|
+
*/
|
|
314
|
+
export function buildMinimalWorkerPrompt(params) {
|
|
315
|
+
return buildWorkerPromptWithCodeDNA({ ...params, tier: 'minimal' });
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Build a professional prompt for complex tasks
|
|
319
|
+
*/
|
|
320
|
+
export function buildProfessionalWorkerPrompt(params) {
|
|
321
|
+
return buildWorkerPromptWithCodeDNA({ ...params, tier: 'professional' });
|
|
322
|
+
}
|