@claudetools/tools 0.9.0 → 0.9.2

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.
Files changed (85) hide show
  1. package/dist/cli.js +9 -1
  2. package/dist/codedna/__tests__/examples/mongoose-example.d.ts +6 -0
  3. package/dist/codedna/__tests__/examples/mongoose-example.js +163 -0
  4. package/dist/codedna/__tests__/fixtures/typeorm-production-test.d.ts +1 -0
  5. package/dist/codedna/__tests__/fixtures/typeorm-production-test.js +231 -0
  6. package/dist/codedna/__tests__/fixtures/typeorm-test.d.ts +1 -0
  7. package/dist/codedna/__tests__/fixtures/typeorm-test.js +124 -0
  8. package/dist/codedna/__tests__/laravel-output-review.d.ts +1 -0
  9. package/dist/codedna/__tests__/laravel-output-review.js +249 -0
  10. package/dist/codedna/__tests__/mongoose-output-test.d.ts +1 -0
  11. package/dist/codedna/__tests__/mongoose-output-test.js +178 -0
  12. package/dist/codedna/examples/radix-example.d.ts +2 -0
  13. package/dist/codedna/examples/radix-example.js +259 -0
  14. package/dist/codedna/index.d.ts +5 -3
  15. package/dist/codedna/index.js +6 -3
  16. package/dist/codedna/kappa-ast.d.ts +143 -5
  17. package/dist/codedna/kappa-drizzle-generator.js +8 -5
  18. package/dist/codedna/kappa-gofiber-generator.d.ts +65 -0
  19. package/dist/codedna/kappa-gofiber-generator.js +587 -0
  20. package/dist/codedna/kappa-laravel-generator.d.ts +68 -0
  21. package/dist/codedna/kappa-laravel-generator.js +741 -0
  22. package/dist/codedna/kappa-lexer.d.ts +44 -0
  23. package/dist/codedna/kappa-lexer.js +124 -0
  24. package/dist/codedna/kappa-mantine-generator.d.ts +65 -0
  25. package/dist/codedna/kappa-mantine-generator.js +518 -0
  26. package/dist/codedna/kappa-mongoose-generator.d.ts +44 -0
  27. package/dist/codedna/kappa-mongoose-generator.js +442 -0
  28. package/dist/codedna/kappa-parser.d.ts +43 -1
  29. package/dist/codedna/kappa-parser.js +601 -0
  30. package/dist/codedna/kappa-radix-generator.d.ts +61 -0
  31. package/dist/codedna/kappa-radix-generator.js +566 -0
  32. package/dist/codedna/kappa-typeorm-generator.d.ts +59 -0
  33. package/dist/codedna/kappa-typeorm-generator.js +723 -0
  34. package/dist/codedna/kappa-vitest-generator.d.ts +85 -0
  35. package/dist/codedna/kappa-vitest-generator.js +739 -0
  36. package/dist/codedna/parser.js +26 -1
  37. package/dist/codegen/cloud-client.d.ts +160 -0
  38. package/dist/codegen/cloud-client.js +195 -0
  39. package/dist/codegen/codegen-tool.d.ts +35 -0
  40. package/dist/codegen/codegen-tool.js +312 -0
  41. package/dist/codegen/field-inference.d.ts +24 -0
  42. package/dist/codegen/field-inference.js +101 -0
  43. package/dist/codegen/form-parser.d.ts +13 -0
  44. package/dist/codegen/form-parser.js +186 -0
  45. package/dist/codegen/index.d.ts +2 -0
  46. package/dist/codegen/index.js +4 -0
  47. package/dist/codegen/natural-parser.d.ts +50 -0
  48. package/dist/codegen/natural-parser.js +769 -0
  49. package/dist/handlers/codedna-handlers.d.ts +1 -1
  50. package/dist/handlers/codegen-handlers.d.ts +20 -0
  51. package/dist/handlers/codegen-handlers.js +60 -0
  52. package/dist/handlers/kappa-handlers.d.ts +97 -0
  53. package/dist/handlers/kappa-handlers.js +408 -0
  54. package/dist/handlers/tool-handlers.js +124 -221
  55. package/dist/helpers/api-client.js +48 -3
  56. package/dist/helpers/compact-formatter.d.ts +9 -2
  57. package/dist/helpers/compact-formatter.js +26 -2
  58. package/dist/helpers/config.d.ts +7 -2
  59. package/dist/helpers/config.js +25 -10
  60. package/dist/helpers/session-validation.d.ts +1 -1
  61. package/dist/helpers/session-validation.js +2 -4
  62. package/dist/helpers/tasks.d.ts +21 -0
  63. package/dist/helpers/tasks.js +52 -0
  64. package/dist/helpers/workers.d.ts +1 -1
  65. package/dist/helpers/workers.js +19 -19
  66. package/dist/setup.d.ts +1 -0
  67. package/dist/setup.js +228 -3
  68. package/dist/templates/claude-md.d.ts +1 -1
  69. package/dist/templates/claude-md.js +37 -152
  70. package/dist/templates/orchestrator-prompt.d.ts +2 -2
  71. package/dist/templates/orchestrator-prompt.js +31 -38
  72. package/dist/templates/self-critique.d.ts +50 -0
  73. package/dist/templates/self-critique.js +209 -0
  74. package/dist/templates/worker-prompt.d.ts +3 -3
  75. package/dist/templates/worker-prompt.js +18 -18
  76. package/dist/tools.js +77 -413
  77. package/docs/codedna/generator-testing-summary.md +205 -0
  78. package/docs/codedna/radix-ui-generator.md +478 -0
  79. package/docs/kappa-gofiber-generator.md +274 -0
  80. package/docs/kappa-laravel-fixes.md +172 -0
  81. package/docs/kappa-mongoose-generator.md +322 -0
  82. package/docs/kappa-vitest-generator.md +337 -0
  83. package/package.json +1 -1
  84. package/dist/context/deduplication.test.d.ts +0 -6
  85. package/dist/context/deduplication.test.js +0 -84
