import { i as writeJsonFile, n as readJsonFile, r as writeJsonArray, t as readJsonArray } from "./json-store-WWsFzXub.js";
import path from "path";
import "crypto";
//#region src/core/approvals.ts
function policyPath(dataDir) {
	return path.join(dataDir, ".agentic", "policy.json");
}
function approvalsPath(dataDir) {
	return path.join(dataDir, ".agentic", "approvals.json");
}
function loadPolicyConfig(dataDir) {
	return readJsonFile(policyPath(dataDir), {});
}
function setPolicy(dataDir, tool, policy, slug) {
	const cfg = loadPolicyConfig(dataDir);
	if (slug) {
		cfg.customers = cfg.customers ?? {};
		cfg.customers[slug] = {
			...cfg.customers[slug] ?? {},
			[tool]: policy
		};
	} else cfg.tools = {
		...cfg.tools ?? {},
		[tool]: policy
	};
	writeJsonFile(policyPath(dataDir), cfg);
}
function listApprovals(dataDir, status) {
	const list = readJsonArray(approvalsPath(dataDir), "approvals");
	return status ? list.filter((a) => a.status === status) : list;
}
function writeApprovals(dataDir, approvals) {
	writeJsonArray(approvalsPath(dataDir), "approvals", approvals);
}
function decideApproval(dataDir, id, decision) {
	const all = listApprovals(dataDir);
	const idx = all.findIndex((a) => a.id === id);
	if (idx < 0) return false;
	all[idx] = {
		...all[idx],
		status: decision,
		decidedAt: (/* @__PURE__ */ new Date()).toISOString()
	};
	writeApprovals(dataDir, all);
	return true;
}
//#endregion
export { decideApproval, listApprovals, setPolicy };

//# sourceMappingURL=approvals-CmDT2eUg.js.map