import{i as e,r as t}from"./home-dir-C44RaPME-B5iLWwCq.mjs";import n from"node:fs";import r from"node:path";import i from"node:os";const a=new Set([`__proto__`,`prototype`,`constructor`]);function o(e){return a.has(e)}function s(e=process.env){return e.OPENCLAW_NIX_MODE===`1`}s();const c=[`.clawdbot`],l=`openclaw.json`,u=[`clawdbot.json`];function d(){return e(process.env,i.homedir)}function f(t){return()=>e(t,i.homedir)}function p(e=d){return c.map(t=>r.join(e(),t))}function m(e=d){return r.join(e(),`.openclaw`)}function h(t=process.env,r=f(t)){let i=()=>e(t,r),a=t.OPENCLAW_STATE_DIR?.trim();if(a)return g(a,t,i);let o=m(i);if(t.OPENCLAW_TEST_FAST===`1`)return o;let s=p(i);return n.existsSync(o)?o:s.find(e=>{try{return n.existsSync(e)}catch{return!1}})||o}function g(e,n=process.env,r=f(n)){return t(e,{env:n,homedir:r})}const _=h();function v(e=process.env,t=h(e,f(e))){let n=e.OPENCLAW_CONFIG_PATH?.trim();return n?g(n,e,f(e)):r.join(t,l)}function y(e=process.env,t=f(e)){return e.OPENCLAW_TEST_FAST===`1`?v(e,h(e,t)):x(e,t).find(e=>{try{return n.existsSync(e)}catch{return!1}})||v(e,h(e,t))}function b(e=process.env,t=h(e,f(e)),i=f(e)){let a=e.OPENCLAW_CONFIG_PATH?.trim();if(a)return g(a,e,i);if(e.OPENCLAW_TEST_FAST===`1`)return r.join(t,l);let o=e.OPENCLAW_STATE_DIR?.trim(),s=[r.join(t,l),...u.map(e=>r.join(t,e))].find(e=>{try{return n.existsSync(e)}catch{return!1}});if(s)return s;if(o)return r.join(t,l);let c=h(e,i);return r.resolve(t)===r.resolve(c)?y(e,i):r.join(t,l)}y();function x(t=process.env,n=f(t)){let i=()=>e(t,n),a=t.OPENCLAW_CONFIG_PATH?.trim();if(a)return[g(a,t,i)];let o=[],s=t.OPENCLAW_STATE_DIR?.trim();if(s){let e=g(s,t,i);o.push(r.join(e,l)),o.push(...u.map(t=>r.join(e,t)))}let c=[m(i),...p(i)];for(let e of c)o.push(r.join(e,l)),o.push(...u.map(t=>r.join(e,t)));return o}const S=18789;function C(e=process.env,t=h(e,f(e))){let n=e.OPENCLAW_OAUTH_DIR?.trim();return n?g(n,e,f(e)):r.join(t,`credentials`)}function w(e=process.env,t=h(e,f(e))){return r.join(C(e,t),`oauth.json`)}function T(e){let t=e?.trim();if(!t)return null;if(/^\d+$/.test(t)){let e=Number.parseInt(t,10);return Number.isFinite(e)&&e>0?e:null}let n=t.match(/^\[[^\]]+\]:(\d+)$/);if(n?.[1]){let e=Number.parseInt(n[1],10);return Number.isFinite(e)&&e>0?e:null}let r=t.indexOf(`:`),i=t.lastIndexOf(`:`);if(r<=0||r!==i)return null;let a=t.slice(r+1);if(!/^\d+$/.test(a))return null;let o=Number.parseInt(a,10);return Number.isFinite(o)&&o>0?o:null}function E(e,t=process.env){let n=t.OPENCLAW_GATEWAY_PORT?.trim(),r=T(n);if(r!==null)return r;let i=e?.gateway?.port;return typeof i==`number`&&Number.isFinite(i)&&i>0?i:S}export{w as a,E as i,_ as n,h as o,b as r,o as s,S as t};