@@ -102,169 +102,55 @@ codebase_context("src/auth.ts") # Get file dependencies
102
102
  analyze_impact("validateToken") # See what changing a function affects
103
103
  \`\`\`
104
104
 
105
- ## CodeDNA: Generate Code, Save 99% Tokens
105
+ ## Code Generation (saves 95-99% tokens)
106
106
 
107
- **BEFORE writing ANY code, check if CodeDNA can generate it.** Call \`codedna_list_generators()\` to see available generators.
107
+ **ALWAYS use \`codegen\` instead of writing boilerplate.** One line of natural language 10+ production files.
108
108
 
109
- ### Available Generators (20+)
110
-
111
- | Category | Frameworks | Tool |
112
- |----------|------------|------|
113
- | **API** | Express, FastAPI, NestJS, Hono, Elysia, tRPC | \`codedna_generate_api\` |
114
- | **Frontend** | React, Vue, SvelteKit, Astro, React Router v7, TanStack Start | \`codedna_generate_frontend\` |
115
- | **ORM** | Prisma, Drizzle | \`codedna_generate_api\` with database option |
116
- | **Auth** | Better Auth, Auth.js, Lucia | \`codedna_generate_api\` with auth option |
117
- | **Components** | Forms, Tables, Cards, Modals (React/Vue/Svelte) | \`codedna_generate_component\` |
118
-
119
- ### Usage Examples
109
+ ### Quick Reference
120
110
 
121
111
  \`\`\`typescript
122
- // API with auth and validation
123
- codedna_generate_api({
124
- spec: "User(email:string:unique, password:string:hashed)",
125
- framework: "express", // or: fastapi, nestjs, hono, elysia, trpc
126
- options: { auth: true, validation: true, tests: true }
127
- })
128
-
129
- // Frontend with forms and data fetching
130
- codedna_generate_frontend({
131
- spec: "User(email:string, name:string, role:enum(admin,user))",
132
- framework: "react", // or: vue, nextjs, sveltekit, astro
133
- options: { forms: true, tables: true, ui: "shadcn" }
134
- })
135
-
136
- // Single component
137
- codedna_generate_component({
138
- spec: "Product(name:string, price:decimal, inStock:boolean)",
139
- type: "form", // or: table, card, modal
140
- framework: "react",
141
- options: { validation: true, ui: "shadcn" }
142
- })
143
- \`\`\`
144
-
145
- ### Entity DSL Quick Reference
146
-
147
- \`\`\`
148
- EntityName(field:type:modifier, field2:type:modifier)
149
-
150
- Types: string, integer, decimal, boolean, datetime, text, json
151
- Modifiers: unique, required, optional, hashed, email, min(n), max(n), default(v)
152
- Relations: userId:User (reference), posts:Post[] (array)
153
- Enums: role:enum(admin,user,guest)
154
- \`\`\`
155
-
156
- **Token savings:** 30,000 tokens → 200 tokens (99% reduction per generation)
157
-
158
- ## Kappa v2.5: Declarative Full-Stack Generation
159
-
160
- **For even higher-level generation**, use Kappa DSL - a declarative specification language that generates complete applications from compact specs.
161
-
162
- ### When to Use Kappa vs CodeDNA
163
-
164
- | Use Case | Tool |
165
- |----------|------|
166
- | Single entity/component | CodeDNA (\`codedna_generate_*\`) |
167
- | Full application with multiple entities | Kappa (\`kappa_generate_all\`) |
168
- | Pages, forms, routing together | Kappa |
169
- | Design system + components | Kappa |
170
-
171
- ### Kappa Tools
172
-
173
- | Tool | Purpose |
174
- |------|---------|
175
- | \`kappa_parse\` | Parse and validate Kappa spec |
176
- | \`kappa_generate_schema\` | Generate Drizzle schema + Zod + types |
177
- | \`kappa_generate_api\` | Generate API routes (Hono/Express/tRPC) |
178
- | \`kappa_generate_pages\` | Generate pages (TanStack Start/Next.js) |
179
- | \`kappa_generate_forms\` | Generate forms (React Hook Form + Zod + shadcn) |
180
- | \`kappa_generate_components\` | Generate React components (compound, forwardRef) |
181
- | \`kappa_generate_design\` | Generate CSS variables + Tailwind config |
182
- | \`kappa_generate_all\` | Generate complete full-stack application |
183
-
184
- ### Kappa DSL Example
112
+ // Entities schema + types + validators + API + tests
113
+ codegen({ describe: "User with email, password, role (admin/user)" })
114
+ codegen({ describe: "Post with title, content, belongs to User as author" })
185
115
 
186
- \`\`\`
187
- // Complete app specification in ~50 lines
188
- project TaskManager {
189
- database postgres
190
- framework tanstack-start
191
- }
192
-
193
- entity Task {
194
- title string required max(100)
195
- description text
196
- status enum(todo, in_progress, done) default(todo)
197
- dueDate datetime
198
- assignee User
199
- }
200
-
201
- entity User {
202
- email string unique email
203
- name string required
204
- tasks Task[]
205
- }
206
-
207
- api /tasks {
208
- GET / -> list Task[]
209
- POST / -> create Task
210
- GET /:id -> get Task
211
- PUT /:id -> update Task
212
- DELETE /:id -> delete Task
213
- }
116
+ // Forms → React Hook Form + Zod + shadcn inputs
117
+ codegen({ describe: "Login form with email, password, submit to /auth/login" })
214
118
 
215
- page /tasks {
216
- layout dashboard
217
- load tasks from /api/tasks
218
- components [TaskList, TaskForm]
219
- }
119
+ // Components → Radix/shadcn with variants
120
+ codegen({ describe: "Button with label, onClick, variant (primary/secondary)" })
220
121
 
221
- form TaskForm for Task {
222
- fields [title, description, status, dueDate]
223
- submit POST /api/tasks
224
- }
122
+ // Pages TanStack Start or Next.js routes
123
+ codegen({ describe: "Dashboard page at /dashboard, requires auth, loads User" })
225
124
 
226
- design {
227
- colors {
228
- primary #3B82F6
229
- secondary #6B7280
230
- }
231
- typography {
232
- fontFamily "Inter"
233
- scale { sm: "0.875rem", base: "1rem", lg: "1.125rem" }
234
- }
235
- }
125
+ // Generate specific outputs
126
+ codegen({ describe: "User with email", generate: ['schema', 'types'] })
127
+ codegen({ describe: "User with email", generate: ['tests'] })
128
+ codegen({ describe: "User with email", generate: ['all'] }) // everything
236
129
  \`\`\`
237
130
 
238
- ### Usage
239
-
240
- \`\`\`typescript
241
- // Generate everything from spec
242
- kappa_generate_all({
243
- spec: \`project MyApp { ... }\`,
244
- options: {
245
- framework: "tanstack-start",
246
- ui: "shadcn",
247
- dbDialect: "postgres"
248
- }
249
- })
250
-
251
- // Or generate incrementally
252
- kappa_parse({ spec: "..." }) // Validate first
253
- kappa_generate_schema({ spec: "...", outputs: ["drizzle", "zod", "types"] })
254
- kappa_generate_api({ spec: "...", framework: "hono" })
255
- kappa_generate_pages({ spec: "...", framework: "tanstack-start" })
256
- \`\`\`
131
+ ### What It Generates
132
+ | Type | Output Files |
133
+ |------|-------------|
134
+ | Entity | schema.ts, types.ts, validators.ts, routes.ts |
135
+ | Tests | *.test.ts, *.factory.ts, *.mock.ts |
136
+ | Form | *-form.tsx (RHF + Zod + shadcn) |
137
+ | Component | *.tsx (Radix primitives + Tailwind) |
138
+ | Page | route.tsx (loaders, guards, layouts) |
257
139
 
258
- **Token savings:** ~50 lines of Kappa → thousands of lines of production code (95%+ reduction)
140
+ ### Smart Inference
141
+ - Field names → types: \`email\` → email, \`password\` → hashed, \`price\` → decimal
142
+ - Enums: \`role (admin/user)\` → enum type
143
+ - Relationships: \`belongs to User as author\` → foreign key + relation
144
+ - Forms: \`email\` → email input, \`message\` → textarea
145
+ - Pages: \`requires auth\` → guard, \`loads User\` → data loader
259
146
 
260
147
  ## Best Practices
261
148
 
262
149
  1. **Trust auto-injection** - Context is injected automatically, don't call memory_search
263
150
  2. **Store decisions** - Use \`memory_store_fact\` for architectural choices
264
151
  3. **Use task tracking** - Break complex work into tasks
265
- 4. **Use Kappa for full apps** - For multi-entity apps with pages/forms, use \`kappa_generate_all\`
266
- 5. **Use CodeDNA for single components** - For individual entities or components, use \`codedna_generate_*\`
267
- 6. **Minimize tool calls** - Every MCP call costs context tokens
152
+ 4. **Use codegen for boilerplate** - Generate schemas, types, validators, routes
153
+ 5. **Minimize tool calls** - Every MCP call costs context tokens
268
154
  ${SECTION_END}
269
155
  `;
