@claudetools/tools 0.8.11 → 0.9.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.
Files changed (75) hide show
  1. package/dist/codedna/generators/astro.d.ts +18 -0
  2. package/dist/codedna/generators/astro.js +91 -0
  3. package/dist/codedna/generators/authjs.d.ts +18 -0
  4. package/dist/codedna/generators/authjs.js +68 -0
  5. package/dist/codedna/generators/better-auth.d.ts +18 -0
  6. package/dist/codedna/generators/better-auth.js +62 -0
  7. package/dist/codedna/generators/drizzle-orm.d.ts +18 -0
  8. package/dist/codedna/generators/drizzle-orm.js +65 -0
  9. package/dist/codedna/generators/elysia-api.d.ts +12 -0
  10. package/dist/codedna/generators/elysia-api.js +64 -0
  11. package/dist/codedna/generators/hono-api.d.ts +12 -0
  12. package/dist/codedna/generators/hono-api.js +64 -0
  13. package/dist/codedna/generators/lucia-auth.d.ts +18 -0
  14. package/dist/codedna/generators/lucia-auth.js +69 -0
  15. package/dist/codedna/generators/prisma.d.ts +18 -0
  16. package/dist/codedna/generators/prisma.js +64 -0
  17. package/dist/codedna/generators/react-router-v7.d.ts +18 -0
  18. package/dist/codedna/generators/react-router-v7.js +77 -0
  19. package/dist/codedna/generators/react19-shadcn.d.ts +21 -0
  20. package/dist/codedna/generators/react19-shadcn.js +367 -0
  21. package/dist/codedna/generators/sveltekit.d.ts +18 -0
  22. package/dist/codedna/generators/sveltekit.js +73 -0
  23. package/dist/codedna/generators/tanstack-start-drizzle.d.ts +92 -0
  24. package/dist/codedna/generators/tanstack-start-drizzle.js +824 -0
  25. package/dist/codedna/generators/trpc-api.d.ts +12 -0
  26. package/dist/codedna/generators/trpc-api.js +64 -0
  27. package/dist/codedna/index.d.ts +31 -0
  28. package/dist/codedna/index.js +39 -0
  29. package/dist/codedna/kappa-api-generator.d.ts +89 -0
  30. package/dist/codedna/kappa-api-generator.js +493 -0
  31. package/dist/codedna/kappa-ast.d.ts +552 -0
  32. package/dist/codedna/kappa-ast.js +141 -0
  33. package/dist/codedna/kappa-cli.d.ts +2 -0
  34. package/dist/codedna/kappa-cli.js +302 -0
  35. package/dist/codedna/kappa-component-generator.d.ts +47 -0
  36. package/dist/codedna/kappa-component-generator.js +295 -0
  37. package/dist/codedna/kappa-design-generator.d.ts +52 -0
  38. package/dist/codedna/kappa-design-generator.js +365 -0
  39. package/dist/codedna/kappa-drizzle-generator.d.ts +45 -0
  40. package/dist/codedna/kappa-drizzle-generator.js +355 -0
  41. package/dist/codedna/kappa-form-generator.d.ts +51 -0
  42. package/dist/codedna/kappa-form-generator.js +319 -0
  43. package/dist/codedna/kappa-lexer.d.ts +268 -0
  44. package/dist/codedna/kappa-lexer.js +757 -0
  45. package/dist/codedna/kappa-page-generator.d.ts +57 -0
  46. package/dist/codedna/kappa-page-generator.js +338 -0
  47. package/dist/codedna/kappa-parser.d.ts +261 -0
  48. package/dist/codedna/kappa-parser.js +2547 -0
  49. package/dist/codedna/kappa-provenance.d.ts +101 -0
  50. package/dist/codedna/kappa-provenance.js +199 -0
  51. package/dist/codedna/kappa-types-generator.d.ts +37 -0
  52. package/dist/codedna/kappa-types-generator.js +159 -0
  53. package/dist/codedna/kappa-validator.d.ts +86 -0
  54. package/dist/codedna/kappa-validator.js +638 -0
  55. package/dist/codedna/kappa-zod-generator.d.ts +32 -0
  56. package/dist/codedna/kappa-zod-generator.js +216 -0
  57. package/dist/handlers/kappa-handlers.d.ts +116 -0
  58. package/dist/handlers/kappa-handlers.js +465 -0
  59. package/dist/handlers/tool-handlers.js +121 -0
  60. package/dist/templates/claude-md.d.ts +1 -1
  61. package/dist/templates/claude-md.js +166 -9
  62. package/dist/tools.js +199 -0
  63. package/docs/research/2026-01-02-codedna-il-specification.md +639 -0
  64. package/docs/research/2026-01-02-codedna-v2-research.md +943 -0
  65. package/docs/research/2026-01-02-computation-foundations.md +564 -0
  66. package/docs/research/2026-01-02-hardware-description.md +814 -0
  67. package/docs/research/2026-01-02-kappa-specification.md +697 -0
  68. package/docs/research/2026-01-02-kappa-tanstack-example.md +527 -0
  69. package/docs/research/2026-01-02-kappa-v2-synthesis.md +406 -0
  70. package/docs/research/2026-01-02-kappa-v2.5-specification.md +1218 -0
  71. package/docs/research/2026-01-02-kappa-v3-specification.md +1864 -0
  72. package/docs/research/2026-01-02-kappa-whitepaper.md +662 -0
  73. package/docs/research/2026-01-02-logic-constraint.md +731 -0
  74. package/docs/research/2026-01-02-quantum-computation.md +635 -0
  75. package/package.json +4 -2
