import{n as e}from"./chunk-DR8-3Aex.js";import{D as t,E as n,O as r,_ as i,h as a,l as o,p as s}from"./debug-otxXY3j-.js";import{o as c,s as l}from"./log-DSV4Ht5l.js";import{AA as u,kA as d}from"./loadAgentsDir-C_wFhytF.js";import{join as f}from"path";import{randomBytes as p}from"crypto";import{readFile as m,rename as h,unlink as g,writeFile as _}from"fs/promises";function v(){return f(d(),D)}function y(e){let n=t(e);if(typeof n!=`object`||!n||!(`plugins`in n)||typeof n.plugins!=`object`||n.plugins===null)return{};let r=n.plugins,i={};for(let[e,t]of Object.entries(r))if(t&&typeof t==`object`&&`flaggedAt`in t&&typeof t.flaggedAt==`string`){let n={flaggedAt:t.flaggedAt};`seenAt`in t&&typeof t.seenAt==`string`&&(n.seenAt=t.seenAt),i[e]=n}return i}async function b(){try{return y(await m(v(),{encoding:`utf-8`}))}catch{return{}}}async function x(e){let t=v(),n=`${t}.${p(8).toString(`hex`)}.tmp`;try{await a().mkdir(d()),await _(n,r({plugins:e},null,2),{encoding:`utf-8`,mode:384}),await h(n,t),k=e}catch(e){l(e);try{await g(n)}catch{}}}async function S(){let e=await b(),t=Date.now(),n=!1;for(let[r,i]of Object.entries(e))i.seenAt&&t-new Date(i.seenAt).getTime()>=O&&(delete e[r],n=!0);k=e,n&&await x(e)}function C(){return k??{}}async function w(e){k===null&&(k=await b()),await x({...k,[e]:{flaggedAt:new Date().toISOString()}}),s(`Flagged plugin: ${e}`)}async function T(e){k===null&&(k=await b());let t=new Date().toISOString(),n=!1,r={...k};for(let i of e){let e=r[i];e&&!e.seenAt&&(r[i]={...e,seenAt:t},n=!0)}n&&await x(r)}async function E(e){if(k===null&&(k=await b()),!(e in k))return;let{[e]:t,...n}=k;k=n,await x(n)}var D,O,k,A=e((()=>{o(),i(),c(),n(),u(),D=`flagged-plugins.json`,O=2880*60*1e3,k=null}));export{T as a,S as i,C as n,E as o,A as r,w as t};