@linzumi/cli 1.0.324 → 1.0.326

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.
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __linzumiBundleCreateRequire } from 'node:module';
2
2
  const require = __linzumiBundleCreateRequire(import.meta.url);
3
3
  var jr=Object.create;var ct=Object.defineProperty;var Rr=Object.getOwnPropertyDescriptor;var Dr=Object.getOwnPropertyNames;var $r=Object.getPrototypeOf,Ur=Object.prototype.hasOwnProperty;var W=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var j=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Vr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Dr(t))!Ur.call(e,i)&&i!==r&&ct(e,i,{get:()=>t[i],enumerable:!(n=Rr(t,i))||n.enumerable});return e};var zr=(e,t,r)=>(r=e!=null?jr($r(e)):{},Vr(t||!e||!e.__esModule?ct(r,"default",{value:e,enumerable:!0}):r,e));var Jt=j((Ci,qt)=>{var K=W("constants"),gn=process.cwd,ke=null,wn=process.env.GRACEFUL_FS_PLATFORM||process.platform;process.cwd=function(){return ke||(ke=gn.call(process)),ke};try{process.cwd()}catch{}typeof process.chdir=="function"&&(We=process.chdir,process.chdir=function(e){ke=null,We.call(process,e)},Object.setPrototypeOf&&Object.setPrototypeOf(process.chdir,We));var We;qt.exports=kn;function kn(e){K.hasOwnProperty("O_SYMLINK")&&process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)&&t(e),e.lutimes||r(e),e.chown=o(e.chown),e.fchown=o(e.fchown),e.lchown=o(e.lchown),e.chmod=n(e.chmod),e.fchmod=n(e.fchmod),e.lchmod=n(e.lchmod),e.chownSync=l(e.chownSync),e.fchownSync=l(e.fchownSync),e.lchownSync=l(e.lchownSync),e.chmodSync=i(e.chmodSync),e.fchmodSync=i(e.fchmodSync),e.lchmodSync=i(e.lchmodSync),e.stat=f(e.stat),e.fstat=f(e.fstat),e.lstat=f(e.lstat),e.statSync=m(e.statSync),e.fstatSync=m(e.fstatSync),e.lstatSync=m(e.lstatSync),e.chmod&&!e.lchmod&&(e.lchmod=function(u,c,s){s&&process.nextTick(s)},e.lchmodSync=function(){}),e.chown&&!e.lchown&&(e.lchown=function(u,c,s,a){a&&process.nextTick(a)},e.lchownSync=function(){}),wn==="win32"&&(e.rename=typeof e.rename!="function"?e.rename:(function(u){function c(s,a,d){var p=Date.now(),h=0;u(s,a,function A(k){if(k&&(k.code==="EACCES"||k.code==="EPERM"||k.code==="EBUSY")&&Date.now()-p<6e4){setTimeout(function(){e.stat(a,function(I,Te){I&&I.code==="ENOENT"?u(s,a,A):d(k)})},h),h<100&&(h+=10);return}d&&d(k)})}return Object.setPrototypeOf&&Object.setPrototypeOf(c,u),c})(e.rename)),e.read=typeof e.read!="function"?e.read:(function(u){function c(s,a,d,p,h,A){var k;if(A&&typeof A=="function"){var I=0;k=function(Te,lt,at){if(Te&&Te.code==="EAGAIN"&&I<10)return I++,u.call(e,s,a,d,p,h,k);A.apply(this,arguments)}}return u.call(e,s,a,d,p,h,k)}return Object.setPrototypeOf&&Object.setPrototypeOf(c,u),c})(e.read),e.readSync=typeof e.readSync!="function"?e.readSync:(function(u){return function(c,s,a,d,p){for(var h=0;;)try{return u.call(e,c,s,a,d,p)}catch(A){if(A.code==="EAGAIN"&&h<10){h++;continue}throw A}}})(e.readSync);function t(u){u.lchmod=function(c,s,a){u.open(c,K.O_WRONLY|K.O_SYMLINK,s,function(d,p){if(d){a&&a(d);return}u.fchmod(p,s,function(h){u.close(p,function(A){a&&a(h||A)})})})},u.lchmodSync=function(c,s){var a=u.openSync(c,K.O_WRONLY|K.O_SYMLINK,s),d=!0,p;try{p=u.fchmodSync(a,s),d=!1}finally{if(d)try{u.closeSync(a)}catch{}else u.closeSync(a)}return p}}function r(u){K.hasOwnProperty("O_SYMLINK")&&u.futimes?(u.lutimes=function(c,s,a,d){u.open(c,K.O_SYMLINK,function(p,h){if(p){d&&d(p);return}u.futimes(h,s,a,function(A){u.close(h,function(k){d&&d(A||k)})})})},u.lutimesSync=function(c,s,a){var d=u.openSync(c,K.O_SYMLINK),p,h=!0;try{p=u.futimesSync(d,s,a),h=!1}finally{if(h)try{u.closeSync(d)}catch{}else u.closeSync(d)}return p}):u.futimes&&(u.lutimes=function(c,s,a,d){d&&process.nextTick(d)},u.lutimesSync=function(){})}function n(u){return u&&function(c,s,a){return u.call(e,c,s,function(d){_(d)&&(d=null),a&&a.apply(this,arguments)})}}function i(u){return u&&function(c,s){try{return u.call(e,c,s)}catch(a){if(!_(a))throw a}}}function o(u){return u&&function(c,s,a,d){return u.call(e,c,s,a,function(p){_(p)&&(p=null),d&&d.apply(this,arguments)})}}function l(u){return u&&function(c,s,a){try{return u.call(e,c,s,a)}catch(d){if(!_(d))throw d}}}function f(u){return u&&function(c,s,a){typeof s=="function"&&(a=s,s=null);function d(p,h){h&&(h.uid<0&&(h.uid+=4294967296),h.gid<0&&(h.gid+=4294967296)),a&&a.apply(this,arguments)}return s?u.call(e,c,s,d):u.call(e,c,d)}}function m(u){return u&&function(c,s){var a=s?u.call(e,c,s):u.call(e,c);return a&&(a.uid<0&&(a.uid+=4294967296),a.gid<0&&(a.gid+=4294967296)),a}}function _(u){if(!u||u.code==="ENOSYS")return!0;var c=!process.getuid||process.getuid()!==0;return!!(c&&(u.code==="EINVAL"||u.code==="EPERM"))}}});var Yt=j((bi,Zt)=>{var Kt=W("stream").Stream;Zt.exports=Cn;function Cn(e){return{ReadStream:t,WriteStream:r};function t(n,i){if(!(this instanceof t))return new t(n,i);Kt.call(this);var o=this;this.path=n,this.fd=null,this.readable=!0,this.paused=!1,this.flags="r",this.mode=438,this.bufferSize=64*1024,i=i||{};for(var l=Object.keys(i),f=0,m=l.length;f<m;f++){var _=l[f];this[_]=i[_]}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(u,c){if(u){o.emit("error",u),o.readable=!1;return}o.fd=c,o.emit("open",c),o._read()})}function r(n,i){if(!(this instanceof r))return new r(n,i);Kt.call(this),this.path=n,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),l=0,f=o.length;l<f;l++){var m=o[l];this[m]=i[m]}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 Qt=j((Ni,Xt)=>{"use strict";Xt.exports=Nn;var bn=Object.getPrototypeOf||function(e){return e.__proto__};function Nn(e){if(e===null||typeof e!="object")return e;if(e instanceof Object)var t={__proto__:bn(e)};else var t=Object.create(null);return Object.getOwnPropertyNames(e).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))}),t}});var Ze=j((Pi,Ke)=>{var S=W("fs"),Pn=Jt(),Fn=Yt(),Mn=Qt(),Ce=W("util"),M,Ne;typeof Symbol=="function"&&typeof Symbol.for=="function"?(M=Symbol.for("graceful-fs.queue"),Ne=Symbol.for("graceful-fs.previous")):(M="___graceful-fs.queue",Ne="___graceful-fs.previous");function In(){}function rr(e,t){Object.defineProperty(e,M,{get:function(){return t}})}var ee=In;Ce.debuglog?ee=Ce.debuglog("gfs4"):/\bgfs4\b/i.test(process.env.NODE_DEBUG||"")&&(ee=function(){var e=Ce.format.apply(Ce,arguments);e="GFS4: "+e.split(/\n/).join(`
4
- GFS4: `),console.error(e)});S[M]||(er=global[M]||[],rr(S,er),S.close=(function(e){function t(r,n){return e.call(S,r,function(i){i||tr(),typeof n=="function"&&n.apply(this,arguments)})}return Object.defineProperty(t,Ne,{value:e}),t})(S.close),S.closeSync=(function(e){function t(r){e.apply(S,arguments),tr()}return Object.defineProperty(t,Ne,{value:e}),t})(S.closeSync),/\bgfs4\b/i.test(process.env.NODE_DEBUG||"")&&process.on("exit",function(){ee(S[M]),W("assert").equal(S[M].length,0)}));var er;global[M]||rr(global,S[M]);Ke.exports=qe(Mn(S));process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH&&!S.__patched&&(Ke.exports=qe(S),S.__patched=!0);function qe(e){Pn(e),e.gracefulify=qe,e.createReadStream=lt,e.createWriteStream=at;var t=e.readFile;e.readFile=r;function r(T,E,y){return typeof E=="function"&&(y=E,E=null),N(T,E,y);function N(P,C,G,g){return t(P,C,function(x){x&&(x.code==="EMFILE"||x.code==="ENFILE")?se([N,[P,C,G],x,g||Date.now(),Date.now()]):typeof G=="function"&&G.apply(this,arguments)})}}var n=e.writeFile;e.writeFile=i;function i(T,E,y,N){return typeof y=="function"&&(N=y,y=null),P(T,E,y,N);function P(C,G,g,x,F){return n(C,G,g,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?se([P,[C,G,g,x],O,F||Date.now(),Date.now()]):typeof x=="function"&&x.apply(this,arguments)})}}var o=e.appendFile;o&&(e.appendFile=l);function l(T,E,y,N){return typeof y=="function"&&(N=y,y=null),P(T,E,y,N);function P(C,G,g,x,F){return o(C,G,g,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?se([P,[C,G,g,x],O,F||Date.now(),Date.now()]):typeof x=="function"&&x.apply(this,arguments)})}}var f=e.copyFile;f&&(e.copyFile=m);function m(T,E,y,N){return typeof y=="function"&&(N=y,y=0),P(T,E,y,N);function P(C,G,g,x,F){return f(C,G,g,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?se([P,[C,G,g,x],O,F||Date.now(),Date.now()]):typeof x=="function"&&x.apply(this,arguments)})}}var _=e.readdir;e.readdir=c;var u=/^v[0-5]\./;function c(T,E,y){typeof E=="function"&&(y=E,E=null);var N=u.test(process.version)?function(G,g,x,F){return _(G,P(G,g,x,F))}:function(G,g,x,F){return _(G,g,P(G,g,x,F))};return N(T,E,y);function P(C,G,g,x){return function(F,O){F&&(F.code==="EMFILE"||F.code==="ENFILE")?se([N,[C,G,g],F,x||Date.now(),Date.now()]):(O&&O.sort&&O.sort(),typeof g=="function"&&g.call(this,F,O))}}}if(process.version.substr(0,4)==="v0.8"){var s=Fn(e);A=s.ReadStream,I=s.WriteStream}var a=e.ReadStream;a&&(A.prototype=Object.create(a.prototype),A.prototype.open=k);var d=e.WriteStream;d&&(I.prototype=Object.create(d.prototype),I.prototype.open=Te),Object.defineProperty(e,"ReadStream",{get:function(){return A},set:function(T){A=T},enumerable:!0,configurable:!0}),Object.defineProperty(e,"WriteStream",{get:function(){return I},set:function(T){I=T},enumerable:!0,configurable:!0});var p=A;Object.defineProperty(e,"FileReadStream",{get:function(){return p},set:function(T){p=T},enumerable:!0,configurable:!0});var h=I;Object.defineProperty(e,"FileWriteStream",{get:function(){return h},set:function(T){h=T},enumerable:!0,configurable:!0});function A(T,E){return this instanceof A?(a.apply(this,arguments),this):A.apply(Object.create(A.prototype),arguments)}function k(){var T=this;De(T.path,T.flags,T.mode,function(E,y){E?(T.autoClose&&T.destroy(),T.emit("error",E)):(T.fd=y,T.emit("open",y),T.read())})}function I(T,E){return this instanceof I?(d.apply(this,arguments),this):I.apply(Object.create(I.prototype),arguments)}function Te(){var T=this;De(T.path,T.flags,T.mode,function(E,y){E?(T.destroy(),T.emit("error",E)):(T.fd=y,T.emit("open",y))})}function lt(T,E){return new e.ReadStream(T,E)}function at(T,E){return new e.WriteStream(T,E)}var Lr=e.open;e.open=De;function De(T,E,y,N){return typeof y=="function"&&(N=y,y=null),P(T,E,y,N);function P(C,G,g,x,F){return Lr(C,G,g,function(O,yi){O&&(O.code==="EMFILE"||O.code==="ENFILE")?se([P,[C,G,g,x],O,F||Date.now(),Date.now()]):typeof x=="function"&&x.apply(this,arguments)})}}return e}function se(e){ee("ENQUEUE",e[0].name,e[1]),S[M].push(e),Je()}var be;function tr(){for(var e=Date.now(),t=0;t<S[M].length;++t)S[M][t].length>2&&(S[M][t][3]=e,S[M][t][4]=e);Je()}function Je(){if(clearTimeout(be),be=void 0,S[M].length!==0){var e=S[M].shift(),t=e[0],r=e[1],n=e[2],i=e[3],o=e[4];if(i===void 0)ee("RETRY",t.name,r),t.apply(null,r);else if(Date.now()-i>=6e4){ee("TIMEOUT",t.name,r);var l=r.pop();typeof l=="function"&&l.call(null,n)}else{var f=Date.now()-o,m=Math.max(o-i,1),_=Math.min(m*1.2,100);f>=_?(ee("RETRY",t.name,r),t.apply(null,r.concat([i]))):S[M].push(e)}be===void 0&&(be=setTimeout(Je,0))}}});var ir=j((Fi,nr)=>{function R(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))}nr.exports=R;R.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts};R.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timeouts=[],this._cachedTimeouts=null};R.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 r=this._timeouts.shift();if(r===void 0)if(this._cachedTimeouts)this._errors.splice(this._errors.length-1,this._errors.length),this._timeouts=this._cachedTimeouts.slice(0),r=this._timeouts.shift();else return!1;var n=this,i=setTimeout(function(){n._attempts++,n._operationTimeoutCb&&(n._timeout=setTimeout(function(){n._operationTimeoutCb(n._attempts)},n._operationTimeout),n._options.unref&&n._timeout.unref()),n._fn(n._attempts)},r);return this._options.unref&&i.unref(),!0};R.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var r=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){r._operationTimeoutCb()},r._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)};R.prototype.try=function(e){console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)};R.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)};R.prototype.start=R.prototype.try;R.prototype.errors=function(){return this._errors};R.prototype.attempts=function(){return this._attempts};R.prototype.mainError=function(){if(this._errors.length===0)return null;for(var e={},t=null,r=0,n=0;n<this._errors.length;n++){var i=this._errors[n],o=i.message,l=(e[o]||0)+1;e[o]=l,l>=r&&(t=i,r=l)}return t}});var or=j(te=>{var Ln=ir();te.operation=function(e){var t=te.timeouts(e);return new Ln(t,{forever:e&&e.forever,unref:e&&e.unref,maxRetryTime:e&&e.maxRetryTime})};te.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 r in e)t[r]=e[r];if(t.minTimeout>t.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var n=[],i=0;i<t.retries;i++)n.push(this.createTimeout(i,t));return e&&e.forever&&!n.length&&n.push(this.createTimeout(i,t)),n.sort(function(o,l){return o-l}),n};te.createTimeout=function(e,t){var r=t.randomize?Math.random()+1:1,n=Math.round(r*t.minTimeout*Math.pow(t.factor,e));return n=Math.min(n,t.maxTimeout),n};te.wrap=function(e,t,r){if(t instanceof Array&&(r=t,t=null),!r){r=[];for(var n in e)typeof e[n]=="function"&&r.push(n)}for(var i=0;i<r.length;i++){var o=r[i],l=e[o];e[o]=function(m){var _=te.operation(t),u=Array.prototype.slice.call(arguments,1),c=u.pop();u.push(function(s){_.retry(s)||(s&&(arguments[0]=_.mainError()),c.apply(this,arguments))}),_.attempt(function(){m.apply(e,u)})}.bind(e,l),e[o].options=t}}});var lr=j((Ii,ur)=>{ur.exports=or()});var ar=j((Li,Pe)=>{Pe.exports=["SIGABRT","SIGALRM","SIGHUP","SIGINT","SIGTERM"];process.platform!=="win32"&&Pe.exports.push("SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");process.platform==="linux"&&Pe.exports.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT","SIGUNUSED")});var mr=j((ji,me)=>{var v=global.process,re=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"};re(v)?(cr=W("assert"),de=ar(),sr=/^win/i.test(v.platform),ve=W("events"),typeof ve!="function"&&(ve=ve.EventEmitter),v.__signal_exit_emitter__?b=v.__signal_exit_emitter__:(b=v.__signal_exit_emitter__=new ve,b.count=0,b.emitted={}),b.infinite||(b.setMaxListeners(1/0),b.infinite=!0),me.exports=function(e,t){if(!re(global.process))return function(){};cr.equal(typeof e,"function","a callback must be provided for exit handler"),fe===!1&&Ye();var r="exit";t&&t.alwaysLast&&(r="afterexit");var n=function(){b.removeListener(r,e),b.listeners("exit").length===0&&b.listeners("afterexit").length===0&&Fe()};return b.on(r,e),n},Fe=function(){!fe||!re(global.process)||(fe=!1,de.forEach(function(t){try{v.removeListener(t,Me[t])}catch{}}),v.emit=Ie,v.reallyExit=Xe,b.count-=1)},me.exports.unload=Fe,ne=function(t,r,n){b.emitted[t]||(b.emitted[t]=!0,b.emit(t,r,n))},Me={},de.forEach(function(e){Me[e]=function(){if(re(global.process)){var r=v.listeners(e);r.length===b.count&&(Fe(),ne("exit",null,e),ne("afterexit",null,e),sr&&e==="SIGHUP"&&(e="SIGINT"),v.kill(v.pid,e))}}}),me.exports.signals=function(){return de},fe=!1,Ye=function(){fe||!re(global.process)||(fe=!0,b.count+=1,de=de.filter(function(t){try{return v.on(t,Me[t]),!0}catch{return!1}}),v.emit=fr,v.reallyExit=dr)},me.exports.load=Ye,Xe=v.reallyExit,dr=function(t){re(global.process)&&(v.exitCode=t||0,ne("exit",v.exitCode,null),ne("afterexit",v.exitCode,null),Xe.call(v,v.exitCode))},Ie=v.emit,fr=function(t,r){if(t==="exit"&&re(global.process)){r!==void 0&&(v.exitCode=r);var n=Ie.apply(this,arguments);return ne("exit",v.exitCode,null),ne("afterexit",v.exitCode,null),n}else return Ie.apply(this,arguments)}):me.exports=function(){return function(){}};var cr,de,sr,ve,b,Fe,ne,Me,fe,Ye,Xe,dr,Ie,fr});var yr=j((Ri,Ge)=>{"use strict";var jn=W("path"),tt=Ze(),Rn=lr(),Dn=mr(),H={};function pe(e,t){return t.lockfilePath||`${e}.lock`}function rt(e,t,r){if(!t.realpath)return r(null,jn.resolve(e));t.fs.realpath(e,r)}function Qe(e,t,r){t.fs.mkdir(pe(e,t),n=>{if(!n)return r();if(n.code!=="EEXIST")return r(n);if(t.stale<=0)return r(Object.assign(new Error("Lock file is already being hold"),{code:"ELOCKED",file:e}));t.fs.stat(pe(e,t),(i,o)=>{if(i)return i.code==="ENOENT"?Qe(e,{...t,stale:0},r):r(i);if(!_r(o,t))return r(Object.assign(new Error("Lock file is already being hold"),{code:"ELOCKED",file:e}));hr(e,t,l=>{if(l)return r(l);Qe(e,{...t,stale:0},r)})})})}function _r(e,t){return e.mtime.getTime()<Date.now()-t.stale}function hr(e,t,r){t.fs.rmdir(pe(e,t),n=>{if(n&&n.code!=="ENOENT")return r(n);r()})}function et(e,t){let r=H[e];r.updateTimeout||(r.updateDelay=r.updateDelay||t.update,r.updateTimeout=setTimeout(()=>{let n=Date.now()/1e3;r.updateTimeout=null,t.fs.utimes(pe(e,t),n,n,i=>{if(!r.released){if(r.lastUpdate<=Date.now()-t.stale&&r.lastUpdate>Date.now()-t.stale*2){let o=Object.assign(new Error(r.updateError||"Unable to update lock within the stale threshold"),{code:"ECOMPROMISED"});return pr(e,r,o)}if(i)return i.code==="ENOENT"?pr(e,r,Object.assign(i,{code:"ECOMPROMISED"})):(r.updateError=i,r.updateDelay=1e3,et(e,t));r.lastUpdate=Date.now(),r.updateError=null,r.updateDelay=null,et(e,t)}})},r.updateDelay),r.updateTimeout.unref&&r.updateTimeout.unref())}function pr(e,t,r){t.released=!0,t.updateTimeout&&clearTimeout(t.updateTimeout),H[e]===t&&delete H[e],t.options.onCompromised(r)}function $n(e,t,r){t={stale:1e4,update:null,realpath:!0,retries:0,fs:tt,onCompromised:n=>{throw n},...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),rt(e,t,(n,i)=>{if(n)return r(n);let o=Rn.operation(t.retries);o.attempt(()=>{Qe(i,t,l=>{if(o.retry(l))return;if(l)return r(o.mainError());let f=H[i]={options:t,lastUpdate:Date.now()};et(i,t),r(null,m=>{if(f.released)return m&&m(Object.assign(new Error("Lock is already released"),{code:"ERELEASED"}));Tr(i,{...t,realpath:!1},m)})})})})}function Tr(e,t,r){t={fs:tt,realpath:!0,...t},rt(e,t,(n,i)=>{if(n)return r(n);let o=H[i];if(!o)return r(Object.assign(new Error("Lock is not acquired/owned by you"),{code:"ENOTACQUIRED"}));o.updateTimeout&&clearTimeout(o.updateTimeout),o.released=!0,delete H[i],hr(i,t,r)})}function Un(e,t,r){t={stale:1e4,realpath:!0,fs:tt,...t},t.stale=Math.max(t.stale||0,2e3),rt(e,t,(n,i)=>{if(n)return r(n);t.fs.stat(pe(i,t),(o,l)=>o?o.code==="ENOENT"?r(null,!1):r(o):r(null,!_r(l,t)))})}function Vn(){return H}Dn(()=>{for(let e in H){let t=H[e].options;try{t.fs.rmdirSync(pe(e,t))}catch{}}});Ge.exports.lock=$n;Ge.exports.unlock=Tr;Ge.exports.check=Un;Ge.exports.getLocks=Vn});var Ar=j((Di,Er)=>{"use strict";var zn=Ze();function Bn(e){let t=["mkdir","realpath","stat","rmdir","utimes"],r={...e};return t.forEach(n=>{r[n]=(...i)=>{let o=i.pop(),l;try{l=e[`${n}Sync`](...i)}catch(f){return o(f)}o(null,l)}}),r}function Hn(e){return(...t)=>new Promise((r,n)=>{t.push((i,o)=>{i?n(i):r(o)}),e(...t)})}function Wn(e){return(...t)=>{let r,n;if(t.push((i,o)=>{r=i,n=o}),e(...t),r)throw r;return n}}function qn(e){if(e={...e},e.fs=Bn(e.fs||zn),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}Er.exports={toPromise:Hn,toSync:Wn,toSyncOptions:qn}});var Or=j(($i,Z)=>{"use strict";var _e=yr(),{toPromise:Le,toSync:je,toSyncOptions:nt}=Ar();async function xr(e,t){let r=await Le(_e.lock)(e,t);return Le(r)}function Jn(e,t){let r=je(_e.lock)(e,nt(t));return je(r)}function Kn(e,t){return Le(_e.unlock)(e,t)}function Zn(e,t){return je(_e.unlock)(e,nt(t))}function Yn(e,t){return Le(_e.check)(e,t)}function Xn(e,t){return je(_e.check)(e,nt(t))}Z.exports=xr;Z.exports.lock=xr;Z.exports.unlock=Kn;Z.exports.lockSync=Jn;Z.exports.unlockSync=Zn;Z.exports.check=Yn;Z.exports.checkSync=Xn});import*as ot from"node:url";import*as Cr from"node:path";function ie(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 $e(e){if(e!=null)return ie(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}}function ye(e,t){if(e!==void 0&&t(L(e)))return e}function dt(e,t){if(e!==void 0)return t(L(e))}function V(e,t,r){return e!==void 0?r(L(e)):t}function $(e,t){if(e!==void 0)return ie(t(L(e)))}function ue(e,t){if(e!==void 0)return t(L(e))}function D(e,t){return e!==void 0?L(e):t}function ft(e,t){return e.TAG==="Ok"?e:{TAG:"Error",_0:t(e._0)}}var _t=(function(e,t){for(var r in e)t(r)});function le(e,t){if(e===t)return!0;let r=typeof e;if(r==="string"||r==="number"||r==="bigint"||r==="boolean"||r==="undefined"||e===null)return!1;let n=typeof t;if(r==="function"||n==="function")throw{RE_EXN_ID:"Invalid_argument",_1:"equal: functional value",Error:new Error};if(n==="number"||n==="bigint"||n==="undefined"||t===null)return!1;let i=e.TAG,o=t.TAG;if(i!==o)return!1;let l=e.length|0,f=t.length|0;if(l===f)if(Array.isArray(e)){let m=0;for(;;){let _=m;if(_===l)return!0;if(!le(e[_],t[_]))return!1;m=_+1|0}}else{if(e instanceof Date&&t instanceof Date)return!(e>t||e<t);{let m={contents:!0},_=c=>{if(!Object.prototype.hasOwnProperty.call(t,c)){m.contents=!1;return}},u=c=>{if(!Object.prototype.hasOwnProperty.call(e,c)||!le(t[c],e[c])){m.contents=!1;return}};return _t(e,_),m.contents&&_t(t,u),m.contents}}else return!1}function X(e,t){return(typeof e=="number"||typeof e=="bigint")&&(typeof t=="number"||typeof t=="bigint")?e!==t:!le(e,t)}import*as br from"node:fs/promises";function Jr(e){return e==null?!1:typeof e.RE_EXN_ID=="string"}function U(e){return Jr(e)?e:{RE_EXN_ID:"JsExn",_1:e}}var ht={name:"@linzumi/cli",version:"1.0.324",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","native/darwin/linzumi-terminal-pty-helper","native/darwin/terminal-pty-helper.manifest.json"],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 && npm run codex-protocol:declarations && 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","codex-protocol:declarations":"node ../linzumi-cli-rescript/scripts/CodexProtocolGenerate.res.mjs --repo-root ../.. --declarations-out packages/linzumi-cli/.generated/codex-app-server-protocol.d.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 && npm run codex-protocol:declarations && tsgo --noEmit -p tsconfig.json","typecheck:watch":"rescript build ../linzumi-cli-rescript && npm run codex-protocol:declarations && 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"},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","ghostty-web":"0.4.0","proper-lockfile":"3.2.0","stream-json":"1.9.1",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 Zr=ht,Ue=Zr.dependencies["@openai/codex"];function xe(e){if(e.RE_EXN_ID==="JsExn")return ie(e._1)}var Se=(e=>t=>t&&typeof t[e]=="string"?t[e]:void 0),Gi=Se("stack"),ge=Se("message"),Tt=Se("name"),Si=Se("fileName");var Xr=new RegExp("\\bsmk_[A-Za-z0-9._-]+","g");function w(e){return e.replace(Xr,"smk_[REDACTED]")}var Qr="https://api.smolmachines.com";function ze(e){return e.TAG==="Smolcloud"?e.message:e._0}function q(e){let t=xe(e);if(t===void 0)return"unknown error";let r=L(t);return D(ge(r),String(r))}function At(e){let t=xe(e);return t!==void 0?le(Tt(L(t)),"AbortError"):!1}var en=new RegExp("\\/+$");function Et(e,t){let r=e[t];if(r===void 0)return;let n=r.trim();if(n!=="")return n}function Be(e){let t=Et(e,"SMOLCLOUD_API_KEY");return $(t!==void 0?t:Et(e,"SMOL_CLOUD_TOKEN"),r=>({baseUrl:D(e.SMOLCLOUD_BASE_URL,Qr).replace(en,""),apiKey:r}))}async function we(e,t){try{return{TAG:"Ok",_0:await fetch(e,t)}}catch(r){return{TAG:"Error",_0:U(r)}}}async function xt(e){try{return await e.text()}catch{return""}}function Ot(e,t){return t===""?e.toString():e.toString()+": "+t}async function Q(e,t,r,n,i){let o=n!==void 0?n:"NoBody",l=i!==void 0?i:3e4,f=Object.fromEntries([["authorization","Bearer "+e.apiKey]]),m=new AbortController,_=setTimeout(()=>{m.abort()},l),u=e.baseUrl+r,c=m.signal,s;if(typeof o!="object"?s=await we(u,{method:t,headers:f,body:null,signal:c}):o.TAG==="JsonBody"?(f["content-type"]="application/json",s=await we(u,{method:t,headers:f,body:JSON.stringify(o._0),signal:c})):(f["content-type"]="application/octet-stream",s=await we(u,{method:t,headers:f,body:o._0,signal:c})),clearTimeout(_),s.TAG==="Ok"){let a=s._0;if(a.ok){if(a.status===204)return{TAG:"Ok",_0:"NoPayload"};if(!D($e(a.headers.get("content-type")),"").includes("application/json"))return{TAG:"Ok",_0:"NoPayload"};try{return{TAG:"Ok",_0:{TAG:"Payload",_0:await a.json()}}}catch(d){let p=U(d);return{TAG:"Error",_0:{TAG:"Thrown",_0:q(p)}}}}else{let d=a.status,p=await xt(a),h;if(d>=402)if(d>=405)h="CloudError";else switch(d){case 402:h="CloudError";break;case 403:h="Unauthorized";break;case 404:h="NotFound";break}else h=d>=401?"Unauthorized":"CloudError";let A="smolcloud "+t+" "+r+" \u2192 "+Ot(d,p);return{TAG:"Error",_0:{TAG:"Smolcloud",code:h,message:w(A)}}}}else{let a=s._0;if(At(a)){let p="smolcloud "+t+" "+r+" timed out after "+l.toString()+"ms";return{TAG:"Error",_0:{TAG:"Smolcloud",code:"Timeout",message:w(p)}}}let d="smolcloud request failed: "+q(a);return{TAG:"Error",_0:{TAG:"Smolcloud",code:"ConnectionFailed",message:w(d)}}}}function ce(e){return"/v1/machines/"+e.id}function ae(e,t){let r=e[t];if(typeof r=="string")return r}function tn(e,t){if(typeof t=="object"){let r=t._0;if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let n=r.id,i;i=n!=null?typeof n=="string"?n:void 0:e.id;let o=r.env,l;return l=typeof o=="object"&&o!==null&&!Array.isArray(o)?ae(o,"LINZUMI_ROLE"):void 0,{id:i,name:ae(r,"name"),role:l}}}return{id:e.id,name:void 0,role:void 0}}async function vt(e){let t=await Q(e.conn,"GET",ce(e),void 0,void 0);return t.TAG==="Ok"?{TAG:"Ok",_0:tn(e,t._0)}:{TAG:"Error",_0:t._0}}function z(e){return e.TAG==="Numeric"?e._0===0:!1}function Gt(e){return e.TAG==="Numeric"?e._0.toString():String(e._0)}function St(e,t){return Object.fromEntries([["command",e.map(r=>r)],["env",Object.fromEntries(D(t.env,[]).map(r=>[r[0],r[1]]))],["cwd",null],["stdin",V(t.stdin,null,r=>r)],["timeoutSeconds",V(t.timeout,null,r=>r)]])}function gt(e){return e!==void 0?e===null?{TAG:"Numeric",_0:0}:typeof e=="number"?{TAG:"Numeric",_0:e}:{TAG:"NonNumeric",_0:e}:{TAG:"Numeric",_0:0}}function rn(e){if(typeof e!="object")return{TAG:"Error",_0:{TAG:"Thrown",_0:"Cannot read properties of undefined (reading 'exitCode')"}};let t=e._0;return t===null?{TAG:"Error",_0:{TAG:"Thrown",_0:"Cannot read properties of null (reading 'exitCode')"}}:typeof t=="object"&&!Array.isArray(t)?{TAG:"Ok",_0:{exitCode:gt(t.exitCode),stdout:D(ae(t,"stdout"),""),stderr:D(ae(t,"stderr"),"")}}:{TAG:"Ok",_0:{exitCode:{TAG:"Numeric",_0:0},stdout:"",stderr:""}}}async function B(e,t,r){let n=r!==void 0?r:{},i=n.timeout,o=i!==void 0?Math.max(3e4,(i*1e3|0)+3e4|0):3e4,l=await Q(e.conn,"POST",ce(e)+"/exec",{TAG:"JsonBody",_0:St(t,n)},o);return l.TAG==="Ok"?rn(l._0):{TAG:"Error",_0:l._0}}function nn(e){let t;try{t=JSON.parse(e)}catch{t=void 0}return t!==void 0?typeof t=="object"&&t!==null&&!Array.isArray(t)?gt(t.exitCode):{TAG:"Numeric",_0:0}:{TAG:"Numeric",_0:0}}function on(e,t){switch(e){case"error":return{TAG:"StreamError",_0:w(t)};case"exit":return{TAG:"Exit",_0:nn(t)};case"stderr":return{TAG:"Stderr",_0:t};case"stdout":return{TAG:"Stdout",_0:t};default:return}}var un=new RegExp("^ ");async function ln(e,t){let r=e.getReader(),n=new TextDecoder,i={contents:""},o={contents:""},l={contents:[]},f=()=>{let c=o.contents,s=l.contents.join(`
4
+ GFS4: `),console.error(e)});S[M]||(er=global[M]||[],rr(S,er),S.close=(function(e){function t(r,n){return e.call(S,r,function(i){i||tr(),typeof n=="function"&&n.apply(this,arguments)})}return Object.defineProperty(t,Ne,{value:e}),t})(S.close),S.closeSync=(function(e){function t(r){e.apply(S,arguments),tr()}return Object.defineProperty(t,Ne,{value:e}),t})(S.closeSync),/\bgfs4\b/i.test(process.env.NODE_DEBUG||"")&&process.on("exit",function(){ee(S[M]),W("assert").equal(S[M].length,0)}));var er;global[M]||rr(global,S[M]);Ke.exports=qe(Mn(S));process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH&&!S.__patched&&(Ke.exports=qe(S),S.__patched=!0);function qe(e){Pn(e),e.gracefulify=qe,e.createReadStream=lt,e.createWriteStream=at;var t=e.readFile;e.readFile=r;function r(T,E,y){return typeof E=="function"&&(y=E,E=null),N(T,E,y);function N(P,C,G,g){return t(P,C,function(x){x&&(x.code==="EMFILE"||x.code==="ENFILE")?se([N,[P,C,G],x,g||Date.now(),Date.now()]):typeof G=="function"&&G.apply(this,arguments)})}}var n=e.writeFile;e.writeFile=i;function i(T,E,y,N){return typeof y=="function"&&(N=y,y=null),P(T,E,y,N);function P(C,G,g,x,F){return n(C,G,g,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?se([P,[C,G,g,x],O,F||Date.now(),Date.now()]):typeof x=="function"&&x.apply(this,arguments)})}}var o=e.appendFile;o&&(e.appendFile=l);function l(T,E,y,N){return typeof y=="function"&&(N=y,y=null),P(T,E,y,N);function P(C,G,g,x,F){return o(C,G,g,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?se([P,[C,G,g,x],O,F||Date.now(),Date.now()]):typeof x=="function"&&x.apply(this,arguments)})}}var f=e.copyFile;f&&(e.copyFile=m);function m(T,E,y,N){return typeof y=="function"&&(N=y,y=0),P(T,E,y,N);function P(C,G,g,x,F){return f(C,G,g,function(O){O&&(O.code==="EMFILE"||O.code==="ENFILE")?se([P,[C,G,g,x],O,F||Date.now(),Date.now()]):typeof x=="function"&&x.apply(this,arguments)})}}var _=e.readdir;e.readdir=c;var u=/^v[0-5]\./;function c(T,E,y){typeof E=="function"&&(y=E,E=null);var N=u.test(process.version)?function(G,g,x,F){return _(G,P(G,g,x,F))}:function(G,g,x,F){return _(G,g,P(G,g,x,F))};return N(T,E,y);function P(C,G,g,x){return function(F,O){F&&(F.code==="EMFILE"||F.code==="ENFILE")?se([N,[C,G,g],F,x||Date.now(),Date.now()]):(O&&O.sort&&O.sort(),typeof g=="function"&&g.call(this,F,O))}}}if(process.version.substr(0,4)==="v0.8"){var s=Fn(e);A=s.ReadStream,I=s.WriteStream}var a=e.ReadStream;a&&(A.prototype=Object.create(a.prototype),A.prototype.open=k);var d=e.WriteStream;d&&(I.prototype=Object.create(d.prototype),I.prototype.open=Te),Object.defineProperty(e,"ReadStream",{get:function(){return A},set:function(T){A=T},enumerable:!0,configurable:!0}),Object.defineProperty(e,"WriteStream",{get:function(){return I},set:function(T){I=T},enumerable:!0,configurable:!0});var p=A;Object.defineProperty(e,"FileReadStream",{get:function(){return p},set:function(T){p=T},enumerable:!0,configurable:!0});var h=I;Object.defineProperty(e,"FileWriteStream",{get:function(){return h},set:function(T){h=T},enumerable:!0,configurable:!0});function A(T,E){return this instanceof A?(a.apply(this,arguments),this):A.apply(Object.create(A.prototype),arguments)}function k(){var T=this;De(T.path,T.flags,T.mode,function(E,y){E?(T.autoClose&&T.destroy(),T.emit("error",E)):(T.fd=y,T.emit("open",y),T.read())})}function I(T,E){return this instanceof I?(d.apply(this,arguments),this):I.apply(Object.create(I.prototype),arguments)}function Te(){var T=this;De(T.path,T.flags,T.mode,function(E,y){E?(T.destroy(),T.emit("error",E)):(T.fd=y,T.emit("open",y))})}function lt(T,E){return new e.ReadStream(T,E)}function at(T,E){return new e.WriteStream(T,E)}var Lr=e.open;e.open=De;function De(T,E,y,N){return typeof y=="function"&&(N=y,y=null),P(T,E,y,N);function P(C,G,g,x,F){return Lr(C,G,g,function(O,yi){O&&(O.code==="EMFILE"||O.code==="ENFILE")?se([P,[C,G,g,x],O,F||Date.now(),Date.now()]):typeof x=="function"&&x.apply(this,arguments)})}}return e}function se(e){ee("ENQUEUE",e[0].name,e[1]),S[M].push(e),Je()}var be;function tr(){for(var e=Date.now(),t=0;t<S[M].length;++t)S[M][t].length>2&&(S[M][t][3]=e,S[M][t][4]=e);Je()}function Je(){if(clearTimeout(be),be=void 0,S[M].length!==0){var e=S[M].shift(),t=e[0],r=e[1],n=e[2],i=e[3],o=e[4];if(i===void 0)ee("RETRY",t.name,r),t.apply(null,r);else if(Date.now()-i>=6e4){ee("TIMEOUT",t.name,r);var l=r.pop();typeof l=="function"&&l.call(null,n)}else{var f=Date.now()-o,m=Math.max(o-i,1),_=Math.min(m*1.2,100);f>=_?(ee("RETRY",t.name,r),t.apply(null,r.concat([i]))):S[M].push(e)}be===void 0&&(be=setTimeout(Je,0))}}});var ir=j((Fi,nr)=>{function R(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))}nr.exports=R;R.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts};R.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timeouts=[],this._cachedTimeouts=null};R.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 r=this._timeouts.shift();if(r===void 0)if(this._cachedTimeouts)this._errors.splice(this._errors.length-1,this._errors.length),this._timeouts=this._cachedTimeouts.slice(0),r=this._timeouts.shift();else return!1;var n=this,i=setTimeout(function(){n._attempts++,n._operationTimeoutCb&&(n._timeout=setTimeout(function(){n._operationTimeoutCb(n._attempts)},n._operationTimeout),n._options.unref&&n._timeout.unref()),n._fn(n._attempts)},r);return this._options.unref&&i.unref(),!0};R.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var r=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){r._operationTimeoutCb()},r._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)};R.prototype.try=function(e){console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)};R.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)};R.prototype.start=R.prototype.try;R.prototype.errors=function(){return this._errors};R.prototype.attempts=function(){return this._attempts};R.prototype.mainError=function(){if(this._errors.length===0)return null;for(var e={},t=null,r=0,n=0;n<this._errors.length;n++){var i=this._errors[n],o=i.message,l=(e[o]||0)+1;e[o]=l,l>=r&&(t=i,r=l)}return t}});var or=j(te=>{var Ln=ir();te.operation=function(e){var t=te.timeouts(e);return new Ln(t,{forever:e&&e.forever,unref:e&&e.unref,maxRetryTime:e&&e.maxRetryTime})};te.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 r in e)t[r]=e[r];if(t.minTimeout>t.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var n=[],i=0;i<t.retries;i++)n.push(this.createTimeout(i,t));return e&&e.forever&&!n.length&&n.push(this.createTimeout(i,t)),n.sort(function(o,l){return o-l}),n};te.createTimeout=function(e,t){var r=t.randomize?Math.random()+1:1,n=Math.round(r*t.minTimeout*Math.pow(t.factor,e));return n=Math.min(n,t.maxTimeout),n};te.wrap=function(e,t,r){if(t instanceof Array&&(r=t,t=null),!r){r=[];for(var n in e)typeof e[n]=="function"&&r.push(n)}for(var i=0;i<r.length;i++){var o=r[i],l=e[o];e[o]=function(m){var _=te.operation(t),u=Array.prototype.slice.call(arguments,1),c=u.pop();u.push(function(s){_.retry(s)||(s&&(arguments[0]=_.mainError()),c.apply(this,arguments))}),_.attempt(function(){m.apply(e,u)})}.bind(e,l),e[o].options=t}}});var lr=j((Ii,ur)=>{ur.exports=or()});var ar=j((Li,Pe)=>{Pe.exports=["SIGABRT","SIGALRM","SIGHUP","SIGINT","SIGTERM"];process.platform!=="win32"&&Pe.exports.push("SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");process.platform==="linux"&&Pe.exports.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT","SIGUNUSED")});var mr=j((ji,me)=>{var v=global.process,re=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"};re(v)?(cr=W("assert"),de=ar(),sr=/^win/i.test(v.platform),ve=W("events"),typeof ve!="function"&&(ve=ve.EventEmitter),v.__signal_exit_emitter__?b=v.__signal_exit_emitter__:(b=v.__signal_exit_emitter__=new ve,b.count=0,b.emitted={}),b.infinite||(b.setMaxListeners(1/0),b.infinite=!0),me.exports=function(e,t){if(!re(global.process))return function(){};cr.equal(typeof e,"function","a callback must be provided for exit handler"),fe===!1&&Ye();var r="exit";t&&t.alwaysLast&&(r="afterexit");var n=function(){b.removeListener(r,e),b.listeners("exit").length===0&&b.listeners("afterexit").length===0&&Fe()};return b.on(r,e),n},Fe=function(){!fe||!re(global.process)||(fe=!1,de.forEach(function(t){try{v.removeListener(t,Me[t])}catch{}}),v.emit=Ie,v.reallyExit=Xe,b.count-=1)},me.exports.unload=Fe,ne=function(t,r,n){b.emitted[t]||(b.emitted[t]=!0,b.emit(t,r,n))},Me={},de.forEach(function(e){Me[e]=function(){if(re(global.process)){var r=v.listeners(e);r.length===b.count&&(Fe(),ne("exit",null,e),ne("afterexit",null,e),sr&&e==="SIGHUP"&&(e="SIGINT"),v.kill(v.pid,e))}}}),me.exports.signals=function(){return de},fe=!1,Ye=function(){fe||!re(global.process)||(fe=!0,b.count+=1,de=de.filter(function(t){try{return v.on(t,Me[t]),!0}catch{return!1}}),v.emit=fr,v.reallyExit=dr)},me.exports.load=Ye,Xe=v.reallyExit,dr=function(t){re(global.process)&&(v.exitCode=t||0,ne("exit",v.exitCode,null),ne("afterexit",v.exitCode,null),Xe.call(v,v.exitCode))},Ie=v.emit,fr=function(t,r){if(t==="exit"&&re(global.process)){r!==void 0&&(v.exitCode=r);var n=Ie.apply(this,arguments);return ne("exit",v.exitCode,null),ne("afterexit",v.exitCode,null),n}else return Ie.apply(this,arguments)}):me.exports=function(){return function(){}};var cr,de,sr,ve,b,Fe,ne,Me,fe,Ye,Xe,dr,Ie,fr});var yr=j((Ri,Ge)=>{"use strict";var jn=W("path"),tt=Ze(),Rn=lr(),Dn=mr(),H={};function pe(e,t){return t.lockfilePath||`${e}.lock`}function rt(e,t,r){if(!t.realpath)return r(null,jn.resolve(e));t.fs.realpath(e,r)}function Qe(e,t,r){t.fs.mkdir(pe(e,t),n=>{if(!n)return r();if(n.code!=="EEXIST")return r(n);if(t.stale<=0)return r(Object.assign(new Error("Lock file is already being hold"),{code:"ELOCKED",file:e}));t.fs.stat(pe(e,t),(i,o)=>{if(i)return i.code==="ENOENT"?Qe(e,{...t,stale:0},r):r(i);if(!_r(o,t))return r(Object.assign(new Error("Lock file is already being hold"),{code:"ELOCKED",file:e}));hr(e,t,l=>{if(l)return r(l);Qe(e,{...t,stale:0},r)})})})}function _r(e,t){return e.mtime.getTime()<Date.now()-t.stale}function hr(e,t,r){t.fs.rmdir(pe(e,t),n=>{if(n&&n.code!=="ENOENT")return r(n);r()})}function et(e,t){let r=H[e];r.updateTimeout||(r.updateDelay=r.updateDelay||t.update,r.updateTimeout=setTimeout(()=>{let n=Date.now()/1e3;r.updateTimeout=null,t.fs.utimes(pe(e,t),n,n,i=>{if(!r.released){if(r.lastUpdate<=Date.now()-t.stale&&r.lastUpdate>Date.now()-t.stale*2){let o=Object.assign(new Error(r.updateError||"Unable to update lock within the stale threshold"),{code:"ECOMPROMISED"});return pr(e,r,o)}if(i)return i.code==="ENOENT"?pr(e,r,Object.assign(i,{code:"ECOMPROMISED"})):(r.updateError=i,r.updateDelay=1e3,et(e,t));r.lastUpdate=Date.now(),r.updateError=null,r.updateDelay=null,et(e,t)}})},r.updateDelay),r.updateTimeout.unref&&r.updateTimeout.unref())}function pr(e,t,r){t.released=!0,t.updateTimeout&&clearTimeout(t.updateTimeout),H[e]===t&&delete H[e],t.options.onCompromised(r)}function $n(e,t,r){t={stale:1e4,update:null,realpath:!0,retries:0,fs:tt,onCompromised:n=>{throw n},...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),rt(e,t,(n,i)=>{if(n)return r(n);let o=Rn.operation(t.retries);o.attempt(()=>{Qe(i,t,l=>{if(o.retry(l))return;if(l)return r(o.mainError());let f=H[i]={options:t,lastUpdate:Date.now()};et(i,t),r(null,m=>{if(f.released)return m&&m(Object.assign(new Error("Lock is already released"),{code:"ERELEASED"}));Tr(i,{...t,realpath:!1},m)})})})})}function Tr(e,t,r){t={fs:tt,realpath:!0,...t},rt(e,t,(n,i)=>{if(n)return r(n);let o=H[i];if(!o)return r(Object.assign(new Error("Lock is not acquired/owned by you"),{code:"ENOTACQUIRED"}));o.updateTimeout&&clearTimeout(o.updateTimeout),o.released=!0,delete H[i],hr(i,t,r)})}function Un(e,t,r){t={stale:1e4,realpath:!0,fs:tt,...t},t.stale=Math.max(t.stale||0,2e3),rt(e,t,(n,i)=>{if(n)return r(n);t.fs.stat(pe(i,t),(o,l)=>o?o.code==="ENOENT"?r(null,!1):r(o):r(null,!_r(l,t)))})}function Vn(){return H}Dn(()=>{for(let e in H){let t=H[e].options;try{t.fs.rmdirSync(pe(e,t))}catch{}}});Ge.exports.lock=$n;Ge.exports.unlock=Tr;Ge.exports.check=Un;Ge.exports.getLocks=Vn});var Ar=j((Di,Er)=>{"use strict";var zn=Ze();function Bn(e){let t=["mkdir","realpath","stat","rmdir","utimes"],r={...e};return t.forEach(n=>{r[n]=(...i)=>{let o=i.pop(),l;try{l=e[`${n}Sync`](...i)}catch(f){return o(f)}o(null,l)}}),r}function Hn(e){return(...t)=>new Promise((r,n)=>{t.push((i,o)=>{i?n(i):r(o)}),e(...t)})}function Wn(e){return(...t)=>{let r,n;if(t.push((i,o)=>{r=i,n=o}),e(...t),r)throw r;return n}}function qn(e){if(e={...e},e.fs=Bn(e.fs||zn),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}Er.exports={toPromise:Hn,toSync:Wn,toSyncOptions:qn}});var Or=j(($i,Z)=>{"use strict";var _e=yr(),{toPromise:Le,toSync:je,toSyncOptions:nt}=Ar();async function xr(e,t){let r=await Le(_e.lock)(e,t);return Le(r)}function Jn(e,t){let r=je(_e.lock)(e,nt(t));return je(r)}function Kn(e,t){return Le(_e.unlock)(e,t)}function Zn(e,t){return je(_e.unlock)(e,nt(t))}function Yn(e,t){return Le(_e.check)(e,t)}function Xn(e,t){return je(_e.check)(e,nt(t))}Z.exports=xr;Z.exports.lock=xr;Z.exports.unlock=Kn;Z.exports.lockSync=Jn;Z.exports.unlockSync=Zn;Z.exports.check=Yn;Z.exports.checkSync=Xn});import*as ot from"node:url";import*as Cr from"node:path";function ie(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 $e(e){if(e!=null)return ie(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}}function ye(e,t){if(e!==void 0&&t(L(e)))return e}function dt(e,t){if(e!==void 0)return t(L(e))}function V(e,t,r){return e!==void 0?r(L(e)):t}function $(e,t){if(e!==void 0)return ie(t(L(e)))}function ue(e,t){if(e!==void 0)return t(L(e))}function D(e,t){return e!==void 0?L(e):t}function ft(e,t){return e.TAG==="Ok"?e:{TAG:"Error",_0:t(e._0)}}var _t=(function(e,t){for(var r in e)t(r)});function le(e,t){if(e===t)return!0;let r=typeof e;if(r==="string"||r==="number"||r==="bigint"||r==="boolean"||r==="undefined"||e===null)return!1;let n=typeof t;if(r==="function"||n==="function")throw{RE_EXN_ID:"Invalid_argument",_1:"equal: functional value",Error:new Error};if(n==="number"||n==="bigint"||n==="undefined"||t===null)return!1;let i=e.TAG,o=t.TAG;if(i!==o)return!1;let l=e.length|0,f=t.length|0;if(l===f)if(Array.isArray(e)){let m=0;for(;;){let _=m;if(_===l)return!0;if(!le(e[_],t[_]))return!1;m=_+1|0}}else{if(e instanceof Date&&t instanceof Date)return!(e>t||e<t);{let m={contents:!0},_=c=>{if(!Object.prototype.hasOwnProperty.call(t,c)){m.contents=!1;return}},u=c=>{if(!Object.prototype.hasOwnProperty.call(e,c)||!le(t[c],e[c])){m.contents=!1;return}};return _t(e,_),m.contents&&_t(t,u),m.contents}}else return!1}function X(e,t){return(typeof e=="number"||typeof e=="bigint")&&(typeof t=="number"||typeof t=="bigint")?e!==t:!le(e,t)}import*as br from"node:fs/promises";function Jr(e){return e==null?!1:typeof e.RE_EXN_ID=="string"}function U(e){return Jr(e)?e:{RE_EXN_ID:"JsExn",_1:e}}var ht={name:"@linzumi/cli",version:"1.0.326",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","native/darwin/linzumi-terminal-pty-helper","native/darwin/terminal-pty-helper.manifest.json"],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 && npm run codex-protocol:declarations && 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","codex-protocol:declarations":"node ../linzumi-cli-rescript/scripts/CodexProtocolGenerate.res.mjs --repo-root ../.. --declarations-out packages/linzumi-cli/.generated/codex-app-server-protocol.d.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 && npm run codex-protocol:declarations && tsgo --noEmit -p tsconfig.json","typecheck:watch":"rescript build ../linzumi-cli-rescript && npm run codex-protocol:declarations && 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"},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","ghostty-web":"0.4.0","proper-lockfile":"3.2.0","stream-json":"1.9.1",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 Zr=ht,Ue=Zr.dependencies["@openai/codex"];function xe(e){if(e.RE_EXN_ID==="JsExn")return ie(e._1)}var Se=(e=>t=>t&&typeof t[e]=="string"?t[e]:void 0),Gi=Se("stack"),ge=Se("message"),Tt=Se("name"),Si=Se("fileName");var Xr=new RegExp("\\bsmk_[A-Za-z0-9._-]+","g");function w(e){return e.replace(Xr,"smk_[REDACTED]")}var Qr="https://api.smolmachines.com";function ze(e){return e.TAG==="Smolcloud"?e.message:e._0}function q(e){let t=xe(e);if(t===void 0)return"unknown error";let r=L(t);return D(ge(r),String(r))}function At(e){let t=xe(e);return t!==void 0?le(Tt(L(t)),"AbortError"):!1}var en=new RegExp("\\/+$");function Et(e,t){let r=e[t];if(r===void 0)return;let n=r.trim();if(n!=="")return n}function Be(e){let t=Et(e,"SMOLCLOUD_API_KEY");return $(t!==void 0?t:Et(e,"SMOL_CLOUD_TOKEN"),r=>({baseUrl:D(e.SMOLCLOUD_BASE_URL,Qr).replace(en,""),apiKey:r}))}async function we(e,t){try{return{TAG:"Ok",_0:await fetch(e,t)}}catch(r){return{TAG:"Error",_0:U(r)}}}async function xt(e){try{return await e.text()}catch{return""}}function Ot(e,t){return t===""?e.toString():e.toString()+": "+t}async function Q(e,t,r,n,i){let o=n!==void 0?n:"NoBody",l=i!==void 0?i:3e4,f=Object.fromEntries([["authorization","Bearer "+e.apiKey]]),m=new AbortController,_=setTimeout(()=>{m.abort()},l),u=e.baseUrl+r,c=m.signal,s;if(typeof o!="object"?s=await we(u,{method:t,headers:f,body:null,signal:c}):o.TAG==="JsonBody"?(f["content-type"]="application/json",s=await we(u,{method:t,headers:f,body:JSON.stringify(o._0),signal:c})):(f["content-type"]="application/octet-stream",s=await we(u,{method:t,headers:f,body:o._0,signal:c})),clearTimeout(_),s.TAG==="Ok"){let a=s._0;if(a.ok){if(a.status===204)return{TAG:"Ok",_0:"NoPayload"};if(!D($e(a.headers.get("content-type")),"").includes("application/json"))return{TAG:"Ok",_0:"NoPayload"};try{return{TAG:"Ok",_0:{TAG:"Payload",_0:await a.json()}}}catch(d){let p=U(d);return{TAG:"Error",_0:{TAG:"Thrown",_0:q(p)}}}}else{let d=a.status,p=await xt(a),h;if(d>=402)if(d>=405)h="CloudError";else switch(d){case 402:h="CloudError";break;case 403:h="Unauthorized";break;case 404:h="NotFound";break}else h=d>=401?"Unauthorized":"CloudError";let A="smolcloud "+t+" "+r+" \u2192 "+Ot(d,p);return{TAG:"Error",_0:{TAG:"Smolcloud",code:h,message:w(A)}}}}else{let a=s._0;if(At(a)){let p="smolcloud "+t+" "+r+" timed out after "+l.toString()+"ms";return{TAG:"Error",_0:{TAG:"Smolcloud",code:"Timeout",message:w(p)}}}let d="smolcloud request failed: "+q(a);return{TAG:"Error",_0:{TAG:"Smolcloud",code:"ConnectionFailed",message:w(d)}}}}function ce(e){return"/v1/machines/"+e.id}function ae(e,t){let r=e[t];if(typeof r=="string")return r}function tn(e,t){if(typeof t=="object"){let r=t._0;if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let n=r.id,i;i=n!=null?typeof n=="string"?n:void 0:e.id;let o=r.env,l;return l=typeof o=="object"&&o!==null&&!Array.isArray(o)?ae(o,"LINZUMI_ROLE"):void 0,{id:i,name:ae(r,"name"),role:l}}}return{id:e.id,name:void 0,role:void 0}}async function vt(e){let t=await Q(e.conn,"GET",ce(e),void 0,void 0);return t.TAG==="Ok"?{TAG:"Ok",_0:tn(e,t._0)}:{TAG:"Error",_0:t._0}}function z(e){return e.TAG==="Numeric"?e._0===0:!1}function Gt(e){return e.TAG==="Numeric"?e._0.toString():String(e._0)}function St(e,t){return Object.fromEntries([["command",e.map(r=>r)],["env",Object.fromEntries(D(t.env,[]).map(r=>[r[0],r[1]]))],["cwd",null],["stdin",V(t.stdin,null,r=>r)],["timeoutSeconds",V(t.timeout,null,r=>r)]])}function gt(e){return e!==void 0?e===null?{TAG:"Numeric",_0:0}:typeof e=="number"?{TAG:"Numeric",_0:e}:{TAG:"NonNumeric",_0:e}:{TAG:"Numeric",_0:0}}function rn(e){if(typeof e!="object")return{TAG:"Error",_0:{TAG:"Thrown",_0:"Cannot read properties of undefined (reading 'exitCode')"}};let t=e._0;return t===null?{TAG:"Error",_0:{TAG:"Thrown",_0:"Cannot read properties of null (reading 'exitCode')"}}:typeof t=="object"&&!Array.isArray(t)?{TAG:"Ok",_0:{exitCode:gt(t.exitCode),stdout:D(ae(t,"stdout"),""),stderr:D(ae(t,"stderr"),"")}}:{TAG:"Ok",_0:{exitCode:{TAG:"Numeric",_0:0},stdout:"",stderr:""}}}async function B(e,t,r){let n=r!==void 0?r:{},i=n.timeout,o=i!==void 0?Math.max(3e4,(i*1e3|0)+3e4|0):3e4,l=await Q(e.conn,"POST",ce(e)+"/exec",{TAG:"JsonBody",_0:St(t,n)},o);return l.TAG==="Ok"?rn(l._0):{TAG:"Error",_0:l._0}}function nn(e){let t;try{t=JSON.parse(e)}catch{t=void 0}return t!==void 0?typeof t=="object"&&t!==null&&!Array.isArray(t)?gt(t.exitCode):{TAG:"Numeric",_0:0}:{TAG:"Numeric",_0:0}}function on(e,t){switch(e){case"error":return{TAG:"StreamError",_0:w(t)};case"exit":return{TAG:"Exit",_0:nn(t)};case"stderr":return{TAG:"Stderr",_0:t};case"stdout":return{TAG:"Stdout",_0:t};default:return}}var un=new RegExp("^ ");async function ln(e,t){let r=e.getReader(),n=new TextDecoder,i={contents:""},o={contents:""},l={contents:[]},f=()=>{let c=o.contents,s=l.contents.join(`
5
5
  `);o.contents="",l.contents=[];let a=on(c,s);return a!==void 0?t(a):"Continue"},m=()=>{for(;;){let c=i.contents.indexOf(`
6
6
  `);if(c===-1)return"Continue";let s=i.contents.slice(0,c);i.contents=i.contents.slice(c+1|0);let a=s.endsWith("\r")?s.slice(0,-1):s,d=a===""?f():(a.startsWith("event:")?o.contents=a.slice(6).trim():a.startsWith("data:")&&l.contents.push(a.slice(5).replace(un,"")),"Continue");if(typeof d=="object")return d}},_=async()=>{let c;try{c={TAG:"Ok",_0:await r.read()}}catch(p){c={TAG:"Error",_0:U(p)}}if(c.TAG!=="Ok")return{TAG:"Error",_0:{TAG:"Thrown",_0:q(c._0)}};let s=c._0;if(s.done){let p=f();return typeof p!="object"?{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:p._0}}let a=s.value;a!=null&&(i.contents=i.contents+n.decode(a,{stream:!0}));let d=m();return typeof d!="object"?await _():{TAG:"Error",_0:d._0}},u=await _();return r.releaseLock(),u}async function wt(e,t,r,n){let i=new AbortController,o=$(r.timeout,c=>setTimeout(()=>{i.abort()},(c*1e3|0)+3e4|0)),l=()=>dt(o,c=>{clearTimeout(c)}),f=ce(e)+"/exec/stream",m=await we(e.conn.baseUrl+f,{method:"POST",headers:Object.fromEntries([["authorization","Bearer "+e.conn.apiKey],["content-type","application/json"],["accept","text/event-stream"]]),body:JSON.stringify(St(t,r)),signal:i.signal});if(m.TAG==="Ok"){let c=m._0,s;if(c.ok){let a=c.body;s=a==null?{TAG:"Error",_0:{TAG:"Smolcloud",code:"CloudError",message:w("exec/stream returned no response body")}}:await ln(a,n)}else{let a=c.status,d=await xt(c),p="smolcloud POST "+f+" \u2192 "+Ot(a,d);s={TAG:"Error",_0:{TAG:"Smolcloud",code:a===404?"NotFound":"CloudError",message:w(p)}}}return l(),s}let _=m._0;if(l(),At(_)){let s="smolcloud exec/stream timed out after "+((D(r.timeout,0)*1e3|0)+3e4|0).toString()+"ms";return{TAG:"Error",_0:{TAG:"Smolcloud",code:"Timeout",message:w(s)}}}let u="smolcloud exec/stream failed: "+q(_);return{TAG:"Error",_0:{TAG:"Smolcloud",code:"ConnectionFailed",message:w(u)}}}function an(e){return e.split("/").map(t=>encodeURIComponent(t)).join("/")}async function Oe(e,t,r,n){let i=await Q(e.conn,"PUT",ce(e)+"/files/"+an(t),{TAG:"BytesBody",_0:Buffer.from(r,"utf8")},void 0);if(i.TAG!=="Ok")return{TAG:"Error",_0:i._0};let o=await B(e,["chmod",n.toString(8),t],void 0);return o.TAG==="Ok"?{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:o._0}}async function He(e){let t=await Q(e.conn,"DELETE",ce(e),void 0,void 0);return t.TAG==="Ok"?{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:t._0}}function cn(e){let t="smolmachine:";if(!e.startsWith(t))return{TAG:"Ok",_0:Object.fromEntries([["type","image"],["reference",e]])};let r=e.slice(t.length),n=(l,f)=>({TAG:"Ok",_0:Object.fromEntries([["type","smolmachine"],["reference",l],["arch",f]])}),i=r.lastIndexOf("@");if(i===-1)return n(r,"arm64");let o=r.slice(i+1|0);switch(o){case"amd64":case"arm64":break;default:let l="invalid smolmachine image arch suffix "+JSON.stringify(o)+" in "+JSON.stringify(e)+" (expected @arm64 or @amd64)";return{TAG:"Error",_0:{TAG:"Smolcloud",code:"CloudError",message:w(l)}}}return n(r.slice(0,i),o)}function sn(e,t){return Object.fromEntries([["name",e.name],["source",t],["resources",Object.fromEntries([["cpus",e.cpus],["memoryMb",e.memoryMb],["diskGb",e.diskGb]])],["network",Object.fromEntries([["mode","open"]])],["env",Object.fromEntries(e.env.map(r=>[r[0],r[1]]))],["autoStopSeconds",e.autoStopSeconds],["ttlSeconds",e.ttlSeconds]])}function dn(e){return new Promise((t,r)=>{setTimeout(()=>t(),e)})}async function fn(e){let t=Date.now()+12e4,r=async()=>{let n=await Q(e.conn,"GET",ce(e),void 0,void 0),i;if(n.TAG==="Ok"){let l=n._0;if(typeof l!="object")i={TAG:"Ok",_0:void 0};else{let f=l._0;i=typeof f=="object"&&f!==null&&!Array.isArray(f)?{TAG:"Ok",_0:ae(f,"state")}:{TAG:"Ok",_0:void 0}}}else{let l=n._0;if(l.TAG==="Smolcloud")switch(l.code){case"Unauthorized":case"NotFound":i={TAG:"Error",_0:l};break;default:i={TAG:"Ok",_0:void 0}}else i={TAG:"Ok",_0:void 0}}if(i.TAG!=="Ok")return{TAG:"Error",_0:i._0};let o=i._0;if(o!==void 0)switch(o){case"error":return{TAG:"Error",_0:{TAG:"Smolcloud",code:"CloudError",message:w("machine "+e.id+" entered error state while starting")}};case"running":case"started":return{TAG:"Ok",_0:void 0}}if(Date.now()>=t){let l="machine "+e.id+" not ready after 120000ms (state="+D(o,"unknown")+")";return{TAG:"Error",_0:{TAG:"Smolcloud",code:"Timeout",message:w(l)}}}return await dn(1e3),await r()};return await r()}async function kt(e,t){let r=cn(t.image);if(r.TAG!=="Ok")return{TAG:"Error",_0:r._0};let n=await Q(e,"POST","/v1/machines",{TAG:"JsonBody",_0:sn(t,r._0)},void 0);if(n.TAG!=="Ok")return{TAG:"Error",_0:n._0};let i=n._0;if(typeof i!="object")return{TAG:"Error",_0:{TAG:"Thrown",_0:"Cannot read properties of undefined (reading 'id')"}};let o=i._0;if(o===null)return{TAG:"Error",_0:{TAG:"Thrown",_0:"Cannot read properties of null (reading 'id')"}};if(typeof o!="object"||o===null||Array.isArray(o))return{TAG:"Error",_0:{TAG:"Smolcloud",code:"CloudError",message:w("machine create returned no machine id")}};let l=ae(o,"id");if(l===void 0)return{TAG:"Error",_0:{TAG:"Smolcloud",code:"CloudError",message:w("machine create returned no machine id")}};let f={conn:e,id:l};await Q(e,"POST","/v1/machines/"+l+"/start",void 0,void 0);let m=await fn(f);return m.TAG==="Ok"?{TAG:"Ok",_0:f}:(await He(f),{TAG:"Error",_0:m._0})}import*as jt from"node:fs";import*as Rt from"node:path";import*as Dt from"node:fs/promises";function bt(e){return"'"+e.replaceAll("'","'\\''")+"'"}import*as Nt from"node:crypto";function Pt(e){return Nt.createHash("sha256").update(e).digest("hex")}var J="/home/agent",_n=J+"/.linzumi-provisioned",$t="v1",Ut=J+"/cloud-supervisor.mjs",Vt=J+"/mcp-server.mjs",Ft=J+"/.secrets",Mt=J+"/.codex",zt="/etc/ssl/certs/ca-certificates.crt",hn=new RegExp("[^A-Za-z0-9._-]","g");function Bt(e){return J+"/.linzumi-provisioned-"+$t+"-"+e.replace(hn,"_")}function Tn(e){return["/bin/sh","-c",["set -e","mkdir -p "+J+" "+Ft+" "+Mt,"chmod 700 "+Ft+" "+Mt,"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@"+bt(e)+" >/dev/null","rm -f "+J+"/.linzumi-provisioned-"+$t+"-* 2>/dev/null || true","touch "+Bt(e),"touch "+_n].join(" && ")]}function Ht(e){return"test -f "+Bt(e)+" && command -v codex >/dev/null && command -v node >/dev/null && "}function yn(e){return["/bin/sh","-c",Ht(e)+"command -v bwrap >/dev/null && test -s "+zt]}function En(e){return["/bin/sh","-c","if "+Ht(e)+("command -v bwrap >/dev/null && test -s "+zt+"; ")+"then echo TOOLCHAIN_OK; else echo TOOLCHAIN_MISSING; fi; "+("echo BUNDLE_SUP $(sha256sum "+Ut+" 2>/dev/null | cut -d' ' -f1); ")+("echo BUNDLE_MCP $(sha256sum "+Vt+" 2>/dev/null | cut -d' ' -f1)")]}var An=new RegExp("^[0-9a-f]{64}$");function xn(e){let t=e.split(`
7
7
  `).map(n=>n.trim()),r=n=>ye($(t.find(i=>i.startsWith(n+" ")),i=>i.slice(n.length+1|0).trim()),i=>An.test(i));return $(t.find(n=>n==="TOOLCHAIN_OK"?!0:n==="TOOLCHAIN_MISSING"),n=>({toolchain:n==="TOOLCHAIN_OK"?"ToolchainOk":"ToolchainMissing",supervisorSha256:r("BUNDLE_SUP"),mcpSha256:r("BUNDLE_MCP")}))}async function It(e,t){let r;try{r={TAG:"Ok",_0:await Dt.readFile(e,"utf8")}}catch(i){let o=U(i);r={TAG:"Error",_0:q(o)}}if(r.TAG!=="Ok")return{TAG:"Error",_0:{TAG:"Thrown",_0:w("could not read "+t+" bundle at "+e+": "+r._0)}};let n=r._0;return n.trim()===""?{TAG:"Error",_0:{TAG:"Thrown",_0:w(t+" bundle at "+e+" is empty")}}:{TAG:"Ok",_0:n}}function Lt(e,t){let r=Rt.join(e,t);if(jt.existsSync(r))return r}async function Wt(e,t,r){let n=Lt(r,"cloud-supervisor.mjs"),i=Lt(r,"mcp-server.mjs");if(n===void 0)return{TAG:"Error",_0:{TAG:"Thrown",_0:w("cloud agent turn requires dist/cloud-supervisor.mjs (run the CLI build); refusing to run without the guest supervisor bundle")}};if(i===void 0)return{TAG:"Error",_0:{TAG:"Thrown",_0:w("cloud agent turn requires dist/mcp-server.mjs (run the CLI build); refusing to run without the in-guest MCP bridge bundle")}};let o=await It(n,"cloud-supervisor.mjs");if(o.TAG!=="Ok")return{TAG:"Error",_0:o._0};let l=o._0,f=await It(i,"mcp-server.mjs");if(f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=f._0,_=await B(e,En(t),{timeout:30}),u;if(_.TAG==="Ok"){let p=_._0;u=z(p.exitCode)?xn(p.stdout):void 0}else console.warn("cloud_agent_provision_preflight_unavailable",{reason:"transport_failure",codexVersion:t}),u=void 0;let c=u!==void 0?u.toolchain!=="ToolchainOk":!0,s;if(c){let p=await B(e,Tn(t),{timeout:600});if(p.TAG==="Ok"){let h=p._0,A=h.exitCode;if(z(A)){let k=await B(e,yn(t),{timeout:30});s=k.TAG==="Ok"?z(k._0.exitCode)?{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:{TAG:"Thrown",_0:w("agent home provision completed but the toolchain check failed (codex/node/CA bundle missing)")}}:{TAG:"Error",_0:k._0}}else{let k="agent home provision failed (exit "+Gt(A)+"): "+h.stderr.slice(0,400);s={TAG:"Error",_0:{TAG:"Thrown",_0:w(k)}}}}else s={TAG:"Error",_0:p._0}}else s={TAG:"Ok",_0:void 0};let a=(p,h)=>c?!0:X(p,Pt(h));if(s.TAG!=="Ok")return{TAG:"Error",_0:s._0};let d=a(ue(u,p=>p.supervisorSha256),l)?await Oe(e,Ut,l,420):{TAG:"Ok",_0:void 0};return d.TAG==="Ok"?a(ue(u,p=>p.mcpSha256),m)?await Oe(e,Vt,m,420):{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:d._0}}var Qn=zr(Or(),1);var vr=new RegExp("(\\d+\\.\\d+\\.\\d+)");function Gr(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}}function ri(e,t){let r=Gr(e,t);switch(r.TAG){case"Match":return{TAG:"Ok",_0:r.version};case"Mismatch":return{TAG:"Error",_0:"hosted_codex_runtime_refused reason=mismatch observed="+r.pathVersion+" expected="+r.pinnedVersion};case"Unverified":return{TAG:"Error",_0:"hosted_codex_runtime_refused reason=unverified observed=unverified expected="+t}}}function Sr(e,t,r){let n;if(e===0&&t.length<=1048576){let i=vr.exec(t);n=i==null?void 0:ue(i.slice(1)[0],o=>o)}else n=void 0;return ri(n,r)}var ut="/opt/linzumi/hosted-coding-account-auth.mjs",Re="/home/agent/.linzumi-hosted-auth",Nr=Re+"/authorization-code.sock",ii="smolmachine:linzumi-agent-vm:codex-0.139.0-claude-2.1.260-v8";function oi(e){return e==="Codex"?"codex":"claude_code"}function ui(e){switch(e){case"claude_code":return"ClaudeCode";case"codex":return"Codex";default:return}}function li(e){return e==="Codex"?2048:4096}var Pr="hosted coding-account authorization and machine cleanup both failed";function ai(e){switch(e.TAG){case"Failed":return e._0;case"CloudFailed":return ze(e._0);case"Cleanup":return Pr}}function Fr(e){switch(e.TAG){case"Failed":case"CloudFailed":return new Error(ai(e));case"Cleanup":return new AggregateError([Fr(e.primary),new Error(ze(e.cleanup))],Pr)}}function it(e){return e.TAG==="Ok"?Promise.resolve():Promise.reject(Fr(e._0))}function he(e,t){let r=e.indexOf(t);return V(ye(r!==-1?e[r+1|0]:void 0,n=>n.trim()!==""),{TAG:"Error",_0:{TAG:"Failed",_0:"missing "+t+" for hosted coding-account authorization"}},n=>({TAG:"Ok",_0:n}))}var Mr={TAG:"Failed",_0:"hosted coding-account authorization compute is unavailable"};function ci(){return ot.fileURLToPath(import.meta.url.includes("/src/")?new URL("../../../linzumi-cli/dist/cloud-supervisor.mjs",import.meta.url):new URL("./cloud-supervisor.mjs",import.meta.url))}async function si(){try{return{TAG:"Ok",_0:await br.readFile(ci(),"utf8")}}catch(e){let t=U(e);return{TAG:"Error",_0:{TAG:"Failed",_0:q(t)}}}}async function di(e,t){let r=Be(process.env);if(r===void 0)return{TAG:"Error",_0:Mr};let n=await kt(r,{image:ii,name:"linzumi-auth-"+e,cpus:2,memoryMb:li(t),diskGb:20,env:[["LINZUMI_ROLE","coding-account-authorization"]],autoStopSeconds:900,ttlSeconds:900});return ft(n,i=>({TAG:"CloudFailed",_0:i}))}async function gr(e,t,r){let n=await B(e,t,void 0);return n.TAG==="Ok"?z(n._0.exitCode)?{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:{TAG:"Failed",_0:"hosted coding-account authorization "+r+" failed"}}:{TAG:"Error",_0:{TAG:"CloudFailed",_0:n._0}}}async function fi(e){let t=await Wt(e,Ue,Cr.dirname(ot.fileURLToPath(import.meta.url)));if(t.TAG!=="Ok")return{TAG:"Error",_0:{TAG:"CloudFailed",_0:t._0}};let r=await B(e,["codex","--version"],{timeout:10});if(r.TAG!=="Ok")return{TAG:"Error",_0:{TAG:"CloudFailed",_0:r._0}};let n=r._0,i=z(n.exitCode)?0:1,o=Sr(i,n.stdout,Ue);return o.TAG==="Ok"?{TAG:"Ok",_0:void 0}:(console.warn(o._0),{TAG:"Error",_0:{TAG:"Failed",_0:"hosted Codex runtime refused"}})}async function mi(e,t,r,n,i,o){let l={contents:void 0},f;f=t==="Authorization"?"--hosted-coding-account-auth":"--hosted-coding-account-model-catalog";let m=await wt(e,["node",ut,f],{env:[["LINZUMI_HOSTED_AUTH_CALLBACK_URL",n],["LINZUMI_HOSTED_AUTH_CALLBACK_TOKEN",i],["LINZUMI_HOSTED_AUTH_ROOT",Re],["LINZUMI_HOSTED_AUTH_EXPIRES_AT",o],["LINZUMI_HOSTED_AUTH_HARNESS",oi(r)],["LINZUMI_HOSTED_AUTH_WORKER_ID",e.id],["LINZUMI_HOSTED_AUTH_CODE_SOCKET",Nr]],timeout:630},u=>{switch(u.TAG){case"Stdout":case"Stderr":return"Continue";case"Exit":return l.contents=u._0,"Continue";case"StreamError":return{TAG:"Stop",_0:{TAG:"Thrown",_0:"hosted coding-account authorization guest failed"}}}}),_=l.contents;return m.TAG==="Ok"?_!==void 0&&z(_)?{TAG:"Ok",_0:void 0}:{TAG:"Error",_0:{TAG:"Failed",_0:"hosted coding-account authorization guest exited unsuccessfully"}}:{TAG:"Error",_0:{TAG:"CloudFailed",_0:m._0}}}async function pi(e,t,r,n,i,o){let l;if(l=r==="Codex"?await fi(e):{TAG:"Ok",_0:void 0},l.TAG!=="Ok")return{TAG:"Error",_0:l._0};let f=await si();if(f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=await gr(e,["mkdir","-p",Re],"auth-root creation");if(m.TAG!=="Ok")return{TAG:"Error",_0:m._0};let _=await gr(e,["chmod","700",Re],"auth-root permission");if(_.TAG!=="Ok")return{TAG:"Error",_0:_._0};let u=await Oe(e,ut,f._0,448);return u.TAG==="Ok"?await mi(e,t,r,n,i,o):{TAG:"Error",_0:{TAG:"CloudFailed",_0:u._0}}}async function wr(e,t){let r;r=t==="Authorization"?"--attempt-id":"--request-id";let n=he(e,r),i;if(n.TAG==="Ok"){let c=he(e,"--harness");if(c.TAG==="Ok"){let s=V(ui(c._0),{TAG:"Error",_0:{TAG:"Failed",_0:"unsupported hosted coding-account authorization harness"}},a=>({TAG:"Ok",_0:a}));if(s.TAG==="Ok"){let a=he(e,"--callback-url");if(a.TAG==="Ok"){let d=he(e,"--expires-at");if(d.TAG==="Ok"){let p=V(ye($(process.env.LINZUMI_HOSTED_AUTH_CALLBACK_TOKEN,h=>h.trim()),h=>h!==""),{TAG:"Error",_0:{TAG:"Failed",_0:"hosted authorization callback token is unavailable"}},h=>({TAG:"Ok",_0:h}));i=p.TAG==="Ok"?{TAG:"Ok",_0:[n._0,s._0,a._0,d._0,p._0]}:p}else i=d}else i=a}else i=s}else i=c}else i=n;if(i.TAG!=="Ok")return{TAG:"Error",_0:i._0};let o=i._0,l=o[1],f=await di(o[0],l);if(f.TAG!=="Ok")return{TAG:"Error",_0:f._0};let m=f._0,_=await pi(m,t,l,o[2],o[4],o[3]),u=await He(m);return u.TAG==="Ok"?_:_.TAG==="Ok"?{TAG:"Error",_0:{TAG:"CloudFailed",_0:u._0}}:{TAG:"Error",_0:{TAG:"Cleanup",primary:_._0,cleanup:u._0}}}var kr="invalid hosted authorization code input";function _i(e){return new Promise((t,r)=>{let n={contents:""},i=()=>{e.removeListener("data",l),e.removeListener("end",f),e.removeListener("error",m)},o=()=>{let _=n.contents.indexOf(`