Code Generation Refinement Skill
You are refining AUTO-GENERATED code produced by deterministic code generators (openapi-generator, asyncapi-generator, tsp compile, protoc, bpmn-engine). Your role is to adapt the generated output to match the target project's coding conventions WITHOUT changing the API contract or structural design.
Scope
ALLOWED Operations
- Rename variables, functions, and types to match project naming conventions (camelCase, PascalCase, snake_case as detected)
- Restyle code formatting to match project style (indentation, quotes, semicolons, trailing commas)
- Adjust imports to match project import style (relative paths vs path aliases like
@/, ~/)
- Apply error handling patterns consistent with the project (try-catch, Result types, custom error classes)
- Improve type safety (replace
any with proper types, add missing generics, use strict null checks)
- Add JSDoc/TSDoc only where the project consistently uses documentation comments
- Fix linting issues that would be caught by the project's ESLint/Prettier configuration
FORBIDDEN Operations
- DO NOT change the API contract (endpoints, parameters, request/response shapes, status codes)
- DO NOT restructure file organization or move code between files
- DO NOT add features, endpoints, or fields not in the original specification
- DO NOT remove any generated code, even if it seems redundant
- DO NOT add abstractions, patterns, or utilities not present in the spec
- DO NOT change database schema, ORM mappings, or data access patterns
- DO NOT modify authentication or authorization logic
- DO NOT add external dependencies not already in the project
Input Format
You will receive:
- Project conventions — A JSON summary of detected conventions (naming, imports, formatting, error handling)
- Scope constraints — Specific ALLOWED and FORBIDDEN operations for this refinement
- Generated files — One or more files with their paths and content
Output Format
For each file, output the refined version in this exact format:
--- REFINED: <filepath> ---
\`\`\`<language>
<refined code here>
\`\`\`
Output ONLY the refined files. No explanations or commentary outside of code comments.
Examples
Naming Convention Adaptation
// BEFORE (generated)
export interface get_users_response {
user_list: User[];
total_count: number;
}
// AFTER (project uses camelCase + PascalCase interfaces)
export interface GetUsersResponse {
userList: User[];
totalCount: number;
}
Import Style Adaptation
// BEFORE (generated with relative imports)
import { User } from '../models/User';
import { validate } from '../utils/validate';
// AFTER (project uses path aliases)
import { User } from '@/models/User';
import { validate } from '@/utils/validate';
Error Handling Adaptation
// BEFORE (generated with basic try-catch)
try {
const result = await service.findAll();
res.json(result);
} catch (err) {
res.status(500).json({ error: 'Internal error' });
}
// AFTER (project uses custom error class + structured response)
try {
const result = await service.findAll();
res.json({ success: true, data: result });
} catch (err) {
if (err instanceof AppError) {
res.status(err.statusCode).json({ success: false, error: err.message });
} else {
res.status(500).json({ success: false, error: 'Internal server error' });
}
}
Quality Checklist
Before outputting refined code, verify:
1---2name: codegen-refinement3description: Refining AUTO-GENERATED code produced by deterministic generators (openapi-generator, asyncapi-generator, tsp compile, protoc, bpmn-engine) so it matches the target project's conventions without changing the API contract or structural design. USE WHEN: adapting generated clients, models or stubs to project style, reviewing generator output before committing it, user mentions "openapi-generator", "protoc", "generated code cleanup" DO NOT USE FOR: writing new code from scratch, changing an API contract or schema, configuring the generator itself4---5# Code Generation Refinement Skill67You are refining AUTO-GENERATED code produced by deterministic code generators (openapi-generator, asyncapi-generator, tsp compile, protoc, bpmn-engine). Your role is to adapt the generated output to match the target project's coding conventions WITHOUT changing the API contract or structural design.89## Scope1011### ALLOWED Operations12- **Rename** variables, functions, and types to match project naming conventions (camelCase, PascalCase, snake_case as detected)13- **Restyle** code formatting to match project style (indentation, quotes, semicolons, trailing commas)14- **Adjust imports** to match project import style (relative paths vs path aliases like `@/`, `~/`)15- **Apply error handling** patterns consistent with the project (try-catch, Result types, custom error classes)16- **Improve type safety** (replace `any` with proper types, add missing generics, use strict null checks)17- **Add JSDoc/TSDoc** only where the project consistently uses documentation comments18- **Fix linting issues** that would be caught by the project's ESLint/Prettier configuration1920### FORBIDDEN Operations21- **DO NOT** change the API contract (endpoints, parameters, request/response shapes, status codes)22- **DO NOT** restructure file organization or move code between files23- **DO NOT** add features, endpoints, or fields not in the original specification24- **DO NOT** remove any generated code, even if it seems redundant25- **DO NOT** add abstractions, patterns, or utilities not present in the spec26- **DO NOT** change database schema, ORM mappings, or data access patterns27- **DO NOT** modify authentication or authorization logic28- **DO NOT** add external dependencies not already in the project2930## Input Format3132You will receive:331. **Project conventions** — A JSON summary of detected conventions (naming, imports, formatting, error handling)342. **Scope constraints** — Specific ALLOWED and FORBIDDEN operations for this refinement353. **Generated files** — One or more files with their paths and content3637## Output Format3839For each file, output the refined version in this exact format:4041```42--- REFINED: <filepath> ---43\`\`\`<language>44<refined code here>45\`\`\`46```4748Output ONLY the refined files. No explanations or commentary outside of code comments.4950## Examples5152### Naming Convention Adaptation53```typescript54// BEFORE (generated)55export interface get_users_response {56 user_list: User[];57 total_count: number;58}5960// AFTER (project uses camelCase + PascalCase interfaces)61export interface GetUsersResponse {62 userList: User[];63 totalCount: number;64}65```6667### Import Style Adaptation68```typescript69// BEFORE (generated with relative imports)70import { User } from '../models/User';71import { validate } from '../utils/validate';7273// AFTER (project uses path aliases)74import { User } from '@/models/User';75import { validate } from '@/utils/validate';76```7778### Error Handling Adaptation79```typescript80// BEFORE (generated with basic try-catch)81try {82 const result = await service.findAll();83 res.json(result);84} catch (err) {85 res.status(500).json({ error: 'Internal error' });86}8788// AFTER (project uses custom error class + structured response)89try {90 const result = await service.findAll();91 res.json({ success: true, data: result });92} catch (err) {93 if (err instanceof AppError) {94 res.status(err.statusCode).json({ success: false, error: err.message });95 } else {96 res.status(500).json({ success: false, error: 'Internal server error' });97 }98}99```100101## Quality Checklist102103Before outputting refined code, verify:104- [ ] All variable/function names match project conventions105- [ ] Import paths use the correct style (relative or alias)106- [ ] Error handling follows project patterns107- [ ] Formatting matches project config (quotes, semicolons, indentation)108- [ ] No `any` types where specific types are available109- [ ] API contract is completely unchanged110- [ ] No new features or abstractions added111- [ ] File structure is unchanged