peppa/packages/db/scripts/export-epics.ts
Асель cdc7e62bfc PEP-73: project tab AGENTS.md — read and edit the agents' prompt
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 18:25:40 +05:00

48 lines
2.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Dumps a project's goals (epics) and their tasks with descriptions into Markdown.
// Usage: tsx packages/db/scripts/export-epics.ts [KEY=PEP] [out=PEPPE_EPICS.md]
import { writeFileSync } from "node:fs";
import { asc, eq } from "drizzle-orm";
import { createDb, goals, projects, tasks } from "../src/index.ts";
const [key = "PEP", out = "PEPPE_EPICS.md"] = process.argv.slice(2);
const db = createDb();
const [project] = await db.select().from(projects).where(eq(projects.key, key));
if (!project) throw new Error(`no project ${key}`);
const gs = await db.select().from(goals).where(eq(goals.projectId, project.id)).orderBy(asc(goals.id));
const ts = await db.select().from(tasks).where(eq(tasks.projectId, project.id)).orderBy(asc(tasks.number));
const STATUS: Record<string, string> = {
backlog: "Бэклог", proposing: "Proposal", awaiting_approval: "Ждёт одобрения",
in_progress: "В работе", review: "Ревью", done: "Готово", blocked: "Заблокирована",
};
function section(title: string, desc: string | null, items: typeof ts) {
const done = items.filter((t) => t.status === "done").length;
const lines = [`## ${title}`, "", `Задач: ${items.length}, готово: ${done}`, ""];
if (desc?.trim()) lines.push(desc.trim(), "");
for (const t of items) {
lines.push(`### ${key}-${t.number}: ${t.title}`, "");
const meta = [`Статус: ${STATUS[t.status] ?? t.status}`];
if (t.openspecChange) meta.push(`OpenSpec: \`${t.openspecChange}\``);
if (t.prUrl) meta.push(`PR: ${t.prUrl}`);
lines.push(meta.join(" · "), "");
if (t.description?.trim()) lines.push(t.description.trim(), "");
}
return lines.join("\n");
}
const parts = [
`# ${project.name} (${key}) — эпики и задачи`,
"",
`Выгружено ${new Date().toISOString().slice(0, 16).replace("T", " ")}: целей ${gs.length}, задач ${ts.length}.`,
"",
...gs.map((g) => section(`${g.title}${g.status === "open" ? "" : ` (${g.status})`}`, g.description, ts.filter((t) => t.goalId === g.id))),
];
const orphans = ts.filter((t) => !t.goalId || !gs.some((g) => g.id === t.goalId));
if (orphans.length) parts.push(section("Без цели", null, orphans));
writeFileSync(out, parts.join("\n").trimEnd() + "\n");
console.log(`${out}: ${gs.length} goals, ${ts.length} tasks`);
process.exit(0);