@dcyfr/ai-code-gen 0.1.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 (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +469 -0
  3. package/dist/ai/code-gen.d.ts +60 -0
  4. package/dist/ai/code-gen.d.ts.map +1 -0
  5. package/dist/ai/code-gen.js +164 -0
  6. package/dist/ai/code-gen.js.map +1 -0
  7. package/dist/ai/index.d.ts +8 -0
  8. package/dist/ai/index.d.ts.map +1 -0
  9. package/dist/ai/index.js +7 -0
  10. package/dist/ai/index.js.map +1 -0
  11. package/dist/ai/prompts.d.ts +32 -0
  12. package/dist/ai/prompts.d.ts.map +1 -0
  13. package/dist/ai/prompts.js +96 -0
  14. package/dist/ai/prompts.js.map +1 -0
  15. package/dist/ai/provider.d.ts +34 -0
  16. package/dist/ai/provider.d.ts.map +1 -0
  17. package/dist/ai/provider.js +76 -0
  18. package/dist/ai/provider.js.map +1 -0
  19. package/dist/ast/analyzer.d.ts +34 -0
  20. package/dist/ast/analyzer.d.ts.map +1 -0
  21. package/dist/ast/analyzer.js +159 -0
  22. package/dist/ast/analyzer.js.map +1 -0
  23. package/dist/ast/index.d.ts +9 -0
  24. package/dist/ast/index.d.ts.map +1 -0
  25. package/dist/ast/index.js +8 -0
  26. package/dist/ast/index.js.map +1 -0
  27. package/dist/ast/parser.d.ts +16 -0
  28. package/dist/ast/parser.d.ts.map +1 -0
  29. package/dist/ast/parser.js +280 -0
  30. package/dist/ast/parser.js.map +1 -0
  31. package/dist/ast/printer.d.ts +51 -0
  32. package/dist/ast/printer.d.ts.map +1 -0
  33. package/dist/ast/printer.js +126 -0
  34. package/dist/ast/printer.js.map +1 -0
  35. package/dist/ast/transformer.d.ts +11 -0
  36. package/dist/ast/transformer.d.ts.map +1 -0
  37. package/dist/ast/transformer.js +194 -0
  38. package/dist/ast/transformer.js.map +1 -0
  39. package/dist/cli.d.ts +15 -0
  40. package/dist/cli.d.ts.map +1 -0
  41. package/dist/cli.js +284 -0
  42. package/dist/cli.js.map +1 -0
  43. package/dist/generators/api-route.d.ts +14 -0
  44. package/dist/generators/api-route.d.ts.map +1 -0
  45. package/dist/generators/api-route.js +82 -0
  46. package/dist/generators/api-route.js.map +1 -0
  47. package/dist/generators/base.d.ts +29 -0
  48. package/dist/generators/base.d.ts.map +1 -0
  49. package/dist/generators/base.js +89 -0
  50. package/dist/generators/base.js.map +1 -0
  51. package/dist/generators/component.d.ts +14 -0
  52. package/dist/generators/component.d.ts.map +1 -0
  53. package/dist/generators/component.js +77 -0
  54. package/dist/generators/component.js.map +1 -0
  55. package/dist/generators/index.d.ts +10 -0
  56. package/dist/generators/index.d.ts.map +1 -0
  57. package/dist/generators/index.js +10 -0
  58. package/dist/generators/index.js.map +1 -0
  59. package/dist/generators/model.d.ts +14 -0
  60. package/dist/generators/model.d.ts.map +1 -0
  61. package/dist/generators/model.js +89 -0
  62. package/dist/generators/model.js.map +1 -0
  63. package/dist/generators/registry.d.ts +42 -0
  64. package/dist/generators/registry.d.ts.map +1 -0
  65. package/dist/generators/registry.js +84 -0
  66. package/dist/generators/registry.js.map +1 -0
  67. package/dist/generators/test.d.ts +13 -0
  68. package/dist/generators/test.d.ts.map +1 -0
  69. package/dist/generators/test.js +39 -0
  70. package/dist/generators/test.js.map +1 -0
  71. package/dist/index.d.ts +19 -0
  72. package/dist/index.d.ts.map +1 -0
  73. package/dist/index.js +20 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/lib/config.d.ts +16 -0
  76. package/dist/lib/config.d.ts.map +1 -0
  77. package/dist/lib/config.js +52 -0
  78. package/dist/lib/config.js.map +1 -0
  79. package/dist/lib/file-system.d.ts +30 -0
  80. package/dist/lib/file-system.d.ts.map +1 -0
  81. package/dist/lib/file-system.js +71 -0
  82. package/dist/lib/file-system.js.map +1 -0
  83. package/dist/lib/logger.d.ts +17 -0
  84. package/dist/lib/logger.d.ts.map +1 -0
  85. package/dist/lib/logger.js +43 -0
  86. package/dist/lib/logger.js.map +1 -0
  87. package/dist/lib/strings.d.ts +41 -0
  88. package/dist/lib/strings.d.ts.map +1 -0
  89. package/dist/lib/strings.js +92 -0
  90. package/dist/lib/strings.js.map +1 -0
  91. package/dist/templates/builtins.d.ts +13 -0
  92. package/dist/templates/builtins.d.ts.map +1 -0
  93. package/dist/templates/builtins.js +275 -0
  94. package/dist/templates/builtins.js.map +1 -0
  95. package/dist/templates/engine.d.ts +69 -0
  96. package/dist/templates/engine.d.ts.map +1 -0
  97. package/dist/templates/engine.js +154 -0
  98. package/dist/templates/engine.js.map +1 -0
  99. package/dist/templates/index.d.ts +6 -0
  100. package/dist/templates/index.d.ts.map +1 -0
  101. package/dist/templates/index.js +6 -0
  102. package/dist/templates/index.js.map +1 -0
  103. package/dist/types/index.d.ts +401 -0
  104. package/dist/types/index.d.ts.map +1 -0
  105. package/dist/types/index.js +7 -0
  106. package/dist/types/index.js.map +1 -0
  107. package/package.json +80 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DCYFR AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,469 @@
1
+ # @dcyfr/ai-code-gen
2
+
3
+ > AI-powered code generation toolkit with AST manipulation, template engine, and intelligent scaffolding.
4
+
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.3+-blue.svg)](https://www.typescriptlang.org/)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
7
+ [![Node.js](https://img.shields.io/badge/Node.js-20+-green.svg)](https://nodejs.org/)
8
+ [![Status](https://img.shields.io/badge/Status-Production%20Ready-success.svg)]()
9
+
10
+ ## Overview
11
+
12
+ `@dcyfr/ai-code-gen` is a comprehensive code generation toolkit that combines template-based scaffolding, AST (Abstract Syntax Tree) manipulation, and AI-assisted code generation. It provides a complete pipeline for generating, analyzing, transforming, and reviewing TypeScript code.
13
+
14
+ **Perfect for:**
15
+ - 🚀 Accelerating development with intelligent code scaffolding
16
+ - 🧪 Ensuring consistency across large codebases with standardized patterns
17
+ - 🔍 Automated code quality analysis and refactoring suggestions
18
+ - 🤖 Integrating AI-powered code generation into your workflow
19
+ - 📝 Generating documentation, tests, and boilerplate automatically
20
+
21
+ ## Features
22
+
23
+ ✅ **Template Engine** — Handlebars-based with 20+ built-in helpers for case conversion, conditionals, and code generation patterns
24
+ ✅ **Code Generators** — Pre-built generators for React components, API routes, data models, test files, and barrel exports
25
+ ✅ **AST Module** — Parse, transform, analyze, and format TypeScript code using ts-morph
26
+ ✅ **AI Integration** — Pluggable AI provider system for intelligent code generation, review, and refactoring
27
+ ✅ **'CLI** — Command-line interface for scaffolding, analysis, and code review
28
+ ✅ **Extensible** — Register custom templates, generators, and AI providers
29
+ ✅ **Type-Safe** — Full TypeScript support with strict mode enabled
30
+ ✅ **Well-Tested** — Comprehensive test suite with Vitest
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ npm install @dcyfr/ai-code-gen
36
+ ```
37
+
38
+ ## Quick Start
39
+
40
+ ### Generate a React Component
41
+
42
+ ```typescript
43
+ import { createGeneratorRegistry } from '@dcyfr/ai-code-gen';
44
+
45
+ const registry = createGeneratorRegistry();
46
+
47
+ const result = await registry.run('component', {
48
+ name: 'user-card',
49
+ outputDir: 'src/components',
50
+ options: {
51
+ props: [
52
+ { name: 'name', type: 'string', required: true },
53
+ { name: 'avatar', type: 'string' },
54
+ ],
55
+ useClient: true,
56
+ withTest: true,
57
+ },
58
+ });
59
+
60
+ for (const file of result.files) {
61
+ console.log(`Generated: ${file.path}`);
62
+ }
63
+ ```
64
+
65
+ ### Analyze TypeScript Code
66
+
67
+ ```typescript
68
+ import { analyzeCode } from '@dcyfr/ai-code-gen';
69
+
70
+ const analysis = analyzeCode(`
71
+ function processData(input: any) {
72
+ console.log(input);
73
+ if (input.a) {
74
+ if (input.b) {
75
+ if (input.c) {
76
+ return true;
77
+ }
78
+ }
79
+ }
80
+ return false;
81
+ }
82
+ `);
83
+
84
+ console.log(analysis.issues);
85
+ // Detects: console.log usage, `any` type, high complexity
86
+ ```
87
+
88
+ ### Transform Code with AST
89
+
90
+ ```typescript
91
+ import { transform } from '@dcyfr/ai-code-gen';
92
+
93
+ const result = transform(sourceCode, [
94
+ { type: 'add-import', moduleSpecifier: 'zod', namedImports: ['z'] },
95
+ { type: 'rename', oldName: 'fetchData', newName: 'loadData' },
96
+ { type: 'add-export', exportName: 'UserSchema' },
97
+ ]);
98
+
99
+ console.log(result.source);
100
+ ```
101
+
102
+ ### Use the Template Engine
103
+
104
+ ```typescript
105
+ import { TemplateEngine } from '@dcyfr/ai-code-gen';
106
+
107
+ const engine = new TemplateEngine();
108
+
109
+ const result = engine.renderSource(
110
+ 'export function {{camelCase name}}({{#each params}}{{this}}{{#unless @last}}, {{/unless}}{{/each}}): {{returnType}} {}',
111
+ { name: 'get-user-data', params: ['id: string', 'options?: Options'], returnType: 'Promise<User>' }
112
+ );
113
+
114
+ console.log(result.content);
115
+ // export function getUserData(id: string, options?: Options): Promise<User> {}
116
+ ```
117
+
118
+ ## Built-in Generators
119
+
120
+ | Generator | Description | Output |
121
+ |-----------|-------------|--------|
122
+ | `component` | React functional component with TypeScript | `.tsx` + barrel export |
123
+ | `api-route` | Next.js API route handler | `.ts` with GET/POST/PUT/DELETE |
124
+ | `model` | Zod schema data model | `.ts` with schema + types + factory |
125
+ | `test` | Vitest test file | `.test.ts` with describe/it scaffolding |
126
+
127
+ ## Built-in Template Helpers
128
+
129
+ ### Case Conversion
130
+ - `{{pascalCase name}}` → `UserProfile`
131
+ - `{{camelCase name}}` → `userProfile`
132
+ - `{{kebabCase name}}` → `user-profile`
133
+ - `{{snakeCase name}}` → `user_profile`
134
+ - `{{constantCase name}}` → `USER_PROFILE`
135
+
136
+ ### Conditionals
137
+ - `{{#if condition}}...{{/if}}`
138
+ - `{{#unless condition}}...{{/unless}}`
139
+ - `{{eq a b}}`, `{{neq a b}}`, `{{or a b}}`, `{{and a b}}`, `{{not a}}`
140
+
141
+ ### Utilities
142
+ - `{{pluralize word}}` — Simple pluralization
143
+ - `{{join array ", "}}` — Join array elements
144
+ - `{{timestamp}}` — ISO timestamp
145
+ - `{{year}}` — Current year
146
+ - `{{typeAnnotation type}}` — TypeScript type annotation
147
+ - `{{genericType base param}}` — Generic type syntax
148
+
149
+ ## AST Module
150
+
151
+ ### Parse
152
+ ```typescript
153
+ import { parseSource, parseFile } from '@dcyfr/ai-code-gen';
154
+
155
+ const ast = parseSource('class User { name: string; }');
156
+ // Returns: classes, interfaces, functions, types, enums, variables, imports, exports, metrics
157
+ ```
158
+
159
+ ### Transform
160
+ ```typescript
161
+ import { transform } from '@dcyfr/ai-code-gen';
162
+
163
+ const result = transform(source, [
164
+ { type: 'add-import', moduleSpecifier: 'zod', namedImports: ['z'] },
165
+ { type: 'remove-import', moduleSpecifier: 'lodash' },
166
+ { type: 'add-property', className: 'User', propertyName: 'email', propertyType: 'string' },
167
+ { type: 'add-method', className: 'User', methodName: 'validate', returnType: 'boolean', body: 'return true;' },
168
+ { type: 'rename', oldName: 'oldFunc', newName: 'newFunc' },
169
+ { type: 'add-export', exportName: 'MyType' },
170
+ ]);
171
+ ```
172
+
173
+ ### Analyze
174
+ ```typescript
175
+ import { analyzeCode, compareStructure } from '@dcyfr/ai-code-gen';
176
+
177
+ const analysis = analyzeCode(source);
178
+ // Detects: dead-code, complexity, naming, missing-jsdoc, large-file issues
179
+
180
+ const diff = compareStructure(oldSource, newSource);
181
+ // Returns: added, removed, modified declarations
182
+ ```
183
+
184
+ ### Format
185
+ ```typescript
186
+ import { formatTypeScript, addLicenseHeader, generateJsDoc } from '@dcyfr/ai-code-gen';
187
+
188
+ const formatted = formatTypeScript(source, { singleQuote: true, tabWidth: 2 });
189
+ const withHeader = addLicenseHeader(source, 'MIT', 2026);
190
+ const doc = generateJsDoc({ description: 'Process data', params: [{ name: 'input', type: 'string' }] });
191
+ ```
192
+
193
+ ## AI Integration
194
+
195
+ ```typescript
196
+ import { createAICodeGenerator } from '@dcyfr/ai-code-gen';
197
+
198
+ // Uses MockAIProvider by default; plug in your own AIProvider for real AI
199
+ const ai = createAICodeGenerator({ provider: 'mock', model: 'gpt-4' });
200
+
201
+ // Generate code
202
+ const generated = await ai.generateCode({ prompt: 'Create a user service', language: 'TypeScript' });
203
+
204
+ // Review code
205
+ const review = await ai.reviewCode({ code: sourceCode, language: 'TypeScript' });
206
+
207
+ // Suggest refactoring
208
+ const suggestions = await ai.suggestRefactoring({ code: sourceCode, language: 'TypeScript' });
209
+
210
+ // Generate documentation
211
+ const docs = await ai.generateDocs({ code: sourceCode, language: 'TypeScript' });
212
+ ```
213
+
214
+ ## CLI Usage
215
+
216
+ ```bash
217
+ # Generate a React component
218
+ npx dcyfr-codegen generate component user-card --output src/components
219
+
220
+ # Analyze a TypeScript file
221
+ npx dcyfr-codegen analyze src/utils.ts
222
+
223
+ # Review code quality
224
+ npx dcyfr-codegen review src/service.ts
225
+
226
+ # List available generators
227
+ npx dcyfr-codegen list
228
+
229
+ # Show help
230
+ npx dcyfr-codegen help
231
+ ```
232
+
233
+ ## Custom Templates
234
+
235
+ ```typescript
236
+ import { TemplateEngine } from '@dcyfr/ai-code-gen';
237
+
238
+ const engine = new TemplateEngine();
239
+
240
+ engine.registerTemplate({
241
+ id: 'my-template',
242
+ name: 'Custom Template',
243
+ description: 'My custom code template',
244
+ outputExtension: '.ts',
245
+ variables: [
246
+ { name: 'name', type: 'string', required: true },
247
+ ],
248
+ source: 'export class {{pascalCase name}} {\n // TODO: implement\n}\n',
249
+ });
250
+
251
+ const result = engine.render('my-template', { name: 'my-service' });
252
+ ```
253
+
254
+ ## Documentation
255
+
256
+ Comprehensive guides for mastering code generation:
257
+
258
+ - **[Template Engine Guide](docs/TEMPLATE_ENGINE.md)** (1,054 lines)
259
+ Learn Handlebars templating with 20+ custom helpers, partials, custom helpers, and advanced patterns for code generation.
260
+
261
+ - **[AST Manipulation Guide](docs/AST_MANIPULATION.md)** (1,017 lines)
262
+ Master TypeScript AST parsing, transformations, code analysis, custom transformers, and metadata extraction.
263
+
264
+ - **[Code Generators Guide](docs/CODE_GENERATORS.md)** (908 lines)
265
+ Build custom generators with Zod validation, hooks, multi-file generation, and advanced composition patterns.
266
+
267
+ - **[AI Integration Guide](docs/AI_INTEGRATION.md)** (915 lines)
268
+ Integrate AI providers (OpenAI, Anthropic), prompt engineering, code review workflows, and custom AI providers.
269
+
270
+ **Total: 3,894 lines of production-ready documentation**
271
+
272
+ ## Examples
273
+
274
+ Three comprehensive executable examples showcasing advanced patterns:
275
+
276
+ ### 1. Custom Generator ([examples/custom-generator.ts](examples/custom-generator.ts))
277
+ Build a complete feature generator with:
278
+ - Zod schema validation
279
+ - Generator hooks (beforeGenerate, afterGenerate, postProcess)
280
+ - Multi-file generation (service, repository, schema, tests, barrel exports)
281
+ - Post-processing (formatting, license headers)
282
+ - Full CRUD operations with Prisma/Drizzle support
283
+
284
+ ### 2. AST Refactoring ([examples/ast-refactoring.ts](examples/ast-refactoring.ts))
285
+ Complex code transformation workflows:
286
+ - Migrate React class components → function components with hooks
287
+ - Add dependency injection decorators
288
+ - Modernize callbacks → promises → async/await
289
+ - Remove `any` types and add error handling
290
+ - Extract interfaces from classes
291
+ - Batch refactoring multiple files
292
+
293
+ ### 3. Template Composition ([examples/template-composition.ts](examples/template-composition.ts))
294
+ Advanced Handlebars patterns:
295
+ - Reusable partials for file headers, imports, JSDoc
296
+ - Template inheritance with base layouts
297
+ - Dynamic component generation from data
298
+ - Conditional imports based on feature flags
299
+ - Custom helpers for complex logic
300
+ - Nested templates with context passing
301
+ - Dynamic form generation with Zod validation
302
+
303
+ Run examples:
304
+ ```bash
305
+ npx tsx examples/custom-generator.ts
306
+ npx tsx examples/ast-refactoring.ts
307
+ npx tsx examples/template-composition.ts
308
+ ```
309
+
310
+ ## Best Practices
311
+
312
+ ### Code Generation
313
+
314
+ ✅ **Use Specific Prompts** — Provide detailed requirements instead of vague descriptions
315
+ ✅ **Validate Input** — Always validate data with Zod before generating code
316
+ ✅ **Format Output** — Run generated code through Prettier for consistency
317
+ ✅ **Add Documentation** — Include JSDoc comments for generated functions
318
+ ✅ **Test Generated Code** — Verify generated code compiles and passes tests
319
+
320
+ ### Template Design
321
+
322
+ ✅ **Use Partials** — Extract reusable fragments into partials
323
+ ✅ **Consistent Helpers** — Use built-in helpers for case conversion
324
+ ✅ **Validate Variables** — Define required variables in template schema
325
+ ✅ **Test Edge Cases** — Test templates with empty/null/missing data
326
+ ✅ **Version Templates** — Track template changes with versioning
327
+
328
+ ### AST Transformations
329
+
330
+ ✅ **Parse Once** — Parse source once, apply multiple transformations
331
+ ✅ **Type-Safe** — Use TypeScript types for transformation parameters
332
+ ✅ **Validate Before** — Check AST structure before transforming
333
+ ✅ **Format After** — Always format code after transformations
334
+ ✅ **Handle Errors** — Gracefully handle malformed code
335
+
336
+ ### AI Integration
337
+
338
+ ✅ **Set Low Temperature** — Use 0.0-0.3 for deterministic code generation
339
+ ✅ **Provide Context** — Include existing code for better AI suggestions
340
+ ✅ **Review AI Output** — Always review AI-generated code before use
341
+ ✅ **Handle Rate Limits** — Implement retry logic with exponential backoff
342
+ ✅ **Log AI Calls** — Track AI usage for debugging and cost monitoring
343
+
344
+ ## Troubleshooting
345
+
346
+ ### Common Issues
347
+
348
+ **Template rendering fails**
349
+ ```
350
+ Error: Missing required variable 'name'
351
+ ```
352
+ **Solution:** Ensure all required variables are provided in template data.
353
+
354
+ **AST transformation fails**
355
+ ```
356
+ Error: Cannot find class 'UserService'
357
+ ```
358
+ **Solution:** Verify class exists in source before applying transformation. Use `parseSource()` to inspect AST structure.
359
+
360
+ **Code analysis detects false positives**
361
+ ```
362
+ Warning: any-type detected at line 15
363
+ ```
364
+ **Solution:** Update analysis rules or add `// @ts-ignore` comments for intentional `any` usage.
365
+
366
+ **AI rate limit exceeded**
367
+ ```
368
+ RateLimitError: Too many requests
369
+ ```
370
+ **Solution:** Implement retry logic with exponential backoff. Consider using a rate limiter utility.
371
+
372
+ **Generated code doesn't compile**
373
+ ```
374
+ TS2304: Cannot find name 'User'
375
+ ```
376
+ **Solution:** Ensure required imports are added. Use `add-import` transformation before generating code.
377
+
378
+ ### Getting Help
379
+
380
+ - **GitHub Issues:** [https://github.com/dcyfr/dcyfr-ai-code-gen/issues](https://github.com/dcyfr/dcyfr-ai-code-gen/issues)
381
+ - **Documentation:** See comprehensive guides in `docs/` directory
382
+ - **Examples:** Run example files in `examples/` directory
383
+ - **Community:** Join discussions on GitHub
384
+
385
+ ## Architecture
386
+
387
+ ```
388
+ src/
389
+ ├── types/ # TypeScript type definitions
390
+ ├── lib/ # Core utilities (config, logger, strings, file-system)
391
+ ├── templates/ # Handlebars template engine + built-in templates
392
+ ├── generators/ # Code generators (component, api-route, model, test)
393
+ ├── ast/ # AST parsing, transformation, analysis, formatting
394
+ ├── ai/ # AI provider integration + prompt engineering
395
+ ├── cli.ts # CLI entry point
396
+ └── index.ts # Public API barrel export
397
+ ```
398
+
399
+ ## Contributing
400
+
401
+ We welcome contributions! Please see our [contributing guidelines](CONTRIBUTING.md) for details.
402
+
403
+ ### Development Workflow
404
+
405
+ 1. Fork the repository
406
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
407
+ 3. Make your changes with tests
408
+ 4. Run tests (`npm test`)
409
+ 5. Run type check (`npx tsc --noEmit`)
410
+ 6. Run linter (`npm run lint`)
411
+ 7. Commit your changes (`git commit -m 'Add amazing feature'`)
412
+ 8. Push to the branch (`git push origin feature/amazing-feature`)
413
+ 9. Open a Pull Request
414
+
415
+ ### Code Quality Standards
416
+
417
+ - ✅ All code must be TypeScript with strict mode
418
+ - ✅ All functions must have JSDoc comments
419
+ - ✅ Test coverage must be ≥80%
420
+ - ✅ All tests must pass before merging
421
+ - ✅ Follow existing code style (enforced by ESLint)
422
+
423
+ ## Roadmap
424
+
425
+ ### v1.1 (Q2 2026)
426
+ - [ ] Additional AI providers (Google Gemini, Mistral, local LLMs)
427
+ - [ ] Visual Studio Code extension
428
+ - [ ] Interactive CLI with prompts
429
+ - [ ] Generator marketplace
430
+
431
+ ### v1.2 (Q3 2026)
432
+ - [ ] Support for Python, Java, and Go code generation
433
+ - [ ] Advanced refactoring patterns (design pattern migration)
434
+ - [ ] Real-time code review in IDE
435
+ - [ ] Team collaboration features
436
+
437
+ ### v2.0 (Q4 2026)
438
+ - [ ] Multi-file project scaffolding
439
+ - [ ] AI-powered architecture suggestions
440
+ - [ ] Code migration tool (React Class → Hooks, JavaScript → TypeScript)
441
+ - [ ] Enterprise features (SSO, audit logs, team management)
442
+
443
+ ## Development
444
+
445
+ ```bash
446
+ # Install dependencies
447
+ npm install
448
+
449
+ # Type check
450
+ npx tsc --noEmit
451
+
452
+ # Run tests
453
+ npm test
454
+
455
+ # Run tests in watch mode
456
+ npx vitest
457
+
458
+ # Lint
459
+ npm run lint
460
+ ```
461
+
462
+ ## Requirements
463
+
464
+ - Node.js >= 20
465
+ - TypeScript >= 5.3
466
+
467
+ ## License
468
+
469
+ MIT — see [LICENSE](LICENSE) for details.
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @dcyfr/ai-code-gen - AI Code Generator
3
+ *
4
+ * High-level AI-powered code generation combining prompts with providers.
5
+ */
6
+ import type { AICodeRequest, AICodeResponse, ReviewResult, RefactorSuggestion, AIProviderConfig } from '../types/index.js';
7
+ /** AI code generation service */
8
+ export declare class AICodeGenerator {
9
+ private readonly provider;
10
+ constructor(config?: AIProviderConfig);
11
+ /**
12
+ * Generate code from a request.
13
+ */
14
+ generateCode(request: AICodeRequest): Promise<AICodeResponse>;
15
+ /**
16
+ * Review code and return findings.
17
+ */
18
+ reviewCode(options: {
19
+ code: string;
20
+ language: string;
21
+ focus?: string[];
22
+ }): Promise<ReviewResult>;
23
+ /**
24
+ * Suggest refactorings for code.
25
+ */
26
+ suggestRefactoring(options: {
27
+ code: string;
28
+ language: string;
29
+ goals?: string[];
30
+ }): Promise<RefactorSuggestion[]>;
31
+ /**
32
+ * Generate documentation for code.
33
+ */
34
+ generateDocs(options: {
35
+ code: string;
36
+ language: string;
37
+ style?: 'jsdoc' | 'tsdoc' | 'markdown';
38
+ }): Promise<string>;
39
+ /**
40
+ * Parse findings from AI response, or return heuristic defaults.
41
+ */
42
+ private parseFindingsOrDefault;
43
+ /**
44
+ * Generate basic heuristic findings from code patterns.
45
+ */
46
+ private generateHeuristicFindings;
47
+ /**
48
+ * Parse refactoring suggestions from AI response, or return defaults.
49
+ */
50
+ private parseSuggestionsOrDefault;
51
+ /**
52
+ * Calculate a quality score from findings.
53
+ */
54
+ private calculateScore;
55
+ }
56
+ /**
57
+ * Create an AI code generator with configuration.
58
+ */
59
+ export declare function createAICodeGenerator(config?: AIProviderConfig): AICodeGenerator;
60
+ //# sourceMappingURL=code-gen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-gen.d.ts","sourceRoot":"","sources":["../../src/ai/code-gen.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,YAAY,EAEZ,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAI3B,iCAAiC;AACjC,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAa;gBAE1B,MAAM,CAAC,EAAE,gBAAgB;IAIrC;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAInE;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE;QACxB,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;KAClB,GAAG,OAAO,CAAC,YAAY,CAAC;IAkBzB;;OAEG;IACG,kBAAkB,CAAC,OAAO,EAAE;QAChC,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;KAClB,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAOjC;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE;QAC1B,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,UAAU,CAAC;KACxC,GAAG,OAAO,CAAC,MAAM,CAAC;IAKnB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAW9B;;OAEG;IACH,OAAO,CAAC,yBAAyB;IA6CjC;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAyBjC;;OAEG;IACH,OAAO,CAAC,cAAc;CAoBvB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,eAAe,CAEhF"}