@linzumi/cli 1.0.286 → 1.0.287
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cloud-supervisor.mjs +1 -1
- package/dist/hosted-coding-account-worker.js +1 -1
- package/dist/index.js +311 -310
- package/dist/remote-codex-harness-worker.js +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __linzumiBundleCreateRequire } from 'node:module';
|
|
2
2
|
const require = __linzumiBundleCreateRequire(import.meta.url);
|
|
3
3
|
var Pp=Object.create;var Oo=Object.defineProperty;var Rp=Object.getOwnPropertyDescriptor;var Ip=Object.getOwnPropertyNames;var Mp=Object.getPrototypeOf,qp=Object.prototype.hasOwnProperty;var K=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var _=(e,t)=>()=>(e&&(t=e(e=0)),t);var V=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),jp=(e,t)=>{for(var n in t)Oo(e,n,{get:t[n],enumerable:!0})},Fp=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ip(t))!qp.call(e,i)&&i!==n&&Oo(e,i,{get:()=>t[i],enumerable:!(r=Rp(t,i))||r.enumerable});return e};var qn=(e,t,n)=>(n=e!=null?Pp(Mp(e)):{},Fp(t||!e||!e.__esModule?Oo(n,"default",{value:e,enumerable:!0}):n,e));var Po=_(()=>{});function ce(e){return e===void 0?{BS_PRIVATE_NESTED_SOME_NONE:0}:e!==null&&e.BS_PRIVATE_NESTED_SOME_NONE!==void 0?{BS_PRIVATE_NESTED_SOME_NONE:e.BS_PRIVATE_NESTED_SOME_NONE+1|0}:e}function gr(e){if(e!=null)return ce(e)}function L(e){if(e===null||e.BS_PRIVATE_NESTED_SOME_NONE===void 0)return e;let t=e.BS_PRIVATE_NESTED_SOME_NONE;if(t!==0)return{BS_PRIVATE_NESTED_SOME_NONE:t-1|0}}var J=_(()=>{});function $t(e,t){if(e!==void 0)return t(L(e))}function Ne(e,t,n){return e!==void 0?n(L(e)):t}function U(e,t){if(e!==void 0)return ce(t(L(e)))}function fe(e,t){if(e!==void 0)return t(L(e))}function $(e,t){return e!==void 0?L(e):t}var M=_(()=>{Po();J()});var si=_(()=>{});function Se(e,t,n){return e.reduce(n,t)}var W=_(()=>{si();J()});function vt(e){if(e.RE_EXN_ID==="JsExn")return ce(e._1)}var li,Gp,xt,gv,bv,Gt=_(()=>{J();li=(e=>t=>t&&typeof t[e]=="string"?t[e]:void 0),Gp=li("stack"),xt=li("message"),gv=li("name"),bv=li("fileName")});var br=_(()=>{});var us=V((Sv,ls)=>{var Nt=K("constants"),Np=process.cwd,ci=null,Dp=process.env.GRACEFUL_FS_PLATFORM||process.platform;process.cwd=function(){return ci||(ci=Np.call(process)),ci};try{process.cwd()}catch{}typeof process.chdir=="function"&&(Io=process.chdir,process.chdir=function(e){ci=null,Io.call(process,e)},Object.setPrototypeOf&&Object.setPrototypeOf(process.chdir,Io));var Io;ls.exports=Lp;function Lp(e){Nt.hasOwnProperty("O_SYMLINK")&&process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)&&t(e),e.lutimes||n(e),e.chown=o(e.chown),e.fchown=o(e.fchown),e.lchown=o(e.lchown),e.chmod=r(e.chmod),e.fchmod=r(e.fchmod),e.lchmod=r(e.lchmod),e.chownSync=a(e.chownSync),e.fchownSync=a(e.fchownSync),e.lchownSync=a(e.lchownSync),e.chmodSync=i(e.chmodSync),e.fchmodSync=i(e.fchmodSync),e.lchmodSync=i(e.lchmodSync),e.stat=d(e.stat),e.fstat=d(e.fstat),e.lstat=d(e.lstat),e.statSync=l(e.statSync),e.fstatSync=l(e.fstatSync),e.lstatSync=l(e.lstatSync),e.chmod&&!e.lchmod&&(e.lchmod=function(s,m,p){p&&process.nextTick(p)},e.lchmodSync=function(){}),e.chown&&!e.lchown&&(e.lchown=function(s,m,p,f){f&&process.nextTick(f)},e.lchownSync=function(){}),Dp==="win32"&&(e.rename=typeof e.rename!="function"?e.rename:(function(s){function m(p,f,h){var c=Date.now(),y=0;s(p,f,function b(x){if(x&&(x.code==="EACCES"||x.code==="EPERM"||x.code==="EBUSY")&&Date.now()-c<6e4){setTimeout(function(){e.stat(f,function(v,g){v&&v.code==="ENOENT"?s(p,f,b):h(x)})},y),y<100&&(y+=10);return}h&&h(x)})}return Object.setPrototypeOf&&Object.setPrototypeOf(m,s),m})(e.rename)),e.read=typeof e.read!="function"?e.read:(function(s){function m(p,f,h,c,y,b){var x;if(b&&typeof b=="function"){var v=0;x=function(g,O,P){if(g&&g.code==="EAGAIN"&&v<10)return v++,s.call(e,p,f,h,c,y,x);b.apply(this,arguments)}}return s.call(e,p,f,h,c,y,x)}return Object.setPrototypeOf&&Object.setPrototypeOf(m,s),m})(e.read),e.readSync=typeof e.readSync!="function"?e.readSync:(function(s){return function(m,p,f,h,c){for(var y=0;;)try{return s.call(e,m,p,f,h,c)}catch(b){if(b.code==="EAGAIN"&&y<10){y++;continue}throw b}}})(e.readSync);function t(s){s.lchmod=function(m,p,f){s.open(m,Nt.O_WRONLY|Nt.O_SYMLINK,p,function(h,c){if(h){f&&f(h);return}s.fchmod(c,p,function(y){s.close(c,function(b){f&&f(y||b)})})})},s.lchmodSync=function(m,p){var f=s.openSync(m,Nt.O_WRONLY|Nt.O_SYMLINK,p),h=!0,c;try{c=s.fchmodSync(f,p),h=!1}finally{if(h)try{s.closeSync(f)}catch{}else s.closeSync(f)}return c}}function n(s){Nt.hasOwnProperty("O_SYMLINK")&&s.futimes?(s.lutimes=function(m,p,f,h){s.open(m,Nt.O_SYMLINK,function(c,y){if(c){h&&h(c);return}s.futimes(y,p,f,function(b){s.close(y,function(x){h&&h(b||x)})})})},s.lutimesSync=function(m,p,f){var h=s.openSync(m,Nt.O_SYMLINK),c,y=!0;try{c=s.futimesSync(h,p,f),y=!1}finally{if(y)try{s.closeSync(h)}catch{}else s.closeSync(h)}return c}):s.futimes&&(s.lutimes=function(m,p,f,h){h&&process.nextTick(h)},s.lutimesSync=function(){})}function r(s){return s&&function(m,p,f){return s.call(e,m,p,function(h){u(h)&&(h=null),f&&f.apply(this,arguments)})}}function i(s){return s&&function(m,p){try{return s.call(e,m,p)}catch(f){if(!u(f))throw f}}}function o(s){return s&&function(m,p,f,h){return s.call(e,m,p,f,function(c){u(c)&&(c=null),h&&h.apply(this,arguments)})}}function a(s){return s&&function(m,p,f){try{return s.call(e,m,p,f)}catch(h){if(!u(h))throw h}}}function d(s){return s&&function(m,p,f){typeof p=="function"&&(f=p,p=null);function h(c,y){y&&(y.uid<0&&(y.uid+=4294967296),y.gid<0&&(y.gid+=4294967296)),f&&f.apply(this,arguments)}return p?s.call(e,m,p,h):s.call(e,m,h)}}function l(s){return s&&function(m,p){var f=p?s.call(e,m,p):s.call(e,m);return f&&(f.uid<0&&(f.uid+=4294967296),f.gid<0&&(f.gid+=4294967296)),f}}function u(s){if(!s||s.code==="ENOSYS")return!0;var m=!process.getuid||process.getuid()!==0;return!!(m&&(s.code==="EINVAL"||s.code==="EPERM"))}}});var ms=V((vv,fs)=>{var cs=K("stream").Stream;fs.exports=Jp;function Jp(e){return{ReadStream:t,WriteStream:n};function t(r,i){if(!(this instanceof t))return new t(r,i);cs.call(this);var o=this;this.path=r,this.fd=null,this.readable=!0,this.paused=!1,this.flags="r",this.mode=438,this.bufferSize=64*1024,i=i||{};for(var a=Object.keys(i),d=0,l=a.length;d<l;d++){var u=a[d];this[u]=i[u]}if(this.encoding&&this.setEncoding(this.encoding),this.start!==void 0){if(typeof this.start!="number")throw TypeError("start must be a Number");if(this.end===void 0)this.end=1/0;else if(typeof this.end!="number")throw TypeError("end must be a Number");if(this.start>this.end)throw new Error("start must be <= end");this.pos=this.start}if(this.fd!==null){process.nextTick(function(){o._read()});return}e.open(this.path,this.flags,this.mode,function(s,m){if(s){o.emit("error",s),o.readable=!1;return}o.fd=m,o.emit("open",m),o._read()})}function n(r,i){if(!(this instanceof n))return new n(r,i);cs.call(this),this.path=r,this.fd=null,this.writable=!0,this.flags="w",this.encoding="binary",this.mode=438,this.bytesWritten=0,i=i||{};for(var o=Object.keys(i),a=0,d=o.length;a<d;a++){var l=o[a];this[l]=i[l]}if(this.start!==void 0){if(typeof this.start!="number")throw TypeError("start must be a Number");if(this.start<0)throw new Error("start must be >= zero");this.pos=this.start}this.busy=!1,this._queue=[],this.fd===null&&(this._open=e.open,this._queue.push([this._open,this.path,this.flags,this.mode,void 0]),this.flush())}}});var _s=V((xv,ps)=>{"use strict";ps.exports=Kp;var Up=Object.getPrototypeOf||function(e){return e.__proto__};function Kp(e){if(e===null||typeof e!="object")return e;if(e instanceof Object)var t={__proto__:Up(e)};else var t=Object.create(null);return Object.getOwnPropertyNames(e).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n))}),t}});var Fo=V((wv,jo)=>{var oe=K("fs"),Bp=us(),zp=ms(),Wp=_s(),fi=K("util"),Ie,pi;typeof Symbol=="function"&&typeof Symbol.for=="function"?(Ie=Symbol.for("graceful-fs.queue"),pi=Symbol.for("graceful-fs.previous")):(Ie="___graceful-fs.queue",pi="___graceful-fs.previous");function Hp(){}function gs(e,t){Object.defineProperty(e,Ie,{get:function(){return t}})}var an=Hp;fi.debuglog?an=fi.debuglog("gfs4"):/\bgfs4\b/i.test(process.env.NODE_DEBUG||"")&&(an=function(){var e=fi.format.apply(fi,arguments);e="GFS4: "+e.split(/\n/).join(`
|
|
4
|
-
GFS4: `),console.error(e)});oe[Ie]||(hs=global[Ie]||[],gs(oe,hs),oe.close=(function(e){function t(n,r){return e.call(oe,n,function(i){i||ys(),typeof r=="function"&&r.apply(this,arguments)})}return Object.defineProperty(t,pi,{value:e}),t})(oe.close),oe.closeSync=(function(e){function t(n){e.apply(oe,arguments),ys()}return Object.defineProperty(t,pi,{value:e}),t})(oe.closeSync),/\bgfs4\b/i.test(process.env.NODE_DEBUG||"")&&process.on("exit",function(){an(oe[Ie]),K("assert").equal(oe[Ie].length,0)}));var hs;global[Ie]||gs(global,oe[Ie]);jo.exports=Mo(Wp(oe));process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH&&!oe.__patched&&(jo.exports=Mo(oe),oe.__patched=!0);function Mo(e){Bp(e),e.gracefulify=Mo,e.createReadStream=O,e.createWriteStream=P;var t=e.readFile;e.readFile=n;function n(k,I,j){return typeof I=="function"&&(j=I,I=null),ue(k,I,j);function ue(R,w,S,A){return t(R,w,function(E){E&&(E.code==="EMFILE"||E.code==="ENFILE")?jn([ue,[R,w,S],E,A||Date.now(),Date.now()]):typeof S=="function"&&S.apply(this,arguments)})}}var r=e.writeFile;e.writeFile=i;function i(k,I,j,ue){return typeof j=="function"&&(ue=j,j=null),R(k,I,j,ue);function R(w,S,A,E,T){return r(w,S,A,function(C){C&&(C.code==="EMFILE"||C.code==="ENFILE")?jn([R,[w,S,A,E],C,T||Date.now(),Date.now()]):typeof E=="function"&&E.apply(this,arguments)})}}var o=e.appendFile;o&&(e.appendFile=a);function a(k,I,j,ue){return typeof j=="function"&&(ue=j,j=null),R(k,I,j,ue);function R(w,S,A,E,T){return o(w,S,A,function(C){C&&(C.code==="EMFILE"||C.code==="ENFILE")?jn([R,[w,S,A,E],C,T||Date.now(),Date.now()]):typeof E=="function"&&E.apply(this,arguments)})}}var d=e.copyFile;d&&(e.copyFile=l);function l(k,I,j,ue){return typeof j=="function"&&(ue=j,j=0),R(k,I,j,ue);function R(w,S,A,E,T){return d(w,S,A,function(C){C&&(C.code==="EMFILE"||C.code==="ENFILE")?jn([R,[w,S,A,E],C,T||Date.now(),Date.now()]):typeof E=="function"&&E.apply(this,arguments)})}}var u=e.readdir;e.readdir=m;var s=/^v[0-5]\./;function m(k,I,j){typeof I=="function"&&(j=I,I=null);var ue=s.test(process.version)?function(S,A,E,T){return u(S,R(S,A,E,T))}:function(S,A,E,T){return u(S,A,R(S,A,E,T))};return ue(k,I,j);function R(w,S,A,E){return function(T,C){T&&(T.code==="EMFILE"||T.code==="ENFILE")?jn([ue,[w,S,A],T,E||Date.now(),Date.now()]):(C&&C.sort&&C.sort(),typeof A=="function"&&A.call(this,T,C))}}}if(process.version.substr(0,4)==="v0.8"){var p=zp(e);b=p.ReadStream,v=p.WriteStream}var f=e.ReadStream;f&&(b.prototype=Object.create(f.prototype),b.prototype.open=x);var h=e.WriteStream;h&&(v.prototype=Object.create(h.prototype),v.prototype.open=g),Object.defineProperty(e,"ReadStream",{get:function(){return b},set:function(k){b=k},enumerable:!0,configurable:!0}),Object.defineProperty(e,"WriteStream",{get:function(){return v},set:function(k){v=k},enumerable:!0,configurable:!0});var c=b;Object.defineProperty(e,"FileReadStream",{get:function(){return c},set:function(k){c=k},enumerable:!0,configurable:!0});var y=v;Object.defineProperty(e,"FileWriteStream",{get:function(){return y},set:function(k){y=k},enumerable:!0,configurable:!0});function b(k,I){return this instanceof b?(f.apply(this,arguments),this):b.apply(Object.create(b.prototype),arguments)}function x(){var k=this;le(k.path,k.flags,k.mode,function(I,j){I?(k.autoClose&&k.destroy(),k.emit("error",I)):(k.fd=j,k.emit("open",j),k.read())})}function v(k,I){return this instanceof v?(h.apply(this,arguments),this):v.apply(Object.create(v.prototype),arguments)}function g(){var k=this;le(k.path,k.flags,k.mode,function(I,j){I?(k.destroy(),k.emit("error",I)):(k.fd=j,k.emit("open",j))})}function O(k,I){return new e.ReadStream(k,I)}function P(k,I){return new e.WriteStream(k,I)}var G=e.open;e.open=le;function le(k,I,j,ue){return typeof j=="function"&&(ue=j,j=null),R(k,I,j,ue);function R(w,S,A,E,T){return G(w,S,A,function(C,F){C&&(C.code==="EMFILE"||C.code==="ENFILE")?jn([R,[w,S,A,E],C,T||Date.now(),Date.now()]):typeof E=="function"&&E.apply(this,arguments)})}}return e}function jn(e){an("ENQUEUE",e[0].name,e[1]),oe[Ie].push(e),qo()}var mi;function ys(){for(var e=Date.now(),t=0;t<oe[Ie].length;++t)oe[Ie][t].length>2&&(oe[Ie][t][3]=e,oe[Ie][t][4]=e);qo()}function qo(){if(clearTimeout(mi),mi=void 0,oe[Ie].length!==0){var e=oe[Ie].shift(),t=e[0],n=e[1],r=e[2],i=e[3],o=e[4];if(i===void 0)an("RETRY",t.name,n),t.apply(null,n);else if(Date.now()-i>=6e4){an("TIMEOUT",t.name,n);var a=n.pop();typeof a=="function"&&a.call(null,r)}else{var d=Date.now()-o,l=Math.max(o-i,1),u=Math.min(l*1.2,100);d>=u?(an("RETRY",t.name,n),t.apply(null,n.concat([i]))):oe[Ie].push(e)}mi===void 0&&(mi=setTimeout(qo,0))}}});var Ss=V((Tv,bs)=>{function Ze(e,t){typeof t=="boolean"&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(e)),this._timeouts=e,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}bs.exports=Ze;Ze.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts};Ze.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timeouts=[],this._cachedTimeouts=null};Ze.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=new Date().getTime();if(e&&t-this._operationStart>=this._maxRetryTime)return this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(e);var n=this._timeouts.shift();if(n===void 0)if(this._cachedTimeouts)this._errors.splice(this._errors.length-1,this._errors.length),this._timeouts=this._cachedTimeouts.slice(0),n=this._timeouts.shift();else return!1;var r=this,i=setTimeout(function(){r._attempts++,r._operationTimeoutCb&&(r._timeout=setTimeout(function(){r._operationTimeoutCb(r._attempts)},r._operationTimeout),r._options.unref&&r._timeout.unref()),r._fn(r._attempts)},n);return this._options.unref&&i.unref(),!0};Ze.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var n=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){n._operationTimeoutCb()},n._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)};Ze.prototype.try=function(e){console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)};Ze.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)};Ze.prototype.start=Ze.prototype.try;Ze.prototype.errors=function(){return this._errors};Ze.prototype.attempts=function(){return this._attempts};Ze.prototype.mainError=function(){if(this._errors.length===0)return null;for(var e={},t=null,n=0,r=0;r<this._errors.length;r++){var i=this._errors[r],o=i.message,a=(e[o]||0)+1;e[o]=a,a>=n&&(t=i,n=a)}return t}});var vs=V(dn=>{var Vp=Ss();dn.operation=function(e){var t=dn.timeouts(e);return new Vp(t,{forever:e&&e.forever,unref:e&&e.unref,maxRetryTime:e&&e.maxRetryTime})};dn.timeouts=function(e){if(e instanceof Array)return[].concat(e);var t={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var n in e)t[n]=e[n];if(t.minTimeout>t.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var r=[],i=0;i<t.retries;i++)r.push(this.createTimeout(i,t));return e&&e.forever&&!r.length&&r.push(this.createTimeout(i,t)),r.sort(function(o,a){return o-a}),r};dn.createTimeout=function(e,t){var n=t.randomize?Math.random()+1:1,r=Math.round(n*t.minTimeout*Math.pow(t.factor,e));return r=Math.min(r,t.maxTimeout),r};dn.wrap=function(e,t,n){if(t instanceof Array&&(n=t,t=null),!n){n=[];for(var r in e)typeof e[r]=="function"&&n.push(r)}for(var i=0;i<n.length;i++){var o=n[i],a=e[o];e[o]=function(l){var u=dn.operation(t),s=Array.prototype.slice.call(arguments,1),m=s.pop();s.push(function(p){u.retry(p)||(p&&(arguments[0]=u.mainError()),m.apply(this,arguments))}),u.attempt(function(){l.apply(e,s)})}.bind(e,a),e[o].options=t}}});var ws=V((Cv,xs)=>{xs.exports=vs()});var Ts=V((Av,_i)=>{_i.exports=["SIGABRT","SIGALRM","SIGHUP","SIGINT","SIGTERM"];process.platform!=="win32"&&_i.exports.push("SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");process.platform==="linux"&&_i.exports.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT","SIGUNUSED")});var Os=V((Ev,Gn)=>{var X=global.process,sn=function(e){return e&&typeof e=="object"&&typeof e.removeListener=="function"&&typeof e.emit=="function"&&typeof e.reallyExit=="function"&&typeof e.listeners=="function"&&typeof e.kill=="function"&&typeof e.pid=="number"&&typeof e.on=="function"};sn(X)?(ks=K("assert"),Fn=Ts(),Cs=/^win/i.test(X.platform),Sr=K("events"),typeof Sr!="function"&&(Sr=Sr.EventEmitter),X.__signal_exit_emitter__?Ae=X.__signal_exit_emitter__:(Ae=X.__signal_exit_emitter__=new Sr,Ae.count=0,Ae.emitted={}),Ae.infinite||(Ae.setMaxListeners(1/0),Ae.infinite=!0),Gn.exports=function(e,t){if(!sn(global.process))return function(){};ks.equal(typeof e,"function","a callback must be provided for exit handler"),$n===!1&&$o();var n="exit";t&&t.alwaysLast&&(n="afterexit");var r=function(){Ae.removeListener(n,e),Ae.listeners("exit").length===0&&Ae.listeners("afterexit").length===0&&hi()};return Ae.on(n,e),r},hi=function(){!$n||!sn(global.process)||($n=!1,Fn.forEach(function(t){try{X.removeListener(t,yi[t])}catch{}}),X.emit=gi,X.reallyExit=Go,Ae.count-=1)},Gn.exports.unload=hi,ln=function(t,n,r){Ae.emitted[t]||(Ae.emitted[t]=!0,Ae.emit(t,n,r))},yi={},Fn.forEach(function(e){yi[e]=function(){if(sn(global.process)){var n=X.listeners(e);n.length===Ae.count&&(hi(),ln("exit",null,e),ln("afterexit",null,e),Cs&&e==="SIGHUP"&&(e="SIGINT"),X.kill(X.pid,e))}}}),Gn.exports.signals=function(){return Fn},$n=!1,$o=function(){$n||!sn(global.process)||($n=!0,Ae.count+=1,Fn=Fn.filter(function(t){try{return X.on(t,yi[t]),!0}catch{return!1}}),X.emit=Es,X.reallyExit=As)},Gn.exports.load=$o,Go=X.reallyExit,As=function(t){sn(global.process)&&(X.exitCode=t||0,ln("exit",X.exitCode,null),ln("afterexit",X.exitCode,null),Go.call(X,X.exitCode))},gi=X.emit,Es=function(t,n){if(t==="exit"&&sn(global.process)){n!==void 0&&(X.exitCode=n);var r=gi.apply(this,arguments);return ln("exit",X.exitCode,null),ln("afterexit",X.exitCode,null),r}else return gi.apply(this,arguments)}):Gn.exports=function(){return function(){}};var ks,Fn,Cs,Sr,Ae,hi,ln,yi,$n,$o,Go,As,gi,Es});var qs=V((Ov,vr)=>{"use strict";var Qp=K("path"),Lo=Fo(),Zp=ws(),Yp=Os(),wt={};function Nn(e,t){return t.lockfilePath||`${e}.lock`}function Jo(e,t,n){if(!t.realpath)return n(null,Qp.resolve(e));t.fs.realpath(e,n)}function No(e,t,n){t.fs.mkdir(Nn(e,t),r=>{if(!r)return n();if(r.code!=="EEXIST")return n(r);if(t.stale<=0)return n(Object.assign(new Error("Lock file is already being hold"),{code:"ELOCKED",file:e}));t.fs.stat(Nn(e,t),(i,o)=>{if(i)return i.code==="ENOENT"?No(e,{...t,stale:0},n):n(i);if(!Rs(o,t))return n(Object.assign(new Error("Lock file is already being hold"),{code:"ELOCKED",file:e}));Is(e,t,a=>{if(a)return n(a);No(e,{...t,stale:0},n)})})})}function Rs(e,t){return e.mtime.getTime()<Date.now()-t.stale}function Is(e,t,n){t.fs.rmdir(Nn(e,t),r=>{if(r&&r.code!=="ENOENT")return n(r);n()})}function Do(e,t){let n=wt[e];n.updateTimeout||(n.updateDelay=n.updateDelay||t.update,n.updateTimeout=setTimeout(()=>{let r=Date.now()/1e3;n.updateTimeout=null,t.fs.utimes(Nn(e,t),r,r,i=>{if(!n.released){if(n.lastUpdate<=Date.now()-t.stale&&n.lastUpdate>Date.now()-t.stale*2){let o=Object.assign(new Error(n.updateError||"Unable to update lock within the stale threshold"),{code:"ECOMPROMISED"});return Ps(e,n,o)}if(i)return i.code==="ENOENT"?Ps(e,n,Object.assign(i,{code:"ECOMPROMISED"})):(n.updateError=i,n.updateDelay=1e3,Do(e,t));n.lastUpdate=Date.now(),n.updateError=null,n.updateDelay=null,Do(e,t)}})},n.updateDelay),n.updateTimeout.unref&&n.updateTimeout.unref())}function Ps(e,t,n){t.released=!0,t.updateTimeout&&clearTimeout(t.updateTimeout),wt[e]===t&&delete wt[e],t.options.onCompromised(n)}function Xp(e,t,n){t={stale:1e4,update:null,realpath:!0,retries:0,fs:Lo,onCompromised:r=>{throw r},...t},t.retries=t.retries||0,t.retries=typeof t.retries=="number"?{retries:t.retries}:t.retries,t.stale=Math.max(t.stale||0,2e3),t.update=t.update==null?t.stale/2:t.update||0,t.update=Math.max(Math.min(t.update,t.stale/2),1e3),Jo(e,t,(r,i)=>{if(r)return n(r);let o=Zp.operation(t.retries);o.attempt(()=>{No(i,t,a=>{if(o.retry(a))return;if(a)return n(o.mainError());let d=wt[i]={options:t,lastUpdate:Date.now()};Do(i,t),n(null,l=>{if(d.released)return l&&l(Object.assign(new Error("Lock is already released"),{code:"ERELEASED"}));Ms(i,{...t,realpath:!1},l)})})})})}function Ms(e,t,n){t={fs:Lo,realpath:!0,...t},Jo(e,t,(r,i)=>{if(r)return n(r);let o=wt[i];if(!o)return n(Object.assign(new Error("Lock is not acquired/owned by you"),{code:"ENOTACQUIRED"}));o.updateTimeout&&clearTimeout(o.updateTimeout),o.released=!0,delete wt[i],Is(i,t,n)})}function e_(e,t,n){t={stale:1e4,realpath:!0,fs:Lo,...t},t.stale=Math.max(t.stale||0,2e3),Jo(e,t,(r,i)=>{if(r)return n(r);t.fs.stat(Nn(i,t),(o,a)=>o?o.code==="ENOENT"?n(null,!1):n(o):n(null,!Rs(a,t)))})}function t_(){return wt}Yp(()=>{for(let e in wt){let t=wt[e].options;try{t.fs.rmdirSync(Nn(e,t))}catch{}}});vr.exports.lock=Xp;vr.exports.unlock=Ms;vr.exports.check=e_;vr.exports.getLocks=t_});var Fs=V((Pv,js)=>{"use strict";var n_=Fo();function r_(e){let t=["mkdir","realpath","stat","rmdir","utimes"],n={...e};return t.forEach(r=>{n[r]=(...i)=>{let o=i.pop(),a;try{a=e[`${r}Sync`](...i)}catch(d){return o(d)}o(null,a)}}),n}function i_(e){return(...t)=>new Promise((n,r)=>{t.push((i,o)=>{i?r(i):n(o)}),e(...t)})}function o_(e){return(...t)=>{let n,r;if(t.push((i,o)=>{n=i,r=o}),e(...t),n)throw n;return r}}function a_(e){if(e={...e},e.fs=r_(e.fs||n_),typeof e.retries=="number"&&e.retries>0||e.retries&&typeof e.retries.retries=="number"&&e.retries.retries>0)throw Object.assign(new Error("Cannot use retries with the sync api"),{code:"ESYNC"});return e}js.exports={toPromise:i_,toSync:o_,toSyncOptions:a_}});var Gs=V((Rv,Dt)=>{"use strict";var Dn=qs(),{toPromise:bi,toSync:Si,toSyncOptions:Uo}=Fs();async function $s(e,t){let n=await bi(Dn.lock)(e,t);return bi(n)}function d_(e,t){let n=Si(Dn.lock)(e,Uo(t));return Si(n)}function s_(e,t){return bi(Dn.unlock)(e,t)}function l_(e,t){return Si(Dn.unlock)(e,Uo(t))}function u_(e,t){return bi(Dn.check)(e,t)}function c_(e,t){return Si(Dn.check)(e,Uo(t))}Dt.exports=$s;Dt.exports.lock=$s;Dt.exports.unlock=s_;Dt.exports.lockSync=d_;Dt.exports.unlockSync=l_;Dt.exports.check=u_;Dt.exports.checkSync=c_});var Ns=_(()=>{});var vi=_(()=>{});var un=_(()=>{});var ee=_(()=>{Ns();vi();un()});function m_(e){return e==null?!1:typeof e.RE_EXN_ID=="string"}function me(e){return m_(e)?e:{RE_EXN_ID:"JsExn",_1:e}}function zo(e){let t=Bo[e];if(t!==void 0){let n=t+1|0;return Bo[e]=n,e+("/"+n)}return Bo[e]=1,e}var Bo,_e=_(()=>{Bo={}});function Be(e){let t=vt(e);if(t===void 0)return{code:void 0,message:"unknown error"};let n=L(t);return{code:gr(n.code),message:$(xt(n),"unknown error")}}var p_,Z=_(()=>{Gt();M();br();p_=qn(Gs(),1);ee();J();_e()});function Us(e,t){return e!==void 0&&t!==void 0?e===t?{TAG:"Match",version:e}:{TAG:"Mismatch",pathVersion:e,pinnedVersion:t}:{TAG:"Unverified",pathVersion:e,pinnedVersion:t}}var Js,Ks=_(()=>{W();Z();M();ee();Js=new RegExp("(\\d+\\.\\d+\\.\\d+)")});function Bs(e){return e!=="claude_code"}function h_(e,t){let n=Us(e,t);switch(n.TAG){case"Match":return{TAG:"Ok",_0:n.version};case"Mismatch":return{TAG:"Error",_0:"hosted_codex_runtime_refused reason=mismatch observed="+n.pathVersion+" expected="+n.pinnedVersion};case"Unverified":return{TAG:"Error",_0:"hosted_codex_runtime_refused reason=unverified observed=unverified expected="+t}}}function zs(e,t,n){let r;if(e===0&&t.length<=1048576){let i=Js.exec(t);r=i==null?void 0:fe(i.slice(1)[0],o=>o)}else r=void 0;return h_(r,n)}var Ws=_(()=>{M();Ks()});var Hs,Vs,Wo=_(()=>{Ws();Hs=Bs,Vs=zs});var Zs,Qs=_(()=>{Zs={name:"@linzumi/cli",version:"1.0.286",description:"Linzumi CLI \u2014 point a Codex agent at the real code on your laptop, with your team watching and steering from shared threads.",type:"module",bin:{linzumi:"bin/linzumi.js"},files:["README.md","bin","dist","scripts","!scripts/build-*-oracle.mjs"],scripts:{build:"rescript build ../linzumi-cli-rescript && node scripts/build.mjs","bump-version":"node scripts/bump-cli-version.mjs",test:"pnpm --dir ../linzumi-cli-rescript test && npm run test:operational",typecheck:"rescript build ../linzumi-cli-rescript && tsgo --noEmit -p tsconfig.source.json",prepack:"rescript build -q ../linzumi-cli-rescript && node scripts/build.mjs","pack:dry-run":"npm pack --dry-run","test:operational":"vitest run --config vitest.config.mjs","vendor:codex-app-server-protocol":"tsx scripts/vendor-codex-app-server-protocol.ts","test:startup":"npm run build && node --test --test-concurrency=1 ../linzumi-cli-rescript/src/parity/CommanderStartupRefusalConformance.res.mjs","typecheck:all":"rescript build ../linzumi-cli-rescript && tsgo --noEmit -p tsconfig.json","typecheck:watch":"rescript build ../linzumi-cli-rescript && tsgo --noEmit -w -p tsconfig.source.json","test:agent-source":"LINZUMI_CI_QUARANTINE=0 pnpm exec vitest run --config vitest.config.mjs test/channelSession.test.ts test/kandanQueue.test.ts -t '(retains three busy accepted source snapshots without fusing or interrupting|keeps different accepted agent sources distinct through interrupt pickup)' && pnpm --dir ../linzumi-cli-rescript build && pnpm --dir ../linzumi-cli-rescript exec node --import tsx src/parity/AgentOpenaiModelProviderConformance.res.mjs && pnpm --dir ../linzumi-cli-rescript exec node --import tsx src/parity/WorkerMintCredentialConformance.res.mjs","codex:history-table":"node scripts/codex_history_table.mjs","vendor:codex-app-server-protocol:check":"tsx scripts/vendor-codex-app-server-protocol.ts --check"},keywords:["linzumi","kandan","codex","local-runner"],license:"MIT",publishConfig:{access:"public"},dependencies:{"@anthropic-ai/claude-agent-sdk":"0.3.283","@inquirer/prompts":"^7.8.6","@modelcontextprotocol/sdk":"^1.29.0","@openai/codex":"0.159.2",blessed:"^0.1.81","proper-lockfile":"3.2.0",undici:"^6.25.0",ws:"^8.18.0",zod:"^3.25.76"},engines:{node:">=20"},readmeFilename:"README.md",devDependencies:{"@types/blessed":"^0.1.27","@types/node":"^22.18.6","@types/proper-lockfile":"4.1.4","@typescript/native-preview":"7.0.0-dev.20260703.1",esbuild:"^0.27.2","fast-check":"^3.23.2",rescript:"12.3.0",tsx:"^4.21.0",typescript:"^5.9.3",vitest:"^1.6.1"}}});var wi,Ti=_(()=>{"use strict";Qs();wi=Zs.dependencies["@openai/codex"]});import{readFileSync as b_}from"node:fs";function x_(e=process.env,t=void 0,n=r=>b_(r,"utf8")){let r=e.SMOLCLOUD_API_KEY?.trim();if(r!==void 0&&r!=="")return r;if(t?.apiKeyFile!==void 0&&t.apiKeyFile!=="")try{let o=n(t.apiKeyFile).trim();if(o!=="")return o}catch{}let i=e.SMOL_CLOUD_TOKEN?.trim();if(i!==void 0&&i!=="")return i}function Qo(e){let t=e.env??process.env,n=x_(t,e.config);if(n===void 0)return;let r=(t.SMOLCLOUD_BASE_URL??e.config?.baseUrl??S_).replace(/\/+$/,"");return e.fetchImpl===void 0?{baseUrl:r,apiKey:n}:{baseUrl:r,apiKey:n,fetchImpl:e.fetchImpl}}function ki(e){return e.replace(/\bsmk_[A-Za-z0-9._-]+/g,"smk_[REDACTED]")}function Ys(e){return e.split("/").map(encodeURIComponent).join("/")}async function Tt(e,t,n,r={}){let i=e.fetchImpl??fetch,o={authorization:`Bearer ${e.apiKey}`},a;r.json!==void 0?(o["content-type"]="application/json",a=JSON.stringify(r.json)):r.body!==void 0&&(o["content-type"]="application/octet-stream",a=r.body);let d=new AbortController,l=r.timeoutMs??Vo,u=setTimeout(()=>d.abort(),l),s;try{s=await i(`${e.baseUrl}${n}`,{method:t,headers:o,body:a??null,signal:d.signal})}catch(p){throw p instanceof Error&&p.name==="AbortError"?new $e("TIMEOUT",`smolcloud ${t} ${n} timed out after ${l}ms`):new $e("CONNECTION",`smolcloud request failed: ${p instanceof Error?p.message:String(p)}`)}finally{clearTimeout(u)}if(!s.ok){let p=await s.text().catch(()=>""),f=s.status===404?"NOT_FOUND":s.status===401||s.status===403?"UNAUTHORIZED":"CLOUD_ERROR";throw new $e(f,`smolcloud ${t} ${n} \u2192 ${s.status}${p===""?"":`: ${p}`}`)}return r.accept==="bytes"?Buffer.from(await s.arrayBuffer()):s.status===204?void 0:(s.headers.get("content-type")??"").includes("application/json")?await s.json():void 0}async function*w_(e){let t=e.getReader(),n=new TextDecoder,r="",i="",o=[],a=()=>{let d=i,l=o.join(`
|
|
4
|
+
GFS4: `),console.error(e)});oe[Ie]||(hs=global[Ie]||[],gs(oe,hs),oe.close=(function(e){function t(n,r){return e.call(oe,n,function(i){i||ys(),typeof r=="function"&&r.apply(this,arguments)})}return Object.defineProperty(t,pi,{value:e}),t})(oe.close),oe.closeSync=(function(e){function t(n){e.apply(oe,arguments),ys()}return Object.defineProperty(t,pi,{value:e}),t})(oe.closeSync),/\bgfs4\b/i.test(process.env.NODE_DEBUG||"")&&process.on("exit",function(){an(oe[Ie]),K("assert").equal(oe[Ie].length,0)}));var hs;global[Ie]||gs(global,oe[Ie]);jo.exports=Mo(Wp(oe));process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH&&!oe.__patched&&(jo.exports=Mo(oe),oe.__patched=!0);function Mo(e){Bp(e),e.gracefulify=Mo,e.createReadStream=O,e.createWriteStream=P;var t=e.readFile;e.readFile=n;function n(k,I,j){return typeof I=="function"&&(j=I,I=null),ue(k,I,j);function ue(R,w,S,A){return t(R,w,function(E){E&&(E.code==="EMFILE"||E.code==="ENFILE")?jn([ue,[R,w,S],E,A||Date.now(),Date.now()]):typeof S=="function"&&S.apply(this,arguments)})}}var r=e.writeFile;e.writeFile=i;function i(k,I,j,ue){return typeof j=="function"&&(ue=j,j=null),R(k,I,j,ue);function R(w,S,A,E,T){return r(w,S,A,function(C){C&&(C.code==="EMFILE"||C.code==="ENFILE")?jn([R,[w,S,A,E],C,T||Date.now(),Date.now()]):typeof E=="function"&&E.apply(this,arguments)})}}var o=e.appendFile;o&&(e.appendFile=a);function a(k,I,j,ue){return typeof j=="function"&&(ue=j,j=null),R(k,I,j,ue);function R(w,S,A,E,T){return o(w,S,A,function(C){C&&(C.code==="EMFILE"||C.code==="ENFILE")?jn([R,[w,S,A,E],C,T||Date.now(),Date.now()]):typeof E=="function"&&E.apply(this,arguments)})}}var d=e.copyFile;d&&(e.copyFile=l);function l(k,I,j,ue){return typeof j=="function"&&(ue=j,j=0),R(k,I,j,ue);function R(w,S,A,E,T){return d(w,S,A,function(C){C&&(C.code==="EMFILE"||C.code==="ENFILE")?jn([R,[w,S,A,E],C,T||Date.now(),Date.now()]):typeof E=="function"&&E.apply(this,arguments)})}}var u=e.readdir;e.readdir=m;var s=/^v[0-5]\./;function m(k,I,j){typeof I=="function"&&(j=I,I=null);var ue=s.test(process.version)?function(S,A,E,T){return u(S,R(S,A,E,T))}:function(S,A,E,T){return u(S,A,R(S,A,E,T))};return ue(k,I,j);function R(w,S,A,E){return function(T,C){T&&(T.code==="EMFILE"||T.code==="ENFILE")?jn([ue,[w,S,A],T,E||Date.now(),Date.now()]):(C&&C.sort&&C.sort(),typeof A=="function"&&A.call(this,T,C))}}}if(process.version.substr(0,4)==="v0.8"){var p=zp(e);b=p.ReadStream,v=p.WriteStream}var f=e.ReadStream;f&&(b.prototype=Object.create(f.prototype),b.prototype.open=x);var h=e.WriteStream;h&&(v.prototype=Object.create(h.prototype),v.prototype.open=g),Object.defineProperty(e,"ReadStream",{get:function(){return b},set:function(k){b=k},enumerable:!0,configurable:!0}),Object.defineProperty(e,"WriteStream",{get:function(){return v},set:function(k){v=k},enumerable:!0,configurable:!0});var c=b;Object.defineProperty(e,"FileReadStream",{get:function(){return c},set:function(k){c=k},enumerable:!0,configurable:!0});var y=v;Object.defineProperty(e,"FileWriteStream",{get:function(){return y},set:function(k){y=k},enumerable:!0,configurable:!0});function b(k,I){return this instanceof b?(f.apply(this,arguments),this):b.apply(Object.create(b.prototype),arguments)}function x(){var k=this;le(k.path,k.flags,k.mode,function(I,j){I?(k.autoClose&&k.destroy(),k.emit("error",I)):(k.fd=j,k.emit("open",j),k.read())})}function v(k,I){return this instanceof v?(h.apply(this,arguments),this):v.apply(Object.create(v.prototype),arguments)}function g(){var k=this;le(k.path,k.flags,k.mode,function(I,j){I?(k.destroy(),k.emit("error",I)):(k.fd=j,k.emit("open",j))})}function O(k,I){return new e.ReadStream(k,I)}function P(k,I){return new e.WriteStream(k,I)}var G=e.open;e.open=le;function le(k,I,j,ue){return typeof j=="function"&&(ue=j,j=null),R(k,I,j,ue);function R(w,S,A,E,T){return G(w,S,A,function(C,F){C&&(C.code==="EMFILE"||C.code==="ENFILE")?jn([R,[w,S,A,E],C,T||Date.now(),Date.now()]):typeof E=="function"&&E.apply(this,arguments)})}}return e}function jn(e){an("ENQUEUE",e[0].name,e[1]),oe[Ie].push(e),qo()}var mi;function ys(){for(var e=Date.now(),t=0;t<oe[Ie].length;++t)oe[Ie][t].length>2&&(oe[Ie][t][3]=e,oe[Ie][t][4]=e);qo()}function qo(){if(clearTimeout(mi),mi=void 0,oe[Ie].length!==0){var e=oe[Ie].shift(),t=e[0],n=e[1],r=e[2],i=e[3],o=e[4];if(i===void 0)an("RETRY",t.name,n),t.apply(null,n);else if(Date.now()-i>=6e4){an("TIMEOUT",t.name,n);var a=n.pop();typeof a=="function"&&a.call(null,r)}else{var d=Date.now()-o,l=Math.max(o-i,1),u=Math.min(l*1.2,100);d>=u?(an("RETRY",t.name,n),t.apply(null,n.concat([i]))):oe[Ie].push(e)}mi===void 0&&(mi=setTimeout(qo,0))}}});var Ss=V((Tv,bs)=>{function Ze(e,t){typeof t=="boolean"&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(e)),this._timeouts=e,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}bs.exports=Ze;Ze.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts};Ze.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timeouts=[],this._cachedTimeouts=null};Ze.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=new Date().getTime();if(e&&t-this._operationStart>=this._maxRetryTime)return this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(e);var n=this._timeouts.shift();if(n===void 0)if(this._cachedTimeouts)this._errors.splice(this._errors.length-1,this._errors.length),this._timeouts=this._cachedTimeouts.slice(0),n=this._timeouts.shift();else return!1;var r=this,i=setTimeout(function(){r._attempts++,r._operationTimeoutCb&&(r._timeout=setTimeout(function(){r._operationTimeoutCb(r._attempts)},r._operationTimeout),r._options.unref&&r._timeout.unref()),r._fn(r._attempts)},n);return this._options.unref&&i.unref(),!0};Ze.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var n=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){n._operationTimeoutCb()},n._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)};Ze.prototype.try=function(e){console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)};Ze.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)};Ze.prototype.start=Ze.prototype.try;Ze.prototype.errors=function(){return this._errors};Ze.prototype.attempts=function(){return this._attempts};Ze.prototype.mainError=function(){if(this._errors.length===0)return null;for(var e={},t=null,n=0,r=0;r<this._errors.length;r++){var i=this._errors[r],o=i.message,a=(e[o]||0)+1;e[o]=a,a>=n&&(t=i,n=a)}return t}});var vs=V(dn=>{var Vp=Ss();dn.operation=function(e){var t=dn.timeouts(e);return new Vp(t,{forever:e&&e.forever,unref:e&&e.unref,maxRetryTime:e&&e.maxRetryTime})};dn.timeouts=function(e){if(e instanceof Array)return[].concat(e);var t={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var n in e)t[n]=e[n];if(t.minTimeout>t.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var r=[],i=0;i<t.retries;i++)r.push(this.createTimeout(i,t));return e&&e.forever&&!r.length&&r.push(this.createTimeout(i,t)),r.sort(function(o,a){return o-a}),r};dn.createTimeout=function(e,t){var n=t.randomize?Math.random()+1:1,r=Math.round(n*t.minTimeout*Math.pow(t.factor,e));return r=Math.min(r,t.maxTimeout),r};dn.wrap=function(e,t,n){if(t instanceof Array&&(n=t,t=null),!n){n=[];for(var r in e)typeof e[r]=="function"&&n.push(r)}for(var i=0;i<n.length;i++){var o=n[i],a=e[o];e[o]=function(l){var u=dn.operation(t),s=Array.prototype.slice.call(arguments,1),m=s.pop();s.push(function(p){u.retry(p)||(p&&(arguments[0]=u.mainError()),m.apply(this,arguments))}),u.attempt(function(){l.apply(e,s)})}.bind(e,a),e[o].options=t}}});var ws=V((Cv,xs)=>{xs.exports=vs()});var Ts=V((Av,_i)=>{_i.exports=["SIGABRT","SIGALRM","SIGHUP","SIGINT","SIGTERM"];process.platform!=="win32"&&_i.exports.push("SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");process.platform==="linux"&&_i.exports.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT","SIGUNUSED")});var Os=V((Ev,Gn)=>{var X=global.process,sn=function(e){return e&&typeof e=="object"&&typeof e.removeListener=="function"&&typeof e.emit=="function"&&typeof e.reallyExit=="function"&&typeof e.listeners=="function"&&typeof e.kill=="function"&&typeof e.pid=="number"&&typeof e.on=="function"};sn(X)?(ks=K("assert"),Fn=Ts(),Cs=/^win/i.test(X.platform),Sr=K("events"),typeof Sr!="function"&&(Sr=Sr.EventEmitter),X.__signal_exit_emitter__?Ae=X.__signal_exit_emitter__:(Ae=X.__signal_exit_emitter__=new Sr,Ae.count=0,Ae.emitted={}),Ae.infinite||(Ae.setMaxListeners(1/0),Ae.infinite=!0),Gn.exports=function(e,t){if(!sn(global.process))return function(){};ks.equal(typeof e,"function","a callback must be provided for exit handler"),$n===!1&&$o();var n="exit";t&&t.alwaysLast&&(n="afterexit");var r=function(){Ae.removeListener(n,e),Ae.listeners("exit").length===0&&Ae.listeners("afterexit").length===0&&hi()};return Ae.on(n,e),r},hi=function(){!$n||!sn(global.process)||($n=!1,Fn.forEach(function(t){try{X.removeListener(t,yi[t])}catch{}}),X.emit=gi,X.reallyExit=Go,Ae.count-=1)},Gn.exports.unload=hi,ln=function(t,n,r){Ae.emitted[t]||(Ae.emitted[t]=!0,Ae.emit(t,n,r))},yi={},Fn.forEach(function(e){yi[e]=function(){if(sn(global.process)){var n=X.listeners(e);n.length===Ae.count&&(hi(),ln("exit",null,e),ln("afterexit",null,e),Cs&&e==="SIGHUP"&&(e="SIGINT"),X.kill(X.pid,e))}}}),Gn.exports.signals=function(){return Fn},$n=!1,$o=function(){$n||!sn(global.process)||($n=!0,Ae.count+=1,Fn=Fn.filter(function(t){try{return X.on(t,yi[t]),!0}catch{return!1}}),X.emit=Es,X.reallyExit=As)},Gn.exports.load=$o,Go=X.reallyExit,As=function(t){sn(global.process)&&(X.exitCode=t||0,ln("exit",X.exitCode,null),ln("afterexit",X.exitCode,null),Go.call(X,X.exitCode))},gi=X.emit,Es=function(t,n){if(t==="exit"&&sn(global.process)){n!==void 0&&(X.exitCode=n);var r=gi.apply(this,arguments);return ln("exit",X.exitCode,null),ln("afterexit",X.exitCode,null),r}else return gi.apply(this,arguments)}):Gn.exports=function(){return function(){}};var ks,Fn,Cs,Sr,Ae,hi,ln,yi,$n,$o,Go,As,gi,Es});var qs=V((Ov,vr)=>{"use strict";var Qp=K("path"),Lo=Fo(),Zp=ws(),Yp=Os(),wt={};function Nn(e,t){return t.lockfilePath||`${e}.lock`}function Jo(e,t,n){if(!t.realpath)return n(null,Qp.resolve(e));t.fs.realpath(e,n)}function No(e,t,n){t.fs.mkdir(Nn(e,t),r=>{if(!r)return n();if(r.code!=="EEXIST")return n(r);if(t.stale<=0)return n(Object.assign(new Error("Lock file is already being hold"),{code:"ELOCKED",file:e}));t.fs.stat(Nn(e,t),(i,o)=>{if(i)return i.code==="ENOENT"?No(e,{...t,stale:0},n):n(i);if(!Rs(o,t))return n(Object.assign(new Error("Lock file is already being hold"),{code:"ELOCKED",file:e}));Is(e,t,a=>{if(a)return n(a);No(e,{...t,stale:0},n)})})})}function Rs(e,t){return e.mtime.getTime()<Date.now()-t.stale}function Is(e,t,n){t.fs.rmdir(Nn(e,t),r=>{if(r&&r.code!=="ENOENT")return n(r);n()})}function Do(e,t){let n=wt[e];n.updateTimeout||(n.updateDelay=n.updateDelay||t.update,n.updateTimeout=setTimeout(()=>{let r=Date.now()/1e3;n.updateTimeout=null,t.fs.utimes(Nn(e,t),r,r,i=>{if(!n.released){if(n.lastUpdate<=Date.now()-t.stale&&n.lastUpdate>Date.now()-t.stale*2){let o=Object.assign(new Error(n.updateError||"Unable to update lock within the stale threshold"),{code:"ECOMPROMISED"});return Ps(e,n,o)}if(i)return i.code==="ENOENT"?Ps(e,n,Object.assign(i,{code:"ECOMPROMISED"})):(n.updateError=i,n.updateDelay=1e3,Do(e,t));n.lastUpdate=Date.now(),n.updateError=null,n.updateDelay=null,Do(e,t)}})},n.updateDelay),n.updateTimeout.unref&&n.updateTimeout.unref())}function Ps(e,t,n){t.released=!0,t.updateTimeout&&clearTimeout(t.updateTimeout),wt[e]===t&&delete wt[e],t.options.onCompromised(n)}function Xp(e,t,n){t={stale:1e4,update:null,realpath:!0,retries:0,fs:Lo,onCompromised:r=>{throw r},...t},t.retries=t.retries||0,t.retries=typeof t.retries=="number"?{retries:t.retries}:t.retries,t.stale=Math.max(t.stale||0,2e3),t.update=t.update==null?t.stale/2:t.update||0,t.update=Math.max(Math.min(t.update,t.stale/2),1e3),Jo(e,t,(r,i)=>{if(r)return n(r);let o=Zp.operation(t.retries);o.attempt(()=>{No(i,t,a=>{if(o.retry(a))return;if(a)return n(o.mainError());let d=wt[i]={options:t,lastUpdate:Date.now()};Do(i,t),n(null,l=>{if(d.released)return l&&l(Object.assign(new Error("Lock is already released"),{code:"ERELEASED"}));Ms(i,{...t,realpath:!1},l)})})})})}function Ms(e,t,n){t={fs:Lo,realpath:!0,...t},Jo(e,t,(r,i)=>{if(r)return n(r);let o=wt[i];if(!o)return n(Object.assign(new Error("Lock is not acquired/owned by you"),{code:"ENOTACQUIRED"}));o.updateTimeout&&clearTimeout(o.updateTimeout),o.released=!0,delete wt[i],Is(i,t,n)})}function e_(e,t,n){t={stale:1e4,realpath:!0,fs:Lo,...t},t.stale=Math.max(t.stale||0,2e3),Jo(e,t,(r,i)=>{if(r)return n(r);t.fs.stat(Nn(i,t),(o,a)=>o?o.code==="ENOENT"?n(null,!1):n(o):n(null,!Rs(a,t)))})}function t_(){return wt}Yp(()=>{for(let e in wt){let t=wt[e].options;try{t.fs.rmdirSync(Nn(e,t))}catch{}}});vr.exports.lock=Xp;vr.exports.unlock=Ms;vr.exports.check=e_;vr.exports.getLocks=t_});var Fs=V((Pv,js)=>{"use strict";var n_=Fo();function r_(e){let t=["mkdir","realpath","stat","rmdir","utimes"],n={...e};return t.forEach(r=>{n[r]=(...i)=>{let o=i.pop(),a;try{a=e[`${r}Sync`](...i)}catch(d){return o(d)}o(null,a)}}),n}function i_(e){return(...t)=>new Promise((n,r)=>{t.push((i,o)=>{i?r(i):n(o)}),e(...t)})}function o_(e){return(...t)=>{let n,r;if(t.push((i,o)=>{n=i,r=o}),e(...t),n)throw n;return r}}function a_(e){if(e={...e},e.fs=r_(e.fs||n_),typeof e.retries=="number"&&e.retries>0||e.retries&&typeof e.retries.retries=="number"&&e.retries.retries>0)throw Object.assign(new Error("Cannot use retries with the sync api"),{code:"ESYNC"});return e}js.exports={toPromise:i_,toSync:o_,toSyncOptions:a_}});var Gs=V((Rv,Dt)=>{"use strict";var Dn=qs(),{toPromise:bi,toSync:Si,toSyncOptions:Uo}=Fs();async function $s(e,t){let n=await bi(Dn.lock)(e,t);return bi(n)}function d_(e,t){let n=Si(Dn.lock)(e,Uo(t));return Si(n)}function s_(e,t){return bi(Dn.unlock)(e,t)}function l_(e,t){return Si(Dn.unlock)(e,Uo(t))}function u_(e,t){return bi(Dn.check)(e,t)}function c_(e,t){return Si(Dn.check)(e,Uo(t))}Dt.exports=$s;Dt.exports.lock=$s;Dt.exports.unlock=s_;Dt.exports.lockSync=d_;Dt.exports.unlockSync=l_;Dt.exports.check=u_;Dt.exports.checkSync=c_});var Ns=_(()=>{});var vi=_(()=>{});var un=_(()=>{});var ee=_(()=>{Ns();vi();un()});function m_(e){return e==null?!1:typeof e.RE_EXN_ID=="string"}function me(e){return m_(e)?e:{RE_EXN_ID:"JsExn",_1:e}}function zo(e){let t=Bo[e];if(t!==void 0){let n=t+1|0;return Bo[e]=n,e+("/"+n)}return Bo[e]=1,e}var Bo,_e=_(()=>{Bo={}});function Be(e){let t=vt(e);if(t===void 0)return{code:void 0,message:"unknown error"};let n=L(t);return{code:gr(n.code),message:$(xt(n),"unknown error")}}var p_,Z=_(()=>{Gt();M();br();p_=qn(Gs(),1);ee();J();_e()});function Us(e,t){return e!==void 0&&t!==void 0?e===t?{TAG:"Match",version:e}:{TAG:"Mismatch",pathVersion:e,pinnedVersion:t}:{TAG:"Unverified",pathVersion:e,pinnedVersion:t}}var Js,Ks=_(()=>{W();Z();M();ee();Js=new RegExp("(\\d+\\.\\d+\\.\\d+)")});function Bs(e){return e!=="claude_code"}function h_(e,t){let n=Us(e,t);switch(n.TAG){case"Match":return{TAG:"Ok",_0:n.version};case"Mismatch":return{TAG:"Error",_0:"hosted_codex_runtime_refused reason=mismatch observed="+n.pathVersion+" expected="+n.pinnedVersion};case"Unverified":return{TAG:"Error",_0:"hosted_codex_runtime_refused reason=unverified observed=unverified expected="+t}}}function zs(e,t,n){let r;if(e===0&&t.length<=1048576){let i=Js.exec(t);r=i==null?void 0:fe(i.slice(1)[0],o=>o)}else r=void 0;return h_(r,n)}var Ws=_(()=>{M();Ks()});var Hs,Vs,Wo=_(()=>{Ws();Hs=Bs,Vs=zs});var Zs,Qs=_(()=>{Zs={name:"@linzumi/cli",version:"1.0.287",description:"Linzumi CLI \u2014 point a Codex agent at the real code on your laptop, with your team watching and steering from shared threads.",type:"module",bin:{linzumi:"bin/linzumi.js"},files:["README.md","bin","dist","scripts","!scripts/build-*-oracle.mjs"],scripts:{build:"rescript build ../linzumi-cli-rescript && node scripts/build.mjs","bump-version":"node scripts/bump-cli-version.mjs",test:"pnpm --dir ../linzumi-cli-rescript test && npm run test:operational",typecheck:"rescript build ../linzumi-cli-rescript && tsgo --noEmit -p tsconfig.source.json",prepack:"rescript build -q ../linzumi-cli-rescript && node scripts/build.mjs","pack:dry-run":"npm pack --dry-run","test:operational":"vitest run --config vitest.config.mjs","vendor:codex-app-server-protocol":"tsx scripts/vendor-codex-app-server-protocol.ts","test:startup":"npm run build && node --test --test-concurrency=1 ../linzumi-cli-rescript/src/parity/CommanderStartupRefusalConformance.res.mjs","typecheck:all":"rescript build ../linzumi-cli-rescript && tsgo --noEmit -p tsconfig.json","typecheck:watch":"rescript build ../linzumi-cli-rescript && tsgo --noEmit -w -p tsconfig.source.json","test:agent-source":"LINZUMI_CI_QUARANTINE=0 pnpm exec vitest run --config vitest.config.mjs test/channelSession.test.ts test/kandanQueue.test.ts -t '(retains three busy accepted source snapshots without fusing or interrupting|keeps different accepted agent sources distinct through interrupt pickup)' && pnpm --dir ../linzumi-cli-rescript build && pnpm --dir ../linzumi-cli-rescript exec node --import tsx src/parity/AgentOpenaiModelProviderConformance.res.mjs && pnpm --dir ../linzumi-cli-rescript exec node --import tsx src/parity/WorkerMintCredentialConformance.res.mjs","codex:history-table":"node scripts/codex_history_table.mjs","vendor:codex-app-server-protocol:check":"tsx scripts/vendor-codex-app-server-protocol.ts --check"},keywords:["linzumi","kandan","codex","local-runner"],license:"MIT",publishConfig:{access:"public"},dependencies:{"@anthropic-ai/claude-agent-sdk":"0.3.283","@inquirer/prompts":"^7.8.6","@modelcontextprotocol/sdk":"^1.29.0","@openai/codex":"0.159.2",blessed:"^0.1.81","proper-lockfile":"3.2.0",undici:"^6.25.0",ws:"^8.18.0",zod:"^3.25.76"},engines:{node:">=20"},readmeFilename:"README.md",devDependencies:{"@types/blessed":"^0.1.27","@types/node":"^22.18.6","@types/proper-lockfile":"4.1.4","@typescript/native-preview":"7.0.0-dev.20260703.1",esbuild:"^0.27.2","fast-check":"^3.23.2",rescript:"12.3.0",tsx:"^4.21.0",typescript:"^5.9.3",vitest:"^1.6.1"}}});var wi,Ti=_(()=>{"use strict";Qs();wi=Zs.dependencies["@openai/codex"]});import{readFileSync as b_}from"node:fs";function x_(e=process.env,t=void 0,n=r=>b_(r,"utf8")){let r=e.SMOLCLOUD_API_KEY?.trim();if(r!==void 0&&r!=="")return r;if(t?.apiKeyFile!==void 0&&t.apiKeyFile!=="")try{let o=n(t.apiKeyFile).trim();if(o!=="")return o}catch{}let i=e.SMOL_CLOUD_TOKEN?.trim();if(i!==void 0&&i!=="")return i}function Qo(e){let t=e.env??process.env,n=x_(t,e.config);if(n===void 0)return;let r=(t.SMOLCLOUD_BASE_URL??e.config?.baseUrl??S_).replace(/\/+$/,"");return e.fetchImpl===void 0?{baseUrl:r,apiKey:n}:{baseUrl:r,apiKey:n,fetchImpl:e.fetchImpl}}function ki(e){return e.replace(/\bsmk_[A-Za-z0-9._-]+/g,"smk_[REDACTED]")}function Ys(e){return e.split("/").map(encodeURIComponent).join("/")}async function Tt(e,t,n,r={}){let i=e.fetchImpl??fetch,o={authorization:`Bearer ${e.apiKey}`},a;r.json!==void 0?(o["content-type"]="application/json",a=JSON.stringify(r.json)):r.body!==void 0&&(o["content-type"]="application/octet-stream",a=r.body);let d=new AbortController,l=r.timeoutMs??Vo,u=setTimeout(()=>d.abort(),l),s;try{s=await i(`${e.baseUrl}${n}`,{method:t,headers:o,body:a??null,signal:d.signal})}catch(p){throw p instanceof Error&&p.name==="AbortError"?new $e("TIMEOUT",`smolcloud ${t} ${n} timed out after ${l}ms`):new $e("CONNECTION",`smolcloud request failed: ${p instanceof Error?p.message:String(p)}`)}finally{clearTimeout(u)}if(!s.ok){let p=await s.text().catch(()=>""),f=s.status===404?"NOT_FOUND":s.status===401||s.status===403?"UNAUTHORIZED":"CLOUD_ERROR";throw new $e(f,`smolcloud ${t} ${n} \u2192 ${s.status}${p===""?"":`: ${p}`}`)}return r.accept==="bytes"?Buffer.from(await s.arrayBuffer()):s.status===204?void 0:(s.headers.get("content-type")??"").includes("application/json")?await s.json():void 0}async function*w_(e){let t=e.getReader(),n=new TextDecoder,r="",i="",o=[],a=()=>{let d=i,l=o.join(`
|
|
5
5
|
`);if(i="",o=[],d==="stdout")return{kind:"stdout",data:l};if(d==="stderr")return{kind:"stderr",data:l};if(d==="error")return{kind:"error",message:ki(l)};if(d==="exit"){let u=0;try{u=JSON.parse(l).exitCode??0}catch{}return{kind:"exit",exitCode:u}}};try{for(;;){let{value:l,done:u}=await t.read();if(u)break;r+=n.decode(l,{stream:!0});let s;for(;(s=r.indexOf(`
|
|
6
6
|
`))>=0;){let m=r.slice(0,s);r=r.slice(s+1);let p=m.endsWith("\r")?m.slice(0,-1):m;if(p===""){let f=a();f!==void 0&&(yield f)}else p.startsWith("event:")?i=p.slice(6).trim():p.startsWith("data:")&&o.push(p.slice(5).replace(/^ /,""))}}let d=a();d!==void 0&&(yield d)}finally{t.releaseLock()}}function T_(e){if(!e.startsWith("smolmachine:"))return{type:"image",reference:e};let t=e.slice(12),n=t.lastIndexOf("@");if(n<0)return{type:"smolmachine",reference:t,arch:"arm64"};let r=t.slice(n+1);if(r!=="arm64"&&r!=="amd64")throw new $e("CLOUD_ERROR",`invalid smolmachine image arch suffix ${JSON.stringify(r)} in ${JSON.stringify(e)} (expected @arm64 or @amd64)`);return{type:"smolmachine",reference:t.slice(0,n),arch:r}}async function Xs(e,t){let n={name:t.name??null,source:T_(t.image),resources:{...t.cpus!==void 0?{cpus:t.cpus}:{},...t.memoryMb!==void 0?{memoryMb:t.memoryMb}:{},diskGb:t.diskGb??null},...t.network!==void 0?{network:t.network}:{},...t.env!==void 0?{env:t.env}:{},autoStopSeconds:t.autoStopSeconds??null,ttlSeconds:t.ttlSeconds??null},r=await Tt(e,"POST","/v1/machines",{json:n});if(r.id===void 0)throw new $e("CLOUD_ERROR","machine create returned no machine id");let i=new wr(e,r.id);try{return await Tt(e,"POST",`/v1/machines/${r.id}/start`).catch(()=>{}),await k_(e,r.id),i}catch(o){throw await i.delete().catch(()=>{}),o}}async function k_(e,t,n=v_,r=i=>new Promise(o=>setTimeout(o,i))){let i=Date.now()+n;for(;;){let o;try{o=(await Tt(e,"GET",`/v1/machines/${t}`))?.state}catch(a){if(a instanceof $e&&(a.code==="UNAUTHORIZED"||a.code==="NOT_FOUND"))throw a}if(o==="started"||o==="running")return;if(o==="error")throw new $e("CLOUD_ERROR",`machine ${t} entered error state while starting`);if(Date.now()>=i)throw new $e("TIMEOUT",`machine ${t} not ready after ${n}ms (state=${o??"unknown"})`);await r(1e3)}}var S_,Vo,Ho,v_,$e,wr,Zo=_(()=>{"use strict";Ti();S_="https://api.smolmachines.com",Vo=3e4,Ho=3e4,v_=12e4;$e=class extends Error{code;constructor(t,n){super(ki(n)),this.code=t,this.name="SmolcloudError"}};wr=class{id;conn;constructor(t,n){this.conn=t,this.id=n}get name(){return this.id}async state(){return(await this.info()).state}async info(){let t=await Tt(this.conn,"GET",`/v1/machines/${this.id}`);return{id:t?.id??this.id,name:t?.name??null,state:t?.state??"unknown",env:t?.env??{}}}async exec(t,n){let r={command:[...t],env:n?.env??{},cwd:n?.workdir??null,stdin:n?.stdin??null,timeoutSeconds:n?.timeout??null},i=n?.timeout!==void 0?Math.max(Vo,n.timeout*1e3+Ho):Vo,o=await Tt(this.conn,"POST",`/v1/machines/${this.id}/exec`,{json:r,timeoutMs:i});return{exitCode:o.exitCode??0,stdout:o.stdout??"",stderr:o.stderr??""}}async*execStream(t,n){let r=this.conn.fetchImpl??fetch,i={command:[...t],env:n?.env??{},cwd:n?.workdir??null,stdin:n?.stdin??null,timeoutSeconds:n?.timeout??null},o=new AbortController,a=n?.timeout!==void 0?setTimeout(()=>o.abort(),n.timeout*1e3+Ho):void 0,d;try{d=await r(`${this.conn.baseUrl}/v1/machines/${this.id}/exec/stream`,{method:"POST",headers:{authorization:`Bearer ${this.conn.apiKey}`,"content-type":"application/json",accept:"text/event-stream"},body:JSON.stringify(i),signal:o.signal})}catch(l){throw a!==void 0&&clearTimeout(a),l instanceof Error&&l.name==="AbortError"?new $e("TIMEOUT",`smolcloud exec/stream timed out after ${(n?.timeout??0)*1e3+Ho}ms`):new $e("CONNECTION",`smolcloud exec/stream failed: ${l instanceof Error?l.message:String(l)}`)}try{if(!d.ok){let l=await d.text().catch(()=>"");throw new $e(d.status===404?"NOT_FOUND":"CLOUD_ERROR",`smolcloud POST /v1/machines/${this.id}/exec/stream \u2192 ${d.status}${l===""?"":`: ${l}`}`)}if(d.body===null)throw new $e("CLOUD_ERROR","exec/stream returned no response body");yield*w_(d.body)}finally{a!==void 0&&clearTimeout(a)}}async readFile(t){return await Tt(this.conn,"GET",`/v1/machines/${this.id}/files/${Ys(t)}`,{accept:"bytes"})}async writeFile(t,n,r){await Tt(this.conn,"PUT",`/v1/machines/${this.id}/files/${Ys(t)}`,{body:typeof n=="string"?Buffer.from(n,"utf8"):n}),r!==void 0&&await this.exec(["chmod",r.toString(8),t])}async stop(){await Tt(this.conn,"POST",`/v1/machines/${this.id}/stop`)}async delete(){await Tt(this.conn,"DELETE",`/v1/machines/${this.id}`)}}});function el(e){return`'${e.replaceAll("'",String.raw`'\''`)}'`}var Yo,Wv,Hv,Vv,tl=_(()=>{"use strict";Yo="/dev/shm/linzumi",Wv=`${Yo}/codex`,Hv=`${Yo}/mcp-auth.json`,Vv=`${Yo}/codex.env`});function Xo(e){let t=e.replace(/[^A-Za-z0-9._-]/g,"_");return`${st}/.linzumi-provisioned-${nl}-${t}`}function ol(e){return["/bin/sh","-c",["set -e",`mkdir -p ${st} ${Tr} ${Ci}`,`chmod 700 ${Tr} ${Ci}`,"export DEBIAN_FRONTEND=noninteractive","apt-get update -qq >/dev/null","apt-get install -y --no-install-recommends bubblewrap ca-certificates git ripgrep curl >/dev/null","update-ca-certificates >/dev/null 2>&1 || true",`npm install -g --no-fund --no-audit @openai/codex@${el(e)} >/dev/null`,`rm -f ${st}/.linzumi-provisioned-${nl}-* 2>/dev/null || true`,`touch ${Xo(e)}`,`touch ${fl}`].join(" && ")]}function al(e){return["/bin/sh","-c",`test -f ${Xo(e)} && command -v codex >/dev/null && command -v node >/dev/null && command -v bwrap >/dev/null && test -s ${il}`]}function dl(e){return["/bin/sh","-c",`if test -f ${Xo(e)} && command -v codex >/dev/null && command -v node >/dev/null && command -v bwrap >/dev/null && test -s ${il}; then echo TOOLCHAIN_OK; else echo TOOLCHAIN_MISSING; fi; echo BUNDLE_SUP $(sha256sum ${Ai} 2>/dev/null | cut -d' ' -f1); echo BUNDLE_MCP $(sha256sum ${Ei} 2>/dev/null | cut -d' ' -f1)`]}function ea(){return["/bin/sh","-c",`rm -rf ${Tr} 2>/dev/null; true`]}function na(e){if(!E_.test(e))throw new Error(`invalid cloud turn nonce: ${JSON.stringify(e.slice(0,80))}`)}function sl(e){return na(e),`${ta}/${e}.beat`}function ll(e){return na(e),`${ta}/${e}.exit`}function ul(e){let t=ll(e),n=sl(e);return["/bin/sh","-c",`if test -f ${t}; then echo EXIT; cat ${t}; elif test -f ${n}; then now=$(date +%s); hb=$(stat -c %Y ${n} 2>/dev/null || echo 0); echo AGE $((now-hb)); else echo NONE; fi`]}function cl(e){let t=ll(e),n=sl(e);return["/bin/sh","-c",`rm -f ${t} ${n} 2>/dev/null; true`]}var nl,rl,Ai,Ei,Tr,C_,Ci,A_,il,ta,E_,ra=_(()=>{"use strict";ia();tl();nl="v1",rl=4500,Ai=`${st}/cloud-supervisor.mjs`,Ei=`${st}/mcp-server.mjs`,Tr=`${st}/.secrets`,C_=`${Tr}/mcp-auth.json`,Ci=`${st}/.codex`,A_=`${Ci}/linzumi-thread-map.json`,il="/etc/ssl/certs/ca-certificates.crt";ta=`${st}/.turn-heartbeats`,E_=/^[A-Za-z0-9-]{8,64}$/});function ml(e){return Buffer.from(JSON.stringify(e),"utf8").toString("base64")}var Oi,pl,oa=_(()=>{"use strict";Oi={mcpAuthFileContents:"LINZUMI_CLOUD_MCP_AUTH_JSON",llmProxyToken:"LINZUMI_CLOUD_LLM_PROXY_TOKEN"};pl="exit"});var _l=_(()=>{});var hl=_(()=>{_l()});var we=_(()=>{"use strict"});var Pi=_(()=>{"use strict";we()});var yl=_(()=>{"use strict";Pi();we()});var kt=V((ux,Sl)=>{"use strict";var gl=["nodebuffer","arraybuffer","fragments"],bl=typeof Blob<"u";bl&&gl.push("blob");Sl.exports={BINARY_TYPES:gl,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:bl,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var kr=V((cx,Ri)=>{"use strict";var{EMPTY_BUFFER:I_}=kt(),aa=Buffer[Symbol.species];function M_(e,t){if(e.length===0)return I_;if(e.length===1)return e[0];let n=Buffer.allocUnsafe(t),r=0;for(let i=0;i<e.length;i++){let o=e[i];n.set(o,r),r+=o.length}return r<t?new aa(n.buffer,n.byteOffset,r):n}function vl(e,t,n,r,i){for(let o=0;o<i;o++)n[r+o]=e[o]^t[o&3]}function xl(e,t){for(let n=0;n<e.length;n++)e[n]^=t[n&3]}function q_(e){return e.length===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.length)}function da(e){if(da.readOnly=!0,Buffer.isBuffer(e))return e;let t;return e instanceof ArrayBuffer?t=new aa(e):ArrayBuffer.isView(e)?t=new aa(e.buffer,e.byteOffset,e.byteLength):(t=Buffer.from(e),da.readOnly=!1),t}Ri.exports={concat:M_,mask:vl,toArrayBuffer:q_,toBuffer:da,unmask:xl};if(!process.env.WS_NO_BUFFER_UTIL)try{let e=K("bufferutil");Ri.exports.mask=function(t,n,r,i,o){o<48?vl(t,n,r,i,o):e.mask(t,n,r,i,o)},Ri.exports.unmask=function(t,n){t.length<32?xl(t,n):e.unmask(t,n)}}catch{}});var kl=V((fx,Tl)=>{"use strict";var wl=Symbol("kDone"),sa=Symbol("kRun"),la=class{constructor(t){this[wl]=()=>{this.pending--,this[sa]()},this.concurrency=t||1/0,this.jobs=[],this.pending=0}add(t){this.jobs.push(t),this[sa]()}[sa](){if(this.pending!==this.concurrency&&this.jobs.length){let t=this.jobs.shift();this.pending++,t(this[wl])}}};Tl.exports=la});var Ar=V((mx,Ol)=>{"use strict";var Cr=K("zlib"),Cl=kr(),j_=kl(),{kStatusCode:Al}=kt(),F_=Buffer[Symbol.species],$_=Buffer.from([0,0,255,255]),Mi=Symbol("permessage-deflate"),Ct=Symbol("total-length"),Un=Symbol("callback"),Lt=Symbol("buffers"),Kn=Symbol("error"),Ii,ua=class{constructor(t,n,r){if(this._maxPayload=r|0,this._options=t||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._isServer=!!n,this._deflate=null,this._inflate=null,this.params=null,!Ii){let i=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Ii=new j_(i)}}static get extensionName(){return"permessage-deflate"}offer(){let t={};return this._options.serverNoContextTakeover&&(t.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(t.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(t.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?t.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(t.client_max_window_bits=!0),t}accept(t){return t=this.normalizeParams(t),this.params=this._isServer?this.acceptAsServer(t):this.acceptAsClient(t),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let t=this._deflate[Un];this._deflate.close(),this._deflate=null,t&&t(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(t){let n=this._options,r=t.find(i=>!(n.serverNoContextTakeover===!1&&i.server_no_context_takeover||i.server_max_window_bits&&(n.serverMaxWindowBits===!1||typeof n.serverMaxWindowBits=="number"&&n.serverMaxWindowBits>i.server_max_window_bits)||typeof n.clientMaxWindowBits=="number"&&!i.client_max_window_bits));if(!r)throw new Error("None of the extension offers can be accepted");return n.serverNoContextTakeover&&(r.server_no_context_takeover=!0),n.clientNoContextTakeover&&(r.client_no_context_takeover=!0),typeof n.serverMaxWindowBits=="number"&&(r.server_max_window_bits=n.serverMaxWindowBits),typeof n.clientMaxWindowBits=="number"?r.client_max_window_bits=n.clientMaxWindowBits:(r.client_max_window_bits===!0||n.clientMaxWindowBits===!1)&&delete r.client_max_window_bits,r}acceptAsClient(t){let n=t[0];if(this._options.clientNoContextTakeover===!1&&n.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!n.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(n.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&n.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return n}normalizeParams(t){return t.forEach(n=>{Object.keys(n).forEach(r=>{let i=n[r];if(i.length>1)throw new Error(`Parameter "${r}" must have only a single value`);if(i=i[0],r==="client_max_window_bits"){if(i!==!0){let o=+i;if(!Number.isInteger(o)||o<8||o>15)throw new TypeError(`Invalid value for parameter "${r}": ${i}`);i=o}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${r}": ${i}`)}else if(r==="server_max_window_bits"){let o=+i;if(!Number.isInteger(o)||o<8||o>15)throw new TypeError(`Invalid value for parameter "${r}": ${i}`);i=o}else if(r==="client_no_context_takeover"||r==="server_no_context_takeover"){if(i!==!0)throw new TypeError(`Invalid value for parameter "${r}": ${i}`)}else throw new Error(`Unknown parameter "${r}"`);n[r]=i})}),t}decompress(t,n,r){Ii.add(i=>{this._decompress(t,n,(o,a)=>{i(),r(o,a)})})}compress(t,n,r){Ii.add(i=>{this._compress(t,n,(o,a)=>{i(),r(o,a)})})}_decompress(t,n,r){let i=this._isServer?"client":"server";if(!this._inflate){let o=`${i}_max_window_bits`,a=typeof this.params[o]!="number"?Cr.Z_DEFAULT_WINDOWBITS:this.params[o];this._inflate=Cr.createInflateRaw({...this._options.zlibInflateOptions,windowBits:a}),this._inflate[Mi]=this,this._inflate[Ct]=0,this._inflate[Lt]=[],this._inflate.on("error",N_),this._inflate.on("data",El)}this._inflate[Un]=r,this._inflate.write(t),n&&this._inflate.write($_),this._inflate.flush(()=>{let o=this._inflate[Kn];if(o){this._inflate.close(),this._inflate=null,r(o);return}let a=Cl.concat(this._inflate[Lt],this._inflate[Ct]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Ct]=0,this._inflate[Lt]=[],n&&this.params[`${i}_no_context_takeover`]&&this._inflate.reset()),r(null,a)})}_compress(t,n,r){let i=this._isServer?"server":"client";if(!this._deflate){let o=`${i}_max_window_bits`,a=typeof this.params[o]!="number"?Cr.Z_DEFAULT_WINDOWBITS:this.params[o];this._deflate=Cr.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:a}),this._deflate[Ct]=0,this._deflate[Lt]=[],this._deflate.on("data",G_)}this._deflate[Un]=r,this._deflate.write(t),this._deflate.flush(Cr.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let o=Cl.concat(this._deflate[Lt],this._deflate[Ct]);n&&(o=new F_(o.buffer,o.byteOffset,o.length-4)),this._deflate[Un]=null,this._deflate[Ct]=0,this._deflate[Lt]=[],n&&this.params[`${i}_no_context_takeover`]&&this._deflate.reset(),r(null,o)})}};Ol.exports=ua;function G_(e){this[Lt].push(e),this[Ct]+=e.length}function El(e){if(this[Ct]+=e.length,this[Mi]._maxPayload<1||this[Ct]<=this[Mi]._maxPayload){this[Lt].push(e);return}this[Kn]=new RangeError("Max payload size exceeded"),this[Kn].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Kn][Al]=1009,this.removeListener("data",El),this.reset()}function N_(e){if(this[Mi]._inflate=null,this[Kn]){this[Un](this[Kn]);return}e[Al]=1007,this[Un](e)}});var Bn=V((px,qi)=>{"use strict";var{isUtf8:Pl}=K("buffer"),{hasBlob:D_}=kt(),L_=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0];function J_(e){return e>=1e3&&e<=1014&&e!==1004&&e!==1005&&e!==1006||e>=3e3&&e<=4999}function ca(e){let t=e.length,n=0;for(;n<t;)if((e[n]&128)===0)n++;else if((e[n]&224)===192){if(n+1===t||(e[n+1]&192)!==128||(e[n]&254)===192)return!1;n+=2}else if((e[n]&240)===224){if(n+2>=t||(e[n+1]&192)!==128||(e[n+2]&192)!==128||e[n]===224&&(e[n+1]&224)===128||e[n]===237&&(e[n+1]&224)===160)return!1;n+=3}else if((e[n]&248)===240){if(n+3>=t||(e[n+1]&192)!==128||(e[n+2]&192)!==128||(e[n+3]&192)!==128||e[n]===240&&(e[n+1]&240)===128||e[n]===244&&e[n+1]>143||e[n]>244)return!1;n+=4}else return!1;return!0}function U_(e){return D_&&typeof e=="object"&&typeof e.arrayBuffer=="function"&&typeof e.type=="string"&&typeof e.stream=="function"&&(e[Symbol.toStringTag]==="Blob"||e[Symbol.toStringTag]==="File")}qi.exports={isBlob:U_,isValidStatusCode:J_,isValidUTF8:ca,tokenChars:L_};if(Pl)qi.exports.isValidUTF8=function(e){return e.length<24?ca(e):Pl(e)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let e=K("utf-8-validate");qi.exports.isValidUTF8=function(t){return t.length<32?ca(t):e(t)}}catch{}});var ha=V((_x,$l)=>{"use strict";var{Writable:K_}=K("stream"),Rl=Ar(),{BINARY_TYPES:B_,EMPTY_BUFFER:Il,kStatusCode:z_,kWebSocket:W_}=kt(),{concat:fa,toArrayBuffer:H_,unmask:V_}=kr(),{isValidStatusCode:Q_,isValidUTF8:Ml}=Bn(),ji=Buffer[Symbol.species],Ye=0,ql=1,jl=2,Fl=3,ma=4,pa=5,Fi=6,_a=class extends K_{constructor(t={}){super(),this._allowSynchronousEvents=t.allowSynchronousEvents!==void 0?t.allowSynchronousEvents:!0,this._binaryType=t.binaryType||B_[0],this._extensions=t.extensions||{},this._isServer=!!t.isServer,this._maxPayload=t.maxPayload|0,this._skipUTF8Validation=!!t.skipUTF8Validation,this[W_]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=Ye}_write(t,n,r){if(this._opcode===8&&this._state==Ye)return r();this._bufferedBytes+=t.length,this._buffers.push(t),this.startLoop(r)}consume(t){if(this._bufferedBytes-=t,t===this._buffers[0].length)return this._buffers.shift();if(t<this._buffers[0].length){let r=this._buffers[0];return this._buffers[0]=new ji(r.buffer,r.byteOffset+t,r.length-t),new ji(r.buffer,r.byteOffset,t)}let n=Buffer.allocUnsafe(t);do{let r=this._buffers[0],i=n.length-t;t>=r.length?n.set(this._buffers.shift(),i):(n.set(new Uint8Array(r.buffer,r.byteOffset,t),i),this._buffers[0]=new ji(r.buffer,r.byteOffset+t,r.length-t)),t-=r.length}while(t>0);return n}startLoop(t){this._loop=!0;do switch(this._state){case Ye:this.getInfo(t);break;case ql:this.getPayloadLength16(t);break;case jl:this.getPayloadLength64(t);break;case Fl:this.getMask();break;case ma:this.getData(t);break;case pa:case Fi:this._loop=!1;return}while(this._loop);this._errored||t()}getInfo(t){if(this._bufferedBytes<2){this._loop=!1;return}let n=this.consume(2);if((n[0]&48)!==0){let i=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");t(i);return}let r=(n[0]&64)===64;if(r&&!this._extensions[Rl.extensionName]){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");t(i);return}if(this._fin=(n[0]&128)===128,this._opcode=n[0]&15,this._payloadLength=n[1]&127,this._opcode===0){if(r){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");t(i);return}if(!this._fragmented){let i=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");t(i);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let i=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");t(i);return}this._compressed=r}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let i=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");t(i);return}if(r){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");t(i);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let i=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");t(i);return}}else{let i=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");t(i);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(n[1]&128)===128,this._isServer){if(!this._masked){let i=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");t(i);return}}else if(this._masked){let i=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");t(i);return}this._payloadLength===126?this._state=ql:this._payloadLength===127?this._state=jl:this.haveLength(t)}getPayloadLength16(t){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(t)}getPayloadLength64(t){if(this._bufferedBytes<8){this._loop=!1;return}let n=this.consume(8),r=n.readUInt32BE(0);if(r>Math.pow(2,21)-1){let i=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");t(i);return}this._payloadLength=r*Math.pow(2,32)+n.readUInt32BE(4),this.haveLength(t)}haveLength(t){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let n=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");t(n);return}this._masked?this._state=Fl:this._state=ma}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=ma}getData(t){let n=Il;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}n=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0&&V_(n,this._mask)}if(this._opcode>7){this.controlMessage(n,t);return}if(this._compressed){this._state=pa,this.decompress(n,t);return}n.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(n)),this.dataMessage(t)}decompress(t,n){this._extensions[Rl.extensionName].decompress(t,this._fin,(i,o)=>{if(i)return n(i);if(o.length){if(this._messageLength+=o.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let a=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");n(a);return}this._fragments.push(o)}this.dataMessage(n),this._state===Ye&&this.startLoop(n)})}dataMessage(t){if(!this._fin){this._state=Ye;return}let n=this._messageLength,r=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let i;this._binaryType==="nodebuffer"?i=fa(r,n):this._binaryType==="arraybuffer"?i=H_(fa(r,n)):this._binaryType==="blob"?i=new Blob(r):i=r,this._allowSynchronousEvents?(this.emit("message",i,!0),this._state=Ye):(this._state=Fi,setImmediate(()=>{this.emit("message",i,!0),this._state=Ye,this.startLoop(t)}))}else{let i=fa(r,n);if(!this._skipUTF8Validation&&!Ml(i)){let o=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");t(o);return}this._state===pa||this._allowSynchronousEvents?(this.emit("message",i,!1),this._state=Ye):(this._state=Fi,setImmediate(()=>{this.emit("message",i,!1),this._state=Ye,this.startLoop(t)}))}}controlMessage(t,n){if(this._opcode===8){if(t.length===0)this._loop=!1,this.emit("conclude",1005,Il),this.end();else{let r=t.readUInt16BE(0);if(!Q_(r)){let o=this.createError(RangeError,`invalid status code ${r}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");n(o);return}let i=new ji(t.buffer,t.byteOffset+2,t.length-2);if(!this._skipUTF8Validation&&!Ml(i)){let o=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");n(o);return}this._loop=!1,this.emit("conclude",r,i),this.end()}this._state=Ye;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",t),this._state=Ye):(this._state=Fi,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",t),this._state=Ye,this.startLoop(n)}))}createError(t,n,r,i,o){this._loop=!1,this._errored=!0;let a=new t(r?`Invalid WebSocket frame: ${n}`:n);return Error.captureStackTrace(a,this.createError),a.code=o,a[z_]=i,a}};$l.exports=_a});var ba=V((yx,Dl)=>{"use strict";var{Duplex:hx}=K("stream"),{randomFillSync:Z_}=K("crypto"),Gl=Ar(),{EMPTY_BUFFER:Y_,kWebSocket:X_,NOOP:eh}=kt(),{isBlob:zn,isValidStatusCode:th}=Bn(),{mask:Nl,toBuffer:cn}=kr(),Xe=Symbol("kByteLength"),nh=Buffer.alloc(4),$i=8*1024,fn,Wn=$i,rt=0,rh=1,ih=2,ya=class e{constructor(t,n,r){this._extensions=n||{},r&&(this._generateMask=r,this._maskBuffer=Buffer.alloc(4)),this._socket=t,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=rt,this.onerror=eh,this[X_]=void 0}static frame(t,n){let r,i=!1,o=2,a=!1;n.mask&&(r=n.maskBuffer||nh,n.generateMask?n.generateMask(r):(Wn===$i&&(fn===void 0&&(fn=Buffer.alloc($i)),Z_(fn,0,$i),Wn=0),r[0]=fn[Wn++],r[1]=fn[Wn++],r[2]=fn[Wn++],r[3]=fn[Wn++]),a=(r[0]|r[1]|r[2]|r[3])===0,o=6);let d;typeof t=="string"?(!n.mask||a)&&n[Xe]!==void 0?d=n[Xe]:(t=Buffer.from(t),d=t.length):(d=t.length,i=n.mask&&n.readOnly&&!a);let l=d;d>=65536?(o+=8,l=127):d>125&&(o+=2,l=126);let u=Buffer.allocUnsafe(i?d+o:o);return u[0]=n.fin?n.opcode|128:n.opcode,n.rsv1&&(u[0]|=64),u[1]=l,l===126?u.writeUInt16BE(d,2):l===127&&(u[2]=u[3]=0,u.writeUIntBE(d,4,6)),n.mask?(u[1]|=128,u[o-4]=r[0],u[o-3]=r[1],u[o-2]=r[2],u[o-1]=r[3],a?[u,t]:i?(Nl(t,r,u,o,d),[u]):(Nl(t,r,t,0,d),[u,t])):[u,t]}close(t,n,r,i){let o;if(t===void 0)o=Y_;else{if(typeof t!="number"||!th(t))throw new TypeError("First argument must be a valid error code number");if(n===void 0||!n.length)o=Buffer.allocUnsafe(2),o.writeUInt16BE(t,0);else{let d=Buffer.byteLength(n);if(d>123)throw new RangeError("The message must not be greater than 123 bytes");o=Buffer.allocUnsafe(2+d),o.writeUInt16BE(t,0),typeof n=="string"?o.write(n,2):o.set(n,2)}}let a={[Xe]:o.length,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==rt?this.enqueue([this.dispatch,o,!1,a,i]):this.sendFrame(e.frame(o,a),i)}ping(t,n,r){let i,o;if(typeof t=="string"?(i=Buffer.byteLength(t),o=!1):zn(t)?(i=t.size,o=!1):(t=cn(t),i=t.length,o=cn.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let a={[Xe]:i,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:9,readOnly:o,rsv1:!1};zn(t)?this._state!==rt?this.enqueue([this.getBlobData,t,!1,a,r]):this.getBlobData(t,!1,a,r):this._state!==rt?this.enqueue([this.dispatch,t,!1,a,r]):this.sendFrame(e.frame(t,a),r)}pong(t,n,r){let i,o;if(typeof t=="string"?(i=Buffer.byteLength(t),o=!1):zn(t)?(i=t.size,o=!1):(t=cn(t),i=t.length,o=cn.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let a={[Xe]:i,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:10,readOnly:o,rsv1:!1};zn(t)?this._state!==rt?this.enqueue([this.getBlobData,t,!1,a,r]):this.getBlobData(t,!1,a,r):this._state!==rt?this.enqueue([this.dispatch,t,!1,a,r]):this.sendFrame(e.frame(t,a),r)}send(t,n,r){let i=this._extensions[Gl.extensionName],o=n.binary?2:1,a=n.compress,d,l;typeof t=="string"?(d=Buffer.byteLength(t),l=!1):zn(t)?(d=t.size,l=!1):(t=cn(t),d=t.length,l=cn.readOnly),this._firstFragment?(this._firstFragment=!1,a&&i&&i.params[i._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(a=d>=i._threshold),this._compress=a):(a=!1,o=0),n.fin&&(this._firstFragment=!0);let u={[Xe]:d,fin:n.fin,generateMask:this._generateMask,mask:n.mask,maskBuffer:this._maskBuffer,opcode:o,readOnly:l,rsv1:a};zn(t)?this._state!==rt?this.enqueue([this.getBlobData,t,this._compress,u,r]):this.getBlobData(t,this._compress,u,r):this._state!==rt?this.enqueue([this.dispatch,t,this._compress,u,r]):this.dispatch(t,this._compress,u,r)}getBlobData(t,n,r,i){this._bufferedBytes+=r[Xe],this._state=ih,t.arrayBuffer().then(o=>{if(this._socket.destroyed){let d=new Error("The socket was closed while the blob was being read");process.nextTick(ga,this,d,i);return}this._bufferedBytes-=r[Xe];let a=cn(o);n?this.dispatch(a,n,r,i):(this._state=rt,this.sendFrame(e.frame(a,r),i),this.dequeue())}).catch(o=>{process.nextTick(oh,this,o,i)})}dispatch(t,n,r,i){if(!n){this.sendFrame(e.frame(t,r),i);return}let o=this._extensions[Gl.extensionName];this._bufferedBytes+=r[Xe],this._state=rh,o.compress(t,r.fin,(a,d)=>{if(this._socket.destroyed){let l=new Error("The socket was closed while data was being compressed");ga(this,l,i);return}this._bufferedBytes-=r[Xe],this._state=rt,r.readOnly=!1,this.sendFrame(e.frame(d,r),i),this.dequeue()})}dequeue(){for(;this._state===rt&&this._queue.length;){let t=this._queue.shift();this._bufferedBytes-=t[3][Xe],Reflect.apply(t[0],this,t.slice(1))}}enqueue(t){this._bufferedBytes+=t[3][Xe],this._queue.push(t)}sendFrame(t,n){t.length===2?(this._socket.cork(),this._socket.write(t[0]),this._socket.write(t[1],n),this._socket.uncork()):this._socket.write(t[0],n)}};Dl.exports=ya;function ga(e,t,n){typeof n=="function"&&n(t);for(let r=0;r<e._queue.length;r++){let i=e._queue[r],o=i[i.length-1];typeof o=="function"&&o(t)}}function oh(e,t,n){ga(e,t,n),e.onerror(t)}});var Vl=V((gx,Hl)=>{"use strict";var{kForOnEventAttribute:Er,kListener:Sa}=kt(),Ll=Symbol("kCode"),Jl=Symbol("kData"),Ul=Symbol("kError"),Kl=Symbol("kMessage"),Bl=Symbol("kReason"),Hn=Symbol("kTarget"),zl=Symbol("kType"),Wl=Symbol("kWasClean"),At=class{constructor(t){this[Hn]=null,this[zl]=t}get target(){return this[Hn]}get type(){return this[zl]}};Object.defineProperty(At.prototype,"target",{enumerable:!0});Object.defineProperty(At.prototype,"type",{enumerable:!0});var mn=class extends At{constructor(t,n={}){super(t),this[Ll]=n.code===void 0?0:n.code,this[Bl]=n.reason===void 0?"":n.reason,this[Wl]=n.wasClean===void 0?!1:n.wasClean}get code(){return this[Ll]}get reason(){return this[Bl]}get wasClean(){return this[Wl]}};Object.defineProperty(mn.prototype,"code",{enumerable:!0});Object.defineProperty(mn.prototype,"reason",{enumerable:!0});Object.defineProperty(mn.prototype,"wasClean",{enumerable:!0});var Vn=class extends At{constructor(t,n={}){super(t),this[Ul]=n.error===void 0?null:n.error,this[Kl]=n.message===void 0?"":n.message}get error(){return this[Ul]}get message(){return this[Kl]}};Object.defineProperty(Vn.prototype,"error",{enumerable:!0});Object.defineProperty(Vn.prototype,"message",{enumerable:!0});var Or=class extends At{constructor(t,n={}){super(t),this[Jl]=n.data===void 0?null:n.data}get data(){return this[Jl]}};Object.defineProperty(Or.prototype,"data",{enumerable:!0});var ah={addEventListener(e,t,n={}){for(let i of this.listeners(e))if(!n[Er]&&i[Sa]===t&&!i[Er])return;let r;if(e==="message")r=function(o,a){let d=new Or("message",{data:a?o:o.toString()});d[Hn]=this,Gi(t,this,d)};else if(e==="close")r=function(o,a){let d=new mn("close",{code:o,reason:a.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});d[Hn]=this,Gi(t,this,d)};else if(e==="error")r=function(o){let a=new Vn("error",{error:o,message:o.message});a[Hn]=this,Gi(t,this,a)};else if(e==="open")r=function(){let o=new At("open");o[Hn]=this,Gi(t,this,o)};else return;r[Er]=!!n[Er],r[Sa]=t,n.once?this.once(e,r):this.on(e,r)},removeEventListener(e,t){for(let n of this.listeners(e))if(n[Sa]===t&&!n[Er]){this.removeListener(e,n);break}}};Hl.exports={CloseEvent:mn,ErrorEvent:Vn,Event:At,EventTarget:ah,MessageEvent:Or};function Gi(e,t,n){typeof e=="object"&&e.handleEvent?e.handleEvent.call(e,n):e.call(t,n)}});var va=V((bx,Ql)=>{"use strict";var{tokenChars:Pr}=Bn();function lt(e,t,n){e[t]===void 0?e[t]=[n]:e[t].push(n)}function dh(e){let t=Object.create(null),n=Object.create(null),r=!1,i=!1,o=!1,a,d,l=-1,u=-1,s=-1,m=0;for(;m<e.length;m++)if(u=e.charCodeAt(m),a===void 0)if(s===-1&&Pr[u]===1)l===-1&&(l=m);else if(m!==0&&(u===32||u===9))s===-1&&l!==-1&&(s=m);else if(u===59||u===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${m}`);s===-1&&(s=m);let f=e.slice(l,s);u===44?(lt(t,f,n),n=Object.create(null)):a=f,l=s=-1}else throw new SyntaxError(`Unexpected character at index ${m}`);else if(d===void 0)if(s===-1&&Pr[u]===1)l===-1&&(l=m);else if(u===32||u===9)s===-1&&l!==-1&&(s=m);else if(u===59||u===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${m}`);s===-1&&(s=m),lt(n,e.slice(l,s),!0),u===44&&(lt(t,a,n),n=Object.create(null),a=void 0),l=s=-1}else if(u===61&&l!==-1&&s===-1)d=e.slice(l,m),l=s=-1;else throw new SyntaxError(`Unexpected character at index ${m}`);else if(i){if(Pr[u]!==1)throw new SyntaxError(`Unexpected character at index ${m}`);l===-1?l=m:r||(r=!0),i=!1}else if(o)if(Pr[u]===1)l===-1&&(l=m);else if(u===34&&l!==-1)o=!1,s=m;else if(u===92)i=!0;else throw new SyntaxError(`Unexpected character at index ${m}`);else if(u===34&&e.charCodeAt(m-1)===61)o=!0;else if(s===-1&&Pr[u]===1)l===-1&&(l=m);else if(l!==-1&&(u===32||u===9))s===-1&&(s=m);else if(u===59||u===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${m}`);s===-1&&(s=m);let f=e.slice(l,s);r&&(f=f.replace(/\\/g,""),r=!1),lt(n,d,f),u===44&&(lt(t,a,n),n=Object.create(null),a=void 0),d=void 0,l=s=-1}else throw new SyntaxError(`Unexpected character at index ${m}`);if(l===-1||o||u===32||u===9)throw new SyntaxError("Unexpected end of input");s===-1&&(s=m);let p=e.slice(l,s);return a===void 0?lt(t,p,n):(d===void 0?lt(n,p,!0):r?lt(n,d,p.replace(/\\/g,"")):lt(n,d,p),lt(t,a,n)),t}function sh(e){return Object.keys(e).map(t=>{let n=e[t];return Array.isArray(n)||(n=[n]),n.map(r=>[t].concat(Object.keys(r).map(i=>{let o=r[i];return Array.isArray(o)||(o=[o]),o.map(a=>a===!0?i:`${i}=${a}`).join("; ")})).join("; ")).join(", ")}).join(", ")}Ql.exports={format:sh,parse:dh}});var Ji=V((xx,su)=>{"use strict";var lh=K("events"),uh=K("https"),ch=K("http"),Xl=K("net"),fh=K("tls"),{randomBytes:mh,createHash:ph}=K("crypto"),{Duplex:Sx,Readable:vx}=K("stream"),{URL:xa}=K("url"),Jt=Ar(),_h=ha(),hh=ba(),{isBlob:yh}=Bn(),{BINARY_TYPES:Zl,EMPTY_BUFFER:Ni,GUID:gh,kForOnEventAttribute:wa,kListener:bh,kStatusCode:Sh,kWebSocket:Ee,NOOP:eu}=kt(),{EventTarget:{addEventListener:vh,removeEventListener:xh}}=Vl(),{format:wh,parse:Th}=va(),{toBuffer:kh}=kr(),Ch=30*1e3,tu=Symbol("kAborted"),Ta=[8,13],Et=["CONNECTING","OPEN","CLOSING","CLOSED"],Ah=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,ne=class e extends lh{constructor(t,n,r){super(),this._binaryType=Zl[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Ni,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=e.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,t!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,n===void 0?n=[]:Array.isArray(n)||(typeof n=="object"&&n!==null?(r=n,n=[]):n=[n]),nu(this,t,n,r)):(this._autoPong=r.autoPong,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(t){Zl.includes(t)&&(this._binaryType=t,this._receiver&&(this._receiver._binaryType=t))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(t,n,r){let i=new _h({allowSynchronousEvents:r.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:r.maxPayload,skipUTF8Validation:r.skipUTF8Validation}),o=new hh(t,this._extensions,r.generateMask);this._receiver=i,this._sender=o,this._socket=t,i[Ee]=this,o[Ee]=this,t[Ee]=this,i.on("conclude",Ph),i.on("drain",Rh),i.on("error",Ih),i.on("message",Mh),i.on("ping",qh),i.on("pong",jh),o.onerror=Fh,t.setTimeout&&t.setTimeout(0),t.setNoDelay&&t.setNoDelay(),n.length>0&&t.unshift(n),t.on("close",ou),t.on("data",Li),t.on("end",au),t.on("error",du),this._readyState=e.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=e.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[Jt.extensionName]&&this._extensions[Jt.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=e.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(t,n){if(this.readyState!==e.CLOSED){if(this.readyState===e.CONNECTING){ze(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===e.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=e.CLOSING,this._sender.close(t,n,!this._isServer,r=>{r||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),iu(this)}}pause(){this.readyState===e.CONNECTING||this.readyState===e.CLOSED||(this._paused=!0,this._socket.pause())}ping(t,n,r){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof t=="function"?(r=t,t=n=void 0):typeof n=="function"&&(r=n,n=void 0),typeof t=="number"&&(t=t.toString()),this.readyState!==e.OPEN){ka(this,t,r);return}n===void 0&&(n=!this._isServer),this._sender.ping(t||Ni,n,r)}pong(t,n,r){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof t=="function"?(r=t,t=n=void 0):typeof n=="function"&&(r=n,n=void 0),typeof t=="number"&&(t=t.toString()),this.readyState!==e.OPEN){ka(this,t,r);return}n===void 0&&(n=!this._isServer),this._sender.pong(t||Ni,n,r)}resume(){this.readyState===e.CONNECTING||this.readyState===e.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(t,n,r){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof n=="function"&&(r=n,n={}),typeof t=="number"&&(t=t.toString()),this.readyState!==e.OPEN){ka(this,t,r);return}let i={binary:typeof t!="string",mask:!this._isServer,compress:!0,fin:!0,...n};this._extensions[Jt.extensionName]||(i.compress=!1),this._sender.send(t||Ni,i,r)}terminate(){if(this.readyState!==e.CLOSED){if(this.readyState===e.CONNECTING){ze(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=e.CLOSING,this._socket.destroy())}}};Object.defineProperty(ne,"CONNECTING",{enumerable:!0,value:Et.indexOf("CONNECTING")});Object.defineProperty(ne.prototype,"CONNECTING",{enumerable:!0,value:Et.indexOf("CONNECTING")});Object.defineProperty(ne,"OPEN",{enumerable:!0,value:Et.indexOf("OPEN")});Object.defineProperty(ne.prototype,"OPEN",{enumerable:!0,value:Et.indexOf("OPEN")});Object.defineProperty(ne,"CLOSING",{enumerable:!0,value:Et.indexOf("CLOSING")});Object.defineProperty(ne.prototype,"CLOSING",{enumerable:!0,value:Et.indexOf("CLOSING")});Object.defineProperty(ne,"CLOSED",{enumerable:!0,value:Et.indexOf("CLOSED")});Object.defineProperty(ne.prototype,"CLOSED",{enumerable:!0,value:Et.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(e=>{Object.defineProperty(ne.prototype,e,{enumerable:!0})});["open","error","close","message"].forEach(e=>{Object.defineProperty(ne.prototype,`on${e}`,{enumerable:!0,get(){for(let t of this.listeners(e))if(t[wa])return t[bh];return null},set(t){for(let n of this.listeners(e))if(n[wa]){this.removeListener(e,n);break}typeof t=="function"&&this.addEventListener(e,t,{[wa]:!0})}})});ne.prototype.addEventListener=vh;ne.prototype.removeEventListener=xh;su.exports=ne;function nu(e,t,n,r){let i={allowSynchronousEvents:!0,autoPong:!0,protocolVersion:Ta[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...r,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(e._autoPong=i.autoPong,!Ta.includes(i.protocolVersion))throw new RangeError(`Unsupported protocol version: ${i.protocolVersion} (supported versions: ${Ta.join(", ")})`);let o;if(t instanceof xa)o=t;else try{o=new xa(t)}catch{throw new SyntaxError(`Invalid URL: ${t}`)}o.protocol==="http:"?o.protocol="ws:":o.protocol==="https:"&&(o.protocol="wss:"),e._url=o.href;let a=o.protocol==="wss:",d=o.protocol==="ws+unix:",l;if(o.protocol!=="ws:"&&!a&&!d?l=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:d&&!o.pathname?l="The URL's pathname is empty":o.hash&&(l="The URL contains a fragment identifier"),l){let c=new SyntaxError(l);if(e._redirects===0)throw c;Di(e,c);return}let u=a?443:80,s=mh(16).toString("base64"),m=a?uh.request:ch.request,p=new Set,f;if(i.createConnection=i.createConnection||(a?Oh:Eh),i.defaultPort=i.defaultPort||u,i.port=o.port||u,i.host=o.hostname.startsWith("[")?o.hostname.slice(1,-1):o.hostname,i.headers={...i.headers,"Sec-WebSocket-Version":i.protocolVersion,"Sec-WebSocket-Key":s,Connection:"Upgrade",Upgrade:"websocket"},i.path=o.pathname+o.search,i.timeout=i.handshakeTimeout,i.perMessageDeflate&&(f=new Jt(i.perMessageDeflate!==!0?i.perMessageDeflate:{},!1,i.maxPayload),i.headers["Sec-WebSocket-Extensions"]=wh({[Jt.extensionName]:f.offer()})),n.length){for(let c of n){if(typeof c!="string"||!Ah.test(c)||p.has(c))throw new SyntaxError("An invalid or duplicated subprotocol was specified");p.add(c)}i.headers["Sec-WebSocket-Protocol"]=n.join(",")}if(i.origin&&(i.protocolVersion<13?i.headers["Sec-WebSocket-Origin"]=i.origin:i.headers.Origin=i.origin),(o.username||o.password)&&(i.auth=`${o.username}:${o.password}`),d){let c=i.path.split(":");i.socketPath=c[0],i.path=c[1]}let h;if(i.followRedirects){if(e._redirects===0){e._originalIpc=d,e._originalSecure=a,e._originalHostOrSocketPath=d?i.socketPath:o.host;let c=r&&r.headers;if(r={...r,headers:{}},c)for(let[y,b]of Object.entries(c))r.headers[y.toLowerCase()]=b}else if(e.listenerCount("redirect")===0){let c=d?e._originalIpc?i.socketPath===e._originalHostOrSocketPath:!1:e._originalIpc?!1:o.host===e._originalHostOrSocketPath;(!c||e._originalSecure&&!a)&&(delete i.headers.authorization,delete i.headers.cookie,c||delete i.headers.host,i.auth=void 0)}i.auth&&!r.headers.authorization&&(r.headers.authorization="Basic "+Buffer.from(i.auth).toString("base64")),h=e._req=m(i),e._redirects&&e.emit("redirect",e.url,h)}else h=e._req=m(i);i.timeout&&h.on("timeout",()=>{ze(e,h,"Opening handshake has timed out")}),h.on("error",c=>{h===null||h[tu]||(h=e._req=null,Di(e,c))}),h.on("response",c=>{let y=c.headers.location,b=c.statusCode;if(y&&i.followRedirects&&b>=300&&b<400){if(++e._redirects>i.maxRedirects){ze(e,h,"Maximum redirects exceeded");return}h.abort();let x;try{x=new xa(y,t)}catch{let g=new SyntaxError(`Invalid URL: ${y}`);Di(e,g);return}nu(e,x,n,r)}else e.emit("unexpected-response",h,c)||ze(e,h,`Unexpected server response: ${c.statusCode}`)}),h.on("upgrade",(c,y,b)=>{if(e.emit("upgrade",c),e.readyState!==ne.CONNECTING)return;h=e._req=null;let x=c.headers.upgrade;if(x===void 0||x.toLowerCase()!=="websocket"){ze(e,y,"Invalid Upgrade header");return}let v=ph("sha1").update(s+gh).digest("base64");if(c.headers["sec-websocket-accept"]!==v){ze(e,y,"Invalid Sec-WebSocket-Accept header");return}let g=c.headers["sec-websocket-protocol"],O;if(g!==void 0?p.size?p.has(g)||(O="Server sent an invalid subprotocol"):O="Server sent a subprotocol but none was requested":p.size&&(O="Server sent no subprotocol"),O){ze(e,y,O);return}g&&(e._protocol=g);let P=c.headers["sec-websocket-extensions"];if(P!==void 0){if(!f){ze(e,y,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let G;try{G=Th(P)}catch{ze(e,y,"Invalid Sec-WebSocket-Extensions header");return}let le=Object.keys(G);if(le.length!==1||le[0]!==Jt.extensionName){ze(e,y,"Server indicated an extension that was not requested");return}try{f.accept(G[Jt.extensionName])}catch{ze(e,y,"Invalid Sec-WebSocket-Extensions header");return}e._extensions[Jt.extensionName]=f}e.setSocket(y,b,{allowSynchronousEvents:i.allowSynchronousEvents,generateMask:i.generateMask,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation})}),i.finishRequest?i.finishRequest(h,e):h.end()}function Di(e,t){e._readyState=ne.CLOSING,e._errorEmitted=!0,e.emit("error",t),e.emitClose()}function Eh(e){return e.path=e.socketPath,Xl.connect(e)}function Oh(e){return e.path=void 0,!e.servername&&e.servername!==""&&(e.servername=Xl.isIP(e.host)?"":e.host),fh.connect(e)}function ze(e,t,n){e._readyState=ne.CLOSING;let r=new Error(n);Error.captureStackTrace(r,ze),t.setHeader?(t[tu]=!0,t.abort(),t.socket&&!t.socket.destroyed&&t.socket.destroy(),process.nextTick(Di,e,r)):(t.destroy(r),t.once("error",e.emit.bind(e,"error")),t.once("close",e.emitClose.bind(e)))}function ka(e,t,n){if(t){let r=yh(t)?t.size:kh(t).length;e._socket?e._sender._bufferedBytes+=r:e._bufferedAmount+=r}if(n){let r=new Error(`WebSocket is not open: readyState ${e.readyState} (${Et[e.readyState]})`);process.nextTick(n,r)}}function Ph(e,t){let n=this[Ee];n._closeFrameReceived=!0,n._closeMessage=t,n._closeCode=e,n._socket[Ee]!==void 0&&(n._socket.removeListener("data",Li),process.nextTick(ru,n._socket),e===1005?n.close():n.close(e,t))}function Rh(){let e=this[Ee];e.isPaused||e._socket.resume()}function Ih(e){let t=this[Ee];t._socket[Ee]!==void 0&&(t._socket.removeListener("data",Li),process.nextTick(ru,t._socket),t.close(e[Sh])),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e))}function Yl(){this[Ee].emitClose()}function Mh(e,t){this[Ee].emit("message",e,t)}function qh(e){let t=this[Ee];t._autoPong&&t.pong(e,!this._isServer,eu),t.emit("ping",e)}function jh(e){this[Ee].emit("pong",e)}function ru(e){e.resume()}function Fh(e){let t=this[Ee];t.readyState!==ne.CLOSED&&(t.readyState===ne.OPEN&&(t._readyState=ne.CLOSING,iu(t)),this._socket.end(),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e)))}function iu(e){e._closeTimer=setTimeout(e._socket.destroy.bind(e._socket),Ch)}function ou(){let e=this[Ee];this.removeListener("close",ou),this.removeListener("data",Li),this.removeListener("end",au),e._readyState=ne.CLOSING;let t;!this._readableState.endEmitted&&!e._closeFrameReceived&&!e._receiver._writableState.errorEmitted&&(t=e._socket.read())!==null&&e._receiver.write(t),e._receiver.end(),this[Ee]=void 0,clearTimeout(e._closeTimer),e._receiver._writableState.finished||e._receiver._writableState.errorEmitted?e.emitClose():(e._receiver.on("error",Yl),e._receiver.on("finish",Yl))}function Li(e){this[Ee]._receiver.write(e)||this.pause()}function au(){let e=this[Ee];e._readyState=ne.CLOSING,e._receiver.end(),this.end()}function du(){let e=this[Ee];this.removeListener("error",du),this.on("error",eu),e&&(e._readyState=ne.CLOSING,this.destroy())}});var fu=V((Tx,cu)=>{"use strict";var wx=Ji(),{Duplex:$h}=K("stream");function lu(e){e.emit("close")}function Gh(){!this.destroyed&&this._writableState.finished&&this.destroy()}function uu(e){this.removeListener("error",uu),this.destroy(),this.listenerCount("error")===0&&this.emit("error",e)}function Nh(e,t){let n=!0,r=new $h({...t,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return e.on("message",function(o,a){let d=!a&&r._readableState.objectMode?o.toString():o;r.push(d)||e.pause()}),e.once("error",function(o){r.destroyed||(n=!1,r.destroy(o))}),e.once("close",function(){r.destroyed||r.push(null)}),r._destroy=function(i,o){if(e.readyState===e.CLOSED){o(i),process.nextTick(lu,r);return}let a=!1;e.once("error",function(l){a=!0,o(l)}),e.once("close",function(){a||o(i),process.nextTick(lu,r)}),n&&e.terminate()},r._final=function(i){if(e.readyState===e.CONNECTING){e.once("open",function(){r._final(i)});return}e._socket!==null&&(e._socket._writableState.finished?(i(),r._readableState.endEmitted&&r.destroy()):(e._socket.once("finish",function(){i()}),e.close()))},r._read=function(){e.isPaused&&e.resume()},r._write=function(i,o,a){if(e.readyState===e.CONNECTING){e.once("open",function(){r._write(i,o,a)});return}e.send(i,a)},r.on("end",Gh),r.on("error",uu),r}cu.exports=Nh});var pu=V((kx,mu)=>{"use strict";var{tokenChars:Dh}=Bn();function Lh(e){let t=new Set,n=-1,r=-1,i=0;for(i;i<e.length;i++){let a=e.charCodeAt(i);if(r===-1&&Dh[a]===1)n===-1&&(n=i);else if(i!==0&&(a===32||a===9))r===-1&&n!==-1&&(r=i);else if(a===44){if(n===-1)throw new SyntaxError(`Unexpected character at index ${i}`);r===-1&&(r=i);let d=e.slice(n,r);if(t.has(d))throw new SyntaxError(`The "${d}" subprotocol is duplicated`);t.add(d),n=r=-1}else throw new SyntaxError(`Unexpected character at index ${i}`)}if(n===-1||r!==-1)throw new SyntaxError("Unexpected end of input");let o=e.slice(n,i);if(t.has(o))throw new SyntaxError(`The "${o}" subprotocol is duplicated`);return t.add(o),t}mu.exports={parse:Lh}});var vu=V((Ax,Su)=>{"use strict";var Jh=K("events"),Ui=K("http"),{Duplex:Cx}=K("stream"),{createHash:Uh}=K("crypto"),_u=va(),pn=Ar(),Kh=pu(),Bh=Ji(),{GUID:zh,kWebSocket:Wh}=kt(),Hh=/^[+/0-9A-Za-z]{22}==$/,hu=0,yu=1,bu=2,Ca=class extends Jh{constructor(t,n){if(super(),t={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:Bh,...t},t.port==null&&!t.server&&!t.noServer||t.port!=null&&(t.server||t.noServer)||t.server&&t.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(t.port!=null?(this._server=Ui.createServer((r,i)=>{let o=Ui.STATUS_CODES[426];i.writeHead(426,{"Content-Length":o.length,"Content-Type":"text/plain"}),i.end(o)}),this._server.listen(t.port,t.host,t.backlog,n)):t.server&&(this._server=t.server),this._server){let r=this.emit.bind(this,"connection");this._removeListeners=Vh(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(i,o,a)=>{this.handleUpgrade(i,o,a,r)}})}t.perMessageDeflate===!0&&(t.perMessageDeflate={}),t.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=t,this._state=hu}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(t){if(this._state===bu){t&&this.once("close",()=>{t(new Error("The server is not running"))}),process.nextTick(Rr,this);return}if(t&&this.once("close",t),this._state!==yu)if(this._state=yu,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(Rr,this):process.nextTick(Rr,this);else{let n=this._server;this._removeListeners(),this._removeListeners=this._server=null,n.close(()=>{Rr(this)})}}shouldHandle(t){if(this.options.path){let n=t.url.indexOf("?");if((n!==-1?t.url.slice(0,n):t.url)!==this.options.path)return!1}return!0}handleUpgrade(t,n,r,i){n.on("error",gu);let o=t.headers["sec-websocket-key"],a=t.headers.upgrade,d=+t.headers["sec-websocket-version"];if(t.method!=="GET"){_n(this,t,n,405,"Invalid HTTP method");return}if(a===void 0||a.toLowerCase()!=="websocket"){_n(this,t,n,400,"Invalid Upgrade header");return}if(o===void 0||!Hh.test(o)){_n(this,t,n,400,"Missing or invalid Sec-WebSocket-Key header");return}if(d!==13&&d!==8){_n(this,t,n,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(t)){Ir(n,400);return}let l=t.headers["sec-websocket-protocol"],u=new Set;if(l!==void 0)try{u=Kh.parse(l)}catch{_n(this,t,n,400,"Invalid Sec-WebSocket-Protocol header");return}let s=t.headers["sec-websocket-extensions"],m={};if(this.options.perMessageDeflate&&s!==void 0){let p=new pn(this.options.perMessageDeflate,!0,this.options.maxPayload);try{let f=_u.parse(s);f[pn.extensionName]&&(p.accept(f[pn.extensionName]),m[pn.extensionName]=p)}catch{_n(this,t,n,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let p={origin:t.headers[`${d===8?"sec-websocket-origin":"origin"}`],secure:!!(t.socket.authorized||t.socket.encrypted),req:t};if(this.options.verifyClient.length===2){this.options.verifyClient(p,(f,h,c,y)=>{if(!f)return Ir(n,h||401,c,y);this.completeUpgrade(m,o,u,t,n,r,i)});return}if(!this.options.verifyClient(p))return Ir(n,401)}this.completeUpgrade(m,o,u,t,n,r,i)}completeUpgrade(t,n,r,i,o,a,d){if(!o.readable||!o.writable)return o.destroy();if(o[Wh])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>hu)return Ir(o,503);let u=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Uh("sha1").update(n+zh).digest("base64")}`],s=new this.options.WebSocket(null,void 0,this.options);if(r.size){let m=this.options.handleProtocols?this.options.handleProtocols(r,i):r.values().next().value;m&&(u.push(`Sec-WebSocket-Protocol: ${m}`),s._protocol=m)}if(t[pn.extensionName]){let m=t[pn.extensionName].params,p=_u.format({[pn.extensionName]:[m]});u.push(`Sec-WebSocket-Extensions: ${p}`),s._extensions=t}this.emit("headers",u,i),o.write(u.concat(`\r
|
|
7
7
|
`).join(`\r
|