@@ -0,0 +1,465 @@
1
+ // =============================================================================
2
+ // Kappa v2.5 MCP Tool Handlers
3
+ // =============================================================================
4
+ //
5
+ // Handlers for Kappa DSL code generation tools. Kappa is a declarative
6
+ // specification language for full-stack applications that generates
7
+ // production-ready code from compact specifications.
8
+ //
9
+ import { parseKappaToAST, validateKappaSpec, formatValidationResults, generateDrizzleSchema, generateZodSchemas, generateTypeScriptTypes, generateAPI, generatePages, generateForms, generateComponents, generateDesign, } from '../codedna/index.js';
10
+ // Map user-friendly dialect names to internal ones
11
+ function normalizeDialect(dialect) {
12
+ switch (dialect) {
13
+ case 'postgres':
14
+ case 'postgresql':
15
+ return 'postgresql';
16
+ case 'mysql':
17
+ return 'mysql';
18
+ case 'sqlite':
19
+ default:
20
+ return 'sqlite';
21
+ }
22
+ }
23
+ // =============================================================================
24
+ // Parse & Validate Handler
25
+ // =============================================================================
26
+ /**
27
+ * Handle kappa_parse tool call
28
+ * Parses and validates a Kappa specification
29
+ */
30
+ export async function handleKappaParse(args) {
31
+ const { spec } = args;
32
+ if (!spec || typeof spec !== 'string') {
33
+ return { success: false, errors: ['spec is required and must be a string'] };
34
+ }
35
+ try {
36
+ const ast = parseKappaToAST(spec);
37
+ if (!ast) {
38
+ return {
39
+ success: false,
40
+ errors: ['Failed to parse Kappa specification'],
41
+ };
42
+ }
43
+ // Validate the AST
44
+ const validation = validateKappaSpec(ast);
45
+ if (validation.errors.length > 0) {
46
+ return {
47
+ success: false,
48
+ errors: formatValidationResults(validation).split('\n').filter(Boolean),
49
+ };
50
+ }
51
+ return {
52
+ success: true,
53
+ ast,
54
+ summary: {
55
+ project: ast.project?.name,
56
+ entities: ast.entities.length,
57
+ apis: ast.apis.length,
58
+ pages: ast.pages?.length ?? 0,
59
+ forms: ast.forms?.length ?? 0,
60
+ components: ast.components?.length ?? 0,
61
+ hasDesign: !!ast.design,
62
+ hasAuth: !!ast.auth,
63
+ },
64
+ };
65
+ }
66
+ catch (error) {
67
+ return {
68
+ success: false,
69
+ errors: [error instanceof Error ? error.message : String(error)],
70
+ };
71
+ }
72
+ }
73
+ // =============================================================================
74
+ // Schema Generation Handler
75
+ // =============================================================================
76
+ /**
77
+ * Handle kappa_generate_schema tool call
78
+ * Generates Drizzle schema, Zod validators, and TypeScript types
79
+ */
80
+ export async function handleKappaGenerateSchema(args) {
81
+ const { spec, outputs = ['drizzle', 'zod', 'types'], options = {} } = args;
82
+ try {
83
+ const ast = parseKappaToAST(spec);
84
+ if (!ast) {
85
+ return { success: false, errors: ['Failed to parse Kappa specification'] };
86
+ }
87
+ const validation = validateKappaSpec(ast);
88
+ if (validation.errors.length > 0) {
89
+ return { success: false, errors: validation.errors.map((e) => e.message) };
90
+ }
91
+ const files = [];
92
+ let totalLines = 0;
93
+ // Generate Drizzle schema
94
+ if (outputs.includes('drizzle')) {
95
+ const drizzle = generateDrizzleSchema(ast.entities, {
96
+ provenance: options.provenance ?? true,
97
+ dialect: normalizeDialect(options.dbDialect),
98
+ });
99
+ files.push({ path: 'db/schema.ts', content: drizzle.schema });
100
+ totalLines += drizzle.schema.split('\n').length;
101
+ if (drizzle.relations) {
102
+ files.push({ path: 'db/relations.ts', content: drizzle.relations });
103
+ totalLines += drizzle.relations.split('\n').length;
104
+ }
105
+ files.push({ path: 'db/types.ts', content: drizzle.types });
106
+ totalLines += drizzle.types.split('\n').length;
107
+ }
108
+ // Generate Zod schemas
109
+ if (outputs.includes('zod')) {
110
+ const zod = generateZodSchemas(ast.entities, {
111
+ provenance: options.provenance ?? true,
112
+ });
113
+ files.push({ path: 'lib/schemas.ts', content: zod.schemas });
114
+ totalLines += zod.schemas.split('\n').length;
115
+ }
116
+ // Generate TypeScript types
117
+ if (outputs.includes('types')) {
118
+ const types = generateTypeScriptTypes(ast.entities, {
119
+ provenance: options.provenance ?? true,
120
+ });
121
+ files.push({ path: 'lib/types.ts', content: types.types });
122
+ totalLines += types.types.split('\n').length;
123
+ }
124
+ return {
125
+ success: true,
126
+ files,
127
+ metadata: {
128
+ filesGenerated: files.length,
129
+ linesOfCode: totalLines,
130
+ estimatedTokensSaved: totalLines * 25 - 200,
131
+ },
132
+ };
133
+ }
134
+ catch (error) {
135
+ return {
136
+ success: false,
137
+ errors: [error instanceof Error ? error.message : String(error)],
138
+ };
139
+ }
140
+ }
141
+ // =============================================================================
142
+ // API Generation Handler
143
+ // =============================================================================
144
+ /**
145
+ * Handle kappa_generate_api tool call
146
+ * Generates API routes from Kappa API blocks
147
+ */
148
+ export async function handleKappaGenerateApi(args) {
149
+ const { spec, framework = 'hono', options = {} } = args;
150
+ try {
151
+ const ast = parseKappaToAST(spec);
152
+ if (!ast) {
153
+ return { success: false, errors: ['Failed to parse Kappa specification'] };
154
+ }
155
+ if (ast.apis.length === 0) {
156
+ return { success: false, errors: ['No API blocks found in specification'] };
157
+ }
158
+ const files = [];
159
+ let totalLines = 0;
160
+ // Generate API routes (pass all APIs at once)
161
+ const result = generateAPI(ast.apis, {
162
+ framework,
163
+ provenance: options.provenance ?? true,
164
+ });
165
+ files.push({ path: 'api/routes.ts', content: result.routes });
166
+ totalLines += result.routes.split('\n').length;
167
+ if (result.validation) {
168
+ files.push({ path: 'api/validation.ts', content: result.validation });
169
+ totalLines += result.validation.split('\n').length;
170
+ }
171
+ if (result.errors) {
172
+ files.push({ path: 'api/errors.ts', content: result.errors });
173
+ totalLines += result.errors.split('\n').length;
174
+ }
175
+ if (result.openapi) {
176
+ files.push({ path: 'api/openapi.json', content: result.openapi });
177
+ totalLines += result.openapi.split('\n').length;
178
+ }
179
+ return {
180
+ success: true,
181
+ files,
182
+ metadata: {
183
+ filesGenerated: files.length,
184
+ linesOfCode: totalLines,
185
+ estimatedTokensSaved: totalLines * 25 - 200,
186
+ },
187
+ };
188
+ }
189
+ catch (error) {
190
+ return {
191
+ success: false,
192
+ errors: [error instanceof Error ? error.message : String(error)],
193
+ };
194
+ }
195
+ }
196
+ // =============================================================================
197
+ // Page Generation Handler
198
+ // =============================================================================
199
+ /**
200
+ * Handle kappa_generate_pages tool call
201
+ * Generates page/route components for TanStack Start or Next.js
202
+ */
203
+ export async function handleKappaGeneratePages(args) {
204
+ const { spec, framework = 'tanstack-start', options = {} } = args;
205
+ try {
206
+ const ast = parseKappaToAST(spec);
207
+ if (!ast) {
208
+ return { success: false, errors: ['Failed to parse Kappa specification'] };
209
+ }
210
+ if (!ast.pages || ast.pages.length === 0) {
211
+ return { success: false, errors: ['No page blocks found in specification'] };
212
+ }
213
+ const result = generatePages(ast.pages, {
214
+ framework,
215
+ provenance: options.provenance ?? true,
216
+ typescript: options.typescript ?? true,
217
+ });
218
+ const files = result.pages.map((p) => ({ path: p.path, content: p.content }));
219
+ const totalLines = files.reduce((sum, f) => sum + f.content.split('\n').length, 0);
220
+ return {
221
+ success: true,
222
+ files,
223
+ metadata: {
224
+ filesGenerated: files.length,
225
+ linesOfCode: totalLines,
226
+ estimatedTokensSaved: totalLines * 25 - 200,
227
+ },
228
+ };
229
+ }
230
+ catch (error) {
231
+ return {
232
+ success: false,
233
+ errors: [error instanceof Error ? error.message : String(error)],
234
+ };
235
+ }
236
+ }
237
+ // =============================================================================
238
+ // Form Generation Handler
239
+ // =============================================================================
240
+ /**
241
+ * Handle kappa_generate_forms tool call
242
+ * Generates React forms with React Hook Form and Zod validation
243
+ */
244
+ export async function handleKappaGenerateForms(args) {
245
+ const { spec, ui = 'shadcn', options = {} } = args;
246
+ try {
247
+ const ast = parseKappaToAST(spec);
248
+ if (!ast) {
249
+ return { success: false, errors: ['Failed to parse Kappa specification'] };
250
+ }
251
+ if (!ast.forms || ast.forms.length === 0) {
252
+ return { success: false, errors: ['No form blocks found in specification'] };
253
+ }
254
+ const result = generateForms(ast.forms, {
255
+ ui,
256
+ provenance: options.provenance ?? true,
257
+ typescript: options.typescript ?? true,
258
+ zod: options.zod ?? true,
259
+ });
260
+ const files = result.forms.map((f) => ({ path: f.path, content: f.content }));
261
+ const totalLines = files.reduce((sum, f) => sum + f.content.split('\n').length, 0);
262
+ return {
263
+ success: true,
264
+ files,
265
+ metadata: {
266
+ filesGenerated: files.length,
267
+ linesOfCode: totalLines,
268
+ estimatedTokensSaved: totalLines * 25 - 200,
269
+ },
270
+ };
271
+ }
272
+ catch (error) {
273
+ return {
274
+ success: false,
275
+ errors: [error instanceof Error ? error.message : String(error)],
276
+ };
277
+ }
278
+ }
279
+ // =============================================================================
280
+ // Component Generation Handler
281
+ // =============================================================================
282
+ /**
283
+ * Handle kappa_generate_components tool call
284
+ * Generates React components including compound components
285
+ */
286
+ export async function handleKappaGenerateComponents(args) {
287
+ const { spec, options = {} } = args;
288
+ try {
289
+ const ast = parseKappaToAST(spec);
290
+ if (!ast) {
291
+ return { success: false, errors: ['Failed to parse Kappa specification'] };
292
+ }
293
+ if (!ast.components || ast.components.length === 0) {
294
+ return { success: false, errors: ['No component blocks found in specification'] };
295
+ }
296
+ const result = generateComponents(ast.components, {
297
+ provenance: options.provenance ?? true,
298
+ typescript: options.typescript ?? true,
299
+ forwardRef: options.forwardRef ?? false,
300
+ basePath: options.basePath ?? 'components',
301
+ });
302
+ const files = result.components.map((c) => ({ path: c.path, content: c.content }));
303
+ const totalLines = files.reduce((sum, f) => sum + f.content.split('\n').length, 0);
304
+ return {
305
+ success: true,
306
+ files,
307
+ metadata: {
308
+ filesGenerated: files.length,
309
+ linesOfCode: totalLines,
310
+ estimatedTokensSaved: totalLines * 25 - 200,
311
+ },
312
+ };
313
+ }
314
+ catch (error) {
315
+ return {
316
+ success: false,
317
+ errors: [error instanceof Error ? error.message : String(error)],
318
+ };
319
+ }
320
+ }
321
+ // =============================================================================
322
+ // Design Generation Handler
323
+ // =============================================================================
324
+ /**
325
+ * Handle kappa_generate_design tool call
326
+ * Generates CSS variables and Tailwind config from design tokens
327
+ */
328
+ export async function handleKappaGenerateDesign(args) {
329
+ const { spec, format = 'both', options = {} } = args;
330
+ try {
331
+ const ast = parseKappaToAST(spec);
332
+ if (!ast) {
333
+ return { success: false, errors: ['Failed to parse Kappa specification'] };
334
+ }
335
+ if (!ast.design) {
336
+ return { success: false, errors: ['No design block found in specification'] };
337
+ }
338
+ const result = generateDesign(ast.design, {
339
+ format,
340
+ provenance: options.provenance ?? true,
341
+ prefix: options.prefix ?? '',
342
+ hsl: options.hsl ?? false,
343
+ });
344
+ const files = [];
345
+ if (result.css) {
346
+ files.push({ path: result.css.path, content: result.css.content });
347
+ }
348
+ if (result.tailwind) {
349
+ files.push({ path: result.tailwind.path, content: result.tailwind.content });
350
+ }
351
+ const totalLines = files.reduce((sum, f) => sum + f.content.split('\n').length, 0);
352
+ return {
353
+ success: true,
354
+ files,
355
+ metadata: {
356
+ filesGenerated: files.length,
357
+ linesOfCode: totalLines,
358
+ estimatedTokensSaved: totalLines * 25 - 200,
359
+ },
360
+ };
361
+ }
362
+ catch (error) {
363
+ return {
364
+ success: false,
365
+ errors: [error instanceof Error ? error.message : String(error)],
366
+ };
367
+ }
368
+ }
369
+ // =============================================================================
370
+ // Full Stack Generation Handler
371
+ // =============================================================================
372
+ /**
373
+ * Handle kappa_generate_all tool call
374
+ * Generates complete full-stack application from Kappa specification
375
+ */
376
+ export async function handleKappaGenerateAll(args) {
377
+ const { spec, options = {} } = args;
378
+ try {
379
+ const ast = parseKappaToAST(spec);
380
+ if (!ast) {
381
+ return { success: false, errors: ['Failed to parse Kappa specification'] };
382
+ }
383
+ const validation = validateKappaSpec(ast);
384
+ if (validation.errors.length > 0) {
385
+ return { success: false, errors: validation.errors.map((e) => e.message) };
386
+ }
387
+ const files = [];
388
+ const { framework = 'tanstack-start', apiFramework = 'hono', ui = 'shadcn', dbDialect = 'sqlite', provenance = true, typescript = true, } = options;
389
+ // 1. Generate database schema
390
+ if (ast.entities.length > 0) {
391
+ const drizzle = generateDrizzleSchema(ast.entities, {
392
+ provenance,
393
+ dialect: normalizeDialect(dbDialect),
394
+ });
395
+ files.push({ path: 'db/schema.ts', content: drizzle.schema });
396
+ if (drizzle.relations) {
397
+ files.push({ path: 'db/relations.ts', content: drizzle.relations });
398
+ }
399
+ files.push({ path: 'db/types.ts', content: drizzle.types });
400
+ const zod = generateZodSchemas(ast.entities, { provenance });
401
+ files.push({ path: 'lib/schemas.ts', content: zod.schemas });
402
+ const types = generateTypeScriptTypes(ast.entities, { provenance });
403
+ files.push({ path: 'lib/types.ts', content: types.types });
404
+ }
405
+ // 2. Generate API routes
406
+ if (ast.apis.length > 0) {
407
+ const result = generateAPI(ast.apis, {
408
+ framework: apiFramework,
409
+ provenance,
410
+ });
411
+ files.push({ path: 'api/routes.ts', content: result.routes });
412
+ if (result.validation) {
413
+ files.push({ path: 'api/validation.ts', content: result.validation });
414
+ }
415
+ if (result.errors) {
416
+ files.push({ path: 'api/errors.ts', content: result.errors });
417
+ }
418
+ }
419
+ // 3. Generate pages
420
+ if (ast.pages && ast.pages.length > 0) {
421
+ const result = generatePages(ast.pages, { framework, provenance, typescript });
422
+ for (const page of result.pages) {
423
+ files.push({ path: page.path, content: page.content });
424
+ }
425
+ }
426
+ // 4. Generate forms
427
+ if (ast.forms && ast.forms.length > 0) {
428
+ const result = generateForms(ast.forms, { ui, provenance, typescript, zod: true });
429
+ for (const form of result.forms) {
430
+ files.push({ path: form.path, content: form.content });
431
+ }
432
+ }
433
+ // 5. Generate components
434
+ if (ast.components && ast.components.length > 0) {
435
+ const result = generateComponents(ast.components, { provenance, typescript });
436
+ for (const component of result.components) {
437
+ files.push({ path: component.path, content: component.content });
438
+ }
439
+ }
440
+ // 6. Generate design tokens
441
+ if (ast.design) {
442
+ const result = generateDesign(ast.design, { format: 'both', provenance });
443
+ if (result.css)
444
+ files.push({ path: result.css.path, content: result.css.content });
445
+ if (result.tailwind)
446
+ files.push({ path: result.tailwind.path, content: result.tailwind.content });
447
+ }
448
+ const totalLines = files.reduce((sum, f) => sum + f.content.split('\n').length, 0);
449
+ return {
450
+ success: true,
451
+ files,
452
+ metadata: {
453
+ filesGenerated: files.length,
454
+ linesOfCode: totalLines,
455
+ estimatedTokensSaved: totalLines * 25 - 300,
456
+ },
457
+ };
458
+ }
459
+ catch (error) {
460
+ return {
461
+ success: false,
462
+ errors: [error instanceof Error ? error.message : String(error)],
463
+ };
464
+ }
465
+ }
@@ -16,6 +16,7 @@ import { createTask, listTasks, getTask, claimTask, releaseTask, updateTaskStatu
16
16
  import { detectTimedOutTasks, retryTask, failTask, autoRetryTimedOutTasks, } from '../helpers/tasks-retry.js';
17
17
  import { detectLibrariesFromPlan } from '../helpers/library-detection.js';
18
18
  import { handleGenerateApi, handleGenerateFrontend, handleGenerateComponent, handleListGenerators, handleValidateSpec, handleListPatterns, handleGetPattern, handleDetectPatterns, handleInitProject, } from './codedna-handlers.js';
19
+ import { handleKappaParse, handleKappaGenerateSchema, handleKappaGenerateApi, handleKappaGeneratePages, handleKappaGenerateForms, handleKappaGenerateComponents, handleKappaGenerateDesign, handleKappaGenerateAll, } from './kappa-handlers.js';
19
20
  export function registerToolHandlers(server) {
20
21
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
21
22
  const { name, arguments: args } = request.params;
@@ -912,6 +913,15 @@ export function registerToolHandlers(server) {
912
913
  const taskId = args?.task_id;
913
914
  const summary = args?.summary;
914
915
  const agentId = args?.agent_id || 'claude-code';
916
+ // Try to claim first in case task wasn't started via task_start
917
+ // This makes task_complete work standalone without requiring task_start
918
+ try {
919
+ await claimTask(DEFAULT_USER_ID, projectId, taskId, agentId, 5); // Short claim just for completion
920
+ }
921
+ catch {
922
+ // Ignore claim errors - task might already be claimed by this agent or another
923
+ // releaseTask will handle the actual authorization check
924
+ }
915
925
  // Add completion context
916
926
  await addTaskContext(DEFAULT_USER_ID, projectId, taskId, 'work_log', summary, agentId);
917
927
  // Release and mark as done
@@ -1980,6 +1990,117 @@ export function registerToolHandlers(server) {
1980
1990
  }],
1981
1991
  };
1982
1992
  }