270
156
  /**
@@ -297,12 +183,11 @@ task_start({ task_id: "task_xxx" })
297
183
  task_complete({ task_id: "task_xxx", summary: "What was done" })
298
184
  \`\`\`
299
185
 
300
- ## CodeDNA (saves 95-99% tokens)
301
- \`\`\`
302
- codedna_list_generators() // See all available generators
303
- codedna_generate_api("User(email:string:unique, password:string)", "express")
304
- codedna_generate_frontend("User(email:string, name:string)", "react")
305
- codedna_generate_component("Product(name:string, price:decimal)", "form", "react")
186
+ ## Code Generation (95-99% token savings)
187
+ \`\`\`typescript
188
+ codegen({ describe: "User with email, password, role (admin/user)" }) // schema + types + API + tests
189
+ codegen({ describe: "Login form with email, password" }) // → RHF + Zod form
190
+ codegen({ describe: "Dashboard page at /dashboard, requires auth" }) // → TanStack/Next route
306
191
  \`\`\`
307
192
  ${SECTION_END}
308
193
  `;
@@ -18,9 +18,9 @@ export declare function buildOrchestratorPrompt(params: {
18
18
  availableWorkers?: string[];
19
19
  }): string;
20
20
  /**
21
- * Get CodeDNA usage hint for task descriptions
21
+ * Get codegen usage hint for task descriptions
22
22
  */
