@claudetools/tools 0.8.10 → 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.
- package/dist/codedna/generators/astro.d.ts +18 -0
- package/dist/codedna/generators/astro.js +91 -0
- package/dist/codedna/generators/authjs.d.ts +18 -0
- package/dist/codedna/generators/authjs.js +68 -0
- package/dist/codedna/generators/better-auth.d.ts +18 -0
- package/dist/codedna/generators/better-auth.js +62 -0
- package/dist/codedna/generators/drizzle-orm.d.ts +18 -0
- package/dist/codedna/generators/drizzle-orm.js +65 -0
- package/dist/codedna/generators/elysia-api.d.ts +12 -0
- package/dist/codedna/generators/elysia-api.js +64 -0
- package/dist/codedna/generators/hono-api.d.ts +12 -0
- package/dist/codedna/generators/hono-api.js +64 -0
- package/dist/codedna/generators/lucia-auth.d.ts +18 -0
- package/dist/codedna/generators/lucia-auth.js +69 -0
- package/dist/codedna/generators/prisma.d.ts +18 -0
- package/dist/codedna/generators/prisma.js +64 -0
- package/dist/codedna/generators/react-router-v7.d.ts +18 -0
- package/dist/codedna/generators/react-router-v7.js +77 -0
- package/dist/codedna/generators/react19-shadcn.d.ts +21 -0
- package/dist/codedna/generators/react19-shadcn.js +367 -0
- package/dist/codedna/generators/sveltekit.d.ts +18 -0
- package/dist/codedna/generators/sveltekit.js +73 -0
- package/dist/codedna/generators/tanstack-start-drizzle.d.ts +92 -0
- package/dist/codedna/generators/tanstack-start-drizzle.js +824 -0
- package/dist/codedna/generators/trpc-api.d.ts +12 -0
- package/dist/codedna/generators/trpc-api.js +64 -0
- package/dist/codedna/index.d.ts +31 -0
- package/dist/codedna/index.js +39 -0
- package/dist/codedna/kappa-api-generator.d.ts +89 -0
- package/dist/codedna/kappa-api-generator.js +493 -0
- package/dist/codedna/kappa-ast.d.ts +552 -0
- package/dist/codedna/kappa-ast.js +141 -0
- package/dist/codedna/kappa-cli.d.ts +2 -0
- package/dist/codedna/kappa-cli.js +302 -0
- package/dist/codedna/kappa-component-generator.d.ts +47 -0
- package/dist/codedna/kappa-component-generator.js +295 -0
- package/dist/codedna/kappa-design-generator.d.ts +52 -0
- package/dist/codedna/kappa-design-generator.js +365 -0
- package/dist/codedna/kappa-drizzle-generator.d.ts +45 -0
- package/dist/codedna/kappa-drizzle-generator.js +355 -0
- package/dist/codedna/kappa-form-generator.d.ts +51 -0
- package/dist/codedna/kappa-form-generator.js +319 -0
- package/dist/codedna/kappa-lexer.d.ts +268 -0
- package/dist/codedna/kappa-lexer.js +757 -0
- package/dist/codedna/kappa-page-generator.d.ts +57 -0
- package/dist/codedna/kappa-page-generator.js +338 -0
- package/dist/codedna/kappa-parser.d.ts +261 -0
- package/dist/codedna/kappa-parser.js +2547 -0
- package/dist/codedna/kappa-provenance.d.ts +101 -0
- package/dist/codedna/kappa-provenance.js +199 -0
- package/dist/codedna/kappa-types-generator.d.ts +37 -0
- package/dist/codedna/kappa-types-generator.js +159 -0
- package/dist/codedna/kappa-validator.d.ts +86 -0
- package/dist/codedna/kappa-validator.js +638 -0
- package/dist/codedna/kappa-zod-generator.d.ts +32 -0
- package/dist/codedna/kappa-zod-generator.js +216 -0
- package/dist/handlers/codedna-handlers.d.ts +1 -1
- package/dist/handlers/kappa-handlers.d.ts +116 -0
- package/dist/handlers/kappa-handlers.js +465 -0
- package/dist/handlers/tool-handlers.js +121 -0
- package/dist/templates/claude-md.d.ts +1 -1
- package/dist/templates/claude-md.js +166 -9
- package/dist/tools.js +199 -0
- package/docs/research/2026-01-02-codedna-il-specification.md +639 -0
- package/docs/research/2026-01-02-codedna-v2-research.md +943 -0
- package/docs/research/2026-01-02-computation-foundations.md +564 -0
- package/docs/research/2026-01-02-hardware-description.md +814 -0
- package/docs/research/2026-01-02-kappa-specification.md +697 -0
- package/docs/research/2026-01-02-kappa-tanstack-example.md +527 -0
- package/docs/research/2026-01-02-kappa-v2-synthesis.md +406 -0
- package/docs/research/2026-01-02-kappa-v2.5-specification.md +1218 -0
- package/docs/research/2026-01-02-kappa-v3-specification.md +1864 -0
- package/docs/research/2026-01-02-kappa-whitepaper.md +662 -0
- package/docs/research/2026-01-02-logic-constraint.md +731 -0
- package/docs/research/2026-01-02-quantum-computation.md +635 -0
- package/package.json +4 -2
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// Kappa v2.5 Zod Schema Generator
|
|
3
|
+
// =============================================================================
|
|
4
|
+
//
|
|
5
|
+
// Generates Zod validation schemas from Kappa entity blocks.
|
|
6
|
+
// Creates insert/update schemas with proper constraints.
|
|
7
|
+
//
|
|
8
|
+
// =============================================================================
|
|
9
|
+
// Generator Class
|
|
10
|
+
// =============================================================================
|
|
11
|
+
export class KappaZodGenerator {
|
|
12
|
+
provenance;
|
|
13
|
+
updateSchemas;
|
|
14
|
+
formSchemas;
|
|
15
|
+
constructor(options = {}) {
|
|
16
|
+
this.provenance = options.provenance ?? true;
|
|
17
|
+
this.updateSchemas = options.updateSchemas ?? true;
|
|
18
|
+
this.formSchemas = options.formSchemas ?? false;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Generate Zod schemas from entity blocks
|
|
22
|
+
*/
|
|
23
|
+
generate(entities) {
|
|
24
|
+
const schemas = this.generateSchemasFile(entities);
|
|
25
|
+
return { schemas };
|
|
26
|
+
}
|
|
27
|
+
// ===========================================================================
|
|
28
|
+
// Schemas File Generation
|
|
29
|
+
// ===========================================================================
|
|
30
|
+
generateSchemasFile(entities) {
|
|
31
|
+
const lines = [];
|
|
32
|
+
// Header comment
|
|
33
|
+
if (this.provenance) {
|
|
34
|
+
lines.push('// Generated by Kappa v2.5 CodeDNA');
|
|
35
|
+
lines.push(`// Generated at: ${new Date().toISOString()}`);
|
|
36
|
+
lines.push('');
|
|
37
|
+
}
|
|
38
|
+
// Import Zod
|
|
39
|
+
lines.push("import { z } from 'zod';");
|
|
40
|
+
lines.push('');
|
|
41
|
+
// Generate schemas for each entity
|
|
42
|
+
for (const entity of entities) {
|
|
43
|
+
lines.push(this.generateEntitySchemas(entity));
|
|
44
|
+
lines.push('');
|
|
45
|
+
}
|
|
46
|
+
return lines.join('\n');
|
|
47
|
+
}
|
|
48
|
+
generateEntitySchemas(entity) {
|
|
49
|
+
const lines = [];
|
|
50
|
+
const schemaName = `${entity.name}Schema`;
|
|
51
|
+
// Main schema (for select/read)
|
|
52
|
+
lines.push(`// ${entity.name} schemas`);
|
|
53
|
+
lines.push(`export const ${schemaName} = z.object({`);
|
|
54
|
+
for (const field of entity.fields) {
|
|
55
|
+
lines.push(` ${field.name}: ${this.generateFieldSchema(field)},`);
|
|
56
|
+
}
|
|
57
|
+
lines.push('});');
|
|
58
|
+
lines.push('');
|
|
59
|
+
// Insert schema (excludes auto-generated fields)
|
|
60
|
+
const insertSchemaName = `Insert${entity.name}Schema`;
|
|
61
|
+
const insertFields = entity.fields.filter(f => !f.modifiers.includes('auto'));
|
|
62
|
+
lines.push(`export const ${insertSchemaName} = z.object({`);
|
|
63
|
+
for (const field of insertFields) {
|
|
64
|
+
const schema = this.generateFieldSchema(field, { forInsert: true });
|
|
65
|
+
lines.push(` ${field.name}: ${schema},`);
|
|
66
|
+
}
|
|
67
|
+
lines.push('});');
|
|
68
|
+
// Update schema (all fields optional)
|
|
69
|
+
if (this.updateSchemas) {
|
|
70
|
+
lines.push('');
|
|
71
|
+
const updateSchemaName = `Update${entity.name}Schema`;
|
|
72
|
+
lines.push(`export const ${updateSchemaName} = ${insertSchemaName}.partial();`);
|
|
73
|
+
}
|
|
74
|
+
// Form schema (for frontend forms)
|
|
75
|
+
if (this.formSchemas) {
|
|
76
|
+
lines.push('');
|
|
77
|
+
const formSchemaName = `${entity.name}FormSchema`;
|
|
78
|
+
lines.push(`export const ${formSchemaName} = ${insertSchemaName};`);
|
|
79
|
+
}
|
|
80
|
+
// Type exports
|
|
81
|
+
lines.push('');
|
|
82
|
+
lines.push(`export type ${entity.name} = z.infer<typeof ${schemaName}>;`);
|
|
83
|
+
lines.push(`export type Insert${entity.name} = z.infer<typeof ${insertSchemaName}>;`);
|
|
84
|
+
if (this.updateSchemas) {
|
|
85
|
+
lines.push(`export type Update${entity.name} = z.infer<typeof Update${entity.name}Schema>;`);
|
|
86
|
+
}
|
|
87
|
+
return lines.join('\n');
|
|
88
|
+
}
|
|
89
|
+
generateFieldSchema(field, options = {}) {
|
|
90
|
+
const { type, modifiers } = field;
|
|
91
|
+
let schema = this.typeToZodSchema(type, field.name);
|
|
92
|
+
// Handle optional modifier
|
|
93
|
+
const isOptional = modifiers.includes('optional');
|
|
94
|
+
const isPrimary = modifiers.includes('primary');
|
|
95
|
+
const isAuto = modifiers.includes('auto');
|
|
96
|
+
// For insert schemas, primary keys with auto are optional
|
|
97
|
+
if (options.forInsert && isPrimary && isAuto) {
|
|
98
|
+
schema = `${schema}.optional()`;
|
|
99
|
+
}
|
|
100
|
+
else if (isOptional) {
|
|
101
|
+
schema = `${schema}.optional()`;
|
|
102
|
+
}
|
|
103
|
+
// Add nullable if needed (optional fields can be null)
|
|
104
|
+
if (isOptional) {
|
|
105
|
+
schema = `${schema}.nullable()`;
|
|
106
|
+
}
|
|
107
|
+
return schema;
|
|
108
|
+
}
|
|
109
|
+
typeToZodSchema(type, fieldName) {
|
|
110
|
+
switch (type.kind) {
|
|
111
|
+
case 'primitive':
|
|
112
|
+
return this.primitiveToZod(type.type, type.range, fieldName);
|
|
113
|
+
case 'enum':
|
|
114
|
+
const enumValues = type.values.map(v => `'${v}'`).join(', ');
|
|
115
|
+
return `z.enum([${enumValues}])`;
|
|
116
|
+
case 'reference':
|
|
117
|
+
// Reference fields are typically UUIDs
|
|
118
|
+
return "z.string().uuid()";
|
|
119
|
+
case 'array':
|
|
120
|
+
const itemSchema = this.typeToZodSchema(type.itemType, fieldName);
|
|
121
|
+
return `z.array(${itemSchema})`;
|
|
122
|
+
default:
|
|
123
|
+
return 'z.unknown()';
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
primitiveToZod(primitiveType, range, fieldName) {
|
|
127
|
+
let schema;
|
|
128
|
+
switch (primitiveType) {
|
|
129
|
+
case 'string':
|
|
130
|
+
schema = 'z.string()';
|
|
131
|
+
if (range) {
|
|
132
|
+
if (range.min !== undefined) {
|
|
133
|
+
schema += `.min(${range.min})`;
|
|
134
|
+
}
|
|
135
|
+
if (range.max !== undefined) {
|
|
136
|
+
schema += `.max(${range.max})`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
case 'int':
|
|
141
|
+
schema = 'z.number().int()';
|
|
142
|
+
if (range) {
|
|
143
|
+
if (range.min !== undefined) {
|
|
144
|
+
schema += `.min(${range.min})`;
|
|
145
|
+
}
|
|
146
|
+
if (range.max !== undefined) {
|
|
147
|
+
schema += `.max(${range.max})`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
break;
|
|
151
|
+
case 'float':
|
|
152
|
+
schema = 'z.number()';
|
|
153
|
+
if (range) {
|
|
154
|
+
if (range.min !== undefined) {
|
|
155
|
+
schema += `.min(${range.min})`;
|
|
156
|
+
}
|
|
157
|
+
if (range.max !== undefined) {
|
|
158
|
+
schema += `.max(${range.max})`;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
case 'bool':
|
|
163
|
+
schema = 'z.boolean()';
|
|
164
|
+
break;
|
|
165
|
+
case 'email':
|
|
166
|
+
schema = 'z.string().email()';
|
|
167
|
+
break;
|
|
168
|
+
case 'url':
|
|
169
|
+
schema = 'z.string().url()';
|
|
170
|
+
break;
|
|
171
|
+
case 'uuid':
|
|
172
|
+
schema = 'z.string().uuid()';
|
|
173
|
+
break;
|
|
174
|
+
case 'phone':
|
|
175
|
+
// Basic phone validation - allows common formats
|
|
176
|
+
schema = "z.string().regex(/^\\+?[0-9\\s\\-()]+$/, 'Invalid phone number')";
|
|
177
|
+
break;
|
|
178
|
+
case 'slug':
|
|
179
|
+
// Slug validation - lowercase, hyphens, numbers
|
|
180
|
+
schema = "z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, 'Invalid slug format')";
|
|
181
|
+
break;
|
|
182
|
+
case 'markdown':
|
|
183
|
+
schema = 'z.string()';
|
|
184
|
+
break;
|
|
185
|
+
case 'json':
|
|
186
|
+
schema = 'z.record(z.unknown())';
|
|
187
|
+
break;
|
|
188
|
+
case 'timestamp':
|
|
189
|
+
schema = 'z.date()';
|
|
190
|
+
break;
|
|
191
|
+
case 'date':
|
|
192
|
+
schema = 'z.string().date()';
|
|
193
|
+
break;
|
|
194
|
+
case 'time':
|
|
195
|
+
schema = 'z.string().time()';
|
|
196
|
+
break;
|
|
197
|
+
case 'duration':
|
|
198
|
+
// Duration as ISO 8601 string (e.g., "P1D", "PT1H30M")
|
|
199
|
+
schema = "z.string().regex(/^P(?:\\d+Y)?(?:\\d+M)?(?:\\d+D)?(?:T(?:\\d+H)?(?:\\d+M)?(?:\\d+S)?)?$/, 'Invalid duration')";
|
|
200
|
+
break;
|
|
201
|
+
default:
|
|
202
|
+
schema = 'z.string()';
|
|
203
|
+
}
|
|
204
|
+
return schema;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// =============================================================================
|
|
208
|
+
// Convenience Function
|
|
209
|
+
// =============================================================================
|
|
210
|
+
/**
|
|
211
|
+
* Generate Zod schemas from Kappa entities
|
|
212
|
+
*/
|
|
213
|
+
export function generateZodSchemas(entities, options = {}) {
|
|
214
|
+
const generator = new KappaZodGenerator(options);
|
|
215
|
+
return generator.generate(entities);
|
|
216
|
+
}
|
|
@@ -213,7 +213,7 @@ export declare function handleValidateSpec(args: any): Promise<{
|
|
|
213
213
|
fields: {
|
|
214
214
|
name: string;
|
|
215
215
|
type: import("../codedna/parser.js").FieldType;
|
|
216
|
-
constraints: ("default" | "length" | "email" | "min" | "max" | "url" | "
|
|
216
|
+
constraints: ("default" | "length" | "email" | "min" | "max" | "url" | "required" | "pattern" | "nullable" | "unique" | "hashed" | "index" | "immutable" | "textarea" | "switch" | "radio")[];
|
|
217
217
|
}[];
|
|
218
218
|
};
|
|
219
219
|
summary: {
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { KappaSpec } from '../codedna/kappa-ast.js';
|
|
2
|
+
export interface KappaGenerateResult {
|
|
3
|
+
success: boolean;
|
|
4
|
+
files?: Array<{
|
|
5
|
+
path: string;
|
|
6
|
+
content: string;
|
|
7
|
+
}>;
|
|
8
|
+
errors?: string[];
|
|
9
|
+
metadata?: {
|
|
10
|
+
filesGenerated: number;
|
|
11
|
+
linesOfCode: number;
|
|
12
|
+
estimatedTokensSaved: number;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Handle kappa_parse tool call
|
|
17
|
+
* Parses and validates a Kappa specification
|
|
18
|
+
*/
|
|
19
|
+
export declare function handleKappaParse(args: {
|
|
20
|
+
spec: string;
|
|
21
|
+
}): Promise<{
|
|
22
|
+
success: boolean;
|
|
23
|
+
ast?: KappaSpec;
|
|
24
|
+
errors?: string[];
|
|
25
|
+
summary?: Record<string, unknown>;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Handle kappa_generate_schema tool call
|
|
29
|
+
* Generates Drizzle schema, Zod validators, and TypeScript types
|
|
30
|
+
*/
|
|
31
|
+
export declare function handleKappaGenerateSchema(args: {
|
|
32
|
+
spec: string;
|
|
33
|
+
outputs?: ('drizzle' | 'zod' | 'types')[];
|
|
34
|
+
options?: {
|
|
35
|
+
provenance?: boolean;
|
|
36
|
+
dbDialect?: 'sqlite' | 'postgres' | 'postgresql' | 'mysql';
|
|
37
|
+
};
|
|
38
|
+
}): Promise<KappaGenerateResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Handle kappa_generate_api tool call
|
|
41
|
+
* Generates API routes from Kappa API blocks
|
|
42
|
+
*/
|
|
43
|
+
export declare function handleKappaGenerateApi(args: {
|
|
44
|
+
spec: string;
|
|
45
|
+
framework?: 'hono' | 'express' | 'trpc';
|
|
46
|
+
options?: {
|
|
47
|
+
provenance?: boolean;
|
|
48
|
+
typescript?: boolean;
|
|
49
|
+
};
|
|
50
|
+
}): Promise<KappaGenerateResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Handle kappa_generate_pages tool call
|
|
53
|
+
* Generates page/route components for TanStack Start or Next.js
|
|
54
|
+
*/
|
|
55
|
+
export declare function handleKappaGeneratePages(args: {
|
|
56
|
+
spec: string;
|
|
57
|
+
framework?: 'tanstack-start' | 'nextjs';
|
|
58
|
+
options?: {
|
|
59
|
+
provenance?: boolean;
|
|
60
|
+
typescript?: boolean;
|
|
61
|
+
};
|
|
62
|
+
}): Promise<KappaGenerateResult>;
|
|
63
|
+
/**
|
|
64
|
+
* Handle kappa_generate_forms tool call
|
|
65
|
+
* Generates React forms with React Hook Form and Zod validation
|
|
66
|
+
*/
|
|
67
|
+
export declare function handleKappaGenerateForms(args: {
|
|
68
|
+
spec: string;
|
|
69
|
+
ui?: 'shadcn' | 'plain';
|
|
70
|
+
options?: {
|
|
71
|
+
provenance?: boolean;
|
|
72
|
+
typescript?: boolean;
|
|
73
|
+
zod?: boolean;
|
|
74
|
+
};
|
|
75
|
+
}): Promise<KappaGenerateResult>;
|
|
76
|
+
/**
|
|
77
|
+
* Handle kappa_generate_components tool call
|
|
78
|
+
* Generates React components including compound components
|
|
79
|
+
*/
|
|
80
|
+
export declare function handleKappaGenerateComponents(args: {
|
|
81
|
+
spec: string;
|
|
82
|
+
options?: {
|
|
83
|
+
provenance?: boolean;
|
|
84
|
+
typescript?: boolean;
|
|
85
|
+
forwardRef?: boolean;
|
|
86
|
+
basePath?: string;
|
|
87
|
+
};
|
|
88
|
+
}): Promise<KappaGenerateResult>;
|
|
89
|
+
/**
|
|
90
|
+
* Handle kappa_generate_design tool call
|
|
91
|
+
* Generates CSS variables and Tailwind config from design tokens
|
|
92
|
+
*/
|
|
93
|
+
export declare function handleKappaGenerateDesign(args: {
|
|
94
|
+
spec: string;
|
|
95
|
+
format?: 'css' | 'tailwind' | 'both';
|
|
96
|
+
options?: {
|
|
97
|
+
provenance?: boolean;
|
|
98
|
+
prefix?: string;
|
|
99
|
+
hsl?: boolean;
|
|
100
|
+
};
|
|
101
|
+
}): Promise<KappaGenerateResult>;
|
|
102
|
+
/**
|
|
103
|
+
* Handle kappa_generate_all tool call
|
|
104
|
+
* Generates complete full-stack application from Kappa specification
|
|
105
|
+
*/
|
|
106
|
+
export declare function handleKappaGenerateAll(args: {
|
|
107
|
+
spec: string;
|
|
108
|
+
options?: {
|
|
109
|
+
framework?: 'tanstack-start' | 'nextjs';
|
|
110
|
+
apiFramework?: 'hono' | 'express' | 'trpc';
|
|
111
|
+
ui?: 'shadcn' | 'plain';
|
|
112
|
+
dbDialect?: 'sqlite' | 'postgres' | 'postgresql' | 'mysql';
|
|
113
|
+
provenance?: boolean;
|
|
114
|
+
typescript?: boolean;
|
|
115
|
+
};
|
|
116
|
+
}): Promise<KappaGenerateResult>;
|