import{s as e}from"./DrKWWDpL.js";import{t}from"./DYP3EJMY.js";var n=/^[A-Za-z]:[\\/]/;function r(e){return!!(e.startsWith(`/`)||n.test(e)||e.startsWith(`\\\\`))}var i=e(t(),1);Object.freeze([``,`   `,`.`,`..`,` .`,`. `,` ..`,`.. `,`../`,`../foo`,`foo/../bar`,`foo/bar`,`foo\\bar`,`foo\0bar`]);function a(e){if(typeof e!=`string`)return!1;let t=e.trim();return t!==``&&t!==`.`&&t!==`..`&&!e.includes(`/`)&&!e.includes(`\\`)&&!e.includes(`\0`)}function o(e){if(typeof e!=`string`)throw TypeError(`Expected a string`);if(!a(e))throw Error(`Unsafe filename: ${JSON.stringify(e)}`)}var s=i.default.homedir(),c=i.default.tmpdir(),{env:l}=i.default,u=e=>{let t=i.default.join(s,`Library`);return{data:i.default.join(t,`Application Support`,e),config:i.default.join(t,`Preferences`,e),cache:i.default.join(t,`Caches`,e),log:i.default.join(t,`Logs`,e),temp:i.default.join(c,e)}},d=e=>{let t=l.APPDATA||i.default.join(s,`AppData`,`Roaming`),n=l.LOCALAPPDATA||i.default.join(s,`AppData`,`Local`);return{data:i.default.join(n,e,`Data`),config:i.default.join(t,e,`Config`),cache:i.default.join(n,e,`Cache`),log:i.default.join(n,e,`Log`),temp:i.default.join(c,e)}},f=e=>{let t=i.default.basename(s);return{data:i.default.join(l.XDG_DATA_HOME||i.default.join(s,`.local`,`share`),e),config:i.default.join(l.XDG_CONFIG_HOME||i.default.join(s,`.config`),e),cache:i.default.join(l.XDG_CACHE_HOME||i.default.join(s,`.cache`),e),log:i.default.join(l.XDG_STATE_HOME||i.default.join(s,`.local`,`state`),e),temp:i.default.join(c,t,e)}};function p(e,{suffix:t=`nodejs`}={}){return o(e),t&&(e+=`-${t}`),o(e),i.default.platform===`darwin`?u(e):i.default.platform===`win32`?d(e):f(e)}function m(e){if(e===void 0)return;let t=e.trim();if(t.length!==0)return t===`~`?(0,i.homedir)():t.startsWith(`~/`)?(0,i.join)((0,i.homedir)(),t.slice(2)):(0,i.isAbsolute)(t)?t:(0,i.join)((0,i.homedir)(),t)}function h(e,t,n){let r=null;function a(){let r=p(e,{suffix:``}),i=m({}[t]),a=n?m({}[n]):void 0;return{data:i??r.data,config:a??r.config,cache:r.cache,log:r.log,temp:r.temp}}return{getPlatformPaths:a,getSystemInfo(){return r||(r={platform:(0,i.platform)(),arch:(0,i.arch)(),release:(0,i.release)(),hostname:(0,i.hostname)(),nodeVersion:process.version,paths:a()},r)},resetCache(){r=null}}}function g(){return(0,i.createRequire)(import.meta.url)(`node:sqlite`).DatabaseSync}var _=h(`cleo`,`CLEO_HOME`,`CLEO_CONFIG_HOME`);function v(){return _.getPlatformPaths()}function y(){return _.getPlatformPaths().data}function b(e){try{return(0,i.resolve)((0,i.execFileSync)(`git`,[`rev-parse`,`--show-toplevel`],{cwd:(0,i.resolve)(e),encoding:`utf-8`,stdio:[`ignore`,`pipe`,`ignore`]}).trim())}catch{return null}}function x(e){try{return(0,i.execFileSync)(`git`,[`remote`,`get-url`,`origin`],{cwd:(0,i.resolve)(e),encoding:`utf-8`,stdio:[`ignore`,`pipe`,`ignore`]}).trim()||null}catch{return null}}function S(e){try{let t=(0,i.readFileSync)((0,i.join)(e,`.cleo`,`project-info.json`),`utf-8`),n=JSON.parse(t);return typeof n.name==`string`?n.name:void 0}catch{return}}function C(e){let t=(0,i.resolve)(e);try{return(0,i.realpathSync)(t)}catch{return t}}function w(e){let t=C(e),n=b(t),r=n??t,a=n?x(n):null,o=[r,S(r)??``,a??``].join(`|`);return(0,i.createHash)(`sha256`).update(o).digest(`hex`).substring(0,12)}function T(e){return Buffer.from(e).toString(`base64url`).slice(0,32)}function E(e){let t=(0,i.resolve)(e??process.cwd());for(;;){let e=(0,i.join)(t,`.cleo`,`project-info.json`);if((0,i.existsSync)(e))try{let n=(0,i.readFileSync)(e,`utf-8`),r=JSON.parse(n);if(typeof r.projectId==`string`&&r.projectId.length>0){let e=C(t);return{projectId:w(e),projectRoot:e,legacyUUID:r.projectId}}}catch{}let n=(0,i.dirname)(t);if(n===t)break;t=n}return null}function D(e){let t=(0,i.join)(y(),`cleo.db`);if(!(0,i.existsSync)(t))return null;let n;try{n=new(g())(t,{readOnly:!0});let r=n.prepare(`SELECT project_path FROM nexus_project_registry WHERE project_id = ? LIMIT 1`),a=r.get(e);if(a&&typeof a.project_path==`string`&&a.project_path.length>0)return(0,i.join)(a.project_path,`.cleo`);try{let t=n.prepare(`SELECT canonical_id FROM nexus_project_id_aliases WHERE legacy_id = ? LIMIT 1`).get(e);if(t&&typeof t.canonical_id==`string`&&t.canonical_id.length>0){let e=r.get(t.canonical_id);if(e&&typeof e.project_path==`string`&&e.project_path.length>0)return(0,i.join)(e.project_path,`.cleo`)}}catch{}return null}catch{return null}finally{try{n?.close()}catch{}}}var O=`worktrees`,k=16;function A(e,...t){return e.includes(`/`)&&!e.includes(`\\`)?[e,...t].join(`/`):(0,i.join)(e,...t)}function j(e){let t;try{t=(0,i.realpathSync)(e)}catch{t=e}return(0,i.createHash)(`sha256`).update(t).digest(`hex`).slice(0,k)}function M(e,t){return t||A(y(),O,e)}export{T as a,h as c,v as i,r as l,M as n,D as o,y as r,E as s,j as t};