23
- export declare function getCodeDNAHint(entitySpec: string): string;
23
+ export declare function getCodegenHint(entityDescription: string): string;
24
24
  /**
25
25
  * Validate task description doesn't contain code
26
26
  */
@@ -85,22 +85,17 @@ export function buildOrchestratorPrompt(params) {
85
85
  - File-by-file change lists
86
86
  </behavior>
87
87
 
88
- <behavior id="codedna_specs" priority="MANDATORY">
88
+ <behavior id="codegen_specs" priority="MANDATORY">
89
89
  When tasks involve creating entities/models/APIs:
90
90
 
91
- INSTEAD OF writing code like:
92
- \`\`\`typescript
93
- interface User {
94
- id: string;
95
- email: string;
96
- password: string;
97
- }
98
- \`\`\`
91
+ INSTEAD OF writing code, USE natural language:
92
+ "User with email, password, role (admin/user)"
99
93
 
100
- USE Entity DSL format:
101
- "User(id:string:unique, email:string:required, password:string:hashed)"
94
+ Workers use codegen() which infers types from field names:
95
+ - email → email type, passwordhashed, createdAt → timestamp
96
+ - (admin/user) → enum, price → decimal, isActive → boolean
102
97
 
103
- This tells workers to use CodeDNA generators (95-99% token savings).
98
+ Token savings: 95-99% vs manual coding.
104
99
  </behavior>
105
100
 
106
101
  <behavior id="parallel_dispatch" priority="IMPORTANT">
@@ -161,19 +156,18 @@ export function buildOrchestratorPrompt(params) {
161
156
  - Random .md files scattered in src/ or root
162
157
  </documentation_standards>
163
158
 
164
- <entity_dsl_format>
165
- When defining data models, use Entity DSL:
159
+ <entity_format>
160
+ When defining data models, use natural language:
166
161
 
167
- FORMAT: EntityName(field:type:constraint, field:type:constraint, ...)
168
-
169
- TYPES: string, integer, decimal, boolean, datetime, ref(Entity), enum(val1|val2)
170
- CONSTRAINTS: unique, required, min(n), max(n), hashed, default(val)
162
+ FORMAT: "EntityName with field1, field2, field3 (enum values)"
171
163
 
172
164
  EXAMPLES:
173
- - "User(email:string:unique:required, password:string:hashed, role:enum(admin|user))"
174
- - "Product(name:string:required, price:decimal:min(0), category:ref(Category))"
175
- - "Order(user:ref(User), total:decimal, status:enum(pending|paid|shipped))"
176
- </entity_dsl_format>
165
+ - "User with email, password, role (admin/user)"
166
+ - "Product with name, price, categoryId"
167
+ - "Order with userId, total, status (pending/paid/shipped)"
168
+
169
+ Types are inferred from field names (email→email, password→hashed, price→decimal)
170
+ </entity_format>
177
171
 
178
172
  <acceptance_criteria_format>
179
173
  Good acceptance criteria are:
@@ -219,24 +213,23 @@ export function buildOrchestratorPrompt(params) {
219
213
  - general-expert: Tasks that don't fit other domains`}
