var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let l=require(`node:fs`);l=c(l);let u=require(`node:path`);u=c(u);let d=require(`node:os`);d=c(d);function f(e){return e?.trim()||void 0}function p(e=process.env,t=d.default.homedir){let n=m(e,t);return n?u.default.resolve(n):void 0}function m(e,t){let n=f(e.OPENCLAW_HOME);if(n){if(n===`~`||n.startsWith(`~/`)||n.startsWith(`~\\`)){let r=f(e.HOME)??f(e.USERPROFILE)??h(t);return r?n.replace(/^~(?=$|[\\/])/,r):void 0}return n}return f(e.HOME)||f(e.USERPROFILE)||h(t)}function h(e){try{return f(e())}catch{return}}function g(e=process.env,t=d.default.homedir){return p(e,t)??u.default.resolve(process.cwd())}function _(e,t){if(!e.startsWith(`~`))return e;let n=f(t?.home)??p(t?.env??process.env,t?.homedir??d.default.homedir);return n?e.replace(/^~(?=$|[\\/])/,n):e}function v(e=process.env){return e.OPENCLAW_NIX_MODE===`1`}v();const y=[`.clawdbot`,`.moldbot`,`.moltbot`],b=`.openclaw-qbot.json`,x=[`openclaw.json`,`clawdbot.json`,`moldbot.json`,`moltbot.json`];function S(){return g(process.env,d.default.homedir)}function C(e){return()=>g(e,d.default.homedir)}function w(e=S){return y.map(t=>u.default.join(e(),t))}function T(e=S){return u.default.join(e(),`.qbotclaw`)}function E(e=process.env,t=C(e)){let n=()=>g(e,t),r=e.OPENCLAW_STATE_DIR?.trim()||e.CLAWDBOT_STATE_DIR?.trim();if(r)return D(r,e,n);let i=T(n);if(e.OPENCLAW_TEST_FAST===`1`)return i;let a=w(n);return l.default.existsSync(i)?i:a.find(e=>{try{return l.default.existsSync(e)}catch{return!1}})||i}function D(e,t=process.env,n=C(t)){let r=e.trim();if(!r)return r;if(r.startsWith(`~`)){let e=_(r,{home:g(t,n),env:t,homedir:n});return u.default.resolve(e)}return u.default.resolve(r)}const O=E();function k(e=process.env,t=E(e,C(e))){let n=e.OPENCLAW_CONFIG_PATH?.trim()||e.CLAWDBOT_CONFIG_PATH?.trim();return n?D(n,e,C(e)):u.default.join(t,b)}function A(e=process.env,t=C(e)){return e.OPENCLAW_TEST_FAST===`1`?k(e,E(e,t)):M(e,t).find(e=>{try{return l.default.existsSync(e)}catch{return!1}})||k(e,E(e,t))}function j(e=process.env,t=E(e,C(e)),n=C(e)){let r=e.OPENCLAW_CONFIG_PATH?.trim();if(r)return D(r,e,n);if(e.OPENCLAW_TEST_FAST===`1`)return u.default.join(t,b);let i=e.OPENCLAW_STATE_DIR?.trim(),a=[u.default.join(t,b),...x.map(e=>u.default.join(t,e))].find(e=>{try{return l.default.existsSync(e)}catch{return!1}});if(a)return a;if(i)return u.default.join(t,b);let o=E(e,n);return u.default.resolve(t)===u.default.resolve(o)?A(e,n):u.default.join(t,b)}A();function M(e=process.env,t=C(e)){let n=()=>g(e,t),r=e.OPENCLAW_CONFIG_PATH?.trim()||e.CLAWDBOT_CONFIG_PATH?.trim();if(r)return[D(r,e,n)];let i=[],a=e.OPENCLAW_STATE_DIR?.trim()||e.CLAWDBOT_STATE_DIR?.trim();if(a){let t=D(a,e,n);i.push(u.default.join(t,b)),i.push(...x.map(e=>u.default.join(t,e)))}let o=[T(n),...w(n)];for(let e of o)i.push(u.default.join(e,b)),i.push(...x.map(t=>u.default.join(e,t)));return i}const N=18789;function P(e=process.env,t=E(e,C(e))){let n=e.OPENCLAW_OAUTH_DIR?.trim();return n?D(n,e,C(e)):u.default.join(t,`credentials`)}function F(e=process.env,t=E(e,C(e))){return u.default.join(P(e,t),`oauth.json`)}function I(e,t=process.env){let n=t.OPENCLAW_GATEWAY_PORT?.trim()||t.CLAWDBOT_GATEWAY_PORT?.trim();if(n){let e=Number.parseInt(n,10);if(Number.isFinite(e)&&e>=0)return e}let r=e?.gateway?.port;return typeof r==`number`&&Number.isFinite(r)&&r>=0?r:N}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return p}});
