import * as fsPromises from "node:fs/promises";
import { assertNoSymbolicLinkPath } from "./plugin-args.js";
const auditLog = (logPath, fs = fsPromises) => ({
    name: "audit-log",
    hooks: {
        async postToolUse(ctx) {
            await assertNoSymbolicLinkPath(fs, logPath);
            await fs.appendFile(logPath, `${JSON.stringify({ ts: new Date().toISOString(), tool: ctx.tool })}\n`).catch(() => undefined);
        },
        async postCompaction(ctx) {
            await assertNoSymbolicLinkPath(fs, logPath);
            await fs.appendFile(logPath, `${JSON.stringify({
                ts: new Date().toISOString(),
                event: "compaction",
                summary: ctx.summary,
                droppedMessageCount: ctx.droppedMessages.length,
            })}\n`);
        },
    },
});
export default auditLog;