220
214
  </available_workers>
221
215
 
222
- <codedna_generators priority="CRITICAL">
223
- CodeDNA generates production code from Entity DSL - workers MUST check availability first.
216
+ <codegen priority="CRITICAL">
217
+ codegen() generates production code from natural language descriptions.
224
218
 
225
- BEFORE creating any task involving APIs, CRUD, or UI components:
226
- 1. Workers should call codedna_list_generators() to see available generators
227
- 2. If a generator exists, use it instead of writing code manually
219
+ USAGE: codegen({ describe: "User with email, password, role (admin/user)" })
228
220
 
229
- AVAILABLE DOMAINS:
230
- - api: Express, FastAPI, NestJS (full CRUD with auth, validation, tests)
231
- - frontend: React/Next.js, Vue 3 (pages, forms, tables)
232
- - component: Forms, tables, cards, modals (React, Vue, Svelte)
221
+ GENERATES:
222
+ - Drizzle schema (database tables)
223
+ - TypeScript types
224
+ - Zod validators
225
+ - API routes (Hono/Express)
233
226
 
234
227
  INCLUDE IN TASK DESCRIPTIONS:
235
- When tasks involve entities, include the DSL spec so workers know to use CodeDNA:
236
- "Create user registration. Entity: User(email:string:unique, password:string:hashed)"
228
+ When tasks involve entities, describe them naturally:
229
+ "Create user registration. Entity: User with email, password, role (admin/user)"
237
230
 
