fix(setup): wrap scratch agent cleanup in transaction, remove session data

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
gabi-simons
2026-04-30 07:56:34 +00:00
committed by exe.dev user
parent d7c76ac12b
commit 8a205808e0

View File

@@ -45,21 +45,20 @@ if (!ag) {
process.exit(0); process.exit(0);
} }
// Dynamically find every table with an agent_group_id column and delete const cleanup = db.transaction(() => {
// matching rows. This is self-maintaining — new FK tables are picked up const tables = db
// automatically without updating a hardcoded list. .prepare(
const tables = db `SELECT DISTINCT m.name FROM sqlite_master m
.prepare( JOIN pragma_table_info(m.name) p ON p.name = 'agent_group_id'
`SELECT DISTINCT m.name FROM sqlite_master m WHERE m.type = 'table' AND m.name != 'agent_groups'`,
JOIN pragma_table_info(m.name) p ON p.name = 'agent_group_id' )
WHERE m.type = 'table' AND m.name != 'agent_groups'`, .all() as { name: string }[];
) for (const { name } of tables) {
.all() as { name: string }[]; db.prepare(`DELETE FROM ${name} WHERE agent_group_id = ?`).run(ag.id);
for (const { name } of tables) { }
db.prepare(`DELETE FROM ${name} WHERE agent_group_id = ?`).run(ag.id); deleteAgentGroup(ag.id);
} });
cleanup();
deleteAgentGroup(ag.id);
// Remove the groups/<folder>/ directory. // Remove the groups/<folder>/ directory.
const groupDir = path.join(process.cwd(), 'groups', args.folder); const groupDir = path.join(process.cwd(), 'groups', args.folder);
@@ -67,4 +66,10 @@ if (fs.existsSync(groupDir)) {
fs.rmSync(groupDir, { recursive: true }); fs.rmSync(groupDir, { recursive: true });
} }
// Remove session data on disk.
const sessionsDir = path.join(DATA_DIR, 'v2-sessions', ag.id);
if (fs.existsSync(sessionsDir)) {
fs.rmSync(sessionsDir, { recursive: true });
}
console.log(`Deleted agent group ${ag.id} (${args.folder}).`); console.log(`Deleted agent group ${ag.id} (${args.folder}).`);