From 8c0382483153ad9c67343d97d01bd734d7b96269 Mon Sep 17 00:00:00 2001 From: repi Date: Mon, 1 Jan 2001 00:00:00 +0000 Subject: [PATCH] feat: add module summary prompt --- packages/llm/src/prompts/module-summary.ts | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 packages/llm/src/prompts/module-summary.ts diff --git a/packages/llm/src/prompts/module-summary.ts b/packages/llm/src/prompts/module-summary.ts new file mode 100644 index 0000000..962d88a --- /dev/null +++ b/packages/llm/src/prompts/module-summary.ts @@ -0,0 +1,42 @@ +import type { LLMMessage, ModuleNode, FileNode } from "@codeboard/shared"; + +export function buildModuleSummaryPrompt( + module: ModuleNode, + files: FileNode[] +): LLMMessage[] { + const fileDetails = files + .map((f) => { + const fns = f.functions.map((fn) => ` ${fn.name}(${fn.params.join(", ")})`).join("\n"); + const cls = f.classes.map((c) => ` class ${c.name}`).join("\n"); + const exps = f.exports.map((e) => ` export ${e.isDefault ? "default " : ""}${e.name}`).join("\n"); + return ` ${f.path}:\n${fns}\n${cls}\n${exps}`; + }) + .join("\n\n"); + + return [ + { + role: "system", + content: `You are analyzing a code module. Provide a concise summary. + +Output format: +## Summary +[1-2 paragraphs explaining what this module does and its role in project] + +## Key Files +[list each important file with a one-line description] + +## Public API +[list main exported functions/classes and what they do]`, + }, + { + role: "user", + content: `Module: ${module.name} (${module.path}) +Files: ${module.files.length} + +FILE DETAILS: +${fileDetails} + +Summarize this module.`, + }, + ]; +}