1993
+ // =====================================================================
1994
+ // Kappa v2.5 DSL Tools
1995
+ // =====================================================================
1996
+ case 'kappa_parse': {
1997
+ const result = await handleKappaParse(args);
1998
+ mcpLogger.toolResult(name, true, timer());
1999
+ return {
2000
+ content: [{
2001
+ type: 'text',
2002
+ text: JSON.stringify(result, null, 2),
2003
+ }],
2004
+ };
2005
+ }
2006
+ case 'kappa_generate_schema': {
2007
+ const result = await handleKappaGenerateSchema(args);
2008
+ mcpLogger.toolResult(name, true, timer());
2009
+ let output = JSON.stringify(result, null, 2);
2010
+ if (workflowWarnings) {
2011
+ output += '\n\n' + workflowWarnings;
2012
+ }
2013
+ return {
2014
+ content: [{
2015
+ type: 'text',
2016
+ text: output,
2017
+ }],
2018
+ };
2019
+ }
2020
+ case 'kappa_generate_api': {
2021
+ const result = await handleKappaGenerateApi(args);
2022
+ mcpLogger.toolResult(name, true, timer());
2023
+ let output = JSON.stringify(result, null, 2);
2024
+ if (workflowWarnings) {
2025
+ output += '\n\n' + workflowWarnings;
2026
+ }
2027
+ return {
2028
+ content: [{
2029
+ type: 'text',
2030
+ text: output,
2031
+ }],
2032
+ };
2033
+ }
2034
+ case 'kappa_generate_pages': {
2035
+ const result = await handleKappaGeneratePages(args);
2036
+ mcpLogger.toolResult(name, true, timer());
2037
+ let output = JSON.stringify(result, null, 2);
2038
+ if (workflowWarnings) {
2039
+ output += '\n\n' + workflowWarnings;
2040
+ }
2041
+ return {
2042
+ content: [{
2043
+ type: 'text',
2044
+ text: output,
2045
+ }],
2046
+ };
2047
+ }
2048
+ case 'kappa_generate_forms': {
2049
+ const result = await handleKappaGenerateForms(args);
2050
+ mcpLogger.toolResult(name, true, timer());
2051
+ let output = JSON.stringify(result, null, 2);
2052
+ if (workflowWarnings) {
2053
+ output += '\n\n' + workflowWarnings;
2054
+ }
2055
+ return {
2056
+ content: [{
2057
+ type: 'text',
2058
+ text: output,
2059
+ }],
2060
+ };
2061
+ }
2062
+ case 'kappa_generate_components': {
2063
+ const result = await handleKappaGenerateComponents(args);
2064
+ mcpLogger.toolResult(name, true, timer());
2065
+ let output = JSON.stringify(result, null, 2);
2066
+ if (workflowWarnings) {
2067
+ output += '\n\n' + workflowWarnings;
2068
+ }
2069
+ return {
2070
+ content: [{
2071
+ type: 'text',
2072
+ text: output,
2073
+ }],
2074
+ };
2075
+ }
2076
+ case 'kappa_generate_design': {
2077
+ const result = await handleKappaGenerateDesign(args);
2078
+ mcpLogger.toolResult(name, true, timer());
2079
+ let output = JSON.stringify(result, null, 2);
2080
+ if (workflowWarnings) {
2081
+ output += '\n\n' + workflowWarnings;
2082
+ }
2083
+ return {
2084
+ content: [{
2085
+ type: 'text',
2086
+ text: output,
2087
+ }],
2088
+ };
2089
+ }
2090
+ case 'kappa_generate_all': {
2091
+ const result = await handleKappaGenerateAll(args);
2092
+ mcpLogger.toolResult(name, true, timer());
2093
+ let output = JSON.stringify(result, null, 2);
2094
+ if (workflowWarnings) {
2095
+ output += '\n\n' + workflowWarnings;
2096
+ }
2097
+ return {
2098
+ content: [{
2099
+ type: 'text',
2100
+ text: output,
2101
+ }],
2102
+ };
2103
+ }
1983
2104
  default:
1984
2105
  throw new Error(`Unknown tool: ${name}`);
1985
2106
  }
@@ -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. **Context is AUTO-INJECTED via hooks** - you rarely need to call memory tools explicitly.\n\n## \u26A0\uFE0F IMPORTANT: Hooks vs MCP Tools\n\n**AUTOMATIC (via hooks - zero context cost):**\n- Context injection \u2192 `user-prompt-submit` hook runs on every message\n- Fact extraction \u2192 `post-tool-use` hook extracts from your work\n- Session context \u2192 `session-start` hook provides initial context\n\n**EXPLICIT (MCP tools - costs context):**\n- `memory_store_fact` \u2192 Store a specific fact you learned\n- `task_plan` / `task_start` / `task_complete` \u2192 Task management\n\n**DO NOT CALL these tools routinely (context already injected):**\n- `memory_search` - only if you need DIFFERENT search params\n- `memory_inject` - only if you need to refresh for a different query\n- `memory_get_context` - only for debugging\n- `memory_index` - only for debugging\n\n## Storing Facts (DO use this)\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 when you learn something concrete. The `post-tool-use` hook also extracts facts automatically.\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### Start with codebase_map() - ALWAYS\n```\ncodebase_map() # FIRST TOOL when exploring unfamiliar code\n```\n**When to use:** Starting a new task, exploring unfamiliar code, understanding project structure, finding entry points.\n\nThe map shows:\n- Project structure and key directories\n- Entry points and their exports\n- Framework detection (React, Express, etc.)\n- Key symbols and their locations\n\n**Use codebase_map BEFORE using Grep/Glob** - it gives you the lay of the land so you know where to look.\n\n### Then use targeted tools\n```\ncodebase_find(\"UserService\") # Find specific symbols/files\ncodebase_context(\"src/auth.ts\") # Get file dependencies\nanalyze_impact(\"validateToken\") # See what changing a function affects\n```\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. **Trust auto-injection** - Context is injected automatically, don't call memory_search\n2. **Store decisions** - Use `memory_store_fact` for architectural choices\n3. **Use task tracking** - Break complex work into tasks\n4. **Use CodeDNA for APIs** - Generate instead of write (99% token savings)\n5. **Minimize tool calls** - Every MCP call costs context tokens\n<!-- CLAUDETOOLS:END -->\n";
8
+ export declare const GLOBAL_TEMPLATE = "\n<!-- CLAUDETOOLS:START -->\n# ClaudeTools Memory System\n\nYou have access to a persistent memory system. **Context is AUTO-INJECTED via hooks** - you rarely need to call memory tools explicitly.\n\n## \u26A0\uFE0F IMPORTANT: Hooks vs MCP Tools\n\n**AUTOMATIC (via hooks - zero context cost):**\n- Context injection \u2192 `user-prompt-submit` hook runs on every message\n- Fact extraction \u2192 `post-tool-use` hook extracts from your work\n- Session context \u2192 `session-start` hook provides initial context\n\n**EXPLICIT (MCP tools - costs context):**\n- `memory_store_fact` \u2192 Store a specific fact you learned\n- `task_plan` / `task_start` / `task_complete` \u2192 Task management\n\n**DO NOT CALL these tools routinely (context already injected):**\n- `memory_search` - only if you need DIFFERENT search params\n- `memory_inject` - only if you need to refresh for a different query\n- `memory_get_context` - only for debugging\n- `memory_index` - only for debugging\n\n## Storing Facts (DO use this)\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 when you learn something concrete. The `post-tool-use` hook also extracts facts automatically.\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### Start with codebase_map() - ALWAYS\n```\ncodebase_map() # FIRST TOOL when exploring unfamiliar code\n```\n**When to use:** Starting a new task, exploring unfamiliar code, understanding project structure, finding entry points.\n\nThe map shows:\n- Project structure and key directories\n- Entry points and their exports\n- Framework detection (React, Express, etc.)\n- Key symbols and their locations\n\n**Use codebase_map BEFORE using Grep/Glob** - it gives you the lay of the land so you know where to look.\n\n### Then use targeted tools\n```\ncodebase_find(\"UserService\") # Find specific symbols/files\ncodebase_context(\"src/auth.ts\") # Get file dependencies\nanalyze_impact(\"validateToken\") # See what changing a function affects\n```\n\n## CodeDNA: Generate Code, Save 99% Tokens\n\n**BEFORE writing ANY code, check if CodeDNA can generate it.** Call `codedna_list_generators()` to see available generators.\n\n### Available Generators (20+)\n\n| Category | Frameworks | Tool |\n|----------|------------|------|\n| **API** | Express, FastAPI, NestJS, Hono, Elysia, tRPC | `codedna_generate_api` |\n| **Frontend** | React, Vue, SvelteKit, Astro, React Router v7, TanStack Start | `codedna_generate_frontend` |\n| **ORM** | Prisma, Drizzle | `codedna_generate_api` with database option |\n| **Auth** | Better Auth, Auth.js, Lucia | `codedna_generate_api` with auth option |\n| **Components** | Forms, Tables, Cards, Modals (React/Vue/Svelte) | `codedna_generate_component` |\n\n### Usage Examples\n\n```typescript\n// API with auth and validation\ncodedna_generate_api({\n spec: \"User(email:string:unique, password:string:hashed)\",\n framework: \"express\", // or: fastapi, nestjs, hono, elysia, trpc\n options: { auth: true, validation: true, tests: true }\n})\n\n// Frontend with forms and data fetching\ncodedna_generate_frontend({\n spec: \"User(email:string, name:string, role:enum(admin,user))\",\n framework: \"react\", // or: vue, nextjs, sveltekit, astro\n options: { forms: true, tables: true, ui: \"shadcn\" }\n})\n\n// Single component\ncodedna_generate_component({\n spec: \"Product(name:string, price:decimal, inStock:boolean)\",\n type: \"form\", // or: table, card, modal\n framework: \"react\",\n options: { validation: true, ui: \"shadcn\" }\n})\n```\n\n### Entity DSL Quick Reference\n\n```\nEntityName(field:type:modifier, field2:type:modifier)\n\nTypes: string, integer, decimal, boolean, datetime, text, json\nModifiers: unique, required, optional, hashed, email, min(n), max(n), default(v)\nRelations: userId:User (reference), posts:Post[] (array)\nEnums: role:enum(admin,user,guest)\n```\n\n**Token savings:** 30,000 tokens \u2192 200 tokens (99% reduction per generation)\n\n## Kappa v2.5: Declarative Full-Stack Generation\n\n**For even higher-level generation**, use Kappa DSL - a declarative specification language that generates complete applications from compact specs.\n\n### When to Use Kappa vs CodeDNA\n\n| Use Case | Tool |\n|----------|------|\n| Single entity/component | CodeDNA (`codedna_generate_*`) |\n| Full application with multiple entities | Kappa (`kappa_generate_all`) |\n| Pages, forms, routing together | Kappa |\n| Design system + components | Kappa |\n\n### Kappa Tools\n\n| Tool | Purpose |\n|------|---------|\n| `kappa_parse` | Parse and validate Kappa spec |\n| `kappa_generate_schema` | Generate Drizzle schema + Zod + types |\n| `kappa_generate_api` | Generate API routes (Hono/Express/tRPC) |\n| `kappa_generate_pages` | Generate pages (TanStack Start/Next.js) |\n| `kappa_generate_forms` | Generate forms (React Hook Form + Zod + shadcn) |\n| `kappa_generate_components` | Generate React components (compound, forwardRef) |\n| `kappa_generate_design` | Generate CSS variables + Tailwind config |\n| `kappa_generate_all` | Generate complete full-stack application |\n\n### Kappa DSL Example\n\n```\n// Complete app specification in ~50 lines\nproject TaskManager {\n database postgres\n framework tanstack-start\n}\n\nentity Task {\n title string required max(100)\n description text\n status enum(todo, in_progress, done) default(todo)\n dueDate datetime\n assignee User\n}\n\nentity User {\n email string unique email\n name string required\n tasks Task[]\n}\n\napi /tasks {\n GET / -> list Task[]\n POST / -> create Task\n GET /:id -> get Task\n PUT /:id -> update Task\n DELETE /:id -> delete Task\n}\n\npage /tasks {\n layout dashboard\n load tasks from /api/tasks\n components [TaskList, TaskForm]\n}\n\nform TaskForm for Task {\n fields [title, description, status, dueDate]\n submit POST /api/tasks\n}\n\ndesign {\n colors {\n primary #3B82F6\n secondary #6B7280\n }\n typography {\n fontFamily \"Inter\"\n scale { sm: \"0.875rem\", base: \"1rem\", lg: \"1.125rem\" }\n }\n}\n```\n\n### Usage\n\n```typescript\n// Generate everything from spec\nkappa_generate_all({\n spec: `project MyApp { ... }`,\n options: {\n framework: \"tanstack-start\",\n ui: \"shadcn\",\n dbDialect: \"postgres\"\n }\n})\n\n// Or generate incrementally\nkappa_parse({ spec: \"...\" }) // Validate first\nkappa_generate_schema({ spec: \"...\", outputs: [\"drizzle\", \"zod\", \"types\"] })\nkappa_generate_api({ spec: \"...\", framework: \"hono\" })\nkappa_generate_pages({ spec: \"...\", framework: \"tanstack-start\" })\n```\n\n**Token savings:** ~50 lines of Kappa \u2192 thousands of lines of production code (95%+ reduction)\n\n## Best Practices\n\n1. **Trust auto-injection** - Context is injected automatically, don't call memory_search\n2. **Store decisions** - Use `memory_store_fact` for architectural choices\n3. **Use task tracking** - Break complex work into tasks\n4. **Use Kappa for full apps** - For multi-entity apps with pages/forms, use `kappa_generate_all`\n5. **Use CodeDNA for single components** - For individual entities or components, use `codedna_generate_*`\n6. **Minimize tool calls** - Every MCP call costs context tokens\n<!-- CLAUDETOOLS:END -->\n";
9
9
  /**
10
10
  * Project-level CLAUDE.md content - added to .claude/CLAUDE.md
11
11
  */