feat: add patterns detection prompt
This commit is contained in:
55
packages/llm/src/prompts/patterns-detection.ts
Normal file
55
packages/llm/src/prompts/patterns-detection.ts
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import type { LLMMessage, CodeStructure } from "@codeboard/shared";
|
||||||
|
|
||||||
|
export function buildPatternsPrompt(structure: CodeStructure): LLMMessage[] {
|
||||||
|
const sampleFunctions = structure.files
|
||||||
|
.flatMap((f) => f.functions.map((fn) => `${f.path}: ${fn.name}(${fn.params.join(", ")})`))
|
||||||
|
.slice(0, 40)
|
||||||
|
.join("\n");
|
||||||
|
|
||||||
|
const sampleClasses = structure.files
|
||||||
|
.flatMap((f) => f.classes.map((c) => `${f.path}: class ${c.name} [${c.methods.map((m) => m.name).join(", ")}]`))
|
||||||
|
.slice(0, 20)
|
||||||
|
.join("\n");
|
||||||
|
|
||||||
|
const importSources = new Set<string>();
|
||||||
|
for (const f of structure.files) {
|
||||||
|
for (const imp of f.imports) {
|
||||||
|
importSources.add(imp.source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
role: "system",
|
||||||
|
content: `You are a code reviewer identifying patterns and conventions in a codebase.
|
||||||
|
|
||||||
|
Output format:
|
||||||
|
## Coding Conventions
|
||||||
|
[list conventions like naming patterns, file organization, error handling approach]
|
||||||
|
|
||||||
|
## Design Patterns
|
||||||
|
[list design patterns detected: factory, singleton, observer, repository, etc.]
|
||||||
|
|
||||||
|
## Architectural Decisions
|
||||||
|
[list key architectural decisions: monorepo vs polyrepo, framework choices, state management, etc.]`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: `Analyze these code patterns:
|
||||||
|
|
||||||
|
FUNCTION SIGNATURES:
|
||||||
|
${sampleFunctions}
|
||||||
|
|
||||||
|
CLASS DEFINITIONS:
|
||||||
|
${sampleClasses}
|
||||||
|
|
||||||
|
EXTERNAL DEPENDENCIES:
|
||||||
|
${Array.from(importSources).filter((s) => !s.startsWith(".")).slice(0, 30).join(", ")}
|
||||||
|
|
||||||
|
DETECTED PATTERNS FROM AST:
|
||||||
|
${structure.patterns.map((p) => ` ${p.name}: ${p.description}`).join("\n") || " (none pre-detected)"}
|
||||||
|
|
||||||
|
Identify coding conventions, design patterns, and architectural decisions.`,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user