import path from "node:path";
import fs from "node:fs/promises";

//#region src/agents/session-dirs.ts
async function resolveAgentSessionDirs(stateDir) {
	const agentsDir = path.join(stateDir, "agents");
	let entries = [];
	try {
		entries = await fs.readdir(agentsDir, { withFileTypes: true });
	} catch (err) {
		if (err.code === "ENOENT") return [];
		throw err;
	}
	return entries.filter((entry) => entry.isDirectory()).map((entry) => path.join(agentsDir, entry.name, "sessions")).toSorted((a, b) => a.localeCompare(b));
}

//#endregion
export { resolveAgentSessionDirs as t };