UNPKG

scai

Version:

> **AI-powered CLI for local code analysis, commit message suggestions, and natural-language queries.** 100% local, private, GDPR-friendly, made in Denmark/EU with ❤️.

59 lines (58 loc) 2.42 kB
import { getDbForRepo } from "../db/client.js"; import { generate } from "../lib/generate.js"; export async function generateSummaries() { const db = getDbForRepo(); const files = db .prepare(`SELECT path, summary FROM files WHERE summary IS NOT NULL`) .all(); // --- Group by folder --- const folders = new Map(); for (const { path, summary } of files) { if (!summary) continue; const parts = path.split("/"); parts.pop(); // remove filename const folderPath = parts.join("/") || "/"; if (!folders.has(folderPath)) folders.set(folderPath, []); folders.get(folderPath).push(summary); } // --- Generate folder-level summaries --- for (const [folderPath, summaries] of folders.entries()) { const content = summaries.join("\n\n"); const input = { query: `Summarize folder ${folderPath}`, content: `Summarize the following files to describe what this folder (${folderPath}) does:\n\n${content}`, }; const response = await generate(input); const summaryText = String(response.content ?? "").trim(); db.prepare(` INSERT INTO summaries (path, type, summary, last_generated) VALUES (?, 'folder', ?, datetime('now')) ON CONFLICT(path) DO UPDATE SET summary=excluded.summary, last_generated=datetime('now') `).run(folderPath, summaryText); console.log(`🧠 Folder summary generated for ${folderPath}`); } // --- Project-level summary generation --- const allFolderSummaries = db .prepare(`SELECT summary FROM summaries WHERE type='folder'`) .all() .map((r) => r.summary) .join("\n\n"); const projectInput = { query: "Summarize project", content: `Summarize the overall purpose and structure of the project based on these folder summaries:\n\n${allFolderSummaries}`, }; const projectResponse = await generate(projectInput); const projectSummary = String(projectResponse.content ?? "").trim(); db.prepare(` INSERT INTO summaries (path, type, summary, last_generated) VALUES ('/', 'project', ?, datetime('now')) ON CONFLICT(path) DO UPDATE SET summary=excluded.summary, last_generated=datetime('now') `).run(projectSummary); console.log("🏗️ Project-level summary generated"); }