import { y as loadWorkspaceBootstrapFiles } from "./workspace-DTN6Y6b8.js";
//#region src/agents/bootstrap-cache.ts
const MAX_BOOTSTRAP_SNAPSHOTS = 64;
const cache = /* @__PURE__ */ new Map();
function bootstrapFilesEqual(previous, next) {
	if (previous.length !== next.length) return false;
	return previous.every((file, index) => {
		const updated = next[index];
		return updated !== void 0 && file.name === updated.name && file.path === updated.path && file.content === updated.content && file.missing === updated.missing;
	});
}
function pruneOldestBootstrapSnapshots() {
	while (cache.size > MAX_BOOTSTRAP_SNAPSHOTS) {
		const oldestKey = cache.keys().next().value;
		if (typeof oldestKey !== "string") return;
		cache.delete(oldestKey);
	}
}
async function getOrLoadBootstrapFiles(params) {
	pruneOldestBootstrapSnapshots();
	const existing = cache.get(params.sessionKey);
	const files = await loadWorkspaceBootstrapFiles(params.workspaceDir);
	if (existing && existing.workspaceDir === params.workspaceDir && bootstrapFilesEqual(existing.files, files)) {
		cache.delete(params.sessionKey);
		cache.set(params.sessionKey, existing);
		return existing.files;
	}
	cache.set(params.sessionKey, {
		workspaceDir: params.workspaceDir,
		files
	});
	pruneOldestBootstrapSnapshots();
	return files;
}
function clearBootstrapSnapshot(sessionKey) {
	cache.delete(sessionKey);
}
function clearBootstrapSnapshotOnSessionRollover(params) {
	if (!params.sessionKey || !params.previousSessionId) return;
	clearBootstrapSnapshot(params.sessionKey);
}
//#endregion
export { clearBootstrapSnapshotOnSessionRollover as n, getOrLoadBootstrapFiles as r, clearBootstrapSnapshot as t };
