import{j as e}from"./agent-scope-BKE4M04k.js";import{b as t,g as n,v as r}from"./utils-7Gdj77QB.js";import i from"node:path";import a from"node:fs/promises";function o(t){let n=new Set,i=t?.agents?.defaults;typeof i?.workspace==`string`&&i.workspace.trim()&&n.add(r(i.workspace));let a=Array.isArray(t?.agents?.list)?t?.agents?.list:[];for(let e of a){let t=e.workspace;typeof t==`string`&&t.trim()&&n.add(r(t))}return n.size===0&&n.add(e()),[...n]}function s(e){return{configInsideState:c(e.configPath,e.stateDir),oauthInsideState:c(e.oauthDir,e.stateDir),workspaceDirs:o(e.cfg)}}function c(e,t){let n=i.relative(t,e);return n===``||!n.startsWith(`..`)&&!i.isAbsolute(n)}function l(e){if(!e.trim())return!0;let t=i.resolve(e);if(t===i.parse(t).root)return!0;let r=n();return!!(r&&t===i.resolve(r))}async function u(e,n,r){if(!e?.trim())return{ok:!1,skipped:!0};let o=i.resolve(e),s=t(r?.label??o);if(l(o))return n.error(`Refusing to remove unsafe path: ${s}`),{ok:!1};if(r?.dryRun)return n.log(`[dry-run] remove ${s}`),{ok:!0,skipped:!0};try{return await a.rm(o,{recursive:!0,force:!0}),n.log(`Removed ${s}`),{ok:!0}}catch(e){return n.error(`Failed to remove ${s}: ${String(e)}`),{ok:!1}}}async function d(e,t,n){await u(e.stateDir,t,{dryRun:n?.dryRun,label:e.stateDir}),e.configInsideState||await u(e.configPath,t,{dryRun:n?.dryRun,label:e.configPath}),e.oauthInsideState||await u(e.oauthDir,t,{dryRun:n?.dryRun,label:e.oauthDir})}async function f(e,t,n){for(let r of e)await u(r,t,{dryRun:n?.dryRun,label:r})}async function p(e){let t=i.join(e,`agents`);try{return(await a.readdir(t,{withFileTypes:!0})).filter(e=>e.isDirectory()).map(e=>i.join(t,e.name,`sessions`))}catch{return[]}}export{d as a,u as i,c as n,f as o,p as r,s as t};
