import { readdirSync, statSync } from "node:fs"; import { createDb } from "../packages/db/src/index.js"; async function audit() { const { prisma } = createDb("postgres://ingowagner@127.0.0.1:5432/evoo"); console.log("=== 1. CHECK RUNS PER BOT ==="); const bots = await prisma.bot.findMany({ include: { runs: { orderBy: { createdAt: "desc" }, take: 3, }, thread: { include: { messages: { orderBy: { seq: "desc" }, take: 2, }, }, }, }, }); for (const b of bots) { console.log(`\nBot: ${b.name} (${b.id}) [${b.title || "No Title"}]`); console.log(` Total runs in DB: ${await prisma.run.count({ where: { botId: b.id } })}`); console.log( ` Thread messages count: ${await prisma.message.count({ where: { threadId: b.thread?.id } })}`, ); for (const r of b.runs) { console.log( ` Run ${r.id}: status=${r.status}, error=${r.error}, completedAt=${r.completedAt}`, ); } } console.log("\n=== 2. CHECK TOOL CALLS IN EVENTS ==="); const toolEvents = await prisma.event.findMany({ where: { type: { in: ["tool.started", "tool.completed", "tool.failed", "agent.action"] }, }, orderBy: { createdAt: "desc" }, take: 10, }); console.log(`Total recent tool events: ${toolEvents.length}`); for (const e of toolEvents) { console.log(` [${e.createdAt.toISOString()}] ${e.type} (run: ${e.runId})`); } console.log("\n=== 3. CHECK GROUP CHAT THREAD ==="); const groups = await prisma.chatGroup.findMany({ include: { thread: { include: { messages: true, }, }, }, }); for (const g of groups) { console.log(`Group: ${g.name}, thread messages: ${g.thread?.messages.length}`); } console.log("\n=== 4. CHECK SANDBOX FILES MODIFICATION TIMES ==="); const baseDir = "/Users/ingowagner/evOo/data/homes/team-9d790f3a504d3e9ef577ca4f2118e446/bots"; const botDirs = readdirSync(baseDir); for (const d of botDirs) { const p = `${baseDir}/${d}/TODO.md`; try { const st = statSync(p); console.log(`Bot ${d} TODO.md modified: ${st.mtime.toISOString()}`); } catch { console.log(`Bot ${d} has NO TODO.md`); } } } audit() .catch(console.error) .finally(() => process.exit(0));