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:
committed by
exe.dev user
parent
d7c76ac12b
commit
8a205808e0
@@ -45,9 +45,7 @@ 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
|
|
||||||
// automatically without updating a hardcoded list.
|
|
||||||
const tables = db
|
const tables = db
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT DISTINCT m.name FROM sqlite_master m
|
`SELECT DISTINCT m.name FROM sqlite_master m
|
||||||
@@ -58,8 +56,9 @@ const tables = db
|
|||||||
for (const { name } of tables) {
|
for (const { name } of tables) {
|
||||||
db.prepare(`DELETE FROM ${name} WHERE agent_group_id = ?`).run(ag.id);
|
db.prepare(`DELETE FROM ${name} WHERE agent_group_id = ?`).run(ag.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteAgentGroup(ag.id);
|
deleteAgentGroup(ag.id);
|
||||||
|
});
|
||||||
|
cleanup();
|
||||||
|
|
||||||
// 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}).`);
|
||||||
|
|||||||
Reference in New Issue
Block a user