238
- Token savings: 95-99% vs manual coding
239
- </codedna_generators>
231
+ Stack auto-detected from package.json. Token savings: 95-99% vs manual coding.
232
+ </codegen>
240
233
 
241
234
  ${epicTitle ? `<epic_context>
242
235
  <title>${epicTitle}</title>
@@ -259,10 +252,10 @@ export function buildOrchestratorPrompt(params) {
259
252
  </user_input>`;
260
253
  }
261
254
  /**
262
- * Get CodeDNA usage hint for task descriptions
255
+ * Get codegen usage hint for task descriptions
263
256
  */
264
- export function getCodeDNAHint(entitySpec) {
265
- return `Entity spec: "${entitySpec}" (workers will use CodeDNA generators)`;
257
+ export function getCodegenHint(entityDescription) {
258
+ return `Entity: ${entityDescription} (workers will use codegen)`;
266
259
  }
267
260
  /**
268
261
  * Validate task description doesn't contain code
@@ -0,0 +1,50 @@
1
+ export interface SelfCritiqueContext {
2
+ taskDescription: string;
3
+ proposedSolution: string;
4
+ codeSnippet?: string;
5
+ targetAudience?: string;
6
+ }
7
+ export interface SelfCritiqueResult {
8
+ passed: boolean;
9
+ issues: SelfCritiqueIssue[];
10
+ suggestions: string[];
11
+ overallScore: number;
12
+ }
13
+ export interface SelfCritiqueIssue {
14
+ category: 'universality' | 'simplicity' | 'hardcoding' | 'assumptions';
15
+ severity: 'low' | 'medium' | 'high';
16
+ description: string;
17
+ suggestion: string;
18
+ }
19
+ /**
20
+ * Generate a self-critique prompt for AI agents.
21
+ * This prompt guides the AI to check its own work for common issues.
22
+ */
23
+ export declare function generateSelfCritiquePrompt(context: SelfCritiqueContext): string;
24
+ /**
25
+ * Quick check prompts for specific concerns.
26
+ * Use these for targeted self-critique on specific aspects.
27
+ */
28
+ export declare const QUICK_CRITIQUE_PROMPTS: {
29
+ universality: string;
30
+ simplicity: string;
31
+ hardcoding: string;
32
+ assumptions: string;
33
+ };
34
+ /**
35
+ * Generate a pre-commit checklist for AI agents.
36
+ * A lightweight version of self-critique for quick checks.
37
+ */
38
+ export declare function generatePreCommitChecklist(taskType: 'code' | 'design' | 'analysis'): string;
39
+ /**
40
+ * Parse a self-critique response from an LLM.
41
+ */
42
+ export declare function parseSelfCritiqueResponse(response: string): SelfCritiqueResult | null;
43
+ /**
44
+ * Determine if a self-critique result warrants action.
45
+ */
46
+ export declare function shouldTakeAction(result: SelfCritiqueResult): {
47
+ shouldRevise: boolean;
48
+ shouldAskUser: boolean;
49
+ reason: string;
50
+ };
@@ -0,0 +1,209 @@
1
+ // =============================================================================
2
+ // Self-Critique Prompt Template
3
+ // =============================================================================
4
+ // A template for AI agents to self-critique their work before finalizing.
5
+ // Catches issues like hardcoded patterns, over-engineering, and assumptions
6
+ // before they require user intervention.
7
+ // =============================================================================
8
+ /**
9
+ * Generate a self-critique prompt for AI agents.
10
+ * This prompt guides the AI to check its own work for common issues.
11
+ */
12
+ export function generateSelfCritiquePrompt(context) {
13
+ const codeSection = context.codeSnippet
14
+ ? `\n## Code to Review\n\`\`\`\n${context.codeSnippet.slice(0, 2000)}\n\`\`\``
15
+ : '';
16
+ const audienceNote = context.targetAudience
17
+ ? `Target audience: ${context.targetAudience}`
18
+ : 'Target audience: All users (universal)';
19
+ return `# Self-Critique Review
20
+
21
+ You are reviewing your own proposed solution before finalizing. Be critical and honest.
22
+
23
+ ## Task
24
+ ${context.taskDescription}
25
+
26
+ ## Proposed Solution
27
+ ${context.proposedSolution}
28
+ ${codeSection}
29
+
30
+ ## Review Criteria
31
+
32
+ ${audienceNote}
33
+
34
+ Evaluate the solution against these criteria:
35
+
36
+ ### 1. Universality (Does this work for ALL users?)
37
+ - Does this assume a specific communication style?
38
+ - Would this work for users from different cultures/backgrounds?
39
+ - Are there hardcoded patterns that only match certain phrasings?
40
+ - Would a user with a different vocabulary trigger this correctly?
41
+
42
+ ### 2. Simplicity (Is this over-engineered?)
43
+ - Is there a simpler way to achieve the same result?
44
+ - Are there unnecessary abstractions or indirections?
45
+ - Is the complexity justified by the requirements?
46
+ - Would a junior developer understand this easily?
47
+
48
+ ### 3. Hardcoding (Am I hardcoding things that should be inferred?)
49
+ - Are there magic strings that should be configurable?
50
+ - Are there hardcoded patterns that limit flexibility?
51
+ - Should any of this logic be LLM-inferred instead of rule-based?
52
+ - Are there assumptions baked into constants that might not hold?
53
+
54
+ ### 4. Assumptions (What am I assuming that might be wrong?)
55
+ - What implicit assumptions does this solution make?
56
+ - Are these assumptions documented or validated?
57
+ - What happens if an assumption is violated?
58
+ - Would a user from a different context have different expectations?
59
+
60
+ ## Output Format
61
+
62
+ Respond with a JSON object:
63
+ {
64
+ "passed": true/false,
65
+ "issues": [
66
+ {
67
+ "category": "universality|simplicity|hardcoding|assumptions",
68
+ "severity": "low|medium|high",
69
+ "description": "What the issue is",
70
+ "suggestion": "How to fix it"
71
+ }
72
+ ],
73
+ "suggestions": ["List of improvement suggestions"],
74
+ "overallScore": 0-100
75
+ }
76
+
77
+ A solution passes if:
78
+ - No high-severity issues
79
+ - overallScore >= 70
80
+ - All critical universality concerns addressed
81
+
82
+ Be critical. It's better to catch issues now than to require user intervention later.`;
83
+ }
84
+ /**
85
+ * Quick check prompts for specific concerns.
86
+ * Use these for targeted self-critique on specific aspects.
87
+ */
88
+ export const QUICK_CRITIQUE_PROMPTS = {
89
+ universality: `Before finalizing, ask yourself:
90
+ - Would this work for a user who communicates differently than me?
91
+ - Am I assuming English idioms or Western communication patterns?
92
+ - Would this handle indirect, polite, or terse communication styles?
93
+ - If I replaced keywords with synonyms, would it still work?`,
94
+ simplicity: `Before finalizing, ask yourself:
95
+ - Can I explain this in one sentence?
96
+ - Is there a 3-line solution I'm missing?
97
+ - Would a code reviewer ask "why is this so complicated?"
98
+ - Am I solving future problems that don't exist yet?`,
99
+ hardcoding: `Before finalizing, ask yourself:
100
+ - Am I matching specific strings that could be phrased differently?
101
+ - Should this regex be an LLM inference instead?
102
+ - Are my constants actually universal, or just common in my experience?
103
+ - Would this break if the user uses different terminology?`,
104
+ assumptions: `Before finalizing, ask yourself:
105
+ - What am I assuming about the user's environment?
106
+ - What am I assuming about their technical level?
107
+ - What am I assuming about their preferences?
108
+ - What happens if any of these assumptions are wrong?`,
109
+ };
110
+ /**
111
+ * Generate a pre-commit checklist for AI agents.
112
+ * A lightweight version of self-critique for quick checks.
113
+ */
114
+ export function generatePreCommitChecklist(taskType) {
115
+ const baseChecks = `
116
+ ## Pre-Commit Checklist
117
+
118
+ Before finalizing, verify:
119
+
120
+ ☐ **Universality**: Works for diverse users, not just specific communication styles
121
+ ☐ **Simplicity**: No unnecessary complexity; a simpler solution doesn't exist
122
+ ☐ **No Hardcoding**: Dynamic where needed; LLM inference over rigid patterns
123
+ ☐ **Assumptions Documented**: Any assumptions are explicit and validated
124
+ `;
125
+ const typeSpecificChecks = {
126
+ code: `
127
+ ### Code-Specific
128
+ ☐ No magic strings that should be configurable
129
+ ☐ No regex patterns that could be LLM inference
130
+ ☐ Error messages are helpful, not cryptic
131
+ ☐ Edge cases are handled, not assumed away
132
+ `,
133
+ design: `
134
+ ### Design-Specific
135
+ ☐ Scales to 10x users without architecture changes
136
+ ☐ Failure modes are graceful, not catastrophic
137
+ ☐ New developers can understand the design in 5 minutes
138
+ ☐ No premature optimization or over-abstraction
139
+ `,
140
+ analysis: `
141
+ ### Analysis-Specific
142
+ ☐ Conclusions are supported by evidence
143
+ ☐ Alternative interpretations are considered
144
+ ☐ Limitations are acknowledged
145
+ ☐ Recommendations are actionable
146
+ `,
147
+ };
148
+ return baseChecks + (typeSpecificChecks[taskType] || '');
149
+ }
150
+ /**
151
+ * Parse a self-critique response from an LLM.
152
+ */
153
+ export function parseSelfCritiqueResponse(response) {
154
+ try {
155
+ // Extract JSON from response (handles markdown code blocks)
156
+ let jsonStr = response.trim();
157
+ if (jsonStr.startsWith('```')) {
158
+ jsonStr = jsonStr.replace(/```json?\n?/g, '').replace(/```$/g, '').trim();
159
+ }
160
+ const parsed = JSON.parse(jsonStr);
161
+ // Validate structure
162
+ if (typeof parsed.passed !== 'boolean')
163
+ return null;
164
+ if (!Array.isArray(parsed.issues))
165
+ return null;
166
+ if (typeof parsed.overallScore !== 'number')
167
+ return null;
168
+ return parsed;
169
+ }
170
+ catch {
171
+ return null;
172
+ }
173
+ }
174
+ /**
175
+ * Determine if a self-critique result warrants action.
176
+ */
177
+ export function shouldTakeAction(result) {
178
+ // High severity issues always require revision
179
+ const highSeverityIssues = result.issues.filter(i => i.severity === 'high');
180
+ if (highSeverityIssues.length > 0) {
181
+ return {
182
+ shouldRevise: true,
183
+ shouldAskUser: false,
184
+ reason: `${highSeverityIssues.length} high-severity issue(s) found: ${highSeverityIssues.map(i => i.description).join('; ')}`,
185
+ };
186
+ }
187
+ // Low score requires revision
188
+ if (result.overallScore < 70) {
189
+ return {
190
+ shouldRevise: true,
191
+ shouldAskUser: false,
192
+ reason: `Score ${result.overallScore}/100 is below threshold (70)`,
193
+ };
194
+ }
195
+ // Multiple medium issues warrant user consultation
196
+ const mediumIssues = result.issues.filter(i => i.severity === 'medium');
197
+ if (mediumIssues.length >= 3) {
198
+ return {
199
+ shouldRevise: false,
200
+ shouldAskUser: true,
201
+ reason: `Multiple medium-severity issues found. User should review: ${mediumIssues.map(i => i.description).join('; ')}`,
202
+ };
203
+ }
204
+ return {
205
+ shouldRevise: false,
206
+ shouldAskUser: false,
207
+ reason: 'Solution passed self-critique',
208
+ };
209
+ }
@@ -27,15 +27,15 @@ export interface WorkerPromptParams {
27
27
  tier?: 'minimal' | 'standard' | 'professional';
28
28
  }
29
29
  /**
30
- * Build worker system prompt with CodeDNA integration
30
+ * Build worker system prompt
31
31
  *
32
32
  * Workers:
33
33
  * - Execute specific implementation tasks
34
- * - Use CodeDNA generators for boilerplate code
34
+ * - Use codegen for boilerplate code
35
35
  * - Use tools (memory, codebase) before writing from scratch
36
36
  * - Report completion with detailed summaries
37
37
  */
38
- export declare function buildWorkerPromptWithCodeDNA(params: WorkerPromptParams): string;
38
+ export declare function buildWorkerPrompt(params: WorkerPromptParams): string;
39
39
  /**
40
40
  * Build a minimal prompt for simple tasks
41
41
  */