@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,355 @@
1
+ // =============================================================================
2
+ // Kappa v2.5 Drizzle Schema Generator
3
+ // =============================================================================
4
+ //
5
+ // Generates Drizzle ORM schema code from Kappa entity blocks.
6
+ // Supports PostgreSQL, MySQL, and SQLite dialects.
7
+ //
8
+ // =============================================================================
9
+ // Type Mappings
10
+ // =============================================================================
11
+ const DRIZZLE_IMPORTS = {
12
+ postgresql: 'drizzle-orm/pg-core',
13
+ mysql: 'drizzle-orm/mysql-core',
14
+ sqlite: 'drizzle-orm/sqlite-core',
15
+ };
16
+ const PRIMITIVE_TYPE_MAP = {
17
+ postgresql: {
18
+ string: 'text',
19
+ int: 'integer',
20
+ float: 'real',
21
+ bool: 'boolean',
22
+ email: 'text',
23
+ url: 'text',
24
+ uuid: 'uuid',
25
+ phone: 'text',
26
+ slug: 'text',
27
+ markdown: 'text',
28
+ json: 'jsonb',
29
+ timestamp: 'timestamp',
30
+ date: 'date',
31
+ time: 'time',
32
+ duration: 'interval',
33
+ },
34
+ mysql: {
35
+ string: 'text',
36
+ int: 'int',
37
+ float: 'double',
38
+ bool: 'boolean',
39
+ email: 'varchar(255)',
40
+ url: 'text',
41
+ uuid: 'varchar(36)',
42
+ phone: 'varchar(20)',
43
+ slug: 'varchar(255)',
44
+ markdown: 'text',
45
+ json: 'json',
46
+ timestamp: 'timestamp',
47
+ date: 'date',
48
+ time: 'time',
49
+ duration: 'varchar(50)',
50
+ },
51
+ sqlite: {
52
+ string: 'text',
53
+ int: 'integer',
54
+ float: 'real',
55
+ bool: 'integer', // SQLite uses 0/1
56
+ email: 'text',
57
+ url: 'text',
58
+ uuid: 'text',
59
+ phone: 'text',
60
+ slug: 'text',
61
+ markdown: 'text',
62
+ json: 'text', // JSON stored as text
63
+ timestamp: 'integer', // Unix timestamp
64
+ date: 'text', // ISO date string
65
+ time: 'text',
66
+ duration: 'text',
67
+ },
68
+ };
69
+ // =============================================================================
70
+ // Generator Class
71
+ // =============================================================================
72
+ export class KappaDrizzleGenerator {
73
+ dialect;
74
+ provenance;
75
+ generateRelations;
76
+ constructor(options = {}) {
77
+ this.dialect = options.dialect ?? 'postgresql';
78
+ this.provenance = options.provenance ?? true;
79
+ this.generateRelations = options.relations ?? true;
80
+ }
81
+ /**
82
+ * Generate Drizzle schema from entity blocks
83
+ */
84
+ generate(entities) {
85
+ const schema = this.generateSchemaFile(entities);
86
+ const types = this.generateTypesFile(entities);
87
+ const result = { schema, types };
88
+ if (this.generateRelations) {
89
+ result.relations = this.generateRelationsFile(entities);
90
+ }
91
+ return result;
92
+ }
93
+ // ===========================================================================
94
+ // Schema File Generation
95
+ // ===========================================================================
96
+ generateSchemaFile(entities) {
97
+ const lines = [];
98
+ // Header comment
99
+ if (this.provenance) {
100
+ lines.push('// Generated by Kappa v2.5 CodeDNA');
101
+ lines.push(`// Dialect: ${this.dialect}`);
102
+ lines.push(`// Generated at: ${new Date().toISOString()}`);
103
+ lines.push('');
104
+ }
105
+ // Imports
106
+ lines.push(this.generateSchemaImports(entities));
107
+ lines.push('');
108
+ // Generate each table
109
+ for (const entity of entities) {
110
+ lines.push(this.generateTable(entity));
111
+ lines.push('');
112
+ }
113
+ return lines.join('\n');
114
+ }
115
+ generateSchemaImports(entities) {
116
+ const importPath = DRIZZLE_IMPORTS[this.dialect];
117
+ const columnTypes = new Set();
118
+ // Collect all column types used
119
+ for (const entity of entities) {
120
+ for (const field of entity.fields) {
121
+ const colType = this.getColumnTypeFunction(field.type);
122
+ columnTypes.add(colType);
123
+ }
124
+ // Add relation types
125
+ for (const rel of entity.relationships) {
126
+ if (rel.type === 'belongs_to') {
127
+ columnTypes.add(this.getColumnTypeFunction({ kind: 'primitive', type: 'uuid' }));
128
+ }
129
+ }
130
+ }
131
+ // Always include table function
132
+ const imports = [this.getTableFunction(), ...Array.from(columnTypes).sort()];
133
+ // Add relations import if needed
134
+ if (this.generateRelations) {
135
+ imports.push('relations');
136
+ }
137
+ return `import { ${imports.join(', ')} } from '${importPath}';`;
138
+ }
139
+ getTableFunction() {
140
+ switch (this.dialect) {
141
+ case 'postgresql':
142
+ return 'pgTable';
143
+ case 'mysql':
144
+ return 'mysqlTable';
145
+ case 'sqlite':
146
+ return 'sqliteTable';
147
+ }
148
+ }
149
+ generateTable(entity) {
150
+ const tableName = this.toSnakeCase(entity.name);
151
+ const tableFunc = this.getTableFunction();
152
+ const lines = [];
153
+ lines.push(`export const ${tableName} = ${tableFunc}('${tableName}', {`);
154
+ // Generate columns
155
+ for (const field of entity.fields) {
156
+ lines.push(` ${this.generateColumn(field, entity)},`);
157
+ }
158
+ // Generate foreign key columns for belongs_to relationships
159
+ for (const rel of entity.relationships) {
160
+ if (rel.type === 'belongs_to') {
161
+ lines.push(` ${this.generateForeignKeyColumn(rel)},`);
162
+ }
163
+ }
164
+ lines.push('});');
165
+ // Generate indexes if any
166
+ if (entity.indexes.length > 0) {
167
+ lines.push('');
168
+ lines.push(this.generateIndexes(entity));
169
+ }
170
+ return lines.join('\n');
171
+ }
172
+ generateColumn(field, entity) {
173
+ const { name, type, modifiers } = field;
174
+ const colName = this.toSnakeCase(name);
175
+ const colType = this.getColumnTypeFunction(type);
176
+ const colTypeCall = this.getColumnTypeCall(type, colName);
177
+ const chainMethods = [];
178
+ // Handle modifiers
179
+ if (modifiers.includes('primary')) {
180
+ chainMethods.push('primaryKey()');
181
+ }
182
+ if (modifiers.includes('auto')) {
183
+ if (type.kind === 'primitive' && type.type === 'uuid') {
184
+ chainMethods.push('defaultRandom()');
185
+ }
186
+ else if (type.kind === 'primitive' && (type.type === 'int' || type.type === 'timestamp')) {
187
+ if (type.type === 'timestamp') {
188
+ chainMethods.push('defaultNow()');
189
+ }
190
+ }
191
+ }
192
+ if (modifiers.includes('unique')) {
193
+ chainMethods.push('unique()');
194
+ }
195
+ if (!modifiers.includes('optional') && !modifiers.includes('primary')) {
196
+ chainMethods.push('notNull()');
197
+ }
198
+ // Handle default values for enums
199
+ if (type.kind === 'enum' && type.defaultValue) {
200
+ chainMethods.push(`default('${type.defaultValue}')`);
201
+ }
202
+ const chain = chainMethods.length > 0 ? '.' + chainMethods.join('.') : '';
203
+ return `${colName}: ${colTypeCall}${chain}`;
204
+ }
205
+ generateForeignKeyColumn(rel) {
206
+ // Derive FK column name from relationship entity (foreignKey field doesn't exist in AST)
207
+ const colName = `${this.toSnakeCase(rel.entity)}_id`;
208
+ const refTable = this.toSnakeCase(rel.entity);
209
+ if (this.dialect === 'postgresql') {
210
+ return `${colName}: uuid('${colName}').references(() => ${refTable}.id)`;
211
+ }
212
+ else {
213
+ return `${colName}: text('${colName}').references(() => ${refTable}.id)`;
214
+ }
215
+ }
216
+ getColumnTypeFunction(type) {
217
+ switch (type.kind) {
218
+ case 'primitive':
219
+ return PRIMITIVE_TYPE_MAP[this.dialect][type.type];
220
+ case 'enum':
221
+ return 'text'; // Enums as text with check constraint
222
+ case 'reference':
223
+ return this.dialect === 'postgresql' ? 'uuid' : 'text';
224
+ case 'array':
225
+ return this.dialect === 'postgresql' ? 'jsonb' : 'text';
226
+ default:
227
+ return 'text';
228
+ }
229
+ }
230
+ getColumnTypeCall(type, colName) {
231
+ const baseType = this.getColumnTypeFunction(type);
232
+ // Handle range constraints for strings
233
+ if (type.kind === 'primitive' && type.range && this.dialect !== 'sqlite') {
234
+ if (type.type === 'string' && type.range.max) {
235
+ return `varchar('${colName}', { length: ${type.range.max} })`;
236
+ }
237
+ }
238
+ return `${baseType}('${colName}')`;
239
+ }
240
+ generateIndexes(entity) {
241
+ const tableName = this.toSnakeCase(entity.name);
242
+ const lines = [];
243
+ for (const index of entity.indexes) {
244
+ // EntityIndex only has fields and unique, so construct name from fields
245
+ const indexName = `${tableName}_${index.fields.join('_')}_idx`;
246
+ const fields = index.fields.map(f => `${tableName}.${this.toSnakeCase(f)}`).join(', ');
247
+ const unique = index.unique ? '.unique()' : '';
248
+ lines.push(`// Index: ${indexName}`);
249
+ lines.push(`export const ${indexName} = index('${indexName}').on(${fields})${unique};`);
250
+ }
251
+ return lines.join('\n');
252
+ }
253
+ // ===========================================================================
254
+ // Relations File Generation
255
+ // ===========================================================================
256
+ generateRelationsFile(entities) {
257
+ const lines = [];
258
+ if (this.provenance) {
259
+ lines.push('// Generated by Kappa v2.5 CodeDNA');
260
+ lines.push('// Drizzle Relations');
261
+ lines.push('');
262
+ }
263
+ // Import relations helper
264
+ lines.push(`import { relations } from 'drizzle-orm';`);
265
+ // Import all tables
266
+ const tableImports = entities.map(e => this.toSnakeCase(e.name)).join(', ');
267
+ lines.push(`import { ${tableImports} } from './schema';`);
268
+ lines.push('');
269
+ // Generate relations for each entity
270
+ for (const entity of entities) {
271
+ if (entity.relationships.length > 0) {
272
+ lines.push(this.generateEntityRelations(entity, entities));
273
+ lines.push('');
274
+ }
275
+ }
276
+ return lines.join('\n');
277
+ }
278
+ generateEntityRelations(entity, allEntities) {
279
+ const tableName = this.toSnakeCase(entity.name);
280
+ const lines = [];
281
+ lines.push(`export const ${tableName}Relations = relations(${tableName}, ({ one, many }) => ({`);
282
+ for (const rel of entity.relationships) {
283
+ const relatedTable = this.toSnakeCase(rel.entity);
284
+ const relName = rel.as || relatedTable;
285
+ switch (rel.type) {
286
+ case 'belongs_to':
287
+ // Derive FK column name from relationship entity
288
+ const fkCol = `${relatedTable}_id`;
289
+ lines.push(` ${relName}: one(${relatedTable}, {`);
290
+ lines.push(` fields: [${tableName}.${fkCol}],`);
291
+ lines.push(` references: [${relatedTable}.id],`);
292
+ lines.push(` }),`);
293
+ break;
294
+ case 'has_one':
295
+ lines.push(` ${relName}: one(${relatedTable}),`);
296
+ break;
297
+ case 'has_many':
298
+ if (rel.through) {
299
+ // Many-to-many through join table
300
+ const throughTable = this.toSnakeCase(rel.through);
301
+ lines.push(` ${relName}: many(${throughTable}),`);
302
+ }
303
+ else {
304
+ lines.push(` ${relName}: many(${relatedTable}),`);
305
+ }
306
+ break;
307
+ }
308
+ }
309
+ lines.push('}));');
310
+ return lines.join('\n');
311
+ }
312
+ // ===========================================================================
313
+ // Types File Generation
314
+ // ===========================================================================
315
+ generateTypesFile(entities) {
316
+ const lines = [];
317
+ if (this.provenance) {
318
+ lines.push('// Generated by Kappa v2.5 CodeDNA');
319
+ lines.push('// TypeScript types inferred from Drizzle schema');
320
+ lines.push('');
321
+ }
322
+ lines.push(`import type { InferSelectModel, InferInsertModel } from 'drizzle-orm';`);
323
+ const tableImports = entities.map(e => this.toSnakeCase(e.name)).join(', ');
324
+ lines.push(`import { ${tableImports} } from './schema';`);
325
+ lines.push('');
326
+ // Generate types for each entity
327
+ for (const entity of entities) {
328
+ const tableName = this.toSnakeCase(entity.name);
329
+ const typeName = entity.name;
330
+ lines.push(`export type ${typeName} = InferSelectModel<typeof ${tableName}>;`);
331
+ lines.push(`export type New${typeName} = InferInsertModel<typeof ${tableName}>;`);
332
+ lines.push('');
333
+ }
334
+ return lines.join('\n');
335
+ }
336
+ // ===========================================================================
337
+ // Utilities
338
+ // ===========================================================================
339
+ toSnakeCase(str) {
340
+ return str
341
+ .replace(/([A-Z])/g, '_$1')
342
+ .toLowerCase()
343
+ .replace(/^_/, '');
344
+ }
345
+ }
346
+ // =============================================================================
347
+ // Convenience Function
348
+ // =============================================================================
349
+ /**
350
+ * Generate Drizzle schema from Kappa entities
351
+ */
352
+ export function generateDrizzleSchema(entities, options = {}) {
353
+ const generator = new KappaDrizzleGenerator(options);
354
+ return generator.generate(entities);
355
+ }
@@ -0,0 +1,51 @@
1
+ import type { FormBlock } from './kappa-ast.js';
2
+ export type FormUILibrary = 'shadcn' | 'plain';
3
+ export interface FormGeneratorOptions {
4
+ /** UI component library (default: 'shadcn') */
5
+ ui?: FormUILibrary;
6
+ /** Add provenance comments (default: true) */
7
+ provenance?: boolean;
8
+ /** Generate TypeScript (default: true) */
9
+ typescript?: boolean;
10
+ /** Use Zod for validation (default: true) */
11
+ zod?: boolean;
12
+ }
13
+ export interface GeneratedForm {
14
+ /** Form component file path */
15
+ path: string;
16
+ /** Form component content */
17
+ content: string;
18
+ /** Zod schema file (if zod enabled) */
19
+ schema?: {
20
+ path: string;
21
+ content: string;
22
+ };
23
+ }
24
+ export interface GeneratedForms {
25
+ /** Generated form files */
26
+ forms: GeneratedForm[];
27
+ }
28
+ export declare class KappaFormGenerator {
29
+ private ui;
30
+ private provenance;
31
+ private typescript;
32
+ private zod;
33
+ constructor(options?: FormGeneratorOptions);
34
+ /**
35
+ * Generate form components from FormBlock AST nodes
36
+ */
37
+ generate(forms: FormBlock[]): GeneratedForms;
38
+ private generateForm;
39
+ private generateZodSchema;
40
+ private fieldTypeToZod;
41
+ private generateLayoutRow;
42
+ private generateShadcnField;
43
+ private generateShadcnInput;
44
+ private generatePlainField;
45
+ private toCamelCase;
46
+ private toKebabCase;
47
+ }
48
+ /**
49
+ * Generate form components from Kappa FormBlock nodes
50
+ */
51
+ export declare function generateForms(forms: FormBlock[], options?: FormGeneratorOptions): GeneratedForms;