diff --git a/packages/llm/src/prompts/patterns-detection.ts b/packages/llm/src/prompts/patterns-detection.ts new file mode 100644 index 0000000..b7b547e --- /dev/null +++ b/packages/llm/src/prompts/patterns-detection.ts @@ -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(); + 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.`, + }, + ]; +}