|
|
|
@@ -12,121 +12,40 @@ import type {
|
|
|
|
|
import { AGENT_INSTRUCTION_TEMPLATES } from './types.js';
|
|
|
|
|
import { analyzePrimer } from './analyzer.js';
|
|
|
|
|
|
|
|
|
|
const ALL_AGENTS: AgentType[] = Object.keys(AGENT_CONFIG) as AgentType[];
|
|
|
|
|
|
|
|
|
|
type OutputFormat = 'markdown' | 'mdc' | 'json' | 'xml';
|
|
|
|
|
|
|
|
|
|
interface FormatRenderer {
|
|
|
|
|
h1(text: string): string;
|
|
|
|
|
h2(text: string): string;
|
|
|
|
|
h3(text: string): string;
|
|
|
|
|
bold(text: string): string;
|
|
|
|
|
code(text: string): string;
|
|
|
|
|
codeBlock(code: string, lang?: string): string;
|
|
|
|
|
list(items: string[]): string;
|
|
|
|
|
keyValue(key: string, value: string): string;
|
|
|
|
|
paragraph(text: string): string;
|
|
|
|
|
separator(): string;
|
|
|
|
|
wrap(content: string, metadata?: Record<string, unknown>): string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const markdownRenderer: FormatRenderer = {
|
|
|
|
|
h1: (text) => `# ${text}`,
|
|
|
|
|
h2: (text) => `## ${text}`,
|
|
|
|
|
h3: (text) => `### ${text}`,
|
|
|
|
|
bold: (text) => `**${text}**`,
|
|
|
|
|
code: (text) => `\`${text}\``,
|
|
|
|
|
codeBlock: (code, lang = '') => `\`\`\`${lang}\n${code}\n\`\`\``,
|
|
|
|
|
list: (items) => items.map(item => `- ${item}`).join('\n'),
|
|
|
|
|
keyValue: (key, value) => `**${key}:** ${value}`,
|
|
|
|
|
paragraph: (text) => text,
|
|
|
|
|
separator: () => '',
|
|
|
|
|
wrap: (content) => content,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mdcRenderer: FormatRenderer = {
|
|
|
|
|
h1: (text) => `# ${text}`,
|
|
|
|
|
h2: (text) => `## ${text}`,
|
|
|
|
|
h3: (text) => `### ${text}`,
|
|
|
|
|
bold: (text) => `**${text}**`,
|
|
|
|
|
code: (text) => `\`${text}\``,
|
|
|
|
|
codeBlock: (code, lang = '') => `\`\`\`${lang}\n${code}\n\`\`\``,
|
|
|
|
|
list: (items) => items.map(item => `- ${item}`).join('\n'),
|
|
|
|
|
keyValue: (key, value) => `**${key}:** ${value}`,
|
|
|
|
|
paragraph: (text) => text,
|
|
|
|
|
separator: () => '',
|
|
|
|
|
wrap: (content, metadata) => {
|
|
|
|
|
if (metadata && Object.keys(metadata).length > 0) {
|
|
|
|
|
const yaml = Object.entries(metadata)
|
|
|
|
|
.map(([k, v]) => `${k}: ${JSON.stringify(v)}`)
|
|
|
|
|
.join('\n');
|
|
|
|
|
return `---\n${yaml}\n---\n\n${content}`;
|
|
|
|
|
}
|
|
|
|
|
return content;
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const jsonRenderer: FormatRenderer = {
|
|
|
|
|
h1: (text) => text,
|
|
|
|
|
h2: (text) => text,
|
|
|
|
|
h3: (text) => text,
|
|
|
|
|
bold: (text) => text,
|
|
|
|
|
code: (text) => text,
|
|
|
|
|
codeBlock: (code) => code,
|
|
|
|
|
list: (items) => items.join(', '),
|
|
|
|
|
keyValue: (key, value) => `${key}: ${value}`,
|
|
|
|
|
paragraph: (text) => text,
|
|
|
|
|
separator: () => '',
|
|
|
|
|
wrap: (content, metadata) => {
|
|
|
|
|
try {
|
|
|
|
|
const data = { ...metadata, content };
|
|
|
|
|
return JSON.stringify(data, null, 2);
|
|
|
|
|
} catch {
|
|
|
|
|
return content;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const xmlRenderer: FormatRenderer = {
|
|
|
|
|
h1: (text) => `<h1>${escapeXml(text)}</h1>`,
|
|
|
|
|
h2: (text) => `<h2>${escapeXml(text)}</h2>`,
|
|
|
|
|
h3: (text) => `<h3>${escapeXml(text)}</h3>`,
|
|
|
|
|
bold: (text) => `<strong>${escapeXml(text)}</strong>`,
|
|
|
|
|
code: (text) => `<code>${escapeXml(text)}</code>`,
|
|
|
|
|
codeBlock: (code, lang = '') => `<pre${lang ? ` lang="${lang}"` : ''}><code>${escapeXml(code)}</code></pre>`,
|
|
|
|
|
list: (items) => `<ul>\n${items.map(item => ` <li>${escapeXml(item)}</li>`).join('\n')}\n</ul>`,
|
|
|
|
|
keyValue: (key, value) => `<dt>${escapeXml(key)}</dt><dd>${escapeXml(value)}</dd>`,
|
|
|
|
|
paragraph: (text) => `<p>${escapeXml(text)}</p>`,
|
|
|
|
|
separator: () => '',
|
|
|
|
|
wrap: (content, metadata) => {
|
|
|
|
|
const attrs = metadata
|
|
|
|
|
? Object.entries(metadata).map(([k, v]) => `${k}="${escapeXml(String(v))}"`).join(' ')
|
|
|
|
|
: '';
|
|
|
|
|
return `<?xml version="1.0" encoding="UTF-8"?>\n<instructions${attrs ? ' ' + attrs : ''}>\n${content}\n</instructions>`;
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function escapeXml(text: string): string {
|
|
|
|
|
return text
|
|
|
|
|
.replace(/&/g, '&')
|
|
|
|
|
.replace(/</g, '<')
|
|
|
|
|
.replace(/>/g, '>')
|
|
|
|
|
.replace(/"/g, '"')
|
|
|
|
|
.replace(/'/g, ''');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getRenderer(format: OutputFormat): FormatRenderer {
|
|
|
|
|
switch (format) {
|
|
|
|
|
case 'mdc':
|
|
|
|
|
return mdcRenderer;
|
|
|
|
|
case 'json':
|
|
|
|
|
return jsonRenderer;
|
|
|
|
|
case 'xml':
|
|
|
|
|
return xmlRenderer;
|
|
|
|
|
default:
|
|
|
|
|
return markdownRenderer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const ALL_AGENTS: AgentType[] = [
|
|
|
|
|
'claude-code',
|
|
|
|
|
'cursor',
|
|
|
|
|
'codex',
|
|
|
|
|
'gemini-cli',
|
|
|
|
|
'opencode',
|
|
|
|
|
'antigravity',
|
|
|
|
|
'amp',
|
|
|
|
|
'clawdbot',
|
|
|
|
|
'droid',
|
|
|
|
|
'github-copilot',
|
|
|
|
|
'goose',
|
|
|
|
|
'kilo',
|
|
|
|
|
'kiro-cli',
|
|
|
|
|
'roo',
|
|
|
|
|
'trae',
|
|
|
|
|
'windsurf',
|
|
|
|
|
'universal',
|
|
|
|
|
'cline',
|
|
|
|
|
'codebuddy',
|
|
|
|
|
'commandcode',
|
|
|
|
|
'continue',
|
|
|
|
|
'crush',
|
|
|
|
|
'factory',
|
|
|
|
|
'mcpjam',
|
|
|
|
|
'mux',
|
|
|
|
|
'neovate',
|
|
|
|
|
'openhands',
|
|
|
|
|
'pi',
|
|
|
|
|
'qoder',
|
|
|
|
|
'qwen',
|
|
|
|
|
'vercel',
|
|
|
|
|
'zencoder',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export class PrimerGenerator {
|
|
|
|
|
private projectPath: string;
|
|
|
|
@@ -142,7 +61,6 @@ export class PrimerGenerator {
|
|
|
|
|
const warnings: string[] = [];
|
|
|
|
|
const errors: string[] = [];
|
|
|
|
|
const generated: GeneratedInstruction[] = [];
|
|
|
|
|
const seenPaths = new Map<string, string>();
|
|
|
|
|
|
|
|
|
|
this.analysis = analyzePrimer(this.projectPath);
|
|
|
|
|
|
|
|
|
@@ -162,15 +80,6 @@ export class PrimerGenerator {
|
|
|
|
|
try {
|
|
|
|
|
const instruction = this.generateForAgent(agent);
|
|
|
|
|
if (instruction) {
|
|
|
|
|
const existingAgent = seenPaths.get(instruction.filepath);
|
|
|
|
|
if (existingAgent) {
|
|
|
|
|
warnings.push(
|
|
|
|
|
`Skipping ${agent}: output path "${instruction.filename}" already used by ${existingAgent}`
|
|
|
|
|
);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
seenPaths.set(instruction.filepath, agent);
|
|
|
|
|
|
|
|
|
|
if (!this.options.dryRun) {
|
|
|
|
|
this.writeInstruction(instruction);
|
|
|
|
|
}
|
|
|
|
@@ -253,21 +162,10 @@ export class PrimerGenerator {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private getDefaultTemplate(agent: AgentType, config: AgentDirectoryConfig): AgentInstructionTemplate {
|
|
|
|
|
const formatMap: Record<string, OutputFormat> = {
|
|
|
|
|
'.md': 'markdown',
|
|
|
|
|
'.json': 'json',
|
|
|
|
|
'.mdc': 'mdc',
|
|
|
|
|
'.xml': 'xml',
|
|
|
|
|
};
|
|
|
|
|
const ext = config.configFile.includes('.')
|
|
|
|
|
? '.' + config.configFile.split('.').pop()
|
|
|
|
|
: '.md';
|
|
|
|
|
const format = formatMap[ext] || 'markdown';
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
agent,
|
|
|
|
|
filename: config.configFile,
|
|
|
|
|
format,
|
|
|
|
|
format: 'markdown',
|
|
|
|
|
sectionOrder: ['overview', 'stack', 'commands', 'conventions', 'structure', 'guidelines'],
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
@@ -275,17 +173,10 @@ export class PrimerGenerator {
|
|
|
|
|
private generateContent(template: AgentInstructionTemplate): string {
|
|
|
|
|
if (!this.analysis) return '';
|
|
|
|
|
|
|
|
|
|
const format = template.format as OutputFormat;
|
|
|
|
|
const renderer = getRenderer(format);
|
|
|
|
|
|
|
|
|
|
if (format === 'json') {
|
|
|
|
|
return this.generateJsonContent(template);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const sections: string[] = [];
|
|
|
|
|
|
|
|
|
|
for (const section of template.sectionOrder) {
|
|
|
|
|
const content = this.generateSection(section, template, renderer);
|
|
|
|
|
const content = this.generateSection(section, template);
|
|
|
|
|
if (content) {
|
|
|
|
|
sections.push(content);
|
|
|
|
|
}
|
|
|
|
@@ -302,310 +193,271 @@ export class PrimerGenerator {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.options.customInstructions) {
|
|
|
|
|
result += '\n\n' + renderer.h2('Custom Instructions') + '\n\n' + this.options.customInstructions;
|
|
|
|
|
result += '\n\n## Custom Instructions\n\n' + this.options.customInstructions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const metadata = format === 'mdc' ? {
|
|
|
|
|
title: this.analysis.project.name,
|
|
|
|
|
type: this.analysis.project.type,
|
|
|
|
|
generated: new Date().toISOString(),
|
|
|
|
|
} : undefined;
|
|
|
|
|
|
|
|
|
|
return renderer.wrap(result, metadata);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private generateJsonContent(template: AgentInstructionTemplate): string {
|
|
|
|
|
if (!this.analysis) return '{}';
|
|
|
|
|
|
|
|
|
|
const data: Record<string, unknown> = {
|
|
|
|
|
project: this.analysis.project,
|
|
|
|
|
languages: this.analysis.languages.map(l => l.name),
|
|
|
|
|
packageManagers: this.analysis.packageManagers,
|
|
|
|
|
stack: {
|
|
|
|
|
frameworks: this.analysis.stack.frameworks.map(f => ({ name: f.name, version: f.version })),
|
|
|
|
|
libraries: this.analysis.stack.libraries.map(l => ({ name: l.name, version: l.version })),
|
|
|
|
|
styling: this.analysis.stack.styling.map(s => s.name),
|
|
|
|
|
testing: this.analysis.stack.testing.map(t => t.name),
|
|
|
|
|
databases: this.analysis.stack.databases.map(d => d.name),
|
|
|
|
|
},
|
|
|
|
|
commands: this.analysis.buildCommands,
|
|
|
|
|
conventions: this.analysis.conventions,
|
|
|
|
|
structure: this.analysis.structure,
|
|
|
|
|
importantFiles: this.analysis.importantFiles,
|
|
|
|
|
generated: {
|
|
|
|
|
agent: template.agent,
|
|
|
|
|
timestamp: new Date().toISOString(),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (this.options.customInstructions) {
|
|
|
|
|
data.customInstructions = this.options.customInstructions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return JSON.stringify(data, null, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private generateSection(section: string, template: AgentInstructionTemplate, renderer: FormatRenderer): string {
|
|
|
|
|
private generateSection(section: string, template: AgentInstructionTemplate): string {
|
|
|
|
|
if (!this.analysis) return '';
|
|
|
|
|
|
|
|
|
|
switch (section) {
|
|
|
|
|
case 'overview':
|
|
|
|
|
return this.generateOverviewSection(renderer);
|
|
|
|
|
return this.generateOverviewSection();
|
|
|
|
|
case 'stack':
|
|
|
|
|
return this.generateStackSection(renderer);
|
|
|
|
|
return this.generateStackSection();
|
|
|
|
|
case 'commands':
|
|
|
|
|
return this.generateCommandsSection(renderer);
|
|
|
|
|
return this.generateCommandsSection();
|
|
|
|
|
case 'conventions':
|
|
|
|
|
return this.generateConventionsSection(renderer);
|
|
|
|
|
return this.generateConventionsSection();
|
|
|
|
|
case 'structure':
|
|
|
|
|
return this.generateStructureSection(renderer);
|
|
|
|
|
return this.generateStructureSection();
|
|
|
|
|
case 'guidelines':
|
|
|
|
|
return this.generateGuidelinesSection(template.agent, renderer);
|
|
|
|
|
return this.generateGuidelinesSection(template.agent);
|
|
|
|
|
default:
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private generateOverviewSection(renderer: FormatRenderer): string {
|
|
|
|
|
private generateOverviewSection(): string {
|
|
|
|
|
if (!this.analysis) return '';
|
|
|
|
|
|
|
|
|
|
const { project, languages } = this.analysis;
|
|
|
|
|
const lines: string[] = [];
|
|
|
|
|
|
|
|
|
|
lines.push(renderer.h1(project.name));
|
|
|
|
|
lines.push(`# ${project.name}`);
|
|
|
|
|
lines.push('');
|
|
|
|
|
|
|
|
|
|
if (project.description) {
|
|
|
|
|
lines.push(renderer.paragraph(project.description));
|
|
|
|
|
lines.push(project.description);
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (project.type) {
|
|
|
|
|
lines.push(renderer.keyValue('Project Type', this.formatProjectType(project.type)));
|
|
|
|
|
lines.push(`**Project Type:** ${this.formatProjectType(project.type)}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (languages.length > 0) {
|
|
|
|
|
const langNames = languages.map(l => this.capitalize(l.name)).join(', ');
|
|
|
|
|
lines.push(renderer.keyValue('Languages', langNames));
|
|
|
|
|
lines.push(`**Languages:** ${langNames}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (project.version) {
|
|
|
|
|
lines.push(renderer.keyValue('Version', project.version));
|
|
|
|
|
lines.push(`**Version:** ${project.version}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return lines.join('\n');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private generateStackSection(renderer: FormatRenderer): string {
|
|
|
|
|
private generateStackSection(): string {
|
|
|
|
|
if (!this.analysis) return '';
|
|
|
|
|
|
|
|
|
|
const { stack, packageManagers } = this.analysis;
|
|
|
|
|
const lines: string[] = [];
|
|
|
|
|
|
|
|
|
|
lines.push(renderer.h2('Technology Stack'));
|
|
|
|
|
lines.push('## Technology Stack');
|
|
|
|
|
lines.push('');
|
|
|
|
|
|
|
|
|
|
if (stack.frameworks.length > 0) {
|
|
|
|
|
lines.push(renderer.h3('Frameworks'));
|
|
|
|
|
const items = stack.frameworks.map(fw => {
|
|
|
|
|
lines.push('### Frameworks');
|
|
|
|
|
for (const fw of stack.frameworks) {
|
|
|
|
|
const version = fw.version ? ` (${fw.version})` : '';
|
|
|
|
|
return `${this.capitalize(fw.name)}${version}`;
|
|
|
|
|
});
|
|
|
|
|
lines.push(renderer.list(items));
|
|
|
|
|
lines.push(`- ${this.capitalize(fw.name)}${version}`);
|
|
|
|
|
}
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stack.libraries.length > 0) {
|
|
|
|
|
lines.push(renderer.h3('Libraries'));
|
|
|
|
|
const items = stack.libraries.map(lib => {
|
|
|
|
|
lines.push('### Libraries');
|
|
|
|
|
for (const lib of stack.libraries) {
|
|
|
|
|
const version = lib.version ? ` (${lib.version})` : '';
|
|
|
|
|
return `${this.capitalize(lib.name)}${version}`;
|
|
|
|
|
});
|
|
|
|
|
lines.push(renderer.list(items));
|
|
|
|
|
lines.push(`- ${this.capitalize(lib.name)}${version}`);
|
|
|
|
|
}
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stack.styling.length > 0) {
|
|
|
|
|
lines.push(renderer.h3('Styling'));
|
|
|
|
|
lines.push(renderer.list(stack.styling.map(s => this.capitalize(s.name))));
|
|
|
|
|
lines.push('### Styling');
|
|
|
|
|
for (const style of stack.styling) {
|
|
|
|
|
lines.push(`- ${this.capitalize(style.name)}`);
|
|
|
|
|
}
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stack.testing.length > 0) {
|
|
|
|
|
lines.push(renderer.h3('Testing'));
|
|
|
|
|
lines.push(renderer.list(stack.testing.map(t => this.capitalize(t.name))));
|
|
|
|
|
lines.push('### Testing');
|
|
|
|
|
for (const test of stack.testing) {
|
|
|
|
|
lines.push(`- ${this.capitalize(test.name)}`);
|
|
|
|
|
}
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stack.databases.length > 0) {
|
|
|
|
|
lines.push(renderer.h3('Databases'));
|
|
|
|
|
lines.push(renderer.list(stack.databases.map(d => this.capitalize(d.name))));
|
|
|
|
|
lines.push('### Databases');
|
|
|
|
|
for (const db of stack.databases) {
|
|
|
|
|
lines.push(`- ${this.capitalize(db.name)}`);
|
|
|
|
|
}
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (packageManagers.length > 0) {
|
|
|
|
|
lines.push(renderer.h3('Package Manager'));
|
|
|
|
|
lines.push(renderer.list([packageManagers.map(pm => this.capitalize(pm)).join(', ')]));
|
|
|
|
|
lines.push('### Package Manager');
|
|
|
|
|
lines.push(`- ${packageManagers.map(pm => this.capitalize(pm)).join(', ')}`);
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return lines.join('\n');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private generateCommandsSection(renderer: FormatRenderer): string {
|
|
|
|
|
private generateCommandsSection(): string {
|
|
|
|
|
if (!this.analysis || !this.analysis.buildCommands) return '';
|
|
|
|
|
|
|
|
|
|
const { buildCommands } = this.analysis;
|
|
|
|
|
const lines: string[] = [];
|
|
|
|
|
const commands: string[] = [];
|
|
|
|
|
|
|
|
|
|
lines.push(renderer.h2('Development Commands'));
|
|
|
|
|
lines.push('## Development Commands');
|
|
|
|
|
lines.push('');
|
|
|
|
|
lines.push('```bash');
|
|
|
|
|
|
|
|
|
|
if (buildCommands.install) {
|
|
|
|
|
commands.push(`# Install dependencies`);
|
|
|
|
|
commands.push(buildCommands.install);
|
|
|
|
|
commands.push('');
|
|
|
|
|
lines.push(`# Install dependencies`);
|
|
|
|
|
lines.push(buildCommands.install);
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (buildCommands.dev) {
|
|
|
|
|
commands.push(`# Start development server`);
|
|
|
|
|
commands.push(buildCommands.dev);
|
|
|
|
|
commands.push('');
|
|
|
|
|
lines.push(`# Start development server`);
|
|
|
|
|
lines.push(buildCommands.dev);
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (buildCommands.build) {
|
|
|
|
|
commands.push(`# Build for production`);
|
|
|
|
|
commands.push(buildCommands.build);
|
|
|
|
|
commands.push('');
|
|
|
|
|
lines.push(`# Build for production`);
|
|
|
|
|
lines.push(buildCommands.build);
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (buildCommands.test) {
|
|
|
|
|
commands.push(`# Run tests`);
|
|
|
|
|
commands.push(buildCommands.test);
|
|
|
|
|
commands.push('');
|
|
|
|
|
lines.push(`# Run tests`);
|
|
|
|
|
lines.push(buildCommands.test);
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (buildCommands.lint) {
|
|
|
|
|
commands.push(`# Run linter`);
|
|
|
|
|
commands.push(buildCommands.lint);
|
|
|
|
|
commands.push('');
|
|
|
|
|
lines.push(`# Run linter`);
|
|
|
|
|
lines.push(buildCommands.lint);
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (buildCommands.format) {
|
|
|
|
|
commands.push(`# Format code`);
|
|
|
|
|
commands.push(buildCommands.format);
|
|
|
|
|
lines.push(`# Format code`);
|
|
|
|
|
lines.push(buildCommands.format);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lines.push(renderer.codeBlock(commands.join('\n'), 'bash'));
|
|
|
|
|
lines.push('```');
|
|
|
|
|
|
|
|
|
|
return lines.join('\n');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private generateConventionsSection(renderer: FormatRenderer): string {
|
|
|
|
|
private generateConventionsSection(): string {
|
|
|
|
|
if (!this.analysis) return '';
|
|
|
|
|
|
|
|
|
|
const { conventions, patterns } = this.analysis;
|
|
|
|
|
const lines: string[] = [];
|
|
|
|
|
|
|
|
|
|
lines.push(renderer.h2('Code Conventions'));
|
|
|
|
|
lines.push('## Code Conventions');
|
|
|
|
|
lines.push('');
|
|
|
|
|
|
|
|
|
|
if (conventions) {
|
|
|
|
|
const items: string[] = [];
|
|
|
|
|
if (conventions.indentation) {
|
|
|
|
|
items.push(`${renderer.bold('Indentation:')} ${conventions.indentation}`);
|
|
|
|
|
lines.push(`- **Indentation:** ${conventions.indentation}`);
|
|
|
|
|
}
|
|
|
|
|
if (conventions.quotes) {
|
|
|
|
|
items.push(`${renderer.bold('Quotes:')} ${conventions.quotes}`);
|
|
|
|
|
lines.push(`- **Quotes:** ${conventions.quotes}`);
|
|
|
|
|
}
|
|
|
|
|
if (conventions.semicolons !== undefined) {
|
|
|
|
|
items.push(`${renderer.bold('Semicolons:')} ${conventions.semicolons ? 'required' : 'omitted'}`);
|
|
|
|
|
lines.push(`- **Semicolons:** ${conventions.semicolons ? 'required' : 'omitted'}`);
|
|
|
|
|
}
|
|
|
|
|
if (conventions.trailingCommas) {
|
|
|
|
|
items.push(`${renderer.bold('Trailing Commas:')} ${conventions.trailingCommas}`);
|
|
|
|
|
lines.push(`- **Trailing Commas:** ${conventions.trailingCommas}`);
|
|
|
|
|
}
|
|
|
|
|
if (conventions.maxLineLength) {
|
|
|
|
|
items.push(`${renderer.bold('Max Line Length:')} ${conventions.maxLineLength}`);
|
|
|
|
|
}
|
|
|
|
|
if (items.length > 0) {
|
|
|
|
|
lines.push(renderer.list(items));
|
|
|
|
|
lines.push(`- **Max Line Length:** ${conventions.maxLineLength}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (patterns) {
|
|
|
|
|
lines.push('');
|
|
|
|
|
lines.push(renderer.h3('Patterns'));
|
|
|
|
|
const items: string[] = [];
|
|
|
|
|
lines.push('### Patterns');
|
|
|
|
|
if (patterns.components) {
|
|
|
|
|
items.push(`${renderer.bold('Components:')} ${patterns.components}`);
|
|
|
|
|
lines.push(`- **Components:** ${patterns.components}`);
|
|
|
|
|
}
|
|
|
|
|
if (patterns.stateManagement) {
|
|
|
|
|
items.push(`${renderer.bold('State Management:')} ${patterns.stateManagement}`);
|
|
|
|
|
lines.push(`- **State Management:** ${patterns.stateManagement}`);
|
|
|
|
|
}
|
|
|
|
|
if (patterns.apiStyle) {
|
|
|
|
|
items.push(`${renderer.bold('API Style:')} ${patterns.apiStyle}`);
|
|
|
|
|
lines.push(`- **API Style:** ${patterns.apiStyle}`);
|
|
|
|
|
}
|
|
|
|
|
if (patterns.styling) {
|
|
|
|
|
items.push(`${renderer.bold('Styling:')} ${patterns.styling}`);
|
|
|
|
|
lines.push(`- **Styling:** ${patterns.styling}`);
|
|
|
|
|
}
|
|
|
|
|
if (patterns.testing) {
|
|
|
|
|
items.push(`${renderer.bold('Testing:')} ${patterns.testing}`);
|
|
|
|
|
lines.push(`- **Testing:** ${patterns.testing}`);
|
|
|
|
|
}
|
|
|
|
|
if (patterns.linting) {
|
|
|
|
|
items.push(`${renderer.bold('Linting:')} ${patterns.linting}`);
|
|
|
|
|
lines.push(`- **Linting:** ${patterns.linting}`);
|
|
|
|
|
}
|
|
|
|
|
if (patterns.formatting) {
|
|
|
|
|
items.push(`${renderer.bold('Formatting:')} ${patterns.formatting}`);
|
|
|
|
|
}
|
|
|
|
|
if (items.length > 0) {
|
|
|
|
|
lines.push(renderer.list(items));
|
|
|
|
|
lines.push(`- **Formatting:** ${patterns.formatting}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return lines.join('\n');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private generateStructureSection(renderer: FormatRenderer): string {
|
|
|
|
|
private generateStructureSection(): string {
|
|
|
|
|
if (!this.analysis) return '';
|
|
|
|
|
|
|
|
|
|
const { structure, importantFiles } = this.analysis;
|
|
|
|
|
const lines: string[] = [];
|
|
|
|
|
|
|
|
|
|
lines.push(renderer.h2('Project Structure'));
|
|
|
|
|
lines.push('## Project Structure');
|
|
|
|
|
lines.push('');
|
|
|
|
|
|
|
|
|
|
if (structure) {
|
|
|
|
|
if (structure.type) {
|
|
|
|
|
lines.push(renderer.keyValue('Structure Type', structure.type));
|
|
|
|
|
lines.push(`**Structure Type:** ${structure.type}`);
|
|
|
|
|
}
|
|
|
|
|
if (structure.srcDir) {
|
|
|
|
|
lines.push(renderer.keyValue('Source Directory', renderer.code(`${structure.srcDir}/`)));
|
|
|
|
|
lines.push(`**Source Directory:** \`${structure.srcDir}/\``);
|
|
|
|
|
}
|
|
|
|
|
if (structure.testDir) {
|
|
|
|
|
lines.push(renderer.keyValue('Test Directory', renderer.code(`${structure.testDir}/`)));
|
|
|
|
|
lines.push(`**Test Directory:** \`${structure.testDir}/\``);
|
|
|
|
|
}
|
|
|
|
|
if (structure.hasWorkspaces && structure.workspaces) {
|
|
|
|
|
lines.push(renderer.keyValue('Workspaces', structure.workspaces.join(', ')));
|
|
|
|
|
lines.push(`**Workspaces:** ${structure.workspaces.join(', ')}`);
|
|
|
|
|
}
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (importantFiles.length > 0) {
|
|
|
|
|
lines.push(renderer.h3('Important Files'));
|
|
|
|
|
lines.push(renderer.list(importantFiles.slice(0, 15).map(f => renderer.code(f))));
|
|
|
|
|
lines.push('### Important Files');
|
|
|
|
|
for (const file of importantFiles.slice(0, 15)) {
|
|
|
|
|
lines.push(`- \`${file}\``);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return lines.join('\n');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private generateGuidelinesSection(_agent: AgentType, renderer: FormatRenderer): string {
|
|
|
|
|
private generateGuidelinesSection(_agent: AgentType): string {
|
|
|
|
|
if (!this.analysis) return '';
|
|
|
|
|
|
|
|
|
|
const { stack, patterns } = this.analysis;
|
|
|
|
|
const lines: string[] = [];
|
|
|
|
|
|
|
|
|
|
lines.push(renderer.h2('Development Guidelines'));
|
|
|
|
|
lines.push('## Development Guidelines');
|
|
|
|
|
lines.push('');
|
|
|
|
|
|
|
|
|
|
const hasReact = stack.frameworks.some(f => f.name === 'react' || f.name === 'nextjs');
|
|
|
|
@@ -616,74 +468,59 @@ export class PrimerGenerator {
|
|
|
|
|
const hasZod = stack.libraries.some(l => l.name === 'zod');
|
|
|
|
|
|
|
|
|
|
if (hasTypeScript) {
|
|
|
|
|
lines.push(renderer.h3('TypeScript'));
|
|
|
|
|
lines.push(renderer.list([
|
|
|
|
|
'Use strict TypeScript with proper type annotations',
|
|
|
|
|
'Prefer `interface` for object types, `type` for unions/intersections',
|
|
|
|
|
'Avoid `any` - use `unknown` when type is uncertain',
|
|
|
|
|
]));
|
|
|
|
|
lines.push('### TypeScript');
|
|
|
|
|
lines.push('- Use strict TypeScript with proper type annotations');
|
|
|
|
|
lines.push('- Prefer `interface` for object types, `type` for unions/intersections');
|
|
|
|
|
lines.push('- Avoid `any` - use `unknown` when type is uncertain');
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hasReact) {
|
|
|
|
|
lines.push(renderer.h3('React'));
|
|
|
|
|
const reactItems = [
|
|
|
|
|
'Use functional components with hooks',
|
|
|
|
|
'Prefer composition over inheritance',
|
|
|
|
|
'Keep components small and focused',
|
|
|
|
|
];
|
|
|
|
|
lines.push('### React');
|
|
|
|
|
lines.push('- Use functional components with hooks');
|
|
|
|
|
lines.push('- Prefer composition over inheritance');
|
|
|
|
|
lines.push('- Keep components small and focused');
|
|
|
|
|
if (patterns?.stateManagement) {
|
|
|
|
|
reactItems.push(`Use ${patterns.stateManagement} for state management`);
|
|
|
|
|
lines.push(`- Use ${patterns.stateManagement} for state management`);
|
|
|
|
|
}
|
|
|
|
|
lines.push(renderer.list(reactItems));
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hasVue) {
|
|
|
|
|
lines.push(renderer.h3('Vue'));
|
|
|
|
|
lines.push(renderer.list([
|
|
|
|
|
'Use Composition API with `<script setup>`',
|
|
|
|
|
'Keep components small and focused',
|
|
|
|
|
]));
|
|
|
|
|
lines.push('### Vue');
|
|
|
|
|
lines.push('- Use Composition API with `<script setup>`');
|
|
|
|
|
lines.push('- Keep components small and focused');
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hasTailwind) {
|
|
|
|
|
lines.push(renderer.h3('Styling'));
|
|
|
|
|
lines.push(renderer.list([
|
|
|
|
|
'Use Tailwind CSS utility classes',
|
|
|
|
|
'Follow mobile-first responsive design',
|
|
|
|
|
'Extract repeated patterns to components',
|
|
|
|
|
]));
|
|
|
|
|
lines.push('### Styling');
|
|
|
|
|
lines.push('- Use Tailwind CSS utility classes');
|
|
|
|
|
lines.push('- Follow mobile-first responsive design');
|
|
|
|
|
lines.push('- Extract repeated patterns to components');
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hasPrisma) {
|
|
|
|
|
lines.push(renderer.h3('Database'));
|
|
|
|
|
lines.push(renderer.list([
|
|
|
|
|
'Use Prisma for database operations',
|
|
|
|
|
'Keep database queries in dedicated service files',
|
|
|
|
|
'Use transactions for related operations',
|
|
|
|
|
]));
|
|
|
|
|
lines.push('### Database');
|
|
|
|
|
lines.push('- Use Prisma for database operations');
|
|
|
|
|
lines.push('- Keep database queries in dedicated service files');
|
|
|
|
|
lines.push('- Use transactions for related operations');
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hasZod) {
|
|
|
|
|
lines.push(renderer.h3('Validation'));
|
|
|
|
|
lines.push(renderer.list([
|
|
|
|
|
'Use Zod for runtime validation',
|
|
|
|
|
'Define schemas alongside types',
|
|
|
|
|
]));
|
|
|
|
|
lines.push('### Validation');
|
|
|
|
|
lines.push('- Use Zod for runtime validation');
|
|
|
|
|
lines.push('- Define schemas alongside types');
|
|
|
|
|
lines.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lines.push(renderer.h3('General'));
|
|
|
|
|
lines.push(renderer.list([
|
|
|
|
|
'Follow existing code patterns and conventions',
|
|
|
|
|
'Write clear, self-documenting code',
|
|
|
|
|
'Keep functions small and focused',
|
|
|
|
|
'Add tests for new functionality',
|
|
|
|
|
]));
|
|
|
|
|
lines.push('### General');
|
|
|
|
|
lines.push('- Follow existing code patterns and conventions');
|
|
|
|
|
lines.push('- Write clear, self-documenting code');
|
|
|
|
|
lines.push('- Keep functions small and focused');
|
|
|
|
|
lines.push('- Add tests for new functionality');
|
|
|
|
|
|
|
|
|
|
return lines.join('\n');
|
|
|
|
|
}
|
|
|
|
|